Mercurial > repos > blastem
annotate cdd_mcu.c @ 2208:3809a0bd680e
Fix a couple of Z80 debugger issues
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 27 Aug 2022 22:02:09 -0700 |
parents | c3ee42c89b27 |
children | a8af8d898a7c |
rev | line source |
---|---|
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include "cdd_mcu.h" |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include "backend.h" |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #define SCD_MCLKS 50000000 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #define CD_BLOCK_CLKS 16934400 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #define CDD_MCU_DIVIDER 8 |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
7 #define SECTORS_PER_SECOND 75 |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
8 #define SECTOR_CLOCKS (CD_BLOCK_CLKS/SECTORS_PER_SECOND) |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #define NIBBLE_CLOCKS (CDD_MCU_DIVIDER * 77) |
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:
2061
diff
changeset
|
10 #define BYTE_CLOCKS (SECTOR_CLOCKS/2352) // 96 |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
11 #define SUBCODE_CLOCKS (SECTOR_CLOCKS/98) |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
12 #define PROCESSING_DELAY 54000 //approximate, based on Wondermega M1 measurements |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 //lead in start max diameter 46 mm |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 //program area start max diameter 50 mm |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 //difference 4 mm = 4000 um |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 //radius difference 2 mm = 2000 um |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 //track pitch 1.6 um |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 //1250 physical tracks in between |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 //linear speed 1.2 m/s - 1.4 m/s |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 // 1.3 m = 1300 mm |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 // circumference at 46 mm ~ 144.51 mm |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 // circumference at 50 mm ~ 157.08 mm |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 // avg is 150.795 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 // 75 sectors per second |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 // 17.3333 mm "typical" length of a sector |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 // ~8.7 sectors per track in lead-in area |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 #define LEADIN_SECTORS 10875 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 static uint32_t cd_block_to_mclks(uint32_t cycles) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 return ((uint64_t)cycles) * ((uint64_t)SCD_MCLKS) / ((uint64_t)CD_BLOCK_CLKS); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 static uint32_t mclks_to_cd_block(uint32_t cycles) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 return ((uint64_t)cycles) * ((uint64_t)CD_BLOCK_CLKS) / ((uint64_t)SCD_MCLKS); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 void cdd_mcu_init(cdd_mcu *context, system_media *media) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 context->next_int_cycle = CYCLE_NEVER; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
43 context->next_subcode_int_cycle = CYCLE_NEVER; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
44 context->last_sector_cycle = CYCLE_NEVER; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 context->last_nibble_cycle = CYCLE_NEVER; |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2084
diff
changeset
|
46 context->next_byte_cycle = 0; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
47 context->next_subcode_cycle = CYCLE_NEVER; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 context->requested_format = SF_NOTREADY; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 context->media = media; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 context->current_status_nibble = -1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 context->current_cmd_nibble = -1; |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2075
diff
changeset
|
52 context->current_sector_byte = -1; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
53 context->current_subcode_byte = -1; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
54 context->current_subcode_dest = 0; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 enum { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 GAO_CDD_CTRL, |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 GAO_CDD_STATUS, |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
60 GAO_CDD_CMD = GAO_CDD_STATUS+5, |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
61 GAO_SUBCODE_ADDR = (0x68-0x36)/2, |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
62 GAO_SUBCODE_START = (0x100-0x36)/2 |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 }; |
2080 | 64 //GAO_CDD_CTRL |
65 #define BIT_MUTE 0x100 | |
66 #define BIT_HOCK 0x0004 | |
67 #define BIT_DRS 0x0002 | |
68 #define BIT_DTS 0x0001 | |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 static uint8_t checksum(uint8_t *vbuffer) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 uint8_t *buffer = vbuffer; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 uint8_t sum = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 for (int i = 0; i < 9; i++) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 sum += buffer[i]; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 return (~sum) & 0xF; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 } |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
80 |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
81 #define MIN_CIRCUMFERENCE 144.51f |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
82 #define MAX_CIRCUMFERENCE 364.42f |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
83 #define SECTOR_LENGTH 17.3333f |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
84 // max diameter for program area 116 mm |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
85 // circumference ~ 364.42 mm |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
86 // ~ 21 sectors per physical track at edge |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
87 // ~8 sectors per physical track at start of lead-in |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
88 #define COARSE_SEEK_TRACKS 57 //estimate based on seek test |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 static void handle_seek(cdd_mcu *context) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 { |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
91 uint32_t old_coarse = context->coarse_seek; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 if (context->seeking) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 if (context->seek_pba == context->head_pba) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 context->seeking = 0; |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
95 context->coarse_seek = 0; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
96 if (context->status == DS_PAUSE) { |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
97 context->pause_pba = context->head_pba; |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
98 } |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
99 } else { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
100 //TODO: better estimate of sectors per track at current head location |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
101 //TODO: drive will periodically lose tracking when seeking which slows |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
102 //things down from this ideal speed I'm curently estimating |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
103 float circumference = (MAX_CIRCUMFERENCE-MIN_CIRCUMFERENCE) * ((float)context->head_pba) / (74 * 60 * SECTORS_PER_SECOND) + MIN_CIRCUMFERENCE; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
104 float sectors_per_track = circumference / SECTOR_LENGTH; |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
105 uint32_t max_seek = sectors_per_track * COARSE_SEEK_TRACKS; |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
106 uint32_t min_seek = sectors_per_track; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
107 |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
108 uint32_t old_pba = context->head_pba; |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
109 if (context->seek_pba > context->head_pba) { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
110 uint32_t seek_amount; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
111 for (seek_amount = max_seek; seek_amount >= min_seek; seek_amount >>= 1) |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
112 { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
113 if (context->seek_pba - context->head_pba >= seek_amount) { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
114 break; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
115 } |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
116 } |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
117 if (seek_amount >= min_seek) { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
118 context->head_pba += seek_amount; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
119 } else { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
120 context->head_pba++; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
121 } |
2067
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
122 } else { |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
123 uint32_t seek_amount; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
124 for (seek_amount = max_seek; seek_amount >= min_seek; seek_amount >>= 1) |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
125 { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
126 if (context->head_pba - context->seek_pba >= seek_amount) { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
127 break; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
128 } |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
129 } |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
130 if (seek_amount >= min_seek) { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
131 context->head_pba -= seek_amount; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
132 } else if (context->head_pba >= min_seek){ |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
133 context->head_pba -= min_seek; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
134 } else { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
135 context->head_pba = 0; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
136 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
137 } |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
138 if (context->head_pba != old_pba + 1) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
139 context->coarse_seek++; |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
140 } else { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
141 context->coarse_seek = 0; |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
142 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 } |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
145 if (old_coarse && !context->coarse_seek) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
146 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 static void lba_to_status(cdd_mcu *context, uint32_t lba) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 uint32_t seconds = lba / 75; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 uint32_t frames = lba % 75; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 uint32_t minutes = seconds / 60; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 seconds = seconds % 60; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 context->status_buffer.b.time.min_high = minutes / 10; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 context->status_buffer.b.time.min_low = minutes % 10; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 context->status_buffer.b.time.sec_high = seconds / 10; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 context->status_buffer.b.time.sec_low = seconds % 10; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 context->status_buffer.b.time.frame_high = frames / 10; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 context->status_buffer.b.time.frame_low = frames % 10; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 |
2080 | 163 static void update_status(cdd_mcu *context, uint16_t *gate_array) |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 { |
2080 | 165 gate_array[GAO_CDD_CTRL] |= BIT_MUTE; |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
166 uint32_t prev_pba = context->head_pba; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 switch (context->status) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 case DS_PLAY: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 handle_seek(context); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 if (!context->seeking) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 context->head_pba++; |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
173 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
174 if (context->head_pba >= LEADIN_SECTORS) { |
2080 | 175 uint8_t track = context->media->seek(context->media, context->head_pba - LEADIN_SECTORS); |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
176 if (!context->seeking && context->media->tracks[track].type == TRACK_AUDIO) { |
2080 | 177 gate_array[GAO_CDD_CTRL] &= ~BIT_MUTE; |
178 } | |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 case DS_PAUSE: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 handle_seek(context); |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
183 if (!context->seeking) { |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
184 context->head_pba++; |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
185 //TODO: better estimate of sectors per track at current head location |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
186 float circumference = (MAX_CIRCUMFERENCE-MIN_CIRCUMFERENCE) * ((float)context->head_pba) / (74 * 60 * SECTORS_PER_SECOND) + MIN_CIRCUMFERENCE; |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
187 float sectors_per_track = circumference / SECTOR_LENGTH; |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
188 //TODO: check the exact behavior during pause on hardware |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
189 uint32_t diff = sectors_per_track * 0.5f + 0.5f; |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
190 if (context->head_pba > context->pause_pba + diff) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
191 context->head_pba = context->pause_pba - diff; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
192 if (context->head_pba < LEADIN_SECTORS) { |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
193 context->head_pba = LEADIN_SECTORS; |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
194 } |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
195 } |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
196 } |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
197 if (context->head_pba >= LEADIN_SECTORS) { |
2117
03304d350339
Set force-mute when CD drive is in the pause state
Michael Pavone <pavone@retrodev.com>
parents:
2116
diff
changeset
|
198 context->media->seek(context->media, context->head_pba - LEADIN_SECTORS); |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
199 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 case DS_TOC_READ: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 handle_seek(context); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 if (!context->seeking) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 context->head_pba++; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 if (context->media && context->media->type == MEDIA_CDROM && context->media->num_tracks) { |
2079
5a2b759f6b2d
BIOS doesn't like it if TOC read happens too quickly
Michael Pavone <pavone@retrodev.com>
parents:
2078
diff
changeset
|
206 if (context->head_pba > 3*(context->media->num_tracks + 2)) { |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 context->toc_valid = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 context->seeking = 1; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
209 context->seek_pba = LEADIN_SECTORS + context->media->tracks[0].start_lba + context->media->tracks[0].fake_pregap; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 context->status = DS_PAUSE; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 context->status = DS_NO_DISC; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 break; |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
218 case DS_TRACKING: |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
219 handle_seek(context); |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
220 if (!context->seeking) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
221 context->status = DS_PAUSE; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
222 context->pause_pba = context->head_pba; |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
223 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
224 if (context->head_pba >= LEADIN_SECTORS) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
225 uint8_t track = context->media->seek(context->media, context->head_pba - LEADIN_SECTORS); |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
226 if (!context->seeking && context->media->tracks[track].type == TRACK_AUDIO) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
227 gate_array[GAO_CDD_CTRL] &= ~BIT_MUTE; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
228 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
229 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
230 break; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 } |
2124
ad346054ca78
Return "not ready" status sometimes when seeking. Fixes issues in multiple games
Michael Pavone <pavone@retrodev.com>
parents:
2122
diff
changeset
|
232 uint8_t force_not_ready = 0; |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
233 if (context->coarse_seek && !(context->coarse_seek % 15)) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
234 //TODO: adjust seeking for focus error when these bad statuses happen |
2124
ad346054ca78
Return "not ready" status sometimes when seeking. Fixes issues in multiple games
Michael Pavone <pavone@retrodev.com>
parents:
2122
diff
changeset
|
235 //BIOS depends on getting a not ready status during seeking to clear certain state |
ad346054ca78
Return "not ready" status sometimes when seeking. Fixes issues in multiple games
Michael Pavone <pavone@retrodev.com>
parents:
2122
diff
changeset
|
236 force_not_ready = context->status_buffer.format != SF_NOTREADY; |
ad346054ca78
Return "not ready" status sometimes when seeking. Fixes issues in multiple games
Michael Pavone <pavone@retrodev.com>
parents:
2122
diff
changeset
|
237 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
238 if (context->first_cmd_received) { |
2124
ad346054ca78
Return "not ready" status sometimes when seeking. Fixes issues in multiple games
Michael Pavone <pavone@retrodev.com>
parents:
2122
diff
changeset
|
239 switch (force_not_ready ? SF_NOTREADY : context->requested_format) |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
240 { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
241 case SF_ABSOLUTE: |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
242 if (context->toc_valid && prev_pba >= LEADIN_SECTORS) { |
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
243 lba_to_status(context, prev_pba - LEADIN_SECTORS); |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
244 context->status_buffer.format = SF_ABSOLUTE; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
245 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
246 context->status_buffer.format = SF_NOTREADY; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
247 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
248 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
249 case SF_RELATIVE: |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
250 if (context->toc_valid && prev_pba >= LEADIN_SECTORS) { |
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
251 uint32_t lba =prev_pba - LEADIN_SECTORS; |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
252 for (uint32_t i = 0; i < context->media->num_tracks; i++) |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
253 { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
254 if (lba < context->media->tracks[i].end_lba) { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
255 if (context->media->tracks[i].fake_pregap) { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
256 if (lba > context->media->tracks[i].fake_pregap) { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
257 lba -= context->media->tracks[i].fake_pregap; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
258 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
259 //relative time counts down to 0 in pregap |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
260 lba = context->media->tracks[i].fake_pregap - lba; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
261 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
262 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
263 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
264 if (lba < context->media->tracks[i].start_lba) { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
265 //relative time counts down to 0 in pregap |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
266 lba = context->media->tracks[i].start_lba - lba; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 } else { |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
268 lba -= context->media->tracks[i].start_lba; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
270 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
271 } else if (context->media->tracks[i].fake_pregap) { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
272 lba -= context->media->tracks[i].fake_pregap; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
274 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
275 lba_to_status(context, lba); |
2065
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
276 context->status_buffer.format = SF_RELATIVE; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
277 } else { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
278 context->status_buffer.format = SF_NOTREADY; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
279 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
280 break; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
281 case SF_TRACK: |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
282 if (context->toc_valid && prev_pba >= LEADIN_SECTORS) { |
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
283 uint32_t lba =prev_pba - LEADIN_SECTORS; |
2065
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
284 uint32_t i; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
285 for (i = 0; i < context->media->num_tracks; i++) |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
286 { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
287 if (lba < context->media->tracks[i].end_lba) { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
288 if (context->media->tracks[i].fake_pregap) { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
289 if (lba > context->media->tracks[i].fake_pregap) { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
290 lba -= context->media->tracks[i].fake_pregap; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
291 } else { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
292 //relative time counts down to 0 in pregap |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
293 lba = context->media->tracks[i].fake_pregap - lba; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
294 break; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
295 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
296 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
297 if (lba < context->media->tracks[i].start_lba) { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
298 //relative time counts down to 0 in pregap |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
299 lba = context->media->tracks[i].start_lba - lba; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
300 } else { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
301 lba -= context->media->tracks[i].start_lba; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
302 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
303 break; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
304 } else if (context->media->tracks[i].fake_pregap) { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
305 lba -= context->media->tracks[i].fake_pregap; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
306 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
307 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
308 context->status_buffer.b.track.track_high = (i + 1) / 10; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
309 context->status_buffer.b.track.track_low = (i + 1) % 10; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
310 if (context->media->tracks[i].type == TRACK_DATA) { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
311 context->status_buffer.b.track.control = 4; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
312 } else { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
313 //TODO: pre-emphasis flag |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
314 //TODO: copy permitted flag |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
315 context->status_buffer.b.track.control = 0; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
316 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
317 context->status_buffer.b.track.adr = 1; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
318 context->status_buffer.format = SF_TRACK; |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
319 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
320 context->status_buffer.format = SF_NOTREADY; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
321 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
322 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
323 case SF_TOCO: |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
324 if (context->toc_valid) { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
325 uint32_t total_fake_pregap = 0; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
326 for (uint32_t i = 0; i < context->media->num_tracks; i++) |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
327 { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
328 total_fake_pregap += context->media->tracks[i].fake_pregap; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
330 lba_to_status(context, context->media->tracks[context->media->num_tracks - 1].end_lba + total_fake_pregap); |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
331 context->status_buffer.format = SF_TOCO; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
332 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
333 context->status_buffer.format = SF_NOTREADY; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
335 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
336 case SF_TOCT: |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
337 if (context->toc_valid) { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
338 context->status_buffer.b.toct.first_track_high = 0; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
339 context->status_buffer.b.toct.first_track_low = 1; |
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
|
340 context->status_buffer.b.toct.last_track_high = (context->media->num_tracks) / 10; |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
341 context->status_buffer.b.toct.last_track_low = (context->media->num_tracks) % 10; |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
342 context->status_buffer.b.toct.version = 0; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
343 context->status_buffer.format = SF_TOCT; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
344 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
345 context->status_buffer.format = SF_NOTREADY; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
346 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
347 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
348 case SF_TOCN: |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
349 if (context->toc_valid) { |
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
|
350 if (context->requested_track > context->media->num_tracks) { |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
351 printf("track number %d is bad\n", context->requested_track); |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
352 exit(0); |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
353 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
354 uint32_t lba = context->media->tracks[context->requested_track - 1].start_lba; |
2065
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
355 for (uint32_t i = 0; i < context->requested_track; i++) { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
356 lba += context->media->tracks[i].fake_pregap; |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
357 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
358 lba_to_status(context, lba); |
2065
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
359 if (context->media->tracks[context->requested_track - 1].type == TRACK_DATA) { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
360 context->status_buffer.b.tocn.frame_low |= 0x80; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
361 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
362 context->status_buffer.b.tocn.track_low = context->requested_track % 10; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
363 context->status_buffer.format = SF_TOCN; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
364 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
365 context->status_buffer.format = SF_NOTREADY; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
366 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
367 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
368 case SF_NOTREADY: |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
369 memset(&context->status_buffer, 0, sizeof(context->status_buffer) - 1); |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 context->status_buffer.format = SF_NOTREADY; |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
371 break; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
373 if (context->error_status == DS_STOP) { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
374 if (context->requested_format >= SF_TOCO && context->requested_format <= SF_TOCN) { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
375 context->status_buffer.status = DS_TOC_READ; |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
376 } else if (context->seeking && context->status != DS_TRACKING) { |
2065
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
377 context->status_buffer.status = DS_SEEK; |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
378 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
379 context->status_buffer.status = context->status; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
380 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
381 } else { |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
382 context->status_buffer.status = context->error_status; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 context->status_buffer.format = SF_NOTREADY; |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
384 context->error_status = DS_STOP; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
386 if (context->requested_format != SF_TOCN) { |
2080 | 387 context->status_buffer.b.time.flags = !!(gate_array[GAO_CDD_CTRL] & BIT_MUTE); //TODO: populate these |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
389 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
390 // Did not receive our first command so just send zeroes |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 memset(&context->status_buffer, 0, sizeof(context->status_buffer) - 1); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 context->status_buffer.checksum = checksum((uint8_t *)&context->status_buffer); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 if (context->status_buffer.format != SF_NOTREADY) { |
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:
2061
diff
changeset
|
395 printf("CDD Status %X%X.%X%X%X%X%X%X.%X%X\n", |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 context->status_buffer.status, context->status_buffer.format, |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 context->status_buffer.b.time.min_high, context->status_buffer.b.time.min_low, |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 context->status_buffer.b.time.sec_high, context->status_buffer.b.time.sec_low, |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 context->status_buffer.b.time.frame_high, context->status_buffer.b.time.frame_low, |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 context->status_buffer.b.time.flags, context->status_buffer.checksum |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 ); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 static void run_command(cdd_mcu *context) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 uint8_t check = checksum((uint8_t*)&context->cmd_buffer); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 if (check != context->cmd_buffer.checksum) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 context->error_status = DS_SUM_ERROR; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 return; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 if (context->cmd_buffer.must_be_zero) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 context->error_status = DS_CMD_ERROR; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 return; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
416 context->first_cmd_received = 1; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 switch (context->cmd_buffer.cmd_type) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 case CMD_NOP: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 case CMD_STOP: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 puts("CDD CMD: STOP"); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 context->status = DS_STOP; |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
424 context->requested_format = SF_ABSOLUTE; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 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:
2061
diff
changeset
|
426 case CMD_READ: |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
427 case CMD_SEEK: { |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
428 if (context->status == DS_DOOR_OPEN || context->status == DS_TRAY_MOVING || context->status == DS_DISC_LEADOUT || context->status == DS_DISC_LEADIN) { |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
429 context->error_status = DS_CMD_ERROR; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
430 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:
2061
diff
changeset
|
431 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
432 if (context->requested_format == SF_TOCT || context->requested_format == SF_TOCN || context->requested_format == SF_TOCO) { |
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:
2061
diff
changeset
|
433 context->requested_format = SF_ABSOLUTE; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
434 } |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
435 if (!context->toc_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:
2061
diff
changeset
|
436 context->error_status = DS_CMD_ERROR; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
437 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:
2061
diff
changeset
|
438 } |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
439 uint32_t lba = context->cmd_buffer.b.time.min_high * 10 + context->cmd_buffer.b.time.min_low; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
440 lba *= 60; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
441 lba += context->cmd_buffer.b.time.sec_high * 10 + context->cmd_buffer.b.time.sec_low; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
442 lba *= 75; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
443 lba += context->cmd_buffer.b.time.frame_high * 10 + context->cmd_buffer.b.time.frame_low; |
2067
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
444 printf("CDD CMD: %s cmd for lba %d, MM:SS:FF %u%u:%u%u:%u%u\n", |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
445 context->cmd_buffer.cmd_type == CMD_READ ? "READ" : "SEEK", lba, |
2065
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
446 context->cmd_buffer.b.time.min_high, context->cmd_buffer.b.time.min_low, |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
447 context->cmd_buffer.b.time.sec_high, context->cmd_buffer.b.time.sec_low, |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
448 context->cmd_buffer.b.time.frame_high, context->cmd_buffer.b.time.frame_low |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
449 ); |
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:
2061
diff
changeset
|
450 if (lba >= context->media->tracks[0].fake_pregap + context->media->tracks[context->media->num_tracks - 1].end_lba) { |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
451 context->error_status = DS_CMD_ERROR; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
452 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:
2061
diff
changeset
|
453 } |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
454 context->seek_pba = lba + LEADIN_SECTORS - 3; |
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:
2061
diff
changeset
|
455 context->seeking = 1; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
456 context->status = context->cmd_buffer.cmd_type == CMD_READ ? DS_PLAY : DS_PAUSE; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
457 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:
2061
diff
changeset
|
458 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
459 case CMD_REPORT_REQUEST: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 switch (context->cmd_buffer.b.format.status_type) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 case SF_ABSOLUTE: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 case SF_RELATIVE: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
464 case SF_TRACK: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 context->requested_format = context->cmd_buffer.b.format.status_type; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 case SF_TOCO: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 if (context->toc_valid) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 context->requested_format = SF_TOCO; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
470 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
471 context->error_status = DS_CMD_ERROR; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 context->requested_format = SF_ABSOLUTE; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 case SF_TOCT: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 if (context->toc_valid) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 if (context->status == DS_STOP) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 context->status = DS_TOC_READ; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 context->seeking = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 context->seek_pba = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 context->status = DS_TOC_READ; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 context->seeking = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 context->seek_pba = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 context->requested_format = SF_TOCT; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 case SF_TOCN: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 context->requested_track = context->cmd_buffer.b.format.track_high * 10; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 context->requested_track += context->cmd_buffer.b.format.track_low; |
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:
2061
diff
changeset
|
492 if (!context->media || context->requested_track > context->media->num_tracks) { |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
493 context->requested_format = SF_ABSOLUTE; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
494 context->error_status = DS_CMD_ERROR; |
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
|
495 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:
2061
diff
changeset
|
496 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 context->status = DS_TOC_READ; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 context->seeking = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 context->seek_pba = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 context->requested_format = SF_TOCN; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 printf("CDD CMD: REPORT REQUEST(%d), format set to %d\n", context->cmd_buffer.b.format.status_type, context->requested_format); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 break; |
2067
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
505 case CMD_PAUSE: |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
506 if (context->status == DS_DOOR_OPEN || context->status == DS_TRAY_MOVING || context->status == DS_DISC_LEADOUT || context->status == DS_DISC_LEADIN) { |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
507 context->error_status = DS_CMD_ERROR; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
508 break; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
509 } |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
510 if (context->requested_format == SF_TOCT || context->requested_format == SF_TOCN) { |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
511 context->requested_format = SF_ABSOLUTE; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
512 } |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
513 if (!context->toc_valid) { |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
514 context->error_status = DS_CMD_ERROR; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
515 break; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
516 } |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
517 if (context->status == DS_STOP) { |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
518 context->seeking = 1; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
519 context->seek_pba = LEADIN_SECTORS + context->media->tracks[0].fake_pregap + context->media->tracks[0].start_lba; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
520 printf("CDD CMD: PAUSE, seeking to %u\n", context->seek_pba); |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
521 } else { |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
522 puts("CDD CMD: PAUSE"); |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
523 } |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
524 context->status = DS_PAUSE; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
525 if (!context->seeking) { |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
526 context->pause_pba = context->head_pba; |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
527 } |
2067
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
528 break; |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
529 case CMD_PLAY: |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
530 if (context->status == DS_DOOR_OPEN || context->status == DS_TRAY_MOVING || context->status == DS_DISC_LEADOUT || context->status == DS_DISC_LEADIN) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
531 context->error_status = DS_CMD_ERROR; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
532 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
533 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
534 if (context->requested_format == SF_TOCT || context->requested_format == SF_TOCN) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
535 context->requested_format = SF_ABSOLUTE; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
536 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
537 if (!context->toc_valid) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
538 context->error_status = DS_CMD_ERROR; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
539 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
540 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
541 if (context->status == DS_STOP || context->status == DS_TOC_READ) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
542 context->seeking = 1; |
2100
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
543 context->seek_pba = LEADIN_SECTORS + context->media->tracks[0].fake_pregap + context->media->tracks[0].start_lba - 4; |
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
544 printf("CDD CMD: PLAY, seeking to %u\n", context->seek_pba); |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
545 } else { |
2100
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
546 puts("CDD CMD: PLAY"); |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
547 } |
2100
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
548 context->status = DS_PLAY; |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
549 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
550 //TODO: CMD_FFWD, CMD_RWD |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
551 case CMD_TRACK_SKIP: |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
552 if (context->status != DS_PLAY && context->status != DS_PAUSE && context->status != DS_DISC_LEADOUT) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
553 context->error_status = DS_CMD_ERROR; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
554 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
555 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
556 if (context->requested_format == SF_TOCT || context->requested_format == SF_TOCN) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
557 context->requested_format = SF_ABSOLUTE; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
558 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
559 if (!context->toc_valid) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
560 context->error_status = DS_CMD_ERROR; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
561 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
562 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
563 { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
564 int32_t to_skip = context->cmd_buffer.b.skip.tracks_highest << 12 | context->cmd_buffer.b.skip.tracks_midhigh << 8 |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
565 | context->cmd_buffer.b.skip.tracks_midlow << 4 | context->cmd_buffer.b.skip.tracks_lowest; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
566 if (context->cmd_buffer.b.skip.direction) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
567 to_skip = -to_skip; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
568 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
569 printf("CDD CMD: TRACK_SKIP direction %u, num_tracks %i, delta %i\n", context->cmd_buffer.b.skip.direction, abs(to_skip), to_skip); |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
570 //circumference at 83mm point (roughly half way between inner and outer edge of program area) |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
571 //~ 260.75cm ~ 15 sectors |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
572 context->seek_pba = context->head_pba + to_skip * 15; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
573 context->seeking = 1; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
574 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
575 context->status = DS_TRACKING; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
576 break; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
577 default: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
578 printf("CDD CMD: Unimplemented(%d)\n", context->cmd_buffer.cmd_type); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
579 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
580 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
581 |
2080 | 582 void cdd_mcu_run(cdd_mcu *context, uint32_t cycle, uint16_t *gate_array, lc8951* cdc, cdd_fader* fader) |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
583 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
584 uint32_t cd_cycle = mclks_to_cd_block(cycle); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
585 if (!(gate_array[GAO_CDD_CTRL] & BIT_HOCK)) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
586 //it's a little unclear if this gates the actual cd block clock or just handshaking |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
587 //assum it's actually the clock for now |
2080 | 588 for (; context->cycle < cd_cycle; context->cycle += CDD_MCU_DIVIDER) { |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2084
diff
changeset
|
589 if (context->cycle >= context->next_byte_cycle) { |
2080 | 590 cdd_fader_data(fader, 0); |
2130
28b6453cf7e3
Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents:
2124
diff
changeset
|
591 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), 0, 0); |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2084
diff
changeset
|
592 context->next_byte_cycle += BYTE_CLOCKS; |
2080 | 593 } |
594 } | |
595 gate_array[GAO_CDD_CTRL] |= BIT_MUTE; | |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
596 return; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
598 uint32_t next_subcode = context->last_sector_cycle + SECTOR_CLOCKS; |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
599 uint32_t next_nibble; |
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
600 if (context->current_status_nibble > 0) { |
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
601 next_nibble = context->last_nibble_cycle + NIBBLE_CLOCKS; |
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
602 } else if (!context->current_status_nibble) { |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
603 next_nibble = context->last_sector_cycle + PROCESSING_DELAY; |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
604 if (context->coarse_seek % 3) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
605 next_nibble += SECTOR_CLOCKS * (3 - (context->coarse_seek % 3)); |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
606 } |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
607 } else { |
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
608 next_nibble = CYCLE_NEVER; |
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
609 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 uint32_t next_cmd_nibble = context->current_cmd_nibble >= 0 ? context->last_nibble_cycle + NIBBLE_CLOCKS : CYCLE_NEVER; |
2080 | 611 |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 for (; context->cycle < cd_cycle; context->cycle += CDD_MCU_DIVIDER) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
613 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
614 if (context->cycle >= next_subcode) { |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
615 uint32_t old_coarse = context->coarse_seek; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
616 context->last_sector_cycle = context->cycle; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
617 next_subcode = context->cycle + SECTOR_CLOCKS; |
2080 | 618 update_status(context, gate_array); |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
619 next_nibble = context->cycle + PROCESSING_DELAY; |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
620 if (context->coarse_seek % 3) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
621 next_nibble += SECTOR_CLOCKS * (3 - (context->coarse_seek % 3)); |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
622 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
623 context->current_status_nibble = 0; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
624 if (context->next_subcode_int_cycle != CYCLE_NEVER) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
625 context->subcode_int_pending = 1; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
626 } |
2142
d9151d0894c7
Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents:
2141
diff
changeset
|
627 if ((context->status == DS_PLAY || context->status == DS_PAUSE) && context->head_pba >= LEADIN_SECTORS && !context->seeking) { |
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:
2061
diff
changeset
|
628 context->current_sector_byte = 0; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
629 context->current_subcode_byte = 0; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
630 context->next_subcode_cycle = context->cycle; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
631 context->next_subcode_int_cycle = cd_block_to_mclks(next_subcode); |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
632 } else { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
633 context->next_subcode_int_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:
2061
diff
changeset
|
634 } |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
635 if (old_coarse != context->coarse_seek) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
636 context->next_int_cycle = cd_block_to_mclks(context->cycle + PROCESSING_DELAY + 7 * NIBBLE_CLOCKS); |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
637 if (context->coarse_seek % 3) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
638 context->next_int_cycle += cd_block_to_mclks(SECTOR_CLOCKS * (3 - (context->coarse_seek % 3))); |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
639 } |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
640 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
641 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 if (context->cycle >= next_nibble) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
643 if (context->current_status_nibble == sizeof(cdd_status)) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
644 context->current_status_nibble = -1; |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
645 gate_array[GAO_CDD_CTRL] &= ~BIT_DRS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
646 if (context->cmd_recv_pending) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
647 context->cmd_recv_pending = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
648 context->current_cmd_nibble = 0; |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
649 gate_array[GAO_CDD_CTRL] |= BIT_DTS; |
2075
983f57d08eff
Fix a couple of CDD bugs
Michael Pavone <pavone@retrodev.com>
parents:
2073
diff
changeset
|
650 next_cmd_nibble = context->cycle + NIBBLE_CLOCKS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
651 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
652 context->cmd_recv_wait = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
653 } |
2075
983f57d08eff
Fix a couple of CDD bugs
Michael Pavone <pavone@retrodev.com>
parents:
2073
diff
changeset
|
654 next_nibble = CYCLE_NEVER; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
655 } else { |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
656 gate_array[GAO_CDD_CTRL] |= BIT_DRS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
657 uint8_t value = ((uint8_t *)&context->status_buffer)[context->current_status_nibble]; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
658 int ga_index = GAO_CDD_STATUS + (context->current_status_nibble >> 1); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
659 if (context->current_status_nibble & 1) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
660 gate_array[ga_index] = value | (gate_array[ga_index] & 0xFF00); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
661 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
662 gate_array[ga_index] = (value << 8) | (gate_array[ga_index] & 0x00FF); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
663 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
664 if (context->current_status_nibble == 7) { |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
665 if (!(context->coarse_seek % 3)) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
666 context->int_pending = 1; |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
667 if (context->coarse_seek) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
668 context->next_int_cycle = cd_block_to_mclks(context->cycle + 3 * SECTOR_CLOCKS); |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
669 } else { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
670 context->next_int_cycle = cd_block_to_mclks(context->cycle + SECTOR_CLOCKS); |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
671 } |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
672 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
673 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
674 context->current_status_nibble++; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
675 context->last_nibble_cycle = context->cycle; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
676 next_nibble = context->cycle + NIBBLE_CLOCKS; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
677 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
678 } else if (context->cycle >= next_cmd_nibble) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
679 if (context->current_cmd_nibble == sizeof(cdd_cmd)) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
680 next_cmd_nibble = CYCLE_NEVER; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
681 context->current_cmd_nibble = -1; |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
682 gate_array[GAO_CDD_CTRL] &= ~BIT_DTS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
683 run_command(context); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
684 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
685 int ga_index = GAO_CDD_CMD + (context->current_cmd_nibble >> 1); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
686 uint8_t value = (context->current_cmd_nibble & 1) ? gate_array[ga_index] : gate_array[ga_index] >> 8; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
687 ((uint8_t *)&context->cmd_buffer)[context->current_cmd_nibble] = value; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
688 context->current_cmd_nibble++; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
689 context->last_nibble_cycle = context->cycle; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
690 next_cmd_nibble = context->cycle + NIBBLE_CLOCKS; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
691 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
692 } |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2084
diff
changeset
|
693 if (context->cycle >= context->next_byte_cycle) { |
2100
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
694 if (context->current_sector_byte >= 0 && (!fader->byte_counter || context->current_sector_byte)) { |
2080 | 695 uint8_t byte = context->media->read(context->media, context->current_sector_byte); |
696 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), context->current_sector_byte++, byte); | |
697 cdd_fader_data(fader, gate_array[GAO_CDD_CTRL] & BIT_MUTE ? 0 : byte); | |
698 } else { | |
2130
28b6453cf7e3
Emulate CDC sync detection and sync insertion rather than relying on external knowledge about sector offset
Michael Pavone <pavone@retrodev.com>
parents:
2124
diff
changeset
|
699 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), 0, 0); |
2080 | 700 cdd_fader_data(fader, 0); |
2100
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
701 if (context->current_sector_byte >= 0) { |
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
702 next_subcode += BYTE_CLOCKS; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
703 context->last_sector_cycle += BYTE_CLOCKS; |
2100
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
704 } |
2080 | 705 } |
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:
2061
diff
changeset
|
706 if (context->current_sector_byte == 2352) { |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
707 context->current_sector_byte = -1; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
708 } |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2084
diff
changeset
|
709 context->next_byte_cycle += BYTE_CLOCKS; |
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:
2061
diff
changeset
|
710 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
711 if (context->cycle >= context->next_subcode_cycle) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
712 uint8_t byte; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
713 if (!context->current_subcode_byte) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
714 byte = 0x9F; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
715 //This probably happens after the second sync symbol, but doing it here simplifies things a little |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
716 context->current_subcode_dest &= 0x7E; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
717 gate_array[GAO_SUBCODE_ADDR] = (context->current_subcode_dest - 96) & 0x7E; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
718 } else if (context->current_subcode_byte == 1) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
719 byte = 0xFD; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
720 } else { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
721 byte = context->media->read_subcodes(context->media, context->current_subcode_byte - 2); |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
722 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
723 int offset = GAO_SUBCODE_START + (context->current_subcode_dest >> 1); |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
724 if (context->current_subcode_dest & 1) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
725 gate_array[offset] &= 0xFF00; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
726 gate_array[offset] |= byte; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
727 } else { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
728 gate_array[offset] &= 0x00FF; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
729 gate_array[offset] |= byte << 8; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
730 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
731 context->current_subcode_byte++; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
732 if (context->current_subcode_byte == 98) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
733 context->current_subcode_byte = 0; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
734 } else if (context->current_subcode_byte == 32) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
735 gate_array[GAO_SUBCODE_ADDR] |= 0x80; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
736 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
737 context->current_subcode_dest++; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
738 context->current_subcode_dest &= 0x7F; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
739 context->next_subcode_cycle += SUBCODE_CLOCKS; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
740 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
741 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
742 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
743 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
744 void cdd_mcu_start_cmd_recv(cdd_mcu *context, uint16_t *gate_array) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
745 { |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
746 if (gate_array[GAO_CDD_CTRL] & BIT_DTS) { |
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
747 return; |
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
748 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
749 if (context->cmd_recv_wait) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
750 context->current_cmd_nibble = 0; |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
751 gate_array[GAO_CDD_CTRL] |= BIT_DTS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
752 context->last_nibble_cycle = context->cycle; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
753 context->cmd_recv_wait = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
754 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
755 context->cmd_recv_pending = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
756 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
757 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
758 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
759 void cdd_hock_enabled(cdd_mcu *context) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
760 { |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
761 context->last_sector_cycle = context->cycle; |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
762 context->next_int_cycle = cd_block_to_mclks(context->cycle + SECTOR_CLOCKS + PROCESSING_DELAY + 7 * NIBBLE_CLOCKS); |
2152
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
763 if (context->coarse_seek % 3) { |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
764 context->next_int_cycle += cd_block_to_mclks(SECTOR_CLOCKS * (3 - (context->coarse_seek % 3))); |
c3ee42c89b27
More accurate seek times and basic emulation of extended time between CDD interrupts during coarse seeking
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
765 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
766 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
767 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
768 void cdd_hock_disabled(cdd_mcu *context) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
769 { |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
770 context->last_sector_cycle = CYCLE_NEVER; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
771 context->next_int_cycle = CYCLE_NEVER; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
772 context->last_nibble_cycle = CYCLE_NEVER; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
773 context->current_status_nibble = -1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
774 context->current_cmd_nibble = -1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
775 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
776 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
777 void cdd_mcu_adjust_cycle(cdd_mcu *context, uint32_t deduction) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
778 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
779 uint32_t cd_deduction = mclks_to_cd_block(deduction); |
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
|
780 if (context->cycle > cd_deduction) { |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
781 context->cycle -= cd_deduction; |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
782 } else { |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
783 context->cycle = 0; |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
784 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
785 if (context->next_int_cycle != CYCLE_NEVER) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
786 context->next_int_cycle -= deduction; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
787 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
788 if (context->last_sector_cycle != CYCLE_NEVER) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
789 if (context->last_sector_cycle > cd_deduction) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
790 context->last_sector_cycle -= cd_deduction; |
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
|
791 } else { |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
792 context->last_sector_cycle = 0; |
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
|
793 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
794 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
795 if (context->last_nibble_cycle != CYCLE_NEVER) { |
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
|
796 if (context->last_nibble_cycle > cd_deduction) { |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
797 context->last_nibble_cycle -= cd_deduction; |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
798 } else { |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
799 context->last_nibble_cycle = 0; |
c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
Michael Pavone <pavone@retrodev.com>
parents:
2067
diff
changeset
|
800 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
801 } |
2096
460c93c19146
Fix CDD byte cycle counter deduction that got broken when I fixed the off-by-one on CD-DA
Michael Pavone <pavone@retrodev.com>
parents:
2095
diff
changeset
|
802 context->next_byte_cycle -= cd_deduction; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
803 if (context->next_subcode_cycle != CYCLE_NEVER) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
804 context->next_subcode_cycle -= cd_deduction; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
805 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
806 } |