Login
Back to forumSee the full topicGo to last reply

Posted By

Csabo
on 2025-06-24
08:31:50
 Re: YAPE 1.2.6!

Nice find, Hop, I don't think I've seen this mentioned anywhere before. (Also doesn't have much to do with YAPE.)

Nevertheless, BASIC "bugs" are always fascinating happy This indeed appears to be an oversight in the code for the GRAPHIC statement. After checking the BASIC sources, it looks like the authors did not account for 32K machines. Or, perhaps to put it another way, they saved two bytes on a check, which causes this issue.

Let's dive in!

The allocation occurs here:
. C641  A5 38    LDA $38     ;is this a 16k or a 64k ted system?
. C643 C9 40 CMP #$40
. C645 B0 34 BCS $C67B ;branch if 64k ted


$38 (or memsiz+1 in the original sources) will contain these values, which is the high byte of the end of usable RAM:
C16/C116 $3F
232 $7F
Plus/4, or 64K expanded machines $FD

So the code checks if this value is less than $40, and if so, the allocation and movement of BASIC occurs. So far so good, this works on 32K as well.

Deallocation is here:
. C741  A5 38    LDA $38    ;is this a 16k or a 64k ted system?
. C743 30 24 BMI $C769 ;branch if 64k


BMI jumps on negative, so... $3F will NOT jump, $FD WILL jump... but $7F (which is what we have on 32K systems) will also not jump! That's the "bug". Basically (no pun intended) they are doing the checks differently.

This could be fixed two ways: the deallocation check could also compare to #$40 instead, and branch with a BCS - this would need 2 more bytes. This fix would ensure that the allocation/deallocation occurs on 32K systems. Or, the first check could also use the negative bit instead, which would save two bytes - and the allocation/deallocation would NOT occur on 32K systems.

But of course we can't change the ROM, so if the very, very unlikely event that someone is coding a BASIC program and want to ensure it works correctly on 32K systems... The fix would be to PEEK the value of $38 before GRAPHIC CLR. If it contains $7F, POKE $80 there temporarily. Issue the GRAPHIC CLR. Restore the original value.

Whew happy I hope this was interesting for someone happy
bszggg1
Lavina1


Back to top


Copyright © Plus/4 World Team, 2001-2025. Support Plus/4 World on Patreon