- trace/exit/error callbacks
- screen border buffer
- screen offset
This commit is contained in:
BADIM-PC\Vadim 2017-08-12 14:34:11 +03:00
parent 2613b6ac20
commit 99f667c5b1
7 changed files with 37 additions and 12 deletions

View File

@ -24,6 +24,19 @@
#include <SDL.h> #include <SDL.h>
#include <tic80.h> #include <tic80.h>
static struct
{
bool quit;
} state =
{
.quit = false,
};
static void onExit()
{
state.quit = true;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
FILE* file = fopen("cart.tic", "rb"); FILE* file = fopen("cart.tic", "rb");
@ -42,8 +55,6 @@ int main(int argc, char **argv)
{ {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); 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_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); 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_input input = {.first.data = 0, .second.data = 0};
tic80* tic = tic80_create(audioSpec.freq); tic80* tic = tic80_create(audioSpec.freq);
tic->callback.exit = onExit;
tic80_load(tic, cart, size); tic80_load(tic, cart, size);
if(tic) if(tic)
{ {
while(!quit) while(!state.quit)
{ {
SDL_Event event; SDL_Event event;
@ -81,7 +95,7 @@ int main(int argc, char **argv)
switch(event.type) switch(event.type)
{ {
case SDL_QUIT: case SDL_QUIT:
quit = true; state.quit = true;
break; break;
} }
} }
@ -120,7 +134,7 @@ int main(int argc, char **argv)
SDL_PauseAudioDevice(audioDevice, 0); 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); SDL_RenderClear(renderer);
@ -128,7 +142,7 @@ int main(int argc, char **argv)
void* pixels = NULL; void* pixels = NULL;
int pitch = 0; int pitch = 0;
SDL_LockTexture(texture, NULL, &pixels, &pitch); 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_UnlockTexture(texture);
SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderCopy(renderer, texture, NULL, NULL);
} }

View File

@ -36,15 +36,26 @@ typedef struct
{ {
struct struct
{ {
s16* buffer; void (*trace)(const char* text, u8 color);
s32 size; void (*error)(const char* info);
} sound; void (*exit)();
} callback;
struct struct
{ {
void* buffer; s16* samples;
s32 size; s32 count;
} screen; } sound;
u32 screen[TIC80_WIDTH * TIC80_HEIGHT];
u32 border[TIC80_HEIGHT];
struct
{
s8 x;
s8 y;
s8 rows[TIC80_HEIGHT];
} offset;
} tic80; } tic80;
typedef union typedef union

Binary file not shown.

Binary file not shown.

BIN
lib/windows/x64/tic80.lib Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.