Exemple #1
0
        public void Step(uint opCycles)
        {
            clockTmp += opCycles;
            //1/16 cpu speed: increment main clock
            if (clockTmp >= 16)
            {
                clockTmp -= 16;
                clock++;

                //1/16 Increment divider
                dividerClockTmp++;
                if (dividerClockTmp == 16)
                {
                    dividerClockTmp = 0;
                    DIV++;
                }
            }

            if (IsRunning)
            {
                //1/x Increment counter
                if (clock >= (int)TimerSpeed)
                {
                    clock = 0;
                    TIMA++;
                    if (TIMA == 0)
                    {
                        mmu.SetInterrupt(MMU.InterruptType.TimerOverflow);
                        TIMA = TMA;
                    }
                }
            }
        }
Exemple #2
0
        public void SetKey(Button button, bool pressed)
        {
            states[button] = pressed;
            byte directions = 0x00;
            byte buttons    = 0x00;

            buttons |= (byte)(states[Button.A] ? 0x01 : 0x00);
            buttons |= (byte)(states[Button.B] ? 0x02 : 0x00);
            buttons |= (byte)(states[Button.Select] ? 0x04 : 0x00);
            buttons |= (byte)(states[Button.Start] ? 0x08 : 0x00);
            buttons  = (byte)~buttons;

            directions |= (byte)(states[Button.Right] ? 0x01 : 0x00);
            directions |= (byte)(states[Button.Left] ? 0x02 : 0x00);
            directions |= (byte)(states[Button.Up] ? 0x04 : 0x00);
            directions |= (byte)(states[Button.Down] ? 0x08 : 0x00);
            directions  = (byte)~directions;

            mmu.WriteJoypadInfo(
                (byte)((buttons) & 0x0F),
                (byte)((directions) & 0xF)
                );

            if (directions != 0x0F || buttons != 0x0F)
            {
                mmu.SetInterrupt(MMU.InterruptType.HighToLowP10P13);
            }
        }
Exemple #3
0
        public void Step(uint opCycles)
        {
            clock += opCycles;

            switch (STAT_Mode)
            {
            //OAM Read
            case GPUMode.OAMRead:
                if (clock >= SCANLINE_OAM_CYCLES)
                {
                    clock    -= SCANLINE_OAM_CYCLES;
                    STAT_Mode = GPUMode.VRAMRead;
                }
                break;

            //VRAM Read
            case GPUMode.VRAMRead:
                if (clock >= SCANLINE_VRAM_CYCLES)
                {
                    clock    -= SCANLINE_VRAM_CYCLES;
                    STAT_Mode = GPUMode.HBlank;
                    DrawScanline();
                }
                break;

            //HBlank
            case GPUMode.HBlank:
                if (clock >= HORIZONAL_BLANK_CYCLES)
                {
                    clock -= HORIZONAL_BLANK_CYCLES;
                    LY++;

                    if (LY == (SCREEN_PIXELS_HEIGHT - 1))
                    {
                        STAT_Mode = GPUMode.VBlank;
                        mmu.SetInterrupt(MMU.InterruptType.VBlank);
                        DrawScreen();
                    }
                    else
                    {
                        STAT_Mode = GPUMode.OAMRead;
                    }
                }
                break;

            //VBlank
            case GPUMode.VBlank:
                if (clock >= VERTICAL_BLANK_CYCLES)
                {
                    clock -= VERTICAL_BLANK_CYCLES;
                    LY++;

                    if (LY > 153)
                    {
                        STAT_Mode = GPUMode.OAMRead;
                        LY        = 0;
                    }
                }
                break;
            }
        }