Here's what I'm trying to do. For the Crude 65816 Emulator, I'm trying to create a, well, crude I/O handler so that if a byte is stored to a "special" address, it doesn't go to memory, but Something Else (TM) happens. (Actually, at the moment that would only be putchr, but we have to start somewhere.) My current idea is to create a zero-terminated array with the special 65816 addresses and associated executive tokens (xt) of the handlers. Like:
Code: Select all
create store-addresses
00fff00 , ' putchar-6522-#1 ,
00fff0f , ' putchar-6522-#2 ,
0 , \ marks end of table Code: Select all
: special-store? ( target-65addr -- 0|xt)
get first 65addr from table
BEGIN
65addr-from-table <>0 WHILE
target-65addr 65addr-from-table = IF get-associated-xt BREAK THEN
get next 65addr-from-table
REPEAT ; Plan B would to use a counted ?DO/LOOP structure, which would be annoying because I'd have to keep track of how many elements there are in the table (but would take care of the special case problem). Plan C would be to execute the xt from inside the loop, and then just continue through the rest of the table in case there are two or more handlers associated with that address; but that seems silly. Of course, as long as we're talking about only two or such addresses, IF ELSE THEN construct would do (plan D), but that's not really expandable.
So by now I'm wondering if this might be the completely wrong way to solve this problem? Thanks!