2016-01-05 04:12:47 +00:00
|
|
|
//
|
|
|
|
// Electron.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 03/01/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-01-05 04:12:47 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Electron.hpp"
|
2016-01-07 02:09:49 +00:00
|
|
|
|
2018-05-11 01:54:10 +00:00
|
|
|
#include "../../Activity/Source.hpp"
|
2020-04-02 03:19:34 +00:00
|
|
|
#include "../MachineTypes.hpp"
|
2020-03-16 03:48:53 +00:00
|
|
|
#include "../../Configurable/Configurable.hpp"
|
2018-03-09 20:19:02 +00:00
|
|
|
|
2017-12-18 02:26:06 +00:00
|
|
|
#include "../../ClockReceiver/ClockReceiver.hpp"
|
|
|
|
#include "../../ClockReceiver/ForceInline.hpp"
|
2017-11-21 02:55:32 +00:00
|
|
|
#include "../../Configurable/StandardOptions.hpp"
|
2017-12-19 02:39:23 +00:00
|
|
|
#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
|
2017-08-16 19:33:40 +00:00
|
|
|
#include "../../Processors/6502/6502.hpp"
|
2021-01-31 23:36:29 +00:00
|
|
|
|
|
|
|
#include "../../Storage/MassStorage/SCSI/SCSI.hpp"
|
|
|
|
#include "../../Storage/MassStorage/SCSI/DirectAccessDevice.hpp"
|
2017-08-16 19:33:40 +00:00
|
|
|
#include "../../Storage/Tape/Tape.hpp"
|
2017-08-03 15:42:31 +00:00
|
|
|
|
2017-10-21 14:30:02 +00:00
|
|
|
#include "../Utility/Typer.hpp"
|
2018-03-09 21:07:29 +00:00
|
|
|
#include "../../Analyser/Static/Acorn/Target.hpp"
|
2016-12-11 02:07:52 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
#include "Interrupts.hpp"
|
2017-10-21 14:52:35 +00:00
|
|
|
#include "Keyboard.hpp"
|
2017-08-16 19:33:40 +00:00
|
|
|
#include "Plus3.hpp"
|
2017-12-18 02:26:06 +00:00
|
|
|
#include "SoundGenerator.hpp"
|
2017-08-16 19:33:40 +00:00
|
|
|
#include "Tape.hpp"
|
|
|
|
#include "Video.hpp"
|
|
|
|
|
|
|
|
namespace Electron {
|
|
|
|
|
2021-01-31 23:36:29 +00:00
|
|
|
template <bool has_scsi_bus> class ConcreteMachine:
|
2017-08-16 19:33:40 +00:00
|
|
|
public Machine,
|
2020-04-02 03:19:34 +00:00
|
|
|
public MachineTypes::TimedMachine,
|
|
|
|
public MachineTypes::ScanProducer,
|
|
|
|
public MachineTypes::AudioProducer,
|
|
|
|
public MachineTypes::MediaTarget,
|
|
|
|
public MachineTypes::MappedKeyboardMachine,
|
2018-03-09 20:19:02 +00:00
|
|
|
public Configurable::Device,
|
2017-08-16 19:33:40 +00:00
|
|
|
public CPU::MOS6502::BusHandler,
|
|
|
|
public Tape::Delegate,
|
2020-03-01 23:44:26 +00:00
|
|
|
public Utility::TypeRecipient<CharacterMapper>,
|
2021-02-01 02:24:54 +00:00
|
|
|
public Activity::Source,
|
|
|
|
public SCSI::Bus::Observer,
|
|
|
|
public ClockingHint::Observer {
|
2017-08-16 19:33:40 +00:00
|
|
|
public:
|
2018-07-11 00:00:46 +00:00
|
|
|
ConcreteMachine(const Analyser::Static::Acorn::Target &target, const ROMMachine::ROMFetcher &rom_fetcher) :
|
2018-08-14 02:17:22 +00:00
|
|
|
m6502_(*this),
|
2021-01-31 23:36:29 +00:00
|
|
|
scsi_bus_(4'000'000),
|
|
|
|
hard_drive_(scsi_bus_, 0),
|
|
|
|
scsi_device_(scsi_bus_.add_device()),
|
2018-11-15 02:52:57 +00:00
|
|
|
video_output_(ram_),
|
2018-07-11 00:00:46 +00:00
|
|
|
sound_generator_(audio_queue_),
|
|
|
|
speaker_(sound_generator_) {
|
2017-08-16 19:33:40 +00:00
|
|
|
memset(key_states_, 0, sizeof(key_states_));
|
|
|
|
for(int c = 0; c < 16; c++)
|
|
|
|
memset(roms_[c], 0xff, 16384);
|
|
|
|
|
|
|
|
tape_.set_delegate(this);
|
|
|
|
set_clock_rate(2000000);
|
2017-12-18 02:26:06 +00:00
|
|
|
|
|
|
|
speaker_.set_input_rate(2000000 / SoundGenerator::clock_rate_divider);
|
2020-03-03 04:11:09 +00:00
|
|
|
speaker_.set_high_frequency_cutoff(6000);
|
2016-03-20 17:50:13 +00:00
|
|
|
|
2019-07-23 01:14:21 +00:00
|
|
|
const std::string machine_name = "Electron";
|
2019-07-21 01:30:37 +00:00
|
|
|
std::vector<ROMMachine::ROM> required_roms = {
|
2019-07-23 01:14:21 +00:00
|
|
|
{machine_name, "the Acorn BASIC II ROM", "basic.rom", 16*1024, 0x79434781},
|
|
|
|
{machine_name, "the Electron MOS ROM", "os.rom", 16*1024, 0xbf63fb1f}
|
2019-07-21 01:30:37 +00:00
|
|
|
};
|
2021-01-31 18:12:59 +00:00
|
|
|
const size_t pres_adfs_rom_position = required_roms.size();
|
|
|
|
if(target.has_pres_adfs) {
|
2019-07-23 01:14:21 +00:00
|
|
|
required_roms.emplace_back(machine_name, "the E00 ADFS ROM, first slot", "ADFS-E00_1.rom", 16*1024, 0x51523993);
|
|
|
|
required_roms.emplace_back(machine_name, "the E00 ADFS ROM, second slot", "ADFS-E00_2.rom", 16*1024, 0x8d17de0e);
|
2018-07-11 00:00:46 +00:00
|
|
|
}
|
2021-01-31 18:12:59 +00:00
|
|
|
const size_t acorn_adfs_rom_position = required_roms.size();
|
|
|
|
if(target.has_acorn_adfs) {
|
|
|
|
required_roms.emplace_back(machine_name, "the Acorn ADFS ROM", "adfs.rom", 16*1024, 0x3289bdc6);
|
|
|
|
}
|
2019-07-21 01:30:37 +00:00
|
|
|
const size_t dfs_rom_position = required_roms.size();
|
2018-07-11 00:00:46 +00:00
|
|
|
if(target.has_dfs) {
|
2019-07-23 01:14:21 +00:00
|
|
|
required_roms.emplace_back(machine_name, "the 1770 DFS ROM", "DFS-1770-2.20.rom", 16*1024, 0xf3dc9bc5);
|
2018-07-11 00:00:46 +00:00
|
|
|
}
|
2021-01-31 00:38:19 +00:00
|
|
|
const size_t ap6_rom_position = required_roms.size();
|
|
|
|
if(target.has_ap6_rom) {
|
|
|
|
required_roms.emplace_back(machine_name, "the 8kb Advanced Plus 6 ROM", "AP6v133.rom", 8*1024, 0xe0013cfc);
|
|
|
|
}
|
2019-07-23 01:14:21 +00:00
|
|
|
const auto roms = rom_fetcher(required_roms);
|
2018-03-23 01:59:19 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
for(const auto &rom: roms) {
|
|
|
|
if(!rom) {
|
|
|
|
throw ROMMachine::Error::MissingROMs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_rom(ROM::BASIC, *roms[0], false);
|
|
|
|
set_rom(ROM::OS, *roms[1], false);
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2021-01-31 00:38:19 +00:00
|
|
|
/*
|
|
|
|
ROM slot mapping applied:
|
|
|
|
|
|
|
|
* the keyboard and BASIC ROMs occupy slots 8, 9, 10 and 11;
|
|
|
|
* the DFS, if in use, occupies slot 1;
|
2021-01-31 18:12:59 +00:00
|
|
|
* the Pres ADFS, if in use, occupies slots 4 and 5;
|
|
|
|
* the Acorn ADFS, if in use, occupies slot 6;
|
2021-01-31 00:38:19 +00:00
|
|
|
* the AP6, if in use, occupies slot 15; and
|
|
|
|
* if sideways RAM was asked for, all otherwise unused slots are populated with sideways RAM.
|
|
|
|
*/
|
2021-01-31 18:12:59 +00:00
|
|
|
if(target.has_dfs || target.has_acorn_adfs || target.has_pres_adfs) {
|
2019-12-24 02:31:46 +00:00
|
|
|
plus3_ = std::make_unique<Plus3>();
|
2018-07-11 00:00:46 +00:00
|
|
|
|
|
|
|
if(target.has_dfs) {
|
|
|
|
set_rom(ROM::Slot0, *roms[dfs_rom_position], true);
|
|
|
|
}
|
2021-01-31 18:12:59 +00:00
|
|
|
if(target.has_pres_adfs) {
|
|
|
|
set_rom(ROM::Slot4, *roms[pres_adfs_rom_position], true);
|
|
|
|
set_rom(ROM::Slot5, *roms[pres_adfs_rom_position+1], true);
|
|
|
|
}
|
|
|
|
if(target.has_acorn_adfs) {
|
|
|
|
set_rom(ROM::Slot6, *roms[acorn_adfs_rom_position], true);
|
2018-07-11 00:00:46 +00:00
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
2016-02-05 03:28:50 +00:00
|
|
|
|
2021-01-31 00:38:19 +00:00
|
|
|
if(target.has_ap6_rom) {
|
|
|
|
set_rom(ROM::Slot15, *roms[ap6_rom_position], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(target.has_sideways_ram) {
|
|
|
|
for(int c = 0; c < 16; c++) {
|
|
|
|
if(rom_inserted_[c]) continue;
|
|
|
|
if(c >= int(ROM::Keyboard) && c < int(ROM::BASIC)+1) continue;
|
|
|
|
set_sideways_ram(ROM(c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
insert_media(target.media);
|
|
|
|
|
|
|
|
if(!target.loading_command.empty()) {
|
|
|
|
type_string(target.loading_command);
|
2018-01-16 02:27:45 +00:00
|
|
|
}
|
2016-01-05 04:12:47 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
if(target.should_shift_restart) {
|
|
|
|
shift_restart_counter_ = 1000000;
|
2017-11-07 03:14:15 +00:00
|
|
|
}
|
2021-02-01 02:24:54 +00:00
|
|
|
|
|
|
|
if(has_scsi_bus) {
|
|
|
|
scsi_bus_.add_observer(this);
|
|
|
|
scsi_bus_.set_clocking_hint_observer(this);
|
|
|
|
}
|
2018-07-11 00:00:46 +00:00
|
|
|
}
|
2017-11-07 03:14:15 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
~ConcreteMachine() {
|
|
|
|
audio_queue_.flush();
|
2017-11-07 03:14:15 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 03:35:39 +00:00
|
|
|
void set_key_state(uint16_t key, bool isPressed) final {
|
2020-03-06 02:01:30 +00:00
|
|
|
switch(key) {
|
|
|
|
default:
|
|
|
|
if(isPressed)
|
|
|
|
key_states_[key >> 4] |= key&0xf;
|
|
|
|
else
|
|
|
|
key_states_[key >> 4] &= ~(key&0xf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyBreak:
|
|
|
|
m6502_.set_reset_line(isPressed);
|
|
|
|
break;
|
|
|
|
|
2020-03-07 02:56:08 +00:00
|
|
|
#define FuncShiftedKey(source, dest) \
|
2020-03-06 02:01:30 +00:00
|
|
|
case source: \
|
2020-03-07 02:56:08 +00:00
|
|
|
set_key_state(KeyFunc, isPressed); \
|
2020-03-06 02:01:30 +00:00
|
|
|
set_key_state(dest, isPressed); \
|
|
|
|
break;
|
|
|
|
|
2020-03-07 02:56:08 +00:00
|
|
|
FuncShiftedKey(KeyF1, Key1);
|
|
|
|
FuncShiftedKey(KeyF2, Key2);
|
|
|
|
FuncShiftedKey(KeyF3, Key3);
|
|
|
|
FuncShiftedKey(KeyF4, Key4);
|
|
|
|
FuncShiftedKey(KeyF5, Key5);
|
|
|
|
FuncShiftedKey(KeyF6, Key6);
|
|
|
|
FuncShiftedKey(KeyF7, Key7);
|
|
|
|
FuncShiftedKey(KeyF8, Key8);
|
|
|
|
FuncShiftedKey(KeyF9, Key9);
|
|
|
|
FuncShiftedKey(KeyF0, Key0);
|
|
|
|
|
|
|
|
#undef FuncShiftedKey
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-25 00:34:25 +00:00
|
|
|
|
2020-01-24 03:35:39 +00:00
|
|
|
void clear_all_keys() final {
|
2017-08-16 19:33:40 +00:00
|
|
|
memset(key_states_, 0, sizeof(key_states_));
|
|
|
|
if(is_holding_shift_) set_key_state(KeyShift, true);
|
|
|
|
}
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2020-01-24 03:35:39 +00:00
|
|
|
bool insert_media(const Analyser::Static::Media &media) final {
|
2017-08-17 14:48:29 +00:00
|
|
|
if(!media.tapes.empty()) {
|
|
|
|
tape_.set_tape(media.tapes.front());
|
|
|
|
}
|
2018-04-18 22:13:30 +00:00
|
|
|
set_use_fast_tape_hack();
|
2017-08-17 14:48:29 +00:00
|
|
|
|
|
|
|
if(!media.disks.empty() && plus3_) {
|
|
|
|
plus3_->set_disk(media.disks.front(), 0);
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
ROM slot = ROM::Slot12;
|
2017-08-17 14:48:29 +00:00
|
|
|
for(std::shared_ptr<Storage::Cartridge::Cartridge> cartridge : media.cartridges) {
|
2018-07-11 00:00:46 +00:00
|
|
|
const ROM first_slot_tried = slot;
|
2020-05-10 03:00:39 +00:00
|
|
|
while(rom_inserted_[int(slot)]) {
|
|
|
|
slot = ROM((int(slot) + 1) & 15);
|
2018-04-18 22:13:30 +00:00
|
|
|
if(slot == first_slot_tried) return false;
|
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
set_rom(slot, cartridge->get_segments().front().data, false);
|
|
|
|
}
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2021-01-31 23:36:29 +00:00
|
|
|
// TODO: allow this only at machine startup?
|
|
|
|
if(!media.mass_storage_devices.empty()) {
|
|
|
|
hard_drive_->set_storage(media.mass_storage_devices.front());
|
|
|
|
}
|
|
|
|
|
|
|
|
return !media.empty();
|
2016-12-16 00:47:04 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 01:56:42 +00:00
|
|
|
forceinline Cycles perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) {
|
2017-08-16 19:33:40 +00:00
|
|
|
unsigned int cycles = 1;
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
if(address < 0x8000) {
|
|
|
|
if(isReadOperation(operation)) {
|
|
|
|
*value = ram_[address];
|
|
|
|
} else {
|
|
|
|
if(address >= video_access_range_.low_address && address <= video_access_range_.high_address) update_display();
|
|
|
|
ram_[address] = *value;
|
|
|
|
}
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
// for the entire frame, RAM is accessible only on odd cycles; in modes below 4
|
|
|
|
// it's also accessible only outside of the pixel regions
|
2019-10-30 02:36:29 +00:00
|
|
|
cycles += video_output_.get_cycles_until_next_ram_availability(int(cycles_since_display_update_.as_integral()) + 1);
|
2017-08-16 19:33:40 +00:00
|
|
|
} else {
|
|
|
|
switch(address & 0xff0f) {
|
|
|
|
case 0xfe00:
|
|
|
|
if(isReadOperation(operation)) {
|
|
|
|
*value = interrupt_status_;
|
|
|
|
interrupt_status_ &= ~PowerOnReset;
|
|
|
|
} else {
|
|
|
|
interrupt_control_ = (*value) & ~1;
|
|
|
|
evaluate_interrupts();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xfe07:
|
|
|
|
if(!isReadOperation(operation)) {
|
|
|
|
// update speaker mode
|
|
|
|
bool new_speaker_is_enabled = (*value & 6) == 2;
|
|
|
|
if(new_speaker_is_enabled != speaker_is_enabled_) {
|
|
|
|
update_audio();
|
2017-12-18 02:26:06 +00:00
|
|
|
sound_generator_.set_is_enabled(new_speaker_is_enabled);
|
2017-08-16 19:33:40 +00:00
|
|
|
speaker_is_enabled_ = new_speaker_is_enabled;
|
|
|
|
}
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
tape_.set_is_enabled((*value & 6) != 6);
|
|
|
|
tape_.set_is_in_input_mode((*value & 6) == 0);
|
2018-05-08 01:57:54 +00:00
|
|
|
tape_.set_is_running((*value & 0x40) ? true : false);
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2018-05-08 01:57:54 +00:00
|
|
|
caps_led_state_ = !!(*value & 0x80);
|
|
|
|
if(activity_observer_)
|
|
|
|
activity_observer_->set_led_status(caps_led, caps_led_state_);
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
2016-01-10 01:26:40 +00:00
|
|
|
|
2020-06-20 03:36:51 +00:00
|
|
|
[[fallthrough]]; // fe07 contains the display mode.
|
|
|
|
|
2018-05-08 01:57:54 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
case 0xfe02: case 0xfe03:
|
|
|
|
case 0xfe08: case 0xfe09: case 0xfe0a: case 0xfe0b:
|
|
|
|
case 0xfe0c: case 0xfe0d: case 0xfe0e: case 0xfe0f:
|
|
|
|
if(!isReadOperation(operation)) {
|
|
|
|
update_display();
|
2020-01-05 18:40:02 +00:00
|
|
|
video_output_.write(address, *value);
|
2018-11-15 02:52:57 +00:00
|
|
|
video_access_range_ = video_output_.get_memory_access_range();
|
2017-08-16 19:33:40 +00:00
|
|
|
queue_next_display_interrupt();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xfe04:
|
|
|
|
if(isReadOperation(operation)) {
|
|
|
|
*value = tape_.get_data_register();
|
|
|
|
tape_.clear_interrupts(Interrupt::ReceiveDataFull);
|
|
|
|
} else {
|
|
|
|
tape_.set_data_register(*value);
|
|
|
|
tape_.clear_interrupts(Interrupt::TransmitDataEmpty);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xfe05:
|
|
|
|
if(!isReadOperation(operation)) {
|
|
|
|
const uint8_t interruptDisable = (*value)&0xf0;
|
|
|
|
if( interruptDisable ) {
|
|
|
|
if( interruptDisable&0x10 ) interrupt_status_ &= ~Interrupt::DisplayEnd;
|
|
|
|
if( interruptDisable&0x20 ) interrupt_status_ &= ~Interrupt::RealTimeClock;
|
|
|
|
if( interruptDisable&0x40 ) interrupt_status_ &= ~Interrupt::HighToneDetect;
|
|
|
|
evaluate_interrupts();
|
|
|
|
|
|
|
|
// TODO: NMI
|
|
|
|
}
|
2016-01-08 03:26:49 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
// latch the paged ROM in case external hardware is being emulated
|
2018-07-11 00:00:46 +00:00
|
|
|
active_rom_ = *value & 0xf;
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
// apply the ULA's test
|
|
|
|
if(*value & 0x08) {
|
|
|
|
if(*value & 0x04) {
|
|
|
|
keyboard_is_active_ = false;
|
|
|
|
basic_is_active_ = false;
|
|
|
|
} else {
|
|
|
|
keyboard_is_active_ = !(*value & 0x02);
|
|
|
|
basic_is_active_ = !keyboard_is_active_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xfe06:
|
|
|
|
if(!isReadOperation(operation)) {
|
|
|
|
update_audio();
|
2017-12-18 02:26:06 +00:00
|
|
|
sound_generator_.set_divider(*value);
|
2017-08-16 19:33:40 +00:00
|
|
|
tape_.set_counter(*value);
|
|
|
|
}
|
|
|
|
break;
|
2016-12-11 21:17:51 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
case 0xfc04: case 0xfc05: case 0xfc06: case 0xfc07:
|
|
|
|
if(plus3_ && (address&0x00f0) == 0x00c0) {
|
|
|
|
if(is_holding_shift_ && address == 0xfcc4) {
|
|
|
|
is_holding_shift_ = false;
|
|
|
|
set_key_state(KeyShift, false);
|
|
|
|
}
|
|
|
|
if(isReadOperation(operation))
|
2020-01-05 18:40:02 +00:00
|
|
|
*value = plus3_->read(address);
|
2017-08-16 19:33:40 +00:00
|
|
|
else
|
2020-01-05 18:40:02 +00:00
|
|
|
plus3_->write(address, *value);
|
2016-01-14 02:03:43 +00:00
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
break;
|
|
|
|
case 0xfc00:
|
|
|
|
if(plus3_ && (address&0x00f0) == 0x00c0) {
|
|
|
|
if(!isReadOperation(operation)) {
|
|
|
|
plus3_->set_control_register(*value);
|
|
|
|
} else *value = 1;
|
|
|
|
}
|
2021-01-31 23:36:29 +00:00
|
|
|
|
|
|
|
if(has_scsi_bus && (address&0x00f0) == 0x0040) {
|
|
|
|
scsi_acknowledge_ = true;
|
|
|
|
if(!isReadOperation(operation)) {
|
|
|
|
scsi_data_ = *value;
|
|
|
|
push_scsi_output();
|
|
|
|
} else {
|
|
|
|
*value = SCSI::data_lines(scsi_bus_.get_state());
|
|
|
|
push_scsi_output();
|
|
|
|
}
|
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
break;
|
2021-01-31 18:12:59 +00:00
|
|
|
case 0xfc03:
|
2021-01-31 23:36:29 +00:00
|
|
|
if(has_scsi_bus && (address&0x00f0) == 0x0040) {
|
2021-02-01 22:40:11 +00:00
|
|
|
scsi_interrupt_state_ = false;
|
|
|
|
scsi_interrupt_mask_ = *value & 1;
|
|
|
|
evaluate_interrupts();
|
2021-01-31 23:36:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xfc01:
|
|
|
|
if(has_scsi_bus && (address&0x00f0) == 0x0040 && isReadOperation(operation)) {
|
|
|
|
// Status byte is:
|
|
|
|
//
|
|
|
|
// b7: SCSI C/D
|
|
|
|
// b6: SCSI I/O
|
|
|
|
// b5: SCSI REQ
|
|
|
|
// b4: interrupt flag
|
|
|
|
// b3: 0
|
|
|
|
// b2: 0
|
|
|
|
// b1: SCSI BSY
|
|
|
|
// b0: SCSI MSG
|
|
|
|
const auto state = scsi_bus_.get_state();
|
|
|
|
*value =
|
|
|
|
(state & SCSI::Line::Control ? 0x80 : 0x00) |
|
|
|
|
(state & SCSI::Line::Input ? 0x40 : 0x00) |
|
|
|
|
(state & SCSI::Line::Request ? 0x20 : 0x00) |
|
2021-02-01 22:40:11 +00:00
|
|
|
((scsi_interrupt_state_ && scsi_interrupt_mask_) ? 0x10 : 0x00) |
|
2021-01-31 23:36:29 +00:00
|
|
|
(state & SCSI::Line::Busy ? 0x02 : 0x00) |
|
|
|
|
(state & SCSI::Line::Message ? 0x01 : 0x00);
|
|
|
|
|
|
|
|
// Empirical guess: this is also the trigger to affect busy/request/acknowledge
|
|
|
|
// signalling. Maybe?
|
|
|
|
if(scsi_select_ && scsi_bus_.get_state() & SCSI::Line::Busy) {
|
|
|
|
scsi_select_ = false;
|
|
|
|
push_scsi_output();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xfc02:
|
|
|
|
if(has_scsi_bus && (address&0x00f0) == 0x0040) {
|
|
|
|
scsi_select_ = true;
|
|
|
|
push_scsi_output();
|
|
|
|
}
|
2021-01-31 18:12:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// SCSI locations:
|
|
|
|
//
|
|
|
|
// fc40: data, read and write
|
|
|
|
// fc41: status read
|
|
|
|
// fc42: select write
|
|
|
|
// fc43: interrupt latch
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Interrupt latch is:
|
|
|
|
//
|
|
|
|
// b0: enable or disable IRQ on REQ
|
|
|
|
// (and, possibly, writing to the latch acknowledges?)
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
if(address >= 0xc000) {
|
|
|
|
if(isReadOperation(operation)) {
|
|
|
|
if(
|
|
|
|
use_fast_tape_hack_ &&
|
|
|
|
(operation == CPU::MOS6502::BusOperation::ReadOpcode) &&
|
|
|
|
(
|
|
|
|
(address == 0xf4e5) || (address == 0xf4e6) || // double NOPs at 0xf4e5, 0xf6de, 0xf6fa and 0xfa51
|
|
|
|
(address == 0xf6de) || (address == 0xf6df) || // act to disable the normal branch into tape-handling
|
|
|
|
(address == 0xf6fa) || (address == 0xf6fb) || // code, forcing the OS along the serially-accessed ROM
|
|
|
|
(address == 0xfa51) || (address == 0xfa52) || // pathway.
|
|
|
|
|
|
|
|
(address == 0xf0a8) // 0xf0a8 is from where a service call would normally be
|
|
|
|
// dispatched; we can check whether it would be call 14
|
|
|
|
// (i.e. read byte) and, if so, whether the OS was about to
|
|
|
|
// issue a read byte call to a ROM despite being the tape
|
|
|
|
// FS being selected. If so then this is a get byte that
|
|
|
|
// we should service synthetically. Put the byte into Y
|
|
|
|
// and set A to zero to report that action was taken, then
|
|
|
|
// allow the PC read to return an RTS.
|
|
|
|
)
|
|
|
|
) {
|
2020-05-10 03:00:39 +00:00
|
|
|
uint8_t service_call = uint8_t(m6502_.get_value_of_register(CPU::MOS6502::Register::X));
|
2017-08-16 19:33:40 +00:00
|
|
|
if(address == 0xf0a8) {
|
|
|
|
if(!ram_[0x247] && service_call == 14) {
|
|
|
|
tape_.set_delegate(nullptr);
|
|
|
|
|
|
|
|
int cycles_left_while_plausibly_in_data = 50;
|
|
|
|
tape_.clear_interrupts(Interrupt::ReceiveDataFull);
|
|
|
|
while(!tape_.get_tape()->is_at_end()) {
|
|
|
|
tape_.run_for_input_pulse();
|
|
|
|
cycles_left_while_plausibly_in_data--;
|
|
|
|
if(!cycles_left_while_plausibly_in_data) fast_load_is_in_data_ = false;
|
|
|
|
if( (tape_.get_interrupt_status() & Interrupt::ReceiveDataFull) &&
|
|
|
|
(fast_load_is_in_data_ || tape_.get_data_register() == 0x2a)
|
|
|
|
) break;
|
|
|
|
}
|
|
|
|
tape_.set_delegate(this);
|
|
|
|
tape_.clear_interrupts(Interrupt::ReceiveDataFull);
|
|
|
|
interrupt_status_ |= tape_.get_interrupt_status();
|
|
|
|
|
|
|
|
fast_load_is_in_data_ = true;
|
|
|
|
m6502_.set_value_of_register(CPU::MOS6502::Register::A, 0);
|
|
|
|
m6502_.set_value_of_register(CPU::MOS6502::Register::Y, tape_.get_data_register());
|
|
|
|
*value = 0x60; // 0x60 is RTS
|
|
|
|
}
|
|
|
|
else *value = os_[address & 16383];
|
2016-09-20 02:06:56 +00:00
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
else *value = 0xea;
|
|
|
|
} else {
|
|
|
|
*value = os_[address & 16383];
|
2016-03-13 21:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-26 18:34:47 +00:00
|
|
|
} else {
|
2017-08-16 19:33:40 +00:00
|
|
|
if(isReadOperation(operation)) {
|
|
|
|
*value = roms_[active_rom_][address & 16383];
|
|
|
|
if(keyboard_is_active_) {
|
|
|
|
*value &= 0xf0;
|
|
|
|
for(int address_line = 0; address_line < 14; address_line++) {
|
|
|
|
if(!(address&(1 << address_line))) *value |= key_states_[address_line];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(basic_is_active_) {
|
2020-05-10 03:00:39 +00:00
|
|
|
*value &= roms_[int(ROM::BASIC)][address & 16383];
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
|
|
|
} else if(rom_write_masks_[active_rom_]) {
|
|
|
|
roms_[active_rom_][address & 16383] = *value;
|
2016-09-20 02:06:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 23:52:47 +00:00
|
|
|
cycles_since_display_update_ += Cycles(int(cycles));
|
|
|
|
cycles_since_audio_update_ += Cycles(int(cycles));
|
2017-08-16 19:33:40 +00:00
|
|
|
if(cycles_since_audio_update_ > Cycles(16384)) update_audio();
|
2020-02-29 23:52:47 +00:00
|
|
|
tape_.run_for(Cycles(int(cycles)));
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
cycles_until_display_interrupt_ -= cycles;
|
|
|
|
if(cycles_until_display_interrupt_ < 0) {
|
|
|
|
signal_interrupt(next_display_interrupt_);
|
|
|
|
update_display();
|
|
|
|
queue_next_display_interrupt();
|
|
|
|
}
|
|
|
|
|
2020-02-29 23:52:47 +00:00
|
|
|
if(typer_) typer_->run_for(Cycles(int(cycles)));
|
|
|
|
if(plus3_) plus3_->run_for(Cycles(4*int(cycles)));
|
2017-08-16 19:33:40 +00:00
|
|
|
if(shift_restart_counter_) {
|
|
|
|
shift_restart_counter_ -= cycles;
|
|
|
|
if(shift_restart_counter_ <= 0) {
|
|
|
|
shift_restart_counter_ = 0;
|
|
|
|
m6502_.set_power_on(true);
|
|
|
|
set_key_state(KeyShift, true);
|
|
|
|
is_holding_shift_ = true;
|
2016-05-05 12:28:06 +00:00
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 02:24:54 +00:00
|
|
|
if constexpr (has_scsi_bus) {
|
|
|
|
if(scsi_is_clocked_) {
|
|
|
|
scsi_bus_.run_for(Cycles(int(cycles)));
|
2021-01-31 23:36:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 03:00:39 +00:00
|
|
|
return Cycles(int(cycles));
|
2016-01-07 02:09:49 +00:00
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
|
2017-08-22 01:56:42 +00:00
|
|
|
forceinline void flush() {
|
2017-08-16 19:33:40 +00:00
|
|
|
update_display();
|
|
|
|
update_audio();
|
2017-12-18 02:26:06 +00:00
|
|
|
audio_queue_.perform();
|
2017-01-08 19:46:19 +00:00
|
|
|
}
|
2016-06-19 21:25:35 +00:00
|
|
|
|
2020-01-24 03:35:39 +00:00
|
|
|
void set_scan_target(Outputs::Display::ScanTarget *scan_target) final {
|
2018-11-15 02:52:57 +00:00
|
|
|
video_output_.set_scan_target(scan_target);
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
2016-02-15 00:28:02 +00:00
|
|
|
|
2020-01-22 03:28:25 +00:00
|
|
|
Outputs::Display::ScanStatus get_scaled_scan_status() const final {
|
|
|
|
return video_output_.get_scaled_scan_status();
|
2020-01-21 02:45:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 03:57:51 +00:00
|
|
|
void set_display_type(Outputs::Display::DisplayType display_type) final {
|
2018-11-30 04:44:21 +00:00
|
|
|
video_output_.set_display_type(display_type);
|
|
|
|
}
|
|
|
|
|
2020-05-21 03:34:26 +00:00
|
|
|
Outputs::Display::DisplayType get_display_type() const final {
|
2020-03-18 02:06:20 +00:00
|
|
|
return video_output_.get_display_type();
|
|
|
|
}
|
|
|
|
|
2020-01-24 03:35:39 +00:00
|
|
|
Outputs::Speaker::Speaker *get_speaker() final {
|
2017-12-18 02:26:06 +00:00
|
|
|
return &speaker_;
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
2016-12-11 23:34:49 +00:00
|
|
|
|
2020-01-24 03:35:39 +00:00
|
|
|
void run_for(const Cycles cycles) final {
|
2017-08-16 19:33:40 +00:00
|
|
|
m6502_.run_for(cycles);
|
|
|
|
}
|
2016-12-11 02:07:52 +00:00
|
|
|
|
2021-02-01 02:24:54 +00:00
|
|
|
void scsi_bus_did_change(SCSI::Bus *, SCSI::BusState new_state, double) final {
|
|
|
|
// Release acknowledge when request is released.
|
|
|
|
if(scsi_acknowledge_ && !(new_state & SCSI::Line::Request)) {
|
|
|
|
scsi_acknowledge_ = false;
|
|
|
|
push_scsi_output();
|
|
|
|
}
|
2021-02-01 22:40:11 +00:00
|
|
|
|
2021-02-03 01:24:39 +00:00
|
|
|
// Output occurs only while SCSI::Line::Input is inactive; therefore a change
|
|
|
|
// in that line affects what's on the bus.
|
|
|
|
if(((new_state^previous_bus_state_)&SCSI::Line::Input)) {
|
|
|
|
push_scsi_output();
|
|
|
|
}
|
|
|
|
|
2021-02-01 22:40:11 +00:00
|
|
|
scsi_interrupt_state_ |= (new_state^previous_bus_state_)&new_state & SCSI::Line::Request;
|
|
|
|
previous_bus_state_ = new_state;
|
|
|
|
evaluate_interrupts();
|
2021-02-01 02:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_component_prefers_clocking(ClockingHint::Source *, ClockingHint::Preference preference) final {
|
|
|
|
scsi_is_clocked_ = preference != ClockingHint::Preference::None;
|
|
|
|
}
|
|
|
|
|
2020-05-30 04:37:06 +00:00
|
|
|
void tape_did_change_interrupt_status(Tape *) final {
|
2017-08-16 19:33:40 +00:00
|
|
|
interrupt_status_ = (interrupt_status_ & ~(Interrupt::TransmitDataEmpty | Interrupt::ReceiveDataFull | Interrupt::HighToneDetect)) | tape_.get_interrupt_status();
|
|
|
|
evaluate_interrupts();
|
|
|
|
}
|
2016-01-14 02:03:43 +00:00
|
|
|
|
2021-01-31 17:25:22 +00:00
|
|
|
HalfCycles get_typer_delay(const std::string &text) const final {
|
|
|
|
if(!m6502_.get_is_resetting()) {
|
|
|
|
return Cycles(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a longer delay for a command at reset that involves pressing a modifier;
|
|
|
|
// empirically this seems to be a requirement, in order to avoid a collision with
|
|
|
|
// the system's built-in modifier-at-startup test (e.g. to perform shift+break).
|
|
|
|
CharacterMapper test_mapper;
|
|
|
|
const uint16_t *const sequence = test_mapper.sequence_for_character(text[0]);
|
|
|
|
return is_modifier(Key(sequence[0])) ? Cycles(1'000'000) : Cycles(750'000);
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2020-05-21 03:34:26 +00:00
|
|
|
HalfCycles get_typer_frequency() const final {
|
2020-03-01 00:26:15 +00:00
|
|
|
return Cycles(60'000);
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
2016-04-20 01:29:10 +00:00
|
|
|
|
2020-01-24 03:35:39 +00:00
|
|
|
void type_string(const std::string &string) final {
|
2020-03-01 23:44:26 +00:00
|
|
|
Utility::TypeRecipient<CharacterMapper>::add_typer(string);
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
2016-12-16 00:47:04 +00:00
|
|
|
|
2020-05-21 03:34:26 +00:00
|
|
|
bool can_type(char c) const final {
|
2020-03-02 01:25:12 +00:00
|
|
|
return Utility::TypeRecipient<CharacterMapper>::can_type(c);
|
|
|
|
}
|
|
|
|
|
2020-01-24 03:57:51 +00:00
|
|
|
KeyboardMapper *get_keyboard_mapper() final {
|
2018-02-09 21:31:05 +00:00
|
|
|
return &keyboard_mapper_;
|
2017-10-13 02:25:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 00:48:10 +00:00
|
|
|
// MARK: - Configuration options.
|
2020-03-17 03:25:05 +00:00
|
|
|
std::unique_ptr<Reflection::Struct> get_options() final {
|
2020-03-18 02:06:20 +00:00
|
|
|
auto options = std::make_unique<Options>(Configurable::OptionsType::UserFriendly);
|
|
|
|
options->output = get_video_signal_configurable();
|
|
|
|
options->quickload = allow_fast_tape_hack_;
|
|
|
|
return options;
|
2017-11-18 04:02:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 02:06:20 +00:00
|
|
|
void set_options(const std::unique_ptr<Reflection::Struct> &str) final {
|
|
|
|
const auto options = dynamic_cast<Options *>(str.get());
|
|
|
|
|
|
|
|
set_video_signal_configurable(options->output);
|
|
|
|
allow_fast_tape_hack_ = options->quickload;
|
|
|
|
set_use_fast_tape_hack();
|
2017-11-18 04:02:00 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 00:01:04 +00:00
|
|
|
// MARK: - Activity Source
|
2020-01-24 03:57:51 +00:00
|
|
|
void set_activity_observer(Activity::Observer *observer) final {
|
2018-05-08 01:57:54 +00:00
|
|
|
activity_observer_ = observer;
|
|
|
|
if(activity_observer_) {
|
|
|
|
activity_observer_->register_led(caps_led);
|
|
|
|
activity_observer_->set_led_status(caps_led, caps_led_state_);
|
2021-02-01 02:41:11 +00:00
|
|
|
}
|
2018-06-19 01:49:57 +00:00
|
|
|
|
2021-02-01 02:41:11 +00:00
|
|
|
if(plus3_) {
|
|
|
|
plus3_->set_activity_observer(observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(has_scsi_bus) {
|
|
|
|
scsi_bus_.set_activity_observer(observer);
|
2018-05-08 01:57:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
private:
|
2018-07-11 00:00:46 +00:00
|
|
|
enum class ROM {
|
|
|
|
Slot0 = 0,
|
|
|
|
Slot1, Slot2, Slot3,
|
|
|
|
Slot4, Slot5, Slot6, Slot7,
|
|
|
|
|
|
|
|
Keyboard = 8, Slot9,
|
|
|
|
BASIC = 10, Slot11,
|
|
|
|
|
|
|
|
Slot12, Slot13, Slot14, Slot15,
|
|
|
|
|
|
|
|
OS, DFS,
|
|
|
|
ADFS1, ADFS2
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Sets the contents of @c slot to @c data. If @c is_writeable is @c true then writing to the slot
|
|
|
|
is enabled: it acts as if it were sideways RAM. Otherwise the slot is modelled as containing ROM.
|
|
|
|
*/
|
|
|
|
void set_rom(ROM slot, const std::vector<uint8_t> &data, bool is_writeable) {
|
|
|
|
uint8_t *target = nullptr;
|
|
|
|
switch(slot) {
|
|
|
|
case ROM::DFS: dfs_ = data; return;
|
|
|
|
case ROM::ADFS1: adfs1_ = data; return;
|
|
|
|
case ROM::ADFS2: adfs2_ = data; return;
|
|
|
|
|
2018-07-11 02:05:50 +00:00
|
|
|
case ROM::OS: target = os_; break;
|
2018-07-11 00:00:46 +00:00
|
|
|
default:
|
2020-05-10 03:00:39 +00:00
|
|
|
target = roms_[int(slot)];
|
|
|
|
rom_write_masks_[int(slot)] = is_writeable;
|
2018-07-11 00:00:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy in, with mirroring.
|
|
|
|
std::size_t rom_ptr = 0;
|
|
|
|
while(rom_ptr < 16384) {
|
|
|
|
std::size_t size_to_copy = std::min(16384 - rom_ptr, data.size());
|
|
|
|
std::memcpy(&target[rom_ptr], data.data(), size_to_copy);
|
|
|
|
rom_ptr += size_to_copy;
|
|
|
|
}
|
2018-07-11 01:49:38 +00:00
|
|
|
|
2021-01-31 00:38:19 +00:00
|
|
|
if(int(slot) < 16) {
|
2020-05-10 03:00:39 +00:00
|
|
|
rom_inserted_[int(slot)] = true;
|
2021-01-31 00:38:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Enables @c slot as sideways RAM; ensures that it does not currently contain a valid ROM signature.
|
|
|
|
*/
|
|
|
|
void set_sideways_ram(ROM slot) {
|
|
|
|
std::memset(roms_[int(slot)], 0xff, 16*1024);
|
|
|
|
if(int(slot) < 16) {
|
|
|
|
rom_inserted_[int(slot)] = true;
|
|
|
|
rom_write_masks_[int(slot)] = true;
|
|
|
|
}
|
2018-07-11 00:00:46 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 00:48:10 +00:00
|
|
|
// MARK: - Work deferral updates.
|
2017-08-16 19:33:40 +00:00
|
|
|
inline void update_display() {
|
|
|
|
if(cycles_since_display_update_ > 0) {
|
2019-07-29 01:49:54 +00:00
|
|
|
video_output_.run_for(cycles_since_display_update_.flush<Cycles>());
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-11 02:07:52 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
inline void queue_next_display_interrupt() {
|
2018-11-15 02:52:57 +00:00
|
|
|
VideoOutput::Interrupt next_interrupt = video_output_.get_next_interrupt();
|
2017-08-16 19:33:40 +00:00
|
|
|
cycles_until_display_interrupt_ = next_interrupt.cycles;
|
|
|
|
next_display_interrupt_ = next_interrupt.interrupt;
|
|
|
|
}
|
2016-12-11 02:07:52 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
inline void update_audio() {
|
2017-12-18 02:26:06 +00:00
|
|
|
speaker_.run_for(audio_queue_, cycles_since_audio_update_.divide(Cycles(SoundGenerator::clock_rate_divider)));
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void signal_interrupt(Interrupt interrupt) {
|
|
|
|
interrupt_status_ |= interrupt;
|
|
|
|
evaluate_interrupts();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void clear_interrupt(Interrupt interrupt) {
|
|
|
|
interrupt_status_ &= ~interrupt;
|
|
|
|
evaluate_interrupts();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void evaluate_interrupts() {
|
|
|
|
if(interrupt_status_ & interrupt_control_) {
|
|
|
|
interrupt_status_ |= 1;
|
|
|
|
} else {
|
|
|
|
interrupt_status_ &= ~1;
|
|
|
|
}
|
2021-02-01 22:40:11 +00:00
|
|
|
|
|
|
|
if constexpr (has_scsi_bus) {
|
|
|
|
m6502_.set_irq_line((scsi_interrupt_state_ && scsi_interrupt_mask_) | (interrupt_status_ & 1));
|
|
|
|
} else {
|
|
|
|
m6502_.set_irq_line(interrupt_status_ & 1);
|
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
}
|
2017-08-03 15:42:31 +00:00
|
|
|
|
2018-08-14 02:17:22 +00:00
|
|
|
CPU::MOS6502::Processor<CPU::MOS6502::Personality::P6502, ConcreteMachine, false> m6502_;
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
// Things that directly constitute the memory map.
|
|
|
|
uint8_t roms_[16][16384];
|
2018-04-18 22:13:30 +00:00
|
|
|
bool rom_inserted_[16] = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
2017-09-01 02:29:24 +00:00
|
|
|
bool rom_write_masks_[16] = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
2017-08-16 19:33:40 +00:00
|
|
|
uint8_t os_[16384], ram_[32768];
|
2017-11-07 03:14:15 +00:00
|
|
|
std::vector<uint8_t> dfs_, adfs1_, adfs2_;
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
// Paging
|
2020-05-10 03:00:39 +00:00
|
|
|
int active_rom_ = int(ROM::Slot0);
|
2017-09-01 02:29:24 +00:00
|
|
|
bool keyboard_is_active_ = false;
|
|
|
|
bool basic_is_active_ = false;
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
// Interrupt and keyboard state
|
2017-09-01 02:29:24 +00:00
|
|
|
uint8_t interrupt_status_ = Interrupt::PowerOnReset | Interrupt::TransmitDataEmpty | 0x80;
|
|
|
|
uint8_t interrupt_control_ = 0;
|
2017-08-16 19:33:40 +00:00
|
|
|
uint8_t key_states_[14];
|
2017-10-13 02:25:02 +00:00
|
|
|
Electron::KeyboardMapper keyboard_mapper_;
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
// Counters related to simultaneous subsystems
|
2017-09-01 02:29:24 +00:00
|
|
|
Cycles cycles_since_display_update_ = 0;
|
|
|
|
Cycles cycles_since_audio_update_ = 0;
|
|
|
|
int cycles_until_display_interrupt_ = 0;
|
|
|
|
Interrupt next_display_interrupt_ = Interrupt::RealTimeClock;
|
|
|
|
VideoOutput::Range video_access_range_ = {0, 0xffff};
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
// Tape
|
|
|
|
Tape tape_;
|
2017-09-01 02:29:24 +00:00
|
|
|
bool use_fast_tape_hack_ = false;
|
2018-02-19 21:57:24 +00:00
|
|
|
bool allow_fast_tape_hack_ = false;
|
|
|
|
void set_use_fast_tape_hack() {
|
|
|
|
use_fast_tape_hack_ = allow_fast_tape_hack_ && tape_.has_tape();
|
|
|
|
}
|
2017-09-01 02:29:24 +00:00
|
|
|
bool fast_load_is_in_data_ = false;
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
// Disk
|
|
|
|
std::unique_ptr<Plus3> plus3_;
|
2017-09-01 02:29:24 +00:00
|
|
|
bool is_holding_shift_ = false;
|
|
|
|
int shift_restart_counter_ = 0;
|
2017-08-16 19:33:40 +00:00
|
|
|
|
2021-01-31 23:36:29 +00:00
|
|
|
// Hard drive.
|
|
|
|
SCSI::Bus scsi_bus_;
|
|
|
|
SCSI::Target::Target<SCSI::DirectAccessDevice> hard_drive_;
|
2021-02-01 22:40:11 +00:00
|
|
|
SCSI::BusState previous_bus_state_ = SCSI::DefaultBusState;
|
2021-01-31 23:36:29 +00:00
|
|
|
const size_t scsi_device_ = 0;
|
|
|
|
uint8_t scsi_data_ = 0;
|
|
|
|
bool scsi_select_ = false;
|
|
|
|
bool scsi_acknowledge_ = false;
|
2021-02-01 02:24:54 +00:00
|
|
|
bool scsi_is_clocked_ = false;
|
2021-02-01 22:40:11 +00:00
|
|
|
bool scsi_interrupt_state_ = false;
|
|
|
|
bool scsi_interrupt_mask_ = false;
|
2021-01-31 23:36:29 +00:00
|
|
|
void push_scsi_output() {
|
|
|
|
scsi_bus_.set_device_output(scsi_device_,
|
2021-02-03 01:24:39 +00:00
|
|
|
(scsi_bus_.get_state()&SCSI::Line::Input ? 0 : scsi_data_) |
|
2021-01-31 23:36:29 +00:00
|
|
|
(scsi_select_ ? SCSI::Line::SelectTarget : 0) |
|
|
|
|
(scsi_acknowledge_ ? SCSI::Line::Acknowledge : 0)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
// Outputs
|
2018-11-15 02:52:57 +00:00
|
|
|
VideoOutput video_output_;
|
2017-12-18 02:26:06 +00:00
|
|
|
|
|
|
|
Concurrency::DeferringAsyncTaskQueue audio_queue_;
|
|
|
|
SoundGenerator sound_generator_;
|
|
|
|
Outputs::Speaker::LowpassSpeaker<SoundGenerator> speaker_;
|
|
|
|
|
2017-09-01 02:29:24 +00:00
|
|
|
bool speaker_is_enabled_ = false;
|
2018-05-08 01:57:54 +00:00
|
|
|
|
|
|
|
// MARK: - Caps Lock status and the activity observer.
|
|
|
|
const std::string caps_led = "CAPS";
|
|
|
|
bool caps_led_state_ = false;
|
2018-05-11 01:54:10 +00:00
|
|
|
Activity::Observer *activity_observer_ = nullptr;
|
2017-08-16 19:33:40 +00:00
|
|
|
};
|
2017-08-03 15:42:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
using namespace Electron;
|
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
Machine *Machine::Electron(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
|
|
|
|
using Target = Analyser::Static::Acorn::Target;
|
|
|
|
const Target *const acorn_target = dynamic_cast<const Target *>(target);
|
2021-01-31 23:36:29 +00:00
|
|
|
|
|
|
|
if(acorn_target->media.mass_storage_devices.empty()) {
|
|
|
|
return new Electron::ConcreteMachine<false>(*acorn_target, rom_fetcher);
|
|
|
|
} else {
|
|
|
|
return new Electron::ConcreteMachine<true>(*acorn_target, rom_fetcher);
|
|
|
|
}
|
2017-08-03 15:42:31 +00:00
|
|
|
}
|
2017-08-16 19:33:40 +00:00
|
|
|
|
|
|
|
Machine::~Machine() {}
|