DC11 code clean-up

This commit is contained in:
folkert van heusden 2024-04-30 13:44:03 +02:00
parent c56eb62560
commit 17e5d59d8b
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
2 changed files with 17 additions and 4 deletions

View file

@ -131,7 +131,7 @@ void dc11::operator()()
registers[line_nr * 4 + 0] |= 128; // DONE: bit 7
if (registers[line_nr * 4 + 0] & 64) // interrupts enabled?
if (is_rx_interrupt_enabled(line_nr))
trigger_interrupt(line_nr);
have_data[line_nr].notify_all();
@ -151,6 +151,16 @@ void dc11::reset()
{
}
bool dc11::is_rx_interrupt_enabled(const int line_nr)
{
return !!(registers[line_nr * 4 + 0] & 64);
}
bool dc11::is_tx_interrupt_enabled(const int line_nr)
{
return !!(registers[line_nr * 4 + 2] & 64);
}
uint8_t dc11::read_byte(const uint16_t addr)
{
uint16_t v = read_word(addr & ~1);
@ -192,10 +202,11 @@ uint16_t dc11::read_word(const uint16_t addr)
recv_buffers[line_nr].erase(recv_buffers[line_nr].begin());
// still data in buffer? generate interrupt
if (recv_buffers[line_nr].empty() == false && (registers[line_nr * 4] & 64)) {
if (recv_buffers[line_nr].empty() == false) {
registers[line_nr * 4 + 0] |= 128; // DONE: bit 7
trigger_interrupt(line_nr);
if (is_rx_interrupt_enabled(line_nr))
trigger_interrupt(line_nr);
}
}
}
@ -236,7 +247,7 @@ void dc11::write_word(const uint16_t addr, uint16_t v)
// TODO handle failed transmit
printf("%ld\r\n", write(pfds[dc11_n_lines + line_nr].fd, &c, 1));
if (registers[line_nr * 4 + 2] & 64)
if (is_tx_interrupt_enabled(line_nr))
trigger_interrupt(line_nr);
}

2
dc11.h
View file

@ -42,6 +42,8 @@ private:
std::mutex input_lock[dc11_n_lines];
void trigger_interrupt(const int line_nr);
bool is_rx_interrupt_enabled(const int line_nr);
bool is_tx_interrupt_enabled(const int line_nr);
public:
dc11(const int base_port, bus *const b);