Skip to content

Comments

Fix SRAM logic in libgambatte cartridge.cpp to fix programs like lsdj#3

Open
amitkulk123 wants to merge 1 commit intorileytestut:masterfrom
amitkulk123:master
Open

Fix SRAM logic in libgambatte cartridge.cpp to fix programs like lsdj#3
amitkulk123 wants to merge 1 commit intorileytestut:masterfrom
amitkulk123:master

Conversation

@amitkulk123
Copy link

@amitkulk123 amitkulk123 commented Apr 25, 2024

This PR fixes issue #295

There's an issue with the way libgambatte handles memory sizes of 128 kib in the sinamas submodule. This matters because in certain ROMs like lsdj, the program will only show the load/save option if it correctly detect 128 kib of memory.

To fix this, I removed the sinimas submodule (since it's publicly archived and no longer updated), and changed the memory logic in the gambatte/libgambatte/src/mem/cartridge.cpp file.

Specifically I changed the way rambanks is assigned by using a switch statement:

// rambanks = numRambanksFromH14x(header[0x147], header[0x149]);
		switch (header[0x0149]) {
			case 0x00: /*std::puts("No RAM");*/ rambanks = type == type_mbc2; break;
			case 0x01: /*std::puts("2kB RAM");*/ /*rambankrom=1; break;*/
			case 0x02: /*std::puts("8kB RAM");*/
				rambanks = 1;
				break;
			case 0x03: /*std::puts("32kB RAM");*/
				rambanks = 4;
				break;
			case 0x04: /*std::puts("128kB RAM");*/
				rambanks = 16;
				break;
			case 0x05: /*std::puts("undocumented kB RAM");*/
				rambanks = 16;
				break;
			default: /*std::puts("Wrong data-format, corrupt or unsupported ROM loaded.");*/
				rambanks = 16;
				break;
		}
		cgb = header[0x0143] >> 7 & (1 ^ forceDmg);

This is the only file I changed and everything else is the same as the sinamas submodule. I actually got this code from looking at a previous PR where this was fixed but then later revoked.

Also the same logic is used in the cartridge.cpp file in Provenance and libretro-gambatte and I can confirm that I haven't had any problems with the gambatte core when using either of those.

For testing, feel free to grab an lsdj rom from here: https://www.littlesounddj.com/lsd/latest/rom_images/stable/.

@amitkulk123
Copy link
Author

A better solution than this would probably be to use a more updated submodule like gambatte-libretro, gambatte-speedrun, openemu gambatte-core, etc. but it would require modifying a couple of the cpp files in xcode and I'm not really experienced with that. There's also a more updated commit of the sinamas submodule that may have fixed the issue but that repo has been taken private and hasn't been updated since 3 years ago so wouldn't really recommend trying it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant