Beispiel #1
0
        public static void run()
        {
            reset();

            while (true)
            {
                CPU.nextInstr();
                DMA.work();
                GPU_Timing.work();
                Sound.work();
                Timer.work();
                Joypad.set_reg();

                Serial.work();

                cycles = cycles + CPU.newticks;

                Memory.GameRAMSnapshot();

                if (do_savestate)
                {
                    create_savestate();
                    do_savestate = false;
                }

                if (do_loadstate)
                {
                    load_savestate();
                    do_loadstate = false;
                }
            }
        }
Beispiel #2
0
        public static void reset()
        {
            cycles = 0;

            if (coldreset)
            {
                GBRegs.reset();
                Flash.reset();
                EEProm.reset();
                GPU.reset();
                Memory.reset(filename);
            }

            CPU.reset();
            GPU_Timing.reset();
            Sound.reset();
            Joypad.set_reg();
            Timer.reset();
            DMA.reset();
            SoundDMA.reset();
            BusTiming.reset();
            gpio.reset();

            //Serial.reset();

            loading_state = false;
            coldreset     = false;

            on = true;
        }
Beispiel #3
0
        public static void write_gbreg(UInt32 adr, UInt32 value, bool dwaccess)
        {
            if (adr == GBRegs.Sect_display.DISPCNT.address)
            {
                GPU.dispcnt_write();
            }
            if (adr == GBRegs.Sect_display.DISPSTAT.address)
            {
                GPU_Timing.dispstat_write();
            }
            else if (adr == GBRegs.Sect_display.BG2RefX.address)
            {
                GPU.refpoint_update_2x_new();
            }
            else if (adr == GBRegs.Sect_display.BG2RefX.address + 2)
            {
                GPU.refpoint_update_2x_new();
            }
            else if (adr == GBRegs.Sect_display.BG2RefY.address)
            {
                GPU.refpoint_update_2y_new();
            }
            else if (adr == GBRegs.Sect_display.BG2RefY.address + 2)
            {
                GPU.refpoint_update_2y_new();
            }
            else if (adr == GBRegs.Sect_display.BG3RefX.address)
            {
                GPU.refpoint_update_3x_new();
            }
            else if (adr == GBRegs.Sect_display.BG3RefX.address + 2)
            {
                GPU.refpoint_update_3x_new();
            }
            else if (adr == GBRegs.Sect_display.BG3RefY.address)
            {
                GPU.refpoint_update_3y_new();
            }
            else if (adr == GBRegs.Sect_display.BG3RefY.address + 2)
            {
                GPU.refpoint_update_3y_new();
            }

            else if (adr >= GBRegs.Sect_sound.SOUND1CNT_L.address && adr < GBRegs.Sect_sound.FIFO_A.address)
            {
                Sound.set_soundreg(adr);
            }

            else if (adr == GBRegs.Sect_sound.FIFO_A.address)
            {
                SoundDMA.fill_fifo(0, value, dwaccess);
            }
            else if (adr == GBRegs.Sect_sound.FIFO_B.address)
            {
                SoundDMA.fill_fifo(1, value, dwaccess);
            }

            else if (adr == GBRegs.Sect_serial.SIOCNT.address)
            {
                Serial.write_SIOCNT(BitConverter.ToUInt16(GBRegs.data, (int)GBRegs.Sect_serial.SIOCNT.address));
            }

            else if (adr == GBRegs.Sect_timer.TM0CNT_L.address)
            {
                Timer.set_reload(0);
            }
            else if (adr == GBRegs.Sect_timer.TM0CNT_L.address + 2)
            {
                Timer.set_settings(0);
            }
            else if (adr == GBRegs.Sect_timer.TM1CNT_L.address)
            {
                Timer.set_reload(1);
            }
            else if (adr == GBRegs.Sect_timer.TM1CNT_L.address + 2)
            {
                Timer.set_settings(1);
            }
            else if (adr == GBRegs.Sect_timer.TM2CNT_L.address)
            {
                Timer.set_reload(2);
            }
            else if (adr == GBRegs.Sect_timer.TM2CNT_L.address + 2)
            {
                Timer.set_settings(2);
            }
            else if (adr == GBRegs.Sect_timer.TM3CNT_L.address)
            {
                Timer.set_reload(3);
            }
            else if (adr == GBRegs.Sect_timer.TM3CNT_L.address + 2)
            {
                Timer.set_settings(3);
            }

            else if (adr == GBRegs.Sect_dma.DMA0CNT_H.address + 2)
            {
                DMA.set_settings(0);
            }
            else if (adr == GBRegs.Sect_dma.DMA1CNT_H.address + 2)
            {
                DMA.set_settings(1);
            }
            else if (adr == GBRegs.Sect_dma.DMA2CNT_H.address + 2)
            {
                DMA.set_settings(2);
            }
            else if (adr == GBRegs.Sect_dma.DMA3CNT_H.address + 2)
            {
                DMA.set_settings(3);
            }

            else if (adr == GBRegs.Sect_keypad.KEYINPUT.address)
            {
                Joypad.set_reg();
            }

            else if (adr == GBRegs.Sect_system.IME.address)
            {
                IRP.update_IME(BitConverter.ToUInt16(GBRegs.data, (int)GBRegs.Sect_system.IME.address));
            }
            else if (adr == GBRegs.Sect_system.IE.address)
            {
                IRP.update_IE();
            }
            else if (adr == GBRegs.Sect_system.IF.address + 2)
            {
                IRP.clear_irp_bits();
            }

            else if (adr == GBRegs.Sect_system.WAITCNT.address)
            {
                BusTiming.update(BitConverter.ToUInt16(GBRegs.data, (int)GBRegs.Sect_system.WAITCNT.address));
            }
            else if (adr == GBRegs.Sect_system.POSTFLG.address & value == 1)
            {
            }
            else if (adr == GBRegs.Sect_system.HALTCNT.address && !gameboy.loading_state)
            {
                if ((GBRegs.Sect_system.HALTCNT.read() & 0x80) == 0x80)
                {
                    CPU.stop = true;
                }
                else
                {
                    CPU.halt = true;
                }
            }
        }