lgblgblgb / xemu

Emulations (running on Linux/Unix/Windows/macOS, utilizing SDL2) of some - mainly - 8 bit machines, including the Commodore LCD, Commodore 65, and the MEGA65 as well.
https://github.com/lgblgblgb/xemu/wiki
GNU General Public License v2.0
201 stars 31 forks source link

MEGA65/BASIC 10 - Modifying last character of a string using MID$ causes illegal quantity error #386

Closed PGNm65 closed 1 year ago

PGNm65 commented 1 year ago

Describe the bug Modifying the last character of a text string using MID$ to change to another character causes an illegal quantity error. Actual M65 machine does not cause an error, only XEMU does...

Used version of the project MEGA65 20230201214849 ROM V920377

To Reproduce Steps to reproduce the behavior. As steps as required, do not try to squeeze everything into one step.

  1. ...10 A$="0123456789"
  2. ...20 IF MID$(A$,10,1)="9" THEN MID$(A$,10,1)="0"

Expected behavior In above example should simply change the 10th character (last character) of the text string to a 0.

Screenshots N/A

Computer/Device (please complete the following information):

Additional context This will work fine on any modern basic with MID$ and on the actual M65 machine.

lgblgblgb commented 1 year ago

Thanks for the report. Are you sure you use the very same ROM with both of MEGA65 and Xemu? Xemu just runs the ROM, the ROM does everything (ie, interpreting BASIC statements, execution etc) as with MEGA65. I would guess it's a ROM bug, but then MEGA65 with the same ROM should be also affected.

Surely, Xemu still can have a bug like bad CPU emulation or anything which causes the executed ROM code to misbehave however that's unlikely since it would be effect (probably) many other things as well. But as I've said, it's it for sure not impossible to be triggered by some obscure hardware level emulation bug in Xemu.

As far as I can see, a more simple example:

A$="0123456789":MID$(A$,10,1)="W":PRINTA$

Result: ?ILLEGAL QUANTITY ERROR

Replacing 10 with smaller numbers seems to work, so indeed, it's seem to be an "off by one" error to check if MID$'s parameter is within the length of the string. I'm still not sure how it can be caused by Xemu, if it's not there as a bug on a real MEGA65 with the very same ROM. Unfortunately I don't have MEGA65 with me currently to check it.

@dansanderson Do you have any opinion on this from the ROM side? If it's really not a ROM bug, I am surprised what kind of MEGA65 hardware emulation bug can effect only this, but not so much any (known ...) other things. Maybe it uses Q opcodes, and there is a bug there? Just guessing.

dansanderson commented 1 year ago

I get consistent incorrect behavior with ROM 920385 in both Xemu and MEGA65. I have filed this here: https://github.com/MEGA65/mega65-rom-public/issues/68

You can resolve this issue, it's not specific to Xemu.

lgblgblgb commented 1 year ago

Being a ROM bug, so I close this now. @dansanderson Thanks for the check!!