... | ... |
@@ -9,22 +9,97 @@ |
9 | 9 |
%AUTO-Y { #02 .Screen/auto DEO } |
10 | 10 |
%AUTO-YADDR { #06 .Screen/auto DEO } |
11 | 11 |
|
12 |
+%HALT { #010f DEO } |
|
13 |
+%EMIT { #18 DEO } |
|
14 |
+%PRINT { ;print-str JSR2 #0a EMIT } |
|
15 |
+%DEBUG { ;print-hex/byte JSR2 #0a EMIT } |
|
16 |
+%DEBUG2 { ;print-hex JSR2 #0a EMIT } |
|
17 |
+ |
|
18 |
+%MODALW { #0024 } |
|
19 |
+%MODALH { #0009 } |
|
20 |
+ |
|
12 | 21 |
%RTN { JMP2r } |
13 | 22 |
%2// { #01 SFT2 } |
23 |
+%8** { #30 SFT2 } |
|
14 | 24 |
|
15 | 25 |
( devices ) |
16 | 26 |
|
27 |
+|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1 |
|
17 | 28 |
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
18 | 29 |
|
19 | 30 |
( variables ) |
20 | 31 |
|
21 | 32 |
|0000 |
22 | 33 |
|
34 |
+@center |
|
35 |
+ &x $2 &y $2 |
|
36 |
+ |
|
37 |
+@modal |
|
38 |
+ &x $2 &y $2 |
|
39 |
+ |
|
23 | 40 |
( init ) |
24 | 41 |
|
25 | 42 |
|0100 ( -> ) |
26 | 43 |
|
44 |
+ .Screen/width DEI2 2// |
|
45 |
+ DUP2 .center/x STZ2 |
|
46 |
+ MODALW #31 SFT2 -- .modal/x STZ2 |
|
47 |
+ .Screen/height DEI2 2// |
|
48 |
+ DUP2 .center/y STZ2 |
|
49 |
+ MODALH #31 SFT2 -- .modal/y STZ2 |
|
50 |
+ |
|
27 | 51 |
;draw-cross JSR2 |
52 |
+ ;draw-stacks JSR2 |
|
53 |
+ |
|
54 |
+ .System/eaddr DEI2 #0000 !! ;on-error JCN2 |
|
55 |
+ |
|
56 |
+BRK |
|
57 |
+ |
|
58 |
+@on-error ( -> ) |
|
59 |
+ |
|
60 |
+ ( background ) |
|
61 |
+ #00 .Screen/auto DEO |
|
62 |
+ ;bg-icn .Screen/addr DEO2 |
|
63 |
+ MODALH #0000 |
|
64 |
+ &ver |
|
65 |
+ DUP2 8** .modal/y LDZ2 ++ .Screen/y DEO2 |
|
66 |
+ MODALW #0000 |
|
67 |
+ &hor |
|
68 |
+ DUP2 8** .modal/x LDZ2 ++ .Screen/x DEO2 |
|
69 |
+ #42 .Screen/sprite DEO |
|
70 |
+ INC2 GTH2k ,&hor JCN |
|
71 |
+ POP2 POP2 |
|
72 |
+ INC2 GTH2k ,&ver JCN |
|
73 |
+ POP2 POP2 |
|
74 |
+ |
|
75 |
+ ( corners ) |
|
76 |
+ ;corner-icn .Screen/addr DEO2 |
|
77 |
+ .modal/x LDZ2 .Screen/x DEO2 |
|
78 |
+ .modal/y LDZ2 .Screen/y DEO2 |
|
79 |
+ #42 .Screen/sprite DEO |
|
80 |
+ .modal/x LDZ2 MODALW #0001 -- 8** ++ .Screen/x DEO2 |
|
81 |
+ #52 .Screen/sprite DEO |
|
82 |
+ |
|
83 |
+ .modal/y LDZ2 MODALH #0001 -- 8** ++ .Screen/y DEO2 |
|
84 |
+ #72 .Screen/sprite DEO |
|
85 |
+ |
|
86 |
+ .modal/x LDZ2 .Screen/x DEO2 |
|
87 |
+ #62 .Screen/sprite DEO |
|
88 |
+ |
|
89 |
+ ( text ) |
|
90 |
+ .modal/x LDZ2 #0010 ++ .Screen/x DEO2 |
|
91 |
+ .modal/y LDZ2 #0010 ++ .Screen/y DEO2 |
|
92 |
+ ;error-txts/0 #4f ;draw-str JSR2 |
|
93 |
+ |
|
94 |
+ ;at-txt #4f ;draw-str JSR2 |
|
95 |
+ |
|
96 |
+ .System/eaddr DEI2 #47 ;draw-short JSR2 |
|
97 |
+ |
|
98 |
+ #0000 .System/eaddr DEO2 |
|
99 |
+ |
|
100 |
+BRK |
|
101 |
+ |
|
102 |
+@draw-stacks ( -- ) |
|
28 | 103 |
|
29 | 104 |
AUTO-YADDR |
30 | 105 |
#0010 #0000 |
... | ... |
@@ -33,23 +108,23 @@ |
33 | 108 |
#0010 .Screen/y DEO2 |
34 | 109 |
DUP2 #0018 ** #0010 ++ .Screen/x DEO2 |
35 | 110 |
DUP #fe00 LDA ( ptr ) EQU #41 + STH |
36 |
- DUP2 #fe01 ++ LDA STHr ;draw-hex JSR2 |
|
111 |
+ DUP2 #fe01 ++ LDA STHr ;draw-byte JSR2 |
|
37 | 112 |
( return stack ) |
38 | 113 |
#0028 .Screen/y DEO2 |
39 | 114 |
DUP2 #0018 ** #0010 ++ .Screen/x DEO2 |
40 | 115 |
DUP #ff00 LDA ( ptr ) EQU #41 + STH |
41 |
- DUP2 #ff01 ++ LDA STHr ;draw-hex JSR2 |
|
116 |
+ DUP2 #ff01 ++ LDA STHr ;draw-byte JSR2 |
|
42 | 117 |
INC2 GTH2k ,&wst JCN |
43 | 118 |
POP2 POP2 |
44 | 119 |
|
45 |
-BRK |
|
120 |
+RTN |
|
46 | 121 |
|
47 | 122 |
@draw-cross ( -- ) |
48 | 123 |
|
49 | 124 |
( ver ) |
50 | 125 |
AUTO-Y |
51 | 126 |
#0000 .Screen/y DEO2 |
52 |
- .Screen/width DEI2 2// .Screen/x DEO2 |
|
127 |
+ .center/x LDZ2 .Screen/x DEO2 |
|
53 | 128 |
.Screen/height DEI2 #0000 |
54 | 129 |
&ver |
55 | 130 |
#43 .Screen/pixel DEO |
... | ... |
@@ -60,7 +135,7 @@ BRK |
60 | 135 |
( hor ) |
61 | 136 |
AUTO-X |
62 | 137 |
#0000 .Screen/x DEO2 |
63 |
- .Screen/height DEI2 2// .Screen/y DEO2 |
|
138 |
+ .center/y LDZ2 .Screen/y DEO2 |
|
64 | 139 |
.Screen/width DEI2 #0000 |
65 | 140 |
&hor |
66 | 141 |
#43 .Screen/pixel DEO |
... | ... |
@@ -70,7 +145,26 @@ BRK |
70 | 145 |
|
71 | 146 |
RTN |
72 | 147 |
|
73 |
-@draw-hex ( byte color -- ) |
|
148 |
+@draw-str ( text* color -- ) |
|
149 |
+ |
|
150 |
+ AUTO-YADDR |
|
151 |
+ STH |
|
152 |
+ &while |
|
153 |
+ LDAk STHkr ,draw-char JSR |
|
154 |
+ INC2 LDAk ,&while JCN |
|
155 |
+ POP2 |
|
156 |
+ POPr |
|
157 |
+ |
|
158 |
+RTN |
|
159 |
+ |
|
160 |
+@draw-short ( short* color -- ) |
|
161 |
+ |
|
162 |
+ STH SWP STHkr ,draw-byte JSR |
|
163 |
+ STHr ,draw-byte JSR |
|
164 |
+ |
|
165 |
+RTN |
|
166 |
+ |
|
167 |
+@draw-byte ( byte color -- ) |
|
74 | 168 |
|
75 | 169 |
STH |
76 | 170 |
DUP #04 SFT ,&parse JSR STHkr ,draw-char JSR |
... | ... |
@@ -90,4 +184,31 @@ RTN |
90 | 184 |
|
91 | 185 |
JMP2r |
92 | 186 |
|
187 |
+@print-hex ( value* -- ) |
|
188 |
+ |
|
189 |
+ SWP ,&byte JSR |
|
190 |
+ &byte ( byte -- ) |
|
191 |
+ STHk #04 SFT ,&parse JSR #18 DEO |
|
192 |
+ STHr #0f AND ,&parse JSR #18 DEO |
|
193 |
+ JMP2r |
|
194 |
+ &parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r |
|
195 |
+ &above #57 ADD JMP2r |
|
196 |
+ |
|
197 |
+JMP2r |
|
198 |
+ |
|
199 |
+@error-txts |
|
200 |
+ &0 "Working-stack 20 "underflow $1 |
|
201 |
+ &1 "Return-stack 20 "underflow $1 |
|
202 |
+ &2 "Working-stack 20 "overflow $1 |
|
203 |
+ &3 "Return-stack 20 "overflow $1 |
|
204 |
+ &4 "Working-stack 20 "division 20 "by 20 "zero $1 |
|
205 |
+ &5 "Return-stack 20 "division 20 "by 20 "zero $1 |
|
206 |
+@at-txt |
|
207 |
+ ', 20 "at 20 $1 |
|
208 |
+ |
|
209 |
+@bg-icn |
|
210 |
+ ffff ffff ffff ffff |
|
211 |
+@corner-icn |
|
212 |
+ 1f7f 7fff ffff ffff |
|
213 |
+ |
|
93 | 214 |
~projects/assets/msx01x02.tal |
94 | 215 |
\ No newline at end of file |
... | ... |
@@ -14,6 +14,8 @@ 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; |
|
18 |
+ |
|
17 | 19 |
static const char *errors[] = { |
18 | 20 |
"Working-stack underflow", |
19 | 21 |
"Return-stack underflow", |
... | ... |
@@ -27,14 +29,27 @@ uxn_halt(Uxn *u, Uint8 error, Uint16 addr) |
27 | 29 |
{ |
28 | 30 |
Device *d = &u->dev[0]; |
29 | 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 |
+ DEVPOKE16(0x4, addr); |
|
43 |
+ d->dat[0x6] = error; |
|
44 |
+ vec = d->vector; |
|
45 |
+ |
|
30 | 46 |
if(vec) { |
31 | 47 |
d->vector = 0; /* need to rearm to run System/vector again */ |
32 |
- DEVPOKE16(0x4, addr); |
|
33 |
- d->dat[0x6] = error; |
|
34 | 48 |
if(error != 2) /* working stack overflow has special treatment */ |
35 | 49 |
vec += 0x0004; |
36 | 50 |
return uxn_eval(u, vec); |
37 | 51 |
} |
52 |
+ |
|
38 | 53 |
fprintf(stderr, "Halted: %s#%04x, at 0x%04x\n", errors[error], u->ram[addr], addr); |
39 | 54 |
return 0; |
40 | 55 |
} |
... | ... |
@@ -44,7 +44,6 @@ static SDL_Rect gRect; |
44 | 44 |
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole; |
45 | 45 |
static Uint8 zoom = 1; |
46 | 46 |
static Uint32 stdin_event, audio0_event; |
47 |
-static Uxn hypervisor; |
|
48 | 47 |
|
49 | 48 |
static int |
50 | 49 |
clamp(int val, int min, int max) |
... | ... |
@@ -283,10 +282,10 @@ start(Uxn *u, char *rom) |
283 | 282 |
return error("Boot", "Failed to start uxn."); |
284 | 283 |
if(!uxn_boot(u, (Stack *)(shadow + 0xfe00), (Stack *)(shadow + 0xff00), memory)) |
285 | 284 |
return error("Boot", "Failed to start uxn."); |
286 |
- if(!load(u, rom)) |
|
287 |
- return error("Boot", "Failed to load rom."); |
|
288 | 285 |
if(!load(&hypervisor, "hypervisor.rom")) |
289 | 286 |
error("Hypervisor", "No debugger found."); |
287 |
+ if(!load(u, rom)) |
|
288 |
+ return error("Boot", "Failed to load rom."); |
|
290 | 289 |
|
291 | 290 |
/* system */ devsystem = uxn_port(u, 0x0, system_dei, system_deo); |
292 | 291 |
/* console */ devconsole = uxn_port(u, 0x1, nil_dei, console_deo); |
... | ... |
@@ -306,6 +305,7 @@ start(Uxn *u, char *rom) |
306 | 305 |
/* unused */ uxn_port(u, 0xf, nil_dei, nil_deo); |
307 | 306 |
|
308 | 307 |
/* Hypervisor */ |
308 |
+ uxn_port(&hypervisor, 0x0, system_dei, system_deo); |
|
309 | 309 |
uxn_port(&hypervisor, 0x1, nil_dei, console_deo); |
310 | 310 |
uxn_port(&hypervisor, 0x2, screen_dei, screen_deo); |
311 | 311 |
|