uxn/projects/software/left.usm

466 lines
11 KiB
Plaintext
Raw Normal View History

2021-03-06 14:44:18 -05:00
(
app/left : text editor
)
2021-03-01 14:18:11 -05:00
2021-03-06 14:44:18 -05:00
&Console { pad 8 stdio 1 }
2021-03-08 13:30:13 -05:00
&Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
&Sprite { pad 8 x 2 y 2 addr 2 color 1 }
2021-03-06 14:44:18 -05:00
&Controller { buttons 1 }
2021-03-08 13:30:13 -05:00
&Keyboard { key 1 }
&Mouse { x 2 y 2 state 1 chord 1 xt 1 yt 1 }
2021-03-06 14:44:18 -05:00
&File { pad 8 name 2 length 2 load 2 save 2 }
2021-03-01 14:18:11 -05:00
2021-03-08 13:30:13 -05:00
&Document { eof 2 body 8000 }
&Range2d { from 2 to 2 }
&Point2d { x 2 y 2 }
&Label2d { x 2 y 2 color 1 addr 2 }
&Textarea2d { x1 2 y1 2 x2 2 y2 2 addr 2 cursor 1 }
2021-03-01 14:18:11 -05:00
2021-03-08 00:09:15 -05:00
;selection Range2d
;pt Point2d ;mouse Point2d ;position Point2d ;scroll Point2d
2021-03-06 14:44:18 -05:00
;textarea Textarea2d
2021-03-07 00:30:16 -05:00
;label Label2d
2021-03-08 00:09:15 -05:00
;j 2 ;addr 2
2021-03-01 14:18:11 -05:00
|0100 @RESET
2021-03-08 00:09:15 -05:00
( load file )
2021-03-08 13:30:13 -05:00
,filepath ,load-file JSR
2021-03-01 14:18:11 -05:00
2021-03-08 00:09:15 -05:00
( place textarea )
#0018 =textarea.x1 ~dev/screen.height #0008 SUB2 =textarea.y2
2021-03-07 00:30:16 -05:00
2021-03-08 13:30:13 -05:00
,select JSR
2021-03-07 00:30:16 -05:00
,redraw JSR
2021-03-01 14:18:11 -05:00
2021-03-06 14:44:18 -05:00
BRK
2021-03-01 14:18:11 -05:00
2021-03-08 13:30:13 -05:00
@FRAME
2021-03-07 00:30:16 -05:00
( ctrl )
2021-03-08 13:30:13 -05:00
,no-ctrl ~dev/ctrl #00 EQU JMP? POP2
,no-ctrl-down ~dev/ctrl #04 ROR #01 NEQ JMP? POP2
~position.y #0001 SUB2 =position.y
,select JSR ,redraw JSR ,no-ctrl JMP
2021-03-07 15:32:19 -05:00
@no-ctrl-down
2021-03-08 13:30:13 -05:00
,no-ctrl-up ~dev/ctrl #04 ROR #02 NEQ JMP? POP2
~position.y #0001 ADD2 =position.y
,select JSR ,redraw JSR ,no-ctrl JMP
2021-03-07 15:32:19 -05:00
@no-ctrl-up
2021-03-08 13:30:13 -05:00
,no-ctrl-left ~dev/ctrl #04 ROR #04 NEQ JMP? POP2
~position.x #0001 SUB2 =position.x
,select JSR ,redraw JSR ,no-ctrl JMP
2021-03-07 00:30:16 -05:00
@no-ctrl-left
2021-03-08 13:30:13 -05:00
,no-ctrl-right ~dev/ctrl #04 ROR #08 NEQ JMP? POP2
~position.x #0001 ADD2 =position.x
,select JSR ,redraw JSR ,no-ctrl JMP
2021-03-07 00:30:16 -05:00
@no-ctrl-right
@no-ctrl
2021-03-08 13:30:13 -05:00
( keys )
2021-03-08 15:35:30 -05:00
,keys-end ~dev/key #00 EQU JMP? POP2
,no-backspace ~dev/key #08 NEQ JMP? POP2
( erase )
~position.x #0001 SUB2 =position.x ,select JSR
~document.eof #0001 SUB2 =document.eof
~selection.from =j ( start -> end )
@erase-loop
~j #0001 ADD2 LDR ~j STR
( incr ) ~j #0001 ADD2 =j
,erase-loop ~j ~document.eof LTH2 JMP? POP2
( release ) #00 =dev/key
,redraw JSR
,keys-end JMP
@no-backspace
2021-03-08 13:30:13 -05:00
2021-03-08 13:55:57 -05:00
( insert )
~document.eof #0001 ADD2 =document.eof
~document.eof =j ( end -> start )
@insert-loop
2021-03-08 15:35:30 -05:00
~j #0001 SUB2 LDR ~j STR
( decr ) ~j #0001 SUB2 =j
,insert-loop ~j ~selection.from GTH2 JMP? POP2
2021-03-08 13:30:13 -05:00
~dev/key ~selection.from STR
2021-03-08 13:55:57 -05:00
~position.x #0001 ADD2 =position.x ,select JSR
2021-03-08 13:30:13 -05:00
( release ) #00 =dev/key
,redraw JSR
2021-03-08 15:35:30 -05:00
@keys-end
2021-03-08 13:30:13 -05:00
2021-03-07 00:30:16 -05:00
( mouse )
,click-end ~dev/mouse.state #00 EQU JMP? POP2
2021-03-07 15:32:19 -05:00
( scrollbar )
2021-03-08 00:09:15 -05:00
,no-click-scroll ~dev/mouse.x ~dev/screen.width #0008 SUB2 LTH2 JMP? POP2
2021-03-07 15:32:19 -05:00
2021-03-08 14:31:55 -05:00
,no-click-scroll-up ~dev/mouse.y #0008 GTH2 JMP? POP2
2021-03-07 15:32:19 -05:00
,scroll-up JSR
,click-end JMP
@no-click-scroll-up
2021-03-08 14:31:55 -05:00
,no-click-scroll-down ~dev/mouse.y ~dev/screen.height #0008 SUB2 LTH2 JMP? POP2
2021-03-07 15:32:19 -05:00
,scroll-down JSR
,click-end JMP
@no-click-scroll-down
( on scrollbar )
2021-03-08 00:09:15 -05:00
~dev/mouse.y #0008 SUB2 =scroll.y
,redraw JSR
,click-end JMP
2021-03-07 15:32:19 -05:00
@no-click-scroll
( select body )
2021-03-08 00:09:15 -05:00
~dev/mouse.y #0008 DIV2 ~scroll.y ADD2 =position.y
2021-03-08 13:30:13 -05:00
~dev/mouse.x ~textarea.x1 SUB2 #0008 ADD2 #0008 DIV2 =position.x
2021-03-07 15:32:19 -05:00
2021-03-08 13:30:13 -05:00
,select JSR
2021-03-07 00:30:16 -05:00
,redraw JSR
@click-end
,draw-cursor JSR
BRK
2021-03-08 13:30:13 -05:00
@load-file ( path )
=dev/file.name #8000 =dev/file.length ,document.body =dev/file.load
( get file length )
,document.body =document.eof
@load-file-loop
( incr ) ~document.eof #0001 ADD2 =document.eof
,load-file-loop ~document.eof LDR #00 NEQ JMP? POP2
RTS
2021-03-07 15:32:19 -05:00
@scroll-up
2021-03-08 00:09:15 -05:00
( clamp ) ~scroll.y #0000 EQU2 RTS?
( decr ) ~scroll.y #0001 SUB2 =scroll.y
2021-03-07 15:32:19 -05:00
,redraw JSR
RTS
@scroll-down
2021-03-08 00:09:15 -05:00
( incr ) ~scroll.y #0001 ADD2 =scroll.y
2021-03-07 15:32:19 -05:00
,redraw JSR
RTS
2021-03-08 13:30:13 -05:00
@select
2021-03-07 00:30:16 -05:00
2021-03-08 13:30:13 -05:00
,document.body =j #0000 =pt.x #0000 =pt.y
2021-03-07 00:30:16 -05:00
2021-03-08 13:30:13 -05:00
@select-loop
2021-03-07 00:30:16 -05:00
2021-03-08 00:09:15 -05:00
,no-reached ~pt.y ~position.y NEQ2 JMP? POP2
,no-reached ~pt.x ~position.x NEQ2 JMP? POP2
2021-03-08 13:30:13 -05:00
,no-ctrl-yes ~dev/ctrl #0f AND #01 NEQ JMP? POP2
~j =selection.to
RTS
@no-ctrl-yes
2021-03-08 00:09:15 -05:00
~j =selection.from
~j #0001 ADD2 =selection.to
2021-03-07 00:30:16 -05:00
RTS
@no-reached
2021-03-08 13:55:57 -05:00
,no-space ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP? POP2
2021-03-07 00:30:16 -05:00
( incr ) ~pt.y #0001 ADD2 =pt.y
#0000 =pt.x
@no-space
( incr ) ~pt.x #0001 ADD2 =pt.x
( incr ) ~j #0001 ADD2 =j
2021-03-08 13:30:13 -05:00
,select-loop ~j LDR #00 NEQ JMP? POP2
2021-03-07 00:30:16 -05:00
RTS
@redraw
2021-03-07 15:32:19 -05:00
,draw-textarea JSR
2021-03-07 00:30:16 -05:00
,draw-scrollbar JSR
,draw-titlebar JSR
,draw-lines JSR
2021-03-08 00:09:15 -05:00
( save/load icons )
2021-03-07 00:30:16 -05:00
2021-03-07 15:32:19 -05:00
~dev/screen.height #0008 SUB2 =dev/sprite.y
2021-03-08 00:09:15 -05:00
~dev/screen.width #0018 SUB2 =dev/sprite.x
,load_icn =dev/sprite.addr
#02 =dev/sprite.color
~dev/screen.width #0010 SUB2 =dev/sprite.x
,save_icn =dev/sprite.addr
#02 =dev/sprite.color
2021-03-07 15:32:19 -05:00
2021-03-07 00:30:16 -05:00
RTS
@draw-lines
#0000 =j
#0000 =dev/sprite.x
#0000 =dev/sprite.y
@draw-lines-loop
#0000 =dev/sprite.x
2021-03-08 00:09:15 -05:00
~scroll.y ~j ADD2 =addr
2021-03-07 00:30:16 -05:00
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
2021-03-08 00:09:15 -05:00
( draw ) #02 ~addr ~position.y EQU2 ADD =dev/sprite.color
2021-03-07 00:30:16 -05:00
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
2021-03-08 00:09:15 -05:00
( draw ) #02 ~addr ~position.y EQU2 ADD =dev/sprite.color
2021-03-07 00:30:16 -05:00
( incr ) ~j #0001 ADD2 =j
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
,draw-lines-loop ~j ~dev/screen.height #0008 DIV2 NEQ2 JMP? POP2
RTS
@draw-short ( short )
=addr
,font_hex #00 ,addr LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
( draw ) #0e =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
( draw ) #0e =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
( draw ) #0e =dev/sprite.color
~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
( draw ) #0e =dev/sprite.color
RTS
@draw-cursor
~mouse.x ~dev/mouse.x NEQU2
~mouse.y ~dev/mouse.y NEQU2
#0000 EQU2 RTS? ( Return if unchanged )
( clear last cursor )
~mouse.x =dev/sprite.x
~mouse.y =dev/sprite.y
,blank_icn =dev/sprite.addr
#10 =dev/sprite.color
( record mouse positions )
~dev/mouse.x =mouse.x
~dev/mouse.y =mouse.y
( draw new cursor )
~mouse.x =dev/sprite.x
~mouse.y =dev/sprite.y
,cursor_icn =dev/sprite.addr
2021-03-07 15:32:19 -05:00
#13 =dev/sprite.color
2021-03-07 00:30:16 -05:00
RTS
2021-03-01 14:18:11 -05:00
2021-03-06 14:44:18 -05:00
@draw-textarea ( x y color addr )
2021-03-01 14:18:11 -05:00
2021-03-08 13:30:13 -05:00
,document.body =textarea.addr
2021-03-07 15:32:19 -05:00
( scroll to position )
2021-03-08 13:30:13 -05:00
#0000 =j ( j is linebreaks )
2021-03-07 15:32:19 -05:00
@find-scroll-offset
2021-03-08 13:30:13 -05:00
,find-scroll-offset-end ~scroll.y ~j EQU2 JMP? POP2
2021-03-08 14:31:55 -05:00
,no-break ~textarea.addr LDR #0a NEQ ~textarea.addr LDR #0d NEQ #0101 EQU2 JMP? POP2
2021-03-07 15:32:19 -05:00
( incr ) ~j #0001 ADD2 =j
@no-break
( incr ) ~textarea.addr #0001 ADD2 =textarea.addr
,find-scroll-offset ~textarea.addr LDR #00 NEQ JMP? POP2
2021-03-08 13:30:13 -05:00
@find-scroll-offset-end
2021-03-07 00:30:16 -05:00
2021-03-08 13:30:13 -05:00
~textarea.addr #0000 ADD2 =textarea.addr
2021-03-07 15:32:19 -05:00
#0000 =dev/sprite.y
2021-03-08 00:09:15 -05:00
~textarea.addr =j
2021-03-07 21:51:29 -05:00
#0018 =dev/sprite.x
@draw-textarea-loop
2021-03-07 00:30:16 -05:00
2021-03-08 13:55:57 -05:00
,no-linebreak ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP? POP2
2021-03-07 21:51:29 -05:00
( fill clear )
@fill-clear
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
,font =dev/sprite.addr
#01 =dev/sprite.color
,fill-clear ~dev/sprite.x ~dev/screen.width #0010 SUB2 LTH2 JMP? POP2
2021-03-08 13:30:13 -05:00
#0010 =dev/sprite.x
2021-03-07 21:51:29 -05:00
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
@no-linebreak
2021-03-06 14:44:18 -05:00
2021-03-07 21:51:29 -05:00
,draw-textarea-end ~dev/sprite.y ~dev/screen.height #0010 SUB2 GTH2 JMP? POP2
2021-03-06 14:44:18 -05:00
2021-03-07 21:51:29 -05:00
( get character )
2021-03-08 00:09:15 -05:00
,font #00 ~j LDR #20 SUB #0008 MUL2 ADD2 =dev/sprite.addr
2021-03-08 13:30:13 -05:00
2021-03-08 00:09:15 -05:00
( draw ) #01
2021-03-08 13:30:13 -05:00
~j ~selection.from #0001 SUB2 GTH2
~j ~selection.to LTH2 #0101 EQU2
2021-03-08 00:09:15 -05:00
#05 MUL ADD =dev/sprite.color
2021-03-01 14:18:11 -05:00
2021-03-08 13:30:13 -05:00
( incr ) ~j #0001 ADD2 =j
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
2021-03-08 00:09:15 -05:00
,draw-textarea-loop ~j LDR #00 NEQ JMP? POP2
2021-03-07 21:51:29 -05:00
@draw-textarea-end
2021-03-07 15:32:19 -05:00
2021-03-01 14:18:11 -05:00
RTS
2021-03-07 00:30:16 -05:00
@draw-scrollbar
~dev/screen.width #0008 SUB2 =dev/sprite.x
#0000 =dev/sprite.y
,scrollbar_bg =dev/sprite.addr
@draw-scrollbar-loop
2021-03-07 15:32:19 -05:00
( draw ) #08 =dev/sprite.color
2021-03-07 00:30:16 -05:00
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
,draw-scrollbar-loop ~dev/sprite.y ~dev/screen.height LTH2 JMP? POP2
#0000 =dev/sprite.y
2021-03-07 15:32:19 -05:00
,arrowup_icn =dev/sprite.addr
( draw ) #08 =dev/sprite.color
( at )
2021-03-08 00:09:15 -05:00
~scroll.y #0008 ADD2 =dev/sprite.y
2021-03-07 00:30:16 -05:00
,scrollbar_fg =dev/sprite.addr
2021-03-07 15:32:19 -05:00
( draw ) #08 =dev/sprite.color
~dev/screen.height #0008 SUB2 =dev/sprite.y
,arrowdown_icn =dev/sprite.addr
( draw ) #08 =dev/sprite.color
2021-03-07 00:30:16 -05:00
RTS
@draw-titlebar
2021-03-08 00:09:15 -05:00
#0018 ~dev/screen.height #0008 SUB2 #09 ,filepath
2021-03-07 00:30:16 -05:00
( load ) =label.addr =label.color =dev/sprite.y =dev/sprite.x
~label.addr
2021-03-07 15:32:19 -05:00
@draw-titlebar-loop
2021-03-07 00:30:16 -05:00
( draw ) DUP2 LDR #00 SWP #20 SUB #0008 MUL2 ,font ADD2 =dev/sprite.addr ~label.color =dev/sprite.color
( incr ) #0001 ADD2
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
2021-03-07 15:32:19 -05:00
DUP2 LDR #00 NEQ ,draw-titlebar-loop ROT JMP? POP2
2021-03-07 00:30:16 -05:00
POP2
2021-03-08 13:30:13 -05:00
( selection )
~selection.from ,document.body SUB2 ,draw-short JSR
( length )
~dev/screen.width #0040 SUB2 =dev/sprite.x
~document.eof ,document.body SUB2 ,draw-short JSR
2021-03-08 00:09:15 -05:00
2021-03-07 00:30:16 -05:00
RTS
2021-03-07 15:32:19 -05:00
@font_hex ( 0-F TODO: should pull from @font instead.. )
2021-03-01 14:18:11 -05:00
[
2021-03-07 15:32:19 -05:00
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
003c 4242 7e42 4200 007c 427c 4242 7c00
003c 4240 4042 3c00 007c 4242 4242 7c00
007e 4078 4040 7e00 007e 4078 4040 4000
2021-03-07 00:30:16 -05:00
]
@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
2021-03-01 14:18:11 -05:00
]
2021-03-07 00:30:16 -05:00
@blank_icn [ 0000 0000 0000 0000 ]
@cursor_icn [ 80c0 e0f0 f8e0 1000 ]
@scrollbar_bg [ aa55 aa55 aa55 aa55 ]
@scrollbar_fg [ ffff ffff ffff ffff ]
2021-03-07 15:32:19 -05:00
@arrowup_icn [ 0010 387c fe10 1010 ]
@arrowdown_icn [ 0010 1010 fe7c 3810 ]
2021-03-08 00:09:15 -05:00
@load_icn [ feaa d6aa d4aa f400 ]
@save_icn [ fe82 8282 848a f400 ]
2021-03-08 14:31:55 -05:00
@filepath1 [ test.txt 00 ]
@filepath [ projects/software/left.usm 00 ]
2021-03-06 14:44:18 -05:00
2021-03-08 13:30:13 -05:00
|4000 ;document Document
2021-03-01 14:18:11 -05:00
|d000 @ERROR BRK
2021-03-06 14:44:18 -05:00
|FF00 ;dev/console Console
|FF10 ;dev/screen Screen
|FF20 ;dev/sprite Sprite
|FF30 ;dev/ctrl Controller
|FF40 ;dev/key Keyboard
|FF50 ;dev/mouse Mouse
|FF60 ;dev/file File
2021-03-01 14:18:11 -05:00
|FFF0 .RESET .FRAME .ERROR ( vectors )
2021-03-08 14:31:55 -05:00
|FFF8 [ 0a4f 0a4f 0a4f ] ( palette )