Grouped emulator routines together in uxnemu
This commit is contained in:
parent
969f03e0ba
commit
4286e0ba53
45
src/uxnemu.c
45
src/uxnemu.c
|
@ -166,6 +166,18 @@ set_window_size(SDL_Window *window, int w, int h)
|
||||||
SDL_SetWindowSize(window, w, h);
|
SDL_SetWindowSize(window, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_zoom(Uint8 z, int win)
|
||||||
|
{
|
||||||
|
if(z >= 1) {
|
||||||
|
zoom = z;
|
||||||
|
if(win)
|
||||||
|
set_window_size(emu_window, (uxn_screen.width) * zoom, (uxn_screen.height) * zoom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* emulator primitives */
|
||||||
|
|
||||||
int
|
int
|
||||||
emu_resize(int width, int height)
|
emu_resize(int width, int height)
|
||||||
{
|
{
|
||||||
|
@ -218,13 +230,12 @@ emu_init(void)
|
||||||
SDL_StartTextInput();
|
SDL_StartTextInput();
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||||
|
SDL_SetRenderDrawColor(emu_renderer, 0x00, 0x00, 0x00, 0xff);
|
||||||
ms_interval = SDL_GetPerformanceFrequency() / 1000;
|
ms_interval = SDL_GetPerformanceFrequency() / 1000;
|
||||||
deadline_interval = ms_interval * TIMEOUT_MS;
|
deadline_interval = ms_interval * TIMEOUT_MS;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Boot */
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
emu_start(Uxn *u, char *rom, int queue)
|
emu_start(Uxn *u, char *rom, int queue)
|
||||||
{
|
{
|
||||||
|
@ -242,13 +253,11 @@ emu_start(Uxn *u, char *rom, int queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_zoom(Uint8 z, int win)
|
emu_restart(Uxn *u)
|
||||||
{
|
{
|
||||||
if(z >= 1) {
|
screen_resize(WIDTH, HEIGHT);
|
||||||
zoom = z;
|
if(!emu_start(u, "launcher.rom", 0))
|
||||||
if(win)
|
emu_start(u, rom_path, 0);
|
||||||
set_window_size(emu_window, (uxn_screen.width) * zoom, (uxn_screen.height) * zoom);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -282,14 +291,6 @@ capture_screen(void)
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
emu_restart(Uxn *u)
|
|
||||||
{
|
|
||||||
screen_resize(WIDTH, HEIGHT);
|
|
||||||
if(!emu_start(u, "launcher.rom", 0))
|
|
||||||
emu_start(u, rom_path, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Uint8
|
static Uint8
|
||||||
get_button(SDL_Event *event)
|
get_button(SDL_Event *event)
|
||||||
{
|
{
|
||||||
|
@ -441,7 +442,7 @@ handle_events(Uxn *u)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
emu_run(Uxn *u)
|
gameloop(Uxn *u)
|
||||||
{
|
{
|
||||||
Uint64 next_refresh = 0;
|
Uint64 next_refresh = 0;
|
||||||
Uint64 now;
|
Uint64 now;
|
||||||
|
@ -474,7 +475,7 @@ emu_run(Uxn *u)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
emu_show(void)
|
show(void)
|
||||||
{
|
{
|
||||||
window_created = 1;
|
window_created = 1;
|
||||||
emu_window = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, uxn_screen.width * zoom, uxn_screen.height * zoom, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
emu_window = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, uxn_screen.width * zoom, uxn_screen.height * zoom, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
|
@ -483,7 +484,6 @@ emu_show(void)
|
||||||
emu_renderer = SDL_CreateRenderer(emu_window, -1, 0);
|
emu_renderer = SDL_CreateRenderer(emu_window, -1, 0);
|
||||||
if(emu_renderer == NULL)
|
if(emu_renderer == NULL)
|
||||||
return system_error("sdl_renderer", SDL_GetError());
|
return system_error("sdl_renderer", SDL_GetError());
|
||||||
SDL_SetRenderDrawColor(emu_renderer, 0x00, 0x00, 0x00, 0xff);
|
|
||||||
emu_resize(uxn_screen.width, uxn_screen.height);
|
emu_resize(uxn_screen.width, uxn_screen.height);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,6 @@ emu_show(void)
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
SDL_DisplayMode DM;
|
|
||||||
Uxn u = {0};
|
Uxn u = {0};
|
||||||
int i = 1;
|
int i = 1;
|
||||||
if(!emu_init())
|
if(!emu_init())
|
||||||
|
@ -501,8 +500,6 @@ main(int argc, char **argv)
|
||||||
/* default zoom */
|
/* default zoom */
|
||||||
if(argc > 1 && (strcmp(argv[i], "-1x") == 0 || strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0))
|
if(argc > 1 && (strcmp(argv[i], "-1x") == 0 || strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0))
|
||||||
set_zoom(argv[i++][1] - '0', 0);
|
set_zoom(argv[i++][1] - '0', 0);
|
||||||
else if(SDL_GetCurrentDisplayMode(0, &DM) == 0)
|
|
||||||
set_zoom(DM.w / 1280, 0);
|
|
||||||
/* load rom */
|
/* load rom */
|
||||||
if(i == argc)
|
if(i == argc)
|
||||||
return system_error("usage", "uxnemu [-2x][-3x] file.rom [args...]");
|
return system_error("usage", "uxnemu [-2x][-3x] file.rom [args...]");
|
||||||
|
@ -516,8 +513,8 @@ main(int argc, char **argv)
|
||||||
console_input(&u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
|
console_input(&u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
|
||||||
}
|
}
|
||||||
/* start rom */
|
/* start rom */
|
||||||
emu_show();
|
show();
|
||||||
emu_run(&u);
|
gameloop(&u);
|
||||||
/* finished */
|
/* finished */
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||||
|
|
Loading…
Reference in New Issue