Can we patch BASIC?

All aspects of programming on the Commander X16.
Post Reply
rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Can we patch BASIC?

Post 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...)

 

Elektron72
Posts: 137
Joined: Tue Jun 30, 2020 3:47 pm

Can we patch BASIC?

Post by Elektron72 »


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

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

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Can we patch BASIC?

Post 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!

 

 

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Can we patch BASIC?

Post by rje »


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

Post Reply