New instructions PEEK and POKE to call outside routines.

To use PEEK and POKE initialize uBASIC from your program with
ubasic_init_peek_poke(program, &peek, &poke) where "peek" is a
function peek(VARIABLE_TYPE addr) that returns VARIABLE_TYPE
and "poke" is a procedure void poke(VARIABLE_TYPE addr,
VARIABLE_TYPE value).

Use "PEEK addr, var" to set the value of the variable var to the
result of calling peek(addr). Use "POKE addr, value" to call
poke(addr, value);

The argument name "addr" is arbitrary; it doesn't mean you should
necessarily use it to pass your routines a memory address.
This commit is contained in:
Danyil Bohdan 2013-12-23 18:46:25 +02:00
parent f9ea3c6e6b
commit 93bb242eb0
6 changed files with 85 additions and 2 deletions

View file

@ -66,6 +66,8 @@ static const struct keyword_token keywords[] = {
{"return", TOKENIZER_RETURN},
{"call", TOKENIZER_CALL},
{"rem", TOKENIZER_REM},
{"peek", TOKENIZER_PEEK},
{"poke", TOKENIZER_POKE},
{"end", TOKENIZER_END},
{NULL, TOKENIZER_ERROR}
};
@ -96,6 +98,8 @@ singlechar(void)
return TOKENIZER_MOD;
} else if(*ptr == '(') {
return TOKENIZER_LEFTPAREN;
} else if(*ptr == '#') {
return TOKENIZER_HASH;
} else if(*ptr == ')') {
return TOKENIZER_RIGHTPAREN;
} else if(*ptr == '<') {