From 02fc5395a0f9e32140154370566f88c08907f2c4 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 2 Jan 2016 06:00:05 -0800 Subject: [PATCH] implement some basic branch pseudo-instructions --- Lua/inject/lips.lua | 71 +++++++++++++++++++++++++------------------- Lua/inject/spawn.asm | 23 +++++++------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/Lua/inject/lips.lua b/Lua/inject/lips.lua index d96ee45..b8c2cea 100644 --- a/Lua/inject/lips.lua +++ b/Lua/inject/lips.lua @@ -409,6 +409,8 @@ local instructions = { -- pseudo-instructions B = {4, 'r', '00o'}, -- BEQ R0, R0, offset BAL = {1, 'r', '0Co', 17}, -- BGEZAL R0, offset + BEQZ = {4, 'sr', 's0o'}, -- BEQ RS, R0, offset + BNEZ = {5, 'sr', 's0o'}, -- BNE RS, R0, offset CL = {0, 'd', '00d0C', 37}, -- OR RD, R0, R0 MOV = {0, 'ds', 's0d0C', 37}, -- OR RD, RS, R0 NEG = {0, 'dt', '0td0C', 34}, -- SUB RD, R0, RT @@ -437,37 +439,18 @@ local instructions = { ROL = {}, -- SLL, SRL, OR ROR = {}, -- SRL, SLL, OR - SEQ = {}, - SEQI = {}, - SEQIU = {}, - SEQU = {}, - SGE = {}, - SGEI = {}, - SGEIU = {}, - SGEU = {}, - SGT = {}, - SGTI = {}, - SGTIU = {}, - SGTU = {}, - SLE = {}, - SLEI = {}, - SLEIU = {}, - SLEU = {}, - SNE = {}, - SNEI = {}, - SNEIU = {}, - SNEU = {}, + SEQ = {}, SEQI = {}, SEQIU = {}, SEQU = {}, + SGE = {}, SGEI = {}, SGEIU = {}, SGEU = {}, + SGT = {}, SGTI = {}, SGTIU = {}, SGTU = {}, + SLE = {}, SLEI = {}, SLEIU = {}, SLEU = {}, + SNE = {}, SNEI = {}, SNEIU = {}, SNEU = {}, - BEQI = {}, - BNEI = {}, - BGE = {}, - BGEI = {}, - BLE = {}, - BLEI = {}, - BLT = {}, - BLTI = {}, - BGT = {}, - BGTI = {}, + BEQI = {}, + BNEI = {}, + BGE = {}, BGEI = {}, + BLE = {}, BLEI = {}, + BLT = {}, BLTI = {}, + BGT = {}, BGTI = {}, } local all_instructions = {} @@ -1263,6 +1246,34 @@ function overrides.JR(self, name) self:format_out(jr[3], jr[1], args, jr[4], jr[5]) end +local branch_basics = { + BEQI = "BEQ", + BNEI = "BNE", +} + +function overrides.BEQI(self, name) + local addiu = instructions['ADDIU'] + local branch = instructions[branch_basics[name]] + local args = {} + local reg = self:register() + self:optional_comma() + args.immediate = self:const() + self:optional_comma() + args.offset = {'SIGNED', self:const('relative')} + + if reg == 'AT' then + self:error('register cannot be AT in this pseudo-instruction') + end + + args.rt = 'AT' + args.rs = 'R0' + self:format_out(addiu[3], addiu[1], args, addiu[4], addiu[5]) + + args.rs = reg + self:format_out(branch[3], branch[1], args, branch[4], branch[5]) +end +overrides.BNEI = overrides.BEQI + function Parser:instruction() local name = self.tok local h = instructions[name] diff --git a/Lua/inject/spawn.asm b/Lua/inject/spawn.asm index 10c792d..4cd4d0c 100644 --- a/Lua/inject/spawn.asm +++ b/Lua/inject/spawn.asm @@ -20,34 +20,33 @@ lhu t9, @rupees_offset(t0) lw s1, hold_delay andi t4, t2, @button_any - bne t4, r0, + + bnez t4, + addi s1, s1, 1 li s1, 0 +: - subi t4, s1, 1 - beq t4, r0, + + beqi s1, 1, + nop subi t4, s1, @hold_delay_amount bltz t4, return nop +: andi t3, t2, @button_D_up - beq t3, r0, + + beqz t3, + nop addi t9, t9, 1 +: andi t3, t2, @button_D_down - beq t3, r0, + + beqz t3, + nop subi t9, t9, 1 +: andi t3, t2, @button_D_right - beq t3, r0, + + beqz t3, + nop addi t9, t9, 10 +: andi t3, t2, @button_D_left - beq t3, r0, + + beqz t3, + nop subi t9, t9, 10 +: @@ -63,7 +62,7 @@ +: sh t9, @rupees_offset(t0) andi t3, t2, @button_L - beq t3, r0, return + beqz t3, return nop mov a0, t9 bal simple_spawn @@ -76,7 +75,7 @@ simple_spawn: // args: a0 (actor to spawn) push 4, 9, ra jal load_object sw a0, 56(sp) // keep me updated! - bne v0, r0, simple_spawn_return + bnez v0, simple_spawn_return lw a2, 56(sp) // keep me updated! li a1, @global_context addi a0, a1, @actor_spawn_offset @@ -122,11 +121,11 @@ load_object: sll t1, a0, 1 addu t0, t0, t1 lhu s0, 0(t0) // object number - beq s0, r0, + + beqz s0, + nop bal is_object_loaded mov a0, s0 - bne v0, r0, + + bnez v0, + cl v0 li t8, @global_context li t9, @object_spawn_offset @@ -167,7 +166,7 @@ is_object_loaded: beq a0, t2, + subi t1, t1, 1 // TODO: double check there's no off-by-one error addi t0, t0, 68 - bne t1, r0, - + bnez t1, - nop cl v0 +: