Use the file device load for roms
This commit is contained in:
parent
21d8f344ac
commit
a593db30f7
|
@ -7,7 +7,7 @@ An emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/site/uxn.html),
|
|||
All you need is X11.
|
||||
|
||||
```
|
||||
gcc src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -DNDEBUG -Os -g0 -s -o bin/uxn11 -lX11
|
||||
gcc src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -D_POSIX_C_SOURCE=199309L -DNDEBUG -Os -g0 -s -o bin/uxn11 -lX11
|
||||
```
|
||||
|
||||
## Terminal
|
||||
|
|
2
build.sh
2
build.sh
|
@ -12,7 +12,7 @@ mkdir -p bin
|
|||
gcc -std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11
|
||||
|
||||
# Build(release)
|
||||
# gcc src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11
|
||||
# gcc src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -D_POSIX_C_SOURCE=199309L -DNDEBUG -Os -g0 -s -o bin/uxn11 -lX11
|
||||
|
||||
echo "Running.."
|
||||
bin/uxn11 ~/roms/left.rom # etc/mouse.rom
|
||||
|
|
|
@ -215,3 +215,15 @@ file_dei(Device *d, Uint8 port)
|
|||
}
|
||||
return d->dat[port];
|
||||
}
|
||||
|
||||
/* Boot */
|
||||
|
||||
int
|
||||
load_rom(Uxn *u, char *filename)
|
||||
{
|
||||
int ret;
|
||||
file_init(uxn_file, filename, strlen(filename) + 1);
|
||||
ret = file_read(uxn_file, &u->ram[PAGE_PROGRAM], 0x10000 - PAGE_PROGRAM);
|
||||
reset(uxn_file);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -15,3 +15,4 @@ WITH REGARD TO THIS SOFTWARE.
|
|||
|
||||
void file_deo(Device *d, Uint8 port);
|
||||
Uint8 file_dei(Device *d, Uint8 port);
|
||||
int load_rom(Uxn *u, char *filename);
|
||||
|
|
35
src/uxn11.c
35
src/uxn11.c
|
@ -2,6 +2,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysymdef.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
|
@ -70,19 +71,6 @@ nil_deo(Device *d, Uint8 port)
|
|||
(void)port;
|
||||
}
|
||||
|
||||
static int
|
||||
load(Uxn *u, char *filepath)
|
||||
{
|
||||
FILE *f;
|
||||
int r;
|
||||
if(!(f = fopen(filepath, "rb"))) return 0;
|
||||
r = fread(u->ram + PAGE_PROGRAM, 1, 0x10000 - PAGE_PROGRAM, f);
|
||||
fclose(f);
|
||||
if(r < 1) return 0;
|
||||
fprintf(stderr, "Loaded %s\n", filepath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
redraw(void)
|
||||
{
|
||||
|
@ -105,20 +93,18 @@ hide_cursor(void)
|
|||
XFreePixmap(display, bitmap);
|
||||
}
|
||||
|
||||
/* usr/include/X11/keysymdef.h */
|
||||
|
||||
static Uint8
|
||||
get_button(KeySym sym)
|
||||
{
|
||||
switch(sym) {
|
||||
case 0xff52: return 0x10; /* Up */
|
||||
case 0xff54: return 0x20; /* Down */
|
||||
case 0xff51: return 0x40; /* Left */
|
||||
case 0xff53: return 0x80; /* Right */
|
||||
case 0xffe3: return 0x01; /* Control */
|
||||
case 0xffe9: return 0x02; /* Alt */
|
||||
case 0xffe1: return 0x04; /* Shift */
|
||||
case 0xff50: return 0x08; /* Home */
|
||||
case XK_Up: return 0x10;
|
||||
case XK_Down: return 0x20;
|
||||
case XK_Left: return 0x40;
|
||||
case XK_Right: return 0x80;
|
||||
case XK_Control_L: return 0x01;
|
||||
case XK_Alt_L: return 0x02;
|
||||
case XK_Shift_L: return 0x04;
|
||||
case XK_Home: return 0x08;
|
||||
}
|
||||
return 0x00;
|
||||
}
|
||||
|
@ -171,8 +157,9 @@ start(Uxn *u, char *rom)
|
|||
{
|
||||
if(!uxn_boot(u, (Uint8 *)calloc(0x10000, sizeof(Uint8))))
|
||||
return error("Boot", "Failed");
|
||||
if(!load(u, rom))
|
||||
if(!load_rom(u, rom))
|
||||
return error("Load", "Failed");
|
||||
fprintf(stderr, "Loaded %s\n", rom);
|
||||
/* system */ uxn_port(u, 0x0, system_dei, system_deo);
|
||||
/* console */ uxn_port(u, 0x1, nil_dei, console_deo);
|
||||
/* screen */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo);
|
||||
|
|
16
src/uxncli.c
16
src/uxncli.c
|
@ -74,19 +74,6 @@ run(Uxn *u)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
load(Uxn *u, char *filepath)
|
||||
{
|
||||
FILE *f;
|
||||
int r;
|
||||
if(!(f = fopen(filepath, "rb"))) return 0;
|
||||
r = fread(u->ram + PAGE_PROGRAM, 1, 0x10000 - PAGE_PROGRAM, f);
|
||||
fclose(f);
|
||||
if(r < 1) return 0;
|
||||
fprintf(stderr, "Loaded %s\n", filepath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
uxn_interrupt(void)
|
||||
{
|
||||
|
@ -126,8 +113,9 @@ main(int argc, char **argv)
|
|||
return error("Usage", "uxncli game.rom args");
|
||||
if(!start(&u))
|
||||
return error("Start", "Failed");
|
||||
if(!load(&u, argv[1]))
|
||||
if(!load_rom(&u, argv[1]))
|
||||
return error("Load", "Failed");
|
||||
fprintf(stderr, "Loaded %s\n", argv[1]);
|
||||
if(!uxn_eval(&u, PAGE_PROGRAM))
|
||||
return error("Init", "Failed");
|
||||
for(i = 2; i < argc; i++) {
|
||||
|
|
Loading…
Reference in New Issue