From eb1352256d6917a4c720e633db3d1257341de4ad Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 2 Nov 2017 22:29:31 +0300 Subject: [PATCH 01/12] no message --- src/console.c | 2 +- src/studio.c | 75 +++++++++++++++++++++++++++++++-------------------- src/tic.c | 2 ++ src/tic.h | 11 +++++++- 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/console.c b/src/console.c index 9def147..0699282 100644 --- a/src/console.c +++ b/src/console.c @@ -1775,7 +1775,7 @@ static void onConsoleRamCommand(Console* console, const char* param) ADDR_RECORD(console->tic->ram.vram.screen, "SCREEN"), ADDR_RECORD(console->tic->ram.vram.palette, "PALETTE"), ADDR_RECORD(console->tic->ram.vram.mapping, "PALETTE MAP"), - ADDR_RECORD(console->tic->ram.vram.vars.border, "BORDER COLOR"), + ADDR_RECORD(console->tic->ram.vram.vars.colors, "BORDER/BG COLOR"), ADDR_RECORD(console->tic->ram.vram.vars.offset, "SCREEN OFFSET"), ADDR_RECORD(console->tic->ram.vram.vars.mask, "GAMEPAD MASK"), ADDR_RECORD(console->tic->ram.vram.input.gamepad, "GAMEPAD"), diff --git a/src/studio.c b/src/studio.c index 3274e93..a847a69 100644 --- a/src/studio.c +++ b/src/studio.c @@ -52,8 +52,6 @@ #define MAX_CONTROLLERS 4 #define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888 -#define MAX_OFFSET 128 -#define FULL_WIDTH (TIC80_WIDTH + MAX_OFFSET*2) #define FRAME_SIZE (TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)) typedef struct @@ -1401,10 +1399,20 @@ static u32* paletteBlit() return srcPaletteBlit(studio.tic->ram.vram.palette.data); } +inline s32 clamp(s32 a, s32 b, s32 val) +{ + if(val < a) return a; + if(val > b) return b; + + return val; +} + static void blit(u32* out, u32* bgOut, s32 pitch, s32 bgPitch) { + tic_mem* tic = studio.tic; + const s32 pitchWidth = pitch/sizeof *out; - const s32 bgPitchWidth = bgPitch/sizeof *bgOut; + // const s32 bgPitchWidth = bgPitch/sizeof *bgOut; u32* row = out; const u32* pal = paletteBlit(); @@ -1413,7 +1421,7 @@ static void blit(u32* out, u32* bgOut, s32 pitch, s32 bgPitch) switch(studio.mode) { case TIC_RUN_MODE: - scanline = studio.tic->api.scanline; + scanline = tic->api.scanline; break; case TIC_SPRITE_MODE: scanline = studio.sprite.scanline; @@ -1425,25 +1433,42 @@ static void blit(u32* out, u32* bgOut, s32 pitch, s32 bgPitch) break; } - for(s32 r = 0, pos = 0; r < TIC80_HEIGHT; r++, row += pitchWidth) + for(s32 r = 0; r < TIC80_HEIGHT; r++, row += pitchWidth) { if(scanline) { - scanline(studio.tic, r); + scanline(tic, r); pal = paletteBlit(); } - if(bgOut) - { - u8 border = tic_tool_peek4(studio.tic->ram.vram.mapping, studio.tic->ram.vram.vars.border & 0xf); - SDL_memset4(bgOut, pal[border], TIC80_WIDTH); - bgOut += bgPitchWidth; - } + // if(bgOut) + // { + // u8 border = tic_tool_peek4(tic->ram.vram.mapping, tic->ram.vram.vars.border & 0xf); + // SDL_memset4(bgOut, pal[border], TIC80_WIDTH); + // bgOut += bgPitchWidth; + // } - SDL_memset4(row, 0, pitchWidth); + SDL_memset4(row, pal[tic->ram.vram.vars.bg], pitchWidth); - for(u32* ptr = row + MAX_OFFSET + studio.tic->ram.vram.vars.offset.x, c = 0; c < TIC80_WIDTH; c++, ptr++) - *ptr = pal[tic_tool_peek4(studio.tic->ram.vram.screen.data, pos++)]; + s32 actualRow = r - tic->ram.vram.vars.offset.y; + + if(actualRow >= TIC80_HEIGHT || actualRow < 0) + continue; + + s32 pos = actualRow * TIC80_WIDTH; + + if(tic->ram.vram.vars.offset.x == 0) + for(u32* ptr = row, c = 0; c < TIC80_WIDTH; c++, ptr++) + *ptr = pal[tic_tool_peek4(tic->ram.vram.screen.data, pos++)]; + else + for(u32* ptr = row, c = 0; c < TIC80_WIDTH; c++, ptr++) + { + s32 x = c + tic->ram.vram.vars.offset.x; + + if(x < 0 || x >= TIC80_WIDTH) continue; + + *ptr = pal[tic_tool_peek4(tic->ram.vram.screen.data, x + pos)]; + } } } @@ -1451,7 +1476,7 @@ static void screen2buffer(u32* buffer, const u8* pixels, s32 pitch) { for(s32 i = 0; i < TIC80_HEIGHT; i++) { - SDL_memcpy(buffer, pixels+MAX_OFFSET * sizeof(u32), TIC80_WIDTH * sizeof(u32)); + SDL_memcpy(buffer, pixels, TIC80_WIDTH * sizeof(u32)); pixels += pitch; buffer += TIC80_WIDTH; } @@ -1461,7 +1486,7 @@ static void setCoverImage() { if(studio.mode == TIC_RUN_MODE) { - enum {Pitch = FULL_WIDTH*sizeof(u32)}; + enum {Pitch = TIC80_WIDTH*sizeof(u32)}; u32* pixels = SDL_malloc(Pitch * TIC80_HEIGHT); if(pixels) @@ -1863,7 +1888,7 @@ 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++) { if(RecLabel[y] & (1 << x)) - memcpy(&frame[((MAX_OFFSET + sx) + 15 - x + (y+sy)*(pitch/4))*4], color, sizeof *color); + memcpy(&frame[(sx + 15 - x + (y+sy)*(pitch/4))*4], color, sizeof *color); } } } @@ -1897,9 +1922,7 @@ static void blitTexture() SDL_Rect rect = {0, 0, 0, 0}; calcTextureRect(&rect); - const s32 Pixel = rect.w / TIC80_WIDTH; - rect.x -= MAX_OFFSET * Pixel; - rect.w = rect.w * FULL_WIDTH / TIC80_WIDTH; + rect.w = rect.w * TIC80_WIDTH / TIC80_WIDTH; void* pixels = NULL; s32 pitch = 0; @@ -1907,8 +1930,6 @@ static void blitTexture() if(studio.mode == TIC_RUN_MODE) { - rect.y += studio.tic->ram.vram.vars.offset.y * Pixel; - { void* bgPixels = NULL; s32 bgPitch = 0; @@ -1929,7 +1950,7 @@ static void blitTexture() SDL_UnlockTexture(studio.texture); { - SDL_Rect srcRect = {0, 0, FULL_WIDTH, TIC80_HEIGHT}; + SDL_Rect srcRect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, &rect); } } @@ -2371,11 +2392,7 @@ static void onFSInitialized(FileSystem* fs) studio.renderer = SDL_CreateRenderer(studio.window, -1, renderFlags); studio.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, - textureLog2(FULL_WIDTH), textureLog2(TIC80_HEIGHT)); - -#if !defined(__ARM_LINUX__) - SDL_SetTextureBlendMode(studio.texture, SDL_BLENDMODE_BLEND); -#endif + textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT)); studio.borderTexture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT)); diff --git a/src/tic.c b/src/tic.c index 857e921..1cb44fe 100644 --- a/src/tic.c +++ b/src/tic.c @@ -493,6 +493,8 @@ static void api_clear(tic_mem* memory, u8 color) { api_rect(memory, machine->state.clip.l, machine->state.clip.t, machine->state.clip.r - machine->state.clip.l, machine->state.clip.b - machine->state.clip.t, color); } + + memory->ram.vram.vars.bg = color & 0xf; } static s32 drawChar(tic_mem* memory, u8 symbol, s32 x, s32 y, s32 width, s32 height, u8 color, s32 scale) diff --git a/src/tic.h b/src/tic.h index 4dcca16..afce57f 100644 --- a/src/tic.h +++ b/src/tic.h @@ -355,7 +355,16 @@ typedef union struct { - u8 border; + union + { + u8 colors; + + struct + { + u8 border:TIC_PALETTE_BPP; + u8 bg:TIC_PALETTE_BPP; + }; + }; struct { From 5c6d87525fc7b5677c172b86d48992aaadbf6c8a Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 2 Nov 2017 22:37:44 +0300 Subject: [PATCH 02/12] removed border texture --- src/studio.c | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/src/studio.c b/src/studio.c index a847a69..b6a1256 100644 --- a/src/studio.c +++ b/src/studio.c @@ -79,7 +79,6 @@ static struct SDL_Window* window; SDL_Renderer* renderer; SDL_Texture* texture; - SDL_Texture* borderTexture; SDL_AudioSpec audioSpec; SDL_AudioDeviceID audioDevice; @@ -194,7 +193,6 @@ static struct .window = NULL, .renderer = NULL, .texture = NULL, - .borderTexture = NULL, .audioDevice = 0, .joysticks = {NULL, NULL, NULL, NULL}, @@ -1407,12 +1405,11 @@ inline s32 clamp(s32 a, s32 b, s32 val) return val; } -static void blit(u32* out, u32* bgOut, s32 pitch, s32 bgPitch) +static void blit(u32* out, s32 pitch, s32 bgPitch) { tic_mem* tic = studio.tic; const s32 pitchWidth = pitch/sizeof *out; - // const s32 bgPitchWidth = bgPitch/sizeof *bgOut; u32* row = out; const u32* pal = paletteBlit(); @@ -1441,12 +1438,7 @@ static void blit(u32* out, u32* bgOut, s32 pitch, s32 bgPitch) pal = paletteBlit(); } - // if(bgOut) - // { // u8 border = tic_tool_peek4(tic->ram.vram.mapping, tic->ram.vram.vars.border & 0xf); - // SDL_memset4(bgOut, pal[border], TIC80_WIDTH); - // bgOut += bgPitchWidth; - // } SDL_memset4(row, pal[tic->ram.vram.vars.bg], pitchWidth); @@ -1491,7 +1483,7 @@ static void setCoverImage() if(pixels) { - blit(pixels, NULL, Pitch, 0); + blit(pixels, Pitch, 0); u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)); @@ -1928,22 +1920,7 @@ static void blitTexture() s32 pitch = 0; SDL_LockTexture(studio.texture, NULL, &pixels, &pitch); - if(studio.mode == TIC_RUN_MODE) - { - { - void* bgPixels = NULL; - s32 bgPitch = 0; - SDL_LockTexture(studio.borderTexture, NULL, &bgPixels, &bgPitch); - blit(pixels, bgPixels, pitch, bgPitch); - SDL_UnlockTexture(studio.borderTexture); - - { - SDL_Rect srcRect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; - SDL_RenderCopy(studio.renderer, studio.borderTexture, &srcRect, NULL); - } - } - } - else blit(pixels, NULL, pitch, 0); + blit(pixels, pitch, 0); recordFrame(pixels, pitch); @@ -2394,9 +2371,6 @@ static void onFSInitialized(FileSystem* fs) studio.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT)); - studio.borderTexture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, - textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT)); - initTouchGamepad(); } @@ -2467,7 +2441,6 @@ s32 main(s32 argc, char **argv) SDL_DestroyTexture(studio.gamepad.texture); SDL_DestroyTexture(studio.texture); - SDL_DestroyTexture(studio.borderTexture); if(studio.mouse.texture) SDL_DestroyTexture(studio.mouse.texture); From b43bfe06fb2fc1bb7b9dc48a1510b9b6babed918 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 2 Nov 2017 23:08:40 +0300 Subject: [PATCH 03/12] switch to software renderer if hardware not detected --- include/tic80/tic80.h | 13 ++++------- src/studio.c | 53 +++++++++++++++++++++++-------------------- src/tic80.c | 7 ------ 3 files changed, 32 insertions(+), 41 deletions(-) diff --git a/include/tic80/tic80.h b/include/tic80/tic80.h index f9efa17..8b70994 100644 --- a/include/tic80/tic80.h +++ b/include/tic80/tic80.h @@ -31,6 +31,8 @@ extern "C" { #define TIC80_WIDTH 240 #define TIC80_HEIGHT 136 +#define TIC80_FULLWIDTH 256 +#define TIC80_FULLHEIGHT (TIC80_FULLWIDTH*9/16) typedef struct { @@ -47,15 +49,8 @@ typedef struct s32 count; } sound; - u32 screen[TIC80_WIDTH * TIC80_HEIGHT]; - u32 border[TIC80_HEIGHT]; - - struct - { - s8 x; - s8 y; - s8 rows[TIC80_HEIGHT]; - } offset; + u32 screen[TIC80_FULLWIDTH * TIC80_FULLHEIGHT]; + } tic80; typedef union diff --git a/src/studio.c b/src/studio.c index b6a1256..c3ad85d 100644 --- a/src/studio.c +++ b/src/studio.c @@ -47,7 +47,6 @@ #include "ext/md5.h" #define STUDIO_UI_SCALE 3 -#define STUDIO_UI_BORDER 16 #define MAX_CONTROLLERS 4 #define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888 @@ -78,6 +77,7 @@ static struct SDL_Window* window; SDL_Renderer* renderer; + SDL_Renderer* softwareRenderer; SDL_Texture* texture; SDL_AudioSpec audioSpec; @@ -192,6 +192,7 @@ static struct .window = NULL, .renderer = NULL, + .softwareRenderer = NULL, .texture = NULL, .audioDevice = 0, @@ -2173,10 +2174,10 @@ static void tick() SDL_SystemCursor cursor = studio.mouse.system; 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); - } + // { + // 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); @@ -2228,7 +2229,7 @@ static void initTouchGamepad() if(!studio.gamepad.texture) { studio.gamepad.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, - textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT)); + textureLog2(TIC80_FULLWIDTH), textureLog2(TIC80_FULLHEIGHT)); SDL_SetTextureBlendMode(studio.gamepad.texture, SDL_BLENDMODE_BLEND); } @@ -2327,8 +2328,8 @@ static void onFSInitialized(FileSystem* fs) SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); studio.window = SDL_CreateWindow( TIC_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - (TIC80_WIDTH+STUDIO_UI_BORDER) * STUDIO_UI_SCALE, - (TIC80_HEIGHT+STUDIO_UI_BORDER) * STUDIO_UI_SCALE, + (TIC80_FULLWIDTH) * STUDIO_UI_SCALE, + (TIC80_FULLHEIGHT) * STUDIO_UI_SCALE, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE #if defined(__ARM_LINUX__) | SDL_WINDOW_FULLSCREEN_DESKTOP @@ -2361,13 +2362,11 @@ static void onFSInitialized(FileSystem* fs) // set the window icon before renderer is created (issues on Linux) setWindowIcon(); -#if defined(__ARM_LINUX__) - s32 renderFlags = SDL_RENDERER_SOFTWARE; -#else - s32 renderFlags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC; -#endif + studio.renderer = SDL_CreateRenderer(studio.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + + if(!studio.renderer) + studio.softwareRenderer = studio.renderer = SDL_CreateRenderer(studio.window, -1, SDL_RENDERER_SOFTWARE); - studio.renderer = SDL_CreateRenderer(studio.window, -1, renderFlags); studio.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT)); @@ -2415,21 +2414,25 @@ s32 main(s32 argc, char **argv) createFileSystem(onFSInitialized); - u64 nextTick = SDL_GetPerformanceCounter(); - const u64 Delta = SDL_GetPerformanceFrequency() / TIC_FRAMERATE; - - while (!studio.quitFlag) + if(studio.softwareRenderer) { - nextTick += Delta; - tick(); + u64 nextTick = SDL_GetPerformanceCounter(); + const u64 Delta = SDL_GetPerformanceFrequency() / TIC_FRAMERATE; + + while (!studio.quitFlag) + { + nextTick += Delta; + tick(); - s64 delay = nextTick - SDL_GetPerformanceCounter(); + s64 delay = nextTick - SDL_GetPerformanceCounter(); - if(delay > 0) - SDL_Delay((u32)(delay * 1000 / SDL_GetPerformanceFrequency())); - else nextTick -= delay; + if(delay > 0) + SDL_Delay((u32)(delay * 1000 / SDL_GetPerformanceFrequency())); + else nextTick -= delay; + } } - + // TODO: check if window minimised + else while(!studio.quitFlag) tick(); #endif diff --git a/src/tic80.c b/src/tic80.c index 9ff3292..81eec0f 100644 --- a/src/tic80.c +++ b/src/tic80.c @@ -139,19 +139,12 @@ static void blit(tic80* tic) tic80_local* tic80 = (tic80_local*)tic; u32* screen = tic->screen; - u32* border = tic->border; - - tic->offset.x = tic80->memory->ram.vram.vars.offset.x; - tic->offset.y = tic80->memory->ram.vram.vars.offset.y; for (s32 r = 0, pos = 0; r < TIC80_HEIGHT; r++, screen += TIC80_WIDTH) { tic80->memory->api.scanline(tic80->memory, r); const u32* pal = paletteBlit(tic80->memory); - tic->offset.rows[r] = tic80->memory->ram.vram.vars.offset.x; - - *border++ = pal[tic_tool_peek4(tic80->memory->ram.vram.mapping, tic80->memory->ram.vram.vars.border & 0xf)]; for (u32* ptr = screen, c = 0; c < TIC80_WIDTH; c++, ptr++) *ptr = pal[tic_tool_peek4(tic80->memory->ram.vram.screen.data, pos++)]; } From f0691038f54c3cdf3837fdbbe88ddbff0a487d6b Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 3 Nov 2017 11:53:10 +0300 Subject: [PATCH 04/12] no message --- src/studio.c | 57 +++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/src/studio.c b/src/studio.c index c3ad85d..f76ac42 100644 --- a/src/studio.c +++ b/src/studio.c @@ -47,6 +47,7 @@ #include "ext/md5.h" #define STUDIO_UI_SCALE 3 +#define TEXTURE_SIZE (TIC80_FULLWIDTH) #define MAX_CONTROLLERS 4 #define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888 @@ -1406,12 +1407,10 @@ inline s32 clamp(s32 a, s32 b, s32 val) return val; } -static void blit(u32* out, s32 pitch, s32 bgPitch) +static void blit(u32* out) { tic_mem* tic = studio.tic; - const s32 pitchWidth = pitch/sizeof *out; - u32* row = out; const u32* pal = paletteBlit(); void(*scanline)(tic_mem* memory, s32 row) = NULL; @@ -1431,7 +1430,7 @@ static void blit(u32* out, s32 pitch, s32 bgPitch) break; } - for(s32 r = 0; r < TIC80_HEIGHT; r++, row += pitchWidth) + for(s32 r = 0; r < TIC80_HEIGHT; r++) { if(scanline) { @@ -1439,29 +1438,20 @@ static void blit(u32* out, s32 pitch, s32 bgPitch) pal = paletteBlit(); } - // u8 border = tic_tool_peek4(tic->ram.vram.mapping, tic->ram.vram.vars.border & 0xf); + SDL_memset4(&out[r * TEXTURE_SIZE], pal[tic->ram.vram.vars.bg], TEXTURE_SIZE); - SDL_memset4(row, pal[tic->ram.vram.vars.bg], pitchWidth); + s32 y = r + tic->ram.vram.vars.offset.y; - s32 actualRow = r - tic->ram.vram.vars.offset.y; + if(y < 0 || y >= TIC80_HEIGHT) continue; + + for(s32 c = 0; c < TIC80_WIDTH; c++) + { + s32 x = c + tic->ram.vram.vars.offset.x; - if(actualRow >= TIC80_HEIGHT || actualRow < 0) - continue; + if(x < 0 || x >= TIC80_WIDTH) continue; - s32 pos = actualRow * TIC80_WIDTH; - - if(tic->ram.vram.vars.offset.x == 0) - for(u32* ptr = row, c = 0; c < TIC80_WIDTH; c++, ptr++) - *ptr = pal[tic_tool_peek4(tic->ram.vram.screen.data, pos++)]; - else - for(u32* ptr = row, c = 0; c < TIC80_WIDTH; c++, ptr++) - { - s32 x = c + tic->ram.vram.vars.offset.x; - - if(x < 0 || x >= TIC80_WIDTH) continue; - - *ptr = pal[tic_tool_peek4(tic->ram.vram.screen.data, x + pos)]; - } + out[c + r * TEXTURE_SIZE] = pal[tic_tool_peek4(tic->ram.vram.screen.data, x + y * TIC80_WIDTH)]; + } } } @@ -1484,7 +1474,8 @@ static void setCoverImage() if(pixels) { - blit(pixels, Pitch, 0); + // TODO: blit without border + // blit(pixels); u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)); @@ -1915,13 +1906,11 @@ static void blitTexture() SDL_Rect rect = {0, 0, 0, 0}; calcTextureRect(&rect); - rect.w = rect.w * TIC80_WIDTH / TIC80_WIDTH; - void* pixels = NULL; s32 pitch = 0; SDL_LockTexture(studio.texture, NULL, &pixels, &pitch); - blit(pixels, pitch, 0); + blit(pixels); recordFrame(pixels, pitch); @@ -2211,14 +2200,6 @@ static void initSound() SDL_PauseAudioDevice(studio.audioDevice, 0); } -static s32 textureLog2(s32 val) -{ - u32 rom = 0; - while( val >>= 1 ) rom++; - - return 1 << ++rom; -} - static void initTouchGamepad() { if (!studio.renderer) @@ -2228,8 +2209,7 @@ static void initTouchGamepad() if(!studio.gamepad.texture) { - studio.gamepad.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, - textureLog2(TIC80_FULLWIDTH), textureLog2(TIC80_FULLHEIGHT)); + studio.gamepad.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, TEXTURE_SIZE, TEXTURE_SIZE); SDL_SetTextureBlendMode(studio.gamepad.texture, SDL_BLENDMODE_BLEND); } @@ -2367,8 +2347,7 @@ static void onFSInitialized(FileSystem* fs) if(!studio.renderer) studio.softwareRenderer = studio.renderer = SDL_CreateRenderer(studio.window, -1, SDL_RENDERER_SOFTWARE); - studio.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, - textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT)); + studio.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, TEXTURE_SIZE, TEXTURE_SIZE); initTouchGamepad(); } From c4aefd3336f1c36c6ccd7b2b14c876fa482c857a Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 3 Nov 2017 18:58:45 +0300 Subject: [PATCH 05/12] no message --- src/studio.c | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/studio.c b/src/studio.c index f76ac42..90ab75a 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1430,29 +1430,47 @@ static void blit(u32* out) break; } + if(scanline) + { + scanline(tic, 0); + pal = paletteBlit(); + } + + enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2, Bottom = Top}; + enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2, Right = Left}; + + SDL_memset4(&out[0 * TEXTURE_SIZE], pal[tic->ram.vram.vars.border], TEXTURE_SIZE*Top); + for(s32 r = 0; r < TIC80_HEIGHT; r++) { - if(scanline) + SDL_memset4(&out[(r+Top) * TEXTURE_SIZE], pal[tic->ram.vram.vars.border], Left); + SDL_memset4(&out[(r+Top) * TEXTURE_SIZE + Left], pal[tic->ram.vram.vars.bg], TIC80_WIDTH); + { - scanline(tic, r); + s32 y = r + tic->ram.vram.vars.offset.y; + + if(y < 0 || y >= TIC80_HEIGHT) continue; + + for(s32 c = 0; c < TIC80_WIDTH; c++) + { + s32 x = c + tic->ram.vram.vars.offset.x; + + if(x < 0 || x >= TIC80_WIDTH) continue; + + out[(c + Left) + (r+Top) * TEXTURE_SIZE] = pal[tic_tool_peek4(tic->ram.vram.screen.data, x + y * TIC80_WIDTH)]; + } + } + + SDL_memset4(&out[(r+Top) * TEXTURE_SIZE + (TIC80_FULLWIDTH-Right)], pal[tic->ram.vram.vars.border], Right); + + if(scanline && (r < TIC80_HEIGHT-1)) + { + scanline(tic, r+1); pal = paletteBlit(); } - - SDL_memset4(&out[r * TEXTURE_SIZE], pal[tic->ram.vram.vars.bg], TEXTURE_SIZE); - - s32 y = r + tic->ram.vram.vars.offset.y; - - if(y < 0 || y >= TIC80_HEIGHT) continue; - - for(s32 c = 0; c < TIC80_WIDTH; c++) - { - s32 x = c + tic->ram.vram.vars.offset.x; - - if(x < 0 || x >= TIC80_WIDTH) continue; - - out[c + r * TEXTURE_SIZE] = pal[tic_tool_peek4(tic->ram.vram.screen.data, x + y * TIC80_WIDTH)]; - } } + + SDL_memset4(&out[(TIC80_FULLHEIGHT-Bottom) * TEXTURE_SIZE], pal[tic->ram.vram.vars.border], TEXTURE_SIZE*Bottom); } static void screen2buffer(u32* buffer, const u8* pixels, s32 pitch) From 9c6a92f4d278427893d880bcdc7ba670e743a9a8 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 3 Nov 2017 19:39:14 +0300 Subject: [PATCH 06/12] blit function moved to tic core --- build/windows/example/example.vcxproj | 14 +++- examples/sdl-renderer.c | 4 +- src/studio.c | 101 ++++++-------------------- src/tic.c | 97 +++++++++++++++++++++++++ src/tic80.c | 41 +---------- src/ticapi.h | 2 + 6 files changed, 136 insertions(+), 123 deletions(-) diff --git a/build/windows/example/example.vcxproj b/build/windows/example/example.vcxproj index 138b2b7..24d9f1e 100644 --- a/build/windows/example/example.vcxproj +++ b/build/windows/example/example.vcxproj @@ -22,6 +22,12 @@ + + {da956fd3-e142-46f2-9dd5-c78bebb56b7a} + + + {81ce8daf-ebb2-4761-8e45-b71abcca8c68} + {c4d8bc10-ebf6-42bb-9b5d-6712fb428a50} @@ -100,7 +106,7 @@ Windows true - SDL2main.lib;SDL2.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + ;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) ..\..\..\lib\windows @@ -115,7 +121,7 @@ Windows true - SDL2main.lib;SDL2.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + ;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) ..\..\..\lib\windows @@ -134,7 +140,7 @@ true true true - SDL2main.lib;SDL2.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + ;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) ..\..\..\lib\windows @@ -153,7 +159,7 @@ true true true - SDL2main.lib;SDL2.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + ;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) ..\..\..\lib\windows diff --git a/examples/sdl-renderer.c b/examples/sdl-renderer.c index d80216b..27a4950 100644 --- a/examples/sdl-renderer.c +++ b/examples/sdl-renderer.c @@ -56,9 +56,9 @@ int main(int argc, char **argv) SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); { - SDL_Window* window = SDL_CreateWindow("TIC-80 SDL demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, TIC80_WIDTH, TIC80_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); + SDL_Window* window = SDL_CreateWindow("TIC-80 SDL demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, TIC80_FULLWIDTH, TIC80_FULLHEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); - SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, TIC80_WIDTH, TIC80_HEIGHT); + SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, TIC80_FULLWIDTH, TIC80_FULLHEIGHT); SDL_AudioDeviceID audioDevice = 0; SDL_AudioSpec audioSpec; diff --git a/src/studio.c b/src/studio.c index 90ab75a..f22cbd8 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1399,80 +1399,6 @@ static u32* paletteBlit() return srcPaletteBlit(studio.tic->ram.vram.palette.data); } -inline s32 clamp(s32 a, s32 b, s32 val) -{ - if(val < a) return a; - if(val > b) return b; - - return val; -} - -static void blit(u32* out) -{ - tic_mem* tic = studio.tic; - - const u32* pal = paletteBlit(); - - void(*scanline)(tic_mem* memory, s32 row) = NULL; - - switch(studio.mode) - { - case TIC_RUN_MODE: - scanline = tic->api.scanline; - break; - case TIC_SPRITE_MODE: - scanline = studio.sprite.scanline; - break; - case TIC_MAP_MODE: - scanline = studio.map.scanline; - break; - default: - break; - } - - if(scanline) - { - scanline(tic, 0); - pal = paletteBlit(); - } - - enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2, Bottom = Top}; - enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2, Right = Left}; - - SDL_memset4(&out[0 * TEXTURE_SIZE], pal[tic->ram.vram.vars.border], TEXTURE_SIZE*Top); - - for(s32 r = 0; r < TIC80_HEIGHT; r++) - { - SDL_memset4(&out[(r+Top) * TEXTURE_SIZE], pal[tic->ram.vram.vars.border], Left); - SDL_memset4(&out[(r+Top) * TEXTURE_SIZE + Left], pal[tic->ram.vram.vars.bg], TIC80_WIDTH); - - { - s32 y = r + tic->ram.vram.vars.offset.y; - - if(y < 0 || y >= TIC80_HEIGHT) continue; - - for(s32 c = 0; c < TIC80_WIDTH; c++) - { - s32 x = c + tic->ram.vram.vars.offset.x; - - if(x < 0 || x >= TIC80_WIDTH) continue; - - out[(c + Left) + (r+Top) * TEXTURE_SIZE] = pal[tic_tool_peek4(tic->ram.vram.screen.data, x + y * TIC80_WIDTH)]; - } - } - - SDL_memset4(&out[(r+Top) * TEXTURE_SIZE + (TIC80_FULLWIDTH-Right)], pal[tic->ram.vram.vars.border], Right); - - if(scanline && (r < TIC80_HEIGHT-1)) - { - scanline(tic, r+1); - pal = paletteBlit(); - } - } - - SDL_memset4(&out[(TIC80_FULLHEIGHT-Bottom) * TEXTURE_SIZE], pal[tic->ram.vram.vars.border], TEXTURE_SIZE*Bottom); -} - static void screen2buffer(u32* buffer, const u8* pixels, s32 pitch) { for(s32 i = 0; i < TIC80_HEIGHT; i++) @@ -1921,6 +1847,7 @@ static void recordFrame(u8* pixels, s32 pitch) static void blitTexture() { + tic_mem* tic = studio.tic; SDL_Rect rect = {0, 0, 0, 0}; calcTextureRect(&rect); @@ -1928,15 +1855,35 @@ static void blitTexture() s32 pitch = 0; SDL_LockTexture(studio.texture, NULL, &pixels, &pitch); - blit(pixels); + tic_scanline scanline = NULL; + + switch(studio.mode) + { + case TIC_RUN_MODE: + scanline = tic->api.scanline; + break; + case TIC_SPRITE_MODE: + scanline = studio.sprite.scanline; + break; + case TIC_MAP_MODE: + scanline = studio.map.scanline; + break; + default: + break; + } + + tic->api.blit(tic, pixels, scanline); recordFrame(pixels, pitch); SDL_UnlockTexture(studio.texture); { - SDL_Rect srcRect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; - SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, &rect); + // SDL_Rect srcRect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; + // SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, &rect); + + SDL_Rect srcRect = {0, 0, TIC80_FULLWIDTH, TIC80_FULLHEIGHT}; + SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, NULL); } } diff --git a/src/tic.c b/src/tic.c index 1cb44fe..1c6d686 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1640,6 +1640,102 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) return (s32)(buffer - start); } +// copy from SDL2 +inline void memset4(void *dst, u32 val, u32 dwords) +{ +#if defined(__GNUC__) && defined(i386) + s32 u0, u1, u2; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; stosl \n\t" + : "=&D" (u0), "=&a" (u1), "=&c" (u2) + : "0" (dst), "1" (val), "2" (dwords) + : "memory" + ); +#else + u32 _n = (dwords + 3) / 4; + u32 *_p = (u32*)dst; + u32 _val = (val); + if (dwords == 0) + return; + switch (dwords % 4) + { + case 0: do { *_p++ = _val; + case 3: *_p++ = _val; + case 2: *_p++ = _val; + case 1: *_p++ = _val; + } while ( --_n ); + } +#endif +} + +static u32* paletteBlit(tic_mem* tic) +{ + static u32 pal[TIC_PALETTE_SIZE] = {0}; + + const u8* src = tic->ram.vram.palette.data; + + memset(pal, 0xff, sizeof pal); + + u8* dst = (u8*)pal; + const u8* end = src + sizeof(tic_palette); + + enum{RGB = sizeof(tic_rgb)}; + + for(; src != end; dst++, src+=RGB) + for(s32 j = 0; j < RGB; j++) + *dst++ = *(src+(RGB-1)-j); + + return pal; +} + +void api_blit(tic_mem* tic, u32* out, tic_scanline scanline) +{ + const u32* pal = paletteBlit(tic); + + if(scanline) + { + scanline(tic, 0); + pal = paletteBlit(tic); + } + + enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2, Bottom = Top}; + enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2, Right = Left}; + + memset4(&out[0 * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], TIC80_FULLWIDTH*Top); + + for(s32 r = 0; r < TIC80_HEIGHT; r++) + { + memset4(&out[(r+Top) * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], Left); + memset4(&out[(r+Top) * TIC80_FULLWIDTH + Left], pal[tic->ram.vram.vars.bg], TIC80_WIDTH); + + { + s32 y = r + tic->ram.vram.vars.offset.y; + + if(y < 0 || y >= TIC80_HEIGHT) continue; + + for(s32 c = 0; c < TIC80_WIDTH; c++) + { + s32 x = c + tic->ram.vram.vars.offset.x; + + if(x < 0 || x >= TIC80_WIDTH) continue; + + out[(c + Left) + (r+Top) * TIC80_FULLWIDTH] = pal[tic_tool_peek4(tic->ram.vram.screen.data, x + y * TIC80_WIDTH)]; + } + } + + memset4(&out[(r+Top) * TIC80_FULLWIDTH + (TIC80_FULLWIDTH-Right)], pal[tic->ram.vram.vars.border], Right); + + if(scanline && (r < TIC80_HEIGHT-1)) + { + scanline(tic, r+1); + pal = paletteBlit(tic); + } + } + + memset4(&out[(TIC80_FULLHEIGHT-Bottom) * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], TIC80_FULLWIDTH*Bottom); +} + static void initApi(tic_api* api) { #define INIT_API(func) api->func = api_##func @@ -1684,6 +1780,7 @@ static void initApi(tic_api* api) INIT_API(save); INIT_API(tick_start); INIT_API(tick_end); + INIT_API(blit); #undef INIT_API } diff --git a/src/tic80.c b/src/tic80.c index 81eec0f..11c1799 100644 --- a/src/tic80.c +++ b/src/tic80.c @@ -111,45 +111,6 @@ TIC80_API void tic80_load(tic80* tic, void* cart, s32 size) } } -static u32* srcPaletteBlit(const u8* src) -{ - static u32 pal[TIC_PALETTE_SIZE] = { 0 }; - - memset(pal, 0xff, sizeof pal); - - u8* dst = (u8*)pal; - const u8* end = src + sizeof(tic_palette); - - enum { RGB = sizeof(tic_rgb) }; - - for (; src != end; dst++, src += RGB) - for (s32 j = 0; j < RGB; j++) - *dst++ = *(src + (RGB - 1) - j); - - return pal; -} - -static u32* paletteBlit(tic_mem* memory) -{ - return srcPaletteBlit(memory->ram.vram.palette.data); -} - -static void blit(tic80* tic) -{ - tic80_local* tic80 = (tic80_local*)tic; - - u32* screen = tic->screen; - - for (s32 r = 0, pos = 0; r < TIC80_HEIGHT; r++, screen += TIC80_WIDTH) - { - tic80->memory->api.scanline(tic80->memory, r); - const u32* pal = paletteBlit(tic80->memory); - - for (u32* ptr = screen, c = 0; c < TIC80_WIDTH; c++, ptr++) - *ptr = pal[tic_tool_peek4(tic80->memory->ram.vram.screen.data, pos++)]; - } -} - TIC80_API void tic80_tick(tic80* tic, tic80_input input) { tic80_local* tic80 = (tic80_local*)tic; @@ -160,7 +121,7 @@ TIC80_API void tic80_tick(tic80* tic, tic80_input input) tic80->memory->api.tick(tic80->memory, &tic80->tickData); tic80->memory->api.tick_end(tic80->memory); - blit(tic); + tic80->memory->api.blit(tic80->memory, tic->screen, tic80->memory->api.scanline); TickCounter++; } diff --git a/src/ticapi.h b/src/ticapi.h index 614bb06..2d113d1 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -60,6 +60,7 @@ typedef struct } tic_tick_data; typedef struct tic_mem tic_mem; +typedef void(*tic_scanline)(tic_mem* memory, s32 row); typedef struct { @@ -104,6 +105,7 @@ typedef struct void (*tick_start) (tic_mem* memory, const tic_sound* src); void (*tick_end) (tic_mem* memory); + void (*blit) (tic_mem* tic, u32* out, tic_scanline scanline); tic_script_lang (*get_script)(tic_mem* memory); } tic_api; From 935518bb46856b1a1c01f76d6cf1f1dd222e0b68 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 3 Nov 2017 19:40:02 +0300 Subject: [PATCH 07/12] no message --- src/tic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tic.c b/src/tic.c index 1c6d686..5728b22 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1689,7 +1689,7 @@ static u32* paletteBlit(tic_mem* tic) return pal; } -void api_blit(tic_mem* tic, u32* out, tic_scanline scanline) +static void api_blit(tic_mem* tic, u32* out, tic_scanline scanline) { const u32* pal = paletteBlit(tic); From 688458f9023ba0aebd4bec1da8da10d0472b2a1b Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 3 Nov 2017 20:01:01 +0300 Subject: [PATCH 08/12] no message --- src/studio.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/studio.c b/src/studio.c index f22cbd8..34bc411 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1879,11 +1879,42 @@ static void blitTexture() SDL_UnlockTexture(studio.texture); { - // SDL_Rect srcRect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; - // SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, &rect); + enum {Header = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; + SDL_Rect srcRect = {0, 0, TIC80_FULLWIDTH, Header}; + SDL_Rect dstRect = {0}; + SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h); + dstRect.h = rect.y; + SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, &dstRect); + } - SDL_Rect srcRect = {0, 0, TIC80_FULLWIDTH, TIC80_FULLHEIGHT}; - SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, NULL); + { + enum {Header = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; + SDL_Rect srcRect = {0, TIC80_FULLHEIGHT - Header, TIC80_FULLWIDTH, Header}; + SDL_Rect dstRect = {0}; + SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h); + dstRect.y = rect.y + rect.h; + dstRect.h = rect.y; + SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, &dstRect); + } + + { + enum {Header = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; + enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2}; + SDL_Rect srcRect = {0, Header, Left, TIC80_HEIGHT}; + SDL_Rect dstRect = {0}; + SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h); + dstRect.y = rect.y; + dstRect.h = rect.h; + SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, &dstRect); + } + + { + enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; + enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2}; + + SDL_Rect srcRect = {Left, Top, TIC80_WIDTH, TIC80_HEIGHT}; + + SDL_RenderCopy(studio.renderer, studio.texture, &srcRect, &rect); } } From 021fcafcd1e1d83cba32edd0a7e895bd88cb1eb2 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 6 Nov 2017 10:35:50 +0300 Subject: [PATCH 09/12] no message --- src/studio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/studio.c b/src/studio.c index 34bc411..dd01c24 100644 --- a/src/studio.c +++ b/src/studio.c @@ -955,7 +955,9 @@ static void calcTextureRect(SDL_Rect* rect) rect->x = (rect->w - discreteWidth) / 2; - rect->y = rect->w > rect->h ? (rect->h - discreteHeight) / 2 : 0; + rect->y = rect->w > rect->h + ? (rect->h - discreteHeight) / 2 + : (TIC80_FULLWIDTH-TIC80_WIDTH)/2*discreteWidth/TIC80_WIDTH; rect->w = discreteWidth; rect->h = discreteHeight; From 1a9ec1b8541bdd86b7c33eae09b3c0fcb059a898 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 6 Nov 2017 10:57:40 +0300 Subject: [PATCH 10/12] fixed gif record --- src/studio.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/studio.c b/src/studio.c index dd01c24..4a80a37 100644 --- a/src/studio.c +++ b/src/studio.c @@ -52,7 +52,7 @@ #define MAX_CONTROLLERS 4 #define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888 -#define FRAME_SIZE (TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)) +#define FRAME_SIZE (TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)) typedef struct { @@ -1403,11 +1403,11 @@ static u32* paletteBlit() static void screen2buffer(u32* buffer, const u8* pixels, s32 pitch) { - for(s32 i = 0; i < TIC80_HEIGHT; i++) + for(s32 i = 0; i < TIC80_FULLHEIGHT; i++) { - SDL_memcpy(buffer, pixels, TIC80_WIDTH * sizeof(u32)); + SDL_memcpy(buffer, pixels, TIC80_FULLWIDTH * sizeof(u32)); pixels += pitch; - buffer += TIC80_WIDTH; + buffer += TIC80_FULLWIDTH; } } @@ -1420,7 +1420,6 @@ static void setCoverImage() if(pixels) { - // TODO: blit without border // blit(pixels); u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)); @@ -1458,7 +1457,7 @@ static void stopVideoRecord() s32 size = 0; u8* data = SDL_malloc(FRAME_SIZE * studio.video.frame); - gif_write_animation(data, &size, TIC80_WIDTH, TIC80_HEIGHT, (const u8*)studio.video.buffer, studio.video.frame, TIC_FRAMERATE, getConfig()->gifScale); + gif_write_animation(data, &size, TIC80_FULLWIDTH, TIC80_FULLHEIGHT, (const u8*)studio.video.buffer, studio.video.frame, TIC_FRAMERATE, getConfig()->gifScale); fsGetFileData(onVideoExported, "screen.gif", data, size, DEFAULT_CHMOD, NULL); } @@ -1829,11 +1828,11 @@ static void recordFrame(u8* pixels, s32 pitch) { if(studio.video.frame < studio.video.frames) { - screen2buffer(studio.video.buffer + (TIC80_WIDTH*TIC80_HEIGHT) * studio.video.frame, pixels, pitch); + screen2buffer(studio.video.buffer + (TIC80_FULLWIDTH*TIC80_FULLHEIGHT) * studio.video.frame, pixels, pitch); if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) { - const u32* pal = srcPaletteBlit(studio.tic->config.palette.data); + const u32* pal = srcPaletteBlit(studio.tic->ram.vram.palette.data); drawRecordLabel(pixels, pitch, TIC80_WIDTH-24, 8, &pal[tic_color_red]); } From 6a86f0dd8f15ca5f0a8876ef9dbe3faa561dc333 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 6 Nov 2017 12:01:35 +0300 Subject: [PATCH 11/12] fixed gif recording and cover assigning --- src/studio.c | 61 ++++++++++++++++++++++++++++------------------------ src/tic.c | 2 +- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/studio.c b/src/studio.c index 4a80a37..a9df867 100644 --- a/src/studio.c +++ b/src/studio.c @@ -54,6 +54,9 @@ #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 { u8 data[16]; @@ -957,7 +960,7 @@ static void calcTextureRect(SDL_Rect* rect) rect->y = rect->w > rect->h ? (rect->h - discreteHeight) / 2 - : (TIC80_FULLWIDTH-TIC80_WIDTH)/2*discreteWidth/TIC80_WIDTH; + : OFFSET_LEFT*discreteWidth/TIC80_WIDTH; rect->w = discreteWidth; rect->h = discreteHeight; @@ -1401,32 +1404,38 @@ static u32* paletteBlit() 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)); - pixels += pitch; - buffer += TIC80_FULLWIDTH; + SDL_memcpy(buffer, pixels + rect.x, rect.w * sizeof(pixels[0])); + pixels += TIC80_FULLWIDTH; + buffer += rect.w; } } static void setCoverImage() { + tic_mem* tic = studio.tic; + if(studio.mode == TIC_RUN_MODE) { - enum {Pitch = TIC80_WIDTH*sizeof(u32)}; - u32* pixels = SDL_malloc(Pitch * TIC80_HEIGHT); + enum {Pitch = TIC80_FULLWIDTH*sizeof(u32)}; + u32* pixels = SDL_malloc(Pitch * TIC80_FULLHEIGHT); if(pixels) { - // blit(pixels); + tic->api.blit(tic, pixels, tic->api.scanline); u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)); 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, 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); } -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[] = { @@ -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++) { 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.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) { - const u32* pal = srcPaletteBlit(studio.tic->ram.vram.palette.data); - drawRecordLabel(pixels, pitch, TIC80_WIDTH-24, 8, &pal[tic_color_red]); + const u32* pal = srcPaletteBlit(studio.tic->config.palette.data); + drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]); } studio.video.frame++; @@ -1875,12 +1885,12 @@ static void blitTexture() tic->api.blit(tic, pixels, scanline); - recordFrame(pixels, pitch); + recordFrame(pixels); 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 dstRect = {0}; 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 dstRect = {0}; SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h); @@ -1899,8 +1909,8 @@ static void blitTexture() } { - enum {Header = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; - enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2}; + enum {Header = OFFSET_TOP}; + enum {Left = OFFSET_LEFT}; SDL_Rect srcRect = {0, Header, Left, TIC80_HEIGHT}; SDL_Rect dstRect = {0}; SDL_GetWindowSize(studio.window, &dstRect.w, &dstRect.h); @@ -1910,8 +1920,8 @@ static void blitTexture() } { - enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; - enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2}; + enum {Top = OFFSET_TOP}; + enum {Left = OFFSET_LEFT}; SDL_Rect srcRect = {Left, Top, TIC80_WIDTH, TIC80_HEIGHT}; @@ -2160,11 +2170,6 @@ static void tick() SDL_SystemCursor cursor = studio.mouse.system; 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); renderStudio(); diff --git a/src/tic.c b/src/tic.c index 5728b22..53c1889 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1640,7 +1640,7 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) return (s32)(buffer - start); } -// copy from SDL2 +// copied from SDL2 inline void memset4(void *dst, u32 val, u32 dwords) { #if defined(__GNUC__) && defined(i386) From e7bfcebfbebd0d5d6b83027285e80674c51e243f Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 6 Nov 2017 12:41:23 +0300 Subject: [PATCH 12/12] no message --- src/studio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/studio.c b/src/studio.c index a9df867..6007f9e 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1793,6 +1793,7 @@ static void blitSound() { s32 samples = studio.audioSpec.freq / TIC_FRAMERATE; + // TODO: use SDL_ConvertAudio to covert format if(studio.audioSpec.format == AUDIO_F32) { if(!studio.floatSamples) @@ -2395,7 +2396,6 @@ s32 main(s32 argc, char **argv) createFileSystem(onFSInitialized); - if(studio.softwareRenderer) { u64 nextTick = SDL_GetPerformanceCounter(); const u64 Delta = SDL_GetPerformanceFrequency() / TIC_FRAMERATE; @@ -2412,8 +2412,6 @@ s32 main(s32 argc, char **argv) else nextTick -= delay; } } - // TODO: check if window minimised - else while(!studio.quitFlag) tick(); #endif