Compare commits

..

No commits in common. "aca7fc9a60192cf340a83e1a381872237b344fc9" and "8ab7a178c136fcd19e4b3fe1d5a46a5f25877af2" have entirely different histories.

5 changed files with 9 additions and 52 deletions

View File

@ -49,7 +49,7 @@ pub fn read32(self: *const Self, addr: u32) u32 {
// Internal Display Memory // Internal Display Memory
0x0500_0000...0x0500_03FF => self.ppu.palette.get32(addr - 0x0500_0000), 0x0500_0000...0x0500_03FF => self.ppu.palette.get32(addr - 0x0500_0000),
0x0600_0000...0x0601_7FFF => self.ppu.vram.get32(addr - 0x0600_0000), 0x0600_0000...0x0601_7FFF => self.ppu.vram.get32(addr - 0x0600_0000),
0x0700_0000...0x0700_03FF => self.ppu.oam.get32(addr - 0x0700_0000), 0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:32] read from 0x{X:} in OAM", .{addr}),
// External Memory (Game Pak) // External Memory (Game Pak)
0x0800_0000...0x09FF_FFFF => self.pak.get32(addr - 0x0800_0000), 0x0800_0000...0x09FF_FFFF => self.pak.get32(addr - 0x0800_0000),
@ -75,7 +75,7 @@ pub fn write32(self: *Self, addr: u32, word: u32) void {
// Internal Display Memory // Internal Display Memory
0x0500_0000...0x0500_03FF => self.ppu.palette.set32(addr - 0x0500_0000, word), 0x0500_0000...0x0500_03FF => self.ppu.palette.set32(addr - 0x0500_0000, word),
0x0600_0000...0x0601_7FFF => self.ppu.vram.set32(addr - 0x0600_0000, word), 0x0600_0000...0x0601_7FFF => self.ppu.vram.set32(addr - 0x0600_0000, word),
0x0700_0000...0x0700_03FF => self.ppu.oam.set32(addr - 0x0700_0000, word), 0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:32] wrote 0x{X:} to 0x{X:} in OAM", .{ word, addr }),
else => log.warn("32-bit write of 0x{X:0>8} to 0x{X:0>8}", .{ word, addr }), else => log.warn("32-bit write of 0x{X:0>8} to 0x{X:0>8}", .{ word, addr }),
} }
@ -92,7 +92,7 @@ pub fn read16(self: *const Self, addr: u32) u16 {
// Internal Display Memory // Internal Display Memory
0x0500_0000...0x0500_03FF => self.ppu.palette.get16(addr - 0x0500_0000), 0x0500_0000...0x0500_03FF => self.ppu.palette.get16(addr - 0x0500_0000),
0x0600_0000...0x0601_7FFF => self.ppu.vram.get16(addr - 0x0600_0000), 0x0600_0000...0x0601_7FFF => self.ppu.vram.get16(addr - 0x0600_0000),
0x0700_0000...0x0700_03FF => self.ppu.oam.get16(addr - 0x0700_0000), 0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:16] read from 0x{X:} in OAM", .{addr}),
// External Memory (Game Pak) // External Memory (Game Pak)
0x0800_0000...0x09FF_FFFF => self.pak.get16(addr - 0x0800_0000), 0x0800_0000...0x09FF_FFFF => self.pak.get16(addr - 0x0800_0000),
@ -117,7 +117,7 @@ pub fn write16(self: *Self, addr: u32, halfword: u16) void {
// Internal Display Memory // Internal Display Memory
0x0500_0000...0x0500_03FF => self.ppu.palette.set16(addr - 0x0500_0000, halfword), 0x0500_0000...0x0500_03FF => self.ppu.palette.set16(addr - 0x0500_0000, halfword),
0x0600_0000...0x0601_7FFF => self.ppu.vram.set16(addr - 0x0600_0000, halfword), 0x0600_0000...0x0601_7FFF => self.ppu.vram.set16(addr - 0x0600_0000, halfword),
0x0700_0000...0x0700_03FF => self.ppu.oam.set16(addr - 0x0700_0000, halfword), 0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:16] write 0x{X:} to 0x{X:} in OAM", .{ halfword, addr }),
else => log.warn("16-bit write of 0x{X:0>4} to 0x{X:0>8}", .{ halfword, addr }), else => log.warn("16-bit write of 0x{X:0>4} to 0x{X:0>8}", .{ halfword, addr }),
} }
@ -134,7 +134,7 @@ pub fn read8(self: *const Self, addr: u32) u8 {
// Internal Display Memory // Internal Display Memory
0x0500_0000...0x0500_03FF => self.ppu.palette.get8(addr - 0x0500_0000), 0x0500_0000...0x0500_03FF => self.ppu.palette.get8(addr - 0x0500_0000),
0x0600_0000...0x0601_7FFF => self.ppu.vram.get8(addr - 0x0600_0000), 0x0600_0000...0x0601_7FFF => self.ppu.vram.get8(addr - 0x0600_0000),
0x0700_0000...0x0700_03FF => self.ppu.oam.get8(addr - 0x0700_0000), 0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:8] read from 0x{X:} in OAM", .{addr}),
// External Memory (Game Pak) // External Memory (Game Pak)
0x0800_0000...0x09FF_FFFF => self.pak.get8(addr - 0x0800_0000), 0x0800_0000...0x09FF_FFFF => self.pak.get8(addr - 0x0800_0000),

