diff --git a/.gitignore b/.gitignore index 9a323db..b80a777 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ *png *bmp /bin +*.chr *snarf -*.chr \ No newline at end of file +*theme \ No newline at end of file diff --git a/src/main.tal b/src/main.tal index 8cd125e..d34ff2c 100644 --- a/src/main.tal +++ b/src/main.tal @@ -20,11 +20,11 @@ %++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } %<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } -%HOR { #20 } %VER { #10 } -%WIDTH { HOR TOS #0008 ** } -%LENGTH { HOR TOS VER TOS ** #0010 ** } +%DEBUG { ;print-hex JSR2 #0a .Console/write DEO } +%DEBUG2 { SWP ;print-hex JSR2 ;print-hex JSR2 #0a .Console/write DEO } -%8** { #30 SFT2 } +%8** { #30 SFT2 } %8// { #03 SFT2 } +%TOB { SWP POP } %TOS { #00 SWP } %RTN { JMP2r } %MOD { DUP2 / * - } %MOD2 { OVR2 OVR2 // ** -- } @@ -32,7 +32,6 @@ %ROL { DUP #07 SFT SWP #10 SFT + } %ROR { DUP #70 SFT SWP #01 SFT + } %SFL { #40 SFT SFT } -%TOB { SWP POP } %TOS { #00 SWP } %LTS2 { #8000 ++ SWP2 #8000 ++ >> } %INCR { SWP #01 + SWP } %INCR2 { SWP2 #0001 ++ SWP2 } @@ -40,6 +39,11 @@ %STEP8 { #33 SFT2 } %TOGGLE { LDZk #00 = SWP STZ } %GET-ITERATORS { SWP2k POP SWP POP } +%GET-ITER { OVR2 SWP POP OVR SWP } + +%HOR { #20 } %VER { #10 } +%WIDTH { HOR TOS #0008 ** } +%LENGTH { HOR TOS VER TOS ** #0010 ** } %BANK { #2000 } %BANK-TEMP { #4000 } @@ -88,6 +92,9 @@ &tool $1 &focus $2 &zoom $1 +@selection + &x1 $1 &y1 $1 + &x2 $1 &y2 $1 @path &length $1 &name $20 @@ -95,9 +102,9 @@ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &width $2 &height $2 -@pointer - &x $2 &y $2 - @color $1 +@cursor + &x $2 &y $2 &last $1 +@color $1 @rect [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] ( interface ) @@ -106,8 +113,11 @@ @blendview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] @dataview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] @preview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] -@tileview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] @zoomview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] +@tileview + &x1 $2 &y1 $2 + &x2 $2 &y2 $2 + &width $2 &height $2 ( program ) @@ -134,6 +144,9 @@ #01 .settings/tool STZ BANK .settings/focus STZ2 + HOR TOS #0008 ** .tileview/width STZ2 + VER TOS #0008 ** .tileview/height STZ2 + .Screen/width DEI2 #01 SFT2 .frame/width LDZ2 #01 SFT2 -- .Screen/height DEI2 #01 SFT2 .frame/height LDZ2 #01 SFT2 -- .frame/width LDZ2 .frame/height LDZ2 @@ -293,10 +306,9 @@ BRK ;draw-cursor JSR2 - ( skip ) .Mouse/state DEI #00 ! #01 JCN [ BRK ] - .Mouse/x DEI2 .Mouse/y DEI2 .tileview ;within-rect JSR2 ;on-touch-tileview JCN2 + .Mouse/x DEI2 .Mouse/y DEI2 .toolview ;within-rect JSR2 ;on-touch-toolview JCN2 .Mouse/x DEI2 .Mouse/y DEI2 .blendview ;within-rect JSR2 @@ -308,10 +320,16 @@ BRK .Mouse/x DEI2 .Mouse/y DEI2 .zoomview ;within-rect JSR2 ;on-touch-zoomview JCN2 + ( release-record ) #0000 .Mouse/state DEO .cursor/last STZ + BRK @on-touch-tileview ( -> ) + .settings/tool LDZ #01 = ;&select JCN2 + + ( skip ) .Mouse/state DEI #00 ! #01 JCN [ BRK ] + .Mouse/x DEI2 .tileview/x1 LDZ2 -- .Mouse/y DEI2 .tileview/y1 LDZ2 -- @@ -354,10 +372,36 @@ BRK POP2 POP2 + BRK + + &select ( -> ) + + .Mouse/state DEI DUP .cursor/last LDZ + DUP2 #0000 == ,&end JCN + DUP2 #0100 !! ,&no-down JCN + .Mouse/x DEI2 .tileview/x1 LDZ2 -- 8// TOB + DUP .selection/x1 STZ .selection/x2 STZ + .Mouse/y DEI2 .tileview/y1 LDZ2 -- 8// TOB + DUP .selection/y1 STZ .selection/y2 STZ + ;clamp-selection JSR2 ;redraw JSR2 + ,&end JMP + &no-down + ( release ) + .Mouse/x DEI2 .tileview/x1 LDZ2 -- 8// TOB .selection/x2 STZ + .Mouse/y DEI2 .tileview/y1 LDZ2 -- 8// TOB .selection/y2 STZ + ;clamp-selection JSR2 ;redraw JSR2 + &end + POP2 + .cursor/last STZ + + BRK + BRK @on-touch-toolview ( -> ) + ( skip ) .Mouse/state DEI #00 ! #01 JCN [ BRK ] + .Mouse/x DEI2 .toolview/x1 LDZ2 -- #0008 // TOB DUP HOR SWP - #01 ! ,&no-save JCN @@ -413,6 +457,9 @@ BRK BRK @on-touch-zoomview ( -> ) + + + ( skip ) .Mouse/state DEI #00 ! #01 JCN [ BRK ] .Mouse/y DEI2 .zoomview/y1 LDZ2 -- #0008 // TOB #04 ! ;&no-mod JCN2 .Mouse/x DEI2 .zoomview/x1 LDZ2 -- #0008 // TOB @@ -463,6 +510,8 @@ BRK @on-touch-blendview ( -> ) + ( skip ) .Mouse/state DEI #00 ! #01 JCN [ BRK ] + .Mouse/x DEI2 .blendview/x1 LDZ2 -- #0008 // TOB .Mouse/y DEI2 .blendview/y1 LDZ2 -- #0008 // TOB #04 * + .settings/blending STZ @@ -474,6 +523,9 @@ BRK BRK @on-touch-colorview ( -> ) + + + ( skip ) .Mouse/state DEI #00 ! #01 JCN [ BRK ] .Mouse/y DEI2 .colorview/y1 LDZ2 -- #0008 // TOB @@ -509,6 +561,9 @@ BRK @on-touch-preview ( -> ) + + ( skip ) .Mouse/state DEI #00 ! #01 JCN [ BRK ] + ( y ) .Mouse/y DEI2 .preview/y1 LDZ2 -- #0008 // TOB ( x ) .Mouse/x DEI2 .preview/x1 LDZ2 -- #0008 // TOB @@ -638,6 +693,18 @@ RTN RTN +@is-selected ( x y -- flag ) + + OVR .selection/x1 LDZ < ,&end JCN + OVR .selection/x2 LDZ > ,&end JCN + DUP .selection/y1 LDZ < ,&end JCN + DUP .selection/y2 LDZ > ,&end JCN + POP2 #01 RTN + &end + POP2 #00 + +RTN + @draw-tileview ( -- ) .settings/zoom LDZ ;draw-tileview-zoom JCN2 @@ -650,8 +717,8 @@ RTN OVR DUP #08 * TOS .tileview/x1 LDZ2 ++ .Screen/x DEO2 STHkr TOS ROT TOS SWP2 HOR TOS ** ++ #0010 ** - BANK ++ [ DUP2 ] .Screen/addr DEO2 - .settings/focus LDZ2 == #0d * + BANK ++ .Screen/addr DEO2 + GET-ITERATORS ;is-selected JSR2 #0d * .settings/blending LDZ + .settings/depth LDZ #80 * + #00 + .Screen/sprite DEO @@ -799,7 +866,7 @@ RTN ;zoom-icns [ .settings/zoom LDZ TOS #0008 ** ++ ] .Screen/addr DEO2 #01 .settings/zoom LDZ + .Screen/sprite DEO ( file i/o ) - ,draw-state JSR + ;draw-state JSR2 .toolview/x2 LDZ2 STH2k #0018 -- .Screen/x DEO2 ;load-icn .Screen/addr DEO2 #01 .Screen/sprite DEO @@ -811,15 +878,6 @@ RTN RTN -@draw-state ( -- ) - - .toolview/x2 LDZ2 #0008 -- .Screen/x DEO2 - .toolview/y1 LDZ2 .Screen/y DEO2 - ;save-icn .Screen/addr DEO2 - #05 .state/changed LDZ #0a * + .Screen/sprite DEO - -RTN - @draw-blendview ( -- ) ( value ) @@ -841,25 +899,6 @@ RTN RTN -@draw-filepath ( color -- ) - - STH - .toolview/x1 LDZ2 #0040 ++ .Screen/x DEO2 - .toolview/y1 LDZ2 .Screen/y DEO2 - ;path/name - &loop - DUP2 LDA DUP #00 ! #20 * - TOS #0008 ** ;font ++ .Screen/addr DEO2 - STHkr .Screen/sprite DEO - .Screen/x DEI2 #0008 ++ .Screen/x DEO2 - #0001 ++ - LDAk #00 ! ,&loop JCN - POP2 - POPr - ( clear last ) - #00 .Screen/sprite DEO - -RTN - @draw-preview ( -- ) ( value ) @@ -913,27 +952,26 @@ RTN .settings/color LDZ .Screen/sprite DEO .colorview/x1 LDZ2 .colorview/y1 LDZ2 - [ .System/r GET-COLOR ] ,draw-slider JSR + [ .System/r GET-COLOR ] ,&slider JSR .colorview/x1 LDZ2 .colorview/y1 LDZ2 #0008 ++ - [ .System/g GET-COLOR ] ,draw-slider JSR + [ .System/g GET-COLOR ] ,&slider JSR .colorview/x1 LDZ2 .colorview/y1 LDZ2 #0010 ++ - [ .System/b GET-COLOR ] ,draw-slider JSR + [ .System/b GET-COLOR ] ,&slider JSR -RTN + RTN -@draw-slider ( x* y* value -- ) - - STH - .Screen/y DEO2 - .Screen/x DEO2 - #00 #10 - &loop - OVR STHkr > #08 * TOS ;slider-icns ++ .Screen/addr DEO2 - #02 .Screen/sprite DEO - .Screen/x DEI2 #0002 ++ .Screen/x DEO2 - INCR LTHk ,&loop JCN - POP2 - POPr + &slider ( x* y* value -- ) + STH + .Screen/y DEO2 + .Screen/x DEO2 + #10 #00 + &loop + DUP STHkr > #08 * TOS ;slider-icns ++ .Screen/addr DEO2 + #02 .Screen/sprite DEO + .Screen/x DEI2 #0002 ++ .Screen/x DEO2 + #01 + GTHk ,&loop JCN + POP2 + POPr RTN @@ -1002,13 +1040,13 @@ RTN @draw-cursor ( -- ) ( clear last cursor ) - .pointer/x LDZ2 .Screen/x DEO2 - .pointer/y LDZ2 .Screen/y DEO2 + .cursor/x LDZ2 .Screen/x DEO2 + .cursor/y LDZ2 .Screen/y DEO2 #40 .Screen/sprite DEO ( record mouse positions ) - .Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 - .Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2 + .Mouse/x DEI2 DUP2 .cursor/x STZ2 .Screen/x DEO2 + .Mouse/y DEI2 DUP2 .cursor/y STZ2 .Screen/y DEO2 ( draw new cursor ) ;tool-brush #00 .settings/tool LDZ #08 * ++ .Screen/addr DEO2 @@ -1016,6 +1054,34 @@ RTN RTN +@draw-filepath ( color -- ) + + STH + .toolview/x1 LDZ2 #0040 ++ .Screen/x DEO2 + .toolview/y1 LDZ2 .Screen/y DEO2 + ;path/name + &loop + DUP2 LDA DUP #00 ! #20 * - TOS #0008 ** ;font ++ .Screen/addr DEO2 + STHkr .Screen/sprite DEO + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + #0001 ++ + LDAk #00 ! ,&loop JCN + POP2 + POPr + ( clear last ) + #00 .Screen/sprite DEO + +RTN + +@draw-state ( -- ) + + .toolview/x2 LDZ2 #0008 -- .Screen/x DEO2 + .toolview/y1 LDZ2 .Screen/y DEO2 + ;save-icn .Screen/addr DEO2 + #05 .state/changed LDZ #0a * + .Screen/sprite DEO + +RTN + @draw-short ( short* color -- ) STH SWP @@ -1050,28 +1116,27 @@ RTN RTN -@line-rect ( x1* y1* x2* y2* color -- ) +( etc ) - ( load ) .color STZ DUP2 STH2 .rect/y2 STZ2 .rect/x2 STZ2 DUP2 STH2 .rect/y1 STZ2 .rect/x1 STZ2 - STH2r STH2r - &ver - ( save ) OVR2 .Screen/y DEO2 - ( draw ) .rect/x1 LDZ2 .Screen/x DEO2 .color LDZ DUP .Screen/pixel DEO - ( draw ) .rect/x2 LDZ2 .Screen/x DEO2 .Screen/pixel DEO - ( incr ) INCR2 - OVR2 OVR2 LTS2 ,&ver JCN - POP2 POP2 - .rect/x1 LDZ2 .rect/x2 LDZ2 - &hor - ( save ) OVR2 .Screen/x DEO2 - ( draw ) .rect/y1 LDZ2 .Screen/y DEO2 .color LDZ DUP .Screen/pixel DEO - ( draw ) .rect/y2 LDZ2 .Screen/y DEO2 .Screen/pixel DEO - ( incr ) INCR2 - OVR2 OVR2 #0001 ++ LTS2 ,&hor JCN - POP2 POP2 +@clamp-selection ( -- ) + + .selection/x1 LDZ HOR #01 - STHk < ,&ok-limitx1 JCN + STHkr .selection/x1 STZ &ok-limitx1 POPr + .selection/y1 LDZ VER #01 - STHk < ,&ok-limity1 JCN + STHkr .selection/y1 STZ &ok-limity1 POPr + .selection/x2 LDZ HOR #01 - STHk < ,&ok-limitx2 JCN + STHkr .selection/x2 STZ &ok-limitx2 POPr + .selection/y2 LDZ VER #01 - STHk < ,&ok-limity2 JCN + STHkr .selection/y2 STZ &ok-limity2 POPr + .selection/x2 LDZ .selection/x1 LDZ STHk > ,&ok-flipx JCN + STHkr .selection/x2 STZ &ok-flipx POPr + .selection/y2 LDZ .selection/y1 LDZ STHk > ,&ok-flipy JCN + STHkr .selection/y2 STZ &ok-flipy POPr RTN +( file ) + @new-file ( default* -- ) BANK LENGTH ;op-clear JSR2 @@ -1130,14 +1195,11 @@ RTN ( theme ) -@theme-txt ".theme $1 - @load-theme ( -- ) - ;theme-txt .File/name DEO2 + ;&path .File/name DEO2 #0006 .File/length DEO2 #fffa .File/load DEO2 - .File/success DEI2 #0006 !! ,&ignore JCN #fffa LDA2 .System/r DEO2 #fffc LDA2 .System/g DEO2 @@ -1146,13 +1208,14 @@ RTN ;redraw JSR2 RTN + &path ".theme $1 @save-theme ( -- ) .System/r DEI2 #fffa STA2 .System/g DEI2 #fffc STA2 .System/b DEI2 #fffe STA2 - ;theme-txt .File/name DEO2 + ;load-theme/path .File/name DEO2 #0006 .File/length DEO2 #fffa .File/save DEO2 @@ -1177,30 +1240,60 @@ RTN RTN +@line-rect ( x1* y1* x2* y2* color -- ) + + ( load ) .color STZ DUP2 STH2 .rect/y2 STZ2 .rect/x2 STZ2 DUP2 STH2 .rect/y1 STZ2 .rect/x1 STZ2 + STH2r STH2r + &ver + ( save ) OVR2 .Screen/y DEO2 + ( draw ) .rect/x1 LDZ2 .Screen/x DEO2 .color LDZ DUP .Screen/pixel DEO + ( draw ) .rect/x2 LDZ2 .Screen/x DEO2 .Screen/pixel DEO + ( incr ) INCR2 + OVR2 OVR2 LTS2 ,&ver JCN + POP2 POP2 + .rect/x1 LDZ2 .rect/x2 LDZ2 + &hor + ( save ) OVR2 .Screen/x DEO2 + ( draw ) .rect/y1 LDZ2 .Screen/y DEO2 .color LDZ DUP .Screen/pixel DEO + ( draw ) .rect/y2 LDZ2 .Screen/y DEO2 .Screen/pixel DEO + ( incr ) INCR2 + OVR2 OVR2 #0001 ++ LTS2 ,&hor JCN + POP2 POP2 + +RTN + @line-hor ( x0* x1* y* color -- ) - STH .Screen/y DEO2 + STH .Screen/y DEO2 SWP2 &loop - ( save ) OVR2 .Screen/x DEO2 + ( save ) DUP2 .Screen/x DEO2 ( draw ) STHkr .Screen/pixel DEO - ( incr ) SWP2 #0002 ++ SWP2 - LTH2k ,&loop JCN + #0002 ++ GTH2k ,&loop JCN POP2 POP2 POPr RTN @line-ver ( x* y0* y1* color -- ) - STH ROT2 .Screen/x DEO2 + STH ROT2 .Screen/x DEO2 SWP2 &loop - ( save ) OVR2 .Screen/y DEO2 + ( save ) DUP2 .Screen/y DEO2 ( draw ) STHkr .Screen/pixel DEO - ( incr ) SWP2 #0002 ++ SWP2 - LTH2k ,&loop JCN + #0002 ++ GTH2k ,&loop JCN POP2 POP2 POPr RTN +@print-hex ( value -- ) + + STHk #04 SFT ,&parse JSR .Console/write DEO + STHr #0f AND ,&parse JSR .Console/write DEO + RTN + &parse ( value -- char ) + DUP #09 GTH ,&above JCN #30 ADD RTN &above #09 SUB #60 ADD RTN + +RTN + @tool-brush e0d0 8844 2212 0c00 @tool-selector 80c0 e0f0 f8e0 1000