25
void SetDisc(bool tray_open, CDIF *cdif, const char disc_id[4]);
18
28
void ResetTS(void);
19
void Update(const pscpu_timestamp_t timestamp);
30
int32 CalcNextEvent(void); // Returns in master cycles to next event.
32
pscpu_timestamp_t Update(const pscpu_timestamp_t timestamp);
21
34
void Write(const pscpu_timestamp_t timestamp, uint32 A, uint8 V);
22
35
uint8 Read(const pscpu_timestamp_t timestamp, uint32 A);
24
37
bool DMACanRead(void);
25
bool DMARead(uint32 &data);
27
INLINE bool GetCDDA(int32 &l, int32 &r)
29
if(CDDABuffer.CanRead())
31
l = (int16)(CDDABuffer.ReadByte() | (CDDABuffer.ReadByte() << 8));
32
r = (int16)(CDDABuffer.ReadByte() | (CDDABuffer.ReadByte() << 8));
40
INLINE uint32 GetCDAudioFreq(void)
42
if(AudioBuffer_UsedCount)
44
const unsigned wb = AudioBuffer_ReadPos >> 12;
45
return AudioBuffer[wb].Freq;
51
inline void ApplyVolume(int32 samples[2])
53
int32 left_source = samples[0]; //(int16)MDFN_de16lsb(&buf[i * sizeof(int16) * 2 + 0]);
54
int32 right_source = samples[1]; //(int16)MDFN_de16lsb(&buf[i * sizeof(int16) * 2 + 2]);
55
int32 left_out = ((left_source * DecodeVolume[0][0]) >> 7) + ((right_source * DecodeVolume[1][0]) >> 7);
56
int32 right_out = ((left_source * DecodeVolume[0][1]) >> 7) + ((right_source * DecodeVolume[1][1]) >> 7);
58
clamp(&left_out, -32768, 32767);
59
clamp(&right_out, -32768, 32767);
61
samples[0] = left_out;
62
samples[1] = right_out;
66
INLINE void GetCDAudio(int32 &l, int32 &r)
68
if(AudioBuffer_UsedCount)
70
const unsigned wb = AudioBuffer_ReadPos >> 12;
71
int32 samples[2] = { AudioBuffer[wb].Samples[0][AudioBuffer_ReadPos & 0xFFF], AudioBuffer[wb].Samples[1][AudioBuffer_ReadPos & 0xFFF] };
78
AudioBuffer_ReadPos = ((AudioBuffer_ReadPos + 1) & 0xFFF) | (AudioBuffer_ReadPos & ~0xFFF);
80
if((AudioBuffer_ReadPos & 0xFFF) == (AudioBuffer[wb].Size & 0xFFF))
82
AudioBuffer_ReadPos = ((((AudioBuffer_ReadPos >> 12) + 1) % AudioBuffer_Count) << 12);
83
AudioBuffer_UsedCount--;
94
int32 DiscStartupDelay;
97
enum { AudioBuffer_Count = 2 };
99
CD_Audio_Buffer AudioBuffer[AudioBuffer_Count];
100
uint32 AudioBuffer_ReadPos;
101
uint32 AudioBuffer_WritePos;
102
uint32 AudioBuffer_UsedCount;
104
uint8 Pending_DecodeVolume[2][2], DecodeVolume[2][2]; // [data_source][output_port]
106
void ClearAudioBuffers(void);
42
109
uint8 ArgsBuf[16];
45
SimpleFIFO<uint8> Results;
110
uint32 ArgsIn; // 5-bit(0 ... 31)
112
uint8 ResultsBuffer[16];
113
uint8 ResultsIn; // 5-bit(0 ... 31)
114
uint8 ResultsWP; // Write position, 4 bit(0 ... 15).
115
uint8 ResultsRP; // Read position, 4 bit(0 ... 15).
117
SimpleFIFO<uint8> DMABuffer;
51
SimpleFIFO<uint8> DMABuffer;
53
SimpleFIFO<uint8> CDDABuffer;
55
122
uint8 SubQBuf[0xC];
56
123
uint8 SubQBuf_Safe[0xC];
57
124
bool SubQChecksumOK;
59
128
void RecalcIRQ(void);
66
135
CDCIRQ_DATA_END = 4,
67
136
CDCIRQ_DISC_ERROR = 5
69
SimpleFIFO<uint8> IRQQueue;
139
// Names are just guessed for these based on what conditions cause them:
142
ERRCODE_BAD_ARGVAL = 0x10,
143
ERRCODE_BAD_NUMARGS = 0x20,
144
ERRCODE_BAD_COMMAND = 0x40,
145
ERRCODE_NOT_READY = 0x80, // 0x80 (happens with getlocl when drive isn't reading, pause when tray is open, and MAYBE when trying to run an async
146
// command while another async command is currently in its asynch phase being executed[pause when in readtoc, todo test more])
150
uint8 IRQOutTestMask;
151
int32 CDCReadyReceiveCounter; // IRQBuffer being non-zero prevents new results and new IRQ from coming in and erasing the current results,
152
// but apparently at least one CONFOUNDED game is clearing the IRQ state BEFORE reading the results, so we need to have a delay
153
// between IRQBuffer being cleared to when we allow new results to come in. (The real thing should be like this too,
154
// but the mechanism is probably more nuanced and complex and ugly and I like anchovy pizza)
156
void BeginResults(void);
71
157
void WriteIRQ(uint8);
72
158
void WriteResult(uint8);
159
uint8 ReadResult(void);
204
unsigned AsyncIRQPending;
205
uint8 AsyncResultsPending[16];
206
uint8 AsyncResultsPendingCount;
210
void SetAIP(unsigned irq, unsigned result_count, uint8 *r);
211
void SetAIP(unsigned irq, uint8 result0);
212
void SetAIP(unsigned irq, uint8 result0, uint8 result1);
112
214
int32 SeekTarget;
114
216
pscpu_timestamp_t lastts;
119
222
int32 CommandLoc;
223
bool CommandLoc_Dirty;
121
225
uint8 MakeStatus(bool cmd_error = false);
122
void DecodeSubQ(uint8 *subpw);
226
bool DecodeSubQ(uint8 *subpw);
227
bool CommandCheckDiscPresent(void);
229
bool XA_Test(const uint8 *sdata);
230
void XA_ProcessSector(const uint8 *sdata, CD_Audio_Buffer *ab);
231
int16 xa_previous[2][2];
124
233
struct CDC_CTEntry
128
237
const char *name;
129
238
int32 (PS_CDC::*func)(const int arg_count, const uint8 *args);
130
239
int32 (PS_CDC::*func2)(void);
133
static CDC_CTEntry Commands[];
242
void BeginSeek(uint32 target);
243
void PreSeekHack(uint32 target);
246
static CDC_CTEntry Commands[0x20];
135
248
int32 Command_Sync(const int arg_count, const uint8 *args);
136
249
int32 Command_Nop(const int arg_count, const uint8 *args);
145
258
int32 Command_Pause(const int arg_count, const uint8 *args);
146
259
int32 Command_Pause_Part2(void);
147
260
int32 Command_Reset(const int arg_count, const uint8 *args);
148
int32 Command_Reset_Part2(void);
149
261
int32 Command_Mute(const int arg_count, const uint8 *args);
150
262
int32 Command_Demute(const int arg_count, const uint8 *args);
151
263
int32 Command_Setfilter(const int arg_count, const uint8 *args);
160
272
int32 Command_GetTN(const int arg_count, const uint8 *args);
161
273
int32 Command_GetTD(const int arg_count, const uint8 *args);
162
274
int32 Command_SeekL(const int arg_count, const uint8 *args);
164
275
int32 Command_SeekP(const int arg_count, const uint8 *args);
276
int32 Command_Seek_PartN(void);
165
278
int32 Command_Test(const int arg_count, const uint8 *args);
167
280
int32 Command_ID(const int arg_count, const uint8 *args);