fixed gif recording and cover assigning
This commit is contained in:
parent
1a9ec1b854
commit
6a86f0dd8f
61
src/studio.c
61
src/studio.c
|
@ -54,6 +54,9 @@
|
||||||
|
|
||||||
#define FRAME_SIZE (TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32))
|
#define FRAME_SIZE (TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32))
|
||||||
|
|
||||||
|
#define OFFSET_LEFT ((TIC80_FULLWIDTH-TIC80_WIDTH)/2)
|
||||||
|
#define OFFSET_TOP ((TIC80_FULLHEIGHT-TIC80_HEIGHT)/2)
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u8 data[16];
|
u8 data[16];
|
||||||
|
@ -957,7 +960,7 @@ static void calcTextureRect(SDL_Rect* rect)
|
||||||
|
|
||||||
rect->y = rect->w > rect->h
|
rect->y = rect->w > rect->h
|
||||||
? (rect->h - discreteHeight) / 2
|
? (rect->h - discreteHeight) / 2
|
||||||
: (TIC80_FULLWIDTH-TIC80_WIDTH)/2*discreteWidth/TIC80_WIDTH;
|
: OFFSET_LEFT*discreteWidth/TIC80_WIDTH;
|
||||||
|
|
||||||
rect->w = discreteWidth;
|
rect->w = discreteWidth;
|
||||||
rect->h = discreteHeight;
|
rect->h = discreteHeight;
|
||||||
|
@ -1401,32 +1404,38 @@ static u32* paletteBlit()
|
||||||
return srcPaletteBlit(studio.tic->ram.vram.palette.data);
|
return srcPaletteBlit(studio.tic->ram.vram.palette.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void screen2buffer(u32* buffer, const u8* pixels, s32 pitch)
|
static void screen2buffer(u32* buffer, const u32* pixels, SDL_Rect rect)
|
||||||
{
|
{
|
||||||
for(s32 i = 0; i < TIC80_FULLHEIGHT; i++)
|
pixels += rect.y * TIC80_FULLWIDTH;
|
||||||
|
|
||||||
|
for(s32 i = 0; i < rect.h; i++)
|
||||||
{
|
{
|
||||||
SDL_memcpy(buffer, pixels, TIC80_FULLWIDTH * sizeof(u32));
|
SDL_memcpy(buffer, pixels + rect.x, rect.w * sizeof(pixels[0]));
|
||||||
pixels += pitch;
|
pixels += TIC80_FULLWIDTH;
|
||||||
buffer += TIC80_FULLWIDTH;
|
buffer += rect.w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setCoverImage()
|
static void setCoverImage()
|
||||||
{
|
{
|
||||||
|
tic_mem* tic = studio.tic;
|
||||||
|
|
||||||
if(studio.mode == TIC_RUN_MODE)
|
if(studio.mode == TIC_RUN_MODE)
|
||||||
{
|
{
|
||||||
enum {Pitch = TIC80_WIDTH*sizeof(u32)};
|
enum {Pitch = TIC80_FULLWIDTH*sizeof(u32)};
|
||||||
u32* pixels = SDL_malloc(Pitch * TIC80_HEIGHT);
|
u32* pixels = SDL_malloc(Pitch * TIC80_FULLHEIGHT);
|
||||||
|
|
||||||
if(pixels)
|
if(pixels)
|
||||||
{
|
{
|
||||||
// blit(pixels);
|
tic->api.blit(tic, pixels, tic->api.scanline);
|
||||||
|
|
||||||
u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32));
|
u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32));
|
||||||
|
|
||||||
if(buffer)
|
if(buffer)
|
||||||
{
|
{
|
||||||
screen2buffer(buffer, (const u8*)pixels, Pitch);
|
SDL_Rect rect = {OFFSET_LEFT, OFFSET_TOP, TIC80_WIDTH, TIC80_HEIGHT};
|
||||||
|
|
||||||
|
screen2buffer(buffer, pixels, rect);
|
||||||
|
|
||||||
gif_write_animation(studio.tic->cart.cover.data, &studio.tic->cart.cover.size,
|
gif_write_animation(studio.tic->cart.cover.data, &studio.tic->cart.cover.size,
|
||||||
TIC80_WIDTH, TIC80_HEIGHT, (const u8*)buffer, 1, TIC_FRAMERATE, 1);
|
TIC80_WIDTH, TIC80_HEIGHT, (const u8*)buffer, 1, TIC_FRAMERATE, 1);
|
||||||
|
@ -1801,7 +1810,7 @@ static void blitSound()
|
||||||
SDL_QueueAudio(studio.audioDevice, studio.tic->samples.buffer, studio.tic->samples.size);
|
SDL_QueueAudio(studio.audioDevice, studio.tic->samples.buffer, studio.tic->samples.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawRecordLabel(u8* frame, s32 pitch, s32 sx, s32 sy, const u32* color)
|
static void drawRecordLabel(u32* frame, s32 pitch, s32 sx, s32 sy, const u32* color)
|
||||||
{
|
{
|
||||||
static const u16 RecLabel[] =
|
static const u16 RecLabel[] =
|
||||||
{
|
{
|
||||||
|
@ -1817,23 +1826,24 @@ static void drawRecordLabel(u8* frame, s32 pitch, s32 sx, s32 sy, const u32* col
|
||||||
for(s32 x = 0; x < sizeof RecLabel[0]*BITS_IN_BYTE; x++)
|
for(s32 x = 0; x < sizeof RecLabel[0]*BITS_IN_BYTE; x++)
|
||||||
{
|
{
|
||||||
if(RecLabel[y] & (1 << x))
|
if(RecLabel[y] & (1 << x))
|
||||||
memcpy(&frame[(sx + 15 - x + (y+sy)*(pitch/4))*4], color, sizeof *color);
|
memcpy(&frame[sx + 15 - x + (y+sy)*TIC80_FULLWIDTH], color, sizeof *color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void recordFrame(u8* pixels, s32 pitch)
|
static void recordFrame(u32* pixels)
|
||||||
{
|
{
|
||||||
if(studio.video.record)
|
if(studio.video.record)
|
||||||
{
|
{
|
||||||
if(studio.video.frame < studio.video.frames)
|
if(studio.video.frame < studio.video.frames)
|
||||||
{
|
{
|
||||||
screen2buffer(studio.video.buffer + (TIC80_FULLWIDTH*TIC80_FULLHEIGHT) * studio.video.frame, pixels, pitch);
|
SDL_Rect rect = {0, 0, TIC80_FULLWIDTH, TIC80_FULLHEIGHT};
|
||||||
|
screen2buffer(studio.video.buffer + (TIC80_FULLWIDTH*TIC80_FULLHEIGHT) * studio.video.frame, pixels, rect);
|
||||||
|
|
||||||
if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2)
|
if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2)
|
||||||
{
|
{
|
||||||
const u32* pal = srcPaletteBlit(studio.tic->ram.vram.palette.data);
|
const u32* pal = srcPaletteBlit(studio.tic->config.palette.data);
|
||||||
drawRecordLabel(pixels, pitch, TIC80_WIDTH-24, 8, &pal[tic_color_red]);
|
drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]);
|
||||||
}
|
}
|
||||||
|
|
||||||
studio.video.frame++;
|
studio.video.frame++;
|
||||||
|
@ -1875,12 +1885,12 @@ static void blitTexture()
|
||||||
|
|
||||||
tic->api.blit(tic, pixels, scanline);
|
tic->api.blit(tic, pixels, scanline);
|
||||||
|
|
||||||
recordFrame(pixels, pitch);
|
recordFrame(pixels);
|
||||||
|
|
||||||
SDL_UnlockTexture(studio.texture);
|
SDL_UnlockTexture(studio.texture);
|
||||||
|
|
||||||
{
|
{
|
||||||
enum {Header = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2};
|
enum {Header = OFFSET_TOP};
|
||||||
SDL_Rect srcRect = {0, 0, TIC80_FULLWIDTH, Header};
|
SDL_Rect srcRect = {0, 0, TIC80_FULLWIDTH, Header};
|
||||||
SDL_Rect dstRect = {0};
|
SDL_Rect dstRect = {0};
|
||||||
SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h);
|
SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h);
|
||||||
|
@ -1889,7 +1899,7 @@ static void blitTexture()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
enum {Header = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2};
|
enum {Header = OFFSET_TOP};
|
||||||
SDL_Rect srcRect = {0, TIC80_FULLHEIGHT - Header, TIC80_FULLWIDTH, Header};
|
SDL_Rect srcRect = {0, TIC80_FULLHEIGHT - Header, TIC80_FULLWIDTH, Header};
|
||||||
SDL_Rect dstRect = {0};
|
SDL_Rect dstRect = {0};
|
||||||
SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h);
|
SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h);
|
||||||
|
@ -1899,8 +1909,8 @@ static void blitTexture()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
enum {Header = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2};
|
enum {Header = OFFSET_TOP};
|
||||||
enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2};
|
enum {Left = OFFSET_LEFT};
|
||||||
SDL_Rect srcRect = {0, Header, Left, TIC80_HEIGHT};
|
SDL_Rect srcRect = {0, Header, Left, TIC80_HEIGHT};
|
||||||
SDL_Rect dstRect = {0};
|
SDL_Rect dstRect = {0};
|
||||||
SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h);
|
SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h);
|
||||||
|
@ -1910,8 +1920,8 @@ static void blitTexture()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2};
|
enum {Top = OFFSET_TOP};
|
||||||
enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2};
|
enum {Left = OFFSET_LEFT};
|
||||||
|
|
||||||
SDL_Rect srcRect = {Left, Top, TIC80_WIDTH, TIC80_HEIGHT};
|
SDL_Rect srcRect = {Left, Top, TIC80_WIDTH, TIC80_HEIGHT};
|
||||||
|
|
||||||
|
@ -2160,11 +2170,6 @@ static void tick()
|
||||||
SDL_SystemCursor cursor = studio.mouse.system;
|
SDL_SystemCursor cursor = studio.mouse.system;
|
||||||
studio.mouse.system = SDL_SYSTEM_CURSOR_ARROW;
|
studio.mouse.system = SDL_SYSTEM_CURSOR_ARROW;
|
||||||
|
|
||||||
// {
|
|
||||||
// const u8* pal = (u8*)(paletteBlit() + tic_tool_peek4(studio.tic->ram.vram.mapping, studio.tic->ram.vram.vars.border & 0xf));
|
|
||||||
// SDL_SetRenderDrawColor(studio.renderer, pal[2], pal[1], pal[0], SDL_ALPHA_OPAQUE);
|
|
||||||
// }
|
|
||||||
|
|
||||||
SDL_RenderClear(studio.renderer);
|
SDL_RenderClear(studio.renderer);
|
||||||
|
|
||||||
renderStudio();
|
renderStudio();
|
||||||
|
|
|
@ -1640,7 +1640,7 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer)
|
||||||
return (s32)(buffer - start);
|
return (s32)(buffer - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy from SDL2
|
// copied from SDL2
|
||||||
inline void memset4(void *dst, u32 val, u32 dwords)
|
inline void memset4(void *dst, u32 val, u32 dwords)
|
||||||
{
|
{
|
||||||
#if defined(__GNUC__) && defined(i386)
|
#if defined(__GNUC__) && defined(i386)
|
||||||
|
|
Loading…
Reference in New Issue