Skip to content

Commit

Permalink
[aica/arm] Use a mask rather than a threshold to signal external read…
Browse files Browse the repository at this point in the history
…/writes.

This hacks shouldn't be needed anymore.
  • Loading branch information
Senryoku committed Jul 17, 2024
1 parent d5409b9 commit f8f7c08
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
2 changes: 1 addition & 1 deletion libs/arm7
Submodule arm7 updated 1 files
+14 −12 src/arm7.zig
40 changes: 4 additions & 36 deletions src/aica.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/jit/arm_jit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit f8f7c08

Please sign in to comment.