Esempio n. 1
0
        public void Tick()
        {
            if ((memory & KeypadFlag.Button) == 0)
            {
                for (int i = 3; i >= 0; i--)
                {
                    byte flag = (byte)(1 << i);

                    if (buttonKeys [i])
                    {
                        // pressed
                        if ((memory & flag) == flag)
                        {
                            mmu.RequestInterrupt(InterruptFlag.Joypad);
                            Debug.Log("Interrupt for button " + System.Convert.ToString(flag, 2) + " " + System.Convert.ToString(memory, 2));
                        }
                        memory &= (byte)~flag;
                        Debug.Log(System.Convert.ToString(memory, 2).PadLeft(8, '0'));
                    }
                    else
                    {
                        // released
                        memory |= flag;
                    }
                }
            }
            else if ((memory & KeypadFlag.Joypad) == 0)
            {
                for (int i = 3; i >= 0; i--)
                {
                    byte flag = (byte)(1 << i);

                    if (joypadKeys [i])
                    {
                        // pressed
                        if ((memory & flag) == flag)
                        {
                            mmu.RequestInterrupt(InterruptFlag.Joypad);
                            Debug.Log("Interrupt for joypad " + System.Convert.ToString(flag, 2) + " " + System.Convert.ToString(memory, 2));
                        }
                        memory &= (byte)~flag;
                        Debug.Log(System.Convert.ToString(memory, 2).PadLeft(8, '0'));
                    }
                    else
                    {
                        // released
                        memory |= flag;
                    }
                }
            }
        }
Esempio n. 2
0
        void TickVram(bool ime)
        {
//            if (!lineRendered && (cc >= (ly > 0 ? 12L : 40L))) {
//                lineRendered = true;
//                RenderScanline ();
//            }

            if (cc >= VramCycles)
            {
                cc -= VramCycles;

                RenderScanline();

                SetLcdMode(LcdMode.Hblank);

//                DoHdma ();

                if (ime && hblankEnabled)
                {
                    mmu.RequestInterrupt(InterruptFlag.LcdStat);
                }
            }
        }
Esempio n. 3
0
        public void Tick(long cc)
        {
            // m-clock increments at 1/4 the m-clock rate
            tc += cc;

            // timer ticks occur at 1/16 the CPU cycles
            while (tc >= TicksPerSecondsAtBaseSpeed)
            {
                tc -= TicksPerSecondsAtBaseSpeed;
                bc++;
                dc++;

                // divider clock
                if (dc == TicksPerSecondsAtBaseSpeed)
                {
                    divider++;
                    dc = 0;
                }

                // check if timer is enabled
                if ((controller & TimerControllerEnabledFlag) == TimerControllerEnabledFlag)
                {
                    // get frequency
                    int threshold = timerFrequencies [controller & 0x03];

                    while (bc >= threshold)
                    {
                        bc -= threshold;

                        if (counter == 0xFF)
                        {
                            // overflow!
                            counter = modulator;
                            mmu.RequestInterrupt(InterruptFlag.TimeOverflow);
                        }
                        else
                        {
                            // increment counter
                            counter++;
                        }
                    }
                }
            }
        }