diff --git a/src/segacd_python/cdd.py b/src/segacd_python/cdd.py index a447af9..4356f4a 100644 --- a/src/segacd_python/cdd.py +++ b/src/segacd_python/cdd.py @@ -194,6 +194,7 @@ class CDD: self.seek_view = SHOWN self.report = BUSY self.pending_report: int | None = None + self.pending_delay = 0 # busy exchanges before the pending report is shown self.report_track = 0 self.new_command: list[int] | None = None self.music = False @@ -478,13 +479,23 @@ class CDD: if code == 0x0: return if code == 0x1: - self.state = READY if not self.ready_in else STOPPED + # Stop shows state 0 afterwards, not 9 (Sonic CD's boot-log.txt line 318: "0F" + # for 13 exchanges, then "04..." when the BIOS asks; the 13 busy exchanges + # are not modelled). FITTED: replay 3,038 -> 3,054 of 11,256. + self.state = STOPPED self.music = False self.report = BUSY return if code == 0x2: self.pending_report = command[3] self.report_track = command[4] * 10 + command[5] + # A track's start (report 5) asked in state 9 is answered after two busy + # exchanges: 112 of the 121 such requests in KRIKzz's logs are answered in + # the third exchange after the command. FITTED: replay 3,004 -> 3,038. Not + # modelled: report 5 asked while playing or paused stops the drive (state 9) + # and answers after about 20 (boot-log.txt line 251; KRIKzz's notes: + # "this one results stop playing", DOC). + self.pending_delay = 2 if command[3] == 5 and self.state == READY else 0 return if code in (0x3, 0x4): minute = command[2] * 10 + command[3] @@ -542,6 +553,9 @@ class CDD: # next reported one (Sonic CD's boot: each of the BIOS's requests during a # seek is answered at the next report, boot-log.txt lines 190-219). FITTED. report = BUSY + elif self.pending_report is not None and self.pending_delay: + self.pending_delay -= 1 + report = BUSY elif self.pending_report is not None: report = self.pending_report self.pending_report = None @@ -554,7 +568,9 @@ class CDD: if report == 5: status[8] = self.report_track % 10 else: - blind = state == SEEKING and self.seek_view == BLIND + # The flags nibble reads 1 (no data) during a seek's start and while stopped + # ("0F.000000.1F", boot-log.txt line 319). FITTED. + blind = state == SEEKING and self.seek_view == BLIND or state == STOPPED data = not not_ready and not blind and self._is_data(self.lba) status[8] = (4 if data else 0) | (0 if state == PLAYING else 1) status[9] = ~sum(status[:9]) & 0xF