38 lines
914 B
C
38 lines
914 B
C
#include "../include/mapper.h"
|
|
#include "../include/rom.h"
|
|
#include "../cpu/memory.h"
|
|
|
|
#define SIMPLE_MAPPER_PRG_START_ADDR 0x8000
|
|
#define PRG_BANK_SIZE 0x4000 // 16Kb
|
|
|
|
byte *nrom_mem_read(address addr) {
|
|
if (addr >= SIMPLE_MAPPER_PRG_START_ADDR) {
|
|
Rom *rom = rom_get();
|
|
address relative_addr = addr - SIMPLE_MAPPER_PRG_START_ADDR;
|
|
|
|
if (addr < PRG_BANK_SIZE || rom->prg_rom_size > PRG_BANK_SIZE) {
|
|
return &rom->prg_rom[relative_addr];
|
|
}
|
|
|
|
// The second bank is mirrored
|
|
return &rom->prg_rom[relative_addr - PRG_BANK_SIZE];
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
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;
|
|
} |