Compare commits
No commits in common. "aca7fc9a60192cf340a83e1a381872237b344fc9" and "8ab7a178c136fcd19e4b3fe1d5a46a5f25877af2" have entirely different histories.
aca7fc9a60
...
8ab7a178c1
10
src/Bus.zig
10
src/Bus.zig
|
@ -49,7 +49,7 @@ pub fn read32(self: *const Self, addr: u32) u32 {
|
|||
// Internal Display Memory
|
||||
0x0500_0000...0x0500_03FF => self.ppu.palette.get32(addr - 0x0500_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)
|
||||
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
|
||||
0x0500_0000...0x0500_03FF => self.ppu.palette.set32(addr - 0x0500_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 }),
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ pub fn read16(self: *const Self, addr: u32) u16 {
|
|||
// Internal Display Memory
|
||||
0x0500_0000...0x0500_03FF => self.ppu.palette.get16(addr - 0x0500_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)
|
||||
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
|
||||
0x0500_0000...0x0500_03FF => self.ppu.palette.set16(addr - 0x0500_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 }),
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ pub fn read8(self: *const Self, addr: u32) u8 {
|
|||
// Internal Display Memory
|
||||
0x0500_0000...0x0500_03FF => self.ppu.palette.get8(addr - 0x0500_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)
|
||||
0x0800_0000...0x09FF_FFFF => self.pak.get8(addr - 0x0800_0000),
|
||||
|
|
|
@ -43,7 +43,7 @@ pub fn format19(comptime is_low: bool) InstrFn {
|
|||
// Instruction 2
|
||||
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;
|
||||
} else {
|
||||
// Instruction 1
|
||||
|
|
|
@ -116,7 +116,7 @@ pub fn format10(comptime L: bool, comptime offset: u5) InstrFn {
|
|||
const rb = opcode >> 3 & 0x7;
|
||||
const rd = opcode & 0x7;
|
||||
|
||||
const address = cpu.r[rb] + (@as(u6, offset) << 1);
|
||||
const address = cpu.r[rb] + (offset << 1);
|
||||
|
||||
if (L) {
|
||||
// LDRH
|
||||
|
|
|
@ -18,12 +18,12 @@ pub fn format5(comptime op: u2, comptime h1: u1, comptime h2: u1) InstrFn {
|
|||
0b00 => {
|
||||
// ADD
|
||||
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
|
||||
0b10 => {
|
||||
// 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 => {
|
||||
// BX
|
||||
|
|
43
src/ppu.zig
43
src/ppu.zig
|
@ -14,7 +14,6 @@ pub const Ppu = struct {
|
|||
|
||||
vram: Vram,
|
||||
palette: Palette,
|
||||
oam: Oam,
|
||||
sched: *Scheduler,
|
||||
framebuf: []u8,
|
||||
alloc: Allocator,
|
||||
|
@ -29,7 +28,6 @@ pub const Ppu = struct {
|
|||
return Self{
|
||||
.vram = try Vram.init(alloc),
|
||||
.palette = try Palette.init(alloc),
|
||||
.oam = try Oam.init(alloc),
|
||||
.sched = sched,
|
||||
.framebuf = framebuf,
|
||||
.alloc = alloc,
|
||||
|
@ -160,44 +158,3 @@ const Vram = struct {
|
|||
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];
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue