|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1 |10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1 |20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |80 @Controller/vector $2 &button $1 &key $1 |90 @Mouse/vector $2 &x $2 &y $2 &state $5 &scrolly &scrolly-hb $1 &scrolly-lb $1 |a0 @File/vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 |58 @canvas-width |1f @canvas-height ( zero page vars ) |00 @x $2 @y $2 (to run gui: `./run_ui.sh one_line_canvas.tal`) (to run debugger: `../uxn/bin/uxnasm one_line_canvas.tal one_line_canvas.rom && ../uxn/bin/uxnemu ../beetbug.rom ./one_line_canvas.rom`) %dbug { #01 .System/debug DEO } %PX { #01 .Screen/pixel DEO } |0100 @on-reset setup-gui ( draw canvas bounds ) ( top line ) .canvas-width #01 ADD .canvas-width .canvas-height #01 SUB draw-h-line ( bot line ) .canvas-width #01 ADD .canvas-width .canvas-height #02 MUL #01 ADD draw-h-line ( left line ) .canvas-height #01 ADD .canvas-width #01 SUB .canvas-height draw-v-line ( right line ) .canvas-height #01 ADD .canvas-width #02 MUL #01 ADD .canvas-height draw-v-line ( set pxs-pt to start of pixels ) ;pxs ;pxs-pt STA2 ;on-mouse .Mouse/vector DEO2 ;on-controller .Controller/vector DEO2 BRK @on-controller .Controller/key DEI ( if "e" key is pressed ) #65 EQU ?write-drawing-file-to-disk BRK @add-px-to-drawing ( figure out if px on on canvas ) ( x too small ) LIT2 =canvas-width .x LDZ2 GTH2 ?/end ( x too big ) LIT2 =canvas-width #0002 MUL2 .x LDZ2 LTH2 ?/end ( y too small ) LIT2 =canvas-height .y LDZ2 GTH2 ?/end ( y too big ) LIT2 =canvas-height #0002 MUL2 .y LDZ2 LTH2 ?/end ( draw px to screen ) .x LDZ2 .Screen/x DEO2 .y LDZ2 .Screen/y DEO2 #01 .Screen/pixel DEO ( set local pt to start of pixels ) !{ &local-pt $2 } ;pxs ,/local-pt STR2 &loop ( is the drawing done? ) ;pxs-pt LDA2 ( pt* ) ;pxs #1550 ADD2 ( pt* end-of-px* ) EQU2 ?/end ( check if current xy has already been visited ) ,/local-pt LDR2 LDA2 ( x1 y1 ) .x LDZ2 NIP ( x1 y1 x ) .y LDZ2 NIP ( x1 y1 x y ) EQU2 ?/end ( have we go through the whole list? ) ,/local-pt LDR2 ( local-pt* ) ;pxs #1550 ADD2 ( local-pt* end-of-px* ) EQU2 ?/save ( incrment pxs pointer and save it ) ,/local-pt LDR2 ( local-pt* ) #0002 ADD2 ( local-pt*+2 ) ,/local-pt STR2 !&loop &save .x LDZ2 NIP .y LDZ2 NIP ( x y ) ;pxs-pt LDA2 ( x y pt* ) STA2 ;pxs-pt LDA2 INC2 INC2 ;pxs-pt STA2 &end JMP2r @write-drawing-file-to-disk ;/filename .File/name DEO2 #1550 .File/length DEO2 ;pxs .File/write DEO2 JMP2r &filename "one_line.txt $1 @on-mouse ( -> ) .Mouse/x DEI2 .x STZ2 .Mouse/y DEI2 .y STZ2 draw-cursor add-px-to-drawing BRK @draw-cursor ( clear fg ) LIT2 0000 .Screen/x DEO2 LIT2 0000 .Screen/y DEO2 #c0 .Screen/pixel DEO ( draw cursor sprite to fg ) .x LDZ2 #0002 SUB2 .Screen/x DEO2 .y LDZ2 #0002 SUB2 .Screen/y DEO2 ;cursor-sprite .Screen/addr DEO2 #41 .Screen/sprite DEO JMP2r @draw-v-line ( l x y ) SWP ( l y x ) #00 ( l y x 00 ) SWP .Screen/x DEO2 ( l y ) ( store vars ) !{ &y $1 &l $1 } ,/y STR ,/l STR &loop ( set y ) ,/y LDR DUP ( y y ) #00 SWP ( y 00 y ) .Screen/y DEO2 ( y ) ( draw pixel ) PX ( incrment y ) INC ( y+1 ) ,/y STR ( ) ( decrement l ) ,/l LDR #01 ( l 01 ) SUB ( l-1 ) ,/l STRk POP ( l ) #00 NEQ ?&loop JMP2r @draw-h-line ( l x y ) #00 ( l x y 00 ) SWP .Screen/y DEO2 ( l x ) ( store vars ) !{ &x $1 &l $1 } ,/x STR ,/l STR &loop ( set x ) ,/x LDR DUP ( x x ) #00 SWP ( x 00 x ) .Screen/x DEO2 ( x ) ( draw pixel ) PX ( incrment x ) INC ( x+1 ) ,/x STR ( ) ( decrement l ) ,/l LDR #01 ( l 01 ) SUB ( l-1 ) ,/l STRk POP ( l ) #00 NEQ ?&loop JMP2r @setup-gui ( -- ) (set screen height and width the 3x canvas size) LIT2 =canvas-width #0003 MUL2 .Screen/width DEO2 LIT2 =canvas-height #0003 MUL2 .Screen/height DEO2 (set basic color scheme) #f07f .System/r DEO2 #f0d6 .System/g DEO2 #f0b2 .System/b DEO2 JMP2r @cursor-sprite 20 20 d8 20 20 00 00 00 ( . . # . . . . . 20 . . # . . . . . 20 # # . # # . . . d8 . . # . . . . . 20 . . # . . . . . 20 . . . . . . . . 7e . . . . . . . . 3c . . . . . . . . 18 ) @pxs-pt $2 @pxs $1550 ( 5456 ) ( pxs are the pixels of the drawing in order they are drawn 0001 05 <-- x1 0002 04 <-- y1 0003 05 <-- x2 0004 03 <-- y2 )