How to add a new command to EhBASIC.
As this is a primary command, it can start a statement, first insert a new entry into the list of primary command tokens. It doesn't particularly matter where in the list.
E.g.
Code:
TK_DOKE = TK_POKE+1 ; DOKE token
TK_CALL = TK_DOKE+1 ; CALL token
TK_DO = TK_CALL+1 ; DO token
TK_LOOP = TK_DO+1 ; LOOP token
.. becomes ..
Code:
TK_DOKE = TK_POKE+1 ; DOKE token
TK_CALL = TK_DOKE+1 ; CALL token
TK_PLOT = TK_CALL+1 ; PLOT token new command entry
TK_DO = TK_PLOT+1 ; DO token modified entry
TK_LOOP = TK_DO+1 ; LOOP token
Next put a corresponding new entry in the command vector table that starts at LAB_CTBL. This must be in the same relative location as the token value.
E.g.
Code:
.word LAB_POKE-1 ; POKE
.word LAB_DOKE-1 ; DOKE
.word LAB_CALL-1 ; CALL
.word LAB_DO-1 ; DO
.. becomes ..
Code:
.word LAB_POKE-1 ; POKE
.word LAB_DOKE-1 ; DOKE
.word LAB_PLOT-1 ; PLOT new command
.word LAB_CALL-1 ; CALL
.word LAB_DO-1 ; DO
Now add an entry in the keyword tables.
E.g.
Code:
LBB_PI
.byte "I",TK_PI ; PI
LBB_POKE
.byte "OKE",TK_POKE ; POKE
.. becomes ..
Code:
LBB_PI
.byte "I",TK_PI ; PI
LBB_PLOT
.byte "LOT",TK_PLOT ; PLOT new command keyword
LBB_POKE
.byte "OKE",TK_POKE ; POKE
In this case there are already keywords that start with "P" so it's just a case of adding this one entry but if you were adding a keyword that starts with a so far unused letter then you also need to add entries in the first character table at TAB_1STC and in the character pointers table at TAB_CHRT and make a new character table for your entry.
Next you need to add an entry in the LIST decode table, this again must be in the same relative location as the token value.
E.g.
Code:
.byte 4,'P'
.word LBB_POKE ; POKE
.byte 4,'D'
.word LBB_DOKE ; DOKE
.byte 4,'C'
.word LBB_CALL ; CALL
.byte 2,'D'
.word LBB_DO ; DO
.. becomes ..
Code:
.byte 4,'P'
.word LBB_POKE ; POKE
.byte 4,'D'
.word LBB_DOKE ; DOKE
.byte 4,'P' ; new keyword length and first character
.word LBB_PLOT ; PLOT new keyword pointer
.byte 4,'C'
.word LBB_CALL ; CALL
.byte 2,'D'
.word LBB_DO ; DO
The last thing to add is the code for the new command which should be the same as the code you used for the CALL version but without the first scan for the comma. So instead of say using LAB_SCGB, scan for "," and get byte, you could use LAB_GTBY, get byte parameter, to get the X value.
.. and that should do it.
Quote:
Longer variable names would be nice but probably difficult to change.
Not that difficult but wastefull of space and speed, unless you want variable length names and then it does get more awkward. The first two significant characters give you over 3000 different variables of each type and you can append any number of other characters of your choice as long as you avoid keywords.
Lee.