From aed26e5bd0e5c8f6924cdd9917af24b157aafbdb Mon Sep 17 00:00:00 2001 From: neauoire Date: Thu, 7 Apr 2022 09:33:52 -0700 Subject: [PATCH] Housekeeping --- src/devices/controller.c | 13 +------------ src/devices/controller.h | 4 +--- src/devices/datetime.c | 3 +-- src/devices/datetime.h | 3 +-- src/devices/file.c | 3 +-- src/devices/file.h | 3 +-- src/devices/mouse.c | 3 +-- src/devices/mouse.h | 3 +-- src/devices/screen.c | 3 +-- src/devices/screen.h | 3 +-- src/uxn.c | 10 +++++----- src/uxn.h | 6 +++--- src/uxn11.c | 19 +++++++++++++++---- 13 files changed, 33 insertions(+), 43 deletions(-) diff --git a/src/devices/controller.c b/src/devices/controller.c index 81bcd7e..55a7d06 100644 --- a/src/devices/controller.c +++ b/src/devices/controller.c @@ -2,8 +2,7 @@ #include "controller.h" /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -40,13 +39,3 @@ controller_key(Uxn *u, Uint8 *d, Uint8 key) d[3] = 0x00; } } - -void -controller_special(Uxn *u, Uint8 *d, Uint8 key) -{ - if(key) { - d[4] = key; - uxn_eval(u, GETVEC(d)); - d[4] = 0x00; - } -} diff --git a/src/devices/controller.h b/src/devices/controller.h index 97dcdc6..487cb86 100644 --- a/src/devices/controller.h +++ b/src/devices/controller.h @@ -1,6 +1,5 @@ /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -13,4 +12,3 @@ WITH REGARD TO THIS SOFTWARE. void controller_down(Uxn *u, Uint8 *d, Uint8 mask); void controller_up(Uxn *u, Uint8 *d, Uint8 mask); void controller_key(Uxn *u, Uint8 *d, Uint8 key); -void controller_special(Uxn *u, Uint8 *d, Uint8 key); diff --git a/src/devices/datetime.c b/src/devices/datetime.c index 8b3c1f8..e7a9f86 100644 --- a/src/devices/datetime.c +++ b/src/devices/datetime.c @@ -4,8 +4,7 @@ #include "datetime.h" /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/devices/datetime.h b/src/devices/datetime.h index 15f5f59..55ff56b 100644 --- a/src/devices/datetime.h +++ b/src/devices/datetime.h @@ -1,6 +1,5 @@ /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/devices/file.c b/src/devices/file.c index 36a1523..eb9d747 100644 --- a/src/devices/file.c +++ b/src/devices/file.c @@ -8,8 +8,7 @@ #include "file.h" /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/devices/file.h b/src/devices/file.h index 0cdb57a..5edb9f5 100644 --- a/src/devices/file.h +++ b/src/devices/file.h @@ -1,6 +1,5 @@ /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/devices/mouse.c b/src/devices/mouse.c index 2369f54..0d6d7e8 100644 --- a/src/devices/mouse.c +++ b/src/devices/mouse.c @@ -2,8 +2,7 @@ #include "mouse.h" /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/devices/mouse.h b/src/devices/mouse.h index 9c0e7af..d63ded8 100644 --- a/src/devices/mouse.h +++ b/src/devices/mouse.h @@ -1,6 +1,5 @@ /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/devices/screen.c b/src/devices/screen.c index ddebf9d..5f239de 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -4,8 +4,7 @@ #include "screen.h" /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/devices/screen.h b/src/devices/screen.h index 3e9c648..011cafe 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -1,6 +1,5 @@ /* -Copyright (c) 2021 Devine Lu Linvega -Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/uxn.c b/src/uxn.c index 6fcd39c..90cd236 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -24,7 +24,7 @@ WITH REGARD TO THIS SOFTWARE. #define PEEK(o, x) { if(bs) { PEEK16(o, x) } else { o = u->ram[(x)]; } } #define DEVR(o, x) { o = u->dei(u, x); if (bs) o = (o << 8) + u->dei(u, ((x) + 1) & 0xFF); } #define DEVW(x, y) { if (bs) { u->deo(u, (x), (y) >> 8); u->deo(u, ((x) + 1) & 0xFF, (y)); } else { u->deo(u, x, (y)); } } -#define WARP(x) { if(bs) pc = (x); else pc += (Sint8)(x); } +#define JUMP(x) { if(bs) pc = (x); else pc += (Sint8)(x); } int uxn_eval(Uxn *u, Uint16 pc) @@ -65,9 +65,9 @@ uxn_eval(Uxn *u, Uint16 pc) case 0x09: /* NEQ */ POP(a) POP(b) PUSH8(src, b != a) break; case 0x0a: /* GTH */ POP(a) POP(b) PUSH8(src, b > a) break; case 0x0b: /* LTH */ POP(a) POP(b) PUSH8(src, b < a) break; - case 0x0c: /* JMP */ POP(a) WARP(a) break; - case 0x0d: /* JCN */ POP(a) POP8(b) if(b) WARP(a) break; - case 0x0e: /* JSR */ POP(a) PUSH16(dst, pc) WARP(a) break; + case 0x0c: /* JMP */ POP(a) JUMP(a) break; + case 0x0d: /* JCN */ POP(a) POP8(b) if(b) JUMP(a) break; + case 0x0e: /* JSR */ POP(a) PUSH16(dst, pc) JUMP(a) break; case 0x0f: /* STH */ POP(a) PUSH(dst, a) break; /* Memory */ case 0x10: /* LDZ */ POP8(a) PEEK(b, a) PUSH(src, b) break; @@ -86,7 +86,7 @@ uxn_eval(Uxn *u, Uint16 pc) case 0x1c: /* AND */ POP(a) POP(b) PUSH(src, b & a) break; case 0x1d: /* ORA */ POP(a) POP(b) PUSH(src, b | a) break; case 0x1e: /* EOR */ POP(a) POP(b) PUSH(src, b ^ a) break; - case 0x1f: /* SFT */ POP8(a) POP(b) c = b >> (a & 0x0f) << ((a & 0xf0) >> 4); PUSH(src, c) break; + case 0x1f: /* SFT */ POP8(a) POP(b) PUSH(src, b >> (a & 0x0f) << ((a & 0xf0) >> 4)) break; } } return 1; diff --git a/src/uxn.h b/src/uxn.h index 57459ca..fa9a216 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -32,10 +32,10 @@ typedef struct { typedef struct Uxn { Uint8 *ram, *dev; Stack *wst, *rst; - Uint8 (*dei)(struct Uxn *u, Uint8 address); - void (*deo)(struct Uxn *u, Uint8 address, Uint8 value); + Uint8 (*dei)(struct Uxn *u, Uint8 addr); + void (*deo)(struct Uxn *u, Uint8 addr, Uint8 value); } Uxn; int uxn_boot(Uxn *u, Uint8 *ram); int uxn_eval(Uxn *u, Uint16 pc); -int uxn_halt(Uxn *u, Uint8 error, Uint16 addr); +int uxn_halt(Uxn *u, Uint8 err, Uint16 addr); diff --git a/src/uxn11.c b/src/uxn11.c index e076f73..15adf5d 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -15,6 +15,17 @@ #include "devices/file.h" #include "devices/datetime.h" +/* +Copyright (c) 2022 Devine Lu Linvega + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE. +*/ + static XImage *ximage; static Display *display; static Visual *visual; @@ -81,7 +92,7 @@ emu_deo(Uxn *u, Uint8 addr, Uint8 v) } static void -emu_redraw(void) +emu_draw(void) { screen_redraw(&uxn_screen, uxn_screen.pixels); XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, 0, 0, uxn_screen.width, uxn_screen.height); @@ -142,7 +153,7 @@ emu_event(Uxn *u) XNextEvent(display, &ev); switch(ev.type) { case Expose: - emu_redraw(); + emu_draw(); break; case ClientMessage: { XDestroyImage(ximage); @@ -213,7 +224,6 @@ 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 */ @@ -227,6 +237,7 @@ main(int argc, char **argv) while(*p) console_input(&u, *p++); console_input(&u, '\n'); } + /* timer */ fds[0].fd = XConnectionNumber(display); fds[1].fd = timerfd_create(CLOCK_MONOTONIC, 0); timerfd_settime(fds[1].fd, 0, &screen_tspec, NULL); @@ -242,7 +253,7 @@ main(int argc, char **argv) uxn_eval(&u, GETVEC(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */ } if(uxn_screen.fg.changed || uxn_screen.bg.changed) - emu_redraw(); + emu_draw(); } XDestroyImage(ximage); return 0;