Skip to content

Commit

Permalink
Don't go through filestream wrapper anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Feb 18, 2015
1 parent 52b8a54 commit dc3b801
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
24 changes: 11 additions & 13 deletions libgambatte/src/mem/cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,20 +443,22 @@ namespace gambatte
return n;
}


int Cartridge::loadROM(File &rom, const bool forceDmg, const bool multiCartCompat)
int Cartridge::loadROM(const void *data, unsigned romsize, const bool forceDmg, const bool multiCartCompat)
{

if (rom.size() < 0x4000) return -1;
uint8_t *romdata = (uint8_t*)data;
if (romsize < 0x4000 || !romdata)
return -1;

unsigned rambanks = 1;
unsigned rombanks = 2;
bool cgb = false;
enum Cartridgetype { PLAIN, MBC1, MBC2, MBC3, MBC5, HUC1 } type = PLAIN;

{
unsigned i;
unsigned char header[0x150];
rom.read(reinterpret_cast<char*>(header), sizeof(header));
for (i = 0; i < 0x150; i++)
header[i] = romdata[i];

switch (header[0x0147])
{
Expand Down Expand Up @@ -521,22 +523,18 @@ namespace gambatte

printf("rambanks: %u\n", rambanks);

rombanks = pow2ceil(rom.size() / 0x4000);
printf("rombanks: %u\n", static_cast<unsigned>(rom.size() / 0x4000));
rombanks = pow2ceil(romsize / 0x4000);
printf("rombanks: %u\n", static_cast<unsigned>(romsize / 0x4000));

ggUndoList_.clear();
mbc.reset();
memptrs_.reset(rombanks, rambanks, cgb ? 8 : 2);
rtc_.set(false, 0);

rom.rewind();
rom.read(reinterpret_cast<char*>(memptrs_.romdata()), (rom.size() / 0x4000) * 0x4000ul);
std::memset(memptrs_.romdata() + (rom.size() / 0x4000) * 0x4000ul, 0xFF, (rombanks - rom.size() / 0x4000) * 0x4000ul);
memcpy(memptrs_.romdata(), romdata, ((romsize / 0x4000) * 0x4000ul) * sizeof(unsigned char));
std::memset(memptrs_.romdata() + (romsize / 0x4000) * 0x4000ul, 0xFF, (rombanks - romsize / 0x4000) * 0x4000ul);
enforce8bit(memptrs_.romdata(), rombanks * 0x4000ul);

if (rom.fail())
return -1;

switch (type)
{
case PLAIN: mbc.reset(new Mbc0(memptrs_)); break;
Expand Down
6 changes: 0 additions & 6 deletions libgambatte/src/mem/cartridge_libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ namespace gambatte
}
}

int Cartridge::loadROM(const void *romdata, unsigned romsize, const bool forceDmg, const bool multiCartCompat)
{
File rom(romdata, romsize);
return loadROM(rom, forceDmg, multiCartCompat);
}

void *Cartridge::savedata_ptr()
{
// Check ROM header for battery.
Expand Down

0 comments on commit dc3b801

Please sign in to comment.