| ... | ... |
@@ -44,8 +44,8 @@ Program p; |
| 44 | 44 |
/* clang-format off */ |
| 45 | 45 |
|
| 46 | 46 |
char ops[][4] = {
|
| 47 |
- "BRK", "NOP", "LIT", "---", "---", "---", "LDR", "STR", |
|
| 48 |
- "JMP", "JSR", "---", "RTS", "AND", "ORA", "ROL", "ROR", |
|
| 47 |
+ "BRK", "NOP", "LIT", "JMP", "JSR", "RTS", "LDR", "STR", |
|
| 48 |
+ "---", "---", "---", "---", "AND", "XOR", "ROL", "ROR", |
|
| 49 | 49 |
"POP", "DUP", "SWP", "OVR", "ROT", "---", "WSR", "RSW", |
| 50 | 50 |
"ADD", "SUB", "MUL", "DIV", "EQU", "NEQ", "GTH", "LTH" |
| 51 | 51 |
}; |
| ... | ... |
@@ -247,11 +247,13 @@ makevariable(char *id, Uint16 *addr, FILE *f) |
| 247 | 247 |
Macro *m = NULL; |
| 248 | 248 |
fscanf(f, "%s", wv); |
| 249 | 249 |
origin = *addr; |
| 250 |
- if((m = findmacro(wv))) {
|
|
| 250 |
+ if(sihx(wv)) |
|
| 251 |
+ len = shex(wv); |
|
| 252 |
+ else if((m = findmacro(wv))) {
|
|
| 251 | 253 |
len = m->size; |
| 252 | 254 |
m->refs++; |
| 253 | 255 |
} else |
| 254 |
- len = shex(wv); |
|
| 256 |
+ return error("Invalid macro", wv);
|
|
| 255 | 257 |
*addr += len; |
| 256 | 258 |
return makelabel(id, origin, len, m); |
| 257 | 259 |
} |
| ... | ... |
@@ -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.key.usm bin/boot.rom |
|
| 23 |
+./bin/assembler examples/app.pattern.usm bin/boot.rom |
|
| 24 | 24 |
./bin/emulator bin/boot.rom |
| 25 | 25 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,181 @@ |
| 1 |
+( app/hex ) |
|
| 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 |
+&Mouse { x 2 y 2 state 1 chord 1 }
|
|
| 6 |
+ |
|
| 7 |
+&Point2d { x 2 y 2 }
|
|
| 8 |
+&Rect2d { x1 2 y1 2 x2 2 y2 2 }
|
|
| 9 |
+&Point { x 1 y 1 }
|
|
| 10 |
+&Editor { x1 2 y1 2 }
|
|
| 11 |
+ |
|
| 12 |
+;pixel Point |
|
| 13 |
+;window Rect2d |
|
| 14 |
+;mouse Point2d |
|
| 15 |
+;editor Editor |
|
| 16 |
+;rect Rect2d |
|
| 17 |
+ |
|
| 18 |
+;color 1 |
|
| 19 |
+ |
|
| 20 |
+|0100 @RESET |
|
| 21 |
+ |
|
| 22 |
+ #0030 =window.x1 #0030 =window.y1 #0090 =window.x2 #00a0 =window.y2 |
|
| 23 |
+ |
|
| 24 |
+ #0040 =editor.x1 #0040 =editor.y |
|
| 25 |
+ |
|
| 26 |
+ #0040 #0040 #01 ,draw-editor JSR |
|
| 27 |
+ |
|
| 28 |
+BRK |
|
| 29 |
+ |
|
| 30 |
+|0200 @FRAME |
|
| 31 |
+ |
|
| 32 |
+ ,no-click ~dev/mouse.state #00 EQU JMP? POP2 |
|
| 33 |
+ |
|
| 34 |
+ ( load ) ,pattern ~dev/mouse.y ~editor.y1 SUB2 #0008 DIV2 ADD2 LDR |
|
| 35 |
+ ( mask ) #01 #07 ~dev/mouse.x ~editor.x1 SUB2 #0008 DIV2 SWP POP SUB ROL |
|
| 36 |
+ XOR |
|
| 37 |
+ ( save ) ,pattern ~dev/mouse.y ~editor.y1 SUB2 #0008 DIV2 ADD2 STR |
|
| 38 |
+ |
|
| 39 |
+ ,redraw JSR |
|
| 40 |
+ |
|
| 41 |
+ @no-click |
|
| 42 |
+ |
|
| 43 |
+ ,draw-cursor JSR |
|
| 44 |
+ |
|
| 45 |
+BRK |
|
| 46 |
+ |
|
| 47 |
+@redraw |
|
| 48 |
+ |
|
| 49 |
+ #0000 #0000 ~dev/screen.width ~dev/screen.height #03 ,pattern ,tile-rect JSR |
|
| 50 |
+ |
|
| 51 |
+ ~window.x1 #0001 ADD2 ~window.y1 ~window.x2 #0004 ADD2 ~window.y2 #0004 ADD2 #00 ,fill-rect JSR |
|
| 52 |
+ ~window.x1 ~window.y1 #0001 ADD2 ~window.x2 #0001 ADD2 ~window.y2 #0004 ADD2 #00 ,fill-rect JSR |
|
| 53 |
+ ~window.x1 #0001 SUB2 ~window.y1 #0001 SUB2 ~window.x2 ~window.y2 #00 ,line-rect JSR |
|
| 54 |
+ ~window.x1 #0002 SUB2 ~window.y1 #0002 SUB2 ~window.x2 #0001 ADD2 ~window.y2 #0001 ADD2 #02 ,line-rect JSR |
|
| 55 |
+ ~window.x1 ~window.y1 ~window.x2 ~window.y2 #00 ,fill-rect JSR |
|
| 56 |
+ |
|
| 57 |
+ ~editor.x1 =dev/sprite.x |
|
| 58 |
+ ~editor.y1 =dev/sprite.y |
|
| 59 |
+ ,pattern =dev/sprite.addr |
|
| 60 |
+ |
|
| 61 |
+ #02 =color |
|
| 62 |
+ |
|
| 63 |
+ #00 =pixel.y |
|
| 64 |
+ @redraw-ver |
|
| 65 |
+ #00 =pixel.x |
|
| 66 |
+ ~editor.x1 =dev/sprite.x |
|
| 67 |
+ @redraw-hor |
|
| 68 |
+ |
|
| 69 |
+ ( get bit ) |
|
| 70 |
+ ,cell0_icn #00 |
|
| 71 |
+ ,pattern #00 ~pixel.y ADD2 LDR #07 ~pixel.x SUB ROR #01 AND ( get bit ) |
|
| 72 |
+ #0008 MUL2 ADD2 =dev/sprite.addr ( add *8 ) |
|
| 73 |
+ |
|
| 74 |
+ ( draw ) ~color =dev/sprite.color |
|
| 75 |
+ ( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x |
|
| 76 |
+ ( incr ) ~pixel.x #01 ADD =pixel.x |
|
| 77 |
+ ,redraw-hor ~dev/sprite.x ~editor.x1 #0040 ADD2 LTH2 JMP? POP2 |
|
| 78 |
+ ( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y |
|
| 79 |
+ ( incr ) ~pixel.y #01 ADD =pixel.y |
|
| 80 |
+ ,redraw-ver ~dev/sprite.y ~editor.y1 #0040 ADD2 LTH2 JMP? POP2 |
|
| 81 |
+ |
|
| 82 |
+ ,pattern =dev/sprite.addr |
|
| 83 |
+ ~dev/sprite.y #0040 SUB2 =dev/sprite.y |
|
| 84 |
+ ~dev/sprite.x #0008 ADD2 =dev/sprite.x |
|
| 85 |
+ ( draw ) #01 =dev/sprite.color |
|
| 86 |
+ |
|
| 87 |
+RTS |
|
| 88 |
+ |
|
| 89 |
+@fill-rect ( x1 y1 x2 y2 color ) |
|
| 90 |
+ |
|
| 91 |
+ ( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1 |
|
| 92 |
+ @fill-rect-ver |
|
| 93 |
+ ~rect.x1 =dev/screen.x |
|
| 94 |
+ @fill-rect-hor |
|
| 95 |
+ ( draw ) ~color =dev/screen.color |
|
| 96 |
+ ( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x |
|
| 97 |
+ ,fill-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP? POP2 |
|
| 98 |
+ ( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y |
|
| 99 |
+ ,fill-rect-ver ~dev/screen.y ~rect.y2 LTH2 JMP? POP2 |
|
| 100 |
+ |
|
| 101 |
+RTS |
|
| 102 |
+ |
|
| 103 |
+@line-rect ( x1 y1 x2 y2 color ) |
|
| 104 |
+ |
|
| 105 |
+ ( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1 |
|
| 106 |
+ @line-rect-hor |
|
| 107 |
+ ( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x |
|
| 108 |
+ ( draw ) ~rect.y1 =dev/screen.y ~color =dev/screen.color |
|
| 109 |
+ ( draw ) ~rect.y2 =dev/screen.y ~color =dev/screen.color |
|
| 110 |
+ ,line-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP? POP2 |
|
| 111 |
+ ~rect.y1 =dev/screen.y |
|
| 112 |
+ @line-rect-ver |
|
| 113 |
+ ( draw ) ~rect.x1 =dev/screen.x ~color =dev/screen.color |
|
| 114 |
+ ( draw ) ~rect.x2 =dev/screen.x ~color =dev/screen.color |
|
| 115 |
+ ( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y |
|
| 116 |
+ ,line-rect-ver ~dev/screen.y ~rect.y2 #0001 ADD2 LTH2 JMP? POP2 |
|
| 117 |
+ |
|
| 118 |
+RTS |
|
| 119 |
+ |
|
| 120 |
+@tile-rect ( x1 y1 x2 y2 color addr ) |
|
| 121 |
+ |
|
| 122 |
+ =dev/sprite.addr =color =rect.y2 =rect.x2 DUP2 =dev/sprite.y =rect.y1 DUP2 =dev/sprite.x =rect.x1 |
|
| 123 |
+ |
|
| 124 |
+ @tile-rect-ver |
|
| 125 |
+ ~rect.x1 =dev/sprite.x |
|
| 126 |
+ @tile-rect-hor |
|
| 127 |
+ ( draw ) ~color =dev/sprite.color |
|
| 128 |
+ ( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x |
|
| 129 |
+ ,tile-rect-hor ~dev/sprite.x ~rect.x2 LTH2 JMP? POP2 |
|
| 130 |
+ ( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y |
|
| 131 |
+ ,tile-rect-ver ~dev/sprite.y ~rect.y2 LTH2 JMP? POP2 |
|
| 132 |
+ |
|
| 133 |
+RTS |
|
| 134 |
+ |
|
| 135 |
+@draw-editor |
|
| 136 |
+ |
|
| 137 |
+ =color DUP2 =dev/sprite.y =editor.y1 DUP2 =dev/sprite.x =editor.x1 |
|
| 138 |
+ |
|
| 139 |
+ ,redraw JSR |
|
| 140 |
+ |
|
| 141 |
+ |
|
| 142 |
+RTS |
|
| 143 |
+ |
|
| 144 |
+@draw-cursor |
|
| 145 |
+ |
|
| 146 |
+ ~mouse.x ~dev/mouse.x NEQU2 |
|
| 147 |
+ ~mouse.y ~dev/mouse.y NEQU2 |
|
| 148 |
+ |
|
| 149 |
+ #0000 EQU2 RTS? ( Return if unchanged ) |
|
| 150 |
+ |
|
| 151 |
+ ( clear last cursor ) |
|
| 152 |
+ #10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
| 153 |
+ ( record mouse positions ) |
|
| 154 |
+ ~dev/mouse.x =mouse.x ~dev/mouse.y =mouse.y |
|
| 155 |
+ #13 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
| 156 |
+ |
|
| 157 |
+RTS |
|
| 158 |
+ |
|
| 159 |
+@draw-sprite |
|
| 160 |
+ |
|
| 161 |
+ =dev/sprite.y |
|
| 162 |
+ =dev/sprite.x |
|
| 163 |
+ =dev/sprite.addr |
|
| 164 |
+ =dev/sprite.color |
|
| 165 |
+ |
|
| 166 |
+RTS |
|
| 167 |
+ |
|
| 168 |
+@pattern [ 0000 0000 0000 0000 ] |
|
| 169 |
+@clear_icn [ 0000 0000 0000 0000 ] |
|
| 170 |
+@cursor_icn [ 80c0 e0f0 f8e0 1000 ] |
|
| 171 |
+@cell0_icn [ 7c82 8282 8282 7c00 ] |
|
| 172 |
+@cell1_icn [ 7cfe fefe fefe 7c00 ] |
|
| 173 |
+ |
|
| 174 |
+|d000 @ERROR BRK |
|
| 175 |
+ |
|
| 176 |
+|FF10 ;dev/screen Screen |
|
| 177 |
+|FF20 ;dev/sprite Sprite |
|
| 178 |
+|FF50 ;dev/mouse Mouse |
|
| 179 |
+ |
|
| 180 |
+|FFF0 .RESET .FRAME .ERROR ( vectors ) |
|
| 181 |
+|FFF8 [ 13fd 1ef3 1bf2 ] ( palette ) |
|
| 0 | 182 |
\ No newline at end of file |
| ... | ... |
@@ -139,18 +139,22 @@ RTS |
| 139 | 139 |
RTS |
| 140 | 140 |
|
| 141 | 141 |
@draw-sprite |
| 142 |
+ |
|
| 142 | 143 |
=dev/sprite.y |
| 143 | 144 |
=dev/sprite.x |
| 144 | 145 |
=dev/sprite.addr |
| 145 | 146 |
=dev/sprite.color |
| 146 |
- RTS |
|
| 147 |
+ |
|
| 148 |
+RTS |
|
| 147 | 149 |
|
| 148 | 150 |
@draw-sprite-chr |
| 151 |
+ |
|
| 149 | 152 |
=dev/sprite.y |
| 150 | 153 |
=dev/sprite.x |
| 151 | 154 |
=dev/sprite.addr |
| 152 | 155 |
#20 =dev/sprite.color |
| 153 |
- RTS |
|
| 156 |
+ |
|
| 157 |
+RTS |
|
| 154 | 158 |
|
| 155 | 159 |
@clear_icn [ 0000 0000 0000 0000 ] |
| 156 | 160 |
@cursor_icn [ 80c0 e0f0 f8e0 1000 ] |
| ... | ... |
@@ -34,14 +34,14 @@ 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_ldr(Uxn *u) { Uint16 a = pop16(&u->wst); push8(&u->wst, mempeek8(u, a)); }
|
|
| 38 |
-void op_str(Uxn *u) { Uint16 a = pop16(&u->wst); Uint8 b = pop8(&u->wst); mempoke8(u, a, b); }
|
|
| 39 |
-/* Logic */ |
|
| 40 | 37 |
void op_jmp(Uxn *u) { u->ram.ptr = pop16(&u->wst); }
|
| 41 | 38 |
void op_jsr(Uxn *u) { push16(&u->rst, u->ram.ptr); u->ram.ptr = pop16(&u->wst); }
|
| 42 | 39 |
void op_rts(Uxn *u) { u->ram.ptr = pop16(&u->rst); }
|
| 40 |
+void op_ldr(Uxn *u) { Uint16 a = pop16(&u->wst); push8(&u->wst, mempeek8(u, a)); }
|
|
| 41 |
+void op_str(Uxn *u) { Uint16 a = pop16(&u->wst); Uint8 b = pop8(&u->wst); mempoke8(u, a, b); }
|
|
| 42 |
+/* Logic */ |
|
| 43 | 43 |
void op_and(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b & a); }
|
| 44 |
-void op_ora(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b | a); }
|
|
| 44 |
+void op_xor(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b | a); }
|
|
| 45 | 45 |
void op_rol(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b << a); }
|
| 46 | 46 |
void op_ror(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b >> a); }
|
| 47 | 47 |
/* Stack */ |
| ... | ... |
@@ -67,7 +67,7 @@ void op_nop16(Uxn *u) { printf("%04x\n", pop16(&u->wst)); }
|
| 67 | 67 |
void op_ldr16(Uxn *u) { Uint16 a = pop16(&u->wst); push16(&u->wst, mempeek16(u, a)); }
|
| 68 | 68 |
void op_str16(Uxn *u) { Uint16 a = pop16(&u->wst); Uint16 b = pop16(&u->wst); mempoke16(u, a, b); }
|
| 69 | 69 |
void op_and16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b & a); }
|
| 70 |
-void op_ora16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b | a); }
|
|
| 70 |
+void op_xor16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b ^ a); }
|
|
| 71 | 71 |
void op_rol16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b << a); }
|
| 72 | 72 |
void op_ror16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b >> a); }
|
| 73 | 73 |
/* Stack(16-bits) */ |
| ... | ... |
@@ -89,13 +89,13 @@ void op_gth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u-
|
| 89 | 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); }
|
| 90 | 90 |
|
| 91 | 91 |
void (*ops[])(Uxn *u) = {
|
| 92 |
- op_brk, op_nop, op_lit, op_nop, op_nop, op_nop, op_ldr, op_str, |
|
| 93 |
- op_jmp, op_jsr, op_nop, op_rts, op_and, op_ora, op_rol, op_ror, |
|
| 92 |
+ op_brk, op_nop, op_lit, op_jmp, op_jsr, op_rts, op_ldr, op_str, |
|
| 93 |
+ op_jmp, op_jsr, op_nop, op_rts, op_and, op_xor, op_rol, op_ror, |
|
| 94 | 94 |
op_pop, op_dup, op_swp, op_ovr, op_rot, op_nop, op_wsr, op_rsw, |
| 95 | 95 |
op_add, op_sub, op_mul, op_div, op_equ, op_neq, op_gth, op_lth, |
| 96 | 96 |
/* 16-bit */ |
| 97 |
- op_brk, op_nop16, op_lit16, op_nop, op_nop, op_nop, op_ldr16, op_str16, |
|
| 98 |
- op_jmp, op_jsr, op_nop, op_rts, op_and16, op_ora16, op_rol16, op_ror16, |
|
| 97 |
+ op_brk, op_nop16, op_lit16, op_jmp, op_jsr, op_rts, op_ldr16, op_str16, |
|
| 98 |
+ op_jmp, op_jsr, op_nop, op_rts, op_and16, op_xor16, op_rol16, op_ror16, |
|
| 99 | 99 |
op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_wsr16, op_rsw16, op_nop, |
| 100 | 100 |
op_add16, op_sub16, op_mul16, op_div16, op_equ16, op_neq16, op_gth16, op_lth16 |
| 101 | 101 |
}; |