static void Main(string[] args) { try { HandleInterrupt += (c, intr, code) => { c.Interrupt(intr, code); }; ThreadCreationHandler th = null; th += HandleThreadCreation; ThreadJoinedHandler th2 = null; th2 += HandleThreadJoin; CPU.CPU a = CPU.CPU.CPUFactory(); a.mov(CPU.REG.AX, 100); CPU.CPU.DebugRegs(a); ThreadStart l = () => Console.WriteLine("Thread Created"); Action l2 = () => Console.WriteLine("Thread Joined"); Thread t = th(l); t.Start(); t.Join(); th2(l2); a.mov(CPU.REG.BX, 10); a.mov(CPU.REG.AX, 0x03); a.Interrupt(CPU.CPU.INTERRUPT.BIOS, 0x13); a.mov(CPU.REG.BX, 0); a.mov(CPU.REG.AX, 0x02); a.Interrupt(CPU.CPU.INTERRUPT.BIOS, 0x13); a.mov(CPU.REG.AX, 10); a.Interrupt(CPU.CPU.INTERRUPT.BIOS, 0x05); Console.ReadKey(); } catch (CPU.InterruptException e) { if (HandleInterrupt != null) { HandleInterrupt(e.cpu, e.intr, e.code); } } catch (Exception e) { Console.Write(e.Message); Console.ReadKey(); } }
public Device(Cartridge.Cartridge cartridge, DeviceType type, IRenderer renderer, ISoundOutput soundOutput, byte[] bootRom) { Log = new LoggerConfiguration() .MinimumLevel.Information() .CreateLogger(); // A bit of double checking that we're loading a valid cartridge for the device type if (cartridge.CGBSupportCode == CGBSupportCode.CGBExclusive && type == DeviceType.DMG) { Log.Error("Cartridge can't be loaded because it's CGB only and this device was created as DMG"); throw new ApplicationException("Cartridge can't be loaded because it's CGB only and this device was created as DMG"); } Type = type; Mode = cartridge.CGBSupportCode switch { CGBSupportCode.CGBExclusive => DeviceType.CGB, CGBSupportCode.CGBCompatible => type, CGBSupportCode.CGBIncompatible => DeviceType.DMG, _ => throw new ArgumentOutOfRangeException() }; Renderer = renderer; SoundOutput = soundOutput; InterruptRegisters = new InterruptRegisters(); ControlRegisters = new ControlRegisters(); APU = new APU(this); LCDRegisters = new LCDRegisters(this); Cartridge = cartridge; MMU = new MMU(bootRom, this); CPU = new CPU.CPU(this); _cpuGenerator = CPU.GetEnumerator(); LCDDriver = new LCDDriver(this); Timer = new Timer(this); DMAController = new DMAController(this); JoypadHandler = new JoypadHandler(this); // Set default values if there was no passed in boot rom if (bootRom == null) { SkipBootRom(); } }