void psxDma3(u32 madr, u32 bcr, u32 chcr) { u32 cdsize; CDR_LOG("*** DMA 3 *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); switch (chcr) { case 0x11000000: case 0x11400100: if (cdr.Readed == 0) { CDR_LOG("*** DMA 3 *** NOT READY\n"); return; } cdsize = (bcr & 0xffff) * 4; memcpy_fast((u8*)PSXM(madr), cdr.pTransfer, cdsize); psxCpu->Clear(madr, cdsize/4); cdr.pTransfer+=cdsize; break; case 0x41000200: //SysPrintf("unhandled cdrom dma3: madr: %x, bcr: %x, chcr %x\n", madr, bcr, chcr); return; default: CDR_LOG("Unknown cddma %lx\n", chcr); break; } HW_DMA3_CHCR &= ~0x01000000; psxDmaInterrupt(3); }
void cdrWrite3(unsigned char rt) { #ifdef CDR_LOG CDR_LOG("cdrWrite3() Log: CD3 write: %x\n", rt); #endif if (rt == 0x07 && cdr.Ctrl & 0x1) { cdr.Stat = 0; if (cdr.Irq == 0xff) { cdr.Irq = 0; return; } if (cdr.Irq) CDR_INT(cdr.eCycle); if (cdr.Reading && !cdr.ResultReady) CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); return; } if (rt == 0x80 && !(cdr.Ctrl & 0x1) && cdr.Readed == 0) { cdr.Readed = 1; cdr.pTransfer = cdr.Transfer; switch (cdr.Mode&0x30) { case 0x10: case 0x00: cdr.pTransfer+=12; break; default: break; } } }
void cdrWrite2(u8 rt) { CDR_LOG("CD2 write: %x\n", rt); if (cdr.Ctrl & 0x1) { switch (rt) { case 0x07: cdr.ParamP = 0; cdr.ParamC = 0; cdr.ResultReady = 0; cdr.Ctrl = 0; break; default: cdr.Reg2 = rt; break; } } else { if (!(cdr.Ctrl & 0x1) && cdr.ParamP < 8) { cdr.Param[cdr.ParamP++] = rt; cdr.ParamC++; } } }
static void ReadTrack(const u8 *time) { unsigned char tmp[3]; struct SubQ *subq; u16 crc; tmp[0] = itob(time[0]); tmp[1] = itob(time[1]); tmp[2] = itob(time[2]); if (memcmp(cdr.Prev, tmp, 3) == 0) return; CDR_LOG("ReadTrack *** %02x:%02x:%02x\n", tmp[0], tmp[1], tmp[2]); cdr.RErr = CDR_readTrack(tmp); memcpy(cdr.Prev, tmp, 3); //senquack - PPF patch file support; not yet added (TODO?) #if 0 if (CheckSBI(time)) return; #endif subq = (struct SubQ *)CDR_getBufferSub(); if (subq != NULL && cdr.CurTrack == 1) { crc = calcCrc((u8 *)subq + 12, 10); if (crc == (((u16)subq->CRC[0] << 8) | subq->CRC[1])) { cdr.subq.Track = subq->TrackNumber; cdr.subq.Index = subq->IndexNumber; memcpy(cdr.subq.Relative, subq->TrackRelativeAddress, 3); memcpy(cdr.subq.Absolute, subq->AbsoluteAddress, 3); } else { CDR_LOG_I("subq bad crc @%02x:%02x:%02x\n", tmp[0], tmp[1], tmp[2]); } } else { generate_subq(time); } CDR_LOG(" -> %02x,%02x %02x:%02x:%02x %02x:%02x:%02x\n", cdr.subq.Track, cdr.subq.Index, cdr.subq.Relative[0], cdr.subq.Relative[1], cdr.subq.Relative[2], cdr.subq.Absolute[0], cdr.subq.Absolute[1], cdr.subq.Absolute[2]); }
void ReadTrack() { cdr.Prev[0] = itob(cdr.SetSector[0]); cdr.Prev[1] = itob(cdr.SetSector[1]); cdr.Prev[2] = itob(cdr.SetSector[2]); CDR_LOG("KEY *** %x:%x:%x\n", cdr.Prev[0], cdr.Prev[1], cdr.Prev[2]); cdr.RErr = CDVDreadTrack(MSFtoLSN(cdr.SetSector), CDVD_MODE_2352); }
// also handles seek void cdrPlayInterrupt() { if (cdr.Seeked == SEEK_PENDING) { if (cdr.Stat) { CDR_LOG_I("cdrom: seek stat hack\n"); CDRMISC_INT(0x1000); return; } SetResultSize(1); cdr.StatP |= STATUS_ROTATING; cdr.StatP &= ~STATUS_SEEK; cdr.Result[0] = cdr.StatP; cdr.Seeked = SEEK_DONE; if (cdr.Irq == 0) { cdr.Stat = Complete; setIrq(); } if (cdr.SetlocPending) { memcpy(cdr.SetSectorPlay, cdr.SetSector, 4); cdr.SetlocPending = 0; } Find_CurTrack(cdr.SetSectorPlay); ReadTrack(cdr.SetSectorPlay); cdr.TrackChanged = FALSE; } if (!cdr.Play) return; CDR_LOG( "CDDA - %d:%d:%d\n", cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2] ); if (memcmp(cdr.SetSectorPlay, cdr.SetSectorEnd, 3) == 0) { StopCdda(); cdr.TrackChanged = TRUE; } if (!cdr.Irq && !cdr.Stat && (cdr.Mode & (MODE_AUTOPAUSE|MODE_REPORT))) cdrPlayInterrupt_Autopause(); if (!cdr.Play) return; cdr.SetSectorPlay[2]++; if (cdr.SetSectorPlay[2] == 75) { cdr.SetSectorPlay[2] = 0; cdr.SetSectorPlay[1]++; if (cdr.SetSectorPlay[1] == 60) { cdr.SetSectorPlay[1] = 0; cdr.SetSectorPlay[0]++; } } CDRMISC_INT(cdReadTime); // update for CdlGetlocP/autopause generate_subq(cdr.SetSectorPlay); }
void ReadTrack() { cdr.Prev[0] = itob(cdr.SetSector[0]); cdr.Prev[1] = itob(cdr.SetSector[1]); cdr.Prev[2] = itob(cdr.SetSector[2]); #ifdef CDR_LOG CDR_LOG("ReadTrack() Log: KEY *** %x:%x:%x\n", cdr.Prev[0], cdr.Prev[1], cdr.Prev[2]); #endif cdr.RErr = CDR_readTrack(cdr.Prev); }
unsigned char cdrRead1(void) { if (cdr.ResultReady) { // && cdr.Ctrl & 0x1) { psxHu8(0x1801) = cdr.Result[cdr.ResultP++]; if (cdr.ResultP == cdr.ResultC) cdr.ResultReady = 0; } else psxHu8(0x1801) = 0; #ifdef CDR_LOG CDR_LOG("cdrRead1() Log: CD1 Read: %x\n", psxHu8(0x1801)); #endif return psxHu8(0x1801); }
unsigned char cdrRead3(void) { if (cdr.Stat) { if (cdr.Ctrl & 0x1) psxHu8(0x1803) = cdr.Stat | 0xE0; else psxHu8(0x1803) = 0xff; } else psxHu8(0x1803) = 0; #ifdef CDR_LOG CDR_LOG("cdrRead3() Log: CD3 Read: %x\n", psxHu8(0x1803)); #endif return psxHu8(0x1803); }
void psxDma3(u32 madr, u32 bcr, u32 chcr) { u32 cdsize; u8 *ptr; #ifdef CDR_LOG CDR_LOG("psxDma3() Log: *** DMA 3 *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); #endif switch (chcr) { case 0x11000000: case 0x11400100: if (cdr.Readed == 0) { #ifdef CDR_LOG CDR_LOG("psxDma3() Log: *** DMA 3 *** NOT READY\n"); #endif break; } cdsize = (bcr & 0xffff) * 4; ptr = (u8*)PSXM(madr); if (ptr == NULL) { #ifdef CPU_LOG CDR_LOG("psxDma3() Log: *** DMA 3 *** NULL Pointer!\n"); #endif break; } memcpy(ptr, cdr.pTransfer, cdsize); psxCpu->Clear(madr, cdsize/4); cdr.pTransfer+= cdsize; break; default: #ifdef CDR_LOG CDR_LOG("psxDma3() Log: Unknown cddma %lx\n", chcr); #endif break; } HW_DMA3_CHCR &= SWAP32(~0x01000000); DMA_INTERRUPT(3); }
u8 cdrRead3(void) { if (cdr.Stat) { if (cdr.Ctrl & 0x1) psxHu8(0x1803) = cdr.Stat | 0xE0; else psxHu8(0x1803) = 0xff; } else psxHu8(0x1803) = 0; CDR_LOG("CD3 Read: %x\n", psxHu8(0x1803)); return psxHu8(0x1803); }
u8 cdrRead1(void) { if (cdr.ResultReady && cdr.Ctrl & 0x1) { psxHu8(0x1801) = cdr.Result[cdr.ResultP++]; if (cdr.ResultP == cdr.ResultC) cdr.ResultReady = 0; } else psxHu8(0x1801) = 0; CDR_LOG("CD1 Read: %x\n", psxHu8(0x1801)); return psxHu8(0x1801); }
void cdrWrite0(u8 rt) { CDR_LOG("CD0 write: %x\n", rt); cdr.Ctrl = rt | (cdr.Ctrl & ~0x3); if (rt == 0) { cdr.ParamP = 0; cdr.ParamC = 0; cdr.ResultReady = 0; } }
void cdrWrite0(unsigned char rt) { #ifdef CDR_LOG CDR_LOG("cdrWrite0() Log: CD0 write: %x\n", rt); #endif cdr.Ctrl = rt | (cdr.Ctrl & ~0x3); if (rt == 0) { cdr.ParamP = 0; cdr.ParamC = 0; cdr.ResultReady = 0; } }
u8 cdrRead2(void) { u8 ret; if (cdr.Readed == 0) { ret = 0; } else { ret = *cdr.pTransfer++; } CDR_LOG("CD2 Read: %x\n", ret); return ret; }
unsigned char cdrRead2(void) { unsigned char ret; if (cdr.Readed == 0) { ret = 0; } else { ret = *cdr.pTransfer++; } #ifdef CDR_LOG CDR_LOG("cdrRead2() Log: CD2 Read: %x\n", ret); #endif return ret; }
unsigned char cdrRead0(void) { if (cdr.ResultReady) cdr.Ctrl|= 0x20; else cdr.Ctrl&=~0x20; if (cdr.OCUP) cdr.Ctrl|= 0x40; // else cdr.Ctrl&=~0x40; // what means the 0x10 and the 0x08 bits? i only saw it used by the bios cdr.Ctrl|=0x18; #ifdef CDR_LOG CDR_LOG("cdrRead0() Log: CD0 Read: %x\n", cdr.Ctrl); #endif return psxHu8(0x1800) = cdr.Ctrl; }
u8 cdrRead0(void) { if (cdr.ResultReady) cdr.Ctrl |= 0x20; else cdr.Ctrl &= ~0x20; if (cdr.OCUP) cdr.Ctrl |= 0x40; else cdr.Ctrl &= ~0x40; // what means the 0x10 and the 0x08 bits? i only saw it used by the bios cdr.Ctrl|=0x18; CDR_LOG("CD0 Read: %x\n", cdr.Ctrl); return psxHu8(0x1800) = cdr.Ctrl; }
static void cdrPlayInterrupt_Autopause() { if ((cdr.Mode & MODE_AUTOPAUSE) && cdr.TrackChanged) { CDR_LOG( "CDDA STOP\n" ); // Magic the Gathering // - looping territory cdda // ...? //cdr.ResultReady = 1; //cdr.Stat = DataReady; cdr.Stat = DataEnd; setIrq(); StopCdda(); } else if (cdr.Mode & MODE_REPORT) { cdr.Result[0] = cdr.StatP; cdr.Result[1] = cdr.subq.Track; cdr.Result[2] = cdr.subq.Index; if (cdr.subq.Absolute[2] & 0x10) { cdr.Result[3] = cdr.subq.Relative[0]; cdr.Result[4] = cdr.subq.Relative[1] | 0x80; cdr.Result[5] = cdr.subq.Relative[2]; } else { cdr.Result[3] = cdr.subq.Absolute[0]; cdr.Result[4] = cdr.subq.Absolute[1]; cdr.Result[5] = cdr.subq.Absolute[2]; } cdr.Result[6] = 0; cdr.Result[7] = 0; // Rayman: Logo freeze (resultready + dataready) cdr.ResultReady = 1; cdr.Stat = DataReady; SetResultSize(8); setIrq(); } }
void cdrWrite2(unsigned char rt) { #ifdef CDR_LOG CDR_LOG("cdrWrite2() Log: CD2 write: %x\n", rt); #endif if (cdr.Ctrl & 0x1) { switch (rt) { case 0x07: cdr.ParamP = 0; cdr.ParamC = 0; cdr.ResultReady = 1; //0; cdr.Ctrl&= ~3; //cdr.Ctrl = 0; break; default: cdr.Reg2 = rt; break; } } else if (!(cdr.Ctrl & 0x1) && cdr.ParamP < 8) { cdr.Param[cdr.ParamP++] = rt; cdr.ParamC++; } }
void cdrWrite3(u8 rt) { CDR_LOG("CD3 write: %x\n", rt); if (rt == 0x07 && cdr.Ctrl & 0x1) { cdr.Stat = 0; if (cdr.Irq == 0xff) { cdr.Irq = 0; return; } if (cdr.Irq) { CDR_INT(cdr.eCycle); } return; } if (rt == 0x80 && !(cdr.Ctrl & 0x1) && cdr.Readed == 0) { cdr.Readed = 1; cdr.pTransfer = cdr.Transfer; switch (cdr.Mode&0x30) { case 0x10: case 0x00: cdr.pTransfer+=12; break; default: break; } } }
void cdrInterrupt() { u16 Irq = cdr.Irq; int no_busy_error = 0; int start_rotating = 0; int error = 0; int delay; // Reschedule IRQ if (cdr.Stat) { CDR_LOG_I("cdrom: stat hack: %02x %x\n", cdr.Irq, cdr.Stat); CDR_INT(0x1000); return; } cdr.Ctrl &= ~0x80; // default response SetResultSize(1); cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; if (cdr.IrqRepeated) { cdr.IrqRepeated = 0; if (cdr.eCycle > psxRegs.cycle) { CDR_INT(cdr.eCycle); goto finish; } } cdr.Irq = 0; switch (Irq) { case CdlSync: // TOOD: sometimes/always return error? break; case CdlNop: if (cdr.DriveState != DRIVESTATE_LID_OPEN) cdr.StatP &= ~STATUS_SHELLOPEN; no_busy_error = 1; break; case CdlSetloc: break; do_CdlPlay: case CdlPlay: StopCdda(); if (cdr.Seeked == SEEK_PENDING) { // XXX: wrong, should seek instead.. cdr.Seeked = SEEK_DONE; } if (cdr.SetlocPending) { memcpy(cdr.SetSectorPlay, cdr.SetSector, 4); cdr.SetlocPending = 0; } // BIOS CD Player // - Pause player, hit Track 01/02/../xx (Setloc issued!!) if (cdr.ParamC == 0 || cdr.Param[0] == 0) { CDR_LOG("PLAY Resume @ %d:%d:%d\n", cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2]); } else { int track = btoi( cdr.Param[0] ); if (track <= cdr.ResultTN[1]) cdr.CurTrack = track; CDR_LOG("PLAY track %d\n", cdr.CurTrack); if (CDR_getTD((u8)cdr.CurTrack, cdr.ResultTD) != -1) { cdr.SetSectorPlay[0] = cdr.ResultTD[2]; cdr.SetSectorPlay[1] = cdr.ResultTD[1]; cdr.SetSectorPlay[2] = cdr.ResultTD[0]; } } /* Rayman: detect track changes - fixes logo freeze Twisted Metal 2: skip PREGAP + starting accurate SubQ - plays tracks without retry play Wild 9: skip PREGAP + starting accurate SubQ - plays tracks without retry play */ Find_CurTrack(cdr.SetSectorPlay); ReadTrack(cdr.SetSectorPlay); cdr.TrackChanged = FALSE; if (!Config.Cdda) CDR_play(cdr.SetSectorPlay); // Vib Ribbon: gameplay checks flag cdr.StatP &= ~STATUS_SEEK; cdr.Result[0] = cdr.StatP; cdr.StatP |= STATUS_PLAY; // BIOS player - set flag again cdr.Play = TRUE; CDRMISC_INT( cdReadTime ); start_rotating = 1; break; case CdlForward: // TODO: error 80 if stopped cdr.Stat = Complete; // GameShark CD Player: Calls 2x + Play 2x if( cdr.FastForward == 0 ) cdr.FastForward = 2; else cdr.FastForward++; cdr.FastBackward = 0; break; case CdlBackward: cdr.Stat = Complete; // GameShark CD Player: Calls 2x + Play 2x if( cdr.FastBackward == 0 ) cdr.FastBackward = 2; else cdr.FastBackward++; cdr.FastForward = 0; break; case CdlStandby: if (cdr.DriveState != DRIVESTATE_STOPPED) { error = ERROR_INVALIDARG; goto set_error; } AddIrqQueue(CdlStandby + 0x100, cdReadTime * 125 / 2); start_rotating = 1; break; case CdlStandby + 0x100: cdr.Stat = Complete; break; case CdlStop: if (cdr.Play) { // grab time for current track CDR_getTD((u8)(cdr.CurTrack), cdr.ResultTD); cdr.SetSectorPlay[0] = cdr.ResultTD[2]; cdr.SetSectorPlay[1] = cdr.ResultTD[1]; cdr.SetSectorPlay[2] = cdr.ResultTD[0]; } StopCdda(); StopReading(); delay = 0x800; if (cdr.DriveState == DRIVESTATE_STANDBY) delay = cdReadTime * 30 / 2; cdr.DriveState = DRIVESTATE_STOPPED; AddIrqQueue(CdlStop + 0x100, delay); break; case CdlStop + 0x100: cdr.StatP &= ~STATUS_ROTATING; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlPause: /* Gundam Battle Assault 2: much slower (*) - Fixes boot, gameplay Hokuto no Ken 2: slower - Fixes intro + subtitles InuYasha - Feudal Fairy Tale: slower - Fixes battles */ AddIrqQueue(CdlPause + 0x100, cdReadTime * 3); cdr.Ctrl |= 0x80; break; case CdlPause + 0x100: cdr.StatP &= ~STATUS_READ; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlInit: AddIrqQueue(CdlInit + 0x100, cdReadTime * 6); no_busy_error = 1; start_rotating = 1; break; case CdlInit + 0x100: cdr.Stat = Complete; break; case CdlMute: cdr.Muted = TRUE; break; case CdlDemute: cdr.Muted = FALSE; break; case CdlSetfilter: cdr.File = cdr.Param[0]; cdr.Channel = cdr.Param[1]; break; case CdlSetmode: no_busy_error = 1; break; case CdlGetmode: SetResultSize(6); cdr.Result[1] = cdr.Mode; cdr.Result[2] = cdr.File; cdr.Result[3] = cdr.Channel; cdr.Result[4] = 0; cdr.Result[5] = 0; no_busy_error = 1; break; case CdlGetlocL: SetResultSize(8); memcpy(cdr.Result, cdr.Transfer, 8); break; case CdlGetlocP: SetResultSize(8); memcpy(&cdr.Result, &cdr.subq, 8); if (!cdr.Play && !cdr.Reading) cdr.Result[1] = 0; // HACK? break; case CdlReadT: // SetSession? // really long AddIrqQueue(CdlReadT + 0x100, cdReadTime * 290 / 4); start_rotating = 1; break; case CdlReadT + 0x100: cdr.Stat = 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]); } 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]); cdr.Result[3] = itob(cdr.ResultTD[0]); } break; case CdlSeekL: case CdlSeekP: StopCdda(); StopReading(); cdr.StatP |= STATUS_SEEK; /* Crusaders of Might and Magic = 0.5x-4x - fix cutscene speech start Eggs of Steel = 2x-? - fix new game Medievil = ?-4x - fix cutscene speech Rockman X5 = 0.5-4x - fix capcom logo */ CDRMISC_INT(cdr.Seeked == SEEK_DONE ? 0x800 : cdReadTime * 4); cdr.Seeked = SEEK_PENDING; start_rotating = 1; break; case CdlTest: switch (cdr.Param[0]) { case 0x20: // System Controller ROM Version SetResultSize(4); memcpy(cdr.Result, Test20, 4); break; case 0x22: SetResultSize(8); memcpy(cdr.Result, Test22, 4); break; case 0x23: case 0x24: SetResultSize(8); memcpy(cdr.Result, Test23, 4); break; } no_busy_error = 1; break; case CdlID: AddIrqQueue(CdlID + 0x100, 20480); break; case CdlID + 0x100: SetResultSize(8); cdr.Result[0] = cdr.StatP; cdr.Result[1] = 0; cdr.Result[2] = 0; cdr.Result[3] = 0; // 0x10 - audio | 0x40 - disk missing | 0x80 - unlicensed if (CDR_getStatus(&stat) == -1 || stat.Type == 0 || stat.Type == 0xff) { cdr.Result[1] = 0xc0; } else { if (stat.Type == 2) cdr.Result[1] |= 0x10; if (CdromId[0] == '\0') cdr.Result[1] |= 0x80; } cdr.Result[0] |= (cdr.Result[1] >> 4) & 0x08; strncpy((char *)&cdr.Result[4], "PCSX", 4); cdr.Stat = Complete; break; case CdlReset: // yes, it really sets STATUS_SHELLOPEN cdr.StatP |= STATUS_SHELLOPEN; cdr.DriveState = DRIVESTATE_RESCAN_CD; CDRLID_INT(20480); no_busy_error = 1; start_rotating = 1; break; case CdlGetQ: // TODO? CDR_LOG_I("got CdlGetQ\n"); break; case CdlReadToc: AddIrqQueue(CdlReadToc + 0x100, cdReadTime * 180 / 4); no_busy_error = 1; start_rotating = 1; break; case CdlReadToc + 0x100: cdr.Stat = Complete; no_busy_error = 1; break; case CdlReadN: case CdlReadS: if (cdr.SetlocPending) { memcpy(cdr.SetSectorPlay, cdr.SetSector, 4); cdr.SetlocPending = 0; } Find_CurTrack(cdr.SetSectorPlay); if ((cdr.Mode & MODE_CDDA) && cdr.CurTrack > 1) // Read* acts as play for cdda tracks in cdda mode goto do_CdlPlay; cdr.Reading = 1; cdr.FirstSector = 1; // Fighting Force 2 - update subq time immediately // - fixes new game ReadTrack(cdr.SetSectorPlay); // Crusaders of Might and Magic - update getlocl now // - fixes cutscene speech { u8 *buf = CDR_getBuffer(); if (buf != NULL) memcpy(cdr.Transfer, buf, 8); } /* Duke Nukem: Land of the Babes - seek then delay read for one frame - fixes cutscenes C-12 - Final Resistance - doesn't like seek */ if (cdr.Seeked != SEEK_DONE) { cdr.StatP |= STATUS_SEEK; cdr.StatP &= ~STATUS_READ; // Crusaders of Might and Magic - use short time // - fix cutscene speech (startup) // ??? - use more accurate seek time later CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime * 1); } else { cdr.StatP |= STATUS_READ; cdr.StatP &= ~STATUS_SEEK; CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime * 1); } cdr.Result[0] = cdr.StatP; start_rotating = 1; break; default: CDR_LOG_I("Invalid command: %02x\n", Irq); error = ERROR_INVALIDCMD; // FALLTHROUGH set_error: SetResultSize(2); cdr.Result[0] = cdr.StatP | STATUS_ERROR; cdr.Result[1] = error; cdr.Stat = DiskError; break; } if (cdr.DriveState == DRIVESTATE_STOPPED && start_rotating) { cdr.DriveState = DRIVESTATE_STANDBY; cdr.StatP |= STATUS_ROTATING; } if (!no_busy_error) { switch (cdr.DriveState) { case DRIVESTATE_LID_OPEN: case DRIVESTATE_RESCAN_CD: case DRIVESTATE_PREPARE_CD: SetResultSize(2); cdr.Result[0] = cdr.StatP | STATUS_ERROR; cdr.Result[1] = ERROR_NOT_READY; cdr.Stat = DiskError; break; } } finish: setIrq(); cdr.ParamC = 0; #ifdef CDR_LOG_CMD_IRQ { int i; SysPrintf("CDR IRQ %d cmd %02x stat %02x: ", !!(cdr.Stat & cdr.Reg2), Irq, cdr.Stat); for (i = 0; i < cdr.ResultC; i++) SysPrintf("%02x ", cdr.Result[i]); SysPrintf("\n"); } #endif }
void cdrInterrupt() { cdvdTD trackInfo; int i; u8 Irq = cdr.Irq; if (cdr.Stat) { CDR_INT(0x800); return; } cdr.Irq = 0xff; cdr.Ctrl&=~0x80; switch (Irq) { case CdlSync: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlNop: SetResultSize(1); cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlSetloc: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlPlay: cdr.CmdProcess = 0; SetResultSize(1); cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; cdr.StatP|= 0x82; break; case CdlForward: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlBackward: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlStandby: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlStop: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP&=~0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; // cdr.Stat = Acknowledge; break; case CdlPause: SetResultSize(1); cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; AddIrqQueue(CdlPause + 0x20, 0x800); break; case CdlPause + 0x20: SetResultSize(1); cdr.StatP&=~0x20; cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlInit: SetResultSize(1); cdr.StatP = 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; AddIrqQueue(CdlInit + 0x20, 0x800); break; case CdlInit + 0x20: SetResultSize(1); cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; cdr.Init = 1; break; case CdlMute: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlDemute: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlSetfilter: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlSetmode: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlGetmode: SetResultSize(6); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Result[1] = cdr.Mode; cdr.Result[2] = cdr.File; cdr.Result[3] = cdr.Channel; cdr.Result[4] = 0; cdr.Result[5] = 0; cdr.Stat = Acknowledge; break; case CdlGetlocL: SetResultSize(8); for (i=0; i<8; i++) cdr.Result[i] = cdr.Transfer[i]; cdr.Stat = Acknowledge; break; case CdlGetlocP: SetResultSize(8); cdr.Result[0] = 1; cdr.Result[1] = 1; cdr.Result[2] = cdr.Prev[0]; cdr.Result[3] = itob((btoi(cdr.Prev[1])) - 2); cdr.Result[4] = cdr.Prev[2]; cdr.Result[5] = cdr.Prev[0]; cdr.Result[6] = cdr.Prev[1]; cdr.Result[7] = cdr.Prev[2]; cdr.Stat = Acknowledge; break; case CdlGetTN: cdr.CmdProcess = 0; SetResultSize(3); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; if (CDVDgetTN(&cdr.ResultTN) == -1) { cdr.Stat = DiskError; cdr.Result[0]|= 0x01; } else { cdr.Stat = Acknowledge; cdr.Result[1] = itob(cdr.ResultTN.strack); cdr.Result[2] = itob(cdr.ResultTN.etrack); } break; case CdlGetTD: cdr.CmdProcess = 0; cdr.Track = btoi(cdr.Param[0]); SetResultSize(4); cdr.StatP|= 0x2; if (CDVDgetTD(cdr.Track, &trackInfo) == -1) { cdr.Stat = DiskError; cdr.Result[0]|= 0x01; } else { LSNtoMSF(cdr.ResultTD, trackInfo.lsn); cdr.Stat = Acknowledge; cdr.Result[0] = cdr.StatP; cdr.Result[1] = itob(cdr.ResultTD[0]); cdr.Result[2] = itob(cdr.ResultTD[1]); cdr.Result[3] = itob(cdr.ResultTD[2]); } break; case CdlSeekL: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; AddIrqQueue(CdlSeekL + 0x20, 0x800); break; case CdlSeekL + 0x20: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlSeekP: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; AddIrqQueue(CdlSeekP + 0x20, 0x800); break; case CdlSeekP + 0x20: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlTest: cdr.Stat = Acknowledge; switch (cdr.Param[0]) { case 0x20: // System Controller ROM Version SetResultSize(4); *(int*)cdr.Result = *(int*)Test20; break; case 0x22: SetResultSize(8); *(int*)cdr.Result = *(int*)Test22; break; case 0x23: case 0x24: SetResultSize(8); *(int*)cdr.Result = *(int*)Test23; break; } break; case CdlID: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; AddIrqQueue(CdlID + 0x20, 0x800); break; case CdlID + 0x20: SetResultSize(8); cdr.Result[0] = 0x00; // 0x08 and cdr.Result[1]|0x10 : audio cd, enters cd player cdr.Result[1] = 0x00; // 0x80 leads to the menu in the bios, else loads CD if (!LoadCdBios) cdr.Result[1] |= 0x80; cdr.Result[2] = 0x00; cdr.Result[3] = 0x00; strncpy((char *)&cdr.Result[4], "PCSX", 4); cdr.Stat = Complete; break; case CdlReset: SetResultSize(1); cdr.StatP = 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlReadToc: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; AddIrqQueue(CdlReadToc + 0x20, 0x800); break; case CdlReadToc + 0x20: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case AUTOPAUSE: cdr.OCUP = 0; AddIrqQueue(CdlPause, 0x400); break; case READ_ACK: if (!cdr.Reading) return; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; ReadTrack(); CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); break; case REPPLAY_ACK: cdr.Stat = Acknowledge; cdr.Result[0] = cdr.StatP; SetResultSize(1); AddIrqQueue(REPPLAY, cdReadTime); break; case REPPLAY: //if ((cdr.Mode & 5) != 5) break; break; case 0xff: return; default: cdr.Stat = Complete; break; } if (cdr.Stat != NoIntr && cdr.Reg2 != 0x18) psxHu32(0x1070)|= 0x4; CDR_LOG("Cdr Interrupt %x\n", Irq); }
void cdrReadInterrupt() { u8 *buf; if (!cdr.Reading) return; if (cdr.Stat) { CDREAD_INT(0x800); return; } CDR_LOG("KEY END"); cdr.OCUP = 1; SetResultSize(1); cdr.StatP|= 0x22; cdr.Result[0] = cdr.StatP; SysPrintf("Reading From CDR"); buf = CDVDgetBuffer(); if (buf == NULL) cdr.RErr = -1; if (cdr.RErr == -1) { CDR_LOG(" err\n"); memzero_ptr<2340>(cdr.Transfer); cdr.Stat = DiskError; cdr.Result[0]|= 0x01; ReadTrack(); CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); return; } memcpy_fast(cdr.Transfer, buf+12, 2340); cdr.Stat = DataReady; CDR_LOG(" %x:%x:%x\n", cdr.Transfer[0], cdr.Transfer[1], cdr.Transfer[2]); cdr.SetSector[2]++; if (cdr.SetSector[2] == 75) { cdr.SetSector[2] = 0; cdr.SetSector[1]++; if (cdr.SetSector[1] == 60) { cdr.SetSector[1] = 0; cdr.SetSector[0]++; } } cdr.Readed = 0; if ((cdr.Transfer[4+2] & 0x80) && (cdr.Mode & 0x2)) { // EOF CDR_LOG("AutoPausing Read\n"); AddIrqQueue(CdlPause, 0x800); } else { ReadTrack(); CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); } psxHu32(0x1070)|= 0x4; return; }
void cdrWrite1(unsigned char rt) { int i; #ifdef CDR_LOG CDR_LOG("cdrWrite1() Log: CD1 write: %x (%s)\n", rt, CmdName[rt]); #endif // psxHu8(0x1801) = rt; cdr.Cmd = rt; cdr.OCUP = 0; #ifdef CDRCMD_DEBUG SysPrintf("cdrWrite1() Log: CD1 write: %x (%s)", rt, CmdName[rt]); if (cdr.ParamC) { SysPrintf(" Param[%d] = {", cdr.ParamC); for (i=0;i<cdr.ParamC;i++) SysPrintf(" %x,", cdr.Param[i]); SysPrintf("}\n"); } else SysPrintf("\n"); #endif if (cdr.Ctrl & 0x1) return; switch(cdr.Cmd) { case CdlSync: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlNop: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSetloc: StopReading(); cdr.Seeked = 0; for (i=0; i<3; i++) cdr.SetSector[i] = btoi(cdr.Param[i]); cdr.SetSector[3] = 0; /* if ((cdr.SetSector[0] | cdr.SetSector[1] | cdr.SetSector[2]) == 0) { *(u32 *)cdr.SetSector = *(u32 *)cdr.SetSectorSeek; }*/ cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlPlay: if (!cdr.SetSector[0] && !cdr.SetSector[1] && !cdr.SetSector[2]) { if (CDR_getTN(cdr.ResultTN) != -1) { if (cdr.CurTrack > cdr.ResultTN[1]) cdr.CurTrack = cdr.ResultTN[1]; if (CDR_getTD((unsigned char)(cdr.CurTrack), cdr.ResultTD) != -1) { int tmp = cdr.ResultTD[2]; cdr.ResultTD[2] = cdr.ResultTD[0]; cdr.ResultTD[0] = tmp; if (!Config.Cdda) CDR_play(cdr.ResultTD); } } } else if (!Config.Cdda) CDR_play(cdr.SetSector); cdr.Play = 1; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlForward: if (cdr.CurTrack < 0xaa) cdr.CurTrack++; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlBackward: if (cdr.CurTrack > 1) cdr.CurTrack--; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlReadN: cdr.Irq = 0; StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; StartReading(1); break; case CdlStandby: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlStop: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlPause: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x40000); break; case CdlReset: case CdlInit: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlMute: cdr.Muted = 0; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlDemute: cdr.Muted = 1; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSetfilter: cdr.File = cdr.Param[0]; cdr.Channel = cdr.Param[1]; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSetmode: #ifdef CDR_LOG CDR_LOG("cdrWrite1() Log: Setmode %x\n", cdr.Param[0]); #endif cdr.Mode = cdr.Param[0]; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetmode: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetlocL: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetlocP: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetTN: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetTD: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSeekL: // ((u32 *)cdr.SetSectorSeek)[0] = ((u32 *)cdr.SetSector)[0]; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSeekP: // ((u32 *)cdr.SetSectorSeek)[0] = ((u32 *)cdr.SetSector)[0]; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlTest: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlID: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlReadS: cdr.Irq = 0; StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; StartReading(2); break; case CdlReadToc: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; default: #ifdef CDR_LOG CDR_LOG("cdrWrite1() Log: Unknown command: %x\n", cdr.Cmd); #endif return; } if (cdr.Stat != NoIntr) { psxHu32ref(0x1070)|= SWAP32((u32)0x4); psxRegs.interrupt|= 0x80000000; } }
void cdrWrite1(u8 rt) { int i; CDR_LOG("CD1 write: %x (%s)\n", rt, CmdName[rt]); cdr.Cmd = rt; cdr.OCUP = 0; #ifdef CDRCMD_DEBUG SysPrintf("CD1 write: %x (%s)", rt, CmdName[rt]); if (cdr.ParamC) { SysPrintf(" Param[%d] = {", cdr.ParamC); for (i=0;i<cdr.ParamC;i++) SysPrintf(" %x,", cdr.Param[i]); SysPrintf("}\n"); } else SysPrintf("\n"); #endif if (cdr.Ctrl & 0x1) return; switch(cdr.Cmd) { case CdlSync: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlNop: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSetloc: StopReading(); for (i=0; i<3; i++) cdr.SetSector[i] = btoi(cdr.Param[i]); cdr.SetSector[3] = 0; if ((cdr.SetSector[0] | cdr.SetSector[1] | cdr.SetSector[2]) == 0) { *(unsigned long *)cdr.SetSector = *(unsigned long *)cdr.SetSectorSeek; } cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlPlay: cdr.Play = 1; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlForward: if (cdr.CurTrack < 0xaa) cdr.CurTrack++; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlBackward: if (cdr.CurTrack > 1) cdr.CurTrack--; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlReadN: cdr.Irq = 0; StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; StartReading(1); break; case CdlStandby: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlStop: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlPause: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x40000); break; case CdlReset: case CdlInit: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlMute: cdr.Muted = 0; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlDemute: cdr.Muted = 1; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSetfilter: cdr.File = cdr.Param[0]; cdr.Channel = cdr.Param[1]; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSetmode: CDR_LOG("Setmode %x\n", cdr.Param[0]); cdr.Mode = cdr.Param[0]; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetmode: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetlocL: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetlocP: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetTN: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlGetTD: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSeekL: ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlSeekP: ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlTest: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlID: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; case CdlReadS: cdr.Irq = 0; StopReading(); cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; StartReading(2); break; case CdlReadToc: cdr.Ctrl|= 0x80; cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); break; default: CDR_LOG("Unknown Cmd: %x\n", cdr.Cmd); return; } if (cdr.Stat != NoIntr) iopIntcIrq( 2 ); }
void cdrReadInterrupt() { u8 *buf; if (!cdr.Reading) return; if (cdr.Stat) { CDREAD_INT(0x800); return; } #ifdef CDR_LOG CDR_LOG("cdrReadInterrupt() Log: KEY END"); #endif cdr.OCUP = 1; SetResultSize(1); cdr.StatP|= 0x22; cdr.StatP&=~0x40; cdr.Result[0] = cdr.StatP; buf = CDR_getBuffer(); if (buf == NULL) { cdr.RErr = -1; #ifdef CDR_LOG fprintf(emuLog, "cdrReadInterrupt() Log: err\n"); #endif memset(cdr.Transfer, 0, 2340); cdr.Stat = DiskError; cdr.Result[0]|= 0x01; ReadTrack(); CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); return; } memcpy(cdr.Transfer, buf, 2340); cdr.Stat = DataReady; #ifdef CDR_LOG fprintf(emuLog, "cdrReadInterrupt() Log: cdr.Transfer %x:%x:%x\n", cdr.Transfer[0], cdr.Transfer[1], cdr.Transfer[2]); #endif if ((cdr.Muted == 1) && (cdr.Mode & 0x40) && (!Config.Xa) && (cdr.FirstSector != -1)) { // CD-XA if ((cdr.Transfer[4+2] & 0x4) && ((cdr.Mode&0x8) ? (cdr.Transfer[4+1] == cdr.Channel) : 1) && (cdr.Transfer[4+0] == cdr.File)) { int ret = xa_decode_sector(&cdr.Xa, cdr.Transfer+4, cdr.FirstSector); if (!ret) { SPU_playADPCMchannel(&cdr.Xa); cdr.FirstSector = 0; } else cdr.FirstSector = -1; } } cdr.SetSector[2]++; if (cdr.SetSector[2] == 75) { cdr.SetSector[2] = 0; cdr.SetSector[1]++; if (cdr.SetSector[1] == 60) { cdr.SetSector[1] = 0; cdr.SetSector[0]++; } } cdr.Readed = 0; if ((cdr.Transfer[4+2] & 0x80) && (cdr.Mode & 0x2)) { // EOF #ifdef CDR_LOG CDR_LOG("cdrReadInterrupt() Log: Autopausing read\n"); #endif // AddIrqQueue(AUTOPAUSE, 0x800); AddIrqQueue(CdlPause, 0x800); } else { ReadTrack(); CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); } psxHu32ref(0x1070)|= SWAP32((u32)0x4); psxRegs.interrupt|= 0x80000000; }
void cdrInterrupt() { int i; unsigned char Irq = cdr.Irq; if (cdr.Stat) { CDR_INT(0x800); return; } cdr.Irq = 0xff; cdr.Ctrl&=~0x80; switch (Irq) { case CdlSync: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlNop: SetResultSize(1); cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; i = stat.Status; if (CDR_getStatus(&stat) != -1) { if (stat.Type == 0xff) cdr.Stat = DiskError; if (stat.Status & 0x10) { cdr.Stat = DiskError; cdr.Result[0]|= 0x11; cdr.Result[0]&=~0x02; } else if (i & 0x10) { cdr.StatP |= 0x2; cdr.Result[0]|= 0x2; CheckCdrom(); } } break; case CdlSetloc: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlPlay: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; cdr.StatP|= 0x80; // if ((cdr.Mode & 0x5) == 0x5) AddIrqQueue(REPPLAY, cdReadTime); break; case CdlForward: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlBackward: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlStandby: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlStop: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP&=~0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; // cdr.Stat = Acknowledge; break; case CdlPause: SetResultSize(1); cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; AddIrqQueue(CdlPause + 0x20, 0x800); cdr.Ctrl|= 0x80; break; case CdlPause + 0x20: SetResultSize(1); cdr.StatP&=~0x20; cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlInit: SetResultSize(1); cdr.StatP = 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; // if (!cdr.Init) { AddIrqQueue(CdlInit + 0x20, 0x800); // } break; case CdlInit + 0x20: SetResultSize(1); cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; cdr.Init = 1; break; case CdlMute: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlDemute: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlSetfilter: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlSetmode: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlGetmode: SetResultSize(6); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Result[1] = cdr.Mode; cdr.Result[2] = cdr.File; cdr.Result[3] = cdr.Channel; cdr.Result[4] = 0; cdr.Result[5] = 0; cdr.Stat = Acknowledge; break; case CdlGetlocL: SetResultSize(8); // for (i=0; i<8; i++) cdr.Result[i] = itob(cdr.Transfer[i]); for (i=0; i<8; i++) cdr.Result[i] = cdr.Transfer[i]; cdr.Stat = Acknowledge; break; case CdlGetlocP: SetResultSize(8); subq = (struct SubQ*) CDR_getBufferSub(); if (subq != NULL) { cdr.Result[0] = subq->TrackNumber; cdr.Result[1] = subq->IndexNumber; memcpy(cdr.Result+2, subq->TrackRelativeAddress, 3); memcpy(cdr.Result+5, subq->AbsoluteAddress, 3); } else { cdr.Result[0] = 1; cdr.Result[1] = 1; cdr.Result[2] = cdr.Prev[0]; cdr.Result[3] = itob((btoi(cdr.Prev[1])) - 2); cdr.Result[4] = cdr.Prev[2]; memcpy(cdr.Result+5, cdr.Prev, 3); } cdr.Stat = Acknowledge; break; case CdlGetTN: cdr.CmdProcess = 0; SetResultSize(3); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; if (CDR_getTN(cdr.ResultTN) == -1) { cdr.Stat = DiskError; cdr.Result[0]|= 0x01; } else { cdr.Stat = Acknowledge; cdr.Result[1] = itob(cdr.ResultTN[0]); cdr.Result[2] = itob(cdr.ResultTN[1]); } break; case CdlGetTD: cdr.CmdProcess = 0; cdr.Track = btoi(cdr.Param[0]); SetResultSize(4); cdr.StatP|= 0x2; if (CDR_getTD(cdr.Track, cdr.ResultTD) == -1) { cdr.Stat = DiskError; cdr.Result[0]|= 0x01; } else { cdr.Stat = Acknowledge; cdr.Result[0] = cdr.StatP; cdr.Result[1] = itob(cdr.ResultTD[2]); cdr.Result[2] = itob(cdr.ResultTD[1]); cdr.Result[3] = itob(cdr.ResultTD[0]); } break; case CdlSeekL: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.StatP|= 0x40; cdr.Stat = Acknowledge; cdr.Seeked = 1; AddIrqQueue(CdlSeekL + 0x20, 0x800); break; case CdlSeekL + 0x20: SetResultSize(1); cdr.StatP|= 0x2; cdr.StatP&=~0x40; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlSeekP: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.StatP|= 0x40; cdr.Stat = Acknowledge; AddIrqQueue(CdlSeekP + 0x20, 0x800); break; case CdlSeekP + 0x20: SetResultSize(1); cdr.StatP|= 0x2; cdr.StatP&=~0x40; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case CdlTest: cdr.Stat = Acknowledge; switch (cdr.Param[0]) { case 0x20: // System Controller ROM Version SetResultSize(4); memcpy(cdr.Result, Test20, 4); break; case 0x22: SetResultSize(8); memcpy(cdr.Result, Test22, 4); break; case 0x23: case 0x24: SetResultSize(8); memcpy(cdr.Result, Test23, 4); break; } break; case CdlID: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; AddIrqQueue(CdlID + 0x20, 0x800); break; case CdlID + 0x20: SetResultSize(8); if (CDR_getStatus(&stat) == -1) { cdr.Result[0] = 0x00; // 0x00 Game CD cdr.Result[1] = 0x00; // 0x00 loads CD } else { if (stat.Type == 2) { cdr.Result[0] = 0x08; // 0x08 audio cd cdr.Result[1] = 0x10; // 0x10 enter cd player } else { cdr.Result[0] = 0x00; // 0x00 game CD cdr.Result[1] = 0x00; // 0x00 loads CD } } if (!LoadCdBios) cdr.Result[1] |= 0x80; //0x80 leads to the menu in the bios cdr.Result[2] = 0x00; cdr.Result[3] = 0x00; // strncpy((char *)&cdr.Result[4], "PCSX", 4); #ifdef HW_RVL strncpy((char *)&cdr.Result[4], "WSX ", 4); #else strncpy((char *)&cdr.Result[4], "GCSX", 4); #endif cdr.Stat = Complete; break; case CdlReset: SetResultSize(1); cdr.StatP = 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; break; case CdlReadToc: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; AddIrqQueue(CdlReadToc + 0x20, 0x800); break; case CdlReadToc + 0x20: SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; break; case AUTOPAUSE: cdr.OCUP = 0; /* SetResultSize(1); StopCdda(); StopReading(); cdr.OCUP = 0; cdr.StatP&=~0x20; cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; cdr.Stat = DataEnd; */ AddIrqQueue(CdlPause, 0x400); break; case READ_ACK: if (!cdr.Reading) return; SetResultSize(1); cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; if (cdr.Seeked == 0) { cdr.Seeked = 1; cdr.StatP|= 0x40; } cdr.StatP|= 0x20; cdr.Stat = Acknowledge; ReadTrack(); // CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); CDREAD_INT(0x40000); break; case REPPLAY_ACK: cdr.Stat = Acknowledge; cdr.Result[0] = cdr.StatP; SetResultSize(1); AddIrqQueue(REPPLAY, cdReadTime); break; case REPPLAY: if ((cdr.Mode & 5) != 5) break; /* if (CDR_getStatus(&stat) == -1) { cdr.Result[0] = 0; cdr.Result[1] = 0; cdr.Result[2] = 0; cdr.Result[3] = 0; cdr.Result[4] = 0; cdr.Result[5] = 0; cdr.Result[6] = 0; cdr.Result[7] = 0; } else memcpy(cdr.Result, &stat.Track, 8); cdr.Stat = 1; SetResultSize(8); AddIrqQueue(REPPLAY_ACK, cdReadTime); */ break; case 0xff: return; default: cdr.Stat = Complete; break; } if (cdr.Stat != NoIntr && cdr.Reg2 != 0x18) { psxHu32ref(0x1070)|= SWAP32((u32)0x4); psxRegs.interrupt|= 0x80000000; } #ifdef CDR_LOG CDR_LOG("cdrInterrupt() Log: CDR Interrupt IRQ %x\n", Irq); #endif }
// also handles seek void cdrPlayInterrupt() { if (cdr.Seeked == SEEK_PENDING) { if (cdr.Stat) { CDR_LOG_I("cdrom: seek stat hack\n"); CDRMISC_INT(0x1000); return; } SetResultSize(1); cdr.StatP |= STATUS_ROTATING; cdr.StatP &= ~STATUS_SEEK; cdr.Result[0] = cdr.StatP; cdr.Seeked = SEEK_DONE; if (cdr.Irq == 0) { cdr.Stat = Complete; setIrq(); } if (cdr.SetlocPending) { memcpy(cdr.SetSectorPlay, cdr.SetSector, 4); cdr.SetlocPending = 0; } Find_CurTrack(cdr.SetSectorPlay); ReadTrack(cdr.SetSectorPlay); cdr.TrackChanged = FALSE; } if (!cdr.Play) return; CDR_LOG( "CDDA - %d:%d:%d\n", cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2] ); if (memcmp(cdr.SetSectorPlay, cdr.SetSectorEnd, 3) == 0) { StopCdda(); cdr.TrackChanged = TRUE; } if (!cdr.Irq && !cdr.Stat && (cdr.Mode & (MODE_AUTOPAUSE|MODE_REPORT))) cdrPlayInterrupt_Autopause(); if (!cdr.Play) return; cdr.SetSectorPlay[2]++; if (cdr.SetSectorPlay[2] == 75) { cdr.SetSectorPlay[2] = 0; cdr.SetSectorPlay[1]++; if (cdr.SetSectorPlay[1] == 60) { cdr.SetSectorPlay[1] = 0; cdr.SetSectorPlay[0]++; } } CDRMISC_INT(cdReadTime); // update for CdlGetlocP/autopause generate_subq(cdr.SetSectorPlay); //senquack - Copy/pasted CHUI's ResetIoCycle() call into this new function // TODO: Are these really beneficial/necessary? // CHUI: Añado ResetIoCycle para permite que en el proximo salto entre en psxBranchTest ResetIoCycle(); }