Rockfall: why does this game crash in 128 mode?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: Rockfall: why does this game crash in 128 mode?

Post by equinox »

ParadigmShifter wrote: Sun Jan 14, 2024 9:59 am First check whether H'L' has that value or not on return to basic, if it does then the proposed fix will not work. Basic should not modify it at any time (I think) so it should still have same value on return.
After returning to BASIC, HL = $5C3B and HL' = $0038. So not the desired value; so this does seem to be the problem.
(The return value in BC doesn't matter as it is unused by the BASIC.)
ParadigmShifter wrote: Sun Jan 14, 2024 9:59 am you could put a breakpoint in the ROM where the USR function exits which looks to be here in the 48K ROM
https://skoolkid.github.io/rom/asm/34B3.html
at address $34BB [...]
the return seems to be at the end of this routine
https://skoolkid.github.io/rom/asm/2D2B.html
at $2D3A
I tried as suggested setting a breakpoint at $23DA or at $34BB. In both cases, the breakpoint is hit immediately when I call the routine (RANDOMIZE USR 60312), before the gameplay actually starts. Not sure what that does for me...
Even if I could catch it on the way out, I don't suppose that knowing I was back in BASIC would tell me anything about the last RET that I came from. Seems I need some kind of trace facility?

Next I'll try AndyC's suggestion of a "wrapper" routine. The site asm80.com seems to be a handy quick one for compiling a few instructions to bytes.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: Rockfall: why does this game crash in 128 mode?

Post by equinox »

AndyC wrote: Sun Jan 14, 2024 10:36 am You probably only need find about 9 bytes somewhere:
[... wrapper code ...]
And then just call that in place of whatever the original USR was doing.
Okay, I tried this.

Code: Select all

1 CLEAR 27135: LOAD "RFC" CODE 27136,38400
2 REM poke wrapper into level 27 map, just for testing
3 RESTORE: FOR n=0 TO 8: READ a: POKE 30208+1024*27+n,a: NEXT n: DATA 205,152,235,217,33,88,39,217,201
4 RANDOMIZE USR 30208+1024*27
When run, it produces some lines and gibberish text on the screen, and stops with "K Invalid colour". Have I made a mistake?
User avatar
bob_fossil
Manic Miner
Posts: 661
Joined: Mon Nov 13, 2017 6:09 pm

Re: Rockfall: why does this game crash in 128 mode?

Post by bob_fossil »

The code that was patched at address 60116 / $ead4 looks like it is setting 'HL to $2758 already.

Code: Select all

ead4: ld sp, $69e8
ead7: nop
ead8: ld hl, $2758
eadb: exx
eadc: ld bc, $ffff
eadf: ret
As was previously said, this works okay in 48k mode. If this was the issue it would return 'B: Integer Out Of Range' there too. I don't know what the problem is but I don't think this is the underlying cause.
User avatar
bob_fossil
Manic Miner
Posts: 661
Joined: Mon Nov 13, 2017 6:09 pm

Re: Rockfall: why does this game crash in 128 mode?

Post by bob_fossil »

@equinox, can you try applying the following POKES to my previously modified RFC code block?

Code: Select all

60116, 237
60117, 123
60118, 96
60119, 238

60318, 96
60319, 238
The RANDOMIZE USR call to 60312 was writing the current stack pointer (SP) into the 128K BASIC system variables which was causing the previous problems. My original fix was to hot wire a fixed correct value for SP but I've now changed this to write SP to a safe area of memory (the routine that detects the Currah speech which is now disabled) and then restores this value back when the game returns control back to BASIC at 60116 - so the correct stack pointer is used rather than a constant. Debugging the crash, the issue was that the stack was off by 2 bytes which meant the code at 60116 was returning to the wrong code in the BASIC ROM which caused the 'B: Integer Out Of Range'. This seems to fix the issue for me.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: Rockfall: why does this game crash in 128 mode?

Post by equinox »

bob_fossil wrote: Sat Jan 20, 2024 10:50 pm @equinox, can you try applying the following POKES to my previously modified RFC code block? [...]
The RANDOMIZE USR call to 60312 was writing the current stack pointer (SP) into the 128K BASIC system variables which was causing the previous problems. My original fix was to hot wire a fixed correct value for SP but I've now changed this to write SP to a safe area of memory (the routine that detects the Currah speech which is now disabled) and then restores this value back when the game returns control back to BASIC at 60116 - so the correct stack pointer is used rather than a constant. Debugging the crash, the issue was that the stack was off by 2 bytes which meant the code at 60116 was returning to the wrong code in the BASIC ROM which caused the 'B: Integer Out Of Range'. This seems to fix the issue for me.
Oooohhhh yeah! Looking good. I did the same statements as before, and this time no problems, just "0 OK" (or as I am henceforth calling it, "Yoko Ono").

Code: Select all

CLEAR 27135: LOAD "pokedJan20" CODE: RANDOMIZE USR 61856: PRINT #1;: RANDOMIZE USR 60312
...
PRINT #1;: RANDOMIZE USR 60312
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: Rockfall: why does this game crash in 128 mode?

Post by equinox »

bob_fossil wrote: Tue Dec 19, 2023 1:15 pm http://www.thefossilrecord.co.uk/wp-con ... all128.zip

This should work when loaded from 128k now. The original loader was one large CODE block loaded from 16384 which stomped over the printer buffer which 128 BASIC uses for paging. I've also applied my patch for the sound effects.
P.S. I have found another issue with this 128 fix — though it doesn't matter for the purposes of my modded version, because I won't be using the demo playback routine.

The title screen calls a routine at 60458, which waits for a keypress, and if no key is pressed, eventually goes into "attract mode", where it plays one of several pre-recorded gameplay demos. The 128 fixed version still does this correctly in 48k mode, but in 128k mode it does something rather strange: the player in the demo does not move, and is instead under the control of you, the human player. So it sort of starts a (semi-) game instead of playing back the demo.
User avatar
bob_fossil
Manic Miner
Posts: 661
Joined: Mon Nov 13, 2017 6:09 pm

Re: Rockfall: why does this game crash in 128 mode?

Post by bob_fossil »

equinox wrote: Sat Feb 10, 2024 10:09 pm P.S. I have found another issue with this 128 fix — though it doesn't matter for the purposes of my modded version, because I won't be using the demo playback routine.

The title screen calls a routine at 60458, which waits for a keypress, and if no key is pressed, eventually goes into "attract mode", where it plays one of several pre-recorded gameplay demos. The 128 fixed version still does this correctly in 48k mode, but in 128k mode it does something rather strange: the player in the demo does not move, and is instead under the control of you, the human player. So it sort of starts a (semi-) game instead of playing back the demo.
The demo state appears to be stored at 23434. When the menu times out and starts the demo mode, it sets this address to 255. At some point 128 BASIC stomps over this, as again this address is in the 128 BASIC system variables area. The game code checks whether this value is 255 to see if it needs to do the demo code - which it isn't so it thinks it's playing a real game. I've moved the demo state address into the unused block for the Currah speech detection which seems to fix the problem.

The following pokes should fix the demo mode:

Code: Select all

59619 95
59620 238

60480 95
60481 238
Post Reply