Browse code

Supervisor is now watching the device page

neauoire authored on 07/01/2022 03:20:50
Showing 7 changed files
... ...
@@ -36,7 +36,7 @@ echo "Cleaning.."
36 36
 rm -f ./bin/uxnasm
37 37
 rm -f ./bin/uxnemu
38 38
 rm -f ./bin/uxncli
39
-rm -f ./bin/hypervisor.rom
39
+rm -f ./bin/supervisor.rom
40 40
 rm -f ./bin/boot.rom
41 41
 rm -f ./bin/asma.rom
42 42
 
... ...
@@ -106,9 +106,10 @@ then
106 106
 	cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/
107 107
 fi
108 108
 
109
-echo "Assembling(boot+hypervisor).."
109
+echo "Assembling(supervisor).."
110
+./bin/uxnasm projects/software/supervisor.tal bin/supervisor.rom
111
+echo "Assembling(boot).."
110 112
 ./bin/uxnasm projects/software/boot.tal bin/boot.rom
111
-./bin/uxnasm projects/software/hypervisor.tal bin/hypervisor.rom
112 113
 echo "Assembling(asma).."
113 114
 ./bin/uxnasm projects/software/asma.tal bin/asma.rom
114 115
 
115 116
similarity index 96%
116 117
rename from projects/software/hypervisor.tal
117 118
rename to projects/software/supervisor.tal
... ...
@@ -22,6 +22,9 @@
22 22
 %2//  { #01 SFT2 }
23 23
 %8**  { #30 SFT2 }
24 24
 
25
+%EADDR { #fd04 }
26
+%ECODE { #fd06 }
27
+
25 28
 ( devices )
26 29
 
27 30
 |00 @System     &vector $2 &wst      $1 &rst    $1 &eaddr  $2 &ecode  $1 &pad     $1 &r       $2 &g      $2 &b     $2 &debug  $1 &halt $1
... ...
@@ -51,7 +54,7 @@
51 54
 	;draw-cross JSR2
52 55
 	;draw-stacks JSR2
53 56
 
54
-	.System/eaddr DEI2 #0000 !! ;on-error JCN2
57
+	EADDR LDA2 #0000 !! ;on-error JCN2
55 58
 
56 59
 BRK
57 60
 
... ...
@@ -93,9 +96,9 @@ BRK
93 96
 
94 97
 	;at-txt #4f ;draw-str JSR2
95 98
 
96
-	.System/eaddr DEI2 #47 ;draw-short JSR2
99
+	EADDR LDA2 #47 ;draw-short JSR2
97 100
 
98
-	#0000 .System/eaddr DEO2
101
+	#0000 EADDR STA2
99 102
 
100 103
 BRK
101 104
 
... ...
@@ -14,7 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 14
 WITH REGARD TO THIS SOFTWARE.
15 15
 */
16 16
 
17
-Uxn hypervisor;
17
+Uxn supervisor;
18 18
 
19 19
 static const char *errors[] = {
20 20
 	"Working-stack underflow",
... ...
@@ -29,27 +29,15 @@ uxn_halt(Uxn *u, Uint8 error, Uint16 addr)
29 29
 {
30 30
 	Device *d = &u->dev[0];
31 31
 	Uint16 vec = d->vector;
32
-
33
-	/* hypervisor */
34
-	d = &hypervisor.dev[0];
35
-	vec = d->vector;
36
-	DEVPOKE16(0x4, addr);
37
-	d->dat[0x6] = error;
38
-	uxn_eval(&hypervisor, PAGE_PROGRAM);
39
-
40
-	/* core */
41
-	d = &u->dev[0];
42 32
 	DEVPOKE16(0x4, addr);
43 33
 	d->dat[0x6] = error;
44
-	vec = d->vector;
45
-
34
+	uxn_eval(&supervisor, PAGE_PROGRAM);
46 35
 	if(vec) {
47 36
 		d->vector = 0; /* need to rearm to run System/vector again */
48 37
 		if(error != 2) /* working stack overflow has special treatment */
49 38
 			vec += 0x0004;
50 39
 		return uxn_eval(u, vec);
51 40
 	}
52
-
53 41
 	fprintf(stderr, "Halted: %s#%04x, at 0x%04x\n", errors[error], u->ram[addr], addr);
54 42
 	return 0;
55 43
 }
... ...
@@ -13,4 +13,4 @@ Uint8 system_dei(Device *d, Uint8 port);
13 13
 void system_deo(Device *d, Uint8 port);
14 14
 void system_deo_special(Device *d, Uint8 port);
15 15
 
16
-extern Uxn hypervisor;
17 16
\ No newline at end of file
17
+extern Uxn supervisor;
18 18
\ No newline at end of file
... ...
@@ -108,15 +108,16 @@ err:
108 108
 /* clang-format on */
109 109
 
110 110
 int
111
-uxn_boot(Uxn *u, Uint8 *ram, Uint8 *dev, Stack *wst, Stack *rst)
111
+uxn_boot(Uxn *u, Uint8 *ram, Uint8 *devpage, Stack *wst, Stack *rst)
112 112
 {
113 113
 	Uint32 i;
114 114
 	char *cptr = (char *)u;
115 115
 	for(i = 0; i < sizeof(*u); i++)
116 116
 		cptr[i] = 0x00;
117
+	u->ram = ram;
118
+	u->devpage = devpage;
117 119
 	u->wst = wst;
118 120
 	u->rst = rst;
119
-	u->ram = ram;
120 121
 	return 1;
121 122
 }
122 123
 
... ...
@@ -124,10 +125,10 @@ Device *
124 125
 uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *d, Uint8 port), void (*deofn)(Device *d, Uint8 port))
125 126
 {
126 127
 	Device *d = &u->dev[id];
127
-	d->addr = id * 0x10;
128 128
 	d->u = u;
129 129
 	d->mem = u->ram;
130 130
 	d->dei = deifn;
131 131
 	d->deo = deofn;
132
+	d->dat = u->devpage + id * 0x10;
132 133
 	return d;
133 134
 }
... ...
@@ -16,6 +16,9 @@ typedef signed short Sint16;
16 16
 typedef unsigned int Uint32;
17 17
 
18 18
 #define PAGE_PROGRAM 0x0100
19
+#define VISOR_DEV 0xfa00
20
+#define VISOR_WST 0xfb00
21
+#define VISOR_RST 0xfc00
19 22
 #define PAGE_DEV 0xfd00
20 23
 #define PAGE_WST 0xfe00
21 24
 #define PAGE_RST 0xff00
... ...
@@ -28,25 +31,24 @@ typedef unsigned int Uint32;
28 31
 /* clang-format on */
29 32
 
30 33
 typedef struct {
31
-	Uint8 ptr;
32
-	Uint8 dat[255];
34
+	Uint8 ptr, dat[255];
33 35
 } Stack;
34 36
 
35 37
 typedef struct Device {
36 38
 	struct Uxn *u;
37
-	Uint8 addr, dat[16], *mem;
39
+	Uint8 *dat, *mem;
38 40
 	Uint16 vector;
39 41
 	Uint8 (*dei)(struct Device *d, Uint8);
40 42
 	void (*deo)(struct Device *d, Uint8);
41 43
 } Device;
42 44
 
43 45
 typedef struct Uxn {
46
+	Uint8 *ram, *devpage;
44 47
 	Stack *wst, *rst;
45
-	Uint8 *ram;
46 48
 	Device dev[16];
47 49
 } Uxn;
48 50
 
49
-int uxn_boot(Uxn *u, Uint8 *ram, Uint8 *dev, Stack *wst, Stack *rst);
51
+int uxn_boot(Uxn *u, Uint8 *ram, Uint8 *devpage, Stack *wst, Stack *rst);
50 52
 int uxn_eval(Uxn *u, Uint16 pc);
51 53
 int uxn_halt(Uxn *u, Uint8 error, Uint16 addr);
52 54
 Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));
