mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-30 01:33:01 +00:00
Housekeeping
This commit is contained in:
parent
eb07d9fba6
commit
dcb434760b
3 changed files with 22 additions and 32 deletions
|
@ -104,9 +104,9 @@ screen_resize(Uint16 width, Uint16 height)
|
||||||
uxn_screen.pixels = pixels;
|
uxn_screen.pixels = pixels;
|
||||||
uxn_screen.width = width;
|
uxn_screen.width = width;
|
||||||
uxn_screen.height = height;
|
uxn_screen.height = height;
|
||||||
screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
|
screen_fill(uxn_screen.bg, 0, 0, width, height, 0);
|
||||||
screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
|
screen_fill(uxn_screen.fg, 0, 0, width, height, 0);
|
||||||
emu_resize();
|
emu_resize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -17,7 +17,7 @@ typedef struct UxnScreen {
|
||||||
} UxnScreen;
|
} UxnScreen;
|
||||||
|
|
||||||
extern UxnScreen uxn_screen;
|
extern UxnScreen uxn_screen;
|
||||||
extern int emu_resize(void);
|
extern int emu_resize(int width, int height);
|
||||||
|
|
||||||
void screen_palette(Uint8 *addr);
|
void screen_palette(Uint8 *addr);
|
||||||
void screen_resize(Uint16 width, Uint16 height);
|
void screen_resize(Uint16 width, Uint16 height);
|
||||||
|
|
46
src/uxnemu.c
46
src/uxnemu.c
|
@ -119,7 +119,7 @@ emu_deo(Uxn *u, Uint8 addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Generics
|
/* Handlers */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
audio_callback(void *u, Uint8 *stream, int len)
|
audio_callback(void *u, Uint8 *stream, int len)
|
||||||
|
@ -166,22 +166,22 @@ set_window_size(SDL_Window *window, int w, int h)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
emu_resize(void)
|
emu_resize(int width, int height)
|
||||||
{
|
{
|
||||||
if(emu_texture != NULL)
|
if(emu_texture != NULL)
|
||||||
SDL_DestroyTexture(emu_texture);
|
SDL_DestroyTexture(emu_texture);
|
||||||
SDL_RenderSetLogicalSize(emu_renderer, uxn_screen.width, uxn_screen.height);
|
SDL_RenderSetLogicalSize(emu_renderer, width, height);
|
||||||
emu_texture = SDL_CreateTexture(emu_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC, uxn_screen.width, uxn_screen.height);
|
emu_texture = SDL_CreateTexture(emu_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC, width, height);
|
||||||
if(emu_texture == NULL || SDL_SetTextureBlendMode(emu_texture, SDL_BLENDMODE_NONE))
|
if(emu_texture == NULL || SDL_SetTextureBlendMode(emu_texture, SDL_BLENDMODE_NONE))
|
||||||
return system_error("SDL_SetTextureBlendMode", SDL_GetError());
|
return system_error("SDL_SetTextureBlendMode", SDL_GetError());
|
||||||
if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0)
|
if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0)
|
||||||
return system_error("SDL_UpdateTexture", SDL_GetError());
|
return system_error("SDL_UpdateTexture", SDL_GetError());
|
||||||
set_window_size(emu_window, (uxn_screen.width) * zoom, (uxn_screen.height) * zoom);
|
set_window_size(emu_window, width * zoom, height * zoom);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
redraw(void)
|
emu_redraw(void)
|
||||||
{
|
{
|
||||||
screen_redraw();
|
screen_redraw();
|
||||||
if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
|
if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
|
||||||
|
@ -226,8 +226,6 @@ init(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Devices
|
|
||||||
|
|
||||||
/* Boot */
|
/* Boot */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -287,7 +285,7 @@ capture_screen(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
restart(Uxn *u)
|
emu_restart(Uxn *u)
|
||||||
{
|
{
|
||||||
screen_resize(WIDTH, HEIGHT);
|
screen_resize(WIDTH, HEIGHT);
|
||||||
if(!start(u, "launcher.rom", 0))
|
if(!start(u, "launcher.rom", 0))
|
||||||
|
@ -342,19 +340,6 @@ get_key(SDL_Event *event)
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
do_shortcut(Uxn *u, SDL_Event *event)
|
|
||||||
{
|
|
||||||
if(event->key.keysym.sym == SDLK_F1)
|
|
||||||
set_zoom(zoom == 3 ? 1 : zoom + 1);
|
|
||||||
else if(event->key.keysym.sym == SDLK_F2)
|
|
||||||
system_inspect(u);
|
|
||||||
else if(event->key.keysym.sym == SDLK_F3)
|
|
||||||
capture_screen();
|
|
||||||
else if(event->key.keysym.sym == SDLK_F4)
|
|
||||||
restart(u);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
handle_events(Uxn *u)
|
handle_events(Uxn *u)
|
||||||
{
|
{
|
||||||
|
@ -364,7 +349,7 @@ handle_events(Uxn *u)
|
||||||
if(event.type == SDL_QUIT)
|
if(event.type == SDL_QUIT)
|
||||||
return 0;
|
return 0;
|
||||||
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED)
|
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED)
|
||||||
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);
|
start(u, event.drop.file, 0);
|
||||||
|
@ -391,12 +376,17 @@ handle_events(Uxn *u)
|
||||||
controller_key(u, &u->dev[0x80], get_key(&event));
|
controller_key(u, &u->dev[0x80], get_key(&event));
|
||||||
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
|
else if(event.key.keysym.sym == SDLK_F1)
|
||||||
do_shortcut(u, &event);
|
set_zoom(zoom == 3 ? 1 : zoom + 1);
|
||||||
|
else if(event.key.keysym.sym == SDLK_F2)
|
||||||
|
system_inspect(u);
|
||||||
|
else if(event.key.keysym.sym == SDLK_F3)
|
||||||
|
capture_screen();
|
||||||
|
else if(event.key.keysym.sym == SDLK_F4)
|
||||||
|
emu_restart(u);
|
||||||
ksym = event.key.keysym.sym;
|
ksym = event.key.keysym.sym;
|
||||||
if(SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYUP, SDL_KEYUP) == 1 && ksym == event.key.keysym.sym) {
|
if(SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYUP, SDL_KEYUP) == 1 && ksym == event.key.keysym.sym)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
} else if(event.type == SDL_KEYUP)
|
} else if(event.type == SDL_KEYUP)
|
||||||
controller_up(u, &u->dev[0x80], get_button(&event));
|
controller_up(u, &u->dev[0x80], get_button(&event));
|
||||||
else if(event.type == SDL_JOYAXISMOTION) {
|
else if(event.type == SDL_JOYAXISMOTION) {
|
||||||
|
@ -473,7 +463,7 @@ run(Uxn *u)
|
||||||
next_refresh = now + frame_interval;
|
next_refresh = now + frame_interval;
|
||||||
uxn_eval(u, screen_vector);
|
uxn_eval(u, screen_vector);
|
||||||
if(uxn_screen.x2)
|
if(uxn_screen.x2)
|
||||||
redraw();
|
emu_redraw();
|
||||||
}
|
}
|
||||||
if(BENCH) {
|
if(BENCH) {
|
||||||
/* no delay */
|
/* no delay */
|
||||||
|
|
Loading…
Reference in a new issue