From 86dabd007bc90d8db1dd575abdcce7f5f56ce2c5 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 5 Jul 2016 16:39:18 -0400 Subject: [PATCH] Furthered fleshing out of the 1540. Though it doesn't yet receive a ROM so won't even attempt to do anything meaningful. --- Machines/Commodore/1540/Commodore1540.cpp | 26 +++++++++++++++++++ Machines/Commodore/1540/Commodore1540.hpp | 22 +++++++++++++++- Machines/Commodore/Vic-20/Vic20.cpp | 19 +++++++++++--- Machines/Commodore/Vic-20/Vic20.hpp | 12 ++++++--- .../Clock Signal/Machine/Wrappers/CSVic20.h | 1 + .../Clock Signal/Machine/Wrappers/CSVic20.mm | 10 ++++--- ROMImages/Commodore1540/readme.txt | 5 ++++ 7 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 ROMImages/Commodore1540/readme.txt diff --git a/Machines/Commodore/1540/Commodore1540.cpp b/Machines/Commodore/1540/Commodore1540.cpp index bec2a9567..5fe054b7a 100644 --- a/Machines/Commodore/1540/Commodore1540.cpp +++ b/Machines/Commodore/1540/Commodore1540.cpp @@ -7,3 +7,29 @@ // #include "Commodore1540.hpp" +#include + +using namespace Commodore::C1540; + +unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) +{ + if(address < 0x800) + { + if(isReadOperation(operation)) + *value = _ram[address]; + else + _ram[address] = *value; + } + else if(address >= 0xc000) + { + if(isReadOperation(operation)) + *value = _rom[address & 0x3fff]; + } + + return 1; +} + +void Machine::set_rom(uint8_t *rom) +{ + memcpy(_rom, rom, sizeof(_rom)); +} diff --git a/Machines/Commodore/1540/Commodore1540.hpp b/Machines/Commodore/1540/Commodore1540.hpp index f661b740a..e0d28d248 100644 --- a/Machines/Commodore/1540/Commodore1540.hpp +++ b/Machines/Commodore/1540/Commodore1540.hpp @@ -9,6 +9,26 @@ #ifndef Commodore1540_hpp #define Commodore1540_hpp -#include +#include "../../../Processors/6502/CPU6502.hpp" +#include "../../../Components/6522/6522.hpp" + +namespace Commodore { +namespace C1540 { + +class Machine: + public CPU6502::Processor { + + public: + unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value); + + void set_rom(uint8_t *rom); + + private: + uint8_t _ram[0x800]; + uint8_t _rom[0x4000]; +}; + +} +} #endif /* Commodore1540_hpp */ diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index a4d8e7523..ab9c61a20 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -54,6 +54,9 @@ Machine::Machine() : write_to_map(_processorWriteMemoryMap, _userBASICMemory, 0x0000, sizeof(_userBASICMemory)); write_to_map(_processorWriteMemoryMap, _screenMemory, 0x1000, sizeof(_screenMemory)); write_to_map(_processorWriteMemoryMap, _colorMemory, 0x9400, sizeof(_colorMemory)); + + // TEMPORARY: attach a [diskless] 1540 + set_disc(); } void Machine::write_to_map(uint8_t **map, uint8_t *area, uint16_t address, uint16_t length) @@ -121,6 +124,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin _keyboardVIA->run_for_half_cycles(2); if(_typer) _typer->update(1); _tape.run_for_cycles(1); + if(_c1540) _c1540->run_for_cycles(1); return 1; } @@ -150,9 +154,11 @@ void Machine::set_rom(ROMSlot slot, size_t length, const uint8_t *data) size_t max_length = 0x2000; switch(slot) { - case ROMSlotKernel: target = _kernelROM; break; - case ROMSlotCharacters: target = _characterROM; max_length = 0x1000; break; - case ROMSlotBASIC: target = _basicROM; break; + case Kernel: target = _kernelROM; break; + case Characters: target = _characterROM; max_length = 0x1000; break; + case BASIC: target = _basicROM; break; + case Drive: + return; } if(target) @@ -323,3 +329,10 @@ void Tape::process_input_pulse(Storage::Tape::Pulse pulse) if(_delegate) _delegate->tape_did_change_input(this); } } + +#pragma mark - Disc + +void Machine::set_disc() +{ + _c1540.reset(new ::Commodore::C1540::Machine); +} diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index 1791b4034..9f625531e 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -13,6 +13,7 @@ #include "../../../Storage/Tape/Tape.hpp" #include "../../../Components/6560/6560.hpp" #include "../../../Components/6522/6522.hpp" +#include "../1540/Commodore1540.hpp" #include "../SerialBus.hpp" #include "../../CRTMachine.hpp" @@ -22,9 +23,10 @@ namespace Commodore { namespace Vic20 { enum ROMSlot { - ROMSlotKernel, - ROMSlotBASIC, - ROMSlotCharacters, + Kernel, + BASIC, + Characters, + Drive }; #define key(line, mask) (((mask) << 3) | (line)) @@ -235,6 +237,7 @@ class Machine: void set_rom(ROMSlot slot, size_t length, const uint8_t *data); void add_prg(size_t length, const uint8_t *data); void set_tape(std::shared_ptr tape); + void set_disc(); void set_key_state(Key key, bool isPressed) { _keyboardVIA->set_key_state(key, isPressed); } void clear_all_keys() { _keyboardVIA->clear_all_keys(); } @@ -296,6 +299,9 @@ class Machine: // Tape Tape _tape; bool _use_fast_tape_hack; + + // Disc + std::shared_ptr<::Commodore::C1540::Machine> _c1540; }; } diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h index ef04a1f78..83f3c7863 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.h @@ -15,6 +15,7 @@ - (void)setKernelROM:(nonnull NSData *)rom; - (void)setBASICROM:(nonnull NSData *)rom; - (void)setCharactersROM:(nonnull NSData *)rom; +- (void)setDriveROM:(nonnull NSData *)rom; - (void)setPRG:(nonnull NSData *)prg; - (BOOL)openTAPAtURL:(nonnull NSURL *)URL; diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm index 3e576ca20..6407fcd9e 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm @@ -29,15 +29,19 @@ using namespace Commodore::Vic20; } - (void)setKernelROM:(nonnull NSData *)rom { - [self setROM:rom slot:ROMSlotKernel]; + [self setROM:rom slot:Kernel]; } - (void)setBASICROM:(nonnull NSData *)rom { - [self setROM:rom slot:ROMSlotBASIC]; + [self setROM:rom slot:BASIC]; } - (void)setCharactersROM:(nonnull NSData *)rom { - [self setROM:rom slot:ROMSlotCharacters]; + [self setROM:rom slot:Characters]; +} + +- (void)setDriveROM:(nonnull NSData *)rom { + [self setROM:rom slot:Drive]; } - (BOOL)openTAPAtURL:(NSURL *)URL { diff --git a/ROMImages/Commodore1540/readme.txt b/ROMImages/Commodore1540/readme.txt new file mode 100644 index 000000000..f5ba5b233 --- /dev/null +++ b/ROMImages/Commodore1540/readme.txt @@ -0,0 +1,5 @@ +ROM files would ordinarily go here; the copyright status of these is uncertain so they have not been included in this repository. + +Expected files: + +1540.rom; a 16kb image of the 1540's ROM area.