optimize some labels, optimize redrawing

This commit is contained in:
~d6 2022-04-01 12:11:09 -04:00
parent 17ed894126
commit 5ef9b333c9
1 changed files with 38 additions and 52 deletions

View File

@ -88,6 +88,8 @@
( zero page )
|0000
@counter $2
@term [
&cols $2 ( relative x coordinate of cursor, from 0 )
&rows $2 ( relative y coordinaet of cursor, from 1 )
@ -145,7 +147,7 @@
&active $1 ( are we displaying search results? )
&orig-row $2 ( row we began the search at )
&orig-col $2 ( col we began the search at )
( &regex $2 ( regex to be stored if any ) )
&regex $2 ( regex to be stored if any )
]
( startup )
@ -153,7 +155,7 @@
;init-zero-page JSR2
;startup JMP2
( ~regex.tal )
~regex.tal
( intialize zero page variables )
( )
@ -276,16 +278,17 @@
( FIXME: handle long lines )
@forward ( -> )
;cur-pos JSR2 ;last-pos JSR2 GTH2 ,&skip JCN
;cur-col JSR2 ;cur-len JSR2 LTH2 ,&normal JCN ,&next-line JMP
;cur-col JSR2 ;cur-len JSR2 LTH2 ,&normal JCN
#0000 .cursor/col STZ2
.cursor/row LDZ2 INC2 .cursor/row STZ2
;ensure-visible-cursor JSR2
,&skip JMP
&normal
;cur-col JSR2 INC2 .cursor/col STZ2
;redraw-statusbar-and-cursor JSR2
,&skip JMP
&next-line #0000 .cursor/col STZ2
.cursor/row LDZ2 INC2 .cursor/row STZ2
;ensure-visible-cursor JSR2
;redraw-cursor JSR2
&skip ;return JMP2
;cur-col JSR2 INC2 .cursor/col STZ2
;redraw-statusbar-and-cursor JSR2
&skip
;redraw-cursor JSR2
;return JMP2
( FIXME: handle long lines )
@go-back ( -> )
@ -543,7 +546,8 @@
#0000 SWP2 ;jump-to-coord JMP2
@ensure-visible-cursor
;cur-rel-row JSR2 .term/rows LDZ2 LTH2 ,&noop JCN
.cursor/row LDZ2 .buffer/line-offset LDZ2
SUB2 .term/rows LDZ2 LTH2 ,&noop JCN
;cur-abs-row JSR2 ;jump-to-line JSR2
;redraw-all JSR2
&noop JMP2r
@ -613,25 +617,24 @@
;redraw-prompt-and-cursor JSR2 ;return JMP2
@do-search ( -> )
( #0000 .searching/regex STZ2 )
#0000 .searching/regex STZ2
;move-to-next-match JSR2 ,&found JCN
;move-to-prev-match JSR2 ,&found JCN
;move-to-message-line JSR2 ;messages/no-matches-found ;print JSR2
;draw-cursor JSR2 BRK
&found #01 .searching/active STZ ;return JMP2
( @regex-search ( -> )
@regex-search ( -> )
;messages/regex-search-prompt ;messages/null ;do-regex-search ;start-prompt JSR2
;redraw-prompt-and-cursor JSR2 ;return JMP2
@do-regex-search ( -> )
;tmp/data ;compile .searching/regex STZ2
( compile regex )
;move-to-next-regex-match JSR2 ,&found JCN
;move-to-prev-regex-match JSR2 ,&found JCN
;move-to-message-line JSR2 ;messages/no-matches-found ;print JSR2
;draw-cursor JSR2 BRK
&found #01 .searching/active STZ ;return JMP2 )
&found #01 .searching/active STZ ;return JMP2
@toggle-color ( -> )
.config/color LDZ2 #3733 EQU2 ,&wrap-around JCN
@ -652,7 +655,7 @@
.state/key LDZ LIT '> EQU ( M-> ) ;goto-end JCN2
.state/key LDZ LIT 'c EQU ( M-c ) ;toggle-color JCN2
.state/key LDZ LIT 'g EQU ( M-g ) ;goto-line JCN2
( .state/key LDZ LIT 's EQU ( M-s ) ;regex-search JCN2 )
.state/key LDZ LIT 's EQU ( M-s ) ;regex-search JCN2
.state/key LDZ LIT 't EQU ( M-t ) ;toggle-tabs JCN2
.state/key LDZ LIT 'v EQU ( M-v ) ;page-up JCN2
.state/key LDZ LIT '[ EQU ( M-[ ) ;xterm JCN2
@ -732,17 +735,14 @@
.buffer/limit LDZ2
;cur-pos JSR2 INC2
&loop
GTH2k ,&next JCN ,&fail JMP
&next
GTH2k #00 EQU ,&fail JCN
DUP2 ;matches-at JSR2
ORA ,&found JCN
INC2 ,&loop JMP
&found
NIP2 ;jump-to-pos JSR2 #01 ,&done JMP
NIP2 ;jump-to-pos JSR2 #01 JMP2r
&fail
;redraw-cursor JSR2 POP2 POP2 #00
&done
JMP2r
;redraw-cursor JSR2 POP2 POP2 #00 JMP2r
@move-to-prev-match ( -> ok^ )
;data
@ -753,18 +753,15 @@
ORA ,&found JCN
#0001 SUB2 ,&loop JMP
&found
NIP2 ;jump-to-pos JSR2 #01 ,&done JMP
NIP2 ;jump-to-pos JSR2 #01 JMP2r
&fail
;redraw-cursor JSR2 POP2 POP2 #00
&done
JMP2r
;redraw-cursor JSR2 POP2 POP2 #00 JMP2r
( @move-to-next-regex-match ( -> ok^ )
@move-to-next-regex-match ( -> ok^ )
.buffer/limit LDZ2
;cur-pos JSR2 INC2
&loop
GTH2k ,&next JCN ,&fail JMP
&next
GTH2k #00 EQU ,&fail JCN
( ;search-start ;search-end )
( DUP2 ;matches-at JSR2 )
DUP2 .searching/regex LDR2 ;rx-search
@ -776,11 +773,9 @@
;search-start LDA2
;jump-to-pos JSR2 #01 JMP2r
&fail
POP2 POP2 #00
&done
JMP2r )
POP2 POP2 #00 JMP2r
( @move-to-prev-regex-match ( -> ok^ )
@move-to-prev-regex-match ( -> ok^ )
#00 JMP2r
( ;data
;cur-pos JSR2 #0001 SUB2
@ -794,7 +789,7 @@
&fail
POP2 POP2 #00
&done
JMP2r ) )
JMP2r )
@on-key-searching
.state/key LDZ #07 EQU ( C-g ) ;cancel-search JCN2
@ -870,21 +865,9 @@
@redraw-prompt-and-cursor ( -> ) #05 ;redraw-add JMP2
@redraw-all ( -> ) #1f ;redraw-add JMP2
( @offset-for-cur-row
.buffer/offset LDZ2 ( offset )
#0000 ;cur-rel-row JSR2 SUB2 STH2 ( offset [-k] )
&loop STH2r ORA ,&next JCN
POP2r JMP2r
&next LDAk #0a NEQ JMP INC2r
INC2 ,&loop JMP )
@draw-cursor ( -> )
.prompt/active LDZ ,&on-prompt JCN
;cur-w-col JSR2 .term/lmargin LDZ2 ADD2
.term/cols LDZ2 LTH2 ,&ok JCN
( we have a long line )
( ;offset-for-cur-row JSR2 )
&ok
( TODO: handle long lines )
;cur-w-col JSR2 .term/lmargin LDZ2 ADD2
;cur-rel-row JSR2
;term-move-cursor JMP2
@ -928,6 +911,7 @@
emit-)
sp
;get-tab-status JSR2 ;print JSR2
sp .counter LDZ2 ;emit-dec2 JSR2 ( FIXME )
;emit-reset JSR2
JMP2r
@ -981,6 +965,8 @@
&not-end
;abs-line JMP2
( TODO: enable drawing of regex matches )
( requires a way to anchor our regex on the LHS (e.g. ^) )
@draw-matches ( -> )
( return if not searching )
.searching/active LDZ #00 EQU ,&return JCN ( )
@ -1093,9 +1079,9 @@
DUP #08 AND ,&do-8 JCN ,&skip-8 JMP &do-8 ;draw-matches JSR2
&skip-8 DUP #04 AND ,&do-4 JCN ,&skip-4 JMP &do-4 ;draw-prompt JSR2
&skip-4 DUP #02 AND ,&do-2 JCN ,&skip-2 JMP &do-2 ;draw-statusbar JSR2
&skip-2 DUP #01 AND ,&do-1 JCN ,&skip-1 JMP &do-1 ;draw-cursor JSR2
&draw-all ;draw-all JSR2
&skip-1 POP #00 .state/redraw STZ BRK
&skip-2 DUP #01 AND ,&do-1 JCN ,&finish JMP &do-1 ;draw-cursor JSR2 ,&finish JMP
&draw-all .counter LDZ2k INC2 ROT STZ2 ;draw-all JSR2
&finish POP #00 .state/redraw STZ BRK
@str-copy ( src* dst* -> )
STH2 ( src [dst] )
@ -1324,7 +1310,7 @@
&goto-line "Go 20 "to 20 "line: 20 00
&save-prompt "File 20 "Name 20 "to 20 "Write: 20 00
&search-prompt "Text 20 "to 20 "Search 20 "for: 20 00
( &regex-search-prompt "Regex 20 "to 20 "Search 20 "for: 20 00 )
&regex-search-prompt "Regex 20 "to 20 "Search 20 "for: 20 00
&quit-prompt "Save 20 "modified 20 "file 20 "(y/n)? 20 00
&unknown-input "Unknown 20 "input: 20 00
&no-matches-found "No 20 "matches 20 "found 00