Mercurial > repos > blastem
annotate cdd_mcu.c @ 2476:aaf7bb58ffca
Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 03 Mar 2024 13:47:59 -0800 |
parents | bcfa5e272f5e |
children |
rev | line source |
---|---|
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2152
diff
changeset
|
1 #include <stdlib.h> |
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2152
diff
changeset
|
2 #include <string.h> |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include "cdd_mcu.h" |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "backend.h" |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #define SCD_MCLKS 50000000 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #define CD_BLOCK_CLKS 16934400 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #define CDD_MCU_DIVIDER 8 |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
9 #define SECTORS_PER_SECOND 75 |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
10 #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
|
11 #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
|
12 #define BYTE_CLOCKS (SECTOR_CLOCKS/2352) // 96 |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
13 #define SUBCODE_CLOCKS (SECTOR_CLOCKS/98) |
2419
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
14 #define PROCESSING_DELAY 121600 //approximate, based on relative level 4 and level 5 interrupt timing on MCD2 in pause_test |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 //lead in start max diameter 46 mm |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 //program area start max diameter 50 mm |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 //difference 4 mm = 4000 um |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 //radius difference 2 mm = 2000 um |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 //track pitch 1.6 um |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 //1250 physical tracks in between |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 //linear speed 1.2 m/s - 1.4 m/s |
2347
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
23 // 1.2 m = 1200 mm |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 // circumference at 46 mm ~ 144.51 mm |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 // circumference at 50 mm ~ 157.08 mm |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 // avg is 150.795 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 // 75 sectors per second |
2347
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
28 // 16 mm "typical" length of a sector |
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
29 // ~9.4 sectors per track in lead-in area |
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
30 #define LEADIN_SECTORS 11780 |
2061
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 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
|
33 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 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
|
35 } |
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 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
|
38 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 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
|
40 } |
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 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
|
43 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 context->next_int_cycle = CYCLE_NEVER; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
45 context->next_subcode_int_cycle = CYCLE_NEVER; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
46 context->last_sector_cycle = CYCLE_NEVER; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 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
|
48 context->next_byte_cycle = 0; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
49 context->next_subcode_cycle = CYCLE_NEVER; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 context->requested_format = SF_NOTREADY; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 context->media = media; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 context->current_status_nibble = -1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 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
|
54 context->current_sector_byte = -1; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
55 context->current_subcode_byte = -1; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
56 context->current_subcode_dest = 0; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 enum { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 GAO_CDD_CTRL, |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 GAO_CDD_STATUS, |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
62 GAO_CDD_CMD = GAO_CDD_STATUS+5, |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
63 GAO_SUBCODE_ADDR = (0x68-0x36)/2, |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
64 GAO_SUBCODE_START = (0x100-0x36)/2 |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 }; |
2080 | 66 //GAO_CDD_CTRL |
67 #define BIT_MUTE 0x100 | |
68 #define BIT_HOCK 0x0004 | |
69 #define BIT_DRS 0x0002 | |
70 #define BIT_DTS 0x0001 | |
2061
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 static uint8_t checksum(uint8_t *vbuffer) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 uint8_t *buffer = vbuffer; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 uint8_t sum = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 for (int i = 0; i < 9; 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 sum += buffer[i]; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 return (~sum) & 0xF; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 } |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
82 |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
83 #define MIN_CIRCUMFERENCE 144.51f |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
84 #define MAX_CIRCUMFERENCE 364.42f |
2347
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
85 #define SECTOR_LENGTH 16.0f |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
86 // max diameter for program area 116 mm |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
87 // circumference ~ 364.42 mm |
2347
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
88 // ~ 23 sectors per physical track at edge |
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
89 // ~9 sectors per physical track at start of lead-in |
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
90 // seek test suggests average somewhere around 54-60 tracks for a long seek, with a peak around 80 |
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
91 // Sonic CD title screen seems to need a much higher value to get reasonable sync |
047253715fd8
Minor fix to seek time calculation
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
92 #define COARSE_SEEK_TRACKS 60 |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
93 static float sectors_per_track_at_pba(uint32_t pba) |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
94 { |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
95 //TODO: better estimate of sectors per track at current head location |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
96 float circumference = (MAX_CIRCUMFERENCE-MIN_CIRCUMFERENCE) * ((float)pba) / ((74 * 60 + 41) * SECTORS_PER_SECOND + LEADIN_SECTORS + 22) + MIN_CIRCUMFERENCE; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
97 return circumference / SECTOR_LENGTH; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
98 } |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
99 |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 static void handle_seek(cdd_mcu *context) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 { |
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
|
102 uint32_t old_coarse = context->coarse_seek; |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
103 if (context->seeking == 2) { |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
104 context->head_pba = context->seek_pba; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
105 context->coarse_seek = 6; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
106 context->seeking = 0; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
107 } else if (context->seeking) { |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 if (context->seek_pba == context->head_pba) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 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
|
110 context->coarse_seek = 0; |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
111 if (context->status == DS_PAUSE && !context->pause_pba) { |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
112 context->pause_pba = context->head_pba; |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
113 } |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
114 } else { |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
115 |
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
|
116 //TODO: drive will periodically lose tracking when seeking which slows |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
117 //things down periodically, I estimate the average |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
118 float sectors_per_track = sectors_per_track_at_pba(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
|
119 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
|
120 uint32_t min_seek = sectors_per_track; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
121 |
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
|
122 uint32_t old_pba = context->head_pba; |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
123 if (context->seek_pba > context->head_pba) { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
124 uint32_t seek_amount; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
125 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
|
126 { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
127 if (context->seek_pba - context->head_pba >= seek_amount) { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
128 break; |
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 } |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
131 if (seek_amount >= min_seek) { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
132 context->head_pba += seek_amount; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
133 } else { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
134 context->head_pba++; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
135 } |
2067
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
136 } else { |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
137 uint32_t seek_amount; |
2348
2025ba21026a
Fix backwards seek calculation
Michael Pavone <pavone@retrodev.com>
parents:
2347
diff
changeset
|
138 for (seek_amount = max_seek; seek_amount >= min_seek;) |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
139 { |
2348
2025ba21026a
Fix backwards seek calculation
Michael Pavone <pavone@retrodev.com>
parents:
2347
diff
changeset
|
140 uint32_t next_seek = seek_amount >> 1; |
2025ba21026a
Fix backwards seek calculation
Michael Pavone <pavone@retrodev.com>
parents:
2347
diff
changeset
|
141 if (context->head_pba - context->seek_pba > next_seek) { |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
142 break; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
143 } |
2348
2025ba21026a
Fix backwards seek calculation
Michael Pavone <pavone@retrodev.com>
parents:
2347
diff
changeset
|
144 seek_amount = next_seek; |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
145 } |
2348
2025ba21026a
Fix backwards seek calculation
Michael Pavone <pavone@retrodev.com>
parents:
2347
diff
changeset
|
146 if (seek_amount >= min_seek && context->head_pba >= seek_amount) { |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
147 context->head_pba -= seek_amount; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
148 } else if (context->head_pba >= min_seek){ |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
149 context->head_pba -= min_seek; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
150 } else { |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
151 context->head_pba = 0; |
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
152 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
153 } |
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
|
154 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
|
155 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
|
156 } 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
|
157 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
|
158 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
160 } else { |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
161 context->coarse_seek = 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
|
162 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 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
|
166 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 uint32_t seconds = lba / 75; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 uint32_t frames = lba % 75; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 uint32_t minutes = seconds / 60; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 seconds = seconds % 60; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 |
2080 | 179 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
|
180 { |
2080 | 181 gate_array[GAO_CDD_CTRL] |= BIT_MUTE; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 switch (context->status) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 { |
2266
5083bc84fd84
Finish seeking after a CDD STOP command is sent
Michael Pavone <pavone@retrodev.com>
parents:
2215
diff
changeset
|
184 case DS_STOP: |
5083bc84fd84
Finish seeking after a CDD STOP command is sent
Michael Pavone <pavone@retrodev.com>
parents:
2215
diff
changeset
|
185 handle_seek(context); |
5083bc84fd84
Finish seeking after a CDD STOP command is sent
Michael Pavone <pavone@retrodev.com>
parents:
2215
diff
changeset
|
186 break; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 case DS_PLAY: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 handle_seek(context); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 if (!context->seeking) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 context->head_pba++; |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
191 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
192 if (context->head_pba >= LEADIN_SECTORS) { |
2080 | 193 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
|
194 if (!context->seeking && context->media->tracks[track].type == TRACK_AUDIO) { |
2080 | 195 gate_array[GAO_CDD_CTRL] &= ~BIT_MUTE; |
196 } | |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 case DS_PAUSE: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 handle_seek(context); |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
201 if (!context->seeking) { |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
202 context->head_pba++; |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
203 if (context->head_pba > context->pause_pba) { |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
204 uint32_t back = sectors_per_track_at_pba(context->head_pba) + 0.5f; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
205 if (back > context->head_pba) { |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
206 back = context->head_pba; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
207 } |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
208 context->head_pba -= back; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
209 context->coarse_seek = 6; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
210 } |
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
211 } |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
212 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
|
213 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
|
214 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 case DS_TOC_READ: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 handle_seek(context); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 if (!context->seeking) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 context->head_pba++; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 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
|
221 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
|
222 context->toc_valid = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 context->seeking = 1; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
224 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
|
225 context->status = DS_PAUSE; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 context->status = DS_NO_DISC; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 break; |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
233 case DS_TRACKING: |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
234 handle_seek(context); |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
235 if (!context->seeking) { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
236 context->status = DS_PAUSE; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
237 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
|
238 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 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
|
243 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
244 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
245 break; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 } |
2124
ad346054ca78
Return "not ready" status sometimes when seeking. Fixes issues in multiple games
Michael Pavone <pavone@retrodev.com>
parents:
2122
diff
changeset
|
247 uint8_t force_not_ready = 0; |
2270
827ab6dd534a
Adjust when not-ready is returned during coarse seeking to fix some regressions
Michael Pavone <pavone@retrodev.com>
parents:
2266
diff
changeset
|
248 if (context->coarse_seek && !(context->coarse_seek % 6)) { |
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
|
249 //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
|
250 //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
|
251 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
|
252 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
253 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
|
254 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
|
255 { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
256 case SF_ABSOLUTE: |
2419
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
257 if (context->toc_valid && context->head_pba >= LEADIN_SECTORS) { |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
258 lba_to_status(context, context->head_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
|
259 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
|
260 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
261 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
|
262 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
263 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
264 case SF_RELATIVE: |
2419
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
265 if (context->toc_valid && context->head_pba >= LEADIN_SECTORS) { |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
266 uint32_t lba =context->head_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
|
267 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
|
268 { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
269 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
|
270 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
|
271 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
|
272 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
|
273 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
274 //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
|
275 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
|
276 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
277 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
278 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
279 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
|
280 //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
|
281 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
|
282 } else { |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
283 lba -= context->media->tracks[i].start_lba; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
285 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
286 } 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
|
287 lba -= context->media->tracks[i].fake_pregap; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
289 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
290 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
|
291 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
|
292 } else { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
293 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
|
294 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
295 break; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
296 case SF_TRACK: |
2419
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
297 if (context->toc_valid && context->head_pba >= LEADIN_SECTORS) { |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
298 uint32_t lba =context->head_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
|
299 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
|
300 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
|
301 { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
302 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
|
303 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
|
304 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
|
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 } else { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
307 //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
|
308 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
|
309 break; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
310 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
311 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
312 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
|
313 //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
|
314 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
|
315 } else { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
316 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
|
317 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
318 break; |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
319 } 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
|
320 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
|
321 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
322 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 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
|
327 } else { |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
328 //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
|
329 //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
|
330 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
|
331 } |
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
332 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
|
333 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
|
334 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
335 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
|
336 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
337 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
338 case SF_TOCO: |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
343 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
|
344 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
345 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
|
346 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
|
347 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
348 context->status_buffer.format = SF_NOTREADY; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
350 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
351 case SF_TOCT: |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
360 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
|
361 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
362 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
363 case SF_TOCN: |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 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
|
368 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
369 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
|
370 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
|
371 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
|
372 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
373 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
|
374 if (context->media->tracks[context->requested_track - 1].type == TRACK_DATA) { |
2419
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
375 context->status_buffer.b.tocn.frame_high |= 0x8; |
2065
02a9846668d1
Implement transfer of data from CDC to elsewhere. Other miscellaneous CDD/CDC improvements
Michael Pavone <pavone@retrodev.com>
parents:
2064
diff
changeset
|
376 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
377 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
|
378 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
|
379 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
380 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
|
381 } |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
382 break; |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
383 case SF_NOTREADY: |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
384 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
|
385 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
|
386 break; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 } 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
|
392 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
|
393 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
394 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
|
395 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 } else { |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
397 context->status_buffer.status = context->error_status; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 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
|
399 context->error_status = DS_STOP; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
401 if (context->requested_format != SF_TOCN) { |
2080 | 402 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
|
403 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
404 } else { |
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
405 // 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
|
406 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
|
407 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 context->status_buffer.checksum = checksum((uint8_t *)&context->status_buffer); |
2421
bcfa5e272f5e
Fix regression in Prince of Persia
Michael Pavone <pavone@retrodev.com>
parents:
2419
diff
changeset
|
409 if (context->status_buffer.format != SF_NOTREADY || (context->status != DS_STOP && context->status < DS_SUM_ERROR)) { |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
410 printf("CDD Status %X%X.%X%X%X%X%X%X.%X%X (lba %u)\n", |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 context->status_buffer.status, context->status_buffer.format, |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 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
|
413 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
|
414 context->status_buffer.b.time.frame_high, context->status_buffer.b.time.frame_low, |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
415 context->status_buffer.b.time.flags, context->status_buffer.checksum, context->head_pba - LEADIN_SECTORS |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 ); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 } |
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 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 static void run_command(cdd_mcu *context) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 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
|
423 if (check != context->cmd_buffer.checksum) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 context->error_status = DS_SUM_ERROR; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 return; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 if (context->cmd_buffer.must_be_zero) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 context->error_status = DS_CMD_ERROR; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 return; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 } |
2064
91e4d2fe5cd9
Get CDD working well enough to get into BIOS CD player
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
431 context->first_cmd_received = 1; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 switch (context->cmd_buffer.cmd_type) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 case CMD_NOP: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 case CMD_STOP: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 puts("CDD CMD: STOP"); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 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
|
439 context->requested_format = SF_ABSOLUTE; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 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
|
446 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
447 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
|
448 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
|
449 } |
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 (!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
|
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 } |
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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 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
|
463 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
|
464 ); |
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
|
465 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
|
466 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
|
467 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
|
468 } |
2141
793715149f16
More accurate seek emulation
Michael Pavone <pavone@retrodev.com>
parents:
2139
diff
changeset
|
469 context->seek_pba = lba + LEADIN_SECTORS - 3; |
2421
bcfa5e272f5e
Fix regression in Prince of Persia
Michael Pavone <pavone@retrodev.com>
parents:
2419
diff
changeset
|
470 if (context->cmd_buffer.cmd_type == CMD_SEEK) { |
bcfa5e272f5e
Fix regression in Prince of Persia
Michael Pavone <pavone@retrodev.com>
parents:
2419
diff
changeset
|
471 context->pause_pba = lba + LEADIN_SECTORS; |
bcfa5e272f5e
Fix regression in Prince of Persia
Michael Pavone <pavone@retrodev.com>
parents:
2419
diff
changeset
|
472 } |
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
|
473 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
|
474 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
|
475 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
|
476 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 case CMD_REPORT_REQUEST: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 switch (context->cmd_buffer.b.format.status_type) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 case SF_ABSOLUTE: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 case SF_RELATIVE: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 case SF_TRACK: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 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
|
484 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 case SF_TOCO: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 if (context->toc_valid) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 context->requested_format = SF_TOCO; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 context->error_status = DS_CMD_ERROR; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 context->requested_format = SF_ABSOLUTE; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 case SF_TOCT: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 if (context->toc_valid) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 if (context->status == DS_STOP) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 context->status = DS_TOC_READ; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 context->seeking = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 context->seek_pba = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 context->status = DS_TOC_READ; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 context->seeking = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 context->seek_pba = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 context->requested_format = SF_TOCT; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 case SF_TOCN: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 context->status = DS_TOC_READ; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 context->seeking = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 context->seek_pba = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 context->requested_format = SF_TOCN; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
519 break; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
520 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
521 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
|
522 break; |
2067
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
523 case CMD_PAUSE: |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
524 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
|
525 context->error_status = DS_CMD_ERROR; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
526 break; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
527 } |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
528 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
|
529 context->requested_format = SF_ABSOLUTE; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
530 } |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
531 if (!context->toc_valid) { |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
532 context->error_status = DS_CMD_ERROR; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
533 break; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
534 } |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
535 if (context->status == DS_STOP) { |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
536 context->seeking = 1; |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
537 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
|
538 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
|
539 } else { |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
540 uint32_t lba = context->head_pba - LEADIN_SECTORS; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
541 uint32_t seconds = lba / 75; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
542 uint32_t frames = lba % 75; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
543 uint32_t minutes = seconds / 60; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
544 seconds = seconds % 60; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
545 printf("CDD CMD: PAUSE, current lba %u, MM:SS:FF %02u:%02u:%02u\n", lba, minutes, seconds, frames); |
2067
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
546 } |
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
547 context->status = DS_PAUSE; |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
548 if (context->seeking) { |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
549 //handle_seek will populate this |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
550 context->pause_pba = 0; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
551 } else { |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
552 context->pause_pba = context->head_pba; |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
553 uint32_t back = 2.1f * sectors_per_track_at_pba(context->head_pba) + 0.5f; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
554 if (back > context->head_pba) { |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
555 back = context->head_pba; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
556 } |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
557 context->seek_pba = context->head_pba - back; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
558 context->seeking = 2; |
2095
c732dcc9c61b
Better simulation of CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
559 } |
2067
f22e04b69272
More CDC/CDD improvements
Michael Pavone <pavone@retrodev.com>
parents:
2065
diff
changeset
|
560 break; |
2084
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
561 case CMD_PLAY: |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
562 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
|
563 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
|
564 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
565 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
566 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
|
567 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
|
568 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
569 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
|
570 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
|
571 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
572 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
573 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
|
574 context->seeking = 1; |
2100
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
575 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
|
576 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
|
577 } else { |
2100
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
578 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
|
579 } |
2100
539450d905b3
Fix CDD PLAY command and CDD fader sample alignment
Michael Pavone <pavone@retrodev.com>
parents:
2096
diff
changeset
|
580 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
|
581 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
582 //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
|
583 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
|
584 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
|
585 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
|
586 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
587 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
588 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
|
589 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
|
590 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
591 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
|
592 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
|
593 break; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
594 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
595 { |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
596 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
|
597 | 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
|
598 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
|
599 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
|
600 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
601 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
|
602 //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
|
603 //~ 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
|
604 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
|
605 context->seeking = 1; |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
606 } |
c9d3b8e1ea56
Implement a couple more CDD commands force CDDA mute when seeking
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
607 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
|
608 break; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
609 default: |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 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
|
611 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
613 |
2080 | 614 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
|
615 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
616 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
|
617 if (!(gate_array[GAO_CDD_CTRL] & BIT_HOCK)) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
618 //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
|
619 //assum it's actually the clock for now |
2080 | 620 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
|
621 if (context->cycle >= context->next_byte_cycle) { |
2080 | 622 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
|
623 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
|
624 context->next_byte_cycle += BYTE_CLOCKS; |
2080 | 625 } |
626 } | |
627 gate_array[GAO_CDD_CTRL] |= BIT_MUTE; | |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
628 return; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
629 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
630 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
|
631 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
|
632 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
|
633 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
|
634 } else if (!context->current_status_nibble) { |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 } |
2115
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
639 } else { |
e93ced356a21
Hopefully more accurate relative timing of CDD status and data reaching the CDC
Michael Pavone <pavone@retrodev.com>
parents:
2100
diff
changeset
|
640 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
|
641 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 uint32_t next_cmd_nibble = context->current_cmd_nibble >= 0 ? context->last_nibble_cycle + NIBBLE_CLOCKS : CYCLE_NEVER; |
2080 | 643 |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
644 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
|
645 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
646 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
|
647 uint32_t old_coarse = context->coarse_seek; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
648 context->last_sector_cycle = context->cycle; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
649 next_subcode = context->cycle + SECTOR_CLOCKS; |
2080 | 650 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
|
651 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
|
652 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
|
653 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
|
654 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
655 context->current_status_nibble = 0; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
656 if (context->next_subcode_int_cycle != CYCLE_NEVER) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
657 context->subcode_int_pending = 1; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
658 } |
2142
d9151d0894c7
Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents:
2141
diff
changeset
|
659 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
|
660 context->current_sector_byte = 0; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
661 context->current_subcode_byte = 0; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
662 context->next_subcode_cycle = context->cycle; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
663 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
|
664 } else { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
665 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
|
666 } |
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
|
667 if (old_coarse != context->coarse_seek) { |
2419
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
668 context->next_int_cycle = cd_block_to_mclks(next_nibble + 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
|
669 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
670 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
671 if (context->cycle >= next_nibble) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
672 if (context->current_status_nibble == sizeof(cdd_status)) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
673 context->current_status_nibble = -1; |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
674 gate_array[GAO_CDD_CTRL] &= ~BIT_DRS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
675 if (context->cmd_recv_pending) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
676 context->cmd_recv_pending = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
677 context->current_cmd_nibble = 0; |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
678 gate_array[GAO_CDD_CTRL] |= BIT_DTS; |
2075
983f57d08eff
Fix a couple of CDD bugs
Michael Pavone <pavone@retrodev.com>
parents:
2073
diff
changeset
|
679 next_cmd_nibble = context->cycle + NIBBLE_CLOCKS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
680 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
681 context->cmd_recv_wait = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
682 } |
2075
983f57d08eff
Fix a couple of CDD bugs
Michael Pavone <pavone@retrodev.com>
parents:
2073
diff
changeset
|
683 next_nibble = CYCLE_NEVER; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
684 } else { |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
685 gate_array[GAO_CDD_CTRL] |= BIT_DRS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
686 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
|
687 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
|
688 if (context->current_status_nibble & 1) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
689 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
|
690 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
691 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
|
692 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
693 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
|
694 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
|
695 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
|
696 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
|
697 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
|
698 } 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
|
699 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
|
700 } |
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
|
701 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
702 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
703 context->current_status_nibble++; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
704 context->last_nibble_cycle = context->cycle; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
705 next_nibble = context->cycle + NIBBLE_CLOCKS; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
706 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
707 } else if (context->cycle >= next_cmd_nibble) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
708 if (context->current_cmd_nibble == sizeof(cdd_cmd)) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
709 next_cmd_nibble = CYCLE_NEVER; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
710 context->current_cmd_nibble = -1; |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
711 gate_array[GAO_CDD_CTRL] &= ~BIT_DTS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
712 run_command(context); |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
713 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
714 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
|
715 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
|
716 ((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
|
717 context->current_cmd_nibble++; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
718 context->last_nibble_cycle = context->cycle; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
719 next_cmd_nibble = context->cycle + NIBBLE_CLOCKS; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
720 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
721 } |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2084
diff
changeset
|
722 if (context->cycle >= context->next_byte_cycle) { |
2419
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
723 if (context->current_sector_byte >= 0/* && (!fader->byte_counter || context->current_sector_byte)*/) { |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
724 if (!context->current_sector_byte) { |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
725 //HACK: things can get a little out of sync currently which causes a mess in the fader code |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
726 // since it expects even multiples of 4 bytes (1 stereo sample) |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
727 while (fader->byte_counter) |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
728 { |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
729 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), 0, 0); |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
730 cdd_fader_data(fader, 0); |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
731 } |
0871f555eff6
Fix some CD-ROM emulation issues and make timing better match my MCD2. Seems to fix or at least improve video playback in Iron Helix and Power Rangers
Michael Pavone <pavone@retrodev.com>
parents:
2353
diff
changeset
|
732 } |
2080 | 733 uint8_t byte = context->media->read(context->media, context->current_sector_byte); |
2353
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
734 if (context->status != DS_PLAY) { |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
735 byte = 0; |
c66e051de8a6
More accurate CDD pause behavior
Michael Pavone <pavone@retrodev.com>
parents:
2348
diff
changeset
|
736 } |
2080 | 737 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), context->current_sector_byte++, byte); |
738 cdd_fader_data(fader, gate_array[GAO_CDD_CTRL] & BIT_MUTE ? 0 : byte); | |
739 } 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
|
740 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), 0, 0); |
2080 | 741 cdd_fader_data(fader, 0); |
742 } | |
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
|
743 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
|
744 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
|
745 } |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2084
diff
changeset
|
746 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
|
747 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
748 if (context->cycle >= context->next_subcode_cycle) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
749 uint8_t byte; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
750 if (!context->current_subcode_byte) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
751 byte = 0x9F; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
752 //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
|
753 context->current_subcode_dest &= 0x7E; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
754 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
|
755 } else if (context->current_subcode_byte == 1) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
756 byte = 0xFD; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
757 } else { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
758 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
|
759 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
760 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
|
761 if (context->current_subcode_dest & 1) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
762 gate_array[offset] &= 0xFF00; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
763 gate_array[offset] |= byte; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
764 } else { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
765 gate_array[offset] &= 0x00FF; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
766 gate_array[offset] |= byte << 8; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
767 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
768 context->current_subcode_byte++; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
769 if (context->current_subcode_byte == 98) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
770 context->current_subcode_byte = 0; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
771 } else if (context->current_subcode_byte == 32) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
772 gate_array[GAO_SUBCODE_ADDR] |= 0x80; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
773 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
774 context->current_subcode_dest++; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
775 context->current_subcode_dest &= 0x7F; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
776 context->next_subcode_cycle += SUBCODE_CLOCKS; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
777 } |
2061
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 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
780 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
781 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
|
782 { |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
783 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
|
784 return; |
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
785 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
786 if (context->cmd_recv_wait) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
787 context->current_cmd_nibble = 0; |
2139
11a3d5b00a66
Fix DRS and DTS bits of CDD status
Michael Pavone <pavone@retrodev.com>
parents:
2130
diff
changeset
|
788 gate_array[GAO_CDD_CTRL] |= BIT_DTS; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
789 context->last_nibble_cycle = context->cycle; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
790 context->cmd_recv_wait = 0; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
791 } else { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
792 context->cmd_recv_pending = 1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
793 } |
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 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
796 void cdd_hock_enabled(cdd_mcu *context) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
797 { |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
798 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
|
799 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
|
800 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
|
801 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
|
802 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
803 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
804 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
805 void cdd_hock_disabled(cdd_mcu *context) |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
806 { |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
807 context->last_sector_cycle = CYCLE_NEVER; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
808 context->next_int_cycle = CYCLE_NEVER; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
809 context->last_nibble_cycle = CYCLE_NEVER; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
810 context->current_status_nibble = -1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
811 context->current_cmd_nibble = -1; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
812 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
813 |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
814 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
|
815 { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
816 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
|
817 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
|
818 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
|
819 } 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
|
820 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
|
821 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
822 if (context->next_int_cycle != CYCLE_NEVER) { |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
823 context->next_int_cycle -= deduction; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
824 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
825 if (context->last_sector_cycle != CYCLE_NEVER) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
826 if (context->last_sector_cycle > cd_deduction) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
827 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
|
828 } else { |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
829 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
|
830 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
831 } |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
832 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
|
833 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
|
834 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
|
835 } 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
|
836 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
|
837 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
838 } |
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
|
839 context->next_byte_cycle -= cd_deduction; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
840 if (context->next_subcode_cycle != CYCLE_NEVER) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
841 context->next_subcode_cycle -= cd_deduction; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2115
diff
changeset
|
842 } |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
843 } |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
844 |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
845 void cdd_mcu_serialize(cdd_mcu *context, serialize_buffer *buf) |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
846 { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
847 save_int32(buf, context->cycle); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
848 save_int32(buf, context->next_int_cycle); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
849 save_int32(buf, context->next_subcode_int_cycle); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
850 save_int32(buf, context->last_sector_cycle); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
851 save_int32(buf, context->last_nibble_cycle); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
852 save_int32(buf, context->next_byte_cycle); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
853 save_int32(buf, context->next_subcode_cycle); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
854 save_int8(buf, context->current_status_nibble); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
855 save_int8(buf, context->current_cmd_nibble); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
856 save_int16(buf, context->current_sector_byte); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
857 save_int8(buf, context->current_subcode_byte); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
858 save_int8(buf, context->current_subcode_dest); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
859 save_int32(buf, context->head_pba); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
860 save_int32(buf, context->seek_pba); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
861 save_int32(buf, context->pause_pba); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
862 save_int32(buf, context->coarse_seek); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
863 save_buffer8(buf, (uint8_t *)&context->cmd_buffer, sizeof(context->cmd_buffer)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
864 save_buffer8(buf, (uint8_t *)&context->status_buffer, sizeof(context->status_buffer)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
865 save_int8(buf, context->requested_format); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
866 save_int8(buf, context->status); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
867 save_int8(buf, context->error_status); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
868 save_int8(buf, context->requested_track); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
869 save_int8(buf, context->cmd_recv_wait); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
870 save_int8(buf, context->cmd_recv_pending); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
871 save_int8(buf, context->int_pending); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
872 save_int8(buf, context->subcode_int_pending); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
873 save_int8(buf, context->toc_valid); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
874 save_int8(buf, context->first_cmd_received); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
875 save_int8(buf, context->seeking); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
876 save_int8(buf, context->in_fake_pregap); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
877 } |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
878 |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
879 static int sign_extend8(uint8_t value) |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
880 { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
881 if (value & 0x80) { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
882 return value | 0xFFFFFF00; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
883 } else { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
884 return value; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
885 } |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
886 } |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
887 |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
888 static int sign_extend16(uint16_t value) |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
889 { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
890 if (value & 0x8000) { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
891 return value | 0xFFFF0000; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
892 } else { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
893 return value; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
894 } |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
895 } |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
896 |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
897 void cdd_mcu_deserialize(deserialize_buffer *buf, void *vcontext) |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
898 { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
899 cdd_mcu *context = vcontext; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
900 context->cycle = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
901 context->next_int_cycle = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
902 context->next_subcode_int_cycle = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
903 context->last_sector_cycle = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
904 context->last_nibble_cycle = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
905 context->next_byte_cycle = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
906 context->next_subcode_cycle = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
907 context->current_status_nibble = sign_extend8(load_int8(buf)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
908 context->current_cmd_nibble = sign_extend8(load_int8(buf)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
909 context->current_sector_byte = sign_extend16(load_int16(buf)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
910 context->current_subcode_byte = sign_extend8(load_int8(buf)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
911 context->current_subcode_dest = sign_extend8(load_int8(buf)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
912 context->head_pba = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
913 context->seek_pba = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
914 context->pause_pba = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
915 context->coarse_seek = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
916 load_buffer8(buf, (uint8_t *)&context->cmd_buffer, sizeof(context->cmd_buffer)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
917 load_buffer8(buf, (uint8_t *)&context->status_buffer, sizeof(context->status_buffer)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
918 context->requested_format = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
919 context->status = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
920 context->error_status = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
921 context->requested_track = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
922 context->cmd_recv_wait = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
923 context->cmd_recv_pending = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
924 context->int_pending = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
925 context->subcode_int_pending = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
926 context->toc_valid = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
927 context->first_cmd_received = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
928 context->seeking = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
929 context->in_fake_pregap = load_int8(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2270
diff
changeset
|
930 } |