bf098bc5 |
1 | /***********************************************************\r |
2 | * *\r |
8b99ab90 |
3 | * This source file was taken from the Gens project *\r |
bf098bc5 |
4 | * Written by Stéphane Dallongeville *\r |
5 | * Copyright (c) 2002 by Stéphane Dallongeville *\r |
6cadc2da |
6 | * Modified/adapted for PicoDrive by notaz, 2007 *\r |
bf098bc5 |
7 | * *\r |
8 | ***********************************************************/\r |
cc68a136 |
9 | \r |
10 | #include "../PicoInt.h"\r |
11 | \r |
cc68a136 |
12 | #define CDC_DMA_SPEED 256\r |
13 | \r |
cc68a136 |
14 | \r |
15 | static void CDD_Reset(void)\r |
16 | {\r |
17 | // Reseting CDD\r |
18 | \r |
19 | memset(Pico_mcd->s68k_regs+0x34, 0, 2*2); // CDD.Fader, CDD.Control\r |
20 | Pico_mcd->cdd.Status = 0;\r |
21 | Pico_mcd->cdd.Minute = 0;\r |
22 | Pico_mcd->cdd.Seconde = 0;\r |
23 | Pico_mcd->cdd.Frame = 0;\r |
24 | Pico_mcd->cdd.Ext = 0;\r |
25 | \r |
26 | // clear receive status and transfer command\r |
27 | memset(Pico_mcd->s68k_regs+0x38, 0, 20);\r |
28 | Pico_mcd->s68k_regs[0x38+9] = 0xF; // Default checksum\r |
29 | }\r |
30 | \r |
31 | \r |
32 | static void CDC_Reset(void)\r |
33 | {\r |
34 | // Reseting CDC\r |
35 | \r |
5c69a605 |
36 | memset(Pico_mcd->cdc.Buffer, 0, sizeof(Pico_mcd->cdc.Buffer));\r |
cc68a136 |
37 | \r |
38 | Pico_mcd->cdc.COMIN = 0;\r |
39 | Pico_mcd->cdc.IFSTAT = 0xFF;\r |
40 | Pico_mcd->cdc.DAC.N = 0;\r |
41 | Pico_mcd->cdc.DBC.N = 0;\r |
42 | Pico_mcd->cdc.HEAD.N = 0x01000000;\r |
43 | Pico_mcd->cdc.PT.N = 0;\r |
44 | Pico_mcd->cdc.WA.N = 2352 * 2;\r |
45 | Pico_mcd->cdc.STAT.N = 0x00000080;\r |
46 | Pico_mcd->cdc.SBOUT = 0;\r |
47 | Pico_mcd->cdc.IFCTRL = 0;\r |
48 | Pico_mcd->cdc.CTRL.N = 0;\r |
49 | \r |
75736070 |
50 | Pico_mcd->cdc.Decode_Reg_Read = 0;\r |
c459aefd |
51 | Pico_mcd->scd.Status_CDC &= ~0x08;\r |
cc68a136 |
52 | }\r |
53 | \r |
54 | \r |
eff55556 |
55 | PICO_INTERNAL void LC89510_Reset(void)\r |
cc68a136 |
56 | {\r |
57 | CDD_Reset();\r |
58 | CDC_Reset();\r |
59 | \r |
cb4a513a |
60 | // clear DMA_Adr & Stop_Watch\r |
61 | memset(Pico_mcd->s68k_regs + 0xA, 0, 4);\r |
cc68a136 |
62 | }\r |
63 | \r |
cc68a136 |
64 | \r |
eff55556 |
65 | PICO_INTERNAL void Update_CDC_TRansfer(int which)\r |
bf098bc5 |
66 | {\r |
0a051f55 |
67 | unsigned int DMA_Adr, dep, length;\r |
bf098bc5 |
68 | unsigned short *dest;\r |
69 | unsigned char *src;\r |
cc68a136 |
70 | \r |
71 | if (Pico_mcd->cdc.DBC.N <= (CDC_DMA_SPEED * 2))\r |
72 | {\r |
bf098bc5 |
73 | length = (Pico_mcd->cdc.DBC.N + 1) >> 1;\r |
c459aefd |
74 | Pico_mcd->scd.Status_CDC &= ~0x08; // Last transfer\r |
bf098bc5 |
75 | Pico_mcd->s68k_regs[4] |= 0x80; // End data transfer\r |
76 | Pico_mcd->s68k_regs[4] &= ~0x40; // no more data ready\r |
77 | Pico_mcd->cdc.IFSTAT |= 0x08; // No more data transfer in progress\r |
cc68a136 |
78 | \r |
bf098bc5 |
79 | if (Pico_mcd->cdc.IFCTRL & 0x40) // DTEIEN = Data Trasnfer End Interrupt Enable ?\r |
cc68a136 |
80 | {\r |
81 | Pico_mcd->cdc.IFSTAT &= ~0x40;\r |
82 | \r |
bf098bc5 |
83 | if (Pico_mcd->s68k_regs[0x33] & (1<<5))\r |
84 | {\r |
ca61ee42 |
85 | elprintf(EL_INTS, "cdc DTE irq 5");\r |
bf098bc5 |
86 | SekInterruptS68k(5);\r |
87 | }\r |
cc68a136 |
88 | }\r |
89 | }\r |
bf098bc5 |
90 | else length = CDC_DMA_SPEED;\r |
91 | \r |
cc68a136 |
92 | \r |
0a051f55 |
93 | // TODO: dst bounds checking?\r |
bf098bc5 |
94 | src = Pico_mcd->cdc.Buffer + Pico_mcd->cdc.DAC.N;\r |
cb4a513a |
95 | DMA_Adr = (Pico_mcd->s68k_regs[0xA]<<8) | Pico_mcd->s68k_regs[0xB];\r |
cc68a136 |
96 | \r |
bf098bc5 |
97 | if (which == 7) // WORD RAM\r |
cc68a136 |
98 | {\r |
bf098bc5 |
99 | if (Pico_mcd->s68k_regs[3] & 4)\r |
cc68a136 |
100 | {\r |
fa1e5e29 |
101 | // test: Final Fight\r |
102 | int bank = !(Pico_mcd->s68k_regs[3]&1);\r |
cb4a513a |
103 | dep = ((DMA_Adr & 0x3FFF) << 3);\r |
bf098bc5 |
104 | cdprintf("CD DMA # %04x -> word_ram1M # %06x, len=%i",\r |
105 | Pico_mcd->cdc.DAC.N, dep, length);\r |
106 | \r |
fa1e5e29 |
107 | dest = (unsigned short *) (Pico_mcd->word_ram1M[bank] + dep);\r |
bf098bc5 |
108 | \r |
0a051f55 |
109 | memcpy16bswap(dest, src, length);\r |
1cd356a3 |
110 | \r |
721cd396 |
111 | /*{ // debug\r |
fa1e5e29 |
112 | unsigned char *b1 = Pico_mcd->word_ram1M[bank] + dep;\r |
0a051f55 |
113 | unsigned char *b2 = (unsigned char *)(dest+length) - 8;\r |
1cd356a3 |
114 | dprintf("%02x %02x %02x %02x .. %02x %02x %02x %02x",\r |
115 | b1[0], b1[1], b1[4], b1[5], b2[0], b2[1], b2[4], b2[5]);\r |
721cd396 |
116 | }*/\r |
cc68a136 |
117 | }\r |
bf098bc5 |
118 | else\r |
119 | {\r |
cb4a513a |
120 | dep = ((DMA_Adr & 0x7FFF) << 3);\r |
bf098bc5 |
121 | cdprintf("CD DMA # %04x -> word_ram2M # %06x, len=%i",\r |
122 | Pico_mcd->cdc.DAC.N, dep, length);\r |
fa1e5e29 |
123 | dest = (unsigned short *) (Pico_mcd->word_ram2M + dep);\r |
cc68a136 |
124 | \r |
0a051f55 |
125 | memcpy16bswap(dest, src, length);\r |
1cd356a3 |
126 | \r |
721cd396 |
127 | /*{ // debug\r |
fa1e5e29 |
128 | unsigned char *b1 = Pico_mcd->word_ram2M + dep;\r |
0a051f55 |
129 | unsigned char *b2 = (unsigned char *)(dest+length) - 4;\r |
1cd356a3 |
130 | dprintf("%02x %02x %02x %02x .. %02x %02x %02x %02x",\r |
131 | b1[0], b1[1], b1[2], b1[3], b2[0], b2[1], b2[2], b2[3]);\r |
721cd396 |
132 | }*/\r |
bf098bc5 |
133 | }\r |
cc68a136 |
134 | }\r |
0a051f55 |
135 | else if (which == 4) // PCM RAM (check: popful Mail)\r |
cc68a136 |
136 | {\r |
0a051f55 |
137 | dep = (DMA_Adr & 0x03FF) << 2;\r |
ca61ee42 |
138 | cdprintf("CD DMA # %04x -> PCM[%i] # %04x, len=%i",\r |
0a051f55 |
139 | Pico_mcd->cdc.DAC.N, Pico_mcd->pcm.bank, dep, length);\r |
140 | dest = (unsigned short *) (Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank] + dep);\r |
141 | \r |
142 | if (Pico_mcd->cdc.DAC.N & 1) /* unaligned src? */\r |
143 | memcpy(dest, src, length*2);\r |
144 | else memcpy16(dest, (unsigned short *) src, length);\r |
bf098bc5 |
145 | }\r |
146 | else if (which == 5) // PRG RAM\r |
147 | {\r |
cb4a513a |
148 | dep = DMA_Adr << 3;\r |
bf098bc5 |
149 | dest = (unsigned short *) (Pico_mcd->prg_ram + dep);\r |
150 | cdprintf("CD DMA # %04x -> prg_ram # %06x, len=%i",\r |
151 | Pico_mcd->cdc.DAC.N, dep, length);\r |
cc68a136 |
152 | \r |
0a051f55 |
153 | memcpy16bswap(dest, src, length);\r |
1cd356a3 |
154 | \r |
721cd396 |
155 | /*{ // debug\r |
1cd356a3 |
156 | unsigned char *b1 = Pico_mcd->prg_ram + dep;\r |
0a051f55 |
157 | unsigned char *b2 = (unsigned char *)(dest+length) - 4;\r |
1cd356a3 |
158 | dprintf("%02x %02x %02x %02x .. %02x %02x %02x %02x",\r |
159 | b1[0], b1[1], b1[2], b1[3], b2[0], b2[1], b2[2], b2[3]);\r |
721cd396 |
160 | }*/\r |
cc68a136 |
161 | }\r |
162 | \r |
bf098bc5 |
163 | length <<= 1;\r |
164 | Pico_mcd->cdc.DAC.N = (Pico_mcd->cdc.DAC.N + length) & 0xFFFF;\r |
c459aefd |
165 | if (Pico_mcd->scd.Status_CDC & 0x08) Pico_mcd->cdc.DBC.N -= length;\r |
cc68a136 |
166 | else Pico_mcd->cdc.DBC.N = 0;\r |
1cd356a3 |
167 | \r |
168 | // update DMA_Adr\r |
169 | length >>= 2;\r |
170 | if (which != 4) length >>= 1;\r |
171 | DMA_Adr += length;\r |
172 | Pico_mcd->s68k_regs[0xA] = DMA_Adr >> 8;\r |
173 | Pico_mcd->s68k_regs[0xB] = DMA_Adr;\r |
cc68a136 |
174 | }\r |
cc68a136 |
175 | \r |
176 | \r |
eff55556 |
177 | PICO_INTERNAL_ASM unsigned short Read_CDC_Host(int is_sub)\r |
cc68a136 |
178 | {\r |
179 | int addr;\r |
180 | \r |
c459aefd |
181 | if (!(Pico_mcd->scd.Status_CDC & 0x08))\r |
cc68a136 |
182 | {\r |
183 | // Transfer data disabled\r |
fa1e5e29 |
184 | cdprintf("Read_CDC_Host FIXME: Transfer data disabled");\r |
cc68a136 |
185 | return 0;\r |
186 | }\r |
187 | \r |
188 | if ((is_sub && (Pico_mcd->s68k_regs[4] & 7) != 3) ||\r |
189 | (!is_sub && (Pico_mcd->s68k_regs[4] & 7) != 2))\r |
190 | {\r |
191 | // Wrong setting\r |
fa1e5e29 |
192 | cdprintf("Read_CDC_Host FIXME: Wrong setting");\r |
cc68a136 |
193 | return 0;\r |
194 | }\r |
195 | \r |
196 | Pico_mcd->cdc.DBC.N -= 2;\r |
197 | \r |
198 | if (Pico_mcd->cdc.DBC.N <= 0)\r |
199 | {\r |
200 | Pico_mcd->cdc.DBC.N = 0;\r |
c459aefd |
201 | Pico_mcd->scd.Status_CDC &= ~0x08; // Last transfer\r |
cc68a136 |
202 | Pico_mcd->s68k_regs[4] |= 0x80; // End data transfer\r |
203 | Pico_mcd->s68k_regs[4] &= ~0x40; // no more data ready\r |
204 | Pico_mcd->cdc.IFSTAT |= 0x08; // No more data transfer in progress\r |
205 | \r |
206 | if (Pico_mcd->cdc.IFCTRL & 0x40) // DTEIEN = Data Transfer End Interrupt Enable ?\r |
207 | {\r |
208 | Pico_mcd->cdc.IFSTAT &= ~0x40;\r |
209 | \r |
210 | if (Pico_mcd->s68k_regs[0x33]&(1<<5)) {\r |
ca61ee42 |
211 | elprintf(EL_INTS, "m68k: s68k irq 5");\r |
cc68a136 |
212 | SekInterruptS68k(5);\r |
213 | }\r |
214 | \r |
c459aefd |
215 | cdprintf("CDC - DTE interrupt");\r |
cc68a136 |
216 | }\r |
217 | }\r |
218 | \r |
219 | addr = Pico_mcd->cdc.DAC.N;\r |
220 | Pico_mcd->cdc.DAC.N += 2;\r |
c459aefd |
221 | \r |
222 | cdprintf("Read_CDC_Host sub=%i d=%04x dac=%04x dbc=%04x", is_sub,\r |
223 | (Pico_mcd->cdc.Buffer[addr]<<8) | Pico_mcd->cdc.Buffer[addr+1], Pico_mcd->cdc.DAC.N, Pico_mcd->cdc.DBC.N);\r |
224 | \r |
cc68a136 |
225 | return (Pico_mcd->cdc.Buffer[addr]<<8) | Pico_mcd->cdc.Buffer[addr+1];\r |
cc68a136 |
226 | }\r |
227 | \r |
228 | \r |
eff55556 |
229 | PICO_INTERNAL void CDC_Update_Header(void)\r |
cc68a136 |
230 | {\r |
231 | if (Pico_mcd->cdc.CTRL.B.B1 & 0x01) // Sub-Header wanted ?\r |
232 | {\r |
233 | Pico_mcd->cdc.HEAD.B.B0 = 0;\r |
234 | Pico_mcd->cdc.HEAD.B.B1 = 0;\r |
235 | Pico_mcd->cdc.HEAD.B.B2 = 0;\r |
236 | Pico_mcd->cdc.HEAD.B.B3 = 0;\r |
237 | }\r |
238 | else\r |
239 | {\r |
240 | _msf MSF;\r |
241 | \r |
242 | LBA_to_MSF(Pico_mcd->scd.Cur_LBA, &MSF);\r |
243 | \r |
244 | Pico_mcd->cdc.HEAD.B.B0 = INT_TO_BCDB(MSF.M);\r |
245 | Pico_mcd->cdc.HEAD.B.B1 = INT_TO_BCDB(MSF.S);\r |
246 | Pico_mcd->cdc.HEAD.B.B2 = INT_TO_BCDB(MSF.F);\r |
247 | Pico_mcd->cdc.HEAD.B.B3 = 0x01;\r |
248 | }\r |
249 | }\r |
250 | \r |
251 | \r |
eff55556 |
252 | PICO_INTERNAL unsigned char CDC_Read_Reg(void)\r |
cc68a136 |
253 | {\r |
254 | unsigned char ret;\r |
255 | \r |
cc68a136 |
256 | switch(Pico_mcd->s68k_regs[5] & 0xF)\r |
257 | {\r |
258 | case 0x0: // COMIN\r |
c459aefd |
259 | cdprintf("CDC read reg 00 = %.2X", Pico_mcd->cdc.COMIN);\r |
cc68a136 |
260 | \r |
261 | Pico_mcd->s68k_regs[5] = 0x1;\r |
262 | return Pico_mcd->cdc.COMIN;\r |
263 | \r |
264 | case 0x1: // IFSTAT\r |
c459aefd |
265 | cdprintf("CDC read reg 01 = %.2X", Pico_mcd->cdc.IFSTAT);\r |
cc68a136 |
266 | \r |
75736070 |
267 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 1); // Reg 1 (decoding)\r |
cc68a136 |
268 | Pico_mcd->s68k_regs[5] = 0x2;\r |
269 | return Pico_mcd->cdc.IFSTAT;\r |
270 | \r |
271 | case 0x2: // DBCL\r |
c459aefd |
272 | cdprintf("CDC read reg 02 = %.2X", Pico_mcd->cdc.DBC.B.L);\r |
cc68a136 |
273 | \r |
274 | Pico_mcd->s68k_regs[5] = 0x3;\r |
275 | return Pico_mcd->cdc.DBC.B.L;\r |
276 | \r |
277 | case 0x3: // DBCH\r |
c459aefd |
278 | cdprintf("CDC read reg 03 = %.2X", Pico_mcd->cdc.DBC.B.H);\r |
cc68a136 |
279 | \r |
280 | Pico_mcd->s68k_regs[5] = 0x4;\r |
281 | return Pico_mcd->cdc.DBC.B.H;\r |
282 | \r |
283 | case 0x4: // HEAD0\r |
c459aefd |
284 | cdprintf("CDC read reg 04 = %.2X", Pico_mcd->cdc.HEAD.B.B0);\r |
cc68a136 |
285 | \r |
75736070 |
286 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 4); // Reg 4 (decoding)\r |
cc68a136 |
287 | Pico_mcd->s68k_regs[5] = 0x5;\r |
288 | return Pico_mcd->cdc.HEAD.B.B0;\r |
289 | \r |
290 | case 0x5: // HEAD1\r |
c459aefd |
291 | cdprintf("CDC read reg 05 = %.2X", Pico_mcd->cdc.HEAD.B.B1);\r |
cc68a136 |
292 | \r |
75736070 |
293 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 5); // Reg 5 (decoding)\r |
cc68a136 |
294 | Pico_mcd->s68k_regs[5] = 0x6;\r |
295 | return Pico_mcd->cdc.HEAD.B.B1;\r |
296 | \r |
297 | case 0x6: // HEAD2\r |
c459aefd |
298 | cdprintf("CDC read reg 06 = %.2X", Pico_mcd->cdc.HEAD.B.B2);\r |
cc68a136 |
299 | \r |
75736070 |
300 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 6); // Reg 6 (decoding)\r |
cc68a136 |
301 | Pico_mcd->s68k_regs[5] = 0x7;\r |
302 | return Pico_mcd->cdc.HEAD.B.B2;\r |
303 | \r |
304 | case 0x7: // HEAD3\r |
c459aefd |
305 | cdprintf("CDC read reg 07 = %.2X", Pico_mcd->cdc.HEAD.B.B3);\r |
cc68a136 |
306 | \r |
75736070 |
307 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 7); // Reg 7 (decoding)\r |
cc68a136 |
308 | Pico_mcd->s68k_regs[5] = 0x8;\r |
309 | return Pico_mcd->cdc.HEAD.B.B3;\r |
310 | \r |
311 | case 0x8: // PTL\r |
c459aefd |
312 | cdprintf("CDC read reg 08 = %.2X", Pico_mcd->cdc.PT.B.L);\r |
cc68a136 |
313 | \r |
75736070 |
314 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 8); // Reg 8 (decoding)\r |
cc68a136 |
315 | Pico_mcd->s68k_regs[5] = 0x9;\r |
316 | return Pico_mcd->cdc.PT.B.L;\r |
317 | \r |
318 | case 0x9: // PTH\r |
c459aefd |
319 | cdprintf("CDC read reg 09 = %.2X", Pico_mcd->cdc.PT.B.H);\r |
cc68a136 |
320 | \r |
75736070 |
321 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 9); // Reg 9 (decoding)\r |
cc68a136 |
322 | Pico_mcd->s68k_regs[5] = 0xA;\r |
323 | return Pico_mcd->cdc.PT.B.H;\r |
324 | \r |
325 | case 0xA: // WAL\r |
c459aefd |
326 | cdprintf("CDC read reg 10 = %.2X", Pico_mcd->cdc.WA.B.L);\r |
cc68a136 |
327 | \r |
328 | Pico_mcd->s68k_regs[5] = 0xB;\r |
329 | return Pico_mcd->cdc.WA.B.L;\r |
330 | \r |
331 | case 0xB: // WAH\r |
c459aefd |
332 | cdprintf("CDC read reg 11 = %.2X", Pico_mcd->cdc.WA.B.H);\r |
cc68a136 |
333 | \r |
334 | Pico_mcd->s68k_regs[5] = 0xC;\r |
335 | return Pico_mcd->cdc.WA.B.H;\r |
336 | \r |
337 | case 0xC: // STAT0\r |
c459aefd |
338 | cdprintf("CDC read reg 12 = %.2X", Pico_mcd->cdc.STAT.B.B0);\r |
cc68a136 |
339 | \r |
75736070 |
340 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 12); // Reg 12 (decoding)\r |
cc68a136 |
341 | Pico_mcd->s68k_regs[5] = 0xD;\r |
342 | return Pico_mcd->cdc.STAT.B.B0;\r |
343 | \r |
344 | case 0xD: // STAT1\r |
c459aefd |
345 | cdprintf("CDC read reg 13 = %.2X", Pico_mcd->cdc.STAT.B.B1);\r |
cc68a136 |
346 | \r |
75736070 |
347 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 13); // Reg 13 (decoding)\r |
cc68a136 |
348 | Pico_mcd->s68k_regs[5] = 0xE;\r |
349 | return Pico_mcd->cdc.STAT.B.B1;\r |
350 | \r |
351 | case 0xE: // STAT2\r |
c459aefd |
352 | cdprintf("CDC read reg 14 = %.2X", Pico_mcd->cdc.STAT.B.B2);\r |
cc68a136 |
353 | \r |
75736070 |
354 | Pico_mcd->cdc.Decode_Reg_Read |= (1 << 14); // Reg 14 (decoding)\r |
cc68a136 |
355 | Pico_mcd->s68k_regs[5] = 0xF;\r |
356 | return Pico_mcd->cdc.STAT.B.B2;\r |
357 | \r |
358 | case 0xF: // STAT3\r |
c459aefd |
359 | cdprintf("CDC read reg 15 = %.2X", Pico_mcd->cdc.STAT.B.B3);\r |
cc68a136 |
360 | \r |
361 | ret = Pico_mcd->cdc.STAT.B.B3;\r |
362 | Pico_mcd->cdc.IFSTAT |= 0x20; // decoding interrupt flag cleared\r |
363 | if ((Pico_mcd->cdc.CTRL.B.B0 & 0x80) && (Pico_mcd->cdc.IFCTRL & 0x20))\r |
364 | {\r |
75736070 |
365 | if ((Pico_mcd->cdc.Decode_Reg_Read & 0x73F2) == 0x73F2)\r |
cc68a136 |
366 | Pico_mcd->cdc.STAT.B.B3 = 0x80;\r |
367 | }\r |
368 | return ret;\r |
369 | }\r |
370 | \r |
371 | return 0;\r |
372 | }\r |
373 | \r |
374 | \r |
eff55556 |
375 | PICO_INTERNAL void CDC_Write_Reg(unsigned char Data)\r |
cc68a136 |
376 | {\r |
c459aefd |
377 | cdprintf("CDC write reg%02d = %.2X", Pico_mcd->s68k_regs[5] & 0xF, Data);\r |
cc68a136 |
378 | \r |
379 | switch (Pico_mcd->s68k_regs[5] & 0xF)\r |
380 | {\r |
381 | case 0x0: // SBOUT\r |
382 | Pico_mcd->s68k_regs[5] = 0x1;\r |
383 | Pico_mcd->cdc.SBOUT = Data;\r |
384 | \r |
385 | break;\r |
386 | \r |
387 | case 0x1: // IFCTRL\r |
388 | Pico_mcd->s68k_regs[5] = 0x2;\r |
389 | Pico_mcd->cdc.IFCTRL = Data;\r |
390 | \r |
391 | if ((Pico_mcd->cdc.IFCTRL & 0x02) == 0) // Stop data transfer\r |
392 | {\r |
393 | Pico_mcd->cdc.DBC.N = 0;\r |
c459aefd |
394 | Pico_mcd->scd.Status_CDC &= ~0x08;\r |
cc68a136 |
395 | Pico_mcd->cdc.IFSTAT |= 0x08; // No more data transfer in progress\r |
396 | }\r |
397 | break;\r |
398 | \r |
399 | case 0x2: // DBCL\r |
400 | Pico_mcd->s68k_regs[5] = 0x3;\r |
401 | Pico_mcd->cdc.DBC.B.L = Data;\r |
402 | \r |
403 | break;\r |
404 | \r |
405 | case 0x3: // DBCH\r |
406 | Pico_mcd->s68k_regs[5] = 0x4;\r |
407 | Pico_mcd->cdc.DBC.B.H = Data;\r |
408 | \r |
409 | break;\r |
410 | \r |
411 | case 0x4: // DACL\r |
412 | Pico_mcd->s68k_regs[5] = 0x5;\r |
413 | Pico_mcd->cdc.DAC.B.L = Data;\r |
414 | \r |
415 | break;\r |
416 | \r |
417 | case 0x5: // DACH\r |
418 | Pico_mcd->s68k_regs[5] = 0x6;\r |
419 | Pico_mcd->cdc.DAC.B.H = Data;\r |
420 | \r |
421 | break;\r |
422 | \r |
423 | case 0x6: // DTTRG\r |
424 | if (Pico_mcd->cdc.IFCTRL & 0x02) // Data transfer enable ?\r |
425 | {\r |
426 | Pico_mcd->cdc.IFSTAT &= ~0x08; // Data transfer in progress\r |
c459aefd |
427 | Pico_mcd->scd.Status_CDC |= 0x08; // Data transfer in progress\r |
cc68a136 |
428 | Pico_mcd->s68k_regs[4] &= 0x7F; // A data transfer start\r |
429 | \r |
c459aefd |
430 | cdprintf("************** Starting Data Transfer ***********");\r |
cc68a136 |
431 | cdprintf("RS0 = %.4X DAC = %.4X DBC = %.4X DMA adr = %.4X\n\n", Pico_mcd->s68k_regs[4]<<8,\r |
cb4a513a |
432 | Pico_mcd->cdc.DAC.N, Pico_mcd->cdc.DBC.N, (Pico_mcd->s68k_regs[0xA]<<8) | Pico_mcd->s68k_regs[0xB]);\r |
cc68a136 |
433 | }\r |
434 | break;\r |
435 | \r |
436 | case 0x7: // DTACK\r |
437 | Pico_mcd->cdc.IFSTAT |= 0x40; // end data transfer interrupt flag cleared\r |
438 | break;\r |
439 | \r |
440 | case 0x8: // WAL\r |
441 | Pico_mcd->s68k_regs[5] = 0x9;\r |
442 | Pico_mcd->cdc.WA.B.L = Data;\r |
443 | \r |
444 | break;\r |
445 | \r |
446 | case 0x9: // WAH\r |
447 | Pico_mcd->s68k_regs[5] = 0xA;\r |
448 | Pico_mcd->cdc.WA.B.H = Data;\r |
449 | \r |
450 | break;\r |
451 | \r |
452 | case 0xA: // CTRL0\r |
453 | Pico_mcd->s68k_regs[5] = 0xB;\r |
454 | Pico_mcd->cdc.CTRL.B.B0 = Data;\r |
455 | \r |
456 | break;\r |
457 | \r |
458 | case 0xB: // CTRL1\r |
459 | Pico_mcd->s68k_regs[5] = 0xC;\r |
460 | Pico_mcd->cdc.CTRL.B.B1 = Data;\r |
461 | \r |
462 | break;\r |
463 | \r |
464 | case 0xC: // PTL\r |
465 | Pico_mcd->s68k_regs[5] = 0xD;\r |
466 | Pico_mcd->cdc.PT.B.L = Data;\r |
467 | \r |
468 | break;\r |
469 | \r |
470 | case 0xD: // PTH\r |
471 | Pico_mcd->s68k_regs[5] = 0xE;\r |
472 | Pico_mcd->cdc.PT.B.H = Data;\r |
473 | \r |
474 | break;\r |
475 | \r |
476 | case 0xE: // CTRL2\r |
477 | Pico_mcd->cdc.CTRL.B.B2 = Data;\r |
478 | break;\r |
479 | \r |
480 | case 0xF: // RESET\r |
481 | CDC_Reset();\r |
482 | break;\r |
483 | }\r |
484 | }\r |
485 | \r |
486 | \r |
487 | static int bswapwrite(int a, unsigned short d)\r |
488 | {\r |
489 | *(unsigned short *)(Pico_mcd->s68k_regs + a) = (d>>8)|(d<<8);\r |
490 | return d + (d >> 8);\r |
491 | }\r |
492 | \r |
eff55556 |
493 | PICO_INTERNAL void CDD_Export_Status(void)\r |
cc68a136 |
494 | {\r |
495 | unsigned int csum;\r |
496 | \r |
497 | csum = bswapwrite( 0x38+0, Pico_mcd->cdd.Status);\r |
498 | csum += bswapwrite( 0x38+2, Pico_mcd->cdd.Minute);\r |
499 | csum += bswapwrite( 0x38+4, Pico_mcd->cdd.Seconde);\r |
500 | csum += bswapwrite( 0x38+6, Pico_mcd->cdd.Frame);\r |
501 | Pico_mcd->s68k_regs[0x38+8] = Pico_mcd->cdd.Ext;\r |
502 | csum += Pico_mcd->cdd.Ext;\r |
503 | Pico_mcd->s68k_regs[0x38+9] = ~csum & 0xf;\r |
504 | \r |
672ad671 |
505 | Pico_mcd->s68k_regs[0x37] &= 3; // CDD.Control\r |
cc68a136 |
506 | \r |
507 | if (Pico_mcd->s68k_regs[0x33] & (1<<4))\r |
508 | {\r |
ca61ee42 |
509 | elprintf(EL_INTS, "cdd export irq 4");\r |
cc68a136 |
510 | SekInterruptS68k(4);\r |
511 | }\r |
512 | \r |
c459aefd |
513 | // cdprintf("CDD exported status\n");\r |
514 | cdprintf("out: Status=%.4X, Minute=%.4X, Second=%.4X, Frame=%.4X Checksum=%.4X",\r |
cc68a136 |
515 | (Pico_mcd->s68k_regs[0x38+0] << 8) | Pico_mcd->s68k_regs[0x38+1],\r |
516 | (Pico_mcd->s68k_regs[0x38+2] << 8) | Pico_mcd->s68k_regs[0x38+3],\r |
517 | (Pico_mcd->s68k_regs[0x38+4] << 8) | Pico_mcd->s68k_regs[0x38+5],\r |
518 | (Pico_mcd->s68k_regs[0x38+6] << 8) | Pico_mcd->s68k_regs[0x38+7],\r |
519 | (Pico_mcd->s68k_regs[0x38+8] << 8) | Pico_mcd->s68k_regs[0x38+9]);\r |
520 | }\r |
521 | \r |
522 | \r |
eff55556 |
523 | PICO_INTERNAL void CDD_Import_Command(void)\r |
cc68a136 |
524 | {\r |
c459aefd |
525 | // cdprintf("CDD importing command\n");\r |
526 | cdprintf("in: Command=%.4X, Minute=%.4X, Second=%.4X, Frame=%.4X Checksum=%.4X",\r |
cc68a136 |
527 | (Pico_mcd->s68k_regs[0x38+10+0] << 8) | Pico_mcd->s68k_regs[0x38+10+1],\r |
528 | (Pico_mcd->s68k_regs[0x38+10+2] << 8) | Pico_mcd->s68k_regs[0x38+10+3],\r |
529 | (Pico_mcd->s68k_regs[0x38+10+4] << 8) | Pico_mcd->s68k_regs[0x38+10+5],\r |
530 | (Pico_mcd->s68k_regs[0x38+10+6] << 8) | Pico_mcd->s68k_regs[0x38+10+7],\r |
531 | (Pico_mcd->s68k_regs[0x38+10+8] << 8) | Pico_mcd->s68k_regs[0x38+10+9]);\r |
532 | \r |
533 | switch (Pico_mcd->s68k_regs[0x38+10+0])\r |
534 | {\r |
535 | case 0x0: // STATUS (?)\r |
536 | Get_Status_CDD_c0();\r |
537 | break;\r |
538 | \r |
539 | case 0x1: // STOP ALL (?)\r |
540 | Stop_CDD_c1();\r |
541 | break;\r |
542 | \r |
543 | case 0x2: // GET TOC INFORMATIONS\r |
544 | switch(Pico_mcd->s68k_regs[0x38+10+3])\r |
545 | {\r |
546 | case 0x0: // get current position (MSF format)\r |
547 | Pico_mcd->cdd.Status = (Pico_mcd->cdd.Status & 0xFF00);\r |
548 | Get_Pos_CDD_c20();\r |
549 | break;\r |
550 | \r |
551 | case 0x1: // get elapsed time of current track played/scanned (relative MSF format)\r |
552 | Pico_mcd->cdd.Status = (Pico_mcd->cdd.Status & 0xFF00) | 1;\r |
553 | Get_Track_Pos_CDD_c21();\r |
554 | break;\r |
555 | \r |
556 | case 0x2: // get current track in RS2-RS3\r |
557 | Pico_mcd->cdd.Status = (Pico_mcd->cdd.Status & 0xFF00) | 2;\r |
558 | Get_Current_Track_CDD_c22();\r |
559 | break;\r |
560 | \r |
bf098bc5 |
561 | case 0x3: // get total length (MSF format)\r |
cc68a136 |
562 | Pico_mcd->cdd.Status = (Pico_mcd->cdd.Status & 0xFF00) | 3;\r |
563 | Get_Total_Lenght_CDD_c23();\r |
564 | break;\r |
565 | \r |
566 | case 0x4: // first & last track number\r |
567 | Pico_mcd->cdd.Status = (Pico_mcd->cdd.Status & 0xFF00) | 4;\r |
568 | Get_First_Last_Track_CDD_c24();\r |
569 | break;\r |
570 | \r |
571 | case 0x5: // get track addresse (MSF format)\r |
572 | Pico_mcd->cdd.Status = (Pico_mcd->cdd.Status & 0xFF00) | 5;\r |
573 | Get_Track_Adr_CDD_c25();\r |
574 | break;\r |
575 | \r |
576 | default : // invalid, then we return status\r |
577 | Pico_mcd->cdd.Status = (Pico_mcd->cdd.Status & 0xFF00) | 0xF;\r |
578 | Get_Status_CDD_c0();\r |
579 | break;\r |
580 | }\r |
581 | break;\r |
582 | \r |
583 | case 0x3: // READ\r |
584 | Play_CDD_c3();\r |
585 | break;\r |
586 | \r |
587 | case 0x4: // SEEK\r |
588 | Seek_CDD_c4();\r |
589 | break;\r |
590 | \r |
591 | case 0x6: // PAUSE/STOP\r |
592 | Pause_CDD_c6();\r |
593 | break;\r |
594 | \r |
595 | case 0x7: // RESUME\r |
596 | Resume_CDD_c7();\r |
597 | break;\r |
598 | \r |
599 | case 0x8: // FAST FOWARD\r |
600 | Fast_Foward_CDD_c8();\r |
601 | break;\r |
602 | \r |
603 | case 0x9: // FAST REWIND\r |
604 | Fast_Rewind_CDD_c9();\r |
605 | break;\r |
606 | \r |
607 | case 0xA: // RECOVER INITIAL STATE (?)\r |
608 | CDD_cA();\r |
609 | break;\r |
610 | \r |
611 | case 0xC: // CLOSE TRAY\r |
612 | Close_Tray_CDD_cC();\r |
613 | break;\r |
614 | \r |
615 | case 0xD: // OPEN TRAY\r |
616 | Open_Tray_CDD_cD();\r |
617 | break;\r |
618 | \r |
619 | default: // UNKNOWN\r |
620 | CDD_Def();\r |
621 | break;\r |
622 | }\r |
623 | }\r |
624 | \r |