... | ... |
@@ -53,11 +53,10 @@ evaluxn(u, u->vframe); /* Each frame |
53 | 53 |
``` |
54 | 54 |
( hello world ) |
55 | 55 |
|
56 |
-:dev/w fff9 ( const write port ) |
|
56 |
+&Console { pad 8 stdio 1 } |
|
57 | 57 |
|
58 | 58 |
|0100 @RESET |
59 | 59 |
|
60 |
- #00 =dev/w ( set dev/write to console ) |
|
61 | 60 |
,text1 ,print-label JSR ( print to console ) |
62 | 61 |
|
63 | 62 |
BRK |
... | ... |
@@ -65,7 +64,7 @@ BRK |
65 | 64 |
@print-label ( text ) |
66 | 65 |
|
67 | 66 |
@cliloop |
68 |
- DUP2 LDR IOW ( write pointer value to console ) |
|
67 |
+ DUP2 LDR =dev/console.stdio ( write pointer value to console ) |
|
69 | 68 |
#0001 ADD2 ( increment string pointer ) |
70 | 69 |
DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2 ( while *ptr!=0 goto loop ) |
71 | 70 |
POP2 |
... | ... |
@@ -77,6 +76,8 @@ RTS |
77 | 76 |
|c000 @FRAME |
78 | 77 |
|d000 @ERROR |
79 | 78 |
|
79 |
+|FF00 ;dev/console Console |
|
80 |
+ |
|
80 | 81 |
|FFF0 [ f3f0 f30b f30a ] ( palette ) |
81 | 82 |
|FFFA .RESET .FRAME .ERROR |
82 | 83 |
``` |
... | ... |
@@ -113,10 +114,6 @@ A device that works like a NES controller, each button is a bit from a single by |
113 | 114 |
- GUI: |
114 | 115 |
- Line routine |
115 | 116 |
|
116 |
-### Devices redesign |
|
117 |
- |
|
118 |
-- Possibly remove |
|
119 |
- |
|
120 | 117 |
### Assembler |
121 | 118 |
|
122 | 119 |
- Includes |
... | ... |
@@ -44,7 +44,7 @@ Program p; |
44 | 44 |
/* clang-format off */ |
45 | 45 |
|
46 | 46 |
char ops[][4] = { |
47 |
- "BRK", "NOP", "LIT", "---", "IOR", "IOW", "LDR", "STR", |
|
47 |
+ "BRK", "NOP", "LIT", "---", "---", "---", "LDR", "STR", |
|
48 | 48 |
"JMP", "JSR", "---", "RTS", "AND", "ORA", "ROL", "ROR", |
49 | 49 |
"POP", "DUP", "SWP", "OVR", "ROT", "WSR", "RSW", "---", |
50 | 50 |
"ADD", "SUB", "MUL", "DIV", "EQU", "NEQ", "GTH", "LTH" |
... | ... |
@@ -65,7 +65,7 @@ SDL_Texture *gTexture; |
65 | 65 |
Uint32 *pixels; |
66 | 66 |
|
67 | 67 |
Screen screen; |
68 |
-Device *devconsole, *devscreen, *devmouse, *devkey, *devsprite, *devcontroller; |
|
68 |
+Device *devconsole, *devscreen, *devmouse, *devkey, *devsprite, *devctrl; |
|
69 | 69 |
|
70 | 70 |
#pragma mark - Helpers |
71 | 71 |
|
... | ... |
@@ -256,7 +256,7 @@ void |
256 | 256 |
domouse(Uxn *u, SDL_Event *event) |
257 | 257 |
{ |
258 | 258 |
Uint8 flag = 0x00; |
259 |
- Uint16 addr = 0xff50; /* TODO: get dynamically */ |
|
259 |
+ Uint16 addr = devmouse->addr; |
|
260 | 260 |
Uint16 x = clamp(event->motion.x / ZOOM - PAD * 8, 0, HOR * 8 - 1); |
261 | 261 |
Uint16 y = clamp(event->motion.y / ZOOM - PAD * 8, 0, VER * 8 - 1); |
262 | 262 |
u->ram.dat[addr + 0] = (x >> 8) & 0xff; |
... | ... |
@@ -283,16 +283,17 @@ domouse(Uxn *u, SDL_Event *event) |
283 | 283 |
} |
284 | 284 |
|
285 | 285 |
void |
286 |
-dotext(SDL_Event *event) |
|
286 |
+dotext(Uxn *u, SDL_Event *event) |
|
287 | 287 |
{ |
288 | 288 |
int i; |
289 |
+ Uint16 addr = devkey->addr; |
|
289 | 290 |
if(SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL) |
290 | 291 |
return; |
291 | 292 |
for(i = 0; i < SDL_TEXTINPUTEVENT_TEXT_SIZE; ++i) { |
292 | 293 |
char c = event->text.text[i]; |
293 | 294 |
if(c < ' ' || c > '~') |
294 | 295 |
break; |
295 |
- devkey->mem[0] = c; |
|
296 |
+ u->ram.dat[addr] = c; |
|
296 | 297 |
} |
297 | 298 |
} |
298 | 299 |
|
... | ... |
@@ -300,8 +301,8 @@ void |
300 | 301 |
doctrl(Uxn *u, SDL_Event *event, int z) |
301 | 302 |
{ |
302 | 303 |
Uint8 flag = 0x00; |
303 |
- Uint16 addr = 0xff30; /* TODO: get dynamically */ |
|
304 |
- if(z && event->key.keysym.sym == SDLK_h) |
|
304 |
+ Uint16 addr = devctrl->addr; |
|
305 |
+ if(z && event->key.keysym.sym == SDLK_h && SDL_GetModState() & KMOD_LCTRL) |
|
305 | 306 |
GUIDES = !GUIDES; |
306 | 307 |
if(SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL) |
307 | 308 |
flag = 0x01; |
... | ... |
@@ -310,11 +311,11 @@ doctrl(Uxn *u, SDL_Event *event, int z) |
310 | 311 |
switch(event->key.keysym.sym) { |
311 | 312 |
case SDLK_BACKSPACE: |
312 | 313 |
flag = 0x04; |
313 |
- if(z) devkey->mem[0] = 0x08; |
|
314 |
+ if(z) u->ram.dat[0xff40] = 0x08; |
|
314 | 315 |
break; |
315 | 316 |
case SDLK_RETURN: |
316 | 317 |
flag = 0x08; |
317 |
- if(z) devkey->mem[0] = 0x0d; |
|
318 |
+ if(z) u->ram.dat[0xff40] = 0x0d; |
|
318 | 319 |
break; |
319 | 320 |
case SDLK_UP: flag = 0x10; break; |
320 | 321 |
case SDLK_DOWN: flag = 0x20; break; |
... | ... |
@@ -378,44 +379,6 @@ ppnil(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
378 | 379 |
return b1; |
379 | 380 |
} |
380 | 381 |
|
381 |
-Uint8 |
|
382 |
-defaultrw(Device *d, Memory *m, Uint8 b) |
|
383 |
-{ |
|
384 |
- (void)m; |
|
385 |
- return d->mem[b]; |
|
386 |
-} |
|
387 |
- |
|
388 |
-Uint8 |
|
389 |
-consolew(Device *d, Memory *m, Uint8 b) |
|
390 |
-{ |
|
391 |
- if(b) |
|
392 |
- printf("%c", b); |
|
393 |
- fflush(stdout); |
|
394 |
- (void)d; |
|
395 |
- (void)m; |
|
396 |
- return 0; |
|
397 |
-} |
|
398 |
- |
|
399 |
-Uint8 |
|
400 |
-spritew(Device *d, Memory *m, Uint8 b) |
|
401 |
-{ |
|
402 |
- d->mem[d->ptr++] = b; |
|
403 |
- if(d->ptr == 7) { |
|
404 |
- Uint16 x = (d->mem[2] << 8) + d->mem[3]; |
|
405 |
- Uint16 y = (d->mem[0] << 8) + d->mem[1]; |
|
406 |
- Uint16 a = (d->mem[4] << 8) + d->mem[5]; |
|
407 |
- Uint8 source = d->mem[6] >> 4 & 0xf; |
|
408 |
- Uint8 *layer = source % 2 ? screen.fg : screen.bg; |
|
409 |
- if(source / 2) |
|
410 |
- paintchr(layer, x, y, &m->dat[a]); |
|
411 |
- else |
|
412 |
- painticn(layer, x, y, &m->dat[a], d->mem[6] & 0xf); |
|
413 |
- screen.reqdraw = 1; |
|
414 |
- d->ptr = 0; |
|
415 |
- } |
|
416 |
- return 0; |
|
417 |
-} |
|
418 |
- |
|
419 | 382 |
#pragma mark - Generics |
420 | 383 |
|
421 | 384 |
int |
... | ... |
@@ -432,14 +395,13 @@ start(Uxn *u) |
432 | 395 |
if(tick < ticknext) |
433 | 396 |
SDL_Delay(ticknext - tick); |
434 | 397 |
ticknext = tick + (1000 / FPS); |
435 |
- devkey->mem[0] = 0x00; /* TODO: cleanup */ |
|
436 | 398 |
while(SDL_PollEvent(&event) != 0) { |
437 | 399 |
switch(event.type) { |
438 | 400 |
case SDL_QUIT: quit(); break; |
439 | 401 |
case SDL_MOUSEBUTTONUP: |
440 | 402 |
case SDL_MOUSEBUTTONDOWN: |
441 | 403 |
case SDL_MOUSEMOTION: domouse(u, &event); break; |
442 |
- case SDL_TEXTINPUT: dotext(&event); break; |
|
404 |
+ case SDL_TEXTINPUT: dotext(u, &event); break; |
|
443 | 405 |
case SDL_KEYDOWN: doctrl(u, &event, 1); break; |
444 | 406 |
case SDL_KEYUP: doctrl(u, &event, 0); break; |
445 | 407 |
case SDL_WINDOWEVENT: |
... | ... |
@@ -468,12 +430,12 @@ main(int argc, char **argv) |
468 | 430 |
if(!init()) |
469 | 431 |
return error("Init", "Failed"); |
470 | 432 |
|
471 |
- devconsole = portuxn(&u, "console", defaultrw, consolew, ppnil, console_poke); |
|
472 |
- devscreen = portuxn(&u, "screen", defaultrw, defaultrw, ppnil, screen_poke); |
|
473 |
- devsprite = portuxn(&u, "sprite", defaultrw, spritew, ppnil, sprite_poke); |
|
474 |
- devcontroller = portuxn(&u, "controller", defaultrw, defaultrw, ppnil, ppnil); |
|
475 |
- devkey = portuxn(&u, "key", defaultrw, consolew, ppnil, ppnil); |
|
476 |
- devmouse = portuxn(&u, "mouse", defaultrw, defaultrw, ppnil, ppnil); |
|
433 |
+ devconsole = portuxn(&u, "console", ppnil, console_poke); |
|
434 |
+ devscreen = portuxn(&u, "screen", ppnil, screen_poke); |
|
435 |
+ devsprite = portuxn(&u, "sprite", ppnil, sprite_poke); |
|
436 |
+ devctrl = portuxn(&u, "controller", ppnil, ppnil); |
|
437 |
+ devkey = portuxn(&u, "key", ppnil, ppnil); |
|
438 |
+ devmouse = portuxn(&u, "mouse", ppnil, ppnil); |
|
477 | 439 |
|
478 | 440 |
u.ram.dat[0xff10] = (HOR * 8 >> 8) & 0xff; |
479 | 441 |
u.ram.dat[0xff11] = HOR * 8 & 0xff; |
5 | 5 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,134 @@ |
1 |
+( dev/key ) |
|
2 |
+ |
|
3 |
+&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 } |
|
4 |
+&Sprite { pad 8 x 2 y 2 addr 2 color 1 } |
|
5 |
+&Keyboard { key 1 } |
|
6 |
+ |
|
7 |
+&Point2d { x 2 y 2 } |
|
8 |
+&Rect2d { x1 2 y1 2 x2 2 y2 2 } |
|
9 |
+ |
|
10 |
+;pos Point2d |
|
11 |
+;rect Rect2d |
|
12 |
+;color 1 |
|
13 |
+;textlen 2 |
|
14 |
+ |
|
15 |
+|0100 @RESET |
|
16 |
+ |
|
17 |
+ ,redraw JSR |
|
18 |
+ |
|
19 |
+BRK |
|
20 |
+ |
|
21 |
+|c000 @FRAME |
|
22 |
+ |
|
23 |
+ ~dev/key #00 EQU ,key-end ROT JMP? POP2 |
|
24 |
+ ( is backspace ) |
|
25 |
+ ~dev/key #08 NEQ ,no-key-back ROT JMP? POP2 |
|
26 |
+ #00 ,body ~textlen ADD2 STR |
|
27 |
+ ~textlen #0001 SUB2 =textlen |
|
28 |
+ ,key-end JMP |
|
29 |
+ @no-key-back |
|
30 |
+ |
|
31 |
+ ~textlen #0001 ADD2 =textlen |
|
32 |
+ ~dev/key ,body ~textlen ADD2 STR |
|
33 |
+ ,redraw JSR |
|
34 |
+ #00 =dev/key ( release key ) |
|
35 |
+ @key-end |
|
36 |
+ |
|
37 |
+BRK |
|
38 |
+ |
|
39 |
+@redraw |
|
40 |
+ |
|
41 |
+ #02 =color |
|
42 |
+ #0040 #0040 #0090 #0090 ,fill-rect JSR |
|
43 |
+ #06 =color |
|
44 |
+ ,body #0040 #0040 ,draw-label-multiline JSR |
|
45 |
+ |
|
46 |
+RTS |
|
47 |
+ |
|
48 |
+@draw-label-multiline ( text x1 y1 ) |
|
49 |
+ =pos.y =pos.x |
|
50 |
+ @draw-label-multiline-loop |
|
51 |
+ ( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr |
|
52 |
+ ~pos.y =dev/sprite.y |
|
53 |
+ ~pos.x =dev/sprite.x |
|
54 |
+ ~color =dev/sprite.color |
|
55 |
+ ( incr ) #0001 ADD2 |
|
56 |
+ ( incr ) ~pos.x #0008 ADD2 =pos.x |
|
57 |
+ |
|
58 |
+ ( detect linebreaks ) |
|
59 |
+ DUP2 LDR #0d NEQ ,no-return ROT JMP? POP2 |
|
60 |
+ #0048 =pos.x |
|
61 |
+ ~pos.y #0008 ADD2 =pos.y |
|
62 |
+ @no-return |
|
63 |
+ |
|
64 |
+ DUP2 LDR #00 NEQ ,draw-label-multiline-loop ROT JMP? POP2 |
|
65 |
+ POP2 |
|
66 |
+RTS |
|
67 |
+ |
|
68 |
+@fill-rect ( x1 y1 x2 y2 ) |
|
69 |
+ =rect.y2 =rect.x2 ( stash x1 y1 ) =rect.y1 DUP2 WSR2 =rect.x1 |
|
70 |
+ @fill-rect-ver |
|
71 |
+ RSW2 DUP2 =rect.x1 WSR2 |
|
72 |
+ ~rect.y1 =dev/screen.y |
|
73 |
+ @fill-rect-hor |
|
74 |
+ ( draw ) ~rect.x1 =dev/screen.x ~color =dev/screen.color |
|
75 |
+ ( incr ) ~rect.x1 #0001 ADD2 DUP2 =rect.x1 |
|
76 |
+ ~rect.x2 LTH2 ,fill-rect-hor ROT JMP? POP2 |
|
77 |
+ ~rect.y1 #0001 ADD2 DUP2 =rect.y1 |
|
78 |
+ ~rect.y2 LTH2 ,fill-rect-ver ROT JMP? POP2 |
|
79 |
+ RSW2 POP2 |
|
80 |
+RTS |
|
81 |
+ |
|
82 |
+@draw-sprite |
|
83 |
+ =dev/sprite.x |
|
84 |
+ =dev/sprite.y |
|
85 |
+ =dev/sprite.addr |
|
86 |
+ =dev/sprite.color |
|
87 |
+ RTS |
|
88 |
+ |
|
89 |
+@font ( spectrum-zx font ) |
|
90 |
+[ |
|
91 |
+ 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 |
|
92 |
+ 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 |
|
93 |
+ 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 |
|
94 |
+ 0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800 |
|
95 |
+ 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 |
|
96 |
+ 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 |
|
97 |
+ 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 |
|
98 |
+ 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000 |
|
99 |
+ 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 |
|
100 |
+ 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000 |
|
101 |
+ 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800 |
|
102 |
+ 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000 |
|
103 |
+ 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00 |
|
104 |
+ 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 |
|
105 |
+ 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810 |
|
106 |
+ 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800 |
|
107 |
+ 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 |
|
108 |
+ 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00 |
|
109 |
+ 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200 |
|
110 |
+ 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 |
|
111 |
+ 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00 |
|
112 |
+ 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200 |
|
113 |
+ 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00 |
|
114 |
+ 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00 |
|
115 |
+ 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00 |
|
116 |
+ 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c |
|
117 |
+ 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400 |
|
118 |
+ 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800 |
|
119 |
+ 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800 |
|
120 |
+ 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800 |
|
121 |
+ 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00 |
|
122 |
+ 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c |
|
123 |
+] |
|
124 |
+ |
|
125 |
+@body [ ] |
|
126 |
+ |
|
127 |
+|d000 @ERROR BRK |
|
128 |
+ |
|
129 |
+|FF10 ;dev/screen Screen |
|
130 |
+|FF20 ;dev/sprite Sprite |
|
131 |
+|FF40 ;dev/key Keyboard |
|
132 |
+ |
|
133 |
+|FFF0 [ f0ff f00f f00f ] ( palette ) |
|
134 |
+|FFFA .RESET .FRAME .ERROR |
5 | 5 |
deleted file mode 100644 |
... | ... |
@@ -1,233 +0,0 @@ |
1 |
-( mouse ) |
|
2 |
- |
|
3 |
-:dev/r fff8 ( std read port ) |
|
4 |
-:dev/w fff9 ( std write port ) |
|
5 |
- |
|
6 |
-&Point2d { x 2 y 2 } |
|
7 |
-&Window2d { x1 2 y1 2 x2 2 y2 2 } |
|
8 |
- |
|
9 |
-;pos Point2d |
|
10 |
-;mouse Point2d |
|
11 |
-;scenter Point2d |
|
12 |
-;win Window2d |
|
13 |
- |
|
14 |
-( drawing ) ;color 1 ;x1 2 ;x2 2 ;y1 2 ;y2 2 ;i 2 |
|
15 |
-;state 1 ;textlen 2 |
|
16 |
- |
|
17 |
-|0100 @RESET |
|
18 |
- |
|
19 |
- #01 =dev/r ( read screen for size ) |
|
20 |
- #02 =dev/w ( write to screen ) |
|
21 |
- |
|
22 |
- #08 =color |
|
23 |
- ,paint-pattern JSR |
|
24 |
- |
|
25 |
- #01 =dev/w ( write to screen ) |
|
26 |
- |
|
27 |
- #00 IOR2 #0002 DIV2 =scenter.x |
|
28 |
- #02 IOR2 #0002 DIV2 =scenter.y |
|
29 |
- |
|
30 |
- ~scenter.x #0050 SUB2 |
|
31 |
- ~scenter.y #0030 SUB2 |
|
32 |
- ~scenter.x #0050 ADD2 |
|
33 |
- ~scenter.y #0030 ADD2 ,paint-window JSR |
|
34 |
- |
|
35 |
- #05 =dev/r ( set dev/read mouse ) |
|
36 |
- #02 =dev/w ( set dev/write to sprite ) |
|
37 |
- |
|
38 |
- #09 =color |
|
39 |
- |
|
40 |
-BRK |
|
41 |
- |
|
42 |
-|c000 @FRAME |
|
43 |
- |
|
44 |
- ( clear last cursor ) |
|
45 |
- #10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
46 |
- ( record mouse positions ) |
|
47 |
- #05 =dev/r ( set dev/read mouse ) |
|
48 |
- #00 IOR2 =mouse.x |
|
49 |
- #02 IOR2 =mouse.y |
|
50 |
- #11 =state |
|
51 |
- |
|
52 |
- #04 IOR #01 NEQ ,no-touch ROT JMP? POP2 |
|
53 |
- #13 =state |
|
54 |
- @no-touch |
|
55 |
- |
|
56 |
- ( clear window ) |
|
57 |
- |
|
58 |
- #04 =dev/r ( set dev/read mouse ) |
|
59 |
- #00 IOR #00 EQU ,key-end ROT JMP? POP2 |
|
60 |
- |
|
61 |
- ( is backspace ) |
|
62 |
- #00 IOR #08 NEQ ,no-key-back ROT JMP? POP2 |
|
63 |
- #00 ,body ~textlen ADD2 STR |
|
64 |
- ~textlen #0001 SUB2 =textlen |
|
65 |
- ,redraw-body-label JSR |
|
66 |
- ,key-end JMP |
|
67 |
- @no-key-back |
|
68 |
- |
|
69 |
- ~textlen #0001 ADD2 =textlen |
|
70 |
- #00 IOR ,body ~textlen ADD2 STR |
|
71 |
- ,redraw-body-label JSR |
|
72 |
- @key-end |
|
73 |
- |
|
74 |
- ( draw mouse ) |
|
75 |
- ~state ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
76 |
- |
|
77 |
-BRK |
|
78 |
- |
|
79 |
-@redraw-body-label |
|
80 |
- |
|
81 |
- #02 =color |
|
82 |
- #01 =dev/w ( write to screen ) |
|
83 |
- ~win.x1 #0004 ADD2 ~win.y1 #0004 ADD2 ~win.x2 #0010 SUB2 ~win.y2 #0010 SUB2 ,fill-rect JSR |
|
84 |
- #02 =dev/w ( write to sprite ) |
|
85 |
- #06 =color |
|
86 |
- ,body ~win.x1 #0018 ADD2 ~scenter.y ,draw-label JSR |
|
87 |
- |
|
88 |
-RTS |
|
89 |
- |
|
90 |
-@paint-pattern ( nil ) |
|
91 |
- |
|
92 |
- #01 =dev/r ( read screen for size ) |
|
93 |
- #02 =dev/w ( write to sprite ) |
|
94 |
- |
|
95 |
- #0000 |
|
96 |
- @paint-pattern-loop-hor |
|
97 |
- #0000 |
|
98 |
- @paint-pattern-loop |
|
99 |
- ( draw ) OVR2 IOW2 DUP2 IOW2 ,pattern IOW2 ~color IOW |
|
100 |
- ( incr ) #0008 ADD2 DUP2 |
|
101 |
- #00 IOR2 LTH2 ,paint-pattern-loop ROT JMP? POP2 |
|
102 |
- POP2 |
|
103 |
- ( incr ) #0008 ADD2 DUP2 |
|
104 |
- #02 IOR2 LTH2 ,paint-pattern-loop-hor ROT JMP? POP2 |
|
105 |
- POP2 |
|
106 |
- |
|
107 |
-RTS |
|
108 |
- |
|
109 |
-@paint-window ( name wx1 wy1 wx2 wy2 ) |
|
110 |
- |
|
111 |
- =win.y2 =win.x2 =win.y1 =win.x1 |
|
112 |
- |
|
113 |
- ( Draw shadow ) |
|
114 |
- #01 =color |
|
115 |
- ~win.x2 ~win.y1 #0003 ADD2 ~win.x2 #0003 ADD2 ~win.y2 #0003 ADD2 ,fill-rect JSR |
|
116 |
- ~win.x1 #0003 ADD2 ~win.y2 ~win.x2 #0003 ADD2 ~win.y2 #0003 ADD2 ,fill-rect JSR |
|
117 |
- ( Fill background ) |
|
118 |
- #02 =color |
|
119 |
- ~win.x1 ~win.y1 ~win.x2 ~win.y2 ,fill-rect JSR |
|
120 |
- ( draw outline ) |
|
121 |
- #01 =color |
|
122 |
- ~win.x1 ~win.y1 ~win.x2 ~win.y2 ,line-rect JSR |
|
123 |
- #01 =color |
|
124 |
- ~win.x1 #0002 ADD2 ~win.y1 #0002 ADD2 ~win.x2 #0002 SUB2 ~win.y2 #0002 SUB2 ,line-rect JSR |
|
125 |
- |
|
126 |
-RTS |
|
127 |
- |
|
128 |
-@draw-label ( text x1 y1 ) |
|
129 |
- |
|
130 |
- =pos.y =pos.x |
|
131 |
- @draw-label-loop |
|
132 |
- |
|
133 |
- ( draw ) ~pos.x ~pos.y IOW2 IOW2 DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 IOW2 ~color IOW |
|
134 |
- ( incr ) #0001 ADD2 |
|
135 |
- ( incr ) ~pos.x #0008 ADD2 =pos.x |
|
136 |
- |
|
137 |
- ( detect linebreaks ) |
|
138 |
- DUP2 LDR #0d NEQ ,no-return ROT JMP? POP2 |
|
139 |
- #0048 =pos.x |
|
140 |
- ( incr ) ~pos.y #0008 ADD2 =pos.y |
|
141 |
- @no-return |
|
142 |
- |
|
143 |
- DUP2 LDR #00 NEQ ,draw-label-loop ROT JMP? POP2 |
|
144 |
- POP2 |
|
145 |
- |
|
146 |
-RTS |
|
147 |
- |
|
148 |
-@fill-rect ( x1 y1 x2 y2 ) |
|
149 |
- =y2 =x2 ( stash x1 y1 ) =y1 DUP2 WSR2 =x1 |
|
150 |
- @fill-rect-ver |
|
151 |
- RSW2 DUP2 =x1 WSR2 |
|
152 |
- @fill-rect-hor |
|
153 |
- ( draw ) ~x1 ~y1 IOW2 IOW2 ~color IOW |
|
154 |
- ( incr ) ~x1 #0001 ADD2 DUP2 =x1 |
|
155 |
- ~x2 LTH2 ,fill-rect-hor ROT JMP? POP2 |
|
156 |
- ~y1 #0001 ADD2 DUP2 =y1 |
|
157 |
- ~y2 LTH2 ,fill-rect-ver ROT JMP? POP2 |
|
158 |
- RSW2 POP2 |
|
159 |
-RTS |
|
160 |
- |
|
161 |
-@line-rect ( x1 y1 x2 y2 ) |
|
162 |
- =y2 =x2 ( stash x1 y1 ) DUP2 WSR2 =y1 DUP2 WSR2 =x1 |
|
163 |
- @line-rect-hor |
|
164 |
- ( draw ) ~x1 ~y1 IOW2 IOW2 ~color IOW |
|
165 |
- ( draw ) ~x1 ~y2 IOW2 IOW2 ~color IOW |
|
166 |
- ( incr ) ~x1 #0001 ADD2 DUP2 =x1 |
|
167 |
- ~x2 #0001 ADD2 LTH2 ,line-rect-hor ROT JMP? POP2 |
|
168 |
- ( restore x1 y1 ) RSW2 =x1 RSW2 =y1 |
|
169 |
- @line-rect-ver |
|
170 |
- ( incr ) ~y1 #0001 ADD2 DUP2 =y1 |
|
171 |
- ( draw ) ~x1 ~y1 IOW2 IOW2 ~color IOW |
|
172 |
- ( draw ) ~x2 ~y1 IOW2 IOW2 ~color IOW |
|
173 |
- ~y2 #0001 SUB2 LTH2 ,line-rect-ver ROT JMP? POP2 |
|
174 |
-RTS |
|
175 |
- |
|
176 |
-@draw-sprite |
|
177 |
- IOW2 ( y byte ) |
|
178 |
- IOW2 ( x byte ) |
|
179 |
- IOW2 ( sprite address ) |
|
180 |
- IOW ( layer-color ) |
|
181 |
- RTS |
|
182 |
- |
|
183 |
-@pattern [ 4281 1824 2418 8142 ] |
|
184 |
- |
|
185 |
-@clear_icn [ 0000 0000 0000 0000 ] |
|
186 |
-@cursor_icn [ 80c0 e0f0 f8e0 1000 ] |
|
187 |
- |
|
188 |
-@mouse0_icn [ 7c82 92ee 8282 4438 ] |
|
189 |
-@mouse1_icn [ 7cf2 f2ee 8282 4438 ] |
|
190 |
-@mouse2_icn [ 7c9e 9eee 8282 4438 ] |
|
191 |
-@mouse12_icn [ 7cfe feee 8282 4438 ] |
|
192 |
- |
|
193 |
-@font ( spectrum-zx font ) |
|
194 |
-[ |
|
195 |
- 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 |
|
196 |
- 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 |
|
197 |
- 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 |
|
198 |
- 0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800 |
|
199 |
- 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 |
|
200 |
- 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 |
|
201 |
- 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 |
|
202 |
- 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000 |
|
203 |
- 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 |
|
204 |
- 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000 |
|
205 |
- 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800 |
|
206 |
- 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000 |
|
207 |
- 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00 |
|
208 |
- 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 |
|
209 |
- 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810 |
|
210 |
- 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800 |
|
211 |
- 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 |
|
212 |
- 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00 |
|
213 |
- 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200 |
|
214 |
- 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 |
|
215 |
- 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00 |
|
216 |
- 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200 |
|
217 |
- 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00 |
|
218 |
- 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00 |
|
219 |
- 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00 |
|
220 |
- 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c |
|
221 |
- 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400 |
|
222 |
- 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800 |
|
223 |
- 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800 |
|
224 |
- 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800 |
|
225 |
- 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00 |
|
226 |
- 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c |
|
227 |
-] |
|
228 |
- |
|
229 |
-@body [ ] |
|
230 |
- |
|
231 |
-|d000 @ERROR BRK |
|
232 |
-|FFF0 [ f0ff f00f f00f ] ( palette ) |
|
233 |
-|FFFA .RESET .FRAME .ERROR |
... | ... |
@@ -34,8 +34,6 @@ Uint16 peek16(Stack *s, Uint8 a) { return peek8(s, a * 2) + (peek8(s, a * 2 + 1) |
34 | 34 |
void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); } |
35 | 35 |
void op_lit(Uxn *u) { u->literal += 1; } |
36 | 36 |
void op_nop(Uxn *u) { printf("0x%02x \n", pop8(&u->wst)); fflush(stdout); } |
37 |
-void op_ior(Uxn *u) { Device *dev = &u->dev[mempeek8(u, u->devr)]; if(dev) push8(&u->wst, dev->read(dev, &u->ram, pop8(&u->wst))); } |
|
38 |
-void op_iow(Uxn *u) { Uint8 a = pop8(&u->wst); Device *dev = &u->dev[mempeek8(u, u->devw)]; if(dev) dev->write(dev, &u->ram, a); } |
|
39 | 37 |
void op_ldr(Uxn *u) { Uint16 a = pop16(&u->wst); push8(&u->wst, mempeek8(u, a)); } |
40 | 38 |
void op_str(Uxn *u) { Uint16 a = pop16(&u->wst); Uint8 b = pop8(&u->wst); mempoke8(u, a, b); } |
41 | 39 |
/* Logic */ |
... | ... |
@@ -66,8 +64,6 @@ void op_lth(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, |
66 | 64 |
/* --- */ |
67 | 65 |
void op_lit16(Uxn *u) { u->literal += 2; } |
68 | 66 |
void op_nop16(Uxn *u) { printf("%04x\n", pop16(&u->wst)); } |
69 |
-void op_ior16(Uxn *u) { Uint8 a = pop8(&u->wst); Device *dev = &u->dev[mempeek8(u, u->devr)]; if(dev) push16(&u->wst, (dev->read(dev, &u->ram, a) << 8) + dev->read(dev, &u->ram, a + 1)); } |
|
70 |
-void op_iow16(Uxn *u) { Uint8 a = pop8(&u->wst); Uint8 b = pop8(&u->wst); Device *dev = &u->dev[mempeek8(u, u->devw)]; if(dev) { dev->write(dev, &u->ram, b); dev->write(dev, &u->ram, a); } } |
|
71 | 67 |
void op_ldr16(Uxn *u) { Uint16 a = pop16(&u->wst); push16(&u->wst, mempeek16(u, a)); } |
72 | 68 |
void op_str16(Uxn *u) { Uint16 a = pop16(&u->wst); Uint16 b = pop16(&u->wst); mempoke16(u, a, b); } |
73 | 69 |
void op_and16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b & a); } |
... | ... |
@@ -93,12 +89,12 @@ void op_gth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u- |
93 | 89 |
void op_lth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u->wst, getflag(&u->status, FLAG_SIGN) ? (Sint16)b < (Sint16)a : b < a); } |
94 | 90 |
|
95 | 91 |
void (*ops[])(Uxn *u) = { |
96 |
- op_brk, op_nop, op_lit, op_nop, op_ior, op_iow, op_ldr, op_str, |
|
92 |
+ op_brk, op_nop, op_lit, op_nop, op_nop, op_nop, op_ldr, op_str, |
|
97 | 93 |
op_jmp, op_jsr, op_nop, op_rts, op_and, op_ora, op_rol, op_ror, |
98 | 94 |
op_pop, op_dup, op_swp, op_ovr, op_rot, op_wsr, op_rsw, op_nop, |
99 | 95 |
op_add, op_sub, op_mul, op_div, op_equ, op_neq, op_gth, op_lth, |
100 | 96 |
/* 16-bit */ |
101 |
- op_brk, op_nop16, op_lit16, op_nop, op_ior16, op_iow16, op_ldr16, op_str16, |
|
97 |
+ op_brk, op_nop16, op_lit16, op_nop, op_nop, op_nop, op_ldr16, op_str16, |
|
102 | 98 |
op_jmp, op_jsr, op_nop, op_rts, op_and16, op_ora16, op_rol16, op_ror16, |
103 | 99 |
op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_wsr16, op_rsw16, op_nop, |
104 | 100 |
op_add16, op_sub16, op_mul16, op_div16, op_equ16, op_neq16, op_gth16, op_lth16 |
... | ... |
@@ -211,14 +207,12 @@ loaduxn(Uxn *u, char *filepath) |
211 | 207 |
} |
212 | 208 |
|
213 | 209 |
Device * |
214 |
-portuxn(Uxn *u, char *name, Uint8 (*rfn)(Device *, Memory *, Uint8), Uint8 (*wfn)(Device *, Memory *, Uint8), Uint8 (*pefn)(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1), Uint8 (*pofn)(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)) |
|
210 |
+portuxn(Uxn *u, char *name, Uint8 (*pefn)(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1), Uint8 (*pofn)(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)) |
|
215 | 211 |
{ |
216 | 212 |
Device *d = &u->dev[u->devices++]; |
217 |
- d->read = rfn; |
|
218 |
- d->write = wfn; |
|
213 |
+ d->addr = 0xff00 + (u->devices - 1) * 0x10; |
|
219 | 214 |
d->peek = pefn; |
220 | 215 |
d->poke = pofn; |
221 |
- d->ptr = 0; |
|
222 |
- printf("Device #%d: %s \n", u->devices - 1, name); |
|
216 |
+ printf("Device #%d: %s, at 0x%04x \n", u->devices - 1, name, d->addr); |
|
223 | 217 |
return d; |
224 | 218 |
} |
... | ... |
@@ -32,9 +32,7 @@ typedef struct { |
32 | 32 |
} Memory; |
33 | 33 |
|
34 | 34 |
typedef struct Device { |
35 |
- Uint8 ptr, mem[8]; |
|
36 |
- Uint8 (*read)(struct Device *, Memory *, Uint8); |
|
37 |
- Uint8 (*write)(struct Device *, Memory *, Uint8); |
|
35 |
+ Uint16 addr; |
|
38 | 36 |
Uint8 (*peek)(Uint8 *, Uint16, Uint8, Uint8); |
39 | 37 |
Uint8 (*poke)(Uint8 *, Uint16, Uint8, Uint8); |
40 | 38 |
} Device; |
... | ... |
@@ -44,7 +42,7 @@ typedef struct { |
44 | 42 |
Uint16 counter, devr, devw, vreset, vframe, verror; |
45 | 43 |
Stack wst, rst; |
46 | 44 |
Memory ram; |
47 |
- Device dev[256]; |
|
45 |
+ Device dev[8]; |
|
48 | 46 |
} Uxn; |
49 | 47 |
|
50 | 48 |
void setflag(Uint8 *status, char flag, int b); |
... | ... |
@@ -52,4 +50,4 @@ int getflag(Uint8 *status, char flag); |
52 | 50 |
int loaduxn(Uxn *c, char *filepath); |
53 | 51 |
int bootuxn(Uxn *c); |
54 | 52 |
int evaluxn(Uxn *u, Uint16 vec); |
55 |
-Device *portuxn(Uxn *u, char *name, Uint8 (*rfn)(Device *, Memory *, Uint8), Uint8 (*wfn)(Device *, Memory *, Uint8), Uint8 (*pefn)(Uint8 *, Uint16, Uint8, Uint8), Uint8 (*pofn)(Uint8 *, Uint16, Uint8, Uint8)); |
|
53 |
+Device *portuxn(Uxn *u, char *name, Uint8 (*pefn)(Uint8 *, Uint16, Uint8, Uint8), Uint8 (*pofn)(Uint8 *, Uint16, Uint8, Uint8)); |