Skip to content

Commit

Permalink
cdrom: removed toggleShell, fixed cddaReport
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Oct 19, 2021
1 parent e33cbf5 commit 34a0f65
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/device/cdrom/cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ void CDROM::handleSector() {
if (mode.cddaReport) {
// Report--> INT1(stat, track, index, mm / amm, ss + 80h / ass, sect / asect, peaklo, peakhi)
auto pos = disc::Position::fromLba(readSector);

int track = disc->getTrackByPosition(pos);

auto posInTrack = pos - disc->getTrackStart(track);

postInterrupt(1);
writeResponse(stat._reg); // stat
writeResponse(bcd::toBcd(track)); // track
writeResponse(0x01); // index
writeResponse(bcd::toBcd(pos.mm)); // minute (disc)
writeResponse(bcd::toBcd(pos.ss)); // second (disc)
writeResponse(bcd::toBcd(pos.ff)); // sector (disc)
writeResponse(bcd::toBcd(posInTrack.mm)); // minute (disc) <<< invalid
writeResponse(bcd::toBcd(posInTrack.ss) | 0x80); // second (disc) <<< invalid
writeResponse(bcd::toBcd(posInTrack.ff)); // sector (disc)
writeResponse(bcd::toBcd(0)); // peaklo
writeResponse(bcd::toBcd(0)); // peakhi

Expand Down
16 changes: 5 additions & 11 deletions src/device/cdrom/cdrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,15 @@ class CDROM {

void setShell(bool opened) {
shellOpen = opened;
if (!shellOpen) {

setMode(Mode::None);
if (opened) {
motor = false;
}
}

bool getShell() const { return shellOpen; }

void toggleShell() {
if (!shellOpen) {
shellOpen = true;
setMode(Mode::None);
} else {
shellOpen = false;
}
}

StatusCode() : _reg(0) { shellOpen = true; }
};

Expand Down Expand Up @@ -202,12 +195,13 @@ class CDROM {

void setShell(bool opened) { stat.setShell(opened); }
bool getShell() const { return stat.getShell(); }
void toggleShell() { stat.toggleShell(); }
void ackMoreData() {
postInterrupt(1);
writeResponse(stat._reg);
}

bool discPresent() { return stat.getShell() == false && disc; }

template <class Archive>
void serialize(Archive& ar) {
ar(status._reg, interruptEnable);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void GUI::mainMenu(std::unique_ptr<System>& sys) {

const char* shellStatus = sys->cdrom->getShell() ? "Close disk tray" : "Open disk tray";
if (ImGui::MenuItem(shellStatus, Key(config.hotkeys["close_tray"]).getButton().c_str())) {
sys->cdrom->toggleShell();
sys->cdrom->setShell(!sys->cdrom->getShell());
}

if (ImGui::MenuItem("Single frame", Key(config.hotkeys["single_frame"]).getButton().c_str())) {
Expand Down
3 changes: 2 additions & 1 deletion src/platform/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ int main(int argc, char** argv) {
toast("Fastboot");
return;
} else if (e.action == Event::File::Load::Action::swap) {
sys->cdrom->setShell(true);
sys->cdrom->disc = std::move(disc);
sys->cdrom->setShell(false);

Expand Down Expand Up @@ -351,7 +352,7 @@ int main(int argc, char** argv) {
}
}
if (button == Key(config.hotkeys["close_tray"])) {
sys->cdrom->toggleShell();
sys->cdrom->setShell(!sys->cdrom->getShell());
toast(fmt::format("Shell {}", sys->cdrom->getShell() ? "open" : "closed"));
}
if (button == Key(config.hotkeys["quick_save"])) {
Expand Down
1 change: 1 addition & 0 deletions src/system_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void loadFile(std::unique_ptr<System>& sys, const std::string& path) {

std::unique_ptr<disc::Disc> disc = disc::load(path);
if (disc) {
sys->cdrom->setShell(true);
sys->cdrom->disc = std::move(disc);
sys->cdrom->setShell(false);
toast(fmt::format("{} loaded", filenameExt));
Expand Down

0 comments on commit 34a0f65

Please sign in to comment.