neilsf / XC-BASIC

A compiling BASIC dialect for the Commodore-64
https://xc-basic.net/
MIT License
74 stars 15 forks source link

PRG files contain a bad start address #138

Closed johanberntsson closed 3 years ago

johanberntsson commented 3 years ago

The two first bytes of the generated PRG files are not 00 08, telling the C64 that the file should be loaded at $0800 when loading with ,8,1. This is incorrect and should be $0801. This creates problems when trying it on the new MEGA65 emulator xemu-xmega65, which checks these bytes to detect if the PRG file is generated for its C64 or C65 mode. Please change so that $0801 is used.

neilsf commented 3 years ago

Hi. Thanks for your feedback! The problem is that we need to make sure that there's a zero byte at $0800 otherwise a C64 system will refuse to run the program. What does the MEGA65 emulator check exactly? Maybe there's a way to fulfill both system's requirements. Please note however that only the C64 is supported right now. Thanks.

johanberntsson commented 3 years ago

The emulator opens the prg file and checks the first two bytes. If they are 01 and 08 then it is assumed to be a C64 file and started in C64 mode. I solved the problem for myself by generating the asm code, and then using a script to replace ORG $0800 HEX 00 with ORG $0801 before calling dasm to compile the prg. This prg can then be used both on the C64 and MEGA65. I don't think you need the padding byte, at least in the normal case where the C64 will be initiated with a 00 in $0800 at reset/startup. If you create a basic program and save it on a real C64 the file will also start with 01 08.

neilsf commented 3 years ago

Okay, if it is safe to assume there's already a 00 byte at $0800 then I can change the start address and omit the 00 byte.

johanberntsson commented 3 years ago

It is definitely safe. As mentioned, this is how basic files are saved and used on the original hardware.

neilsf commented 3 years ago

Please try the latest release: https://github.com/neilsf/XC-BASIC/releases/tag/v2.3.12

johanberntsson commented 3 years ago

Excellent, the new release solves the problem and everything looks fine. Thanks for your quick response