1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-11-04 22:29:02 -08:00

implement some basic branch pseudo-instructions

This commit is contained in:
Connor Olding 2016-01-02 06:00:05 -08:00
parent c0be8f2ef2
commit 02fc5395a0
2 changed files with 52 additions and 42 deletions

View file

@ -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]

View file

@ -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
+: