comparison notes/cdd_mcu_notes.txt @ 2060:f1c2415f4d1d segacd

Move old notes into a subdir and add CDD MCU notes
author Michael Pavone <pavone@retrodev.com>
date Sun, 23 Jan 2022 11:11:07 -0800
parents
children
comparison
equal deleted inserted replaced
2059:6399a776e981 2060:f1c2415f4d1d
1 CD Block Clock: 16.9344 MHz
2 MCU Clock divider: 2.1168 MHz (cd clock / 8)
3
4 State at Reset:
5 Status buffer is filled with zero
6 Mechanism is reset
7 Emulation state set to ES_CLOSING
8
9 HSCK active low
10 IRQ active high
11 CDCK active high
12
13 Main Loop:
14 wait for subcode data for next frame
15 seems to be delivered via a "bank" IRQ
16 if servo is not in PLAY state
17 set DOUT and EMP to inactive
18 set MUTE to active
19 elif Q subcode CRC is not valid
20 set MUTE to active
21 elif Q subcode CONTROL field indicates a DATA track
22 set DOUT and MUTE to active
23 set EMP to inactive
24 else
25 set DOUT and MUTE to inactive
26 set EMP based on emphasis bit in Q subcode CONTROL field
27 run drive emulation state machine
28 if we received a valid command last loop
29 populate status buffer based on request format (see table below)
30 if drive error status is valid
31 override status format (2nd nibble) to RF_NOTREADY
32 put error status in STATUS (1st nibble) of status buffer
33 set error status valid to false
34 else
35 put drive status in STATUS (1st nibble) of status buffer
36 Communication with Host via gate array:
37 goes to fail state if HSCK is active (i.e. low)
38 IRQ line is asserted
39 Waits ~2ms (4234 cycles) for HSCK to go active (i.e lo)
40 on timeout, resets outputs to host to inactive and quits comms this loop
41 deasserts irq
42 Sends 10 status nibbles
43 nibbles are inverted
44 HSCK is handshake from host
45 CDCK is handshake frm MCU
46 minimum 77 cycles per nibble
47
48 HSCK 1 (inactive) -> 0 (active)
49 nibble output
50 CDCK 0 (inactive) ->1 (active)
51 HSCK 0->1
52 CDCK 1->0
53 sets status sent flag
54 Gets 10 command nibbles
55 HSCK 1->0
56 nibble input
57 CDCK 0->1
58 HSCK 0->1
59 CDCK 1->0
60 Entire status/command transfer has timeout of ~3ms (6351 cycles)
61 on timeout, resets outputs to host to inactive and quits comms this loop
62 sets command received flag
63 Checksum of command is checked
64 if bad, resets outputs to host to inactive and quits comms this loop
65 set command valid flag
66 resets outputs to host to inactive
67 Runs command from host
68 Generally comms failures cause it to just run a Nop command
69 checksum failures cause drive error status to be set to STATUS_SUMERROR
70 command is specified by first 2 nibbles of command packet
71 second nibble must be zero or command is invalid
72 first nibble must be < 0xE and != 0x5 or command is invalid
73 command is sent to PC
74 command implementation is run
75
76
77 format Absolute
78 if Q subcode CRC is bad OR Q subcode Control ADR mode is not 1 or Q subcode tracknum indicates leadin
79 set status format (2nd nibble) to RF_NOTREADY
80 else
81 store Absolute (RF_A == 0) in status format (2nd nibble)
82 copy ATIME in BCD format from Q subcode buffer to 3rd through 8th nibble (inclusive)
83 store flags in 9th nibble
84 these seem to correspond to the data, emphasis and mute control bits sent to CD hardware
85 format Relative
86 if Q subcode CRC is bad OR Q subcode Control ADR mode is not 1 or Q subcode tracknum indicates leadin
87 set status format (2nd nibble) to RF_NOTREADY
88 else
89 store Relative (RF_R == 1) in status format (2nd nibble)
90 copy relative track TIME in BCD format from Q subcode buffer to 3rd through 8th nibble (inclusive)
91 store flags in 9th nibble
92 these seem to correspond to the data, emphasis and mute control bits sent to CD hardware
93 format Track
94 if Q subcode CRC is bad OR Q subcode Control ADR mode is not 1 or Q subcode tracknum indicates leadin
95 set status format (2nd nibble) to RF_NOTREADY
96 else
97 store Track (RF_T == 2) in status format (2nd nibble)
98 copy track number to 3rd and 4th status buffer nibbles
99 copy Q subcode CONTROL field to 5th status buffer nibble
100 copy Q subcode ADR field to 6th status buffer nibble
101 store flags in 9th nibble
102 these seem to correspond to the data, emphasis and mute control bits sent to CD hardware
103 format TOCO
104 if disc is not validated
105 set status format (2nd nibble) to RF_NOTREADY
106 else
107 set status format (2nd nibble) to RF_TOCO(3)
108 copy leadout start in MM:SS:FF format (BCD) to 3rd through 8th nibble (inclusive)
109 store flags in 9th nibble
110 these seem to correspond to the data, emphasis and mute control bits sent to CD hardware
111 format TOCT
112 if disc is not validated
113 set status format (2nd nibble) to RF_NOTREADY
114 else
115 set status format (2nd nibble) to RF_TOCT(4)
116 copy first track number in BCD format to 3rd and 4th nibbles
117 copy last track number in BCD format to 5th and 6th nibbles
118 copy TOCTVERSION(0) in BCD format to 7th and 8th nibbles
119 store flags in 9th nibble
120 these seem to correspond to the data, emphasis and mute control bits sent to CD hardware
121 format TOCN
122 if disc is not validated
123 set status format (2nd nibble) to RF_NOTREADY
124 store flags in 9th nibble
125 these seem to correspond to the data, emphasis and mute control bits sent to CD hardware
126 else
127 set status format (2nd nibble) to RF_TOCN(5)
128 if requested trac is not valid
129 set status format (2nd nibble) to RF_NOTREADY(F)
130 store flags in 9th nibble
131 these seem to correspond to the data, emphasis and mute control bits sent to CD hardware
132 else
133 copy track start time in MM:SS:FF format (BCD) to 3rd through 8th nibble (includisve)
134 if track is a data track, force MSB of frame to 1
135 notably, since frame numbers sould be <75 this bit would always be zero otherwise
136 store low nibble of BCD track number in 8th nibble
137 format Error
138 set status format (2nd nibble) to RF_E(6)
139 error number is placed in 3rd nibble
140 note emulator always writes 0
141 store flags in 9th nibble
142 these seem to correspond to the data, emphasis and mute control bits sent to CD hardware
143
144 state Stopping:
145 if servo is in STOP status
146 if disc is known present or disc status is unknown
147 set drive status to STOP
148 else
149 set drive status to NODISC
150 state TOCing:
151 if servo is in STOP status
152 if focus is in NOTFOCUSING status
153 set haveDisc to FALSE
154 set haveDiscValid to TRUE
155 set drive status to NODISC
156 else
157 do nothing this tick
158 elif haveDisc is FALSE
159 do nothing this tick (comments suggest this is an abnormal situation)
160 else
161 set drive status to TOCREAD
162 if servo is NOT in PLAY status
163 stop here
164 if haveTOCValid is FALSE
165 process current Q subcode data for TOC entry (see GetTOC)
166 if TOC reading is done
167 set haveTOCValid to true
168 SEEK command is set to mechanism for PBA of program area start
169 stop until next tick
170 else
171 stop until next tick
172 else
173 if havePAValid is TRUE (comments say this isn't supposed to happen)
174 PAUSE command is sent to mechanism
175 else
176 check Q subcode data to see if we have found the start of the Program Area
177 if we have
178 set havePAValid to TRUE
179 SEEK command for start of first track is sent to mechanism
180 PAUSE command is sent to mechanism
181 else if current block Q subcode is invalid or not Mode 1
182 SEEK to next block
183 else
184 SEEK forward 250 blocks
185 state Reading:
186 state Seeking:
187 state Pausing:
188 state Playing:
189 state Cuing:
190 These 5 states share a common implementation
191 if servo status is STOP
192 do nothing
193 elif servo status is SEEK
194 if mechanism error status is NOERROR
195 set drive status to SEEK
196 else
197 STOP command sent to mechanism
198 emulation state set to STOPPING
199 else
200 if servo status is PAUSE
201 if drive status is NOT DISCEND
202 set drive status to PAUSE
203 else
204 if Q subcode CRC is bad OR Q Control ADR is not mode 1 OR Q subcode tracknum is not lead out
205 set drive status to PLAY
206 else
207 PAUSE command sent to mechanism
208 set drive status to DISCEND
209
210 state FWDing:
211 if servo status is STOP
212 do nothing
213 elif servo status is SEEK
214 if mechanism error status is NOERROR
215 set drive status to SCAN
216 else
217 STOP command is sent to mechanism
218 emulation state is set to STOPPING
219 elif servo status is PAUSE
220 set drive status to DISCEND
221 else:
222 set drive status to SCAN
223 if Q subcode CRC is valid AND Q Control ADR is mode 1
224 if Q subcode tracknum indicates leadout
225 PAUSE command is sent to mechanism
226 set drive status to DISCEND
227 else
228 if scanClock is 0
229 get ATIME from current Q subcode block
230 turn it into an LBA, then PBA
231 Add 100 to it
232 SEEK command sent to mechanism
233 reset scanClock to SCANPLAYTIME(10)
234 state RVSing:
235 if servo status is STOP
236 do nothing
237 elif servo status is SEEK
238 if mechanism error status is NOERROR
239 set drive status to SCAN
240 else
241 STOP command is sent to mechanism
242 emulation state is set to STOPPING
243 elif servo status is PAUSE
244 do nothing
245 else
246 set drive status to SCAN
247 if Q subcode CRC is valid AND Q Control ADR is mode 1
248 if Q subcode tracknum indcates we're in the leadin area
249 SEEK command is sent to mechanism for beginning of first track
250 PLAY command is sent to mechanism
251 Set emulation state to PLAYING
252 else
253 if scanClock is 0
254 get ATIME from current Q subcode block
255 turn it into an LBA, then PBA
256 subtract 140 from it
257 SEEK command sent to mechanism
258 reset scanClock to SCANPLAYTIME(10)
259 state Skipping:
260 if servo status is STOP
261 do nothing
262 elif servo status is SEEK
263 if mechanism error status is NOERROR
264 set drive status to TRACKING
265 else
266 STOP command is sent to mechanism
267 emulation state is set to STOPPING
268 elif servo status is PAUSE
269 set drive status to PAUSE
270 else
271 PAUSE command sent to mechanism
272 state DoorClosing:
273 if door state is CLOSING
274 set drive status to TRAYMOVING
275 elif door state is CLOSED
276 set drive status to STOP
277 set request format to absolute
278 set emulation state to CLOSED
279 state DoorClosed:
280 do nothing
281 state DoorOpening:
282 if door state is OPENING
283 set drive status to TRAYMOVING
284 elif door state is OPEN
285 set drive status to DOOROPEN
286 set emulation state to OPEN
287 state DoorOpen:
288 if door status is NOT one of OPEN or OPENING
289 set emulation state to CLOSING
290
291 command Nop
292 command Stop
293 set request format to absolute
294 if drive status is not DOOROPEN and status is notTRAYMOVING
295 send stop command to mechanism
296 set emulation state to ES_STOPPING
297 command Report Request
298 4th nibble specifies request type
299 RF_A(0)
300 set absolute time format
301 RF_R(1)
302 set relative time format
303 RF_T(2)
304 request current track info
305 RF_TOCO(3)
306 request disc completion time
307 will be ignored if disc has not been validated yet
308 drive error status will be set to COMMANDERROR
309 request format will be set back to absolute
310 RF_TOCT(4)
311 request start/end tracks on disc
312 if disc is validated and drive is stopped
313 will seek to start of disc and pause there
314 emulation state set to TOCing
315 if disc is validated and drive is not stopped
316 only request format is changed
317 else
318 prepares memory state for TOC read
319 will seek to start of disc and tell mechanism to play
320 emulation state set to TOCing
321 RF_TOCN(5)
322 request start time of track N
323 if drivestatus is DOOROPEN, TRAYMOVING or STOP
324 command will be ignore dand drive error status will be set to COMMANDERROR
325 request format will be set back to absolute
326 requested track number is in the 5th and 6th nibbles in BCD format
327 SEEK command sent to mechanism for start of disc
328 PAUSE command sent to mechansim
329 emulation state set to TOCing
330 RF_E(6)
331 request error info
332
333 command Read
334 if drive status is DOOROPEN or TRAYMOVING
335 set drive error status to COMMANDERROR and stop processing command
336 check request format, if it's TOCT or TOCN, force it to absolute
337 if disc is not validated
338 set drive error status to COMMANDERROR and stop processing command
339 location specified in MM:SS:FF format (BCD) in the 3rd through 8th nibbles (inclusive)
340 location is converted to an LBA
341 if location >= leadout start
342 set drive error status to COMMANDERROR and stop processing command
343 program area offset is added to location to convert it to a physical block address
344 PBA is adjusted back 4
345 SEEK command is sent to mechanism for adjusted PBA
346 PLAY command is sent to mechanism
347 Emulation state set to Reading
348 command Seek
349 Same as Read, except sends Pause instead of Play for second command to mechanism
350 Emulation state set to Seeking
351 command Pause
352 if drive status is DOOROPEN or TRAYMOVING or SCAN
353 set drive error status to COMMANDERROR and stop processing command
354 check request format, if it's TOCT or TOCN, force it to absolute
355 if disc is not validated
356 set drive error status to COMMANDERROR and stop processing command
357 if drive status is STOP
358 calculates PBA of first track from TOC
359 PBA is NOT adjusted back
360 send SEEK command to mechanism for calculated PBA
361 send PAUSE to mechanism
362 set emulation state to Pausing
363 command Play
364 if drive status is DOOROPEN or TRAYMOVING or DISCEND or DISCIN
365 set drive error status to COMMANDERROR and stop processing command
366 check request format, if it's TOCT or TOCN, force it to absolute
367 if disc is not validated
368 set drive error status to COMMANDERROR and stop processing command
369 if drive status is TOCREAD or STOP
370 calculates PBA of first track from TOC
371 PBA is adjusted back by 4
372 SEEK command is sent to mechanism for adjusted PBA
373 send PLAY command to mechanism
374 set emulation state to Playing
375 command Fwd
376 if drive status is NOT one of PLAY, PAUSE or DISCIN
377 set drive error status to COMMANDERROR and stop processing command
378 check request format, if it's TOCT or TOCN, force it to absolute
379 if disc is not validated
380 set drive error status to COMMANDERROR and stop processing command
381 Send PLAY command to mechanism
382 Emulation state set to Fwding
383 scanClock is set to SCANPLAYTIME(10)??
384 command Rvs
385 if drive status is NOT one of PLAY, PAUSE or DISCEND
386 set drive error status to COMMANDERROR and stop processing command
387 check request format, if it's TOCT or TOCN, force it to absolute
388 if disc is not validated
389 set drive error status to COMMANDERROR and stop processing command
390 Send PLAY command to mechanism
391 Emulation state set to Rvsing
392 command TrackSkip
393 if drive status is NOT one of PLAY, PAUSE or DISCEND
394 set drive error status to COMMANDERROR and stop processing command
395 check request format, if it's TOCT or TOCN, force it to absolute
396 if disc is not validated
397 set drive error status to COMMANDERROR and stop processing command
398 direction to skip is in 4th nibble of command
399 number of tracks to skip is a 16-bit value in the 5th-8th nibbles
400 note tese are physical tracks i.e. loops of the spiral
401 SKIP command is sent to mechanism
402 PAUSE command is sent to mechanism
403 emulation state is set to TSkping
404 command TrackCue
405 if drive status is NOT one of STOP, PLAY, PAUSE, DISCEND, DISCIN or TOCREAD
406 set drive error status to COMMANDERROR and stop processing command
407 if drive status is TOCREAD
408 check request format, if it's TOCT or TOCN, force it to absolute
409 if disc is not validated
410 set drive error status to COMMANDERROR and stop processing command
411 track number is in nibbles 3 and 4 in BCD format
412 calculates PBA of requested track from TOC
413 Sends SEEK command to mechanism for calculated PBA
414 if drive status at start of command was STOP, DISCEND or DISCIN
415 send PLAY command to mechanism
416 emulation state is set to CUING
417 command DoorClose
418 if drive status is NOT one of DOOROPEN or TRAYMOVING
419 set drive error status to COMMANDERROR and stop processing command
420 CLOSE command is set to mechanism
421 emulation state is set to CLOSING
422 command DoorOpen
423 if drive status is DOOROPEN
424 set drive error status to COMMANDERROR and stop processing command
425 if drive servo is not stopped:
426 set request format to absolute
427 OPEN command is sent to mechanism
428 emulation state set to OPENING
429 disc, TOC and program area validitly flags are cleared