diff --git a/README.md b/README.md index 641d44b..ecd5d54 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Nasu -[Nasu](https://100r.co/site/nasu.html) is a sprite editor, written in [Uxambly](https://wiki.xxiivv.com/site/uxambly.html). +[Nasu](https://100r.co/site/nasu.html) is a sprite editor, written in [Uxntal](https://wiki.xxiivv.com/site/uxntal.html). ## Build You must have the [Uxn](https://git.sr.ht/~rabbits/uxn/) assembler and emulator. ``` -uxnasm nasu.usm nasu.rom && uxnemu nasu.rom +uxnasm nasu.tal nasu.rom && uxnemu nasu.rom ``` To build the C version(old), you must have [SDL2](https://wiki.libsdl.org/). diff --git a/build.sh b/build.sh index 16ba7b0..71925c5 100755 --- a/build.sh +++ b/build.sh @@ -5,7 +5,7 @@ rm -rf bin mkdir bin echo "Assembling.." -uxnasm nasu.usm bin/nasu.rom +uxnasm nasu.tal bin/nasu.rom echo "Installing.." if [ -d "$HOME/roms" ] && [ -e ./bin/nasu.rom ] diff --git a/nasu.tal b/nasu.tal new file mode 100644 index 0000000..008c0dc --- /dev/null +++ b/nasu.tal @@ -0,0 +1,1100 @@ +( + app/nasu : spritesheet editor + + arrows - move selection + enter - insert tile + backspace - delete tile + left-click - add pixel + right-click - remove pixel + 1 2 3 - select color + q w e - select tool +) + +%+ { ADD } %- { SUB } %* { MUL } %/ { DIV } +%< { LTH } %> { GTH } %= { EQU } %! { NEQ } +%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } +%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } + +%HOR { #20 } %VER { #10 } +%WIDTH { HOR TOS #0008 ** } %HEIGHT { VER TOS #0008 ** } +%LENGTH { HOR TOS VER TOS ** #0010 ** } + +%RTN { JMP2r } +%STEP8 { #33 SFT2 } +%MOD { DUP2 / * - } +%MOD2 { OVR2 OVR2 // ** -- } +%MOD8 { #07 AND } +%ROL { DUP #07 SFT SWP #10 SFT + } +%ROR { DUP #70 SFT SWP #01 SFT + } +%SFL { #40 SFT SFT } +%TOB { SWP POP } %TOS { #00 SWP } +%INCR { SWP #01 + SWP } +%INCR2 { SWP2 #0001 ++ SWP2 } +%DECR2 { SWP2 #0001 -- SWP2 } +%TOGGLE { DUP LDZ #00 = SWP STZ } +%GET-ITERATORS { SWP2k POP SWP POP } + +%DEBUG { .Console/byte DEO #0a .Console/char DEO } +%DEBUG2 { .Console/short DEO2 #0a .Console/char DEO } + +%BANK { #2000 } +%GET-COLOR { .settings/color LDZ STHk #02 / + DEI #01 STHr #01 AND - #04 * SFT #0f AND } +%GET-POSITION { .settings/focus LDZ2 BANK -- DUP2 #0002 // WIDTH MOD2 SWP2 WIDTH #0002 ** // #0008 ** } +%ADD-POSITIONS { ROT2 ++ ROT2 ROT2 ++ SWP2 } +%RELEASE-MOUSE { #00 .Mouse/state DEO } + +%SIZE-TO-RECT { + STH2 STH2 OVR2 STH2r ++ OVR2 STH2r ++ +} ( x y w h -- x1 y1 x2 y2 ) + +%SET-RECT { + DUP2 ROT2 SWP2 #0006 ++ STA2 + DUP2 ROT2 SWP2 #0004 ++ STA2 + DUP2 ROT2 SWP2 #0002 ++ STA2 + DUP2 ROT2 SWP2 STA2 + POP2 +} ( x1 y1 x2 y2 addr -- ) + +( devices ) + +|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] +|10 @Console [ &vector $2 &pad $6 &char $1 &byte $1 &short $2 &string $2 ] +|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ] +|80 @Controller [ &vector $2 &button $1 &key $1 ] +|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &chord $1 ] +|a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ] + +( variables ) + +|0000 + +@state + &timer $1 + &trap $1 + &blink $1 + +@settings + &depth $1 + &color $1 + &blending $1 + &ratio $1 + &tool $1 + &focus $2 + &zoom $1 + +@frame [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &width $2 &height $2 ] + +( interface ) +@toolview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] +@colorview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] +@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 ] +@pointer [ &x $2 &y $2 ] + +@path + &length $1 + &name $20 + +( program ) + +|0100 ( -> ) + + ( theme ) + #0a6f .System/r DEO2 + #05cf .System/g DEO2 + #0caf .System/b DEO2 + + ( vectors ) + ;on-button .Controller/vector DEO2 + ;on-mouse .Mouse/vector DEO2 + ;on-transfer .File/vector DEO2 + ;on-frame .Screen/vector DEO2 + + ( set defaults ) + HOR TOS #0008 ** .frame/width STZ2 + VER TOS #0008 ** #0040 ++ .frame/height STZ2 + #01 .settings/depth STZ + #01 .settings/color STZ + #01 .settings/blending STZ + #32 .settings/ratio STZ + #01 .settings/tool STZ + BANK .settings/focus 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 + SIZE-TO-RECT ;frame SET-RECT + + .frame/x1 LDZ2 .frame/y1 LDZ2 #0030 ++ HOR TOS #0008 ** VER TOS #0008 ** SIZE-TO-RECT ;tileview SET-RECT + .tileview/x1 LDZ2 .tileview/y2 LDZ2 #0008 ++ HOR TOS #0008 ** #0008 SIZE-TO-RECT ;toolview SET-RECT + + .frame/x1 LDZ2 .frame/y1 LDZ2 #0020 #0020 SIZE-TO-RECT ;blendview SET-RECT + .frame/x1 LDZ2 #0030 ++ .frame/y1 LDZ2 #0020 #0020 SIZE-TO-RECT ;preview SET-RECT + .frame/x1 LDZ2 #0060 ++ .frame/y1 LDZ2 #0020 #0020 SIZE-TO-RECT ;colorview SET-RECT + .frame/x1 LDZ2 #0090 ++ .frame/y1 LDZ2 #0020 #0028 SIZE-TO-RECT ;zoomview SET-RECT + .frame/x1 LDZ2 #00c0 ++ .frame/y1 LDZ2 #0048 #0020 SIZE-TO-RECT ;dataview SET-RECT + + ;untitled-txt ;new-file JSR2 + ;redraw JSR2 + +BRK + +@on-frame ( -> ) + + .state/trap LDZ #00 ! #01 JCN [ BRK ] + + ( incr ) .state/timer LDZ #01 + DUP .state/timer STZ + + #08 ! ,&no-toggle JCN + .state/blink TOGGLE + #23 .state/blink LDZ #09 * + ;draw-filepath JSR2 + #00 .state/timer STZ + &no-toggle + +BRK + +@on-transfer ( -> ) + + ;redraw JSR2 + +BRK + +@on-button ( -> ) + + .Controller/key DEI .Controller/button DEI #0000 !! #01 JCN [ BRK ] + + .Controller/key DEI #00 ! .state/trap LDZ #0101 == ;on-button-trap JCN2 + + .Controller/key DEI + DUP #31 ! ,&no-1 JCN + ( color ) #00 .settings/color STZ ;draw-toolview JSR2 &no-1 + DUP #32 ! ,&no-2 JCN + ( color ) #01 .settings/color STZ ;draw-toolview JSR2 &no-2 + DUP #33 ! ,&no-3 JCN + ( color ) #02 .settings/color STZ ;draw-toolview JSR2 &no-3 + DUP #34 ! ,&no-4 JCN + ( color ) #03 .settings/color STZ ;draw-toolview JSR2 &no-4 + DUP #08 ! ,&no-delete JCN + ( delete ) .settings/focus LDZ2 ;op-shift-memory-left JSR2 ;redraw JSR2 &no-delete + DUP #0d ! ,&no-insert JCN + ( insert ) .settings/focus LDZ2 ;op-shift-memory-right JSR2 ;redraw JSR2 &no-insert + DUP #20 ! ,&no-zoom JCN + ( zoom ) .settings/zoom TOGGLE ;redraw JSR2 &no-zoom + DUP #71 ! ,&no-tool0 JCN + ( tool ) #00 .settings/tool STZ ;redraw JSR2 &no-tool0 + DUP #77 ! ,&no-tool1 JCN + ( tool ) #01 .settings/tool STZ ;redraw JSR2 &no-tool1 + DUP #65 ! ,&no-tool2 JCN + ( tool ) #02 .settings/tool STZ ;redraw JSR2 &no-tool2 + POP + + ( release ) #00 .Controller/key DEO + + .Controller/button DEI #f0 AND + DUP #04 SFT #01 AND #01 ! ,&no-up JCN + ( clamp ) .settings/focus LDZ2 BANK HOR TOS #0010 ** ++ << ,&no-up JCN + ( up ) .settings/focus LDZ2 #0010 HOR TOS ** -- .settings/focus STZ2 &no-up + DUP #05 SFT #01 AND #01 ! ,&no-down JCN + ( clamp ) .settings/focus LDZ2 BANK LENGTH HOR TOS #0010 ** -- ++ >> ,&no-down JCN + ( down ) .settings/focus LDZ2 #0010 HOR TOS ** ++ .settings/focus STZ2 &no-down + DUP #06 SFT #01 AND #01 ! ,&no-left JCN + ( clamp ) .settings/focus LDZ2 BANK #0001 ++ << ,&no-left JCN + ( left ) .settings/focus LDZ2 #0010 -- .settings/focus STZ2 &no-left + DUP #07 SFT #01 AND #01 ! ,&no-right JCN + ( clamp ) .settings/focus LDZ2 BANK LENGTH #0020 -- ++ >> ,&no-right JCN + ( right ) .settings/focus LDZ2 #0010 ++ .settings/focus STZ2 &no-right + POP + + ;redraw JSR2 + +BRK + +@on-button-trap ( -> ) + + ( enter ) + .Controller/key DEI #0d ! ,&no-edit-enter JCN + #00 .state/trap STZ + #23 ;draw-filepath JSR2 + BRK + &no-edit-enter + ( backspace ) + .Controller/key DEI #08 ! ,&no-edit-backspace JCN + .path/length LDZ #00 = ,&edit-end JCN + .path/length LDZ #01 - .path/length STZ + #00 .path/name .path/length LDZ + STZ + #23 ;draw-filepath JSR2 + BRK + &no-edit-backspace + ( default ) + .path/length LDZ #1f = ,&edit-end JCN + .Controller/key DEI .path/name .path/length LDZ + STZ + .path/length LDZ #01 + .path/length STZ + &edit-end + #00 .path/name .path/length LDZ + STZ + +BRK + +@on-mouse ( -> ) + + ;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 + ;on-touch-blendview JCN2 + .Mouse/x DEI2 .Mouse/y DEI2 .colorview ;within-rect JSR2 + ;on-touch-colorview JCN2 + .Mouse/x DEI2 .Mouse/y DEI2 .preview ;within-rect JSR2 + ;on-touch-preview JCN2 + .Mouse/x DEI2 .Mouse/y DEI2 .zoomview ;within-rect JSR2 + ;on-touch-zoomview JCN2 + +BRK + +@on-touch-tileview ( -> ) + + .Mouse/x DEI2 .tileview/x1 LDZ2 -- + .Mouse/y DEI2 .tileview/y1 LDZ2 -- + + .settings/zoom LDZ #01 ! ,&no-zoom JCN + #0008 // SWP2 #0008 // SWP2 + GET-POSITION ADD-POSITIONS + #00 .Mouse/state DEI #10 = ,&do-erase-zoom JCN + POP .settings/color LDZ &do-erase-zoom + ;put-pixel JSR2 + ;redraw JSR2 + BRK + &no-zoom + + .settings/tool LDZ + DUP #00 ! ,&no-brush JCN + POP + #00 .Mouse/state DEI #10 = ,&do-erase JCN + POP .settings/color LDZ &do-erase + ;put-pixel JSR2 + ;draw-tileview JSR2 + ;draw-preview JSR2 + BRK &no-brush + DUP #01 ! ,&no-selector JCN + POP + ;get-tile-addr JSR2 .settings/focus STZ2 + ;redraw JSR2 + BRK &no-selector + DUP #02 ! ,&no-copy JCN + POP + ;get-tile-addr JSR2 + .settings/focus LDZ2 SWP2 + ;op-copy-tile JSR2 + ;redraw JSR2 + RELEASE-MOUSE + BRK &no-copy + POP + POP2 POP2 + +BRK + +@on-touch-toolview ( -> ) + + .Mouse/x DEI2 .toolview/x1 LDZ2 -- #0008 // TOB + + DUP HOR SWP - #01 ! ,&no-save JCN + ;save-file JSR2 + &no-save + DUP HOR SWP - #03 ! ,&no-load JCN + ;load-file JSR2 + ;redraw JSR22 + &no-load + DUP HOR SWP - #04 ! ,&no-name JCN + #20 ;draw-filepath JSR2 + ;blank-txt ;new-file JSR2 + ;redraw JSR2 + &no-name + DUP #07 ! ,&no-zoom JCN + .settings/zoom TOGGLE + ;draw-tileview JSR2 + ;draw-toolview JSR2 + &no-zoom + DUP #08 > OVR HOR SWP - #05 > #0101 !! ,&no-rename JCN + .state/trap TOGGLE + #00 .state/blink STZ + #23 ;draw-filepath JSR2 + &no-rename + DUP #01 + .settings/color LDZ ! ,&no-eraser JCN + #00 .settings/color STZ + ;draw-colorview JSR2 + ;draw-toolview JSR2 + POP RELEASE-MOUSE BRK + &no-eraser + DUP #02 > ,&no-color JCN + DUP #01 + .settings/color STZ + ;draw-colorview JSR2 + ;draw-toolview JSR2 + POP RELEASE-MOUSE BRK + &no-color + DUP #06 > ,&no-tool JCN + DUP #03 = ,&end JCN + DUP #04 - .settings/tool STZ + ;draw-toolview JSR2 + POP RELEASE-MOUSE BRK + &no-tool + POP + &end + + RELEASE-MOUSE + +BRK + +@on-touch-zoomview ( -> ) + + .Mouse/y DEI2 .zoomview/y1 LDZ2 -- #0008 // TOB #04 ! ;&no-mod JCN2 + .Mouse/x DEI2 .zoomview/x1 LDZ2 -- #0008 // TOB + DUP #00 = .Mouse/state DEI #01 = #0101 !! ,&no-shiftup JCN + .settings/focus LDZ2 + DUP2 ;op-shift-tile-up JSR2 + #0008 ++ ;op-shift-tile-up JSR2 &no-shiftup + DUP #00 = .Mouse/state DEI #10 = #0101 !! ,&no-shiftdown JCN + .settings/focus LDZ2 + DUP2 ;op-shift-tile-down JSR2 + #0008 ++ ;op-shift-tile-down JSR2 &no-shiftdown + DUP #01 = .Mouse/state DEI #01 = #0101 !! ,&no-shiftright JCN + .settings/focus LDZ2 + DUP2 ;op-shift-tile-right JSR2 + #0008 ++ ;op-shift-tile-right JSR2 &no-shiftright + DUP #01 = .Mouse/state DEI #10 = #0101 !! ,&no-shiftleft JCN + .settings/focus LDZ2 + DUP2 ;op-shift-tile-left JSR2 + #0008 ++ ;op-shift-tile-left JSR2 &no-shiftleft + POP + RELEASE-MOUSE + ,&finish JMP + &no-mod + + ( paint ) + .Mouse/x DEI2 .zoomview/x1 LDZ2 -- #0004 // + .Mouse/y DEI2 .zoomview/y1 LDZ2 -- #0004 // + .settings/focus LDZ2 ++ + ( detect erase ) + #00 .Mouse/state DEI #10 = ,&do-erase JCN + POP .settings/color LDZ &do-erase + STH + OVR2 OVR2 + STHkr #00 ;toggle-pixel JSR2 + #0008 ++ + STHr #01 ;toggle-pixel JSR2 + + &finish + + ;redraw JSR2 + +BRK + +@on-touch-blendview ( -> ) + + .Mouse/x DEI2 .blendview/x1 LDZ2 -- #0008 // TOB + .Mouse/y DEI2 .blendview/y1 LDZ2 -- #0008 // TOB #04 * + + .settings/blending STZ + + ;redraw JSR2 + + RELEASE-MOUSE + +BRK + +@on-touch-colorview ( -> ) + + .Mouse/y DEI2 .colorview/y1 LDZ2 -- #0008 // TOB + + DUP #00 ! ,&no-r JCN + .System/r STHk ,&set-color JSR + STHr [ .settings/color LDZ #02 / + ] DEO + &no-r + DUP #01 ! ,&no-g JCN + .System/g STHk ,&set-color JSR + STHr [ .settings/color LDZ #02 / + ] DEO + &no-g + DUP #02 ! ,&no-b JCN + .System/b STHk ,&set-color JSR + STHr [ .settings/color LDZ #02 / + ] DEO + &no-b + POP + + ;redraw JSR2 + + BRK + + &set-color + .settings/color LDZ STHk #02 / + DEI + STHr #02 MOD STHk + #0f SWP [ #40 * SFT ] AND + STHr #00 = + .Mouse/x DEI2 .colorview/x1 LDZ2 -- #0002 // TOB + ( clamp to #0f ) DUP #10 = #01 * - + SWP [ #40 * SFT ] + + RTN + +BRK + +@on-touch-preview ( -> ) + + ( y ) .Mouse/y DEI2 .preview/y1 LDZ2 -- #0008 // TOB + ( x ) .Mouse/x DEI2 .preview/x1 LDZ2 -- #0008 // TOB + + #40 SFT + #11 + + .settings/ratio STZ + + ;redraw JSR2 + + RELEASE-MOUSE + +BRK + +( operations ) + +@op-clear ( addr* length* -- ) + + OVR2 ++ + &loop + OVR2 #00 ROT ROT STA + INCR2 + NEQ2k ,&loop JCN + POP2 POP2 + +RTN + +@op-shift-memory-left ( addr* -- ) + + DUP2 LENGTH ++ + &loop + OVR2 #0010 ++ LDA STH + OVR2 STHr ROT ROT STA + INCR2 + NEQ2k ,&loop JCN + POP2 POP2 + +RTN + +@op-shift-memory-right ( addr* -- ) + + DUP2 LENGTH ++ SWP2 #0001 -- + &loop + OVR2 LDA STH + OVR2 #0010 ++ STHr ROT ROT STA + DECR2 + NEQ2k ,&loop JCN + POP2 POP2 + +RTN + +@op-shift-tile-up ( addr* -- ) + + STH2 + STH2kr LDA + STH2kr #0001 ++ LDA STH2kr STA + STH2kr #0002 ++ LDA STH2kr #0001 ++ STA + STH2kr #0003 ++ LDA STH2kr #0002 ++ STA + STH2kr #0004 ++ LDA STH2kr #0003 ++ STA + STH2kr #0005 ++ LDA STH2kr #0004 ++ STA + STH2kr #0006 ++ LDA STH2kr #0005 ++ STA + STH2kr #0007 ++ LDA STH2kr #0006 ++ STA + STH2r #0007 ++ STA + +RTN + +@op-shift-tile-down ( addr* -- ) + + STH2 + STH2kr #0007 ++ LDA + STH2kr #0006 ++ LDA STH2kr #0007 ++ STA + STH2kr #0005 ++ LDA STH2kr #0006 ++ STA + STH2kr #0004 ++ LDA STH2kr #0005 ++ STA + STH2kr #0003 ++ LDA STH2kr #0004 ++ STA + STH2kr #0002 ++ LDA STH2kr #0003 ++ STA + STH2kr #0001 ++ LDA STH2kr #0002 ++ STA + STH2kr LDA STH2kr #0001 ++ STA + STH2r STA + +RTN + +@op-shift-tile-left ( addr* -- ) + + STH2 + #00 #08 + &loop + OVR TOS STH2kr ++ DUP2 + LDA [ ROL ] ROT ROT STA + INCR + LTHk ,&loop JCN + POP2 + POP2r + +RTN + +@op-shift-tile-right ( addr* -- ) + + STH2 + #00 #08 + &loop + OVR TOS STH2kr ++ DUP2 + LDA [ ROR ] ROT ROT STA + INCR + LTHk ,&loop JCN + POP2 + POP2r + +RTN + +@op-copy-tile ( from* to* -- ) + + STH2 STH2 + #00 #10 + &loop + ( get ) + OVR TOS DUP2 STH2kr ++ LDA + ( put ) + ROT ROT SWP2r STH2kr SWP2r ++ STA + INCR + LTHk ,&loop JCN + POP2 + POP2r POP2r + +RTN + +@redraw ( -- ) + + ;draw-toolview JSR2 + ;draw-blendview JSR2 + ;draw-colorview JSR2 + ;draw-dataview JSR2 + ;draw-preview JSR2 + ;draw-tileview JSR2 + ;draw-zoomview JSR2 + +RTN + +@draw-tileview ( -- ) + + .settings/zoom LDZ ;draw-tileview-zoom JCN2 + + #00 VER + &ver + OVR DUP #08 * TOS .tileview/y1 LDZ2 ++ .Screen/y DEO2 STH + #00 HOR + &hor + 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 == ( TODO: Highlight full range ) + .settings/blending LDZ + + .settings/depth LDZ #20 * + + #20 + .Screen/color DEO + INCR + LTHk ,&hor JCN + POP2 + POPr + INCR + LTHk ,&ver JCN + POP2 + +RTN + +@draw-tileview-zoom ( -- ) + + ( find focus ) GET-POSITION STH2 STH2 + ;pixel-icn .Screen/addr DEO2 + #00 VER + &ver + OVR #08 * TOS .tileview/y1 LDZ2 ++ .Screen/y DEO2 + #00 HOR + &hor + OVR #08 * TOS .tileview/x1 LDZ2 ++ .Screen/x DEO2 + ( get pixel offset ) GET-ITERATORS SWP TOS ROT TOS + ( add focus ) STH2kr SWP2r STH2kr SWP2r ADD-POSITIONS + ,get-pixel JSR #20 + .Screen/color DEO + INCR + LTHk ,&hor JCN + POP2 + INCR + LTHk ,&ver JCN + POP2 + POP2r POP2r + +RTN + +@get-pixel ( x* y* -- color ) + + ( channel 1 ) + OVR2 SWP2 ,get-addr JSR [ STH2k ] LDA + ROT ROT TOB MOD8 [ STHk ] + #07 SWP - SFT #01 AND + ( channel 2 ) + [ STHr ] [ STH2r ] #0008 ++ LDA SWP + #07 SWP - SFT #01 AND + #02 * + + + +RTN + +@get-addr ( x* y* -- addr* ) + + ( get row ) + DUP2 #0008 MOD2 + ( get tile ) + SWP2 #0008 // WIDTH #0002 ** ** ++ + SWP2 STEP8 #0002 ** ++ + BANK ++ + +RTN + +@put-pixel ( x* y* color -- ) + + STH + OVR2 SWP2 ,get-addr JSR + ( ch1 ) + OVR2 OVR2 + STHkr #00 ,toggle-pixel JSR + ( ch2 ) + #0008 ++ + STHr #01 ,toggle-pixel JSR + +RTN + +@toggle-pixel ( x* addr* color* -- ) + + STH2 + DUP2 LDA + STH SWP2 TOB + STHr SWP + STH2r SFT #01 AND ,&do-set JCN + ( mask ) #01 #07 ROT MOD8 - SFL #ff EOR AND + ( save ) ROT ROT STA + RTN + &do-set + ( mask ) #01 #07 ROT MOD8 - SFL ORA + ( save ) ROT ROT STA + +RTN + +@get-tile-addr ( x* y* -- addr* ) + + STEP8 WIDTH ** #0004 // SWP2 + STEP8 #0002 ** ++ + BANK ++ + +RTN + +@draw-toolview ( -- ) + + .toolview/y1 LDZ2 .Screen/y DEO2 + .toolview/x1 LDZ2 .Screen/x DEO2 + + ( colors ) + ;circle-icns [ .settings/color LDZ #01 = TOS #0008 ** ] ++ .Screen/addr DEO2 + #21 .Screen/color DEO + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ;circle-icns [ .settings/color LDZ #02 = TOS #0008 ** ] ++ .Screen/addr DEO2 + #22 .Screen/color DEO + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ;circle-icns [ .settings/color LDZ #03 = TOS #0008 ** ] ++ .Screen/addr DEO2 + #23 .Screen/color DEO + + ( tools ) + .Screen/x DEI2 #0010 ++ .Screen/x DEO2 + ;brush-icn .Screen/addr DEO2 + #21 .settings/tool LDZ #00 = + .Screen/color DEO + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ;tool-selector .Screen/addr DEO2 + #21 .settings/tool LDZ #01 = + .Screen/color DEO + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ;tool-hand .Screen/addr DEO2 + #21 .settings/tool LDZ #02 = + .Screen/color DEO + + ( misc ) + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ;zoom-icns [ .settings/zoom LDZ TOS #0008 ** ++ ] .Screen/addr DEO2 + #21 .Screen/color DEO + + ( file i/o ) + .toolview/x2 LDZ2 #0008 -- .Screen/x DEO2 + ;save-icn .Screen/addr DEO2 + #21 .Screen/color DEO + .Screen/x DEI2 #0010 -- .Screen/x DEO2 + ;load-icn .Screen/addr DEO2 + #21 .Screen/color DEO + .Screen/x DEI2 #0008 -- .Screen/x DEO2 + ;make-icn .Screen/addr DEO2 + #21 .Screen/color DEO + + ( filepath ) + #23 ;draw-filepath JSR2 + +RTN + +@draw-blendview ( -- ) + + ( value ) + .blendview/x1 LDZ2 .Screen/x DEO2 + .blendview/y2 LDZ2 #0001 ++ .Screen/y DEO2 + ( get blending ) .settings/blending LDZ + ( get depth ) .settings/depth LDZ #20 * + ( draw ) #20 + + #21 ;draw-byte JSR2 + + .settings/focus LDZ2 .Screen/addr DEO2 + #00 #10 + &loop + OVR #04 MOD #00 SWP #0008 ** .blendview/x1 LDZ2 ++ .Screen/x DEO2 + OVR #04 / #00 SWP #0008 ** .blendview/y1 LDZ2 ++ .Screen/y DEO2 + #20 .Screen/color DEO + OVR #20 + .settings/depth LDZ #20 * + .Screen/color DEO + INCR + LTHk ,&loop JCN + POP2 + +RTN + +@draw-filepath ( color -- ) + + STH + .toolview/x1 LDZ2 #0048 ++ .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/color DEO + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + #0001 ++ + LDAk #00 ! ,&loop JCN + POP2 + POPr + ( clear last ) + #20 .Screen/color DEO + +RTN + +@draw-preview ( -- ) + + ( value ) + .preview/x1 LDZ2 .Screen/x DEO2 + .preview/y2 LDZ2 #0001 ++ .Screen/y DEO2 + .settings/ratio LDZ #22 ;draw-byte JSR2 + + ( stash address ) + .settings/focus LDZ2 STH2k .Screen/addr DEO2 + #00 #04 + &ver + OVR #08 * TOS .preview/y1 LDZ2 ++ .Screen/y DEO2 + #00 #04 + &hor + OVR #08 * TOS .preview/x1 LDZ2 ++ .Screen/x DEO2 + ( get x,y ) + GET-ITERATORS + ( check if within ratio ) + .settings/ratio LDZ #0f AND < STH + .settings/ratio LDZ #04 SFT < STHr + #0101 !! ,&outside JCN + ( get tile ) STH2kr .Screen/addr DEO2 + ( get blending ) .settings/blending LDZ + ( get depth ) .settings/depth LDZ #20 * + ( draw ) #20 + + .Screen/color DEO + ( incr ) STH2r #0008 [ .settings/depth LDZ #08 * TOS ++ ] ++ STH2 + ,&resume JMP + &outside + ;halftone-icn .Screen/addr DEO2 + #23 .Screen/color DEO + &resume + ( incr ) INCR + LTHk ,&hor JCN + POP2 + ( incr ) INCR + LTHk ;&ver JCN2 + POP2 + POP2r + +RTN + +@draw-colorview ( -- ) + + .colorview/y2 LDZ2 #0001 ++ .Screen/y DEO2 + .colorview/x1 LDZ2 .Screen/x DEO2 + ;font-hex [ .System/r GET-COLOR ] TOS #0008 ** ++ .Screen/addr DEO2 + #20 .settings/color LDZ + .Screen/color DEO + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ;font-hex [ .System/g GET-COLOR ] TOS #0008 ** ++ .Screen/addr DEO2 + #20 .settings/color LDZ + .Screen/color DEO + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ;font-hex [ .System/b GET-COLOR ] TOS #0008 ** ++ .Screen/addr DEO2 + #20 .settings/color LDZ + .Screen/color DEO + + .colorview/x1 LDZ2 .colorview/y1 LDZ2 + [ .System/r GET-COLOR ] ,draw-slider JSR + .colorview/x1 LDZ2 .colorview/y1 LDZ2 #0008 ++ + [ .System/g GET-COLOR ] ,draw-slider JSR + .colorview/x1 LDZ2 .colorview/y1 LDZ2 #0010 ++ + [ .System/b GET-COLOR ] ,draw-slider JSR + +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 + #22 .Screen/color DEO + .Screen/x DEI2 #0002 ++ .Screen/x DEO2 + INCR + LTHk ,&loop JCN + POP2 + POPr + +RTN + +@draw-dataview ( -- ) + + ( position ) + .dataview/x1 LDZ2 .Screen/x DEO2 + .dataview/y2 LDZ2 #0001 ++ .Screen/y DEO2 + .settings/focus LDZ2 BANK -- #22 ;draw-short JSR2 + + ( depth1 ) + #00 #04 + &loop + .dataview/x1 LDZ2 .Screen/x DEO2 + OVR #08 * TOS .dataview/y1 LDZ2 ++ .Screen/y DEO2 + OVR #02 * TOS .settings/focus LDZ2 ++ LDA2 #23 ;draw-short JSR2 + .dataview/x1 LDZ2 #0020 ++ .Screen/x DEO2 + OVR #02 * TOS .settings/focus LDZ2 ++ #0008 ++ LDA2 #23 ;draw-short JSR2 + INCR + LTHk ,&loop JCN + POP2 + +RTN + +@draw-zoomview ( -- ) + + ;bigpixel-icn .Screen/addr DEO2 + #00 #08 + &ver + OVR #04 * TOS .zoomview/y1 LDZ2 ++ .Screen/y DEO2 + #00 #08 + &hor + OVR #04 * TOS .zoomview/x1 LDZ2 ++ .Screen/x DEO2 + ( get pixel ) + GET-ITERATORS + ( ch 1 ) + TOS .settings/focus LDZ2 ++ [ STH2k ] LDA + SWP [ STHk ] #07 SWP - SFT #01 AND + ( ch2 ) + [ STHr ] [ STH2r ] #0008 ++ LDA SWP + #07 SWP - SFT #01 AND + #02 * + + #20 + .Screen/color DEO + INCR + LTHk ,&hor JCN + POP2 + INCR + LTHk ,&ver JCN + POP2 + + ( effects ) + .zoomview/y1 LDZ2 #0021 ++ .Screen/y DEO2 + .zoomview/x1 LDZ2 .Screen/x DEO2 + ;opshift-icn .Screen/addr DEO2 + #21 .Screen/color DEO + + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ;oproll-icn .Screen/addr DEO2 + #21 .Screen/color DEO + +RTN + +@draw-cursor ( -- ) + + ( clear last cursor ) + .pointer/x LDZ2 .Screen/x DEO2 + .pointer/y LDZ2 .Screen/y DEO2 + #30 .Screen/color DEO + + ( record mouse positions ) + .Mouse/x DEI2 .pointer/x STZ2 + .Mouse/y DEI2 .pointer/y STZ2 + + ( draw new cursor ) + .pointer/x LDZ2 .Screen/x DEO2 + .pointer/y LDZ2 .Screen/y DEO2 + ;brush-icn #00 .settings/tool LDZ #08 * ++ .Screen/addr DEO2 + #32 .Mouse/state DEI #00 ! + .Screen/color DEO + +RTN + +@draw-byte ( byte color -- ) + + STH STH + ;font-hex #00 STHkr #f0 AND #04 SFT #08 * ++ .Screen/addr DEO2 + ( draw ) OVRr STHr .Screen/color DEO + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ;font-hex #00 STHr #0f AND #08 * ++ .Screen/addr DEO2 + ( draw ) STHr .Screen/color DEO + +RTN + +@draw-short ( short* color -- ) + + STH SWP + DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2 + ( draw ) STHkr .Screen/color DEO + #0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2 + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ( draw ) STHkr .Screen/color DEO + DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2 + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ( draw ) STHkr .Screen/color DEO + #0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2 + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ( draw ) STHr .Screen/color DEO + +RTN + +@new-file ( default* -- ) + + BANK LENGTH ;op-clear JSR2 + STH2 + #00 #0c + &loop + OVR DUP TOS STH2kr ++ LDA + SWP .path/name + STZ + INCR + LTHk ,&loop JCN + .path/length STZ POP + POP2r + ;load-file JSR2 + +RTN + +@load-file ( -- ) + + BANK LENGTH ;op-clear JSR2 + ;path/name .File/name DEO2 + #2000 .File/length DEO2 + BANK .File/load DEO2 + +RTN + +@save-file ( -- ) + + ;path/name .File/name DEO2 + #2000 .File/length DEO2 + BANK .File/save DEO2 + +RTN + +@within-rect ( x* y* rect -- flag ) + + STH + ( y < rect.y1 ) DUP2 STHkr #02 ADD LDZ2 LTH2 ,&skip JCN + ( y > rect.y2 ) DUP2 STHkr #06 ADD LDZ2 GTH2 ,&skip JCN + SWP2 + ( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ,&skip JCN + ( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ,&skip JCN + POP2 POP2 POPr + #01 +RTN + &skip + POP2 POP2 POPr + #00 + +RTN + +@brush-icn 8040 e070 381c 0c00 +@tool-selector 80c0 e0f0 f8e0 1000 +@tool-hand 2020 20b8 7c7c 3838 +@halftone-icn aa55 aa55 aa55 aa55 +@pixel-icn 7cfe fefe fefe 7c00 +@bigpixel-icn f0f0 f0f0 0000 0000 + +@opshift-icn 0010 387c fe10 1000 +@oproll-icn 0008 0c0e 7f0e 0c08 + +@save-icn 1054 28c6 2854 1000 +@make-icn fe82 8282 848a f400 +@load-icn feaa d6aa d4aa f400 + +@untitled-txt "untitled.chr $1 +@blank-txt "blank.chr $1 + +@slider-icns + f0f0 f0f0 f0f0 f000 ( full ) + 50a0 50a0 50a0 5000 ( empty ) +@circle-icns + 3844 8282 8244 3800 ( full ) + 387c fefe fe7c 3800 ( line ) +@zoom-icns + 3048 8484 4834 0200 ( in ) + 3245 8284 4834 0200 ( out ) +@font-hex + 007c 8282 8282 827c 0030 1010 1010 1010 + 007c 8202 7c80 80fe 007c 8202 1c02 827c + 000c 1424 4484 fe04 00fe 8080 7c02 827c + 007c 8280 fc82 827c 007c 8202 1e02 0202 + 007c 8282 7c82 827c 007c 8282 7e02 827c + 007c 8202 7e82 827e 00fc 8282 fc82 82fc + 007c 8280 8080 827c 00fc 8282 8282 82fc + 007c 8280 f080 827c 007c 8280 f080 8080 +@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