예제 #1
0
        public void LoadRom(byte[] rom)
        {
            cartridge = rom;

            byte cartridgeType = rom [Address.CartridgeType];
            byte romSize       = rom [Address.RomSize];
            byte ramSize       = rom [Address.RamSize];

            int romBankCount, ramBankCount, ramLength;

            GetRomBankInfo(romSize, out romBankCount);
            GetRamBankInfo(ramSize, out ramBankCount, out ramLength);

            byte[][] romBanks = new byte[romBankCount][];
            byte[][] ramBanks = new byte[ramBankCount][];

            romBanks [0] = rom;

            for (int i = 1; i < romBankCount; ++i)
            {
                romBanks [i] = new byte[RomBankLength];
                Array.Copy(rom, i * RomBankLength, romBanks [i], 0, RomBankLength);
            }

            for (int i = 0; i < ramBankCount; ++i)
            {
                ramBanks [i] = new byte[ramLength];
            }

            mbc = GetMbc(cartridgeType, romBanks, ramBanks);
        }
예제 #2
0
        public void Reset(bool bios)
        {
            biosActive = bios;

            ie = 0;
            ir = 0;

            Array.Clear(zram, 0, zram.Length);
            Array.Clear(mmio, 0, mmio.Length);
            Array.Clear(oam, 0, oam.Length);
            Array.Clear(wram, 0, wram.Length);
            Array.Clear(vram, 0, vram.Length);

            mbc = null;

            if (biosActive)
            {
                return;
            }

            wbr(0xFFFF, 0x00);
            wbr(Address.NR10, 0x80);
            wbr(Address.NR11, 0xBF);
            wbr(Address.NR12, 0xF3);
            wbr(Address.NR14, 0xBF);
            wbr(Address.NR21, 0x3F);
            wbr(Address.NR22, 0x00);
            wbr(Address.NR24, 0xBF);
            wbr(Address.NR30, 0x7F);
            wbr(Address.NR31, 0xFF);
            wbr(Address.NR32, 0x9F);
            wbr(Address.NR33, 0xBF);
            wbr(Address.NR41, 0xFF);
            wbr(Address.NR42, 0x00);
            wbr(Address.NR43, 0x00);
            wbr(Address.NR44, 0xBF);
            wbr(Address.NR50, 0x77);
            wbr(Address.NR51, 0xF3);
            wbr(Address.NR52, 0xF1);
            wbr(Address.Bgp, 0xFC);
            wbr(Address.Obp0, 0xFF);
            wbr(Address.Obp1, 0xFF);
        }
예제 #3
0
        public void Reset()
        {
            Array.Clear(ie, 0, ie.Length);
            Array.Clear(zram, 0, zram.Length);
            Array.Clear(mmio, 0, mmio.Length);
            Array.Clear(oam, 0, oam.Length);
            Array.Clear(wram, 0, wram.Length);
            Array.Clear(vram, 0, vram.Length);

            wbr(0xFF05, (byte)0x00);
            wbr(0xFF06, (byte)0x00);
            wbr(0xFF07, (byte)0x00);
            wbr(0xFF10, (byte)0x80);
            wbr(0xFF11, (byte)0xBF);
            wbr(0xFF12, (byte)0xF3);
            wbr(0xFF14, (byte)0xBF);
            wbr(0xFF16, (byte)0x3F);
            wbr(0xFF17, (byte)0x00);
            wbr(0xFF19, (byte)0xBF);
            wbr(0xFF1A, (byte)0x7F);
            wbr(0xFF1B, (byte)0xFF);
            wbr(0xFF1C, (byte)0x9F);
            wbr(0xFF1E, (byte)0xBF);
            wbr(0xFF20, (byte)0xFF);
            wbr(0xFF21, (byte)0x00);
            wbr(0xFF22, (byte)0x00);
            wbr(0xFF23, (byte)0xBF);
            wbr(0xFF24, (byte)0x77);
            wbr(0xFF25, (byte)0xF3);
            wbr(0xFF26, (byte)0xF1);
            wbr(0xFF40, (byte)0x91);
            wbr(0xFF42, (byte)0x00);
            wbr(0xFF43, (byte)0x00);
            wbr(0xFF45, (byte)0x00);
            wbr(0xFF47, (byte)0xFC);
            wbr(0xFF48, (byte)0xFF);
            wbr(0xFF49, (byte)0xFF);
            wbr(0xFF4A, (byte)0x00);
            wbr(0xFF4B, (byte)0x00);
            wbr(0xFFFF, (byte)0x00);

            mbc = null;
        }
예제 #4
0
        protected Mbc GetMbc(byte cartridgeType, byte[][] romBanks, byte[][] ramBanks)
        {
            Mbc mbc = null;

            switch (cartridgeType)
            {
            case 0x00:
                mbc = new Mbc0(romBanks);
                break;

            case 0x01:
                mbc = new Mbc1(romBanks);
//            case 0x02:
//                mbc = new Mbc1 (romBanks, ramBanks);
//            case 0x03:
//                mbc = new Mbc1 (romBanks, ramBanks, true);
                break;

            default:
                throw new Exception("Cartridge not implemented");
            }

            return(mbc);
        }