mirror of
https://github.com/TomHarte/CLK.git
synced 2024-06-28 08:29:34 +00:00
Makes an attempt to rope in the WD1770 for MSX disk ROM emulation.
This commit is contained in:
parent
999a0c22d4
commit
513c067f94
69
Machines/MSX/DiskROM.cpp
Normal file
69
Machines/MSX/DiskROM.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
//
|
||||
// DiskROM.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 07/01/2018.
|
||||
// Copyright © 2018 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "DiskROM.hpp"
|
||||
|
||||
using namespace MSX;
|
||||
|
||||
DiskROM::DiskROM(const std::vector<uint8_t> &rom) :
|
||||
WD1770(P1793),
|
||||
rom_(rom) {
|
||||
set_is_double_density(true);
|
||||
}
|
||||
|
||||
void DiskROM::write(uint16_t address, uint8_t value) {
|
||||
switch(address) {
|
||||
case 0x7ff8: case 0x7ff9: case 0x7ffa: case 0x7ffb:
|
||||
set_register(address, value);
|
||||
break;
|
||||
case 0x7ffc:
|
||||
selected_head_ = value & 1;
|
||||
if(drives_[0]) drives_[0]->set_head(selected_head_);
|
||||
if(drives_[1]) drives_[1]->set_head(selected_head_);
|
||||
break;
|
||||
case 0x7ffd:
|
||||
selected_drive_ = value & 1;
|
||||
set_drive(drives_[selected_drive_]);
|
||||
set_motor_on(!!(value & 0x80));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t DiskROM::read(uint16_t address) {
|
||||
if(address >= 0x7ff8 && address < 0x7ffc) {
|
||||
return get_register(address);
|
||||
}
|
||||
return rom_[address & 0x3fff];
|
||||
}
|
||||
|
||||
void DiskROM::run_for(HalfCycles half_cycles) {
|
||||
// Input clock is going to be 7159090/2 Mhz, but the drive controller
|
||||
// needs an 8Mhz clock, so scale up. 8000000/7159090 simplifies to
|
||||
// 800000/715909.
|
||||
controller_cycles_ += 800000 * half_cycles.as_int();
|
||||
WD::WD1770::run_for(Cycles(static_cast<int>(controller_cycles_ / 715909)));
|
||||
controller_cycles_ %= 715909;
|
||||
}
|
||||
|
||||
void DiskROM::set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int drive) {
|
||||
if(!drives_[drive]) {
|
||||
drives_[drive].reset(new Storage::Disk::Drive(8000000, 300, 2));
|
||||
drives_[drive]->set_head(selected_head_);
|
||||
if(drive == selected_drive_) set_drive(drives_[drive]);
|
||||
}
|
||||
drives_[drive]->set_disk(disk);
|
||||
}
|
||||
|
||||
void DiskROM::set_head_load_request(bool head_load) {
|
||||
// Magic!
|
||||
set_head_loaded(head_load);
|
||||
}
|
||||
|
||||
bool DiskROM::get_drive_is_ready() {
|
||||
return true;
|
||||
}
|
45
Machines/MSX/DiskROM.hpp
Normal file
45
Machines/MSX/DiskROM.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// DiskROM.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 07/01/2018.
|
||||
// Copyright © 2018 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef DiskROM_hpp
|
||||
#define DiskROM_hpp
|
||||
|
||||
#include "ROMSlotHandler.hpp"
|
||||
|
||||
#include "../../Components/1770/1770.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace MSX {
|
||||
|
||||
class DiskROM: public ROMSlotHandler, public WD::WD1770 {
|
||||
public:
|
||||
DiskROM(const std::vector<uint8_t> &rom);
|
||||
|
||||
void write(uint16_t address, uint8_t value) override;
|
||||
uint8_t read(uint16_t address) override;
|
||||
void run_for(HalfCycles half_cycles) override;
|
||||
|
||||
void set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int drive);
|
||||
|
||||
private:
|
||||
const std::vector<uint8_t> &rom_;
|
||||
|
||||
long int controller_cycles_ = 0;
|
||||
int selected_drive_ = 0;
|
||||
int selected_head_ = 0;
|
||||
std::shared_ptr<Storage::Disk::Drive> drives_[4];
|
||||
|
||||
void set_head_load_request(bool head_load);
|
||||
bool get_drive_is_ready();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* DiskROM_hpp */
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "MSX.hpp"
|
||||
|
||||
#include "DiskROM.hpp"
|
||||
#include "Keyboard.hpp"
|
||||
#include "ROMSlotHandler.hpp"
|
||||
|
||||
|
@ -156,19 +157,28 @@ class ConcreteMachine:
|
|||
}
|
||||
|
||||
void configure_as_target(const StaticAnalyser::Target &target) override {
|
||||
// Add a disk cartridge if any disks were supplied.
|
||||
if(!target.media.disks.empty()) {
|
||||
map(2, 0, 0x4000, 0x2000);
|
||||
unmap(2, 0x6000, 0x2000);
|
||||
memory_slots_[2].set_handler(new DiskROM(memory_slots_[2].source));
|
||||
}
|
||||
|
||||
// Insert the media.
|
||||
insert_media(target.media);
|
||||
|
||||
// Type whatever has been requested.
|
||||
if(target.loading_command.length()) {
|
||||
type_string(target.loading_command);
|
||||
}
|
||||
|
||||
// Attach the hardware necessary for a game cartridge, if any.
|
||||
switch(target.msx.cartridge_type) {
|
||||
default: break;
|
||||
case StaticAnalyser::MSXCartridgeType::Konami:
|
||||
memory_slots_[1].set_handler(new Cartridge::KonamiROMSlotHandler(*this, 1));
|
||||
break;
|
||||
case StaticAnalyser::MSXCartridgeType::KonamiWithSCC:
|
||||
// TODO: enable an SCC.
|
||||
memory_slots_[1].set_handler(new Cartridge::KonamiWithSCCROMSlotHandler(*this, 1, scc_));
|
||||
break;
|
||||
case StaticAnalyser::MSXCartridgeType::ASCII8kb:
|
||||
|
@ -191,6 +201,16 @@ class ConcreteMachine:
|
|||
tape_player_.set_tape(media.tapes.front());
|
||||
}
|
||||
|
||||
if(!media.disks.empty()) {
|
||||
DiskROM *disk_rom = dynamic_cast<DiskROM *>(memory_slots_[2].handler.get());
|
||||
int drive = 0;
|
||||
for(auto &disk : media.disks) {
|
||||
disk_rom->set_disk(disk, drive);
|
||||
drive++;
|
||||
if(drive == 2) break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -439,14 +459,18 @@ class ConcreteMachine:
|
|||
auto roms = roms_with_names(
|
||||
"MSX",
|
||||
{
|
||||
"msx.rom"
|
||||
"msx.rom",
|
||||
"disk.rom"
|
||||
});
|
||||
|
||||
if(!roms[0]) return false;
|
||||
if(!roms[0] || !roms[1]) return false;
|
||||
|
||||
memory_slots_[0].source = std::move(*roms[0]);
|
||||
memory_slots_[0].source.resize(32768);
|
||||
|
||||
memory_slots_[2].source = std::move(*roms[1]);
|
||||
memory_slots_[2].source.resize(16384);
|
||||
|
||||
for(size_t c = 0; c < 8; ++c) {
|
||||
for(size_t slot = 0; slot < 3; ++slot) {
|
||||
memory_slots_[slot].read_pointers[c] = unpopulated_;
|
||||
|
|
|
@ -593,6 +593,8 @@
|
|||
4BEA52661DF3472B007E74F2 /* TIASound.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEA52641DF3472B007E74F2 /* TIASound.cpp */; };
|
||||
4BEBFB4D2002C4BF000708CC /* MSXDSK.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEBFB4B2002C4BF000708CC /* MSXDSK.cpp */; };
|
||||
4BEBFB4E2002C4BF000708CC /* MSXDSK.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEBFB4B2002C4BF000708CC /* MSXDSK.cpp */; };
|
||||
4BEBFB512002DB30000708CC /* DiskROM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEBFB4F2002DB30000708CC /* DiskROM.cpp */; };
|
||||
4BEBFB522002DB30000708CC /* DiskROM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEBFB4F2002DB30000708CC /* DiskROM.cpp */; };
|
||||
4BEE0A6F1D72496600532C7B /* Cartridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEE0A6A1D72496600532C7B /* Cartridge.cpp */; };
|
||||
4BEE0A701D72496600532C7B /* PRG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEE0A6D1D72496600532C7B /* PRG.cpp */; };
|
||||
4BEF6AAA1D35CE9E00E73575 /* DigitalPhaseLockedLoopBridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BEF6AA91D35CE9E00E73575 /* DigitalPhaseLockedLoopBridge.mm */; };
|
||||
|
@ -1312,6 +1314,8 @@
|
|||
4BEAC08E1E7E110500EE56B2 /* Pitfall2.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Pitfall2.hpp; sourceTree = "<group>"; };
|
||||
4BEBFB4B2002C4BF000708CC /* MSXDSK.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MSXDSK.cpp; sourceTree = "<group>"; };
|
||||
4BEBFB4C2002C4BF000708CC /* MSXDSK.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = MSXDSK.hpp; sourceTree = "<group>"; };
|
||||
4BEBFB4F2002DB30000708CC /* DiskROM.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DiskROM.cpp; path = MSX/DiskROM.cpp; sourceTree = "<group>"; };
|
||||
4BEBFB502002DB30000708CC /* DiskROM.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = DiskROM.hpp; path = MSX/DiskROM.hpp; sourceTree = "<group>"; };
|
||||
4BEE0A6A1D72496600532C7B /* Cartridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Cartridge.cpp; sourceTree = "<group>"; };
|
||||
4BEE0A6B1D72496600532C7B /* Cartridge.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Cartridge.hpp; sourceTree = "<group>"; };
|
||||
4BEE0A6D1D72496600532C7B /* PRG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PRG.cpp; sourceTree = "<group>"; };
|
||||
|
@ -2019,8 +2023,10 @@
|
|||
4B79A4FC1FC8FF9800EEDAD5 /* MSX */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4BEBFB4F2002DB30000708CC /* DiskROM.cpp */,
|
||||
4B12C0EB1FCFA98D005BFD93 /* Keyboard.cpp */,
|
||||
4B79A4FF1FC913C900EEDAD5 /* MSX.cpp */,
|
||||
4BEBFB502002DB30000708CC /* DiskROM.hpp */,
|
||||
4B12C0EC1FCFA98D005BFD93 /* Keyboard.hpp */,
|
||||
4B79A5001FC913C900EEDAD5 /* MSX.hpp */,
|
||||
4B70EF6A1FFDCDF400A3494E /* ROMSlotHandler.hpp */,
|
||||
|
@ -3376,6 +3382,7 @@
|
|||
4B055A7F1FAE852F0060FFFF /* StaticAnalyser.cpp in Sources */,
|
||||
4B055ADB1FAE9B460060FFFF /* 6560.cpp in Sources */,
|
||||
4B055AA01FAE85DA0060FFFF /* MFMSectorDump.cpp in Sources */,
|
||||
4BEBFB522002DB30000708CC /* DiskROM.cpp in Sources */,
|
||||
4B055AA11FAE85DA0060FFFF /* OricMFMDSK.cpp in Sources */,
|
||||
4B055A951FAE85BB0060FFFF /* BitReverse.cpp in Sources */,
|
||||
4B055A891FAE85580060FFFF /* StaticAnalyser.cpp in Sources */,
|
||||
|
@ -3490,6 +3497,7 @@
|
|||
4BF829661D8F732B001BAE39 /* Disk.cpp in Sources */,
|
||||
4B448E811F1C45A00009ABD6 /* TZX.cpp in Sources */,
|
||||
4B1BA08A1FD4967800CB4ADA /* CSMSX.mm in Sources */,
|
||||
4BEBFB512002DB30000708CC /* DiskROM.cpp in Sources */,
|
||||
4BEA52631DF339D7007E74F2 /* SoundGenerator.cpp in Sources */,
|
||||
4BC5E4921D7ED365008CF980 /* StaticAnalyser.cpp in Sources */,
|
||||
4BC830D11D6E7C690000A26F /* Tape.cpp in Sources */,
|
||||
|
|
Loading…
Reference in New Issue
Block a user