1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-25 18:30:07 +00:00

Makes first attempt at giving the Z80 something to do.

This commit is contained in:
Thomas Harte 2021-06-14 21:29:56 -04:00
parent b5340c8f74
commit 2a2ac1227b

View File

@ -23,7 +23,7 @@ class ConcreteMachine:
public MachineTypes::ScanProducer,
public MachineTypes::TimedMachine {
public:
ConcreteMachine(const Analyser::Static::Enterprise::Target &target, const ROMMachine::ROMFetcher &rom_fetcher) :
ConcreteMachine([[maybe_unused]] const Analyser::Static::Enterprise::Target &target, const ROMMachine::ROMFetcher &rom_fetcher) :
z80_(*this) {
// Request a clock of 4Mhz; this'll be mapped upwards for Nick and Dave elsewhere.
set_clock_rate(4'000'000);
@ -34,8 +34,45 @@ class ConcreteMachine:
throw ROMMachine::Error::MissingROMs;
}
(void)target;
(void)rom_fetcher;
// Take a reasonable guess at the initial memory configuration.
page<0>(0x00);
page<1>(0x01);
page<2>(0xfe);
page<3>(0xff);
}
// MARK: - Z80::BusHandler.
forceinline HalfCycles perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) {
using PartialMachineCycle = CPU::Z80::PartialMachineCycle;
const uint16_t address = cycle.address ? *cycle.address : 0x0000;
// TODO: possibly apply an access penalty.
switch(cycle.operation) {
default: break;
case CPU::Z80::PartialMachineCycle::Input:
case CPU::Z80::PartialMachineCycle::Output:
assert(false);
break;
case CPU::Z80::PartialMachineCycle::Read:
case CPU::Z80::PartialMachineCycle::ReadOpcode:
if(read_pointers_[address >> 14]) {
*cycle.value = read_pointers_[address >> 14][address];
} else {
*cycle.value = 0xff;
}
break;
case CPU::Z80::PartialMachineCycle::Write:
if(write_pointers_[address >> 14]) {
write_pointers_[address >> 14][address] = *cycle.value;
}
break;
}
return HalfCycles(0);
}
private:
@ -43,11 +80,32 @@ class ConcreteMachine:
std::array<uint8_t, 32 * 1024> exos_;
std::array<uint8_t, 256 * 1024> ram_;
const uint8_t min_ram_slot_ = 0xff - 3;
// MARK: - Z80::BusHandler.
forceinline HalfCycles perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) {
(void)cycle;
return HalfCycles(0);
const uint8_t *read_pointers_[4];
uint8_t *write_pointers_[4];
uint8_t pages_[4];
template <size_t slot> void page(uint8_t offset) {
pages_[slot] = offset;
if(offset < 2) {
page<slot>(&exos_[offset * 0x4000], nullptr);
return;
}
if(offset >= min_ram_slot_) {
const size_t address = (offset - min_ram_slot_) * 0x4000;
page<slot>(&ram_[address], &ram_[address]);
return;
}
page<slot>(nullptr, nullptr);
}
template <size_t slot> void page(const uint8_t *read, uint8_t *write) {
read_pointers_[slot] = read ? read - (slot * 0x4000) : nullptr;
write_pointers_[slot] = write ? write - (slot * 0x4000) : nullptr;
}
// MARK: - ScanProducer
@ -61,7 +119,7 @@ class ConcreteMachine:
// MARK: - TimedMachine
void run_for(const Cycles cycles) override {
(void)cycles;
z80_.run_for(cycles);
}
};