Page 1 of 1

Can we patch BASIC?

Posted: Fri Mar 26, 2021 5:53 pm
by rje

BASIC 7 corrected a bug in the multiply routine, where sometimes the floating point result of a multiply is NOT QUITE zero.

https://www.c64-wiki.com/wiki/Multiply_bug

The patch apparently involves changing two bytes, and only changing two bytes:

 


Quote




BASIC 7.0 avoids the bug by bypassing MLTPLY's zero byte optimization at certain points; it calls MLTPL1 instead. MLTPL1 in the C64 BASIC is located at $BA5E.



The C64 BASIC can be patched to remove the bug, implementing the BASIC 7.0 fix, by changing the following bytes. The bytes at offset $1A40 in the ROM image read as follows:




00001a40: 59ba a565 2059 baa5 6420 59ba a563 2059 Y..e Y..d Y..c Y



To patch the bug, change the first and last instances of $59 to $5E:




00001a40: 5eba a565 2059 baa5 6420 59ba a563 205e Y..e Y..d Y..c



(I popped into the monitor and tried to find this code fragment, but it's not at da40 or ea40 or fa40...  ba5e is of course not necessarily where the x16 stores the multiply routine, so...)

 


Can we patch BASIC?

Posted: Fri Mar 26, 2021 6:44 pm
by Elektron72

This bug was fixed last year when the floating-point routines were optimized:

https://github.com/commanderx16/x16-rom/pull/143


Can we patch BASIC?

Posted: Fri Mar 26, 2021 7:04 pm
by rje

Hooray!  Thank you.

 

...that's BETTER than the patch-fix.  This is a significant performance improvement to Add, Mul, and Sqr, over the original 1970s-era code!

 

 


Can we patch BASIC?

Posted: Fri Mar 26, 2021 7:46 pm
by rje

Okay, next question.  Have we let the MEGA65 team know about this improvement?  CAN we?