cdrom: get rid of cdrPlayInterrupt
authornotaz <notasas@gmail.com>
Fri, 2 Sep 2022 20:13:44 +0000 (23:13 +0300)
committernotaz <notasas@gmail.com>
Fri, 2 Sep 2022 23:13:01 +0000 (02:13 +0300)
unify with cdrReadInterrupt and name it cdrPlaySeekReadInterrupt

... althoug these are not actually interrupts, more like events,
but keep this weird PCSX's naming convention

libpcsxcore/cdrom.c
libpcsxcore/cdrom.h
libpcsxcore/new_dynarec/emu_if.c
libpcsxcore/r3000a.c
libpcsxcore/r3000a.h

index 963405c..50c3d13 100644 (file)
@@ -241,8 +241,8 @@ static void sec2msf(unsigned int s, u8 *msf) {
        new_dyna_set_event(PSXINT_CDR, eCycle); \
 }
 
-// cdrReadInterrupt
-#define CDREAD_INT(eCycle) { \
+// cdrPlaySeekReadInterrupt
+#define CDRPLAYSEEKREAD_INT(eCycle) { \
        psxRegs.interrupt |= (1 << PSXINT_CDREAD); \
        psxRegs.intCycle[PSXINT_CDREAD].cycle = eCycle; \
        psxRegs.intCycle[PSXINT_CDREAD].sCycle = psxRegs.cycle; \
@@ -257,14 +257,6 @@ static void sec2msf(unsigned int s, u8 *msf) {
        new_dyna_set_event(PSXINT_CDRLID, eCycle); \
 }
 
-// cdrPlayInterrupt
-#define CDRSEEKPLAY_INT(eCycle) { \
-       psxRegs.interrupt |= (1 << PSXINT_CDRPLAY); \
-       psxRegs.intCycle[PSXINT_CDRPLAY].cycle = eCycle; \
-       psxRegs.intCycle[PSXINT_CDRPLAY].sCycle = psxRegs.cycle; \
-       new_dyna_set_event(PSXINT_CDRPLAY, eCycle); \
-}
-
 #define StopReading() { \
        cdr.Reading = 0; \
        psxRegs.interrupt &= ~(1 << PSXINT_CDREAD); \
@@ -307,7 +299,7 @@ static void setIrq(int log_cmd)
 
 // timing used in this function was taken from tests on real hardware
 // (yes it's slow, but you probably don't want to modify it)
