108 lines
3.7 KiB
Tal
108 lines
3.7 KiB
Tal
|10 @Console [
|
|
&vector $2 &stdin $1 &pad1 $1 &proc-get $1 &host-get $1 &pad2 $1 &type $1
|
|
&stdout $1 &stderr $1 &proc-put $1 &pad3 $1 ¶m $2 &opts $1 &host-put $1
|
|
]
|
|
|
|
|0000
|
|
@word-buf $100
|
|
@word-pos $2
|
|
@spelled-ok $1 ( ; was the last word spelled ok? )
|
|
@resume $2 ( ; if set should have effect ` -- BRK` )
|
|
|
|
|0100 ( -> BRK )
|
|
;on-console-init .Console/vector DEO2 ( ; set up console vector callback )
|
|
init-ispell ( ; set up ispell child process )
|
|
word-reset BRK
|
|
|
|
@init-ispell ( -- )
|
|
LIT "! print
|
|
#31 .Console/opts DEO ( ; child 1: write to stdin, read from stdout )
|
|
;ispell-cmd .Console/param DEO2 ( ; set up `ispell -a` to run )
|
|
#01 .Console/host-put DEO JMP2r ( ; run the command now and return )
|
|
|
|
@on-console-init ( -- BRK )
|
|
( LIT "? print )
|
|
.Console/type DEI #21 EQU ?{ LIT "u print BRK } ( ; 0x21 signals input from child 1 )
|
|
( LIT ". print )
|
|
( .Console/proc-get DEI emit/byte )
|
|
.Console/proc-get DEI #0a EQU ?{ BRK } ( ; skip ispell's one line banner )
|
|
LIT "> print
|
|
;on-console-read .Console/vector DEO2 ( ; finished banner, checker is ready )
|
|
BRK
|
|
|
|
@word-reset ( -> )
|
|
;word-buf ;word-pos STA2 ( ; reset word-pos pointer )
|
|
#00 ;word-buf STA JMP2r ( ; write zero into word buffer )
|
|
|
|
@on-console-read
|
|
LIT ", print
|
|
( .Console/type emit/byte )
|
|
.Console/type DEI #21 EQU ?on-ispell-input
|
|
.Console/type DEI #01 EQU ?on-stdin
|
|
BRK
|
|
|
|
@on-stdin
|
|
.Console/stdin DEI DUP #0a NEQ ?word-append
|
|
POP ;word-buf ;finish !check-spelling
|
|
|
|
@on-ispell-input ( -> BRK )
|
|
LIT "i print
|
|
.Console/proc-get DEI emit/byte
|
|
.Console/proc-get DEI LIT "* EQU ( ; line starting with "*" means ok )
|
|
.spelled-ok STZ ( ; store spelling result )
|
|
LIT "- print LIT "0 .spelled-ok LDZ ADD print
|
|
#00 ,on-ispell-drain/done STR ( ; drain two lines )
|
|
;on-ispell-drain .Console/vector DEO2 ( ; ignore rest of line )
|
|
BRK
|
|
|
|
@word-append ( c^ -> BRK )
|
|
LIT "% print
|
|
DUP print
|
|
;word-pos LDA2 STA ( ; pos<-c )
|
|
;word-pos LDA2 INC2 ;word-pos STA2 ( ; pos<-pos+1 )
|
|
#00 ;word-pos LDA2 STA BRK ( ; pos<-00 )
|
|
|
|
@finish ( -> BRK )
|
|
LIT "f print
|
|
LIT "0 .spelled-ok LDZ ADD println
|
|
LIT "> print
|
|
word-reset BRK
|
|
|
|
@ispell-cmd "ispell 20 "-a 00 ( ; "ispell -a" )
|
|
|
|
@on-ispell-drain ( -- BRK )
|
|
LIT "d print
|
|
.Console/type DEI #21 EQU ?{ BRK } ( ; 0x21 signals input from child 1 )
|
|
.Console/proc-get DEI #0a EQU ?{ BRK } ( ; skip ispell's outupt )
|
|
LIT [ &done $1 ] ?{ ( ; is this the second newline? )
|
|
#01 ,on-ispell-drain/done STR BRK ( ; no, but next one will be. )
|
|
}
|
|
;on-console-read .Console/vector DEO2 ( ; drain finished, checker is ready )
|
|
;resume LDA2 JMP2 ( ; resume whatever we wanted to do after checking )
|
|
|
|
@check-spelling ( word* continue* -- BRK )
|
|
LIT "$ print
|
|
;resume STA2 ( ; write continuation to resume )
|
|
#01 .Console/opts DEO ( ; act on child 1 )
|
|
LIT "< print
|
|
&loop LIT ": print LDAk ( #00 NEQ ) ?{
|
|
POP2
|
|
"> print
|
|
#0a .Console/proc-put DEO BRK
|
|
} ( ; when we read \0 we are done )
|
|
LDAk print
|
|
LDAk .Console/proc-put DEO INC2 !&loop ( ; send byte to child 1 and loop )
|
|
|
|
@print
|
|
.Console/stdout DEO JMP2r
|
|
|
|
@println
|
|
.Console/stdout DEO #0a .Console/stdout DEO JMP2r
|
|
|
|
@emit
|
|
&long SWP2 ,&short JSR
|
|
&short SWP ,&byte JSR
|
|
&byte DUP #04 SFT ,&char JSR
|
|
&char #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
|
|
JMP2r
|