| ... | ... |
@@ -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/left.usm bin/boot.rom |
|
| 23 |
+./bin/assembler projects/software/noodle.usm bin/boot.rom |
|
| 24 | 24 |
./bin/emulator bin/boot.rom |
| 25 | 25 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,145 @@ |
| 1 |
+( draw bezier ) |
|
| 2 |
+ |
|
| 3 |
+%RTN { JMP2r }
|
|
| 4 |
+%2/ { #0002 DIV2 }
|
|
| 5 |
+%ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? }
|
|
| 6 |
+%STEP8 { #0033 SFT2 }
|
|
| 7 |
+%STEP4 { #0022 SFT2 }
|
|
| 8 |
+ |
|
| 9 |
+;pt1 { x 2 y 2 }
|
|
| 10 |
+;pt2 { x 2 y 2 }
|
|
| 11 |
+;pt3 { x 2 y 2 }
|
|
| 12 |
+;pta { x 2 y 2 }
|
|
| 13 |
+;ptb { x 2 y 2 }
|
|
| 14 |
+;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
|
|
| 15 |
+;color { byte 1 }
|
|
| 16 |
+;pointer { x 2 y 2 }
|
|
| 17 |
+;i { byte 1 }
|
|
| 18 |
+;j { byte 1 }
|
|
| 19 |
+ |
|
| 20 |
+( devices ) |
|
| 21 |
+ |
|
| 22 |
+|0100 ;Console { pad 8 char 1 byte 1 short 2 }
|
|
| 23 |
+|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|
|
| 24 |
+|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 25 |
+|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|
|
| 26 |
+|01F0 .RESET .FRAME .ERROR ( vectors ) |
|
| 27 |
+|01F8 [ 13fd 1ef3 1bf2 ] ( palette ) |
|
| 28 |
+ |
|
| 29 |
+|0200 @RESET |
|
| 30 |
+ |
|
| 31 |
+ #0020 #0020 =pt1.y =pt1.x |
|
| 32 |
+ #0040 #0080 =pt2.y =pt2.x |
|
| 33 |
+ #00f0 #00a0 =pt3.y =pt3.x |
|
| 34 |
+ |
|
| 35 |
+ ,redraw JSR2 |
|
| 36 |
+ |
|
| 37 |
+BRK |
|
| 38 |
+ |
|
| 39 |
+@FRAME |
|
| 40 |
+ |
|
| 41 |
+ ,draw-cursor JSR2 |
|
| 42 |
+ |
|
| 43 |
+ ,$no-touch ~Mouse.state #00 EQU JMP2? |
|
| 44 |
+ |
|
| 45 |
+ ~Mouse.x STEP4 =pt2.x |
|
| 46 |
+ ~Mouse.y STEP4 =pt2.y |
|
| 47 |
+ ,redraw JSR2 |
|
| 48 |
+ |
|
| 49 |
+ $no-touch |
|
| 50 |
+ |
|
| 51 |
+BRK |
|
| 52 |
+ |
|
| 53 |
+@redraw |
|
| 54 |
+ |
|
| 55 |
+ #0000 =Sprite.y |
|
| 56 |
+ $ver |
|
| 57 |
+ #0000 =Sprite.x |
|
| 58 |
+ $hor |
|
| 59 |
+ ( draw ) #00 =Sprite.color |
|
| 60 |
+ ( incr ) ~Sprite.x #0008 ADD2 =Sprite.x |
|
| 61 |
+ ( incr ) #0000 =Sprite.addr |
|
| 62 |
+ ,$hor ~Sprite.x ~Screen.width LTH2 JMP2? |
|
| 63 |
+ ( incr ) ~Sprite.y #0008 ADD2 =Sprite.y |
|
| 64 |
+ ,$ver ~Sprite.y ~Screen.height LTH2 JMP2? |
|
| 65 |
+ |
|
| 66 |
+ ~pt1.x ~pt1.y ~pt2.x ~pt2.y #03 ,draw-line JSR2 |
|
| 67 |
+ ~pt2.x ~pt2.y ~pt3.x ~pt3.y #03 ,draw-line JSR2 |
|
| 68 |
+ |
|
| 69 |
+ ~pt1.x ~pt1.y #0a ,draw-point JSR2 |
|
| 70 |
+ ~pt2.x ~pt2.y #0a ,draw-point JSR2 |
|
| 71 |
+ ~pt3.x ~pt3.y #0a ,draw-point JSR2 |
|
| 72 |
+ |
|
| 73 |
+ #00 =i |
|
| 74 |
+ |
|
| 75 |
+ $loop |
|
| 76 |
+ ~pt1.x ~pt2.x ~pt1.x SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =pta.x |
|
| 77 |
+ ~pt1.y ~pt2.y ~pt1.y SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =pta.y |
|
| 78 |
+ ~pt2.x ~pt3.x ~pt2.x SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =ptb.x |
|
| 79 |
+ ~pt2.y ~pt3.y ~pt2.y SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =ptb.y |
|
| 80 |
+ ~pta.x ~pta.y ~ptb.x ~ptb.y #0a ,draw-line JSR2 |
|
| 81 |
+ ( incr ) ~i #01 ADD =i |
|
| 82 |
+ ,$loop ~i #08 LTH JMP2? |
|
| 83 |
+ |
|
| 84 |
+RTN |
|
| 85 |
+ |
|
| 86 |
+@draw-point ( x y color ) |
|
| 87 |
+ |
|
| 88 |
+ =color |
|
| 89 |
+ #0003 SUB2 =Sprite.y |
|
| 90 |
+ #0003 SUB2 =Sprite.x |
|
| 91 |
+ ,handle =Sprite.addr |
|
| 92 |
+ ~color =Sprite.color |
|
| 93 |
+ |
|
| 94 |
+RTN |
|
| 95 |
+ |
|
| 96 |
+@draw-line ( x1 y1 x2 y2 color ) |
|
| 97 |
+ |
|
| 98 |
+ ( load ) =color =line.y0 =line.x0 =line.y =line.x |
|
| 99 |
+ ~line.x0 ~line.x SUB2 ABS2 =line.dx |
|
| 100 |
+ ~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy |
|
| 101 |
+ #ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx |
|
| 102 |
+ #ffff #00 ~line.y ~line.y0 LTS2 #0002 MUL2 ADD2 =line.sy |
|
| 103 |
+ ~line.dx ~line.dy ADD2 =line.e1 |
|
| 104 |
+ $loop |
|
| 105 |
+ ~line.x =Screen.x ~line.y =Screen.y ~color =Screen.color |
|
| 106 |
+ ,$end ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 JMP2? |
|
| 107 |
+ ~line.e1 #0002 MUL2 =line.e2 |
|
| 108 |
+ ,$skipy ~line.e2 ~line.dy LTS2 JMP2? |
|
| 109 |
+ ~line.e1 ~line.dy ADD2 =line.e1 |
|
| 110 |
+ ~line.x ~line.sx ADD2 =line.x |
|
| 111 |
+ $skipy |
|
| 112 |
+ ,$skipx ~line.e2 ~line.dx GTS2 JMP2? |
|
| 113 |
+ ~line.e1 ~line.dx ADD2 =line.e1 |
|
| 114 |
+ ~line.y ~line.sy ADD2 =line.y |
|
| 115 |
+ $skipx |
|
| 116 |
+ ,$loop JMP2 |
|
| 117 |
+ |
|
| 118 |
+ $end |
|
| 119 |
+ |
|
| 120 |
+RTN |
|
| 121 |
+ |
|
| 122 |
+@draw-cursor |
|
| 123 |
+ |
|
| 124 |
+ ( clear last cursor ) |
|
| 125 |
+ ,clear_icn =Sprite.addr |
|
| 126 |
+ ~pointer.x =Sprite.x |
|
| 127 |
+ ~pointer.y =Sprite.y |
|
| 128 |
+ #10 =Sprite.color |
|
| 129 |
+ |
|
| 130 |
+ ( record pointer positions ) |
|
| 131 |
+ ~Mouse.x =pointer.x ~Mouse.y =pointer.y |
|
| 132 |
+ |
|
| 133 |
+ ( draw new cursor ) |
|
| 134 |
+ ,cursor_icn =Sprite.addr |
|
| 135 |
+ ~pointer.x =Sprite.x |
|
| 136 |
+ ~pointer.y =Sprite.y |
|
| 137 |
+ #11 =Sprite.color |
|
| 138 |
+ |
|
| 139 |
+RTN |
|
| 140 |
+ |
|
| 141 |
+@handle [ 0010 2844 2810 0000 ] |
|
| 142 |
+@clear_icn [ 0000 0000 0000 0000 ] |
|
| 143 |
+@cursor_icn [ 80c0 e0f0 f8e0 1000 ] |
|
| 144 |
+ |
|
| 145 |
+@ERROR BRK |
| ... | ... |
@@ -8,7 +8,7 @@ |
| 8 | 8 |
;label { x 2 y 2 color 1 addr 2 }
|
| 9 | 9 |
;pict { x 2 y 2 width 2 height 2 color 1 addr 2 }
|
| 10 | 10 |
;rect { x1 2 y1 2 x2 2 y2 2 }
|
| 11 |
-;line { x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
|
|
| 11 |
+;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
|
|
| 12 | 12 |
;color { byte 1 }
|
| 13 | 13 |
|
| 14 | 14 |
|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|
| ... | ... |
@@ -44,15 +44,15 @@ BRK |
| 44 | 44 |
|
| 45 | 45 |
@draw-line ( x1 y1 x2 y2 color ) |
| 46 | 46 |
|
| 47 |
- ( load ) =color =Sprite.y =Sprite.x =line.y =line.x |
|
| 48 |
- ~Sprite.x ~line.x SUB2 ABS2 =line.dx |
|
| 49 |
- ~Sprite.y ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy |
|
| 50 |
- #ffff #00 ~line.x ~Sprite.x LTS2 #0002 MUL2 ADD2 =line.sx |
|
| 51 |
- #ffff #00 ~line.y ~Sprite.y LTS2 #0002 MUL2 ADD2 =line.sy |
|
| 47 |
+ ( load ) =color =line.y0 =line.x0 =line.y =line.x |
|
| 48 |
+ ~line.x0 ~line.x SUB2 ABS2 =line.dx |
|
| 49 |
+ ~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy |
|
| 50 |
+ #ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx |
|
| 51 |
+ #ffff #00 ~line.y ~line.y0 LTS2 #0002 MUL2 ADD2 =line.sy |
|
| 52 | 52 |
~line.dx ~line.dy ADD2 =line.e1 |
| 53 | 53 |
$loop |
| 54 | 54 |
~line.x =Screen.x ~line.y =Screen.y ~color =Screen.color |
| 55 |
- ,$end ~line.x ~Sprite.x EQU2 ~line.y ~Sprite.y EQU2 #0101 EQU2 JMP2? |
|
| 55 |
+ ,$end ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 JMP2? |
|
| 56 | 56 |
~line.e1 #0002 MUL2 =line.e2 |
| 57 | 57 |
,$skipy ~line.e2 ~line.dy LTS2 JMP2? |
| 58 | 58 |
~line.e1 ~line.dy ADD2 =line.e1 |
| ... | ... |
@@ -35,10 +35,10 @@ |
| 35 | 35 |
|
| 36 | 36 |
;center { x 2 y 2 }
|
| 37 | 37 |
;toolbar { x1 2 y1 2 x2 2 y2 2 }
|
| 38 |
-;cursor { x 2 y 2 x0 2 y0 2 size 1 patt 1 drag 1 mirror 1 }
|
|
| 38 |
+;cursor { x 2 y 2 x0 2 y0 2 size 1 patt 1 drag 1 mirror 1 oper 2 }
|
|
| 39 | 39 |
;zoom { active 1 x 2 y 2 }
|
| 40 | 40 |
;rect { x1 2 y1 2 x2 2 y2 2 }
|
| 41 |
-;line { x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
|
|
| 41 |
+;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
|
|
| 42 | 42 |
;origin { x1 2 y1 2 x2 2 y2 2 }
|
| 43 | 43 |
;color { byte 1 }
|
| 44 | 44 |
;pt0 { x 2 y 2 }
|
| ... | ... |
@@ -143,9 +143,16 @@ BRK |
| 143 | 143 |
,$no-touch-canvas ~Mouse.x CLN2r ~canvas.x1 GTH2 STH2r ~canvas.x2 LTH2 #0101 NEQ2 JMP2? |
| 144 | 144 |
,$no-touch-canvas ~Mouse.y CLN2r ~canvas.y1 GTH2 STH2r ~canvas.y2 LTH2 #0101 NEQ2 JMP2? |
| 145 | 145 |
|
| 146 |
- ~cursor.x0 ~canvas.x1 SUB2 ~cursor.y0 ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 #01 ,paint-line JSR2 |
|
| 146 |
+ ( set cursor operation ) |
|
| 147 |
+ ,add-pixel =cursor.oper |
|
| 148 |
+ ,$no-oper ~Mouse.state #01 EQU JMP2? |
|
| 149 |
+ ,remove-pixel =cursor.oper |
|
| 150 |
+ $no-oper |
|
| 147 | 151 |
|
| 152 |
+ ( paint line ) |
|
| 153 |
+ ~cursor.x0 ~canvas.x1 SUB2 ~cursor.y0 ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 #01 ,paint-line JSR2 |
|
| 148 | 154 |
|
| 155 |
+ ( paint fill ) |
|
| 149 | 156 |
~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 ,paint JSR2 |
| 150 | 157 |
|
| 151 | 158 |
,$no-mirror-mode ~cursor.mirror #00 EQU JMP2? |
| ... | ... |
@@ -246,8 +253,6 @@ RTN |
| 246 | 253 |
RTN |
| 247 | 254 |
|
| 248 | 255 |
@paint ( x y ) |
| 249 |
- |
|
| 250 |
- ,erase ~Mouse.state #10 EQU JMP2? |
|
| 251 | 256 |
|
| 252 | 257 |
#0003 SUB2 =pt0.y #0003 SUB2 =pt0.x ( cursor offset ) |
| 253 | 258 |
|
| ... | ... |
@@ -271,7 +276,7 @@ RTN |
| 271 | 276 |
( byte ) #00 ~px.y ADD2 LDR #07 ~px.x SUB SFT #01 AND |
| 272 | 277 |
#00 EQU ,$no-pixel ROT JMP2? |
| 273 | 278 |
,$no-pixel ,patternize JSR2 #00 EQU JMP2? |
| 274 |
- ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ,add-pixel JSR2 |
|
| 279 |
+ ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ~cursor.oper JSR2 |
|
| 275 | 280 |
$no-pixel |
| 276 | 281 |
( incr ) ~px.x #01 ADD =px.x |
| 277 | 282 |
,$hor ~px.x #08 LTH JMP2? |
| ... | ... |
@@ -283,41 +288,6 @@ RTN |
| 283 | 288 |
|
| 284 | 289 |
RTN |
| 285 | 290 |
|
| 286 |
-@erase ( x y ) |
|
| 287 |
- |
|
| 288 |
- #0003 SUB2 =pt0.y #0003 SUB2 =pt0.x ( cursor offset ) |
|
| 289 |
- |
|
| 290 |
- ( trim if zoomed ) |
|
| 291 |
- ,$no-zoom ~zoom.active #01 NEQ JMP2? |
|
| 292 |
- ~pt0.x 8/ ~zoom.x ADD2 #0003 SUB2 =pt0.x |
|
| 293 |
- ~pt0.y 8/ ~zoom.y ADD2 #0003 SUB2 =pt0.y |
|
| 294 |
- $no-zoom |
|
| 295 |
- |
|
| 296 |
- ( center zoom on paint ) |
|
| 297 |
- ,$no-follow ~zoom.active JMP2? |
|
| 298 |
- ~pt0.x ~canvas.w 2/ SUB2 #0003 ADD2 =zoom.x |
|
| 299 |
- ~pt0.y ~canvas.h 2/ SUB2 #0003 ADD2 =zoom.y |
|
| 300 |
- $no-follow |
|
| 301 |
- |
|
| 302 |
- #00 =px.x #00 =px.y |
|
| 303 |
- $ver |
|
| 304 |
- #00 =px.x |
|
| 305 |
- $hor |
|
| 306 |
- ( addr ) ,size_icn #00 ~cursor.size 8* ADD2 |
|
| 307 |
- ( byte ) #00 ~px.y ADD2 LDR #07 ~px.x SUB SFT #01 AND |
|
| 308 |
- #00 EQU ,$no-pixel ROT JMP2? |
|
| 309 |
- ,$no-pixel ,patternize JSR2 #00 EQU JMP2? |
|
| 310 |
- ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ,remove-pixel JSR2 |
|
| 311 |
- $no-pixel |
|
| 312 |
- ( incr ) ~px.x #01 ADD =px.x |
|
| 313 |
- ,$hor ~px.x #08 LTH JMP2? |
|
| 314 |
- ( incr ) ~px.y #01 ADD =px.y |
|
| 315 |
- ,$ver ~px.y #08 LTH JMP2? |
|
| 316 |
- ,draw-canvas JSR2 |
|
| 317 |
- ,draw-toolbar JSR2 |
|
| 318 |
- |
|
| 319 |
-RTN |
|
| 320 |
- |
|
| 321 | 291 |
@patternize |
| 322 | 292 |
|
| 323 | 293 |
,$noplain ~cursor.patt #00 NEQ JMP2? |
| ... | ... |
@@ -579,15 +549,15 @@ RTN |
| 579 | 549 |
|
| 580 | 550 |
@paint-line ( x1 y1 x2 y2 color ) |
| 581 | 551 |
|
| 582 |
- ( load ) =color =Sprite.y =Sprite.x =line.y =line.x |
|
| 583 |
- ~Sprite.x ~line.x SUB2 ABS2 =line.dx |
|
| 584 |
- ~Sprite.y ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy |
|
| 585 |
- #ffff #00 ~line.x ~Sprite.x LTS2 #0002 MUL2 ADD2 =line.sx |
|
| 586 |
- #ffff #00 ~line.y ~Sprite.y LTS2 #0002 MUL2 ADD2 =line.sy |
|
| 552 |
+ ( load ) =color =line.y0 =line.x0 =line.y =line.x |
|
| 553 |
+ ~line.x0 ~line.x SUB2 ABS2 =line.dx |
|
| 554 |
+ ~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy |
|
| 555 |
+ #ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx |
|
| 556 |
+ #ffff #00 ~line.y ~line.y0 LTS2 #0002 MUL2 ADD2 =line.sy |
|
| 587 | 557 |
~line.dx ~line.dy ADD2 =line.e1 |
| 588 | 558 |
$loop |
| 589 |
- ( paint ) ~line.x ~line.y ,add-pixel JSR2 |
|
| 590 |
- ,$end ~line.x ~Sprite.x EQU2 ~line.y ~Sprite.y EQU2 #0101 EQU2 JMP2? |
|
| 559 |
+ ( paint ) ~line.x ~line.y ~cursor.oper JSR2 |
|
| 560 |
+ ,$end ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 JMP2? |
|
| 591 | 561 |
~line.e1 #0002 MUL2 =line.e2 |
| 592 | 562 |
,$skipy ~line.e2 ~line.dy LTS2 JMP2? |
| 593 | 563 |
~line.e1 ~line.dy ADD2 =line.e1 |
| ... | ... |
@@ -698,4 +668,5 @@ RTN |
| 698 | 668 |
@ERROR BRK |
| 699 | 669 |
|
| 700 | 670 |
;canvas { w 2 h 2 x1 2 y1 2 x2 2 y2 2 }
|
| 671 |
+ |
|
| 701 | 672 |
@data [ ] |