Exemple #1
0
        public DEC(Gameboy parent, byte opcode) : base(parent)
        {
            target = OpcodeUtils.BitsToRegister((opcode & 0b111000) >> 3);

            Cycles       = target == Register.M ? 12 : 4;
            TickAccurate = target == Register.M;
            Disassembly  = "dec " + (target == Register.M ? "[hl]" : OpcodeUtils.RegisterToString(target));
        }
Exemple #2
0
        public LDMSP(Gameboy parent) : base(parent)
        {
            Cycles       = 20;
            Length       = 3;
            TickAccurate = true;

            Disassembly = "ld [$" + (parent.Memory[parent.PC + 1] + (parent.Memory[parent.PC + 2] << 8)).ToString("X4") + "]";
        }
Exemple #3
0
        public OR(Gameboy parent, byte opcode) : base(parent)
        {
            source = OpcodeUtils.BitsToRegister(opcode & 0b111);

            Cycles = source == Register.M ? 8 : 4;

            Disassembly = "or " + (source == Register.M ? "[hl]" : OpcodeUtils.RegisterToString(source));
        }
Exemple #4
0
        public LDHLSP(Gameboy parent) : base(parent)
        {
            Cycles       = 12;
            Length       = 2;
            TickAccurate = true;

            Disassembly = "ld hl, " + ((ushort)(parent.ReadRegister16(Register16.SP) + (sbyte)parent.Memory[parent.PC + 1])).ToString("X1");
        }
Exemple #5
0
 private void InitGameboy(string filePath)
 {
     if (File.Exists(filePath))
     {
         this.gb             = new Gameboy(this.MessageCallback, this.DrawFramebuffer, this.framebuffer, SAMPLE_RATE, filePath);
         this.lastFrameTime  = Stopwatch.GetTimestamp();
         this.lastRenderTick = Stopwatch.GetTimestamp();
     }
 }
Exemple #6
0
        public CPU(Gameboy gameboy)
        {
            _gameboy  = gameboy;
            _debugger = new Debugger(gameboy);

            RegisterInstructions();

            Reset(false, null);
        }
Exemple #7
0
        public ObjectSprite(Gameboy parent, ushort addr)
        {
            Y          = parent.Memory.Get(addr);
            X          = parent.Memory.Get(addr + 1);
            TileNo     = parent.Memory.Get(addr + 2);
            Attributes = parent.Memory.Get(addr + 3);

            this.parent = parent;
        }
Exemple #8
0
 private void GBGPUView_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (_gb != null)
     {
         _gb.SetScanlineCallback(null, 0);
         _gb = null;
     }
     Global.Config.GBGPUSpriteBack = spriteback;
 }
        public SerialTestRunner(FileInfo romFile, TextWriter os)
        {
            var options = new GameboyOptions(romFile);
            var cart    = new Cartridge(options);

            gb      = new Gameboy(options, cart, new NullDisplay(), new NullController(), new NullSoundOutput(), this);
            text    = new StringBuilder();
            this.os = os;
        }
Exemple #10
0
        public CRET(Gameboy parent, byte opcode) : base(parent)
        {
            cFlagSet = (opcode & 0b1000) > 0;
            cFlag    = (opcode & 0b10000) > 0 ? Flag.Carry : Flag.Zero;

            Cycles = 20;

            Disassembly = "ret " + (cFlagSet ? "" : "n") + OpcodeUtils.FlagToString(cFlag);
        }
Exemple #11
0
        public LDAHL(Gameboy parent, byte opcode) : base(parent)
        {
            inc  = (opcode & 0b10000) == 0;
            load = (opcode & 0b1000) > 0;

            Cycles       = 8;
            TickAccurate = true;

            Disassembly = load ? "ld a, [hl" + (inc ? "+" : "-") + "]" : "ld [hl" + (inc ? "+" : "-") + "], a";
        }
Exemple #12
0
    // Use this for initialization
    void Start()
    {
        GameObject gameObject = GameObject.Find("Screen");

        if (gameObject == null)
        {
            return;
        }
        _gameboy = gameObject.GetComponent <Gameboy>();
    }
Exemple #13
0
        public LDA(Gameboy parent, byte opcode) : base(parent)
        {
            load    = (opcode & 0b1000) > 0;
            regpair = (opcode & 0b10000) > 0 ? Register16.DE : Register16.BC;

            Cycles       = 8;
            TickAccurate = true;

            Disassembly = load ? "ld a, [" + OpcodeUtils.Register16ToString(regpair) + "]" : "ld [" + OpcodeUtils.Register16ToString(regpair) + "], a";
        }
