add nes cartridge subsystem and 41 ines mapper variants
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
const types = @import("types.zig");
|
||||
const Mirroring = types.Mirroring;
|
||||
|
||||
const Mapper180 = @This();
|
||||
|
||||
prg_bank: u8 = 0,
|
||||
prg_bank_count: usize,
|
||||
mirroring_mode: Mirroring,
|
||||
|
||||
pub fn init(
|
||||
prg_size: usize,
|
||||
_mirroring: Mirroring,
|
||||
) Mapper180 {
|
||||
return .{
|
||||
.prg_bank_count = prg_size / 0x4000,
|
||||
.mirroring_mode = _mirroring,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn cpuMapRead(
|
||||
self: *const Mapper180,
|
||||
address: u16,
|
||||
) ?usize {
|
||||
if (address < 0x8000) return null;
|
||||
|
||||
if (address < 0xC000) {
|
||||
const offset = @as(usize, address - 0x8000);
|
||||
return offset; // Fixed bank 0
|
||||
} else {
|
||||
const offset = @as(usize, address - 0xC000);
|
||||
const bank = @as(usize, self.prg_bank) % self.prg_bank_count;
|
||||
return bank * 0x4000 + offset;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cpuWrite(
|
||||
self: *Mapper180,
|
||||
address: u16,
|
||||
value: u8,
|
||||
) void {
|
||||
if (address >= 0x8000) {
|
||||
self.prg_bank = value & 0x07;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ppuMapRead(
|
||||
_: *const Mapper180,
|
||||
address: u16,
|
||||
) ?usize {
|
||||
if (address >= 0x2000) return null;
|
||||
return address;
|
||||
}
|
||||
|
||||
pub fn ppuMapWrite(
|
||||
_: *const Mapper180,
|
||||
address: u16,
|
||||
) ?usize {
|
||||
if (address >= 0x2000) return null;
|
||||
return address;
|
||||
}
|
||||
|
||||
pub fn mirroring(
|
||||
self: *const Mapper180,
|
||||
) Mirroring {
|
||||
return self.mirroring_mode;
|
||||
}
|
||||
|
||||
pub fn irqAsserted(_: *const Mapper180) bool {
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user