예제 #1
0
        /// <summary>
        /// Disassemble a calculator entry
        /// </summary>
        private DisassemblyItem DisassembleCalculatorEntry(ushort address, byte calcCode, out bool carryOn)
        {
            // --- Create the default disassembly item
            var item = new DisassemblyItem(address)
            {
                LastAddress = (ushort)(_offset - 1),
                Instruction = $".defb #{calcCode:X2}"
            };

            var opCodes = new List <byte> {
                calcCode
            };

            carryOn = true;

            // --- If we're in series mode, obtain the subsequent series value
            if (_seriesCount > 0)
            {
                var lenght = (calcCode >> 6) + 1;
                if ((calcCode & 0x3F) == 0)
                {
                    lenght++;
                }
                for (var i = 0; i < lenght; i++)
                {
                    var nextByte = Fetch();
                    opCodes.Add(nextByte);
                }
                item.Instruction = ".defb " + string.Join(", ", opCodes.Select(o => $"#{o:X2}"));
                item.HardComment = $"({FloatNumber.FromCompactBytes(opCodes)})";
                _seriesCount--;
                return(item);
            }

            // --- Generate the output according the calculation op code
            switch (calcCode)
            {
            case 0x00:
            case 0x33:
            case 0x35:
                var jump = Fetch();
                opCodes.Add(jump);
                var jumpAddr = (ushort)(_offset - 1 + (sbyte)jump);
                _output.CreateLabel(jumpAddr, null);
                item.Instruction = $".defb #{calcCode:X2}, #{jump:X2}";
                item.HardComment = $"({s_CalcOps[calcCode]}: {GetLabelName(jumpAddr)})";
                carryOn          = calcCode != 0x33;
                break;

            case 0x34:
                _seriesCount     = 1;
                item.HardComment = "(stk-data)";
                break;

            case 0x38:
                item.HardComment = "(end-calc)";
                carryOn          = false;
                break;

            case 0x86:
            case 0x88:
            case 0x8C:
                _seriesCount     = calcCode - 0x80;
                item.HardComment = $"(series-0{calcCode-0x80:X1})";
                break;

            case 0xA0:
            case 0xA1:
            case 0xA2:
            case 0xA3:
            case 0xA4:
                var constNo = calcCode - 0xA0;
                item.HardComment = GetIndexedCalcOp(0x3F, constNo);
                break;

            case 0xC0:
            case 0xC1:
            case 0xC2:
            case 0xC3:
            case 0xC4:
            case 0xC5:
                var stNo = calcCode - 0xC0;
                item.HardComment = GetIndexedCalcOp(0x40, stNo);
                break;

            case 0xE0:
            case 0xE1:
            case 0xE2:
            case 0xE3:
            case 0xE4:
            case 0xE5:
                var getNo = calcCode - 0xE0;
                item.HardComment = GetIndexedCalcOp(0x41, getNo);
                break;

            default:
                var comment = s_CalcOps.ContainsKey(calcCode)
                        ? s_CalcOps[calcCode]
                        : $"calc code: #{calcCode:X2}";
                item.HardComment = $"({comment})";
                break;
            }
            return(item);
        }
예제 #2
0
        private void TestFloat(List <byte> bytes, float value)
        {
            var convVal = FloatNumber.FromCompactBytes(bytes);

            Math.Abs(convVal - value).ShouldBeLessThanOrEqualTo((float)1.0e-12);
        }