-void cdrLidSeekInterrupt()
+void cdrLidSeekInterrupt(void)
 {
        switch (cdr.DriveState) {
        default:
@@ -584,18 +576,24 @@ static int cdrSeekTime(unsigned char *target)
        return seekTime;
 }
 
-// also handles seek
-void cdrPlayInterrupt()
+static void cdrReadInterrupt(void);
+
+void cdrPlaySeekReadInterrupt(void)
 {
-       if (cdr.StatP & STATUS_SEEK) {
+       if (cdr.Reading) {
+               cdrReadInterrupt();
+               return;
+       }
+
+       if (!cdr.Play && (cdr.StatP & STATUS_SEEK)) {
                if (cdr.Stat) {
                        CDR_LOG_I("cdrom: seek stat hack\n");
-                       CDRSEEKPLAY_INT(0x1000);
+                       CDRPLAYSEEKREAD_INT(0x1000);
                        return;
                }
                SetResultSize(1);
                cdr.StatP |= STATUS_ROTATING;
-               SetPlaySeekRead(cdr.StatP, cdr.Play ? STATUS_PLAY : 0);
+               SetPlaySeekRead(cdr.StatP, 0);
                cdr.Result[0] = cdr.StatP;
                if (cdr.Irq == 0) {
                        cdr.Stat = Complete;
@@ -605,6 +603,7 @@ void cdrPlayInterrupt()
                Find_CurTrack(cdr.SetSectorPlay);
                ReadTrack(cdr.SetSectorPlay);
                cdr.TrackChanged = FALSE;
+               return;
        }
 
        if (!cdr.Play) return;
@@ -612,6 +611,7 @@ void cdrPlayInterrupt()
        CDR_LOG( "CDDA - %d:%d:%d\n",
                cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2] );
 
+       SetPlaySeekRead(cdr.StatP, STATUS_PLAY);
        if (memcmp(cdr.SetSectorPlay, cdr.SetSectorEnd, 3) == 0) {
                StopCdda();
                SetPlaySeekRead(cdr.StatP, 0);
@@ -640,13 +640,13 @@ void cdrPlayInterrupt()
                }
        }
 
-       CDRSEEKPLAY_INT(cdReadTime);
+       CDRPLAYSEEKREAD_INT(cdReadTime);
 
        // update for CdlGetlocP/autopause
        generate_subq(cdr.SetSectorPlay);
 }
 
-void cdrInterrupt() {
+void cdrInterrupt(void) {
        u16 Irq = cdr.Irq;
        int no_busy_error = 0;
        int start_rotating = 0;
@@ -765,7 +765,7 @@ void cdrInterrupt() {
                        // BIOS player - set flag again
                        cdr.Play = TRUE;
 
-                       CDRSEEKPLAY_INT(cdReadTime + seekTime);
+                       CDRPLAYSEEKREAD_INT(cdReadTime + seekTime);
                        start_rotating = 1;
                        break;
 
@@ -973,7 +973,7 @@ void cdrInterrupt() {
                        Rockman X5 = 0.5-4x
                        - fix capcom logo
                        */
-                       CDRSEEKPLAY_INT(cdReadTime + seekTime);
+                       CDRPLAYSEEKREAD_INT(cdReadTime + seekTime);
                        start_rotating = 1;
                        break;
 
@@ -1104,7 +1104,7 @@ void cdrInterrupt() {
                                Gameblabla additional notes :
                                This still needs the "+ seekTime" that PCSX Redux doesn't have for the Driver "retry" mission error.
                        */
-                       CDREAD_INT(((cdr.Mode & 0x80) ? (cdReadTime) : cdReadTime * 2) + seekTime);
+                       CDRPLAYSEEKREAD_INT(((cdr.Mode & 0x80) ? (cdReadTime) : cdReadTime * 2) + seekTime);
 
                        SetPlaySeekRead(cdr.StatP, STATUS_SEEK);
                        start_rotating = 1;
@@ -1194,15 +1194,13 @@ void cdrAttenuate(s16 *buf, int samples, int stereo)
        }
 }
 
-void cdrReadInterrupt() {
+static void cdrReadInterrupt(void)
+{
        u8 *buf;
 
-       if (!cdr.Reading)
-               return;
-
        if (cdr.Irq || cdr.Stat) {
                CDR_LOG_I("cdrom: read stat hack %02x %x\n", cdr.Irq, cdr.Stat);
-               CDREAD_INT(2048);
+               CDRPLAYSEEKREAD_INT(2048);
                return;
        }
 
@@ -1222,7 +1220,7 @@ void cdrReadInterrupt() {
                memset(cdr.Transfer, 0, DATA_SIZE);
                cdr.Stat = DiskError;
                cdr.Result[0] |= STATUS_ERROR;
-               CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime);
+               setIrq(0x205);
                return;
        }
 
@@ -1269,7 +1267,7 @@ void cdrReadInterrupt() {
 
        cdr.Readed = 0;
 
-       CDREAD_INT((cdr.Mode & MODE_SPEED) ? (cdReadTime / 2) : cdReadTime);
+       CDRPLAYSEEKREAD_INT((cdr.Mode & MODE_SPEED) ? (cdReadTime / 2) : cdReadTime);
 
        /*
        Croc 2: $40 - only FORM1 (*)
@@ -1545,7 +1543,7 @@ void psxDma3(u32 madr, u32 bcr, u32 chcr) {
        DMA_INTERRUPT(3);
 }
 
-void cdrDmaInterrupt()
+void cdrDmaInterrupt(void)
 {
        if (HW_DMA3_CHCR & SWAP32(0x01000000))
        {
@@ -1621,6 +1619,8 @@ int cdrFreeze(void *f, int Mode) {
                        Find_CurTrack(cdr.SetSectorPlay);
                        if (!Config.Cdda)
                                CDR_play(cdr.SetSectorPlay);
+                       if (psxRegs.interrupt & (1 << PSXINT_CDRPLAY_OLD))
+                               CDRPLAYSEEKREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime);
                }
 
                if ((cdr.freeze_ver & 0xffffff00) != 0x63647200) {
@@ -1641,7 +1641,7 @@ int cdrFreeze(void *f, int Mode) {
        return 0;
 }
 
-void LidInterrupt() {
+void LidInterrupt(void) {
        getCdInfo();
        cdrLidSeekInterrupt();
 }
index e12c39a..0cd6c5f 100644 (file)
@@ -48,13 +48,11 @@ extern "C" {
 void cdrReset();
 void cdrAttenuate(s16 *buf, int samples, int stereo);
 
-void cdrInterrupt();
-void cdrReadInterrupt();
-void cdrRepplayInterrupt();
-void cdrLidSeekInterrupt();
-void cdrPlayInterrupt();
-void cdrDmaInterrupt();
-void LidInterrupt();
+void cdrInterrupt(void);
+void cdrPlaySeekReadInterrupt(void);
+void cdrLidSeekInterrupt(void);
+void cdrDmaInterrupt(void);
+void LidInterrupt(void);
 unsigned char cdrRead0(void);
 unsigned char cdrRead1(void);
 unsigned char cdrRead2(void);
index e221a79..036f1cd 100644 (file)
@@ -46,12 +46,16 @@ static void schedule_timeslice(void)
        next_interupt = c + min;
 }
 
+static void unusedInterrupt()
+{
+}
+
 typedef void (irq_func)();
 
 static irq_func * const irq_funcs[] = {
        [PSXINT_SIO]    = sioInterrupt,
        [PSXINT_CDR]    = cdrInterrupt,
-       [PSXINT_CDREAD] = cdrReadInterrupt,
+       [PSXINT_CDREAD] = cdrPlaySeekReadInterrupt,
        [PSXINT_GPUDMA] = gpuInterrupt,
        [PSXINT_MDECOUTDMA] = mdec1Interrupt,
        [PSXINT_SPUDMA] = spuInterrupt,
@@ -59,7 +63,7 @@ static irq_func * const irq_funcs[] = {
        [PSXINT_GPUOTCDMA] = gpuotcInterrupt,
        [PSXINT_CDRDMA] = cdrDmaInterrupt,
        [PSXINT_CDRLID] = cdrLidSeekInterrupt,
-       [PSXINT_CDRPLAY] = cdrPlayInterrupt,
+       [PSXINT_CDRPLAY_OLD] = unusedInterrupt,
        [PSXINT_SPU_UPDATE] = spuUpdate,
        [PSXINT_RCNT] = psxRcntUpdate,
 };
index 57ae830..8eb2618 100644 (file)
@@ -140,7 +140,7 @@ void psxBranchTest() {
                if (psxRegs.interrupt & (1 << PSXINT_CDREAD)) { // cdr read
                        if ((psxRegs.cycle - psxRegs.intCycle[PSXINT_CDREAD].sCycle) >= psxRegs.intCycle[PSXINT_CDREAD].cycle) {
                                psxRegs.interrupt &= ~(1 << PSXINT_CDREAD);
-                               cdrReadInterrupt();
+                               cdrPlaySeekReadInterrupt();
                        }
                }
                if (psxRegs.interrupt & (1 << PSXINT_GPUDMA)) { // gpu dma
@@ -179,12 +179,6 @@ void psxBranchTest() {
                                cdrDmaInterrupt();
                        }
                }
-               if (psxRegs.interrupt & (1 << PSXINT_CDRPLAY)) { // cdr play timing
-                       if ((psxRegs.cycle - psxRegs.intCycle[PSXINT_CDRPLAY].sCycle) >= psxRegs.intCycle[PSXINT_CDRPLAY].cycle) {
-                               psxRegs.interrupt &= ~(1 << PSXINT_CDRPLAY);
-                               cdrPlayInterrupt();
-                       }
-               }
                if (psxRegs.interrupt & (1 << PSXINT_CDRLID)) { // cdr lid states
                        if ((psxRegs.cycle - psxRegs.intCycle[PSXINT_CDRLID].sCycle) >= psxRegs.intCycle[PSXINT_CDRLID].cycle) {
                                psxRegs.interrupt &= ~(1 << PSXINT_CDRLID);
index b8d4d79..8bac391 100644 (file)
@@ -164,7 +164,7 @@ enum {
        PSXINT_NEWDRC_CHECK,
        PSXINT_RCNT,
        PSXINT_CDRLID,
-       PSXINT_CDRPLAY,
+       PSXINT_CDRPLAY_OLD,     /* unused */
        PSXINT_SPU_UPDATE,
        PSXINT_COUNT
 };