mirror of
https://github.com/sanni/cartreader.git
synced 2025-02-03 15:22:47 +01:00
V30J: Fix SA1 sram write
Mayne thanks to Oatburner and skaman.
This commit is contained in:
parent
9c2fcae43d
commit
742e96151a
@ -2,8 +2,8 @@
|
|||||||
Cartridge Reader for Arduino Mega2560
|
Cartridge Reader for Arduino Mega2560
|
||||||
|
|
||||||
Author: sanni
|
Author: sanni
|
||||||
Date: 2018-02-02
|
Date: 2018-03-12
|
||||||
Version: V30I
|
Version: V30J
|
||||||
|
|
||||||
SD lib: https://github.com/greiman/SdFat
|
SD lib: https://github.com/greiman/SdFat
|
||||||
LCD lib: https://github.com/adafruit/Adafruit_SSD1306
|
LCD lib: https://github.com/adafruit/Adafruit_SSD1306
|
||||||
@ -35,7 +35,7 @@
|
|||||||
infinest - help with GB Memory cart
|
infinest - help with GB Memory cart
|
||||||
|
|
||||||
**********************************************************************************/
|
**********************************************************************************/
|
||||||
char ver[5] = "V30I";
|
char ver[5] = "V30J";
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
Define Starting Point
|
Define Starting Point
|
||||||
|
@ -16,7 +16,7 @@ uint16_t sramEndAddress = 0;
|
|||||||
// GBx start menu
|
// GBx start menu
|
||||||
static const char gbxMenuItem1[] PROGMEM = "Game Boy (Color)";
|
static const char gbxMenuItem1[] PROGMEM = "Game Boy (Color)";
|
||||||
static const char gbxMenuItem2[] PROGMEM = "Game Boy Advance";
|
static const char gbxMenuItem2[] PROGMEM = "Game Boy Advance";
|
||||||
static const char gbxMenuItem3[] PROGMEM = "NP GB Memory";
|
static const char gbxMenuItem3[] PROGMEM = "NintPower GB Memory";
|
||||||
static const char* const menuOptionsGBx[] PROGMEM = {gbxMenuItem1, gbxMenuItem2, gbxMenuItem3};
|
static const char* const menuOptionsGBx[] PROGMEM = {gbxMenuItem1, gbxMenuItem2, gbxMenuItem3};
|
||||||
|
|
||||||
// GB menu items
|
// GB menu items
|
||||||
|
@ -27,7 +27,7 @@ boolean NP = false;
|
|||||||
*****************************************/
|
*****************************************/
|
||||||
// SNES/Nintendo Power SF Memory start menu
|
// SNES/Nintendo Power SF Memory start menu
|
||||||
static const char snsMenuItem1[] PROGMEM = "SNES SFC";
|
static const char snsMenuItem1[] PROGMEM = "SNES SFC";
|
||||||
static const char snsMenuItem2[] PROGMEM = "NP SF Memory";
|
static const char snsMenuItem2[] PROGMEM = "NintPower SF Memory";
|
||||||
static const char* const menuOptionsSNS[] PROGMEM = {snsMenuItem1, snsMenuItem2};
|
static const char* const menuOptionsSNS[] PROGMEM = {snsMenuItem1, snsMenuItem2};
|
||||||
|
|
||||||
// SNES menu items
|
// SNES menu items
|
||||||
@ -1178,59 +1178,45 @@ void writeSRAM (boolean browseFile) {
|
|||||||
|
|
||||||
// Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work
|
// Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work
|
||||||
// Break BW-RAM (SRAM) into 0x2000 blocks
|
// Break BW-RAM (SRAM) into 0x2000 blocks
|
||||||
// Use $2225 to map BW-RAM block to 0x6000-0x7FFF
|
|
||||||
// Writes must be to entire address range 0x0000-0x7FFF
|
|
||||||
byte lastBlock = 0;
|
byte lastBlock = 0;
|
||||||
lastBlock = lastByte / 0x2000;
|
lastBlock = lastByte / 0x2000;
|
||||||
|
|
||||||
// Writing SRAM on SA1 needs CS(PH3) to be high
|
// Writing SRAM on SA1 needs CS(PH3) to be high
|
||||||
PORTH |= (1 << 3);
|
// PORTH |= (1 << 3);
|
||||||
|
|
||||||
|
// Setup BW-RAM
|
||||||
|
// Set 0x2224 (SNES BMAPS) to map SRAM Block 0 to 0x6000-0x7FFF
|
||||||
|
writeBank_SNES(0, 0x2224, 0);
|
||||||
|
// Set 0x2226 (SNES SBWE) to 0x80 Write Enable
|
||||||
|
writeBank_SNES(0, 0x2226, 0x80);
|
||||||
|
// Set 0x2228 (SNES BWPA) to 0x00 BW-RAM Write-Protected Area
|
||||||
|
writeBank_SNES(0, 0x2228, 0);
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
// Use $2224 (SNES) to map BW-RAM block to 0x6000-0x7FFF
|
||||||
|
// Use $2226 (SNES) to write enable the BW-RAM
|
||||||
|
byte firstByte = 0;
|
||||||
for (byte currBlock = 0; currBlock < lastBlock; currBlock++) {
|
for (byte currBlock = 0; currBlock < lastBlock; currBlock++) {
|
||||||
// Set 0x2225 (SA-1 BMAP) to map SRAM Block to 0x6000-0x7FFF
|
// Set 0x2224 (SNES BMAPS) to map SRAM Block to 0x6000-0x7FFF
|
||||||
writeBank_SNES(0, 0x2225, currBlock);
|
writeBank_SNES(0, 0x2224, currBlock);
|
||||||
// Set 0x2227 to 0x80 SA-1 SWBE BW-RAM Write Enable
|
// Set 0x2226 (SNES SBWE) to 0x80 Write Enable
|
||||||
writeBank_SNES(0, 0x2227, 0x80);
|
writeBank_SNES(0, 0x2226, 0x80);
|
||||||
for (long currByte = 0x0000; currByte < 0x8000; currByte += 512) {
|
for (long currByte = 0x6000; currByte < 0x8000; currByte += 512) {
|
||||||
if (currByte < 0x6000) {
|
myFile.read(sdBuffer, 512);
|
||||||
for (int c = 0; c < 512; c++) {
|
if ((currBlock == 0) && (currByte == 0x6000)) {
|
||||||
// Shift to bypass protected 1st 0x100 bytes
|
firstByte = sdBuffer[0];
|
||||||
writeBank_SNES(0, currByte + c, currBlock + lastBlock);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
for (int c = 0; c < 512; c++) {
|
||||||
myFile.read(sdBuffer, 512);
|
writeBank_SNES(0, currByte + c, sdBuffer[c]);
|
||||||
for (int c = 0; c < 512; c++) {
|
|
||||||
writeBank_SNES(0, currByte + c, sdBuffer[c]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set 0x2227 to 0x00 SA-1 SWBE BW-RAM Write Disable
|
// Rewrite First Byte
|
||||||
writeBank_SNES(0, 0x2227, 0x00);
|
writeBank_SNES(0, 0x2224, 0);
|
||||||
|
writeBank_SNES(0, 0x2226, 0x80);
|
||||||
|
writeBank_SNES(0, 0x6000, firstByte);
|
||||||
// Disable CPU clock
|
// Disable CPU clock
|
||||||
clockgen.output_enable(SI5351_CLK1, 0);
|
clockgen.output_enable(SI5351_CLK1, 0);
|
||||||
|
|
||||||
/* // MOVED RESET TO AFTER VERIFY
|
|
||||||
// Reset SA1
|
|
||||||
// Set pins to input
|
|
||||||
dataIn();
|
|
||||||
// Close the file:
|
|
||||||
myFile.close();
|
|
||||||
println_Msg(F("SRAM writing finished"));
|
|
||||||
println_Msg(F("Press Button to reset"));
|
|
||||||
display_Update();
|
|
||||||
wait();
|
|
||||||
// Set reset pin to output (PH0)
|
|
||||||
DDRH |= (1 << 0);
|
|
||||||
// Switch RST(PH0) to LOW
|
|
||||||
PORTH &= ~(1 << 0);
|
|
||||||
display_Clear();
|
|
||||||
print_Msg("Resetting...");
|
|
||||||
display_Update();
|
|
||||||
delay(3000); // wait 3 secs to switch to next game
|
|
||||||
asm volatile (" jmp 0");
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set pins to input
|
// Set pins to input
|
||||||
@ -1690,36 +1676,39 @@ boolean eraseSRAM (byte b) {
|
|||||||
|
|
||||||
// Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work
|
// Direct writes to BW-RAM (SRAM) in banks 0x40-0x43 don't work
|
||||||
// Break BW-RAM (SRAM) into 0x2000 blocks
|
// Break BW-RAM (SRAM) into 0x2000 blocks
|
||||||
// Use $2225 to map BW-RAM block to 0x6000-0x7FFF
|
// Use $2224 to map BW-RAM block to 0x6000-0x7FFF
|
||||||
// Writes must be to entire address range 0x0000-0x7FFF
|
|
||||||
byte lastBlock = 0;
|
byte lastBlock = 0;
|
||||||
lastBlock = lastByte / 0x2000;
|
lastBlock = lastByte / 0x2000;
|
||||||
|
|
||||||
// Writing SRAM on SA1 needs CS(PH3) to be high
|
// Writing SRAM on SA1 needs CS(PH3) to be high
|
||||||
PORTH |= (1 << 3);
|
// PORTH |= (1 << 3);
|
||||||
|
|
||||||
|
// Setup BW-RAM
|
||||||
|
// Set 0x2224 (SNES BMAPS) to map SRAM Block 0 to 0x6000-0x7FFF
|
||||||
|
writeBank_SNES(0, 0x2224, 0);
|
||||||
|
// Set 0x2226 (SNES SBWE) to 0x80 Write Enable
|
||||||
|
writeBank_SNES(0, 0x2226, 0x80);
|
||||||
|
// Set 0x2228 (SNES BWPA) to 0x00 BW-RAM Write-Protected Area
|
||||||
|
writeBank_SNES(0, 0x2228, 0);
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
// Use $2224 (SNES) to map BW-RAM block to 0x6000-0x7FFF
|
||||||
|
// Use $2226 (SNES) to write enable the BW-RAM
|
||||||
for (byte currBlock = 0; currBlock < lastBlock; currBlock++) {
|
for (byte currBlock = 0; currBlock < lastBlock; currBlock++) {
|
||||||
// Set 0x2225 (SA-1 BMAP) to map SRAM Block to 0x6000-0x7FFF
|
// Set 0x2224 (SNES BMAPS) to map SRAM Block to 0x6000-0x7FFF
|
||||||
writeBank_SNES(0, 0x2225, currBlock);
|
writeBank_SNES(0, 0x2224, currBlock);
|
||||||
// Set 0x2227 to 0x80 SA-1 SWBE BW-RAM Write Enable
|
// Set 0x2226 (SNES SBWE) to 0x80 Write Enable
|
||||||
writeBank_SNES(0, 0x2227, 0x80);
|
writeBank_SNES(0, 0x2226, 0x80);
|
||||||
for (long currByte = 0x0000; currByte < 0x8000; currByte += 512) {
|
for (long currByte = 0x6000; currByte < 0x8000; currByte += 512) {
|
||||||
if (currByte < 0x6000) {
|
for (int c = 0; c < 512; c++) {
|
||||||
for (int c = 0; c < 512; c++) {
|
writeBank_SNES(0, currByte + c, b);
|
||||||
// Shift to bypass protected 1st 0x100 bytes
|
|
||||||
writeBank_SNES(0, currByte + c, currBlock + lastBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
myFile.read(sdBuffer, 512);
|
|
||||||
for (int c = 0; c < 512; c++) {
|
|
||||||
writeBank_SNES(0, currByte + c, b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set 0x2227 to 0x00 SA-1 SWBE BW-RAM Write Disable
|
// Rewrite First Byte
|
||||||
writeBank_SNES(0, 0x2227, 0x00);
|
writeBank_SNES(0, 0x2224, 0);
|
||||||
|
writeBank_SNES(0, 0x2226, 0x80);
|
||||||
|
writeBank_SNES(0, 0x6000, b);
|
||||||
// Disable CPU clock
|
// Disable CPU clock
|
||||||
clockgen.output_enable(SI5351_CLK1, 0);
|
clockgen.output_enable(SI5351_CLK1, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user