From e3ad17f609669a1f0fc64c96850303ba187bab04 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 30 Nov 2017 13:10:20 +0300 Subject: [PATCH] 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);