-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathMegaDrivePlusPlus.ino
665 lines (575 loc) · 20.9 KB
/
MegaDrivePlusPlus.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
/*******************************************************************************
* This file is part of MegaDrive++. *
* *
* Copyright (C) 2015-2016 by SukkoPera <software@sukkology.net> *
* *
* MegaDrive++ is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* MegaDrive++ is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with MegaDrive++. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
*
* MegaDrive++ - Universal Region mod, 50/60 Hz switch and In-Game-Reset (IGR)
* for Sega Mega Drive (AKA Genesis)
*
* Please refer to the GitHub page and wiki for any information:
* https://github.com/SukkoPera/MegaDrivePlusPlus
*/
/* Bare ATmega328 Wiring diagram:
*
* ,-----_-----.
* |1 A5 28| JP1/2 (Language)
* Pad Port Pin 9 |2 0 A4 27| JP3/4 (Video Mode)
* |3 1 A3 26| Reset In
* Pad Port Pin 7 |4 2 A2 25| Reset Out
* Pad Port Pin 6 |5 3 A1 24|
* Pad Port Pin 4 |6 4 A0 23|
* +5V |7 22| GND
* GND |8 21| +5V
* |9 20| +5V
* |10 13 19| (Built-in LED)
* Pad Port Pin 3 |11 5 12 18|
* Pad Port Pin 2 |12 6 11 17| LED Blue
* Pad Port Pin 1 |13 7 10 16| LED Green
* |14 8 9 15| LED Red
* `-----------'
*
*
* Arduino Nano:
*
* +-----+
* +------------| USB |------------+
* | +-----+ |
* (Built-in LED) | [ ]D13/SCK MISO/D12[ ] |
* | [ ]3.3V MOSI/D11[X]~| LED Blue
* | [ ]V.ref ___ SS/D10[X]~| LED Green
* | [ ]A0 / N \ D9[X]~| LED Red
* | [ ]A1 / A \ D8[ ] |
* Reset Out | [X]A2 \ N / D7[X] | Pad Port Pin 1
* Reset In | [X]A3 \_0_/ D6[X]~| Pad Port Pin 2
* JP3/4 (Video Mode) | [X]A4/SDA D5[X]~| Pad Port Pin 3
* JP1/2 (Language) | [X]A5/SCL D4[X] | Pad Port Pin 4
* | [ ]A6 INT1/D3[X]~| Pad Port Pin 6
* | [ ]A7 INT0/D2[X] | Pad Port Pin 7
* +5V | [X]5V GND[X] | GND
* | [ ]RST RST[ ] |
* | [ ]GND 5V MOSI GND TX1[ ] |
* | [ ]Vin [ ] [ ] [ ] RX0[X] | Pad Port Pin 9
* | [ ] [ ] [ ] |
* | MISO SCK RST |
* | NANO-V3 |
* +-------------------------------+
*
* Wiring considerations:
* - We read the pad port status through an ISR triggered by a level change on
* the SELECT line. Said line is triggered very quickly for 6-button pads (~4
* us), so the ISR has very little time to complete. Thus we need to keep all
* button lines on the same port and only PORTD has enough pins on an
* ATmega328.
* - Outputting debugging messages is useful, but unfortunately the hardware
* UART is right on PORTD on the 328. Actually we only need the TX pin
* (ATmega328 pin 3, mapped to pin 1 on an Arduino), so we keep that one free.
* We cannot use the hardware UART support though, since that would also
* prevent us from using pin 0 at will. Thus we resort to using Nick Gammon's
* SendOnlySoftwareSerial library, available here:
* https://forum.arduino.cc/index.php?topic=112013.0. Note that while we are
* not tied to any specific pin anymore at this point, we really want to use
* pin 1, since that is connected to the onboard Serial <-> USB converter on
* Arduino boards.
*/
#define RESET_IN_PIN A3
#define RESET_OUT_PIN A2
#define VIDEOMODE_PIN A4
#define LANGUAGE_PIN A5
#define MODE_LED_R_PIN 9 // PWM
#define MODE_LED_G_PIN 10 // PWM
#define MODE_LED_B_PIN 11 // PWM
#define PAD_LED_PIN LED_BUILTIN
#define ENABLE_SERIAL_DEBUG
/*******************************************************************************
* BUTTON COMBO SETTINGS
******************************************************************************/
// DON'T TOUCH THIS! Just look at it for the button names you can use below!
enum __attribute__ ((__packed__)) PadButton {
MD_BTN_Z = 1 << 11,
MD_BTN_Y = 1 << 10,
MD_BTN_X = 1 << 9,
MD_BTN_MODE = 1 << 8,
MD_BTN_UP = 1 << 7,
MD_BTN_DOWN = 1 << 6,
MD_BTN_LEFT = 1 << 5,
MD_BTN_RIGHT = 1 << 4,
MD_BTN_B = 1 << 3,
MD_BTN_C = 1 << 2,
MD_BTN_A = 1 << 1,
MD_BTN_START = 1 << 0
};
/* Button combo that enables the other combos.
*
* Note: That vertical bar ("pipe") means that the buttons must be pressed
* together.
*/
#define TRIGGER_COMBO (MD_BTN_START | MD_BTN_B)
/* Button combos to perform other actions. These are to be considered in
* addition to TRIGGER_COMBO.
*
* Note that we cannot detect certain buttons on some platforms
*/
#define RESET_COMBO (MD_BTN_A | MD_BTN_C)
/* On ATtinyX61's, ATtinyX313's and Arduinos we can detect all buttons, so we
* can make up a specific combo for every mode that switches straight to it,
* no need to cycle among modes.
*/
#define EUR_COMBO MD_BTN_DOWN
#define USA_COMBO MD_BTN_RIGHT
#define JAP_COMBO MD_BTN_LEFT
/*******************************************************************************
* ADVANCED SETTINGS
******************************************************************************/
/* Offset in the EEPROM at which the current mode should be saved. Undefine to
* disable mode saving.
*/
#define MODE_ROM_OFFSET 42
// Time to wait after mode change before saving the new mode (milliseconds)
#define MODE_SAVE_DELAY 3000L
// Force the reset line level when active. Undefine to enable auto-detection.
//#define FORCE_RESET_ACTIVE_LEVEL LOW
/* Colors to use to indicate the video mode, in 8-bit RGB componentes. You can
* use any value here if your led is connected to PWM-capable pins, otherwise
* values specified here will be interpreted as either fully off (if 0) or fully
* on (if anything else).
*
* Note that using PWM-values here sometimes causes unpredictable problems. This
* happened to me on an ATtiny861, and it's probably due to how pins and timers
* interact. It seems to work fine on a full Arduino, but unless you really want
* weird colors, use only 0x00 and 0xFF.
*
* Oh, and good luck trying to fit a 5mm RGB led in the MegaDrive ;).
*/
#define MODE_LED_EUR_COLOR {0x00, 0xFF, 0x00} // Green
#define MODE_LED_USA_COLOR {0x00, 0x00, 0xFF} // Blue
#define MODE_LED_JAP_COLOR {0xFF, 0x00, 0x00} // Red
// Define this if your led is common-anode, comment out for common-cathode
//#define MODE_LED_COMMON_ANODE
/* Use a single led to indicate the video mode. This is enabled automatically
* in place of the RGB led when low flash space is detected, but since this
* does NOT disable the RGB led, it can be used together with it, provided that
* you have a free pin.
*
* Basically, the single led is blinked 1-3 times according to which mode is set
* (1 is EUR, see enum VideoMode below).
*/
//#define MODE_LED_SINGLE_PIN A1
/* Presses of the reset button longer than this amount of milliseconds will
* switch to the next mode, shorter presses will reset the console.
*/
#define LONGPRESS_LEN 700
// Debounce duration for the reset button
#define DEBOUNCE_MS 20
// Duration of the reset pulse (milliseconds)
#define RESET_LEN 350
// Print the controller status on serial. Useful for debugging.
#ifdef ENABLE_SERIAL_DEBUG
#define DEBUG_PAD
#endif
/*******************************************************************************
* END OF SETTINGS
******************************************************************************/
#ifdef ENABLE_SERIAL_DEBUG
#include <SendOnlySoftwareSerial.h>
SendOnlySoftwareSerial swSerial (1);
#define dstart(spd) swSerial.begin (spd)
#define debug(...) swSerial.print (__VA_ARGS__)
#define debugln(...) swSerial.println (__VA_ARGS__)
#else
#define dstart(...)
#define debug(...)
#define debugln(...)
#endif
#ifdef MODE_ROM_OFFSET
#include <EEPROM.h>
#endif
enum __attribute__ ((__packed__)) VideoMode {
EUR,
USA,
JAP,
MODES_NO // Leave at end
};
// This will be handy
#if (defined MODE_LED_R_PIN || defined MODE_LED_G_PIN || defined MODE_LED_B_PIN)
#define ENABLE_MODE_LED_RGB
const byte mode_led_colors[][MODES_NO] = {
MODE_LED_EUR_COLOR,
MODE_LED_USA_COLOR,
MODE_LED_JAP_COLOR
};
#endif
// Video mode
VideoMode current_mode;
unsigned long mode_last_changed_time;
// Reset level when NOT ACTIVE
byte reset_inactive_level;
/* Raw pad port statuses as read by the ISR:
* - g_buttons_1 contains the port status when SELECT is HIGH
* - g_buttons_2 contains the port status when SELECT is LOW
* - g_buttons_3 contains the port status when SELECT is PULSE-3
*
* These are raw readings, since we don't really have any time to spare in the
* ISR, so HIGH means "Not pressed" here, that's why we start with 0xFFs.
*/
volatile byte g_buttons_1 = 0xFF;
volatile byte g_buttons_2 = 0xFF;
volatile byte g_buttons_3 = 0xFF;
inline void save_mode () {
#ifdef MODE_ROM_OFFSET
if (mode_last_changed_time > 0 && millis () - mode_last_changed_time >= MODE_SAVE_DELAY) {
debug (F("Saving video mode to EEPROM: "));
debugln (current_mode);
byte saved_mode = EEPROM.read (MODE_ROM_OFFSET);
if (current_mode != saved_mode) {
EEPROM.write (MODE_ROM_OFFSET, static_cast<byte> (current_mode));
} else {
debugln (F("Mode unchanged, not saving"));
}
mode_last_changed_time = 0; // Don't save again
// Blink led to tell the user that mode was saved
#ifdef ENABLE_MODE_LED_RGB
byte c = 0;
#ifdef RGB_LED_COMMON_ANODE
c = 255 - c;
#endif
#ifdef MODE_LED_R_PIN
analogWrite (MODE_LED_R_PIN, c);
#endif
#ifdef MODE_LED_G_PIN
analogWrite (MODE_LED_G_PIN, c);
#endif
#ifdef MODE_LED_B_PIN
analogWrite (MODE_LED_B_PIN, c);
#endif
// Keep off for a bit
delay (200);
// Turn leds back on
update_mode_leds ();
#endif // ENABLE_MODE_LED_RGB
#ifdef MODE_LED_SINGLE_PIN
// Make one long flash
digitalWrite (MODE_LED_SINGLE_PIN, LOW);
delay (500);
digitalWrite (MODE_LED_SINGLE_PIN, HIGH);
#endif
}
#endif // MODE_ROM_OFFSET
}
inline void change_mode (int increment) {
// This also loops in [0, MODES_NO) backwards
VideoMode new_mode = static_cast<VideoMode> ((current_mode + increment + MODES_NO) % MODES_NO);
set_mode (new_mode);
}
inline void next_mode () {
change_mode (+1);
}
inline void prev_mode () {
change_mode (-1);
}
void update_mode_leds () {
#ifdef ENABLE_MODE_LED_RGB
const byte *colors = mode_led_colors[current_mode];
byte c;
#ifdef MODE_LED_R_PIN
c = colors[0];
#ifdef MODE_LED_COMMON_ANODE
c = 255 - c;
#endif
analogWrite (MODE_LED_R_PIN, c);
#endif
#ifdef MODE_LED_G_PIN
c = colors[1];
#ifdef MODE_LED_COMMON_ANODE
c = 255 - c;
#endif
analogWrite (MODE_LED_G_PIN, c);
#endif
#ifdef MODE_LED_B_PIN
c = colors[2];
#ifdef MODE_LED_COMMON_ANODE
c = 255 - c;
#endif
analogWrite (MODE_LED_B_PIN, c);
#endif
#endif // ENABLE_MODE_LED_RGB
#ifdef MODE_LED_SINGLE_PIN
// WARNING: This loop must be reasonably shorter than LONGPRESS_LEN in the worst case!
for (byte i = 0; i < current_mode + 1; ++i) {
digitalWrite (MODE_LED_SINGLE_PIN, LOW);
delay (40);
digitalWrite (MODE_LED_SINGLE_PIN, HIGH);
delay (80);
}
#endif
}
void set_mode (VideoMode m) {
switch (m) {
default:
case EUR:
digitalWrite (VIDEOMODE_PIN, LOW); // PAL 50Hz
digitalWrite (LANGUAGE_PIN, HIGH); // ENG
break;
case USA:
digitalWrite (VIDEOMODE_PIN, HIGH); // NTSC 60Hz
digitalWrite (LANGUAGE_PIN, HIGH); // ENG
break;
case JAP:
digitalWrite (VIDEOMODE_PIN, HIGH); // NTSC 60Hz
digitalWrite (LANGUAGE_PIN, LOW); // JAP
break;
}
current_mode = m;
update_mode_leds ();
mode_last_changed_time = millis ();
}
inline void handle_reset_button () {
static byte debounce_level = LOW;
static bool reset_pressed_before = false;
static long last_int = 0, reset_press_start = 0;
static unsigned int hold_cycles = 0;
byte reset_level = digitalRead (RESET_IN_PIN);
if (reset_level != debounce_level) {
// Reset debouncing timer
last_int = millis ();
debounce_level = reset_level;
} else if (millis () - last_int > DEBOUNCE_MS) {
// OK, button is stable, see if it has changed
if (reset_level != reset_inactive_level && !reset_pressed_before) {
// Button just pressed
reset_press_start = millis ();
hold_cycles = 0;
} else if (reset_level == reset_inactive_level && reset_pressed_before) {
// Button released
if (hold_cycles == 0) {
debugln (F("Reset button pushed for a short time"));
reset_console ();
}
} else {
// Button has not just been pressed/released
if (reset_level != reset_inactive_level && millis () % reset_press_start >= LONGPRESS_LEN * (hold_cycles + 1)) {
// Reset has been held for a while
debugln (F("Reset button hold"));
++hold_cycles;
next_mode ();
}
}
reset_pressed_before = (reset_level != reset_inactive_level);
}
}
void reset_console () {
debugln (F("Resetting console"));
digitalWrite (RESET_OUT_PIN, !reset_inactive_level);
delay (RESET_LEN);
digitalWrite (RESET_OUT_PIN, reset_inactive_level);
}
void setup () {
dstart (57600);
debugln (F("Starting up..."));
/* Rant: As per D4s's installation schematics out there (which we use too), it
* seems that on consoles with an active low reset signal, the Reset In input
* is taken before the pull-up resistor, while on consoles with active-high
* reset it is taken AFTER the pull-down resistor. This means that detecting
* the reset level by sampling the same line on both consoles is tricky, as in
* both cases one of the Reset In/Out signals is left floating :(. The
* following should work reliably, but we allow for a way to force the reset
* line level.
*/
#ifndef FORCE_RESET_ACTIVE_LEVEL
// Let things settle down and then sample the reset line
delay (100);
pinMode (RESET_IN_PIN, INPUT_PULLUP);
reset_inactive_level = digitalRead (RESET_IN_PIN);
debug (F("Reset line is "));
debug (reset_inactive_level ? F("HIGH") : F("LOW"));
debugln (" at startup");
#else
reset_inactive_level = !FORCE_RESET_ACTIVE_LEVEL;
debug (F("Reset line is forced to active-"));
debugln (FORCE_RESET_ACTIVE_LEVEL ? F("HIGH") : F("LOW"));
#endif
if (reset_inactive_level == LOW) {
// No need for pull-up
pinMode (RESET_IN_PIN, INPUT);
#ifdef FORCE_RESET_ACTIVE_LEVEL // If this is not defined pull-up was already enabled above
} else {
pinMode (RESET_IN_PIN, INPUT_PULLUP);
#endif
}
// Enable reset
pinMode (RESET_OUT_PIN, OUTPUT);
digitalWrite (RESET_OUT_PIN, !reset_inactive_level);
// Setup leds
#ifdef MODE_LED_R_PIN
pinMode (MODE_LED_R_PIN, OUTPUT);
#endif
#ifdef MODE_LED_G_PIN
pinMode (MODE_LED_G_PIN, OUTPUT);
#endif
#ifdef MODE_LED_B_PIN
pinMode (MODE_LED_B_PIN, OUTPUT);
#endif
#ifdef MODE_LED_SINGLE_PIN
pinMode (MODE_LED_SINGLE_PIN, OUTPUT);
#endif
#ifdef PAD_LED_PIN
pinMode (PAD_LED_PIN, OUTPUT);
#endif
// Init video mode
pinMode (VIDEOMODE_PIN, OUTPUT);
pinMode (LANGUAGE_PIN, OUTPUT);
current_mode = EUR;
#ifdef MODE_ROM_OFFSET
byte tmp = EEPROM.read (MODE_ROM_OFFSET);
debug (F("Loaded video mode from EEPROM: "));
debugln (tmp);
if (tmp < MODES_NO) {
// Palette EEPROM value is good
current_mode = static_cast<VideoMode> (tmp);
}
#endif
set_mode (current_mode);
mode_last_changed_time = 0; // No need to save what we just loaded
// Prepare to read pad
setup_pad ();
// Finally release the reset line
digitalWrite (RESET_OUT_PIN, reset_inactive_level);
}
inline void setup_pad () {
// Set port directions: All button lines are INPUTs
pinMode (0, INPUT);
pinMode (2, INPUT);
pinMode (3, INPUT);
pinMode (4, INPUT);
pinMode (5, INPUT);
pinMode (6, INPUT);
pinMode (7, INPUT);
// The SIGNALLING line is an output
pinMode (12, OUTPUT);
/* Enable interrupts: we can't use attachInterrupt() here, since our ISR is
* going to be bare
*/
EICRA |= (1 << ISC00); // Trigger interrupt on CHANGE
EIMSK |= (1 << INT0); // Enable interrupt 0 (i.e.: on pin 2)
interrupts (); // Enable all interrupts, probably redundant
}
/******************************************************************************/
/* The basic idea here is to make up a word (i.e.: 2 bytes) where each bit
* represents the state of a button, with 1 meaning pressed, for commodity's
* sake. The bit-button mapping is defined in the PadButton enum above.
*/
word read_pad () {
// Invert all bits, since we want to use 1 for pressed
byte b1 = ~g_buttons_1; // Select HIGH......: UDLRBxxC
byte b2 = ~g_buttons_2; // Select LOW.......: UDxxAxxS
byte b3 = ~g_buttons_3; // Select PULSE-3...: ZYXMxxxx
/* Compose all bytes into a single word, respecting the order in PadButton.
* Note that we take UP and DOWN from b2 because sometimes b1 will contain
* spurious data from b3, i.e.: Keeping X pressed reports LEFT, Y reports
* DOWN, etc... This way we restrict the problem to X and MODE.
*
* It would be great to eliminate the problem completely, but we still haven't
* found a way :(.
*/
word buttons = (b1 & 0x38) | ((b1 & 0x01) << 2)
| (b2 & 0xC0) | ((b2 & 0x08) >> 2) | (b2 & 0x01)
| (((word) (b3 & 0xF0)) << 4)
;
return buttons;
}
#define IGNORE_COMBO_MS LONGPRESS_LEN
inline void handle_pad () {
static long last_combo_time = 0;
word pad_status = read_pad ();
#ifdef PAD_LED_PIN
digitalWrite (PAD_LED_PIN, pad_status != 0);
#endif
#ifdef DEBUG_PAD
static word last_pad_status = 0;
if (pad_status != last_pad_status) {
debug (F("Pressed: "));
if (pad_status & MD_BTN_UP)
debug (F("Up "));
if (pad_status & MD_BTN_DOWN)
debug (F("Down "));
if (pad_status & MD_BTN_LEFT)
debug (F("Left "));
if (pad_status & MD_BTN_RIGHT)
debug (F("Right "));
if (pad_status & MD_BTN_A)
debug (F("A "));
if (pad_status & MD_BTN_B)
debug (F("B "));
if (pad_status & MD_BTN_C)
debug (F("C "));
if (pad_status & MD_BTN_X)
debug (F("X "));
if (pad_status & MD_BTN_Y)
debug (F("Y "));
if (pad_status & MD_BTN_Z)
debug (F("Z "));
if (pad_status & MD_BTN_MODE)
debug (F("Mode "));
if (pad_status & MD_BTN_START)
debug (F("Start "));
debugln ();
last_pad_status = pad_status;
}
#endif
if ((pad_status & TRIGGER_COMBO) == TRIGGER_COMBO && millis () - last_combo_time > IGNORE_COMBO_MS) {
if ((pad_status & RESET_COMBO) == RESET_COMBO) {
debugln (F("Reset combo detected"));
reset_console ();
pad_status = 0; // Avoid continuous reset (pad_status might keep the last value during reset!)
last_combo_time = millis ();
#ifdef EUR_COMBO
} else if ((pad_status & EUR_COMBO) == EUR_COMBO) {
debugln (F("EUR mode combo detected"));
set_mode (EUR);
last_combo_time = millis ();
#endif
#ifdef USA_COMBO
} else if ((pad_status & USA_COMBO) == USA_COMBO) {
debugln (F("USA mode combo detected"));
set_mode (USA);
last_combo_time = millis ();
#endif
#ifdef JAP_COMBO
} else if ((pad_status & JAP_COMBO) == JAP_COMBO) {
debugln (F("JAP mode combo detected"));
set_mode (JAP);
last_combo_time = millis ();
#endif
#ifdef NEXT_MODE_COMBO
} else if ((pad_status & NEXT_MODE_COMBO) == NEXT_MODE_COMBO) {
debugln (F("Next mode combo detected"));
next_mode ();
last_combo_time = millis ();
#endif
#ifdef PREV_MODE_COMBO
} else if ((pad_status & PREV_MODE_COMBO) == PREV_MODE_COMBO) {
debugln (F("Previous mode combo detected"));
prev_mode ();
last_combo_time = millis ();
#endif
}
}
}
void loop () {
handle_reset_button ();
handle_pad ();
save_mode ();
}