... ...
@@ -278,12 +278,12 @@ start(Uxn *u, char *rom)
278 278
 	memory = (Uint8 *)calloc(0xffff, sizeof(Uint8));
279 279
 	shadow = (Uint8 *)calloc(0xffff, sizeof(Uint8));
280 280
 
281
-	if(!uxn_boot(&hypervisor, shadow, shadow + PAGE_DEV, (Stack *)(shadow + 0xfb00), (Stack *)(shadow + 0xfc00)))
281
+	if(!uxn_boot(&supervisor, shadow, shadow + VISOR_DEV, (Stack *)(shadow + VISOR_WST), (Stack *)(shadow + VISOR_RST)))
282 282
 		return error("Boot", "Failed to start uxn.");
283 283
 	if(!uxn_boot(u, memory, shadow + PAGE_DEV, (Stack *)(shadow + PAGE_WST), (Stack *)(shadow + PAGE_RST)))
284 284
 		return error("Boot", "Failed to start uxn.");
285
-	if(!load(&hypervisor, "hypervisor.rom"))
286
-		error("Hypervisor", "No debugger found.");
285
+	if(!load(&supervisor, "supervisor.rom"))
286
+		error("Supervisor", "No debugger found.");
287 287
 	if(!load(u, rom))
288 288
 		return error("Boot", "Failed to load rom.");
289 289
 
... ...
@@ -304,10 +304,10 @@ start(Uxn *u, char *rom)
304 304
 	/* unused   */ uxn_port(u, 0xe, nil_dei, nil_deo);
305 305
 	/* unused   */ uxn_port(u, 0xf, nil_dei, nil_deo);
306 306
 
307
-	/* Hypervisor */
308
-	uxn_port(&hypervisor, 0x0, system_dei, system_deo);
309
-	uxn_port(&hypervisor, 0x1, nil_dei, console_deo);
310
-	uxn_port(&hypervisor, 0x2, screen_dei, screen_deo);
307
+	/* Supervisor */
308
+	uxn_port(&supervisor, 0x0, system_dei, system_deo);
309
+	uxn_port(&supervisor, 0x1, nil_dei, console_deo);
310
+	uxn_port(&supervisor, 0x2, screen_dei, screen_deo);
311 311
 
312 312
 	if(!uxn_eval(u, PAGE_PROGRAM))
313 313
 		return error("Boot", "Failed to start rom.");
... ...
@@ -485,7 +485,7 @@ run(Uxn *u)
485 485
 				console_input(u, event.cbutton.button);
486 486
 		}
487 487
 		if(devsystem->dat[0xe])
488
-			uxn_eval(&hypervisor, PAGE_PROGRAM);
488
+			uxn_eval(&supervisor, PAGE_PROGRAM);
489 489
 		uxn_eval(u, devscreen->vector);
490 490
 		if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe])
491 491
 			redraw();