Cleanup voltage requests

The `setVoltage()` function should be called even when `ENABLE_VSELECT` is disabled because `ENABLE_3V3FIX` also uses it. There is no resource cost to do this as when both options are disabled the compiler will optimize this function out. This just "future proofs" the code so if that function ever does more it doesn't need updated everywhere. This applies to `setup_FlashVoltage()` as well.

The changes to OSCR.cpp are just for code formatting and additional comments to clarify this.
This commit is contained in:
Ancyker 2023-06-26 15:25:54 -04:00
parent 9fb7af3f5b
commit 2cf7f5dbe7
28 changed files with 70 additions and 119 deletions

View File

@ -56,10 +56,8 @@ static const char arcMenuItem4[] PROGMEM = "Reset";
static const char* const menuOptionsARC[] PROGMEM = { arcMenuItem1, arcMenuItem2, arcMenuItem3, arcMenuItem4 }; static const char* const menuOptionsARC[] PROGMEM = { arcMenuItem1, arcMenuItem2, arcMenuItem3, arcMenuItem4 };
void setup_ARC() { void setup_ARC() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
// Arcadia 2001 uses A0-A13 [A14-A23 UNUSED] // Arcadia 2001 uses A0-A13 [A14-A23 UNUSED]

View File

@ -63,10 +63,8 @@ static const char atariMenuItem4[] PROGMEM = "Reset";
static const char* const menuOptionsATARI[] PROGMEM = { atariMenuItem1, atariMenuItem2, atariMenuItem3, atariMenuItem4 }; static const char* const menuOptionsATARI[] PROGMEM = { atariMenuItem1, atariMenuItem2, atariMenuItem3, atariMenuItem4 };
void setup_ATARI() { void setup_ATARI() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
// Atari 2600 uses A0-A12 [A13-A23 UNUSED] // Atari 2600 uses A0-A12 [A13-A23 UNUSED]

View File

@ -55,10 +55,8 @@ static const char colMenuItem3[] PROGMEM = "Set Size";
static const char* const menuOptionsCOL[] PROGMEM = { colMenuItem1, colMenuItem2, colMenuItem3, string_reset2 }; static const char* const menuOptionsCOL[] PROGMEM = { colMenuItem1, colMenuItem2, colMenuItem3, string_reset2 };
void setup_COL() { void setup_COL() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
// Colecovision uses A0-A14 [A15-A23 UNUSED] // Colecovision uses A0-A14 [A15-A23 UNUSED]

View File

@ -87,10 +87,8 @@ static const char fairchildMenuItem5[] PROGMEM = "Reset";
static const char* const menuOptionsFAIRCHILD[] PROGMEM = { fairchildMenuItem1, fairchildMenuItem2, fairchildMenuItem3, fairchildMenuItem4, fairchildMenuItem5 }; static const char* const menuOptionsFAIRCHILD[] PROGMEM = { fairchildMenuItem1, fairchildMenuItem2, fairchildMenuItem3, fairchildMenuItem4, fairchildMenuItem5 };
void setup_FAIRCHILD() { void setup_FAIRCHILD() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
// Channel F uses A0-A4 [A5-A23 UNUSED] // Channel F uses A0-A4 [A5-A23 UNUSED]

View File

@ -680,7 +680,7 @@ void id_Flash16() {
/****************************************** /******************************************
Setup Setup
*****************************************/ *****************************************/
#ifdef ENABLE_VSELECT #if defined(ENABLE_VSELECT) || defined(ENABLE_3V3FIX)
static const char flashvoltItem1[] PROGMEM = "3.3V"; static const char flashvoltItem1[] PROGMEM = "3.3V";
static const char flashvoltItem2[] PROGMEM = "5V"; static const char flashvoltItem2[] PROGMEM = "5V";
//static const char flashvoltItem3[] PROGMEM = "Reset"; (stored in common strings array) //static const char flashvoltItem3[] PROGMEM = "Reset"; (stored in common strings array)
@ -696,12 +696,12 @@ void setup_FlashVoltage() {
// wait for user choice to come back from the question box menu // wait for user choice to come back from the question box menu
switch (flashvolt) { switch (flashvolt) {
case 0: case 0:
// Set Automatic Voltage Selection to 3V // Request 3.3V
setVoltage(VOLTS_SET_3V3); setVoltage(VOLTS_SET_3V3);
break; break;
case 1: case 1:
// Set Automatic Voltage Selection to 5V // Request 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
break; break;
@ -710,6 +710,9 @@ void setup_FlashVoltage() {
break; break;
} }
} }
#else
// The compiler will optimize this out when this condition is met.
void setup_FlashVoltage() {}
#endif #endif
void setup_Flash8() { void setup_Flash8() {

View File

@ -370,10 +370,8 @@ void gbMenu() {
Setup Setup
*****************************************/ *****************************************/
void setup_GB() { void setup_GB() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
//A0-A7 //A0-A7

View File

@ -246,10 +246,8 @@ void gbaMenu() {
Setup Setup
*****************************************/ *****************************************/
void setup_GBA() { void setup_GBA() {
#ifdef ENABLE_VSELECT // Request 3.3V
// Set Automatic Voltage Selection to 3V
setVoltage(VOLTS_SET_3V3); setVoltage(VOLTS_SET_3V3);
#endif
setROM_GBA(); setROM_GBA();

View File

@ -184,10 +184,8 @@ void gbmMenu() {
Setup Setup
*****************************************/ *****************************************/
void setup_GBM() { void setup_GBM() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set RST(PH0) to Input // Set RST(PH0) to Input
DDRH &= ~(1 << 0); DDRH &= ~(1 << 0);

View File

@ -109,10 +109,8 @@ byte readByte_GBS(word myAddress) {
} }
void setup_GBSmart() { void setup_GBSmart() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// take from setup_GB // take from setup_GB
// Set RST(PH0) to Input // Set RST(PH0) to Input

View File

@ -99,10 +99,8 @@ static const char intvMenuItem3[] PROGMEM = "Set Mapper + Size";
static const char* const menuOptionsINTV[] PROGMEM = { intvMenuItem1, intvMenuItem2, intvMenuItem3, string_reset2 }; static const char* const menuOptionsINTV[] PROGMEM = { intvMenuItem1, intvMenuItem2, intvMenuItem3, string_reset2 };
void setup_INTV() { void setup_INTV() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output (UNUSED) // Set Address Pins to Output (UNUSED)
//A0-A7 //A0-A7

View File

@ -463,10 +463,8 @@ void segaCDMenu() {
Setup Setup
*****************************************/ *****************************************/
void setup_MD() { void setup_MD() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
#ifdef use_md_conf #ifdef use_md_conf
mdLoadConf(); mdLoadConf();

View File

@ -181,10 +181,8 @@ void msxMenu() {
// SETUP // SETUP
//****************************************** //******************************************
void setup_MSX() { void setup_MSX() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
// MSX uses A0-A15 // MSX uses A0-A15

View File

@ -399,10 +399,8 @@ void n64CartMenu() {
Setup Setup
*****************************************/ *****************************************/
void setup_N64_Controller() { void setup_N64_Controller() {
#ifdef ENABLE_VSELECT // Request 3.3V
// Set Automatic Voltage Selection to 3V
setVoltage(VOLTS_SET_3V3); setVoltage(VOLTS_SET_3V3);
#endif
// Output a low signal // Output a low signal
PORTH &= ~(1 << 4); PORTH &= ~(1 << 4);
@ -411,10 +409,8 @@ void setup_N64_Controller() {
} }
void setup_N64_Cart() { void setup_N64_Cart() {
#ifdef ENABLE_VSELECT // Request 3.3V
// Set Automatic Voltage Selection to 3V
setVoltage(VOLTS_SET_3V3); setVoltage(VOLTS_SET_3V3);
#endif
// Set Address Pins to Output and set them low // Set Address Pins to Output and set them low
//A0-A7 //A0-A7

View File

@ -418,10 +418,8 @@ void nesChipMenu() {
Setup Setup
*****************************************/ *****************************************/
void setup_NES() { void setup_NES() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// CPU R/W, IRQ, PPU /RD, PPU /A13, CIRAM /CE, PPU /WR, /ROMSEL, PHI2 // CPU R/W, IRQ, PPU /RD, PPU /A13, CIRAM /CE, PPU /WR, /ROMSEL, PHI2
DDRF = 0b10110111; DDRF = 0b10110111;

View File

@ -21,10 +21,8 @@ uint8_t manufacturerID;
uint8_t deviceID; uint8_t deviceID;
void setup_NGP() { void setup_NGP() {
#ifdef ENABLE_VSELECT // Request 3.3V
// Set Automatic Voltage Selection to 3V
setVoltage(VOLTS_SET_3V3); setVoltage(VOLTS_SET_3V3);
#endif
// A0 - A7 // A0 - A7
DDRF = 0xff; DDRF = 0xff;

View File

@ -69,10 +69,8 @@ static const char ody2MenuItem4[] PROGMEM = "Reset";
static const char* const menuOptionsODY2[] PROGMEM = { ody2MenuItem1, ody2MenuItem2, ody2MenuItem3, ody2MenuItem4 }; static const char* const menuOptionsODY2[] PROGMEM = { ody2MenuItem1, ody2MenuItem2, ody2MenuItem3, ody2MenuItem4 };
void setup_ODY2() { void setup_ODY2() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
// Odyssey 2 uses A0-A13 [A14-A23 UNUSED] // Odyssey 2 uses A0-A13 [A14-A23 UNUSED]

View File

@ -186,27 +186,27 @@ VOLTS setVoltage(VOLTS volts) {
) return VOLTS_SUCCESS; // Just return if already as requested ) return VOLTS_SUCCESS; // Just return if already as requested
// Adjust voltage high if VSELECT is available // Adjust voltage high if VSELECT is available
#if defined(ENABLE_VSELECT) #if defined(ENABLE_VSELECT)
PORTD &= ~(1 << 7); /*[1]*/ PORTD &= ~(1 << 7); /*[1]*/
voltage = VOLTS_SET_5V; voltage = VOLTS_SET_5V;
#endif #endif
// Adjust clock speed when 3V3FIX is enabled // Adjust clock speed when 3V3FIX is enabled
#if defined(ENABLE_3V3FIX) #if defined(ENABLE_3V3FIX)
// Stop serial if running // Stop serial if running
#if !defined(enable_serial) && defined(ENABLE_UPDATER) #if !defined(enable_serial) && defined(ENABLE_UPDATER)
ClockedSerial.end(); ClockedSerial.end();
#endif #endif
// Set clock speed // Set clock speed
clock = CS_16MHZ; clock = CS_16MHZ;
setClockScale(volts); /*[2]*/ setClockScale(volts); /*[2]*/
// Restart serial // Restart serial
#if !defined(enable_serial) && defined(ENABLE_UPDATER) #if !defined(enable_serial) && defined(ENABLE_UPDATER)
ClockedSerial.begin(UPD_BAUD); ClockedSerial.begin(UPD_BAUD);
#endif #endif
#else #else
clock = CS_16MHZ; clock = CS_16MHZ;
#endif #endif
// Done // Done
return VOLTS_SUCCESS; return VOLTS_SUCCESS;
@ -226,22 +226,23 @@ VOLTS setVoltage(VOLTS volts) {
) return VOLTS_SUCCESS; // Just return if already as requested ) return VOLTS_SUCCESS; // Just return if already as requested
// Adjust clock speed when 3V3FIX is enabled // Adjust clock speed when 3V3FIX is enabled
#if defined(ENABLE_3V3FIX) #if defined(ENABLE_3V3FIX)
#if !defined(enable_serial) && defined(ENABLE_UPDATER) #if !defined(enable_serial) && defined(ENABLE_UPDATER)
ClockedSerial.end(); ClockedSerial.end();
#endif #endif
clock = CS_8MHZ; // Set clock speed
setClockScale(volts); /*[2]*/ clock = CS_8MHZ;
#if !defined(enable_serial) && defined(ENABLE_UPDATER) setClockScale(volts); /*[2]*/
ClockedSerial.begin(UPD_BAUD); #if !defined(enable_serial) && defined(ENABLE_UPDATER)
#endif ClockedSerial.begin(UPD_BAUD);
#endif #endif
#endif
// Adjust voltage high if VSELECT is available // Adjust voltage high if VSELECT is available
#if defined(ENABLE_VSELECT) #if defined(ENABLE_VSELECT)
PORTD |= (1 << 7); /*[1]*/ PORTD |= (1 << 7); /*[1]*/
voltage = VOLTS_SET_3V3; voltage = VOLTS_SET_3V3;
#endif #endif
// Done // Done
return VOLTS_SUCCESS; return VOLTS_SUCCESS;
@ -252,6 +253,9 @@ VOLTS setVoltage(VOLTS volts) {
} }
} }
#else #else
// The compiler will optimize this out when this condition is met.
// Yes, even though it has a return value it will only be compiled
// if something reads that value. Currently nothing does.
VOLTS setVoltage(VOLTS volts __attribute__((unused))) { VOLTS setVoltage(VOLTS volts __attribute__((unused))) {
return VOLTS_NOTENABLED; return VOLTS_NOTENABLED;
} }

View File

@ -170,10 +170,8 @@ void pin_init_PCE(void) {
} }
void setup_cart_PCE(void) { void setup_cart_PCE(void) {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set cicrstPin(PG1) to Output // Set cicrstPin(PG1) to Output
DDRG |= (1 << 1); DDRG |= (1 << 1);

View File

@ -101,10 +101,8 @@ byte bank1;
//****************************************** //******************************************
void setup_PCW() { void setup_PCW() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
//A8-A15 //A8-A15

View File

@ -105,10 +105,8 @@ void pokeMenu() {
// SETUP // SETUP
//****************************************** //******************************************
void setup_POKE() { void setup_POKE() {
#ifdef ENABLE_VSELECT // Request 3.3V
// Set Automatic Voltage Selection to 3V
setVoltage(VOLTS_SET_3V3); setVoltage(VOLTS_SET_3V3);
#endif
// Set Address Pins to Output // Set Address Pins to Output
// Pokemon Mini uses A0-A9 (DUAL A10-A19) + A20 (CONNECT TO SNES A10) [A11-A23 UNUSED] // Pokemon Mini uses A0-A9 (DUAL A10-A19) + A20 (CONNECT TO SNES A10) [A11-A23 UNUSED]

View File

@ -524,10 +524,8 @@ void getGames(char gameCode[8][20], boolean* hasMenu, byte* numGames) {
Setup Setup
*****************************************/ *****************************************/
void setup_SFM() { void setup_SFM() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set cicrstPin(PG1) to Output // Set cicrstPin(PG1) to Output
DDRG |= (1 << 1); DDRG |= (1 << 1);

View File

@ -155,10 +155,8 @@ void smsOperations() {
// Setup I/O // Setup I/O
//******************************** //********************************
void setup_SMS() { void setup_SMS() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
//A0-A7 //A0-A7

View File

@ -172,9 +172,7 @@ void snsMenu() {
#ifdef enable_FLASH #ifdef enable_FLASH
case 3: case 3:
#ifdef ENABLE_VSELECT
setup_FlashVoltage(); setup_FlashVoltage();
#endif
reproMenu(); reproMenu();
break; break;
#endif #endif
@ -388,10 +386,8 @@ void stopSnesClocks_resetCic_resetCart() {
Setup Setup
*****************************************/ *****************************************/
void setup_Snes() { void setup_Snes() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set cicrstPin(PG1) to Output // Set cicrstPin(PG1) to Output
DDRG |= (1 << 1); DDRG |= (1 << 1);

View File

@ -17,10 +17,8 @@ static const char acanMenuItem6[] PROGMEM = "Flash repro";
static const char *const menuOptionsAcan[] PROGMEM = { acanMenuItem1, acanMenuItem2, acanMenuItem3, acanMenuItem4, acanMenuItem5, string_reset2, acanMenuItem6 }; static const char *const menuOptionsAcan[] PROGMEM = { acanMenuItem1, acanMenuItem2, acanMenuItem3, acanMenuItem4, acanMenuItem5, string_reset2, acanMenuItem6 };
void setup_SuprAcan() { void setup_SuprAcan() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// addr as output // addr as output
DDRF = 0xff; // A0 - A7 DDRF = 0xff; // A0 - A7

View File

@ -101,10 +101,8 @@ void svMenu() {
Setup Setup
*****************************************/ *****************************************/
void setup_SV() { void setup_SV() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set cicrstPin(PG1) to Output // Set cicrstPin(PG1) to Output
DDRG |= (1 << 1); DDRG |= (1 << 1);

View File

@ -56,10 +56,8 @@
//****************************************** //******************************************
void setup_VBOY() { void setup_VBOY() {
#ifdef ENABLE_VSELECT // Request 5V
// Set Automatic Voltage Selection to 5V
setVoltage(VOLTS_SET_5V); setVoltage(VOLTS_SET_5V);
#endif
// Set Address Pins to Output // Set Address Pins to Output
//A0-A7 //A0-A7

View File

@ -46,10 +46,8 @@ static uint8_t wsEepromShiftReg[2];
static boolean wsWitch = false; static boolean wsWitch = false;
void setup_WS() { void setup_WS() {
#ifdef ENABLE_VSELECT // Request 3.3V
// Set Automatic Voltage Selection to 3V
setVoltage(VOLTS_SET_3V3); setVoltage(VOLTS_SET_3V3);
#endif
// A-1 - A6 // A-1 - A6
DDRF = 0xff; DDRF = 0xff;

View File

@ -53,10 +53,8 @@ byte newwsvsize;
//****************************************** //******************************************
void setup_WSV() { void setup_WSV() {
#ifdef ENABLE_VSELECT // Request 3.3V
// Set Automatic Voltage Selection to 3V
setVoltage(VOLTS_SET_3V3); setVoltage(VOLTS_SET_3V3);
#endif
// Set Address Pins to Output // Set Address Pins to Output
//A0-A7 //A0-A7