annotate lc8951.c @ 2229:f699f9d500b4

Fix build
author Michael Pavone <pavone@retrodev.com>
date Mon, 05 Sep 2022 23:48:17 -0700
parents 8a30e44e8223
children 8e6fb2c06024
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include "lc8951.h"
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
2 #include "backend.h"
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 enum {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 COMIN,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 IFSTAT,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 DBCL,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 DBCH,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 HEAD0,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 HEAD1,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 HEAD2,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 HEAD3,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 PTL,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 PTH,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 WAL,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 WAH,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 STAT0,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 STAT1,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 STAT2,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 STAT3,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 SBOUT = COMIN,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 IFCTRL = IFSTAT,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 DACL = HEAD0,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 DACH = HEAD1,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 DTTRG = HEAD2,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 DTACK = HEAD3,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 WAL_WRITE = PTL,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 WAH_WRITE = PTH,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 CTRL0 = WAL,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 CTRL1 = WAH,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 PTL_WRITE = STAT0,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 PTH_WRITE = STAT1,
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 RESET = STAT3
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 };
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 //IFCTRL
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 #define BIT_CMDIEN 0x80
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 #define BIT_DTEIEN 0x40
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
40 #define BIT_DECIEN 0x20
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 #define BIT_CMDBK 0x10
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 #define BIT_DTWAI 0x08
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 #define BIT_STWAI 0x04
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 #define BIT_DOUTEN 0x02
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 #define BIT_SOUTEN 0x01
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 //IFSTAT
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 #define BIT_CMDI 0x80
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 #define BIT_DTEI 0x40
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 #define BIT_DECI 0x20
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 #define BIT_DTBSY 0x08
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 #define BIT_STBSY 0x04
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 #define BIT_DTEN 0x02
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 #define BIT_STEN 0x01
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
56 //CTRL0
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
57 #define BIT_DECEN 0x80
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
58 #define BIT_WRRQ 0x04
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
59 #define BIT_ORQ 0x02
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
60 #define BIT_PRQ 0x01
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
61
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
62 //CTRL1
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
63 #define BIT_SYIEN 0x80
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
64 #define BIT_SYDEN 0x40
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
65
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
66 //STAT0
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
67 #define BIT_CRCOK 0x80
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
68 #define BIT_ILSYNC 0x40
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
69 #define BIT_NOSYNC 0x20
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
70 #define BIT_LBLK 0x10
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
71 #define BIT_SBLK 0x04
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
72 #define BIT_UCEBLK 0x01
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
73
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
74 //STAT3
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
75 #define BIT_VALST 0x80
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
76 #define BIT_WLONG 0x40
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
77
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 //datasheet timing info
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 //3 cycles for memory operation
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 //6 cycles min for DMA-mode host transfer
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
82 void lc8951_init(lc8951 *context, lcd8951_byte_recv_fun byte_handler, void *handler_data)
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 //This seems to vary somewhat between Sega CD models
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 //unclear if the difference is in the lc8951 or gate array
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 context->regs[IFSTAT] = 0xFF;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 context->ar_mask = 0x1F;
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
88 context->clock_step = (2 + 2); // external divider, internal divider
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
89 context->cycles_per_byte = context->clock_step * 6;
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
90 context->byte_handler = byte_handler;
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
91 context->handler_data = handler_data;
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
92 context->decode_end = CYCLE_NEVER;
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
93 context->transfer_end = CYCLE_NEVER;
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
94 context->next_byte_cycle = CYCLE_NEVER;
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
95 }
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
96
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
97 void lc8951_set_dma_multiple(lc8951 *context, uint32_t multiple)
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
98 {
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
99 context->cycles_per_byte = context->clock_step * multiple;
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
100 if (context->transfer_end != CYCLE_NEVER) {
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
101 uint16_t transfer_size = context->regs[DBCL] | (context->regs[DBCH] << 8);
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
102 context->transfer_end = context->next_byte_cycle + transfer_size * context->cycles_per_byte;
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
103 }
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 void lc8951_reg_write(lc8951 *context, uint8_t value)
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108 switch (context->ar)
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109 {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 case SBOUT:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 context->regs[context->ar] = value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 if (context->ifctrl & BIT_SOUTEN) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 context->regs[IFSTAT] &= ~BIT_STBSY;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
115 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 case IFCTRL:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 context->ifctrl = value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 if (!(value & BIT_SOUTEN)) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 context->regs[IFSTAT] |= BIT_STBSY;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 if (!(value & BIT_DOUTEN)) {
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
122 context->regs[IFSTAT] |= BIT_DTBSY|BIT_DTEI;
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
123 context->transfer_end = CYCLE_NEVER;
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 case DBCL:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 context->regs[context->ar] = value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 case DBCH:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 context->regs[context->ar] = value & 0xF;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 case DACL:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 context->dac &= 0xFF00;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 context->dac |= value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 case DACH:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 context->dac &= 0xFF;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 context->dac |= value << 8;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 case DTTRG:
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
141 if (context->ifctrl & BIT_DOUTEN) {
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 context->regs[IFSTAT] &= ~BIT_DTBSY;
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
143 uint16_t transfer_size = context->regs[DBCL] | (context->regs[DBCH] << 8);
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
144 context->transfer_end = context->cycle + transfer_size * context->cycles_per_byte;
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
145 context->next_byte_cycle = context->cycle;
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
146 printf("DTTRG: size %u, cycle %u, end %u\n", transfer_size, context->cycle, context->transfer_end);
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 case DTACK:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 context->regs[IFSTAT] |= BIT_DTEI;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 case WAL_WRITE:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 context->regs[WAL] = value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 case WAH_WRITE:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 context->regs[WAH] = value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 break;
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
158 case CTRL0:
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
159 context->ctrl0 = value;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
160 break;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
161 case CTRL1:
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
162 context->ctrl1 = value;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
163 break;
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 case PTL_WRITE:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 context->regs[PTL] = value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 case PTH_WRITE:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 context->regs[PTH] = value;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
169 //TODO: Datasheet says any write to PT triggers a decode, but initial tests suggest that's not the case
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
170 //Need to do more tests with other CTRL0/CTRL1 settings
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
171 //context->decode_end = context->cycle + 2352 * context->clock_step * 4;
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 case RESET:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 context->comin_count = 0;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 context->regs[IFSTAT] = 0xFF;
2080
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2073
diff changeset
176 context->ifctrl = 0;
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2073
diff changeset
177 context->ctrl0 = 0;
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2073
diff changeset
178 context->ctrl1 = 0;
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 default:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 if (context->ar != SBOUT) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 context->ar++;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 context->ar &= context->ar_mask;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 uint8_t lc8951_reg_read(lc8951 *context)
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 uint8_t value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 if (context->ar == COMIN) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
193 if (!context->comin_count) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194 return 0xFF;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 value = context->comin[(context->comin_write - context->comin_count)&sizeof(context->comin)];
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 context->comin_count--;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 if (!context->comin_count) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
199 context->regs[IFSTAT] |= BIT_CMDI;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 return value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 if (context->ar == STAT3) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 context->regs[IFSTAT] |= BIT_DECI;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 if (context->ar >= sizeof(context->regs)) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 value = 0xFF;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 } else {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 value = context->regs[context->ar];
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 }
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
211 printf("CDC read %X: %X\n", context->ar, value);
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 context->ar++;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 context->ar &= context->ar_mask;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 return value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 void lc8951_ar_write(lc8951 *context, uint8_t value)
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 context->ar = value & context->ar_mask;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 }
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
221
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
222 //25 MHz clock input (1/2 SCD MCLK)
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
223 //internal /2 divider
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
224 //3 cycles for each SRAM access (though might be crystal frequency rather than internal frequency)
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
225 //6 cycle period for DMA transfer out
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
226 //
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
227
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
228 void lc8951_run(lc8951 *context, uint32_t cycle)
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
229 {
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
230 for(; context->cycle < cycle; context->cycle += context->clock_step)
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
231 {
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
232 if (context->cycle >= context->decode_end) {
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
233 context->decode_end = CYCLE_NEVER;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
234 context->regs[IFSTAT] &= ~BIT_DECI;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
235 context->regs[STAT3] &= ~BIT_VALST;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
236 if (context->ctrl0 & BIT_WRRQ) {
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
237 uint16_t block_start = (context->regs[PTL] | (context->regs[PTH] << 8)) & (sizeof(context->buffer)-1);
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
238 for (int reg = HEAD0; reg < PTL; reg++)
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
239 {
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
240 context->regs[reg] =context->buffer[block_start++];
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
241 block_start &= (sizeof(context->buffer)-1);
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
242 }
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
243 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
244 printf("Decode done %X:%X:%X mode %X\n", context->regs[HEAD0], context->regs[HEAD1], context->regs[HEAD2], context->regs[HEAD3]);
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
245 // This check is a hack until I properly implement error detection
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
246 if (context->regs[HEAD0] < 0x74 && (context->regs[HEAD0] & 0xF) < 0xA
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
247 && context->regs[HEAD1] < 0x60 && (context->regs[HEAD1] & 0xF) < 0xA
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
248 && context->regs[HEAD2] < 0x75 && (context->regs[HEAD2] & 0xF) < 0xA
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
249 && context->regs[HEAD3] < 3 && !(context->regs[STAT0] & (BIT_NOSYNC|BIT_ILSYNC))
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
250 ) {
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
251
2153
8a30e44e8223 Minor CDC fix
Michael Pavone <pavone@retrodev.com>
parents: 2147
diff changeset
252 if (context->ctrl0 & (BIT_WRRQ|BIT_ORQ|BIT_PRQ)) {
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
253 context->regs[STAT0] |= BIT_CRCOK;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
254 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
255 context->regs[STAT1] = 0;
2153
8a30e44e8223 Minor CDC fix
Michael Pavone <pavone@retrodev.com>
parents: 2147
diff changeset
256 context->regs[STAT2] = 0x10;
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
257 } else {
2153
8a30e44e8223 Minor CDC fix
Michael Pavone <pavone@retrodev.com>
parents: 2147
diff changeset
258 if (context->ctrl0 & (BIT_WRRQ|BIT_ORQ|BIT_PRQ)) {
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
259 context->regs[STAT0] |= BIT_UCEBLK;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
260 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
261 context->regs[STAT1] = 0xFF;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
262 context->regs[STAT2] = 0xF2;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
263 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
264 context->regs[STAT3] |= BIT_WLONG;
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
265 }
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
266 if (context->cycle >= context->next_byte_cycle) {
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
267 if (context->byte_handler(context->handler_data, context->buffer[context->dac & (sizeof(context->buffer)-1)])) {
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
268 context->next_byte_cycle += context->cycles_per_byte;
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
269 context->dac++;
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
270 context->regs[DBCL]--;
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
271 if (context->regs[DBCL] == 0xFF) {
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
272 context->regs[DBCH]--;
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
273 if (context->regs[DBCH] == 0xFF) {
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
274 context->regs[IFSTAT] &= ~BIT_DTEI;
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
275 context->regs[IFSTAT] |= BIT_DTBSY;
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
276 if (context->cycle != context->transfer_end) {
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
277 printf("Expected transfer end at %u but ended at %u\n", context->transfer_end, context->cycle);
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
278 }
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
279 context->transfer_end = CYCLE_NEVER;
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
280 context->next_byte_cycle = CYCLE_NEVER;
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
281 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
282 }
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
283 } else {
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
284 // pause transfer
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
285 context->next_byte_cycle = CYCLE_NEVER;
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
286 context->transfer_end = CYCLE_NEVER;
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
287 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
288 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
289 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
290 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
291
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
292 void lc8951_resume_transfer(lc8951 *context, uint32_t cycle)
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
293 {
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
294 if (context->transfer_end == CYCLE_NEVER && (context->ifctrl & BIT_DOUTEN)) {
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
295 uint16_t transfer_size = context->regs[DBCL] | (context->regs[DBCH] << 8);
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
296 if (transfer_size != 0xFFFF) {
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
297 //HACK!!! Work around Sub CPU running longer than we would like and dragging other components with it
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
298 uint32_t step_diff = (context->cycle - cycle) / context->clock_step;
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
299 if (step_diff) {
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
300 context->cycle -= step_diff * context->clock_step;
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
301 }
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
302 context->transfer_end = context->cycle + transfer_size * context->cycles_per_byte;
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
303 context->next_byte_cycle = context->cycle;
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
304 if (step_diff) {
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
305 lc8951_run(context, cycle);
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
306 }
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
307 }
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
308 }
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
309 }
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
310
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
311 void lc8951_write_byte(lc8951 *context, uint32_t cycle, int sector_offset, uint8_t byte)
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
312 {
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
313 lc8951_run(context, cycle);
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
314 uint16_t current_write_addr = context->regs[WAL] | (context->regs[WAH] << 8);
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
315
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
316 uint8_t sync_detected = 0, sync_ignored = 0;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
317 if (byte == 0) {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
318 if (context->sync_counter == 11 && ((sector_offset & 3) == 3)) {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
319 if (context->ctrl1 & BIT_SYDEN) {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
320 sync_detected = 1;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
321 } else {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
322 sync_ignored = 1;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
323 }
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
324 context->sync_counter = 0;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
325 } else {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
326 context->sync_counter = 1;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
327 }
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
328 } else if (byte == 0xFF && context->sync_counter) {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
329 context->sync_counter++;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
330 } else {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
331 context->sync_counter = 0;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
332 }
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
333
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
334 uint8_t sync_inserted = 0;
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
335 if (context->ctrl1 & BIT_SYIEN && context->sector_counter == 2351) {
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
336 sync_inserted = 1;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
337 }
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
338
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
339
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
340 if (context->sector_counter < 4) {
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
341 //TODO: Handle SHDREN = 1
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
342 if ((context->ctrl0 & (BIT_DECEN|BIT_WRRQ)) == (BIT_DECEN)) {
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
343 //monitor only mode
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
344 context->regs[HEAD0 + context->sector_counter] = byte;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
345 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
346 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
347
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
348 if (sync_detected || sync_inserted) {
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
349 //we've recevied the sync pattern for the next block
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
350 context->regs[STAT0] &= ~(BIT_ILSYNC | BIT_NOSYNC | BIT_LBLK | BIT_SBLK);
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
351 if (sync_inserted && !(sync_detected || sync_ignored)) {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
352 context->regs[STAT0] |= BIT_NOSYNC;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
353 }
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
354 if (sync_detected && context->sector_counter != 2351) {
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
355 context->regs[STAT0] |= BIT_ILSYNC;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
356 }
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
357 context->sector_counter = 0;
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
358
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
359 //header/status regs no longer considered "valid"
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
360 context->regs[STAT3] |= BIT_VALST;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
361 //!DECI is set inactive at the same time as !VALST
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
362 context->regs[IFSTAT] |= BIT_DECI;
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
363 //clear error detection status bits
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
364 context->regs[STAT0] &= ~(BIT_CRCOK|BIT_UCEBLK);
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
365 context->regs[STAT3] &= ~BIT_WLONG;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
366 if (context->ctrl0 & BIT_DECEN) {
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
367 if (context->ctrl0 & BIT_WRRQ) {
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
368 uint16_t block_start = current_write_addr + 1 - 2352;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
369 context->regs[PTL] = block_start;
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
370 context->regs[PTH] = block_start >> 8;
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
371 }
2080
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2073
diff changeset
372 printf("Decoding block starting at %X (WRRQ: %d)\n", context->regs[PTL] | (context->regs[PTH] << 8), !!(context->ctrl0 & BIT_WRRQ));
2131
d90d92ce5cab Improve CDC decode timing accuracy
Michael Pavone <pavone@retrodev.com>
parents: 2130
diff changeset
373 //Based on measurements of a Wondermega M1 (LC8951) with SYDEN, SYIEN and DECEN only
d90d92ce5cab Improve CDC decode timing accuracy
Michael Pavone <pavone@retrodev.com>
parents: 2130
diff changeset
374 context->decode_end = context->cycle + 22030 * context->clock_step;
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
375 }
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
376 } else {
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
377 context->sector_counter++;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
378 context->sector_counter &= 0xFFF;
2130
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
379 if (sync_ignored) {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
380 context->regs[STAT0] |= BIT_SBLK;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
381 }
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
382 if (context->sector_counter == 2352) {
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
383 context->regs[STAT0] |= BIT_LBLK;
28b6453cf7e3 Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents: 2122
diff changeset
384 }
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
385 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
386 if ((context->ctrl0 & (BIT_DECEN|BIT_WRRQ)) == (BIT_DECEN|BIT_WRRQ)) {
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
387 context->buffer[current_write_addr & (sizeof(context->buffer)-1)] = byte;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
388 context->regs[WAL]++;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
389 if (!context->regs[WAL]) {
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
390 context->regs[WAH]++;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
391 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
392 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
393 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
394
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
395 uint32_t lc8951_next_interrupt(lc8951 *context)
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
396 {
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
397 if ((~context->regs[IFSTAT]) & context->ifctrl & (BIT_CMDI|BIT_DTEI|BIT_DECI)) {
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
398 //interrupt already pending
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
399 return context->cycle;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
400 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
401 uint32_t deci_cycle = CYCLE_NEVER;
2131
d90d92ce5cab Improve CDC decode timing accuracy
Michael Pavone <pavone@retrodev.com>
parents: 2130
diff changeset
402 if (context->ifctrl & BIT_DECIEN) {
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
403 deci_cycle = context->decode_end;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
404 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
405 uint32_t dtei_cycle = CYCLE_NEVER;
2131
d90d92ce5cab Improve CDC decode timing accuracy
Michael Pavone <pavone@retrodev.com>
parents: 2130
diff changeset
406 if (context->ifctrl & BIT_DTEIEN) {
2062
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
407 dtei_cycle = context->transfer_end;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
408 }
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
409 return deci_cycle < dtei_cycle ? deci_cycle : dtei_cycle;
07ed42bd7b4c Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents: 2058
diff changeset
410 }
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
411
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
412 void lc8951_adjust_cycles(lc8951 *context, uint32_t deduction)
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
413 {
2073
c69e42444f96 Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents: 2067
diff changeset
414 printf("CDC deduction of %u cycles @ %u, ", deduction, context->cycle);
c69e42444f96 Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents: 2067
diff changeset
415 context->cycle -= deduction;
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
416 if (context->decode_end != CYCLE_NEVER) {
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
417 context->decode_end -= deduction;
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
418 }
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
419 if (context->transfer_end != CYCLE_NEVER) {
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
420 context->transfer_end -= deduction;
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
421 }
2147
4cd60eecb0b1 Fix LC8951 cycle adjustment for data transfer next byte tracking
Michael Pavone <pavone@retrodev.com>
parents: 2144
diff changeset
422 if (context->next_byte_cycle != CYCLE_NEVER) {
4cd60eecb0b1 Fix LC8951 cycle adjustment for data transfer next byte tracking
Michael Pavone <pavone@retrodev.com>
parents: 2144
diff changeset
423 context->next_byte_cycle -= deduction;
4cd60eecb0b1 Fix LC8951 cycle adjustment for data transfer next byte tracking
Michael Pavone <pavone@retrodev.com>
parents: 2144
diff changeset
424 }
2073
c69e42444f96 Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents: 2067
diff changeset
425 printf("cycle is now %u, decode_end %u, transfer_end %u\n", context->cycle, context->decode_end, context->transfer_end);
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
426 }