Skip to content

Commit 316f8ef

Browse files
authored
Merge pull request #919 from smesgr9000/master
Add support for Atari 7800 Bankset bank switch
2 parents 385b6b0 + a2924e4 commit 316f8ef

File tree

1 file changed

+92
-15
lines changed

1 file changed

+92
-15
lines changed

Cart_Reader/7800.ino

+92-15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
// CONTROL PINS:
4545
// CLK(PH1) - SNES CPUCLK
4646
// R/W(PH6) - SNES /RD
47+
// HALT(PH0) - SNES /RESET
4748

4849
//******************************************
4950
// Supported Mappers
@@ -58,9 +59,10 @@ static const byte PROGMEM a7800mapsize[] = {
5859
4, 4, 4, // Double Dragon/Rampage 128K [78AC]
5960
5, 3, 3, // Realsports Baseball/Tank Command/Tower Toppler/Waterski 64K [78S4]
6061
6, 3, 3, // Karateka (PAL) 64K [78S4 Variant]
62+
7, 1, 4, // Bankset switching
6163
};
6264

63-
byte a7800mapcount = 7; // (sizeof(a7800mapsize) / sizeof(a7800mapsize[0])) / 3;
65+
byte a7800mapcount = 8; // (sizeof(a7800mapsize) / sizeof(a7800mapsize[0])) / 3;
6466
byte a7800mapselect;
6567
int a7800index;
6668

