From f5784283816735e2143c5799177914f55f9590c9 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 30 Nov 2017 12:21:34 +0300 Subject: [PATCH 01/13] no message --- src/jsapi.c | 5 +++++ src/luaapi.c | 7 ++++++- src/machine.h | 8 +++++--- src/studio.c | 6 ++++-- src/tic.c | 18 +++++++++++++++++- src/tic80.c | 2 +- src/ticapi.h | 4 +++- 7 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/jsapi.c b/src/jsapi.c index 768c4dc..879689c 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -828,3 +828,8 @@ void callJavascriptScanline(tic_mem* memory, s32 row) } else duk_pop(duk); } + +void callJavascriptOverlap(tic_mem* memory) +{ + +} \ No newline at end of file diff --git a/src/luaapi.c b/src/luaapi.c index 2dd9168..eb7f77a 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -1245,4 +1245,9 @@ void callLuaScanline(tic_mem* memory, s32 row) } else lua_pop(lua, 1); } -} \ No newline at end of file +} + +void callLuaOverlap(tic_mem* memory) +{ + +} diff --git a/src/machine.h b/src/machine.h index 39d7f4f..bf08dc3 100644 --- a/src/machine.h +++ b/src/machine.h @@ -46,8 +46,6 @@ typedef struct s32 duration; } Channel; -typedef void(ScanlineFunc)(tic_mem* memory, s32 row); - typedef struct { s32 l; @@ -84,7 +82,8 @@ typedef struct Channel channels[TIC_SOUND_CHANNELS]; } music; - ScanlineFunc* scanline; + tic_scanline scanline; + tic_overlap overlap; bool initialized; } MachineState; @@ -134,3 +133,6 @@ void callJavascriptTick(tic_machine* machine); void callLuaScanline(tic_mem* memory, s32 row); void callJavascriptScanline(tic_mem* memory, s32 row); + +void callLuaOverlap(tic_mem* memory); +void callJavascriptOverlap(tic_mem* memory); diff --git a/src/studio.c b/src/studio.c index 456e410..6c41ce3 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1452,7 +1452,7 @@ static void setCoverImage() if(pixels) { - tic->api.blit(tic, pixels, tic->api.scanline); + tic->api.blit(tic, pixels, tic->api.scanline, tic->api.overlap); u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)); @@ -1932,11 +1932,13 @@ static void blitTexture() SDL_LockTexture(studio.texture, NULL, &pixels, &pitch); tic_scanline scanline = NULL; + tic_overlap overlap = NULL; switch(studio.mode) { case TIC_RUN_MODE: scanline = tic->api.scanline; + overlap = tic->api.overlap; break; case TIC_SPRITE_MODE: scanline = studio.sprite.scanline; @@ -1948,7 +1950,7 @@ static void blitTexture() break; } - tic->api.blit(tic, pixels, scanline); + tic->api.blit(tic, pixels, scanline, overlap); recordFrame(pixels); diff --git a/src/tic.c b/src/tic.c index c66f29d..d57afca 100644 --- a/src/tic.c +++ b/src/tic.c @@ -430,6 +430,7 @@ static void api_reset(tic_mem* memory) tic_machine* machine = (tic_machine*)memory; machine->state.initialized = false; machine->state.scanline = NULL; + machine->state.overlap = NULL; updateSaveid(memory); } @@ -1428,6 +1429,7 @@ static void api_tick(tic_mem* memory, tic_tick_data* data) if(done) { machine->state.scanline = memory->script == tic_script_js ? callJavascriptScanline : callLuaScanline; + machine->state.overlap = memory->script == tic_script_js ? callJavascriptOverlap : callLuaOverlap; machine->state.initialized = true; } else return; @@ -1447,6 +1449,14 @@ static void api_scanline(tic_mem* memory, s32 row) machine->state.scanline(memory, row); } +static void api_overlap(tic_mem* memory) +{ + tic_machine* machine = (tic_machine*)memory; + + if(machine->state.initialized) + machine->state.overlap(memory); +} + static double api_time(tic_mem* memory) { tic_machine* machine = (tic_machine*)memory; @@ -1645,7 +1655,7 @@ static u32* paletteBlit(tic_mem* tic) return pal; } -static void api_blit(tic_mem* tic, u32* out, tic_scanline scanline) +static void api_blit(tic_mem* tic, u32* out, tic_scanline scanline, tic_overlap overlap) { const u32* pal = paletteBlit(tic); @@ -1721,6 +1731,11 @@ static void api_blit(tic_mem* tic, u32* out, tic_scanline scanline) } memset4(&out[(TIC80_FULLHEIGHT-Bottom) * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], TIC80_FULLWIDTH*Bottom); + + if(overlap) + { + overlap(tic); + } } static void initApi(tic_api* api) @@ -1757,6 +1772,7 @@ static void initApi(tic_api* api) INIT_API(time); INIT_API(tick); INIT_API(scanline); + INIT_API(overlap); INIT_API(reset); INIT_API(pause); INIT_API(resume); diff --git a/src/tic80.c b/src/tic80.c index 11c1799..2f0fde1 100644 --- a/src/tic80.c +++ b/src/tic80.c @@ -121,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); - tic80->memory->api.blit(tic80->memory, tic->screen, tic80->memory->api.scanline); + tic80->memory->api.blit(tic80->memory, tic->screen, tic80->memory->api.scanline, tic80->memory->api.overlap); TickCounter++; } diff --git a/src/ticapi.h b/src/ticapi.h index 674885c..1e98282 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -63,6 +63,7 @@ typedef struct typedef struct tic_mem tic_mem; typedef void(*tic_scanline)(tic_mem* memory, s32 row); +typedef void(*tic_overlap)(tic_mem* memory); typedef struct { @@ -96,6 +97,7 @@ typedef struct double (*time) (tic_mem* memory); void (*tick) (tic_mem* memory, tic_tick_data* data); void (*scanline) (tic_mem* memory, s32 row); + void (*overlap) (tic_mem* memory); void (*reset) (tic_mem* memory); void (*pause) (tic_mem* memory); void (*resume) (tic_mem* memory); @@ -107,7 +109,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); + void (*blit) (tic_mem* tic, u32* out, tic_scanline scanline, tic_overlap overlap); tic_script_lang (*get_script)(tic_mem* memory); } tic_api; From e3ad17f609669a1f0fc64c96850303ba187bab04 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 30 Nov 2017 13:10:20 +0300 Subject: [PATCH 02/13] no message --- examples/sdl-renderer.c | 2 +- include/tic80/tic80.h | 2 +- src/machine.h | 4 ++++ src/studio.c | 31 +++++++++++++------------------ src/tic.c | 24 +++++++++++++++++++++--- src/tic80.c | 4 +++- src/ticapi.h | 4 +++- 7 files changed, 46 insertions(+), 25 deletions(-) diff --git a/examples/sdl-renderer.c b/examples/sdl-renderer.c index 27a4950..410991b 100644 --- a/examples/sdl-renderer.c +++ b/examples/sdl-renderer.c @@ -142,7 +142,7 @@ int main(int argc, char **argv) void* pixels = NULL; int pitch = 0; SDL_LockTexture(texture, NULL, &pixels, &pitch); - SDL_memcpy(pixels, tic->screen, sizeof tic->screen); + SDL_memcpy(pixels, tic->screen, TIC80_FULLWIDTH * TIC80_FULLHEIGHT); SDL_UnlockTexture(texture); SDL_RenderCopy(renderer, texture, NULL, NULL); } diff --git a/include/tic80/tic80.h b/include/tic80/tic80.h index 8b70994..1f4be68 100644 --- a/include/tic80/tic80.h +++ b/include/tic80/tic80.h @@ -49,7 +49,7 @@ typedef struct s32 count; } sound; - u32 screen[TIC80_FULLWIDTH * TIC80_FULLHEIGHT]; + u32* screen; } tic80; diff --git a/src/machine.h b/src/machine.h index bf08dc3..3440f6d 100644 --- a/src/machine.h +++ b/src/machine.h @@ -83,7 +83,11 @@ typedef struct } music; tic_scanline scanline; + tic_overlap overlap; + void (*pixel)(tic_mem* memory, s32 x, s32 y, u8 color); + u32 overlapPalette[TIC_PALETTE_SIZE]; + bool initialized; } MachineState; diff --git a/src/studio.c b/src/studio.c index 6c41ce3..2fcab52 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1448,29 +1448,23 @@ static void setCoverImage() if(studio.mode == TIC_RUN_MODE) { enum {Pitch = TIC80_FULLWIDTH*sizeof(u32)}; - u32* pixels = SDL_malloc(Pitch * TIC80_FULLHEIGHT); - if(pixels) + tic->api.blit(tic, tic->api.scanline, tic->api.overlap); + + u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)); + + if(buffer) { - tic->api.blit(tic, pixels, tic->api.scanline, tic->api.overlap); + SDL_Rect rect = {OFFSET_LEFT, OFFSET_TOP, TIC80_WIDTH, TIC80_HEIGHT}; - u32* buffer = SDL_malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)); + screen2buffer(buffer, tic->screen, rect); - if(buffer) - { - SDL_Rect rect = {OFFSET_LEFT, OFFSET_TOP, TIC80_WIDTH, TIC80_HEIGHT}; + gif_write_animation(studio.tic->cart.cover.data, &studio.tic->cart.cover.size, + TIC80_WIDTH, TIC80_HEIGHT, (const u8*)buffer, 1, TIC_FRAMERATE, 1); - screen2buffer(buffer, pixels, rect); + SDL_free(buffer); - gif_write_animation(studio.tic->cart.cover.data, &studio.tic->cart.cover.size, - TIC80_WIDTH, TIC80_HEIGHT, (const u8*)buffer, 1, TIC_FRAMERATE, 1); - - SDL_free(buffer); - - showPopupMessage("COVER IMAGE SAVED :)"); - } - - SDL_free(pixels); + showPopupMessage("COVER IMAGE SAVED :)"); } } } @@ -1950,7 +1944,8 @@ static void blitTexture() break; } - tic->api.blit(tic, pixels, scanline, overlap); + tic->api.blit(tic, scanline, overlap); + SDL_memcpy(pixels, tic->screen, sizeof tic->screen); recordFrame(pixels); diff --git a/src/tic.c b/src/tic.c index d57afca..5804346 100644 --- a/src/tic.c +++ b/src/tic.c @@ -149,11 +149,26 @@ static void resetPalette(tic_mem* memory) memory->ram.vram.vars.mask.data = TIC_GAMEPAD_MASK; } -static inline void setPixel(tic_machine* machine, s32 x, s32 y, u8 color) +static void dmaPixel(tic_mem* tic, s32 x, s32 y, u8 color) +{ + tic_tool_poke4(tic->ram.vram.screen.data, y * TIC80_WIDTH + x, tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)); +} + +static void overlapPixel(tic_mem* tic, s32 x, s32 y, u8 color) +{ + tic_machine* machine = (tic_machine*)tic; + + enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2, Bottom = Top}; + enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2, Right = Left}; + + tic->screen[x + Left + (y + Top) * TIC80_FULLWIDTH] = machine->state.overlapPalette[tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)]; +} + +static void setPixel(tic_machine* machine, s32 x, s32 y, u8 color) { if(x < machine->state.clip.l || y < machine->state.clip.t || x >= machine->state.clip.r || y >= machine->state.clip.b) return; - tic_tool_poke4(machine->memory.ram.vram.screen.data, y * TIC80_WIDTH + x, tic_tool_peek4(machine->memory.ram.vram.mapping, color & 0xf)); + machine->state.pixel(&machine->memory, x, y, color); } static u8 getPixel(tic_machine* machine, s32 x, s32 y) @@ -432,6 +447,8 @@ static void api_reset(tic_mem* memory) machine->state.scanline = NULL; machine->state.overlap = NULL; + machine->state.pixel = dmaPixel; + updateSaveid(memory); } @@ -1655,8 +1672,9 @@ static u32* paletteBlit(tic_mem* tic) return pal; } -static void api_blit(tic_mem* tic, u32* out, tic_scanline scanline, tic_overlap overlap) +static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap) { + u32* out = tic->screen; const u32* pal = paletteBlit(tic); if(scanline) diff --git a/src/tic80.c b/src/tic80.c index 2f0fde1..d340b6a 100644 --- a/src/tic80.c +++ b/src/tic80.c @@ -93,6 +93,8 @@ TIC80_API void tic80_load(tic80* tic, void* cart, s32 size) tic80->tic.sound.count = tic80->memory->samples.size/sizeof(s16); tic80->tic.sound.samples = tic80->memory->samples.buffer; + tic80->tic.screen = tic80->memory->screen; + { tic80->tickData.error = onError; tic80->tickData.trace = onTrace; @@ -121,7 +123,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); - tic80->memory->api.blit(tic80->memory, tic->screen, tic80->memory->api.scanline, tic80->memory->api.overlap); + tic80->memory->api.blit(tic80->memory, tic80->memory->api.scanline, tic80->memory->api.overlap); TickCounter++; } diff --git a/src/ticapi.h b/src/ticapi.h index 1e98282..2159339 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -109,7 +109,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_overlap overlap); + void (*blit) (tic_mem* tic, tic_scanline scanline, tic_overlap overlap); tic_script_lang (*get_script)(tic_mem* memory); } tic_api; @@ -131,6 +131,8 @@ struct tic_mem s16* buffer; s32 size; } samples; + + u32 screen[TIC80_FULLWIDTH * TIC80_FULLHEIGHT]; }; tic_mem* tic_create(s32 samplerate); From c69d36abb722a214df864e09c25925e33e73d9b0 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 30 Nov 2017 14:21:05 +0300 Subject: [PATCH 03/13] OVR works --- src/luaapi.c | 17 ++++++++++++++++- src/tic.c | 30 +++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/luaapi.c b/src/luaapi.c index eb7f77a..42a3644 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -1249,5 +1249,20 @@ void callLuaScanline(tic_mem* memory, s32 row) void callLuaOverlap(tic_mem* memory) { - + tic_machine* machine = (tic_machine*)memory; + lua_State* lua = machine->lua; + + if (lua) + { + static const char* OverlapFunc = "overlap"; + + lua_getglobal(lua, OverlapFunc); + if(lua_isfunction(lua, -1)) + { + if(lua_pcall(lua, 0, 0, 0) != LUA_OK) + machine->data->error(machine->data->data, lua_tostring(lua, -1)); + } + else lua_pop(lua, 1); + } + } diff --git a/src/tic.c b/src/tic.c index 5804346..3d1f291 100644 --- a/src/tic.c +++ b/src/tic.c @@ -158,10 +158,10 @@ static void overlapPixel(tic_mem* tic, s32 x, s32 y, u8 color) { tic_machine* machine = (tic_machine*)tic; - enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2, Bottom = Top}; - enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2, Right = Left}; + enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; + enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2}; - tic->screen[x + Left + (y + Top) * TIC80_FULLWIDTH] = machine->state.overlapPalette[tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)]; + tic->screen[x + y * TIC80_FULLWIDTH + (Left + Top * TIC80_FULLWIDTH)] = machine->state.overlapPalette[tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)]; } static void setPixel(tic_machine* machine, s32 x, s32 y, u8 color) @@ -1181,6 +1181,8 @@ static void api_tick_start(tic_mem* memory, const tic_sound* src) if(prevDown && prevDown == down) (*hold)++; else *hold = 0; } + + machine->state.pixel = dmaPixel; } static void api_tick_end(tic_mem* memory) @@ -1204,6 +1206,26 @@ static void api_tick_end(tic_mem* memory) blip_end_frame(machine->blip, EndTime); blip_read_samples(machine->blip, machine->memory.samples.buffer, machine->samplerate / TIC_FRAMERATE); + + machine->state.pixel = overlapPixel; + + // temporary palette blit + { + u32* pal = machine->state.overlapPalette; + + const u8* src = memory->cart.palette.data; + + memset(pal, 0xff, TIC_PALETTE_SIZE); + + 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); + } } @@ -1751,9 +1773,7 @@ static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap) memset4(&out[(TIC80_FULLHEIGHT-Bottom) * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], TIC80_FULLWIDTH*Bottom); if(overlap) - { overlap(tic); - } } static void initApi(tic_api* api) From a2e97b018a945db065fad408340fe022c517a567 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 30 Nov 2017 15:51:52 +0300 Subject: [PATCH 04/13] no message --- src/jsapi.c | 17 ++++++++++++++- src/luaapi.c | 6 +++--- src/machine.h | 8 +++++-- src/studio.c | 31 ++++----------------------- src/tic.c | 59 ++++++++++----------------------------------------- src/tic.h | 2 +- src/tools.c | 20 +++++++++++++++++ src/tools.h | 3 ++- 8 files changed, 63 insertions(+), 83 deletions(-) diff --git a/src/jsapi.c b/src/jsapi.c index 879689c..2da9612 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -715,6 +715,7 @@ static const struct{duk_c_function func; s32 params;} ApiFunc[] = { {NULL, 0}, {NULL, 1}, + {NULL, 0}, {duk_print, 6}, {duk_cls, 1}, {duk_pix, 3}, @@ -831,5 +832,19 @@ void callJavascriptScanline(tic_mem* memory, s32 row) void callJavascriptOverlap(tic_mem* memory) { - + tic_machine* machine = (tic_machine*)memory; + duk_context* duk = machine->js; + + const char* OvrFunc = ApiKeywords[2]; + + if(duk_get_global_string(duk, OvrFunc)) + { + if(duk_pcall(duk, 0) != 0) + { + machine->data->error(machine->data->data, duk_safe_to_string(duk, -1)); + duk_pop(duk); + } + else duk_pop(duk); + } + else duk_pop(duk); } \ No newline at end of file diff --git a/src/luaapi.c b/src/luaapi.c index 42a3644..b8931b5 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -1052,7 +1052,7 @@ static void setloaded(lua_State* l, char* name) static const char* const ApiKeywords[] = API_KEYWORDS; static const lua_CFunction ApiFunc[] = { - NULL, NULL, lua_print, lua_cls, lua_pix, lua_line, lua_rect, + NULL, NULL, NULL, lua_print, lua_cls, lua_pix, lua_line, lua_rect, lua_rectb, lua_spr, lua_btn, lua_btnp, lua_sfx, lua_map, lua_mget, lua_mset, lua_peek, lua_poke, lua_peek4, lua_poke4, lua_memcpy, lua_memset, lua_trace, lua_pmem, lua_time, lua_exit, lua_font, lua_mouse, @@ -1254,9 +1254,9 @@ void callLuaOverlap(tic_mem* memory) if (lua) { - static const char* OverlapFunc = "overlap"; + const char* OvrFunc = ApiKeywords[2]; - lua_getglobal(lua, OverlapFunc); + lua_getglobal(lua, OvrFunc); if(lua_isfunction(lua, -1)) { if(lua_pcall(lua, 0, 0, 0) != LUA_OK) diff --git a/src/machine.h b/src/machine.h index 3440f6d..060889c 100644 --- a/src/machine.h +++ b/src/machine.h @@ -84,9 +84,13 @@ typedef struct tic_scanline scanline; - tic_overlap overlap; + struct + { + tic_overlap callback; + u32 palette[TIC_PALETTE_SIZE]; + } ovr; + void (*pixel)(tic_mem* memory, s32 x, s32 y, u8 color); - u32 overlapPalette[TIC_PALETTE_SIZE]; bool initialized; } MachineState; diff --git a/src/studio.c b/src/studio.c index 2fcab52..a0d36ed 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1406,29 +1406,6 @@ static void saveProject() else showPopupMessage("SAVE ERROR :("); } -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() -{ - return srcPaletteBlit(studio.tic->ram.vram.palette.data); -} - static void screen2buffer(u32* buffer, const u32* pixels, SDL_Rect rect) { pixels += rect.y * TIC80_FULLWIDTH; @@ -1824,7 +1801,7 @@ static void transparentBlit(u32* out, s32 pitch) { const u8* in = studio.tic->ram.vram.screen.data; const u8* end = in + sizeof(studio.tic->ram.vram.screen); - const u32* pal = srcPaletteBlit(studio.tic->config.palette.data); + const u32* pal = tic_palette_blit(&studio.tic->config.palette); const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH); s32 col = 0; @@ -1901,7 +1878,7 @@ static void recordFrame(u32* pixels) if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) { - const u32* pal = srcPaletteBlit(studio.tic->config.palette.data); + const u32* pal = tic_palette_blit(&studio.tic->config.palette); drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]); } @@ -2009,7 +1986,7 @@ static void blitCursor(const u8* in) { const u8* end = in + sizeof(tic_tile); - const u32* pal = paletteBlit(); + const u32* pal = tic_palette_blit(&studio.tic->ram.vram.palette); u32* out = pixels; while(in != end) @@ -2321,7 +2298,7 @@ static void setWindowIcon() u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); - const u32* pal = srcPaletteBlit(studio.tic->config.palette.data); + const u32* pal = tic_palette_blit(&studio.tic->config.palette); for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) diff --git a/src/tic.c b/src/tic.c index 3d1f291..766a463 100644 --- a/src/tic.c +++ b/src/tic.c @@ -154,14 +154,14 @@ static void dmaPixel(tic_mem* tic, s32 x, s32 y, u8 color) tic_tool_poke4(tic->ram.vram.screen.data, y * TIC80_WIDTH + x, tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)); } -static void overlapPixel(tic_mem* tic, s32 x, s32 y, u8 color) +static void ovrPixel(tic_mem* tic, s32 x, s32 y, u8 color) { tic_machine* machine = (tic_machine*)tic; enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2}; - tic->screen[x + y * TIC80_FULLWIDTH + (Left + Top * TIC80_FULLWIDTH)] = machine->state.overlapPalette[tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)]; + tic->screen[x + y * TIC80_FULLWIDTH + (Left + Top * TIC80_FULLWIDTH)] = machine->state.ovr.palette[tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)]; } static void setPixel(tic_machine* machine, s32 x, s32 y, u8 color) @@ -445,7 +445,7 @@ static void api_reset(tic_mem* memory) tic_machine* machine = (tic_machine*)memory; machine->state.initialized = false; machine->state.scanline = NULL; - machine->state.overlap = NULL; + machine->state.ovr.callback = NULL; machine->state.pixel = dmaPixel; @@ -1207,25 +1207,8 @@ static void api_tick_end(tic_mem* memory) blip_end_frame(machine->blip, EndTime); blip_read_samples(machine->blip, machine->memory.samples.buffer, machine->samplerate / TIC_FRAMERATE); - machine->state.pixel = overlapPixel; - - // temporary palette blit - { - u32* pal = machine->state.overlapPalette; - - const u8* src = memory->cart.palette.data; - - memset(pal, 0xff, TIC_PALETTE_SIZE); - - 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); - } + machine->state.pixel = ovrPixel; + memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palette), sizeof machine->state.ovr.palette); } @@ -1468,7 +1451,7 @@ static void api_tick(tic_mem* memory, tic_tick_data* data) if(done) { machine->state.scanline = memory->script == tic_script_js ? callJavascriptScanline : callLuaScanline; - machine->state.overlap = memory->script == tic_script_js ? callJavascriptOverlap : callLuaOverlap; + machine->state.ovr.callback = memory->script == tic_script_js ? callJavascriptOverlap : callLuaOverlap; machine->state.initialized = true; } else return; @@ -1493,7 +1476,7 @@ static void api_overlap(tic_mem* memory) tic_machine* machine = (tic_machine*)memory; if(machine->state.initialized) - machine->state.overlap(memory); + machine->state.ovr.callback(memory); } static double api_time(tic_mem* memory) @@ -1507,7 +1490,7 @@ static void api_sync(tic_mem* tic, bool toCart) if(toCart) { memcpy(&tic->cart.gfx, &tic->ram.gfx, sizeof tic->cart.gfx); - memcpy(&tic->cart.sound, &tic->ram.sound, sizeof tic->cart.sound); + memcpy(&tic->cart.sound, &tic->ram.sound, sizeof tic->cart.sound); } else { @@ -1674,35 +1657,15 @@ static inline void memset4(void *dst, u32 val, u32 dwords) #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; -} - static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap) { u32* out = tic->screen; - const u32* pal = paletteBlit(tic); + const u32* pal = tic_palette_blit(&tic->ram.vram.palette); if(scanline) { scanline(tic, 0); - pal = paletteBlit(tic); + pal = tic_palette_blit(&tic->ram.vram.palette); } enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2, Bottom = Top}; @@ -1766,7 +1729,7 @@ static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap) if(scanline && (r < TIC80_HEIGHT-1)) { scanline(tic, r+1); - pal = paletteBlit(tic); + pal = tic_palette_blit(&tic->ram.vram.palette); } } diff --git a/src/tic.h b/src/tic.h index 2596905..c68cb35 100644 --- a/src/tic.h +++ b/src/tic.h @@ -109,7 +109,7 @@ #define SFX_NOTES {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"} -#define API_KEYWORDS {"TIC", "scanline", "print", "cls", "pix", "line", "rect", "rectb", \ +#define API_KEYWORDS {"TIC", "scanline", "OVR", "print", "cls", "pix", "line", "rect", "rectb", \ "spr", "btn", "btnp", "sfx", "map", "mget", "mset", "peek", "poke", "peek4", "poke4", \ "memcpy", "memset", "trace", "pmem", "time", "exit", "font", "mouse", "circ", "circb", "tri", "textri", \ "clip", "music", "sync"} diff --git a/src/tools.c b/src/tools.c index b4dab40..807f530 100644 --- a/src/tools.c +++ b/src/tools.c @@ -85,3 +85,23 @@ u32 tic_tool_find_closest_color(const tic_rgb* palette, const tic_rgb* color) return closetColor; } + +u32* tic_palette_blit(const tic_palette* srcpal) +{ + static u32 pal[TIC_PALETTE_SIZE] = {0}; + + const u8* src = srcpal->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; +} \ No newline at end of file diff --git a/src/tools.h b/src/tools.h index 50e5361..c18b037 100644 --- a/src/tools.h +++ b/src/tools.h @@ -50,4 +50,5 @@ inline u8 tic_tool_peek4(const void* addr, u32 index) bool tic_tool_parse_note(const char* noteStr, s32* note, s32* octave); s32 tic_tool_get_pattern_id(const tic_track* track, s32 frame, s32 channel); void tic_tool_set_pattern_id(tic_track* track, s32 frame, s32 channel, s32 id); -u32 tic_tool_find_closest_color(const tic_rgb* palette, const tic_rgb* color); \ No newline at end of file +u32 tic_tool_find_closest_color(const tic_rgb* palette, const tic_rgb* color); +u32* tic_palette_blit(const tic_palette* src); \ No newline at end of file From 68a89c742142ab9ab5bfc0b4142ed3fba1eedae3 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 30 Nov 2017 16:23:37 +0300 Subject: [PATCH 05/13] added OVR palette --- src/console.c | 20 ++++++++++++-------- src/machine.h | 2 +- src/map.c | 2 +- src/sprite.c | 10 +++++----- src/studio.c | 8 ++++---- src/surf.c | 2 +- src/tic.c | 24 +++++++++++++++--------- src/tic.h | 7 ++++++- 8 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/console.c b/src/console.c index 5c6f74c..d55d8ce 100644 --- a/src/console.c +++ b/src/console.c @@ -291,7 +291,7 @@ static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s if(palette) { - const tic_rgb* pal = tic->cart.palette.colors; + const tic_rgb* pal = tic->cart.palettes.bg.colors; for(s32 i = 0; i < TIC_PALETTE_SIZE; i++, pal++) palette[i].r = pal->r, palette[i].g = pal->g, palette[i].b = pal->b; @@ -308,7 +308,10 @@ static void loadCart(tic_mem* tic, tic_cartridge* cart, const u8* buffer, s32 si tic->api.load(cart, buffer, size, palette); if(!palette) - memcpy(cart->palette.data, tic->config.palette.data, sizeof(tic_palette)); + { + memcpy(cart->palettes.bg.data, tic->config.palettes.bg.data, sizeof(tic_palette)); + memcpy(cart->palettes.ovr.data, tic->config.palettes.ovr.data, sizeof(tic_palette)); + } } static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette) @@ -367,7 +370,7 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) case 3: memcpy(&tic->cart.code, &cart->code, sizeof cart->code); break; case 4: memcpy(&tic->cart.sound.sfx, &cart->sound.sfx, sizeof cart->sound.sfx); break; case 5: memcpy(&tic->cart.sound.music, &cart->sound.music, sizeof cart->sound.music); break; - case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof cart->palette); break; + case 6: memcpy(&tic->cart.palettes, &cart->palettes, sizeof cart->palettes); break; } studioRomLoaded(); @@ -604,7 +607,7 @@ static char* saveBinarySection(char* ptr, const char* comment, const char* tag, typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection; static const BinarySection BinarySections[] = { - {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, + {"PALETTE", 2, offsetof(tic_cartridge, palettes), sizeof(tic_palette), false}, {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, gfx.tiles), sizeof(tic_tile), true}, {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, gfx.sprites), sizeof(tic_tile), true}, {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, gfx.map), TIC_MAP_WIDTH, true}, @@ -735,7 +738,8 @@ static bool loadProject(Console* console, const char* name, const char* data, s3 if(cart) { SDL_memset(cart, 0, sizeof(tic_cartridge)); - SDL_memcpy(&cart->palette, &tic->config.palette.data, sizeof(tic_palette)); + SDL_memcpy(&cart->palettes.bg, &tic->config.palettes.bg, sizeof cart->palettes.bg); + SDL_memcpy(&cart->palettes.ovr, &tic->config.palettes.ovr, sizeof cart->palettes.ovr); const char* comment = projectComment(name); @@ -1329,7 +1333,7 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v u8 src = image->buffer[x + y * image->width]; const gif_color* c = &image->palette[src]; tic_rgb rgb = {c->r, c->g, c->b}; - u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(console->tic->cart.palettes.bg.colors, &rgb); setSpritePixel(console->tic->cart.gfx.tiles, x, y, color); } @@ -2741,7 +2745,7 @@ static void cmdInjectSprites(Console* console, const char* param, const char* na u8 src = image->buffer[x + y * image->width]; const gif_color* c = &image->palette[src]; tic_rgb rgb = {c->r, c->g, c->b}; - u8 color = tic_tool_find_closest_color(embed.file.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(embed.file.palettes.bg.colors, &rgb); setSpritePixel(embed.file.gfx.tiles, x, y, color); } @@ -2847,7 +2851,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, if(argc > 1) { - memcpy(embed.file.palette.data, tic->config.palette.data, sizeof(tic_palette)); + memcpy(&embed.file.palettes, &tic->config.palettes, sizeof embed.file.palettes); if (argc == 2) cmdLoadCart(console, argv[1]); else if (argc == 3) diff --git a/src/machine.h b/src/machine.h index 060889c..726112e 100644 --- a/src/machine.h +++ b/src/machine.h @@ -116,7 +116,7 @@ typedef struct struct { - MachineState state; + MachineState state; tic_sound_register registers[TIC_SOUND_CHANNELS]; tic_music_pos music_pos; tic_vram vram; diff --git a/src/map.c b/src/map.c index 4c4538d..4975ea3 100644 --- a/src/map.c +++ b/src/map.c @@ -1133,7 +1133,7 @@ static void onStudioEvent(Map* map, StudioEvent event) static void scanline(tic_mem* tic, s32 row) { - memcpy(tic->ram.vram.palette.data, row < TOOLBAR_SIZE ? tic->config.palette.data : tic->cart.palette.data, sizeof(tic_palette)); + memcpy(tic->ram.vram.palette.data, row < TOOLBAR_SIZE ? tic->config.palettes.bg.data : tic->cart.palettes.bg.data, sizeof(tic_palette)); } void initMap(Map* map, tic_mem* tic) diff --git a/src/sprite.c b/src/sprite.c index fe9b7d1..1e0957e 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -639,8 +639,8 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value) static void pasteColor(Sprite* sprite) { - fromClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false); - fromClipboard(&sprite->tic->cart.palette.colors[sprite->color], sizeof(tic_rgb), false); + fromClipboard(sprite->tic->cart.palettes.bg.data, sizeof(tic_palette), false); + fromClipboard(&sprite->tic->cart.palettes.bg.colors[sprite->color], sizeof(tic_rgb), false); } static void drawRGBTools(Sprite* sprite, s32 x, s32 y) @@ -675,7 +675,7 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y) down = true; if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) - toClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false); + toClipboard(sprite->tic->cart.palettes.bg.data, sizeof(tic_palette), false); } if(down) @@ -739,7 +739,7 @@ static void drawRGBSliders(Sprite* sprite, s32 x, s32 y) { enum{Gap = 6, Count = sizeof(tic_rgb)}; - u8* data = &sprite->tic->cart.palette.data[sprite->color * Count]; + u8* data = &sprite->tic->cart.palettes.bg.data[sprite->color * Count]; for(s32 i = 0; i < Count; i++) drawRGBSlider(sprite, x, y + Gap*i, &data[i]); @@ -1482,7 +1482,7 @@ static void onStudioEvent(Sprite* sprite, StudioEvent event) static void scanline(tic_mem* tic, s32 row) { - memcpy(tic->ram.vram.palette.data, row < TOOLBAR_SIZE ? tic->config.palette.data : tic->cart.palette.data, sizeof(tic_palette)); + memcpy(tic->ram.vram.palette.data, row < TOOLBAR_SIZE ? tic->config.palettes.bg.data : tic->cart.palettes.bg.data, sizeof(tic_palette)); } void initSprite(Sprite* sprite, tic_mem* tic) diff --git a/src/studio.c b/src/studio.c index a0d36ed..51845a6 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1801,7 +1801,7 @@ static void transparentBlit(u32* out, s32 pitch) { const u8* in = studio.tic->ram.vram.screen.data; const u8* end = in + sizeof(studio.tic->ram.vram.screen); - const u32* pal = tic_palette_blit(&studio.tic->config.palette); + const u32* pal = tic_palette_blit(&studio.tic->config.palettes.bg); const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH); s32 col = 0; @@ -1878,7 +1878,7 @@ static void recordFrame(u32* pixels) if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) { - const u32* pal = tic_palette_blit(&studio.tic->config.palette); + const u32* pal = tic_palette_blit(&studio.tic->config.palettes.bg); drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]); } @@ -2041,7 +2041,7 @@ static void renderCursor() static void useSystemPalette() { - memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.palette.data, sizeof(tic_palette)); + memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.palettes.bg.data, sizeof(tic_palette)); } static void renderStudio() @@ -2298,7 +2298,7 @@ static void setWindowIcon() u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); - const u32* pal = tic_palette_blit(&studio.tic->config.palette); + const u32* pal = tic_palette_blit(&studio.tic->config.palettes.bg); for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) diff --git a/src/surf.c b/src/surf.c index 6d8ff81..100f9b1 100644 --- a/src/surf.c +++ b/src/surf.c @@ -508,7 +508,7 @@ static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size) { const gif_color* c = &image->palette[image->buffer[i]]; tic_rgb rgb = { c->r, c->g, c->b }; - u8 color = tic_tool_find_closest_color(tic->config.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(tic->config.palettes.bg.colors, &rgb); tic_tool_poke4(item->cover->data, i, color); } } diff --git a/src/tic.c b/src/tic.c index 766a463..2a5529d 100644 --- a/src/tic.c +++ b/src/tic.c @@ -53,8 +53,8 @@ typedef enum CHUNK_TEMP3, // 8 CHUNK_SOUND, // 9 CHUNK_WAVEFORM, // 10 - CHUNK_TEMP4, // 11 - CHUNK_PALETTE, // 12 + CHUNK_OVR_PAL, // 11 + CHUNK_BG_PAL, // 12 CHUNK_PATTERNS, // 13 CHUNK_MUSIC, // 14 @@ -143,7 +143,7 @@ static void runNoise(blip_buffer_t* blip, tic_sound_register* reg, tic_sound_reg static void resetPalette(tic_mem* memory) { static const u8 DefaultMapping[] = {16, 50, 84, 118, 152, 186, 220, 254}; - memcpy(memory->ram.vram.palette.data, memory->cart.palette.data, sizeof(tic_palette)); + memcpy(memory->ram.vram.palette.data, memory->cart.palettes.bg.data, sizeof(tic_palette)); memcpy(memory->ram.vram.mapping, DefaultMapping, sizeof DefaultMapping); memset(&memory->ram.vram.vars, 0, sizeof memory->ram.vram.vars); memory->ram.vram.vars.mask.data = TIC_GAMEPAD_MASK; @@ -1208,7 +1208,7 @@ static void api_tick_end(tic_mem* memory) blip_read_samples(machine->blip, machine->memory.samples.buffer, machine->samplerate / TIC_FRAMERATE); machine->state.pixel = ovrPixel; - memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palette), sizeof machine->state.ovr.palette); + memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palettes.ovr), sizeof machine->state.ovr.palette); } @@ -1265,7 +1265,7 @@ static void initCover(tic_mem* tic) { const gif_color* c = &image->palette[image->buffer[i]]; tic_rgb rgb = { c->r, c->g, c->b }; - u8 color = tic_tool_find_closest_color(tic->cart.palette.colors, &rgb); + u8 color = tic_tool_find_closest_color(tic->cart.palettes.bg.colors, &rgb); tic_tool_poke4(tic->ram.vram.screen.data, i, color); } } @@ -1529,7 +1529,8 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet if(palette) { static const u8 DB16[] = {0x14, 0x0c, 0x1c, 0x44, 0x24, 0x34, 0x30, 0x34, 0x6d, 0x4e, 0x4a, 0x4e, 0x85, 0x4c, 0x30, 0x34, 0x65, 0x24, 0xd0, 0x46, 0x48, 0x75, 0x71, 0x61, 0x59, 0x7d, 0xce, 0xd2, 0x7d, 0x2c, 0x85, 0x95, 0xa1, 0x6d, 0xaa, 0x2c, 0xd2, 0xaa, 0x99, 0x6d, 0xc2, 0xca, 0xda, 0xd4, 0x5e, 0xde, 0xee, 0xd6}; - memcpy(cart->palette.data, DB16, sizeof(tic_palette)); + memcpy(cart->palettes.bg.data, DB16, sizeof(tic_palette)); + memcpy(cart->palettes.ovr.data, DB16, sizeof(tic_palette)); } #define LOAD_CHUNK(to) memcpy(&to, buffer, min(sizeof(to), chunk.size)) @@ -1550,9 +1551,13 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet case CHUNK_WAVEFORM: LOAD_CHUNK(cart->sound.sfx.waveform); break; case CHUNK_MUSIC: LOAD_CHUNK(cart->sound.music.tracks.data); break; case CHUNK_PATTERNS: LOAD_CHUNK(cart->sound.music.patterns.data); break; - case CHUNK_PALETTE: + case CHUNK_BG_PAL: if(palette) - LOAD_CHUNK(cart->palette); + LOAD_CHUNK(cart->palettes.bg); + break; + case CHUNK_OVR_PAL: + if(palette) + LOAD_CHUNK(cart->palettes.ovr); break; case CHUNK_COVER: LOAD_CHUNK(cart->cover.data); @@ -1619,7 +1624,8 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->sound.sfx.waveform); buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->sound.music.patterns.data); buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->sound.music.tracks.data); - buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); + buffer = SAVE_CHUNK(CHUNK_BG_PAL, cart->palettes.bg); + buffer = SAVE_CHUNK(CHUNK_OVR_PAL, cart->palettes.ovr); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); diff --git a/src/tic.h b/src/tic.h index c68cb35..deda730 100644 --- a/src/tic.h +++ b/src/tic.h @@ -338,7 +338,12 @@ typedef struct tic_sound sound; tic_code code; tic_cover_image cover; - tic_palette palette; + + struct + { + tic_palette bg; + tic_palette ovr; + } palettes; } tic_cartridge; typedef struct From 983c31475d49501e2fe160be0ca3e8ee8e8ac99c Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 30 Nov 2017 16:41:37 +0300 Subject: [PATCH 06/13] no message --- src/tic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tic.c b/src/tic.c index 2a5529d..f39d5d7 100644 --- a/src/tic.c +++ b/src/tic.c @@ -161,7 +161,7 @@ static void ovrPixel(tic_mem* tic, s32 x, s32 y, u8 color) enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2}; - tic->screen[x + y * TIC80_FULLWIDTH + (Left + Top * TIC80_FULLWIDTH)] = machine->state.ovr.palette[tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)]; + tic->screen[x + y * TIC80_FULLWIDTH + (Left + Top * TIC80_FULLWIDTH)] = machine->state.ovr.palette[color & 0xf]; } static void setPixel(tic_machine* machine, s32 x, s32 y, u8 color) From b46be919d49321e965d0e65a3608514e30249fa4 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 30 Nov 2017 16:42:06 +0300 Subject: [PATCH 07/13] Revert "added OVR palette" This reverts commit 68a89c742142ab9ab5bfc0b4142ed3fba1eedae3. --- src/console.c | 20 ++++++++------------ src/machine.h | 2 +- src/map.c | 2 +- src/sprite.c | 10 +++++----- src/studio.c | 8 ++++---- src/surf.c | 2 +- src/tic.c | 24 +++++++++--------------- src/tic.h | 7 +------ 8 files changed, 30 insertions(+), 45 deletions(-) diff --git a/src/console.c b/src/console.c index d55d8ce..5c6f74c 100644 --- a/src/console.c +++ b/src/console.c @@ -291,7 +291,7 @@ static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s if(palette) { - const tic_rgb* pal = tic->cart.palettes.bg.colors; + const tic_rgb* pal = tic->cart.palette.colors; for(s32 i = 0; i < TIC_PALETTE_SIZE; i++, pal++) palette[i].r = pal->r, palette[i].g = pal->g, palette[i].b = pal->b; @@ -308,10 +308,7 @@ static void loadCart(tic_mem* tic, tic_cartridge* cart, const u8* buffer, s32 si tic->api.load(cart, buffer, size, palette); if(!palette) - { - memcpy(cart->palettes.bg.data, tic->config.palettes.bg.data, sizeof(tic_palette)); - memcpy(cart->palettes.ovr.data, tic->config.palettes.ovr.data, sizeof(tic_palette)); - } + memcpy(cart->palette.data, tic->config.palette.data, sizeof(tic_palette)); } static bool loadRom(tic_mem* tic, const void* data, s32 size, bool palette) @@ -370,7 +367,7 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param) case 3: memcpy(&tic->cart.code, &cart->code, sizeof cart->code); break; case 4: memcpy(&tic->cart.sound.sfx, &cart->sound.sfx, sizeof cart->sound.sfx); break; case 5: memcpy(&tic->cart.sound.music, &cart->sound.music, sizeof cart->sound.music); break; - case 6: memcpy(&tic->cart.palettes, &cart->palettes, sizeof cart->palettes); break; + case 6: memcpy(&tic->cart.palette, &cart->palette, sizeof cart->palette); break; } studioRomLoaded(); @@ -607,7 +604,7 @@ static char* saveBinarySection(char* ptr, const char* comment, const char* tag, typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection; static const BinarySection BinarySections[] = { - {"PALETTE", 2, offsetof(tic_cartridge, palettes), sizeof(tic_palette), false}, + {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, gfx.tiles), sizeof(tic_tile), true}, {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, gfx.sprites), sizeof(tic_tile), true}, {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, gfx.map), TIC_MAP_WIDTH, true}, @@ -738,8 +735,7 @@ static bool loadProject(Console* console, const char* name, const char* data, s3 if(cart) { SDL_memset(cart, 0, sizeof(tic_cartridge)); - SDL_memcpy(&cart->palettes.bg, &tic->config.palettes.bg, sizeof cart->palettes.bg); - SDL_memcpy(&cart->palettes.ovr, &tic->config.palettes.ovr, sizeof cart->palettes.ovr); + SDL_memcpy(&cart->palette, &tic->config.palette.data, sizeof(tic_palette)); const char* comment = projectComment(name); @@ -1333,7 +1329,7 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v u8 src = image->buffer[x + y * image->width]; const gif_color* c = &image->palette[src]; tic_rgb rgb = {c->r, c->g, c->b}; - u8 color = tic_tool_find_closest_color(console->tic->cart.palettes.bg.colors, &rgb); + u8 color = tic_tool_find_closest_color(console->tic->cart.palette.colors, &rgb); setSpritePixel(console->tic->cart.gfx.tiles, x, y, color); } @@ -2745,7 +2741,7 @@ static void cmdInjectSprites(Console* console, const char* param, const char* na u8 src = image->buffer[x + y * image->width]; const gif_color* c = &image->palette[src]; tic_rgb rgb = {c->r, c->g, c->b}; - u8 color = tic_tool_find_closest_color(embed.file.palettes.bg.colors, &rgb); + u8 color = tic_tool_find_closest_color(embed.file.palette.colors, &rgb); setSpritePixel(embed.file.gfx.tiles, x, y, color); } @@ -2851,7 +2847,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, if(argc > 1) { - memcpy(&embed.file.palettes, &tic->config.palettes, sizeof embed.file.palettes); + memcpy(embed.file.palette.data, tic->config.palette.data, sizeof(tic_palette)); if (argc == 2) cmdLoadCart(console, argv[1]); else if (argc == 3) diff --git a/src/machine.h b/src/machine.h index 726112e..060889c 100644 --- a/src/machine.h +++ b/src/machine.h @@ -116,7 +116,7 @@ typedef struct struct { - MachineState state; + MachineState state; tic_sound_register registers[TIC_SOUND_CHANNELS]; tic_music_pos music_pos; tic_vram vram; diff --git a/src/map.c b/src/map.c index 4975ea3..4c4538d 100644 --- a/src/map.c +++ b/src/map.c @@ -1133,7 +1133,7 @@ static void onStudioEvent(Map* map, StudioEvent event) static void scanline(tic_mem* tic, s32 row) { - memcpy(tic->ram.vram.palette.data, row < TOOLBAR_SIZE ? tic->config.palettes.bg.data : tic->cart.palettes.bg.data, sizeof(tic_palette)); + memcpy(tic->ram.vram.palette.data, row < TOOLBAR_SIZE ? tic->config.palette.data : tic->cart.palette.data, sizeof(tic_palette)); } void initMap(Map* map, tic_mem* tic) diff --git a/src/sprite.c b/src/sprite.c index 1e0957e..fe9b7d1 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -639,8 +639,8 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value) static void pasteColor(Sprite* sprite) { - fromClipboard(sprite->tic->cart.palettes.bg.data, sizeof(tic_palette), false); - fromClipboard(&sprite->tic->cart.palettes.bg.colors[sprite->color], sizeof(tic_rgb), false); + fromClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false); + fromClipboard(&sprite->tic->cart.palette.colors[sprite->color], sizeof(tic_rgb), false); } static void drawRGBTools(Sprite* sprite, s32 x, s32 y) @@ -675,7 +675,7 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y) down = true; if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) - toClipboard(sprite->tic->cart.palettes.bg.data, sizeof(tic_palette), false); + toClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false); } if(down) @@ -739,7 +739,7 @@ static void drawRGBSliders(Sprite* sprite, s32 x, s32 y) { enum{Gap = 6, Count = sizeof(tic_rgb)}; - u8* data = &sprite->tic->cart.palettes.bg.data[sprite->color * Count]; + u8* data = &sprite->tic->cart.palette.data[sprite->color * Count]; for(s32 i = 0; i < Count; i++) drawRGBSlider(sprite, x, y + Gap*i, &data[i]); @@ -1482,7 +1482,7 @@ static void onStudioEvent(Sprite* sprite, StudioEvent event) static void scanline(tic_mem* tic, s32 row) { - memcpy(tic->ram.vram.palette.data, row < TOOLBAR_SIZE ? tic->config.palettes.bg.data : tic->cart.palettes.bg.data, sizeof(tic_palette)); + memcpy(tic->ram.vram.palette.data, row < TOOLBAR_SIZE ? tic->config.palette.data : tic->cart.palette.data, sizeof(tic_palette)); } void initSprite(Sprite* sprite, tic_mem* tic) diff --git a/src/studio.c b/src/studio.c index 51845a6..a0d36ed 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1801,7 +1801,7 @@ static void transparentBlit(u32* out, s32 pitch) { const u8* in = studio.tic->ram.vram.screen.data; const u8* end = in + sizeof(studio.tic->ram.vram.screen); - const u32* pal = tic_palette_blit(&studio.tic->config.palettes.bg); + const u32* pal = tic_palette_blit(&studio.tic->config.palette); const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH); s32 col = 0; @@ -1878,7 +1878,7 @@ static void recordFrame(u32* pixels) if(studio.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) { - const u32* pal = tic_palette_blit(&studio.tic->config.palettes.bg); + const u32* pal = tic_palette_blit(&studio.tic->config.palette); drawRecordLabel(pixels, TIC80_FULLWIDTH, TIC80_WIDTH-24, 8, &pal[tic_color_red]); } @@ -2041,7 +2041,7 @@ static void renderCursor() static void useSystemPalette() { - memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.palettes.bg.data, sizeof(tic_palette)); + memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.palette.data, sizeof(tic_palette)); } static void renderStudio() @@ -2298,7 +2298,7 @@ static void setWindowIcon() u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); - const u32* pal = tic_palette_blit(&studio.tic->config.palettes.bg); + const u32* pal = tic_palette_blit(&studio.tic->config.palette); for(s32 j = 0, index = 0; j < Size; j++) for(s32 i = 0; i < Size; i++, index++) diff --git a/src/surf.c b/src/surf.c index 100f9b1..6d8ff81 100644 --- a/src/surf.c +++ b/src/surf.c @@ -508,7 +508,7 @@ static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size) { const gif_color* c = &image->palette[image->buffer[i]]; tic_rgb rgb = { c->r, c->g, c->b }; - u8 color = tic_tool_find_closest_color(tic->config.palettes.bg.colors, &rgb); + u8 color = tic_tool_find_closest_color(tic->config.palette.colors, &rgb); tic_tool_poke4(item->cover->data, i, color); } } diff --git a/src/tic.c b/src/tic.c index f39d5d7..97ae82a 100644 --- a/src/tic.c +++ b/src/tic.c @@ -53,8 +53,8 @@ typedef enum CHUNK_TEMP3, // 8 CHUNK_SOUND, // 9 CHUNK_WAVEFORM, // 10 - CHUNK_OVR_PAL, // 11 - CHUNK_BG_PAL, // 12 + CHUNK_TEMP4, // 11 + CHUNK_PALETTE, // 12 CHUNK_PATTERNS, // 13 CHUNK_MUSIC, // 14 @@ -143,7 +143,7 @@ static void runNoise(blip_buffer_t* blip, tic_sound_register* reg, tic_sound_reg static void resetPalette(tic_mem* memory) { static const u8 DefaultMapping[] = {16, 50, 84, 118, 152, 186, 220, 254}; - memcpy(memory->ram.vram.palette.data, memory->cart.palettes.bg.data, sizeof(tic_palette)); + memcpy(memory->ram.vram.palette.data, memory->cart.palette.data, sizeof(tic_palette)); memcpy(memory->ram.vram.mapping, DefaultMapping, sizeof DefaultMapping); memset(&memory->ram.vram.vars, 0, sizeof memory->ram.vram.vars); memory->ram.vram.vars.mask.data = TIC_GAMEPAD_MASK; @@ -1208,7 +1208,7 @@ static void api_tick_end(tic_mem* memory) blip_read_samples(machine->blip, machine->memory.samples.buffer, machine->samplerate / TIC_FRAMERATE); machine->state.pixel = ovrPixel; - memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palettes.ovr), sizeof machine->state.ovr.palette); + memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palette), sizeof machine->state.ovr.palette); } @@ -1265,7 +1265,7 @@ static void initCover(tic_mem* tic) { const gif_color* c = &image->palette[image->buffer[i]]; tic_rgb rgb = { c->r, c->g, c->b }; - u8 color = tic_tool_find_closest_color(tic->cart.palettes.bg.colors, &rgb); + u8 color = tic_tool_find_closest_color(tic->cart.palette.colors, &rgb); tic_tool_poke4(tic->ram.vram.screen.data, i, color); } } @@ -1529,8 +1529,7 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet if(palette) { static const u8 DB16[] = {0x14, 0x0c, 0x1c, 0x44, 0x24, 0x34, 0x30, 0x34, 0x6d, 0x4e, 0x4a, 0x4e, 0x85, 0x4c, 0x30, 0x34, 0x65, 0x24, 0xd0, 0x46, 0x48, 0x75, 0x71, 0x61, 0x59, 0x7d, 0xce, 0xd2, 0x7d, 0x2c, 0x85, 0x95, 0xa1, 0x6d, 0xaa, 0x2c, 0xd2, 0xaa, 0x99, 0x6d, 0xc2, 0xca, 0xda, 0xd4, 0x5e, 0xde, 0xee, 0xd6}; - memcpy(cart->palettes.bg.data, DB16, sizeof(tic_palette)); - memcpy(cart->palettes.ovr.data, DB16, sizeof(tic_palette)); + memcpy(cart->palette.data, DB16, sizeof(tic_palette)); } #define LOAD_CHUNK(to) memcpy(&to, buffer, min(sizeof(to), chunk.size)) @@ -1551,13 +1550,9 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet case CHUNK_WAVEFORM: LOAD_CHUNK(cart->sound.sfx.waveform); break; case CHUNK_MUSIC: LOAD_CHUNK(cart->sound.music.tracks.data); break; case CHUNK_PATTERNS: LOAD_CHUNK(cart->sound.music.patterns.data); break; - case CHUNK_BG_PAL: + case CHUNK_PALETTE: if(palette) - LOAD_CHUNK(cart->palettes.bg); - break; - case CHUNK_OVR_PAL: - if(palette) - LOAD_CHUNK(cart->palettes.ovr); + LOAD_CHUNK(cart->palette); break; case CHUNK_COVER: LOAD_CHUNK(cart->cover.data); @@ -1624,8 +1619,7 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->sound.sfx.waveform); buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->sound.music.patterns.data); buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->sound.music.tracks.data); - buffer = SAVE_CHUNK(CHUNK_BG_PAL, cart->palettes.bg); - buffer = SAVE_CHUNK(CHUNK_OVR_PAL, cart->palettes.ovr); + buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); diff --git a/src/tic.h b/src/tic.h index deda730..c68cb35 100644 --- a/src/tic.h +++ b/src/tic.h @@ -338,12 +338,7 @@ typedef struct tic_sound sound; tic_code code; tic_cover_image cover; - - struct - { - tic_palette bg; - tic_palette ovr; - } palettes; + tic_palette palette; } tic_cartridge; typedef struct From 05bad24852cb67769f302ecc723709ba92d2087d Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 30 Nov 2017 16:50:21 +0300 Subject: [PATCH 08/13] no message --- src/console.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/console.c b/src/console.c index 5c6f74c..2686213 100644 --- a/src/console.c +++ b/src/console.c @@ -696,6 +696,7 @@ static bool loadBinarySection(const char* project, const char* comment, const ch str2buf(ptr, size*2, (u8*)dst + size*index, flip); ptr += size*2 + 1; } + else break; } } else From 01669fcd8939bf5f664fdab6e3b9f0eac45ef3e5 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 1 Dec 2017 09:40:06 +0300 Subject: [PATCH 09/13] no message --- include/tic80/tic80.h | 3 ++- src/studio.c | 2 +- src/tic.c | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/tic80/tic80.h b/include/tic80/tic80.h index 1f4be68..0cf3d6f 100644 --- a/include/tic80/tic80.h +++ b/include/tic80/tic80.h @@ -31,7 +31,8 @@ extern "C" { #define TIC80_WIDTH 240 #define TIC80_HEIGHT 136 -#define TIC80_FULLWIDTH 256 +#define TIC80_FULLWIDTH_BITS 8 +#define TIC80_FULLWIDTH (1 << TIC80_FULLWIDTH_BITS) #define TIC80_FULLHEIGHT (TIC80_FULLWIDTH*9/16) typedef struct diff --git a/src/studio.c b/src/studio.c index a0d36ed..306322f 100644 --- a/src/studio.c +++ b/src/studio.c @@ -1862,7 +1862,7 @@ static void drawRecordLabel(u32* frame, s32 pitch, s32 sx, s32 sy, const u32* co for(s32 x = 0; x < sizeof RecLabel[0]*BITS_IN_BYTE; x++) { if(RecLabel[y] & (1 << x)) - memcpy(&frame[sx + 15 - x + (y+sy)*TIC80_FULLWIDTH], color, sizeof *color); + memcpy(&frame[sx + 15 - x + ((y+sy) << TIC80_FULLWIDTH_BITS)], color, sizeof *color); } } } diff --git a/src/tic.c b/src/tic.c index 97ae82a..94db161 100644 --- a/src/tic.c +++ b/src/tic.c @@ -149,9 +149,14 @@ static void resetPalette(tic_mem* memory) memory->ram.vram.vars.mask.data = TIC_GAMEPAD_MASK; } +static inline u8 mapColor(tic_mem* tic, u8 color) +{ + return tic_tool_peek4(tic->ram.vram.mapping, color & 0xf); +} + static void dmaPixel(tic_mem* tic, s32 x, s32 y, u8 color) { - tic_tool_poke4(tic->ram.vram.screen.data, y * TIC80_WIDTH + x, tic_tool_peek4(tic->ram.vram.mapping, color & 0xf)); + tic_tool_poke4(tic->ram.vram.screen.data, y * TIC80_WIDTH + x, mapColor(tic, color)); } static void ovrPixel(tic_mem* tic, s32 x, s32 y, u8 color) @@ -161,7 +166,7 @@ static void ovrPixel(tic_mem* tic, s32 x, s32 y, u8 color) enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2}; - tic->screen[x + y * TIC80_FULLWIDTH + (Left + Top * TIC80_FULLWIDTH)] = machine->state.ovr.palette[color & 0xf]; + *(tic->screen + x + (y << TIC80_FULLWIDTH_BITS) + (Left + Top * TIC80_FULLWIDTH)) = *(machine->state.ovr.palette + mapColor(tic, color)); } static void setPixel(tic_machine* machine, s32 x, s32 y, u8 color) From 096cd980df763d6703c12ad1d69e597013aed3f7 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 1 Dec 2017 10:40:53 +0300 Subject: [PATCH 10/13] no message --- src/tic.c | 50 ++++++++------------------------------------------ 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/src/tic.c b/src/tic.c index 94db161..ba12b78 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1664,7 +1664,6 @@ static inline void memset4(void *dst, u32 val, u32 dwords) static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap) { - u32* out = tic->screen; const u32* pal = tic_palette_blit(&tic->ram.vram.palette); if(scanline) @@ -1676,6 +1675,8 @@ static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap) enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2, Bottom = Top}; enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2, Right = Left}; + u32* out = tic->screen; + memset4(&out[0 * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], TIC80_FULLWIDTH*Top); u32* rowPtr = out + Top*TIC80_FULLWIDTH; @@ -1683,52 +1684,17 @@ static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap) for(s32 r = 0, y = tic->ram.vram.vars.offset.y; r < TIC80_HEIGHT; r++, y++, rowPtr += TIC80_FULLWIDTH) { memset4(rowPtr, pal[tic->ram.vram.vars.border], Left); + memset4(rowPtr + Left, pal[tic->ram.vram.vars.bg], TIC80_WIDTH); + + u32* colPtr = rowPtr + Left; if(y >= 0 && y < TIC80_HEIGHT) - { - u32* colPtr = rowPtr + Left; - s32 offset = tic->ram.vram.vars.offset.x; - s32 count = TIC80_WIDTH; - s32 index = y * TIC80_WIDTH; - - if (offset > 0) + for(s32 c = 0, x = (tic->ram.vram.vars.offset.x + TIC80_WIDTH) % TIC80_WIDTH, pos = y * TIC80_WIDTH; c < TIC80_WIDTH; c++, colPtr++, x++) { - memset4(rowPtr + Left, pal[tic->ram.vram.vars.bg], offset); - count -= offset; - colPtr += offset; - } - else - { - count += offset; - index -= offset; + if(x >= TIC80_WIDTH) x %= TIC80_WIDTH; + *colPtr = pal[tic_tool_peek4(tic->ram.vram.screen.data, pos + x)]; } - // copy the first pixel if the line is not alligned to bytes. - if (index & 1 && count > 0) - { - *colPtr++ = pal[tic_tool_peek4(tic->ram.vram.screen.data, index)]; - index++; - count--; - } - - for(s32 c = 0, di = index >> 1; c < count >> 1; c++) - { - // copy two pixels in one cycle - u8 val = tic->ram.vram.screen.data[di++]; - *colPtr++ = pal[val & 0xf]; - *colPtr++ = pal[val >> 4]; - } - - // copy the remaining pixel - if (count & 1) *colPtr = pal[tic_tool_peek4(tic->ram.vram.screen.data, index + count/2*2)]; - - if (offset < 0) memset4(rowPtr + Left + TIC80_WIDTH + offset, pal[tic->ram.vram.vars.bg], -offset); - } - else - { - memset4(rowPtr + Left, pal[tic->ram.vram.vars.bg], TIC80_WIDTH); - } - memset4(rowPtr + (TIC80_FULLWIDTH-Right), pal[tic->ram.vram.vars.border], Right); if(scanline && (r < TIC80_HEIGHT-1)) From c0c90287b85daa35250a2656b1ad2b4b9da1c561 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 1 Dec 2017 11:25:07 +0300 Subject: [PATCH 11/13] added getPixel --- src/machine.h | 3 ++- src/tic.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/machine.h b/src/machine.h index 060889c..529d1b6 100644 --- a/src/machine.h +++ b/src/machine.h @@ -90,7 +90,8 @@ typedef struct u32 palette[TIC_PALETTE_SIZE]; } ovr; - void (*pixel)(tic_mem* memory, s32 x, s32 y, u8 color); + void (*setpix)(tic_mem* memory, s32 x, s32 y, u8 color); + u8 (*getpix)(tic_mem* memory, s32 x, s32 y); bool initialized; } MachineState; diff --git a/src/tic.c b/src/tic.c index ba12b78..fe05d38 100644 --- a/src/tic.c +++ b/src/tic.c @@ -154,33 +154,59 @@ static inline u8 mapColor(tic_mem* tic, u8 color) return tic_tool_peek4(tic->ram.vram.mapping, color & 0xf); } -static void dmaPixel(tic_mem* tic, s32 x, s32 y, u8 color) +static void setPixelDma(tic_mem* tic, s32 x, s32 y, u8 color) { tic_tool_poke4(tic->ram.vram.screen.data, y * TIC80_WIDTH + x, mapColor(tic, color)); } -static void ovrPixel(tic_mem* tic, s32 x, s32 y, u8 color) +static inline u32* getOvrAddr(tic_mem* tic, s32 x, s32 y) { - tic_machine* machine = (tic_machine*)tic; - enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2}; enum {Left = (TIC80_FULLWIDTH-TIC80_WIDTH)/2}; - *(tic->screen + x + (y << TIC80_FULLWIDTH_BITS) + (Left + Top * TIC80_FULLWIDTH)) = *(machine->state.ovr.palette + mapColor(tic, color)); + return tic->screen + x + (y << TIC80_FULLWIDTH_BITS) + (Left + Top * TIC80_FULLWIDTH); +} + +static void setPixelOvr(tic_mem* tic, s32 x, s32 y, u8 color) +{ + tic_machine* machine = (tic_machine*)tic; + + *getOvrAddr(tic, x, y) = *(machine->state.ovr.palette + mapColor(tic, color)); +} + +static u8 getPixelOvr(tic_mem* tic, s32 x, s32 y) +{ + tic_machine* machine = (tic_machine*)tic; + + u32 color = *getOvrAddr(tic, x, y); + u32* pal = machine->state.ovr.palette; + + for(s32 i = 0; i < TIC_PALETTE_SIZE; i++, pal++) + if(*pal == color) + return i; + + return 0; +} + +static u8 getPixelDma(tic_mem* tic, s32 x, s32 y) +{ + tic_machine* machine = (tic_machine*)tic; + + return tic_tool_peek4(machine->memory.ram.vram.screen.data, y * TIC80_WIDTH + x); } static void setPixel(tic_machine* machine, s32 x, s32 y, u8 color) { if(x < machine->state.clip.l || y < machine->state.clip.t || x >= machine->state.clip.r || y >= machine->state.clip.b) return; - machine->state.pixel(&machine->memory, x, y, color); + machine->state.setpix(&machine->memory, x, y, color); } static u8 getPixel(tic_machine* machine, s32 x, s32 y) { if(x < 0 || y < 0 || x >= TIC80_WIDTH || y >= TIC80_HEIGHT) return 0; - return tic_tool_peek4(machine->memory.ram.vram.screen.data, y * TIC80_WIDTH + x); + return machine->state.getpix(&machine->memory, x, y); } static void drawHLine(tic_machine* machine, s32 x, s32 y, s32 width, u8 color) @@ -452,7 +478,8 @@ static void api_reset(tic_mem* memory) machine->state.scanline = NULL; machine->state.ovr.callback = NULL; - machine->state.pixel = dmaPixel; + machine->state.setpix = setPixelDma; + machine->state.getpix = getPixelDma; updateSaveid(memory); } @@ -1187,7 +1214,8 @@ static void api_tick_start(tic_mem* memory, const tic_sound* src) else *hold = 0; } - machine->state.pixel = dmaPixel; + machine->state.setpix = setPixelDma; + machine->state.getpix = getPixelDma; } static void api_tick_end(tic_mem* memory) @@ -1212,7 +1240,8 @@ static void api_tick_end(tic_mem* memory) blip_end_frame(machine->blip, EndTime); blip_read_samples(machine->blip, machine->memory.samples.buffer, machine->samplerate / TIC_FRAMERATE); - machine->state.pixel = ovrPixel; + machine->state.setpix = setPixelOvr; + machine->state.getpix = getPixelOvr; memcpy(machine->state.ovr.palette, tic_palette_blit(&memory->cart.palette), sizeof machine->state.ovr.palette); } From 6cd9d17b9ecd6ca2205f8d577aa774c1a0170964 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 1 Dec 2017 13:01:48 +0300 Subject: [PATCH 12/13] no message --- src/tic.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tic.c b/src/tic.c index fe05d38..66d2584 100644 --- a/src/tic.c +++ b/src/tic.c @@ -145,8 +145,6 @@ static void resetPalette(tic_mem* memory) static const u8 DefaultMapping[] = {16, 50, 84, 118, 152, 186, 220, 254}; memcpy(memory->ram.vram.palette.data, memory->cart.palette.data, sizeof(tic_palette)); memcpy(memory->ram.vram.mapping, DefaultMapping, sizeof DefaultMapping); - memset(&memory->ram.vram.vars, 0, sizeof memory->ram.vram.vars); - memory->ram.vram.vars.mask.data = TIC_GAMEPAD_MASK; } static inline u8 mapColor(tic_mem* tic, u8 color) @@ -469,6 +467,10 @@ static void api_clip(tic_mem* memory, s32 x, s32 y, s32 width, s32 height) static void api_reset(tic_mem* memory) { resetPalette(memory); + + memset(&memory->ram.vram.vars, 0, sizeof memory->ram.vram.vars); + memory->ram.vram.vars.mask.data = TIC_GAMEPAD_MASK; + api_clip(memory, 0, 0, TIC80_WIDTH, TIC80_HEIGHT); soundClear(memory); @@ -1214,6 +1216,8 @@ static void api_tick_start(tic_mem* memory, const tic_sound* src) else *hold = 0; } + resetPalette(memory); + machine->state.setpix = setPixelDma; machine->state.getpix = getPixelDma; } From 2d4a36d66cd692a3c32e3929fad5492645128aa9 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Sat, 2 Dec 2017 19:19:17 +0300 Subject: [PATCH 13/13] added vertical border scroll --- src/tic.c | 23 ++++++++++------------- src/tic.h | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/tic.c b/src/tic.c index 66d2584..bddbef3 100644 --- a/src/tic.c +++ b/src/tic.c @@ -546,8 +546,6 @@ 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) @@ -1712,24 +1710,23 @@ static void api_blit(tic_mem* tic, tic_scanline scanline, tic_overlap overlap) memset4(&out[0 * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], TIC80_FULLWIDTH*Top); - u32* rowPtr = out + Top*TIC80_FULLWIDTH; + u32* rowPtr = out + (Top*TIC80_FULLWIDTH); + u32* colPtr = rowPtr + Left; - for(s32 r = 0, y = tic->ram.vram.vars.offset.y; r < TIC80_HEIGHT; r++, y++, rowPtr += TIC80_FULLWIDTH) + for(s32 r = 0; r < TIC80_HEIGHT; r++, rowPtr += TIC80_FULLWIDTH, colPtr += (Left + Right)) { memset4(rowPtr, pal[tic->ram.vram.vars.border], Left); - memset4(rowPtr + Left, pal[tic->ram.vram.vars.bg], TIC80_WIDTH); - u32* colPtr = rowPtr + Left; + s32 pos = (r + tic->ram.vram.vars.offset.y + TIC80_HEIGHT) % TIC80_HEIGHT * TIC80_WIDTH; - if(y >= 0 && y < TIC80_HEIGHT) - for(s32 c = 0, x = (tic->ram.vram.vars.offset.x + TIC80_WIDTH) % TIC80_WIDTH, pos = y * TIC80_WIDTH; c < TIC80_WIDTH; c++, colPtr++, x++) - { - if(x >= TIC80_WIDTH) x %= TIC80_WIDTH; - *colPtr = pal[tic_tool_peek4(tic->ram.vram.screen.data, pos + x)]; - } + for(s32 c = 0, x = (tic->ram.vram.vars.offset.x + TIC80_WIDTH) % TIC80_WIDTH; c < TIC80_WIDTH; c++, colPtr++, x++) + { + if(x >= TIC80_WIDTH) x %= TIC80_WIDTH; + *colPtr = pal[tic_tool_peek4(tic->ram.vram.screen.data, pos + x)]; + } memset4(rowPtr + (TIC80_FULLWIDTH-Right), pal[tic->ram.vram.vars.border], Right); - + if(scanline && (r < TIC80_HEIGHT-1)) { scanline(tic, r+1); diff --git a/src/tic.h b/src/tic.h index c68cb35..ea22bfd 100644 --- a/src/tic.h +++ b/src/tic.h @@ -368,7 +368,7 @@ typedef union struct { u8 border:TIC_PALETTE_BPP; - u8 bg:TIC_PALETTE_BPP; + u8 tmp:TIC_PALETTE_BPP; }; };