MJoergen / C64MEGA65

Commodore 64 core for the MEGA65 based on the MiSTer FPGA C64 core
GNU General Public License v3.0
30 stars 4 forks source link

"Quite a few" .PRG files are not working #144

Open sy2002 opened 5 months ago

sy2002 commented 5 months ago

Here is the problem:

Some details:

Reported by Forum64 user clarkkent: https://www.forum64.de/index.php?thread/125676-c64-core-f%C3%BCr-den-mega65/&postID=2159973#post2159973

And also via dm on Discord:

grafik

Questions for Clark Kent:

cwscws commented 5 months ago

First: Yes, I did everything that it recommended. Usually "Simulate Cartridge" is selected but I also tried the other options without any success. And it's also after a cold start or long-reset. And there is not combination or way to make it work - the PRGs that are not working are not working in any case. It also does not matter in which order I start the PRGs. I also tried several other settings in the menu, no difference.

Here a short list (I tried about 40 - 50 games, these had the problems): ALLEYKAT.PRG (no reaction after RUN) ANTIRIAD.PRG (no reaction after RUN) ARKANOID.PRG (no reaction after RUN) CHOPLIFTER.PRG (no reaction after RUN) HIGHNOON.PRG (RUN -> READY.) MR. DO!.PRG (RUN - > READY.) 1943.PRG (RUN -> stuck in light blue screen) APPLE CIDER SPIDER.PRG (no reaction after RUN) BOMB JACK.PRG (destroyed graphics right after RUN) BURGER TIME.PRG (no reaction after RUN) ENIGMA FORCE.PRG (no reaction after RUN) POOYAN.PRG (no reaction after RUN) PITFALL.PRG (characters on screen like from a decruncher, then no reaction) TRAILBLAZER.PRG (RUN -> READY.) SQUISH.PRG (no reaction after RUN) SPINDIZZY.PRG (RUN -> READY.) ZORRO.PRG (RUN -> READY.) YIE AR KUNG FU.PRG (RUN -> READY.)

All of these games are working perfectly in any C64 emulator. Also no problems on the MiSTer with these games - all are working.

paich64 commented 5 months ago

First: Yes, I did everything that it recommended. Usually "Simulate Cartridge" is selected but I also tried the other options without any success. And it's also after a cold start or long-reset. And there is not combination or way to make it work - the PRGs that are not working are not working in any case. It also does not matter in which order I start the PRGs. I also tried several other settings in the menu, no difference.

Here a short list (I tried about 40 - 50 games, these had the problems): ALLEYKAT.PRG (no reaction after RUN) ANTIRIAD.PRG (no reaction after RUN) ARKANOID.PRG (no reaction after RUN) CHOPLIFTER.PRG (no reaction after RUN) HIGHNOON.PRG (RUN -> READY.) MR. DO!.PRG (RUN - > READY.) 1943.PRG (RUN -> stuck in light blue screen) APPLE CIDER SPIDER.PRG (no reaction after RUN) BOMB JACK.PRG (destroyed graphics right after RUN) BURGER TIME.PRG (no reaction after RUN) ENIGMA FORCE.PRG (no reaction after RUN) POOYAN.PRG (no reaction after RUN) PITFALL.PRG (characters on screen like from a decruncher, then no reaction) TRAILBLAZER.PRG (RUN -> READY.) SQUISH.PRG (no reaction after RUN) SPINDIZZY.PRG (RUN -> READY.) ZORRO.PRG (RUN -> READY.) YIE AR KUNG FU.PRG (RUN -> READY.)

All of these games are working perfectly in any C64 emulator. Also no problems on the MiSTer with these games - all are working.

I confirm the issue on the c64 core with Antiriad, and yes it works on the Mister. It may be related to .prg injection since as a workaround i have put ANTIRIAD.PRG on a blank .d64 (created with DIRMASTER) and the game will properly load in the C64core. So while it's not a fix, it's a workaround for the moment.

paich64 commented 5 months ago

Here is an archive with the .prg which does not work, and the .d64 using the exact same .prg and which is working as expected. antiriad.zip

paich64 commented 5 months ago

@MJoergen @sy2002 Let me know if you want me to test all these releases (as well as the workaround used for Antiriad) and i will.

paich64 commented 5 months ago

@MJoergen @sy2002 @cwscws Here is another version of Antiriad.prg (which obviously comes with some kind of fastloader) and it's running correctly on the C64 core. Antiriad (1986)(Palace Software).zip

