From bb3daaa99b0952991d18036f47f8008af32bf893 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 18 Mar 2017 15:04:01 -0400 Subject: [PATCH] Sought to reintroduce the Atari 8k paging scheme, at the same time deciding to do away with the copy and paste of holding on to ROM data. --- Machines/Atari2600/Atari2600.cpp | 10 ++- Machines/Atari2600/Cartridge.hpp | 6 ++ Machines/Atari2600/CartridgeAtari8k.hpp | 68 +++++++++++++++++++ ...tridgeCommaVid.h => CartridgeCommaVid.hpp} | 3 +- Machines/Atari2600/CartridgeUnpaged.hpp | 5 +- .../Clock Signal.xcodeproj/project.pbxproj | 4 ++ 6 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 Machines/Atari2600/CartridgeAtari8k.hpp rename Machines/Atari2600/{CartridgeCommaVid.h => CartridgeCommaVid.hpp} (95%) diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index 550e452b4..483fd3409 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -11,7 +11,8 @@ #include #include "CartridgeUnpaged.hpp" -#include "CartridgeCommaVid.h" +#include "CartridgeCommaVid.hpp" +#include "CartridgeAtari8k.hpp" using namespace Atari2600; namespace { @@ -80,6 +81,13 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) { case StaticAnalyser::Atari2600PagingModel::CommaVid: bus_.reset(new CartridgeCommaVid(target.cartridges.front()->get_segments().front().data)); break; + case StaticAnalyser::Atari2600PagingModel::Atari8k: + if(target.atari.uses_superchip) { + bus_.reset(new CartridgeAtari8kSuperChip(target.cartridges.front()->get_segments().front().data)); + } else { + bus_.reset(new CartridgeAtari8k(target.cartridges.front()->get_segments().front().data)); + } + break; } /* if(!target.cartridges.front()->get_segments().size()) return; diff --git a/Machines/Atari2600/Cartridge.hpp b/Machines/Atari2600/Cartridge.hpp index 4a25bfdce..a94d3f71c 100644 --- a/Machines/Atari2600/Cartridge.hpp +++ b/Machines/Atari2600/Cartridge.hpp @@ -60,6 +60,9 @@ template class Cartridge: public Bus { public: + Cartridge(const std::vector &rom) : + rom_(rom) {} + void run_for_cycles(int number_of_cycles) { CPU6502::Processor>::run_for_cycles(number_of_cycles); } // to satisfy CPU6502::Processor @@ -201,6 +204,9 @@ template class Cartridge: update_video(); speaker_->flush(); } + + protected: + std::vector rom_; }; } diff --git a/Machines/Atari2600/CartridgeAtari8k.hpp b/Machines/Atari2600/CartridgeAtari8k.hpp new file mode 100644 index 000000000..a5c508738 --- /dev/null +++ b/Machines/Atari2600/CartridgeAtari8k.hpp @@ -0,0 +1,68 @@ +// +// CartridgeAtari8k.h +// Clock Signal +// +// Created by Thomas Harte on 18/03/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +#ifndef CartridgeAtari8k_h +#define CartridgeAtari8k_h + +#include "Cartridge.hpp" + +namespace Atari2600 { + +class CartridgeAtari8k: public Cartridge { + public: + CartridgeAtari8k(const std::vector &rom) : + Cartridge(rom) { + rom_ptr_ = rom_.data(); + } + + void perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { + address &= 0x1fff; + if(!(address & 0x1000)) return; + + if(address == 0x1ff8) rom_ptr_ = rom_.data(); + else if(address == 0x1ff9) rom_ptr_ = rom_.data() + 4096; + + if(isReadOperation(operation)) { + *value = rom_ptr_[address & 4095]; + } + } + + private: + uint8_t *rom_ptr_; +}; + +class CartridgeAtari8kSuperChip: public Cartridge { + public: + CartridgeAtari8kSuperChip(const std::vector &rom) : + Cartridge(rom) { + rom_ptr_ = rom_.data(); + } + + void perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { + address &= 0x1fff; + if(!(address & 0x1000)) return; + + if(address == 0x1ff8) rom_ptr_ = rom_.data(); + if(address == 0x1ff9) rom_ptr_ = rom_.data() + 4096; + + if(isReadOperation(operation)) { + *value = rom_ptr_[address & 4095]; + } + + if(address < 0x1080) ram_[address & 0x7f] = *value; + else if(address < 0x1100 && isReadOperation(operation)) *value = ram_[address & 0x7f]; + } + + private: + uint8_t *rom_ptr_; + uint8_t ram_[128]; +}; + +} + +#endif /* CartridgeAtari8k_h */ diff --git a/Machines/Atari2600/CartridgeCommaVid.h b/Machines/Atari2600/CartridgeCommaVid.hpp similarity index 95% rename from Machines/Atari2600/CartridgeCommaVid.h rename to Machines/Atari2600/CartridgeCommaVid.hpp index d470f0ad7..09cd49fce 100644 --- a/Machines/Atari2600/CartridgeCommaVid.h +++ b/Machines/Atari2600/CartridgeCommaVid.hpp @@ -14,7 +14,7 @@ namespace Atari2600 { class CartridgeCommaVid: public Cartridge { public: CartridgeCommaVid(const std::vector &rom) : - rom_(rom) {} + Cartridge(rom) {} void perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { if(!(address & 0x1000)) return; @@ -34,7 +34,6 @@ class CartridgeCommaVid: public Cartridge { } private: - std::vector rom_; uint8_t ram_[1024]; }; diff --git a/Machines/Atari2600/CartridgeUnpaged.hpp b/Machines/Atari2600/CartridgeUnpaged.hpp index 19d17e2f4..2cab2fd3e 100644 --- a/Machines/Atari2600/CartridgeUnpaged.hpp +++ b/Machines/Atari2600/CartridgeUnpaged.hpp @@ -16,16 +16,13 @@ namespace Atari2600 { class CartridgeUnpaged: public Cartridge { public: CartridgeUnpaged(const std::vector &rom) : - rom_(rom) {} + Cartridge(rom) {} void perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { if(isReadOperation(operation) && (address & 0x1000)) { *value = rom_[address & (rom_.size() - 1)]; } } - - private: - std::vector rom_; }; } diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 9645d05f4..9d8046b66 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -582,6 +582,8 @@ 4B9CCDA21DA27C3F0098B625 /* CSJoystickMachine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSJoystickMachine.h; sourceTree = ""; }; 4BA22B051D8817CE0008C640 /* Disk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Disk.cpp; path = ../../StaticAnalyser/Commodore/Disk.cpp; sourceTree = ""; }; 4BA22B061D8817CE0008C640 /* Disk.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Disk.hpp; path = ../../StaticAnalyser/Commodore/Disk.hpp; sourceTree = ""; }; + 4BA443E71E7DB54700C86749 /* CartridgeCommaVid.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CartridgeCommaVid.hpp; sourceTree = ""; }; + 4BA443E81E7DB8F900C86749 /* CartridgeAtari8k.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CartridgeAtari8k.hpp; sourceTree = ""; }; 4BA61EAE1D91515900B3C876 /* NSData+StdVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+StdVector.h"; sourceTree = ""; }; 4BA61EAF1D91515900B3C876 /* NSData+StdVector.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSData+StdVector.mm"; sourceTree = ""; }; 4BA799931D8B656E0045123D /* StaticAnalyser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StaticAnalyser.cpp; path = ../../StaticAnalyser/Atari/StaticAnalyser.cpp; sourceTree = ""; }; @@ -1114,6 +1116,8 @@ 4BE7C9171E3D397100A5496D /* TIA.hpp */, 4BE069991E7C942C00DD379F /* Cartridge.hpp */, 4BE0699A1E7C9C5A00DD379F /* CartridgeUnpaged.hpp */, + 4BA443E71E7DB54700C86749 /* CartridgeCommaVid.hpp */, + 4BA443E81E7DB8F900C86749 /* CartridgeAtari8k.hpp */, ); path = Atari2600; sourceTree = "";