2016-01-05 04:12:47 +00:00
|
|
|
//
|
|
|
|
// Electron.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 03/01/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Electron_hpp
|
|
|
|
#define Electron_hpp
|
|
|
|
|
|
|
|
#include "../../Processors/6502/CPU6502.hpp"
|
2016-01-20 03:05:34 +00:00
|
|
|
#include "../../Storage/Tape/Tape.hpp"
|
2016-06-19 21:25:35 +00:00
|
|
|
|
2016-09-08 09:32:17 +00:00
|
|
|
#include "../ConfigurationTarget.hpp"
|
2016-06-01 01:23:44 +00:00
|
|
|
#include "../CRTMachine.hpp"
|
2016-06-19 21:25:35 +00:00
|
|
|
#include "../Typer.hpp"
|
2016-12-11 02:07:52 +00:00
|
|
|
|
|
|
|
#include "Interrupts.hpp"
|
2016-09-26 01:24:16 +00:00
|
|
|
#include "Plus3.hpp"
|
2016-12-03 17:41:02 +00:00
|
|
|
#include "Speaker.hpp"
|
2016-12-03 17:18:08 +00:00
|
|
|
#include "Tape.hpp"
|
2016-12-11 02:07:52 +00:00
|
|
|
#include "Video.hpp"
|
2016-06-19 21:25:35 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
2016-09-20 11:36:57 +00:00
|
|
|
#include <vector>
|
2016-01-05 04:12:47 +00:00
|
|
|
|
|
|
|
namespace Electron {
|
|
|
|
|
2016-01-08 02:01:13 +00:00
|
|
|
enum ROMSlot: uint8_t {
|
2016-01-08 03:26:49 +00:00
|
|
|
ROMSlot0 = 0,
|
|
|
|
ROMSlot1, ROMSlot2, ROMSlot3,
|
|
|
|
ROMSlot4, ROMSlot5, ROMSlot6, ROMSlot7,
|
2016-01-08 02:01:13 +00:00
|
|
|
|
|
|
|
ROMSlotKeyboard = 8, ROMSlot9,
|
|
|
|
ROMSlotBASIC = 10, ROMSlot11,
|
|
|
|
|
2016-01-08 03:26:49 +00:00
|
|
|
ROMSlot12, ROMSlot13, ROMSlot14, ROMSlot15,
|
2016-01-08 02:01:13 +00:00
|
|
|
|
2016-09-20 11:36:57 +00:00
|
|
|
ROMSlotOS, ROMSlotDFS, ROMSlotADFS
|
2016-01-07 02:09:49 +00:00
|
|
|
};
|
|
|
|
|
2016-01-12 00:48:31 +00:00
|
|
|
enum Key: uint16_t {
|
2016-01-13 03:19:56 +00:00
|
|
|
KeySpace = 0x0000 | 0x08, KeyCopy = 0x0000 | 0x02, KeyRight = 0x0000 | 0x01,
|
|
|
|
KeyDelete = 0x0010 | 0x08, KeyReturn = 0x0010 | 0x04, KeyDown = 0x0010 | 0x02, KeyLeft = 0x0010 | 0x01,
|
|
|
|
KeyColon = 0x0020 | 0x04, KeyUp = 0x0020 | 0x02, KeyMinus = 0x0020 | 0x01,
|
|
|
|
KeySlash = 0x0030 | 0x08, KeySemiColon = 0x0030 | 0x04, KeyP = 0x0030 | 0x02, Key0 = 0x0030 | 0x01,
|
|
|
|
KeyFullStop = 0x0040 | 0x08, KeyL = 0x0040 | 0x04, KeyO = 0x0040 | 0x02, Key9 = 0x0040 | 0x01,
|
|
|
|
KeyComma = 0x0050 | 0x08, KeyK = 0x0050 | 0x04, KeyI = 0x0050 | 0x02, Key8 = 0x0050 | 0x01,
|
|
|
|
KeyM = 0x0060 | 0x08, KeyJ = 0x0060 | 0x04, KeyU = 0x0060 | 0x02, Key7 = 0x0060 | 0x01,
|
|
|
|
KeyN = 0x0070 | 0x08, KeyH = 0x0070 | 0x04, KeyY = 0x0070 | 0x02, Key6 = 0x0070 | 0x01,
|
|
|
|
KeyB = 0x0080 | 0x08, KeyG = 0x0080 | 0x04, KeyT = 0x0080 | 0x02, Key5 = 0x0080 | 0x01,
|
|
|
|
KeyV = 0x0090 | 0x08, KeyF = 0x0090 | 0x04, KeyR = 0x0090 | 0x02, Key4 = 0x0090 | 0x01,
|
|
|
|
KeyC = 0x00a0 | 0x08, KeyD = 0x00a0 | 0x04, KeyE = 0x00a0 | 0x02, Key3 = 0x00a0 | 0x01,
|
|
|
|
KeyX = 0x00b0 | 0x08, KeyS = 0x00b0 | 0x04, KeyW = 0x00b0 | 0x02, Key2 = 0x00b0 | 0x01,
|
|
|
|
KeyZ = 0x00c0 | 0x08, KeyA = 0x00c0 | 0x04, KeyQ = 0x00c0 | 0x02, Key1 = 0x00c0 | 0x01,
|
|
|
|
KeyShift = 0x00d0 | 0x08, KeyControl = 0x00d0 | 0x04, KeyFunc = 0x00d0 | 0x02, KeyEscape = 0x00d0 | 0x01,
|
2016-01-12 00:48:31 +00:00
|
|
|
|
2016-11-05 19:07:57 +00:00
|
|
|
KeyBreak = 0xfffd,
|
2016-06-19 21:25:35 +00:00
|
|
|
|
2016-11-05 19:07:57 +00:00
|
|
|
TerminateSequence = 0xffff, NotMapped = 0xfffe,
|
2016-01-12 00:48:31 +00:00
|
|
|
};
|
|
|
|
|
2016-01-23 05:14:44 +00:00
|
|
|
/*!
|
2016-01-21 02:55:38 +00:00
|
|
|
@abstract Represents an Acorn Electron.
|
|
|
|
|
|
|
|
@discussion An instance of Electron::Machine represents the current state of an
|
|
|
|
Acorn Electron.
|
|
|
|
*/
|
2016-06-19 21:25:35 +00:00
|
|
|
class Machine:
|
|
|
|
public CPU6502::Processor<Machine>,
|
|
|
|
public CRTMachine::Machine,
|
2016-09-08 09:32:17 +00:00
|
|
|
public Tape::Delegate,
|
|
|
|
public Utility::TypeRecipient,
|
|
|
|
public ConfigurationTarget::Machine {
|
2016-01-05 04:12:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Machine();
|
|
|
|
|
2016-09-25 02:04:54 +00:00
|
|
|
void set_rom(ROMSlot slot, std::vector<uint8_t> data, bool is_writeable);
|
2016-01-20 03:05:34 +00:00
|
|
|
|
2016-11-05 18:47:09 +00:00
|
|
|
void set_key_state(uint16_t key, bool isPressed);
|
2016-04-20 01:29:10 +00:00
|
|
|
void clear_all_keys();
|
2016-01-07 02:09:49 +00:00
|
|
|
|
2016-12-03 18:01:01 +00:00
|
|
|
inline void set_use_fast_tape_hack(bool activate) { use_fast_tape_hack_ = activate; }
|
2016-01-08 03:26:49 +00:00
|
|
|
|
2016-10-12 02:20:13 +00:00
|
|
|
// to satisfy ConfigurationTarget::Machine
|
|
|
|
void configure_as_target(const StaticAnalyser::Target &target);
|
|
|
|
|
2016-06-01 01:23:44 +00:00
|
|
|
// to satisfy CPU6502::Processor
|
|
|
|
unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value);
|
|
|
|
void synchronise();
|
2016-01-23 05:14:44 +00:00
|
|
|
|
2016-06-01 01:23:44 +00:00
|
|
|
// to satisfy CRTMachine::Machine
|
|
|
|
virtual void setup_output(float aspect_ratio);
|
|
|
|
virtual void close_output();
|
2016-12-11 02:07:52 +00:00
|
|
|
virtual std::shared_ptr<Outputs::CRT::CRT> get_crt();
|
|
|
|
virtual std::shared_ptr<Outputs::Speaker> get_speaker();
|
2016-06-01 01:23:44 +00:00
|
|
|
virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor<Machine>::run_for_cycles(number_of_cycles); }
|
|
|
|
|
|
|
|
// to satisfy Tape::Delegate
|
|
|
|
virtual void tape_did_change_interrupt_status(Tape *tape);
|
2016-02-15 00:28:02 +00:00
|
|
|
|
2016-06-19 21:25:35 +00:00
|
|
|
// for Utility::TypeRecipient
|
|
|
|
virtual int get_typer_delay();
|
|
|
|
virtual int get_typer_frequency();
|
2016-11-05 19:07:57 +00:00
|
|
|
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
|
2016-06-19 21:25:35 +00:00
|
|
|
|
2016-01-07 02:09:49 +00:00
|
|
|
private:
|
2016-01-20 03:05:34 +00:00
|
|
|
inline void update_display();
|
2016-12-11 23:34:49 +00:00
|
|
|
inline void queue_next_display_interrupt();
|
2016-01-20 03:05:34 +00:00
|
|
|
inline void update_audio();
|
2016-12-11 02:07:52 +00:00
|
|
|
|
2016-01-20 03:05:34 +00:00
|
|
|
inline void signal_interrupt(Interrupt interrupt);
|
2016-03-11 03:08:50 +00:00
|
|
|
inline void clear_interrupt(Interrupt interrupt);
|
2016-01-20 03:05:34 +00:00
|
|
|
inline void evaluate_interrupts();
|
|
|
|
|
|
|
|
// Things that directly constitute the memory map.
|
2016-12-03 18:01:01 +00:00
|
|
|
uint8_t roms_[16][16384];
|
|
|
|
bool rom_write_masks_[16];
|
|
|
|
uint8_t os_[16384], ram_[32768];
|
|
|
|
std::vector<uint8_t> dfs_, adfs_;
|
2016-01-20 03:05:34 +00:00
|
|
|
|
2016-12-11 21:17:51 +00:00
|
|
|
// Paging
|
2016-12-03 18:01:01 +00:00
|
|
|
ROMSlot active_rom_;
|
|
|
|
bool keyboard_is_active_, basic_is_active_;
|
2016-01-08 03:26:49 +00:00
|
|
|
|
2016-12-11 21:17:51 +00:00
|
|
|
// Interrupt and keyboard state
|
|
|
|
uint8_t interrupt_status_, interrupt_control_;
|
|
|
|
uint8_t key_states_[14];
|
|
|
|
|
2016-04-22 01:07:29 +00:00
|
|
|
// Counters related to simultaneous subsystems
|
2016-12-11 23:34:49 +00:00
|
|
|
unsigned int cycles_since_display_update_;
|
|
|
|
unsigned int cycles_since_audio_update_;
|
|
|
|
int cycles_until_display_interrupt_;
|
|
|
|
Interrupt next_display_interrupt_;
|
2016-12-16 00:20:14 +00:00
|
|
|
VideoOutput::Range video_access_range_;
|
2016-01-14 02:03:43 +00:00
|
|
|
|
2016-06-01 01:23:44 +00:00
|
|
|
// Tape
|
2016-12-03 18:01:01 +00:00
|
|
|
Tape tape_;
|
|
|
|
bool use_fast_tape_hack_;
|
|
|
|
bool fast_load_is_in_data_;
|
2016-01-20 03:05:34 +00:00
|
|
|
|
2016-09-20 02:06:56 +00:00
|
|
|
// Disk
|
2016-12-03 18:01:01 +00:00
|
|
|
std::unique_ptr<Plus3> plus3_;
|
2016-09-25 18:11:22 +00:00
|
|
|
bool is_holding_shift_;
|
2017-01-08 19:46:19 +00:00
|
|
|
int shift_restart_counter_;
|
2016-09-20 02:06:56 +00:00
|
|
|
|
2016-06-01 01:23:44 +00:00
|
|
|
// Outputs
|
2016-12-11 02:07:52 +00:00
|
|
|
std::unique_ptr<VideoOutput> video_output_;
|
2016-12-03 18:01:01 +00:00
|
|
|
std::shared_ptr<Speaker> speaker_;
|
2016-10-07 21:02:36 +00:00
|
|
|
bool speaker_is_enabled_;
|
2016-01-05 04:12:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Electron_hpp */
|