fix major stack bug

This commit is contained in:
~d6 2023-01-23 20:54:52 -05:00
parent a58b0f1133
commit 5366902b51
1 changed files with 51 additions and 18 deletions

View File

@ -23,6 +23,7 @@
|10 @Console [ &vect $2 &r $1 &pad $5 &w $1 ] |10 @Console [ &vect $2 &r $1 &pad $5 &w $1 ]
|20 @Screen [ &vect $2 &w $2 &h $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |20 @Screen [ &vect $2 &w $2 &h $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|80 @Controller [ &vect $2 &button $1 &key $1 &fn $1 ] |80 @Controller [ &vect $2 &button $1 &key $1 &fn $1 ]
|a0 @File [ &vect $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|0000 |0000
@tint $1 ( draw mode. 01=regular, 04=inverted ) @tint $1 ( draw mode. 01=regular, 04=inverted )
@ -68,7 +69,10 @@
;on-key .Controller/vect DEO2 ( set up keyboard ) ;on-key .Controller/vect DEO2 ( set up keyboard )
;on-read .Console/vect DEO2 ( set up stdin ) ;on-read .Console/vect DEO2 ( set up stdin )
( return ) ( set up debug log )
;debug .File/name DEO2
#01 .File/append DEO
BRK BRK
@first-addr ( -> ) @first-addr ( -> )
@ -164,8 +168,8 @@
,ctrl? JSR ,on-ctrl-key JCN ,ctrl? JSR ,on-ctrl-key JCN
.Controller/key DEI .Console/w DEO BRK .Controller/key DEI .Console/w DEO BRK
@ctrl? ( -> down? ) .Controller/button DEI #01 AND JMP2r @ctrl? ( -> is-down? ) .Controller/button DEI #01 AND JMP2r
@alt? ( -> down? ) .Controller/button DEI #02 AND JMP2r @alt? ( -> is-down? ) .Controller/button DEI #02 AND JMP2r
( alt-XYZ emits ESC and then emits XYZ ) ( alt-XYZ emits ESC and then emits XYZ )
@on-alt-key ( -> ) @on-alt-key ( -> )
@ -192,16 +196,30 @@
DUP LIT "9 GTH ;end-arg JCN2 DUP LIT "9 GTH ;end-arg JCN2
;add-to-arg JMP2 ;add-to-arg JMP2
@debug-seq ( c^ -> )
;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^ -> ) @end-arg ( c^ -> )
;on-read .Console/vect DEO2 ;on-read .Console/vect DEO2
DUP LIT "h EQU ;exec-noop JCN2 ( enable line wrap ) DUP ,debug-seq JSR
DUP LIT "l EQU ;exec-noop JCN2 ( disable line wrap ) DUP LIT "h EQU ;exec-noop JCN2 ( enable line wrap )
DUP LIT "m EQU ;exec-noop JCN2 ( set attr ) DUP LIT "l EQU ;exec-noop JCN2 ( disable line wrap )
DUP LIT "n EQU ;exec-status JCN2 ( get status ) DUP LIT "m EQU ;exec-noop JCN2 ( set attr )
DUP LIT "H EQU ;exec-move JCN2 ( move cursor ) DUP LIT "n EQU ;exec-status JCN2 ( get status )
DUP LIT "A EQU ;exec-up JCN2 ( up ) DUP LIT "H EQU ;exec-move JCN2 ( move cursor )
DUP LIT "B EQU ;exec-down JCN2 ( down ) DUP LIT "A EQU ;exec-up JCN2 ( up )
DUP LIT "C EQU ;exec-forward JCN2 ( forward ) DUP LIT "B EQU ;exec-down JCN2 ( down )
DUP LIT "C EQU ;exec-forward JCN2 ( forward )
DUP LIT "D EQU ;exec-back JCN2 ( back ) DUP LIT "D EQU ;exec-back JCN2 ( back )
DUP LIT "J EQU ;exec-erase-screen JCN2 ( erase screen ) DUP LIT "J EQU ;exec-erase-screen JCN2 ( erase screen )
DUP LIT "K EQU ;exec-erase-line JCN2 ( erase line ) DUP LIT "K EQU ;exec-erase-line JCN2 ( erase line )
@ -273,8 +291,20 @@
#0001 ;read-arg-2 JSR2 #0001 SUB2 ( col ) #0001 ;read-arg-2 JSR2 #0001 SUB2 ( col )
;goto JSR2 BRK ;goto JSR2 BRK
@debug-esc ( c^ -> )
;scratch STH2
LIT "1 STH2kr STA INC2r
LIT "b STH2kr STA INC2r
#20 STH2kr STA INC2r
STH2kr STA INC2r
#0a STH2r STA
#0005 .File/len DEO2
;scratch .File/w DEO2
JMP2r
@on-read-esc ( -> ) @on-read-esc ( -> )
.Console/r DEI LIT "[ EQU ;start-seq JCN2 .Console/r DEI LIT "[ EQU ;start-seq JCN2
.Console/r DEI ,debug-esc JSR
;on-read .Console/vect DEO2 ;on-read .Console/vect DEO2
;on-read JMP2 ;on-read JMP2
@ -287,7 +317,7 @@
.Console/r DEI .Console/r DEI
DUP ,&ok JCN POP BRK DUP ,&ok JCN POP BRK
&ok #41 .tint STZ &ok #41 .tint STZ
;read JSR2 BRK ;read JMP2
@read ( c^ -> ) @read ( c^ -> )
DUP #20 LTH ;read-ctrl JCN2 DUP #20 LTH ;read-ctrl JCN2
@ -303,7 +333,7 @@
DUP #1b EQU ;read-esc JCN2 DUP #1b EQU ;read-esc JCN2
@read-bel ( 07 -> ) @read-bel ( 07 -> )
POP JMP2r ( TODO: flash terminal ) POP BRK ( TODO: flash terminal )
@read-bs ( 08 -> ) @read-bs ( 08 -> )
POP POP
@ -316,7 +346,7 @@
POP ;on-read-esc .Console/vect DEO2 BRK POP ;on-read-esc .Console/vect DEO2 BRK
@read-del ( 7f -> ) @read-del ( 7f -> )
POP JMP2r POP BRK
( @read-tab POP JMP2r ) ( @read-tab POP JMP2r )
@read-tab @read-tab
@ -330,19 +360,19 @@
POP JMP2r POP JMP2r
@read-cr ( 0d -> ) @read-cr ( 0d -> )
POP ;hide-cursor JSR2 #0000 .cur-x STZ2 JMP2r POP ;hide-cursor JSR2 #0000 .cur-x STZ2 BRK
@at-max-y ( -> true? ) @at-max-y ( -> true? )
.cur-y LDZ2 .max-y LDZ2 EQU2 JMP2r .cur-y LDZ2 .max-y LDZ2 EQU2 JMP2r
@read-nl ( 0a -> ) @read-nl ( 0a -> )
POP ;hide-cursor JSR2 POP ;hide-cursor JSR2
,at-max-y JSR ;scroll JCN2 ;down JMP2 ,at-max-y JSR ;scroll JCN2 ;down JSR2 BRK
@read-printable ( c -> ) @read-printable ( c -> )
DUP ;cursor-addr JSR2 STA DUP ;cursor-addr JSR2 STA
;draw-tile JSR2 ;draw-tile JSR2
;forward JMP2 ;forward JSR2 BRK
@goto ( y* x* -> ) @goto ( y* x* -> )
;hide-cursor JSR2 ;hide-cursor JSR2
@ -389,7 +419,7 @@
INC2r GTH2kr STHr ,&loop JCN INC2r GTH2kr STHr ,&loop JCN
POP2r POP2r POP2r POP2r
#01 .dirty? STZ #01 .dirty? STZ
;show-cursor JMP2 ;show-cursor JSR2 BRK
@cursor-addr ( -> addr* ) @cursor-addr ( -> addr* )
.cur-y LDZ2 .cols LDZ2 MUL2 .cur-y LDZ2 .cols LDZ2 MUL2
@ -447,6 +477,9 @@
INCr STHkr ,&loop JCN INCr STHkr ,&loop JCN
POPr POP2 POP2 JMP2r POPr POP2 POP2 JMP2r
@debug "debug_term.log 00
@scratch $40
( store up to 8 arguments for control sequences ) ( store up to 8 arguments for control sequences )
@args $10 &pos $2 @args $10 &pos $2