bsnes/higan/gba/cartridge/eeprom.cpp

95 lines
2.0 KiB
C++
Raw Normal View History

auto Cartridge::EEPROM::read(uint addr) -> bool {
return data[addr >> 3] & 0x80 >> (addr & 7);
}
auto Cartridge::EEPROM::write(uint addr, bool bit) -> void {
if(bit == 0) data[addr >> 3] &=~ (0x80 >> (addr & 7));
if(bit == 1) data[addr >> 3] |= (0x80 >> (addr & 7));
}
auto Cartridge::EEPROM::read() -> bool {
bool bit = 1;
Update to v087r30 release. byuu says: Changelog: - DMA channel masks added (some are 27-bit source/target and some are 14-bit length -- hooray, varuint_t class.) - No more state.pending flags. Instead, we set dma.pending flag when we want a transfer (fixes GBA Video - Pokemon audio) [Cydrak] - fixed OBJ Vmosaic [Cydrak, krom] - OBJ cannot read <=0x13fff in BG modes 3-5 (fixes the garbled tile at the top-left of some games) - DMA timing should be much closer to hardware now, but probably not perfect - PPU frame blending uses blargg's bit-perfect, rounded method (slower, but what can you do?) - GBA carts really unload now - added nall/gba/cartridge.hpp: used when there is no manifest. Scans ROMs for library tags, and selects the first valid one found - added EEPROM auto-detection when EEPROM size=0. Forces disk/save state size to 8192 (otherwise states could crash between pre and post detect.) - detects first read after a set read address command when the size is zero, and sets all subsequent bit-lengths to that value, prints detected size to terminal - added nall/nes/cartridge.hpp: moves iNES detection out of emulation core. Important to note: long-term goal is to remove all nall/(system)/cartridge.hpp detections from the core and replace with databases. All in good time. Anyway, the GBA workarounds should work for ~98.5% of the library, if my pre-scanning was correct (~40 games with odd tags. I reject ones without numeric versions now, too.) I think we're basically at a point where we can release a new version now. Compatibility should be relatively high (at least for a first release), and fixes are only going to affect one or two games at a time. I'd like to start doing some major cleaning house internally (rename NES->Famicom, SNES->SuperFamicom and such.) Would be much wiser to do that on a .01 WIP to minimize regressions. The main problems with a release now: - speed is pretty bad, haven't really optimized much yet (not sure how much we can improve it yet, this usually isn't easy) - sound isn't -great-, but the GBA audio sucks anyway :P - couple of known bugs (Sonic X video, etc.)
2012-04-22 10:49:19 +00:00
//EEPROM size auto-detection
if(bits == 0 && mode == Mode::ReadAddress) {
print("EEPROM address bits: ", --addressbits, "\n");
bits = addressbits == 6 ? 6 : 14;
size = 8192;
mode = Mode::ReadData;
offset = 0;
//fallthrough
}
if(mode == Mode::ReadData) {
if(offset >= 4) bit = read(address * 64 + (offset - 4));
if(++offset == 68) mode = Mode::Wait;
}
return bit;
}
auto Cartridge::EEPROM::write(bool bit) -> void {
if(mode == Mode::Wait) {
if(bit == 1) mode = Mode::Command;
}
else if(mode == Mode::Command) {
if(bit == 0) mode = Mode::WriteAddress;
if(bit == 1) mode = Mode::ReadAddress;
offset = 0;
address = 0;
Update to v087r30 release. byuu says: Changelog: - DMA channel masks added (some are 27-bit source/target and some are 14-bit length -- hooray, varuint_t class.) - No more state.pending flags. Instead, we set dma.pending flag when we want a transfer (fixes GBA Video - Pokemon audio) [Cydrak] - fixed OBJ Vmosaic [Cydrak, krom] - OBJ cannot read <=0x13fff in BG modes 3-5 (fixes the garbled tile at the top-left of some games) - DMA timing should be much closer to hardware now, but probably not perfect - PPU frame blending uses blargg's bit-perfect, rounded method (slower, but what can you do?) - GBA carts really unload now - added nall/gba/cartridge.hpp: used when there is no manifest. Scans ROMs for library tags, and selects the first valid one found - added EEPROM auto-detection when EEPROM size=0. Forces disk/save state size to 8192 (otherwise states could crash between pre and post detect.) - detects first read after a set read address command when the size is zero, and sets all subsequent bit-lengths to that value, prints detected size to terminal - added nall/nes/cartridge.hpp: moves iNES detection out of emulation core. Important to note: long-term goal is to remove all nall/(system)/cartridge.hpp detections from the core and replace with databases. All in good time. Anyway, the GBA workarounds should work for ~98.5% of the library, if my pre-scanning was correct (~40 games with odd tags. I reject ones without numeric versions now, too.) I think we're basically at a point where we can release a new version now. Compatibility should be relatively high (at least for a first release), and fixes are only going to affect one or two games at a time. I'd like to start doing some major cleaning house internally (rename NES->Famicom, SNES->SuperFamicom and such.) Would be much wiser to do that on a .01 WIP to minimize regressions. The main problems with a release now: - speed is pretty bad, haven't really optimized much yet (not sure how much we can improve it yet, this usually isn't easy) - sound isn't -great-, but the GBA audio sucks anyway :P - couple of known bugs (Sonic X video, etc.)
2012-04-22 10:49:19 +00:00
addressbits = 0;
}
else if(mode == Mode::ReadAddress) {
address = (address << 1) | bit;
Update to v087r30 release. byuu says: Changelog: - DMA channel masks added (some are 27-bit source/target and some are 14-bit length -- hooray, varuint_t class.) - No more state.pending flags. Instead, we set dma.pending flag when we want a transfer (fixes GBA Video - Pokemon audio) [Cydrak] - fixed OBJ Vmosaic [Cydrak, krom] - OBJ cannot read <=0x13fff in BG modes 3-5 (fixes the garbled tile at the top-left of some games) - DMA timing should be much closer to hardware now, but probably not perfect - PPU frame blending uses blargg's bit-perfect, rounded method (slower, but what can you do?) - GBA carts really unload now - added nall/gba/cartridge.hpp: used when there is no manifest. Scans ROMs for library tags, and selects the first valid one found - added EEPROM auto-detection when EEPROM size=0. Forces disk/save state size to 8192 (otherwise states could crash between pre and post detect.) - detects first read after a set read address command when the size is zero, and sets all subsequent bit-lengths to that value, prints detected size to terminal - added nall/nes/cartridge.hpp: moves iNES detection out of emulation core. Important to note: long-term goal is to remove all nall/(system)/cartridge.hpp detections from the core and replace with databases. All in good time. Anyway, the GBA workarounds should work for ~98.5% of the library, if my pre-scanning was correct (~40 games with odd tags. I reject ones without numeric versions now, too.) I think we're basically at a point where we can release a new version now. Compatibility should be relatively high (at least for a first release), and fixes are only going to affect one or two games at a time. I'd like to start doing some major cleaning house internally (rename NES->Famicom, SNES->SuperFamicom and such.) Would be much wiser to do that on a .01 WIP to minimize regressions. The main problems with a release now: - speed is pretty bad, haven't really optimized much yet (not sure how much we can improve it yet, this usually isn't easy) - sound isn't -great-, but the GBA audio sucks anyway :P - couple of known bugs (Sonic X video, etc.)
2012-04-22 10:49:19 +00:00
addressbits++;
if(++offset == bits) {
mode = Mode::ReadValidate;
offset = 0;
}
}
else if(mode == Mode::ReadValidate) {
if(bit == 1); //invalid
mode = Mode::ReadData;
}
else if(mode == Mode::WriteAddress) {
address = (address << 1) | bit;
if(++offset == bits) {
mode = Mode::WriteData;
offset = 0;
}
}
else if(mode == Mode::WriteData) {
write(address * 64 + offset, bit);
if(++offset == 64) {
mode = Mode::WriteValidate;
}
}
else if(mode == Mode::WriteValidate) {
if(bit == 1); //invalid
mode = Mode::Wait;
}
}
auto Cartridge::EEPROM::power() -> void {
mode = Mode::Wait;
offset = 0;
address = 0;
}
auto Cartridge::EEPROM::serialize(serializer& s) -> void {
s.array(data, size);
s.integer(size);
s.integer(mask);
s.integer(test);
s.integer(bits);
s.integer((uint&)mode);
s.integer(offset);
s.integer(address);
}