Uxnemu skips resizing window until reset vector is done.
This commit is contained in:
parent
07f2ea43f7
commit
969f03e0ba
56
src/uxnemu.c
56
src/uxnemu.c
|
@ -59,6 +59,7 @@ static Uint32 stdin_event, audio0_event, zoom = 1;
|
||||||
static Uint64 exec_deadline, deadline_interval, ms_interval;
|
static Uint64 exec_deadline, deadline_interval, ms_interval;
|
||||||
|
|
||||||
char *rom_path;
|
char *rom_path;
|
||||||
|
int window_created = 0;
|
||||||
|
|
||||||
static Uint8
|
static Uint8
|
||||||
audio_dei(int instance, Uint8 *d, Uint8 port)
|
audio_dei(int instance, Uint8 *d, Uint8 port)
|
||||||
|
@ -168,6 +169,8 @@ set_window_size(SDL_Window *window, int w, int h)
|
||||||
int
|
int
|
||||||
emu_resize(int width, int height)
|
emu_resize(int width, int height)
|
||||||
{
|
{
|
||||||
|
if(!window_created)
|
||||||
|
return 0;
|
||||||
if(emu_texture != NULL)
|
if(emu_texture != NULL)
|
||||||
SDL_DestroyTexture(emu_texture);
|
SDL_DestroyTexture(emu_texture);
|
||||||
SDL_RenderSetLogicalSize(emu_renderer, width, height);
|
SDL_RenderSetLogicalSize(emu_renderer, width, height);
|
||||||
|
@ -191,7 +194,7 @@ emu_redraw(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
init(void)
|
emu_init(void)
|
||||||
{
|
{
|
||||||
SDL_AudioSpec as;
|
SDL_AudioSpec as;
|
||||||
SDL_zero(as);
|
SDL_zero(as);
|
||||||
|
@ -203,13 +206,7 @@ init(void)
|
||||||
as.userdata = NULL;
|
as.userdata = NULL;
|
||||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
|
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
|
||||||
return system_error("sdl", SDL_GetError());
|
return system_error("sdl", SDL_GetError());
|
||||||
emu_window = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (WIDTH)*zoom, (HEIGHT)*zoom, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
|
||||||
if(emu_window == NULL)
|
|
||||||
return system_error("sdl_window", SDL_GetError());
|
|
||||||
emu_renderer = SDL_CreateRenderer(emu_window, -1, 0);
|
|
||||||
if(emu_renderer == NULL)
|
|
||||||
return system_error("sdl_renderer", SDL_GetError());
|
|
||||||
SDL_SetRenderDrawColor(emu_renderer, 0x00, 0x00, 0x00, 0xff);
|
|
||||||
audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0);
|
audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0);
|
||||||
if(!audio_id)
|
if(!audio_id)
|
||||||
system_error("sdl_audio", SDL_GetError());
|
system_error("sdl_audio", SDL_GetError());
|
||||||
|
@ -229,7 +226,7 @@ init(void)
|
||||||
/* Boot */
|
/* Boot */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
start(Uxn *u, char *rom, int queue)
|
emu_start(Uxn *u, char *rom, int queue)
|
||||||
{
|
{
|
||||||
free(u->ram);
|
free(u->ram);
|
||||||
if(!uxn_boot(u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
|
if(!uxn_boot(u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
|
||||||
|
@ -245,11 +242,12 @@ start(Uxn *u, char *rom, int queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_zoom(Uint8 z)
|
set_zoom(Uint8 z, int win)
|
||||||
{
|
{
|
||||||
if(z >= 1) {
|
if(z >= 1) {
|
||||||
zoom = z;
|
zoom = z;
|
||||||
set_window_size(emu_window, (uxn_screen.width) * zoom, (uxn_screen.height) * zoom);
|
if(win)
|
||||||
|
set_window_size(emu_window, (uxn_screen.width) * zoom, (uxn_screen.height) * zoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,8 +286,8 @@ static void
|
||||||
emu_restart(Uxn *u)
|
emu_restart(Uxn *u)
|
||||||
{
|
{
|
||||||
screen_resize(WIDTH, HEIGHT);
|
screen_resize(WIDTH, HEIGHT);
|
||||||
if(!start(u, "launcher.rom", 0))
|
if(!emu_start(u, "launcher.rom", 0))
|
||||||
start(u, rom_path, 0);
|
emu_start(u, rom_path, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8
|
static Uint8
|
||||||
|
@ -352,7 +350,7 @@ handle_events(Uxn *u)
|
||||||
emu_redraw();
|
emu_redraw();
|
||||||
else if(event.type == SDL_DROPFILE) {
|
else if(event.type == SDL_DROPFILE) {
|
||||||
screen_resize(WIDTH, HEIGHT);
|
screen_resize(WIDTH, HEIGHT);
|
||||||
start(u, event.drop.file, 0);
|
emu_start(u, event.drop.file, 0);
|
||||||
SDL_free(event.drop.file);
|
SDL_free(event.drop.file);
|
||||||
}
|
}
|
||||||
/* Audio */
|
/* Audio */
|
||||||
|
@ -377,7 +375,7 @@ handle_events(Uxn *u)
|
||||||
else if(get_button(&event))
|
else if(get_button(&event))
|
||||||
controller_down(u, &u->dev[0x80], get_button(&event));
|
controller_down(u, &u->dev[0x80], get_button(&event));
|
||||||
else if(event.key.keysym.sym == SDLK_F1)
|
else if(event.key.keysym.sym == SDLK_F1)
|
||||||
set_zoom(zoom == 3 ? 1 : zoom + 1);
|
set_zoom(zoom == 3 ? 1 : zoom + 1, 1);
|
||||||
else if(event.key.keysym.sym == SDLK_F2)
|
else if(event.key.keysym.sym == SDLK_F2)
|
||||||
system_inspect(u);
|
system_inspect(u);
|
||||||
else if(event.key.keysym.sym == SDLK_F3)
|
else if(event.key.keysym.sym == SDLK_F3)
|
||||||
|
@ -443,7 +441,7 @@ handle_events(Uxn *u)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
run(Uxn *u)
|
emu_run(Uxn *u)
|
||||||
{
|
{
|
||||||
Uint64 next_refresh = 0;
|
Uint64 next_refresh = 0;
|
||||||
Uint64 now;
|
Uint64 now;
|
||||||
|
@ -475,26 +473,41 @@ run(Uxn *u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
emu_show(void)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
if(emu_window == NULL)
|
||||||
|
return system_error("sdl_window", SDL_GetError());
|
||||||
|
emu_renderer = SDL_CreateRenderer(emu_window, -1, 0);
|
||||||
|
if(emu_renderer == NULL)
|
||||||
|
return system_error("sdl_renderer", SDL_GetError());
|
||||||
|
SDL_SetRenderDrawColor(emu_renderer, 0x00, 0x00, 0x00, 0xff);
|
||||||
|
emu_resize(uxn_screen.width, uxn_screen.height);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
SDL_DisplayMode DM;
|
SDL_DisplayMode DM;
|
||||||
Uxn u = {0};
|
Uxn u = {0};
|
||||||
int i = 1;
|
int i = 1;
|
||||||
if(!init())
|
if(!emu_init())
|
||||||
return system_error("Init", "Failed to initialize emulator.");
|
return system_error("Init", "Failed to initialize emulator.");
|
||||||
/* default resolution */
|
/* default resolution */
|
||||||
screen_resize(WIDTH, HEIGHT);
|
screen_resize(WIDTH, HEIGHT);
|
||||||
/* 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');
|
set_zoom(argv[i++][1] - '0', 0);
|
||||||
else if(SDL_GetCurrentDisplayMode(0, &DM) == 0)
|
else if(SDL_GetCurrentDisplayMode(0, &DM) == 0)
|
||||||
set_zoom(DM.w / 1280);
|
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...]");
|
||||||
rom_path = argv[i++];
|
rom_path = argv[i++];
|
||||||
if(!start(&u, rom_path, argc - i))
|
if(!emu_start(&u, rom_path, argc - i))
|
||||||
return system_error("Start", "Failed");
|
return system_error("Start", "Failed");
|
||||||
/* read arguments */
|
/* read arguments */
|
||||||
for(; i < argc; i++) {
|
for(; i < argc; i++) {
|
||||||
|
@ -503,7 +516,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 */
|
||||||
run(&u);
|
emu_show();
|
||||||
|
emu_run(&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