Ypsilon.Emulation.Processor.YCPU.DisassembleALU C# (CSharp) Method

DisassembleALU() private method

private DisassembleALU ( string name, ushort operand, ushort nextword, ushort address, bool showMemoryContents, ushort &instructionSize ) : string
name string
operand ushort
nextword ushort
address ushort
showMemoryContents bool
instructionSize ushort
return string
        private string DisassembleALU(string name, ushort operand, ushort nextword, ushort address, bool showMemoryContents, out ushort instructionSize)
        {
            int addressingmode = (operand & 0x7000) >> 12;
            RegGeneral regDest = (RegGeneral)(operand & 0x0007);
            RegGeneral regSrc = (RegGeneral)((operand & 0x0E00) >> 9);
            bool isEightBit = (operand & 0x0100) != 0;
            SegmentIndex segData = (operand & 0x8000) != 0 ? SegmentIndex.ES : SegmentIndex.DS;
            switch (addressingmode) {
                case 0:
                    if (regSrc == 0) // immediate
                    {
                        if (name == "STO") {
                            instructionSize = 2;
                            return "???";
                        }
                        instructionSize = 4;
                        string disasm =
                            $"{name + (isEightBit ? ".8" : string.Empty),-8}{NameOfRegGP(regDest)}, ${nextword:X4}";
                        if (showMemoryContents)
                            disasm = AppendMemoryContents(disasm, nextword);
                        return disasm;
                    }
                    if ((int)regSrc == 1) // absolute
                    {
                        instructionSize = 4;
                        string disasm =
                            $"{name + (isEightBit ? ".8" : string.Empty),-8}{NameOfRegGP(regDest)}, [${nextword:X4}]";
                        if (showMemoryContents)
                            disasm = AppendMemoryContents(disasm, DebugReadMemory(nextword, segData));
                        return disasm;
                    }
                    else // control register
                    {
                        instructionSize = 2;
                        RegControl cr = (RegControl)((operand & 0x0700) >> 8);
                        string disasm = $"{name,-8}{NameOfRegGP(regDest)}, {NameOfRegSP(cr)}";
                        if (showMemoryContents)
                            disasm = AppendMemoryContents(disasm, nextword);
                        return disasm;
                    }
                case 1: // Register
                    instructionSize = 2;
                    return
                        $"{name + (isEightBit ? ".8" : string.Empty),-8}{NameOfRegGP(regDest)}, {NameOfRegGP(regSrc),-12}(${R[(int)regSrc]:X4})";
                case 2: // Indirect
                    instructionSize = 2;
                    return
                        $"{name + (isEightBit ? ".8" : string.Empty),-8}{NameOfRegGP(regDest)}, [{NameOfRegGP(regSrc)}]        (${DebugReadMemory(R[(int)regSrc], segData):X4})";
                case 3: // Indirect Offset (also Absolute Offset)
                    instructionSize = 4;
                    return
                        $"{name + (isEightBit ? ".8" : string.Empty),-8}{NameOfRegGP(regDest)}, [{NameOfRegGP(regSrc)},${nextword:X4}]  (${DebugReadMemory((ushort)(R[(int)regSrc] + nextword), segData):X4})";
                default: // $4 - $7 are Indirect Indexed
                    instructionSize = 2;
                    RegGeneral regIndex = (RegGeneral)((operand & 0x7000) >> 12);
                    return
                        $"{name + (isEightBit ? ".8" : string.Empty),-8}{NameOfRegGP(regDest)}, [{NameOfRegGP(regSrc)},{NameOfRegGP(regIndex)}]     (${DebugReadMemory((ushort)(R[(int)regSrc] + R[(int)regIndex]), segData):X4})";
            }
        }