Skip to content

Commit

Permalink
Add support for mapper 2 (UxROM) (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorsevero authored Mar 11, 2024
1 parent ec43dfd commit 8b7fcdb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
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 @@ -19,6 +19,8 @@ public static NesMapper getMapper(int mapperNum) throws UnimplementedNesMapperEx
return new NromMapper();
case 1:
return new MMC1Mapper();
case 2:
return new UxROMMapper();
case 7:
return new AxROMMapper();
case 10:
Expand Down
39 changes: 39 additions & 0 deletions GhidraNes/src/main/java/ghidranes/mappers/UxROMMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 UxROMMapper extends NesMapper {
@Override
public void updateMemoryMapForRom(NesRom rom, Program program, TaskMonitor monitor) throws LockException, MemoryConflictException, AddressOverflowException, CancelledException, DuplicateNameException {

/* UxROM has switchable 16k PRG ROM banks mapped at 8000-FFFF.
The lower bank (fixed at 8000-BFFF) is typically the first bank, and
the upper bank (C000-FFFF) is switchable. */
int bankCount = rom.prgRom.length / 0x4000;

// Load the fixed lower bank (first 16KB)
int lowerBankPermissions = MemoryBlockDescription.READ | MemoryBlockDescription.EXECUTE;
byte[] lowerBankBytes = Arrays.copyOfRange(rom.prgRom, 0, 0x4000);
MemoryBlockDescription.initialized(0x8000, 0x4000, "PRG Lower", lowerBankPermissions, lowerBankBytes, false, monitor)
.create(program);

// Load switchable upper banks
for (int bank = 1; bank < bankCount; bank++) {
int upperBankPermissions = MemoryBlockDescription.READ | MemoryBlockDescription.EXECUTE;

byte[] upperBankBytes = Arrays.copyOfRange(rom.prgRom, bank*0x4000, (bank+1)*0x4000);
MemoryBlockDescription.initialized(0xC000, 0x4000, "PRG Upper " + bank, upperBankPermissions, upperBankBytes, bank < (bankCount - 1), monitor)
.create(program);
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A Ghidra extension to support disassembling and analyzing NES ROMs.
- Import NES ROMs in the iNES format. The following mappers are supported:
- [NROM](https://www.nesdev.org/wiki/NROM) (mapper 0)
- [MMC1](https://www.nesdev.org/wiki/MMC1) (mapper 1)
- [UxROM] (https://www.nesdev.org/wiki/UxROM) (mapper 2)
- [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)
Expand Down

0 comments on commit 8b7fcdb

Please sign in to comment.