Exemple #14
0
        public CCALL(Gameboy parent, byte opcode) : base(parent)
        {
            cFlagSet = (opcode & 0b1000) > 0;
            cFlag    = (opcode & 0b10000) > 0 ? Flag.Carry : Flag.Zero;

            Length = 3;
            Cycles = 24;

            Disassembly = "call " + (cFlagSet ? "" : "n") + OpcodeUtils.FlagToString(cFlag) + ", $" + (parent.Memory[parent.PC + 1] + (parent.Memory[parent.PC + 2] << 8)).ToString("X1");
        }
Exemple #15
0
        public PSL(Gameboy parent, byte opcode) : base(parent)
        {
            target = OpcodeUtils.BitsToRegister(opcode & 0b111);

            Length       = 2;
            Cycles       = target == Register.M ? 16 : 8;
            TickAccurate = target == Register.M;

            Disassembly = "srl " + OpcodeUtils.RegisterToString(target);
        }
Exemple #16
0
        public CJR(Gameboy parent, byte opcode) : base(parent)
        {
            cFlagSet = (opcode & 0b1000) > 0;
            cFlag    = (opcode & 0b10000) > 0 ? Flag.Carry : Flag.Zero;

            Length = 2;
            Cycles = 12;

            Disassembly = "jr " + (cFlagSet ? "" : "n") + OpcodeUtils.FlagToString(cFlag) + ", $" + (parent.PC + (sbyte)parent.Memory[parent.PC + 1] + 2).ToString("X4");
        }
Exemple #17
0
        public SWAP(Gameboy parent, byte opcode) : base(parent)
        {
            target = OpcodeUtils.BitsToRegister(opcode & 0b111);

            Length       = 2;
            Cycles       = (target == Register.M) ? 16 : 8;
            TickAccurate = target == Register.M;

            Disassembly = "swap " + (target == Register.M ? "[hl]" : OpcodeUtils.RegisterToString(target));
        }
        public SerialTestRunner(FileInfo romFileInfo, TextWriter os, bool trace)
        {
            _tracer = trace ? (ITracer) new Tracer(romFileInfo.Name) : new NullTracer();

            var options = new GameboyOptions(romFileInfo);
            var cart    = new Cartridge(options);

            _gb   = new Gameboy(options, cart, new NullDisplay(), new NullController(), new NullSoundOutput(), this);
            _text = new StringBuilder();
            _os   = os;
        }
Exemple #19
0
        public SET(Gameboy parent, byte opcode) : base(parent)
        {
            target = OpcodeUtils.BitsToRegister(opcode & 0b111);
            bit    = (byte)((opcode & 0b111000) >> 3);

            Cycles       = target == Register.M ? 16 : 8;
            Length       = 2;
            TickAccurate = true;

            Disassembly = "set $" + bit.ToString("X2") + ", " + (target == Register.M ? "[hl]" : OpcodeUtils.RegisterToString(target));
        }
Exemple #20
0
        public PSA(Gameboy parent, byte opcode) : base(parent)
        {
            left   = (opcode & 0b1000) == 0;
            target = OpcodeUtils.BitsToRegister(opcode & 0b111);

            Length       = 2;
            Cycles       = target == Register.M ? 16 : 8;
            TickAccurate = target == Register.M;

            Disassembly = (left ? "sla" : "sra") + " " + OpcodeUtils.RegisterToString(target);
        }
Exemple #21
0
        public LDAI(Gameboy parent, byte opcode) : base(parent)
        {
            load = (opcode & 0b10000) > 0;

            Cycles = 16;
            Length = 3;

            TickAccurate = true;

            Disassembly = load ? "ld a, [$" + (parent.Memory[parent.PC + 1] + (parent.Memory[parent.PC + 2] << 8)).ToString("X4") + "]" : "ld [$" + (parent.Memory[parent.PC + 1] + (parent.Memory[parent.PC + 2] << 8)).ToString("X4") + "], a";
        }
Exemple #22
0
        public PUSH(Gameboy parent, byte opcode) : base(parent)
        {
            source = OpcodeUtils.BitsToRegister16((opcode & 0b110000) >> 4);
            if (source == Register16.SP)
            {
                source = Register16.AF;
            }

            Cycles = 16;

            Disassembly = "push " + OpcodeUtils.Register16ToString(source);
        }
Exemple #23
0
        public POP(Gameboy parent, byte opcode) : base(parent)
        {
            target = OpcodeUtils.BitsToRegister16((opcode & 0b110000) >> 4);
            if (target == Register16.SP)
            {
                target = Register16.AF;
            }

            Cycles = 12;

            Disassembly = "pop " + OpcodeUtils.Register16ToString(target);
        }
