fix yet another portability issue
[picodrive.git] / pico / cd / cd_sys.c
CommitLineData
6cadc2da 1/***********************************************************\r
2 * *\r
8b99ab90 3 * This source file was taken from the Gens project *\r
6cadc2da 4 * Written by Stéphane Dallongeville *\r
5 * Copyright (c) 2002 by Stéphane Dallongeville *\r
6 * Modified/adapted for PicoDrive by notaz, 2007 *\r
7 * *\r
8 ***********************************************************/\r
9\r
cc68a136 10#include <stdio.h>\r
cc68a136 11\r
efcba75f 12#include "../pico_int.h"\r
eff55556 13#include "cd_sys.h"\r
14#include "cd_file.h"\r
cc68a136 15\r
c459aefd 16#define DEBUG_CD\r
cc68a136 17\r
18#define TRAY_OPEN 0x0500 // TRAY OPEN CDD status\r
19#define NOCD 0x0000 // CD removed CDD status\r
20#define STOPPED 0x0900 // STOPPED CDD status (happen after stop or close tray command)\r
21#define READY 0x0400 // READY CDD status (also used for seeking)\r
22#define FAST_FOW 0x0300 // FAST FORWARD track CDD status\r
23#define FAST_REV 0x10300 // FAST REVERSE track CDD status\r
24#define PLAYING 0x0100 // PLAYING audio track CDD status\r
25\r
cc68a136 26\r
cc68a136 27static int CD_Present = 0;\r
cc68a136 28\r
29\r
30#define CHECK_TRAY_OPEN \\r
31if (Pico_mcd->scd.Status_CDD == TRAY_OPEN) \\r
32{ \\r
33 Pico_mcd->cdd.Status = Pico_mcd->scd.Status_CDD; \\r
34 \\r
35 Pico_mcd->cdd.Minute = 0; \\r
36 Pico_mcd->cdd.Seconde = 0; \\r
37 Pico_mcd->cdd.Frame = 0; \\r
38 Pico_mcd->cdd.Ext = 0; \\r
39 \\r
51a902ae 40 Pico_mcd->scd.CDD_Complete = 1; \\r
cc68a136 41 \\r
42 return 2; \\r
43}\r
44\r
45\r
46#define CHECK_CD_PRESENT \\r
47if (!CD_Present) \\r
48{ \\r
49 Pico_mcd->scd.Status_CDD = NOCD; \\r
50 Pico_mcd->cdd.Status = Pico_mcd->scd.Status_CDD; \\r
51 \\r
52 Pico_mcd->cdd.Minute = 0; \\r
53 Pico_mcd->cdd.Seconde = 0; \\r
54 Pico_mcd->cdd.Frame = 0; \\r
55 Pico_mcd->cdd.Ext = 0; \\r
56 \\r
51a902ae 57 Pico_mcd->scd.CDD_Complete = 1; \\r
cc68a136 58 \\r
59 return 3; \\r
60}\r
61\r
62\r
cc68a136 63static int MSF_to_LBA(_msf *MSF)\r
64{\r
65 return (MSF->M * 60 * 75) + (MSF->S * 75) + MSF->F - 150;\r
66}\r
67\r
68\r
eff55556 69PICO_INTERNAL void LBA_to_MSF(int lba, _msf *MSF)\r
cc68a136 70{\r
71 if (lba < -150) lba = 0;\r
72 else lba += 150;\r
73 MSF->M = lba / (60 * 75);\r
74 MSF->S = (lba / 75) % 60;\r
75 MSF->F = lba % 75;\r
76}\r
77\r
78\r
79static unsigned int MSF_to_Track(_msf *MSF)\r
80{\r
81 int i, Start, Cur;\r
82\r
83 Start = (MSF->M << 16) + (MSF->S << 8) + MSF->F;\r
84\r
75736070 85 for(i = 1; i <= (Pico_mcd->TOC.Last_Track + 1); i++)\r
cc68a136 86 {\r
75736070 87 Cur = Pico_mcd->TOC.Tracks[i - 1].MSF.M << 16;\r
88 Cur += Pico_mcd->TOC.Tracks[i - 1].MSF.S << 8;\r
89 Cur += Pico_mcd->TOC.Tracks[i - 1].MSF.F;\r
cc68a136 90\r
91 if (Cur > Start) break;\r
92 }\r
93\r
94 --i;\r
95\r
75736070 96 if (i > Pico_mcd->TOC.Last_Track) return 100;\r
97 else if (i < 1) i = 1;\r
cc68a136 98\r
99 return (unsigned) i;\r
100}\r
101\r
102\r
103static unsigned int LBA_to_Track(int lba)\r
104{\r
105 _msf MSF;\r
106\r
107 LBA_to_MSF(lba, &MSF);\r
108 return MSF_to_Track(&MSF);\r
109}\r
110\r
111\r
112static void Track_to_MSF(int track, _msf *MSF)\r
113{\r
75736070 114 if (track < 1) track = 1;\r
115 else if (track > Pico_mcd->TOC.Last_Track) track = Pico_mcd->TOC.Last_Track;\r
cc68a136 116\r
75736070 117 MSF->M = Pico_mcd->TOC.Tracks[track - 1].MSF.M;\r
118 MSF->S = Pico_mcd->TOC.Tracks[track - 1].MSF.S;\r
119 MSF->F = Pico_mcd->TOC.Tracks[track - 1].MSF.F;\r
cc68a136 120}\r
121\r
122\r
eff55556 123PICO_INTERNAL int Track_to_LBA(int track)\r
cc68a136 124{\r
125 _msf MSF;\r
126\r
127 Track_to_MSF(track, &MSF);\r
128 return MSF_to_LBA(&MSF);\r
129}\r
130\r
131\r
eff55556 132PICO_INTERNAL void Check_CD_Command(void)\r
cc68a136 133{\r
c459aefd 134 cdprintf("CHECK CD COMMAND");\r
cc68a136 135\r
cc68a136 136 // Check CDC\r
cc68a136 137 if (Pico_mcd->scd.Status_CDC & 1) // CDC is reading data ...\r
138 {\r
c459aefd 139 cdprintf("Got a read command");\r
cc68a136 140\r
141 // DATA ?\r
75736070 142 if (Pico_mcd->scd.Cur_Track == 1)\r
cc68a136 143 Pico_mcd->s68k_regs[0x36] |= 0x01;\r
144 else Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO\r
145\r
51a902ae 146 if (Pico_mcd->scd.File_Add_Delay == 0)\r
cc68a136 147 {\r
cc68a136 148 FILE_Read_One_LBA_CDC();\r
cc68a136 149 }\r
51a902ae 150 else Pico_mcd->scd.File_Add_Delay--;\r
cc68a136 151 }\r
152\r
1cd356a3 153 // Check CDD\r
154 if (Pico_mcd->scd.CDD_Complete)\r
155 {\r
156 Pico_mcd->scd.CDD_Complete = 0;\r
157\r
158 CDD_Export_Status();\r
159 }\r
160\r
cc68a136 161 if (Pico_mcd->scd.Status_CDD == FAST_FOW)\r
162 {\r
163 Pico_mcd->scd.Cur_LBA += 10;\r
164 CDC_Update_Header();\r
165\r
166 }\r
167 else if (Pico_mcd->scd.Status_CDD == FAST_REV)\r
168 {\r
169 Pico_mcd->scd.Cur_LBA -= 10;\r
170 if (Pico_mcd->scd.Cur_LBA < -150) Pico_mcd->scd.Cur_LBA = -150;\r
171 CDC_Update_Header();\r
172 }\r
173}\r
174\r
175\r
eff55556 176PICO_INTERNAL int Init_CD_Driver(void)\r
cc68a136 177{\r
cc68a136 178 return 0;\r
179}\r
180\r
181\r
eff55556 182PICO_INTERNAL void End_CD_Driver(void)\r
cc68a136 183{\r
eff55556 184 Unload_ISO();\r
cc68a136 185}\r
186\r
187\r
eff55556 188PICO_INTERNAL void Reset_CD(void)\r
cc68a136 189{\r
190 Pico_mcd->scd.Cur_Track = 0;\r
191 Pico_mcd->scd.Cur_LBA = -150;\r
5c69a605 192 Pico_mcd->scd.Status_CDC &= ~1;\r
721cd396 193 Pico_mcd->scd.Status_CDD = CD_Present ? READY : NOCD;\r
51a902ae 194 Pico_mcd->scd.CDD_Complete = 0;\r
5c69a605 195 Pico_mcd->scd.File_Add_Delay = 0;\r
cc68a136 196}\r
197\r
198\r
35e3031a 199int Insert_CD(const char *cdimg_name, int type)\r
cc68a136 200{\r
b923ecbe 201 int ret = 1;\r
bf098bc5 202\r
bf098bc5 203 CD_Present = 0;\r
721cd396 204 Pico_mcd->scd.Status_CDD = NOCD;\r
bf098bc5 205\r
b923ecbe 206 if (cdimg_name != NULL && type != CIT_NOT_CD)\r
cc68a136 207 {\r
b923ecbe 208 ret = Load_CD_Image(cdimg_name, type);\r
721cd396 209 if (ret == 0) {\r
bf098bc5 210 CD_Present = 1;\r
d687ef50 211 /* for open tray close command will handle Status_CDD */\r
212 if (Pico_mcd->scd.Status_CDD != TRAY_OPEN)\r
213 Pico_mcd->scd.Status_CDD = READY;\r
721cd396 214 }\r
cc68a136 215 }\r
216\r
bf098bc5 217 return ret;\r
cc68a136 218}\r
219\r
220\r
221void Stop_CD(void)\r
222{\r
cc68a136 223 Unload_ISO();\r
cc68a136 224 CD_Present = 0;\r
225}\r
226\r
227\r
eff55556 228/*\r
229PICO_INTERNAL void Change_CD(void)\r
cc68a136 230{\r
231 if (Pico_mcd->scd.Status_CDD == TRAY_OPEN) Close_Tray_CDD_cC();\r
232 else Open_Tray_CDD_cD();\r
233}\r
eff55556 234*/\r
cc68a136 235\r
eff55556 236PICO_INTERNAL int Get_Status_CDD_c0(void)\r
cc68a136 237{\r
c459aefd 238 cdprintf("Status command : Cur LBA = %d", Pico_mcd->scd.Cur_LBA);\r
cc68a136 239\r
240 // Clear immediat status\r
241 if ((Pico_mcd->cdd.Status & 0x0F00) == 0x0200)\r
242 Pico_mcd->cdd.Status = (Pico_mcd->scd.Status_CDD & 0xFF00) | (Pico_mcd->cdd.Status & 0x00FF);\r
243 else if ((Pico_mcd->cdd.Status & 0x0F00) == 0x0700)\r
244 Pico_mcd->cdd.Status = (Pico_mcd->scd.Status_CDD & 0xFF00) | (Pico_mcd->cdd.Status & 0x00FF);\r
245 else if ((Pico_mcd->cdd.Status & 0x0F00) == 0x0E00)\r
246 Pico_mcd->cdd.Status = (Pico_mcd->scd.Status_CDD & 0xFF00) | (Pico_mcd->cdd.Status & 0x00FF);\r
247\r
51a902ae 248 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 249\r
250 return 0;\r
251}\r
252\r
253\r
eff55556 254PICO_INTERNAL int Stop_CDD_c1(void)\r
cc68a136 255{\r
256 CHECK_TRAY_OPEN\r
257\r
258 Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read\r
259\r
260 if (CD_Present) Pico_mcd->scd.Status_CDD = STOPPED;\r
261 else Pico_mcd->scd.Status_CDD = NOCD;\r
262 Pico_mcd->cdd.Status = 0x0000;\r
263\r
264 Pico_mcd->s68k_regs[0x36] |= 0x01; // Data bit set because stopped\r
265\r
266 Pico_mcd->cdd.Minute = 0;\r
267 Pico_mcd->cdd.Seconde = 0;\r
268 Pico_mcd->cdd.Frame = 0;\r
269 Pico_mcd->cdd.Ext = 0;\r
270\r
51a902ae 271 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 272\r
273 return 0;\r
274}\r
275\r
276\r
eff55556 277PICO_INTERNAL int Get_Pos_CDD_c20(void)\r
cc68a136 278{\r
279 _msf MSF;\r
280\r
c459aefd 281 cdprintf("command 200 : Cur LBA = %d", Pico_mcd->scd.Cur_LBA);\r
cc68a136 282\r
283 CHECK_TRAY_OPEN\r
284\r
285 Pico_mcd->cdd.Status &= 0xFF;\r
286 if (!CD_Present)\r
287 {\r
288 Pico_mcd->scd.Status_CDD = NOCD;\r
289 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
290 }\r
291// else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
292 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
293\r
c459aefd 294 cdprintf("Status CDD = %.4X Status = %.4X", Pico_mcd->scd.Status_CDD, Pico_mcd->cdd.Status);\r
cc68a136 295\r
296 LBA_to_MSF(Pico_mcd->scd.Cur_LBA, &MSF);\r
297\r
298 Pico_mcd->cdd.Minute = INT_TO_BCDW(MSF.M);\r
299 Pico_mcd->cdd.Seconde = INT_TO_BCDW(MSF.S);\r
300 Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F);\r
301 Pico_mcd->cdd.Ext = 0;\r
302\r
51a902ae 303 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 304\r
305 return 0;\r
306}\r
307\r
308\r
eff55556 309PICO_INTERNAL int Get_Track_Pos_CDD_c21(void)\r
cc68a136 310{\r
311 int elapsed_time;\r
312 _msf MSF;\r
313\r
314 cdprintf("command 201 : Cur LBA = %d", Pico_mcd->scd.Cur_LBA);\r
315\r
316 CHECK_TRAY_OPEN\r
317\r
318 Pico_mcd->cdd.Status &= 0xFF;\r
319 if (!CD_Present)\r
320 {\r
321 Pico_mcd->scd.Status_CDD = NOCD;\r
322 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
323 }\r
324// else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
325 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
326\r
327 elapsed_time = Pico_mcd->scd.Cur_LBA - Track_to_LBA(LBA_to_Track(Pico_mcd->scd.Cur_LBA));\r
328 LBA_to_MSF(elapsed_time - 150, &MSF);\r
329\r
c459aefd 330 cdprintf(" elapsed = %d", elapsed_time);\r
cc68a136 331\r
332 Pico_mcd->cdd.Minute = INT_TO_BCDW(MSF.M);\r
333 Pico_mcd->cdd.Seconde = INT_TO_BCDW(MSF.S);\r
334 Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F);\r
335 Pico_mcd->cdd.Ext = 0;\r
336\r
51a902ae 337 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 338\r
339 return 0;\r
340}\r
341\r
342\r
eff55556 343PICO_INTERNAL int Get_Current_Track_CDD_c22(void)\r
cc68a136 344{\r
c459aefd 345 cdprintf("Status CDD = %.4X Status = %.4X", Pico_mcd->scd.Status_CDD, Pico_mcd->cdd.Status);\r
cc68a136 346\r
347 CHECK_TRAY_OPEN\r
348\r
349 Pico_mcd->cdd.Status &= 0xFF;\r
350 if (!CD_Present)\r
351 {\r
352 Pico_mcd->scd.Status_CDD = NOCD;\r
353 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
354 }\r
355// else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
356 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
357\r
358 Pico_mcd->scd.Cur_Track = LBA_to_Track(Pico_mcd->scd.Cur_LBA);\r
359\r
360 if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02;\r
361 else Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->scd.Cur_Track);\r
362 Pico_mcd->cdd.Seconde = 0;\r
363 Pico_mcd->cdd.Frame = 0;\r
364 Pico_mcd->cdd.Ext = 0;\r
365\r
51a902ae 366 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 367\r
368 return 0;\r
369}\r
370\r
371\r
eff55556 372PICO_INTERNAL int Get_Total_Lenght_CDD_c23(void)\r
cc68a136 373{\r
374 CHECK_TRAY_OPEN\r
375\r
376 Pico_mcd->cdd.Status &= 0xFF;\r
377 if (!CD_Present)\r
378 {\r
379 Pico_mcd->scd.Status_CDD = NOCD;\r
380 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
381 }\r
382// else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
383 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
384\r
75736070 385 Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->TOC.Tracks[Pico_mcd->TOC.Last_Track].MSF.M);\r
386 Pico_mcd->cdd.Seconde = INT_TO_BCDW(Pico_mcd->TOC.Tracks[Pico_mcd->TOC.Last_Track].MSF.S);\r
387 Pico_mcd->cdd.Frame = INT_TO_BCDW(Pico_mcd->TOC.Tracks[Pico_mcd->TOC.Last_Track].MSF.F);\r
cc68a136 388 Pico_mcd->cdd.Ext = 0;\r
389\r
51a902ae 390 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 391\r
392 return 0;\r
393}\r
394\r
395\r
eff55556 396PICO_INTERNAL int Get_First_Last_Track_CDD_c24(void)\r
cc68a136 397{\r
398 CHECK_TRAY_OPEN\r
399\r
400 Pico_mcd->cdd.Status &= 0xFF;\r
401 if (!CD_Present)\r
402 {\r
403 Pico_mcd->scd.Status_CDD = NOCD;\r
404 }\r
405// else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
406 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
407\r
75736070 408 Pico_mcd->cdd.Minute = INT_TO_BCDW(1);\r
409 Pico_mcd->cdd.Seconde = INT_TO_BCDW(Pico_mcd->TOC.Last_Track);\r
cc68a136 410 Pico_mcd->cdd.Frame = 0;\r
411 Pico_mcd->cdd.Ext = 0;\r
412\r
51a902ae 413 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 414\r
415 return 0;\r
416}\r
417\r
418\r
eff55556 419PICO_INTERNAL int Get_Track_Adr_CDD_c25(void)\r
cc68a136 420{\r
421 int track_number;\r
422\r
423 CHECK_TRAY_OPEN\r
424\r
425 // track number in TC4 & TC5\r
426\r
427 track_number = (Pico_mcd->s68k_regs[0x38+10+4] & 0xF) * 10 + (Pico_mcd->s68k_regs[0x38+10+5] & 0xF);\r
428\r
429 Pico_mcd->cdd.Status &= 0xFF;\r
430 if (!CD_Present)\r
431 {\r
432 Pico_mcd->scd.Status_CDD = NOCD;\r
433 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
434 }\r
435// else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
436 Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD;\r
437\r
75736070 438 if (track_number > Pico_mcd->TOC.Last_Track) track_number = Pico_mcd->TOC.Last_Track;\r
439 else if (track_number < 1) track_number = 1;\r
cc68a136 440\r
75736070 441 Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->TOC.Tracks[track_number - 1].MSF.M);\r
442 Pico_mcd->cdd.Seconde = INT_TO_BCDW(Pico_mcd->TOC.Tracks[track_number - 1].MSF.S);\r
443 Pico_mcd->cdd.Frame = INT_TO_BCDW(Pico_mcd->TOC.Tracks[track_number - 1].MSF.F);\r
cc68a136 444 Pico_mcd->cdd.Ext = track_number % 10;\r
445\r
75736070 446 if (track_number == 1) Pico_mcd->cdd.Frame |= 0x0800; // data track\r
cc68a136 447\r
51a902ae 448 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 449 return 0;\r
450}\r
451\r
452\r
eff55556 453PICO_INTERNAL int Play_CDD_c3(void)\r
cc68a136 454{\r
455 _msf MSF;\r
456 int delay, new_lba;\r
457\r
458 CHECK_TRAY_OPEN\r
459 CHECK_CD_PRESENT\r
460\r
461 // MSF of the track to play in TC buffer\r
462\r
463 MSF.M = (Pico_mcd->s68k_regs[0x38+10+2] & 0xF) * 10 + (Pico_mcd->s68k_regs[0x38+10+3] & 0xF);\r
464 MSF.S = (Pico_mcd->s68k_regs[0x38+10+4] & 0xF) * 10 + (Pico_mcd->s68k_regs[0x38+10+5] & 0xF);\r
465 MSF.F = (Pico_mcd->s68k_regs[0x38+10+6] & 0xF) * 10 + (Pico_mcd->s68k_regs[0x38+10+7] & 0xF);\r
466\r
467 Pico_mcd->scd.Cur_Track = MSF_to_Track(&MSF);\r
468\r
469 new_lba = MSF_to_LBA(&MSF);\r
470 delay = new_lba - Pico_mcd->scd.Cur_LBA;\r
471 if (delay < 0) delay = -delay;\r
472 delay >>= 12;\r
473\r
474 Pico_mcd->scd.Cur_LBA = new_lba;\r
475 CDC_Update_Header();\r
476\r
c459aefd 477 cdprintf("Read : Cur LBA = %d, M=%d, S=%d, F=%d", Pico_mcd->scd.Cur_LBA, MSF.M, MSF.S, MSF.F);\r
cc68a136 478\r
479 if (Pico_mcd->scd.Status_CDD != PLAYING) delay += 20;\r
480\r
481 Pico_mcd->scd.Status_CDD = PLAYING;\r
482 Pico_mcd->cdd.Status = 0x0102;\r
483// Pico_mcd->cdd.Status = COMM_OK;\r
484\r
51a902ae 485 if (Pico_mcd->scd.File_Add_Delay == 0) Pico_mcd->scd.File_Add_Delay = delay;\r
cc68a136 486\r
75736070 487 if (Pico_mcd->scd.Cur_Track == 1)\r
cc68a136 488 {\r
489 Pico_mcd->s68k_regs[0x36] |= 0x01; // DATA\r
490 }\r
491 else\r
492 {\r
493 Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO\r
c9e1affc 494 cdda_start_play();\r
cc68a136 495 }\r
496\r
497 if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02;\r
498 else Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->scd.Cur_Track);\r
499 Pico_mcd->cdd.Seconde = 0;\r
500 Pico_mcd->cdd.Frame = 0;\r
501 Pico_mcd->cdd.Ext = 0;\r
502\r
503 Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC\r
504\r
51a902ae 505 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 506 return 0;\r
507}\r
508\r
509\r
eff55556 510PICO_INTERNAL int Seek_CDD_c4(void)\r
cc68a136 511{\r
512 _msf MSF;\r
513\r
514 CHECK_TRAY_OPEN\r
515 CHECK_CD_PRESENT\r
516\r
517 // MSF to seek in TC buffer\r
518\r
519 MSF.M = (Pico_mcd->s68k_regs[0x38+10+2] & 0xF) * 10 + (Pico_mcd->s68k_regs[0x38+10+3] & 0xF);\r
520 MSF.S = (Pico_mcd->s68k_regs[0x38+10+4] & 0xF) * 10 + (Pico_mcd->s68k_regs[0x38+10+5] & 0xF);\r
521 MSF.F = (Pico_mcd->s68k_regs[0x38+10+6] & 0xF) * 10 + (Pico_mcd->s68k_regs[0x38+10+7] & 0xF);\r
522\r
523 Pico_mcd->scd.Cur_Track = MSF_to_Track(&MSF);\r
524 Pico_mcd->scd.Cur_LBA = MSF_to_LBA(&MSF);\r
525 CDC_Update_Header();\r
526\r
527 Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read\r
528\r
529 Pico_mcd->scd.Status_CDD = READY;\r
530 Pico_mcd->cdd.Status = 0x0200;\r
531\r
532 // DATA ?\r
75736070 533 if (Pico_mcd->scd.Cur_Track == 1)\r
cc68a136 534 Pico_mcd->s68k_regs[0x36] |= 0x01;\r
535 else Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO\r
536\r
537 Pico_mcd->cdd.Minute = 0;\r
538 Pico_mcd->cdd.Seconde = 0;\r
539 Pico_mcd->cdd.Frame = 0;\r
540 Pico_mcd->cdd.Ext = 0;\r
541\r
51a902ae 542 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 543\r
544 return 0;\r
545}\r
546\r
547\r
eff55556 548PICO_INTERNAL int Pause_CDD_c6(void)\r
cc68a136 549{\r
550 CHECK_TRAY_OPEN\r
551 CHECK_CD_PRESENT\r
552\r
553 Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read to start a new one if raw data\r
554\r
555 Pico_mcd->scd.Status_CDD = READY;\r
556 Pico_mcd->cdd.Status = Pico_mcd->scd.Status_CDD;\r
557\r
558 Pico_mcd->s68k_regs[0x36] |= 0x01; // Data bit set because stopped\r
559\r
560 Pico_mcd->cdd.Minute = 0;\r
561 Pico_mcd->cdd.Seconde = 0;\r
562 Pico_mcd->cdd.Frame = 0;\r
563 Pico_mcd->cdd.Ext = 0;\r
564\r
51a902ae 565 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 566\r
567 return 0;\r
568}\r
569\r
570\r
eff55556 571PICO_INTERNAL int Resume_CDD_c7(void)\r
cc68a136 572{\r
573 CHECK_TRAY_OPEN\r
574 CHECK_CD_PRESENT\r
575\r
576 Pico_mcd->scd.Cur_Track = LBA_to_Track(Pico_mcd->scd.Cur_LBA);\r
577\r
578#ifdef DEBUG_CD\r
579 {\r
580 _msf MSF;\r
581 LBA_to_MSF(Pico_mcd->scd.Cur_LBA, &MSF);\r
c459aefd 582 cdprintf("Resume read : Cur LBA = %d, M=%d, S=%d, F=%d", Pico_mcd->scd.Cur_LBA, MSF.M, MSF.S, MSF.F);\r
cc68a136 583 }\r
584#endif\r
585\r
586 Pico_mcd->scd.Status_CDD = PLAYING;\r
587 Pico_mcd->cdd.Status = 0x0102;\r
588\r
75736070 589 if (Pico_mcd->scd.Cur_Track == 1)\r
cc68a136 590 {\r
591 Pico_mcd->s68k_regs[0x36] |= 0x01; // DATA\r
592 }\r
593 else\r
594 {\r
595 Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO\r
c9e1affc 596 cdda_start_play();\r
cc68a136 597 }\r
598\r
599 if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02;\r
600 else Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->scd.Cur_Track);\r
601 Pico_mcd->cdd.Seconde = 0;\r
602 Pico_mcd->cdd.Frame = 0;\r
603 Pico_mcd->cdd.Ext = 0;\r
604\r
605 Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC\r
606\r
51a902ae 607 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 608 return 0;\r
609}\r
610\r
611\r
eff55556 612PICO_INTERNAL int Fast_Foward_CDD_c8(void)\r
cc68a136 613{\r
614 CHECK_TRAY_OPEN\r
615 CHECK_CD_PRESENT\r
616\r
617 Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read\r
618\r
619 Pico_mcd->scd.Status_CDD = FAST_FOW;\r
620 Pico_mcd->cdd.Status = Pico_mcd->scd.Status_CDD | 2;\r
621\r
622 Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->scd.Cur_Track);\r
623 Pico_mcd->cdd.Seconde = 0;\r
624 Pico_mcd->cdd.Frame = 0;\r
625 Pico_mcd->cdd.Ext = 0;\r
626\r
51a902ae 627 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 628\r
629 return 0;\r
630}\r
631\r
632\r
eff55556 633PICO_INTERNAL int Fast_Rewind_CDD_c9(void)\r
cc68a136 634{\r
635 CHECK_TRAY_OPEN\r
636 CHECK_CD_PRESENT\r
637\r
638 Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read\r
639\r
640 Pico_mcd->scd.Status_CDD = FAST_REV;\r
641 Pico_mcd->cdd.Status = Pico_mcd->scd.Status_CDD | 2;\r
642\r
643 Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->scd.Cur_Track);\r
644 Pico_mcd->cdd.Seconde = 0;\r
645 Pico_mcd->cdd.Frame = 0;\r
646 Pico_mcd->cdd.Ext = 0;\r
647\r
51a902ae 648 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 649\r
650 return 0;\r
651}\r
652\r
653\r
eff55556 654PICO_INTERNAL int Close_Tray_CDD_cC(void)\r
cc68a136 655{\r
cc68a136 656 Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read\r
657\r
c6196c0f 658 elprintf(EL_STATUS, "tray close\n");\r
cc68a136 659\r
721cd396 660 if (PicoMCDcloseTray != NULL)\r
d687ef50 661 PicoMCDcloseTray();\r
cc68a136 662\r
721cd396 663 Pico_mcd->scd.Status_CDD = CD_Present ? STOPPED : NOCD;\r
664 Pico_mcd->cdd.Status = 0x0000;\r
cc68a136 665\r
721cd396 666 Pico_mcd->cdd.Minute = 0;\r
667 Pico_mcd->cdd.Seconde = 0;\r
668 Pico_mcd->cdd.Frame = 0;\r
669 Pico_mcd->cdd.Ext = 0;\r
cc68a136 670\r
51a902ae 671 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 672\r
673 return 0;\r
674}\r
675\r
676\r
eff55556 677PICO_INTERNAL int Open_Tray_CDD_cD(void)\r
cc68a136 678{\r
679 CHECK_TRAY_OPEN\r
680\r
681 Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read\r
682\r
c6196c0f 683 elprintf(EL_STATUS, "tray open\n");\r
721cd396 684\r
cc68a136 685 Unload_ISO();\r
cc68a136 686 CD_Present = 0;\r
687\r
721cd396 688 if (PicoMCDopenTray != NULL)\r
689 PicoMCDopenTray();\r
690\r
cc68a136 691 Pico_mcd->scd.Status_CDD = TRAY_OPEN;\r
692 Pico_mcd->cdd.Status = 0x0E00;\r
693\r
694 Pico_mcd->cdd.Minute = 0;\r
695 Pico_mcd->cdd.Seconde = 0;\r
696 Pico_mcd->cdd.Frame = 0;\r
697 Pico_mcd->cdd.Ext = 0;\r
698\r
51a902ae 699 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 700\r
701 return 0;\r
702}\r
703\r
704\r
eff55556 705PICO_INTERNAL int CDD_cA(void)\r
cc68a136 706{\r
707 CHECK_TRAY_OPEN\r
708 CHECK_CD_PRESENT\r
709\r
710 Pico_mcd->scd.Status_CDC &= ~1;\r
711\r
712 Pico_mcd->scd.Status_CDD = READY;\r
713 Pico_mcd->cdd.Status = Pico_mcd->scd.Status_CDD;\r
714\r
715 Pico_mcd->cdd.Minute = 0;\r
716 Pico_mcd->cdd.Seconde = INT_TO_BCDW(1);\r
717 Pico_mcd->cdd.Frame = INT_TO_BCDW(1);\r
718 Pico_mcd->cdd.Ext = 0;\r
719\r
51a902ae 720 Pico_mcd->scd.CDD_Complete = 1;\r
cc68a136 721\r
722 return 0;\r
723}\r
724\r
725\r
eff55556 726PICO_INTERNAL int CDD_Def(void)\r
cc68a136 727{\r
728 Pico_mcd->cdd.Status = Pico_mcd->scd.Status_CDD;\r
729\r
730 Pico_mcd->cdd.Minute = 0;\r
731 Pico_mcd->cdd.Seconde = 0;\r
732 Pico_mcd->cdd.Frame = 0;\r
733 Pico_mcd->cdd.Ext = 0;\r
734\r
735 return 0;\r
736}\r
737\r
738\r