diff --git a/Machines/Acorn/Tube/Tube6502.hpp b/Machines/Acorn/Tube/Tube6502.hpp index 184e5ed2e..d55c1b1f7 100644 --- a/Machines/Acorn/Tube/Tube6502.hpp +++ b/Machines/Acorn/Tube/Tube6502.hpp @@ -14,6 +14,10 @@ namespace Acorn::Tube { +// TODO: the handling of the 'ROM' below seems to match what I'm reading but doesn't make a lot +// of sense to me; it is copied into RAM (by whom?) and then copied in again upon every reset +// (again: by whom?). + template struct Tube6502 { public: @@ -33,10 +37,8 @@ public: const uint8_t result = ula_.parasite_read(address); value = result; update_interrupts(); -// printf("Parasite read %04x of %02x\n", +address, result); } else { ula_.parasite_write(address, value); -// printf("Parasite write %04x of %02x\n", +address, +value); } } else { if constexpr (is_read(operation)) { @@ -48,9 +50,8 @@ public: return Cycles(1); } - void set_rom(const std::vector &source) { - // TODO: verify the ROM is 2kb. - // TODO: determine whether this really is ROM, or is ROM that should have copied itself to RAM, or is something else. + void set_rom(std::vector source) { + source.resize(sizeof(rom_)); std::copy(source.begin(), source.end(), rom_); reinstall_rom(); } diff --git a/Machines/Acorn/Tube/ULA.hpp b/Machines/Acorn/Tube/ULA.hpp index 459c65d66..aaafb33d3 100644 --- a/Machines/Acorn/Tube/ULA.hpp +++ b/Machines/Acorn/Tube/ULA.hpp @@ -29,38 +29,23 @@ struct ULA { to_host4_(*this, 0x01) {} - uint8_t status() const { - return flags_; - } - - void set_status(const uint8_t value) { - const uint8_t bits = value & 0x3f; - if(value & 0x80) { - flags_ |= bits; - } else { - flags_ &= ~bits; - } - } - + /// @returns @c true if the parasite's reset line should be active. bool parasite_reset() const { return !(flags_ & 0x20); } + /// Call-in for the FIFOs; indicates that a FIFO just went from empty to not-empty, + /// which might cause an interrupt elsewhere depending on the mask and on whether + /// that interrupt is enabled. void fifo_has_data(const uint8_t mask) { if(!(flags_ & mask)) return; switch(mask) { - default: __builtin_unreachable(); - case 0x01: - host_.set_host_tube_irq(); - break; + default: __builtin_unreachable(); + case 0x01: host_.set_host_tube_irq(); break; case 0x02: - case 0x04: - host_.set_parasite_tube_irq(); - break; - case 0x08: - host_.set_parasite_tube_nmi(); - break; + case 0x04: host_.set_parasite_tube_irq(); break; + case 0x08: host_.set_parasite_tube_nmi(); break; } } @@ -129,6 +114,21 @@ struct ULA { } } private: + uint8_t status() const { + return flags_; + } + + void set_status(const uint8_t value) { + const uint8_t bits = value & 0x3f; + if(value & 0x80) { + flags_ |= bits; + } else { + flags_ &= ~bits; + } + + // TODO: understand meaning of bit 4. + } + HostT &host_; uint8_t flags_ = 0x3f;