uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 4633fcf920b53afe91148de7360579da93145da1
parent f792684b44a7d84bf5ee2e0990d94dc6ecb45749
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu, 18 Mar 2021 10:13:55 -0700

Starting noodle

Diffstat:
Mprojects/software/noodle.usm | 236+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Aprojects/tests/draw.usm | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 297 insertions(+), 28 deletions(-)

diff --git a/projects/software/noodle.usm b/projects/software/noodle.usm @@ -1,22 +1,35 @@ ( app/noodle : illustration program + + TODO + - Only redraw when mouse has changed + - Only redraw target tile ) %RTN { JMP2r } %RTN? { JMP2r? } +%++ { #0001 ADD2 } %-- { #0001 SUB2 } +%2/ { #0001 SHR2 } %2* { #0001 SHL2 } +%8/ { #0003 SHR2 } %8* { #0003 SHL2 } +%8- { #0008 SUB2 } %8+ { #0008 ADD2 } +%MOD8 { #0007 AND2 } -%ABS { DUP #07 SHR #ff SWP MUL? } ( abs ) -%ABS2 { DUP2 #000f SHR2 #ffff SWP2 SWP POP MUL2? } ( abs2 ) - +;toolbar { x 2 y 2 } ;cursor { x 2 y 2 } -;a { x 2 y 2 } -;b { x 2 y 2 } -;d { x 2 y 2 } -;s { x 2 y 2 } +;rect { x1 2 y1 2 x2 2 y2 2 } +;color { byte 1 } +;pt { x 2 y 2 } +;label { x 2 y 2 color 1 addr 2 } ( remove ) |0100 @RESET + + #0008 =toolbar.x #0068 =toolbar.y - #0020 #0020 #0090 #0070 ,draw-line JSR2 + #0010 =canvas.x1 #0020 =canvas.y1 + #0026 =canvas.w #0010 =canvas.h ,fit JSR2 + + ,draw-titlebar JSR2 + ,draw-toolbar JSR2 BRK @@ -24,27 +37,65 @@ BRK ,draw-cursor JSR2 + ,$no-touch ~Mouse.state #01 NEQ JMP2? + + ,$no-paint ~Mouse.x CLN2r ~canvas.x1 GTH2 STH2r ~canvas.x2 LTH2 #0101 NEQ2 JMP2? + ,$no-paint ~Mouse.y CLN2r ~canvas.y1 GTH2 STH2r ~canvas.y2 LTH2 #0101 NEQ2 JMP2? + + ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 ,paint JSR2 + + $no-paint + + $no-touch + BRK -@draw-line ( x1 y1 x2 y2 ) +@paint ( x y ) - =b.y =b.x ( target, b ) - =a.y =a.x ( target, a ) + =pt.y =pt.x - ( dx = abs[bx - ax] ) - ~b.x ~a.x SUB2 ABS2 =d.x + ( get tile addr ) ,data ~pt.x 8/ ~pt.y 8/ ~canvas.w MUL2 ADD2 8* ~pt.y MOD8 ADD2 ADD2 - ( dx = abs[bx - ax] ) - ~b.y ~a.y SUB2 ABS2 =d.y + ( load ) DUP2 LDR + ( mask ) #01 #07 ~pt.x MOD8 SWP POP SUB SHL XOR + ( save ) ROT ROT STR - ( sx = ax < bx ? 1 : -1; ) - #ffff #00 ~a.x ~b.x GTH2 #0002 MUL2 ADD2 =s.x - - ( sy = ay < by ? 1 : -1; ) - #ffff #00 ~a.y ~b.y GTH2 #0002 MUL2 ADD2 =s.y + ,redraw JSR2 + +RTN + +@redraw + ~canvas.y1 =Sprite.y + ,data =Sprite.addr + $ver + ~canvas.x1 =Sprite.x + $hor + ( draw ) #09 =Sprite.color + ( incr ) ~Sprite.x 8+ =Sprite.x + ( incr ) ~Sprite.addr 8+ =Sprite.addr + ,$hor ~Sprite.x ~canvas.x2 LTH2 JMP2? + ( incr ) ~Sprite.y 8+ =Sprite.y + ,$ver ~Sprite.y ~canvas.y2 LTH2 JMP2? + + ,draw-toolbar JSR2 + +RTN - #01 =Screen.color +@line-rect ( x1 y1 x2 y2 color ) + + ( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1 + $hor + ( incr ) ~Screen.x ++ =Screen.x + ( draw ) ~rect.y1 =Screen.y ~color =Screen.color + ( draw ) ~rect.y2 =Screen.y ~color =Screen.color + ,$hor ~Screen.x ~rect.x2 LTH2 JMP2? + ~rect.y1 =Screen.y + $ver + ( draw ) ~rect.x1 =Screen.x ~color =Screen.color + ( draw ) ~rect.x2 =Screen.x ~color =Screen.color + ( incr ) ~Screen.y ++ =Screen.y + ,$ver ~Screen.y ~rect.y2 ++ LTH2 JMP2? RTN @@ -68,15 +119,144 @@ RTN ( draw new cursor ) ~cursor.x =Sprite.x ~cursor.y =Sprite.y - ,tool_pointer =Sprite.addr - #12 =Sprite.color + ,brush_pointer =Sprite.addr + #13 =Sprite.color + +RTN + +@draw-titlebar + + ~canvas.x1 ~canvas.y2 #06 ,filepath + ( load ) =label.addr =label.color =Sprite.y =Sprite.x + ~label.addr + $loop NOP + ( draw ) DUP2 LDR #00 SWP #20 SUB 8* ,font ADD2 =Sprite.addr ~label.color =Sprite.color + ( incr ) ++ + ( incr ) ~Sprite.x 8+ =Sprite.x + DUP2 LDR #00 NEQ ^$loop MUL JMP + POP2 RTN -@tool_pointer [ 80c0 e0f0 f8e0 1000 ] -@tool_hand [ 4040 4070 f8f8 f870 ] -@tool_eraser [ 2050 b87c 3e1c 0800 ] +@fit + + ~canvas.w 8* ~canvas.x1 ADD2 =canvas.x2 + ~canvas.h 8* ~canvas.y1 ADD2 =canvas.y2 + ~canvas.x1 -- ~canvas.y1 -- ~canvas.x2 ~canvas.y2 #01 ,line-rect JSR2 + ,redraw JSR2 + +RTN + +@draw-toolbar + + ~toolbar.x -- ~toolbar.y -- ~toolbar.x #0010 ADD2 ~toolbar.y #0050 ADD2 #02 ,line-rect JSR2 + ~toolbar.x #0002 SUB2 ~toolbar.y #0002 SUB2 ~toolbar.x #0010 ADD2 ++ ~toolbar.y #0050 ADD2 ++ #01 ,line-rect JSR2 + + ~toolbar.x =Sprite.x + ~toolbar.y =Sprite.y + ,size0_icn =Sprite.addr + + ( draw brush sizes ) + + $sizes + ( draw ) #09 =Sprite.color + ( incr ) ~Sprite.y 8+ =Sprite.y + ( incr ) ~Sprite.addr 8+ =Sprite.addr + ,$sizes ~Sprite.y ~toolbar.y #0040 ADD2 LTH2 JMP2? + + ( draw brush tools ) + + ~toolbar.x 8+ =Sprite.x + ~toolbar.y =Sprite.y + + $brushes + ( draw ) #09 =Sprite.color + ( incr ) ~Sprite.y 8+ =Sprite.y + ( incr ) ~Sprite.addr 8+ =Sprite.addr + ,$brushes ~Sprite.y ~toolbar.y #0040 ADD2 LTH2 JMP2? + +RTN + +@size0_icn [ 0000 0010 0000 0000 ] +@size1_icn [ 0000 1038 1000 0000 ] +@size2_icn [ 0000 3838 3800 0000 ] +@size3_icn [ 0010 387c 3810 0000 ] +@size4_icn [ 0038 7c7c 7c38 0000 ] +@size5_icn [ 1038 7cfe 7c38 1000 ] +@size6_icn [ 387c fefe fe7c 3800 ] +@size7_icn [ 7cfe fefe fefe 7c00 ] + +@brush_pointer [ 80c0 e0f0 f8e0 1000 ] +@brush_hand [ 4040 4070 f8f8 f870 ] +@brush_eraser [ 2050 b87c 3e1c 0800 ] +@brush_pattern0 [ ffff ffff ffff ffff ] +@brush_pattern1 [ aa55 aa55 aa55 aa55 ] +@brush_pattern2 [ 8800 2200 8800 2200 ] + +@mode_guidesoff [ 0038 4492 2810 0000 ] +@mode_zoomout [ 3048 8484 4834 0200 ] + +@mode_guideson [ 0000 0082 4438 0000 ] +@mode_zoomin [ 3245 8284 4834 0200 ] + @blank_icn [ 0000 0000 0000 0000 ] +@filepath [ projects/drawings/hello.chr 00 ] + +@font ( specter8-frag font ) +[ + 0000 0000 0000 0000 0008 0808 0800 0800 + 0014 1400 0000 0000 0024 7e24 247e 2400 + 0008 1e28 1c0a 3c08 0000 2204 0810 2200 + 0030 4832 4c44 3a00 0008 1000 0000 0000 + 0004 0808 0808 0400 0020 1010 1010 2000 + 0000 2214 0814 2200 0000 0808 3e08 0800 + 0000 0000 0000 0810 0000 0000 3e00 0000 + 0000 0000 0000 0800 0000 0204 0810 2000 + 003c 464a 5262 3c00 0018 0808 0808 1c00 + 003c 4202 3c40 7e00 003c 421c 0242 3c00 + 000c 1424 447e 0400 007e 407c 0242 3c00 + 003c 407c 4242 3c00 007e 0204 0810 1000 + 003c 423c 4242 3c00 003c 4242 3e02 3c00 + 0000 0010 0000 1000 0000 1000 0010 1020 + 0000 0810 2010 0800 0000 003e 003e 0000 + 0000 1008 0408 1000 003c 420c 1000 1000 + 003c 4232 4a42 3c00 003c 4242 7e42 4200 + 007c 427c 4242 7c00 003c 4240 4042 3c00 + 007c 4242 4242 7c00 007e 4078 4040 7e00 + 007e 4078 4040 4000 003c 4240 4642 3c00 + 0042 427e 4242 4200 001c 0808 0808 1c00 + 007e 0202 0242 3c00 0042 4478 4442 4200 + 0040 4040 4040 7e00 0042 665a 4242 4200 + 0042 6252 4a46 4200 003c 4242 4242 3c00 + 007c 4242 7c40 4000 003c 4242 4244 3a00 + 007c 4242 7c44 4200 003e 403c 0242 3c00 + 007e 0808 0808 1000 0042 4242 4244 3a00 + 0042 4242 4224 1800 0042 4242 5a66 4200 + 0042 423c 4242 4200 0042 423e 0242 3c00 + 007e 020c 3040 7e00 000c 0808 0808 0c00 + 0040 2010 0804 0200 0030 1010 1010 3000 + 0008 1400 0000 0000 0000 0000 0000 7e00 + 0008 0400 0000 0000 0000 3c02 3e42 3a00 + 0040 407c 4242 7c00 0000 3c42 4042 3c00 + 0002 023e 4242 3e00 0000 3c42 7e40 3e00 + 0000 3e40 7840 4000 0000 3c42 3e02 3c00 + 0040 405c 6242 4200 0008 0018 0808 0400 + 0008 0018 0808 4830 0040 4244 7844 4200 + 0010 1010 1010 0c00 0000 6c52 5252 5200 + 0000 5c62 4242 4200 0000 3c42 4242 3c00 + 0000 7c42 427c 4040 0000 3e42 423e 0202 + 0000 5c62 4040 4000 0000 3e40 3c02 7c00 + 0008 7e08 0808 1000 0000 4242 4244 3a00 + 0000 4242 4224 1800 0000 5252 5252 2e00 + 0000 4224 1824 4200 0000 4242 3e02 7c00 + 0000 7e02 3c40 7e00 000c 0810 1008 0c00 + 0008 0808 0808 0800 0030 1008 0810 3000 + 0000 0032 4c00 0000 3c42 99a1 a199 423c + +] + +|8000 ;canvas { w 2 h 2 x1 2 y1 2 x2 2 y2 2 } +|9000 @data |F000 @ERROR BRK @@ -89,4 +269,4 @@ RTN |FF60 ;File { pad 8 name 2 length 2 load 2 save 2 } |FFF0 .RESET .FRAME .ERROR ( vectors ) -|FFF8 [ 13fd 1ef3 1bf2 ] ( palette ) -\ No newline at end of file +|FFF8 [ c0fd c0f3 c0f2 ] ( palette ) +\ No newline at end of file diff --git a/projects/tests/draw.usm b/projects/tests/draw.usm @@ -0,0 +1,88 @@ +( tests/draw ) + +%RTN { JMP2r } +%RTN? { JMP2r? } + +;cursor { x 2 y 2 } +;a { x 2 y 2 } +;b { x 2 y 2 } +;s { x 2 y 2 } + +|0100 @RESET + + #0020 #0020 #0070 #0080 ,draw-line JSR2 + #0020 #0080 #0070 #0030 ,draw-line JSR2 + #00a0 #0020 #0050 #00b0 ,draw-line JSR2 + #00b0 #0090 #0030 #0010 ,draw-line JSR2 + +BRK + +@draw-line ( x1 y1 x2 y2 ) + + =b.y =b.x ( target, b ) + =a.y =a.x ( target, a ) + + ~a.x =Screen.x ~a.y =Screen.y #02 =Screen.color + ~b.x =Screen.x ~b.y =Screen.y #02 =Screen.color + + ( dx = abs[bx - ax] ) + ~b.x ~a.x SUB2 ABS2 =d.x + + ( dy = -abs[by - ay] ) + ~b.y ~a.y SUB2 ABS2 #0000 SWP2 SUB2 =d.y + + ( sx = ax < bx ? 1 : -1; ) + #ffff #00 ~a.x ~b.x LTH2 #0002 MUL2 ADD2 =s.x + + ( sy = ay < by ? 1 : -1; ) + #ffff #00 ~a.y ~b.y LTH2 #0002 MUL2 ADD2 =s.y + + ( err = dx + dy ) + ~d.x ~d.y ADD2 =err + + ( loop ) + $loop + + ( putchr[ax, ay, color]; ) + ~a.x =Screen.x ~a.y =Screen.y #01 =Screen.color + + ( if[ax == bx && ay == by] break; ) + ,$end ~a.x ~b.x EQU2 ~a.y ~b.y EQU2 #0101 EQU2 JMP2? + + ( fallback, remove ) + ,$end ~i #90 GTH JMP2? ~i #01 ADD =i + + ( err2 = 2 * err; ) + ~err #0002 MUL2 =err2 + + ~err2 =Console.short + + ( if[err2 >= dy] ) + ,$skipy ~err2 ~d.y LTH2 JMP2? + ( err += dy; ) + ~err ~d.y ADD2 =err + ( ax += sx; ) + ~a.x ~s.x ADD2 =a.x + $skipy + + ( if[err2 <= dx] ) + ,$skipx ~err2 ~d.x GTH2 JMP2? + ( err += dx; ) + ~err ~d.x ADD2 =err + ( ay += sy; ) + ~a.y ~s.y ADD2 =a.y + $skipx + + ,$loop JMP2 + + $end + +RTN + +|c000 @FRAME +|d000 @ERROR + +|FF00 ;Console { pad 8 char 1 byte 1 short 2 } + +|FFF0 .RESET .FRAME .ERROR ( vectors ) +|FFF8 [ 13fd 1ef3 1bf2 ] ( palette ) +\ No newline at end of file