Compare commits
No commits in common. "68012f84d3991b407402b5d73526943958093d68" and "f2f4bb205a6796b5a580f7cae0ccc9feb8445613" have entirely different histories.
68012f84d3
...
f2f4bb205a
|
@ -15,7 +15,7 @@ An in-progress Gameboy Advance Emulator written in Zig ⚡!
|
||||||
- [x] `midikey2freq`
|
- [x] `midikey2freq`
|
||||||
- [ ] `swi-tests-random`
|
- [ ] `swi-tests-random`
|
||||||
- [ ] [destoer's GBA Tests](https://github.com/destoer/gba_tests)
|
- [ ] [destoer's GBA Tests](https://github.com/destoer/gba_tests)
|
||||||
- [x] `cond_invalid.gba`
|
- [ ] `cond_invalid.gba`
|
||||||
- [x] `dma_priority.gba`
|
- [x] `dma_priority.gba`
|
||||||
- [x] `hello_world.gba`
|
- [x] `hello_world.gba`
|
||||||
- [x] `if_ack.gba`
|
- [x] `if_ack.gba`
|
||||||
|
|
|
@ -30,8 +30,6 @@ pub const Apu = struct {
|
||||||
cnt: io.SoundControl,
|
cnt: io.SoundControl,
|
||||||
|
|
||||||
sampling_cycle: u2,
|
sampling_cycle: u2,
|
||||||
|
|
||||||
// TODO: Research whether we can have Atomic Pointers
|
|
||||||
stream: *SDL.SDL_AudioStream,
|
stream: *SDL.SDL_AudioStream,
|
||||||
sched: *Scheduler,
|
sched: *Scheduler,
|
||||||
|
|
||||||
|
|
|
@ -459,7 +459,7 @@ pub fn checkCond(cpsr: PSR, cond: u4) bool {
|
||||||
0xC => !cpsr.z.read() and (cpsr.n.read() == cpsr.v.read()), // GT - Greater than
|
0xC => !cpsr.z.read() and (cpsr.n.read() == cpsr.v.read()), // GT - Greater than
|
||||||
0xD => cpsr.z.read() or (cpsr.n.read() != cpsr.v.read()), // LE - Less than or equal
|
0xD => cpsr.z.read() or (cpsr.n.read() != cpsr.v.read()), // LE - Less than or equal
|
||||||
0xE => true, // AL - Always
|
0xE => true, // AL - Always
|
||||||
0xF => false, // NV - Never (reserved in ARMv3 and up, but seems to have not changed?)
|
0xF => std.debug.panic("[CPU/Cond] 0xF is a reserved condition field", .{}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,12 @@ pub fn psrTransfer(comptime I: bool, comptime R: bool, comptime kind: u2) InstrF
|
||||||
// MSR
|
// MSR
|
||||||
const field_mask = @truncate(u4, opcode >> 16 & 0xF);
|
const field_mask = @truncate(u4, opcode >> 16 & 0xF);
|
||||||
const rm_idx = opcode & 0xF;
|
const rm_idx = opcode & 0xF;
|
||||||
const right = if (I) rotr(u32, opcode & 0xFF, (opcode >> 8 & 0xF) * 2) else cpu.r[rm_idx];
|
const right = if (I) rotr(u32, opcode & 0xFF, (opcode >> 8 & 0xF) << 1) else cpu.r[rm_idx];
|
||||||
|
|
||||||
if (R and !cpu.hasSPSR()) log.err("Tried to write to SPSR in User/System Mode", .{});
|
if (R and !cpu.hasSPSR()) log.err("Tried to write to SPSR in User/System Mode", .{});
|
||||||
|
|
||||||
if (R) {
|
if (R) {
|
||||||
// arm.gba seems to expect the SPSR to do somethign in SYS mode,
|
if (cpu.isPrivileged()) cpu.spsr.raw = fieldMask(&cpu.spsr, field_mask, right);
|
||||||
// so we just assume that despite writing to the SPSR in USR or SYS mode
|
|
||||||
// being UNPREDICTABLE, it just magically has a working SPSR somehow
|
|
||||||
cpu.spsr.raw = fieldMask(&cpu.spsr, field_mask, right);
|
|
||||||
} else {
|
} else {
|
||||||
if (cpu.isPrivileged()) cpu.setCpsr(fieldMask(&cpu.cpsr, field_mask, right));
|
if (cpu.isPrivileged()) cpu.setCpsr(fieldMask(&cpu.cpsr, field_mask, right));
|
||||||
}
|
}
|
||||||
|
@ -44,8 +41,6 @@ pub fn psrTransfer(comptime I: bool, comptime R: bool, comptime kind: u2) InstrF
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fieldMask(psr: *const PSR, field_mask: u4, right: u32) u32 {
|
fn fieldMask(psr: *const PSR, field_mask: u4, right: u32) u32 {
|
||||||
// This bitwise ORs bits 3 and 0 of the field mask into a u2
|
|
||||||
// We do this because we only care about bits 7:0 and 31:28 of the CPSR
|
|
||||||
const bits = @truncate(u2, (field_mask >> 2 & 0x2) | (field_mask & 1));
|
const bits = @truncate(u2, (field_mask >> 2 & 0x2) | (field_mask & 1));
|
||||||
|
|
||||||
const mask: u32 = switch (bits) {
|
const mask: u32 = switch (bits) {
|
||||||
|
|
|
@ -266,7 +266,6 @@ fn initAudio(apu: *Apu) SDL.SDL_AudioDeviceID {
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Sometimes, we hear garbage upon program start. Why?
|
|
||||||
export fn audioCallback(userdata: ?*anyopaque, stream: [*c]u8, len: c_int) void {
|
export fn audioCallback(userdata: ?*anyopaque, stream: [*c]u8, len: c_int) void {
|
||||||
const apu = @ptrCast(*Apu, @alignCast(8, userdata));
|
const apu = @ptrCast(*Apu, @alignCast(8, userdata));
|
||||||
_ = SDL.SDL_AudioStreamGet(apu.stream, stream, len);
|
_ = SDL.SDL_AudioStreamGet(apu.stream, stream, len);
|
||||||
|
|
Loading…
Reference in New Issue