chore: remove unnecessary @as calls
This commit is contained in:
parent
aa6f3c7a92
commit
2842345111
44
src/Bus.zig
44
src/Bus.zig
|
@ -40,20 +40,20 @@ pub fn deinit(self: Self) void {
|
||||||
pub fn read32(self: *const Self, addr: u32) u32 {
|
pub fn read32(self: *const Self, addr: u32) u32 {
|
||||||
return switch (addr) {
|
return switch (addr) {
|
||||||
// General Internal Memory
|
// General Internal Memory
|
||||||
0x0000_0000...0x0000_3FFF => self.bios.get32(@as(usize, addr)),
|
0x0000_0000...0x0000_3FFF => self.bios.get32(addr),
|
||||||
0x0200_0000...0x0203_FFFF => self.iwram.get32(addr - 0x0200_0000),
|
0x0200_0000...0x0203_FFFF => self.iwram.get32(addr - 0x0200_0000),
|
||||||
0x0300_0000...0x0300_7FFF => self.ewram.get32(addr - 0x0300_0000),
|
0x0300_0000...0x0300_7FFF => self.ewram.get32(addr - 0x0300_0000),
|
||||||
0x0400_0000...0x0400_03FE => self.io.read32(addr),
|
0x0400_0000...0x0400_03FE => self.io.read32(addr),
|
||||||
|
|
||||||
// Internal Display Memory
|
// Internal Display Memory
|
||||||
0x0500_0000...0x0500_03FF => self.ppu.palette.get32(@as(usize, addr - 0x0500_0000)),
|
0x0500_0000...0x0500_03FF => self.ppu.palette.get32(addr - 0x0500_0000),
|
||||||
0x0600_0000...0x0601_7FFF => self.ppu.vram.get32(@as(usize, addr - 0x0600_0000)),
|
0x0600_0000...0x0601_7FFF => self.ppu.vram.get32(addr - 0x0600_0000),
|
||||||
0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:32] read from 0x{X:} in OAM", .{addr}),
|
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(@as(usize, addr - 0x0800_0000)),
|
0x0800_0000...0x09FF_FFFF => self.pak.get32(addr - 0x0800_0000),
|
||||||
0x0A00_0000...0x0BFF_FFFF => self.pak.get32(@as(usize, addr - 0x0A00_0000)),
|
0x0A00_0000...0x0BFF_FFFF => self.pak.get32(addr - 0x0A00_0000),
|
||||||
0x0C00_0000...0x0DFF_FFFF => self.pak.get32(@as(usize, addr - 0x0C00_0000)),
|
0x0C00_0000...0x0DFF_FFFF => self.pak.get32(addr - 0x0C00_0000),
|
||||||
|
|
||||||
else => {
|
else => {
|
||||||
std.log.warn("[Bus:32] ZBA tried to read from 0x{X:}", .{addr});
|
std.log.warn("[Bus:32] ZBA tried to read from 0x{X:}", .{addr});
|
||||||
|
@ -72,8 +72,8 @@ pub fn write32(self: *Self, addr: u32, word: u32) void {
|
||||||
0x0400_0000...0x0400_03FE => self.io.write32(addr, word),
|
0x0400_0000...0x0400_03FE => self.io.write32(addr, word),
|
||||||
|
|
||||||
// Internal Display Memory
|
// Internal Display Memory
|
||||||
0x0500_0000...0x0500_03FF => self.ppu.palette.set32(@as(usize, addr - 0x0500_0000), word),
|
0x0500_0000...0x0500_03FF => self.ppu.palette.set32(addr - 0x0500_0000, word),
|
||||||
0x0600_0000...0x0601_7FFF => self.ppu.vram.set32(@as(usize, addr - 0x0600_0000), word),
|
0x0600_0000...0x0601_7FFF => self.ppu.vram.set32(addr - 0x0600_0000, word),
|
||||||
0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:32] wrote 0x{X:} to 0x{X:} in OAM", .{ word, addr }),
|
0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:32] wrote 0x{X:} to 0x{X:} in OAM", .{ word, addr }),
|
||||||
|
|
||||||
else => std.log.warn("[Bus:32] ZBA tried to write 0x{X:} to 0x{X:}", .{ word, addr }),
|
else => std.log.warn("[Bus:32] ZBA tried to write 0x{X:} to 0x{X:}", .{ word, addr }),
|
||||||
|
@ -83,20 +83,20 @@ pub fn write32(self: *Self, addr: u32, word: u32) void {
|
||||||
pub fn read16(self: *const Self, addr: u32) u16 {
|
pub fn read16(self: *const Self, addr: u32) u16 {
|
||||||
return switch (addr) {
|
return switch (addr) {
|
||||||
// General Internal Memory
|
// General Internal Memory
|
||||||
0x0000_0000...0x0000_3FFF => self.bios.get16(@as(usize, addr)),
|
0x0000_0000...0x0000_3FFF => self.bios.get16(addr),
|
||||||
0x0200_0000...0x0203_FFFF => self.iwram.get16(addr - 0x0200_0000),
|
0x0200_0000...0x0203_FFFF => self.iwram.get16(addr - 0x0200_0000),
|
||||||
0x0300_0000...0x0300_7FFF => self.ewram.get16(addr - 0x0300_0000),
|
0x0300_0000...0x0300_7FFF => self.ewram.get16(addr - 0x0300_0000),
|
||||||
0x0400_0000...0x0400_03FE => self.io.read16(addr),
|
0x0400_0000...0x0400_03FE => self.io.read16(addr),
|
||||||
|
|
||||||
// Internal Display Memory
|
// Internal Display Memory
|
||||||
0x0500_0000...0x0500_03FF => self.ppu.palette.get16(@as(usize, addr - 0x0500_0000)),
|
0x0500_0000...0x0500_03FF => self.ppu.palette.get16(addr - 0x0500_0000),
|
||||||
0x0600_0000...0x0601_7FFF => self.ppu.vram.get16(@as(usize, addr - 0x0600_0000)),
|
0x0600_0000...0x0601_7FFF => self.ppu.vram.get16(addr - 0x0600_0000),
|
||||||
0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:16] read from 0x{X:} in OAM", .{addr}),
|
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(@as(usize, addr - 0x0800_0000)),
|
0x0800_0000...0x09FF_FFFF => self.pak.get16(addr - 0x0800_0000),
|
||||||
0x0A00_0000...0x0BFF_FFFF => self.pak.get16(@as(usize, addr - 0x0A00_0000)),
|
0x0A00_0000...0x0BFF_FFFF => self.pak.get16(addr - 0x0A00_0000),
|
||||||
0x0C00_0000...0x0DFF_FFFF => self.pak.get16(@as(usize, addr - 0x0C00_0000)),
|
0x0C00_0000...0x0DFF_FFFF => self.pak.get16(addr - 0x0C00_0000),
|
||||||
|
|
||||||
else => {
|
else => {
|
||||||
std.log.warn("[Bus:16] ZBA tried to read from 0x{X:}", .{addr});
|
std.log.warn("[Bus:16] ZBA tried to read from 0x{X:}", .{addr});
|
||||||
|
@ -114,8 +114,8 @@ pub fn write16(self: *Self, addr: u32, halfword: u16) void {
|
||||||
0x0400_0000...0x0400_03FE => self.io.write16(addr, halfword),
|
0x0400_0000...0x0400_03FE => self.io.write16(addr, halfword),
|
||||||
|
|
||||||
// Internal Display Memory
|
// Internal Display Memory
|
||||||
0x0500_0000...0x0500_03FF => self.ppu.palette.set16(@as(usize, addr - 0x0500_0000), halfword),
|
0x0500_0000...0x0500_03FF => self.ppu.palette.set16(addr - 0x0500_0000, halfword),
|
||||||
0x0600_0000...0x0601_7FFF => self.ppu.vram.set16(@as(usize, addr - 0x0600_0000), halfword),
|
0x0600_0000...0x0601_7FFF => self.ppu.vram.set16(addr - 0x0600_0000, halfword),
|
||||||
0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:16] write 0x{X:} to 0x{X:} in OAM", .{ halfword, addr }),
|
0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:16] write 0x{X:} to 0x{X:} in OAM", .{ halfword, addr }),
|
||||||
|
|
||||||
else => std.log.warn("[Bus:16] ZBA tried to write 0x{X:} to 0x{X:}", .{ halfword, addr }),
|
else => std.log.warn("[Bus:16] ZBA tried to write 0x{X:} to 0x{X:}", .{ halfword, addr }),
|
||||||
|
@ -125,20 +125,20 @@ pub fn write16(self: *Self, addr: u32, halfword: u16) void {
|
||||||
pub fn read8(self: *const Self, addr: u32) u8 {
|
pub fn read8(self: *const Self, addr: u32) u8 {
|
||||||
return switch (addr) {
|
return switch (addr) {
|
||||||
// General Internal Memory
|
// General Internal Memory
|
||||||
0x0000_0000...0x0000_3FFF => self.bios.get8(@as(usize, addr)),
|
0x0000_0000...0x0000_3FFF => self.bios.get8(addr),
|
||||||
0x0200_0000...0x0203_FFFF => self.iwram.get8(addr - 0x0200_0000),
|
0x0200_0000...0x0203_FFFF => self.iwram.get8(addr - 0x0200_0000),
|
||||||
0x0300_0000...0x0300_7FFF => self.ewram.get8(addr - 0x0300_0000),
|
0x0300_0000...0x0300_7FFF => self.ewram.get8(addr - 0x0300_0000),
|
||||||
0x0400_0000...0x0400_03FE => self.io.read8(addr),
|
0x0400_0000...0x0400_03FE => self.io.read8(addr),
|
||||||
|
|
||||||
// Internal Display Memory
|
// Internal Display Memory
|
||||||
0x0500_0000...0x0500_03FF => self.ppu.palette.get8(@as(usize, addr - 0x0500_0000)),
|
0x0500_0000...0x0500_03FF => self.ppu.palette.get8(addr - 0x0500_0000),
|
||||||
0x0600_0000...0x0601_7FFF => self.ppu.vram.get8(@as(usize, addr - 0x0600_0000)),
|
0x0600_0000...0x0601_7FFF => self.ppu.vram.get8(addr - 0x0600_0000),
|
||||||
0x0700_0000...0x0700_03FF => std.debug.panic("[Bus:8] read from 0x{X:} in OAM", .{addr}),
|
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(@as(usize, addr - 0x0800_0000)),
|
0x0800_0000...0x09FF_FFFF => self.pak.get8(addr - 0x0800_0000),
|
||||||
0x0A00_0000...0x0BFF_FFFF => self.pak.get8(@as(usize, addr - 0x0A00_0000)),
|
0x0A00_0000...0x0BFF_FFFF => self.pak.get8(addr - 0x0A00_0000),
|
||||||
0x0C00_0000...0x0DFF_FFFF => self.pak.get8(@as(usize, addr - 0x0C00_0000)),
|
0x0C00_0000...0x0DFF_FFFF => self.pak.get8(addr - 0x0C00_0000),
|
||||||
0x0E00_0000...0x0E00_FFFF => std.debug.panic("[Bus:8] read from 0x{X:} in Game Pak SRAM", .{addr}),
|
0x0E00_0000...0x0E00_FFFF => std.debug.panic("[Bus:8] read from 0x{X:} in Game Pak SRAM", .{addr}),
|
||||||
|
|
||||||
else => {
|
else => {
|
||||||
|
|
|
@ -40,9 +40,7 @@ fn parseTitle(buf: []u8) [12]u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookupMaker(slice: *const [2]u8) ?[]const u8 {
|
fn lookupMaker(slice: *const [2]u8) ?[]const u8 {
|
||||||
const num = @as(u16, slice[1]) << 8 | @as(u16, slice[0]);
|
return switch (std.mem.bytesToValue(u16, slice)) {
|
||||||
|
|
||||||
return switch (num) {
|
|
||||||
0x3130 => "Nintendo",
|
0x3130 => "Nintendo",
|
||||||
else => null,
|
else => null,
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,10 +27,10 @@ pub const Io = struct {
|
||||||
|
|
||||||
pub fn read32(self: *const Self, addr: u32) u32 {
|
pub fn read32(self: *const Self, addr: u32) u32 {
|
||||||
return switch (addr) {
|
return switch (addr) {
|
||||||
0x0400_0000 => @as(u32, self.dispcnt.raw),
|
0x0400_0000 => self.dispcnt.raw,
|
||||||
0x0400_0004 => @as(u32, self.dispstat.raw),
|
0x0400_0004 => self.dispstat.raw,
|
||||||
0x0400_0006 => @as(u32, self.vcount.raw),
|
0x0400_0006 => self.vcount.raw,
|
||||||
0x0400_0200 => @as(u32, self.ie.raw),
|
0x0400_0200 => self.ie.raw,
|
||||||
0x0400_0208 => @boolToInt(self.ime),
|
0x0400_0208 => @boolToInt(self.ime),
|
||||||
else => std.debug.panic("[I/O:32] tried to read from {X:}", .{addr}),
|
else => std.debug.panic("[I/O:32] tried to read from {X:}", .{addr}),
|
||||||
};
|
};
|
||||||
|
|
|
@ -250,7 +250,7 @@ pub const Arm7tdmi = struct {
|
||||||
pub fn step(self: *Self) u64 {
|
pub fn step(self: *Self) u64 {
|
||||||
if (self.cpsr.t.read()) {
|
if (self.cpsr.t.read()) {
|
||||||
const opcode = self.thumbFetch();
|
const opcode = self.thumbFetch();
|
||||||
if (enable_logging) if (self.log_file) |file| self.log(file, @as(u32, opcode));
|
if (enable_logging) if (self.log_file) |file| self.log(file, opcode);
|
||||||
|
|
||||||
thumb_lut[thumbIdx(opcode)](self, self.bus, opcode);
|
thumb_lut[thumbIdx(opcode)](self, self.bus, opcode);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -37,15 +37,15 @@ pub fn halfAndSignedDataTransfer(comptime P: bool, comptime U: bool, comptime I:
|
||||||
0b01 => {
|
0b01 => {
|
||||||
// LDRH
|
// LDRH
|
||||||
const value = bus.read16(address & 0xFFFF_FFFE);
|
const value = bus.read16(address & 0xFFFF_FFFE);
|
||||||
result = std.math.rotr(u32, @as(u32, value), 8 * (address & 1));
|
result = std.math.rotr(u32, value, 8 * (address & 1));
|
||||||
},
|
},
|
||||||
0b10 => {
|
0b10 => {
|
||||||
// LDRSB
|
// LDRSB
|
||||||
result = util.u32SignExtend(8, @as(u32, bus.read8(address)));
|
result = util.u32SignExtend(8, bus.read8(address));
|
||||||
},
|
},
|
||||||
0b11 => {
|
0b11 => {
|
||||||
// LDRSH
|
// LDRSH
|
||||||
result = util.u32SignExtend(16, @as(u32, bus.read16(address & 0xFFFF_FFFE)));
|
result = util.u32SignExtend(16, bus.read16(address & 0xFFFF_FFFE));
|
||||||
},
|
},
|
||||||
0b00 => unreachable, // SWP
|
0b00 => unreachable, // SWP
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ pub fn format14(comptime L: bool, comptime R: bool) InstrFn {
|
||||||
// POP
|
// POP
|
||||||
address = cpu.r[13];
|
address = cpu.r[13];
|
||||||
|
|
||||||
var i: usize = 0;
|
var i: u4 = 0;
|
||||||
while (i < 8) : (i += 1) {
|
while (i < 8) : (i += 1) {
|
||||||
if ((opcode >> @truncate(u3, i)) & 1 == 1) {
|
if ((opcode >> i) & 1 == 1) {
|
||||||
cpu.r[i] = bus.read32(address);
|
cpu.r[i] = bus.read32(address);
|
||||||
address += 4;
|
address += 4;
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,11 @@ pub fn format14(comptime L: bool, comptime R: bool) InstrFn {
|
||||||
address -= 4;
|
address -= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
var i: usize = 8;
|
var i: u4 = 8;
|
||||||
while (i > 0) : (i -= 1) {
|
while (i > 0) : (i -= 1) {
|
||||||
const j = i - 1;
|
const j = i - 1;
|
||||||
|
|
||||||
if ((opcode >> @truncate(u3, j)) & 1 == 1) {
|
if ((opcode >> j) & 1 == 1) {
|
||||||
bus.write32(address, cpu.r[j]);
|
bus.write32(address, cpu.r[j]);
|
||||||
address -= 4;
|
address -= 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub fn format19(comptime is_low: bool) InstrFn {
|
||||||
cpu.r[14] = old_pc | 1;
|
cpu.r[14] = old_pc | 1;
|
||||||
} else {
|
} else {
|
||||||
// Instruction 1
|
// Instruction 1
|
||||||
cpu.r[14] = (cpu.r[15] + 2) +% (u32SignExtend(11, @as(u32, offset)) << 12);
|
cpu.r[14] = (cpu.r[15] + 2) +% (u32SignExtend(11, offset) << 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.inner;
|
}.inner;
|
||||||
|
|
|
@ -60,14 +60,14 @@ pub fn format2(comptime I: bool, is_sub: bool, rn: u3) InstrFn {
|
||||||
if (is_sub) {
|
if (is_sub) {
|
||||||
// SUB
|
// SUB
|
||||||
cpu.r[rd] = if (I) blk: {
|
cpu.r[rd] = if (I) blk: {
|
||||||
break :blk sub(true, cpu, cpu.r[rs], @as(u32, rn));
|
break :blk sub(true, cpu, cpu.r[rs], rn);
|
||||||
} else blk: {
|
} else blk: {
|
||||||
break :blk sub(true, cpu, cpu.r[rs], cpu.r[rn]);
|
break :blk sub(true, cpu, cpu.r[rs], cpu.r[rn]);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// ADD
|
// ADD
|
||||||
cpu.r[rd] = if (I) blk: {
|
cpu.r[rd] = if (I) blk: {
|
||||||
break :blk add(true, cpu, cpu.r[rs], @as(u32, rn));
|
break :blk add(true, cpu, cpu.r[rs], rn);
|
||||||
} else blk: {
|
} else blk: {
|
||||||
break :blk add(true, cpu, cpu.r[rs], cpu.r[rn]);
|
break :blk add(true, cpu, cpu.r[rs], cpu.r[rn]);
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,12 +36,12 @@ pub fn format78(comptime op: u2, comptime T: bool) InstrFn {
|
||||||
},
|
},
|
||||||
0b01 => {
|
0b01 => {
|
||||||
// LDSB
|
// LDSB
|
||||||
cpu.r[rd] = u32SignExtend(8, @as(u32, bus.read8(address)));
|
cpu.r[rd] = u32SignExtend(8, bus.read8(address));
|
||||||
},
|
},
|
||||||
0b10 => {
|
0b10 => {
|
||||||
// LDRH
|
// LDRH
|
||||||
const value = bus.read16(address & 0xFFFF_FFFE);
|
const value = bus.read16(address & 0xFFFF_FFFE);
|
||||||
cpu.r[rd] = std.math.rotr(u32, @as(u32, value), 8 * (address & 1));
|
cpu.r[rd] = std.math.rotr(u32, value, 8 * (address & 1));
|
||||||
},
|
},
|
||||||
0b11 => {
|
0b11 => {
|
||||||
// LDRSH
|
// LDRSH
|
||||||
|
@ -123,7 +123,7 @@ pub fn format10(comptime L: bool, comptime offset: u5) InstrFn {
|
||||||
if (L) {
|
if (L) {
|
||||||
// LDRH
|
// LDRH
|
||||||
const value = bus.read16(address & 0xFFFF_FFFE);
|
const value = bus.read16(address & 0xFFFF_FFFE);
|
||||||
cpu.r[rd] = std.math.rotr(u32, @as(u32, value), 8 * (address & 1));
|
cpu.r[rd] = std.math.rotr(u32, value, 8 * (address & 1));
|
||||||
} else {
|
} else {
|
||||||
// STRH
|
// STRH
|
||||||
bus.write16(address & 0xFFFF_FFFE, @truncate(u16, cpu.r[rd]));
|
bus.write16(address & 0xFFFF_FFFE, @truncate(u16, cpu.r[rd]));
|
||||||
|
|
Loading…
Reference in New Issue