Пример #1
0
        static MMU()
        {
            MMU.bios = new byte[] {
                0x31, 0xFE, 0xFF, 0xAF, 0x21, 0xFF, 0x9F, 0x32, 0xCB, 0x7C, 0x20, 0xFB, 0x21, 0x26, 0xFF, 0x0E,
                0x11, 0x3E, 0x80, 0x32, 0xE2, 0x0C, 0x3E, 0xF3, 0xE2, 0x32, 0x3E, 0x77, 0x77, 0x3E, 0xFC, 0xE0,
                0x47, 0x11, 0x04, 0x01, 0x21, 0x10, 0x80, 0x1A, 0xCD, 0x95, 0x00, 0xCD, 0x96, 0x00, 0x13, 0x7B,
                0xFE, 0x34, 0x20, 0xF3, 0x11, 0xD8, 0x00, 0x06, 0x08, 0x1A, 0x13, 0x22, 0x23, 0x05, 0x20, 0xF9,
                0x3E, 0x19, 0xEA, 0x10, 0x99, 0x21, 0x2F, 0x99, 0x0E, 0x0C, 0x3D, 0x28, 0x08, 0x32, 0x0D, 0x20,
                0xF9, 0x2E, 0x0F, 0x18, 0xF3, 0x67, 0x3E, 0x64, 0x57, 0xE0, 0x42, 0x3E, 0x91, 0xE0, 0x40, 0x04,
                0x1E, 0x02, 0x0E, 0x0C, 0xF0, 0x44, 0xFE, 0x90, 0x20, 0xFA, 0x0D, 0x20, 0xF7, 0x1D, 0x20, 0xF2,
                0x0E, 0x13, 0x24, 0x7C, 0x1E, 0x83, 0xFE, 0x62, 0x28, 0x06, 0x1E, 0xC1, 0xFE, 0x64, 0x20, 0x06,
                0x7B, 0xE2, 0x0C, 0x3E, 0x87, 0xF2, 0xF0, 0x42, 0x90, 0xE0, 0x42, 0x15, 0x20, 0xD2, 0x05, 0x20,
                0x4F, 0x16, 0x20, 0x18, 0xCB, 0x4F, 0x06, 0x04, 0xC5, 0xCB, 0x11, 0x17, 0xC1, 0xCB, 0x11, 0x17,
                0x05, 0x20, 0xF5, 0x22, 0x23, 0x22, 0x23, 0xC9, 0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B,
                0x03, 0x73, 0x00, 0x83, 0x00, 0x0C, 0x00, 0x0D, 0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E,
                0xDC, 0xCC, 0x6E, 0xE6, 0xDD, 0xDD, 0xD9, 0x99, 0xBB, 0xBB, 0x67, 0x63, 0x6E, 0x0E, 0xEC, 0xCC,
                0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E, 0x3c, 0x42, 0xB9, 0xA5, 0xB9, 0xA5, 0x42, 0x4C,
                0x21, 0x04, 0x01, 0x11, 0xA8, 0x00, 0x1A, 0x13, 0xBE, 0x20, 0xFE, 0x23, 0x7D, 0xFE, 0x34, 0x20,
                0xF5, 0x06, 0x19, 0x78, 0x86, 0x23, 0x05, 0x20, 0xFB, 0x86, 0x20, 0xFE, 0x3E, 0x01, 0xE0, 0x50
            };
            MMU.rom  = new byte[0x8000];
            MMU.wram = new byte[0x2000];
            MMU.eram = new byte[0x2000];
            MMU.zram = new byte[0xFF];

            MMU.reset();
        }
Пример #2
0
        public static void renderScan()
        {
            // VRAM offset for the tile map
            UInt16 mapOffs = (UInt16)(curLine + yScrl);

            mapOffs  &= 0xFF;
            mapOffs >>= 3;
            mapOffs <<= 5;

            UInt16 lineOffs = (UInt16)((xScrl >> 3) & 31);

            UInt16 index = BgTileMapSelect ? MMU.readByte((UInt16)((mapOffs + lineOffs) + 0x8800)) : MMU.readByte((UInt16)((mapOffs + lineOffs) + 0x8800));

            // Where in the tile to start
            byte x = (byte)(xScrl & 7);
            byte y = (byte)((curLine + yScrl) & 7);

            if (!TileDataSelect)
            {
                if (index < 128)
                {
                    index += 128;
                }
                else
                {
                    index -= 128;
                }
            }

            for (int i = 0; i < 160; i++)
            {
                //get 16-bit tile data
                UInt16 tile = TileDataSelect ? MMU.readWord((UInt16)((index << 1) + 0x8000)) : MMU.readWord((UInt16)((index << 1) + 0x8800));

                //mask all but 0xnn where n = 'pixel number'
                //then add the 2 bits
                byte a = (byte)(((tile & 0xFF) & (1 << x)) >> x);
                byte b = (byte)(((tile >> 8) & (1 << x)) >> x);
                byte c = (byte)(a + (b >> 1));


                // Write to linebuffer
                GPU.lineBuffer[i] = c;

                // Increment x pixel within tile
                x++;

                if (x == 8)
                {
                    //Reset x pixel within tile, get new tile data
                    x        = 0;
                    lineOffs = (UInt16)((lineOffs + 1) & 31);
                    index    = BgTileMapSelect ? vram[(mapOffs + lineOffs) + 0x1C00] : vram[(mapOffs + lineOffs) + 0x1800];
                }
            }
        }
