| ... | ... |
@@ -48,7 +48,7 @@ char ops[][4] = {
|
| 48 | 48 |
"BRK", "NOP", "LIT", "LDR", "STR", "---", "JMP", "JSR", |
| 49 | 49 |
"EQU", "NEQ", "GTH", "LTH", "AND", "ORA", "EOR", "SFT", |
| 50 | 50 |
"POP", "DUP", "SWP", "OVR", "ROT", "---", "CLN", "STH", |
| 51 |
- "ADD", "SUB", "MUL", "DIV", "---", "---", "---", "---" |
|
| 51 |
+ "ADD", "SUB", "MUL", "DIV", "---", "---", "GTS", "LTS" |
|
| 52 | 52 |
}; |
| 53 | 53 |
|
| 54 | 54 |
int scin(char *s, char c) { int i = 0; while(s[i]) if(s[i++] == c) return i - 1; return -1; } /* string char index */
|
| ... | ... |
@@ -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 projects/software/nasu.usm bin/boot.rom |
|
| 23 |
+./bin/assembler projects/examples/gui.shapes.usm bin/boot.rom |
|
| 24 | 24 |
./bin/emulator bin/boot.rom |
| ... | ... |
@@ -3,11 +3,19 @@ |
| 3 | 3 |
%RTN { JMP2r }
|
| 4 | 4 |
%++ { #0001 ADD2 }
|
| 5 | 5 |
%8+ { #0008 ADD2 }
|
| 6 |
+%ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? }
|
|
| 6 | 7 |
|
| 7 | 8 |
;label { x 2 y 2 color 1 addr 2 }
|
| 8 | 9 |
;pict { x 2 y 2 width 2 height 2 color 1 addr 2 }
|
| 9 | 10 |
;rect { x1 2 y1 2 x2 2 y2 2 }
|
| 10 | 11 |
;color { byte 1 }
|
| 12 |
+( clean up ) |
|
| 13 |
+;a { x 2 y 2 }
|
|
| 14 |
+;b { x 2 y 2 }
|
|
| 15 |
+;s { x 2 y 2 }
|
|
| 16 |
+;d { x 2 y 2 }
|
|
| 17 |
+;err { short 2 }
|
|
| 18 |
+;err2 { short 2 }
|
|
| 11 | 19 |
|
| 12 | 20 |
|0100 @RESET |
| 13 | 21 |
|
| ... | ... |
@@ -27,6 +35,11 @@ |
| 27 | 35 |
#0038 #0078 #02 ,text ,draw-label JSR2 |
| 28 | 36 |
#0048 #0088 #03 ,text ,draw-label JSR2 |
| 29 | 37 |
#0058 #0098 #04 ,text ,draw-label JSR2 |
| 38 |
+ |
|
| 39 |
+ #0020 #0020 #0070 #0080 #01 ,draw-line JSR2 |
|
| 40 |
+ #0020 #0080 #0070 #0030 #02 ,draw-line JSR2 |
|
| 41 |
+ #00a0 #0020 #0050 #00b0 #03 ,draw-line JSR2 |
|
| 42 |
+ #00b0 #0090 #0030 #0010 #01 ,draw-line JSR2 |
|
| 30 | 43 |
|
| 31 | 44 |
BRK |
| 32 | 45 |
|
| ... | ... |
@@ -88,6 +101,38 @@ RTN |
| 88 | 101 |
|
| 89 | 102 |
RTN |
| 90 | 103 |
|
| 104 |
+@draw-line ( x1 y1 x2 y2 ) |
|
| 105 |
+ |
|
| 106 |
+ =color |
|
| 107 |
+ =b.y =b.x =a.y =a.x |
|
| 108 |
+ ~b.x ~a.x SUB2 ABS2 =d.x |
|
| 109 |
+ ~b.y ~a.y SUB2 ABS2 #0000 SWP2 SUB2 =d.y |
|
| 110 |
+ #ffff #00 ~a.x ~b.x LTS2 #0002 MUL2 ADD2 =s.x |
|
| 111 |
+ #ffff #00 ~a.y ~b.y LTS2 #0002 MUL2 ADD2 =s.y |
|
| 112 |
+ ~d.x ~d.y ADD2 =err |
|
| 113 |
+ |
|
| 114 |
+ $loop |
|
| 115 |
+ |
|
| 116 |
+ ~a.x =Screen.x ~a.y =Screen.y ~color =Screen.color |
|
| 117 |
+ ,$end ~a.x ~b.x EQU2 ~a.y ~b.y EQU2 #0101 EQU2 JMP2? |
|
| 118 |
+ ~err #0002 MUL2 =err2 |
|
| 119 |
+ |
|
| 120 |
+ ,$skipy ~err2 ~d.y LTS2 JMP2? |
|
| 121 |
+ ~err ~d.y ADD2 =err |
|
| 122 |
+ ~a.x ~s.x ADD2 =a.x |
|
| 123 |
+ $skipy |
|
| 124 |
+ |
|
| 125 |
+ ,$skipx ~err2 ~d.x GTS2 JMP2? |
|
| 126 |
+ ~err ~d.x ADD2 =err |
|
| 127 |
+ ~a.y ~s.y ADD2 =a.y |
|
| 128 |
+ $skipx |
|
| 129 |
+ |
|
| 130 |
+ ,$loop JMP2 |
|
| 131 |
+ |
|
| 132 |
+ $end |
|
| 133 |
+ |
|
| 134 |
+RTN |
|
| 135 |
+ |
|
| 91 | 136 |
@pict_small [ |
| 92 | 137 |
|
| 93 | 138 |
ff80 8080 8080 8088 ffff fffc f8f9 f1f4 |
| ... | ... |
@@ -145,4 +190,4 @@ RTN |
| 145 | 190 |
|FF20 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
| 146 | 191 |
|
| 147 | 192 |
|FFF0 .RESET .FRAME .ERROR ( vectors ) |
| 148 |
-|FFF8 [ 0f0f 0fff 0ff0 ] ( palette ) |
|
| 149 | 193 |
\ No newline at end of file |
| 194 |
+|FFF8 [ 13fd 1ef3 1bf2 ] ( palette ) |
|
| 150 | 195 |
\ No newline at end of file |
| ... | ... |
@@ -2,74 +2,51 @@ |
| 2 | 2 |
|
| 3 | 3 |
%RTN { JMP2r }
|
| 4 | 4 |
%RTN? { JMP2r? }
|
| 5 |
+%ABS { DUP #07 SHR #ff SWP MUL? }
|
|
| 6 |
+%ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? }
|
|
| 5 | 7 |
|
| 6 | 8 |
;cursor { x 2 y 2 }
|
| 7 | 9 |
;a { x 2 y 2 }
|
| 8 | 10 |
;b { x 2 y 2 }
|
| 9 | 11 |
;s { x 2 y 2 }
|
| 12 |
+;d { x 2 y 2 }
|
|
| 13 |
+;err { short 2 }
|
|
| 14 |
+;err2 { short 2 }
|
|
| 15 |
+;i { byte 1 }
|
|
| 16 |
+;color { byte 1 }
|
|
| 10 | 17 |
|
| 11 | 18 |
|0100 @RESET |
| 12 | 19 |
|
| 13 |
- #0020 #0020 #0070 #0080 ,draw-line JSR2 |
|
| 14 |
- #0020 #0080 #0070 #0030 ,draw-line JSR2 |
|
| 15 |
- #00a0 #0020 #0050 #00b0 ,draw-line JSR2 |
|
| 16 |
- #00b0 #0090 #0030 #0010 ,draw-line JSR2 |
|
| 20 |
+ #0020 #0020 #0070 #0080 #01 ,draw-line JSR2 |
|
| 21 |
+ #0020 #0080 #0070 #0030 #02 ,draw-line JSR2 |
|
| 22 |
+ #00a0 #0020 #0050 #00b0 #03 ,draw-line JSR2 |
|
| 23 |
+ #00b0 #0090 #0030 #0010 #01 ,draw-line JSR2 |
|
| 17 | 24 |
|
| 18 | 25 |
BRK |
| 19 | 26 |
|
| 20 | 27 |
@draw-line ( x1 y1 x2 y2 ) |
| 21 |
- |
|
| 22 |
- =b.y =b.x ( target, b ) |
|
| 23 |
- =a.y =a.x ( target, a ) |
|
| 24 |
- |
|
| 25 |
- ~a.x =Screen.x ~a.y =Screen.y #02 =Screen.color |
|
| 26 |
- ~b.x =Screen.x ~b.y =Screen.y #02 =Screen.color |
|
| 27 |
- |
|
| 28 |
- ( dx = abs[bx - ax] ) |
|
| 28 |
+ |
|
| 29 |
+ =color |
|
| 30 |
+ =b.y =b.x =a.y =a.x |
|
| 29 | 31 |
~b.x ~a.x SUB2 ABS2 =d.x |
| 30 |
- |
|
| 31 |
- ( dy = -abs[by - ay] ) |
|
| 32 | 32 |
~b.y ~a.y SUB2 ABS2 #0000 SWP2 SUB2 =d.y |
| 33 |
- |
|
| 34 |
- ( sx = ax < bx ? 1 : -1; ) |
|
| 35 |
- #ffff #00 ~a.x ~b.x LTH2 #0002 MUL2 ADD2 =s.x |
|
| 36 |
- |
|
| 37 |
- ( sy = ay < by ? 1 : -1; ) |
|
| 38 |
- #ffff #00 ~a.y ~b.y LTH2 #0002 MUL2 ADD2 =s.y |
|
| 39 |
- |
|
| 40 |
- ( err = dx + dy ) |
|
| 33 |
+ #ffff #00 ~a.x ~b.x LTS2 #0002 MUL2 ADD2 =s.x |
|
| 34 |
+ #ffff #00 ~a.y ~b.y LTS2 #0002 MUL2 ADD2 =s.y |
|
| 41 | 35 |
~d.x ~d.y ADD2 =err |
| 42 | 36 |
|
| 43 |
- ( loop ) |
|
| 44 | 37 |
$loop |
| 45 | 38 |
|
| 46 |
- ( putchr[ax, ay, color]; ) |
|
| 47 |
- ~a.x =Screen.x ~a.y =Screen.y #01 =Screen.color |
|
| 48 |
- |
|
| 49 |
- ( if[ax == bx && ay == by] break; ) |
|
| 39 |
+ ~a.x =Screen.x ~a.y =Screen.y ~color =Screen.color |
|
| 50 | 40 |
,$end ~a.x ~b.x EQU2 ~a.y ~b.y EQU2 #0101 EQU2 JMP2? |
| 51 |
- |
|
| 52 |
- ( fallback, remove ) |
|
| 53 |
- ,$end ~i #90 GTH JMP2? ~i #01 ADD =i |
|
| 54 |
- |
|
| 55 |
- ( err2 = 2 * err; ) |
|
| 56 | 41 |
~err #0002 MUL2 =err2 |
| 57 | 42 |
|
| 58 |
- ~err2 =Console.short |
|
| 59 |
- |
|
| 60 |
- ( if[err2 >= dy] ) |
|
| 61 |
- ,$skipy ~err2 ~d.y LTH2 JMP2? |
|
| 62 |
- ( err += dy; ) |
|
| 43 |
+ ,$skipy ~err2 ~d.y LTS2 JMP2? |
|
| 63 | 44 |
~err ~d.y ADD2 =err |
| 64 |
- ( ax += sx; ) |
|
| 65 | 45 |
~a.x ~s.x ADD2 =a.x |
| 66 | 46 |
$skipy |
| 67 | 47 |
|
| 68 |
- ( if[err2 <= dx] ) |
|
| 69 |
- ,$skipx ~err2 ~d.x GTH2 JMP2? |
|
| 70 |
- ( err += dx; ) |
|
| 48 |
+ ,$skipx ~err2 ~d.x GTS2 JMP2? |
|
| 71 | 49 |
~err ~d.x ADD2 =err |
| 72 |
- ( ay += sy; ) |
|
| 73 | 50 |
~a.y ~s.y ADD2 =a.y |
| 74 | 51 |
$skipx |
| 75 | 52 |
|
| ... | ... |
@@ -83,6 +60,12 @@ RTN |
| 83 | 60 |
|d000 @ERROR |
| 84 | 61 |
|
| 85 | 62 |
|FF00 ;Console { pad 8 char 1 byte 1 short 2 }
|
| 63 |
+|FF10 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|
|
| 64 |
+|FF20 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 65 |
+|FF30 ;Controller { buttons 1 }
|
|
| 66 |
+|FF40 ;Keys { key 1 }
|
|
| 67 |
+|FF50 ;Mouse { x 2 y 2 state 1 chord 1 change 1 }
|
|
| 68 |
+|FF60 ;File { pad 8 name 2 length 2 load 2 save 2 }
|
|
| 86 | 69 |
|
| 87 | 70 |
|FFF0 .RESET .FRAME .ERROR ( vectors ) |
| 88 | 71 |
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette ) |
| 89 | 72 |
\ No newline at end of file |
| ... | ... |
@@ -58,7 +58,9 @@ void op_div(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b
|
| 58 | 58 |
void op_equ(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b == a); }
|
| 59 | 59 |
void op_neq(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b != a); }
|
| 60 | 60 |
void op_gth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b > a); }
|
| 61 |
+void op_gts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (Sint8)b > (Sint8)a); }
|
|
| 61 | 62 |
void op_lth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b < a); }
|
| 63 |
+void op_lts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (Sint8)b < (Sint8)a); }
|
|
| 62 | 64 |
/* --- */ |
| 63 | 65 |
void op_lit16(Uxn *u) { u->literal += 2; }
|
| 64 | 66 |
void op_nop16(Uxn *u) { printf("%04x\n", pop16(u->src)); }
|
| ... | ... |
@@ -87,18 +89,20 @@ void op_div16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->s
|
| 87 | 89 |
void op_equ16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b == a); }
|
| 88 | 90 |
void op_neq16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b != a); }
|
| 89 | 91 |
void op_gth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b > a); }
|
| 92 |
+void op_gts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b > (Sint16)a); }
|
|
| 90 | 93 |
void op_lth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b < a); }
|
| 94 |
+void op_lts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b < (Sint16)a); }
|
|
| 91 | 95 |
|
| 92 | 96 |
void (*ops[])(Uxn *u) = {
|
| 93 | 97 |
op_brk, op_nop, op_lit, op_ldr, op_str, op_nop, op_jmp, op_jsr, |
| 94 | 98 |
op_equ, op_neq, op_gth, op_lth, op_and, op_ora, op_eor, op_sft, |
| 95 | 99 |
op_pop, op_dup, op_swp, op_ovr, op_rot, op_nop, op_cln, op_sth, |
| 96 |
- op_add, op_sub, op_mul, op_div, op_nop, op_nop, op_nop, op_eor, |
|
| 100 |
+ op_add, op_sub, op_mul, op_div, op_nop, op_nop, op_gts, op_lts, |
|
| 97 | 101 |
/* 16-bit */ |
| 98 | 102 |
op_brk, op_nop16, op_lit16, op_ldr16, op_str16, op_nop, op_jmp16, op_jsr16, |
| 99 | 103 |
op_equ16, op_neq16, op_gth16, op_lth16, op_and16, op_ora16, op_eor16, op_sft16, |
| 100 | 104 |
op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_nop, op_cln16, op_sth16, |
| 101 |
- op_add16, op_sub16, op_mul16, op_div16, op_nop, op_nop, op_nop, op_nop |
|
| 105 |
+ op_add16, op_sub16, op_mul16, op_div16, op_nop, op_nop, op_gts16, op_lts16 |
|
| 102 | 106 |
}; |
| 103 | 107 |
|
| 104 | 108 |
Uint8 opr[][4] = { /* wstack-/+ rstack-/+ */
|