diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index af2f81733..40457ca7f 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -16,6 +16,7 @@ #include "CartridgeActivisionStack.hpp" #include "CartridgeCBSRAMPlus.hpp" #include "CartridgeCommaVid.hpp" +#include "CartridgeMegaBoy.hpp" #include "CartridgeParkerBros.hpp" #include "CartridgeTigervision.hpp" #include "CartridgeUnpaged.hpp" @@ -27,8 +28,6 @@ namespace { } Machine::Machine() : - rom_(nullptr), - rom_pages_{nullptr, nullptr, nullptr, nullptr}, frame_record_pointer_(0), is_ntsc_(true) { set_clock_rate(NTSC_clock_rate); @@ -88,6 +87,7 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) { case StaticAnalyser::Atari2600PagingModel::ParkerBros: bus_.reset(new CartridgeParkerBros(rom)); break; case StaticAnalyser::Atari2600PagingModel::Tigervision: bus_.reset(new CartridgeTigervision(rom)); break; case StaticAnalyser::Atari2600PagingModel::CBSRamPlus: bus_.reset(new CartridgeCBSRAMPlus(rom)); break; + case StaticAnalyser::Atari2600PagingModel::MegaBoy: bus_.reset(new CartridgeMegaBoy(rom)); break; case StaticAnalyser::Atari2600PagingModel::Atari8k: if(target.atari.uses_superchip) { bus_.reset(new CartridgeAtari8kSuperChip(rom)); @@ -112,9 +112,6 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) { } /* switch(target.atari.paging_model) { - case StaticAnalyser::Atari2600PagingModel::MegaBoy: - mega_boy_page_ = 15; - break; case StaticAnalyser::Atari2600PagingModel::MNetwork: ram_.resize(2048); // Put 256 bytes of RAM for writing at 0x1800 and reading at 0x1900 diff --git a/Machines/Atari2600/Atari2600.hpp b/Machines/Atari2600/Atari2600.hpp index 1c9414a27..e579e1896 100644 --- a/Machines/Atari2600/Atari2600.hpp +++ b/Machines/Atari2600/Atari2600.hpp @@ -53,21 +53,7 @@ class Machine: virtual void crt_did_end_batch_of_frames(Outputs::CRT::CRT *crt, unsigned int number_of_frames, unsigned int number_of_unexpected_vertical_syncs); private: - // ROM information - uint8_t *rom_; - size_t rom_size_; - - // Memory model - uint8_t *rom_pages_[4], *ram_write_targets_[32], *ram_read_targets_[32]; - uint8_t mega_boy_page_; - StaticAnalyser::Atari2600PagingModel paging_model_; - std::vector ram_; - uint8_t throwaway_ram_[128]; - - // Activision stack records - uint8_t last_opcode_; - - // the cartridge + // the bus std::unique_ptr bus_; // output frame rate tracker diff --git a/Machines/Atari2600/CartridgeMegaBoy.hpp b/Machines/Atari2600/CartridgeMegaBoy.hpp new file mode 100644 index 000000000..0a543ca65 --- /dev/null +++ b/Machines/Atari2600/CartridgeMegaBoy.hpp @@ -0,0 +1,45 @@ +// +// CartridgeMegaBoy.h +// Clock Signal +// +// Created by Thomas Harte on 18/03/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +#ifndef Atari2600_CartridgeMegaBoy_hpp +#define Atari2600_CartridgeMegaBoy_hpp + +#include "Cartridge.hpp" + +namespace Atari2600 { + +class CartridgeMegaBoy: public Cartridge { + public: + CartridgeMegaBoy(const std::vector &rom) : + Cartridge(rom), + current_page_(0) { + 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 == 0x1ff0) { + current_page_ = (current_page_ + 1) & 15; + rom_ptr_ = rom_.data() + current_page_ * 4096; + } + + if(isReadOperation(operation)) { + *value = rom_ptr_[address & 4095]; + } + } + + private: + uint8_t *rom_ptr_; + uint8_t current_page_; +}; + +} + +#endif /* CartridgeMegaBoy_h */ diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index db22f8e49..d4e620bc5 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -950,6 +950,7 @@ 4BEAC07B1E7DE74200EE56B2 /* CartridgeParkerBros.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CartridgeParkerBros.hpp; sourceTree = ""; }; 4BEAC07C1E7DEA6B00EE56B2 /* CartridgeTigervision.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CartridgeTigervision.hpp; sourceTree = ""; }; 4BEAC07D1E7DF13E00EE56B2 /* CartridgeCBSRAMPlus.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CartridgeCBSRAMPlus.hpp; sourceTree = ""; }; + 4BEAC07E1E7DF2D000EE56B2 /* CartridgeMegaBoy.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CartridgeMegaBoy.hpp; sourceTree = ""; }; 4BEE0A6A1D72496600532C7B /* Cartridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Cartridge.cpp; sourceTree = ""; }; 4BEE0A6B1D72496600532C7B /* Cartridge.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Cartridge.hpp; sourceTree = ""; }; 4BEE0A6D1D72496600532C7B /* PRG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PRG.cpp; sourceTree = ""; }; @@ -1124,6 +1125,7 @@ 4BEAC0791E7DD86E00EE56B2 /* CartridgeAtari32k.hpp */, 4BEAC07D1E7DF13E00EE56B2 /* CartridgeCBSRAMPlus.hpp */, 4BA443E71E7DB54700C86749 /* CartridgeCommaVid.hpp */, + 4BEAC07E1E7DF2D000EE56B2 /* CartridgeMegaBoy.hpp */, 4BEAC07B1E7DE74200EE56B2 /* CartridgeParkerBros.hpp */, 4BEAC07C1E7DEA6B00EE56B2 /* CartridgeTigervision.hpp */, 4BE0699A1E7C9C5A00DD379F /* CartridgeUnpaged.hpp */,