View File

@ -43,7 +43,7 @@ pub fn format19(comptime is_low: bool) InstrFn {
// Instruction 2 // Instruction 2
const old_pc = cpu.r[15]; const old_pc = cpu.r[15];
cpu.r[15] = cpu.r[14] +% (offset << 1); cpu.r[15] = cpu.r[14] + (offset << 1);
cpu.r[14] = old_pc | 1; cpu.r[14] = old_pc | 1;
} else { } else {
// Instruction 1 // Instruction 1

View File

@ -116,7 +116,7 @@ pub fn format10(comptime L: bool, comptime offset: u5) InstrFn {
const rb = opcode >> 3 & 0x7; const rb = opcode >> 3 & 0x7;
const rd = opcode & 0x7; const rd = opcode & 0x7;
const address = cpu.r[rb] + (@as(u6, offset) << 1); const address = cpu.r[rb] + (offset << 1);
if (L) { if (L) {
// LDRH // LDRH

View File

@ -18,12 +18,12 @@ pub fn format5(comptime op: u2, comptime h1: u1, comptime h2: u1) InstrFn {
0b00 => { 0b00 => {
// ADD // ADD
const sum = add(false, cpu, dst, src); const sum = add(false, cpu, dst, src);
cpu.r[dst_idx] = if (dst_idx == 0xF) sum & 0xFFFF_FFFE else sum; cpu.r[dst_idx] = if (dst_idx == 0xF) sum & 0xFFFF_FFFC else sum;
}, },
0b01 => cmp(cpu, dst, src), // CMP 0b01 => cmp(cpu, dst, src), // CMP
0b10 => { 0b10 => {
// MOV // MOV
cpu.r[dst_idx] = if (dst_idx == 0xF) src & 0xFFFF_FFFE else src; cpu.r[dst_idx] = if (dst_idx == 0xF) src & 0xFFFF_FFFC else src;
}, },
0b11 => { 0b11 => {
// BX // BX

View File

@ -14,7 +14,6 @@ pub const Ppu = struct {
vram: Vram, vram: Vram,
palette: Palette, palette: Palette,
oam: Oam,
sched: *Scheduler, sched: *Scheduler,
framebuf: []u8, framebuf: []u8,
alloc: Allocator, alloc: Allocator,
@ -29,7 +28,6 @@ pub const Ppu = struct {
return Self{ return Self{
.vram = try Vram.init(alloc), .vram = try Vram.init(alloc),
.palette = try Palette.init(alloc), .palette = try Palette.init(alloc),
.oam = try Oam.init(alloc),
.sched = sched, .sched = sched,
.framebuf = framebuf, .framebuf = framebuf,
.alloc = alloc, .alloc = alloc,
@ -160,44 +158,3 @@ const Vram = struct {
return self.buf[idx]; return self.buf[idx];
} }
}; };
const Oam = struct {
const Self = @This();
buf: []u8,
alloc: Allocator,
fn init(alloc: Allocator) !Self {
const buf = try alloc.alloc(u8, 0x400);
std.mem.set(u8, buf, 0);
return Self{
.buf = buf,
.alloc = alloc,
};
}
pub fn get32(self: *const Self, idx: usize) u32 {
return (@as(u32, self.buf[idx + 3]) << 24) | (@as(u32, self.buf[idx + 2]) << 16) | (@as(u32, self.buf[idx + 1]) << 8) | (@as(u32, self.buf[idx]));
}
pub fn set32(self: *Self, idx: usize, word: u32) void {
self.buf[idx + 3] = @truncate(u8, word >> 24);
self.buf[idx + 2] = @truncate(u8, word >> 16);
self.buf[idx + 1] = @truncate(u8, word >> 8);
self.buf[idx] = @truncate(u8, word);
}
pub fn get16(self: *const Self, idx: usize) u16 {
return (@as(u16, self.buf[idx + 1]) << 8) | @as(u16, self.buf[idx]);
}
pub fn set16(self: *Self, idx: usize, halfword: u16) void {
self.buf[idx + 1] = @truncate(u8, halfword >> 8);
self.buf[idx] = @truncate(u8, halfword);
}
pub fn get8(self: *const Self, idx: usize) u8 {
return self.buf[idx];
}
};