Housekeeping
This commit is contained in:
parent
228a951f22
commit
dd1f3e0725
|
@ -334,3 +334,14 @@ audio_get_position(int instance)
|
||||||
{
|
{
|
||||||
return channel[instance].sample.pos;
|
return channel[instance].sample.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uint8
|
||||||
|
audio_dei(int instance, Uint8 *d, Uint8 port)
|
||||||
|
{
|
||||||
|
switch(port) {
|
||||||
|
case 0x2: return audio_get_position(instance) >> 8;
|
||||||
|
case 0x3: return audio_get_position(instance);
|
||||||
|
case 0x4: return audio_get_vu(instance);
|
||||||
|
}
|
||||||
|
return d[port];
|
||||||
|
}
|
||||||
|
|
|
@ -25,3 +25,4 @@ int audio_render(int instance, Sint16 *sample, Sint16 *end);
|
||||||
void audio_start(int instance, Uint8 *d, Uxn *u);
|
void audio_start(int instance, Uint8 *d, Uxn *u);
|
||||||
void audio_finished_handler(int instance);
|
void audio_finished_handler(int instance);
|
||||||
void audio_handler(void *ctx, Uint8 *out_stream, int len);
|
void audio_handler(void *ctx, Uint8 *out_stream, int len);
|
||||||
|
Uint8 audio_dei(int instance, Uint8 *d, Uint8 port);
|
||||||
|
|
|
@ -39,7 +39,7 @@ screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color)
|
screen_rect(Uint8 *layer, int x1, int y1, int x2, int y2, int color)
|
||||||
{
|
{
|
||||||
int x, y, width = uxn_screen.width, height = uxn_screen.height;
|
int x, y, width = uxn_screen.width, height = uxn_screen.height;
|
||||||
for(y = y1; y < y2 && y < height; y++)
|
for(y = y1; y < y2 && y < height; y++)
|
||||||
|
@ -153,8 +153,8 @@ 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, width, height, 0);
|
screen_rect(uxn_screen.bg, 0, 0, width, height, 0);
|
||||||
screen_fill(uxn_screen.fg, 0, 0, width, height, 0);
|
screen_rect(uxn_screen.fg, 0, 0, width, height, 0);
|
||||||
emu_resize(width, height);
|
emu_resize(width, height);
|
||||||
screen_change(0, 0, width, height);
|
screen_change(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
|
||||||
Uint16 y2 = uxn_screen.height;
|
Uint16 y2 = uxn_screen.height;
|
||||||
if(ctrl & 0x10) x2 = x, x = 0;
|
if(ctrl & 0x10) x2 = x, x = 0;
|
||||||
if(ctrl & 0x20) y2 = y, y = 0;
|
if(ctrl & 0x20) y2 = y, y = 0;
|
||||||
screen_fill(layer, x, y, x2, y2, color);
|
screen_rect(layer, x, y, x2, y2, color);
|
||||||
screen_change(x, y, x2, y2);
|
screen_change(x, y, x2, y2);
|
||||||
}
|
}
|
||||||
/* pixel mode */
|
/* pixel mode */
|
||||||
|
|
|
@ -22,7 +22,7 @@ typedef struct UxnScreen {
|
||||||
extern UxnScreen uxn_screen;
|
extern UxnScreen uxn_screen;
|
||||||
extern int emu_resize(int width, int height);
|
extern int emu_resize(int width, int height);
|
||||||
|
|
||||||
void screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color);
|
void screen_rect(Uint8 *layer, int x1, int y1, int x2, int y2, int color);
|
||||||
void screen_palette(Uint8 *addr);
|
void screen_palette(Uint8 *addr);
|
||||||
void screen_resize(Uint16 width, Uint16 height);
|
void screen_resize(Uint16 width, Uint16 height);
|
||||||
void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2);
|
void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2);
|
||||||
|
|
|
@ -72,7 +72,7 @@ main(int argc, char **argv)
|
||||||
return system_error("usage", "uxncli [-v] file.rom [args..]");
|
return system_error("usage", "uxncli [-v] file.rom [args..]");
|
||||||
/* Read flags */
|
/* Read flags */
|
||||||
if(argv[i][0] == '-' && argv[i][1] == 'v')
|
if(argv[i][0] == '-' && argv[i][1] == 'v')
|
||||||
return system_version("Uxncli - Console Varvara Emulator", "9 Nov 2023");
|
return system_version("Uxncli - Console Varvara Emulator", "11 Nov 2023");
|
||||||
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
|
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
|
||||||
return system_error("Init", "Failed to initialize uxn.");
|
return system_error("Init", "Failed to initialize uxn.");
|
||||||
/* Game Loop */
|
/* Game Loop */
|
||||||
|
|
101
src/uxnemu.c
101
src/uxnemu.c
|
@ -55,8 +55,7 @@ static SDL_Thread *stdin_thread;
|
||||||
|
|
||||||
/* devices */
|
/* devices */
|
||||||
|
|
||||||
static int window_created = 0;
|
static int window_created, fullscreen, borderless;
|
||||||
static int fullscreen = 0, borderless = 0;
|
|
||||||
static Uint32 stdin_event, audio0_event, zoom = 1;
|
static Uint32 stdin_event, audio0_event, zoom = 1;
|
||||||
static Uint64 exec_deadline, deadline_interval, ms_interval;
|
static Uint64 exec_deadline, deadline_interval, ms_interval;
|
||||||
|
|
||||||
|
@ -67,25 +66,6 @@ clamp(int v, int min, int max)
|
||||||
: v;
|
: v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8
|
|
||||||
audio_dei(int instance, Uint8 *d, Uint8 port)
|
|
||||||
{
|
|
||||||
switch(port) {
|
|
||||||
case 0x2:
|
|
||||||
return audio_get_position(instance) >> 8;
|
|
||||||
case 0x3:
|
|
||||||
return audio_get_position(instance);
|
|
||||||
case 0x4:
|
|
||||||
return audio_get_vu(instance);
|
|
||||||
case 0x0:
|
|
||||||
case 0x8:
|
|
||||||
case 0xa:
|
|
||||||
case 0xc: return PEEK2(d + port);
|
|
||||||
default: return d[port];
|
|
||||||
}
|
|
||||||
return d[port];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
audio_deo(int instance, Uint8 *d, Uint8 port, Uxn *u)
|
audio_deo(int instance, Uint8 *d, Uint8 port, Uxn *u)
|
||||||
{
|
{
|
||||||
|
@ -122,8 +102,7 @@ emu_deo(Uxn *u, Uint8 addr, Uint8 value)
|
||||||
switch(d) {
|
switch(d) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
system_deo(u, &u->dev[d], p);
|
system_deo(u, &u->dev[d], p);
|
||||||
if(p > 0x7 && p < 0xe)
|
if(p > 0x7 && p < 0xe) screen_palette(&u->dev[0x8]);
|
||||||
screen_palette(&u->dev[0x8]);
|
|
||||||
break;
|
break;
|
||||||
case 0x10: console_deo(&u->dev[d], p); break;
|
case 0x10: console_deo(&u->dev[d], p); break;
|
||||||
case 0x20: screen_deo(u->ram, &u->dev[d], p); break;
|
case 0x20: screen_deo(u->ram, &u->dev[d], p); break;
|
||||||
|
@ -160,23 +139,20 @@ stdin_handler(void *p)
|
||||||
static void
|
static void
|
||||||
set_window_size(SDL_Window *window, int w, int h)
|
set_window_size(SDL_Window *window, int w, int h)
|
||||||
{
|
{
|
||||||
SDL_Point win, win_old;
|
SDL_Point win_old;
|
||||||
SDL_GetWindowPosition(window, &win.x, &win.y);
|
|
||||||
SDL_GetWindowSize(window, &win_old.x, &win_old.y);
|
SDL_GetWindowSize(window, &win_old.x, &win_old.y);
|
||||||
if(w == win_old.x && h == win_old.y) return;
|
if(w == win_old.x && h == win_old.y) return;
|
||||||
SDL_RenderClear(emu_renderer);
|
SDL_RenderClear(emu_renderer);
|
||||||
/* SDL_SetWindowPosition(window, (win.x + win_old.x / 2) - w / 2, (win.y + win_old.y / 2) - h / 2); */
|
|
||||||
SDL_SetWindowSize(window, w, h);
|
SDL_SetWindowSize(window, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_zoom(Uint8 z, int win)
|
set_zoom(Uint8 z, int win)
|
||||||
{
|
{
|
||||||
if(z >= 1) {
|
if(z < 1) return;
|
||||||
zoom = z;
|
|
||||||
if(win)
|
if(win)
|
||||||
set_window_size(emu_window, (uxn_screen.width + PAD2) * zoom, (uxn_screen.height + PAD2) * zoom);
|
set_window_size(emu_window, (uxn_screen.width + PAD2) * z, (uxn_screen.height + PAD2) * z);
|
||||||
}
|
zoom = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -184,9 +160,8 @@ set_fullscreen(int value, int win)
|
||||||
{
|
{
|
||||||
Uint32 flags = 0; /* windowed mode; SDL2 has no constant for this */
|
Uint32 flags = 0; /* windowed mode; SDL2 has no constant for this */
|
||||||
fullscreen = value;
|
fullscreen = value;
|
||||||
if(fullscreen) {
|
if(fullscreen)
|
||||||
flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
}
|
|
||||||
if(win)
|
if(win)
|
||||||
SDL_SetWindowFullscreen(emu_window, flags);
|
SDL_SetWindowFullscreen(emu_window, flags);
|
||||||
}
|
}
|
||||||
|
@ -203,7 +178,7 @@ static void
|
||||||
set_debugger(Uxn *u, int value)
|
set_debugger(Uxn *u, int value)
|
||||||
{
|
{
|
||||||
u->dev[0x0e] = value;
|
u->dev[0x0e] = value;
|
||||||
screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
|
screen_rect(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
|
||||||
screen_redraw(u);
|
screen_redraw(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +229,6 @@ emu_init(Uxn *u)
|
||||||
as.userdata = u;
|
as.userdata = u;
|
||||||
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());
|
||||||
|
|
||||||
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());
|
||||||
|
@ -279,8 +253,8 @@ static void
|
||||||
emu_restart(Uxn *u, char *rom, int soft)
|
emu_restart(Uxn *u, char *rom, int soft)
|
||||||
{
|
{
|
||||||
screen_resize(WIDTH, HEIGHT);
|
screen_resize(WIDTH, HEIGHT);
|
||||||
screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
|
screen_rect(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
|
||||||
screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
|
screen_rect(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
|
||||||
system_reboot(u, rom, soft);
|
system_reboot(u, rom, soft);
|
||||||
SDL_SetWindowTitle(emu_window, boot_rom);
|
SDL_SetWindowTitle(emu_window, boot_rom);
|
||||||
}
|
}
|
||||||
|
@ -428,37 +402,15 @@ handle_events(Uxn *u)
|
||||||
else if(event.type == SDL_JOYHATMOTION) {
|
else if(event.type == SDL_JOYHATMOTION) {
|
||||||
/* NOTE: Assuming there is only one joyhat in the controller */
|
/* NOTE: Assuming there is only one joyhat in the controller */
|
||||||
switch(event.jhat.value) {
|
switch(event.jhat.value) {
|
||||||
case SDL_HAT_UP:
|
case SDL_HAT_UP: controller_down(u, &u->dev[0x80], 0x10); break;
|
||||||
controller_down(u, &u->dev[0x80], 0x10);
|
case SDL_HAT_DOWN: controller_down(u, &u->dev[0x80], 0x20); break;
|
||||||
break;
|
case SDL_HAT_LEFT: controller_down(u, &u->dev[0x80], 0x40); break;
|
||||||
case SDL_HAT_DOWN:
|
case SDL_HAT_RIGHT: controller_down(u, &u->dev[0x80], 0x80); break;
|
||||||
controller_down(u, &u->dev[0x80], 0x20);
|
case SDL_HAT_LEFTDOWN: controller_down(u, &u->dev[0x80], 0x40 | 0x20); break;
|
||||||
break;
|
case SDL_HAT_LEFTUP: controller_down(u, &u->dev[0x80], 0x40 | 0x10); break;
|
||||||
case SDL_HAT_LEFT:
|
case SDL_HAT_RIGHTDOWN: controller_down(u, &u->dev[0x80], 0x80 | 0x20); break;
|
||||||
controller_down(u, &u->dev[0x80], 0x40);
|
case SDL_HAT_RIGHTUP: controller_down(u, &u->dev[0x80], 0x80 | 0x10); break;
|
||||||
break;
|
case SDL_HAT_CENTERED: controller_up(u, &u->dev[0x80], 0x10 | 0x20 | 0x40 | 0x80); break;
|
||||||
case SDL_HAT_RIGHT:
|
|
||||||
controller_down(u, &u->dev[0x80], 0x80);
|
|
||||||
break;
|
|
||||||
case SDL_HAT_LEFTDOWN:
|
|
||||||
controller_down(u, &u->dev[0x80], 0x40 | 0x20);
|
|
||||||
break;
|
|
||||||
case SDL_HAT_LEFTUP:
|
|
||||||
controller_down(u, &u->dev[0x80], 0x40 | 0x10);
|
|
||||||
break;
|
|
||||||
case SDL_HAT_RIGHTDOWN:
|
|
||||||
controller_down(u, &u->dev[0x80], 0x80 | 0x20);
|
|
||||||
break;
|
|
||||||
case SDL_HAT_RIGHTUP:
|
|
||||||
controller_down(u, &u->dev[0x80], 0x80 | 0x10);
|
|
||||||
break;
|
|
||||||
case SDL_HAT_CENTERED:
|
|
||||||
/* Set all directions to down */
|
|
||||||
controller_up(u, &u->dev[0x80], 0x10 | 0x20 | 0x40 | 0x80);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* Ignore */
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Console */
|
/* Console */
|
||||||
|
@ -478,7 +430,12 @@ emu_run(Uxn *u, char *rom)
|
||||||
window_created = 1;
|
window_created = 1;
|
||||||
if(fullscreen)
|
if(fullscreen)
|
||||||
window_flags = window_flags | SDL_WINDOW_FULLSCREEN_DESKTOP;
|
window_flags = window_flags | SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
emu_window = SDL_CreateWindow(rom, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (uxn_screen.width + PAD2) * zoom, (uxn_screen.height + PAD2) * zoom, window_flags);
|
emu_window = SDL_CreateWindow(rom,
|
||||||
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
(uxn_screen.width + PAD2) * zoom,
|
||||||
|
(uxn_screen.height + PAD2) * zoom,
|
||||||
|
window_flags);
|
||||||
if(emu_window == NULL)
|
if(emu_window == NULL)
|
||||||
return system_error("sdl_window", SDL_GetError());
|
return system_error("sdl_window", SDL_GetError());
|
||||||
emu_renderer = SDL_CreateRenderer(emu_window, -1, SDL_RENDERER_ACCELERATED);
|
emu_renderer = SDL_CreateRenderer(emu_window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
@ -540,7 +497,7 @@ main(int argc, char **argv)
|
||||||
/* Read flag. Right now, there can be only one. */
|
/* Read flag. Right now, there can be only one. */
|
||||||
if(argv[i][0] == '-') {
|
if(argv[i][0] == '-') {
|
||||||
if(argv[i][1] == 'v')
|
if(argv[i][1] == 'v')
|
||||||
return system_version("Uxnemu - Graphical Varvara Emulator", "9 Nov 2023");
|
return system_version("Uxnemu - Graphical Varvara Emulator", "11 Nov 2023");
|
||||||
if(argv[i][1] == '-')
|
if(argv[i][1] == '-')
|
||||||
i++;
|
i++;
|
||||||
if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)
|
if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)
|
||||||
|
@ -553,12 +510,10 @@ main(int argc, char **argv)
|
||||||
/* Start system. */
|
/* Start system. */
|
||||||
Uint8 *ram = (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8));
|
Uint8 *ram = (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8));
|
||||||
char *rom = argv[i++];
|
char *rom = argv[i++];
|
||||||
if(!system_init(&u, ram, rom)) {
|
if(!system_init(&u, ram, rom))
|
||||||
return system_error("Init", "Failed to initialize uxn.");
|
return system_error("Init", "Failed to initialize uxn.");
|
||||||
}
|
if(!system_init(&u_audio, ram, rom))
|
||||||
if(!system_init(&u_audio, ram, rom)) {
|
|
||||||
return system_error("Init", "Failed to initialize uxn.");
|
return system_error("Init", "Failed to initialize uxn.");
|
||||||
}
|
|
||||||
if(!emu_init(&u_audio))
|
if(!emu_init(&u_audio))
|
||||||
return system_error("Init", "Failed to initialize varvara.");
|
return system_error("Init", "Failed to initialize varvara.");
|
||||||
/* Game Loop */
|
/* Game Loop */
|
||||||
|
|
Loading…
Reference in New Issue