paich64 commented 4 months ago

@cwscws Any chance you share here a .zip file containing the .prg files you have identified as "not working on the C64 core" ? I would like to do further tests / investigation being sure i'm working with the exact same .prg you are using. Thanks.

MJoergen commented 4 months ago

@sy2002 I believe the problem is our prg_loader.vhd file.

Here are my findings so far: In the game antiriad.prg I've disassembled the first few lines of code. They are:

0810   78         L0810     SEI
0811   A2 FF                LDX #$FF
0813   9A                   TXS
0814   A0 00                LDY #$00
0816   84 01                STY $01
0818   A2 CC                LDX #$CC
081A   BD 57 08   L081A     LDA $0857,X
081D   9D 33 03             STA $0333,X
0820   B9 1D 09             LDA $091D,Y
0823   99 FF 00             STA $00FF,Y
0826   CA                   DEX
0827   D0 02                BNE L082B
0829   A2 01                LDX #$01
082B   88         L082B     DEY
082C   D0 EC                BNE L081A
082E   C6 2E      L082E     DEC $2E
0830   A5 2E                LDA $2E

What is troubling to me are the last two lines, accessing the zero page variable $2E. In the C64 memory map I find the following:

$002D-$002E : Pointer to beginning of variable area. (End of program plus 1.)

I don't see anywhere in our prg_loader.vhd that we set this variable.

Now, this is not the only variable needed. If you look in the MiSTer file c64.sv lines 740-774 we see a list of zero-page variables that must be set:

$002B-$002C : Pointer to beginning of BASIC area.
$00AC-$00AD : Start address for SAVE to serial bus.
$002D-$002E : Pointer to beginning of variable area. (End of program plus 1.)
$002F-$0030 : Pointer to beginning of array variable area.
$0031-$0032 : Pointer to end of array variable area.
$00AE-$00AF : Load address read from input file and pointer to current byte during LOAD/VERIFY from serial bus.

Note. I actually had the same problem for the VIC20 core, and this is how I implemented it there: https://github.com/MJoergen/VIC20MEGA65/blob/develop/CORE/vhdl/prg_loader.vhd

sy2002 commented 4 months ago

@MJoergen Excellent catch: When implementing the PRG loader back in the days, I did not realize that the C64's Zero Page "registers" need to be set properly - I ignored them. It is quite a miracle that it worked so often :-) Thank you - I will take care.

@paich64 No need to test more PRGs at this moment in time. (And I do have @cwscws 's ZIP which I can share with you to test as soon as I fixed this).

paich64 commented 4 months ago

@MJoergen Excellent catch: When implementing the PRG loader back in the days, I did not realize that the C64's Zero Page "registers" need to be set properly - I ignored them. It is quite a miracle that it worked so often :-) Thank you - I will take care.

@paich64 No need to test more PRGs at this moment in time. (And I do have @cwscws 's ZIP which I can share with you to test as soon as I fixed this).

Actually i just want to check if as a workaround, i can use a compresser to make these .prg working (again as a workaround) as it looks like the issue does not occure with .prg which use a compresser (possibly not using the same ZP). That would be i think an acceptable workaround if this works.

paich64 commented 4 months ago

@MJoergen Excellent catch: When implementing the PRG loader back in the days, I did not realize that the C64's Zero Page "registers" need to be set properly - I ignored them. It is quite a miracle that it worked so often :-) Thank you - I will take care.

@paich64 No need to test more PRGs at this moment in time. (And I do have @cwscws 's ZIP which I can share with you to test as soon as I fixed this).

1) just to be exhaustive : HIGHNOON.PRG does not work in VICE 2) For the 17 other .PRG I have found this alternative if people want to be able to load the non loading .PRG fast :

All the games will start.

cwscws commented 4 months ago

Funnily enough, Q*bert is working now🤣

tonedef71 commented 4 months ago

Just curious. When loading a .PRG file, how does the C64 Core know where in memory the binary contents of a file should be loaded? Is it always the same memory location, or are starting memory locations encoded in the .PRG file itself?

MJoergen commented 4 months ago

Just curious. When loading a .PRG file, how does the C64 Core know where in memory the binary contents of a file should be loaded? Is it always the same memory location, or are starting memory locations encoded in the .PRG file itself?

The first two bytes of the PRG file contains the loading address.