Example #1
0
        public static byte[] DisassembleGetOpcodeBytes(SM83 cpu, ushort address)
        {
            var opcode = new byte[3];

            for (int i = 0; i < opcode.Length; i++)
            {
                opcode[i] = address + i <= 0xFFFF ? cpu.memoryReadDelegate((ushort)(address + i)) : (byte)0;
            }
            return(opcode);
        }
Example #2
0
 public static int DisassembleGetOpcodeLen(SM83 cpu, byte[] opcode)
 {
     if (opcode[0] == 0xCB)
     {
         return(opcodeLengthPrefixCB[opcode[1]]);
     }
     else
     {
         return(opcodeLengthNoPrefix[opcode[0]]);
     }
 }
Example #3
0
        public static string DisassembleMakeMnemonicString(SM83 cpu, byte[] opcode)
        {
            var len       = DisassembleGetOpcodeLen(cpu, opcode);
            var start     = opcode[0] == 0xCB ? 1 : 0;
            var mnemonics = opcode[0] == 0xCB ? opcodeMnemonicPrefixCB : opcodeMnemonicNoPrefix;

            switch (len - start)
            {
            case 1: return(mnemonics[opcode[start]]);

            case 2: return(string.Format(mnemonics[opcode[start]], opcode[start + 1]));

            case 3: return(string.Format(mnemonics[opcode[start]], (opcode[start + 2] << 8 | opcode[start + 1])));

            default: return(string.Empty);
            }
        }
Example #4
0
        public static string PrintInterrupt(SM83 cpu)
        {
            var intFlags  = (InterruptSource)cpu.memoryReadDelegate(0xFF0F);
            var intEnable = (InterruptSource)cpu.memoryReadDelegate(0xFFFF);

            var intFlagsString =
                $"{((intFlags & InterruptSource.VBlank) != 0 ? "V" : "-")}" +
                $"{((intFlags & InterruptSource.LCDCStatus) != 0 ? "L" : "-")}" +
                $"{((intFlags & InterruptSource.TimerOverflow) != 0 ? "T" : "-")}" +
                $"{((intFlags & InterruptSource.SerialIO) != 0 ? "S" : "-")}" +
                $"{((intFlags & InterruptSource.Keypad) != 0 ? "K" : "-")}";

            var intEnableString =
                $"{((intEnable & InterruptSource.VBlank) != 0 ? "V" : "-")}" +
                $"{((intEnable & InterruptSource.LCDCStatus) != 0 ? "L" : "-")}" +
                $"{((intEnable & InterruptSource.TimerOverflow) != 0 ? "T" : "-")}" +
                $"{((intEnable & InterruptSource.SerialIO) != 0 ? "S" : "-")}" +
                $"{((intEnable & InterruptSource.Keypad) != 0 ? "K" : "-")}";

            return($"IME:{(cpu.ime ? "1" : "0")} IF:{intFlagsString} IE:{intEnableString}");
        }
Example #5
0
 public static string DisassembleMakeByteString(SM83 cpu, byte[] opcode)
 {
     return(string.Join(" ", opcode.Select(x => $"{x:X2}").Take(DisassembleGetOpcodeLen(cpu, opcode))));
 }
Example #6
0
        public static string DisassembleOpcode(SM83 cpu, ushort address)
        {
            var opcode = DisassembleGetOpcodeBytes(cpu, address);

            return($"0x{address:X4} | {DisassembleMakeByteString(cpu, opcode).PadRight(15)} | {DisassembleMakeMnemonicString(cpu, opcode)}");
        }
Example #7
0
 public static string PrintFlags(SM83 cpu)
 {
     return($"{(cpu.IsFlagSet(Flags.Zero) ? "Z" : "-")}{(cpu.IsFlagSet(Flags.Subtract) ? "N" : "-")}{(cpu.IsFlagSet(Flags.HalfCarry) ? "H" : "-")}{(cpu.IsFlagSet(Flags.Carry) ? "C" : "-")}");
 }
Example #8
0
 public static string PrintRegisters(SM83 cpu)
 {
     return($"AF:{cpu.af.Word:X4} BC:{cpu.bc.Word:X4} DE:{cpu.de.Word:X4} HL:{cpu.hl.Word:X4} SP:{cpu.sp:X4}");
 }