... | ... |
@@ -295,11 +295,15 @@ pass1(FILE *f) |
295 | 295 |
addr += 1; |
296 | 296 |
else { |
297 | 297 |
switch(w[0]) { |
298 |
- case '|': addr = shex(w + 1); break; |
|
298 |
+ case '|': |
|
299 |
+ if(shex(w + 1) < addr) |
|
300 |
+ return error("Memory Overlap", w); |
|
301 |
+ addr = shex(w + 1); |
|
302 |
+ break; |
|
299 | 303 |
case '<': addr -= shex(w + 1); break; |
300 | 304 |
case '>': addr += shex(w + 1); break; |
301 |
- case '=': addr += 4; break; /* STR helper */ |
|
302 |
- case '~': addr += 4; break; /* LDR helper */ |
|
305 |
+ case '=': addr += 4; break; /* STR helper (lit addr-hb addr-lb str) */ |
|
306 |
+ case '~': addr += 4; break; /* LDR helper (lit addr-hb addr-lb ldr) */ |
|
303 | 307 |
case ',': addr += 3; break; |
304 | 308 |
case '.': addr += (slen(w + 1) == 2 ? 1 : 2); break; |
305 | 309 |
case '+': /* signed positive */ |
... | ... |
@@ -345,12 +349,12 @@ pass2(FILE *f) |
345 | 349 |
else if(w[0] == '+' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)shex(w + 1), 1); |
346 | 350 |
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 2) pushbyte((Sint8)(shex(w + 1) * -1), 1); |
347 | 351 |
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)(shex(w + 1) * -1), 1); |
348 |
- else if(w[0] == '=' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w+1), 1); pushbyte(findopcode(findlabellen(w+1) == 2? "STR2" : "STR"), 0); } |
|
352 |
+ else if(w[0] == '=' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w+1), 1); pushbyte(findopcode(findlabellen(w+1) == 2 ? "STR2" : "STR"), 0); } |
|
349 | 353 |
else if(w[0] == '~' && (l = findlabel(w + 1)) && l->len){ pushshort(findlabeladdr(w+1), 1); pushbyte(findopcode(findlabellen(w+1) == 2 ? "LDR2" : "LDR"), 0); } |
354 |
+ else if(w[0] == '=' && sihx(w + 1)) { pushshort(shex(w + 1), 1); pushbyte(findopcode("STR2"), 0); } |
|
355 |
+ else if(w[0] == '~' && sihx(w + 1)) { pushshort(shex(w + 1), 1); pushbyte(findopcode("LDR2"), 0); } |
|
350 | 356 |
else if((l = findlabel(w + 1))) pushshort(findlabeladdr(w+1), w[0] == ','); |
351 |
- else { |
|
352 |
- return error("Unknown label in second pass", w); |
|
353 |
- } |
|
357 |
+ else return error("Unknown label in second pass", w); |
|
354 | 358 |
/* clang-format on */ |
355 | 359 |
} |
356 | 360 |
return 1; |
... | ... |
@@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr |
20 | 20 |
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator |
21 | 21 |
|
22 | 22 |
# run |
23 |
-./bin/assembler examples/dev.ctrl.usm bin/boot.rom |
|
23 |
+./bin/assembler examples/dev.mouse.usm bin/boot.rom |
|
24 | 24 |
./bin/emulator bin/boot.rom |
... | ... |
@@ -65,7 +65,7 @@ SDL_Texture *gTexture; |
65 | 65 |
Uint32 *pixels; |
66 | 66 |
|
67 | 67 |
Screen screen; |
68 |
-Device *devconsole, *devscreen, *devmouse, *devkey, *devsprite, *devctrl; |
|
68 |
+Device *devconsole, *devscreen, *devmouse, *devkey, *devsprite, *devctrl, *devsystem; |
|
69 | 69 |
|
70 | 70 |
#pragma mark - Helpers |
71 | 71 |
|
... | ... |
@@ -368,6 +368,13 @@ sprite_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
368 | 368 |
return b1; |
369 | 369 |
} |
370 | 370 |
|
371 |
+Uint8 |
|
372 |
+system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
373 |
+{ |
|
374 |
+ printf("system_poke\n"); |
|
375 |
+ return b1; |
|
376 |
+} |
|
377 |
+ |
|
371 | 378 |
Uint8 |
372 | 379 |
ppnil(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
373 | 380 |
{ |
... | ... |
@@ -384,7 +391,7 @@ start(Uxn *u) |
384 | 391 |
{ |
385 | 392 |
int ticknext = 0; |
386 | 393 |
evaluxn(u, u->vreset); |
387 |
- loadtheme(u->ram.dat + 0xfff0); |
|
394 |
+ loadtheme(u->ram.dat + 0xfff8); |
|
388 | 395 |
if(screen.reqdraw) |
389 | 396 |
redraw(pixels, u); |
390 | 397 |
while(1) { |
... | ... |
@@ -435,10 +442,14 @@ main(int argc, char **argv) |
435 | 442 |
devkey = portuxn(&u, "key", ppnil, ppnil); |
436 | 443 |
devmouse = portuxn(&u, "mouse", ppnil, ppnil); |
437 | 444 |
|
438 |
- u.ram.dat[0xff10] = (HOR * 8 >> 8) & 0xff; |
|
439 |
- u.ram.dat[0xff11] = HOR * 8 & 0xff; |
|
440 |
- u.ram.dat[0xff12] = (VER * 8 >> 8) & 0xff; |
|
441 |
- u.ram.dat[0xff13] = VER * 8 & 0xff; |
|
445 |
+ u.devices = 7; |
|
446 |
+ devsystem = portuxn(&u, "system", ppnil, system_poke); |
|
447 |
+ |
|
448 |
+ /* Write screen size to dev/screen */ |
|
449 |
+ u.ram.dat[devscreen->addr + 0] = (HOR * 8 >> 8) & 0xff; |
|
450 |
+ u.ram.dat[devscreen->addr + 1] = HOR * 8 & 0xff; |
|
451 |
+ u.ram.dat[devscreen->addr + 2] = (VER * 8 >> 8) & 0xff; |
|
452 |
+ u.ram.dat[devscreen->addr + 3] = VER * 8 & 0xff; |
|
442 | 453 |
|
443 | 454 |
start(&u); |
444 | 455 |
quit(); |
... | ... |
@@ -4,8 +4,10 @@ |
4 | 4 |
&Sprite { pad 8 x 2 y 2 addr 2 color 1 } |
5 | 5 |
&Mouse { x 2 y 2 state 1 chord 1 } |
6 | 6 |
|
7 |
+&Label2d { x 2 y 2 color 1 addr 2 } |
|
7 | 8 |
&Point2d { x 2 y 2 } |
8 | 9 |
|
10 |
+;label Label2d |
|
9 | 11 |
;cat Point2d |
10 | 12 |
;mouse Point2d |
11 | 13 |
;pos Point2d |
... | ... |
@@ -23,42 +25,37 @@ |
23 | 25 |
|
24 | 26 |
BRK |
25 | 27 |
|
26 |
-|c000 @FRAME |
|
28 |
+|0200 @FRAME |
|
27 | 29 |
|
28 |
- ( clear last cursor ) |
|
29 |
- #10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
30 |
- ( record mouse positions ) |
|
31 |
- ~dev/mouse.x =mouse.x ~dev/mouse.y =mouse.y |
|
30 |
+ ,draw-cursor JSR |
|
31 |
+ |
|
32 | 32 |
( reset timer -> move cat tail ) |
33 |
- ~dev/mouse.state #01 NEQ ,no-click ROT JMP? POP2 |
|
33 |
+ ,no-click ~dev/mouse.state #00 EQU JMP? POP2 |
|
34 | 34 |
#50 =timer |
35 | 35 |
@no-click |
36 |
- |
|
37 | 36 |
( detect click ) |
38 |
- ~dev/mouse.state #11 NEQ ,no-click12 ROT JMP? POP2 |
|
39 |
- ,mouse12_text #0058 #0040 ,draw-label JSR |
|
37 |
+ ,no-click12 ~dev/mouse.state #11 NEQ JMP? POP2 |
|
38 |
+ #0058 #0040 #01 ,mouse12_text ,draw-label JSR |
|
40 | 39 |
#10 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
41 | 40 |
~color ,mouse12_icn #0048 #0040 ,draw-sprite JSR |
42 | 41 |
,end-click JMP |
43 | 42 |
@no-click12 |
44 |
- ~dev/mouse.state #01 NEQ ,no-click1 ROT JMP? POP2 |
|
45 |
- ,mouse1_text #0058 #0040 ,draw-label JSR |
|
43 |
+ ,no-click1 ~dev/mouse.state #01 NEQ JMP? POP2 |
|
44 |
+ #0058 #0040 #01 ,mouse1_text ,draw-label JSR |
|
46 | 45 |
#12 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
47 | 46 |
~color ,mouse1_icn #0048 #0040 ,draw-sprite JSR |
48 | 47 |
,end-click JMP |
49 | 48 |
@no-click1 |
50 |
- ~dev/mouse.state #10 NEQ ,no-click2 ROT JMP? POP2 |
|
51 |
- ,mouse2_text #0058 #0040 ,draw-label JSR |
|
49 |
+ ,no-click2 ~dev/mouse.state #10 NEQ JMP? POP2 |
|
50 |
+ #0058 #0040 #01 ,mouse2_text ,draw-label JSR |
|
52 | 51 |
#13 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
53 | 52 |
~color ,mouse2_icn #0048 #0040 ,draw-sprite JSR |
54 | 53 |
,end-click JMP |
55 | 54 |
@no-click2 |
56 | 55 |
( default ) |
57 |
- ,mouse0_text #0058 #0040 ,draw-label JSR |
|
56 |
+ #0058 #0040 #01 ,mouse0_text ,draw-label JSR |
|
58 | 57 |
~color ,mouse0_icn #0048 #0040 ,draw-sprite JSR |
59 |
- #11 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
60 | 58 |
@end-click |
61 |
- |
|
62 | 59 |
( animate ) |
63 | 60 |
,animate-polycat JSR |
64 | 61 |
( update last pos ) |
... | ... |
@@ -66,6 +63,21 @@ BRK |
66 | 63 |
|
67 | 64 |
BRK |
68 | 65 |
|
66 |
+@draw-cursor |
|
67 |
+ |
|
68 |
+ ~mouse.x ~dev/mouse.x NEQU2 |
|
69 |
+ ~mouse.y ~dev/mouse.y NEQU2 |
|
70 |
+ |
|
71 |
+ #0000 EQU2 RTS? ( Return if unchanged ) |
|
72 |
+ |
|
73 |
+ ( clear last cursor ) |
|
74 |
+ #10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
75 |
+ ( record mouse positions ) |
|
76 |
+ ~dev/mouse.x =mouse.x ~dev/mouse.y =mouse.y |
|
77 |
+ #11 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
78 |
+ |
|
79 |
+RTS |
|
80 |
+ |
|
69 | 81 |
@draw-polycat |
70 | 82 |
|
71 | 83 |
( ears ) |
... | ... |
@@ -117,14 +129,16 @@ RTS |
117 | 129 |
|
118 | 130 |
RTS |
119 | 131 |
|
120 |
-@draw-label ( text x1 y1 ) |
|
121 |
- =pos.y =pos.x |
|
132 |
+@draw-label ( x y color addr ) |
|
133 |
+ |
|
134 |
+ ( load ) =label.addr =label.color =dev/sprite.y =dev/sprite.x ~label.addr |
|
122 | 135 |
@draw-label-loop |
123 |
- ( draw ) ~pos.x ~pos.y =dev/sprite.y =dev/sprite.x DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr ~color =dev/sprite.color |
|
136 |
+ ( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr ~label.color =dev/sprite.color |
|
124 | 137 |
( incr ) #0001 ADD2 |
125 |
- ( incr ) ~pos.x #0008 ADD2 =pos.x |
|
138 |
+ ( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x |
|
126 | 139 |
DUP2 LDR #00 NEQ ,draw-label-loop ROT JMP? POP2 |
127 | 140 |
POP2 |
141 |
+ |
|
128 | 142 |
RTS |
129 | 143 |
|
130 | 144 |
@draw-sprite |
... | ... |
@@ -211,10 +225,11 @@ RTS |
211 | 225 |
@mouse2_text [ mouse _2 ] <1 .00 |
212 | 226 |
@mouse12_text [ mouse 12 ] <1 .00 |
213 | 227 |
|
228 |
+|d000 @ERROR BRK |
|
229 |
+ |
|
214 | 230 |
|FF10 ;dev/screen Screen |
215 | 231 |
|FF20 ;dev/sprite Sprite |
216 | 232 |
|FF50 ;dev/mouse Mouse |
217 | 233 |
|
218 |
-|d000 @ERROR BRK |
|
219 |
-|FFF0 [ 0f85 0fd5 0fb5 ] ( palette ) |
|
220 |
-|FFFA .RESET .FRAME .ERROR |
|
234 |
+|FFF0 .RESET .FRAME .ERROR |
|
235 |
+|FFF8 [ 0f85 0fd5 0fb5 ] ( palette ) |
... | ... |
@@ -149,5 +149,5 @@ RTS |
149 | 149 |
|FF10 ;dev/screen Screen |
150 | 150 |
|FF20 ;dev/sprite Sprite |
151 | 151 |
|
152 |
-|FFF0 [ 0f0f 0fff 0ff0 ] ( palette ) |
|
153 |
-|FFFA .RESET .FRAME .ERROR ( vectors ) |
|
154 | 152 |
\ No newline at end of file |
153 |
+|FFF0 .RESET .FRAME .ERROR ( vectors ) |
|
154 |
+|FFF8 [ 0f0f 0fff 0ff0 ] ( palette ) |
|
155 | 155 |
\ No newline at end of file |
... | ... |
@@ -193,9 +193,9 @@ loaduxn(Uxn *u, char *filepath) |
193 | 193 |
if(!(f = fopen(filepath, "rb"))) |
194 | 194 |
return haltuxn(u, "Missing input rom.", 0); |
195 | 195 |
fread(u->ram.dat, sizeof(u->ram.dat), 1, f); |
196 |
- u->vreset = mempeek16(u, 0xfffa); |
|
197 |
- u->vframe = mempeek16(u, 0xfffc); |
|
198 |
- u->verror = mempeek16(u, 0xfffe); |
|
196 |
+ u->vreset = mempeek16(u, 0xfff0); |
|
197 |
+ u->vframe = mempeek16(u, 0xfff2); |
|
198 |
+ u->verror = mempeek16(u, 0xfff4); |
|
199 | 199 |
printf("Uxn loaded[%s] vrst:%04x vfrm:%04x verr:%04x.\n", |
200 | 200 |
filepath, |
201 | 201 |
u->vreset, |