Optimized noodle

This commit is contained in:
neauoire 2021-03-21 16:33:34 -07:00
parent d7f355b0be
commit 5eedfea8e6
4 changed files with 172 additions and 56 deletions

View File

@ -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/software/left.usm bin/boot.rom
./bin/assembler projects/software/noodle.usm bin/boot.rom
./bin/emulator bin/boot.rom

View File

@ -0,0 +1,145 @@
( draw bezier )
%RTN { JMP2r }
%2/ { #0002 DIV2 }
%ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? }
%STEP8 { #0033 SFT2 }
%STEP4 { #0022 SFT2 }
;pt1 { x 2 y 2 }
;pt2 { x 2 y 2 }
;pt3 { x 2 y 2 }
;pta { x 2 y 2 }
;ptb { x 2 y 2 }
;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
;color { byte 1 }
;pointer { x 2 y 2 }
;i { byte 1 }
;j { byte 1 }
( devices )
|0100 ;Console { pad 8 char 1 byte 1 short 2 }
|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|01F0 .RESET .FRAME .ERROR ( vectors )
|01F8 [ 13fd 1ef3 1bf2 ] ( palette )
|0200 @RESET
#0020 #0020 =pt1.y =pt1.x
#0040 #0080 =pt2.y =pt2.x
#00f0 #00a0 =pt3.y =pt3.x
,redraw JSR2
BRK
@FRAME
,draw-cursor JSR2
,$no-touch ~Mouse.state #00 EQU JMP2?
~Mouse.x STEP4 =pt2.x
~Mouse.y STEP4 =pt2.y
,redraw JSR2
$no-touch
BRK
@redraw
#0000 =Sprite.y
$ver
#0000 =Sprite.x
$hor
( draw ) #00 =Sprite.color
( incr ) ~Sprite.x #0008 ADD2 =Sprite.x
( incr ) #0000 =Sprite.addr
,$hor ~Sprite.x ~Screen.width LTH2 JMP2?
( incr ) ~Sprite.y #0008 ADD2 =Sprite.y
,$ver ~Sprite.y ~Screen.height LTH2 JMP2?
~pt1.x ~pt1.y ~pt2.x ~pt2.y #03 ,draw-line JSR2
~pt2.x ~pt2.y ~pt3.x ~pt3.y #03 ,draw-line JSR2
~pt1.x ~pt1.y #0a ,draw-point JSR2
~pt2.x ~pt2.y #0a ,draw-point JSR2
~pt3.x ~pt3.y #0a ,draw-point JSR2
#00 =i
$loop
~pt1.x ~pt2.x ~pt1.x SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =pta.x
~pt1.y ~pt2.y ~pt1.y SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =pta.y
~pt2.x ~pt3.x ~pt2.x SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =ptb.x
~pt2.y ~pt3.y ~pt2.y SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =ptb.y
~pta.x ~pta.y ~ptb.x ~ptb.y #0a ,draw-line JSR2
( incr ) ~i #01 ADD =i
,$loop ~i #08 LTH JMP2?
RTN
@draw-point ( x y color )
=color
#0003 SUB2 =Sprite.y
#0003 SUB2 =Sprite.x
,handle =Sprite.addr
~color =Sprite.color
RTN
@draw-line ( x1 y1 x2 y2 color )
( load ) =color =line.y0 =line.x0 =line.y =line.x
~line.x0 ~line.x SUB2 ABS2 =line.dx
~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy
#ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx
#ffff #00 ~line.y ~line.y0 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 ~line.x0 EQU2 ~line.y ~line.y0 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
@draw-cursor
( clear last cursor )
,clear_icn =Sprite.addr
~pointer.x =Sprite.x
~pointer.y =Sprite.y
#10 =Sprite.color
( record pointer positions )
~Mouse.x =pointer.x ~Mouse.y =pointer.y
( draw new cursor )
,cursor_icn =Sprite.addr
~pointer.x =Sprite.x
~pointer.y =Sprite.y
#11 =Sprite.color
RTN
@handle [ 0010 2844 2810 0000 ]
@clear_icn [ 0000 0000 0000 0000 ]
@cursor_icn [ 80c0 e0f0 f8e0 1000 ]
@ERROR BRK

View File

@ -8,7 +8,7 @@
;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 }
;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
;color { byte 1 }
|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
@ -44,15 +44,15 @@ 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
( load ) =color =line.y0 =line.x0 =line.y =line.x
~line.x0 ~line.x SUB2 ABS2 =line.dx
~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy
#ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx
#ffff #00 ~line.y ~line.y0 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?
,$end ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 JMP2?
~line.e1 #0002 MUL2 =line.e2
,$skipy ~line.e2 ~line.dy LTS2 JMP2?
~line.e1 ~line.dy ADD2 =line.e1

View File

@ -35,10 +35,10 @@
;center { x 2 y 2 }
;toolbar { x1 2 y1 2 x2 2 y2 2 }
;cursor { x 2 y 2 x0 2 y0 2 size 1 patt 1 drag 1 mirror 1 }
;cursor { x 2 y 2 x0 2 y0 2 size 1 patt 1 drag 1 mirror 1 oper 2 }
;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 }
;line { x0 2 y0 2 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 }
@ -143,9 +143,16 @@ 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?
( set cursor operation )
,add-pixel =cursor.oper
,$no-oper ~Mouse.state #01 EQU JMP2?
,remove-pixel =cursor.oper
$no-oper
( paint line )
~cursor.x0 ~canvas.x1 SUB2 ~cursor.y0 ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 #01 ,paint-line JSR2
( paint fill )
~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 ,paint JSR2
,$no-mirror-mode ~cursor.mirror #00 EQU JMP2?
@ -246,8 +253,6 @@ RTN
RTN
@paint ( x y )
,erase ~Mouse.state #10 EQU JMP2?
#0003 SUB2 =pt0.y #0003 SUB2 =pt0.x ( cursor offset )
@ -271,7 +276,7 @@ RTN
( byte ) #00 ~px.y ADD2 LDR #07 ~px.x SUB SFT #01 AND
#00 EQU ,$no-pixel ROT JMP2?
,$no-pixel ,patternize JSR2 #00 EQU JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ,add-pixel JSR2
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ~cursor.oper JSR2
$no-pixel
( incr ) ~px.x #01 ADD =px.x
,$hor ~px.x #08 LTH JMP2?
@ -283,41 +288,6 @@ RTN
RTN
@erase ( x y )
#0003 SUB2 =pt0.y #0003 SUB2 =pt0.x ( cursor offset )
( trim if zoomed )
,$no-zoom ~zoom.active #01 NEQ JMP2?
~pt0.x 8/ ~zoom.x ADD2 #0003 SUB2 =pt0.x
~pt0.y 8/ ~zoom.y ADD2 #0003 SUB2 =pt0.y
$no-zoom
( center zoom on paint )
,$no-follow ~zoom.active JMP2?
~pt0.x ~canvas.w 2/ SUB2 #0003 ADD2 =zoom.x
~pt0.y ~canvas.h 2/ SUB2 #0003 ADD2 =zoom.y
$no-follow
#00 =px.x #00 =px.y
$ver
#00 =px.x
$hor
( addr ) ,size_icn #00 ~cursor.size 8* ADD2
( byte ) #00 ~px.y ADD2 LDR #07 ~px.x SUB SFT #01 AND
#00 EQU ,$no-pixel ROT JMP2?
,$no-pixel ,patternize JSR2 #00 EQU JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ,remove-pixel JSR2
$no-pixel
( incr ) ~px.x #01 ADD =px.x
,$hor ~px.x #08 LTH JMP2?
( incr ) ~px.y #01 ADD =px.y
,$ver ~px.y #08 LTH JMP2?
,draw-canvas JSR2
,draw-toolbar JSR2
RTN
@patternize
,$noplain ~cursor.patt #00 NEQ JMP2?
@ -579,15 +549,15 @@ RTN
@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
( load ) =color =line.y0 =line.x0 =line.y =line.x
~line.x0 ~line.x SUB2 ABS2 =line.dx
~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy
#ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx
#ffff #00 ~line.y ~line.y0 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?
( paint ) ~line.x ~line.y ~cursor.oper JSR2
,$end ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 JMP2?
~line.e1 #0002 MUL2 =line.e2
,$skipy ~line.e2 ~line.dy LTS2 JMP2?
~line.e1 ~line.dy ADD2 =line.e1
@ -698,4 +668,5 @@ RTN
@ERROR BRK
;canvas { w 2 h 2 x1 2 y1 2 x2 2 y2 2 }
@data [ ]