Files
6soz/src/system/nes/mapper/mapper13.zig
T

70 lines
1.3 KiB
Zig

const types = @import("types.zig");
const Mirroring = types.Mirroring;
const Mapper13 = @This();
chr_bank: u8 = 0,
fixed_mirroring: Mirroring,
prg_mask: usize,
pub fn init(
prg_size: usize,
mirroring_mode: Mirroring,
) Mapper13 {
return .{
.fixed_mirroring = mirroring_mode,
.prg_mask = if (prg_size > 0) prg_size - 1 else 0x7fff,
};
}
pub fn cpuMapRead(
self: *const Mapper13,
address: u16,
) ?usize {
if (address < 0x8000) return null;
return (@as(usize, address) - 0x8000) & self.prg_mask;
}
pub fn cpuWrite(
self: *Mapper13,
address: u16,
value: u8,
) void {
if (address < 0x8000) return;
self.chr_bank = value & 0x03;
}
pub fn ppuMapRead(
self: *const Mapper13,
address: u16,
) ?usize {
if (address >= 0x2000) return null;
if (address < 0x1000) {
return 0x80000000 | @as(usize, address);
} else {
const bank = @as(usize, self.chr_bank & 3);
const offset = @as(usize, address & 0x0fff);
return 0x80000000 | (bank * 0x1000 + offset);
}
}
pub fn ppuMapWrite(
self: *const Mapper13,
address: u16,
) ?usize {
return self.ppuMapRead(address);
}
pub fn mirroring(
self: *const Mapper13,
) Mirroring {
return self.fixed_mirroring;
}
pub fn irqAsserted(
_: *const Mapper13,
) bool {
return false;
}