Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for mapper 10 (MMC4) #15

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions GhidraNes/src/main/java/ghidranes/mappers/MMC4Mapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ghidranes.mappers;

import java.util.Arrays;

import ghidra.framework.store.LockException;
import ghidra.program.model.address.AddressOverflowException;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.MemoryConflictException;
import ghidra.util.exception.CancelledException;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.task.TaskMonitor;
import ghidranes.NesRom;
import ghidranes.util.MemoryBlockDescription;


public class MMC4Mapper extends NesMapper {
@Override
public void updateMemoryMapForRom(NesRom rom, Program program, TaskMonitor monitor) throws LockException, MemoryConflictException, AddressOverflowException, CancelledException, DuplicateNameException {
int sramPermissions = MemoryBlockDescription.READ | MemoryBlockDescription.WRITE | MemoryBlockDescription.EXECUTE;
MemoryBlockDescription.uninitialized(0x6000, 0x2000, "SRAM", sramPermissions, false).create(program);

int romPermissions = MemoryBlockDescription.READ | MemoryBlockDescription.EXECUTE;
for (int bank = 0; bank * 0x4000 < rom.prgRom.length; bank++) {
byte[] rombankBytes = Arrays.copyOfRange(rom.prgRom, bank * 0x4000, (bank + 1) * 0x4000);
MemoryBlockDescription.initialized(0x8000, 0x4000, "PRG" + bank, romPermissions, rombankBytes, bank != 0, monitor).create(program);
}

int lastBank = rom.prgRom.length / 0x4000 - 1;
byte[] lastBankBytes = Arrays.copyOfRange(rom.prgRom, lastBank * 0x4000, (lastBank + 1) * 0x4000);
MemoryBlockDescription.initialized(0xC000, 0x4000, "PRG" + lastBank + "_MIRROR", romPermissions, lastBankBytes, false, monitor).create(program);
}
}
2 changes: 2 additions & 0 deletions GhidraNes/src/main/java/ghidranes/mappers/NesMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static NesMapper getMapper(int mapperNum) throws UnimplementedNesMapperEx
return new MMC1Mapper();
case 7:
return new AxROMMapper();
case 10:
return new MMC4Mapper();
case 19:
return new Mapper019();
default:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A Ghidra extension to support disassembling and analyzing NES ROMs.
- [NROM](https://www.nesdev.org/wiki/NROM) (mapper 0)
- [MMC1](https://www.nesdev.org/wiki/MMC1) (mapper 1)
- [AxROM](https://www.nesdev.org/wiki/AxROM) (mapper 7)
- [MMC4](https://www.nesdev.org/wiki/MMC4) (mapper 10)
- [Namco 129/163](https://www.nesdev.org/wiki/INES_Mapper_019) (mapper 19)

- Add labels and memory blocks in disassembly, making it easier to jump around a disassembled ROM!
Expand Down