public PpuDebug(Ppu ppu) { InitializeComponent(); this.ppu = ppu; this.DoubleBuffered = true; //this.ClientSize = new Size(16 * 8, 32 * 8); }
public Nes(string romfile) { ActiveNes = this; Rom = new Rom(romfile); Mem = new NesMemory(this); Cpu = new Chip6502(Mem); Ppu = new Ppu(this); switch (Rom.MapperNumber) { case 0: Mapper = new NROM(this); break; case 1: Mapper = new MMC1(this); break; case 2: Mapper = new UxROM(this); break; default: // TODO: Cleaner... throw new Exception("Unknown mapper"); } Reset(); }
public Nes(string romfile) { ActiveNes=this; Rom = new Rom(romfile); Mem = new NesMemory(this); Cpu = new Chip6502(Mem); Ppu = new Ppu(this); switch (Rom.MapperNumber) { case 0: Mapper = new NROM(this); break; case 1: Mapper = new MMC1(this); break; case 2: Mapper = new UxROM(this); break; default: // TODO: Cleaner... throw new Exception("Unknown mapper"); } Reset(); }
public PpuOutput(Nes nes) { InitializeComponent(); //this.DoubleBuffered = true; this.ClientSize = new Size(Ppu.ScreenWidth * 3, Ppu.ScreenHeight * 3); this.ppu = nes.Ppu; this.nes = nes; PresentationParameters pp = new PresentationParameters(); pp.AutoDepthStencilFormat = DepthFormat.Depth16; pp.BackBufferCount = 1; pp.BackBufferFormat = SurfaceFormat.Bgr32; pp.BackBufferWidth = Ppu.ScreenWidth; pp.BackBufferHeight = Ppu.ScreenHeight; pp.DeviceWindowHandle = this.Handle; pp.EnableAutoDepthStencil = true; pp.IsFullScreen = false; pp.MultiSampleType = MultiSampleType.None; pp.PresentationInterval = PresentInterval.Default; // TODO pp.RenderTargetUsage = RenderTargetUsage.PreserveContents; pp.SwapEffect = SwapEffect.Discard; pp.PresentationInterval = PresentInterval.One; device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, this.Handle, pp); tex = new Texture2D(device, Ppu.ScreenWidth, Ppu.ScreenHeight, 1, TextureUsage.None, SurfaceFormat.Bgr32); sb = new SpriteBatch(device); }
private Bitmap GetPattern(int addr) { Bitmap bmp = new Bitmap(8, 8); for (int y = 0; y < 8; ++y) { for (int x = 0; x < 8; ++x) { int addr1 = addr + y; int addr2 = addr + y + 8; // Note: patternhigh should be same for both here byte b1 = ppu.PatternTables[Ppu.PatternHigh(addr1)][Ppu.PatternLow(addr1)]; byte b2 = ppu.PatternTables[Ppu.PatternHigh(addr2)][Ppu.PatternLow(addr2)]; byte bit1 = (byte)((b1 >> (7 - x)) & 0x1); byte bit2 = (byte)((b2 >> (7 - x)) & 0x1); byte result = (byte)(bit2 << 1 | bit1); int color; if (result == 3) { color = 0xFF << 24 | 0xFF0000; } else if (result == 2) { color = 0xFF << 24 | 0x00FF00; } else if (result == 1) { color = 0xFF << 24 | 0x0000FF; } else { color = 0; } if (result == 0) { bmp.SetPixel(x, y, Color.FromArgb(0, 0, 0, 0)); } else { bmp.SetPixel(x, y, Color.FromArgb(color)); } /*if (result == 0) * bmp.SetPixel(x, y, Color.FromArgb(0, 0, 0, 0)); * else * { * int paletteEntry = ppu.Read(paletteAddr + result) % 64; // todo: bits * bmp.SetPixel(x, y, Color.FromArgb(0xFF << 24 | Palette[paletteEntry])); * }*/ } } return(bmp); }
public void Reset() { sw.Reset(); sw.Start(); //cpuCycles = 0;// ppuCycles = 0; cpuDivider = 0; TotalPpuCycles = 0; TotalCpuCycles = 0; frameCount = 0; Mem.Reset(); Ppu.Reset(); Mapper.Reset(); Cpu.RAM = Mem.RAM; Cpu.Reset(); sw.Start(); }
private Bitmap GetPattern(int addr, int paletteAddr) { Bitmap bmp = new Bitmap(8, 8); for (int y = 0; y < 8; ++y) { for (int x = 0; x < 8; ++x) { int addr1 = addr + y; int addr2 = addr + y + 8; byte b1 = ppu.PatternTables[Ppu.PatternHigh(addr1)][Ppu.PatternLow(addr1)]; byte b2 = ppu.PatternTables[Ppu.PatternHigh(addr2)][Ppu.PatternLow(addr2)]; byte bit1 = (byte)((b1 >> (7 - x)) & 0x1); byte bit2 = (byte)((b2 >> (7 - x)) & 0x1); byte result = (byte)(bit2 << 1 | bit1); /*byte intensity; * if (result == 3) * intensity = 255; * else if (result == 2) * intensity = 160; * else if (result == 1) * intensity = 80; * else * intensity = 0; * * if (result == 0) * bmp.SetPixel(x, y, Color.FromArgb(0,0,0,0)); * else * bmp.SetPixel(x, y, Color.FromArgb(intensity, intensity, intensity));*/ if (result == 0) { bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(0, 0, 0, 0)); } else { int paletteEntry = ppu.Read(paletteAddr + result) % 64; // todo: bits bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(0xFF << 24 | Palette[paletteEntry])); } } } return(bmp); }
public int RunOneFrame() { /*if (Cpu.Paused) * return ppuCyclesToRun;*/ while (true) { if (Cpu.WaitCycles <= Ppu.WaitCycles) { Cpu.Run(Ppu.WaitCycles); } else { Cpu.WaitCycles -= Ppu.WaitCycles; } Ppu.FrameCycle += Ppu.WaitCycles; Ppu.WaitCycles = 0; Ppu.Tick(); if (Ppu.VsyncSignalToMainLoop) { Ppu.VsyncSignalToMainLoop = false; ++frameCount; if (frameCount == 10) { float secs = sw.ElapsedTicks / (float)Stopwatch.Frequency; FPS = frameCount / secs; sw.Reset(); sw.Start(); frameCount = 0; } //render = true; return(0); } #if false //Console.WriteLine("ToRun: {0} CPU: {1} PPU: {2}", ppuCyclesToRun, Cpu.WaitCycles, Ppu.WaitCycles); //int min = ppuCyclesToRun < Ppu.WaitCycles ? ppuCyclesToRun : Ppu.WaitCycles; int min = Ppu.WaitCycles < Cpu.WaitCycles ? Ppu.WaitCycles : Cpu.WaitCycles; //Console.WriteLine("Min={0}", min); //TotalCpuCycles += min; //TotalPpuCycles += min; Cpu.WaitCycles -= min; Ppu.WaitCycles -= min; //ppuCyclesToRun -= min; if (Cpu.WaitCycles == 0) { Cpu.Tick(); } /*if (Ppu.WaitCycles < 0) * throw new InvalidOperationException("F**K");*/ Ppu.FrameCycle += min; if (Ppu.WaitCycles == 0) { Ppu.Tick(); if (Ppu.VsyncSignalToMainLoop) { Ppu.VsyncSignalToMainLoop = false; ++frameCount; if (frameCount == 10) { float secs = sw.ElapsedTicks / (float)Stopwatch.Frequency; FPS = frameCount / secs; sw.Reset(); sw.Start(); frameCount = 0; } //render = true; return(0); } } #endif } //return ppuCyclesToRun; }
public PpuOutput(Nes nes) { InitializeComponent(); //this.DoubleBuffered = true; this.ClientSize = new Size(Ppu.ScreenWidth*3, Ppu.ScreenHeight*3); this.ppu = nes.Ppu; this.nes = nes; PresentationParameters pp = new PresentationParameters(); pp.AutoDepthStencilFormat = DepthFormat.Depth16; pp.BackBufferCount = 1; pp.BackBufferFormat = SurfaceFormat.Bgr32; pp.BackBufferWidth = Ppu.ScreenWidth; pp.BackBufferHeight = Ppu.ScreenHeight; pp.DeviceWindowHandle = this.Handle; pp.EnableAutoDepthStencil = true; pp.IsFullScreen = false; pp.MultiSampleType = MultiSampleType.None; pp.PresentationInterval = PresentInterval.Default; // TODO pp.RenderTargetUsage = RenderTargetUsage.PreserveContents; pp.SwapEffect = SwapEffect.Discard; pp.PresentationInterval = PresentInterval.One; device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, this.Handle, pp); tex = new Texture2D(device, Ppu.ScreenWidth, Ppu.ScreenHeight, 1, TextureUsage.None, SurfaceFormat.Bgr32); sb = new SpriteBatch(device); }