nesemu/mappers/nrom.c

32 lines
687 B
C
Raw Normal View History

2024-05-23 22:44:52 -04:00
#include "../include/mapper.h"
#include "../include/rom.h"
#include "../cpu/memory.h"
#define PRG_BANK_SIZE 0x4000 // 16Kb
byte *nrom_mem_read(address addr) {
2024-05-23 23:52:04 -04:00
Rom *rom = rom_get();
2024-05-23 22:44:52 -04:00
2024-05-23 23:52:04 -04:00
if (addr < PRG_BANK_SIZE || rom->prg_rom_size > PRG_BANK_SIZE) {
return &rom->prg_rom[addr];
2024-05-23 22:44:52 -04:00
}
2024-05-23 23:52:04 -04:00
// The second bank is mirrored
return &rom->prg_rom[addr - PRG_BANK_SIZE];
2024-05-23 22:44:52 -04:00
}
byte *nrom_ppu_read(address addr) {
if (addr < 0x2000) {
Rom *rom = rom_get();
return &rom->chr_rom[addr];
}
return NULL;
}
Mapper get_simple_mapper() {
Mapper mapper;
mapper.mem_read = &nrom_mem_read;
mapper.ppu_read = &nrom_ppu_read;
return mapper;
}