2024-03-04 17:06:43 +00:00
|
|
|
//
|
|
|
|
// Archimedes.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 04/03/2024.
|
|
|
|
// Copyright © 2024 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Archimedes.hpp"
|
|
|
|
|
|
|
|
#include "../../AudioProducer.hpp"
|
|
|
|
#include "../../KeyboardMachine.hpp"
|
|
|
|
#include "../../MediaTarget.hpp"
|
|
|
|
#include "../../ScanProducer.hpp"
|
|
|
|
#include "../../TimedMachine.hpp"
|
|
|
|
|
2024-03-04 17:08:46 +00:00
|
|
|
#include "../../../InstructionSets/ARM/Executor.hpp"
|
|
|
|
|
2024-03-05 02:09:24 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <vector>
|
|
|
|
|
2024-03-04 17:06:43 +00:00
|
|
|
namespace Archimedes {
|
|
|
|
|
2024-03-04 17:08:46 +00:00
|
|
|
struct Memory {
|
2024-03-05 02:09:24 +00:00
|
|
|
void set_rom(const std::vector<uint8_t> &rom) {
|
|
|
|
std::copy(
|
|
|
|
rom.begin(),
|
|
|
|
rom.begin() + static_cast<ptrdiff_t>(std::min(rom.size(), rom_.size())),
|
|
|
|
rom_.begin());
|
|
|
|
}
|
2024-03-04 17:08:46 +00:00
|
|
|
|
|
|
|
template <typename IntT>
|
|
|
|
bool write(uint32_t address, IntT source, InstructionSet::ARM::Mode mode, bool trans) {
|
|
|
|
(void)mode;
|
|
|
|
(void)trans;
|
|
|
|
|
|
|
|
printf("W of %08x to %08x [%lu]\n", source, address, sizeof(IntT));
|
|
|
|
|
|
|
|
if(has_moved_rom_ && address < ram_.size()) {
|
|
|
|
*reinterpret_cast<IntT *>(&ram_[address]) = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename IntT>
|
|
|
|
bool read(uint32_t address, IntT &source, InstructionSet::ARM::Mode mode, bool trans) {
|
|
|
|
(void)mode;
|
|
|
|
(void)trans;
|
|
|
|
|
|
|
|
if(address >= 0x3800000) {
|
|
|
|
has_moved_rom_ = true;
|
2024-03-05 02:09:24 +00:00
|
|
|
source = *reinterpret_cast<const IntT *>(&rom_[address - 0x3800000]);
|
2024-03-04 17:08:46 +00:00
|
|
|
} else if(!has_moved_rom_) {
|
|
|
|
// TODO: this is true only very transiently.
|
2024-03-05 02:09:24 +00:00
|
|
|
source = *reinterpret_cast<const IntT *>(&rom_[address]);
|
2024-03-04 17:08:46 +00:00
|
|
|
} else if(address < ram_.size()) {
|
|
|
|
source = *reinterpret_cast<const IntT *>(&ram_[address]);
|
|
|
|
} else {
|
|
|
|
source = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool has_moved_rom_ = false;
|
|
|
|
std::array<uint8_t, 4*1024*1024> ram_{};
|
2024-03-05 02:09:24 +00:00
|
|
|
std::array<uint8_t, 2*1024*1024> rom_;
|
2024-03-04 17:08:46 +00:00
|
|
|
};
|
|
|
|
|
2024-03-04 17:06:43 +00:00
|
|
|
class ConcreteMachine:
|
|
|
|
public Machine,
|
2024-03-05 02:09:24 +00:00
|
|
|
public MachineTypes::MediaTarget,
|
2024-03-04 17:06:43 +00:00
|
|
|
public MachineTypes::TimedMachine,
|
|
|
|
public MachineTypes::ScanProducer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ConcreteMachine(
|
|
|
|
const Analyser::Static::Target &target,
|
|
|
|
const ROMMachine::ROMFetcher &rom_fetcher
|
|
|
|
) {
|
2024-03-05 02:09:24 +00:00
|
|
|
constexpr ROM::Name risc_os = ROM::Name::AcornRISCOS319;
|
|
|
|
ROM::Request request(risc_os);
|
|
|
|
auto roms = rom_fetcher(request);
|
|
|
|
if(!request.validate(roms)) {
|
|
|
|
throw ROMMachine::Error::MissingROMs;
|
|
|
|
}
|
|
|
|
|
|
|
|
executor_.bus.set_rom(roms.find(risc_os)->second);
|
|
|
|
|
|
|
|
// TODO: pick a sensible clock rate; this is just code for '20 MIPS, please'.
|
|
|
|
set_clock_rate(20'000'000);
|
|
|
|
|
|
|
|
insert_media(target.media);
|
2024-03-04 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// MARK: - ScanProducer.
|
|
|
|
void set_scan_target(Outputs::Display::ScanTarget *scan_target) override {
|
|
|
|
(void)scan_target;
|
|
|
|
}
|
|
|
|
Outputs::Display::ScanStatus get_scaled_scan_status() const override {
|
|
|
|
return Outputs::Display::ScanStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - TimedMachine.
|
|
|
|
void run_for(Cycles cycles) override {
|
2024-03-05 02:09:24 +00:00
|
|
|
auto instructions = cycles.as<int>();
|
|
|
|
while(instructions--) {
|
|
|
|
uint32_t instruction;
|
|
|
|
executor_.bus.read(executor_.pc(), instruction, executor_.registers().mode(), false);
|
|
|
|
// TODO: what if abort? How about pipeline prefetch?
|
|
|
|
|
|
|
|
InstructionSet::ARM::execute<arm_model>(instruction, executor_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - MediaTarget
|
|
|
|
bool insert_media(const Analyser::Static::Media &) override {
|
|
|
|
// int c = 0;
|
|
|
|
// for(auto &disk : media.disks) {
|
|
|
|
// fdc_.set_disk(disk, c);
|
|
|
|
// c++;
|
|
|
|
// if(c == 4) break;
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
return false;
|
2024-03-04 17:06:43 +00:00
|
|
|
}
|
2024-03-04 17:08:46 +00:00
|
|
|
|
|
|
|
// MARK: - ARM execution
|
2024-03-05 02:09:24 +00:00
|
|
|
static constexpr auto arm_model = InstructionSet::ARM::Model::ARMv2;
|
|
|
|
InstructionSet::ARM::Executor<arm_model, Memory> executor_;
|
2024-03-04 17:06:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace Archimedes;
|
|
|
|
|
|
|
|
std::unique_ptr<Machine> Machine::Archimedes(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
|
|
|
|
return std::make_unique<ConcreteMachine>(*target, rom_fetcher);
|
|
|
|
}
|