New Keywords
Posted: Fri Dec 29, 2023 4:55 pm
I'm on the lookout for resources about BASIC extensions, specifically of the type that add new BASIC commands. As I see it, I need to intercept three vectors, to
(1) Tokenize the new keywords while parsing a BASIC input line (vector @ $0304)
(2) Detokenize the new keywords during LIST ($0306)
(3) Execute the code associated with each new keyword ($0308)
So, I'm looking at the ROM listing, working on Step 1. I figured I could look for my own keywords first and create my own tokens ($D0 and up), then pass execution along to the original $0304 vector ($C57C). As a quick-and-dirty* proof-of-concept, I redirected $0304 to this.
But after my stuff does its work, the original routine pulls my new "token" out of the input buffer. No SYNTAX ERROR when just entering Z, but the token is gone and the input is shifted away by some code later on in the ROM routine ($C5CB). When I change the token for Z to something like $8A (RUN), I'd hope that Z becomes an alias for RUN. But no.
It seems like I'll need to completely re-implement the tokenization routine, rather than simply patch into it. Is this a correct assessment?
I thought there was a section in one of the Compute! Nth Book of VIC books, but I didn't find it. Maybe I misremember, and I should look at the Books of C64...
Once I get this part figured out, I'll probably use this same topic for the other two steps as I work through my BASIC extension.
________________
* For example, don't care about quotes here
(1) Tokenize the new keywords while parsing a BASIC input line (vector @ $0304)
(2) Detokenize the new keywords during LIST ($0306)
(3) Execute the code associated with each new keyword ($0308)
So, I'm looking at the ROM listing, working on Step 1. I figured I could look for my own keywords first and create my own tokens ($D0 and up), then pass execution along to the original $0304 vector ($C57C). As a quick-and-dirty* proof-of-concept, I redirected $0304 to this.
Code: Select all
ldx $7a
@1 lda $0200,x
cmp #"Z"
bne @2
lda #$d0
sta $0200,x
@2 inx
bpl @1
jmp $c57c
It seems like I'll need to completely re-implement the tokenization routine, rather than simply patch into it. Is this a correct assessment?
I thought there was a section in one of the Compute! Nth Book of VIC books, but I didn't find it. Maybe I misremember, and I should look at the Books of C64...
Once I get this part figured out, I'll probably use this same topic for the other two steps as I work through my BASIC extension.
________________
* For example, don't care about quotes here