diff --git a/libs/arm7 b/libs/arm7 index 9d510375..3dc4cf81 160000 --- a/libs/arm7 +++ b/libs/arm7 @@ -1 +1 @@ -Subproject commit 9d51037505d6f4ad76ca9ba38be82c73541bfc7a +Subproject commit 3dc4cf81470b0bdd23b4b3f8f0acb5111fd9ea34 diff --git a/src/aica.zig b/src/aica.zig index a2aee854..de129e16 100644 --- a/src/aica.zig +++ b/src/aica.zig @@ -11,10 +11,6 @@ const Dreamcast = @import("dreamcast.zig").Dreamcast; // Yamaha AICA Audio Chip // Most notable source outside of official docs: Neill Corlett's Yamaha AICA notes -const Hacks = struct { - const ignore_out_of_bounds_accesses = true; // Don't crash when reading/writing out of bounds. Helps in Speed Devils (See #36). -}; - const SampleFormat = enum(u2) { i16 = 0, // 16-bit signed little-endian i8 = 1, // 8-bit signed @@ -748,49 +744,21 @@ pub const AICA = struct { } pub fn read8_from_arm(self: *AICA, addr: u32) u8 { - if (!(addr >= 0x00800000 and addr < 0x00808000)) { - aica_log.err(termcolor.red("Out of bounds read8 from ARM. Address: 0x{X:0>8}"), .{addr}); - if (Hacks.ignore_out_of_bounds_accesses) - return 0; - self.arm_debug_dump(); - self.dump_wave_memory(); - @panic("AICA read8 from ARM out of bounds address"); - } + std.debug.assert(addr & self.arm7.external_memory_address_mask != 0); return self.read_register(u8, addr); } pub fn read32_from_arm(self: *AICA, addr: u32) u32 { - if (!(addr >= 0x00800000 and addr < 0x00808000)) { - aica_log.err(termcolor.red("Out of bounds read32 from ARM. Address: 0x{X:0>8}"), .{addr}); - if (Hacks.ignore_out_of_bounds_accesses) - return 0; - self.arm_debug_dump(); - self.dump_wave_memory(); - @panic("AICA read32 from ARM out of bounds address"); - } + std.debug.assert(addr & self.arm7.external_memory_address_mask != 0); return self.read_register(u32, addr); } pub fn write8_from_arm(self: *AICA, addr: u32, value: u8) void { - if (!(addr >= 0x00800000 and addr < 0x00808000)) { - aica_log.err(termcolor.red("Out of bounds write8 from ARM: 0x{X:0>8} = 0x{X:0>2}"), .{ addr, value }); - if (Hacks.ignore_out_of_bounds_accesses) - return; - self.arm_debug_dump(); - self.dump_wave_memory(); - @panic("AICA write8 from ARM out of bounds address"); - } + std.debug.assert(addr & self.arm7.external_memory_address_mask != 0); self.write_register(u8, addr, value); } pub fn write32_from_arm(self: *AICA, addr: u32, value: u32) void { - if (!(addr >= 0x00800000 and addr < 0x00808000)) { - aica_log.err(termcolor.red("Out of bounds write32 from ARM: 0x{X:0>8} = 0x{X:0>8}"), .{ addr, value }); - if (Hacks.ignore_out_of_bounds_accesses) - return; - self.arm_debug_dump(); - self.dump_wave_memory(); - @panic("AICA write32 from ARM out of bounds address"); - } + std.debug.assert(addr & self.arm7.external_memory_address_mask != 0); self.write_register(u32, addr, value); } diff --git a/src/jit/arm_jit.zig b/src/jit/arm_jit.zig index d2d8d695..fedd12f7 100644 --- a/src/jit/arm_jit.zig +++ b/src/jit/arm_jit.zig @@ -301,7 +301,7 @@ fn store_wave_memory(b: *JITBlock, ctx: *const JITContext, comptime T: type, add fn load_mem(b: *JITBlock, ctx: *const JITContext, comptime T: type, dst: JIT.Register, addr: JIT.Operand) !void { switch (addr) { .imm32 => |addr_imm32| { - if (addr_imm32 < ctx.cpu.external_memory_address_threshold) { + if ((addr_imm32 & ctx.cpu.external_memory_address_mask) == 0) { try load_wave_memory(b, ctx, T, dst, addr_imm32); } else { // TODO: External memory, fallback for now! @@ -336,7 +336,7 @@ fn load_mem(b: *JITBlock, ctx: *const JITContext, comptime T: type, dst: JIT.Reg fn store_mem(b: *JITBlock, ctx: *const JITContext, comptime T: type, addr: JIT.Operand, value: JIT.Register) !void { switch (addr) { .imm32 => |addr_imm32| { - if (addr_imm32 < ctx.cpu.external_memory_address_threshold) { + if ((addr_imm32 & ctx.cpu.external_memory_address_mask) == 0) { try store_wave_memory(b, ctx, T, addr_imm32, value); } else { // TODO: External memory, fallback for now!