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