Exemple #1
0
        public void BlitScreen()
        {
            //int i;
            //int j;
#if FOURSCREEN
            int currentNameTableAddress = myPPU.nameTableAddress;
            //FIXME: This is for debugging
            unsafe {
                short *p = (short *)sdlBuffer;
                int    f, g;
                //int maxlength = width*height;
                int maxlength = 256 * 224;

                for (f = 0; f < maxlength; f++)
                {
                    p[(f % 256) + 780 * (f / 256)] = myPPU.offscreenBuffer[f];
                }
            }

            myPPU.nameTableAddress = 0x2000;
            myPPU.scrollH          = 0;
            myPPU.scrollV          = 0;
            for (i = 0; i < 240; i++)
            {
                myPPU.currentScanline = i;
                //Clean up the line from before
                for (j = 0; j < 256; j++)
                {
                    //myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + i] = (short)myPPU.Nes_Palette[myPPU.nameTables[0x1f00]];
                    //myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + j] = 0;
                    myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + j] = (short)myPPU.Nes_Palette[myPPU.nameTables[0x1f00]];
                }

                myPPU.RenderBackground();
            }
            myPPU.currentScanline = 240;
            //FIXME: This is for debugging
            unsafe {
                short *p = (short *)sdlBuffer;
                int    f, g;
                //int maxlength = width*height;
                int maxlength = 256 * 224;

                for (f = 0; f < maxlength; f++)
                {
                    p[264 + (f % 256) + 780 * (f / 256)] = myPPU.offscreenBuffer[f];
                }
            }

            myPPU.nameTableAddress = 0x2400;
            myPPU.scrollH          = 0;
            myPPU.scrollV          = 0;
            for (i = 0; i < 240; i++)
            {
                myPPU.currentScanline = i;
                //Clean up the line from before
                for (j = 0; j < 256; j++)
                {
                    //offscreenBuffer[(currentScanline * 256) + i] = (int)Nes_Palette[(int)nameTables[0x1f00]];
                    //myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + i] = (int)Nes_Palette[(int)nameTables[0x1f00]];
                    //myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + j] = 0;
                    myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + j] = (short)myPPU.Nes_Palette[myPPU.nameTables[0x1f00]];
                }

                myPPU.RenderBackground();
            }
            myPPU.currentScanline = 240;
            //FIXME: This is for debugging
            unsafe {
                short *p = (short *)sdlBuffer;
                int    f, g;
                //int maxlength = width*height;
                int maxlength = 256 * 224;

                for (f = 0; f < maxlength; f++)
                {
                    //p[187980 + 264 + (f % 256) + 780 * (f / 256)] = myPPU.offscreenBuffer[f];
                    p[256 + 264 + (f % 256) + 780 * (f / 256)] = myPPU.offscreenBuffer[f];
                }
            }

            myPPU.nameTableAddress = 0x2800;
            myPPU.scrollH          = 0;
            myPPU.scrollV          = 0;
            for (i = 0; i < 240; i++)
            {
                myPPU.currentScanline = i;
                //Clean up the line from before
                for (j = 0; j < 256; j++)
                {
                    //offscreenBuffer[(currentScanline * 256) + i] = (int)Nes_Palette[(int)nameTables[0x1f00]];
                    //myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + j] = 0;
                    //myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + i] = (int)Nes_Palette[(int)nameTables[0x1f00]];
                    myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + j] = (short)myPPU.Nes_Palette[myPPU.nameTables[0x1f00]];
                }

                myPPU.RenderBackground();
            }
            myPPU.currentScanline = 240;
            //FIXME: This is for debugging
            unsafe {
                short *p = (short *)sdlBuffer;
                int    f, g;
                //int maxlength = width*height;
                int maxlength = 256 * 224;

                for (f = 0; f < maxlength; f++)
                {
                    p[187980 + 264 + (f % 256) + 780 * (f / 256)] = myPPU.offscreenBuffer[f];
                }
            }
            myPPU.nameTableAddress = 0x2C00;
            myPPU.scrollH          = 0;
            myPPU.scrollV          = 0;
            for (i = 0; i < 240; i++)
            {
                myPPU.currentScanline = i;
                //Clean up the line from before
                for (j = 0; j < 256; j++)
                {
                    //offscreenBuffer[(currentScanline * 256) + i] = (int)Nes_Palette[(int)nameTables[0x1f00]];
                    //myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + j] = 0;
                    //myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + i] = (int)Nes_Palette[(int)nameTables[0x1f00]];
                    myPPU.offscreenBuffer[(myPPU.currentScanline * 256) + j] = (short)myPPU.Nes_Palette[myPPU.nameTables[0x1f00]];
                }

                myPPU.RenderBackground();
            }
            myPPU.currentScanline = 240;
            //FIXME: This is for debugging
            unsafe {
                short *p = (short *)sdlBuffer;
                int    f, g;
                //int maxlength = width*height;
                int maxlength = 256 * 224;

                for (f = 0; f < maxlength; f++)
                {
                    p[187980 + 256 + 264 + (f % 256) + 780 * (f / 256)] = myPPU.offscreenBuffer[f];
                }
            }

            myPPU.nameTableAddress = currentNameTableAddress;
#else
            Marshal.Copy(myPPU.OffScreenBuffer, 256 * 8, sdlBuffer, width * height);
#endif
            Video.Update();
            //Sdl.SDL_Flip(surfacePtr);
            //FIXME: Come up with a better way of frame limiting

            //Sdl.SDL_Delay((int)(16.667 - ((dtafter-dtbefore).Ticks / 10000.0)));
            //Console.WriteLine("Will Delay: {0}", 60 * ((dtafter-dtbefore).Ticks / 1000000.0));
            framecount++;
            if ((framecount % 100) == 0)
            {
                //FIXME: This assumes NTSC

                dtafter = DateTime.Now;
                fps     = (int)(((dtafter - dtbefore).Ticks) / 100000);
                //Console.WriteLine("Current Speed: {0}", 100.0 / fps);
                if (fps < 100)
                {
                    willSleep = true;
                    sleepTime++;
                    //Console.WriteLine("Will Delay: {0}", (100 - fps) * 1000);
                }
                dtbefore = DateTime.Now;
            }
            if (willSleep)
            {
                Thread.Sleep(sleepTime);
            }
            //Thread.Sleep(10);
        }