diff --git a/PSNee/MCU.h b/PSNee/MCU.h index c39cd77..00a1af5 100644 --- a/PSNee/MCU.h +++ b/PSNee/MCU.h @@ -208,12 +208,12 @@ #endif - #if defined(PSNEEDEBUG) - #define DEBUG_PRINT(x) Serial.print(x) - #define DEBUG_PRINTHEX(x) Serial.print(x, HEX) - #define DEBUG_PRINTLN(x) Serial.println(x) - #define DEBUG_FLUSH Serial.flush() - #endif + // #if defined(PSNEE_DEBUG_SERIAL_MONITOR) + // #define DEBUG_PRINT(x) Serial.print(x) + // #define DEBUG_PRINTHEX(x) Serial.print(x, HEX) + // #define DEBUG_PRINTLN(x) Serial.println(x) + // #define DEBUG_FLUSH Serial.flush() + // #endif #endif @@ -374,13 +374,13 @@ #error "ATtiny85_45_25 Not compatible with BIOS patch" #endif - #if defined(PSNEEDEBUG) + #if defined(PSNEE_DEBUG_SERIAL_MONITOR) #include SoftwareSerial mySerial(-1, 3); // RX, TX. (RX -1 = off) - #define DEBUG_PRINT(x) mySerial.print(x) - #define DEBUG_PRINTHEX(x) mySerial.print(x, HEX) - #define DEBUG_PRINTLN(x) mySerial.println(x) - #define DEBUG_FLUSH mySerial.flush() + // #define DEBUG_PRINT(x) mySerial.print(x) + // #define DEBUG_PRINTHEX(x) mySerial.print(x, HEX) + // #define DEBUG_PRINTLN(x) mySerial.println(x) + // #define DEBUG_FLUSH mySerial.flush() #endif #endif diff --git a/PSNee/PSNee.ino b/PSNee/PSNee.ino index ba08e53..633a2f2 100644 --- a/PSNee/PSNee.ino +++ b/PSNee/PSNee.ino @@ -6,21 +6,20 @@ // No BIOS patching. // You can use injection via USB. -// // HYSTERESIS | region | -//------------------------------------------------------------------------------------------------- -//#define SCPH_xxxx_15 // 15 | All | mode works the same as V7. -#define SCPH_xxxx_25 // 25 | All | Only FAT! For models with problematic CD players. -//#define SCPH_xxx1_15 // 15 | NTSC U/C | America. -//#define SCPH_xxx1_25 // 25 | NTSC U/C | America only FAT! For models with problematic CD players. -//#define SCPH_xxx2_15 // 15 | PAL | Europ. -//#define SCPH_xxx2_25 // 25 | PAL | Europ only FAT! For models with problematic CD players. -//#define SCPH_xxx3_15 // 15 | NTSC J | Asia. -//#define SCPH_xxx3_25 // 25 | NTSC J | Asia only FAT! For models with problematic CD players. +// SCPH model number // region code | region +//------------------------------------------------------------------------------------------------- +//#define SCPH_xxx1 // NTSC U/C | America. +//#define SCPH_xxx2 // PAL | Europ. +//#define SCPH_xxx3 // NTSC J | Asia. +//#define SCPH_xxxx // | All mode works the same as V7, but that's not what I recommend the most. // Models that require a BIOS patch. -// | Adres pin | +// It is only possible to inject the code via ISP! +// The delay in starting up caused by the bootloader of the Arduino cards prevents the injection of the BIOS patch within the delay, +// that's why you have to use the ISP which eliminates the bootloader. +// | Adres pin | // SCPH model number // Data pin | 32-pin BIOS | 40-pin BIOS | BIOS version //------------------------------------------------------------------------------------------------- //#define SCPH_102 // DX - D0 | AX - A7 | | 4.4e - CRC 0BAD7EA9, 4.5e -CRC 76B880E5 @@ -44,7 +43,7 @@ // MCU // Arduino //------------------------------------------------------------------------------------------------ -#define ATmega328_168 // Nano, Pro Mini, Uno +//#define ATmega328_168 // Nano, Pro Mini, Uno //#define ATmega32U4_16U4 // Micro, Pro Micro //#define ATtiny85_45_25 // ATtiny @@ -58,23 +57,18 @@ //#define PATCH_SWITCH // Enables hardware support for disabling BIOS patching. // With SCPH_7000 - 9000 models, Bios 4.0j, the bios patch prevents reading memory cards in the console interface, and in some cases can cause a crash (No problem in game). // In rare cases where the BIOS patch prevents the playback of original games. -#define PSNEEDEBUG -//------------------------------------------------------------------------------------------------ -// Make your own sauce -//------------------------------------------------------------------------------------------------ -// Here you can have fun making your ideal mode, you just have to choose a region, and a duration of histeresis. +//#define PSNEE_DEBUG_SERIAL_MONITOR // Enables serial monitor output. +// For Arduino connect TXD and GND, for ATtiny PB3 (pin 2) and GND, to your serial card RXD and GND. +// Arduino | ATtiny +// --------------------- +// TXD--RXD | PB3--RXD +// GND--GND | GND--GND -// Region //------------------------------------------------------------------------------------------------ -//#define SCEA // NTSC U/C -//#define SCEE // PAL -//#define SCEI // NTSC J -//#define All // All regions - // Hysteresis //------------------------------------------------------------------------------------------------ -//#define HYSTERESIS_MAX 15 // All model +#define HYSTERESIS_MAX 15 // All model //#define HYSTERESIS_MAX 25 // Only FAT! For models with problematic CD players. //------------------------------------------------------------------------------------------------ @@ -86,8 +80,8 @@ Fuses MCU | High | Low | Extended -------------------------------------------------- - ATmega | DF | EE | FD - ATtiny | DF | E2 | FD + ATmega | DF | EE | FF + ATtiny | DF | E2 | FF Pinout Arduino | PSNee | @@ -103,18 +97,18 @@ D7 | SUBQ | D8 | DATA | D9 | GATE_WFCK | - D13 - D10 | LED | D10 for ATmega32U4_16U4 + D13 ^ D10 | LED | D10 only for ATmega32U4_16U4 - ATtiny | PSNee | ISP + ATtiny | PSNee | ISP | --------------------------------------------------- - Pin1 | | RESET - Pin2 | LED | - Pin3 | WFCK | - Pin4 | GND | GND - Pin5 | SQCK | MOSI - Pin6 | SUBQ | MISO - Pin7 | DATA | SCK - Pin8 | VCC | VCC + Pin1 | | RESET | + Pin2 | LED ^ serial | | serial only for PSNEE_DEBUG_SERIAL_MONITOR + Pin3 | WFCK | | + Pin4 | GND | GND | + Pin5 | SQCK | MOSI | + Pin6 | SUBQ | MISO | + Pin7 | DATA | SCK | + Pin8 | VCC | VCC | */ @@ -130,8 +124,6 @@ #define DELAY_BETWEEN_BITS 4000 // 250 bits/s (microseconds) (ATtiny 8Mhz works from 3950 to 4100) PU-23 PU-22 MAX 4250 MIN 3850 #define DELAY_BETWEEN_INJECTIONS 90 // The sweet spot is around 80~100. For all observed models, the worst minimum time seen is 72, and it works well up to 250. -#define N_T_S 12 - //Creation of the different variables for the counter volatile uint8_t count_isr = 0; volatile uint32_t microsec = 0; @@ -361,10 +353,10 @@ void Init() { PIN_SQCK_INPUT; PIN_SUBQ_INPUT; -#if defined(PSNEEDEBUG) && defined(ATtiny85_45_25) +#if defined(PSNEE_DEBUG_SERIAL_MONITOR) && defined(ATtiny85_45_25) pinMode(debugtx, OUTPUT); // software serial tx pin mySerial.begin(115200); // 13,82 bytes in 12ms, max for softwareserial. (expected data: ~13 bytes / 12ms) // update: this is actually quicker -#elif defined(PSNEEDEBUG) && !defined(ATtiny85_45_25) +#elif defined(PSNEE_DEBUG_SERIAL_MONITOR) && !defined(ATtiny85_45_25) Serial.begin(500000); // 60 bytes in 12ms (expected data: ~26 bytes / 12ms) // update: this is actually quicker // DEBUG_PRINT("MCU frequency: "); DEBUG_PRINT(F_CPU); DEBUG_PRINTLN(" Hz"); // DEBUG_PRINTLN("Waiting for SQCK.."); @@ -373,7 +365,7 @@ void Init() { int main() { uint8_t hysteresis = 0; - uint8_t scbuf[N_T_S] = { 0 }; // SUBQ bit storage + uint8_t scbuf[12] = { 0 }; // SUBQ bit storage uint16_t timeout_clock_counter = 0; uint8_t bitbuf = 0; uint8_t bitpos = 0; @@ -427,7 +419,7 @@ int main() { wfck_mode = 0; //flag oldmod } -#if defined(PSNEEDEBUG) +#if defined(PSNEE_DEBUG_SERIAL_MONITOR) Debug_Log(lows, wfck_mode); #endif @@ -476,28 +468,9 @@ int main() { - // log SUBQ packets. We only have 12ms to get the logs written out. Slower MCUs get less formatting. -#if defined(PSNEEDEBUG) && defined(ATtiny85_45_25) - if (!(scbuf[0] == 0 && scbuf[1] == 0 && scbuf[2] == 0 && scbuf[3] == 0)) { // a bad sector read is all 0 except for the CRC fields. Don't log it. - for (int i = 0; i < 12; i++) { - if (scbuf[i] < 0x10) { - DEBUG_PRINT("0"); // padding - } - DEBUG_PRINTHEX(scbuf[i]); - } - DEBUG_PRINTLN(""); - } -#elif defined(PSNEEDEBUG) && !defined(ATtiny85_45_25) - if (!(scbuf[0] == 0 && scbuf[1] == 0 && scbuf[2] == 0 && scbuf[3] == 0)) { - for (int i = 0; i < 12; i++) { - if (scbuf[i] < 0x10) { - DEBUG_PRINT("0"); // padding - } - DEBUG_PRINTHEX(scbuf[i]); - DEBUG_PRINT(" "); - } - DEBUG_PRINTLN(""); - } + +#if defined(PSNEE_DEBUG_SERIAL_MONITOR) + Debug_Scbuf(scbuf); #endif //************************************************************************ @@ -572,11 +545,10 @@ int main() { PIN_LED_OFF; #endif -#if defined(PSNEEDEBUG) && defined(ATtiny85_45_25) - DEBUG_PRINTLN("!"); -#elif defined(PSNEEDEBUG) && !defined(ATtiny85_45_25) - DEBUG_PRINTLN(" INJECT ! "); +#if defined(PSNEE_DEBUG_SERIAL_MONITOR) + Debug_Inject(); #endif + } } } diff --git a/PSNee/settings.h b/PSNee/settings.h index ecd1134..c30d6fb 100644 --- a/PSNee/settings.h +++ b/PSNee/settings.h @@ -105,42 +105,43 @@ #define TRIGGER2 71 #endif -#if defined(SCEA) || defined(SCPH_xxx1_15) || defined(SCPH_xxx1_25) +#if defined(SCPH_xxx15) const char region[3] = {'a', 'a', 'a'}; #endif -#if defined(SCEE) || defined(SCPH_102) || defined(SCPH_xxx2_15) || defined(SCPH_xxx2_25) +#if defined(SCPH_102) || defined(SCPH_xxx2) const char region[3] = {'e', 'e', 'e'}; #endif -#if defined(SCPH_100) || defined(SCPH_7000_9000) || defined(SCPH_5500) || defined(SCPH_3500_5000) || defined(SCPH_3000) || defined(SCPH_1000) || defined(SCEI) || defined(SCPH_xxx3_15) || defined(SCPH_xxx3_25) +#if defined(SCPH_100) || defined(SCPH_7000_9000) || defined(SCPH_5500) || defined(SCPH_3500_5000) || defined(SCPH_3000) || defined(SCPH_1000) || defined(SCPH_xxx3) const char region[3] = {'i', 'i', 'i'}; #endif -#if defined(SCPH_xxxx) || defined(SCPH_xxxx_25) || defined(SCPH_102_legacy) || defined(All) +#if defined(SCPH_xxxx) const char region[3] = {'a', 'e', 'i'}; #endif //All models have bad behavior below 11, PU-41 can start to have bad behavior beyond 20, for fat models we can go up to 60 -#if defined(SCPH_102) || defined(SCPH_102_legacy) || defined(SCPH_xxxx) || defined(SCPH_xxx1_15) || defined(SCPH_xxx2_15) || defined(SCPH_xxx3_15) -#define HYSTERESIS_MAX 15 -#endif +// #if defined(SCPH_102) || defined(SCPH_102_legacy) || defined(SCPH_xxxx) || defined(SCPH_xxx1_15) || defined(SCPH_xxx2_15) || defined(SCPH_xxx3_15) +// #define HYSTERESIS_MAX 15 +// #endif -#if defined(SCPH_7000_9000) || defined(SCPH_5500) || defined(SCPH_3500_5000) || defined(SCPH_3000) || defined(SCPH_1000) || defined(SCPH_xxxx_25) || defined(SCPH_xxx1_25) || defined(SCPH_xxx2_25) || defined(SCPH_xxx3_25) -#define HYSTERESIS_MAX 25 -#endif +// #if defined(SCPH_7000_9000) || defined(SCPH_5500) || defined(SCPH_3500_5000) || defined(SCPH_3000) || defined(SCPH_1000) || defined(SCPH_xxxx_25) || defined(SCPH_xxx1_25) || defined(SCPH_xxx2_25) || defined(SCPH_xxx3_25) +// #define HYSTERESIS_MAX 25 +// #endif +#if defined(PSNEE_DEBUG_SERIAL_MONITOR) void Debug_Log (int Lows, int Wfck_mode){ #if defined(ATtiny85_45_25) - DEBUG_PRINT("m "); DEBUG_PRINTLN(Wfck_mode); + mySerial.print("m "); mySerial.println(Wfck_mode); #elif !defined(ATtiny85_45_25) //DEBUG_PRINT("highs: "); DEBUG_PRINT(highs); - DEBUG_PRINT(" lows: "); DEBUG_PRINTLN(Lows); - DEBUG_PRINT(" wfck_mode: "); DEBUG_PRINTLN(Wfck_mode); - DEBUG_PRINT(" region: "); DEBUG_PRINT(region[0]); DEBUG_PRINT(region[1]); DEBUG_PRINTLN (region[2]); + Serial.print(" lows: "); Serial.println(Lows); + Serial.print(" wfck_mode: "); Serial.println(Wfck_mode); + Serial.print(" region: "); Serial.print(region[0]); Serial.print(region[1]); Serial.println(region[2]); // Power saving // Disable the ADC by setting the ADEN bit (bit 7) of the ADCSRA register to zero. ADCSRA = ADCSRA & B01111111; @@ -151,22 +152,53 @@ void Debug_Log (int Lows, int Wfck_mode){ #endif } + // log SUBQ packets. We only have 12ms to get the logs written out. Slower MCUs get less formatting. +void Debug_Scbuf (uint8_t *Scbuf){ +#if defined(ATtiny85_45_25) + if (!(Scbuf[0] == 0 && Scbuf[1] == 0 && Scbuf[2] == 0 && Scbuf[3] == 0)) { // a bad sector read is all 0 except for the CRC fields. Don't log it. + for (int i = 0; i < 12; i++) { + if (Scbuf[i] < 0x10) { + mySerial.print("0"); // padding + } + mySerial.print(Scbuf[i, HEX]); + } + mySerial.println(""); + } +#elif !defined(ATtiny85_45_25) + if (!(Scbuf[0] == 0 && Scbuf[1] == 0 && Scbuf[2] == 0 && Scbuf[3] == 0)) { + for (int i = 0; i < 12; i++) { + if (Scbuf[i] < 0x10) { + Serial.print("0"); // padding + } + Serial.print(Scbuf[i], HEX); + Serial.print(" "); + } + Serial.println(""); + } +#endif +} +void Debug_Inject(){ +#if defined(ATtiny85_45_25) + mySerial.print("!"); +#elif !defined(ATtiny85_45_25) + Serial.println(" INJECT ! "); +#endif +} +#endif -#if !defined(SCEA) && !defined(SCEE) && !defined(SCEI) && !defined(All) && !defined(SCPH_103) && \ +#if !defined(SCPH_103) && \ !defined(SCPH_102) && !defined(SCPH_101) && !defined(SCPH_100) && !defined(SCPH_7000_9000) && \ !defined(SCPH_5500) && !defined(SCPH_3500_5000) && !defined(SCPH_3000) && \ - !defined(SCPH_1000) && !defined(SCPH_xxxx) && !defined(SCPH_102_legacy) && !defined(SCPH_xxxx_25) &&\ - !defined(SCPH_xxx1_25) && !defined(SCPH_xxx2_25) && !defined(SCPH_xxxx3_25) && !defined(SCPH_xxx1_15) &&\ - !defined(SCPH_xxx2_15) && !defined(SCPH_xxx3_15) + !defined(SCPH_1000) && !defined(SCPH_xxxx) && !defined(SCPH_102_legacy) && \ + !defined(SCPH_xxx1) && !defined(SCPH_xxx2) && !defined(SCPH_xxxx3) #error "Console not selected! Please uncoment #define with SCPH model number." -#elif !(defined(SCEA) ^ defined(SCEE) ^ defined(SCEAI) ^ defined(All) ^ defined(SCPH_103) ^ \ +#elif !defined(SCPH_103) ^ \ defined(SCPH_102) ^ defined(SCPH_101) ^ defined(SCPH_100) ^ defined(SCPH_7000_9000) ^ \ defined(SCPH_5500) ^ defined(SCPH_3500_5000) ^ defined(SCPH_3000) ^ \ - defined(SCPH_1000) ^ defined(SCPH_xxxx) ^ defined(SCPH_102_legacy) ^ defined(SCPH_xxxx_25) ^ \ - defined(SCPH_xxx1_25) ^ defined(SCPH_xxx2_25) ^ defined(SCPH_xxx3_25) ^ defined(SCPH_xxx1_15) ^ \ - defined(SCPH_xxx2_15) ^ defined(SCPH_xxx3_15)) + defined(SCPH_1000) ^ defined(SCPH_xxxx) ^ defined(SCPH_102_legacy) ^ \ + defined(SCPH_xxx1) ^ defined(SCPH_xxx2) ^ defined(SCPH_xxx3) #error "May be selected only one console! Please check #define with SCPH model number." #endif