diff options
author | 2015-06-07 17:37:34 +0200 | |
---|---|---|
committer | 2015-06-07 17:37:34 +0200 | |
commit | b6ce8ee991c7e14ca214a2931bfbc4e4a5a0dc0f (patch) | |
tree | da1e239053b7bfd9e841a103bbb36aefb71c4e7f /src/lib/util/cdrom.c | |
parent | b6a4cf45ca6fdf842b319806d61d638cf2d8b2d2 (diff) |
Licenses for Raphael Nabet (nw)
Diffstat (limited to 'src/lib/util/cdrom.c')
-rw-r--r-- | src/lib/util/cdrom.c | 423 |
1 files changed, 376 insertions, 47 deletions
diff --git a/src/lib/util/cdrom.c b/src/lib/util/cdrom.c index 6655418583a..40f3caf4190 100644 --- a/src/lib/util/cdrom.c +++ b/src/lib/util/cdrom.c @@ -28,11 +28,41 @@ DEBUGGING ***************************************************************************/ +/** @brief The verbose. */ #define VERBOSE (0) #if VERBOSE + +/** + * @def LOG(x) do + * + * @brief A macro that defines log. + * + * @param x The void to process. + */ + #define LOG(x) do { if (VERBOSE) logerror x; } while (0) + +/** + * @fn void CLIB_DECL logerror(const char *text, ...) ATTR_PRINTF(1,2); + * + * @brief Logerrors the given text. + * + * @param text The text. + * + * @return A CLIB_DECL. + */ + void CLIB_DECL logerror(const char *text, ...) ATTR_PRINTF(1,2); #else + +/** + * @def LOG(x); + * + * @brief A macro that defines log. + * + * @param x The void to process. + */ + #define LOG(x) #endif @@ -42,18 +72,27 @@ void CLIB_DECL logerror(const char *text, ...) ATTR_PRINTF(1,2); CONSTANTS ***************************************************************************/ -const int SYNC_OFFSET = 0x000; // offset within sector -const int SYNC_NUM_BYTES = 12; // 12 bytes +/** @brief offset within sector. */ +const int SYNC_OFFSET = 0x000; +/** @brief 12 bytes. */ +const int SYNC_NUM_BYTES = 12; -const int MODE_OFFSET = 0x00f; // offset within sector +/** @brief offset within sector. */ +const int MODE_OFFSET = 0x00f; -const int ECC_P_OFFSET = 0x81c; // offset within sector -const int ECC_P_NUM_BYTES = 86; // 2 lots of 86 -const int ECC_P_COMP = 24; // 24 bytes each +/** @brief offset within sector. */ +const int ECC_P_OFFSET = 0x81c; +/** @brief 2 lots of 86. */ +const int ECC_P_NUM_BYTES = 86; +/** @brief 24 bytes each. */ +const int ECC_P_COMP = 24; +/** @brief The ECC q offset. */ const int ECC_Q_OFFSET = ECC_P_OFFSET + 2 * ECC_P_NUM_BYTES; -const int ECC_Q_NUM_BYTES = 52; // 2 lots of 52 -const int ECC_Q_COMP = 43; // 43 bytes each +/** @brief 2 lots of 52. */ +const int ECC_Q_NUM_BYTES = 52; +/** @brief 43 bytes each. */ +const int ECC_Q_COMP = 43; @@ -61,11 +100,21 @@ const int ECC_Q_COMP = 43; // 43 bytes each TYPE DEFINITIONS ***************************************************************************/ +/** + * @struct cdrom_file + * + * @brief A cdrom file. + */ + struct cdrom_file { + /** @brief The chd. */ chd_file * chd; /* CHD file */ + /** @brief The cdtoc. */ cdrom_toc cdtoc; /* TOC for the CD */ + /** @brief Information describing the track. */ chdcd_track_input_info track_info; /* track info */ + /** @brief The fhandle[ CD maximum tracks]. */ core_file * fhandle[CD_MAX_TRACKS];/* file handle */ }; @@ -80,6 +129,18 @@ struct cdrom_file and the track number -------------------------------------------------*/ +/** + * @fn INLINE UINT32 physical_to_chd_lba(cdrom_file *file, UINT32 physlba, UINT32 &tracknum) + * + * @brief Physical to chd lba. + * + * @param [in,out] file If non-null, the file. + * @param physlba The physlba. + * @param [in,out] tracknum The tracknum. + * + * @return An UINT32. + */ + INLINE UINT32 physical_to_chd_lba(cdrom_file *file, UINT32 physlba, UINT32 &tracknum) { UINT32 chdlba; @@ -102,6 +163,18 @@ INLINE UINT32 physical_to_chd_lba(cdrom_file *file, UINT32 physlba, UINT32 &trac and the track number -------------------------------------------------*/ +/** + * @fn INLINE UINT32 logical_to_chd_lba(cdrom_file *file, UINT32 loglba, UINT32 &tracknum) + * + * @brief Logical to chd lba. + * + * @param [in,out] file If non-null, the file. + * @param loglba The loglba. + * @param [in,out] tracknum The tracknum. + * + * @return An UINT32. + */ + INLINE UINT32 logical_to_chd_lba(cdrom_file *file, UINT32 loglba, UINT32 &tracknum) { UINT32 chdlba, physlba; @@ -134,6 +207,16 @@ INLINE UINT32 logical_to_chd_lba(cdrom_file *file, UINT32 loglba, UINT32 &trackn BASE FUNCTIONALITY ***************************************************************************/ +/** + * @fn cdrom_file *cdrom_open(const char *inputfile) + * + * @brief Queries if a given cdrom open. + * + * @param inputfile The inputfile. + * + * @return null if it fails, else a cdrom_file*. + */ + cdrom_file *cdrom_open(const char *inputfile) { int i; @@ -220,6 +303,16 @@ cdrom_file *cdrom_open(const char *inputfile) already-opened CHD file -------------------------------------------------*/ +/** + * @fn cdrom_file *cdrom_open(chd_file *chd) + * + * @brief Queries if a given cdrom open. + * + * @param [in,out] chd If non-null, the chd. + * + * @return null if it fails, else a cdrom_file*. + */ + cdrom_file *cdrom_open(chd_file *chd) { int i; @@ -308,6 +401,14 @@ cdrom_file *cdrom_open(chd_file *chd) cdrom_close - "close" a CD-ROM file -------------------------------------------------*/ +/** + * @fn void cdrom_close(cdrom_file *file) + * + * @brief Cdrom close. + * + * @param [in,out] file If non-null, the file. + */ + void cdrom_close(cdrom_file *file) { if (file == NULL) @@ -330,6 +431,22 @@ void cdrom_close(cdrom_file *file) CORE READ ACCESS ***************************************************************************/ +/** + * @fn chd_error read_partial_sector(cdrom_file *file, void *dest, UINT32 lbasector, UINT32 chdsector, UINT32 tracknum, UINT32 startoffs, UINT32 length) + * + * @brief Reads partial sector. + * + * @param [in,out] file If non-null, the file. + * @param [in,out] dest If non-null, destination for the. + * @param lbasector The lbasector. + * @param chdsector The chdsector. + * @param tracknum The tracknum. + * @param startoffs The startoffs. + * @param length The length. + * + * @return The partial sector. + */ + chd_error read_partial_sector(cdrom_file *file, void *dest, UINT32 lbasector, UINT32 chdsector, UINT32 tracknum, UINT32 startoffs, UINT32 length) { chd_error result = CHDERR_NONE; @@ -388,6 +505,20 @@ chd_error read_partial_sector(cdrom_file *file, void *dest, UINT32 lbasector, UI from a CD-ROM -------------------------------------------------*/ +/** + * @fn UINT32 cdrom_read_data(cdrom_file *file, UINT32 lbasector, void *buffer, UINT32 datatype, bool phys) + * + * @brief Cdrom read data. + * + * @param [in,out] file If non-null, the file. + * @param lbasector The lbasector. + * @param [in,out] buffer If non-null, the buffer. + * @param datatype The datatype. + * @param phys true to physical. + * + * @return An UINT32. + */ + UINT32 cdrom_read_data(cdrom_file *file, UINT32 lbasector, void *buffer, UINT32 datatype, bool phys) { if (file == NULL) @@ -460,6 +591,19 @@ UINT32 cdrom_read_data(cdrom_file *file, UINT32 lbasector, void *buffer, UINT32 a sector -------------------------------------------------*/ +/** + * @fn UINT32 cdrom_read_subcode(cdrom_file *file, UINT32 lbasector, void *buffer, bool phys) + * + * @brief Cdrom read subcode. + * + * @param [in,out] file If non-null, the file. + * @param lbasector The lbasector. + * @param [in,out] buffer If non-null, the buffer. + * @param phys true to physical. + * + * @return An UINT32. + */ + UINT32 cdrom_read_subcode(cdrom_file *file, UINT32 lbasector, void *buffer, bool phys) { if (file == NULL) @@ -497,6 +641,17 @@ UINT32 cdrom_read_subcode(cdrom_file *file, UINT32 lbasector, void *buffer, bool for a physical frame number -------------------------------------------------*/ +/** + * @fn UINT32 cdrom_get_track(cdrom_file *file, UINT32 frame) + * + * @brief Cdrom get track. + * + * @param [in,out] file If non-null, the file. + * @param frame The frame. + * + * @return An UINT32. + */ + UINT32 cdrom_get_track(cdrom_file *file, UINT32 frame) { UINT32 track = 0; @@ -516,6 +671,17 @@ UINT32 cdrom_get_track(cdrom_file *file, UINT32 frame) that a track starts at -------------------------------------------------*/ +/** + * @fn UINT32 cdrom_get_track_start(cdrom_file *file, UINT32 track) + * + * @brief Cdrom get track start. + * + * @param [in,out] file If non-null, the file. + * @param track The track. + * + * @return An UINT32. + */ + UINT32 cdrom_get_track_start(cdrom_file *file, UINT32 track) { if (file == NULL) @@ -533,6 +699,17 @@ UINT32 cdrom_get_track_start(cdrom_file *file, UINT32 track) physical frame number that a track starts at -------------------------------------------------*/ +/** + * @fn UINT32 cdrom_get_track_start_phys(cdrom_file *file, UINT32 track) + * + * @brief Cdrom get track start physical. + * + * @param [in,out] file If non-null, the file. + * @param track The track. + * + * @return An UINT32. + */ + UINT32 cdrom_get_track_start_phys(cdrom_file *file, UINT32 track) { if (file == NULL) @@ -554,6 +731,16 @@ UINT32 cdrom_get_track_start_phys(cdrom_file *file, UINT32 track) number -------------------------------------------------*/ +/** + * @fn int cdrom_get_last_track(cdrom_file *file) + * + * @brief Cdrom get last track. + * + * @param [in,out] file If non-null, the file. + * + * @return An int. + */ + int cdrom_get_last_track(cdrom_file *file) { if (file == NULL) @@ -568,6 +755,17 @@ int cdrom_get_last_track(cdrom_file *file) for a track -------------------------------------------------*/ +/** + * @fn int cdrom_get_adr_control(cdrom_file *file, int track) + * + * @brief Cdrom get address control. + * + * @param [in,out] file If non-null, the file. + * @param track The track. + * + * @return An int. + */ + int cdrom_get_adr_control(cdrom_file *file, int track) { if (file == NULL) @@ -586,6 +784,17 @@ int cdrom_get_adr_control(cdrom_file *file, int track) cdrom_get_track_type - return the track type -------------------------------------------------*/ +/** + * @fn int cdrom_get_track_type(cdrom_file *file, int track) + * + * @brief Cdrom get track type. + * + * @param [in,out] file If non-null, the file. + * @param track The track. + * + * @return An int. + */ + int cdrom_get_track_type(cdrom_file *file, int track) { if (file == NULL) @@ -600,6 +809,16 @@ int cdrom_get_track_type(cdrom_file *file, int track) CD-ROM -------------------------------------------------*/ +/** + * @fn const cdrom_toc *cdrom_get_toc(cdrom_file *file) + * + * @brief Cdrom get TOC. + * + * @param [in,out] file If non-null, the file. + * + * @return null if it fails, else a cdrom_toc*. + */ + const cdrom_toc *cdrom_get_toc(cdrom_file *file) { if (file == NULL) @@ -620,6 +839,16 @@ const cdrom_toc *cdrom_get_toc(cdrom_file *file) and track data size -------------------------------------------------*/ +/** + * @fn static void cdrom_get_info_from_type_string(const char *typestring, UINT32 *trktype, UINT32 *datasize) + * + * @brief Cdrom get information from type string. + * + * @param typestring The typestring. + * @param [in,out] trktype If non-null, the trktype. + * @param [in,out] datasize If non-null, the datasize. + */ + static void cdrom_get_info_from_type_string(const char *typestring, UINT32 *trktype, UINT32 *datasize) { if (!strcmp(typestring, "MODE1")) @@ -705,6 +934,15 @@ static void cdrom_get_info_from_type_string(const char *typestring, UINT32 *trkt and track data size -------------------------------------------------*/ +/** + * @fn void cdrom_convert_type_string_to_track_info(const char *typestring, cdrom_track_info *info) + * + * @brief Cdrom convert type string to track information. + * + * @param typestring The typestring. + * @param [in,out] info If non-null, the information. + */ + void cdrom_convert_type_string_to_track_info(const char *typestring, cdrom_track_info *info) { cdrom_get_info_from_type_string(typestring, &info->trktype, &info->datasize); @@ -716,6 +954,15 @@ void cdrom_convert_type_string_to_track_info(const char *typestring, cdrom_track and pregap data size -------------------------------------------------*/ +/** + * @fn void cdrom_convert_type_string_to_pregap_info(const char *typestring, cdrom_track_info *info) + * + * @brief Cdrom convert type string to pregap information. + * + * @param typestring The typestring. + * @param [in,out] info If non-null, the information. + */ + void cdrom_convert_type_string_to_pregap_info(const char *typestring, cdrom_track_info *info) { cdrom_get_info_from_type_string(typestring, &info->pgtype, &info->pgdatasize); @@ -727,6 +974,15 @@ void cdrom_convert_type_string_to_pregap_info(const char *typestring, cdrom_trac and track subcode data size -------------------------------------------------*/ +/** + * @fn void cdrom_convert_subtype_string_to_track_info(const char *typestring, cdrom_track_info *info) + * + * @brief Cdrom convert subtype string to track information. + * + * @param typestring The typestring. + * @param [in,out] info If non-null, the information. + */ + void cdrom_convert_subtype_string_to_track_info(const char *typestring, cdrom_track_info *info) { if (!strcmp(typestring, "RW")) @@ -747,6 +1003,15 @@ void cdrom_convert_subtype_string_to_track_info(const char *typestring, cdrom_tr and track subcode data size -------------------------------------------------*/ +/** + * @fn void cdrom_convert_subtype_string_to_pregap_info(const char *typestring, cdrom_track_info *info) + * + * @brief Cdrom convert subtype string to pregap information. + * + * @param typestring The typestring. + * @param [in,out] info If non-null, the information. + */ + void cdrom_convert_subtype_string_to_pregap_info(const char *typestring, cdrom_track_info *info) { if (!strcmp(typestring, "RW")) @@ -766,6 +1031,16 @@ void cdrom_convert_subtype_string_to_pregap_info(const char *typestring, cdrom_t associated with the given type -------------------------------------------------*/ +/** + * @fn const char *cdrom_get_type_string(UINT32 trktype) + * + * @brief Cdrom get type string. + * + * @param trktype The trktype. + * + * @return null if it fails, else a char*. + */ + const char *cdrom_get_type_string(UINT32 trktype) { switch (trktype) @@ -788,6 +1063,16 @@ const char *cdrom_get_type_string(UINT32 trktype) associated with the given subcode type -------------------------------------------------*/ +/** + * @fn const char *cdrom_get_subtype_string(UINT32 subtype) + * + * @brief Cdrom get subtype string. + * + * @param subtype The subtype. + * + * @return null if it fails, else a char*. + */ + const char *cdrom_get_subtype_string(UINT32 subtype) { switch (subtype) @@ -809,6 +1094,17 @@ const char *cdrom_get_subtype_string(UINT32 subtype) TOC structure -------------------------------------------------*/ +/** + * @fn chd_error cdrom_parse_metadata(chd_file *chd, cdrom_toc *toc) + * + * @brief Cdrom parse metadata. + * + * @param [in,out] chd If non-null, the chd. + * @param [in,out] toc If non-null, the TOC. + * + * @return A chd_error. + */ + chd_error cdrom_parse_metadata(chd_file *chd, cdrom_toc *toc) { std::string metadata; @@ -975,6 +1271,17 @@ chd_error cdrom_parse_metadata(chd_file *chd, cdrom_toc *toc) cdrom_write_metadata - write metadata -------------------------------------------------*/ +/** + * @fn chd_error cdrom_write_metadata(chd_file *chd, const cdrom_toc *toc) + * + * @brief Cdrom write metadata. + * + * @param [in,out] chd If non-null, the chd. + * @param toc The TOC. + * + * @return A chd_error. + */ + chd_error cdrom_write_metadata(chd_file *chd, const cdrom_toc *toc) { chd_error err; @@ -1019,11 +1326,11 @@ chd_error cdrom_write_metadata(chd_file *chd, const cdrom_toc *toc) return CHDERR_NONE; } - -//------------------------------------------------- -// ECC lookup tables -// pre-calculated tables for ECC data calcs -//------------------------------------------------- +/** + * @brief ------------------------------------------------- + * ECC lookup tables pre-calculated tables for ECC data calcs + * -------------------------------------------------. + */ static const UINT8 ecclow[256] = { @@ -1045,6 +1352,7 @@ static const UINT8 ecclow[256] = 0xfd, 0xff, 0xf9, 0xfb, 0xf5, 0xf7, 0xf1, 0xf3, 0xed, 0xef, 0xe9, 0xeb, 0xe5, 0xe7, 0xe1, 0xe3 }; +/** @brief The ecchigh[ 256]. */ static const UINT8 ecchigh[256] = { 0x00, 0xf4, 0xf5, 0x01, 0xf7, 0x03, 0x02, 0xf6, 0xf3, 0x07, 0x06, 0xf2, 0x04, 0xf0, 0xf1, 0x05, @@ -1065,13 +1373,12 @@ static const UINT8 ecchigh[256] = 0x50, 0xa4, 0xa5, 0x51, 0xa7, 0x53, 0x52, 0xa6, 0xa3, 0x57, 0x56, 0xa2, 0x54, 0xa0, 0xa1, 0x55 }; - -//------------------------------------------------- -// poffsets - each row represents the addresses -// used to calculate a byte of the ECC P data -// 86 (*2) ECC P bytes, 24 values represented by -// each -//------------------------------------------------- +/** + * @brief ------------------------------------------------- + * poffsets - each row represents the addresses used to calculate a byte of the ECC P + * data 86 (*2) ECC P bytes, 24 values represented by each + * -------------------------------------------------. + */ static const UINT16 poffsets[ECC_P_NUM_BYTES][ECC_P_COMP] = { @@ -1163,13 +1470,12 @@ static const UINT16 poffsets[ECC_P_NUM_BYTES][ECC_P_COMP] = { 0x055,0x0ab,0x101,0x157,0x1ad,0x203,0x259,0x2af,0x305,0x35b,0x3b1,0x407,0x45d,0x4b3,0x509,0x55f,0x5b5,0x60b,0x661,0x6b7,0x70d,0x763,0x7b9,0x80f } }; - -//------------------------------------------------- -// qoffsets - each row represents the addresses -// used to calculate a byte of the ECC Q data -// 52 (*2) ECC Q bytes, 43 values represented by -// each -//------------------------------------------------- +/** + * @brief ------------------------------------------------- + * qoffsets - each row represents the addresses used to calculate a byte of the ECC Q + * data 52 (*2) ECC Q bytes, 43 values represented by each + * -------------------------------------------------. + */ static const UINT16 qoffsets[ECC_Q_NUM_BYTES][ECC_Q_COMP] = { @@ -1240,11 +1546,19 @@ inline UINT8 ecc_source_byte(const UINT8 *sector, UINT32 offset) return (sector[MODE_OFFSET] == 2 && offset < 4) ? 0x00 : sector[SYNC_OFFSET + SYNC_NUM_BYTES + offset]; } - -//------------------------------------------------- -// ecc_compute_bytes - calculate an ECC value -// (P or Q) -//------------------------------------------------- +/** + * @fn void ecc_compute_bytes(const UINT8 *sector, const UINT16 *row, int rowlen, UINT8 &val1, UINT8 &val2) + * + * @brief ------------------------------------------------- + * ecc_compute_bytes - calculate an ECC value (P or Q) + * -------------------------------------------------. + * + * @param sector The sector. + * @param row The row. + * @param rowlen The rowlen. + * @param [in,out] val1 The first value. + * @param [in,out] val2 The second value. + */ void ecc_compute_bytes(const UINT8 *sector, const UINT16 *row, int rowlen, UINT8 &val1, UINT8 &val2) { @@ -1259,11 +1573,17 @@ void ecc_compute_bytes(const UINT8 *sector, const UINT16 *row, int rowlen, UINT8 val2 ^= val1; } - -//------------------------------------------------- -// ecc_verify - verify the P and Q ECC codes in -// a sector -//------------------------------------------------- +/** + * @fn bool ecc_verify(const UINT8 *sector) + * + * @brief ------------------------------------------------- + * ecc_verify - verify the P and Q ECC codes in a sector + * -------------------------------------------------. + * + * @param sector The sector. + * + * @return true if it succeeds, false if it fails. + */ bool ecc_verify(const UINT8 *sector) { @@ -1287,11 +1607,16 @@ bool ecc_verify(const UINT8 *sector) return true; } - -//------------------------------------------------- -// ecc_generate - generate the P and Q ECC codes -// for a sector, overwriting any existing codes -//------------------------------------------------- +/** + * @fn void ecc_generate(UINT8 *sector) + * + * @brief ------------------------------------------------- + * ecc_generate - generate the P and Q ECC codes for a sector, overwriting any + * existing codes + * -------------------------------------------------. + * + * @param [in,out] sector If non-null, the sector. + */ void ecc_generate(UINT8 *sector) { @@ -1304,11 +1629,15 @@ void ecc_generate(UINT8 *sector) ecc_compute_bytes(sector, qoffsets[byte], ECC_Q_COMP, sector[ECC_Q_OFFSET + byte], sector[ECC_Q_OFFSET + ECC_Q_NUM_BYTES + byte]); } - -//------------------------------------------------- -// ecc_clear - erase the ECC P and Q cods to 0 -// within a sector -//------------------------------------------------- +/** + * @fn void ecc_clear(UINT8 *sector) + * + * @brief ------------------------------------------------- + * ecc_clear - erase the ECC P and Q cods to 0 within a sector + * -------------------------------------------------. + * + * @param [in,out] sector If non-null, the sector. + */ void ecc_clear(UINT8 *sector) { |