| 1 | #cxx . . $ `<file>/mednafen/cdrom/CDUtility.h`/ifndef __MDFN_CDROM_CDUTILITY_H |
| 2 | #define __MDFN_CDROM_CDUTILITY_Hcxx . . $ `mednafen/cdrom/CDUtility.h:2:9`! |
| 3 | |
| 4 | namespace CDUtilitycxx . . $ CDUtility/ |
| 5 | { |
| 6 | // Call once at app startup before creating any threads that could potentially cause re-entrancy to these functions. |
| 7 | // It will also be called automatically if needed for the first time a function in this namespace that requires |
| 8 | // the initialization function to be called is called, for potential |
| 9 | // usage in constructors of statically-declared objects. |
| 10 | void CDUtility_Initcxx . . $ CDUtility/CDUtility_Init(49f6e7a06ebc5aa8).(void); |
| 11 | |
| 12 | // Quick definitions here: |
| 13 | // |
| 14 | // ABA - Absolute block address, synonymous to absolute MSF |
| 15 | // aba = (m_a * 60 * 75) + (s_a * 75) + f_a |
| 16 | // |
| 17 | // LBA - Logical block address(related: data CDs are required to have a pregap of 2 seconds, IE 150 frames/sectors) |
| 18 | // lba = aba - 150 |
| 19 | |
| 20 | |
| 21 | enumcxx . . $ CDUtility/$anonymous_type_28146622f1ea3022_0# |
| 22 | { |
| 23 | ADR_NOQINFOcxx . . $ CDUtility/ADR_NOQINFO. = 0x00, |
| 24 | ADR_CURPOScxx . . $ CDUtility/ADR_CURPOS. = 0x01, |
| 25 | ADR_MCNcxx . . $ CDUtility/ADR_MCN. = 0x02, |
| 26 | ADR_ISRCcxx . . $ CDUtility/ADR_ISRC. = 0x03 |
| 27 | }; |
| 28 | |
| 29 | |
| 30 | struct TOC_Trackcxx . . $ CDUtility/TOC_Track# |
| 31 | { |
| 32 | uint8cxx . . $ uint8# adrcxx . . $ CDUtility/TOC_Track#adr.; |
| 33 | uint8cxx . . $ uint8# controlcxx . . $ CDUtility/TOC_Track#control.; |
| 34 | uint32cxx . . $ uint32# lbacxx . . $ CDUtility/TOC_Track#lba.; |
| 35 | }; |
| 36 | |
| 37 | // SubQ control field flags. |
| 38 | enumcxx . . $ CDUtility/$anonymous_type_28146622f1ea3022_1# |
| 39 | { |
| 40 | SUBQ_CTRLF_PREcxx . . $ CDUtility/SUBQ_CTRLF_PRE. = 0x01, // With 50/15us pre-emphasis. |
| 41 | SUBQ_CTRLF_DCPcxx . . $ CDUtility/SUBQ_CTRLF_DCP. = 0x02, // Digital copy permitted. |
| 42 | SUBQ_CTRLF_DATAcxx . . $ CDUtility/SUBQ_CTRLF_DATA. = 0x04, // Data track. |
| 43 | SUBQ_CTRLF_4CHcxx . . $ CDUtility/SUBQ_CTRLF_4CH. = 0x08, // 4-channel CD-DA. |
| 44 | }; |
| 45 | |
| 46 | enumcxx . . $ CDUtility/$anonymous_type_28146622f1ea3022_2# |
| 47 | { |
| 48 | DISC_TYPE_CDDA_OR_M1cxx . . $ CDUtility/DISC_TYPE_CDDA_OR_M1. = 0x00, |
| 49 | DISC_TYPE_CD_Icxx . . $ CDUtility/DISC_TYPE_CD_I. = 0x10, |
| 50 | DISC_TYPE_CD_XAcxx . . $ CDUtility/DISC_TYPE_CD_XA. = 0x20 |
| 51 | }; |
| 52 | |
| 53 | struct TOCcxx . . $ CDUtility/TOC# |
| 54 | { |
| 55 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! TOCcxx . . $ CDUtility/TOC#TOC(49f6e7a06ebc5aa8).() |
| 56 | { |
| 57 | Clearcxx . . $ CDUtility/TOC#Clear(49f6e7a06ebc5aa8).(); |
| 58 | } |
| 59 | |
| 60 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void Clearcxx . . $ CDUtility/TOC#Clear(49f6e7a06ebc5aa8).(void) |
| 61 | { |
| 62 | first_trackcxx . . $ CDUtility/TOC#first_track. = last_trackcxx . . $ CDUtility/TOC#last_track. = 0; |
| 63 | disc_typecxx . . $ CDUtility/TOC#disc_type. = 0; |
| 64 | |
| 65 | memset(trackscxx . . $ CDUtility/TOC#tracks., 0, sizeof(trackscxx . . $ CDUtility/TOC#tracks.)); // FIXME if we change TOC_Track to non-POD type. |
| 66 | } |
| 67 | |
| 68 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! int FindTrackByLBAcxx . . $ CDUtility/TOC#FindTrackByLBA(4c679297bf94b9eb).(uint32cxx . . $ uint32# LBA) |
| 69 | { |
| 70 | for(int32cxx . . $ int32# track = first_trackcxx . . $ CDUtility/TOC#first_track.; track <= (last_trackcxx . . $ CDUtility/TOC#last_track. + 1); track++) |
| 71 | { |
| 72 | if(track == (last_trackcxx . . $ CDUtility/TOC#last_track. + 1)) |
| 73 | { |
| 74 | if(LBA < trackscxx . . $ CDUtility/TOC#tracks.[100].lbacxx . . $ CDUtility/TOC_Track#lba.) |
| 75 | return(track - 1); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | if(LBA < trackscxx . . $ CDUtility/TOC#tracks.[track].lbacxx . . $ CDUtility/TOC_Track#lba.) |
| 80 | return(track - 1); |
| 81 | } |
| 82 | } |
| 83 | return(0); |
| 84 | } |
| 85 | |
| 86 | uint8cxx . . $ uint8# first_trackcxx . . $ CDUtility/TOC#first_track.; |
| 87 | uint8cxx . . $ uint8# last_trackcxx . . $ CDUtility/TOC#last_track.; |
| 88 | uint8cxx . . $ uint8# disc_typecxx . . $ CDUtility/TOC#disc_type.; |
| 89 | TOC_Trackcxx . . $ CDUtility/TOC_Track# trackscxx . . $ CDUtility/TOC#tracks.[100 + 1]; // [0] is unused, [100] is for the leadout track. |
| 90 | // Also, for convenience, tracks[last_track + 1] will always refer |
| 91 | // to the leadout track(even if last_track < 99, IE the leadout track details are duplicated). |
| 92 | }; |
| 93 | |
| 94 | // |
| 95 | // Address conversion functions. |
| 96 | // |
| 97 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint32cxx . . $ uint32# AMSF_to_ABAcxx . . $ CDUtility/AMSF_to_ABA(530956271a9518a5).(int32cxx . . $ int32# m_a, int32cxx . . $ int32# s_a, int32cxx . . $ int32# f_a) |
| 98 | { |
| 99 | return(f_a + 75 * s_a + 75 * 60 * m_a); |
| 100 | } |
| 101 | |
| 102 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void ABA_to_AMSFcxx . . $ CDUtility/ABA_to_AMSF(f86fb2429ce25bf8).(uint32cxx . . $ uint32# aba, uint8cxx . . $ uint8# *m_a, uint8cxx . . $ uint8# *s_a, uint8cxx . . $ uint8# *f_a) |
| 103 | { |
| 104 | *m_a = aba / 75 / 60; |
| 105 | *s_a = (aba - *m_a * 75 * 60) / 75; |
| 106 | *f_a = aba - (*m_a * 75 * 60) - (*s_a * 75); |
| 107 | } |
| 108 | |
| 109 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! int32cxx . . $ int32# ABA_to_LBAcxx . . $ CDUtility/ABA_to_LBA(4c679297bf94b9eb).(uint32cxx . . $ uint32# aba) |
| 110 | { |
| 111 | return(aba - 150); |
| 112 | } |
| 113 | |
| 114 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint32cxx . . $ uint32# LBA_to_ABAcxx . . $ CDUtility/LBA_to_ABA(46cc46841198e427).(int32cxx . . $ int32# lba) |
| 115 | { |
| 116 | return(lba + 150); |
| 117 | } |
| 118 | |
| 119 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! int32cxx . . $ int32# AMSF_to_LBAcxx . . $ CDUtility/AMSF_to_LBA(61bf41d5caea65af).(uint8cxx . . $ uint8# m_a, uint8cxx . . $ uint8# s_a, uint8cxx . . $ uint8# f_a) |
| 120 | { |
| 121 | return(ABA_to_LBAcxx . . $ CDUtility/ABA_to_LBA(4c679297bf94b9eb).(AMSF_to_ABAcxx . . $ CDUtility/AMSF_to_ABA(530956271a9518a5).(m_a, s_a, f_a))); |
| 122 | } |
| 123 | |
| 124 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void LBA_to_AMSFcxx . . $ CDUtility/LBA_to_AMSF(e84e8f147c6dbba1).(int32cxx . . $ int32# lba, uint8cxx . . $ uint8# *m_a, uint8cxx . . $ uint8# *s_a, uint8cxx . . $ uint8# *f_a) |
| 125 | { |
| 126 | ABA_to_AMSFcxx . . $ CDUtility/ABA_to_AMSF(f86fb2429ce25bf8).(LBA_to_ABAcxx . . $ CDUtility/LBA_to_ABA(46cc46841198e427).(lba), m_a, s_a, f_a); |
| 127 | } |
| 128 | |
| 129 | // |
| 130 | // BCD conversion functions |
| 131 | // |
| 132 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! bool BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(uint8cxx . . $ uint8# bcd_number) |
| 133 | { |
| 134 | if((bcd_number & 0xF0) >= 0xA0) |
| 135 | return(false); |
| 136 | |
| 137 | if((bcd_number & 0x0F) >= 0x0A) |
| 138 | return(false); |
| 139 | |
| 140 | return(true); |
| 141 | } |
| 142 | |
| 143 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint8cxx . . $ uint8# BCD_to_U8cxx . . $ CDUtility/BCD_to_U8(50106d451684defa).(uint8cxx . . $ uint8# bcd_number) |
| 144 | { |
| 145 | return( ((bcd_number >> 4) * 10) + (bcd_number & 0x0F) ); |
| 146 | } |
| 147 | |
| 148 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint8cxx . . $ uint8# U8_to_BCDcxx . . $ CDUtility/U8_to_BCD(50106d451684defa).(uint8cxx . . $ uint8# num) |
| 149 | { |
| 150 | return( ((num / 10) << 4) + (num % 10) ); |
| 151 | } |
| 152 | |
| 153 | // should always perform the conversion, even if the bcd number is invalid. |
| 154 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! bool BCD_to_U8_checkcxx . . $ CDUtility/BCD_to_U8_check(873100f25ba96511).(uint8cxx . . $ uint8# bcd_number, uint8cxx . . $ uint8# *out_number) |
| 155 | { |
| 156 | *out_number = BCD_to_U8cxx . . $ CDUtility/BCD_to_U8(50106d451684defa).(bcd_number); |
| 157 | |
| 158 | if(!BCD_is_validcxx . . $ CDUtility/BCD_is_valid(cef82f9be00a201a).(bcd_number)) |
| 159 | return(false); |
| 160 | |
| 161 | return(true); |
| 162 | } |
| 163 | |
| 164 | // |
| 165 | // Sector data encoding functions(to full 2352 bytes raw sector). |
| 166 | // |
| 167 | // sector_data must be able to contain at least 2352 bytes. |
| 168 | void encode_mode0_sectorcxx . . $ CDUtility/encode_mode0_sector(30e3fcb1063142c7).(uint32cxx . . $ uint32# aba, uint8cxx . . $ uint8# *sector_data); |
| 169 | void encode_mode1_sectorcxx . . $ CDUtility/encode_mode1_sector(30e3fcb1063142c7).(uint32cxx . . $ uint32# aba, uint8cxx . . $ uint8# *sector_data); // 2048 bytes of user data at offset 16 |
| 170 | void encode_mode2_sectorcxx . . $ CDUtility/encode_mode2_sector(30e3fcb1063142c7).(uint32cxx . . $ uint32# aba, uint8cxx . . $ uint8# *sector_data); // 2336 bytes of user data at offset 16 |
| 171 | void encode_mode2_form1_sectorcxx . . $ CDUtility/encode_mode2_form1_sector(30e3fcb1063142c7).(uint32cxx . . $ uint32# aba, uint8cxx . . $ uint8# *sector_data); // 2048+8 bytes of user data at offset 16 |
| 172 | void encode_mode2_form2_sectorcxx . . $ CDUtility/encode_mode2_form2_sector(30e3fcb1063142c7).(uint32cxx . . $ uint32# aba, uint8cxx . . $ uint8# *sector_data); // 2324+8 bytes of user data at offset 16 |
| 173 | |
| 174 | |
| 175 | // out_buf must be able to contain 2352+96 bytes. |
| 176 | // "mode" is only used if(toc.tracks[100].control & 0x4) |
| 177 | void synth_leadout_sector_lbacxx . . $ CDUtility/synth_leadout_sector_lba(81ffdaf34d0c6954).(const uint8cxx . . $ uint8# mode, const TOCcxx . . $ CDUtility/TOC#& toc, const int32cxx . . $ int32# lba, uint8cxx . . $ uint8#* out_buf); |
| 178 | |
| 179 | // |
| 180 | // User data error detection and correction |
| 181 | // |
| 182 | |
| 183 | // Check EDC of a mode 1 or mode 2 form 1 sector. |
| 184 | // Returns "true" if checksum is ok(matches). |
| 185 | // Returns "false" if checksum mismatch. |
| 186 | // sector_data should contain 2352 bytes of raw sector data. |
| 187 | bool edc_checkcxx . . $ CDUtility/edc_check(ee06816edad3d32e).(const uint8cxx . . $ uint8# *sector_data, bool xa); |
| 188 | |
| 189 | // Check EDC and L-EC data of a mode 1 or mode 2 form 1 sector, and correct bit errors if any exist. |
| 190 | // Returns "true" if errors weren't detected, or they were corrected succesfully. |
| 191 | // Returns "false" if errors couldn't be corrected. |
| 192 | // sector_data should contain 2352 bytes of raw sector data. |
| 193 | bool edc_lec_check_and_correctcxx . . $ CDUtility/edc_lec_check_and_correct(ecc5f6bcf4eac26).(uint8cxx . . $ uint8# *sector_data, bool xa); |
| 194 | |
| 195 | // |
| 196 | // Subchannel(Q in particular) functions |
| 197 | // |
| 198 | |
| 199 | // Returns false on checksum mismatch, true on match. |
| 200 | bool subq_check_checksumcxx . . $ CDUtility/subq_check_checksum(190063cf6fb4afb1).(const uint8cxx . . $ uint8# *subq_buf); |
| 201 | |
| 202 | // Calculates the checksum of Q subchannel data(not including the checksum bytes of course ;)) from subq_buf, and stores it into the appropriate position |
| 203 | // in subq_buf. |
| 204 | void subq_generate_checksumcxx . . $ CDUtility/subq_generate_checksum(f25546b61a629de7).(uint8cxx . . $ uint8# *subq_buf); |
| 205 | |
| 206 | // Deinterleaves 12 bytes of subchannel Q data from 96 bytes of interleaved subchannel PW data. |
| 207 | void subq_deinterleavecxx . . $ CDUtility/subq_deinterleave(b1fdb6ced7ea43e9).(const uint8cxx . . $ uint8# *subpw_buf, uint8cxx . . $ uint8# *subq_buf); |
| 208 | |
| 209 | // Deinterleaves 96 bytes of subchannel P-W data from 96 bytes of interleaved subchannel PW data. |
| 210 | void subpw_deinterleavecxx . . $ CDUtility/subpw_deinterleave(b1fdb6ced7ea43e9).(const uint8cxx . . $ uint8# *in_buf, uint8cxx . . $ uint8# *out_buf); |
| 211 | |
| 212 | // Interleaves 96 bytes of subchannel P-W data from 96 bytes of uninterleaved subchannel PW data. |
| 213 | void subpw_interleavecxx . . $ CDUtility/subpw_interleave(b1fdb6ced7ea43e9).(const uint8cxx . . $ uint8# *in_buf, uint8cxx . . $ uint8# *out_buf); |
| 214 | |
| 215 | // Extrapolates Q subchannel current position data from subq_input, with frame/sector delta position_delta, and writes to subq_output. |
| 216 | // Only valid for ADR_CURPOS. |
| 217 | // subq_input must pass subq_check_checksum(). |
| 218 | // TODO |
| 219 | //void subq_extrapolate(const uint8 *subq_input, int32 position_delta, uint8 *subq_output); |
| 220 | |
| 221 | // (De)Scrambles data sector. |
| 222 | void scrambleize_data_sectorcxx . . $ CDUtility/scrambleize_data_sector(f25546b61a629de7).(uint8cxx . . $ uint8# *sector_data); |
| 223 | } |
| 224 | |
| 225 | #endif |