diff --git a/examples/sdl-renderer.c b/examples/sdl-renderer.c index bd42334..d80216b 100644 --- a/examples/sdl-renderer.c +++ b/examples/sdl-renderer.c @@ -24,6 +24,19 @@ #include #include +static struct +{ + bool quit; +} state = +{ + .quit = false, +}; + +static void onExit() +{ + state.quit = true; +} + int main(int argc, char **argv) { FILE* file = fopen("cart.tic", "rb"); @@ -42,8 +55,6 @@ int main(int argc, char **argv) { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); - bool quit = false; - { 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_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); @@ -68,11 +79,14 @@ int main(int argc, char **argv) tic80_input input = {.first.data = 0, .second.data = 0}; tic80* tic = tic80_create(audioSpec.freq); + + tic->callback.exit = onExit; + tic80_load(tic, cart, size); if(tic) { - while(!quit) + while(!state.quit) { SDL_Event event; @@ -81,7 +95,7 @@ int main(int argc, char **argv) switch(event.type) { case SDL_QUIT: - quit = true; + state.quit = true; break; } } @@ -120,7 +134,7 @@ int main(int argc, char **argv) SDL_PauseAudioDevice(audioDevice, 0); } - SDL_QueueAudio(audioDevice, tic->sound.buffer, tic->sound.size); + SDL_QueueAudio(audioDevice, tic->sound.samples, tic->sound.count * sizeof(tic->sound.samples[0])); SDL_RenderClear(renderer); @@ -128,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.buffer, tic->screen.size); + SDL_memcpy(pixels, tic->screen, sizeof tic->screen); SDL_UnlockTexture(texture); SDL_RenderCopy(renderer, texture, NULL, NULL); } diff --git a/include/tic80/tic80.h b/include/tic80/tic80.h index 8118367..939dd77 100644 --- a/include/tic80/tic80.h +++ b/include/tic80/tic80.h @@ -36,15 +36,26 @@ typedef struct { struct { - s16* buffer; - s32 size; - } sound; + void (*trace)(const char* text, u8 color); + void (*error)(const char* info); + void (*exit)(); + } callback; struct { - void* buffer; - s32 size; - } screen; + s16* samples; + s32 count; + } sound; + + u32 screen[TIC80_WIDTH * TIC80_HEIGHT]; + u32 border[TIC80_HEIGHT]; + + struct + { + s8 x; + s8 y; + s8 rows[TIC80_HEIGHT]; + } offset; } tic80; typedef union diff --git a/lib/windows/x64/tic.lib b/lib/windows/x64/tic.lib deleted file mode 100644 index f28d42f..0000000 Binary files a/lib/windows/x64/tic.lib and /dev/null differ diff --git a/lib/windows/x64/tic80.dll b/lib/windows/x64/tic80.dll index b869f03..d047f4c 100644 Binary files a/lib/windows/x64/tic80.dll and b/lib/windows/x64/tic80.dll differ diff --git a/lib/windows/x64/tic80.lib b/lib/windows/x64/tic80.lib new file mode 100644 index 0000000..625dca9 Binary files /dev/null and b/lib/windows/x64/tic80.lib differ diff --git a/lib/windows/x86/tic80.dll b/lib/windows/x86/tic80.dll index 244a83b..f78ccf9 100644 Binary files a/lib/windows/x86/tic80.dll and b/lib/windows/x86/tic80.dll differ diff --git a/lib/windows/x86/tic80.lib b/lib/windows/x86/tic80.lib index 3b71052..29579ee 100644 Binary files a/lib/windows/x86/tic80.lib and b/lib/windows/x86/tic80.lib differ