Пример #3
0
 public static void writeWord(UInt16 addr, UInt16 val)
 {
     MMU.writeByte(addr, (byte)(val & 0x00FF));
     MMU.writeByte((UInt16)(addr + 1), (byte)(val >> 8));
 }
Пример #4
0
 public static UInt16 readWord(UInt16 addr)
 {
     return((UInt16)(MMU.readByte(addr) + (MMU.readByte((UInt16)(addr + 1)) << 8)));
 }
Пример #5
0
 /*
  *  [STAThread]
  *  static void Main()
  *  {
  *      // Load Emulator Window
  *      StartLoadWindowThread();
  *
  *      Console.WriteLine("GBEMU DEV by Saintwolf");
  *
  *      Console.WriteLine("Resetting Gameboy");
  *      reset();
  *
  *      Console.WriteLine("Loading ROM...");
  *      MMU.load("C:\\GBROMS\\Pokemon Blue.gb");
  *
  *
  *      bool running = true;
  *
  *      while (running)
  *      {
  *          Console.WriteLine("Registers:");
  *          Console.WriteLine("A : " + Z80.Registers.a.ToString("X"));
  *          Console.WriteLine("B : " + Z80.Registers.b.ToString("X"));
  *          Console.WriteLine("C : " + Z80.Registers.c.ToString("X"));
  *          Console.WriteLine("D : " + Z80.Registers.d.ToString("X"));
  *          Console.WriteLine("E : " + Z80.Registers.e.ToString("X"));
  *          Console.WriteLine("H : " + Z80.Registers.h.ToString("X"));
  *          Console.WriteLine("L : " + Z80.Registers.l.ToString("X"));
  *          Console.WriteLine("PC : " + Z80.Registers.pc.ToString("X"));
  *          Console.WriteLine("SP : " + Z80.Registers.sp.ToString("X"));
  *          Console.WriteLine("F (Decimal) : " + Z80.Registers.f.ToString("X"));
  *          Console.WriteLine("Clock m : " + Z80.Clock.m.ToString("X"));
  *          Console.WriteLine("Clock t : " + Z80.Clock.t.ToString("X"));
  *          Console.Write("Press S to step, N to step 100 times, R to reset or X to exit: ");
  *          ConsoleKey key = Console.ReadKey().Key;
  *          Console.WriteLine();
  *          switch (key)
  *          {
  *              case ConsoleKey.S:
  *                  Console.WriteLine("Executing command at address: " + Z80.Registers.pc.ToString("X") + "(" + MMU.readByte(Z80.Registers.pc).ToString("X") + ")");
  *                  Z80.step();
  *                  GPU.step();
  *                  break;
  *
  *              case ConsoleKey.X:
  *                  running = false;
  *                  Console.WriteLine("Shutting Down...");
  *                  break;
  *
  *              case ConsoleKey.J:
  *                  while (Z80.Registers.pc != 0x6A)
  *                  {
  *                      Z80.step();
  *                      GPU.step();
  *                  }
  *                  break;
  *
  *              case ConsoleKey.N:
  *                  for (int i = 0; i < 1000; i++)
  *                  {
  *                      frame();
  *                  }
  *                  break;
  *
  *              case ConsoleKey.R:
  *                  Z80.reset();
  *                  break;
  *          }
  *
  *      }
  *  }
  */
 public static void reset()
 {
     GPU.reset();
     MMU.reset();
     Z80.reset();
 }
Пример #6
0
        public static void Main()
        {
            StartLoadGUIThread();

            bool reset = true;

            while (true)
            {
                //    Application.Run(new GBEmuWindow());
                if (reset)
                {
                    MMU.load("C:\\GBROMS\\hello.gb");
                    GBEmu.reset();
                    reset = false;
                }

                Console.WriteLine("Registers:");
                Console.WriteLine("A : " + Z80.Registers.a.ToString("X"));
                Console.WriteLine("B : " + Z80.Registers.b.ToString("X"));
                Console.WriteLine("C : " + Z80.Registers.c.ToString("X"));
                Console.WriteLine("D : " + Z80.Registers.d.ToString("X"));
                Console.WriteLine("E : " + Z80.Registers.e.ToString("X"));
                Console.WriteLine("H : " + Z80.Registers.h.ToString("X"));
                Console.WriteLine("L : " + Z80.Registers.l.ToString("X"));
                Console.WriteLine("PC : " + Z80.Registers.pc.ToString("X"));
                Console.WriteLine("SP : " + Z80.Registers.sp.ToString("X"));
                Console.WriteLine("F (Decimal) : " + Z80.Registers.f.ToString("X"));
                Console.WriteLine("Clock m : " + Z80.Clock.m.ToString("X"));
                Console.WriteLine("Clock t : " + Z80.Clock.t.ToString("X"));
                Console.Write("Press S to step, N to step 100 times, R to reset or X to exit: ");
                ConsoleKey key = Console.ReadKey().Key;
                Console.WriteLine();
                switch (key)
                {
                case ConsoleKey.S:
                    Console.WriteLine("Executing command at address: " + Z80.Registers.pc.ToString("X") + "(" + MMU.readByte(Z80.Registers.pc).ToString("X") + ")");
                    Z80.step();
                    GPU.step();
                    break;

                case ConsoleKey.J:
                    Z80.step();
                    GPU.step();
                    while (Z80.Registers.pc != 0x100)
                    {
                        Z80.step();
                        GPU.step();
                    }
                    break;

                case ConsoleKey.N:
                    for (int i = 0; i < 1000; i++)
                    {
                        GBEmu.frame();
                    }
                    break;

                case ConsoleKey.R:
                    Z80.reset();
                    break;
                }
            }
        }