mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-22 16:21:47 -05:00
add a lot of opcodes
This commit is contained in:
parent
b349b87108
commit
bf2ed7fe76
10 changed files with 72 additions and 14 deletions
|
@ -415,6 +415,11 @@ namespace OpenTS2.Lua.Disassembly
|
|||
get { return (int)((long)Bx - Function.Owner.Bias); }
|
||||
}
|
||||
|
||||
public virtual int GetPCForJumpTarget()
|
||||
{
|
||||
return PC;
|
||||
}
|
||||
|
||||
public virtual void PreProcess(Context context)
|
||||
{
|
||||
|
||||
|
@ -483,6 +488,8 @@ namespace OpenTS2.Lua.Disassembly
|
|||
|
||||
public JumpLabel MakeAbsoluteJump(int pc)
|
||||
{
|
||||
var opCodeAtPC = Function.OpCodes[pc];
|
||||
pc = opCodeAtPC.GetPCForJumpTarget();
|
||||
var jLabels = GetJumpLabelsHere(pc);
|
||||
if (jLabels.Count > 0)
|
||||
return jLabels[0];
|
||||
|
|
|
@ -11,9 +11,9 @@ namespace OpenTS2.Lua.Disassembly.OpCodes
|
|||
public override void Disassemble(LuaC50.Context context)
|
||||
{
|
||||
if (GetBool(A))
|
||||
context.Code.WriteLine($"if ({context.RKAsString(B)} == {context.RKAsString(C)}) then");
|
||||
else
|
||||
context.Code.WriteLine($"if ({context.RKAsString(B)} ~= {context.RKAsString(C)}) then");
|
||||
else
|
||||
context.Code.WriteLine($"if ({context.RKAsString(B)} == {context.RKAsString(C)}) then");
|
||||
context.Code.Indentation++;
|
||||
var targetLabel = context.MakeRelativeJump(2);
|
||||
context.Code.WriteGoto(targetLabel);
|
||||
|
|
|
@ -10,11 +10,11 @@ namespace OpenTS2.Lua.Disassembly.OpCodes
|
|||
{
|
||||
public override void PreProcess(LuaC50.Context context)
|
||||
{
|
||||
context.MakeRelativeJump(sBx);
|
||||
context.MakeRelativeJump(sBx+1);
|
||||
}
|
||||
public override void Disassemble(LuaC50.Context context)
|
||||
{
|
||||
var jumpLabel = context.MakeRelativeJump(sBx);
|
||||
var jumpLabel = context.MakeRelativeJump(sBx+1);
|
||||
context.Code.WriteGoto(jumpLabel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ namespace OpenTS2.Lua.Disassembly.OpCodes
|
|||
public override void Disassemble(LuaC50.Context context)
|
||||
{
|
||||
if (GetBool(A))
|
||||
context.Code.WriteLine($"if ({context.RKAsString(B)} < {context.RKAsString(C)}) then");
|
||||
else
|
||||
context.Code.WriteLine($"if ({context.RKAsString(B)} >= {context.RKAsString(C)}) then");
|
||||
else
|
||||
context.Code.WriteLine($"if ({context.RKAsString(B)} < {context.RKAsString(C)}) then");
|
||||
context.Code.Indentation++;
|
||||
var targetLabel = context.MakeRelativeJump(2);
|
||||
context.Code.WriteGoto(targetLabel);
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace OpenTS2.Lua.Disassembly.OpCodes
|
|||
typeof(RETURN), //RETURN
|
||||
typeof(LuaC50.OpCode), //FORLOOP
|
||||
typeof(TFORLOOP), //TFORLOOP
|
||||
typeof(LuaC50.OpCode), //TFORREP
|
||||
typeof(TFORPREP), //TFORPREP
|
||||
typeof(LuaC50.OpCode), //SETLIST
|
||||
typeof(LuaC50.OpCode), //SETLISTO
|
||||
typeof(LuaC50.OpCode), //CLOSE
|
||||
|
|
|
@ -8,6 +8,19 @@ namespace OpenTS2.Lua.Disassembly.OpCodes
|
|||
{
|
||||
public class RETURN : LuaC50.OpCode
|
||||
{
|
||||
public override int GetPCForJumpTarget()
|
||||
{
|
||||
if (!ValidReturnToDisassemble())
|
||||
{
|
||||
var aboveMe = PC - 1;
|
||||
if (aboveMe >= 0)
|
||||
{
|
||||
if (Function.OpCodes[aboveMe] is RETURN)
|
||||
return Function.OpCodes[aboveMe].PC;
|
||||
}
|
||||
}
|
||||
return PC;
|
||||
}
|
||||
public override void Disassemble(LuaC50.Context context)
|
||||
{
|
||||
if (!ValidReturnToDisassemble())
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace OpenTS2.Lua.Disassembly.OpCodes
|
|||
{
|
||||
public override void Disassemble(LuaC50.Context context)
|
||||
{
|
||||
context.Code.WriteLine($"if ({context.R(B)} ~= {C}) then");
|
||||
context.Code.WriteLine($"if ({context.R(B)} == {C}) then");
|
||||
context.Code.Indentation++;
|
||||
context.Code.WriteLine($"{context.R(A)} = {context.R(B)}");
|
||||
context.Code.Indentation--;
|
||||
|
|
|
@ -12,18 +12,23 @@ namespace OpenTS2.Lua.Disassembly.OpCodes
|
|||
{
|
||||
var start = A + 2;
|
||||
var end = A + 2 + C;
|
||||
var loopValues = "";
|
||||
var retValues = "";
|
||||
for (var i = start; i <= end; i++)
|
||||
{
|
||||
if (i > start)
|
||||
loopValues += ", ";
|
||||
loopValues += context.R((ushort)i);
|
||||
retValues += ", ";
|
||||
retValues += context.R((ushort)i);
|
||||
|
||||
// Probably don't need to do this
|
||||
context.Code.WriteLine(context.R((ushort)i) + " = nil");
|
||||
//context.Code.WriteLine(context.R((ushort)i) + " = nil");
|
||||
}
|
||||
|
||||
context.Code.WriteLine("for " + loopValues + " in " + context.R((ushort)(A)) + ", " + context.R((ushort)(A + 1)) + " do");
|
||||
context.Code.WriteLine(retValues + " = " + context.R(A) + "("+context.R((ushort)(A+1))+", "+context.R((ushort)(A+2))+")");
|
||||
context.Code.WriteLine("if " + context.R((ushort)(A + 2)) + " ~= nil then");
|
||||
context.Code.Indentation++;
|
||||
context.Code.WriteGoto(context.MakeRelativeJump(2));
|
||||
context.Code.Indentation--;
|
||||
context.Code.WriteEnd();
|
||||
//context.Code.WriteLine("for " + loopValues + " in " + context.R((ushort)(A)) + ", " + context.R((ushort)(A + 1)) + " do");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
Assets/Scripts/OpenTS2/Lua/Disassembly/OpCodes/TFORPREP.cs
Normal file
22
Assets/Scripts/OpenTS2/Lua/Disassembly/OpCodes/TFORPREP.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenTS2.Lua.Disassembly.OpCodes
|
||||
{
|
||||
public class TFORPREP : LuaC50.OpCode
|
||||
{
|
||||
public override void PreProcess(LuaC50.Context context)
|
||||
{
|
||||
context.MakeRelativeJump(sBx + 1);
|
||||
}
|
||||
public override void Disassemble(LuaC50.Context context)
|
||||
{
|
||||
context.Code.WriteLine(context.R((ushort)(A + 1)) + " = " + context.R(A)+ " -- tforprep...");
|
||||
var jmp = context.MakeRelativeJump(sBx + 1);
|
||||
context.Code.WriteGoto(jmp);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/OpenTS2/Lua/Disassembly/OpCodes/TFORPREP.cs.meta
generated
Normal file
11
Assets/Scripts/OpenTS2/Lua/Disassembly/OpCodes/TFORPREP.cs.meta
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2e01f0b7b9807b140bfa64e166f145e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue