Skip to content

Commit

Permalink
Let ROMs set their default mode. Default implementation returns the f…
Browse files Browse the repository at this point in the history
…irst mode in the available mode list
  • Loading branch information
Alejandro Dubrovsky authored and mgbellemare committed Aug 25, 2020
1 parent 3343d62 commit d3f2b25
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/environment/stella_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ StellaEnvironment::StellaEnvironment(OSystem* osystem, RomSettings* settings)
m_num_reset_steps = 4;
m_cartridge_md5 = m_osystem->console().properties().get(Cartridge_MD5);

// Set current mode to the ROM's default mode
m_state.setCurrentMode(settings->getDefaultMode());

m_max_num_frames_per_episode =
m_osystem->settings().getInt("max_num_frames_per_episode");
m_colour_averaging = m_osystem->settings().getBool("color_averaging");
Expand Down
10 changes: 10 additions & 0 deletions src/games/RomSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ void RomSettings::setMode(game_mode_t m, System&, std::unique_ptr<StellaEnvironm
}
}

game_mode_t RomSettings::getDefaultMode() {
// By default, return the first available mode, or 0 if none are listed
ModeVect available_modes = getAvailableModes();
if (available_modes.empty()) {
return 0;
} else {
return available_modes[0];
}
}

DifficultyVect RomSettings::getAvailableDifficulties() {
return DifficultyVect(1, 0);
}
Expand Down
3 changes: 3 additions & 0 deletions src/games/RomSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class RomSettings {
game_mode_t, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment);

// Return the default mode for the game.
virtual game_mode_t getDefaultMode();

// Returns a list of difficulties that the game can be played in.
// By default, there is only one available difficulty.
virtual DifficultyVect getAvailableDifficulties();
Expand Down
3 changes: 0 additions & 3 deletions src/games/supported/AirRaid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ ModeVect AirRaidSettings::getAvailableModes() {
void AirRaidSettings::setMode(
game_mode_t m, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment) {
if (m == 0) {
m = 1; // the default mode is not valid in this game
}
if (m >= 1 && m <= getNumModes()) {
//open the mode selection panel
environment->pressSelect(20);
Expand Down
3 changes: 0 additions & 3 deletions src/games/supported/BattleZone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ ModeVect BattleZoneSettings::getAvailableModes() {
void BattleZoneSettings::setMode(
game_mode_t m, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment) {
if (m == 0) {
m = 1; // the default mode is not valid here
}
if (m >= 1 && m <= 3) {
// read the mode we are currently in
unsigned char mode = readRam(&system, 0xA1);
Expand Down
3 changes: 0 additions & 3 deletions src/games/supported/Berzerk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ ModeVect BerzerkSettings::getAvailableModes() {
void BerzerkSettings::setMode(
game_mode_t m, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment) {
if (m == 0) {
m = 1; // The mode 0, which is the default, is not available in this game.
}
if (m >= 1 && (m <= 9 || m == 0x10 || m == 0x11 || m == 0x12)) {
// we wait that the game is ready to change mode
for (unsigned int i = 0; i < 20; i++) {
Expand Down
3 changes: 0 additions & 3 deletions src/games/supported/Centipede.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ ModeVect CentipedeSettings::getAvailableModes() {
void CentipedeSettings::setMode(
game_mode_t m, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment) {
if (m == 0) {
m = 0x16; // The default mode doesn't work here.
}
if (m == 0x16 || m == 0x56) {
// read the mode we are currently in
unsigned char mode = readRam(&system, 0xA7);
Expand Down
3 changes: 0 additions & 3 deletions src/games/supported/Defender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ ModeVect DefenderSettings::getAvailableModes() {
void DefenderSettings::setMode(
game_mode_t m, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment) {
if (m == 0) {
m = 1; // The default mode (0) is not valid here.
}
if (m >= 1 && (m <= 9 || m == 16)) {
// read the mode we are currently in
unsigned char mode = readRam(&system, 0x9B);
Expand Down
3 changes: 0 additions & 3 deletions src/games/supported/DemonAttack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ ModeVect DemonAttackSettings::getAvailableModes() {
void DemonAttackSettings::setMode(
game_mode_t m, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment) {
if (m == 0) {
m = 1; // The default mode is not valid here
}
if (m == 1 || m == 3 || m == 5 || m == 7) {
// read the mode we are currently in
unsigned char mode = readRam(&system, 0xEA);
Expand Down
3 changes: 0 additions & 3 deletions src/games/supported/Galaxian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ ModeVect GalaxianSettings::getAvailableModes() {
void GalaxianSettings::setMode(
game_mode_t mode, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment) {
if (mode == 0)
mode = 1;

if (mode >= 1 && mode <= 9) {
// press select until the correct mode is reached
while (mode != static_cast<unsigned>(readRam(&system, 0xB3))) {
Expand Down
3 changes: 0 additions & 3 deletions src/games/supported/NameThisGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ ModeVect NameThisGameSettings::getAvailableModes() {
void NameThisGameSettings::setMode(
game_mode_t m, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment) {
if (m == 0) {
m = 0x08; // the default mode is not valid here
}
if (m == 0x08 || m == 0x18 || m == 0x28) {
// read the mode we are currently in
unsigned char mode = readRam(&system, 0xDE);
Expand Down
3 changes: 0 additions & 3 deletions src/games/supported/Pooyan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ ModeVect PooyanSettings::getAvailableModes() {
void PooyanSettings::setMode(
game_mode_t m, System& system,
std::unique_ptr<StellaEnvironmentWrapper> environment) {
if (m == 0) {
m = 0x0A; // The default mode (0) is not valid here.
}
if (m == 0x0A || m == 0x1E || m == 0x32 || m == 0x46) {
environment->pressSelect(2);
// read the mode we are currently in
Expand Down

0 comments on commit d3f2b25

Please sign in to comment.