commit e549266

neauoire  ·  2022-04-05 02:57:44 +0000 UTC
parent 5a5ec67
Broken, cancel please hold me tight
4 files changed,  +32, -28
+1, -1
1@@ -22,4 +22,4 @@ fi
2 echo "Done."
3 
4 # echo "Running.."
5-# uxnasm etc/repl.tal bin/repl.rom && bin/uxn11 bin/repl.rom
6+bin/uxn11 ~/roms/left.rom
+5, -5
 1@@ -22,9 +22,8 @@ WITH REGARD TO THIS SOFTWARE.
 2 #define POKE(x, y) { if(bs) { u->ram[(x)] = (y) >> 8; u->ram[(x) + 1] = (y); } else { u->ram[(x)] = y; } }
 3 #define PEEK16(o, x) { o = (u->ram[(x)] << 8) + u->ram[(x) + 1]; }
 4 #define PEEK(o, x) { if(bs) { PEEK16(o, x) } else { o = u->ram[(x)]; } }
 5-#define DEVR(o, d, x) { dev = (d); o = dev->dei(dev, (x) & 0x0f); if(bs) { o = (o << 8) + dev->dei(dev, ((x) + 1) & 0x0f); } }
 6-#define DEVW8(x, y) { dev->dat[(x) & 0xf] = y; dev->deo(dev, (x) & 0x0f); }
 7-#define DEVW(d, x, y) { dev = (d); if(bs) { DEVW8((x), (y) >> 8); DEVW8((x) + 1, (y)); } else { DEVW8((x), (y)) } }
 8+#define DEVR(o, x) { o = u->dei(u, x); if (bs) o = (o << 8) + u->dei(u, ((x) + 1) & 0xFF); }
 9+#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)); } }
10 #define WARP(x) { if(bs) pc = (x); else pc += (Sint8)(x); }
11 
12 int
13@@ -78,8 +77,8 @@ uxn_eval(Uxn *u, Uint16 pc)
14 		case 0x13: /* STR */ POP8(a) POP(b) c = pc + (Sint8)a; POKE(c, b) break;
15 		case 0x14: /* LDA */ POP16(a) PEEK(b, a) PUSH(src, b) break;
16 		case 0x15: /* STA */ POP16(a) POP(b) POKE(a, b) break;
17-		case 0x16: /* DEI */ POP8(a) DEVR(b, &u->dev[a >> 4], a) PUSH(src, b) break;
18-		case 0x17: /* DEO */ POP8(a) POP(b) DEVW(&u->dev[a >> 4], a, b) break;
19+		case 0x16: /* DEI */ POP8(a) DEVR(b, a) PUSH(src, b) break;
20+		case 0x17: /* DEO */ POP8(a) POP(b) DEVW(a, b) break;
21 		/* Arithmetic */
22 		case 0x18: /* ADD */ POP(a) POP(b) PUSH(src, b + a) break;
23 		case 0x19: /* SUB */ POP(a) POP(b) PUSH(src, b - a) break;
24@@ -112,6 +111,7 @@ uxn_boot(Uxn *u, Uint8 *ram)
25 	u->ram = ram;
26 	u->wst = (Stack*)(ram + 0x10000);
27 	u->rst = (Stack*)(ram + 0x10100);
28+	u->dev2 = (Uint8*)(ram + 0x10200);
29 	return 1;
30 }
31 
+3, -1
 1@@ -37,8 +37,10 @@ typedef struct Device {
 2 } Device;
 3 
 4 typedef struct Uxn {
 5-	Uint8 *ram;
 6+	Uint8 *ram, *dev2;
 7 	Stack *wst, *rst;
 8+	Uint8 (*dei)(struct Uxn *u, Uint8 address);
 9+	void (*deo)(struct Uxn *u, Uint8 address, Uint8 value);
10 	Device dev[16];
11 } Uxn;
12 
+23, -21
 1@@ -59,16 +59,32 @@ console_deo(Device *d, Uint8 port)
 2 }
 3 
 4 static Uint8
 5-nil_dei(Device *d, Uint8 port)
 6+uxn11_dei(struct Uxn *u, Uint8 addr)
 7 {
 8-	return d->dat[port];
 9+	Uint8 p = addr & 0x0f;
10+	Device *d = &u->dev[addr >> 4];
11+	switch(addr & 0xf0) {
12+	case 0x20: screen_dei(d, p); break;
13+	case 0xa0: file_dei(d, p); break;
14+	case 0xb0: file_dei(d, p); break;
15+	case 0xc0: datetime_dei(d, p); break;
16+	}
17+	return d->dat[p];
18 }
19 
20 static void
21-nil_deo(Device *d, Uint8 port)
22+uxn11_deo(Uxn *u, Uint8 addr, Uint8 v)
23 {
24-	(void)d;
25-	(void)port;
26+	Uint8 p = addr & 0x0f;
27+	Device *d = &u->dev[addr >> 4];
28+	d->dat[p] = v;
29+	switch(addr & 0xf0) {
30+	case 0x00: system_deo(d, p); break;
31+	case 0x10: console_deo(d, p); break;
32+	case 0x20: screen_deo(d, p); break;
33+	case 0xa0: file_deo(d, p); break;
34+	case 0xb0: file_deo(d, p); break;
35+	}
36 }
37 
38 static void
39@@ -160,22 +176,8 @@ start(Uxn *u, char *rom)
40 	if(!load_rom(u, rom))
41 		return error("Load", "Failed");
42 	fprintf(stderr, "Loaded %s\n", rom);
43-	/* system   */ uxn_port(u, 0x0, nil_dei, system_deo);
44-	/* console  */ uxn_port(u, 0x1, nil_dei, console_deo);
45-	/* screen   */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo);
46-	/* empty    */ uxn_port(u, 0x3, nil_dei, nil_deo);
47-	/* empty    */ uxn_port(u, 0x4, nil_dei, nil_deo);
48-	/* empty    */ uxn_port(u, 0x5, nil_dei, nil_deo);
49-	/* empty    */ uxn_port(u, 0x6, nil_dei, nil_deo);
50-	/* empty    */ uxn_port(u, 0x7, nil_dei, nil_deo);
51-	/* control  */ devctrl = uxn_port(u, 0x8, nil_dei, nil_deo);
52-	/* mouse    */ devmouse = uxn_port(u, 0x9, nil_dei, nil_deo);
53-	/* file0    */ uxn_port(u, 0xa, file_dei, file_deo);
54-	/* file1    */ uxn_port(u, 0xb, file_dei, file_deo);
55-	/* datetime */ uxn_port(u, 0xc, datetime_dei, nil_deo);
56-	/* empty    */ uxn_port(u, 0xd, nil_dei, nil_deo);
57-	/* reserved */ uxn_port(u, 0xe, nil_dei, nil_deo);
58-	/* reserved */ uxn_port(u, 0xf, nil_dei, nil_deo);
59+	u->dei = uxn11_dei;
60+	u->deo = uxn11_deo;
61 	screen_resize(&uxn_screen, WIDTH, HEIGHT);
62 	if(!uxn_eval(u, PAGE_PROGRAM))
63 		return error("Boot", "Failed to start rom.");