From d825ebc99ea1e3b16f80cfc9ef0da74a269183be Mon Sep 17 00:00:00 2001 From: thrust26 Date: Tue, 11 Feb 2020 17:04:34 +0100 Subject: [PATCH] add two more methods for retrieving current values add Stella.pro for testing --- src/common/HighScoresManager.cxx | 106 ++++++++++++++++++++++--------- src/common/HighScoresManager.hxx | 5 ++ src/common/stella.pro | 101 +++++++++++++++++++++++++++++ 3 files changed, 183 insertions(+), 29 deletions(-) create mode 100644 src/common/stella.pro diff --git a/src/common/HighScoresManager.cxx b/src/common/HighScoresManager.cxx index 515eb966d..fbcfa4b55 100644 --- a/src/common/HighScoresManager.cxx +++ b/src/common/HighScoresManager.cxx @@ -33,6 +33,8 @@ - score swaps (Asteroids) */ +#include + #include "OSystem.hxx" #include "PropsSet.hxx" #include "Console.hxx" @@ -177,9 +179,9 @@ void HighScoresManager::set(Properties& props, uInt32 numPlayers, uInt32 numVari } // add optional addresses - if (numVariations > 1 || numPlayers > 1) + if (numVariations != DEFAULT_VARIATION || numPlayers != DEFAULT_PLAYER) buf << info.varsAddr << "," ; - if (numPlayers > 1) + if (numPlayers != DEFAULT_PLAYER) buf << info.playersAddr << "," ; output = buf.str(); @@ -264,6 +266,66 @@ uInt32 HighScoresManager::numAddrBytes(const Properties& props) const return numAddrBytes(numDigits(props), trailingZeroes(props)); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Int32 HighScoresManager::player(uInt16 addr, uInt32 numPlayers, bool zeroBased) const +{ + if (!myOSystem.hasConsole()) + return -1; + + Int32 player = peek(addr); + Int32 bits = ceil(log(numPlayers + (!zeroBased ? 1 : 0))/log(2)); + + // limit to game's number of players + player %= 1 << bits; + player += zeroBased ? 1 : 0; + + return player; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Int32 HighScoresManager::player() const +{ + Properties props; + uInt16 addr = playerAddress(properties(props)); + + if (addr == DEFAULT_ADDRESS) + return DEFAULT_PLAYER; + + return player(addr, numPlayers(props), playerZeroBased(props)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Int32 HighScoresManager::variation(uInt16 addr, bool varBCD, bool zeroBased, + uInt32 numVariations) const +{ + if (!myOSystem.hasConsole()) + return -1; + + Int32 var = peek(addr); + Int32 bits = ceil(log(numVariations + (!zeroBased ? 1 : 0))/log(2)); + + if (varBCD) + var = fromBCD(var); + + // limit to game's number of variations + var %= 1 << bits; + var += zeroBased ? 1 : 0; + + return var; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Int32 HighScoresManager::variation() const +{ + Properties props; + uInt16 addr = varAddress(properties(props)); + + if (addr == DEFAULT_ADDRESS) + return DEFAULT_VARIATION; + + return variation(addr, varBCD(props), varZeroBased(props), numVariations(props)); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Int32 HighScoresManager::score(uInt32 player, uInt32 numAddrBytes, uInt32 trailingZeroes, bool isBCD, const ScoreAddresses& scoreAddr) const @@ -282,11 +344,10 @@ Int32 HighScoresManager::score(uInt32 player, uInt32 numAddrBytes, uInt32 traili score = peek(addr); if (isBCD) { + score = fromBCD(score); // verify if score is legit - if (score >= 160) + if (score == -1) return -1; - - score = (score >> 4) * 10 + score % 16; } totalScore += score; } @@ -298,36 +359,13 @@ Int32 HighScoresManager::score(uInt32 player, uInt32 numAddrBytes, uInt32 traili return totalScore; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Int32 HighScoresManager::player() const -{ - Properties props; - uInt16 addr = playerAddress(properties(props)); - - if (addr == DEFAULT_ADDRESS) - return DEFAULT_PLAYER; - - return peek(addr) + playerZeroBased(props) ? 1 : 0; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Int32 HighScoresManager::variation() const -{ - Properties props; - uInt16 addr = varAddress(properties(props)); - - if (addr == DEFAULT_ADDRESS) - return DEFAULT_VARIATION; - - return peek(addr) + varZeroBased(props) ? 1 : 0; -} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Int32 HighScoresManager::score() const { Properties props; uInt32 numBytes = numAddrBytes(properties(props)); - uInt32 currentPlayer = player() - playerZeroBased(props) ? 1 : 0; + uInt32 currentPlayer = player() - (playerZeroBased(props) ? 1 : 0); uInt32 idx = numBytes * currentPlayer; ScoreAddresses scoreAddr; @@ -342,3 +380,13 @@ Int32 HighScoresManager::score() const return score(currentPlayer, numBytes, trailingZeroes(props), scoreBCD(props), scoreAddr); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Int32 HighScoresManager::fromBCD(uInt8 bcd) const +{ + // verify if score is legit + if (bcd >= 160) + return -1; + + return (bcd >> 4) * 10 + bcd % 16; +} diff --git a/src/common/HighScoresManager.hxx b/src/common/HighScoresManager.hxx index 08b1533ad..5dd2f9062 100644 --- a/src/common/HighScoresManager.hxx +++ b/src/common/HighScoresManager.hxx @@ -84,6 +84,9 @@ class HighScoresManager */ uInt32 numAddrBytes(Int32 digits, Int32 trailing) const; + // Retrieve current values from (using given parameters) + Int32 player(uInt16 addr, uInt32 numPlayers, bool zeroBased = true) const; + Int32 variation(uInt16 addr, bool varBCD, bool zeroBased, uInt32 numVariations) const; /** Calculate the score from given parameters @@ -132,6 +135,8 @@ class HighScoresManager // Peek into memory Int16 peek(uInt16 addr) const; + Int32 fromBCD(uInt8 bcd) const; + private: // Reference to the osystem object OSystem& myOSystem; diff --git a/src/common/stella.pro b/src/common/stella.pro new file mode 100644 index 000000000..a6cb54616 --- /dev/null +++ b/src/common/stella.pro @@ -0,0 +1,101 @@ +"Cart.MD5" "278f14887d601b5e5b620f1870bc09f6" +"Cart.Manufacturer" "Thomas Jentzsch" +"Cart.Name" "SWOOPS! (v0.96) (TJ)" +"Cart.Note" "Uses the Joystick (L) and Paddle (R) Controllers" +"Cart.Rarity" "Homebrew" +"Cart.Variations" "4" +"Cart.Formats" "6,0,B,B,1" +"Cart.Addresses" "FD,FE,FF,FC" +"" + +"Cart.MD5" "72ffbef6504b75e69ee1045af9075f66" +"Cart.Manufacturer" "Atari, Richard Maurer - Sears" +"Cart.ModelNo" "CX2632 - 49-75153" +"Cart.Name" "Space Invaders (1980) (Atari)" +"Cart.Variations" "112" +"Cart.Formats" "4,0,B,H,1" +"Cart.Addresses" "E6,E8,DC" +"" + +"Cart.MD5" "91c2098e88a6b13f977af8c003e0bca5" +"Cart.Manufacturer" "Atari - GCC" +"Cart.ModelNo" "CX2676" +"Cart.Name" "Centipede (1983) (Atari)" +"Cart.Formats" "6" +"Cart.Addresses" "F4,F5,F6" +"" + +"Cart.MD5" "9ad36e699ef6f45d9eb6c4cf90475c9f" +"Cart.Manufacturer" "Imagic, Dennis Koble" +"Cart.ModelNo" "720103-1A, 720103-1B, IA3203, IX-010-04" +"Cart.Name" "Atlantis (1982) (Imagic)" +"Cart.Note" "AKA Lost City of Atlantis" +"Cart.Rarity" "Uncommon" +"Cart.Variations" "4" +"Cart.Formats" "6,2,B,B,1" +"Cart.Addresses" "A3,A2,8D" +"" + +"Cart.MD5" "ab5bf1ef5e463ad1cbb11b6a33797228" +"Cart.Manufacturer" "Imagic, Rob Fulop" +"Cart.ModelNo" "720104-1A, 720104-1B, IA3204" +"Cart.Name" "Cosmic Ark (1982) (Imagic)" +"Cart.Variations" "6" +"Cart.Formats" "6" +"Cart.Addresses" "AE,B0,B2,BC" +"" + +"Cart.MD5" "c1cb228470a87beb5f36e90ac745da26" +"Cart.Manufacturer" "Activision, Bob Whitehead" +"Cart.ModelNo" "AX-015, AX-015-04" +"Cart.Name" "Chopper Command (1982) (Activision)" +"Cart.Players" "2" +"Cart.Variations" "4" +"Cart.Formats" "6,0,B,B,1" +"Cart.Addresses" "EC,EE,F0,ED,EF,F1,E0,EB" +"" + +"Cart.MD5" "ccbd36746ed4525821a8083b0d6d2c2c" +"Cart.Manufacturer" "Atari, Brad Stewart - Sears" +"Cart.ModelNo" "CX2649, 49-75163" +"Cart.Name" "Asteroids (1981) (Atari) [no copyright]" +"Cart.Rarity" "Common" +"Display.Phosphor" "YES" +"Cart.Players" "2" +"Cart.Variations" "66" +"Cart.Formats" "5,1,B,D,0" +"Cart.Addresses" "BD,BE,C0,C1,80,C7" +"" + +"Cart.MD5" "dd7884b4f93cab423ac471aa1935e3df" +"Cart.Manufacturer" "Atari, Brad Stewart - Sears" +"Cart.ModelNo" "CX2649, 49-75163" +"Cart.Name" "Asteroids (1981) (Atari)" +"Cart.Players" "2" +"Cart.Variations" "66" +"Cart.Formats" "5,1,B,D,0" +"Cart.Addresses" "BD,BE,C0,C1,80,C7" +"" + +"Cart.MD5" "f1489e27a4539a0c6c8529262f9f7e18" +"Cart.Manufacturer" "Champ Games" +"Cart.ModelNo" "CG-01-P" +"Cart.Name" "Lady Bug (PAL60)" +"Cart.Rarity" "Homebrew" +"Console.RightDiff" "A" +"Display.Format" "PAL60" +"Display.Phosphor" "YES" +"Cart.Variations" "3" +"Cart.Formats" "6,0,B,B,1" +"Cart.Addresses" "8E,8D,8C,8A" +"" + +"Cart.MD5" "fca4a5be1251927027f2c24774a02160" +"Cart.Manufacturer" "Activision, John Van Ryzin" +"Cart.ModelNo" "AZ-036-04" +"Cart.Name" "H.E.R.O. (1984) (Activision)" +"Cart.Variations" "5" +"Cart.Formats" "6,0,B,B,1" +"Cart.Addresses" "B7,B8,B9,B4" +"" +