annotate lc8951.c @ 2274:bf1bb893f104

Properly ignore low bits of SP start address in disassembler
author Michael Pavone <pavone@retrodev.com>
date Thu, 29 Dec 2022 22:44:35 -0800
parents 5c28534e6e09
children 9ead0fe69d9b
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;
2231
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
146 context->triggered = 1;
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
147 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
148 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 case DTACK:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 context->regs[IFSTAT] |= BIT_DTEI;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 case WAL_WRITE:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 context->regs[WAL] = value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 case WAH_WRITE:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 context->regs[WAH] = value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 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
159 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
160 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
161 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
162 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
163 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
164 break;
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 case PTL_WRITE:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 context->regs[PTL] = value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 case PTH_WRITE:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 context->regs[PTH] = value;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
170 //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
171 //Need to do more tests with other CTRL0/CTRL1 settings
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
172 //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
173 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 case RESET:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 context->comin_count = 0;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 context->regs[IFSTAT] = 0xFF;
2080
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2073
diff changeset
177 context->ifctrl = 0;
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2073
diff changeset
178 context->ctrl0 = 0;
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2073
diff changeset
179 context->ctrl1 = 0;
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 default:
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 break;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 if (context->ar != SBOUT) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 context->ar++;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 context->ar &= context->ar_mask;
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
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 uint8_t lc8951_reg_read(lc8951 *context)
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 uint8_t value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
193 if (context->ar == COMIN) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194 if (!context->comin_count) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 return 0xFF;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 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
198 context->comin_count--;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
199 if (!context->comin_count) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 context->regs[IFSTAT] |= BIT_CMDI;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 return value;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 if (context->ar == STAT3) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 context->regs[IFSTAT] |= BIT_DECI;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 }
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 if (context->ar >= sizeof(context->regs)) {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 value = 0xFF;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 } else {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 value = context->regs[context->ar];
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 }
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
212 printf("CDC read %X: %X\n", context->ar, value);
2058
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 context->ar++;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 context->ar &= context->ar_mask;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 return value;
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
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 void lc8951_ar_write(lc8951 *context, uint8_t value)
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 {
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 context->ar = value & context->ar_mask;
70260f6051dd Initial work on CDC emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221 }
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
222
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 //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
224 //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
225 //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
226 //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
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
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 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
230 {
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 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
232 {
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 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
234 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
235 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
236 context->regs[STAT3] &= ~BIT_VALST;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
237 if (context->ctrl0 & BIT_WRRQ) {
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
238 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
239 for (int reg = HEAD0; reg < PTL; reg++)
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
240 {
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
241 context->regs[reg] =context->buffer[block_start++];
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
242 block_start &= (sizeof(context->buffer)-1);
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
243 }
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
244 }
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
245 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
246 // 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
247 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
248 && 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
249 && 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
250 && 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
251 ) {
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
252
2153
8a30e44e8223 Minor CDC fix
Michael Pavone <pavone@retrodev.com>
parents: 2147
diff changeset
253 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
254 context->regs[STAT0] |= BIT_CRCOK;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
255 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
256 context->regs[STAT1] = 0;
2153
8a30e44e8223 Minor CDC fix
Michael Pavone <pavone@retrodev.com>
parents: 2147
diff changeset
257 context->regs[STAT2] = 0x10;
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
258 } else {
2153
8a30e44e8223 Minor CDC fix
Michael Pavone <pavone@retrodev.com>
parents: 2147
diff changeset
259 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
260 context->regs[STAT0] |= BIT_UCEBLK;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
261 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
262 context->regs[STAT1] = 0xFF;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
263 context->regs[STAT2] = 0xF2;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
264 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
265 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
266 }
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
267 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
268 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
269 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
270 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
271 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
272 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
273 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
274 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
275 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
276 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
277 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
278 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
279 }
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
280 context->transfer_end = CYCLE_NEVER;
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
281 context->next_byte_cycle = CYCLE_NEVER;
2231
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
282 context->triggered = 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
283 }
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
284 }
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
285 } else {
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
286 // pause transfer
2144
10e4439d8f13 Fix speed of CDC to PCM RAM DMA
Michael Pavone <pavone@retrodev.com>
parents: 2142
diff changeset
287 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
288 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
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 }
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
292 }
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
293
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
294 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
295 {
2231
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
296 if (context->triggered && context->transfer_end == CYCLE_NEVER && (context->ifctrl & BIT_DOUTEN)) {
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
297 uint16_t transfer_size = context->regs[DBCL] | (context->regs[DBCH] << 8);
2231
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
298 //HACK!!! Work around Sub CPU running longer than we would like and dragging other components with it
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
299 uint32_t step_diff = (context->cycle - cycle) / context->clock_step;
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
300 if (step_diff) {
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
301 context->cycle -= step_diff * context->clock_step;
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
302 }
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
303 context->transfer_end = context->cycle + transfer_size * context->cycles_per_byte;
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
304 context->next_byte_cycle = context->cycle;
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
305 if (step_diff) {
8e6fb2c06024 Fix CDC transfer regression
Michael Pavone <pavone@retrodev.com>
parents: 2153
diff changeset
306 lc8951_run(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
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) {
2265
5c28534e6e09 Fix regression in Thunderhawk
Michael Pavone <pavone@retrodev.com>
parents: 2231
diff changeset
318 // HACK!: The (sector_offset < 0x10) check is not correct, but without it Thunderhawk gets stuck
5c28534e6e09 Fix regression in Thunderhawk
Michael Pavone <pavone@retrodev.com>
parents: 2231
diff changeset
319 // It has a sector that contains the sync pattern in the main data area
5c28534e6e09 Fix regression in Thunderhawk
Michael Pavone <pavone@retrodev.com>
parents: 2231
diff changeset
320 // From the LC8951 datasheet, I would expect tohis to trigger a short block, but either
5c28534e6e09 Fix regression in Thunderhawk
Michael Pavone <pavone@retrodev.com>
parents: 2231
diff changeset
321 // it's sync detection is fancier than I thought or I have a bug that is confusing the BIOS
5c28534e6e09 Fix regression in Thunderhawk
Michael Pavone <pavone@retrodev.com>
parents: 2231
diff changeset
322 if (context->sync_counter == 11 && ((sector_offset & 3) == 3) && (sector_offset < 0x10)) {
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
323 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
324 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
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 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
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 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
329 } 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
330 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
331 }
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 } 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
333 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
334 } 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
335 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
336 }
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 uint8_t sync_inserted = 0;
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
339 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
340 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
341 }
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
342
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
343
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
344 if (context->sector_counter < 4) {
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
345 //TODO: Handle SHDREN = 1
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
346 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
347 //monitor only mode
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
348 context->regs[HEAD0 + context->sector_counter] = byte;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
349 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
350 }
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
351
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
352 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
353 //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
354 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
355 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
356 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
357 }
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
358 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
359 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
360 }
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
361 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
362
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
363 //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
364 context->regs[STAT3] |= BIT_VALST;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
365 //!DECI is set inactive at the same time as !VALST
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
366 context->regs[IFSTAT] |= BIT_DECI;
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
367 //clear error detection status bits
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
368 context->regs[STAT0] &= ~(BIT_CRCOK|BIT_UCEBLK);
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
369 context->regs[STAT3] &= ~BIT_WLONG;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
370 if (context->ctrl0 & BIT_DECEN) {
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
371 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
372 uint16_t block_start = current_write_addr + 1 - 2352;
2067
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
373 context->regs[PTL] = block_start;
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
374 context->regs[PTH] = block_start >> 8;
f22e04b69272 More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents: 2066
diff changeset
375 }
2080
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2073
diff changeset
376 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
377 //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
378 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
379 }
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
380 } else {
2142
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
381 context->sector_counter++;
d9151d0894c7 Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents: 2131
diff changeset
382 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
383 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
384 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
385 }
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
386 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
387 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
388 }
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
389 }
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 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
391 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
392 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
393 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
394 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
395 }
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 }
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
397 }
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
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 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
400 {
2065
02a9846668d1 Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents: 2062
diff changeset
401 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
402 //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
403 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
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 deci_cycle = CYCLE_NEVER;
2131
d90d92ce5cab Improve CDC decode timing accuracy
Michael Pavone <pavone@retrodev.com>
parents: 2130
diff changeset
406 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
407 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
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 uint32_t dtei_cycle = CYCLE_NEVER;
2131
d90d92ce5cab Improve CDC decode timing accuracy
Michael Pavone <pavone@retrodev.com>
parents: 2130
diff changeset
410 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
411 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
412 }
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
413 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
414 }
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
415
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
416 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
417 {
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
418 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
419 context->cycle -= deduction;
2066
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
420 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
421 context->decode_end -= deduction;
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
422 }
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
423 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
424 context->transfer_end -= deduction;
a61a8a87410c Fix a bunch of CDC/CDD related mcd-verificator failures
Michael Pavone <pavone@retrodev.com>
parents: 2065
diff changeset
425 }
2147
4cd60eecb0b1 Fix LC8951 cycle adjustment for data transfer next byte tracking
Michael Pavone <pavone@retrodev.com>
parents: 2144
diff changeset
426 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
427 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
428 }
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
429 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
430 }