commit 2e1b56018b1aba7696fda3b7054905db0ed7ca8a
parent 97d299261f52b52caf7f7995cc1a7f86c0e107fb
Author: neauoire <aliceffekt@gmail.com>
Date: Tue, 8 Aug 2023 14:44:17 -0700
Added per-device versions
Diffstat:
12 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/src/devices/audio.h b/src/devices/audio.h
@@ -12,10 +12,9 @@ WITH REGARD TO THIS SOFTWARE.
typedef signed int Sint32;
-
#define AUDIO_VERSION 1
-#define AUDIO_DEIMASK 0x0000
-#define AUDIO_DEOMASK 0x0000
+#define AUDIO_DEIMASK 0x0014
+#define AUDIO_DEOMASK 0x8000
#define SAMPLE_FREQUENCY 44100
#define POLYPHONY 4
diff --git a/src/devices/console.h b/src/devices/console.h
@@ -11,7 +11,7 @@ WITH REGARD TO THIS SOFTWARE.
#define CONSOLE_VERSION 1
#define CONSOLE_DEIMASK 0x0000
-#define CONSOLE_DEOMASK 0x0000
+#define CONSOLE_DEOMASK 0x0300
#define CONSOLE_STD 0x1
#define CONSOLE_ARG 0x2
diff --git a/src/devices/datetime.h b/src/devices/datetime.h
@@ -10,7 +10,7 @@ WITH REGARD TO THIS SOFTWARE.
*/
#define DATETIME_VERSION 1
-#define DATETIME_DEIMASK 0x0000
+#define DATETIME_DEIMASK 0x07ff
#define DATETIME_DEOMASK 0x0000
Uint8 datetime_dei(Uxn *u, Uint8 addr);
diff --git a/src/devices/file.h b/src/devices/file.h
@@ -11,7 +11,7 @@ WITH REGARD TO THIS SOFTWARE.
#define FILE_VERSION 1
#define FILE_DEIMASK 0x0000
-#define FILE_DEOMASK 0x0000
+#define FILE_DEOMASK 0xa260
#define POLYFILEY 2
#define DEV_FILE0 0xa
diff --git a/src/devices/mouse.h b/src/devices/mouse.h
@@ -9,7 +9,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
-
#define MOUSE_VERSION 1
#define MOUSE_DEIMASK 0x0000
#define MOUSE_DEOMASK 0x0000
diff --git a/src/devices/screen.h b/src/devices/screen.h
@@ -11,8 +11,8 @@ WITH REGARD TO THIS SOFTWARE.
*/
#define SCREEN_VERSION 1
-#define SCREEN_DEIMASK 0x0000
-#define SCREEN_DEOMASK 0x0000
+#define SCREEN_DEIMASK 0x003c
+#define SCREEN_DEOMASK 0xc028
typedef struct UxnScreen {
int width, height, x1, y1, x2, y2;
diff --git a/src/devices/system.c b/src/devices/system.c
@@ -74,6 +74,15 @@ system_inspect(Uxn *u)
system_print(&u->rst, "rst");
}
+void
+system_connect(Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo)
+{
+ /* printf("%02x -> v%d %04x %04x\n", device, ver, dei, deo); */
+ dev_vers[device] = ver;
+ dei_mask[device] = dei;
+ deo_mask[device] = deo;
+}
+
/* IO */
void
diff --git a/src/devices/system.h b/src/devices/system.h
@@ -11,10 +11,11 @@ WITH REGARD TO THIS SOFTWARE.
#define SYSTEM_VERSION 1
#define SYSTEM_DEIMASK 0x0000
-#define SYSTEM_DEOMASK 0x0000
+#define SYSTEM_DEOMASK 0xff28
#define RAM_PAGES 0x10
+void system_connect(Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo);
int system_load(Uxn *u, char *filename);
void system_inspect(Uxn *u);
int system_error(char *msg, const char *err);
diff --git a/src/uxn.c b/src/uxn.c
@@ -95,4 +95,5 @@ uxn_boot(Uxn *u, Uint8 *ram)
cptr[i] = 0;
u->ram = ram;
return 1;
+
}
diff --git a/src/uxn.h b/src/uxn.h
@@ -42,8 +42,7 @@ typedef struct Uxn {
extern Uint8 emu_dei(Uxn *u, Uint8 addr);
extern void emu_deo(Uxn *u, Uint8 addr);
extern int emu_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr);
-extern Uint16 dei_mask[];
-extern Uint16 deo_mask[];
+extern Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10];
/* built-ins */
diff --git a/src/uxncli.c b/src/uxncli.c
@@ -18,8 +18,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
-Uint16 deo_mask[] = {0xc028, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
-Uint16 dei_mask[] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
+Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10];
Uint8
emu_dei(Uxn *u, Uint8 addr)
@@ -53,6 +52,12 @@ main(int argc, char **argv)
return system_error("Boot", "Failed");
if(!system_load(&u, argv[i++]))
return system_error("Load", "Failed");
+ /* connect devices */
+ system_connect(0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK);
+ system_connect(0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK);
+ system_connect(0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
+ system_connect(0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
+ system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
u.dev[0x17] = argc - i;
if(uxn_eval(&u, PAGE_PROGRAM)) {
for(; i < argc; i++) {
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -60,8 +60,7 @@ static Uint32 stdin_event, audio0_event, zoom = 1;
static Uint64 exec_deadline, deadline_interval, ms_interval;
static char *rom_path;
-Uint16 deo_mask[] = {0xff28, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
-Uint16 dei_mask[] = {0x0000, 0x0000, 0x003c, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
+Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10];
static int
clamp(int v, int min, int max)
@@ -252,6 +251,19 @@ emu_init(void)
SDL_SetRenderDrawColor(emu_renderer, 0x00, 0x00, 0x00, 0xff);
ms_interval = SDL_GetPerformanceFrequency() / 1000;
deadline_interval = ms_interval * TIMEOUT_MS;
+ /* connect devices */
+ system_connect(0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK);
+ system_connect(0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK);
+ system_connect(0x2, SCREEN_VERSION, SCREEN_DEIMASK, SCREEN_DEOMASK);
+ system_connect(0x3, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK);
+ system_connect(0x4, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK);
+ system_connect(0x5, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK);
+ system_connect(0x6, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK);
+ system_connect(0x8, CONTROL_VERSION, CONTROL_DEIMASK, CONTROL_DEOMASK);
+ system_connect(0x9, MOUSE_VERSION, MOUSE_DEIMASK, MOUSE_DEOMASK);
+ system_connect(0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
+ system_connect(0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
+ system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
return 1;
}