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"
|
|
|
|
|
2024-03-20 18:25:20 +00:00
|
|
|
#include "HalfDuplexSerial.hpp"
|
|
|
|
#include "InputOutputController.hpp"
|
|
|
|
#include "Keyboard.hpp"
|
2024-03-23 19:43:04 +00:00
|
|
|
#include "KeyboardMapper.hpp"
|
2024-03-20 18:25:20 +00:00
|
|
|
#include "MemoryController.hpp"
|
|
|
|
#include "Sound.hpp"
|
|
|
|
|
2024-03-04 17:06:43 +00:00
|
|
|
#include "../../AudioProducer.hpp"
|
|
|
|
#include "../../KeyboardMachine.hpp"
|
|
|
|
#include "../../MediaTarget.hpp"
|
2024-04-06 17:32:59 +00:00
|
|
|
#include "../../MouseMachine.hpp"
|
2024-03-04 17:06:43 +00:00
|
|
|
#include "../../ScanProducer.hpp"
|
|
|
|
#include "../../TimedMachine.hpp"
|
|
|
|
|
2024-03-25 19:03:54 +00:00
|
|
|
#include "../../../Activity/Source.hpp"
|
|
|
|
|
2024-03-19 15:34:10 +00:00
|
|
|
#include "../../../InstructionSets/ARM/Disassembler.hpp"
|
2024-03-04 17:08:46 +00:00
|
|
|
#include "../../../InstructionSets/ARM/Executor.hpp"
|
2024-03-06 14:54:39 +00:00
|
|
|
#include "../../../Outputs/Log.hpp"
|
2024-03-16 19:00:23 +00:00
|
|
|
#include "../../../Components/I2C/I2C.hpp"
|
2024-03-04 17:08:46 +00:00
|
|
|
|
2024-05-14 01:42:38 +00:00
|
|
|
#include "../../../Analyser/Static/Acorn/Target.hpp"
|
|
|
|
|
2024-03-05 02:09:24 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
2024-03-09 03:54:42 +00:00
|
|
|
#include <set>
|
2024-03-05 02:09:24 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2024-04-18 02:15:05 +00:00
|
|
|
namespace Archimedes {
|
2024-03-05 02:43:06 +00:00
|
|
|
|
2024-03-04 17:06:43 +00:00
|
|
|
class ConcreteMachine:
|
|
|
|
public Machine,
|
2024-04-14 01:54:50 +00:00
|
|
|
public MachineTypes::AudioProducer,
|
2024-03-23 19:43:04 +00:00
|
|
|
public MachineTypes::MappedKeyboardMachine,
|
2024-03-05 02:09:24 +00:00
|
|
|
public MachineTypes::MediaTarget,
|
2024-04-06 17:32:59 +00:00
|
|
|
public MachineTypes::MouseMachine,
|
2024-03-04 17:06:43 +00:00
|
|
|
public MachineTypes::TimedMachine,
|
2024-03-25 19:03:54 +00:00
|
|
|
public MachineTypes::ScanProducer,
|
|
|
|
public Activity::Source
|
2024-03-04 17:06:43 +00:00
|
|
|
{
|
2024-03-20 15:42:37 +00:00
|
|
|
private:
|
2024-05-07 00:36:00 +00:00
|
|
|
Log::Logger<Log::Source::Archimedes> logger;
|
|
|
|
|
|
|
|
// This fictitious clock rate just means '24 MIPS, please'; it's divided elsewhere.
|
2024-03-20 15:42:37 +00:00
|
|
|
static constexpr int ClockRate = 24'000'000;
|
2024-03-07 16:12:40 +00:00
|
|
|
|
2024-03-20 15:42:37 +00:00
|
|
|
// Runs for 24 cycles, distributing calls to the various ticking subsystems
|
|
|
|
// 'correctly' (i.e. correctly for the approximation in use).
|
|
|
|
//
|
|
|
|
// The implementation of this is coupled to the ClockRate above, hence its
|
|
|
|
// appearance here.
|
2024-05-01 01:38:37 +00:00
|
|
|
template <int video_divider, bool original_speed>
|
2024-03-20 15:42:37 +00:00
|
|
|
void macro_tick() {
|
|
|
|
macro_counter_ -= 24;
|
|
|
|
|
|
|
|
// This is a 24-cycle window, so at 24Mhz macro_tick() is called at 1Mhz.
|
|
|
|
// Hence, required ticks are:
|
|
|
|
//
|
|
|
|
// * CPU: 24;
|
2024-03-22 14:01:34 +00:00
|
|
|
// * video: 24 / video_divider;
|
2024-04-08 01:22:35 +00:00
|
|
|
// * floppy: 8;
|
2024-03-20 15:42:37 +00:00
|
|
|
// * timers: 2;
|
2024-03-21 15:24:47 +00:00
|
|
|
// * sound: 1.
|
2024-03-20 15:42:37 +00:00
|
|
|
|
2024-05-01 01:38:37 +00:00
|
|
|
tick_cpu_video<0, video_divider, original_speed>(); tick_cpu_video<1, video_divider, original_speed>();
|
|
|
|
tick_cpu_video<2, video_divider, original_speed>(); tick_floppy();
|
|
|
|
tick_cpu_video<3, video_divider, original_speed>(); tick_cpu_video<4, video_divider, original_speed>();
|
|
|
|
tick_cpu_video<5, video_divider, original_speed>(); tick_floppy();
|
|
|
|
tick_cpu_video<6, video_divider, original_speed>(); tick_cpu_video<7, video_divider, original_speed>();
|
|
|
|
tick_cpu_video<8, video_divider, original_speed>(); tick_floppy();
|
|
|
|
tick_cpu_video<9, video_divider, original_speed>(); tick_cpu_video<10, video_divider, original_speed>();
|
|
|
|
tick_cpu_video<11, video_divider, original_speed>(); tick_floppy();
|
2024-03-20 15:42:37 +00:00
|
|
|
tick_timers();
|
|
|
|
|
2024-05-01 01:38:37 +00:00
|
|
|
tick_cpu_video<12, video_divider, original_speed>(); tick_cpu_video<13, video_divider, original_speed>();
|
|
|
|
tick_cpu_video<14, video_divider, original_speed>(); tick_floppy();
|
|
|
|
tick_cpu_video<15, video_divider, original_speed>(); tick_cpu_video<16, video_divider, original_speed>();
|
|
|
|
tick_cpu_video<17, video_divider, original_speed>(); tick_floppy();
|
|
|
|
tick_cpu_video<18, video_divider, original_speed>(); tick_cpu_video<19, video_divider, original_speed>();
|
|
|
|
tick_cpu_video<20, video_divider, original_speed>(); tick_floppy();
|
|
|
|
tick_cpu_video<21, video_divider, original_speed>(); tick_cpu_video<22, video_divider, original_speed>();
|
|
|
|
tick_cpu_video<23, video_divider, original_speed>(); tick_floppy();
|
2024-03-20 15:42:37 +00:00
|
|
|
tick_timers();
|
2024-03-21 15:24:47 +00:00
|
|
|
tick_sound();
|
2024-03-20 15:42:37 +00:00
|
|
|
}
|
|
|
|
int macro_counter_ = 0;
|
2024-03-07 16:12:40 +00:00
|
|
|
|
2024-05-01 01:38:37 +00:00
|
|
|
template <int offset, int video_divider, bool original_speed>
|
2024-03-22 14:01:34 +00:00
|
|
|
void tick_cpu_video() {
|
|
|
|
if constexpr (!(offset % video_divider)) {
|
|
|
|
tick_video();
|
|
|
|
}
|
2024-03-25 19:50:59 +00:00
|
|
|
|
2024-03-26 01:31:33 +00:00
|
|
|
// Debug mode: run CPU a lot slower. Actually at close to original advertised MIPS speed.
|
2024-05-01 01:38:37 +00:00
|
|
|
if constexpr (original_speed && (offset & 7)) return;
|
2024-04-17 02:32:00 +00:00
|
|
|
if constexpr (offset & 1) return;
|
2024-03-25 19:50:59 +00:00
|
|
|
tick_cpu();
|
2024-03-22 14:01:34 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 17:06:43 +00:00
|
|
|
public:
|
|
|
|
ConcreteMachine(
|
2024-05-14 01:42:38 +00:00
|
|
|
const Analyser::Static::Acorn::ArchimedesTarget &target,
|
2024-03-04 17:06:43 +00:00
|
|
|
const ROMMachine::ROMFetcher &rom_fetcher
|
2024-04-08 02:08:12 +00:00
|
|
|
) : executor_(*this, *this, *this) {
|
2024-03-07 16:12:40 +00:00
|
|
|
set_clock_rate(ClockRate);
|
|
|
|
|
2024-04-02 01:44:42 +00:00
|
|
|
constexpr ROM::Name risc_os = ROM::Name::AcornRISCOS311;
|
2024-03-05 02:09:24 +00:00
|
|
|
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);
|
|
|
|
insert_media(target.media);
|
2024-04-20 01:30:15 +00:00
|
|
|
|
2024-05-13 02:16:29 +00:00
|
|
|
if(!target.media.disks.empty()) {
|
|
|
|
autoload_phase_ = AutoloadPhase::WaitingForStartup;
|
|
|
|
}
|
|
|
|
|
2024-04-20 01:30:15 +00:00
|
|
|
fill_pipeline(0);
|
2024-03-04 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 18:25:20 +00:00
|
|
|
void update_interrupts() {
|
|
|
|
using Exception = InstructionSet::ARM::Registers::Exception;
|
|
|
|
|
|
|
|
const int requests = executor_.bus.interrupt_mask();
|
2024-04-20 02:21:23 +00:00
|
|
|
if((requests & InterruptRequests::FIQ) && executor_.registers().would_interrupt<Exception::FIQ>()) {
|
|
|
|
pipeline_.reschedule(Pipeline::SWISubversion::FIQ);
|
2024-03-20 18:25:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-04-20 02:21:23 +00:00
|
|
|
if((requests & InterruptRequests::IRQ) && executor_.registers().would_interrupt<Exception::IRQ>()) {
|
|
|
|
pipeline_.reschedule(Pipeline::SWISubversion::IRQ);
|
2024-03-20 18:25:20 +00:00
|
|
|
}
|
2024-03-12 15:34:31 +00:00
|
|
|
}
|
2024-03-04 17:06:43 +00:00
|
|
|
|
2024-04-08 02:08:12 +00:00
|
|
|
void did_set_status() {
|
2024-04-20 01:30:15 +00:00
|
|
|
// This might have been a change of mode, so...
|
2024-04-30 02:35:01 +00:00
|
|
|
trans_ = executor_.registers().mode() == InstructionSet::ARM::Mode::User;
|
2024-04-20 01:30:15 +00:00
|
|
|
fill_pipeline(executor_.pc());
|
2024-04-08 02:08:12 +00:00
|
|
|
update_interrupts();
|
|
|
|
}
|
|
|
|
|
2024-04-18 23:30:07 +00:00
|
|
|
void did_set_pc() {
|
2024-04-20 01:30:15 +00:00
|
|
|
fill_pipeline(executor_.pc());
|
2024-04-18 23:30:07 +00:00
|
|
|
}
|
|
|
|
|
2024-05-07 02:40:00 +00:00
|
|
|
bool should_swi(uint32_t comment) {
|
2024-04-20 01:30:15 +00:00
|
|
|
using Exception = InstructionSet::ARM::Registers::Exception;
|
|
|
|
using SWISubversion = Pipeline::SWISubversion;
|
|
|
|
|
|
|
|
switch(pipeline_.swi_subversion()) {
|
2024-05-07 02:40:00 +00:00
|
|
|
case Pipeline::SWISubversion::None: {
|
|
|
|
// TODO: 400C1 to intercept create window 400C1 and positioning; then
|
|
|
|
// plot icon 400e2 to listen for icons in window. That'll give a click area.
|
|
|
|
// Probably also 400c2 which seems to be used to add icons to the icon bar.
|
|
|
|
//
|
|
|
|
// 400D4 for menus?
|
|
|
|
|
|
|
|
const auto get_string = [&](uint32_t address, bool indirect) -> std::string {
|
|
|
|
std::string desc;
|
|
|
|
if(indirect) {
|
|
|
|
executor_.bus.read(address, address, false);
|
|
|
|
}
|
|
|
|
while(true) {
|
|
|
|
uint8_t next;
|
|
|
|
executor_.bus.read(address, next, false);
|
|
|
|
if(next < 0x20) break;
|
|
|
|
desc.push_back(static_cast<char>(next));
|
|
|
|
++address;
|
|
|
|
}
|
|
|
|
return desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
switch(comment & static_cast<uint32_t>(~(1 << 17))) {
|
|
|
|
case 0x400d4: {
|
|
|
|
uint32_t address = executor_.registers()[1] + 28;
|
|
|
|
|
|
|
|
printf("Menu:\n");
|
|
|
|
while(true) {
|
|
|
|
uint32_t icon_flags;
|
|
|
|
uint32_t item_flags;
|
|
|
|
executor_.bus.read(address, item_flags, false);
|
|
|
|
executor_.bus.read(address + 8, icon_flags, false);
|
|
|
|
auto desc = get_string(address + 12, icon_flags & (1 << 8));
|
|
|
|
printf("%s\n", desc.c_str());
|
|
|
|
address += 24;
|
|
|
|
if(item_flags & (1 << 7)) break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2024-05-13 02:16:29 +00:00
|
|
|
case 0x400c5: {
|
|
|
|
const uint32_t address = executor_.registers()[1];
|
|
|
|
uint32_t x1, y1, x2, y2;
|
|
|
|
executor_.bus.read(address + 4, x1, false);
|
|
|
|
executor_.bus.read(address + 8, y1, false);
|
|
|
|
executor_.bus.read(address + 12, x2, false);
|
|
|
|
executor_.bus.read(address + 16, y2, false);
|
|
|
|
|
|
|
|
printf("Wimp_OpenWindow: %d, %d -> %d, %d\n", x1, y1, x2, y2);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 0x400c2:
|
|
|
|
if(autoload_phase_ == AutoloadPhase::WaitingForStartup) {
|
|
|
|
// Wait a further second, mouse down to (32, 240), left click.
|
|
|
|
// That'll trigger disk access.
|
|
|
|
cursor_actions_.push_back(CursorAction::wait(24'000'000));
|
|
|
|
cursor_actions_.push_back(CursorAction::move_to(32, 240));
|
|
|
|
cursor_actions_.push_back(CursorAction::button(0, true));
|
|
|
|
cursor_actions_.push_back(CursorAction::wait(12'000'000));
|
|
|
|
cursor_actions_.push_back(CursorAction::button(0, false));
|
|
|
|
autoload_phase_ = AutoloadPhase::OpeningDisk;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("!!");
|
|
|
|
[[fallthrough]];
|
2024-05-07 02:40:00 +00:00
|
|
|
case 0x400e2: {
|
|
|
|
// Wimp_PlotIcon; try to determine what's on-screen next.
|
|
|
|
const uint32_t address = executor_.registers()[1];
|
|
|
|
uint32_t x1, y1, x2, y2, flags;
|
|
|
|
executor_.bus.read(address + 0, x1, false);
|
|
|
|
executor_.bus.read(address + 4, y1, false);
|
|
|
|
executor_.bus.read(address + 8, x2, false);
|
|
|
|
executor_.bus.read(address + 12, y2, false);
|
|
|
|
executor_.bus.read(address + 16, flags, false);
|
|
|
|
|
|
|
|
std::string desc;
|
|
|
|
if(flags & 1) {
|
|
|
|
desc = get_string(address + 20, flags & (1 << 8));
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Wimp_PlotIcon: %d, %d -> %d, %d; flags %08x; icon data: %s\n", x1, y1, x2, y2, flags, desc.c_str());
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} return true;
|
2024-04-20 01:30:15 +00:00
|
|
|
|
|
|
|
case SWISubversion::DataAbort:
|
|
|
|
// executor_.set_pc(executor_.pc() - 4);
|
2024-04-20 02:21:23 +00:00
|
|
|
executor_.registers().exception<Exception::DataAbort>();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// FIQ and IRQ decrement the PC because their apperance in the pipeline causes
|
|
|
|
// it to look as though they were fetched, but they weren't.
|
|
|
|
case SWISubversion::FIQ:
|
|
|
|
executor_.set_pc(executor_.pc() - 4);
|
|
|
|
executor_.registers().exception<Exception::FIQ>();
|
|
|
|
break;
|
|
|
|
case SWISubversion::IRQ:
|
|
|
|
executor_.set_pc(executor_.pc() - 4);
|
|
|
|
executor_.registers().exception<Exception::IRQ>();
|
2024-04-20 01:30:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
did_set_pc();
|
|
|
|
return false;
|
2024-04-19 02:13:58 +00:00
|
|
|
}
|
|
|
|
|
2024-03-22 14:01:34 +00:00
|
|
|
void update_clock_rates() {
|
2024-03-22 14:24:24 +00:00
|
|
|
video_divider_ = executor_.bus.video().clock_divider();
|
2024-03-22 14:01:34 +00:00
|
|
|
}
|
|
|
|
|
2024-03-12 15:34:31 +00:00
|
|
|
private:
|
2024-03-04 17:06:43 +00:00
|
|
|
// MARK: - ScanProducer.
|
|
|
|
void set_scan_target(Outputs::Display::ScanTarget *scan_target) override {
|
2024-03-22 00:41:24 +00:00
|
|
|
executor_.bus.video().crt().set_scan_target(scan_target);
|
2024-03-04 17:06:43 +00:00
|
|
|
}
|
|
|
|
Outputs::Display::ScanStatus get_scaled_scan_status() const override {
|
2024-04-10 01:56:42 +00:00
|
|
|
return executor_.bus.video().crt().get_scaled_scan_status() * video_divider_;
|
2024-03-04 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - TimedMachine.
|
2024-05-01 01:38:37 +00:00
|
|
|
int video_divider_ = 1;
|
2024-03-04 17:06:43 +00:00
|
|
|
void run_for(Cycles cycles) override {
|
2024-05-01 01:38:37 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Debug mode: always run 'slowly' because that's less of a burden, and
|
|
|
|
// because it allows me to peer at problems with greater leisure.
|
|
|
|
const bool use_original_speed = true;
|
|
|
|
#else
|
|
|
|
// As a first, blunt implementation: try to model something close
|
|
|
|
// to original speed if there have been 10 frame rate overages in total.
|
|
|
|
const bool use_original_speed = executor_.bus.video().frame_rate_overages() > 10;
|
|
|
|
#endif
|
|
|
|
|
2024-05-13 02:16:29 +00:00
|
|
|
//
|
|
|
|
// Mouse scripting.
|
|
|
|
//
|
|
|
|
if(!cursor_actions_.empty()) {
|
|
|
|
const auto move_to_next = [&]() {
|
|
|
|
cursor_action_waited_ = 0;
|
|
|
|
cursor_actions_.erase(cursor_actions_.begin());
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto &action = cursor_actions_.front();
|
|
|
|
switch(action.type) {
|
|
|
|
case CursorAction::Type::MoveTo: {
|
|
|
|
// A measure of where within the tip lies within
|
|
|
|
// the default RISC OS cursor.
|
|
|
|
constexpr int ActionPointOffset = 20;
|
|
|
|
constexpr int MaxStep = 8;
|
|
|
|
|
|
|
|
const auto position = executor_.bus.video().cursor_location();
|
|
|
|
if(!position) break;
|
|
|
|
const auto [x, y] = *position;
|
|
|
|
|
|
|
|
auto x_diff = action.value.move_to.x - (x + ActionPointOffset);
|
|
|
|
auto y_diff = action.value.move_to.y - y;
|
|
|
|
|
|
|
|
if(abs(x_diff) < 2 && abs(y_diff) < 2) {
|
|
|
|
move_to_next();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(abs(y_diff) > MaxStep || abs(x_diff) > MaxStep) {
|
|
|
|
if(abs(y_diff) > abs(x_diff)) {
|
|
|
|
x_diff = (x_diff * MaxStep + abs(y_diff) - 1) / abs(y_diff);
|
|
|
|
y_diff = std::clamp(y_diff, -MaxStep, MaxStep);
|
|
|
|
} else {
|
|
|
|
y_diff = (y_diff * MaxStep + abs(x_diff) - 1) / abs(x_diff);
|
|
|
|
x_diff = std::clamp(x_diff, -MaxStep, MaxStep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
get_mouse().move(x_diff, y_diff);
|
|
|
|
} break;
|
|
|
|
case CursorAction::Type::Wait:
|
|
|
|
cursor_action_waited_ += cycles.as<int>();
|
|
|
|
if(cursor_action_waited_ >= action.value.wait.duration) {
|
|
|
|
move_to_next();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CursorAction::Type::Button:
|
|
|
|
get_mouse().set_button_pressed(action.value.button.button, action.value.button.down);
|
|
|
|
move_to_next();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Execution proper.
|
|
|
|
//
|
|
|
|
// TODO: divide up the following if necessary to put scripted mouse actions
|
|
|
|
// at predictably-regular steps.
|
2024-05-01 01:38:37 +00:00
|
|
|
if(use_original_speed) run_for<true>(cycles);
|
|
|
|
else run_for<false>(cycles);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <bool original_speed>
|
|
|
|
void run_for(Cycles cycles) {
|
2024-03-20 15:42:37 +00:00
|
|
|
macro_counter_ += cycles.as<int>();
|
2024-03-07 15:23:46 +00:00
|
|
|
|
2024-03-20 15:42:37 +00:00
|
|
|
while(macro_counter_ > 0) {
|
2024-03-22 14:01:34 +00:00
|
|
|
switch(video_divider_) {
|
2024-05-01 01:38:37 +00:00
|
|
|
default: macro_tick<2, original_speed>(); break;
|
|
|
|
case 3: macro_tick<3, original_speed>(); break;
|
|
|
|
case 4: macro_tick<4, original_speed>(); break;
|
|
|
|
case 6: macro_tick<6, original_speed>(); break;
|
2024-03-22 14:01:34 +00:00
|
|
|
}
|
2024-03-20 15:42:37 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-07 16:12:40 +00:00
|
|
|
|
2024-03-20 15:42:37 +00:00
|
|
|
void tick_cpu() {
|
2024-04-20 01:30:15 +00:00
|
|
|
const uint32_t instruction = advance_pipeline(executor_.pc() + 8);
|
2024-03-20 15:42:37 +00:00
|
|
|
InstructionSet::ARM::execute(instruction, executor_);
|
2024-03-05 02:09:24 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 18:25:20 +00:00
|
|
|
void tick_timers() { executor_.bus.tick_timers(); }
|
2024-03-22 00:41:24 +00:00
|
|
|
void tick_sound() { executor_.bus.sound().tick(); }
|
|
|
|
void tick_video() { executor_.bus.video().tick(); }
|
2024-04-08 01:22:35 +00:00
|
|
|
void tick_floppy() { executor_.bus.tick_floppy(); }
|
2024-03-20 15:42:37 +00:00
|
|
|
|
2024-03-05 02:09:24 +00:00
|
|
|
// MARK: - MediaTarget
|
2024-04-09 01:15:40 +00:00
|
|
|
bool insert_media(const Analyser::Static::Media &media) override {
|
2024-04-10 01:56:42 +00:00
|
|
|
size_t c = 0;
|
2024-04-09 01:15:40 +00:00
|
|
|
for(auto &disk : media.disks) {
|
|
|
|
executor_.bus.set_disk(disk, c);
|
|
|
|
c++;
|
|
|
|
if(c == 4) break;
|
|
|
|
}
|
|
|
|
return true;
|
2024-03-04 17:06:43 +00:00
|
|
|
}
|
2024-03-04 17:08:46 +00:00
|
|
|
|
2024-04-14 01:54:50 +00:00
|
|
|
// MARK: - AudioProducer
|
|
|
|
Outputs::Speaker::Speaker *get_speaker() override {
|
|
|
|
return executor_.bus.speaker();
|
|
|
|
}
|
|
|
|
|
2024-03-25 19:03:54 +00:00
|
|
|
// MARK: - Activity::Source.
|
|
|
|
void set_activity_observer(Activity::Observer *observer) final {
|
|
|
|
executor_.bus.set_activity_observer(observer);
|
|
|
|
}
|
|
|
|
|
2024-03-23 19:43:04 +00:00
|
|
|
// MARK: - MappedKeyboardMachine.
|
|
|
|
MappedKeyboardMachine::KeyboardMapper *get_keyboard_mapper() override {
|
|
|
|
return &keyboard_mapper_;
|
|
|
|
}
|
|
|
|
Archimedes::KeyboardMapper keyboard_mapper_;
|
|
|
|
|
|
|
|
void set_key_state(uint16_t key, bool is_pressed) override {
|
|
|
|
const int row = Archimedes::KeyboardMapper::row(key);
|
|
|
|
const int column = Archimedes::KeyboardMapper::column(key);
|
|
|
|
executor_.bus.keyboard().set_key_state(row, column, is_pressed);
|
|
|
|
}
|
|
|
|
|
2024-04-06 17:32:59 +00:00
|
|
|
// MARK: - MouseMachine.
|
|
|
|
Inputs::Mouse &get_mouse() override {
|
|
|
|
return executor_.bus.keyboard().mouse();
|
|
|
|
}
|
|
|
|
|
2024-04-20 01:30:15 +00:00
|
|
|
// MARK: - ARM execution.
|
2024-03-05 02:09:24 +00:00
|
|
|
static constexpr auto arm_model = InstructionSet::ARM::Model::ARMv2;
|
2024-04-08 02:08:12 +00:00
|
|
|
using Executor = InstructionSet::ARM::Executor<arm_model, MemoryController<ConcreteMachine, ConcreteMachine>, ConcreteMachine>;
|
2024-03-31 22:15:48 +00:00
|
|
|
Executor executor_;
|
2024-04-30 02:35:01 +00:00
|
|
|
bool trans_ = false;
|
2024-03-31 22:15:48 +00:00
|
|
|
|
2024-04-20 01:30:15 +00:00
|
|
|
void fill_pipeline(uint32_t pc) {
|
2024-04-20 02:21:23 +00:00
|
|
|
if(pipeline_.interrupt_next()) return;
|
2024-04-20 01:30:15 +00:00
|
|
|
advance_pipeline(pc);
|
|
|
|
advance_pipeline(pc + 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t advance_pipeline(uint32_t pc) {
|
2024-04-24 02:20:13 +00:00
|
|
|
uint32_t instruction = 0; // Value should never be used; this avoids a spurious GCC warning.
|
2024-04-30 02:35:01 +00:00
|
|
|
const bool did_read = executor_.bus.read(pc, instruction, trans_);
|
2024-04-20 01:30:15 +00:00
|
|
|
return pipeline_.exchange(
|
2024-04-23 02:08:09 +00:00
|
|
|
did_read ? instruction : Pipeline::SWI,
|
2024-04-20 01:30:15 +00:00
|
|
|
did_read ? Pipeline::SWISubversion::None : Pipeline::SWISubversion::DataAbort);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Pipeline {
|
|
|
|
enum SWISubversion: uint8_t {
|
|
|
|
None,
|
|
|
|
DataAbort,
|
2024-04-20 02:21:23 +00:00
|
|
|
IRQ,
|
|
|
|
FIQ,
|
2024-04-20 01:30:15 +00:00
|
|
|
};
|
|
|
|
|
2024-04-23 02:08:09 +00:00
|
|
|
static constexpr uint32_t SWI = 0xef'000000;
|
|
|
|
|
2024-04-20 01:30:15 +00:00
|
|
|
uint32_t exchange(uint32_t next, SWISubversion subversion) {
|
|
|
|
const uint32_t result = upcoming_[active_].opcode;
|
|
|
|
latched_subversion_ = upcoming_[active_].subversion;
|
|
|
|
|
|
|
|
upcoming_[active_].opcode = next;
|
|
|
|
upcoming_[active_].subversion = subversion;
|
|
|
|
active_ ^= 1;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWISubversion swi_subversion() const {
|
|
|
|
return latched_subversion_;
|
|
|
|
}
|
|
|
|
|
2024-04-20 02:21:23 +00:00
|
|
|
// TODO: one day, possibly: schedule the subversion one slot further into the future
|
|
|
|
// (i.e. active_ ^ 1) to allow one further instruction to occur as usual before the
|
|
|
|
// action paplies. That is, if interrupts take effect one instruction later after a flags
|
|
|
|
// change, which I don't yet know.
|
|
|
|
//
|
|
|
|
// In practice I got into a bit of a race condition between interrupt scheduling and
|
|
|
|
// flags changes, so have backed off for now.
|
|
|
|
void reschedule(SWISubversion subversion) {
|
2024-04-23 02:08:09 +00:00
|
|
|
upcoming_[active_].opcode = SWI;
|
2024-04-20 02:21:23 +00:00
|
|
|
upcoming_[active_].subversion = subversion;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool interrupt_next() const {
|
|
|
|
return upcoming_[active_].subversion == SWISubversion::IRQ || upcoming_[active_].subversion == SWISubversion::FIQ;
|
|
|
|
}
|
2024-04-20 01:46:09 +00:00
|
|
|
|
2024-04-20 01:30:15 +00:00
|
|
|
private:
|
|
|
|
struct Stage {
|
|
|
|
uint32_t opcode;
|
2024-04-20 01:46:09 +00:00
|
|
|
SWISubversion subversion = SWISubversion::None;
|
2024-04-20 01:30:15 +00:00
|
|
|
};
|
|
|
|
Stage upcoming_[2];
|
|
|
|
int active_ = 0;
|
|
|
|
|
|
|
|
SWISubversion latched_subversion_;
|
|
|
|
} pipeline_;
|
2024-05-13 02:16:29 +00:00
|
|
|
|
|
|
|
struct CursorAction {
|
|
|
|
enum class Type {
|
|
|
|
MoveTo,
|
|
|
|
Button,
|
|
|
|
Wait,
|
|
|
|
} type;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int x, y;
|
|
|
|
} move_to;
|
|
|
|
struct {
|
|
|
|
int duration;
|
|
|
|
} wait;
|
|
|
|
struct {
|
|
|
|
int button;
|
|
|
|
bool down;
|
|
|
|
} button;
|
|
|
|
} value;
|
|
|
|
|
|
|
|
static CursorAction move_to(int x, int y) {
|
|
|
|
CursorAction action;
|
|
|
|
action.type = Type::MoveTo;
|
|
|
|
action.value.move_to.x = x;
|
|
|
|
action.value.move_to.y = y;
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
static CursorAction wait(int duration) {
|
|
|
|
CursorAction action;
|
|
|
|
action.type = Type::Wait;
|
|
|
|
action.value.wait.duration = duration;
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
static CursorAction button(int button, bool down) {
|
|
|
|
CursorAction action;
|
|
|
|
action.type = Type::Button;
|
|
|
|
action.value.button.button = button;
|
|
|
|
action.value.button.down = down;
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
std::vector<CursorAction> cursor_actions_;
|
|
|
|
int cursor_action_waited_ = 0;
|
|
|
|
|
|
|
|
enum class AutoloadPhase {
|
|
|
|
WaitingForStartup,
|
|
|
|
OpeningDisk,
|
|
|
|
Ended,
|
|
|
|
};
|
|
|
|
AutoloadPhase autoload_phase_ = AutoloadPhase::Ended;
|
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) {
|
2024-05-14 01:42:38 +00:00
|
|
|
const auto archimedes_target = dynamic_cast<const Analyser::Static::Acorn::ArchimedesTarget *>(target);
|
|
|
|
return std::make_unique<ConcreteMachine>(*archimedes_target, rom_fetcher);
|
2024-03-04 17:06:43 +00:00
|
|
|
}
|