1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 13:48:06 +11:00
collapseos/blk/291
Virgil Dupras 31a58d00f1 z80: fix tricky memory initialization issue
Among random "better safe than sorry" changes, the real fix is in
changing "4" for "5" above _find declaration. This off-by-one error
had that word, which is the root word in z80, have a 0x01 prev field
instead of a 0x00 one.

When all memory was initialized to zero, it didn't matter, we ended
up hitting 0 prev and considered ourselves properly at the end of
dict.

When memory wasn't initialized, however, we would end up jumping at
all kinds of places, leading to random behavior.
2020-08-15 16:37:58 -04:00

17 lines
686 B
Plaintext

( Native words )
H@ 5 + XCURRENT ! ( make next CODE have 0 prev field )
CODE _find ( cur w -- a f )
HL POP, ( w ) DE POP, ( cur ) chkPS,
HL PUSH, ( --> lvl 1 )
( First, figure out string len )
A (HL) LDrr, A ORr,
( special case. zero len? we never find anything. )
IFZ, PUSH0, JPNEXT, THEN,
BC PUSH, ( --> lvl 2, protect )
( Let's do something weird: We'll hold HL by the *tail*.
Because of our dict structure and because we know our
lengths, it's easier to compare starting from the end. )
C A LDrr, B 0 LDri, ( C holds our length )
BC ADDHLd, HL INCd, ( HL points to after-last-char )
( cont . )