2022-02-02 12:44:33 +00:00
|
|
|
const Bus = @import("../../Bus.zig");
|
|
|
|
const Arm7tdmi = @import("../../cpu.zig").Arm7tdmi;
|
2022-07-27 16:23:29 +00:00
|
|
|
const InstrFn = @import("../../cpu.zig").arm.InstrFn;
|
2022-02-02 12:44:33 +00:00
|
|
|
|
2023-03-10 06:05:31 +00:00
|
|
|
const rotr = @import("zba-util").rotr;
|
2022-03-17 01:28:24 +00:00
|
|
|
|
2022-02-02 12:44:33 +00:00
|
|
|
pub fn singleDataSwap(comptime B: bool) InstrFn {
|
|
|
|
return struct {
|
|
|
|
fn inner(cpu: *Arm7tdmi, bus: *Bus, opcode: u32) void {
|
|
|
|
const rn = opcode >> 16 & 0xF;
|
|
|
|
const rd = opcode >> 12 & 0xF;
|
|
|
|
const rm = opcode & 0xF;
|
|
|
|
|
|
|
|
const address = cpu.r[rn];
|
|
|
|
|
|
|
|
if (B) {
|
|
|
|
// SWPB
|
2022-04-08 19:48:43 +00:00
|
|
|
const value = bus.read(u8, address);
|
|
|
|
bus.write(u8, address, @truncate(u8, cpu.r[rm]));
|
2022-02-02 12:44:33 +00:00
|
|
|
cpu.r[rd] = value;
|
|
|
|
} else {
|
|
|
|
// SWP
|
2022-04-08 19:48:43 +00:00
|
|
|
const value = rotr(u32, bus.read(u32, address), 8 * (address & 0x3));
|
|
|
|
bus.write(u32, address, cpu.r[rm]);
|
2022-02-02 12:44:33 +00:00
|
|
|
cpu.r[rd] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.inner;
|
|
|
|
}
|