uxn

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

commit ac76a7ca8b66c7b3d95be4f438a50ec2d8ffe572
parent 195a54c6d60ad88ca935540252fab69953e92fc1
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun, 21 Mar 2021 09:18:52 -0700

Added bresenham to noodle

Diffstat:
Mbuild.sh | 2+-
Mprojects/examples/gui.shapes.usm | 66+++++++++++++++++++++++++++---------------------------------------
Mprojects/software/noodle.usm | 31+++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 40 deletions(-)

diff --git a/build.sh b/build.sh @@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator # run -./bin/assembler projects/examples/gui.shapes.usm bin/boot.rom +./bin/assembler projects/software/noodle.usm bin/boot.rom ./bin/emulator bin/boot.rom diff --git a/projects/examples/gui.shapes.usm b/projects/examples/gui.shapes.usm @@ -8,14 +8,8 @@ ;label { x 2 y 2 color 1 addr 2 } ;pict { x 2 y 2 width 2 height 2 color 1 addr 2 } ;rect { x1 2 y1 2 x2 2 y2 2 } +;line { x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 } ;color { byte 1 } -( clean up ) -;a { x 2 y 2 } -;b { x 2 y 2 } -;s { x 2 y 2 } -;d { x 2 y 2 } -;err { short 2 } -;err2 { short 2 } |0100 @RESET @@ -43,6 +37,32 @@ BRK +@draw-line ( x1 y1 x2 y2 color ) + + ( load ) =color =Sprite.y =Sprite.x =line.y =line.x + ~Sprite.x ~line.x SUB2 ABS2 =line.dx + ~Sprite.y ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy + #ffff #00 ~line.x ~Sprite.x LTS2 #0002 MUL2 ADD2 =line.sx + #ffff #00 ~line.y ~Sprite.y LTS2 #0002 MUL2 ADD2 =line.sy + ~line.dx ~line.dy ADD2 =line.e1 + $loop + ~line.x =Screen.x ~line.y =Screen.y ~color =Screen.color + ,$end ~line.x ~Sprite.x EQU2 ~line.y ~Sprite.y EQU2 #0101 EQU2 JMP2? + ~line.e1 #0002 MUL2 =line.e2 + ,$skipy ~line.e2 ~line.dy LTS2 JMP2? + ~line.e1 ~line.dy ADD2 =line.e1 + ~line.x ~line.sx ADD2 =line.x + $skipy + ,$skipx ~line.e2 ~line.dx GTS2 JMP2? + ~line.e1 ~line.dx ADD2 =line.e1 + ~line.y ~line.sy ADD2 =line.y + $skipx + ,$loop JMP2 + + $end + +RTN + @line-rect ( x1 y1 x2 y2 color ) ( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1 @@ -101,38 +121,6 @@ RTN RTN -@draw-line ( x1 y1 x2 y2 ) - - =color - =b.y =b.x =a.y =a.x - ~b.x ~a.x SUB2 ABS2 =d.x - ~b.y ~a.y SUB2 ABS2 #0000 SWP2 SUB2 =d.y - #ffff #00 ~a.x ~b.x LTS2 #0002 MUL2 ADD2 =s.x - #ffff #00 ~a.y ~b.y LTS2 #0002 MUL2 ADD2 =s.y - ~d.x ~d.y ADD2 =err - - $loop - - ~a.x =Screen.x ~a.y =Screen.y ~color =Screen.color - ,$end ~a.x ~b.x EQU2 ~a.y ~b.y EQU2 #0101 EQU2 JMP2? - ~err #0002 MUL2 =err2 - - ,$skipy ~err2 ~d.y LTS2 JMP2? - ~err ~d.y ADD2 =err - ~a.x ~s.x ADD2 =a.x - $skipy - - ,$skipx ~err2 ~d.x GTS2 JMP2? - ~err ~d.x ADD2 =err - ~a.y ~s.y ADD2 =a.y - $skipx - - ,$loop JMP2 - - $end - -RTN - @pict_small [ ff80 8080 8080 8088 ffff fffc f8f9 f1f4 diff --git a/projects/software/noodle.usm b/projects/software/noodle.usm @@ -23,6 +23,7 @@ %RTN { JMP2r } %RTN? { JMP2r? } +%ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? } %++ { #0001 ADD2 } %-- { #0001 SUB2 } %2/ { #0001 SFT2 } %8/ { #0003 SFT2 } %8* { #0030 SFT2 } @@ -35,6 +36,7 @@ ;cursor { x 2 y 2 x0 2 y0 2 size 1 patt 1 drag 1 mirror 1 } ;zoom { active 1 x 2 y 2 } ;rect { x1 2 y1 2 x2 2 y2 2 } +;line { x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 } ;origin { x1 2 y1 2 x2 2 y2 2 } ;color { byte 1 } ;pt0 { x 2 y 2 } @@ -125,6 +127,9 @@ BRK ,$no-touch-canvas ~Mouse.x CLN2r ~canvas.x1 GTH2 STH2r ~canvas.x2 LTH2 #0101 NEQ2 JMP2? ,$no-touch-canvas ~Mouse.y CLN2r ~canvas.y1 GTH2 STH2r ~canvas.y2 LTH2 #0101 NEQ2 JMP2? + ~cursor.x0 ~canvas.x1 SUB2 ~cursor.y0 ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 #01 ,paint-line JSR2 + + ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 ,paint JSR2 ,$no-mirror-mode ~cursor.mirror #00 EQU JMP2? @@ -556,6 +561,32 @@ RTN ( Generics ) +@paint-line ( x1 y1 x2 y2 color ) + + ( load ) =color =Sprite.y =Sprite.x =line.y =line.x + ~Sprite.x ~line.x SUB2 ABS2 =line.dx + ~Sprite.y ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy + #ffff #00 ~line.x ~Sprite.x LTS2 #0002 MUL2 ADD2 =line.sx + #ffff #00 ~line.y ~Sprite.y LTS2 #0002 MUL2 ADD2 =line.sy + ~line.dx ~line.dy ADD2 =line.e1 + $loop + ( paint ) ~line.x ~line.y ,add-pixel JSR2 + ,$end ~line.x ~Sprite.x EQU2 ~line.y ~Sprite.y EQU2 #0101 EQU2 JMP2? + ~line.e1 #0002 MUL2 =line.e2 + ,$skipy ~line.e2 ~line.dy LTS2 JMP2? + ~line.e1 ~line.dy ADD2 =line.e1 + ~line.x ~line.sx ADD2 =line.x + $skipy + ,$skipx ~line.e2 ~line.dx GTS2 JMP2? + ~line.e1 ~line.dx ADD2 =line.e1 + ~line.y ~line.sy ADD2 =line.y + $skipx + ,$loop JMP2 + + $end + +RTN + @line-rect ( x1 y1 x2 y2 color ) ( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1