From 4bff44377add9cb0386b3e29c69e1d28ffbe2745 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 23 Apr 2018 22:11:31 -0700 Subject: [PATCH] Attempts to route Disk II requests to the thing itself. --- Components/DiskII/DiskII.cpp | 28 ++++++++ Machines/AppleII/AppleII.cpp | 14 ++-- Machines/AppleII/Card.hpp | 1 + Machines/AppleII/DiskIICard.cpp | 64 +++++++++++++++++++ Machines/AppleII/DiskIICard.hpp | 35 ++++++++++ Machines/ROMMachine.hpp | 1 + .../Clock Signal.xcodeproj/project.pbxproj | 10 ++- 7 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 Machines/AppleII/DiskIICard.cpp create mode 100644 Machines/AppleII/DiskIICard.hpp diff --git a/Components/DiskII/DiskII.cpp b/Components/DiskII/DiskII.cpp index 0c92ad670..b93d12097 100644 --- a/Components/DiskII/DiskII.cpp +++ b/Components/DiskII/DiskII.cpp @@ -7,3 +7,31 @@ // #include "DiskII.hpp" + +#include + +using namespace Apple; + +void DiskII::set_control(Control control, bool on) { + printf("Set control %d %s\n", control, on ? "on" : "off"); +} + +void DiskII::set_mode(Mode mode) { + printf("Set mode %d\n", mode); +} + +void DiskII::select_drive(int drive) { + printf("Select drive %d\n", drive); +} + +void DiskII::set_shift_register(uint8_t value) { + printf("Set shift register\n"); +} + +uint8_t DiskII::get_shift_register() { + printf("Get shift register\n"); + return 0xff; +} + +void DiskII::run_for(const Cycles cycles) { +} diff --git a/Machines/AppleII/AppleII.cpp b/Machines/AppleII/AppleII.cpp index f550d2247..868a6a2e7 100644 --- a/Machines/AppleII/AppleII.cpp +++ b/Machines/AppleII/AppleII.cpp @@ -19,6 +19,7 @@ #include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" #include "Card.hpp" +#include "DiskIICard.hpp" #include "Video.hpp" #include "../../Analyser/Static/AppleII/Target.hpp" @@ -61,11 +62,8 @@ class ConcreteMachine: speaker_.run_for(audio_queue_, cycles_since_audio_update_.divide(Cycles(audio_divider))); } void update_cards() { - cycles_since_card_update_ += stretched_cycles_since_card_update_ / 7; - stretched_cycles_since_card_update_ %= 7; for(int c = 0; c < 7; ++c) { - if(cards_[c]) - cards_[c]->run_for(cycles_since_card_update_, stretched_cycles_since_card_update_); + if(cards_[c]) cards_[c]->run_for(cycles_since_card_update_, stretched_cycles_since_card_update_); } cycles_since_card_update_ = 0; stretched_cycles_since_card_update_ = 0; @@ -83,7 +81,7 @@ class ConcreteMachine: Cycles cycles_since_audio_update_; ROMMachine::ROMFetcher rom_fetcher_; - AppleII::Card *cards_[7] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; + std::unique_ptr cards_[7]; Cycles cycles_since_card_update_; int stretched_cycles_since_card_update_ = 0; @@ -193,10 +191,10 @@ class ConcreteMachine: Decode the area conventionally used by cards for registers: C0n0--C0nF: card n - 8. */ - const int card_number = (address - 0xc080) >> 4; + const int card_number = (address - 0xc090) >> 4; if(cards_[card_number]) { update_cards(); - cards_[card_number]->perform_bus_operation(operation, address, value); + cards_[card_number]->perform_bus_operation(operation, 0x100 | (address&0xf), value); } } @@ -268,7 +266,7 @@ class ConcreteMachine: void configure_as_target(const Analyser::Static::Target *target) override { auto *const apple_target = dynamic_cast(target); if(apple_target->has_disk) { - // ... add Disk II + cards_[6].reset(new AppleII::DiskIICard(rom_fetcher_, true)); } } diff --git a/Machines/AppleII/Card.hpp b/Machines/AppleII/Card.hpp index 7f02a270a..d7c00cdb6 100644 --- a/Machines/AppleII/Card.hpp +++ b/Machines/AppleII/Card.hpp @@ -9,6 +9,7 @@ #ifndef Card_h #define Card_h +#include "../../Processors/6502/6502.hpp" #include "../../ClockReceiver/ClockReceiver.hpp" namespace AppleII { diff --git a/Machines/AppleII/DiskIICard.cpp b/Machines/AppleII/DiskIICard.cpp new file mode 100644 index 000000000..d536dfe63 --- /dev/null +++ b/Machines/AppleII/DiskIICard.cpp @@ -0,0 +1,64 @@ +// +// DiskII.cpp +// Clock Signal +// +// Created by Thomas Harte on 23/04/2018. +// Copyright © 2018 Thomas Harte. All rights reserved. +// + +#include "DiskIICard.hpp" + +using namespace AppleII; + +DiskIICard::DiskIICard(const ROMMachine::ROMFetcher &rom_fetcher, bool is_16_sector) { + auto roms = rom_fetcher( + "DiskII", + { + "boot.rom", + "state-machine.rom" + }); + boot_ = std::move(*roms[0]); + state_machine_ = std::move(*roms[1]); +} + +void DiskIICard::perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { + if(isReadOperation(operation) && address < 0x100) { + *value &= boot_[address]; + } else { + using Control = Apple::DiskII::Control; + using Mode = Apple::DiskII::Mode; + switch(address & 0xf) { + case 0x0: diskii_.set_control(Control::P0, false); break; + case 0x1: diskii_.set_control(Control::P0, true); break; + case 0x2: diskii_.set_control(Control::P1, false); break; + case 0x3: diskii_.set_control(Control::P1, true); break; + case 0x4: diskii_.set_control(Control::P2, false); break; + case 0x5: diskii_.set_control(Control::P2, true); break; + case 0x6: diskii_.set_control(Control::P3, false); break; + case 0x7: diskii_.set_control(Control::P3, true); break; + + case 0x8: diskii_.set_control(Control::Motor, false); break; + case 0x9: diskii_.set_control(Control::Motor, true); break; + + case 0xa: diskii_.select_drive(0); break; + case 0xb: diskii_.select_drive(1); break; + + case 0xc: + /* shift register? */ + if(isReadOperation(operation)) + *value = diskii_.get_shift_register(); + break; + case 0xd: + /* data register? */ + diskii_.set_shift_register(*value); + break; + + case 0xe: diskii_.set_mode(Mode::Read); break; + case 0xf: diskii_.set_mode(Mode::Write); break; + } + } +} + +void DiskIICard::run_for(Cycles cycles, int stretches) { + diskii_.run_for(cycles); +} diff --git a/Machines/AppleII/DiskIICard.hpp b/Machines/AppleII/DiskIICard.hpp new file mode 100644 index 000000000..08b80027a --- /dev/null +++ b/Machines/AppleII/DiskIICard.hpp @@ -0,0 +1,35 @@ +// +// DiskII.hpp +// Clock Signal +// +// Created by Thomas Harte on 23/04/2018. +// Copyright © 2018 Thomas Harte. All rights reserved. +// + +#ifndef DiskIICard_hpp +#define DiskIICard_hpp + +#include "Card.hpp" +#include "../ROMMachine.hpp" +#include "../../Components/DiskII/DiskII.hpp" + +#include +#include + +namespace AppleII { + +class DiskIICard: public Card { + public: + DiskIICard(const ROMMachine::ROMFetcher &rom_fetcher, bool is_16_sector); + void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) override; + void run_for(Cycles cycles, int stretches) override; + + private: + std::vector boot_; + std::vector state_machine_; + Apple::DiskII diskii_; +}; + +} + +#endif /* DiskIICard_hpp */ diff --git a/Machines/ROMMachine.hpp b/Machines/ROMMachine.hpp index 4c40e8bad..42c34e07f 100644 --- a/Machines/ROMMachine.hpp +++ b/Machines/ROMMachine.hpp @@ -11,6 +11,7 @@ #include #include +#include #include namespace ROMMachine { diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 0785cb63f..6c3663dea 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -606,6 +606,8 @@ 4BBF99181C8FBA6F0075DAFB /* TextureTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BBF99121C8FBA6F0075DAFB /* TextureTarget.cpp */; }; 4BBFBB6C1EE8401E00C01E7A /* ZX8081.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BBFBB6A1EE8401E00C01E7A /* ZX8081.cpp */; }; 4BBFFEE61F7B27F1005F3FEB /* TrackSerialiser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BBFFEE51F7B27F1005F3FEB /* TrackSerialiser.cpp */; }; + 4BC39568208EE6CF0044766B /* DiskIICard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC39566208EE6CF0044766B /* DiskIICard.cpp */; }; + 4BC39569208EE6CF0044766B /* DiskIICard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC39566208EE6CF0044766B /* DiskIICard.cpp */; }; 4BC3B74F1CD194CC00F86E85 /* Shader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC3B74D1CD194CC00F86E85 /* Shader.cpp */; }; 4BC3B7521CD1956900F86E85 /* OutputShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC3B7501CD1956900F86E85 /* OutputShader.cpp */; }; 4BC751B21D157E61006C31D9 /* 6522Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC751B11D157E61006C31D9 /* 6522Tests.swift */; }; @@ -1333,6 +1335,8 @@ 4BBFBB6B1EE8401E00C01E7A /* ZX8081.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ZX8081.hpp; path = Parsers/ZX8081.hpp; sourceTree = ""; }; 4BBFFEE51F7B27F1005F3FEB /* TrackSerialiser.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TrackSerialiser.cpp; sourceTree = ""; }; 4BC39565208EDFCE0044766B /* Card.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Card.hpp; sourceTree = ""; }; + 4BC39566208EE6CF0044766B /* DiskIICard.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DiskIICard.cpp; sourceTree = ""; }; + 4BC39567208EE6CF0044766B /* DiskIICard.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = DiskIICard.hpp; sourceTree = ""; }; 4BC3B74D1CD194CC00F86E85 /* Shader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Shader.cpp; sourceTree = ""; }; 4BC3B74E1CD194CC00F86E85 /* Shader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Shader.hpp; sourceTree = ""; }; 4BC3B7501CD1956900F86E85 /* OutputShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OutputShader.cpp; sourceTree = ""; }; @@ -1553,10 +1557,12 @@ isa = PBXGroup; children = ( 4B15AA0C2082C799005E6C8D /* AppleII.cpp */, + 4BC39566208EE6CF0044766B /* DiskIICard.cpp */, 4B15AA0A2082C799005E6C8D /* Video.cpp */, 4B15AA092082C799005E6C8D /* AppleII.hpp */, - 4B15AA0B2082C799005E6C8D /* Video.hpp */, 4BC39565208EDFCE0044766B /* Card.hpp */, + 4BC39567208EE6CF0044766B /* DiskIICard.hpp */, + 4B15AA0B2082C799005E6C8D /* Video.hpp */, ); path = AppleII; sourceTree = ""; @@ -3607,6 +3613,7 @@ 4B15AA0E2082C799005E6C8D /* Video.cpp in Sources */, 4B055A991FAE85CB0060FFFF /* DiskController.cpp in Sources */, 4B055ACC1FAE9B030060FFFF /* Electron.cpp in Sources */, + 4BC39569208EE6CF0044766B /* DiskIICard.cpp in Sources */, 4B055AB11FAE86070060FFFF /* Tape.cpp in Sources */, 4BFE7B881FC39D8900160B38 /* StandardOptions.cpp in Sources */, 4B894533201967B4007DE474 /* 6502.cpp in Sources */, @@ -3711,6 +3718,7 @@ 4B595FAD2086DFBA0083CAA8 /* AudioToggle.cpp in Sources */, 4B1497921EE4B5A800CE2596 /* ZX8081.cpp in Sources */, 4B643F3F1D77B88000D431D6 /* DocumentController.swift in Sources */, + 4BC39568208EE6CF0044766B /* DiskIICard.cpp in Sources */, 4B4518861F75E91A00926311 /* MFMDiskController.cpp in Sources */, 4B54C0BF1F8D8F450050900F /* Keyboard.cpp in Sources */, 4B3FE75E1F3CF68B00448EE4 /* CPM.cpp in Sources */,