@@ -96,7 +98,7 @@ void setup_7800() {
9698
DDRL = 0xFF;
9799

98100
// Set Control Pins to Output
99-
// ---(PH0) ---(PH3) ---(PH4) ---(PH5) R/W(PH6)
101+
// HALT(PH0) ---(PH3) ---(PH4) ---(PH5) R/W(PH6)
100102
DDRH |= (1 << 0) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
101103

102104
// Set TIME(PJ0) to Output (UNUSED)
@@ -106,7 +108,7 @@ void setup_7800() {
106108
DDRC = 0x00;
107109

108110
// Setting Control Pins to HIGH
109-
// ---(PH0) ---(PH3) ---(PH4) ---(PH5) R/W(PH6)
111+
// HALT(PH0) ---(PH3) ---(PH4) ---(PH5) R/W(PH6)
110112
PORTH |= (1 << 0) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
111113

112114
// Set Unused Data Pins (PA0-PA7) to Output
@@ -263,7 +265,32 @@ void writeData_7800(uint32_t addr, uint8_t data) {
263265
NOP;
264266
NOP;
265267
NOP;
268+
NOP;
269+
NOP;
270+
NOP;
271+
NOP;
272+
NOP;
273+
NOP;
274+
NOP;
275+
NOP;
276+
NOP;
277+
NOP;
266278
PORTH |= (1 << 6); // R/W(PH6) HIGH = READ
279+
NOP;
280+
NOP;
281+
NOP;
282+
NOP;
283+
NOP;
284+
NOP;
285+
NOP;
286+
NOP;
287+
NOP;
288+
NOP;
289+
NOP;
290+
NOP;
291+
NOP;
292+
NOP;
293+
NOP;
267294

268295
DDRC = 0x00; // Reset to Input
269296
}
@@ -321,20 +348,11 @@ void readROM_7800() {
321348

322349
switch (a7800mapper) {
323350
case 0: // Standard 16K/32K/48K [7816/7832/7848]
324-
if (a7800size > 1)
325-
readSegment_7800(0x4000, 0x8000); // +16K = 48K
326-
if (a7800size > 0)
327-
readSegment_7800(0x8000, 0xC000); // +16K = 32K
328-
// Base 16K
329-
readSegment_7800(0xC000, 0x10000); // 16K
351+
readStandard_7800();
330352
break;
331353

332354
case 1: // SuperGame 128K [78SG]
333-
for (int x = 0; x < 7; x++) {
334-
writeData_7800(0x8000, x); // Banks 0-6
335-
readSegment_7800(0x8000, 0xC000); // 16K * 7 = 112K
336-
}
337-
readSegment_7800(0xC000, 0x10000); // Bank 7 +16 = 128K
355+
readSupergame_7800();
338356
break;
339357

340358
case 2: // SuperGame - Alien Brigade/Crossbow 144K [78S9]
@@ -392,6 +410,20 @@ void readROM_7800() {
392410
readSegment_7800(0x8000, 0xC000); // 16K * 4 = 64K
393411
}
394412
break;
413+
414+
case 7: // Bankset switching
415+
if (a7800size > 3) {
416+
setHalt_7800(1);
417+
readSupergame_7800();
418+
setHalt_7800(0);
419+
readSupergame_7800();
420+
} else {
421+
setHalt_7800(1);
422+
readStandard_7800();
423+
setHalt_7800(0);
424+
readStandard_7800();
425+
}
426+
break;
395427
}
396428
myFile.close();
397429

@@ -405,6 +437,38 @@ void readROM_7800() {
405437
wait();
406438
}
407439

440+
void readStandard_7800() {
441+
if (a7800size > 1)
442+
readSegment_7800(0x4000, 0x8000); // +16K = 48K
443+
if (a7800size > 0)
444+
readSegment_7800(0x8000, 0xC000); // +16K = 32K
445+
// Base 16K
446+
readSegment_7800(0xC000, 0x10000); // 16K
447+
}
448+
449+
void readSupergame_7800() {
450+
for (int x = 0; x < 7; x++) {
451+
writeData_7800(0x8000, x); // Banks 0-6
452+
readSegment_7800(0x8000, 0xC000); // 16K * 7 = 112K
453+
}
454+
readSegment_7800(0xC000, 0x10000); // Bank 7 +16 = 128K
455+
}
456+
457+
void setHalt_7800(byte on) {
458+
if(on == 1) {
459+
PORTH |= (1 << 0); // HALT(PH0) HIGH = SALLY
460+
} else {
461+
PORTH &= ~(1 << 0); // HALT(PH0) LOW = MARIA
462+
}
463+
NOP;
464+
NOP;
465+
NOP;
466+
NOP;
467+
NOP;
468+
NOP;
469+
NOP;
470+
}
471+
408472
//******************************************
409473
// ROM SIZE
410474
//******************************************
@@ -560,6 +624,8 @@ void checkStatus_7800() {
560624
println_Msg(F("BASEBALL/ETC [78S4]"));
561625
else if (a7800mapper == 6)
562626
println_Msg(F("KARATEKA(PAL)[78S4]"));
627+
else if (a7800mapper == 7)
628+
println_Msg(F("BANKSET"));
563629
print_Msg(F("ROM SIZE: "));
564630
print_Msg(a7800[a7800size]);
565631
println_Msg(F("K"));
@@ -582,6 +648,8 @@ void checkStatus_7800() {
582648
Serial.println(F("Realsports Baseball/Tank Command/Tower Toppler/Waterski [78S4]"));
583649
else if (a7800mapper == 6)
584650
Serial.println(F("Karateka (PAL) [78S4 Variant]"));
651+
else if (a7800mapper == 7)
652+
Serial.println(F("Bankset"));
585653
Serial.print(F("ROM SIZE: "));
586654
Serial.print(A7800[a7800size]);
587655
Serial.println(F("K"));
@@ -637,6 +705,8 @@ void setMapper_7800() {
637705
println_Msg(F("BASEBALL/ETC [78S4]"));
638706
else if (a7800mapselect == 6)
639707
println_Msg(F("KARATEKA(PAL) [78S4]"));
708+
else if (a7800mapselect == 7)
709+
println_Msg(F("BANKSET"));
640710
display_Update();
641711
if (i == (a7800mapcount - 1))
642712
i = 0;
@@ -665,6 +735,8 @@ void setMapper_7800() {
665735
println_Msg(F("BASEBALL/ETC [78S4]"));
666736
else if (a7800mapselect == 6)
667737
println_Msg(F("KARATEKA(PAL) [78S4]"));
738+
else if (a7800mapselect == 7)
739+
println_Msg(F("BANKSET"));
668740
println_Msg(FS(FSTRING_EMPTY));
669741
#if defined(ENABLE_OLED)
670742
print_STR(press_to_change_STR, 1);
@@ -702,6 +774,8 @@ void setMapper_7800() {
702774
println_Msg(F("BASEBALL/ETC [78S4]"));
703775
else if (a7800mapselect == 6)
704776
println_Msg(F("KARATEKA(PAL) [78S4]"));
777+
else if (a7800mapselect == 7)
778+
println_Msg(F("BANKSET"));
705779
println_Msg(FS(FSTRING_EMPTY));
706780
#if defined(ENABLE_OLED)
707781
print_STR(press_to_change_STR, 1);
@@ -738,6 +812,8 @@ void setMapper_7800() {
738812
println_Msg(F("BASEBALL/ETC [78S4]"));
739813
else if (a7800mapselect == 6)
740814
println_Msg(F("KARATEKA(PAL) [78S4]"));
815+
else if (a7800mapselect == 7)
816+
println_Msg(F("BANKSET"));
741817
println_Msg(FS(FSTRING_EMPTY));
742818
#if defined(ENABLE_OLED)
743819
print_STR(press_to_change_STR, 1);
@@ -770,7 +846,8 @@ setmapper:
770846
Serial.println(F("4 = Double Dragon/Rampage [78AC]"));
771847
Serial.println(F("5 = Realsports Baseball/Tank Command/Tower Toppler/Waterski [78S4]"));
772848
Serial.println(F("6 = Karateka (PAL) [78S4 Variant]"));
773-
Serial.print(F("Enter Mapper [0-6]: "));
849+
Serial.println(F("7 = Bankset"));
850+
Serial.print(F("Enter Mapper [0-7]: "));
774851
while (Serial.available() == 0) {}
775852
newmap = Serial.readStringUntil('\n');
776853
Serial.println(newmap);

0 commit comments

Comments
 (0)