I believe this to be necessary in order to get hardware interrupts working. thumb.gba test 108 fails but I'm committing anyways (despite the regression) because this is kind of rebase/merge hell and I have something that at least sort of works rn
		
			
				
	
	
		
			29 lines
		
	
	
		
			825 B
		
	
	
	
		
			Zig
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			825 B
		
	
	
	
		
			Zig
		
	
	
	
	
	
| const std = @import("std");
 | |
| 
 | |
| const Bus = @import("../../Bus.zig");
 | |
| const Arm7tdmi = @import("../../cpu.zig").Arm7tdmi;
 | |
| const InstrFn = @import("../../cpu.zig").arm.InstrFn;
 | |
| 
 | |
| const sext = @import("../../util.zig").sext;
 | |
| 
 | |
| pub fn branch(comptime L: bool) InstrFn {
 | |
|     return struct {
 | |
|         fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u32) void {
 | |
|             if (L) cpu.r[14] = cpu.r[15] - 4;
 | |
| 
 | |
|             cpu.r[15] +%= sext(u32, u24, opcode) << 2;
 | |
|             cpu.pipe.reload(u32, cpu);
 | |
|         }
 | |
|     }.inner;
 | |
| }
 | |
| 
 | |
| pub fn branchAndExchange(cpu: *Arm7tdmi, _: *Bus, opcode: u32) void {
 | |
|     const rn = opcode & 0xF;
 | |
| 
 | |
|     const thumb = cpu.r[rn] & 1 == 1;
 | |
|     cpu.r[15] = cpu.r[rn] & if (thumb) ~@as(u32, 1) else ~@as(u32, 3);
 | |
| 
 | |
|     cpu.cpsr.t.write(thumb);
 | |
|     if (thumb) cpu.pipe.reload(u16, cpu) else cpu.pipe.reload(u32, cpu);
 | |
| }
 |