uxn/projects/software/left.usm

721 lines
18 KiB
Plaintext
Raw Normal View History

2021-03-06 14:44:18 -05:00
(
app/left : text editor
2021-03-08 19:41:31 -05:00
TODO
- Save/Load
- Double-click select word
- Right-click find next instance of selection
2021-03-09 23:26:33 -05:00
- Draw tab characters
2021-03-13 13:31:29 -05:00
- Don't redraw if nothing has changed
- Input on selection should erase selection range
- Erase on selection should erase selection range
2021-03-10 22:41:46 -05:00
- Scrollbar
- Don't scroll past oef
- Hor scroll
- Real scrolling distance
2021-03-06 14:44:18 -05:00
)
2021-03-01 14:18:11 -05:00
2021-03-12 14:37:45 -05:00
&Console { pad 8 char 1 byte 1 short 2 }
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 }
2021-03-12 14:37:45 -05:00
&Clip { len 2 body 256 }
2021-03-08 13:30:13 -05:00
&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-10 12:29:08 -05:00
&Touch2d { x1 2 y1 2 x2 2 y2 2 state 1 }
2021-03-01 14:18:11 -05:00
2021-03-10 12:29:08 -05:00
;lock 1
2021-03-12 23:22:28 -05:00
;i 2 ;j 2 ;k 1 ;l 1 ;addr 2
2021-03-01 14:18:11 -05:00
2021-03-10 14:00:21 -05:00
;selection Range2d ;position Point2d ;scroll Point2d
;pt Point2d ;mouse Point2d ;touch Touch2d
;textarea Textarea2d
;label Label2d ( remove )
2021-03-09 20:29:56 -05:00
2021-03-01 14:18:11 -05:00
|0100 @RESET
2021-03-08 00:09:15 -05:00
( load file )
2021-03-10 22:41:46 -05:00
,filepath ,load-file JSR2
2021-03-08 00:09:15 -05:00
( place textarea )
2021-03-11 15:19:59 -05:00
#0018 =textarea.x1 ~SCRN.height #0008 SUB2 =textarea.y2
2021-03-07 00:30:16 -05:00
2021-03-10 22:41:46 -05:00
,select JSR2
,redraw JSR2
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-09 20:29:56 -05:00
2021-03-07 00:30:16 -05:00
( ctrl )
2021-03-11 15:19:59 -05:00
,ctrl-end ~CTRL #00 EQU ~lock #00 NEQ #0000 NEQ2 JMP2? POP2
2021-03-10 14:00:21 -05:00
( lock ) #04 =lock
2021-03-11 15:19:59 -05:00
,no-ctrl-up ~CTRL #10 NEQ JMP2? POP2
2021-03-10 22:41:46 -05:00
( clamp ) ,no-ctrl-up ~position.y #0000 EQU2 JMP2? POP2
,find-lineoffset JSR2 =position.x
2021-03-10 12:29:08 -05:00
~position.y #0001 SUB2 =position.y
2021-03-10 22:41:46 -05:00
,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to
2021-03-12 23:22:28 -05:00
,clamp-selection JSR2 ,follow-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-07 15:32:19 -05:00
@no-ctrl-up
2021-03-11 15:19:59 -05:00
,no-ctrl-down ~CTRL #20 NEQ JMP2? POP2
2021-03-10 22:41:46 -05:00
,find-lineoffset JSR2 =position.x ~position.y #0001 ADD2 =position.y
,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to
2021-03-12 23:22:28 -05:00
,clamp-selection JSR2 ,follow-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-09 20:29:56 -05:00
@no-ctrl-down
2021-03-11 15:19:59 -05:00
,no-ctrl-left ~CTRL #40 NEQ JMP2? POP2
2021-03-10 22:41:46 -05:00
( clamp ) ,no-ctrl-left ~selection.from ,document.body EQU2 JMP2? POP2
2021-03-09 20:29:56 -05:00
~selection.from #0001 SUB2 DUP2 =selection.from #0001 ADD2 =selection.to
2021-03-13 13:31:29 -05:00
,clamp-selection JSR2 ,follow-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-07 00:30:16 -05:00
@no-ctrl-left
2021-03-11 15:19:59 -05:00
,no-ctrl-right ~CTRL #80 NEQ JMP2? POP2
2021-03-09 20:29:56 -05:00
~selection.from #0001 ADD2 DUP2 =selection.from #0001 ADD2 =selection.to
2021-03-13 13:31:29 -05:00
,clamp-selection JSR2 ,follow-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-07 00:30:16 -05:00
@no-ctrl-right
2021-03-08 22:50:12 -05:00
( alt )
2021-03-11 15:19:59 -05:00
,no-alt ~CTRL #0f AND #02 NEQ JMP2? POP2
,no-aup ~CTRL #04 ROR #01 NEQ JMP2? POP2
2021-03-10 22:41:46 -05:00
,find-wordstart JSR2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-09 20:29:56 -05:00
@no-aup
2021-03-11 15:19:59 -05:00
,no-adown ~CTRL #04 ROR #02 NEQ JMP2? POP2
2021-03-10 22:41:46 -05:00
,find-wordend JSR2 =selection.to
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-09 20:29:56 -05:00
@no-adown
2021-03-11 15:19:59 -05:00
,no-aleft ~CTRL #04 ROR #04 NEQ JMP2? POP2
2021-03-08 22:50:12 -05:00
~selection.to #0001 SUB2 =selection.to
2021-03-10 22:41:46 -05:00
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-08 22:50:12 -05:00
@no-aleft
2021-03-11 15:19:59 -05:00
,no-aright ~CTRL #04 ROR #08 NEQ JMP2? POP2
2021-03-08 22:50:12 -05:00
~selection.to #0001 ADD2 =selection.to
2021-03-10 22:41:46 -05:00
,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-08 22:50:12 -05:00
@no-aright
@no-alt
2021-03-09 14:33:31 -05:00
( ctrl )
2021-03-11 15:19:59 -05:00
,no-ctrl ~CTRL #0f AND #01 NEQ JMP2? POP2
,no-cup ~CTRL #04 ROR #01 NEQ JMP2? POP2
2021-03-12 23:22:28 -05:00
#0004 ,scroll-up JSR2
2021-03-10 22:41:46 -05:00
,redraw JSR2 ,ctrl-end JMP2
2021-03-10 13:00:43 -05:00
@no-cup
2021-03-11 15:19:59 -05:00
,no-cdown ~CTRL #04 ROR #02 NEQ JMP2? POP2
2021-03-12 23:22:28 -05:00
#0004 ,scroll-down JSR2
2021-03-10 22:41:46 -05:00
,redraw JSR2 ,ctrl-end JMP2
2021-03-10 13:00:43 -05:00
@no-cdown
2021-03-11 15:19:59 -05:00
,no-cleft ~CTRL #04 ROR #04 NEQ JMP2? POP2
2021-03-10 22:41:46 -05:00
,goto-linestart JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-09 14:33:31 -05:00
@no-cleft
2021-03-11 15:19:59 -05:00
,no-cright ~CTRL #04 ROR #08 NEQ JMP2? POP2
2021-03-10 22:41:46 -05:00
,goto-lineend JSR2 ,redraw JSR2 ,ctrl-end JMP2
2021-03-09 14:33:31 -05:00
@no-cright
@no-ctrl
2021-03-08 22:50:12 -05:00
@ctrl-end
2021-03-07 00:30:16 -05:00
2021-03-08 13:30:13 -05:00
( keys )
2021-03-13 13:31:29 -05:00
,no-keys ~KEYS #00 EQU JMP2? POP2
2021-03-08 15:35:30 -05:00
2021-03-13 13:31:29 -05:00
,$no-backspace ~KEYS #08 NEQ JMP2? POP2
2021-03-08 15:35:30 -05:00
( erase )
2021-03-13 13:31:29 -05:00
,$erase-multiple ~selection.to ~selection.from SUB2 #0001 NEQ2 JMP2? POP2
$erase-single
~selection.to ~selection.from SUB2 ,shift-left JSR2
,$erase-end JMP2
$erase-multiple
~selection.from #0001 ADD2 =selection.from
~selection.to ~selection.from SUB2 #0001 ADD2 ,shift-left JSR2
$erase-end
2021-03-08 22:50:12 -05:00
~selection.from #0001 SUB2 =selection.from
2021-03-13 13:31:29 -05:00
,$keys-end JMP2
$no-backspace
2021-03-08 13:30:13 -05:00
2021-03-08 13:55:57 -05:00
( insert )
2021-03-10 22:41:46 -05:00
~selection.to ~selection.from SUB2 ,shift-right JSR2
2021-03-11 15:19:59 -05:00
~KEYS ~selection.from STR
2021-03-08 19:41:31 -05:00
~selection.from #0001 ADD2 =selection.from
2021-03-08 13:30:13 -05:00
2021-03-13 13:31:29 -05:00
$keys-end
~selection.from #0001 ADD2 =selection.to
( release ) #00 =KEYS
,redraw JSR2
@no-keys
2021-03-08 13:30:13 -05:00
2021-03-07 00:30:16 -05:00
( mouse )
2021-03-12 15:04:44 -05:00
,no-change ~MOUS.state ~touch.state EQU JMP2? POP2
#0000 =SPRT.x ~SCRN.height #0008 SUB2 =SPRT.y
,mouse00icn =SPRT.addr
,nobutton1 ~MOUS.state #01 NEQ JMP2? POP2 ,mouse01icn =SPRT.addr @nobutton1
,nobutton2 ~MOUS.state #10 NEQ JMP2? POP2 ,mouse10icn =SPRT.addr @nobutton2
,nobutton3 ~MOUS.state #11 NEQ JMP2? POP2 ,mouse11icn =SPRT.addr @nobutton3
#01 =SPRT.color
@no-change
2021-03-11 15:19:59 -05:00
,touch-end ~MOUS.state #00 EQU JMP2? POP2
2021-03-09 20:29:56 -05:00
2021-03-11 15:19:59 -05:00
,touch-linebar ~MOUS.x #0010 LTH2 JMP2? POP2
,touch-body ~MOUS.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2
2021-03-10 22:41:46 -05:00
,touch-scrollbar JMP2
2021-03-07 15:32:19 -05:00
2021-03-10 12:29:08 -05:00
@touch-end
2021-03-07 00:30:16 -05:00
2021-03-11 15:19:59 -05:00
~MOUS.state =touch.state
2021-03-07 00:30:16 -05:00
2021-03-10 22:41:46 -05:00
( unlock ) ,skip-unlock ~lock #00 EQU JMP2? POP2 ~lock #01 SUB =lock @skip-unlock
2021-03-09 20:29:56 -05:00
2021-03-10 22:41:46 -05:00
,draw-cursor JSR2
2021-03-07 00:30:16 -05:00
BRK
2021-03-10 12:29:08 -05:00
@touch-scrollbar
2021-03-12 14:37:45 -05:00
,$no-up ~MOUS.y #0008 GTH2 JMP2? POP2
2021-03-10 12:29:08 -05:00
( decr ) ~scroll.y #00 ~scroll.y #0000 NEQ2 SUB2 =scroll.y
2021-03-12 14:37:45 -05:00
^$end JMPS
$no-up
,$no-down ~MOUS.y ~SCRN.height #0008 SUB2 LTH2 JMP2? POP2
2021-03-10 12:29:08 -05:00
( incr ) ~scroll.y #0001 ADD2 =scroll.y
2021-03-12 14:37:45 -05:00
^$end JMPS
$no-down
2021-03-11 15:19:59 -05:00
~MOUS.y #0008 SUB2 =scroll.y
2021-03-12 14:37:45 -05:00
$end
2021-03-10 22:41:46 -05:00
,redraw JSR2
,touch-end JMP2
2021-03-10 12:29:08 -05:00
RTS
@touch-linebar
2021-03-11 15:19:59 -05:00
~MOUS.y #0008 DIV2 ~scroll.y ADD2 =position.y #0000 =position.x
2021-03-10 22:41:46 -05:00
,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to
,redraw JSR2
,touch-end JMP2
2021-03-10 12:29:08 -05:00
RTS
@touch-body
2021-03-12 14:37:45 -05:00
2021-03-11 15:19:59 -05:00
~MOUS.y #0008 DIV2 ~scroll.y ADD2 =position.y
~MOUS.x ~textarea.x1 SUB2 #0007 ADD2 #0007 DIV2 =position.x
2021-03-10 12:29:08 -05:00
2021-03-12 14:37:45 -05:00
,$no-chord-cut ~MOUS.chord #01 NEQ JMP2? POP2
,cut JSR2
( release ) #00 DUP =MOUS.state =MOUS.chord
^$end JMPS
$no-chord-cut
,$no-chord-paste ~MOUS.chord #10 NEQ JMP2? POP2
,paste JSR2
( release ) #00 DUP =MOUS.state =MOUS.chord
^$end JMPS
$no-chord-paste
,$end ~MOUS.state #11 EQU JMP2? POP2
,$no-drag ~MOUS.state ~touch.state NEQ ~CTRL #0f AND #02 NEQ #0101 EQU2 JMP2? POP2
2021-03-10 12:29:08 -05:00
( on drag )
2021-03-10 22:41:46 -05:00
,find-selection JSR2 #0001 ADD2 =selection.to
,clamp-selection JSR2
2021-03-12 14:37:45 -05:00
^$end JMPS
$no-drag
2021-03-10 12:29:08 -05:00
( on click )
2021-03-10 22:41:46 -05:00
,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to
2021-03-12 14:37:45 -05:00
$end
,redraw JSR2
,touch-end JMP2
2021-03-10 12:29:08 -05:00
RTS
2021-03-08 13:30:13 -05:00
@load-file ( path )
2021-03-11 15:19:59 -05:00
=FILE.name #8000 =FILE.length ,document.body =FILE.load
2021-03-08 13:30:13 -05:00
( get file length )
,document.body =document.eof
2021-03-11 23:41:35 -05:00
$loop NOP
2021-03-08 13:30:13 -05:00
( incr ) ~document.eof #0001 ADD2 =document.eof
2021-03-11 23:41:35 -05:00
~document.eof LDR #00 NEQ ^$loop MUL JMPS
2021-03-08 13:30:13 -05:00
RTS
2021-03-12 23:22:28 -05:00
@scroll-up ( length )
DUP2 ~scroll.y LTH2 ,$clamp ROT JMP2? POP2
#0000 =scroll.y POP2 RTS
$clamp
~scroll.y SWP2 SUB2 =scroll.y
RTS
@scroll-down ( length )
( TODO: Clamp )
~scroll.y SWP2 ADD2 =scroll.y
RTS
2021-03-10 14:00:21 -05:00
@shift-left ( length )
=i
~selection.from #0001 SUB2 =j ( start -> end )
2021-03-11 23:41:35 -05:00
$loop NOP
2021-03-10 14:00:21 -05:00
( move ) ~j ~i ADD2 LDR ~j STR
( incr ) ~j #0001 ADD2 =j
2021-03-11 23:41:35 -05:00
~j ~document.eof LTH2 ^$loop MUL JMPS
2021-03-10 14:00:21 -05:00
~document.eof ~i SUB2 =document.eof
RTS
@shift-right ( length )
=i
~document.eof =j ( end -> start )
2021-03-12 23:22:28 -05:00
$loop NOP
2021-03-10 14:00:21 -05:00
( move ) ~j ~i SUB2 LDR ~j STR
( decr ) ~j #0001 SUB2 =j
2021-03-12 23:22:28 -05:00
~j ~selection.from GTH2 ^$loop MUL JMPS
2021-03-10 14:00:21 -05:00
~document.eof ~i ADD2 =document.eof
RTS
2021-03-12 23:22:28 -05:00
@follow-selection
,$no-up ~position.y ~scroll.y GTH2 JMP2? POP2
~position.y =scroll.y RTS
$no-up
,$no-down ~position.y ~SCRN.height #0010 SUB2 #0008 DIV2 ~scroll.y ADD2 LTH2 JMP2? POP2
~position.y ~SCRN.height #0010 SUB2 #0008 DIV2 SUB2 =scroll.y RTS
$no-down
RTS
2021-03-08 22:50:12 -05:00
@clamp-selection
~selection.from ~selection.to LTH2 RTS?
~selection.from #0001 ADD2 =selection.to
RTS
2021-03-09 20:29:56 -05:00
@goto-linestart
2021-03-07 15:32:19 -05:00
2021-03-11 23:41:35 -05:00
$loop NOP
2021-03-09 20:29:56 -05:00
~selection.from #0001 SUB2 LDR #0a EQU RTS?
~selection.from #0001 SUB2 LDR #0d EQU RTS?
( decr ) ~selection.from DUP2 =selection.to #0001 SUB2 =selection.from
2021-03-11 23:41:35 -05:00
~selection.from LDR #00 NEQ ^$loop MUL JMPS
2021-03-09 20:29:56 -05:00
( clamp at document body )
~selection.from ,document.body GTH2 RTS?
,document.body DUP2 =selection.from #0001 ADD2 =selection.to
2021-03-07 15:32:19 -05:00
2021-03-09 20:29:56 -05:00
RTS
2021-03-09 14:33:31 -05:00
2021-03-09 20:29:56 -05:00
@goto-lineend
2021-03-11 23:41:35 -05:00
$loop NOP
2021-03-09 20:29:56 -05:00
~selection.from LDR #0a EQU RTS?
~selection.from LDR #0d EQU RTS?
( incr ) ~selection.from #0001 ADD2 DUP2 #0001 ADD2 =selection.to =selection.from
2021-03-11 23:41:35 -05:00
~selection.from LDR #00 NEQ ^$loop MUL JMPS
2021-03-09 20:29:56 -05:00
( clamp at document body )
~selection.from ,document.eof LTH2 RTS?
,document.eof #0001 SUB2 DUP2 =selection.from #0001 ADD2 =selection.to
2021-03-09 14:33:31 -05:00
RTS
2021-03-09 20:29:56 -05:00
@find-wordstart
2021-03-09 14:33:31 -05:00
2021-03-09 20:29:56 -05:00
~selection.to =j
2021-03-11 23:41:35 -05:00
$loop NOP
2021-03-09 20:29:56 -05:00
( decr ) ~j #0001 SUB2 =j
2021-03-11 23:41:35 -05:00
,$end ~j LDR #20 EQU JMP2? POP2
,$end ~j LDR #0a EQU JMP2? POP2
,$end ~j LDR #0d EQU JMP2? POP2
~j ,document.body GTH2 ^$loop MUL JMPS
$end
2021-03-09 23:26:33 -05:00
( return ) ~j #0001 SUB2
2021-03-09 14:33:31 -05:00
RTS
2021-03-09 20:29:56 -05:00
@find-wordend
2021-03-07 00:30:16 -05:00
2021-03-09 20:29:56 -05:00
~selection.to =j
2021-03-11 23:41:35 -05:00
$loop NOP
2021-03-09 20:29:56 -05:00
( incr ) ~j #0001 ADD2 =j
2021-03-11 23:41:35 -05:00
,$end ~j LDR #20 EQU JMP2? POP2
,$end ~j LDR #0a EQU JMP2? POP2
,$end ~j LDR #0d EQU JMP2? POP2
~j ,document.body GTH2 ^$loop MUL JMPS
$end
2021-03-09 23:26:33 -05:00
( return ) ~j #0001 ADD2
2021-03-07 00:30:16 -05:00
2021-03-09 14:33:31 -05:00
RTS
2021-03-07 00:30:16 -05:00
2021-03-10 12:29:08 -05:00
@find-lineoffset ( return character offset from linestart )
#0000 =j
2021-03-11 23:41:35 -05:00
$loop NOP
2021-03-10 12:29:08 -05:00
( incr ) ~j #0001 ADD2 =j
2021-03-11 23:41:35 -05:00
,$end ~selection.from ~j SUB2 LDR #0a EQU JMP2? POP2
,$end ~selection.from ~j SUB2 LDR #0d EQU JMP2? POP2
~selection.from ~j SUB2 ,document.body GTH2 ^$loop MUL JMPS
$end
2021-03-10 12:29:08 -05:00
( return ) ~j
RTS
2021-03-09 23:26:33 -05:00
@find-line ( position -> addr )
2021-03-08 13:30:13 -05:00
2021-03-09 23:26:33 -05:00
,document.body =j #0000 =pt.y
2021-03-11 23:41:35 -05:00
$loop NOP
,$end ~pt.y ~position.y #0001 SUB2 GTH2 JMP2? POP2
,$no-space ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP2? POP2
2021-03-09 23:26:33 -05:00
( incr ) ~pt.y #0001 ADD2 =pt.y
2021-03-11 23:41:35 -05:00
$no-space
2021-03-09 23:26:33 -05:00
( incr ) ~j #0001 ADD2 =j
2021-03-11 23:41:35 -05:00
~j LDR #00 NEQ ^$loop MUL JMPS
$end
2021-03-09 23:26:33 -05:00
( return ) ~j
2021-03-08 13:30:13 -05:00
2021-03-09 23:26:33 -05:00
RTS
2021-03-09 14:33:31 -05:00
2021-03-09 23:26:33 -05:00
@find-selection ( position -> addr )
2021-03-07 00:30:16 -05:00
2021-03-10 22:41:46 -05:00
,find-line JSR2 ( find line )
2021-03-09 23:26:33 -05:00
#0000 =pt.x
2021-03-11 23:41:35 -05:00
$loop NOP
,$end ~j ~pt.x ADD2 LDR #0a EQU JMP2? POP2
,$end ~j ~pt.x ADD2 LDR #0d EQU JMP2? POP2
2021-03-09 23:26:33 -05:00
( incr ) ~pt.x #0001 ADD2 =pt.x
2021-03-11 23:41:35 -05:00
~pt.x ~position.x #0001 SUB2 LTH2 ^$loop MUL JMPS
$end
2021-03-09 23:26:33 -05:00
( return ) ~pt.x ADD2
2021-03-09 14:33:31 -05:00
RTS
2021-03-12 14:37:45 -05:00
@cut
,copy JSR2
~selection.to ~selection.from SUB2 ,shift-left JSR2
~selection.from #0001 ADD2 =selection.to
RTS
@copy ( selection )
#0000 =i ( start )
~selection.to ~selection.from SUB2 =j ( end )
~j =clip.len
2021-03-12 23:22:28 -05:00
$loop NOP
2021-03-12 14:37:45 -05:00
~selection.from ~i ADD2 LDR ,clip.body ~i ADD2 STR
( incr ) ~i #0001 ADD2 =i
2021-03-12 23:22:28 -05:00
~i ~j LTH2 ^$loop MUL JMPS
2021-03-12 14:37:45 -05:00
RTS
@paste
~clip.len ,shift-right JSR2
#0000 =i ( start )
~clip.len =j ( end )
2021-03-12 23:22:28 -05:00
$loop NOP
2021-03-12 14:37:45 -05:00
,clip.body ~i ADD2 LDR ~selection.from ~i ADD2 STR
( incr ) ~i #0001 ADD2 =i
2021-03-12 23:22:28 -05:00
~i ~j LTH2 ^$loop MUL JMPS
2021-03-12 14:37:45 -05:00
RTS
2021-03-09 14:33:31 -05:00
@select ( position -> selection )
,document.body =selection.from #0000 =pt.x #0000 =pt.y
2021-03-11 23:41:35 -05:00
$loop
,$no-space ~selection.from LDR #0a NEQ ~selection.from LDR #0d NEQ #0101 EQU2 JMP2? POP2
2021-03-07 00:30:16 -05:00
( incr ) ~pt.y #0001 ADD2 =pt.y
#0000 =pt.x
2021-03-11 23:41:35 -05:00
$no-space
,$no-reached ~pt.y ~position.y #0001 SUB2 GTH2 ~pt.x ~position.x #0001 SUB2 GTH2 #0101 NEQ2 JMP2? POP2
2021-03-09 14:33:31 -05:00
~selection.from #0001 ADD2 =selection.to
RTS
2021-03-11 23:41:35 -05:00
$no-reached
2021-03-07 00:30:16 -05:00
( incr ) ~pt.x #0001 ADD2 =pt.x
2021-03-09 14:33:31 -05:00
( incr ) ~selection.from #0001 ADD2 =selection.from
2021-03-11 23:41:35 -05:00
,$loop ~selection.from LDR #00 NEQ JMP2? POP2
2021-03-07 00:30:16 -05:00
RTS
2021-03-09 23:26:33 -05:00
( drawing functions )
2021-03-07 00:30:16 -05:00
@redraw
2021-03-10 22:41:46 -05:00
,draw-textarea JSR2
,draw-scrollbar JSR2
,draw-titlebar JSR2
2021-03-07 00:30:16 -05:00
2021-03-08 00:09:15 -05:00
( save/load icons )
2021-03-11 15:19:59 -05:00
~SCRN.height #0008 SUB2 =SPRT.y
~SCRN.width #0018 SUB2 =SPRT.x
,load_icn =SPRT.addr
#02 =SPRT.color
~SCRN.width #0010 SUB2 =SPRT.x
,save_icn =SPRT.addr
#02 =SPRT.color
2021-03-07 15:32:19 -05:00
2021-03-07 00:30:16 -05:00
RTS
@draw-short ( short )
=addr
2021-03-11 15:19:59 -05:00
,font_hex #00 ,addr LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr
( draw ) #0e =SPRT.color
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ,addr LDR #0f AND #08 MUL ADD2 =SPRT.addr
( draw ) #0e =SPRT.color
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr
( draw ) #0e =SPRT.color
~SPRT.x #0008 ADD2 =SPRT.x
,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =SPRT.addr
( draw ) #0e =SPRT.color
2021-03-07 00:30:16 -05:00
RTS
@draw-cursor
2021-03-11 15:19:59 -05:00
~mouse.x ~MOUS.x NEQU2
~mouse.y ~MOUS.y NEQU2
2021-03-07 00:30:16 -05:00
#0000 EQU2 RTS? ( Return if unchanged )
( clear last cursor )
2021-03-11 15:19:59 -05:00
~mouse.x =SPRT.x
~mouse.y =SPRT.y
,blank_icn =SPRT.addr
#10 =SPRT.color
2021-03-07 00:30:16 -05:00
( record mouse positions )
2021-03-11 15:19:59 -05:00
~MOUS.x =mouse.x
~MOUS.y =mouse.y
2021-03-07 00:30:16 -05:00
( draw new cursor )
2021-03-11 15:19:59 -05:00
~mouse.x =SPRT.x
~mouse.y =SPRT.y
,cursor_icn =SPRT.addr
#13 =SPRT.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-12 23:22:28 -05:00
$find-offset NOP
,$find-offset-end ~scroll.y ~j EQU2 JMP2? POP2
,$no-break ~textarea.addr LDR #0a NEQ ~textarea.addr LDR #0d NEQ #0101 EQU2 JMP2? POP2
2021-03-07 15:32:19 -05:00
( incr ) ~j #0001 ADD2 =j
2021-03-12 23:22:28 -05:00
$no-break
2021-03-07 15:32:19 -05:00
( incr ) ~textarea.addr #0001 ADD2 =textarea.addr
2021-03-12 23:22:28 -05:00
~textarea.addr LDR #00 NEQ ^$find-offset MUL JMPS
$find-offset-end
2021-03-07 00:30:16 -05:00
2021-03-12 23:22:28 -05:00
#0018 =SPRT.x #0000 =SPRT.y
~textarea.addr =i
2021-03-07 21:51:29 -05:00
2021-03-11 23:41:35 -05:00
$loop
2021-03-07 00:30:16 -05:00
2021-03-11 23:41:35 -05:00
,$end ~SPRT.y ~SCRN.height #0010 SUB2 GTH2 JMP2? POP2
2021-03-09 23:26:33 -05:00
( get character )
2021-03-12 23:22:28 -05:00
,font #00 ~i LDR #20 SUB #0008 MUL2 ADD2 =SPRT.addr
2021-03-09 23:26:33 -05:00
( draw ) #01
2021-03-12 23:22:28 -05:00
~i ~selection.from #0001 SUB2 GTH2
~i ~selection.to LTH2 #0101 EQU2
2021-03-13 13:31:29 -05:00
#05 MUL ADD ~i ~selection.from EQU2 ADD =SPRT.color
2021-03-09 23:26:33 -05:00
2021-03-12 23:22:28 -05:00
,$no-linebreak ~i LDR #0a NEQ ~i LDR #0d NEQ #0101 EQU2 JMP2? POP2
2021-03-09 14:33:31 -05:00
( draw linebreak )
2021-03-11 15:19:59 -05:00
,linebreak_icn =SPRT.addr
2021-03-11 23:41:35 -05:00
( draw ) #02
2021-03-12 23:22:28 -05:00
~i ~selection.from #0001 SUB2 GTH2
~i ~selection.to LTH2 #0101 EQU2
2021-03-11 23:41:35 -05:00
#06 MUL ADD =SPRT.color
2021-03-07 21:51:29 -05:00
( fill clear )
2021-03-11 23:41:35 -05:00
$fill-clear
2021-03-11 15:19:59 -05:00
( incr ) ~SPRT.x #0008 ADD2 =SPRT.x
,font =SPRT.addr
#01 =SPRT.color
2021-03-11 23:41:35 -05:00
,$fill-clear ~SPRT.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2
2021-03-12 23:22:28 -05:00
( draw line number )
#0000 =SPRT.x
~scroll.y ~SPRT.y #0008 DIV2 ADD2 DUP2 SWP POP =k
~position.y EQU2 #0c MUL =l
,font_hex #00 ~k #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr
#02 ~l ADD =SPRT.color
#0008 =SPRT.x
,font_hex #00 ~k #0f AND #08 MUL ADD2 =SPRT.addr
#02 ~l ADD =SPRT.color
2021-03-11 15:19:59 -05:00
#0010 =SPRT.x
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
2021-03-11 23:41:35 -05:00
$no-linebreak
2021-03-06 14:44:18 -05:00
2021-03-12 23:22:28 -05:00
( incr ) ~i #0001 ADD2 =i
2021-03-11 15:19:59 -05:00
( incr ) ~SPRT.x #0007 ADD2 =SPRT.x
2021-03-08 13:30:13 -05:00
2021-03-12 23:22:28 -05:00
,$loop ~i LDR #00 NEQ JMP2? POP2
2021-03-07 21:51:29 -05:00
2021-03-11 23:41:35 -05:00
$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
2021-03-11 15:19:59 -05:00
~SCRN.width #0008 SUB2 =SPRT.x
#0000 =SPRT.y
,scrollbar_bg =SPRT.addr
2021-03-07 00:30:16 -05:00
2021-03-13 13:31:29 -05:00
$loop NOP
2021-03-11 15:19:59 -05:00
( draw ) #08 =SPRT.color
( incr ) ~SPRT.y #0008 ADD2 =SPRT.y
2021-03-13 13:31:29 -05:00
~SPRT.y ~SCRN.height LTH2 ^$loop MUL JMPS
2021-03-07 00:30:16 -05:00
2021-03-11 15:19:59 -05:00
#0000 =SPRT.y
,arrowup_icn =SPRT.addr
( draw ) #08 =SPRT.color
2021-03-07 15:32:19 -05:00
( at )
2021-03-11 15:19:59 -05:00
~scroll.y #0008 ADD2 =SPRT.y
,scrollbar_fg =SPRT.addr
( draw ) #08 =SPRT.color
2021-03-07 15:32:19 -05:00
2021-03-11 15:19:59 -05:00
~SCRN.height #0008 SUB2 =SPRT.y
,arrowdown_icn =SPRT.addr
( draw ) #08 =SPRT.color
2021-03-07 00:30:16 -05:00
RTS
@draw-titlebar
2021-03-11 15:19:59 -05:00
#0018 ~SCRN.height #0008 SUB2 #09 ,filepath
( load ) =label.addr =label.color =SPRT.y =SPRT.x
2021-03-07 00:30:16 -05:00
~label.addr
2021-03-11 23:41:35 -05:00
$loop NOP
2021-03-11 15:19:59 -05:00
( draw ) DUP2 LDR #00 SWP #20 SUB #0008 MUL2 ,font ADD2 =SPRT.addr ~label.color =SPRT.color
2021-03-07 00:30:16 -05:00
( incr ) #0001 ADD2
2021-03-11 15:19:59 -05:00
( incr ) ~SPRT.x #0008 ADD2 =SPRT.x
2021-03-11 23:41:35 -05:00
DUP2 LDR #00 NEQ ^$loop MUL JMPS
2021-03-07 00:30:16 -05:00
POP2
2021-03-08 13:30:13 -05:00
( selection )
2021-03-10 22:41:46 -05:00
~selection.from ,document.body SUB2 ,draw-short JSR2
2021-03-08 13:30:13 -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-12 15:04:44 -05:00
@mouse00icn [ 0000 0000 0000 0000 ]
@mouse01icn [ 0078 7878 7878 7800 ]
@mouse10icn [ 001e 1e1e 1e1e 1e00 ]
@mouse11icn [ 007e 7e7e 7e7e 7e00 ]
2021-03-09 14:33:31 -05:00
@linebreak_icn [ 003e 7474 3414 1400 ]
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-12 14:37:45 -05:00
@filepath1 [ projects/examples/gui.hover.usm 00 ]
@filepath [ projects/software/left.usm 00 ]
2021-03-06 14:44:18 -05:00
2021-03-12 14:37:45 -05:00
|3000 ;document Document
|c000 ;clip Clip
2021-03-01 14:18:11 -05:00
|d000 @ERROR BRK
2021-03-12 14:37:45 -05:00
|FF00 ;CNSL Console
2021-03-11 15:19:59 -05:00
|FF10 ;SCRN Screen
|FF20 ;SPRT Sprite
|FF30 ;CTRL Controller
|FF40 ;KEYS Keyboard
|FF50 ;MOUS Mouse
|FF60 ;FILE File
2021-03-01 14:18:11 -05:00
|FFF0 .RESET .FRAME .ERROR ( vectors )
2021-03-11 23:41:35 -05:00
|FFF8 [ 30ff e0f3 b0f3 ] ( palette )