Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

nes ppu vbl unit test

a guest Aug 19th, 2018 6 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. // Test raw PPU vblank timing when PPU rendering is off.
  2. TEST(ppu_off_vblank)
  3. {
  4.   static const std::vector<uint8_t> program = {};
  5.   auto emu = createTestEmulator(MapperType::NROM, 2, 1, 0, program);
  6.   auto &ppu = emu->ppu();  // alias for brevity
  7.  
  8.   ppu.bus_read(IORegisters::PPUSTATUS);  // reset latch
  9.   ppu.bus_write(IORegisters::PPUCTRL, 0);
  10.   ppu.bus_write(IORegisters::PPUMASK, 0);
  11.  
  12.   // Pre-flight check.
  13.   TEST_EQUAL_INT(0, ppu.getFrame());
  14.   TEST_EQUAL_INT(0, ppu.getOddFrame());
  15.   TEST_EQUAL_INT(PreRenderScanline, ppu.getScanline());
  16.   TEST_EQUAL_INT(0, ppu.getCycle());
  17.   TEST_EQUAL_BYTE(0, ppu.getVBlank());
  18.   TEST_EQUAL_INT(PpuState::PreRender, ppu.getState());
  19.  
  20.   // Process pre-render scanline, plus one tick to start rendering.
  21.   for (int i = 0; i < 341; i++) {
  22.     ppu.tick();
  23.   }
  24.   TEST_EQUAL_INT(0, ppu.getFrame());
  25.   TEST_EQUAL_INT(0, ppu.getOddFrame());
  26.   TEST_EQUAL_INT(FirstRenderScanline, ppu.getScanline());
  27.   TEST_EQUAL_INT(0, ppu.getCycle());
  28.   TEST_EQUAL_BYTE(0, ppu.getVBlank());
  29.   TEST_EQUAL_INT(PpuState::Render, ppu.getState());
  30.  
  31.   // Get through render scanlines.
  32.   for (int i = 0; i < 341 * 240; i++) {
  33.     ppu.tick();
  34.   }
  35.   TEST_EQUAL_INT(0, ppu.getFrame());
  36.   TEST_EQUAL_INT(0, ppu.getOddFrame());
  37.   TEST_EQUAL_INT(PostRenderScanline, ppu.getScanline());
  38.   TEST_EQUAL_INT(0, ppu.getCycle());
  39.   TEST_EQUAL_BYTE(0, ppu.getVBlank());
  40.   TEST_EQUAL_INT(PpuState::PostRender, ppu.getState());
  41.  
  42.   // PostRender scanline.
  43.   for (int i = 0; i < 341; i++) {
  44.     ppu.tick();
  45.   }
  46.   TEST_EQUAL_INT(0, ppu.getFrame());
  47.   TEST_EQUAL_INT(0, ppu.getOddFrame());
  48.   TEST_EQUAL_INT(FirstVBlankScanline, ppu.getScanline());
  49.   TEST_EQUAL_INT(0, ppu.getCycle());
  50.   TEST_EQUAL_BYTE(0, ppu.getVBlank());
  51.   TEST_EQUAL_INT(PpuState::VBlank, ppu.getState());
  52.  
  53.   // Next tick is right before VBLank on.
  54.   ppu.tick();
  55.   TEST_EQUAL_BYTE(0, ppu.getVBlank());
  56.  
  57.   // Next tick should turn VBlank on.
  58.   ppu.tick();
  59.   TEST_EQUAL_BYTE(1, ppu.getVBlank());
  60.  
  61.   // Finish vblank period.
  62.   for (int i = 0; i < 339 + 341 * 19; i++) {
  63.     ppu.tick();
  64.   }
  65.   TEST_EQUAL_INT(1, ppu.getFrame());
  66.   TEST_EQUAL_INT(1, ppu.getOddFrame());
  67.   TEST_EQUAL_INT(PreRenderScanline, ppu.getScanline());
  68.   TEST_EQUAL_INT(0, ppu.getCycle());
  69.   TEST_EQUAL_BYTE(1, ppu.getVBlank());
  70.   TEST_EQUAL_INT(PpuState::PreRender, ppu.getState());
  71.  
  72.   // Cycle #0 of pre-render does not touch vblank, but cycle #1 does.
  73.   ppu.tick();
  74.   TEST_EQUAL_BYTE(1, ppu.getVBlank());
  75.  
  76.   // Next tick should turn VBlank off.
  77.   ppu.tick();
  78.   TEST_EQUAL_BYTE(0, ppu.getVBlank());
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top