2017-06-04 21:55:19 +00:00
|
|
|
//
|
|
|
|
// ZX8081.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 04/06/2017.
|
|
|
|
// Copyright © 2017 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ZX8081_hpp
|
|
|
|
#define ZX8081_hpp
|
|
|
|
|
|
|
|
#include "../ConfigurationTarget.hpp"
|
|
|
|
#include "../CRTMachine.hpp"
|
|
|
|
|
|
|
|
#include "../../Processors/Z80/Z80.hpp"
|
2017-06-06 14:13:32 +00:00
|
|
|
#include "../../Storage/Tape/Tape.hpp"
|
2017-06-11 22:31:43 +00:00
|
|
|
#include "../../Storage/Tape/Parsers/ZX8081.hpp"
|
2017-06-04 21:55:19 +00:00
|
|
|
|
2017-06-06 21:53:23 +00:00
|
|
|
#include "Video.hpp"
|
|
|
|
|
2017-06-04 22:08:35 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-06-04 21:55:19 +00:00
|
|
|
namespace ZX8081 {
|
|
|
|
|
2017-06-04 22:08:35 +00:00
|
|
|
enum ROMType: uint8_t {
|
|
|
|
ZX80, ZX81
|
|
|
|
};
|
|
|
|
|
2017-06-06 13:25:18 +00:00
|
|
|
enum Key: uint16_t {
|
|
|
|
KeyShift = 0x0000 | 0x01, KeyZ = 0x0000 | 0x02, KeyX = 0x0000 | 0x04, KeyC = 0x0000 | 0x08, KeyV = 0x0000 | 0x10,
|
|
|
|
KeyA = 0x0100 | 0x01, KeyS = 0x0100 | 0x02, KeyD = 0x0100 | 0x04, KeyF = 0x0100 | 0x08, KeyG = 0x0100 | 0x10,
|
|
|
|
KeyQ = 0x0200 | 0x01, KeyW = 0x0200 | 0x02, KeyE = 0x0200 | 0x04, KeyR = 0x0200 | 0x08, KeyT = 0x0200 | 0x10,
|
|
|
|
Key1 = 0x0300 | 0x01, Key2 = 0x0300 | 0x02, Key3 = 0x0300 | 0x04, Key4 = 0x0300 | 0x08, Key5 = 0x0300 | 0x10,
|
|
|
|
Key0 = 0x0400 | 0x01, Key9 = 0x0400 | 0x02, Key8 = 0x0400 | 0x04, Key7 = 0x0400 | 0x08, Key6 = 0x0400 | 0x10,
|
|
|
|
KeyP = 0x0500 | 0x01, KeyO = 0x0500 | 0x02, KeyI = 0x0500 | 0x04, KeyU = 0x0500 | 0x08, KeyY = 0x0500 | 0x10,
|
|
|
|
KeyEnter = 0x0600 | 0x01, KeyL = 0x0600 | 0x02, KeyK = 0x0600 | 0x04, KeyJ = 0x0600 | 0x08, KeyH = 0x0600 | 0x10,
|
|
|
|
KeySpace = 0x0700 | 0x01, KeyDot = 0x0700 | 0x02, KeyM = 0x0700 | 0x04, KeyN = 0x0700 | 0x08, KeyB = 0x0700 | 0x10,
|
|
|
|
};
|
|
|
|
|
2017-06-04 21:55:19 +00:00
|
|
|
class Machine:
|
|
|
|
public CPU::Z80::Processor<Machine>,
|
|
|
|
public CRTMachine::Machine,
|
|
|
|
public ConfigurationTarget::Machine {
|
|
|
|
public:
|
|
|
|
Machine();
|
|
|
|
|
2017-06-22 00:38:08 +00:00
|
|
|
int perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle);
|
2017-06-04 22:08:35 +00:00
|
|
|
void flush();
|
2017-06-04 21:55:19 +00:00
|
|
|
|
|
|
|
void setup_output(float aspect_ratio);
|
|
|
|
void close_output();
|
|
|
|
|
|
|
|
std::shared_ptr<Outputs::CRT::CRT> get_crt();
|
|
|
|
std::shared_ptr<Outputs::Speaker> get_speaker();
|
|
|
|
|
|
|
|
void run_for_cycles(int number_of_cycles);
|
|
|
|
|
|
|
|
void configure_as_target(const StaticAnalyser::Target &target);
|
|
|
|
|
2017-06-04 22:08:35 +00:00
|
|
|
void set_rom(ROMType type, std::vector<uint8_t> data);
|
2017-06-06 13:25:18 +00:00
|
|
|
void set_key_state(uint16_t key, bool isPressed);
|
|
|
|
void clear_all_keys();
|
2017-06-04 22:08:35 +00:00
|
|
|
|
2017-06-04 21:55:19 +00:00
|
|
|
private:
|
2017-06-06 21:53:23 +00:00
|
|
|
std::shared_ptr<Video> video_;
|
2017-06-11 23:29:02 +00:00
|
|
|
std::vector<uint8_t> zx81_rom_, zx80_rom_;
|
2017-06-11 20:42:49 +00:00
|
|
|
uint16_t tape_trap_address_, tape_return_address_;
|
2017-06-04 22:32:23 +00:00
|
|
|
|
2017-06-11 23:29:02 +00:00
|
|
|
std::vector<uint8_t> ram_;
|
|
|
|
uint16_t ram_mask_, ram_base_;
|
|
|
|
|
|
|
|
std::vector<uint8_t> rom_;
|
|
|
|
uint16_t rom_mask_;
|
|
|
|
|
2017-06-05 01:54:55 +00:00
|
|
|
bool vsync_, hsync_;
|
2017-06-06 12:55:07 +00:00
|
|
|
int line_counter_;
|
2017-06-04 22:32:23 +00:00
|
|
|
|
2017-06-06 13:25:18 +00:00
|
|
|
uint8_t key_states_[8];
|
|
|
|
|
2017-06-05 01:54:55 +00:00
|
|
|
void set_vsync(bool sync);
|
|
|
|
void set_hsync(bool sync);
|
2017-06-05 14:47:42 +00:00
|
|
|
void update_sync();
|
2017-06-06 14:13:32 +00:00
|
|
|
|
|
|
|
Storage::Tape::BinaryTapePlayer tape_player_;
|
2017-06-11 22:31:43 +00:00
|
|
|
Storage::Tape::ZX8081::Parser parser_;
|
2017-06-13 01:33:16 +00:00
|
|
|
|
|
|
|
int horizontal_counter_;
|
|
|
|
bool is_zx81_;
|
2017-06-14 01:25:55 +00:00
|
|
|
bool nmi_is_enabled_;
|
|
|
|
int vsync_start_cycle_, vsync_end_cycle_;
|
2017-06-22 01:18:09 +00:00
|
|
|
uint8_t latched_video_byte_;
|
2017-06-04 21:55:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ZX8081_hpp */
|