示例#1
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];
                }
            }
        }
示例#2
0
文件: MMU.cs 项目: saintwolf/GBEmu
 public static UInt16 readWord(UInt16 addr)
 {
     return((UInt16)(MMU.readByte(addr) + (MMU.readByte((UInt16)(addr + 1)) << 8)));
 }
示例#3
0
文件: main.cs 项目: saintwolf/GBEmu
        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;
                }
            }
        }