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
+64
View File
@@ -0,0 +1,64 @@
const types = @import("types.zig");
const Mirroring = types.Mirroring;
const Axrom = @This();
prg_bank_select: u8 = 0,
mirroring_select: u1 = 0,
prg_bank_count: usize,
pub fn init(
prg_size: usize,
) Axrom {
return .{
.prg_bank_count = prg_size / 0x8000,
};
}
pub fn cpuMapRead(
self: *const Axrom,
address: u16,
) ?usize {
if (address < 0x8000) return null;
const offset = @as(usize, address - 0x8000);
const bank = @as(usize, self.prg_bank_select & 0x07) % self.prg_bank_count;
return bank * 0x8000 + offset;
}
pub fn cpuWrite(
self: *Axrom,
address: u16,
value: u8,
) void {
if (address >= 0x8000) {
self.prg_bank_select = value & 0x07;
self.mirroring_select = @truncate((value >> 4) & 1);
}
}
pub fn ppuMapRead(
_: *const Axrom,
address: u16,
) ?usize {
if (address >= 0x2000) return null;
return address;
}
pub fn ppuMapWrite(
_: *const Axrom,
address: u16,
) ?usize {
if (address >= 0x2000) return null;
return address;
}
pub fn mirroring(
self: *const Axrom,
) Mirroring {
return if (self.mirroring_select == 0) .single_screen_lower else .single_screen_upper;
}
pub fn irqAsserted(_: *const Axrom) bool {
return false;
}