2017-11-25 01:43:26 +00:00
|
|
|
//
|
|
|
|
// MSX.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 24/11/2017.
|
|
|
|
// Copyright © 2017 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "MSX.hpp"
|
|
|
|
|
2017-11-25 02:59:54 +00:00
|
|
|
#include "../../Processors/Z80/Z80.hpp"
|
|
|
|
|
2017-11-25 03:05:50 +00:00
|
|
|
#include "../../Components/1770/1770.hpp"
|
2017-11-26 18:28:26 +00:00
|
|
|
#include "../../Components/9918/9918.hpp"
|
2017-11-25 03:05:50 +00:00
|
|
|
#include "../../Components/8255/i8255.hpp"
|
|
|
|
#include "../../Components/AY38910/AY38910.hpp"
|
|
|
|
|
2017-11-25 18:33:51 +00:00
|
|
|
#include "../CRTMachine.hpp"
|
2017-11-26 18:28:26 +00:00
|
|
|
#include "../ConfigurationTarget.hpp"
|
2017-11-25 18:33:51 +00:00
|
|
|
|
2017-11-25 01:43:26 +00:00
|
|
|
namespace MSX {
|
|
|
|
|
2017-11-26 21:47:59 +00:00
|
|
|
class i8255PortHandler: public Intel::i8255::PortHandler {
|
|
|
|
};
|
|
|
|
|
|
|
|
class AYPortHandler: public GI::AY38910::PortHandler {
|
|
|
|
};
|
|
|
|
|
2017-11-25 01:43:26 +00:00
|
|
|
class ConcreteMachine:
|
2017-11-25 18:33:51 +00:00
|
|
|
public Machine,
|
2017-11-25 02:59:54 +00:00
|
|
|
public CPU::Z80::BusHandler,
|
2017-11-26 18:28:26 +00:00
|
|
|
public CRTMachine::Machine,
|
|
|
|
public ConfigurationTarget::Machine {
|
2017-11-25 02:59:54 +00:00
|
|
|
public:
|
|
|
|
ConcreteMachine():
|
2017-11-26 21:47:59 +00:00
|
|
|
z80_(*this),
|
|
|
|
i8255_(i8255_port_handler_) {
|
|
|
|
ay_.set_port_handler(&ay_port_handler_);
|
2017-11-25 18:33:51 +00:00
|
|
|
set_clock_rate(3579545);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_output(float aspect_ratio) override {
|
2017-11-26 18:28:26 +00:00
|
|
|
vdp_.reset(new TI::TMS9918(TI::TMS9918::TMS9918A));
|
2017-11-25 18:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void close_output() override {
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Outputs::CRT::CRT> get_crt() override {
|
2017-11-26 18:28:26 +00:00
|
|
|
return vdp_->get_crt();
|
2017-11-25 18:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Outputs::Speaker> get_speaker() override {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_for(const Cycles cycles) override {
|
|
|
|
z80_.run_for(cycles);
|
|
|
|
}
|
2017-11-26 18:28:26 +00:00
|
|
|
|
|
|
|
void configure_as_target(const StaticAnalyser::Target &target) override {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool insert_media(const StaticAnalyser::Media &media) override {
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-25 02:59:54 +00:00
|
|
|
|
2017-11-26 21:47:59 +00:00
|
|
|
HalfCycles perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) {
|
|
|
|
uint16_t address = cycle.address ? *cycle.address : 0x0000;
|
|
|
|
switch(cycle.operation) {
|
|
|
|
case CPU::Z80::PartialMachineCycle::ReadOpcode:
|
|
|
|
case CPU::Z80::PartialMachineCycle::Read:
|
|
|
|
*cycle.value = read_pointers_[address >> 14][address & 16383];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CPU::Z80::PartialMachineCycle::Write:
|
|
|
|
write_pointers_[address >> 14][address & 16383] = *cycle.value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CPU::Z80::PartialMachineCycle::Input:
|
|
|
|
switch(address & 0xff) {
|
|
|
|
case 0x98: case 0x99:
|
|
|
|
*cycle.value = vdp_->get_register(address);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xa2:
|
|
|
|
ay_.set_control_lines(static_cast<GI::AY38910::ControlLines>(GI::AY38910::BDIR | GI::AY38910::BC1));
|
|
|
|
ay_.set_data_input(*cycle.value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xa8: case 0xa9:
|
|
|
|
case 0xaa: case 0xab:
|
|
|
|
*cycle.value = i8255_.get_register(address);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CPU::Z80::PartialMachineCycle::Output:
|
|
|
|
switch(address & 0xff) {
|
|
|
|
case 0x98: case 0x99:
|
2017-11-26 23:34:40 +00:00
|
|
|
printf("VDP %d %02x\n", address&1, *cycle.value);
|
2017-11-26 21:47:59 +00:00
|
|
|
vdp_->set_register(address, *cycle.value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xa0:
|
|
|
|
ay_.set_control_lines(static_cast<GI::AY38910::ControlLines>(GI::AY38910::BDIR | GI::AY38910::BC2 | GI::AY38910::BC1));
|
|
|
|
ay_.set_data_input(*cycle.value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xa1:
|
|
|
|
ay_.set_control_lines(static_cast<GI::AY38910::ControlLines>(GI::AY38910::BDIR | GI::AY38910::BC2));
|
|
|
|
ay_.set_data_input(*cycle.value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xa8: case 0xa9:
|
|
|
|
case 0xaa: case 0xab:
|
2017-11-26 23:34:40 +00:00
|
|
|
printf("8255 %d %02x\n", address&3, *cycle.value);
|
2017-11-26 21:47:59 +00:00
|
|
|
i8255_.set_register(address, *cycle.value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Per the best information I currently have, the MSX inserts an extra cycle into each opcode read,
|
|
|
|
// but otherwise runs without pause.
|
|
|
|
return HalfCycles((cycle.operation == CPU::Z80::PartialMachineCycle::ReadOpcode) ? 2 : 0);;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains the system ROMs.
|
|
|
|
bool set_rom_fetcher(const std::function<std::vector<std::unique_ptr<std::vector<uint8_t>>>(const std::string &machine, const std::vector<std::string> &names)> &roms_with_names) override {
|
|
|
|
auto roms = roms_with_names(
|
|
|
|
"MSX",
|
|
|
|
{
|
2017-11-26 23:34:40 +00:00
|
|
|
"basic.rom",
|
|
|
|
"main_msx1.rom"
|
2017-11-26 21:47:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if(!roms[0] || !roms[1]) return false;
|
|
|
|
|
|
|
|
basic_ = std::move(*roms[0]);
|
|
|
|
basic_.resize(16384);
|
|
|
|
|
|
|
|
main_ = std::move(*roms[1]);
|
|
|
|
main_.resize(16384);
|
|
|
|
|
2017-11-26 23:34:40 +00:00
|
|
|
for(size_t c = 0; c < 4; ++c) {
|
|
|
|
write_pointers_[c] = &ram_[c * 16384];
|
|
|
|
read_pointers_[c] = &ram_[c * 16384];
|
|
|
|
}
|
|
|
|
read_pointers_[0] = main_.data();
|
|
|
|
write_pointers_[0] = scratch_;
|
|
|
|
read_pointers_[1] = basic_.data();
|
|
|
|
write_pointers_[1] = scratch_;
|
|
|
|
|
2017-11-26 21:47:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-25 02:59:54 +00:00
|
|
|
private:
|
|
|
|
CPU::Z80::Processor<ConcreteMachine, false, false> z80_;
|
2017-11-26 18:28:26 +00:00
|
|
|
std::unique_ptr<TI::TMS9918> vdp_;
|
2017-11-26 21:47:59 +00:00
|
|
|
Intel::i8255::i8255<i8255PortHandler> i8255_;
|
|
|
|
GI::AY38910::AY38910 ay_;
|
|
|
|
|
|
|
|
i8255PortHandler i8255_port_handler_;
|
|
|
|
AYPortHandler ay_port_handler_;
|
|
|
|
|
|
|
|
uint8_t *read_pointers_[4];
|
|
|
|
uint8_t *write_pointers_[4];
|
|
|
|
uint8_t ram_[65536];
|
2017-11-26 23:34:40 +00:00
|
|
|
uint8_t scratch_[16384];
|
2017-11-26 21:47:59 +00:00
|
|
|
std::vector<uint8_t> basic_, main_;
|
2017-11-25 01:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace MSX;
|
|
|
|
|
|
|
|
Machine *Machine::MSX() {
|
|
|
|
return new ConcreteMachine;
|
|
|
|
}
|
|
|
|
|
|
|
|
Machine::~Machine() {}
|