Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Princess Maker 2 freezes at end of startup animation #154

Closed
dshadoff opened this issue Aug 8, 2021 · 13 comments
Closed

Princess Maker 2 freezes at end of startup animation #154

dshadoff opened this issue Aug 8, 2021 · 13 comments

Comments

@dshadoff
Copy link
Member

dshadoff commented Aug 8, 2021

This happens:

  1. with or without Arcade Card
  2. with or without MB128
  3. with or without normal CD seek timing.

The log output leading up to the failure is this:

PCECD: Command SAPSP, start = 134069, end = 326787, [1] = 00, [2] = 04, [9] = 80
From sector 134069 to sector 134069:
Time = 33.00 milliseconds
seek time ticks: 2
PCECD: Command SAPSP, start = 134069, end = 326787, [1] = 00, [2] = 04, [9] = 80
PCECD: Command SAPEP, end = 147329, [1] = 02, [2] = 05, [9] = 80
PCECD: Command undefined, [0] = FF, [1] = FF, [2] = FF, [3] = FF, [4] = FF, [5] = FF
PCECD: playback reached the end 147329
From sector 147329 to sector 6611:
Time = 1509.38 milliseconds
seek time ticks: 113
PCECD: Command READ6, lba = 6611, cnt = 64

This appears that it could be caused by a request/response mismatch : The audio plays fine, but the undefined command seems to be related to the issue. As the READ6 request is made, nothing happens after that (black screen).

How to reproduce:

  1. Start game - a screen will appear saying a maximum of 2 saves can be stored ("バックアップメモリに登録できるデータは最大2個です")
  2. Choose middle selection to start from the beginning ("最初から")
  3. Enter some data about the character... I used:
    Family Name -> ア (then おわり)
    Girl's Name -> カ (then おわり)
    1 月 1 日
    11 才
    2 月 1 日
    Blood Type A
  4. Wait for cinema to play until complete. The cinema runs for about 1-2 minutes, and pictures of a king and queen appear at the end.
    -> The screens fades to black, but then all activity stops.

Note: skipping this cinema will avoid the error.

@dshadoff
Copy link
Member Author

dshadoff commented Aug 8, 2021

Based on running in Mednafen, the initial SCSI command is to position the head:

PCECD: Command SAPSP, start = 134069, end = 326787, [1] = 00, [2] = 04, [9] = 80
From sector 134069 to sector 134069:
Time = 33.00 milliseconds
seek time ticks: 2

The next commands define the start and stop of playback (play track 4; stop when track is reached):

PCECD: Command SAPSP, start = 134069, end = 326787, [1] = 00, [2] = 04, [9] = 80
PCECD: Command SAPEP, end = 147329, [1] = 02, [2] = 05, [9] = 80

(these are SCSI commands 0xd8 and 0xd9)

But Mednafen doesn't log a SCSI 0xff.
It does, however, log thousands of "dd 0a 00 . . ." commands, which are intended to read subchannel Q, to determine timing/status of the playback.

@dshadoff
Copy link
Member Author

dshadoff commented Aug 9, 2021

After some investigation, is looks as though the subchannel Q reads were waiting for the audio playback to reach a specific sector - one sector AFTER the Main_MiSTer function stops playing.
Classic off-by-one issue.

@dshadoff
Copy link
Member Author

dshadoff commented Aug 9, 2021

Pull request created (Main_MiSTer #439)

@dshadoff
Copy link
Member Author

dshadoff commented Aug 9, 2021

While this worked for me, others appear to continue to have issues; the ultimate solution may not be as simple as this.

@dshadoff
Copy link
Member Author

Retested after pull request #439 and more recent TIMER fix for CD Hanafuda Bishoujo Fan Club.

Issue is now resolved - when running after a fresh boot.

However, if you use the on-screen display's "RESET" option or reload the game (and re-execute the steps), the game will freeze at that point. The problem also occurs if you reload the core and load the game.
The only solution is to press the "RESET" button to cause a reboot.
Seems to be due to a hardware register not being reset to boot value.

This scenario cannot be reproduced on real hardware because "select+run" soft-reset is suppressed. On original hardware, a power cycle would be required, which would reset both hardware registers and memory.

@dshadoff
Copy link
Member Author

This issue is mostly resolved, but will stay open until we understand why a hard reset is needed.

@dshadoff
Copy link
Member Author

dshadoff commented Oct 2, 2021

One of the most recent changes undid the fix, and it stopped working again...

@dshadoff
Copy link
Member Author

This issue remains open after Pull request #163 (which fixed Battle Royale)... but #163 did not cause the issue to regress (this happened previously).

@srg320
Copy link
Collaborator

srg320 commented Nov 6, 2021

First, TIMER is not active during animation playback, so this is just a coincidence.

The SAPSP/SAPEP command status (at the end of the track) does not have time to be sent before the READ6 command arrives. If PendStatus() is replaced by SendStatus(), the status will be sent immediately (https://github.com/MiSTer-devel/Main_MiSTer/blob/91b93352baa24f23ce19217f96536a7dfe671fc3/support/pcecd/pcecdd.cpp#L455).
It worked for me 3 times out of 3 attempts, but need to test other games.

@dshadoff
Copy link
Member Author

dshadoff commented Nov 6, 2021

Oh, this looks like a good solution.
I didn't understand why some situation were "PendStatus" and others were "SendStatus"... but I knew that a delay could cause problems. This change would only affect when an audio track ends, so it sounds like it probably won't make any new problems.

I will also test this.

@dshadoff
Copy link
Member Author

dshadoff commented Nov 6, 2021

My testing shows this works for Princess Maker 2. I think the only reason to use PendStatus would be to show the core that the CD is busy, but I think it isn't needed at the end of playing an audio track. I think the main use of PendStatus would be while preparing to move/play/read.

I think this fix should be committed, and let users test more widely.

@srg320
Copy link
Collaborator

srg320 commented Nov 7, 2021

@dshadoff
Copy link
Member Author

Most recent release of Main_MiSTer looks fixed. I will close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants