Skip to content

Commit

Permalink
adding back in some cdrom irq delays
Browse files Browse the repository at this point in the history
  • Loading branch information
timlump committed Jun 20, 2020
1 parent 20be678 commit 8d4d01e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
65 changes: 55 additions & 10 deletions Cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,31 @@ Cdrom::~Cdrom()

void Cdrom::tick()
{
if (pending_response.empty() == false)
{
int delay = pending_response.front().delay;
if (delay != -1) // -1 means this delay is actually waiting for an ack
{
delay--;
if (delay == 0)
{
pending_response_data data = pending_response.front();
pending_response.pop_front();

current_int = data.int_type;
for (auto & iter : data.responses)
{
response_fifo->push(iter);
}

SystemControlCoprocessor::get_instance()->set_irq_bits(system_control::CDROM_BIT);
}
else
{
pending_response.front().delay = delay;
}
}
}
}

void Cdrom::reset()
Expand Down Expand Up @@ -447,8 +471,6 @@ void Cdrom::execute_command(unsigned char command)
default:
throw std::logic_error("not implemented");
}

SystemControlCoprocessor::get_instance()->set_irq_bits(system_control::CDROM_BIT);
}

void Cdrom::execute_test_command()
Expand All @@ -459,13 +481,19 @@ void Cdrom::execute_test_command()
unsigned char sub_function = parameter_fifo->pop();
if (sub_function == 0x20)
{
pending_response_data data;

data.delay = cdrom_response_timings::FIRST_RESPONSE_DELAY;

data.int_type = cdrom_response_interrupts::FIRST_RESPONSE;

// push the cd rom bios version onto the response fifo
response_fifo->push(0x94);
response_fifo->push(0x11);
response_fifo->push(0x18);
response_fifo->push(0xC0);
data.responses.push_back(0x94);
data.responses.push_back(0x11);
data.responses.push_back(0x18);
data.responses.push_back(0xC0);

current_int = cdrom_response_interrupts::FIRST_RESPONSE;
pending_response.push_back(data);
}
else
{
Expand All @@ -475,13 +503,30 @@ void Cdrom::execute_test_command()

void Cdrom::execute_getstat_command()
{
response_fifo->push(0x2);
current_int = cdrom_response_interrupts::FIRST_RESPONSE;
pending_response_data data;

data.delay = cdrom_response_timings::FIRST_RESPONSE_DELAY;
data.int_type = cdrom_response_interrupts::FIRST_RESPONSE;
data.responses.push_back(0x2);

pending_response.push_back(data);
}

void Cdrom::execute_getid_command()
{
throw std::logic_error("not implemented");
execute_getstat_command();

pending_response_data data;

data.int_type = cdrom_response_interrupts::SECOND_RESPONSE;

data.responses.push_back(0x53); // S
data.responses.push_back(0x43); // C
data.responses.push_back(0x45); // E
data.responses.push_back(0x41); // A

pending_response.push_back(data);

}

// this command seems a bit pointless
Expand Down
1 change: 1 addition & 0 deletions Cdrom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class Cdrom : public Bus::BusDevice

struct pending_response_data
{
int delay = -1;
cdrom_response_interrupts int_type;
std::vector<unsigned char> responses;
};
Expand Down
6 changes: 6 additions & 0 deletions CdromEnums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ enum class cdrom_response_interrupts : unsigned char
// N/A
INT6 = 6,
INT7 = 7
};

enum cdrom_response_timings
{
FIRST_RESPONSE_DELAY = 0xC4E1,
SECOND_REPONSE_DELAY = 0x4a00
};

0 comments on commit 8d4d01e

Please sign in to comment.