add nes cartridge subsystem and 41 ines mapper variants

This commit is contained in:
2026-08-14 06:48:16 +02:00
parent 42f20478bd
commit 04fb7bcc1f
41 changed files with 5042 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
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;
}