From 0935b408ec5a62af5d75e5c38bc0c0a9cca31973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ada=20Gottenstr=C3=A4ter?= Date: Sun, 13 Jun 2021 11:22:07 +0200 Subject: [PATCH] Fix reversed assignment ops --- Gear/EmulationCore/InstructionDisassembler.cs | 4 ++-- Gear/EmulationCore/InterpretedCog.cs | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Gear/EmulationCore/InstructionDisassembler.cs b/Gear/EmulationCore/InstructionDisassembler.cs index e2db3f0..c0f829f 100644 --- a/Gear/EmulationCore/InstructionDisassembler.cs +++ b/Gear/EmulationCore/InstructionDisassembler.cs @@ -115,11 +115,11 @@ private static string GetEffectCode(Propeller.MemoryManager memory, bool useShor if (useShortOpcodes) { - effect += "(" + ParsedAssignment.GetBasicInstruction().NameBrief + ")"; + effect += "(" + ParsedAssignment.GetBasicInstruction().NameBrief + (ParsedAssignment.Swap ? ",reverse" : "") + ")"; } else { - effect += ParsedAssignment.GetBasicInstruction().Name; + effect += ParsedAssignment.GetBasicInstruction().Name + (ParsedAssignment.Swap ? " REVERSE" : ""); } if (!ParsedAssignment.Math) diff --git a/Gear/EmulationCore/InterpretedCog.cs b/Gear/EmulationCore/InterpretedCog.cs index b80b78b..be995b0 100644 --- a/Gear/EmulationCore/InterpretedCog.cs +++ b/Gear/EmulationCore/InterpretedCog.cs @@ -248,10 +248,10 @@ override public bool DoInstruction() byte op = Hub.DirectReadByte(PC++); frameFlag = FrameState.frameNone; - // Masked Memory Operations + // Math Operations if (op >= 0xE0) { - PushStack(BaseMathOp((byte)(op - 0xE0), false, PopStack())); + PushStack(BaseMathOp((byte)(op - 0xE0), false, false, PopStack())); } // Masked Memory Operations else if (op >= 0x80) @@ -897,7 +897,7 @@ private void CogMemoryOp(uint mask, int lowestbit) } } - private uint BaseMathOp(byte op, bool inplace, uint initial) + private uint BaseMathOp(byte op, bool inplace, bool swap, uint initial) { // --- Unary Operators --- switch (op) @@ -940,8 +940,13 @@ private uint BaseMathOp(byte op, bool inplace, uint initial) if (inplace) { - left = initial; - right = PopStack(); + if (swap) { + left = PopStack(); + right = initial; + } else { + left = initial; + right = PopStack(); + } } else { @@ -1196,9 +1201,9 @@ private uint InplaceEffect(uint originalValue) op &= 0x7F; // Use Main opcode set - if (op >= 0x40 && op <= 0x5F) + if (op >= 0x40) { - stored = result = BaseMathOp((byte)(op - 0x40), true, originalValue); + stored = result = BaseMathOp((byte)(op & 0x1F), true, (op & 0x20) != 0, originalValue); } else {