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-01 01:23:44 +00:00
|
|
|
#include "../CRTMachine.hpp"
|
2016-01-05 04:12:47 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
ROMSlotOS
|
2016-01-07 02:09:49 +00:00
|
|
|
};
|
|
|
|
|
2016-01-10 01:26:40 +00:00
|
|
|
enum Interrupt: uint8_t {
|
2016-02-19 04:23:49 +00:00
|
|
|
PowerOnReset = 0x02,
|
2016-01-21 02:55:38 +00:00
|
|
|
DisplayEnd = 0x04,
|
|
|
|
RealTimeClock = 0x08,
|
2016-01-24 23:20:55 +00:00
|
|
|
ReceiveDataFull = 0x10,
|
|
|
|
TransmitDataEmpty = 0x20,
|
2016-01-21 02:55:38 +00:00
|
|
|
HighToneDetect = 0x40
|
2016-01-10 01:26:40 +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
|
|
|
|
|
|
|
KeyBreak = 0xffff
|
|
|
|
};
|
|
|
|
|
2016-01-23 05:14:44 +00:00
|
|
|
class Tape {
|
|
|
|
public:
|
|
|
|
Tape();
|
|
|
|
|
|
|
|
void set_tape(std::shared_ptr<Storage::Tape> tape);
|
2016-04-20 01:00:48 +00:00
|
|
|
inline bool has_tape()
|
|
|
|
{
|
|
|
|
return (bool)_tape;
|
|
|
|
}
|
2016-01-23 05:14:44 +00:00
|
|
|
|
2016-01-30 02:14:13 +00:00
|
|
|
inline uint8_t get_data_register();
|
2016-01-24 23:20:55 +00:00
|
|
|
inline void set_data_register(uint8_t value);
|
|
|
|
inline void set_counter(uint8_t value);
|
2016-01-23 05:14:44 +00:00
|
|
|
|
|
|
|
inline uint8_t get_interrupt_status() { return _interrupt_status; }
|
|
|
|
inline void clear_interrupts(uint8_t interrupts);
|
|
|
|
|
|
|
|
class Delegate {
|
|
|
|
public:
|
|
|
|
virtual void tape_did_change_interrupt_status(Tape *tape) = 0;
|
|
|
|
};
|
|
|
|
inline void set_delegate(Delegate *delegate) { _delegate = delegate; }
|
|
|
|
|
2016-01-23 16:42:14 +00:00
|
|
|
inline void run_for_cycles(unsigned int number_of_cycles);
|
2016-03-15 02:42:52 +00:00
|
|
|
inline void run_for_input_pulse();
|
2016-01-23 05:14:44 +00:00
|
|
|
|
2016-01-23 18:09:56 +00:00
|
|
|
inline void set_is_running(bool is_running) { _is_running = is_running; }
|
|
|
|
inline void set_is_enabled(bool is_enabled) { _is_enabled = is_enabled; }
|
2016-01-24 23:20:55 +00:00
|
|
|
inline void set_is_in_input_mode(bool is_in_input_mode);
|
2016-01-23 05:14:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
inline void push_tape_bit(uint16_t bit);
|
|
|
|
inline void get_next_tape_pulse();
|
|
|
|
|
|
|
|
std::shared_ptr<Storage::Tape> _tape;
|
|
|
|
|
2016-03-13 01:32:26 +00:00
|
|
|
struct {
|
|
|
|
Storage::Tape::Pulse current_pulse;
|
|
|
|
std::unique_ptr<SignalProcessing::Stepper> pulse_stepper;
|
|
|
|
uint32_t time_into_pulse;
|
|
|
|
int minimum_bits_until_full;
|
|
|
|
} _input;
|
|
|
|
struct {
|
|
|
|
unsigned int cycles_into_pulse;
|
|
|
|
unsigned int bits_remaining_until_empty;
|
|
|
|
} _output;
|
2016-01-23 05:14:44 +00:00
|
|
|
|
|
|
|
bool _is_running;
|
2016-01-23 18:09:56 +00:00
|
|
|
bool _is_enabled;
|
2016-01-24 23:20:55 +00:00
|
|
|
bool _is_in_input_mode;
|
2016-01-23 05:14:44 +00:00
|
|
|
|
2016-01-24 23:20:55 +00:00
|
|
|
inline void evaluate_interrupts();
|
2016-01-23 05:14:44 +00:00
|
|
|
uint16_t _data_register;
|
|
|
|
|
2016-01-24 23:20:55 +00:00
|
|
|
uint8_t _interrupt_status, _last_posted_interrupt_status;
|
2016-01-23 05:14:44 +00:00
|
|
|
Delegate *_delegate;
|
|
|
|
|
|
|
|
enum {
|
2016-01-28 02:35:57 +00:00
|
|
|
Long, Short, Unrecognised, Recognised
|
2016-01-23 05:14:44 +00:00
|
|
|
} _crossings[4];
|
|
|
|
};
|
|
|
|
|
2016-01-23 22:45:06 +00:00
|
|
|
class Speaker: public ::Outputs::Filter<Speaker> {
|
|
|
|
public:
|
|
|
|
void set_divider(uint8_t divider);
|
|
|
|
|
|
|
|
void set_is_enabled(bool is_enabled);
|
|
|
|
inline bool get_is_enabled() { return _is_enabled; }
|
|
|
|
|
|
|
|
void get_samples(unsigned int number_of_samples, int16_t *target);
|
|
|
|
void skip_samples(unsigned int number_of_samples);
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int _counter;
|
2016-04-07 01:12:22 +00:00
|
|
|
unsigned int _divider;
|
2016-01-23 22:45:06 +00:00
|
|
|
bool _is_enabled;
|
|
|
|
};
|
|
|
|
|
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-01 02:16:20 +00:00
|
|
|
class Machine: public CPU6502::Processor<Machine>, public CRTMachine::Machine, Tape::Delegate {
|
2016-01-05 04:12:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Machine();
|
|
|
|
|
2016-01-07 02:09:49 +00:00
|
|
|
void set_rom(ROMSlot slot, size_t length, const uint8_t *data);
|
2016-01-20 13:27:25 +00:00
|
|
|
void set_tape(std::shared_ptr<Storage::Tape> tape);
|
2016-01-20 03:05:34 +00:00
|
|
|
|
2016-01-12 00:48:31 +00:00
|
|
|
void set_key_state(Key key, bool isPressed);
|
2016-04-20 01:29:10 +00:00
|
|
|
void clear_all_keys();
|
2016-01-07 02:09:49 +00:00
|
|
|
|
2016-06-01 01:23:44 +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-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();
|
|
|
|
virtual Outputs::CRT::CRT *get_crt() { return _crt.get(); }
|
|
|
|
virtual Outputs::Speaker *get_speaker() { return &_speaker; }
|
|
|
|
virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor<Machine>::run_for_cycles(number_of_cycles); }
|
2016-06-17 00:39:46 +00:00
|
|
|
virtual double get_clock_rate() { return 2000000; }
|
2016-06-01 01:23:44 +00:00
|
|
|
|
|
|
|
// to satisfy Tape::Delegate
|
|
|
|
virtual void tape_did_change_interrupt_status(Tape *tape);
|
2016-02-15 00:28:02 +00:00
|
|
|
|
2016-01-07 02:09:49 +00:00
|
|
|
private:
|
2016-01-20 03:05:34 +00:00
|
|
|
|
|
|
|
inline void update_display();
|
2016-03-11 03:08:50 +00:00
|
|
|
inline void start_pixel_line();
|
|
|
|
inline void end_pixel_line();
|
|
|
|
inline void output_pixels(unsigned int number_of_cycles);
|
2016-02-19 04:23:49 +00:00
|
|
|
|
2016-01-20 03:05:34 +00:00
|
|
|
inline void update_audio();
|
|
|
|
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-01-13 03:34:26 +00:00
|
|
|
uint8_t _roms[16][16384];
|
|
|
|
uint8_t _os[16384], _ram[32768];
|
2016-01-20 03:05:34 +00:00
|
|
|
|
|
|
|
// Things affected by registers, explicitly or otherwise.
|
2016-02-19 04:23:49 +00:00
|
|
|
uint8_t _interrupt_status, _interrupt_control;
|
2016-01-12 00:48:31 +00:00
|
|
|
uint8_t _palette[16];
|
2016-02-19 04:23:49 +00:00
|
|
|
uint8_t _key_states[14];
|
|
|
|
ROMSlot _active_rom;
|
2016-05-05 12:28:06 +00:00
|
|
|
bool _keyboard_is_active, _basic_is_active;
|
2016-02-19 04:23:49 +00:00
|
|
|
uint8_t _screen_mode;
|
2016-01-12 03:08:30 +00:00
|
|
|
uint16_t _screenModeBaseAddress;
|
2016-01-20 03:05:34 +00:00
|
|
|
uint16_t _startScreenAddress;
|
2016-01-08 03:26:49 +00:00
|
|
|
|
2016-04-22 01:07:29 +00:00
|
|
|
// Counters related to simultaneous subsystems
|
2016-03-11 03:08:50 +00:00
|
|
|
unsigned int _frameCycles, _displayOutputPosition;
|
2016-04-14 02:31:59 +00:00
|
|
|
unsigned int _audioOutputPosition, _audioOutputPositionError;
|
2016-04-22 01:07:29 +00:00
|
|
|
uint8_t _phase;
|
2016-01-14 02:03:43 +00:00
|
|
|
|
2016-04-06 02:07:10 +00:00
|
|
|
struct {
|
|
|
|
uint16_t forty1bpp[256];
|
|
|
|
uint8_t forty2bpp[256];
|
|
|
|
uint32_t eighty1bpp[256];
|
|
|
|
uint16_t eighty2bpp[256];
|
|
|
|
uint8_t eighty4bpp[256];
|
|
|
|
} _paletteTables;
|
|
|
|
|
2016-01-20 03:05:34 +00:00
|
|
|
// Display generation.
|
|
|
|
uint16_t _startLineAddress, _currentScreenAddress;
|
2016-03-11 03:19:54 +00:00
|
|
|
int _current_pixel_line, _current_pixel_column, _current_character_row;
|
2016-03-11 03:08:50 +00:00
|
|
|
uint8_t _last_pixel_byte;
|
2016-03-11 03:19:54 +00:00
|
|
|
bool _isBlankLine;
|
2016-02-20 04:41:09 +00:00
|
|
|
|
|
|
|
// CRT output
|
2016-03-23 01:16:32 +00:00
|
|
|
uint8_t *_current_output_target, *_initial_output_target;
|
|
|
|
unsigned int _current_output_divider;
|
2016-01-10 01:26:40 +00:00
|
|
|
|
2016-06-01 01:23:44 +00:00
|
|
|
// Tape
|
2016-01-23 05:14:44 +00:00
|
|
|
Tape _tape;
|
2016-03-13 21:39:53 +00:00
|
|
|
bool _use_fast_tape_hack;
|
|
|
|
bool _fast_load_is_in_data;
|
2016-01-20 03:05:34 +00:00
|
|
|
|
2016-06-01 01:23:44 +00:00
|
|
|
// Outputs
|
2016-03-09 01:49:07 +00:00
|
|
|
std::unique_ptr<Outputs::CRT::CRT> _crt;
|
2016-01-23 22:45:06 +00:00
|
|
|
Speaker _speaker;
|
2016-01-05 04:12:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Electron_hpp */
|