Skip to content

Commit

Permalink
cdrom: 75/150 sectors per second speed
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Oct 19, 2021
1 parent 4ef44fb commit e33cbf5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/device/cdrom/cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace device {
namespace cdrom {

const int CPU_FREQ = 38'868'800;

CDROM::CDROM(System* sys) : sys(sys) {
verbose = config.debug.log.cdrom;
disc = std::make_unique<disc::Empty>();
Expand Down Expand Up @@ -151,9 +149,8 @@ void CDROM::step(int cycles) {
}
}

const int CD_SECTOR_SIZE = 2048;
const int sectorsPerSecond = (44100 * 2 * 2) / CD_SECTOR_SIZE;
const int cyclesPerSector = (CPU_FREQ / sectorsPerSecond) / (mode.speed ? 2 : 1); // not perfect division
const int sectorsPerSecond = mode.speed ? 150 : 75;
const int cyclesPerSector = timing::CPU_CLOCK / sectorsPerSecond;
for (int i = 0; i < readcnt / cyclesPerSector; i++) {
handleSector();
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const float CYCLES_PER_LINE_PAL = 3406.1f;
const int LINES_TOTAL_NTSC = 263;
const int LINES_TOTAL_PAL = 314;
#else
const float CYCLES_PER_LINE_NTSC = 3372;
const float CYCLES_PER_LINE_NTSC = 3372.7f;
const float CYCLES_PER_LINE_PAL = 3389;
const int LINES_TOTAL_NTSC = 263;
const int LINES_TOTAL_PAL = 314;
#endif

const float NTSC_FRAMERATE = (float)GPU_CLOCK / (CYCLES_PER_LINE_NTSC * LINES_TOTAL_NTSC);
const float PAL_FRAMERATE = (float)GPU_CLOCK / (CYCLES_PER_LINE_PAL * LINES_TOTAL_PAL);
const double NTSC_FRAMERATE = (double)GPU_CLOCK / (CYCLES_PER_LINE_NTSC * LINES_TOTAL_NTSC);
const double PAL_FRAMERATE = (double)GPU_CLOCK / (CYCLES_PER_LINE_PAL * LINES_TOTAL_PAL);

constexpr uint64_t usToCpuCycles(uint64_t us) { return us * CPU_CLOCK / US_IN_SECOND; }
} // namespace timing

0 comments on commit e33cbf5

Please sign in to comment.