uxn/projects/software/left.usm

719 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
2021-03-30 23:36:41 -04:00
- Rename icon in titlebar
2021-03-08 19:41:31 -05:00
- 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
FIXME
- Imperfect port from previous assembler syntax
)
2021-03-13 23:51:43 -05:00
2021-03-16 00:29:44 -04:00
%RTN { JMP2r }
2021-05-11 14:12:07 -04:00
%RTN? { #00 EQU #02 JCN STH2r JMP2 }
2021-03-16 00:29:44 -04:00
2021-03-16 14:25:26 -04:00
%++ { #0001 ADD2 } %-- { #0001 SUB2 }
2021-03-20 00:13:09 -04:00
%8/ { #0003 SFT2 } %8* { #0030 SFT2 }
2021-03-16 14:25:26 -04:00
%8- { #0008 SUB2 } %8+ { #0008 ADD2 }
( devices )
2021-03-21 16:58:32 -04:00
|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 ]
2021-04-26 13:52:46 -04:00
|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 ]
2021-03-09 20:29:56 -05:00
( variables )
2021-03-21 16:58:32 -04:00
|0000
@lock [ &byte $1 ]
@k [ &byte $1 ]
@l [ &byte $1 ]
@i [ &short $2 ]
@j [ &short $2 ]
@addr [ &short $2 ]
@selection [ &from $2 &to $2 ]
@position [ &x $2 &y $2 ]
@scroll [ &x $2 &y $2 ]
@pt [ &x $2 &y $2 ]
@mouse [ &x $2 &y $2 ]
@touch [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &state $1 ]
@textarea [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &addr $2 &cursor $1 ]
@label [ &x $2 &y $2 &color $1 &addr $2 ] ( remove )
2021-03-28 13:19:06 -04:00
2021-03-21 16:58:32 -04:00
( program )
|0100 @RESET
2021-03-08 00:09:15 -05:00
( theme ) #e0fa .System/r DEO2 #30fa .System/g DEO2 #30fa .System/b DEO2
( vectors ) ;on-mouse .Mouse/vector DEO2
( vectors ) ;on-button .Controller/vector DEO2
2021-03-28 14:02:11 -04:00
2021-03-08 00:09:15 -05:00
( load file )
;filepath ;load-file JSR2
2021-03-31 13:00:32 -04:00
2021-03-08 00:09:15 -05:00
( place textarea )
2021-05-11 14:14:52 -04:00
#0018 .textarea/x1 STZ2 .Screen/height DEI2 8- .textarea/y2 STZ2
2021-03-07 00:30:16 -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-04-09 13:01:53 -04:00
@on-button ( -> )
( alt + arrow )
2021-05-11 14:12:07 -04:00
.Controller/button DEI #0f AND #02 NEQ ,&no-alt JCN
.Controller/button DEI #04 SFT
2021-05-11 14:12:07 -04:00
DUP #01 NEQ ,&no-aup JCN
2021-05-11 14:14:52 -04:00
( sel word ) ;find-wordstart JSR2 .selection/to STZ2 &no-aup
2021-05-11 14:12:07 -04:00
DUP #02 NEQ ,&no-adown JCN
2021-05-11 14:14:52 -04:00
( sel word ) ;find-wordend JSR2 .selection/to STZ2 &no-adown
2021-05-11 14:12:07 -04:00
DUP #04 NEQ ,&no-aleft JCN
2021-05-11 14:14:52 -04:00
( sel decr ) .selection/to LDZ2 -- .selection/to STZ2 &no-aleft
2021-05-11 14:12:07 -04:00
DUP #08 NEQ ,&no-aright JCN
2021-05-11 14:14:52 -04:00
( sel incr ) .selection/to LDZ2 ++ .selection/to STZ2 &no-aright
2021-04-09 13:01:53 -04:00
POP
;clamp-selection JSR2
;redraw JSR2
2021-04-09 13:01:53 -04:00
BRK
&no-alt
2021-04-09 13:01:53 -04:00
( ctrl + arrow )
2021-05-11 14:12:07 -04:00
.Controller/button DEI #0f AND #01 NEQ ,&no-ctrl JCN
.Controller/button DEI #04 SFT
2021-05-11 14:12:07 -04:00
DUP #01 NEQ ,&no-cup JCN
( jump scroll ) #0004 ;scroll-up JSR2 &no-cup
2021-05-11 14:12:07 -04:00
DUP #02 NEQ ,&no-cdown JCN
( jump scroll ) #0004 ;scroll-down JSR2 &no-cdown
2021-05-11 14:12:07 -04:00
DUP #04 NEQ ,&no-cleft JCN
( jump line ) ;goto-linestart JSR2 &no-cleft
2021-05-11 14:12:07 -04:00
DUP #08 NEQ ,&no-cright JCN
( jump line ) ;goto-lineend JSR2 &no-cright
2021-04-09 13:01:53 -04:00
POP
;redraw JSR2
2021-04-09 13:01:53 -04:00
BRK
&no-ctrl
2021-04-09 13:01:53 -04:00
( arrow )
2021-05-11 14:12:07 -04:00
.Controller/button DEI #f0 AND #00 EQU ;&no-arrow JCN2
.Controller/button DEI #f0 AND
2021-05-11 14:12:07 -04:00
DUP #10 NEQ ,&no-arrowup JCN
2021-05-11 14:14:52 -04:00
( clamp ) .position/y LDZ2 #0000 EQU2 ,&no-arrowup JCN
;find-lineoffset JSR2 .position/x STZ2 .position/y LDZ2 -- .position/y STZ2
;find-selection JSR2 DUP2 .selection/from STZ2 ++ .selection/to STZ2 &no-arrowup
2021-05-11 14:12:07 -04:00
DUP #20 NEQ ,&no-arrowdown JCN
2021-04-09 13:01:53 -04:00
( clamp:TODO )
2021-05-11 14:14:52 -04:00
;find-lineoffset JSR2 .position/x STZ2 .position/y LDZ2 ++ .position/y STZ2
;find-selection JSR2 DUP2 .selection/from STZ2 ++ .selection/to STZ2 &no-arrowdown
2021-05-11 14:12:07 -04:00
DUP #40 NEQ ,&no-arrowleft JCN
2021-05-11 14:14:52 -04:00
( clamp ) .selection/from LDZ2 ;document/body EQU2 ,&no-arrowleft JCN
.selection/from LDZ2 -- DUP2 .selection/from STZ2 ++ .selection/to STZ2 &no-arrowleft
2021-05-11 14:12:07 -04:00
DUP #80 NEQ ,&no-arrowright JCN
2021-04-09 13:01:53 -04:00
( clamp:TODO )
#aa .Console/byte DEO
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 ++ DUP2 .selection/from STZ2 ++ .selection/to STZ2 &no-arrowright
2021-04-09 13:01:53 -04:00
POP
;clamp-selection JSR2
;follow-selection JSR2
;redraw JSR2
&no-arrow
2021-03-07 00:30:16 -05:00
2021-05-11 14:12:07 -04:00
.Controller/key DEI #08 NEQ ,&no-backspace JCN
2021-04-10 23:55:31 -04:00
( erase )
2021-05-11 14:14:52 -04:00
.selection/to LDZ2 .selection/from LDZ2 SUB2 #0001 NEQ2 ,&erase-multiple JCN
.selection/to LDZ2 .selection/from LDZ2 SUB2 ;shift-left JSR2
;&erase-end JMP2
&erase-multiple
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 ++ .selection/from STZ2
.selection/to LDZ2 .selection/from LDZ2 SUB2 ++ ;shift-left JSR2
&erase-end
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 -- .selection/from STZ2
.selection/from LDZ2 ++ .selection/to STZ2
;redraw JSR2
2021-04-10 23:55:31 -04:00
BRK
&no-backspace
2021-04-10 23:55:31 -04:00
( insert )
2021-05-11 14:14:52 -04:00
.selection/to LDZ2 .selection/from LDZ2 SUB2 ;shift-right JSR2
.Controller/key DEI .selection/from LDZ2 STA
.selection/from LDZ2 ++ .selection/from STZ2
.selection/from LDZ2 ++ .selection/to STZ2
;redraw JSR2
2021-04-10 23:55:31 -04:00
2021-04-09 13:01:53 -04:00
BRK
@on-mouse ( -> )
2021-05-11 14:12:07 -04:00
.Mouse/state DEI #00 EQU ,&touch-end JCN
.Mouse/x DEI2 #0010 LTH2 ;touch-linebar JCN2
.Mouse/x DEI2 .Screen/width DEI2 8- LTH2 ;touch-body JCN2
;touch-scrollbar JMP2
&touch-end
2021-03-07 00:30:16 -05:00
2021-05-11 14:14:52 -04:00
.Mouse/state DEI .touch/state STZ
2021-03-07 00:30:16 -05:00
;draw-cursor JSR2
2021-03-07 00:30:16 -05:00
2021-04-09 13:01:53 -04:00
BRK
2021-03-07 00:30:16 -05:00
@touch-linebar ( -- )
2021-05-11 14:14:52 -04:00
#0000 .position/x STZ2
.Mouse/y DEI2 8/ .scroll/y LDZ2 ADD2 .position/y STZ2
;find-selection JSR2 DUP2 .selection/from STZ2 ++ .selection/to STZ2
;goto-linestart JSR2
;redraw JSR2
;draw-cursor JSR2
2021-03-10 12:29:08 -05:00
BRK
2021-03-10 12:29:08 -05:00
@touch-body ( -- )
2021-03-12 14:37:45 -05:00
2021-05-11 14:14:52 -04:00
.Mouse/y DEI2 8/ .scroll/y LDZ2 ADD2 .position/y STZ2
.Mouse/x DEI2 .textarea/x1 LDZ2 SUB2 #0007 ADD2 #0007 DIV2 .position/x STZ2
( chords )
2021-05-11 14:12:07 -04:00
.Mouse/chord DEI #00 EQU ,&no-chords JCN
.Mouse/chord DEI
2021-05-11 14:12:07 -04:00
DUP #01 NEQ ,&no-chord-cut JCN
;cut JSR2 ( release ) #00 DUP .Mouse/state DEO .Mouse/chord DEO &no-chord-cut
2021-05-11 14:12:07 -04:00
DUP #10 NEQ ,&no-chord-paste JCN
;paste JSR2 ( release ) #00 DUP .Mouse/state DEO .Mouse/chord DEO &no-chord-paste
POP
;redraw JSR2
BRK
&no-chords
( drag )
2021-05-11 14:14:52 -04:00
.Mouse/state DEI .touch/state LDZ NEQ .Controller/button DEI #0f AND #02 NEQ #0101 EQU2 ,&no-drag JCN
2021-03-10 12:29:08 -05:00
( on drag )
2021-05-11 14:14:52 -04:00
;find-selection JSR2 ++ .selection/to STZ2
;clamp-selection JSR2
,&end JMP
&no-drag
( on click )
2021-05-11 14:14:52 -04:00
;find-selection JSR2 DUP2 .selection/from STZ2 ++ .selection/to STZ2
&end
2021-05-11 14:14:52 -04:00
.Mouse/state DEI .touch/state STZ
;draw-cursor JSR2
;redraw JSR2
2021-03-10 12:29:08 -05:00
BRK
@touch-scrollbar ( -- )
2021-05-11 14:12:07 -04:00
.Mouse/y DEI2 #0008 GTH2 ,&no-up JCN
2021-05-11 14:14:52 -04:00
( decr ) .scroll/y LDZ2 #00 .scroll/y LDZ2 #0000 NEQ2 SUB2 .scroll/y STZ2
,&end JMP
&no-up
2021-05-11 14:12:07 -04:00
.Mouse/y DEI2 .Screen/height DEI2 8- LTH2 ,&no-down JCN
2021-05-11 14:14:52 -04:00
( incr ) .scroll/y LDZ2 ++ .scroll/y STZ2
,&end JMP
&no-down
2021-05-11 14:14:52 -04:00
.Mouse/y DEI2 8- .scroll/y STZ2
&end
2021-05-11 14:14:52 -04:00
.Mouse/state DEI .touch/state STZ
;draw-cursor JSR2
;redraw JSR2
BRK
2021-03-10 12:29:08 -05:00
2021-03-08 13:30:13 -05:00
@load-file ( path )
.File/name DEO2 #8000 .File/length DEO2 ;document/body .File/load DEO2
2021-03-08 13:30:13 -05:00
( get file length )
2021-05-03 12:57:39 -04:00
;document/body ;document/eof STA2
&loop
2021-05-03 12:57:39 -04:00
( incr ) ;document/eof LDA2 ++ ;document/eof STA2
2021-05-11 14:12:07 -04:00
;document/eof LDA2 LDA #00 NEQ ,&loop JCN
2021-03-08 13:30:13 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-08 13:30:13 -05:00
2021-03-31 13:00:32 -04:00
@scroll-up ( length -- )
2021-03-12 23:22:28 -05:00
2021-05-11 14:14:52 -04:00
DUP2 .scroll/y LDZ2 LTH2 ,&clamp JCN
#0000 .scroll/y STZ2 POP2 RTN
&clamp
2021-05-11 14:14:52 -04:00
.scroll/y LDZ2 SWP2 SUB2 .scroll/y STZ2
2021-03-12 23:22:28 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-12 23:22:28 -05:00
2021-03-31 13:00:32 -04:00
@scroll-down ( length -- )
2021-03-12 23:22:28 -05:00
( TODO: Clamp )
2021-05-11 14:14:52 -04:00
.scroll/y LDZ2 SWP2 ADD2 .scroll/y STZ2
2021-03-12 23:22:28 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-12 23:22:28 -05:00
@shift-left ( length -- )
2021-03-10 14:00:21 -05:00
2021-05-11 14:14:52 -04:00
.i STZ2
.selection/from LDZ2 -- .j STZ2 ( start -> end )
&loop
2021-05-11 14:14:52 -04:00
( move ) .j LDZ2 .i LDZ2 ADD2 LDA .j LDZ2 STA
( incr ) .j LDZ2 ++ .j STZ2
.j LDZ2 ;document/eof LDA2 LTH2 ,&loop JCN
;document/eof LDA2 .i LDZ2 SUB2 ;document/eof STA2
2021-03-10 14:00:21 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-10 14:00:21 -05:00
@shift-right ( length -- )
2021-03-10 14:00:21 -05:00
2021-05-11 14:14:52 -04:00
.i STZ2
;document/eof LDA2 .j STZ2 ( end -> start )
&loop
2021-05-11 14:14:52 -04:00
( move ) .j LDZ2 .i LDZ2 SUB2 LDA .j LDZ2 STA
( decr ) .j LDZ2 -- .j STZ2
.j LDZ2 .selection/from LDZ2 GTH2 ,&loop JCN
;document/eof LDA2 .i LDZ2 ADD2 ;document/eof STA2
2021-03-10 14:00:21 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-10 14:00:21 -05:00
@follow-selection ( -- )
2021-03-12 23:22:28 -05:00
2021-05-11 14:14:52 -04:00
.position/y LDZ2 .scroll/y LDZ2 GTH2 ,&no-up JCN
.position/y LDZ2 .scroll/y STZ2 RTN
&no-up
2021-05-11 14:14:52 -04:00
.position/y LDZ2 .Screen/height DEI2 #0010 SUB2 8/ .scroll/y LDZ2 ADD2 LTH2 ,&no-down JCN
.position/y LDZ2 .Screen/height DEI2 #0010 SUB2 8/ SUB2 .scroll/y STZ2 RTN
&no-down
2021-03-12 23:22:28 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-12 23:22:28 -05:00
@clamp-selection ( -- )
2021-03-08 22:50:12 -05:00
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 .selection/to LDZ2 LTH2 RTN?
.selection/from LDZ2 ++ .selection/to STZ2
2021-03-08 22:50:12 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-08 22:50:12 -05:00
@goto-linestart ( -- )
2021-03-07 15:32:19 -05:00
&loop
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 -- LDA #0a EQU RTN?
.selection/from LDZ2 -- LDA #0d EQU RTN?
( decr ) .selection/from LDZ2 DUP2 .selection/to STZ2 -- .selection/from STZ2
.selection/from LDZ2 LDA #00 NEQ ,&loop JCN
2021-03-09 20:29:56 -05:00
( clamp at document body )
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 ;document/body GTH2 RTN?
;document/body DUP2 .selection/from STZ2 ++ .selection/to STZ2
2021-03-07 15:32:19 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-09 14:33:31 -05:00
@goto-lineend ( -- )
2021-03-09 20:29:56 -05:00
&loop
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 LDA #0a EQU RTN?
.selection/from LDZ2 LDA #0d EQU RTN?
( incr ) .selection/from LDZ2 ++ DUP2 ++ .selection/to STZ2 .selection/from STZ2
.selection/from LDZ2 LDA #00 NEQ ,&loop JCN
2021-03-09 20:29:56 -05:00
( clamp at document body )
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 ;document/eof LTH2 RTN?
;document/eof -- DUP2 .selection/from STZ2 ++ .selection/to STZ2
2021-03-09 14:33:31 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-09 14:33:31 -05:00
@find-wordstart ( -- )
2021-03-09 14:33:31 -05:00
2021-05-11 14:14:52 -04:00
.selection/to LDZ2 .j STZ2
&loop
2021-05-11 14:14:52 -04:00
( decr ) .j LDZ2 -- .j STZ2
.j LDZ2 LDA #20 EQU ,&end JCN
.j LDZ2 LDA #0a EQU ,&end JCN
.j LDZ2 LDA #0d EQU ,&end JCN
.j LDZ2 ;document/body GTH2 ,&loop JCN
&end
2021-05-11 14:14:52 -04:00
( return ) .j LDZ2 --
2021-03-09 14:33:31 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-09 14:33:31 -05:00
@find-wordend ( -- )
2021-03-07 00:30:16 -05:00
2021-05-11 14:14:52 -04:00
.selection/to LDZ2 .j STZ2
&loop
2021-05-11 14:14:52 -04:00
( incr ) .j LDZ2 ++ .j STZ2
.j LDZ2 LDA #20 EQU ,&end JCN
.j LDZ2 LDA #0a EQU ,&end JCN
.j LDZ2 LDA #0d EQU ,&end JCN
.j LDZ2 ;document/body GTH2 ,&loop JCN
&end
2021-05-11 14:14:52 -04:00
( return ) .j LDZ2 ++
2021-03-07 00:30:16 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-07 00:30:16 -05:00
2021-03-10 12:29:08 -05:00
@find-lineoffset ( return character offset from linestart )
2021-05-11 14:14:52 -04:00
#0000 .j STZ2
&loop
2021-05-11 14:14:52 -04:00
( incr ) .j LDZ2 ++ .j STZ2
.selection/from LDZ2 .j LDZ2 SUB2 LDA #0a EQU ,&end JCN
.selection/from LDZ2 .j LDZ2 SUB2 LDA #0d EQU ,&end JCN
.selection/from LDZ2 .j LDZ2 SUB2 ;document/body GTH2 ,&loop JCN
&end
2021-05-11 14:14:52 -04:00
( return ) .j LDZ2
2021-03-10 12:29:08 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-10 12:29:08 -05:00
2021-03-09 23:26:33 -05:00
@find-line ( position -> addr )
2021-03-08 13:30:13 -05:00
2021-05-11 14:14:52 -04:00
;document/body .j STZ2 #0000 .pt/y STZ2
&loop
2021-05-11 14:14:52 -04:00
.pt/y LDZ2 .position/y LDZ2 -- GTH2 ,&end JCN
.j LDZ2 LDA #0a NEQ .j LDZ2 LDA #0d NEQ #0101 EQU2 ,&no-space JCN
( incr ) .pt/y LDZ2 ++ .pt/y STZ2
&no-space
2021-05-11 14:14:52 -04:00
( incr ) .j LDZ2 ++ .j STZ2
.j LDZ2 LDA #00 NEQ ,&loop JCN
&end
2021-05-11 14:14:52 -04:00
( return ) .j LDZ2
2021-03-08 13:30:13 -05:00
2021-03-14 17:26:17 -04:00
RTN
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
;find-line JSR2 ( find line )
2021-05-11 14:14:52 -04:00
#0000 .pt/x STZ2
&loop
2021-05-11 14:14:52 -04:00
.j LDZ2 .pt/x LDZ2 ADD2 LDA #0a EQU ,&end JCN
.j LDZ2 .pt/x LDZ2 ADD2 LDA #0d EQU ,&end JCN
( incr ) .pt/x LDZ2 ++ .pt/x STZ2
.pt/x LDZ2 .position/x LDZ2 -- LTH2 ,&loop JCN
&end
2021-05-11 14:14:52 -04:00
( return ) .pt/x LDZ2 ADD2
2021-03-09 14:33:31 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-09 14:33:31 -05:00
@cut ( -- )
2021-03-12 14:37:45 -05:00
;copy JSR2
2021-05-11 14:14:52 -04:00
.selection/to LDZ2 .selection/from LDZ2 SUB2 ;shift-left JSR2
.selection/from LDZ2 ++ .selection/to STZ2
2021-03-12 14:37:45 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-12 14:37:45 -05:00
@copy ( -- )
2021-03-12 14:37:45 -05:00
2021-05-11 14:14:52 -04:00
#0000 .i STZ2 ( start )
.selection/to LDZ2 .selection/from LDZ2 SUB2 .j STZ2 ( end )
.j LDZ2 ;clip/len STA2
&loop
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 .i LDZ2 ADD2 LDA ;clip/body .i LDZ2 ADD2 STA
( incr ) .i LDZ2 ++ .i STZ2
.i LDZ2 .j LDZ2 LTH2 ,&loop JCN
2021-03-12 14:37:45 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-12 14:37:45 -05:00
@paste ( -- )
2021-03-12 14:37:45 -05:00
2021-05-03 12:57:39 -04:00
;clip/len LDA2 ;shift-right JSR2
2021-05-11 14:14:52 -04:00
#0000 .i STZ2 ( start )
;clip/len LDA2 .j STZ2 ( end )
&loop
2021-05-11 14:14:52 -04:00
;clip/body .i LDZ2 ADD2 LDA .selection/from LDZ2 .i LDZ2 ADD2 STA
( incr ) .i LDZ2 ++ .i STZ2
.i LDZ2 .j LDZ2 LTH2 ,&loop JCN
2021-03-12 14:37:45 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-12 14:37:45 -05:00
2021-03-09 14:33:31 -05:00
@select ( position -> selection )
2021-05-11 14:14:52 -04:00
;document/body .selection/from STZ2 #0000 .pt/x STZ2 #0000 .pt/y STZ2
&loop
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 LDA #0a NEQ .selection/from LDZ2 LDA #0d NEQ #0101 EQU2 ,&no-space JCN
( incr ) .pt/y LDZ2 ++ .pt/y STZ2
#0000 .pt/x STZ2
&no-space
2021-05-11 14:14:52 -04:00
.pt/y LDZ2 .position/y LDZ2 -- GTH2 .pt/x LDZ2 .position/x LDZ2 -- GTH2 #0101 NEQ2 ,&no-reached JCN
.selection/from LDZ2 ++ .selection/to STZ2
2021-03-14 17:26:17 -04:00
RTN
&no-reached
2021-05-11 14:14:52 -04:00
( incr ) .pt/x LDZ2 ++ .pt/x STZ2
( incr ) .selection/from LDZ2 ++ .selection/from STZ2
.selection/from LDZ2 LDA #00 NEQ ,&loop JCN
2021-03-07 00:30:16 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-07 00:30:16 -05:00
2021-03-09 23:26:33 -05:00
( drawing functions )
2021-03-07 00:30:16 -05:00
@redraw
;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 )
.Screen/height DEI2 8- .Screen/y DEO2
.Screen/width DEI2 #0030 SUB2 .Screen/x DEO2
;eye_icn .Screen/addr DEO2
#22 .Screen/color DEO
.Screen/width DEI2 #0028 SUB2 .Screen/x DEO2
;name_icn .Screen/addr DEO2
#22 .Screen/color DEO
.Screen/width DEI2 #0020 SUB2 .Screen/x DEO2
;load_icn .Screen/addr DEO2
#22 .Screen/color DEO
.Screen/width DEI2 #0018 SUB2 .Screen/x DEO2
;save_icn .Screen/addr DEO2
#22 .Screen/color DEO
2021-03-07 15:32:19 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-07 00:30:16 -05:00
@draw-short ( short )
2021-05-11 14:14:52 -04:00
.addr STZ2
2021-05-03 12:57:39 -04:00
;font_hex #00 ;addr LDA #f0 AND #04 SFT #08 MUL ADD2 .Screen/addr DEO2
( draw ) #2e .Screen/color DEO
.Screen/x DEI2 8+ .Screen/x DEO2
2021-05-03 12:57:39 -04:00
;font_hex #00 ;addr LDA #0f AND #08 MUL ADD2 .Screen/addr DEO2
( draw ) #2e .Screen/color DEO
.Screen/x DEI2 8+ .Screen/x DEO2
2021-05-03 12:57:39 -04:00
;font_hex #00 ;addr ++ LDA #f0 AND #04 SFT #08 MUL ADD2 .Screen/addr DEO2
( draw ) #2e .Screen/color DEO
.Screen/x DEI2 8+ .Screen/x DEO2
2021-05-03 12:57:39 -04:00
;font_hex #00 ;addr ++ LDA #0f AND #08 MUL ADD2 .Screen/addr DEO2
( draw ) #2e .Screen/color DEO
2021-03-14 17:26:17 -04:00
RTN
2021-03-07 00:30:16 -05:00
@draw-cursor
( clear last cursor )
2021-05-11 14:14:52 -04:00
.mouse/x LDZ2 .Screen/x DEO2
.mouse/y LDZ2 .Screen/y DEO2
;blank_icn .Screen/addr DEO2
#30 .Screen/color DEO
2021-03-07 00:30:16 -05:00
( record mouse positions )
2021-05-11 14:14:52 -04:00
.Mouse/x DEI2 .mouse/x STZ2
.Mouse/y DEI2 .mouse/y STZ2
2021-03-07 00:30:16 -05:00
( draw new cursor )
2021-05-11 14:14:52 -04:00
.mouse/x LDZ2 .Screen/x DEO2
.mouse/y LDZ2 .Screen/y DEO2
;cursor_icn .Screen/addr DEO2
#3f .Mouse/state DEI #01 EQU #0a MUL SUB .Screen/color DEO
2021-03-07 00:30:16 -05:00
2021-03-14 17:26:17 -04:00
RTN
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-05-11 14:14:52 -04:00
;document/body .textarea/addr STZ2
2021-03-07 15:32:19 -05:00
( scroll to position )
2021-05-11 14:14:52 -04:00
#0000 .j STZ2 ( j is linebreaks )
&find-offset
2021-05-11 14:14:52 -04:00
.scroll/y LDZ2 .j LDZ2 EQU2 ,&find-offset-end JCN
.textarea/addr LDZ2 LDA #0a NEQ .textarea/addr LDZ2 LDA #0d NEQ #0101 EQU2 ,&no-break JCN
( incr ) .j LDZ2 ++ .j STZ2 &no-break
( incr ) .textarea/addr LDZ2 ++ .textarea/addr STZ2
.textarea/addr LDZ2 LDA #00 NEQ ,&find-offset JCN
&find-offset-end
2021-03-07 00:30:16 -05:00
#0018 .Screen/x DEO2 #0000 .Screen/y DEO2
2021-05-11 14:14:52 -04:00
.textarea/addr LDZ2 .i STZ2
2021-03-07 21:51:29 -05:00
&loop
2021-03-07 00:30:16 -05:00
2021-05-11 14:12:07 -04:00
.Screen/y DEI2 .Screen/height DEI2 #0010 SUB2 GTH2 ;&end JCN2
2021-03-09 23:26:33 -05:00
2021-05-11 14:14:52 -04:00
.i LDZ2 LDA #0a NEQ .i LDZ2 LDA #0d NEQ #0101 EQU2 ;&no-linebreak JCN2
2021-03-09 14:33:31 -05:00
( draw linebreak )
;linebreak_icn .Screen/addr DEO2
2021-03-11 23:41:35 -05:00
( draw ) #02
2021-05-11 14:14:52 -04:00
.i LDZ2 .selection/from LDZ2 -- GTH2
.i LDZ2 .selection/to LDZ2 LTH2 #0101 EQU2
#26 MUL ADD .Screen/color DEO
2021-03-07 21:51:29 -05:00
( fill clear )
&fill-clear
( incr ) .Screen/x DEI2 8+ .Screen/x DEO2
;font .Screen/addr DEO2
#21 .Screen/color DEO
2021-05-11 14:12:07 -04:00
.Screen/x DEI2 .Screen/width DEI2 8- LTH2 ,&fill-clear JCN
2021-03-12 23:22:28 -05:00
( draw line number )
#0000 .Screen/x DEO2
2021-05-11 14:14:52 -04:00
.scroll/y LDZ2 .Screen/y DEI2 8/ ADD2 DUP2 SWP POP .k STZ
.position/y LDZ2 EQU2 #05 MUL .l STZ
;font_hex #00 .k LDZ #f0 AND #04 SFT #08 MUL ADD2 .Screen/addr DEO2
#24 .l LDZ ADD .Screen/color DEO
#0008 .Screen/x DEO2
2021-05-11 14:14:52 -04:00
;font_hex #00 .k LDZ #0f AND #08 MUL ADD2 .Screen/addr DEO2
#24 .l LDZ ADD .Screen/color DEO
2021-04-09 13:01:53 -04:00
#0010 .Screen/x DEO2
( incr ) .Screen/y DEI2 8+ .Screen/y DEO2
&no-linebreak
2021-03-06 14:44:18 -05:00
2021-03-30 23:36:41 -04:00
( get character )
2021-05-11 14:14:52 -04:00
;font #00 .i LDZ2 LDA #20 SUB 8* ADD2 .Screen/addr DEO2
2021-03-30 23:36:41 -04:00
( is a special character )
2021-05-11 14:14:52 -04:00
.i LDZ2 LDA #20 GTH ,&no-tab JCN ;font .Screen/addr DEO2 &no-tab
2021-03-30 23:36:41 -04:00
( draw ) #21
2021-05-11 14:14:52 -04:00
.i LDZ2 .selection/from LDZ2 -- GTH2
.i LDZ2 .selection/to LDZ2 LTH2 #0101 EQU2
#05 MUL ADD .Screen/color DEO
2021-03-30 23:36:41 -04:00
2021-05-11 14:14:52 -04:00
( incr ) .i LDZ2 ++ .i STZ2
( incr ) .Screen/x DEI2 #0007 ADD2 .Screen/x DEO2
2021-03-08 13:30:13 -05:00
2021-05-11 14:14:52 -04:00
.i LDZ2 LDA #00 NEQ ;&loop JCN2
2021-03-07 21:51:29 -05:00
&end
2021-03-07 15:32:19 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-01 14:18:11 -05:00
@draw-scrollbar ( -- )
;scrollbar_icn ( keeping a copy on stack )
2021-03-07 00:30:16 -05:00
.Screen/width DEI2 8- .Screen/x DEO2
#0008 .Screen/y DEO2
DUP2 .Screen/addr DEO2
2021-03-07 00:30:16 -05:00
#0008 .Screen/height DEI2 8-
&loop
( draw ) #21 .Screen/color DEO
( incr ) SWP2 8+ DUP2 .Screen/y DEO2 SWP2
2021-05-11 14:12:07 -04:00
OVR2 OVR2 LTH2 ,&loop JCN
POP2 POP2
2021-03-07 15:32:19 -05:00
2021-05-11 14:14:52 -04:00
.scroll/y LDZ2 8+ .Screen/y DEO2
DUP2 #0008 ADD2 .Screen/addr DEO2
( draw ) #21 .Screen/color DEO
#0000 .Screen/y DEO2
DUP2 #0010 ADD2 .Screen/addr DEO2
( draw ) #24 .Screen/color DEO
2021-03-07 15:32:19 -05:00
.Screen/height DEI2 8- .Screen/y DEO2
#0018 ADD2 .Screen/addr DEO2
( draw ) #24 .Screen/color DEO
2021-03-07 00:30:16 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-07 00:30:16 -05:00
@draw-titlebar
#0018 .Screen/height DEI2 8- #29 ;filepath
2021-05-11 14:14:52 -04:00
( load ) .label/addr STZ2 .label/color STZ .Screen/y DEO2 .Screen/x DEO2
.label/addr LDZ2
&loop
2021-05-11 14:14:52 -04:00
( draw ) DUP2 LDA #00 SWP #20 SUB 8* ;font ADD2 .Screen/addr DEO2 .label/color LDZ .Screen/color DEO
2021-03-16 14:25:26 -04:00
( incr ) ++
( incr ) .Screen/x DEI2 8+ .Screen/x DEO2
2021-05-11 14:12:07 -04:00
DUP2 LDA #00 NEQ ,&loop JCN
2021-03-07 00:30:16 -05:00
POP2
2021-03-08 13:30:13 -05:00
( selection )
2021-05-11 14:14:52 -04:00
.selection/from LDZ2 ;document/body SUB2 ;draw-short JSR2
2021-03-08 13:30:13 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-03-07 00:30:16 -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
2021-03-07 15:32:19 -05:00
007e 4078 4040 7e00 007e 4078 4040 4000
2021-03-07 00:30:16 -05:00
]
@font ( specter8-frag font )
2021-03-07 00:30:16 -05:00
[
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
]
( interface )
@eye_icn
[ 0038 4492 2810 0000 ] ( open )
[ 0000 0082 4438 0000 ] ( closed )
@scrollbar_icn
[ aa55 aa55 aa55 aa55 ] ( bg )
[ ffff ffff ffff ffff ] ( fg )
[ 0010 387c fe10 1010 ] ( up )
[ 0010 1010 fe7c 3810 ] ( down )
@name_icn [ 1054 28c6 2854 1000 ]
@load_icn [ feaa d6aa d4aa f400 ]
@save_icn [ fe82 8282 848a f400 ]
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 ]
@filepath1 [ "projects/examples/gui.hover.usm 00 ]
@filepath [ "README.md 00 ]
@clip [ &len $2 &body $100 ]
@document [ &eof $2 &body $0 ]
2021-03-06 14:44:18 -05:00