2023-11-26 12:11:49 -05:00
|
|
|
//
|
|
|
|
// Created by william on 10/15/23.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "memory.h"
|
|
|
|
#include "ram.h"
|
2023-12-23 16:35:23 -05:00
|
|
|
#include "../include/rom.h"
|
2023-11-26 12:11:49 -05:00
|
|
|
|
|
|
|
byte mem_get_byte(Mapper *mapper, address addr) {
|
|
|
|
address redirected_addr = mapper->redirect_addr(addr);
|
2023-12-23 16:35:23 -05:00
|
|
|
|
|
|
|
if (redirected_addr < 0x0800) {
|
|
|
|
return ram_get_byte(redirected_addr);
|
|
|
|
} else if (redirected_addr >= 0x4020) {
|
|
|
|
return rom_prg_get_byte(redirected_addr - 0x4020);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2023-11-26 12:11:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
word mem_get_word(Mapper *mapper, address addr) {
|
|
|
|
address redirected_addr = mapper->redirect_addr(addr);
|
2023-12-23 16:35:23 -05:00
|
|
|
|
|
|
|
if (redirected_addr < 0x0800) {
|
|
|
|
return ram_get_word(redirected_addr);
|
|
|
|
} else if (redirected_addr >= 0x4020) {
|
|
|
|
return rom_prg_get_word(redirected_addr - 0x4020);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2023-11-26 12:11:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void mem_set_byte(Mapper *mapper, address addr, byte byte) {
|
|
|
|
address redirected_addr = mapper->redirect_addr(addr);
|
|
|
|
ram_set_byte(redirected_addr, byte);
|
|
|
|
}
|