0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-14 10:15:06 +00:00
uxn/projects/software/nasu.usm
2021-04-14 22:06:22 -07:00

527 lines
13 KiB
Text

(
app/nasu : spritesheet editor
arrows - move selection
left-click - add pixel
right-click - remove pixel
1 2 3 - select brush
)
%RTN { JMP2r }
%STEP8 { #0033 SFT2 }
%++ { #0001 ADD2 }
%2/ { #0001 SFT2 } %2* { #0010 SFT2 }
%8/ { #0003 SFT2 } %8* { #0030 SFT2 }
%8- { #0008 SUB2 } %8+ { #0008 ADD2 }
%SFL { #40 SFT SFT }
%MOD { DUP2 DIV MUL SUB }
%BANK { #2000 }
( variables )
;bankview { x 2 y 2 mode 1 addr 2 depth 1 }
;tileview { x 2 y 2 addr 2 }
;rect { x1 2 y1 2 x2 2 y2 2 }
;mouse { x 2 y 2 }
;color { byte 1 }
;i { byte 1 }
;pt { x 1 y 1 }
;addr { short 2 }
;pos { x 2 y 2 }
( devices )
|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|0110 ;Console { pad 8 char 1 byte 1 short 2 }
|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 }
|0140 ;Controller { vector 2 button 1 key 1 }
|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 }
|0170 ;File { vector 2 pad 6 name 2 length 2 load 2 save 2 }
( program )
|0200
( theme ) #0efc =System.r #03cc =System.g #03ac =System.b
( vectors ) ,on-button =Controller.vector
( vectors ) ,on-mouse =Mouse.vector
( vectors ) ,on-transfer =File.vector
~Screen.width 2/ #008a SUB2 =bankview.x
~Screen.height 2/ #003f SUB2 =bankview.y
BANK =bankview.addr
~Screen.width 2/ #0002 ADD2 =tileview.x
~Screen.height 2/ #003f SUB2 =tileview.y
BANK #0448 ADD2 =tileview.addr
,filepath1 =File.name #0800 =File.length BANK =File.load
,filepath2 =File.name #0800 =File.length BANK #0800 ADD2 =File.load
,filepath3 =File.name #1000 =File.length BANK #1000 ADD2 =File.load
,redraw JSR2
BRK
@on-transfer ( -> )
,redraw JSR2
BRK
@on-button ( -> )
~Controller.button
DUP #10 EQU ^$no-ctrl-up JNZ
~tileview.addr #0080 ADD2 =tileview.addr $no-ctrl-up
DUP #20 EQU ^$no-ctrl-down JNZ
~tileview.addr #0080 SUB2 =tileview.addr $no-ctrl-down
DUP #40 EQU ^$no-ctrl-left JNZ
~tileview.addr 8+ =tileview.addr $no-ctrl-left
DUP #80 EQU ^$no-ctrl-right JNZ
~tileview.addr 8- =tileview.addr $no-ctrl-right
POP
~tileview.addr #0800 DIV2 #0800 MUL2 =bankview.addr
~Controller.key #31 LTH ^$skip JNZ
~Controller.key #33 GTH ^$skip JNZ
( select ) ~Controller.key #31 SUB =bankview.mode
$skip
,redraw JSR2
BRK
@on-mouse ( -> )
~Mouse.state #00 EQU ,$click-end JNZ2
( toolbar )
~Mouse.y ~bankview.y #0010 SUB2 SUB2 8/ #0000 NEQ2 ,$no-toolbar-click JNZ2
( brush )
~Mouse.x ~bankview.x SUB2 8/ #000d LTH2 ^$no-brush-click JNZ
~Mouse.x ~bankview.x SUB2 8/ #000f GTH2 ^$no-brush-click JNZ
( select ) ~mouse.x ~bankview.x SUB2 8/ #000d SUB2 SWP POP =bankview.mode
$no-brush-click
~Mouse.x ~tileview.x SUB2 8/ #000e NEQ2 ^$no-load-click JNZ
( load ) ,filepath1 =File.name #0800 =File.length ~bankview.addr =File.load
$no-load-click
~Mouse.x ~tileview.x SUB2 8/ #000f NEQ2 ^$no-save-click JNZ
( save ) ,filepath1 =File.name #0800 =File.length ~bankview.addr =File.save
$no-save-click
~Mouse.x ~bankview.x SUB2 8/ #0005 NEQ2 ^$no-toggle-depth JNZ
( toggle ) ~bankview.depth #00 EQU =bankview.depth
$no-toggle-depth
( release ) #00 =Mouse.state
,redraw JSR2 ,$click-end JMP2
$no-toolbar-click
( bankview )
~Mouse.x ~bankview.x GTH2 ~Mouse.x ~bankview.x #0080 ADD2 LTH2 #0101 EQU2
~Mouse.y ~bankview.y GTH2 ~Mouse.y ~bankview.y #0080 ADD2 LTH2 #0101 EQU2
#0101 NEQ2 ,$no-bank-click JNZ2
~bankview.mode #01 NEQ ^$not-copy-mode JNZ
#00 =i
$copy-loop
( load ) ~tileview.addr ~i ADD PEK2
( get touch addr )
~Mouse.x ~bankview.x SUB2 STEP8
~Mouse.y ~bankview.y SUB2 STEP8 #0010 MUL2 ADD2
~bankview.addr ADD2 #00 ~i ADD2 POK2
( incr ) ~i #01 ADD =i
~i #08 LTH ^$copy-loop JNZ
,redraw JSR2 ,$click-end JMP2
$not-copy-mode
~bankview.mode #02 NEQ ^$not-erase-mode JNZ
#00 =i
$erase-loop
#00
( get touch addr )
~Mouse.x ~bankview.x SUB2 STEP8
~Mouse.y ~bankview.y SUB2 STEP8 #0010 MUL2 ADD2
~bankview.addr ADD2 #00 ~i ADD2 POK2
( incr ) ~i #01 ADD =i
~i #08 LTH ^$erase-loop JNZ
,redraw JSR2 ,$click-end JMP2
$not-erase-mode
~Mouse.x ~bankview.x SUB2 STEP8
~Mouse.y ~bankview.y SUB2 STEP8 #0010 MUL2 ADD2
~bankview.addr ADD2 =tileview.addr
,redraw JSR2 ,$click-end JMP2
$no-bank-click
( tileview )
~Mouse.x ~tileview.x GTH2 ~Mouse.x ~tileview.x #0080 ADD2 LTH2 #0101 EQU2
~Mouse.y ~tileview.y GTH2 ~Mouse.y ~tileview.y #0080 ADD2 LTH2 #0101 EQU2
#0101 NEQ2 ,$no-tile-click JNZ2
~Mouse.x ~tileview.x SUB2 STEP8 #0040 DIV2
~Mouse.y ~tileview.y SUB2 STEP8 #0040 DIV2 2* ADD2
8*
~tileview.addr ADD2 =addr ( addr offset )
~Mouse.x ~tileview.x SUB2 ~Mouse.x ~tileview.x SUB2 #0040 DIV2 #0040 MUL2 SUB2 =pos.x
~Mouse.y ~tileview.y SUB2 ~Mouse.y ~tileview.y SUB2 #0040 DIV2 #0040 MUL2 SUB2 =pos.y
~Mouse.state #10 NEQ ^$no-erase-mode JNZ
( load ) ~addr ~pos.y 8/ ADD2 PEK2
( mask ) #01 #07 ~pos.x 8/ SWP POP SUB SFL
#ff EOR AND
( save ) ~addr ~pos.y 8/ ADD2 POK2
,redraw JSR2 ,$click-end JMP2
$no-erase-mode
( load ) ~addr ~pos.y 8/ ADD2 PEK2
( mask ) #01 #07 ~pos.x 8/ SWP POP SUB SFL
ORA
( save ) ~addr ~pos.y 8/ ADD2 POK2
,redraw JSR2 ,$click-end JMP2
$no-tile-click
( operations )
~Mouse.y ~tileview.y SUB2 8/ #000c NEQ2 ,$no-operations JNZ2
~Mouse.x ~tileview.x SUB2 8/ #0011 NEQ2 ^$no-move-up JNZ
,op_shiftup JSR2
( release ) #00 =Mouse.state
,redraw JSR2 ,$click-end JMP2
$no-move-up
~Mouse.x ~tileview.x SUB2 8/ #0012 NEQ2 ^$no-move-down JNZ
,op_shiftdown JSR2
( release ) #00 =Mouse.state
,redraw JSR2 ,$click-end JMP2
$no-move-down
$no-operations
$click-end
,draw-cursor JSR2
BRK
@op_shiftup
~tileview.addr PEK2
~tileview.addr #0001 ADD2 PEK2 ~tileview.addr POK2
~tileview.addr #0002 ADD2 PEK2 ~tileview.addr #0001 ADD2 POK2
~tileview.addr #0003 ADD2 PEK2 ~tileview.addr #0002 ADD2 POK2
~tileview.addr #0004 ADD2 PEK2 ~tileview.addr #0003 ADD2 POK2
~tileview.addr #0005 ADD2 PEK2 ~tileview.addr #0004 ADD2 POK2
~tileview.addr #0006 ADD2 PEK2 ~tileview.addr #0005 ADD2 POK2
~tileview.addr #0007 ADD2 PEK2 ~tileview.addr #0006 ADD2 POK2
~tileview.addr #0007 ADD2 POK2
RTN
@op_shiftdown
~tileview.addr #0007 ADD2 PEK2
~tileview.addr #0006 ADD2 PEK2 ~tileview.addr #0007 ADD2 POK2
~tileview.addr #0005 ADD2 PEK2 ~tileview.addr #0006 ADD2 POK2
~tileview.addr #0004 ADD2 PEK2 ~tileview.addr #0005 ADD2 POK2
~tileview.addr #0003 ADD2 PEK2 ~tileview.addr #0004 ADD2 POK2
~tileview.addr #0002 ADD2 PEK2 ~tileview.addr #0003 ADD2 POK2
~tileview.addr #0001 ADD2 PEK2 ~tileview.addr #0002 ADD2 POK2
~tileview.addr PEK2 ~tileview.addr #0001 ADD2 POK2
~tileview.addr POK2
RTN
@redraw
,draw-bankview JSR2
,draw-tileview JSR2
RTN
@draw-bankview
~bankview.x #0002 SUB2 ~bankview.y #0002 SUB2 ~bankview.x #0081 ADD2 ~bankview.y #0081 ADD2 #03 ,line-rect JSR2
( position )
~bankview.x =Screen.x
~bankview.y #0010 SUB2 =Screen.y
~bankview.addr ,draw-short JSR2
( toolbar )
~bankview.y #0010 SUB2 =Screen.y
~bankview.x #0028 ADD2 =Screen.x
,depth_icn #00 ~bankview.depth 8* ADD2 =Screen.addr
#23 =Screen.color
~bankview.x #0068 ADD2 =Screen.x
,tool_selector =Screen.addr
#21 ~bankview.mode #00 EQU ADD =Screen.color
~Screen.x 8+ =Screen.x
,tool_hand =Screen.addr
#21 ~bankview.mode #01 EQU ADD =Screen.color
~Screen.x 8+ =Screen.x
,tool_eraser =Screen.addr
#21 ~bankview.mode #02 EQU ADD =Screen.color
~tileview.x #0070 ADD2 =Screen.x
,load_icn =Screen.addr
#21 =Screen.color
~tileview.x #0078 ADD2 =Screen.x
,save_icn =Screen.addr
#21 =Screen.color
( guides )
#00 =i ,font_hex =Screen.addr
$guides
~bankview.x #0010 SUB2 =Screen.x
~bankview.y #00 ~i #08 MUL ADD2 =Screen.y
( draw ) #22 =Screen.color
~bankview.x #00 ~i #08 MUL ADD2 =Screen.x
~bankview.y #0088 ADD2 =Screen.y
( draw ) #22 =Screen.color
~Screen.addr 8+ =Screen.addr
( incr ) ~i #01 ADD =i
~i #10 LTH ^$guides JNZ
( body )
( load ) ~bankview.addr =Screen.addr
~bankview.y DUP2 #0080 ADD2
$ver
( save ) OVR2 =Screen.y
~bankview.x DUP2 #0080 ADD2
$hor
( save ) OVR2 =Screen.x
( draw ) #21 ~Screen.addr ~tileview.addr EQU2 #06 MUL ADD ~bankview.depth #2e MUL ADD =Screen.color
( incr ) SWP2 8+ SWP2
( incr ) ~Screen.addr 8+ #00 ~bankview.depth #0008 MUL2 ADD2 =Screen.addr
OVR2 OVR2 LTH2 ^$hor JNZ
POP2 POP2
( incr ) SWP2 8+ SWP2
OVR2 OVR2 LTH2 ^$ver JNZ
POP2 POP2
RTN
@draw-tileview
~tileview.x #0002 SUB2 ~tileview.y #0002 SUB2 ~tileview.x #0080 ADD2 ~tileview.y #0081 ADD2 #03 ,line-rect JSR2
~tileview.x #0028 ADD2 =Screen.x
~tileview.y #0010 SUB2 =Screen.y
~tileview.addr =Screen.addr
#23 =Screen.color
( position )
~tileview.x =Screen.x
~tileview.y #0010 SUB2 =Screen.y
~tileview.addr ,draw-short JSR2
( body )
~tileview.x =Screen.x
~tileview.y =Screen.y
~tileview.addr =tileview.addr
,draw-tileview-icn JSR2
~tileview.x #0040 ADD2 =Screen.x
~tileview.y =Screen.y
~tileview.addr 8+ =tileview.addr
,draw-tileview-icn JSR2
~tileview.x =Screen.x
~tileview.y #0040 ADD2 =Screen.y
~tileview.addr 8+ =tileview.addr
,draw-tileview-icn JSR2
~tileview.x #0040 ADD2 =Screen.x
~tileview.y #0040 ADD2 =Screen.y
~tileview.addr 8+ =tileview.addr
,draw-tileview-icn JSR2
( line hor )
~tileview.y #003f ADD2 =Screen.y
~tileview.x =Screen.x
$line-hor
( draw ) #03 =Screen.color
( incr ) ~Screen.x #0002 ADD2 =Screen.x
~Screen.x ~tileview.x #0082 ADD2 LTH2 ^$line-hor JNZ
( line ver )
~tileview.y =Screen.y
~tileview.x #003f ADD2 =Screen.x
$line-ver
( draw ) #03 =Screen.color
( incr ) ~Screen.y #0002 ADD2 =Screen.y
~Screen.y ~tileview.y #0081 ADD2 LTH2 ^$line-ver JNZ
( rewind ) ~tileview.addr #0018 SUB2 =tileview.addr
( bytes )
~tileview.y #0018 ADD2 =Screen.y
#00 =i
$bytes
~tileview.x #0088 ADD2 =Screen.x
,font_hex #00 ~tileview.addr #00 ~i ADD2 PEK2 #f0 AND #04 SFT #08 MUL ADD2 =Screen.addr
( draw ) #22 =Screen.color
~Screen.x 8+ =Screen.x
,font_hex #00 ~tileview.addr #00 ~i ADD2 PEK2 #0f AND #08 MUL ADD2 =Screen.addr
( draw ) #22 =Screen.color
( incr ) ~i #01 ADD =i
( incr ) ~Screen.y 8+ =Screen.y
~i #08 LTH ,$bytes JNZ2
( operations )
~Screen.y 8+ =Screen.y
,movedown_icn =Screen.addr
#21 =Screen.color
~Screen.x 8- =Screen.x
,moveup_icn =Screen.addr
#21 =Screen.color
( draw tiles )
~tileview.y =Screen.y
#00 =pt.x #00 =pt.y ~tileview.addr =Screen.addr
$tiles-ver
#00 =pt.x
~tileview.x #0088 ADD2 =Screen.x
$tiles-hor
( draw ) #23 =Screen.color
( incr ) ~Screen.x 8+ =Screen.x
( incr ) ~Screen.addr 8+ =Screen.addr
( incr ) ~pt.x #01 ADD =pt.x
~pt.x #02 LTH ,$tiles-hor JNZ2
( incr ) ~pt.y #01 ADD =pt.y
( incr ) ~Screen.y 8+ =Screen.y
~pt.y #02 LTH ,$tiles-ver JNZ2
RTN
@draw-tileview-icn
#00 =pt.x #00 =pt.y
$ver
#00 =pt.x
$hor
( get bit )
,blank_icn #00
~tileview.addr #00 ~pt.y ADD2 PEK2 #07 ~pt.x SUB SFT #01 AND ( get bit )
8* ADD2 =Screen.addr ( add *8 )
( draw ) #21 =Screen.color
( incr ) ~Screen.x 8+ =Screen.x
( incr ) ~pt.x #01 ADD =pt.x
~pt.x #08 LTH ,$hor JNZ2
( incr ) ~Screen.y 8+ =Screen.y
( incr ) ~pt.y #01 ADD =pt.y
~Screen.x #0040 SUB2 =Screen.x
~pt.y #08 LTH ,$ver JNZ2
RTN
@draw-cursor
( clear last cursor )
~mouse.x =Screen.x
~mouse.y =Screen.y
,blank_icn =Screen.addr
#30 =Screen.color
( record mouse positions )
~Mouse.x =mouse.x
~Mouse.y =mouse.y
( draw new cursor )
~mouse.x =Screen.x
~mouse.y =Screen.y
,tool_selector #00 ~bankview.mode #08 MUL ADD2 =Screen.addr
#32 ~Mouse.state #00 NEQ ADD =Screen.color
RTN
@draw-short ( short )
=addr
,font_hex #00 ,addr PEK2 #f0 AND #04 SFT #08 MUL ADD2 =Screen.addr
( draw ) #22 =Screen.color
~Screen.x 8+ =Screen.x
,font_hex #00 ,addr PEK2 #0f AND #08 MUL ADD2 =Screen.addr
( draw ) #22 =Screen.color
~Screen.x 8+ =Screen.x
,font_hex #00 ,addr ++ PEK2 #f0 AND #04 SFT #08 MUL ADD2 =Screen.addr
( draw ) #22 =Screen.color
~Screen.x 8+ =Screen.x
,font_hex #00 ,addr ++ PEK2 #0f AND #08 MUL ADD2 =Screen.addr
( draw ) #22 =Screen.color
RTN
( Utils )
@line-rect ( x1 y1 x2 y2 color -- )
( load ) =color DUP2 STH2 =rect.y2 =rect.x2 DUP2 STH2 =rect.y1 =rect.x1
STH2r STH2r
$ver
( save ) OVR2 =Screen.y
( draw ) ~rect.x1 =Screen.x ~color DUP =Screen.color
( draw ) ~rect.x2 =Screen.x =Screen.color
( incr ) SWP2 ++ SWP2
OVR2 OVR2 LTS2 ^$ver JNZ
POP2 POP2
~rect.x1 ~rect.x2
$hor
( save ) OVR2 =Screen.x
( draw ) ~rect.y1 =Screen.y ~color DUP =Screen.color
( draw ) ~rect.y2 =Screen.y =Screen.color
( incr ) SWP2 ++ SWP2
OVR2 OVR2 ++ LTS2 ^$hor JNZ
POP2 POP2
RTN
@tool_selector [ 80c0 e0f0 f8e0 1000 ]
@tool_hand [ 4040 4070 f8f8 f870 ]
@tool_eraser [ 2050 b87c 3e1c 0800 ]
@blank_icn [
0000 0000 0000 0000
7cfe fefe fefe 7c00
]
@depth_icn [
00fe 8282 fe82 82fe
00fe 9292 fe92 92fe
]
@load_icn [ feaa d6aa d4aa f400 ]
@save_icn [ fe82 8282 848a f400 ]
@moveup_icn [ 0010 387c fe10 1000 ]
@movedown_icn [ 0010 1010 fe7c 3810 ]
@filepath1 [ projects/fonts/specter8.bit 00 ]
@filepath2 [ projects/pictures/cibo.bit 00 ]
@filepath3 [ projects/pictures/zerotwo10x10.chr 00 ]
@font_hex ( 0-F )
[
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
]