Skip to content

Commit a81156c

Browse files
cdromdrive: convert MSF values to BCD.
1 parent f31c71e commit a81156c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

devices/storage/cdromdrive.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
DingusPPC - The Experimental PowerPC Macintosh emulator
3-
Copyright (C) 2018-23 divingkatae and maximum
3+
Copyright (C) 2018-24 divingkatae and maximum
44
(theweirdo) spatium
55
66
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -138,8 +138,17 @@ uint32_t CdromDrive::report_capacity(uint8_t *data_ptr) {
138138
return 8;
139139
}
140140

141+
uint8_t CdromDrive::hex_to_bcd(const uint8_t val) {
142+
uint8_t hi = val / 10;
143+
uint8_t lo = val % 10;
144+
return (hi << 4) | lo;
145+
}
146+
141147
AddrMsf CdromDrive::lba_to_msf(const int lba) {
142-
return {lba / 4500, /*.min*/ (lba / 75) % 60, /*.sec*/ lba % 75 /*.frm*/};
148+
return {hex_to_bcd( lba / 4500), /*.min*/
149+
hex_to_bcd((lba / 75) % 60), /*.sec*/
150+
hex_to_bcd( lba % 75) /*.frm*/
151+
};
143152
}
144153

145154
uint32_t CdromDrive::read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr) {

devices/storage/cdromdrive.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
DingusPPC - The Experimental PowerPC Macintosh emulator
3-
Copyright (C) 2018-23 divingkatae and maximum
3+
Copyright (C) 2018-24 divingkatae and maximum
44
(theweirdo) spatium
55
66
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -69,6 +69,7 @@ class CdromDrive : public BlockStorageDevice {
6969

7070
protected:
7171
std::function<void(uint8_t, uint8_t)> set_error;
72+
uint8_t hex_to_bcd(const uint8_t val);
7273
AddrMsf lba_to_msf(const int lba);
7374

7475
TrackDescriptor tracks[CDROM_MAX_TRACKS];

0 commit comments

Comments
 (0)