diff options
author | Pixel <pixel@nobis-crew.org> | 2013-06-22 18:23:03 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2013-06-22 18:23:03 -0700 |
commit | 8f8d2164a7605b60d2efc9cd0f46ee70a0706d8e (patch) | |
tree | 806eebd420b1c00d7e5c1a6b0c16c39a6a3d0d37 /VP-disasm.lua | |
parent | ad728683a0f8896508bcf24dadf9161b158573af (diff) |
First pass at reinsertion; window computation should now work.
Diffstat (limited to 'VP-disasm.lua')
-rw-r--r-- | VP-disasm.lua | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/VP-disasm.lua b/VP-disasm.lua index 204b280..0fb82fb 100644 --- a/VP-disasm.lua +++ b/VP-disasm.lua @@ -138,6 +138,10 @@ local opcodes_fromstack = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, -- f } +local function disasm_write(self, ...) + if self.out then self.out:write(...) end +end + local function disasm_opcode(self) self.oPC = self.PC self.opcode = self:rdn() @@ -151,27 +155,27 @@ local function disasm_opcode(self) self.flags.is_local = andB(self.opcode, 0x800000) ~= 0 self.flags.from_stack = andB(self.opcode, 0x100000) ~= 0 - self.out:write(string.format("%08X %08X ", self.oPC, self.opcode)) + self:write(string.format("%08X %08X ", self.oPC, self.opcode)) if self.code == 0 then - self.out:write("OPCODE00?!") + self:write("OPCODE00?!") return end local name = opcodes_names[self.code] if name then - self.out:write(string.format("%-8s", name)) + self:write(string.format("%-8s", name)) elseif opcodes_known[self.code] then - self.out:write(string.format("OP_%02X ", self.code)) + self:write(string.format("OP_%02X ", self.code)) else - self.out:write(string.format("UNK%02X ", self.code)) + self:write(string.format("UNK%02X ", self.code)) end if self.flags.from_stack and opcodes_fromstack[self.code] then for i = 1, opcodes_nparams[self.code] do - self.out:write("POP()") - if i ~= opcodes_nparams[self.code] then self.out:write(", ") end + self:write("POP()") + if i ~= opcodes_nparams[self.code] then self:write(", ") end end else local nargs = opcodes_nparams[self.code] @@ -186,42 +190,42 @@ local function disasm_opcode(self) -- 6 = var_idx2 -- 7 = low8 + high8 elseif sv == 1 then - self.out:write(string.format("%02X", self.imm8)) + self:write(string.format("%02X", self.imm8)) nargs = nargs - 1 elseif sv == 2 then - self.out:write(string.format("%04X", self.imm16)) + self:write(string.format("%04X", self.imm16)) nargs = nargs - 1 elseif sv == 3 then - self.out:write(string.format("%08X", self.imm23)) + self:write(string.format("%08X", self.imm23)) nargs = nargs - 1 elseif sv == 4 then - self.out:write(string.format("%02X", self.high8)) + self:write(string.format("%02X", self.high8)) nargs = nargs - 1 elseif sv == 5 then - self.out:write(string.format("%s[%04X]", self.flags.is_local and "locl" or "glbl", self.imm16)) + self:write(string.format("%s[%04X]", self.flags.is_local and "locl" or "glbl", self.imm16)) nargs = nargs - 1 elseif sv == 6 then - self.out:write(string.format("%s[%04X]", self.flags.is_local and "locl" or "glbl", self.idx2)) + self:write(string.format("%s[%04X]", self.flags.is_local and "locl" or "glbl", self.idx2)) nargs = nargs - 1 elseif sv == 7 then - self.out:write(string.format("%02X, %02X", self.imm8, self.high8)) + self:write(string.format("%02X, %02X", self.imm8, self.high8)) nargs = nargs - 2 end if sv ~= 0 and nargs ~= 0 then - self.out:write(", ") + self:write(", ") end for i = 1, opcodes_imms[self.code] do - self.out:write(string.format("%08X", self:rdn())) - if i ~= opcodes_imms[self.code] then self.out:write(", ") end + self:write(string.format("%08X", self:rdn())) + if i ~= opcodes_imms[self.code] then self:write(", ") end nargs = nargs - 1 end if not opcodes_fromstack[self.code] then for i = 1, nargs do - self.out:write("POP()") - if i ~= nargs then self.out:write(", ") end + self:write("POP()") + if i ~= nargs then self:write(", ") end end end end @@ -232,14 +236,14 @@ end local function disasm(self) while self.PC ~= self.EPC do self:disasm_opcode() - self.out:write("\n") + self:write("\n") for padPC = self.oPC + 1, self.PC - 1 do - self.out:write(string.format(" %08X\n", self:rd(padPC))) + self:write(string.format(" %08X\n", self:rd(padPC))) end end end function logic_disasm(logic, o, hooks) - local dobj = { rd = rd, rdn = rdn, disasm_opcode = disasm_opcode, disasm = disasm, PC = 0, fin = logic, out = o, EPC = logic:getsize() / 4, hooks = hooks } + local dobj = { rd = rd, rdn = rdn, disasm_opcode = disasm_opcode, disasm = disasm, PC = 0, fin = logic, out = o, EPC = logic:getsize() / 4, hooks = hooks, write = disasm_write } dobj:disasm() end |