2016-06-05 01:43:50 +00:00
|
|
|
//
|
|
|
|
// Vic20.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 04/06/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-06-05 01:43:50 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Vic20.hpp"
|
2016-06-05 02:00:50 +00:00
|
|
|
|
2017-10-20 02:27:30 +00:00
|
|
|
#include "Keyboard.hpp"
|
2016-06-05 14:51:07 +00:00
|
|
|
|
2018-05-12 02:24:33 +00:00
|
|
|
#include "../../../Activity/Source.hpp"
|
2018-07-11 01:32:28 +00:00
|
|
|
#include "../../MediaTarget.hpp"
|
2018-03-09 20:19:02 +00:00
|
|
|
#include "../../CRTMachine.hpp"
|
|
|
|
#include "../../KeyboardMachine.hpp"
|
|
|
|
#include "../../JoystickMachine.hpp"
|
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
#include "../../../Processors/6502/6502.hpp"
|
|
|
|
#include "../../../Components/6560/6560.hpp"
|
|
|
|
#include "../../../Components/6522/6522.hpp"
|
2016-06-05 02:00:50 +00:00
|
|
|
|
2017-08-22 01:56:42 +00:00
|
|
|
#include "../../../ClockReceiver/ForceInline.hpp"
|
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
#include "../../../Storage/Tape/Parsers/Commodore.hpp"
|
2016-08-13 21:21:25 +00:00
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
#include "../SerialBus.hpp"
|
|
|
|
#include "../1540/C1540.hpp"
|
2016-06-05 14:51:07 +00:00
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
#include "../../../Storage/Tape/Tape.hpp"
|
|
|
|
#include "../../../Storage/Disk/Disk.hpp"
|
2016-07-01 23:01:22 +00:00
|
|
|
|
2017-11-21 02:55:32 +00:00
|
|
|
#include "../../../Configurable/StandardOptions.hpp"
|
|
|
|
|
2018-03-09 21:07:29 +00:00
|
|
|
#include "../../../Analyser/Static/Commodore/Target.hpp"
|
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
#include <algorithm>
|
2018-04-12 01:35:23 +00:00
|
|
|
#include <array>
|
2017-11-24 22:55:28 +00:00
|
|
|
#include <cstdint>
|
2017-08-16 20:05:30 +00:00
|
|
|
|
|
|
|
namespace Commodore {
|
|
|
|
namespace Vic20 {
|
|
|
|
|
2017-11-24 22:55:28 +00:00
|
|
|
enum ROMSlot {
|
|
|
|
Kernel = 0,
|
|
|
|
BASIC,
|
|
|
|
Characters,
|
|
|
|
Drive
|
|
|
|
};
|
|
|
|
|
2017-11-21 02:55:32 +00:00
|
|
|
std::vector<std::unique_ptr<Configurable::Option>> get_options() {
|
2018-04-01 02:14:34 +00:00
|
|
|
return Configurable::standard_options(
|
2018-11-29 01:53:33 +00:00
|
|
|
static_cast<Configurable::StandardOptions>(Configurable::DisplaySVideo | Configurable::DisplayCompositeColour | Configurable::QuickLoadTape)
|
2018-04-01 02:14:34 +00:00
|
|
|
);
|
2017-11-21 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-15 02:36:31 +00:00
|
|
|
enum JoystickInput {
|
|
|
|
Up = 0x04,
|
|
|
|
Down = 0x08,
|
|
|
|
Left = 0x10,
|
|
|
|
Right = 0x80,
|
|
|
|
Fire = 0x20
|
|
|
|
};
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/*!
|
2018-05-13 19:34:31 +00:00
|
|
|
Models the user-port VIA, which is the Vic's connection point for controlling its tape recorder;
|
|
|
|
sensing the presence or absence of a tape and controlling the tape motor; and reading the current
|
2017-08-16 20:23:33 +00:00
|
|
|
state from its serial port. Most of the joystick input is also exposed here.
|
|
|
|
*/
|
2017-09-04 18:26:04 +00:00
|
|
|
class UserPortVIA: public MOS::MOS6522::IRQDelegatePortHandler {
|
2017-08-16 20:05:30 +00:00
|
|
|
public:
|
|
|
|
UserPortVIA() : port_a_(0xbf) {}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Reports the current input to the 6522 port @c port.
|
2017-09-04 18:26:04 +00:00
|
|
|
uint8_t get_port_input(MOS::MOS6522::Port port) {
|
2017-08-16 20:23:33 +00:00
|
|
|
// Port A provides information about the presence or absence of a tape, and parts of
|
|
|
|
// the joystick and serial port state, both of which have been statefully collected
|
|
|
|
// into port_a_.
|
2017-08-16 20:05:30 +00:00
|
|
|
if(!port) {
|
|
|
|
return port_a_ | (tape_->has_tape() ? 0x00 : 0x40);
|
|
|
|
}
|
|
|
|
return 0xff;
|
|
|
|
}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Receives announcements of control line output change from the 6522.
|
2017-09-04 18:26:04 +00:00
|
|
|
void set_control_line_output(MOS::MOS6522::Port port, MOS::MOS6522::Line line, bool value) {
|
2017-08-16 20:23:33 +00:00
|
|
|
// The CA2 output is used to control the tape motor.
|
2017-09-04 18:26:04 +00:00
|
|
|
if(port == MOS::MOS6522::Port::A && line == MOS::MOS6522::Line::Two) {
|
2017-08-16 20:05:30 +00:00
|
|
|
tape_->set_motor_control(!value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Receives announcements of changes in the serial bus connected to the serial port and propagates them into Port A.
|
2017-08-16 20:05:30 +00:00
|
|
|
void set_serial_line_state(::Commodore::Serial::Line line, bool value) {
|
|
|
|
switch(line) {
|
|
|
|
default: break;
|
|
|
|
case ::Commodore::Serial::Line::Data: port_a_ = (port_a_ & ~0x02) | (value ? 0x02 : 0x00); break;
|
|
|
|
case ::Commodore::Serial::Line::Clock: port_a_ = (port_a_ & ~0x01) | (value ? 0x01 : 0x00); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Allows the current joystick input to be set.
|
2017-08-16 20:05:30 +00:00
|
|
|
void set_joystick_state(JoystickInput input, bool value) {
|
|
|
|
if(input != JoystickInput::Right) {
|
|
|
|
port_a_ = (port_a_ & ~input) | (value ? 0 : input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Receives announcements from the 6522 of user-port output, which might affect what's currently being presented onto the serial bus.
|
2017-09-04 18:26:04 +00:00
|
|
|
void set_port_output(MOS::MOS6522::Port port, uint8_t value, uint8_t mask) {
|
2017-08-16 20:23:33 +00:00
|
|
|
// Line 7 of port A is inverted and output as serial ATN.
|
2017-08-16 20:05:30 +00:00
|
|
|
if(!port) {
|
|
|
|
std::shared_ptr<::Commodore::Serial::Port> serialPort = serial_port_.lock();
|
2017-08-16 20:23:33 +00:00
|
|
|
if(serialPort) serialPort->set_output(::Commodore::Serial::Line::Attention, (::Commodore::Serial::LineLevel)!(value&0x80));
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Sets @serial_port as this VIA's connection to the serial bus.
|
|
|
|
void set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serial_port) {
|
|
|
|
serial_port_ = serial_port;
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Sets @tape as the tape player connected to this VIA.
|
2017-08-16 20:05:30 +00:00
|
|
|
void set_tape(std::shared_ptr<Storage::Tape::BinaryTapePlayer> tape) {
|
|
|
|
tape_ = tape;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t port_a_;
|
|
|
|
std::weak_ptr<::Commodore::Serial::Port> serial_port_;
|
|
|
|
std::shared_ptr<Storage::Tape::BinaryTapePlayer> tape_;
|
|
|
|
};
|
2016-06-11 18:00:12 +00:00
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/*!
|
|
|
|
Models the keyboard VIA, which is used by the Vic for reading its keyboard, to output to its serial port,
|
|
|
|
and for the small portion of joystick input not connected to the user-port VIA.
|
|
|
|
*/
|
2017-09-04 18:26:04 +00:00
|
|
|
class KeyboardVIA: public MOS::MOS6522::IRQDelegatePortHandler {
|
2017-08-16 20:05:30 +00:00
|
|
|
public:
|
|
|
|
KeyboardVIA() : port_b_(0xff) {
|
|
|
|
clear_all_keys();
|
|
|
|
}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Sets whether @c key @c is_pressed.
|
|
|
|
void set_key_state(uint16_t key, bool is_pressed) {
|
2017-10-20 02:02:34 +00:00
|
|
|
if(is_pressed)
|
|
|
|
columns_[key & 7] &= ~(key >> 3);
|
|
|
|
else
|
|
|
|
columns_[key & 7] |= (key >> 3);
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Sets all keys as unpressed.
|
2017-08-16 20:05:30 +00:00
|
|
|
void clear_all_keys() {
|
|
|
|
memset(columns_, 0xff, sizeof(columns_));
|
|
|
|
}
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Called by the 6522 to get input. Reads the keyboard on Port A, returns a small amount of joystick state on Port B.
|
2017-09-04 18:26:04 +00:00
|
|
|
uint8_t get_port_input(MOS::MOS6522::Port port) {
|
2017-08-16 20:05:30 +00:00
|
|
|
if(!port) {
|
|
|
|
uint8_t result = 0xff;
|
|
|
|
for(int c = 0; c < 8; c++) {
|
|
|
|
if(!(activation_mask_&(1 << c)))
|
|
|
|
result &= columns_[c];
|
2017-05-08 00:32:48 +00:00
|
|
|
}
|
2017-08-16 20:05:30 +00:00
|
|
|
return result;
|
|
|
|
}
|
2017-05-08 00:32:48 +00:00
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
return port_b_;
|
|
|
|
}
|
2017-05-08 02:22:59 +00:00
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Called by the 6522 to set output. The value of Port B selects which part of the keyboard to read.
|
2017-09-04 18:26:04 +00:00
|
|
|
void set_port_output(MOS::MOS6522::Port port, uint8_t value, uint8_t mask) {
|
2017-08-16 20:23:33 +00:00
|
|
|
if(port) activation_mask_ = (value & mask) | (~mask);
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
2017-05-08 02:22:59 +00:00
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Called by the 6522 to set control line output. Which affects the serial port.
|
2017-09-04 18:26:04 +00:00
|
|
|
void set_control_line_output(MOS::MOS6522::Port port, MOS::MOS6522::Line line, bool value) {
|
|
|
|
if(line == MOS::MOS6522::Line::Two) {
|
2017-08-16 20:05:30 +00:00
|
|
|
std::shared_ptr<::Commodore::Serial::Port> serialPort = serial_port_.lock();
|
|
|
|
if(serialPort) {
|
|
|
|
// CB2 is inverted to become serial data; CA2 is inverted to become serial clock
|
2017-09-04 18:26:04 +00:00
|
|
|
if(port == MOS::MOS6522::Port::A)
|
2017-08-16 20:05:30 +00:00
|
|
|
serialPort->set_output(::Commodore::Serial::Line::Clock, (::Commodore::Serial::LineLevel)!value);
|
|
|
|
else
|
|
|
|
serialPort->set_output(::Commodore::Serial::Line::Data, (::Commodore::Serial::LineLevel)!value);
|
2017-05-08 02:22:59 +00:00
|
|
|
}
|
2016-07-01 23:01:22 +00:00
|
|
|
}
|
2016-06-07 23:15:18 +00:00
|
|
|
}
|
2017-08-16 20:05:30 +00:00
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Sets whether the joystick input @c input is pressed.
|
2017-08-16 20:05:30 +00:00
|
|
|
void set_joystick_state(JoystickInput input, bool value) {
|
|
|
|
if(input == JoystickInput::Right) {
|
|
|
|
port_b_ = (port_b_ & ~input) | (value ? 0 : input);
|
|
|
|
}
|
2016-06-07 23:15:18 +00:00
|
|
|
}
|
2016-06-05 15:44:29 +00:00
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Sets the serial port to which this VIA is connected.
|
2017-08-16 20:05:30 +00:00
|
|
|
void set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serialPort) {
|
|
|
|
serial_port_ = serialPort;
|
2016-11-05 19:28:03 +00:00
|
|
|
}
|
2016-09-11 21:34:02 +00:00
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
private:
|
|
|
|
uint8_t port_b_;
|
|
|
|
uint8_t columns_[8];
|
|
|
|
uint8_t activation_mask_;
|
|
|
|
std::weak_ptr<::Commodore::Serial::Port> serial_port_;
|
|
|
|
};
|
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/*!
|
|
|
|
Models the Vic's serial port, providing the receipticle for input.
|
|
|
|
*/
|
2017-08-16 20:05:30 +00:00
|
|
|
class SerialPort : public ::Commodore::Serial::Port {
|
|
|
|
public:
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Receives an input change from the base serial port class, and communicates it to the user-port VIA.
|
2017-08-16 20:05:30 +00:00
|
|
|
void set_input(::Commodore::Serial::Line line, ::Commodore::Serial::LineLevel level) {
|
|
|
|
std::shared_ptr<UserPortVIA> userPortVIA = user_port_via_.lock();
|
2018-09-12 00:37:15 +00:00
|
|
|
if(userPortVIA) userPortVIA->set_serial_line_state(line, static_cast<bool>(level));
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
2016-06-05 13:06:59 +00:00
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Sets the user-port VIA with which this serial port communicates.
|
2017-08-16 20:05:30 +00:00
|
|
|
void set_user_port_via(std::shared_ptr<UserPortVIA> userPortVIA) {
|
|
|
|
user_port_via_ = userPortVIA;
|
|
|
|
}
|
2017-08-16 15:56:52 +00:00
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
private:
|
|
|
|
std::weak_ptr<UserPortVIA> user_port_via_;
|
|
|
|
};
|
2016-06-10 02:37:59 +00:00
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
/*!
|
|
|
|
Provides the bus over which the Vic 6560 fetches memory in a Vic-20.
|
|
|
|
*/
|
2018-04-12 02:00:42 +00:00
|
|
|
class Vic6560BusHandler {
|
2017-08-16 20:05:30 +00:00
|
|
|
public:
|
2017-08-16 20:23:33 +00:00
|
|
|
/// Performs a read on behalf of the 6560; in practice uses @c video_memory_map and @c colour_memory to find data.
|
2018-04-12 02:00:42 +00:00
|
|
|
forceinline void perform_read(uint16_t address, uint8_t *pixel_data, uint8_t *colour_data) {
|
2017-08-16 20:05:30 +00:00
|
|
|
*pixel_data = video_memory_map[address >> 10] ? video_memory_map[address >> 10][address & 0x3ff] : 0xff; // TODO
|
|
|
|
*colour_data = colour_memory[address & 0x03ff];
|
|
|
|
}
|
2016-06-10 02:37:59 +00:00
|
|
|
|
2017-08-16 20:23:33 +00:00
|
|
|
// It is assumed that these pointers have been filled in by the machine.
|
|
|
|
uint8_t *video_memory_map[16]; // Segments video memory into 1kb portions.
|
|
|
|
uint8_t *colour_memory; // Colour memory must be contiguous.
|
2017-08-16 20:05:30 +00:00
|
|
|
};
|
|
|
|
|
2017-10-15 02:36:31 +00:00
|
|
|
/*!
|
|
|
|
Interfaces a joystick to the two VIAs.
|
|
|
|
*/
|
2018-06-12 01:35:03 +00:00
|
|
|
class Joystick: public Inputs::ConcreteJoystick {
|
2017-10-15 02:36:31 +00:00
|
|
|
public:
|
|
|
|
Joystick(UserPortVIA &user_port_via_port_handler, KeyboardVIA &keyboard_via_port_handler) :
|
2018-06-12 01:35:03 +00:00
|
|
|
ConcreteJoystick({
|
2018-06-11 00:45:52 +00:00
|
|
|
Input(Input::Up),
|
|
|
|
Input(Input::Down),
|
|
|
|
Input(Input::Left),
|
|
|
|
Input(Input::Right),
|
|
|
|
Input(Input::Fire)
|
2018-06-12 01:35:03 +00:00
|
|
|
}),
|
|
|
|
user_port_via_port_handler_(user_port_via_port_handler),
|
|
|
|
keyboard_via_port_handler_(keyboard_via_port_handler) {}
|
2018-02-26 00:08:50 +00:00
|
|
|
|
2018-06-12 01:35:03 +00:00
|
|
|
void did_set_input(const Input &digital_input, bool is_active) override {
|
2017-10-15 02:36:31 +00:00
|
|
|
JoystickInput mapped_input;
|
2018-02-26 00:08:50 +00:00
|
|
|
switch(digital_input.type) {
|
2017-10-15 02:36:31 +00:00
|
|
|
default: return;
|
2018-06-11 00:45:52 +00:00
|
|
|
case Input::Up: mapped_input = Up; break;
|
|
|
|
case Input::Down: mapped_input = Down; break;
|
|
|
|
case Input::Left: mapped_input = Left; break;
|
|
|
|
case Input::Right: mapped_input = Right; break;
|
|
|
|
case Input::Fire: mapped_input = Fire; break;
|
2017-10-15 02:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
user_port_via_port_handler_.set_joystick_state(mapped_input, is_active);
|
|
|
|
keyboard_via_port_handler_.set_joystick_state(mapped_input, is_active);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
UserPortVIA &user_port_via_port_handler_;
|
|
|
|
KeyboardVIA &keyboard_via_port_handler_;
|
|
|
|
};
|
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
class ConcreteMachine:
|
2018-03-09 20:19:02 +00:00
|
|
|
public CRTMachine::Machine,
|
2018-07-11 01:32:28 +00:00
|
|
|
public MediaTarget::Machine,
|
2018-10-25 01:59:30 +00:00
|
|
|
public KeyboardMachine::MappedMachine,
|
2018-03-09 20:19:02 +00:00
|
|
|
public JoystickMachine::Machine,
|
|
|
|
public Configurable::Device,
|
2017-08-16 20:05:30 +00:00
|
|
|
public CPU::MOS6502::BusHandler,
|
2017-09-04 18:26:04 +00:00
|
|
|
public MOS::MOS6522::IRQDelegatePortHandler::Delegate,
|
2017-08-16 20:05:30 +00:00
|
|
|
public Utility::TypeRecipient,
|
|
|
|
public Storage::Tape::BinaryTapePlayer::Delegate,
|
2018-03-28 01:52:52 +00:00
|
|
|
public Machine,
|
2018-05-28 03:17:06 +00:00
|
|
|
public ClockingHint::Observer,
|
2018-05-12 02:24:33 +00:00
|
|
|
public Activity::Source {
|
2017-08-16 20:05:30 +00:00
|
|
|
public:
|
2018-07-11 00:00:46 +00:00
|
|
|
ConcreteMachine(const Analyser::Static::Commodore::Target &target, const ROMMachine::ROMFetcher &rom_fetcher) :
|
2018-08-14 02:17:22 +00:00
|
|
|
m6502_(*this),
|
2018-11-23 03:43:42 +00:00
|
|
|
mos6560_(mos6560_bus_handler_),
|
2017-09-04 18:26:04 +00:00
|
|
|
user_port_via_port_handler_(new UserPortVIA),
|
|
|
|
keyboard_via_port_handler_(new KeyboardVIA),
|
2017-08-16 20:05:30 +00:00
|
|
|
serial_port_(new SerialPort),
|
2017-09-04 18:26:04 +00:00
|
|
|
serial_bus_(new ::Commodore::Serial::Bus),
|
|
|
|
user_port_via_(*user_port_via_port_handler_),
|
2017-11-11 03:47:10 +00:00
|
|
|
keyboard_via_(*keyboard_via_port_handler_),
|
|
|
|
tape_(new Storage::Tape::BinaryTapePlayer(1022727)) {
|
2017-08-16 20:05:30 +00:00
|
|
|
// communicate the tape to the user-port VIA
|
2017-09-04 18:26:04 +00:00
|
|
|
user_port_via_port_handler_->set_tape(tape_);
|
2017-08-16 20:05:30 +00:00
|
|
|
|
|
|
|
// wire up the serial bus and serial port
|
|
|
|
Commodore::Serial::AttachPortAndBus(serial_port_, serial_bus_);
|
|
|
|
|
|
|
|
// wire up 6522s and serial port
|
2017-09-04 18:26:04 +00:00
|
|
|
user_port_via_port_handler_->set_serial_port(serial_port_);
|
|
|
|
keyboard_via_port_handler_->set_serial_port(serial_port_);
|
|
|
|
serial_port_->set_user_port_via(user_port_via_port_handler_);
|
2017-08-16 20:05:30 +00:00
|
|
|
|
|
|
|
// wire up the 6522s, tape and machine
|
2017-09-04 18:26:04 +00:00
|
|
|
user_port_via_port_handler_->set_interrupt_delegate(this);
|
|
|
|
keyboard_via_port_handler_->set_interrupt_delegate(this);
|
2017-08-16 20:05:30 +00:00
|
|
|
tape_->set_delegate(this);
|
2018-05-28 03:17:06 +00:00
|
|
|
tape_->set_clocking_hint_observer(this);
|
2017-08-16 20:05:30 +00:00
|
|
|
|
2017-10-15 02:36:31 +00:00
|
|
|
// install a joystick
|
2017-10-16 00:49:47 +00:00
|
|
|
joysticks_.emplace_back(new Joystick(*user_port_via_port_handler_, *keyboard_via_port_handler_));
|
2016-06-05 15:20:05 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
std::vector<std::string> rom_names = { "basic.bin" };
|
|
|
|
switch(target.region) {
|
|
|
|
default:
|
|
|
|
rom_names.push_back("characters-english.bin");
|
|
|
|
rom_names.push_back("kernel-pal.bin");
|
|
|
|
break;
|
|
|
|
case Analyser::Static::Commodore::Target::Region::American:
|
|
|
|
rom_names.push_back("characters-english.bin");
|
|
|
|
rom_names.push_back("kernel-ntsc.bin");
|
|
|
|
break;
|
|
|
|
case Analyser::Static::Commodore::Target::Region::Danish:
|
|
|
|
rom_names.push_back("characters-danish.bin");
|
|
|
|
rom_names.push_back("kernel-danish.bin");
|
|
|
|
break;
|
|
|
|
case Analyser::Static::Commodore::Target::Region::Japanese:
|
|
|
|
rom_names.push_back("characters-japanese.bin");
|
|
|
|
rom_names.push_back("kernel-japanese.bin");
|
|
|
|
break;
|
|
|
|
case Analyser::Static::Commodore::Target::Region::Swedish:
|
|
|
|
rom_names.push_back("characters-swedish.bin");
|
|
|
|
rom_names.push_back("kernel-japanese.bin");
|
|
|
|
break;
|
2016-08-19 17:35:34 +00:00
|
|
|
}
|
2017-11-25 03:22:32 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
const auto roms = rom_fetcher("Vic20", rom_names);
|
2017-11-25 03:22:32 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
for(const auto &rom: roms) {
|
|
|
|
if(!rom) {
|
|
|
|
throw ROMMachine::Error::MissingROMs;
|
|
|
|
}
|
|
|
|
}
|
2016-08-14 17:33:20 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
basic_rom_ = std::move(*roms[0]);
|
|
|
|
character_rom_ = std::move(*roms[1]);
|
|
|
|
kernel_rom_ = std::move(*roms[2]);
|
2018-03-09 21:07:29 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
// Characters ROMs should be 4kb.
|
|
|
|
character_rom_.resize(4096);
|
|
|
|
// Kernel ROMs and the BASIC ROM should be 8kb.
|
|
|
|
kernel_rom_.resize(8192);
|
2017-08-17 14:48:29 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
if(target.has_c1540) {
|
2017-08-16 20:05:30 +00:00
|
|
|
// construct the 1540
|
2018-07-11 00:00:46 +00:00
|
|
|
c1540_.reset(new ::Commodore::C1540::Machine(Commodore::C1540::Personality::C1540, rom_fetcher));
|
2016-06-05 14:51:07 +00:00
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
// attach it to the serial bus
|
|
|
|
c1540_->set_serial_bus(serial_bus_);
|
2016-07-05 00:34:11 +00:00
|
|
|
|
2018-03-27 01:06:07 +00:00
|
|
|
// give it a little warm up
|
|
|
|
c1540_->run_for(Cycles(2000000));
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
2016-09-08 02:17:19 +00:00
|
|
|
|
2017-11-08 02:19:51 +00:00
|
|
|
// Determine PAL/NTSC
|
2018-07-11 00:00:46 +00:00
|
|
|
if(target.region == Analyser::Static::Commodore::Target::Region::American || target.region == Analyser::Static::Commodore::Target::Region::Japanese) {
|
2017-11-08 02:19:51 +00:00
|
|
|
// NTSC
|
2018-07-11 00:00:46 +00:00
|
|
|
set_clock_rate(1022727);
|
2018-11-23 03:43:42 +00:00
|
|
|
mos6560_.set_output_mode(MOS::MOS6560::OutputMode::NTSC);
|
2017-11-08 02:19:51 +00:00
|
|
|
} else {
|
|
|
|
// PAL
|
2018-07-11 00:00:46 +00:00
|
|
|
set_clock_rate(1108404);
|
2018-11-23 03:43:42 +00:00
|
|
|
mos6560_.set_output_mode(MOS::MOS6560::OutputMode::PAL);
|
2017-11-08 02:19:51 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 03:43:42 +00:00
|
|
|
mos6560_.set_high_frequency_cutoff(1600); // There is a 1.6Khz low-pass filter in the Vic-20.
|
|
|
|
mos6560_.set_clock_rate(get_clock_rate());
|
|
|
|
|
2018-03-31 22:54:40 +00:00
|
|
|
// Initialise the memory maps as all pointing to nothing
|
2017-08-16 20:05:30 +00:00
|
|
|
memset(processor_read_memory_map_, 0, sizeof(processor_read_memory_map_));
|
|
|
|
memset(processor_write_memory_map_, 0, sizeof(processor_write_memory_map_));
|
2018-04-12 02:00:42 +00:00
|
|
|
memset(mos6560_bus_handler_.video_memory_map, 0, sizeof(mos6560_bus_handler_.video_memory_map));
|
2017-08-16 20:05:30 +00:00
|
|
|
|
2018-03-31 22:54:40 +00:00
|
|
|
#define set_ram(baseaddr, length) \
|
|
|
|
write_to_map(processor_read_memory_map_, &ram_[baseaddr], baseaddr, length); \
|
|
|
|
write_to_map(processor_write_memory_map_, &ram_[baseaddr], baseaddr, length);
|
|
|
|
|
|
|
|
// Add 6502-visible RAM as requested
|
2018-07-11 00:00:46 +00:00
|
|
|
switch(target.memory_model) {
|
2018-03-31 22:54:40 +00:00
|
|
|
case Analyser::Static::Commodore::Target::MemoryModel::Unexpanded:
|
|
|
|
// The default Vic-20 memory map has 1kb at address 0 and another 4kb at address 0x1000.
|
|
|
|
set_ram(0x0000, 0x0400);
|
|
|
|
set_ram(0x1000, 0x1000);
|
|
|
|
break;
|
2018-03-26 23:01:57 +00:00
|
|
|
case Analyser::Static::Commodore::Target::MemoryModel::EightKB:
|
2018-03-31 22:54:40 +00:00
|
|
|
// An 8kb Vic-20 fills in the gap between the two blocks of RAM on an unexpanded machine.
|
|
|
|
set_ram(0x0000, 0x2000);
|
2017-08-16 20:05:30 +00:00
|
|
|
break;
|
2018-03-26 23:01:57 +00:00
|
|
|
case Analyser::Static::Commodore::Target::MemoryModel::ThirtyTwoKB:
|
2018-03-31 22:54:40 +00:00
|
|
|
// A 32kb Vic-20 fills the entire lower 32kb with RAM.
|
|
|
|
set_ram(0x0000, 0x8000);
|
2017-08-16 20:05:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2018-03-31 22:54:40 +00:00
|
|
|
#undef set_ram
|
2017-11-08 03:54:22 +00:00
|
|
|
|
2018-03-31 22:54:40 +00:00
|
|
|
// all expansions also have colour RAM visible at 0x9400.
|
|
|
|
write_to_map(processor_read_memory_map_, colour_ram_, 0x9400, sizeof(colour_ram_));
|
|
|
|
write_to_map(processor_write_memory_map_, colour_ram_, 0x9400, sizeof(colour_ram_));
|
2017-08-16 20:05:30 +00:00
|
|
|
|
2018-03-31 22:54:40 +00:00
|
|
|
// also push memory resources into the 6560 video memory map; the 6560 has only a
|
|
|
|
// 14-bit address bus and the top bit is invested and used as bit 15 for the main
|
2018-04-12 01:35:23 +00:00
|
|
|
// memory bus. It can access only internal memory, so the first 1kb, then the 4kb from 0x1000.
|
2018-04-12 02:06:50 +00:00
|
|
|
struct Range {
|
2018-04-12 01:35:23 +00:00
|
|
|
const std::size_t start, end;
|
2018-04-12 02:06:50 +00:00
|
|
|
Range(std::size_t start, std::size_t end) : start(start), end(end) {}
|
2018-04-12 01:35:23 +00:00
|
|
|
};
|
2018-04-12 02:06:50 +00:00
|
|
|
const std::array<Range, 2> video_ranges = {{
|
|
|
|
Range(0x0000, 0x0400),
|
|
|
|
Range(0x1000, 0x2000),
|
2018-04-12 01:35:23 +00:00
|
|
|
}};
|
2018-05-01 02:23:57 +00:00
|
|
|
for(const auto &video_range : video_ranges) {
|
2018-04-12 01:35:23 +00:00
|
|
|
for(auto addr = video_range.start; addr < video_range.end; addr += 0x400) {
|
|
|
|
auto destination_address = (addr & 0x1fff) | (((addr & 0x8000) >> 2) ^ 0x2000);
|
|
|
|
if(processor_read_memory_map_[addr >> 10]) {
|
2018-04-12 02:00:42 +00:00
|
|
|
write_to_map(mos6560_bus_handler_.video_memory_map, &ram_[addr], static_cast<uint16_t>(destination_address), 0x400);
|
2018-04-12 01:35:23 +00:00
|
|
|
}
|
2018-03-31 22:54:40 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-12 02:00:42 +00:00
|
|
|
mos6560_bus_handler_.colour_memory = colour_ram_;
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2018-03-31 22:54:40 +00:00
|
|
|
// install the BASIC ROM
|
2017-11-11 03:59:11 +00:00
|
|
|
write_to_map(processor_read_memory_map_, basic_rom_.data(), 0xc000, static_cast<uint16_t>(basic_rom_.size()));
|
2017-11-08 02:19:51 +00:00
|
|
|
|
2018-03-31 22:54:40 +00:00
|
|
|
// install the system ROM
|
2018-07-11 00:00:46 +00:00
|
|
|
write_to_map(processor_read_memory_map_, character_rom_.data(), 0x8000, static_cast<uint16_t>(character_rom_.size()));
|
|
|
|
write_to_map(mos6560_bus_handler_.video_memory_map, character_rom_.data(), 0x0000, static_cast<uint16_t>(character_rom_.size()));
|
|
|
|
write_to_map(processor_read_memory_map_, kernel_rom_.data(), 0xe000, static_cast<uint16_t>(kernel_rom_.size()));
|
|
|
|
|
|
|
|
insert_media(target.media);
|
|
|
|
if(!target.loading_command.empty()) {
|
|
|
|
type_string(target.loading_command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool insert_media(const Analyser::Static::Media &media) override final {
|
|
|
|
if(!media.tapes.empty()) {
|
|
|
|
tape_->set_tape(media.tapes.front());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!media.disks.empty() && c1540_) {
|
|
|
|
c1540_->set_disk(media.disks.front());
|
2017-11-08 02:19:51 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
if(!media.cartridges.empty()) {
|
|
|
|
rom_address_ = 0xa000;
|
|
|
|
std::vector<uint8_t> rom_image = media.cartridges.front()->get_segments().front().data;
|
|
|
|
rom_length_ = static_cast<uint16_t>(rom_image.size());
|
2017-11-08 02:19:51 +00:00
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
rom_ = rom_image;
|
|
|
|
rom_.resize(0x2000);
|
2018-03-28 01:52:52 +00:00
|
|
|
write_to_map(processor_read_memory_map_, rom_.data(), rom_address_, rom_length_);
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
2018-07-11 00:00:46 +00:00
|
|
|
|
|
|
|
set_use_fast_tape();
|
|
|
|
|
|
|
|
return !media.tapes.empty() || (!media.disks.empty() && c1540_ != nullptr) || !media.cartridges.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_key_state(uint16_t key, bool is_pressed) override final {
|
|
|
|
if(key != KeyRestore)
|
|
|
|
keyboard_via_port_handler_->set_key_state(key, is_pressed);
|
|
|
|
else
|
|
|
|
user_port_via_.set_control_line_input(MOS::MOS6522::Port::A, MOS::MOS6522::Line::One, !is_pressed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_all_keys() override final {
|
|
|
|
keyboard_via_port_handler_->clear_all_keys();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<Inputs::Joystick>> &get_joysticks() override {
|
|
|
|
return joysticks_;
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
// to satisfy CPU::MOS6502::Processor
|
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 20:05:30 +00:00
|
|
|
// run the phase-1 part of this cycle, in which the VIC accesses memory
|
2018-03-28 01:52:52 +00:00
|
|
|
cycles_since_mos6560_update_++;
|
2017-08-16 20:05:30 +00:00
|
|
|
|
|
|
|
// run the phase-2 part of the cycle, which is whatever the 6502 said it should be
|
|
|
|
if(isReadOperation(operation)) {
|
|
|
|
uint8_t result = processor_read_memory_map_[address >> 10] ? processor_read_memory_map_[address >> 10][address & 0x3ff] : 0xff;
|
|
|
|
if((address&0xfc00) == 0x9000) {
|
2018-04-08 22:51:37 +00:00
|
|
|
if(!(address&0x100)) {
|
2018-03-30 00:49:36 +00:00
|
|
|
update_video();
|
2018-11-23 03:43:42 +00:00
|
|
|
result &= mos6560_.get_register(address);
|
2018-03-30 00:49:36 +00:00
|
|
|
}
|
2018-04-08 22:51:37 +00:00
|
|
|
if(address & 0x10) result &= user_port_via_.get_register(address);
|
|
|
|
if(address & 0x20) result &= keyboard_via_.get_register(address);
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
|
|
|
*value = result;
|
|
|
|
|
2018-03-28 01:52:52 +00:00
|
|
|
// Consider applying the fast tape hack.
|
2018-02-19 21:57:24 +00:00
|
|
|
if(use_fast_tape_hack_ && operation == CPU::MOS6502::BusOperation::ReadOpcode) {
|
2017-08-16 20:05:30 +00:00
|
|
|
if(address == 0xf7b2) {
|
|
|
|
// Address 0xf7b2 contains a JSR to 0xf8c0 that will fill the tape buffer with the next header.
|
|
|
|
// So cancel that via a double NOP and fill in the next header programmatically.
|
|
|
|
Storage::Tape::Commodore::Parser parser;
|
|
|
|
std::unique_ptr<Storage::Tape::Commodore::Header> header = parser.get_next_header(tape_->get_tape());
|
|
|
|
|
2018-03-31 01:22:52 +00:00
|
|
|
const uint64_t tape_position = tape_->get_tape()->get_offset();
|
2017-08-16 20:05:30 +00:00
|
|
|
if(header) {
|
2018-03-31 01:22:52 +00:00
|
|
|
// serialise to wherever b2:b3 points
|
2018-03-31 22:54:40 +00:00
|
|
|
const uint16_t tape_buffer_pointer = static_cast<uint16_t>(ram_[0xb2]) | static_cast<uint16_t>(ram_[0xb3] << 8);
|
|
|
|
header->serialise(&ram_[tape_buffer_pointer], 0x8000 - tape_buffer_pointer);
|
2018-03-31 01:22:52 +00:00
|
|
|
hold_tape_ = true;
|
|
|
|
printf("Found header\n");
|
2017-08-16 20:05:30 +00:00
|
|
|
} else {
|
2018-03-31 01:22:52 +00:00
|
|
|
// no header found, so pretend this hack never interceded
|
|
|
|
tape_->get_tape()->set_offset(tape_position);
|
|
|
|
hold_tape_ = false;
|
|
|
|
printf("Didn't find header\n");
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// clear status and the verify flag
|
2018-03-31 22:54:40 +00:00
|
|
|
ram_[0x90] = 0;
|
|
|
|
ram_[0x93] = 0;
|
2017-08-16 20:05:30 +00:00
|
|
|
|
2018-03-31 01:22:52 +00:00
|
|
|
*value = 0x0c; // i.e. NOP abs, to swallow the entire JSR
|
2017-08-16 20:05:30 +00:00
|
|
|
} else if(address == 0xf90b) {
|
2017-10-22 01:50:53 +00:00
|
|
|
uint8_t x = static_cast<uint8_t>(m6502_.get_value_of_register(CPU::MOS6502::Register::X));
|
2017-08-16 20:05:30 +00:00
|
|
|
if(x == 0xe) {
|
|
|
|
Storage::Tape::Commodore::Parser parser;
|
2018-03-25 17:37:33 +00:00
|
|
|
const uint64_t tape_position = tape_->get_tape()->get_offset();
|
2018-03-31 01:22:52 +00:00
|
|
|
const std::unique_ptr<Storage::Tape::Commodore::Data> data = parser.get_next_data(tape_->get_tape());
|
2018-03-25 17:37:33 +00:00
|
|
|
if(data) {
|
|
|
|
uint16_t start_address, end_address;
|
2018-03-31 22:54:40 +00:00
|
|
|
start_address = static_cast<uint16_t>(ram_[0xc1] | (ram_[0xc2] << 8));
|
|
|
|
end_address = static_cast<uint16_t>(ram_[0xae] | (ram_[0xaf] << 8));
|
2018-03-25 17:37:33 +00:00
|
|
|
|
|
|
|
// perform a via-processor_write_memory_map_ memcpy
|
|
|
|
uint8_t *data_ptr = data->data.data();
|
|
|
|
std::size_t data_left = data->data.size();
|
|
|
|
while(data_left && start_address != end_address) {
|
|
|
|
uint8_t *page = processor_write_memory_map_[start_address >> 10];
|
|
|
|
if(page) page[start_address & 0x3ff] = *data_ptr;
|
|
|
|
data_ptr++;
|
|
|
|
start_address++;
|
|
|
|
data_left--;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set tape status, carry and flag
|
2018-03-31 22:54:40 +00:00
|
|
|
ram_[0x90] |= 0x40;
|
2018-03-25 17:37:33 +00:00
|
|
|
uint8_t flags = static_cast<uint8_t>(m6502_.get_value_of_register(CPU::MOS6502::Register::Flags));
|
|
|
|
flags &= ~static_cast<uint8_t>((CPU::MOS6502::Flag::Carry | CPU::MOS6502::Flag::Interrupt));
|
|
|
|
m6502_.set_value_of_register(CPU::MOS6502::Register::Flags, flags);
|
|
|
|
|
|
|
|
// to ensure that execution proceeds to 0xfccf, pretend a NOP was here and
|
|
|
|
// ensure that the PC leaps to 0xfccf
|
|
|
|
m6502_.set_value_of_register(CPU::MOS6502::Register::ProgramCounter, 0xfccf);
|
|
|
|
*value = 0xea; // i.e. NOP implied
|
2018-03-31 01:22:52 +00:00
|
|
|
hold_tape_ = true;
|
|
|
|
printf("Found data\n");
|
2018-03-25 17:37:33 +00:00
|
|
|
} else {
|
|
|
|
tape_->get_tape()->set_offset(tape_position);
|
2018-03-31 01:22:52 +00:00
|
|
|
hold_tape_ = false;
|
|
|
|
printf("Didn't find data\n");
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uint8_t *ram = processor_write_memory_map_[address >> 10];
|
2018-03-30 00:49:36 +00:00
|
|
|
if(ram) {
|
|
|
|
update_video();
|
|
|
|
ram[address & 0x3ff] = *value;
|
|
|
|
}
|
2018-04-08 22:51:37 +00:00
|
|
|
// Anything between 0x9000 and 0x9400 is the IO area.
|
2017-08-16 20:05:30 +00:00
|
|
|
if((address&0xfc00) == 0x9000) {
|
2018-04-08 22:51:37 +00:00
|
|
|
// The VIC is selected by bit 8 = 0
|
|
|
|
if(!(address&0x100)) {
|
2018-03-30 00:49:36 +00:00
|
|
|
update_video();
|
2018-11-23 03:43:42 +00:00
|
|
|
mos6560_.set_register(address, *value);
|
2018-03-30 00:49:36 +00:00
|
|
|
}
|
2018-04-08 22:51:37 +00:00
|
|
|
// The first VIA is selected by bit 4 = 1.
|
|
|
|
if(address & 0x10) user_port_via_.set_register(address, *value);
|
|
|
|
// The second VIA is selected by bit 5 = 1.
|
|
|
|
if(address & 0x20) keyboard_via_.set_register(address, *value);
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2017-09-04 18:26:04 +00:00
|
|
|
user_port_via_.run_for(Cycles(1));
|
|
|
|
keyboard_via_.run_for(Cycles(1));
|
2018-05-13 17:57:19 +00:00
|
|
|
if(typer_ && address == 0xeb1e && operation == CPU::MOS6502::BusOperation::ReadOpcode) {
|
2017-08-16 20:05:30 +00:00
|
|
|
if(!typer_->type_next_character()) {
|
|
|
|
clear_all_keys();
|
|
|
|
typer_.reset();
|
|
|
|
}
|
|
|
|
}
|
2018-03-31 01:22:52 +00:00
|
|
|
if(!tape_is_sleeping_ && !hold_tape_) tape_->run_for(Cycles(1));
|
2017-08-16 20:05:30 +00:00
|
|
|
if(c1540_) c1540_->run_for(Cycles(1));
|
2017-05-07 02:00:12 +00:00
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
return Cycles(1);
|
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2018-03-28 01:52:52 +00:00
|
|
|
void flush() {
|
2018-03-30 00:49:36 +00:00
|
|
|
update_video();
|
2018-11-23 03:43:42 +00:00
|
|
|
mos6560_.flush();
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2017-08-22 01:56:42 +00:00
|
|
|
void run_for(const Cycles cycles) override final {
|
2017-08-16 20:05:30 +00:00
|
|
|
m6502_.run_for(cycles);
|
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2018-11-15 02:52:57 +00:00
|
|
|
void set_scan_target(Outputs::Display::ScanTarget *scan_target) override final {
|
2018-11-23 03:43:42 +00:00
|
|
|
mos6560_.set_scan_target(scan_target);
|
2016-10-21 01:05:32 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 04:44:21 +00:00
|
|
|
void set_display_type(Outputs::Display::DisplayType display_type) override final {
|
|
|
|
mos6560_.set_display_type(display_type);
|
|
|
|
}
|
|
|
|
|
2017-12-18 02:26:06 +00:00
|
|
|
Outputs::Speaker::Speaker *get_speaker() override final {
|
2018-11-23 03:43:42 +00:00
|
|
|
return mos6560_.get_speaker();
|
2016-10-21 01:05:32 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 01:56:42 +00:00
|
|
|
void mos6522_did_change_interrupt_status(void *mos6522) override final {
|
2017-09-04 18:26:04 +00:00
|
|
|
m6502_.set_nmi_line(user_port_via_.get_interrupt_line());
|
|
|
|
m6502_.set_irq_line(keyboard_via_.get_interrupt_line());
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2017-12-29 20:26:03 +00:00
|
|
|
void type_string(const std::string &string) override final {
|
2017-08-16 20:05:30 +00:00
|
|
|
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper());
|
2017-12-29 20:26:03 +00:00
|
|
|
Utility::TypeRecipient::add_typer(string, std::move(mapper));
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2017-08-22 01:56:42 +00:00
|
|
|
void tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape) override final {
|
2017-09-04 18:26:04 +00:00
|
|
|
keyboard_via_.set_control_line_input(MOS::MOS6522::Port::A, MOS::MOS6522::Line::One, !tape->get_input());
|
2017-08-16 20:05:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 21:31:05 +00:00
|
|
|
KeyboardMapper *get_keyboard_mapper() override {
|
|
|
|
return &keyboard_mapper_;
|
2017-10-13 02:25:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 00:48:10 +00:00
|
|
|
// MARK: - Configuration options.
|
|
|
|
std::vector<std::unique_ptr<Configurable::Option>> get_options() override {
|
2017-11-21 02:55:32 +00:00
|
|
|
return Commodore::Vic20::get_options();
|
2017-11-19 00:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_selections(const Configurable::SelectionSet &selections_by_option) override {
|
2017-11-21 02:55:32 +00:00
|
|
|
bool quickload;
|
|
|
|
if(Configurable::get_quick_load_tape(selections_by_option, quickload)) {
|
2018-02-19 21:57:24 +00:00
|
|
|
allow_fast_tape_hack_ = quickload;
|
|
|
|
set_use_fast_tape();
|
2017-11-21 02:55:32 +00:00
|
|
|
}
|
2018-04-01 02:14:34 +00:00
|
|
|
|
|
|
|
Configurable::Display display;
|
|
|
|
if(Configurable::get_display(selections_by_option, display)) {
|
|
|
|
set_video_signal_configurable(display);
|
|
|
|
}
|
2017-11-19 00:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Configurable::SelectionSet get_accurate_selections() override {
|
|
|
|
Configurable::SelectionSet selection_set;
|
2017-11-21 02:55:32 +00:00
|
|
|
Configurable::append_quick_load_tape_selection(selection_set, false);
|
2018-11-29 01:53:33 +00:00
|
|
|
Configurable::append_display_selection(selection_set, Configurable::Display::CompositeColour);
|
2017-11-19 00:48:10 +00:00
|
|
|
return selection_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
Configurable::SelectionSet get_user_friendly_selections() override {
|
|
|
|
Configurable::SelectionSet selection_set;
|
2017-11-21 02:55:32 +00:00
|
|
|
Configurable::append_quick_load_tape_selection(selection_set, true);
|
2018-04-01 02:14:34 +00:00
|
|
|
Configurable::append_display_selection(selection_set, Configurable::Display::SVideo);
|
2017-11-19 00:48:10 +00:00
|
|
|
return selection_set;
|
|
|
|
}
|
|
|
|
|
2018-05-28 03:17:06 +00:00
|
|
|
void set_component_prefers_clocking(ClockingHint::Source *component, ClockingHint::Preference clocking) override {
|
|
|
|
tape_is_sleeping_ = clocking == ClockingHint::Preference::None;
|
2018-03-28 01:52:52 +00:00
|
|
|
set_use_fast_tape();
|
|
|
|
}
|
|
|
|
|
2018-05-12 02:24:33 +00:00
|
|
|
// MARK: - Activity Source
|
|
|
|
void set_activity_observer(Activity::Observer *observer) override {
|
|
|
|
if(c1540_) c1540_->set_activity_observer(observer);
|
|
|
|
}
|
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
private:
|
2018-03-30 00:49:36 +00:00
|
|
|
void update_video() {
|
2018-11-23 03:43:42 +00:00
|
|
|
mos6560_.run_for(cycles_since_mos6560_update_.flush());
|
2018-03-30 00:49:36 +00:00
|
|
|
}
|
2018-08-14 02:17:22 +00:00
|
|
|
CPU::MOS6502::Processor<CPU::MOS6502::Personality::P6502, ConcreteMachine, false> m6502_;
|
2017-08-16 20:05:30 +00:00
|
|
|
|
2017-11-08 02:19:51 +00:00
|
|
|
std::vector<uint8_t> character_rom_;
|
|
|
|
std::vector<uint8_t> basic_rom_;
|
|
|
|
std::vector<uint8_t> kernel_rom_;
|
2017-08-16 20:05:30 +00:00
|
|
|
|
2018-03-28 01:52:52 +00:00
|
|
|
std::vector<uint8_t> rom_;
|
2017-08-16 20:05:30 +00:00
|
|
|
uint16_t rom_address_, rom_length_;
|
2018-03-31 22:54:40 +00:00
|
|
|
uint8_t ram_[0x8000];
|
|
|
|
uint8_t colour_ram_[0x0400];
|
2017-11-08 02:19:51 +00:00
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
uint8_t *processor_read_memory_map_[64];
|
|
|
|
uint8_t *processor_write_memory_map_[64];
|
|
|
|
void write_to_map(uint8_t **map, uint8_t *area, uint16_t address, uint16_t length) {
|
|
|
|
address >>= 10;
|
|
|
|
length >>= 10;
|
|
|
|
while(length--) {
|
|
|
|
map[address] = area;
|
|
|
|
area += 0x400;
|
|
|
|
address++;
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
|
2017-10-13 02:25:02 +00:00
|
|
|
Commodore::Vic20::KeyboardMapper keyboard_mapper_;
|
2017-10-16 00:49:47 +00:00
|
|
|
std::vector<std::unique_ptr<Inputs::Joystick>> joysticks_;
|
2017-08-16 20:05:30 +00:00
|
|
|
|
2018-03-28 01:52:52 +00:00
|
|
|
Cycles cycles_since_mos6560_update_;
|
2018-04-12 02:00:42 +00:00
|
|
|
Vic6560BusHandler mos6560_bus_handler_;
|
2018-11-23 03:43:42 +00:00
|
|
|
MOS::MOS6560::MOS6560<Vic6560BusHandler> mos6560_;
|
2017-09-04 18:26:04 +00:00
|
|
|
std::shared_ptr<UserPortVIA> user_port_via_port_handler_;
|
|
|
|
std::shared_ptr<KeyboardVIA> keyboard_via_port_handler_;
|
2017-08-16 20:05:30 +00:00
|
|
|
std::shared_ptr<SerialPort> serial_port_;
|
|
|
|
std::shared_ptr<::Commodore::Serial::Bus> serial_bus_;
|
|
|
|
|
2017-09-04 18:26:04 +00:00
|
|
|
MOS::MOS6522::MOS6522<UserPortVIA> user_port_via_;
|
|
|
|
MOS::MOS6522::MOS6522<KeyboardVIA> keyboard_via_;
|
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
// Tape
|
|
|
|
std::shared_ptr<Storage::Tape::BinaryTapePlayer> tape_;
|
2018-02-19 21:57:24 +00:00
|
|
|
bool use_fast_tape_hack_ = false;
|
2018-03-31 01:22:52 +00:00
|
|
|
bool hold_tape_ = false;
|
2018-02-19 21:57:24 +00:00
|
|
|
bool allow_fast_tape_hack_ = false;
|
2018-03-28 01:52:52 +00:00
|
|
|
bool tape_is_sleeping_ = true;
|
2018-02-19 21:57:24 +00:00
|
|
|
void set_use_fast_tape() {
|
2018-03-28 01:52:52 +00:00
|
|
|
use_fast_tape_hack_ = !tape_is_sleeping_ && allow_fast_tape_hack_ && tape_->has_tape();
|
2018-02-19 21:57:24 +00:00
|
|
|
}
|
2017-08-16 20:05:30 +00:00
|
|
|
|
|
|
|
// Disk
|
|
|
|
std::shared_ptr<::Commodore::C1540::Machine> c1540_;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2016-10-21 01:05:32 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 20:05:30 +00:00
|
|
|
using namespace Commodore::Vic20;
|
|
|
|
|
2018-07-11 00:00:46 +00:00
|
|
|
Machine *Machine::Vic20(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
|
|
|
|
using Target = Analyser::Static::Commodore::Target;
|
|
|
|
const Target *const commodore_target = dynamic_cast<const Target *>(target);
|
|
|
|
return new Vic20::ConcreteMachine(*commodore_target, rom_fetcher);
|
2016-10-21 01:05:32 +00:00
|
|
|
}
|
2017-08-16 20:05:30 +00:00
|
|
|
|
|
|
|
Machine::~Machine() {}
|