From 031a68000aba071b8d8afdeb03f4d4c1b067566e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 18 Mar 2017 22:08:47 -0400 Subject: [PATCH 01/12] Added a class to contain the Pitfall 2 pager and a skeleton of initial work. --- Machines/Atari2600/Atari2600.cpp | 11 ++-- .../Cartridges/CartridgePitfall2.hpp | 65 +++++++++++++++++++ .../Clock Signal.xcodeproj/project.pbxproj | 2 + 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 Machines/Atari2600/Cartridges/CartridgePitfall2.hpp diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index 3353c7290..8abeb1d67 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -19,6 +19,7 @@ #include "Cartridges/CartridgeMegaBoy.hpp" #include "Cartridges/CartridgeMNetwork.hpp" #include "Cartridges/CartridgeParkerBros.hpp" +#include "Cartridges/CartridgePitfall2.hpp" #include "Cartridges/CartridgeTigervision.hpp" #include "Cartridges/CartridgeUnpaged.hpp" @@ -82,14 +83,16 @@ void Machine::set_switch_is_enabled(Atari2600Switch input, bool state) { void Machine::configure_as_target(const StaticAnalyser::Target &target) { const std::vector &rom = target.cartridges.front()->get_segments().front().data; switch(target.atari.paging_model) { - case StaticAnalyser::Atari2600PagingModel::None: bus_.reset(new CartridgeUnpaged(rom)); break; - case StaticAnalyser::Atari2600PagingModel::CommaVid: bus_.reset(new CartridgeCommaVid(rom)); break; case StaticAnalyser::Atari2600PagingModel::ActivisionStack: bus_.reset(new CartridgeActivisionStack(rom)); break; - 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::CommaVid: bus_.reset(new CartridgeCommaVid(rom)); break; case StaticAnalyser::Atari2600PagingModel::MegaBoy: bus_.reset(new CartridgeMegaBoy(rom)); break; case StaticAnalyser::Atari2600PagingModel::MNetwork: bus_.reset(new CartridgeMNetwork(rom)); break; + case StaticAnalyser::Atari2600PagingModel::None: bus_.reset(new CartridgeUnpaged(rom)); break; + case StaticAnalyser::Atari2600PagingModel::ParkerBros: bus_.reset(new CartridgeParkerBros(rom)); break; + case StaticAnalyser::Atari2600PagingModel::Pitfall2: bus_.reset(new CartridgePitfall2(rom)); break; + case StaticAnalyser::Atari2600PagingModel::Tigervision: bus_.reset(new CartridgeTigervision(rom)); break; + case StaticAnalyser::Atari2600PagingModel::Atari8k: if(target.atari.uses_superchip) { bus_.reset(new CartridgeAtari8kSuperChip(rom)); diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp new file mode 100644 index 000000000..fcd8c479e --- /dev/null +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -0,0 +1,65 @@ +// +// CartridgePitfall2.h +// Clock Signal +// +// Created by Thomas Harte on 18/03/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +#ifndef Atari2600_CartridgePitfall2_hpp +#define Atari2600_CartridgePitfall2_hpp + +namespace Atari2600 { + +class CartridgePitfall2: public Cartridge { + public: + CartridgePitfall2(const std::vector &rom) : + Cartridge(rom), + random_number_generator_(0), + featcher_address_{0, 0, 0, 0, 0, 0, 0, 0} { + rom_ptr_ = rom_.data(); + } + + void perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { + address &= 0x1fff; + if(!(address & 0x1000)) return; + + switch(address) { + // The random number generator + case 0x1000: case 0x1001: case 0x1002: case 0x1003: + if(isReadOperation(operation)) { + *value = random_number_generator_; + } + random_number_generator_ = (uint8_t)( + (random_number_generator_ << 1) | + ~(( (random_number_generator_ >> 7) ^ + (random_number_generator_ >> 5) ^ + (random_number_generator_ >> 4) ^ + (random_number_generator_ >> 3) + ) & 1)); + break; + + case 0x1040: case 0x1041: case 0x1042: case 0x1043: case 0x1044: case 0x1045: case 0x1046: case 0x1047: +// featcher_address_[address - 0x1040] + break; + + case 0x1ff8: rom_ptr_ = rom_.data(); break; + case 0x1ff9: rom_ptr_ = rom_.data() + 4096; break; + + default: + if(isReadOperation(operation)) { + *value = rom_ptr_[address & 4095]; + } + break; + } + } + + private: + uint16_t featcher_address_[8]; + uint8_t random_number_generator_; + uint8_t *rom_ptr_; +}; + +} + +#endif /* Atari2600_CartridgePitfall2_hpp */ diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 3915a3812..b9f53cea6 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -953,6 +953,7 @@ 4BEAC08B1E7E0DF800EE56B2 /* CartridgeTigervision.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CartridgeTigervision.hpp; sourceTree = ""; }; 4BEAC08C1E7E0DF800EE56B2 /* CartridgeUnpaged.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CartridgeUnpaged.hpp; sourceTree = ""; }; 4BEAC08D1E7E0E1A00EE56B2 /* Bus.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Bus.hpp; sourceTree = ""; }; + 4BEAC08E1E7E110500EE56B2 /* CartridgePitfall2.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CartridgePitfall2.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 = ""; }; @@ -1971,6 +1972,7 @@ 4BEAC08A1E7E0DF800EE56B2 /* CartridgeParkerBros.hpp */, 4BEAC08B1E7E0DF800EE56B2 /* CartridgeTigervision.hpp */, 4BEAC08C1E7E0DF800EE56B2 /* CartridgeUnpaged.hpp */, + 4BEAC08E1E7E110500EE56B2 /* CartridgePitfall2.hpp */, ); path = Cartridges; sourceTree = ""; From 7c66c36d3f6902f1a3dea7a8081dd5dfe5e264c5 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Mar 2017 17:31:08 -0400 Subject: [PATCH 02/12] Attempted at least to manage appropriate data storage. --- .../Cartridges/CartridgePitfall2.hpp | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index fcd8c479e..60a95d338 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -25,8 +25,11 @@ class CartridgePitfall2: public Cartridge { if(!(address & 0x1000)) return; switch(address) { + +#pragma mark - Reads + // The random number generator - case 0x1000: case 0x1001: case 0x1002: case 0x1003: + case 0x1000: case 0x1001: case 0x1002: case 0x1003: case 0x1004: if(isReadOperation(operation)) { *value = random_number_generator_; } @@ -39,13 +42,45 @@ class CartridgePitfall2: public Cartridge { ) & 1)); break; - case 0x1040: case 0x1041: case 0x1042: case 0x1043: case 0x1044: case 0x1045: case 0x1046: case 0x1047: -// featcher_address_[address - 0x1040] + // Music fetcher + case 0x1005: case 0x1006: case 0x1007: + *value = 0x00; + printf("m\n"); break; + case 0x1008: case 0x1009: case 0x100a: case 0x100b: case 0x100c: case 0x100d: case 0x100e: case 0x100f: + printf("d\n"); + break; + + case 0x1010: case 0x1011: case 0x1012: case 0x1013: case 0x1014: case 0x1015: case 0x1016: case 0x1017: + printf("da\n"); + break; + +#pragma mark - Writes + + case 0x1040: case 0x1041: case 0x1042: case 0x1043: case 0x1044: case 0x1045: case 0x1046: case 0x1047: + top_[address & 7] = *value; + break; + case 0x1048: case 0x1049: case 0x104a: case 0x104b: case 0x104c: case 0x104d: case 0x104e: case 0x104f: + bottom_[address & 7] = *value; + break; + case 0x1050: case 0x1051: case 0x1052: case 0x1053: case 0x1054: case 0x1055: case 0x1056: case 0x1057: + featcher_address_[address & 7] = (featcher_address_[address & 7] & 0xff00) | *value; + break; + case 0x1058: case 0x1059: case 0x105a: case 0x105b: case 0x105c: case 0x105d: case 0x105e: case 0x105f: + featcher_address_[address & 7] = (featcher_address_[address & 7] & 0x00ff) | (uint16_t)(*value << 8); + break; + case 0x1070: case 0x1071: case 0x1072: case 0x1073: case 0x1074: case 0x1075: case 0x1076: case 0x1077: + random_number_generator_ = 0; + break; + +#pragma mark - Paging + case 0x1ff8: rom_ptr_ = rom_.data(); break; case 0x1ff9: rom_ptr_ = rom_.data() + 4096; break; +#pragma mark - Business as usual + default: if(isReadOperation(operation)) { *value = rom_ptr_[address & 4095]; @@ -56,6 +91,8 @@ class CartridgePitfall2: public Cartridge { private: uint16_t featcher_address_[8]; + uint8_t top_[8], bottom_[8]; + uint8_t music_mode_[3]; uint8_t random_number_generator_; uint8_t *rom_ptr_; }; From c445eaec3e640433ef70a71fed563919d18f9a46 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Mar 2017 17:38:26 -0400 Subject: [PATCH 03/12] Switched startup values, following a comment on AtariAge. May or may not be correct, the thread was speculative. --- Components/6532/6532.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Components/6532/6532.hpp b/Components/6532/6532.hpp index 69f85b996..b9b72ff7e 100644 --- a/Components/6532/6532.hpp +++ b/Components/6532/6532.hpp @@ -131,7 +131,7 @@ template class MOS6532 { port_{{.output_mask = 0, .output = 0}, {.output_mask = 0, .output = 0}}, a7_interrupt_({.last_port_value = 0, .enabled = false}), interrupt_line_(false), - timer_{.value = 0, .activeShift = 0, .writtenShift = 0, .interrupt_enabled = false} + timer_{.value = 16320, .activeShift = 6, .writtenShift = 6, .interrupt_enabled = false} {} inline void set_port_did_change(int port) From d5c37c86195770400fa680e1a69f4de1dcb046a1 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Mar 2017 17:38:54 -0400 Subject: [PATCH 04/12] Shushed a little, so as to be able to see a reasonable amount of output during my lifetime. --- Machines/Atari2600/Cartridges/CartridgePitfall2.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index 60a95d338..e8a38da0b 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -45,15 +45,14 @@ class CartridgePitfall2: public Cartridge { // Music fetcher case 0x1005: case 0x1006: case 0x1007: *value = 0x00; - printf("m\n"); break; case 0x1008: case 0x1009: case 0x100a: case 0x100b: case 0x100c: case 0x100d: case 0x100e: case 0x100f: - printf("d\n"); + *value = 0x20; break; case 0x1010: case 0x1011: case 0x1012: case 0x1013: case 0x1014: case 0x1015: case 0x1016: case 0x1017: - printf("da\n"); + *value = 0x40; break; #pragma mark - Writes From 6c161b1150778a9ab04c8f547fd73dfa13cd6b15 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Mar 2017 17:49:48 -0400 Subject: [PATCH 05/12] This gives something that might be the correct background. --- Machines/Atari2600/Cartridges/CartridgePitfall2.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index e8a38da0b..5dfe7a01f 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -47,12 +47,14 @@ class CartridgePitfall2: public Cartridge { *value = 0x00; break; - case 0x1008: case 0x1009: case 0x100a: case 0x100b: case 0x100c: case 0x100d: case 0x100e: case 0x100f: - *value = 0x20; - break; + case 0x1008: case 0x1009: case 0x100a: case 0x100b: case 0x100c: case 0x100d: case 0x100e: case 0x100f: { + uint16_t fetch_address = (featcher_address_[address & 7] & 2047) ^ 2047; + featcher_address_[address & 7]--; + *value = rom_[8192 + fetch_address]; + } break; case 0x1010: case 0x1011: case 0x1012: case 0x1013: case 0x1014: case 0x1015: case 0x1016: case 0x1017: - *value = 0x40; + *value = 0xff; break; #pragma mark - Writes From 321030bb441fa6add93626038a45df08206c68f4 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Mar 2017 18:28:06 -0400 Subject: [PATCH 06/12] Added a slightly faulty but seemingly 'close' version of masking. --- .../Cartridges/CartridgePitfall2.hpp | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index 5dfe7a01f..1fed81ee1 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -47,14 +47,12 @@ class CartridgePitfall2: public Cartridge { *value = 0x00; break; - case 0x1008: case 0x1009: case 0x100a: case 0x100b: case 0x100c: case 0x100d: case 0x100e: case 0x100f: { - uint16_t fetch_address = (featcher_address_[address & 7] & 2047) ^ 2047; - featcher_address_[address & 7]--; - *value = rom_[8192 + fetch_address]; - } break; + case 0x1008: case 0x1009: case 0x100a: case 0x100b: case 0x100c: case 0x100d: case 0x100e: case 0x100f: + *value = rom_[8192 + address_for_counter(address & 7)]; + break; case 0x1010: case 0x1011: case 0x1012: case 0x1013: case 0x1014: case 0x1015: case 0x1016: case 0x1017: - *value = 0xff; + *value = rom_[8192 + address_for_counter(address & 7)] & mask_[address & 7]; break; #pragma mark - Writes @@ -91,8 +89,16 @@ class CartridgePitfall2: public Cartridge { } private: + inline uint16_t address_for_counter(int counter) { + uint16_t fetch_address = (featcher_address_[counter] & 2047) ^ 2047; + featcher_address_[counter]--; + if((featcher_address_[counter] & 0xff) == top_[counter]) mask_[counter] = 0xff; + if((featcher_address_[counter] & 0xff) == bottom_[counter]) mask_[counter] = 0x00; + return fetch_address; + } + uint16_t featcher_address_[8]; - uint8_t top_[8], bottom_[8]; + uint8_t top_[8], bottom_[8], mask_[8]; uint8_t music_mode_[3]; uint8_t random_number_generator_; uint8_t *rom_ptr_; From 4bb70e7d31efd7ff7e6ffa8ab978984c883d6163 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Mar 2017 18:49:37 -0400 Subject: [PATCH 07/12] Resetting the mask upon low byte write appears to resolve some issues. --- Machines/Atari2600/Cartridges/CartridgePitfall2.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index 1fed81ee1..cd7337d82 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -16,7 +16,8 @@ class CartridgePitfall2: public Cartridge { CartridgePitfall2(const std::vector &rom) : Cartridge(rom), random_number_generator_(0), - featcher_address_{0, 0, 0, 0, 0, 0, 0, 0} { + featcher_address_{0, 0, 0, 0, 0, 0, 0, 0}, + mask_{0, 0, 0, 0, 0, 0, 0, 0} { rom_ptr_ = rom_.data(); } @@ -51,9 +52,10 @@ class CartridgePitfall2: public Cartridge { *value = rom_[8192 + address_for_counter(address & 7)]; break; - case 0x1010: case 0x1011: case 0x1012: case 0x1013: case 0x1014: case 0x1015: case 0x1016: case 0x1017: - *value = rom_[8192 + address_for_counter(address & 7)] & mask_[address & 7]; - break; + case 0x1010: case 0x1011: case 0x1012: case 0x1013: case 0x1014: case 0x1015: case 0x1016: case 0x1017: { + uint8_t mask = mask_[address & 7]; + *value = rom_[8192 + address_for_counter(address & 7)] & mask; + } break; #pragma mark - Writes @@ -65,6 +67,7 @@ class CartridgePitfall2: public Cartridge { break; case 0x1050: case 0x1051: case 0x1052: case 0x1053: case 0x1054: case 0x1055: case 0x1056: case 0x1057: featcher_address_[address & 7] = (featcher_address_[address & 7] & 0xff00) | *value; + mask_[address & 7] = 0x00; break; case 0x1058: case 0x1059: case 0x105a: case 0x105b: case 0x105c: case 0x105d: case 0x105e: case 0x105f: featcher_address_[address & 7] = (featcher_address_[address & 7] & 0x00ff) | (uint16_t)(*value << 8); From 7d8d1c7828288ebc6b13c735b1327b80100c6680 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Mar 2017 18:54:35 -0400 Subject: [PATCH 08/12] Fixed 'random' number generator. --- Machines/Atari2600/Cartridges/CartridgePitfall2.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index cd7337d82..9ee414d7d 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -36,7 +36,7 @@ class CartridgePitfall2: public Cartridge { } random_number_generator_ = (uint8_t)( (random_number_generator_ << 1) | - ~(( (random_number_generator_ >> 7) ^ + (~( (random_number_generator_ >> 7) ^ (random_number_generator_ >> 5) ^ (random_number_generator_ >> 4) ^ (random_number_generator_ >> 3) From 4722f6b5c4933fe57b0024fbef007841c19b3239 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Mar 2017 18:58:35 -0400 Subject: [PATCH 09/12] =?UTF-8?q?Fixed=20sprite=20disappearance:=20test=20?= =?UTF-8?q?should=20be=20applied=20predecrement,=20not=20post=20=E2=80=94?= =?UTF-8?q?=20it=20relates=20to=20the=20address=20being=20used=20this=20ac?= =?UTF-8?q?cess,=20not=20the=20next=20one.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Machines/Atari2600/Cartridges/CartridgePitfall2.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index 9ee414d7d..269d91761 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -52,10 +52,9 @@ class CartridgePitfall2: public Cartridge { *value = rom_[8192 + address_for_counter(address & 7)]; break; - case 0x1010: case 0x1011: case 0x1012: case 0x1013: case 0x1014: case 0x1015: case 0x1016: case 0x1017: { - uint8_t mask = mask_[address & 7]; - *value = rom_[8192 + address_for_counter(address & 7)] & mask; - } break; + case 0x1010: case 0x1011: case 0x1012: case 0x1013: case 0x1014: case 0x1015: case 0x1016: case 0x1017: + *value = rom_[8192 + address_for_counter(address & 7)] & mask_[address & 7]; + break; #pragma mark - Writes @@ -94,9 +93,9 @@ class CartridgePitfall2: public Cartridge { private: inline uint16_t address_for_counter(int counter) { uint16_t fetch_address = (featcher_address_[counter] & 2047) ^ 2047; - featcher_address_[counter]--; if((featcher_address_[counter] & 0xff) == top_[counter]) mask_[counter] = 0xff; if((featcher_address_[counter] & 0xff) == bottom_[counter]) mask_[counter] = 0x00; + featcher_address_[counter]--; return fetch_address; } From f3f4e1a541320820a71390a0a034478f2d2b56d8 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 20 Mar 2017 19:35:51 -0400 Subject: [PATCH 10/12] Made a first, hacky, attempt at audio. --- .../Cartridges/CartridgePitfall2.hpp | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index 269d91761..5769c30f9 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -17,11 +17,13 @@ class CartridgePitfall2: public Cartridge { Cartridge(rom), random_number_generator_(0), featcher_address_{0, 0, 0, 0, 0, 0, 0, 0}, - mask_{0, 0, 0, 0, 0, 0, 0, 0} { + mask_{0, 0, 0, 0, 0, 0, 0, 0}, + cycles_since_audio_update_(0) { rom_ptr_ = rom_.data(); } void perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { + cycles_since_audio_update_++; address &= 0x1fff; if(!(address & 0x1000)) return; @@ -43,9 +45,9 @@ class CartridgePitfall2: public Cartridge { ) & 1)); break; - // Music fetcher case 0x1005: case 0x1006: case 0x1007: - *value = 0x00; + *value = update_audio(); + printf("%01x ", *value); break; case 0x1008: case 0x1009: case 0x100a: case 0x100b: case 0x100c: case 0x100d: case 0x100e: case 0x100f: @@ -99,11 +101,29 @@ class CartridgePitfall2: public Cartridge { return fetch_address; } + inline uint8_t update_audio() { + unsigned int cycles_to_run_for = cycles_since_audio_update_ / 57; + cycles_since_audio_update_ %= 57; + + int table_position = 0; + for(int c = 0; c < 3; c++) { + audio_channel_[c] = (audio_channel_[c] + cycles_to_run_for) % (top_[5 + c] ^ 0xff); + if((featcher_address_[5 + c] & 0x1000) && ((audio_channel_[c] ^ 0xff) > bottom_[5 + c])) { + table_position |= 0x4 >> c; + } + } + + static uint8_t level_table[8] = { 0x0, 0x4, 0x5, 0x9, 0x6, 0xa, 0xb, 0xf }; + return level_table[table_position]; + } + uint16_t featcher_address_[8]; uint8_t top_[8], bottom_[8], mask_[8]; uint8_t music_mode_[3]; uint8_t random_number_generator_; uint8_t *rom_ptr_; + uint8_t audio_channel_[3]; + unsigned int cycles_since_audio_update_; }; } From 4c3cc42c915e542f7597666987d23d7f9c82d327 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 20 Mar 2017 20:38:29 -0400 Subject: [PATCH 11/12] This gives a very noisy version of the real audio. --- Machines/Atari2600/Cartridges/CartridgePitfall2.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index 5769c30f9..134b5e994 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -47,7 +47,6 @@ class CartridgePitfall2: public Cartridge { case 0x1005: case 0x1006: case 0x1007: *value = update_audio(); - printf("%01x ", *value); break; case 0x1008: case 0x1009: case 0x100a: case 0x100b: case 0x100c: case 0x100d: case 0x100e: case 0x100f: @@ -102,13 +101,14 @@ class CartridgePitfall2: public Cartridge { } inline uint8_t update_audio() { - unsigned int cycles_to_run_for = cycles_since_audio_update_ / 57; - cycles_since_audio_update_ %= 57; + const unsigned int clock_divisor = 57; + unsigned int cycles_to_run_for = cycles_since_audio_update_ / clock_divisor; + cycles_since_audio_update_ %= clock_divisor; int table_position = 0; for(int c = 0; c < 3; c++) { - audio_channel_[c] = (audio_channel_[c] + cycles_to_run_for) % (top_[5 + c] ^ 0xff); - if((featcher_address_[5 + c] & 0x1000) && ((audio_channel_[c] ^ 0xff) > bottom_[5 + c])) { + audio_channel_[c] = (audio_channel_[c] + cycles_to_run_for) % (1 + top_[5 + c]); + if((featcher_address_[5 + c] & 0x1000) && ((top_[5 + c] - audio_channel_[c]) > bottom_[5 + c])) { table_position |= 0x4 >> c; } } From a26b87f3483f7cff0ecd1e0d2bcb4d0805c9ec43 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 20 Mar 2017 20:44:03 -0400 Subject: [PATCH 12/12] Fixed: mistake was failure to count ready cycles. --- Machines/Atari2600/Cartridges/Cartridge.hpp | 2 ++ Machines/Atari2600/Cartridges/CartridgePitfall2.hpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Machines/Atari2600/Cartridges/Cartridge.hpp b/Machines/Atari2600/Cartridges/Cartridge.hpp index 8581270fe..37dbb30a7 100644 --- a/Machines/Atari2600/Cartridges/Cartridge.hpp +++ b/Machines/Atari2600/Cartridges/Cartridge.hpp @@ -24,6 +24,7 @@ template class Cartridge: void run_for_cycles(int number_of_cycles) { CPU6502::Processor>::run_for_cycles(number_of_cycles); } void set_reset_line(bool state) { CPU6502::Processor>::set_reset_line(state); } + void advance_cycles(unsigned int cycles) {} // to satisfy CPU6502::Processor unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { @@ -40,6 +41,7 @@ template class Cartridge: cycles_since_speaker_update_ += cycles_run_for; cycles_since_video_update_ += cycles_run_for; cycles_since_6532_update_ += (cycles_run_for / 3); + static_cast(this)->advance_cycles(cycles_run_for / 3); if(operation != CPU6502::BusOperation::Ready) { // give the cartridge a chance to respond to the bus access diff --git a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp index 134b5e994..5592f175b 100644 --- a/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp +++ b/Machines/Atari2600/Cartridges/CartridgePitfall2.hpp @@ -22,8 +22,11 @@ class CartridgePitfall2: public Cartridge { rom_ptr_ = rom_.data(); } + void advance_cycles(unsigned int cycles) { + cycles_since_audio_update_ += cycles; + } + void perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { - cycles_since_audio_update_++; address &= 0x1fff; if(!(address & 0x1000)) return;