// unused members maintain savesate compatibility
unsigned char unused0;
unsigned char unused1;
- unsigned char Reg2;
+ unsigned char IrqMask;
unsigned char unused2;
unsigned char Ctrl;
- unsigned char Stat;
+ unsigned char IrqStat;
unsigned char StatP;
unsigned char Test22[] = { 0x66, 0x6F, 0x72, 0x20, 0x45, 0x75, 0x72, 0x6F };
unsigned char Test23[] = { 0x43, 0x58, 0x44, 0x32, 0x39 ,0x34, 0x30, 0x51 };
-// cdr.Stat:
+// cdr.IrqStat:
#define NoIntr 0
#define DataReady 1
#define Complete 2
/* Errors */
#define ERROR_NOTREADY (1<<7) // 0x80
#define ERROR_INVALIDCMD (1<<6) // 0x40
-#define ERROR_INVALIDARG (1<<5) // 0x20
+#define ERROR_BAD_ARGNUM (1<<5) // 0x20
+#define ERROR_BAD_ARGVAL (1<<4) // 0x10
#define ERROR_SHELLOPEN (1<<3) // 0x08
// 1x = 75 sectors per second
x |= f; \
}
-#define SetResultSize(size) { \
+#define SetResultSize_(size) { \
cdr.ResultP = 0; \
cdr.ResultC = size; \
cdr.ResultReady = 1; \
}
-static void setIrq(int log_cmd)
+#define SetResultSize(size) { \
+ if (cdr.ResultP < cdr.ResultC) \
+ CDR_LOG_I("overwriting result, len=%u\n", cdr.ResultC); \
+ SetResultSize_(size); \
+}
+
+static void setIrq(u8 irq, int log_cmd)
{
- if (cdr.Stat & cdr.Reg2)
+ u8 old = cdr.IrqStat & cdr.IrqMask ? 1 : 0;
+ u8 new_ = irq & cdr.IrqMask ? 1 : 0;
+
+ cdr.IrqStat = irq;
+ if ((old ^ new_) & new_)
psxHu32ref(0x1070) |= SWAP32((u32)0x4);
#ifdef CDR_LOG_CMD_IRQ
- if (cdr.Stat)
+ if (cdr.IrqStat)
{
int i;
- CDR_LOG_I("CDR IRQ=%d cmd %02x stat %02x: ",
- !!(cdr.Stat & cdr.Reg2), log_cmd, cdr.Stat);
+ CDR_LOG_I("CDR IRQ=%d cmd %02x irqstat %02x: ",
+ !!(cdr.IrqStat & cdr.IrqMask), log_cmd, cdr.IrqStat);
for (i = 0; i < cdr.ResultC; i++)
SysPrintf("%02x ", cdr.Result[i]);
SysPrintf("\n");
SetResultSize(2);
cdr.Result[0] = cdr.StatP | STATUS_SEEKERROR;
cdr.Result[1] = ERROR_SHELLOPEN;
- cdr.Stat = DiskError;
- setIrq(0x1006);
+ setIrq(DiskError, 0x1006);
}
if (cdr.CmdInProgress) {
psxRegs.interrupt &= ~(1 << PSXINT_CDR);
SetResultSize(2);
cdr.Result[0] = cdr.StatP | STATUS_ERROR;
cdr.Result[1] = ERROR_NOTREADY;
- cdr.Stat = DiskError;
- setIrq(0x1007);
+ setIrq(DiskError, 0x1007);
}
set_event(PSXINT_CDRLID, cdReadTime * 30);
SetResultSize(1);
cdr.Result[0] = cdr.StatP;
- cdr.Stat = DataEnd;
- setIrq(0x1000); // 0x1000 just for logging purposes
+ setIrq(DataEnd, 0x1000); // 0x1000 just for logging purposes
StopCdda();
SetPlaySeekRead(cdr.StatP, 0);
cdr.Result[6] = abs_lev_max >> 0;
cdr.Result[7] = abs_lev_max >> 8;
- cdr.Stat = DataReady;
- setIrq(0x1001);
+ setIrq(DataReady, 0x1001);
}
if (cdr.ReportDelay)
CDR_readCDDA(cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2], (u8 *)read_buf);
}
- if (!cdr.Stat && (cdr.Mode & (MODE_AUTOPAUSE|MODE_REPORT)))
+ if (!cdr.IrqStat && (cdr.Mode & (MODE_AUTOPAUSE|MODE_REPORT)))
cdrPlayInterrupt_Autopause();
if (!cdr.Muted && cdr.Play && !Config.Cdda) {
u8 set_loc[3];
int read_ok;
u16 not_ready = 0;
+ u8 IrqStat = Acknowledge;
u16 Cmd;
int i;
- if (cdr.Stat) {
+ if (cdr.IrqStat) {
CDR_LOG_I("cmd %02x with irqstat %x\n",
- cdr.CmdInProgress, cdr.Stat);
+ cdr.CmdInProgress, cdr.IrqStat);
return;
}
if (cdr.Irq1Pending) {
cdr.CmdInProgress, cdr.Irq1Pending);
SetResultSize(1);
cdr.Result[0] = cdr.Irq1Pending;
- cdr.Stat = (cdr.Irq1Pending & STATUS_ERROR) ? DiskError : DataReady;
cdr.Irq1Pending = 0;
- setIrq(0x1003);
+ setIrq((cdr.Irq1Pending & STATUS_ERROR) ? DiskError : DataReady, 0x1003);
return;
}
// default response
SetResultSize(1);
cdr.Result[0] = cdr.StatP;
- cdr.Stat = Acknowledge;
Cmd = cdr.CmdInProgress;
cdr.CmdInProgress = 0;
CDR_LOG_I("Invalid/out of range seek to %02X:%02X:%02X\n", cdr.Param[0], cdr.Param[1], cdr.Param[2]);
if (++cdr.errorRetryhack > 100)
break;
- error = ERROR_INVALIDARG;
+ error = ERROR_BAD_ARGNUM;
goto set_error;
}
else
case CdlForward:
// TODO: error 80 if stopped
- cdr.Stat = Complete;
+ IrqStat = Complete;
// GameShark CD Player: Calls 2x + Play 2x
cdr.FastForward = 1;
break;
case CdlBackward:
- cdr.Stat = Complete;
+ IrqStat = Complete;
// GameShark CD Player: Calls 2x + Play 2x
cdr.FastBackward = 1;
case CdlStandby:
if (cdr.DriveState != DRIVESTATE_STOPPED) {
- error = ERROR_INVALIDARG;
+ error = ERROR_BAD_ARGNUM;
goto set_error;
}
second_resp_time = cdReadTime * 125 / 2;
break;
case CdlStandby + CMD_PART2:
- cdr.Stat = Complete;
+ IrqStat = Complete;
break;
case CdlStop:
break;
case CdlStop + CMD_PART2:
- cdr.Stat = Complete;
+ IrqStat = Complete;
break;
case CdlPause:
break;
case CdlPause + CMD_PART2:
- cdr.Stat = Complete;
+ IrqStat = Complete;
break;
case CdlReset:
case CdlReset + CMD_PART2:
case CdlReset + CMD_PART2 + CMD_WHILE_NOT_READY:
- cdr.Stat = Complete;
+ IrqStat = Complete;
break;
case CdlMute:
case CdlGetparam:
case CdlGetparam + CMD_WHILE_NOT_READY:
/* Gameblabla : According to mednafen, Result size should be 5 and done this way. */
- SetResultSize(5);
+ SetResultSize_(5);
cdr.Result[1] = cdr.Mode;
cdr.Result[2] = 0;
cdr.Result[3] = cdr.FilterFile;
error = 0x80;
goto set_error;
}
- SetResultSize(8);
+ SetResultSize_(8);
memcpy(cdr.Result, cdr.LocL, 8);
break;
case CdlGetlocP:
- SetResultSize(8);
+ SetResultSize_(8);
memcpy(&cdr.Result, &cdr.subq, 8);
break;
break;
case CdlReadT + CMD_PART2:
- cdr.Stat = Complete;
+ IrqStat = Complete;
break;
case CdlGetTN:
- SetResultSize(3);
if (CDR_getTN(cdr.ResultTN) == -1) {
- cdr.Stat = DiskError;
- cdr.Result[0] |= STATUS_ERROR;
- } else {
- cdr.Stat = Acknowledge;
- cdr.Result[1] = itob(cdr.ResultTN[0]);
- cdr.Result[2] = itob(cdr.ResultTN[1]);
+ assert(0);
}
+ SetResultSize_(3);
+ cdr.Result[1] = itob(cdr.ResultTN[0]);
+ cdr.Result[2] = itob(cdr.ResultTN[1]);
break;
case CdlGetTD:
cdr.Track = btoi(cdr.Param[0]);
- SetResultSize(4);
if (CDR_getTD(cdr.Track, cdr.ResultTD) == -1) {
- cdr.Stat = DiskError;
- cdr.Result[0] |= STATUS_ERROR;
- } else {
- cdr.Stat = Acknowledge;
- cdr.Result[0] = cdr.StatP;
- cdr.Result[1] = itob(cdr.ResultTD[2]);
- cdr.Result[2] = itob(cdr.ResultTD[1]);
- /* According to Nocash's documentation, the function doesn't care about ff.
- * This can be seen also in Mednafen's implementation. */
- //cdr.Result[3] = itob(cdr.ResultTD[0]);
+ error = ERROR_BAD_ARGVAL;
+ goto set_error;
}
+ SetResultSize_(3);
+ cdr.Result[1] = itob(cdr.ResultTD[2]);
+ cdr.Result[2] = itob(cdr.ResultTD[1]);
+ // no sector number
+ //cdr.Result[3] = itob(cdr.ResultTD[0]);
break;
case CdlSeekL:
case CdlSeekP + CMD_PART2:
SetPlaySeekRead(cdr.StatP, 0);
cdr.Result[0] = cdr.StatP;
- cdr.Stat = Complete;
+ IrqStat = Complete;
Find_CurTrack(cdr.SetSectorPlay);
read_ok = ReadTrack(cdr.SetSectorPlay);
case CdlTest + CMD_WHILE_NOT_READY:
switch (cdr.Param[0]) {
case 0x20: // System Controller ROM Version
- SetResultSize(4);
+ SetResultSize_(4);
memcpy(cdr.Result, Test20, 4);
break;
case 0x22:
- SetResultSize(8);
+ SetResultSize_(8);
memcpy(cdr.Result, Test22, 4);
break;
case 0x23: case 0x24:
- SetResultSize(8);
+ SetResultSize_(8);
memcpy(cdr.Result, Test23, 4);
break;
}
break;
case CdlID + CMD_PART2:
- SetResultSize(8);
+ SetResultSize_(8);
cdr.Result[0] = cdr.StatP;
cdr.Result[1] = 0;
cdr.Result[2] = 0;
/* This adds the string "PCSX" in Playstation bios boot screen */
memcpy((char *)&cdr.Result[4], "PCSX", 4);
- cdr.Stat = Complete;
+ IrqStat = Complete;
break;
case CdlInit:
case CdlReadToc + CMD_PART2:
case CdlReadToc + CMD_PART2 + CMD_WHILE_NOT_READY:
- cdr.Stat = Complete;
+ IrqStat = Complete;
break;
case CdlReadN:
// FALLTHROUGH
set_error:
- SetResultSize(2);
+ SetResultSize_(2);
cdr.Result[0] = cdr.StatP | STATUS_ERROR;
cdr.Result[1] = not_ready ? ERROR_NOTREADY : error;
- cdr.Stat = DiskError;
+ IrqStat = DiskError;
CDR_LOG_I("cmd %02x error %02x\n", Cmd, cdr.Result[1]);
break;
}
CDR_LOG_I("cmd %02x came before %02x finished\n", cdr.Cmd, Cmd);
}
- setIrq(Cmd);
+ setIrq(IrqStat, Cmd);
}
#ifdef HAVE_ARMV7
static void cdrReadInterruptSetResult(unsigned char result)
{
- if (cdr.Stat) {
+ if (cdr.IrqStat) {
CDR_LOG_I("%d:%02d:%02d irq miss, cmd=%02x irqstat=%02x\n",
cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2],
- cdr.CmdInProgress, cdr.Stat);
+ cdr.CmdInProgress, cdr.IrqStat);
cdr.Irq1Pending = result;
return;
}
SetResultSize(1);
cdr.Result[0] = result;
- cdr.Stat = (result & STATUS_ERROR) ? DiskError : DataReady;
- setIrq(0x1004);
+ setIrq((result & STATUS_ERROR) ? DiskError : DataReady, 0x1004);
}
static void cdrUpdateTransferBuf(const u8 *buf)
}
memcpy(cdr.LocL, buf, 8);
- if (!cdr.Stat && !cdr.Irq1Pending)
+ if (!cdr.IrqStat && !cdr.Irq1Pending)
cdrUpdateTransferBuf(buf);
subhdr = (void *)(buf + 4);
cdr.Param[cdr.ParamC++] = rt;
return;
case 1:
- cdr.Reg2 = rt;
- setIrq(0x1005);
+ cdr.IrqMask = rt;
+ setIrq(cdr.IrqStat, 0x1005);
return;
case 2:
cdr.AttenuatorLeftToLeftT = rt;
unsigned char cdrRead3(void) {
if (cdr.Ctrl & 0x1)
- psxHu8(0x1803) = cdr.Stat | 0xE0;
+ psxHu8(0x1803) = cdr.IrqStat | 0xE0;
else
- psxHu8(0x1803) = cdr.Reg2 | 0xE0;
+ psxHu8(0x1803) = cdr.IrqMask | 0xE0;
CDR_LOG_IO("cdr r3.%s: %02x\n", (cdr.Ctrl & 1) ? "ifl" : "ien", psxHu8(0x1803));
return psxHu8(0x1803);
case 0:
break; // transfer
case 1:
- if (cdr.Stat & rt) {
+ if (cdr.IrqStat & rt) {
u32 nextCycle = psxRegs.intCycle[PSXINT_CDR].sCycle
+ psxRegs.intCycle[PSXINT_CDR].cycle;
int pending = psxRegs.interrupt & (1 << PSXINT_CDR);
#ifdef CDR_LOG_CMD_IRQ
- CDR_LOG_I("ack %02x (w=%02x p=%d,%x,%x,%d)\n", cdr.Stat & rt, rt,
- !!pending, cdr.CmdInProgress,
+ CDR_LOG_I("ack %02x (w=%02x p=%d,%x,%x,%d)\n",
+ cdr.IrqStat & rt, rt, !!pending, cdr.CmdInProgress,
cdr.Irq1Pending, nextCycle - psxRegs.cycle);
#endif
// note: Croc, Shadow Tower (more) vs Discworld Noir (<993)
set_event(PSXINT_CDR, c);
}
}
- cdr.Stat &= ~rt;
+ cdr.IrqStat &= ~rt;
if (rt & 0x40)
cdr.ParamC = 0;
cdr.CurTrack = 1;
cdr.FilterFile = 0;
cdr.FilterChannel = 0;
- cdr.Reg2 = 0x1f;
- cdr.Stat = NoIntr;
+ cdr.IrqMask = 0x1f;
+ cdr.IrqStat = NoIntr;
cdr.FifoOffset = DATA_SIZE; // fifo empty
CDR_getStatus(&stat);
if (!Config.Cdda)
CDR_play(cdr.SetSectorPlay);
}
-
- if ((cdr.freeze_ver & 0xffffff00) != 0x63647200) {
- // old versions did not latch Reg2, have to fixup..
- if (cdr.Reg2 == 0) {
- SysPrintf("cdrom: fixing up old savestate\n");
- cdr.Reg2 = 7;
- }
- // also did not save Attenuator..
- if ((cdr.AttenuatorLeftToLeft | cdr.AttenuatorLeftToRight
- | cdr.AttenuatorRightToLeft | cdr.AttenuatorRightToRight) == 0)
- {
- cdr.AttenuatorLeftToLeft = cdr.AttenuatorRightToRight = 0x80;
- }
- }
}
return 0;