Exemple #24
0
        public LD16(Gameboy parent, byte opcode) : base(parent)
        {
            target     = OpcodeUtils.BitsToRegister16((opcode & 0b110000) >> 4);
            targetLow  = target == Register16.BC ? Register.C : target == Register16.DE ? Register.E : Register.L;
            targetHigh = target == Register16.BC ? Register.B : target == Register16.DE ? Register.D : Register.H;

            Cycles       = 12;
            Length       = 3;
            TickAccurate = true;

            Disassembly = "ld " + OpcodeUtils.Register16ToString(target) + ", $" + (parent.Memory[parent.PC + 1] + (parent.Memory[parent.PC + 2] << 8)).ToString("X2");
        }
Exemple #25
0
 public void Setup()
 {
     Gameboy.Reset();
     Assert.AreEqual(1, Gameboy.cpu.A, "Pretest sanity check: A is incorrect");
     Assert.AreEqual(176, Gameboy.cpu.F, "Pretest sanity check: F is incorrect");
     Assert.AreEqual(0, Gameboy.cpu.B, "Pretest sanity check: B is incorrect");
     Assert.AreEqual(19, Gameboy.cpu.C, "Pretest sanity check: C is incorrect");
     Assert.AreEqual(0, Gameboy.cpu.D, "Pretest sanity check: D is incorrect");
     Assert.AreEqual(216, Gameboy.cpu.E, "Pretest sanity check: E is incorrect");
     Assert.AreEqual(1, Gameboy.cpu.H, "Pretest sanity check: H is incorrect");
     Assert.AreEqual(77, Gameboy.cpu.L, "Pretest sanity check: L is incorrect");
 }
Exemple #26
0
        public CPU(Gameboy gameBoy)
        {
            this.gb              = gameBoy;
            this.opcodes         = this.GenerateOpcodes();
            this.extendedOpcodes = this.GenerateExtendedOpcodes();

#if ENABLE_TRACING
            log          = System.IO.File.Create("trace.log");
            sw           = new System.IO.StreamWriter(log);
            sw.AutoFlush = true;
#endif
        }
Exemple #27
0
        public LDI(Gameboy parent, byte opcode) : base(parent)
        {
            target = OpcodeUtils.BitsToRegister((opcode & 0b111000) >> 3);

            Cycles = target == Register.M ? 12 : 8;
            Length = 2;

            TickAccurate = true;
            actionTick   = target == Register.M ? 7 : 3;

            Disassembly = "ld " + (target == Register.M ? "[hl]" : OpcodeUtils.RegisterToString(target)) + ", $" + parent.Memory[parent.PC + 1].ToString("X2");
        }
Exemple #28
0
        public PRT(Gameboy parent, byte opcode) : base(parent)
        {
            left     = (opcode & 0b1000) == 0;
            useCarry = (opcode & 0b10000) > 0;
            target   = OpcodeUtils.BitsToRegister(opcode & 0b111);

            Length       = 2;
            Cycles       = (target == Register.M) ? 16 : 8;
            TickAccurate = target == Register.M;

            Disassembly = (left ? "rl" : "rr") + (useCarry ? "c" : "") + " " + OpcodeUtils.RegisterToString(target);
        }
Exemple #29
0
        public LDH(Gameboy parent, byte opcode) : base(parent)
        {
            load = (opcode & 0b10000) > 0;
            regC = (opcode & 0b10) > 0;

            Cycles = regC ? 8 : 12;
            Length = regC ? 1 : 2;

            TickAccurate = true;
            actionTick   = regC ? 3 : 7;

            Disassembly = load ? "ld a, [$" + ((ushort)(0xFF00 + (regC ? parent.Registers[Register.C] : parent.Memory[parent.PC + 1]))).ToString("X4") + "]" : "ld [$" + ((ushort)(0xFF00 + (regC ? parent.Registers[Register.C] : parent.Memory[parent.PC + 1]))).ToString("X4") + "], a";
        }
Exemple #30
0
        public LD(Gameboy parent, byte opcode) : base(parent)
        {
            source = OpcodeUtils.BitsToRegister(opcode & 0b111);
            target = OpcodeUtils.BitsToRegister((opcode & 0b111000) >> 3);

            Cycles = source == Register.M || target == Register.M ? 8 : 4;

            if (target == Register.M || source == Register.M)
            {
                TickAccurate = true;
            }

            Disassembly = "ld " + (target == Register.M ? "[hl]" : OpcodeUtils.RegisterToString(target)) + ", " + (source == Register.M ? "[hl]" : OpcodeUtils.RegisterToString(source));
        }