From 60b20eaaf778e0777f19d1af943f01379fb17fa4 Mon Sep 17 00:00:00 2001 From: neauoire Date: Tue, 5 Apr 2022 20:06:42 -0700 Subject: [PATCH] Added Fn keys controls --- .clang-format | 1 + README.md | 37 ++++++++++++++++++++++++++++++++++--- src/uxn11.c | 38 ++++++++++++++++++++++++++------------ src/uxncli.c | 4 ++-- 4 files changed, 63 insertions(+), 17 deletions(-) diff --git a/.clang-format b/.clang-format index d923eb7..5475a73 100644 --- a/.clang-format +++ b/.clang-format @@ -7,6 +7,7 @@ AllowShortEnumsOnASingleLine: true AllowShortIfStatementsOnASingleLine: true AllowShortLoopsOnASingleLine: true AlwaysBreakAfterDefinitionReturnType: TopLevel +BreakBeforeTernaryOperators: false BinPackArguments: false BinPackParameters: false BreakBeforeBraces: WebKit diff --git a/README.md b/README.md index 555b3d2..665eef3 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,17 @@ To use the last page of ram(`0xff00`) to host the working stack: The stack mapping is 254 bytes of data, a byte for the pointer and a byte for an error code. -## Graphical +## Building + +### Graphical All you need is X11. -``` +```sh 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 +### Terminal If you wish to build the emulator without graphics mode: @@ -34,6 +36,12 @@ If you wish to build the emulator without graphics mode: cc src/devices/datetime.c src/devices/system.c src/devices/file.c src/uxn.c -DNDEBUG -Os -g0 -s src/uxncli.c -o bin/uxncli ``` +## Run + +```sh +bin/uxnemu bin/polycat.rom +``` + ## Devices - `00` system @@ -46,6 +54,29 @@ cc src/devices/datetime.c src/devices/system.c src/devices/file.c src/uxn.c -DND - `a0` file - `c0` datetime +## Emulator Controls + +- `F2` toggle debug +- `F4` load launcher.rom + +### Buttons + +- `LCTRL` A +- `LALT` B +- `LSHIFT` SEL +- `HOME` START + +## Need a hand? + +The following resources are a good place to start: + +* [XXIIVV — uxntal](https://wiki.xxiivv.com/site/uxntal.html) +* [XXIIVV — uxntal cheatsheet](https://wiki.xxiivv.com/site/uxntal_cheatsheet.html) +* [XXIIVV — uxntal reference](https://wiki.xxiivv.com/site/uxntal_reference.html) +* [compudanzas — uxn tutorial](https://compudanzas.net/uxn_tutorial.html) + +You can also find us in [`#uxn` on irc.esper.net](ircs://irc.esper.net:6697/#uxn). + ## Contributing Submit patches using [`git send-email`](https://git-send-email.io/) to the [~rabbits/public-inbox mailing list](https://lists.sr.ht/~rabbits/public-inbox). diff --git a/src/uxn11.c b/src/uxn11.c index db604a0..e076f73 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -41,8 +41,8 @@ console_input(Uxn *u, char c) static void console_deo(Uint8 *d, Uint8 port) { - FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr - : 0; + FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr : + 0; if(fd) { fputc(d[port], fd); fflush(fd); @@ -87,6 +87,23 @@ emu_redraw(void) XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, 0, 0, uxn_screen.width, uxn_screen.height); } +static int +emu_start(Uxn *u, char *rom) +{ + free(u->ram); + if(!uxn_boot(u, (Uint8 *)calloc(0x10300, sizeof(Uint8)))) + return emu_error("Boot", "Failed"); + if(!load_rom(u, rom)) + return emu_error("Load", "Failed"); + fprintf(stderr, "Loaded %s\n", rom); + u->dei = emu_dei; + u->deo = emu_deo; + screen_resize(&uxn_screen, WIDTH, HEIGHT); + if(!uxn_eval(u, PAGE_PROGRAM)) + return emu_error("Boot", "Failed to start rom."); + return 1; +} + static void hide_cursor(void) { @@ -137,6 +154,10 @@ emu_event(Uxn *u) KeySym sym; char buf[7]; XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0); + if(sym == XK_F2) + system_inspect(u); + if(sym == XK_F4) + emu_start(u, "boot.rom"); controller_down(u, &u->dev[0x80], get_button(sym)); controller_key(u, &u->dev[0x80], sym < 0x80 ? sym : (Uint8)buf[0]); } break; @@ -192,19 +213,12 @@ main(int argc, char **argv) char expirations[8]; struct pollfd fds[2]; static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}}; + /* TODO: Try loading launcher.rom if present */ if(argc < 2) return emu_error("Usage", "uxncli game.rom args"); /* start sequence */ - if(!uxn_boot(&u, (Uint8 *)calloc(0x10300, sizeof(Uint8)))) - return emu_error("Boot", "Failed"); - if(!load_rom(&u, argv[1])) - return emu_error("Load", "Failed"); - fprintf(stderr, "Loaded %s\n", argv[1]); - u.dei = emu_dei; - u.deo = emu_deo; - screen_resize(&uxn_screen, WIDTH, HEIGHT); - if(!uxn_eval(&u, PAGE_PROGRAM)) - return emu_error("Boot", "Failed to start rom."); + if(!emu_start(&u, argv[1])) + return emu_error("Start", "Failed"); if(!init()) return emu_error("Init", "Failed"); /* console vector */ diff --git a/src/uxncli.c b/src/uxncli.c index 64af552..bb98e6e 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -35,8 +35,8 @@ console_input(Uxn *u, char c) static void console_deo(Uint8 *d, Uint8 port) { - FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr - : 0; + FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr : + 0; if(fd) { fputc(d[port], fd); fflush(fd);