lots of bugs fixed

This commit is contained in:
~d6 2023-01-29 23:07:03 -05:00
parent e57df8c544
commit 12a484c10c
1 changed files with 53 additions and 46 deletions

View File

@ -63,6 +63,8 @@
@cur-y $2 ( cursor y: 0 <= cur-y < rows )
@max-x $2 ( cols-1 )
@max-y $2 ( rows-1 )
@col-bytes $2 ( 2*cols )
@debug $1 ( use debug log? )
( terminal settings )
@irm $1 ( 01: insert and move right, 00: replace and overwrite )
@ -73,6 +75,9 @@
#0028 .rows STZ2
#0050 .cols STZ2
( set col-bytes, frequently needed )
.cols LDZ2 DUP2 ADD2 .col-bytes STZ2
( set max row/col )
.rows LDZ2 #0001 SUB2 .max-y STZ2
.cols LDZ2 #0001 SUB2 .max-x STZ2
@ -110,12 +115,13 @@
;on-key .Controller/vect DEO2 ( set up keyboard )
;on-read .Console/vect DEO2 ( set up stdin )
#99
( #010e DEO )
( set up debug log )
;debug .File/name DEO2
#01 .File/append DEO
( set to 01 to enable debug log )
#00 .debug STZ
.debug LDZ ,&continue JCN BRK &continue
#99 #010e DEO
;debug-log .File/name DEO2
#01 .File/append DEO
BRK
@load-theme ( -> )
@ -134,16 +140,16 @@
;cells JMP2r
@bol-addr ( -> addr* )
.cols LDZ2 .cur-y LDZ2 MUL2 #0002 MUL2 ;cells ADD2 JMP2r
.col-bytes LDZ2 .cur-y LDZ2 MUL2 ;cells ADD2 JMP2r
@cur-addr ( -> addr* )
.cols LDZ2 .cur-y LDZ2 MUL2 .cur-x LDZ2 ADD2 #0002 MUL2 ;cells ADD2 JMP2r
.col-bytes LDZ2 .cur-y LDZ2 MUL2 .cur-x LDZ2 DUP2 ADD2 ADD2 ;cells ADD2 JMP2r
@eol-addr ( -> addr* )
.cols LDZ2 .cur-y LDZ2 INC2 MUL2 #0002 MUL2 ;cells ADD2 JMP2r
.col-bytes LDZ2 .cur-y LDZ2 INC2 MUL2 ;cells ADD2 JMP2r
@limit-addr ( -> )
.cols LDZ2 .rows LDZ2 MUL2 #0002 MUL2 ;cells ADD2 JMP2r
.col-bytes LDZ2 .rows LDZ2 MUL2 ;cells ADD2 JMP2r
@min ( x* y* -> min* )
LTH2k JMP SWP2 POP2 JMP2r
@ -279,6 +285,7 @@
&done POP2 POP2 JMP2r
@debug-priv ( c^ -> )
.debug LDZ ,&continue JCN POP JMP2r &continue
;reset-scratch JSR2
;scratch-write STH2
LIT "1 STH2kr JSR2
@ -295,21 +302,6 @@
;scratch .File/w DEO2
JMP2r
( ;scratch STH2
LIT "1 STH2kr STA INC2r
LIT "b STH2kr STA INC2r
#20 STH2kr STA INC2r
LIT "[ STH2kr STA INC2r
#20 STH2kr STA INC2r
LIT "? STH2kr STA INC2r
#20 STH2kr STA INC2r
( TODO: numeric args )
STH2kr STA INC2r
#0a STH2r STA
#0009 .File/len DEO2
;scratch .File/w DEO2
JMP2r )
@end-arg-priv ( c^ -> )
;on-read .Console/vect DEO2
DUP ,debug-priv JSR
@ -317,6 +309,7 @@
POP BRK
@debug-csi ( c^ -> )
.debug LDZ ,&continue JCN POP JMP2r &continue
;reset-scratch JSR2
;scratch-write STH2
LIT "1 STH2kr JSR2
@ -330,17 +323,6 @@
;scratch-len JSR2 .File/len DEO2
;scratch .File/w DEO2
JMP2r
( ;scratch STH2
LIT "1 STH2kr STA INC2r
LIT "b STH2kr STA INC2r
#20 STH2kr STA INC2r
LIT "[ STH2kr STA INC2r
#20 STH2kr STA INC2r
STH2kr STA INC2r
#0a STH2r STA
#0007 .File/len DEO2
;scratch .File/w DEO2
JMP2r )
@end-arg ( c^ -> )
;on-read .Console/vect DEO2
@ -360,6 +342,8 @@
DUP LIT "J EQU ;exec-erase-screen JCN2 ( erase screen )
DUP LIT "K EQU ;exec-erase-line JCN2 ( erase line )
DUP LIT "L EQU ;exec-insert-lines JCN2 ( insert blank lines )
DUP LIT "M EQU ;exec-delete-lines JCN2 ( delete n lines )
DUP LIT "P EQU ;exec-delete-chars JCN2 ( delete n chars )
POP BRK
@exec-noop ( c^ -> )
@ -394,7 +378,6 @@
@exec-set-attr ( c^ -> )
POP
( BRK ( FIXME: gaining 4 bytes per ls -F ) )
;args/pos LDA2 ;args
&loop
LDA2k ;read-attr JSR2
@ -423,6 +406,8 @@
@exec-forward POP ;forward-n ;exec1 JMP2
@exec-back POP ;back-n ;exec1 JMP2
@exec-insert-blanks POP ;insert-n-spaces ;exec1 JMP2
@exec-delete-lines POP ;delete-n-lines ;exec1 JMP2
@exec-delete-chars POP ;delete-n-chars ;exec1 JMP2
@exec-erase-line
POP #0000 ;read-arg-1 JSR2
@ -488,6 +473,7 @@
BRK
@debug-esc ( c^ -> )
.debug LDZ ,&continue JCN POP JMP2r &continue
;scratch STH2
LIT "1 STH2kr STA INC2r
LIT "b STH2kr STA INC2r
@ -547,13 +533,15 @@
( @read-tab POP JMP2r )
@read-tab
POP
.cur-x LDZ2 NIP #07 AND #08 SUB
&loop
.tint LDZ #20 DUP ;cur-addr JSR2 STA2
;draw-cell JSR2
;forward JSR2
INC DUP ,&loop JCN
POP JMP2r
.cur-x LDZ2 ( x* )
NIP #07 AND #08 SUB ( i=(xlo&7)-8^ )
&loop ( i^ )
.tint LDZ #20 DUP2 ( i^ cell* cell* )
;cur-addr JSR2 STA2 ( i^ cell* ; addr<-cell )
;draw-cell JSR2 ( i^ )
;forward JSR2 ( i^ )
INC DUP ,&loop JCN ( i+1^ )
POP BRK ( )
@read-cr ( 0d -> )
POP ;clear-cursor JSR2 #0000 .cur-x STZ2 BRK
@ -642,12 +630,31 @@
POP2 POP2 POP2r ( )
#01 .dirty? STZ JMP2r ( )
( starts with cursor pos )
@delete-n-chars ( n* -> )
DUP2 ADD2 STH2 ( [i=2n*] )
;eol-addr JSR2 STH2kr SUB2 ( limit=eol-i* [i*] )
;cur-addr JSR2 ( limit* start* [i*] )
&loop ( limit* pos* [n*] )
DUP2 STH2kr ADD2 LDA2k ( limit* pos* pos+i* x* [i*] )
#4220 ROT2 STA2 ( limit* pos* x* [i*] ; pos+i<-4220 )
OVR2 STA2 INC2 INC2 ( limit* pos+2* [i*] ; pos<-x )
GTH2k ,&loop JCN ( limit* pos+2* [i*] )
POP2 POP2 POP2r ( )
#01 .dirty? STZ JMP2r ( )
( starts below current line )
@delete-n-lines ( n* -> )
( ;limit-addr JSR2 ;eol-addr JSR2 )
POP2
JMP2r
@scroll
;limit-addr JSR2 STH2
;cells .cols LDZ2 #0002 MUL2 ADD2 STH2
;cells .col-bytes LDZ2 ADD2 STH2
&loop
STH2kr LDA2 #4220 STH2kr STA2
STH2kr .cols LDZ2 #0002 MUL2 SUB2 STA2
STH2kr .col-bytes LDZ2 SUB2 STA2
INC2r INC2r GTH2kr STHr ,&loop JCN
POP2r POP2r
#01 .dirty? STZ
@ -709,7 +716,7 @@
INCr STHkr ,&loop JCN
POPr POP2 POP2 JMP2r
@debug "debug_term.log 00
@debug-log "debug_term.log 00
@scratch $40 &pos $2
@scratch-write ( c^ -> )