Esempio n. 1
0
        public Ppu(NesEngine theEngine)
        {
            myEngine = theEngine;

            nameTables = new byte[0x2000];
            spriteRam  = new byte[0x100];
            //offscreenBuffer = new int[256 * 240];
            offScreenBuffer = new short[256 * 240];
            sprite0Buffer   = new int[256];
            myVideo         = new VideoNes(this);
            RestartPpu();
        }
Esempio n. 2
0
 public static void Run(string defaultRom)
 {
     if (String.IsNullOrEmpty(defaultRom))
     {
         throw new ArgumentNullException("defaultRom");
     }
     try
     {
         if (File.Exists(defaultRom))
         {
             filePath      = "";
             fileDirectory = "";
         }
         else if (File.Exists(Path.Combine(fileDirectory, defaultRom)))
         {
             filePath = "";
         }
         //our game-specific bool
         //FIXME: move this to a more sane place when I figure out where to put it
         gameIsRunning = false;
         myEngine      = new NesEngine();
         //If they gave us a ROM to run on the commandline, go ahead and start it up
         if (!String.IsNullOrEmpty(defaultRom))
         {
             try
             {
                 RunCart(Path.Combine(Path.Combine(filePath, fileDirectory), defaultRom));
             }
             catch (ArgumentException e)
             {
                 Console.WriteLine(e.StackTrace);
                 Console.WriteLine("defaultRom: " + defaultRom);
                 Console.WriteLine("fileDirectory: " + fileDirectory);
             }
         }
     }
     catch (ArgumentException e)
     {
         Console.WriteLine(e.StackTrace);
         Console.WriteLine("defaultRom: " + defaultRom);
         Console.WriteLine("fileDirectory: " + fileDirectory);
     }
 }
Esempio n. 3
0
        public Ppu(NesEngine theEngine)
        {
            myEngine = theEngine;

            nameTables = new byte[0x2000];
            spriteRam = new byte[0x100];
            //offscreenBuffer = new int[256 * 240];
            offScreenBuffer = new short[256 * 240];
            sprite0Buffer = new int[256];
            myVideo = new VideoNes(this);
            RestartPpu();
        }
Esempio n. 4
0
 public Mapper(NesEngine theEngine, NesCartridge theCartridge)
 {
     myEngine = theEngine;
     mapperCartridge = theCartridge;
     currentPrgRomPage = new uint[8];
     currentChrRomPage = new uint[8];
     //timerIrqEnabled;
 }
Esempio n. 5
0
 public static void Run(string defaultRom)
 {
     if (String.IsNullOrEmpty(defaultRom))
     {
         throw new ArgumentNullException("defaultRom");
     }
     try
     {
         if (File.Exists(defaultRom))
         {
             filePath = "";
             fileDirectory = "";
         }
         else if (File.Exists(Path.Combine(fileDirectory, defaultRom)))
         {
             filePath = "";
         }
         //our game-specific bool
         //FIXME: move this to a more sane place when I figure out where to put it
         gameIsRunning = false;
         myEngine = new NesEngine();
         //If they gave us a ROM to run on the commandline, go ahead and start it up 
         if (!String.IsNullOrEmpty(defaultRom))
         {
             try
             {
                 RunCart(Path.Combine(Path.Combine(filePath, fileDirectory), defaultRom));
             }
             catch (ArgumentException e)
             {
                 Console.WriteLine(e.StackTrace);
                 Console.WriteLine("defaultRom: " + defaultRom);
                 Console.WriteLine("fileDirectory: " + fileDirectory);
             }
         }
     }
     catch (ArgumentException e)
     {
         Console.WriteLine(e.StackTrace);
         Console.WriteLine("defaultRom: " + defaultRom);
         Console.WriteLine("fileDirectory: " + fileDirectory);
     }
 }
Esempio n. 6
0
        public ProcessorNes6502(NesEngine theEngine)
        {
            myEngine = theEngine;
            //aRegister;
            //xIndexRegister = 0;
            //yIndexRegister = 0;
            spRegister = 0xff;

            //FIXME: this is for debugging
            //totalTickCount = 0;
        }
Esempio n. 7
0
        public bool RenderNextScanline()
        {
            int i;

            //Console.WriteLine("Rendering line: {0}", currentScanline);

            if (currentScanline < 234)
            {
                //Clean up the line from before
                if ((uint)nameTables[0x1f00] > 63)
                {
                    for (i = 0; i < 256; i++)
                    {
                        //offscreenBuffer[(currentScanline * 256) + i] = (int)Nes_Palette[(int)nameTables[0x1f00]];
                        offScreenBuffer[(currentScanline * 256) + i] = 0;
                        sprite0Buffer[i] = 0;
                    }
                }
                else
                {
                    for (i = 0; i < 256; i++)
                    {
                        offScreenBuffer[(currentScanline * 256) + i] = (short)NesPalette[(uint)nameTables[0x1f00]];
                        sprite0Buffer[i] = 0;
                        //offscreenBuffer[(currentScanline * 256) + i] = 0;
                    }
                }

                spritesCrossed = 0;
                //We are in visible territory, so render to our offscreen buffer
                if (spritesVisible)
                {
                    RenderSprites(0x20);
                }

                if (backgroundVisible)
                {
                    RenderBackground();
                }

                if (spritesVisible)
                {
                    RenderSprites(0);
                }


                //Check to see if we hit sprite 0 against the background
                //Sprite pixels = 1, BG = 4, so if we're greater than 4, we hit
                if (sprite0Hit == 0)
                {
                    for (i = 0; i < 256; i++)
                    {
                        //Console.Write("{0} ", sprite0Buffer[i]);
                        if (sprite0Buffer[i] > 4)
                        {
                            sprite0Hit = 1;
                        }
                        //offscreenBuffer[(currentScanline * 256) + i] = 0;
                    }
                }
                //Console.WriteLine("Scanline: {0}  Hit: {1}", currentScanline, sprite0Hit);
                if (!noBackgroundClipping)
                {
                    for (i = 0; i < 8; i++)
                    {
                        offScreenBuffer[(currentScanline * 256) + i] = 0;
                    }
                }
            }

            if (currentScanline == 240)
            {
                myVideo.BlitScreen();
                NesEngine.CheckForEvents();
            }

            currentScanline++;
            if (myEngine.FixScrollOffset1)
            {
                if (currentScanline > 244)
                {
                    //FIXME: This helps fix Battle of Olympus, does it
                    //break anything?
                    //244 and greater is vblank, so maybe this makes sense
                    //--OR--
                    //Is this cleared on a read?
                    sprite0Hit = 0;
                }
            }
            if (currentScanline > 262)
            {
                //Reset our screen-by-screen variables
                currentScanline = 0;
                sprite0Hit      = 0;
                //scrollH = 0;
                //scrollV = 0;
                frameCounter++;

                /*
                 * if (frameCounter == 60)
                 * {
                 *  dtafter = DateTime.Now;
                 *  Console.WriteLine("FPS: " + (60.0 / ((dtafter-dtbefore).Ticks / 10000000.0)));
                 *  dtbefore = dtafter;
                 *  frameCounter = 0;
                 * }
                 */
            }

            //Are we about to NMI on vblank?
            if ((currentScanline == 240) && (executeNMIonVBlank == true))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }