bsnes/higan/gba/cartridge/flash.cpp

101 lines
2.3 KiB
C++
Raw Normal View History

//Dev.ID Size Blocks Manufacturer
//====== ===== ======== ============
//0xd4bf 64KB 16x4096 SST
//0x1cc2 64KB 16x4096 Macronix
//0x1b32 64KB 16x4096 Panasonic
//0x3d1f 64KB 512x 128 Atmel
//0x1362 128KB 32x4096 Sanyo
//0x09c2 128KB 32x4096 Macronix
auto Cartridge::FLASH::read(uint16 addr) -> uint8 {
if(idmode) {
if(addr == 0x0000) return id >> 0;
if(addr == 0x0001) return id >> 8;
return 0u;
}
return data[bank << 16 | addr];
}
auto Cartridge::FLASH::write(uint16 addr, uint8 byte) -> void {
if(bankselect) {
bankselect = false;
//bank select is only applicable on 128KB chips
if(addr == 0x0000) bank = byte & (size > 64 * 1024);
return;
}
if(writeselect) {
//Atmel writes 128 bytes per command; all others write 1 byte per command
if(id != 0x3d1f || (addr & 0x007f) == 0x007f) writeselect = false;
data[bank << 16 | addr] = byte;
return;
}
if(byte == 0xaa && addr == 0x5555) { unlockhi = true; return; }
if(byte == 0x55 && addr == 0x2aaa) { unlocklo = true; return; }
if(unlockhi && unlocklo) {
unlockhi = false;
unlocklo = false;
if(byte == 0x10 && addr == 0x5555) {
if(erasemode) {
erasemode = false;
Update to v099r13 release. byuu says: Changelog: - GB core code cleanup completed - GBA core code cleanup completed - some more cleanup on missed processor/arm functions/variables - fixed FC loading icarus bug - "Load ROM File" icarus functionality restored - minor code unification efforts all around (not perfect yet) - MMIO->IO - mmio.cpp->io.cpp - read,write->readIO,writeIO It's been a very long work in progress ... starting all the way back with v094r09, but the major part of the higan code cleanup is now completed! Of course, it's very important to note that this is only for the basic style: - under_score functions and variables are now camelCase - return-type function-name() are now auto function-name() -> return-type - Natural<T>/Integer<T> replace (u)intT_n types where possible - signed/unsigned are now int/uint - most of the x==true,x==false tests changed to x,!x A lot of spot improvements to consistency, simplicity and quality have gone in along the way, of course. But we'll probably never fully finishing beautifying every last line of code in the entire codebase. Still, this is a really great start. Going forward, WIP diffs should start being smaller and of higher quality once again. I know the joke is, "until my coding style changes again", but ... this was way too stressful, way too time consuming, and way too risky. I'm too old and tired now for extreme upheavel like this again. The only major change I'm slowly mulling over would be renaming the using Natural<T>/Integer<T> = (u)intT; shorthand to something that isn't as easily confused with the (u)int_t types ... but we'll see. I'll definitely continue to change small things all the time, but for the larger picture, I need to just accept the style I have and live with it.
2016-06-29 11:10:28 +00:00
for(uint n : range(size)) data[n] = 0xff;
}
}
if(byte == 0x30 && (addr & 0x0fff) == 0x0000) {
//command only valid for non-Atmel chips
if(erasemode && id != 0x3d1f) {
erasemode = false;
Update to v099r13 release. byuu says: Changelog: - GB core code cleanup completed - GBA core code cleanup completed - some more cleanup on missed processor/arm functions/variables - fixed FC loading icarus bug - "Load ROM File" icarus functionality restored - minor code unification efforts all around (not perfect yet) - MMIO->IO - mmio.cpp->io.cpp - read,write->readIO,writeIO It's been a very long work in progress ... starting all the way back with v094r09, but the major part of the higan code cleanup is now completed! Of course, it's very important to note that this is only for the basic style: - under_score functions and variables are now camelCase - return-type function-name() are now auto function-name() -> return-type - Natural<T>/Integer<T> replace (u)intT_n types where possible - signed/unsigned are now int/uint - most of the x==true,x==false tests changed to x,!x A lot of spot improvements to consistency, simplicity and quality have gone in along the way, of course. But we'll probably never fully finishing beautifying every last line of code in the entire codebase. Still, this is a really great start. Going forward, WIP diffs should start being smaller and of higher quality once again. I know the joke is, "until my coding style changes again", but ... this was way too stressful, way too time consuming, and way too risky. I'm too old and tired now for extreme upheavel like this again. The only major change I'm slowly mulling over would be renaming the using Natural<T>/Integer<T> = (u)intT; shorthand to something that isn't as easily confused with the (u)int_t types ... but we'll see. I'll definitely continue to change small things all the time, but for the larger picture, I need to just accept the style I have and live with it.
2016-06-29 11:10:28 +00:00
uint offset = bank << 16 | (addr & ~4095);
for(uint n : range(4096)) data[offset++] = 0xff;
}
}
if(byte == 0x80 && addr == 0x5555) {
erasemode = true;
}
if(byte == 0x90 && addr == 0x5555) {
idmode = true;
}
if(byte == 0xa0 && addr == 0x5555) {
writeselect = true;
}
if(byte == 0xb0 && addr == 0x5555) {
bankselect = true;
}
if(byte == 0xf0 && addr == 0x5555) {
idmode = false;
}
}
}
auto Cartridge::FLASH::power() -> void {
unlockhi = false;
unlocklo = false;
idmode = false;
bankselect = false;
writeselect = false;
bank = 0;
}
auto Cartridge::FLASH::serialize(serializer& s) -> void {
s.array(data, size);
s.integer(size);
s.integer(id);
s.integer(unlockhi);
s.integer(unlocklo);
s.integer(idmode);
s.integer(erasemode);
s.integer(bankselect);
s.integer(writeselect);
s.integer(bank);
}