Example #1
0
 private final void realSpriteZeroRendering(final int layer) {
   for (int x = 0; x < 8; x++) {
     if (layer == 0) {
       // behind sprites for sprite #0
       frameManager.setPixelLayer0(
           (sprite.paletteUpperBitsColor << 2) | tile[x][lineToRender], sprite.xCoordinate + x, y);
       colorIndex =
           ppu.vram.readUnhandled(
               VideoMemoryMap.SPR_PALLETE_START
                   + frameManager.getPixelLayer0At(sprite.xCoordinate + x, y));
     } else {
       // front sprites for sprite #0
       frameManager.setPixelLayer2(
           (sprite.paletteUpperBitsColor << 2) | tile[x][lineToRender], sprite.xCoordinate + x, y);
       colorIndex =
           ppu.vram.readUnhandled(
               VideoMemoryMap.SPR_PALLETE_START
                   + frameManager.getPixelLayer2At(sprite.xCoordinate + x, y));
     }
     // just rendering when the colour isn't the transparency one!
     if (colorIndex != ppu.vram.readUnhandled(VideoMemoryMap.SPR_PALLETE_START)) {
       frameManager.setPixel(NesPalette.getRGBAt(colorIndex), sprite.xCoordinate + x, y);
       // The Sprite #0 Detection!
       if (frameManager.getPixelLayer1At(sprite.xCoordinate + x, y) != 0) {
         ppu.ppuStatus.sprite0Hit = 1;
       }
     }
   }
 }
Example #2
0
  private final void renderLayer1() {
    // 1. Name table byte
    // 2. Attribute table byte
    // 3. Pattern table bitmap #0
    // 4. Pattern table bitmap #1

    // just render if it is enable!
    if (ppu.ppuMask.backgroundRenderingEnable != 0) {
      for (int pixel = 0; pixel < 256; pixel++) {
        // int nametableAddress = ppu.pPUAddress.completeAddress & 0x7FF;
        int tileIndex =
            ppu.vram.read(
                VideoMemoryMap.NAME_TABLE_0_START
                    + (ppu.scrolling.tileY * 32 + ppu.scrolling.tileX));
        int[][] bgTile = ppu.getTile(ppu.ppuControl.patternTableAddressBackground, tileIndex);
        frameManager.setPixelLayer1(
            bgTile[ppu.scrolling.loopyX][ppu.scrolling.fineY], pixel, ppu.actualScanLine);
        colorIndex =
            ppu.vram.readUnhandled(
                VideoMemoryMap.BG_PALLETE_START
                    + ((ppu.getUpper2BitColorFromAttributeTable(
                                VideoMemoryMap.NAME_TABLE_0_START, tileIndex)
                            << 2)
                        | frameManager.getPixelLayer1At(pixel, ppu.actualScanLine)));
        frameManager.setPixel(NesPalette.getRGBAt(colorIndex), pixel, ppu.actualScanLine);
        /*frameManager.setPixel(new float[]{(float)Math.random(),(float)Math.random(),(float)Math.random()},
        pixel, ppu.actualScanLine);*/

        // fine controls what pixel to start to rendering (0-7) from the tile.
        // when it reaches the 7 it will wrap to 0 and increase the tilex!-
        if (ppu.scrolling.loopyX == 7) {
          ppu.scrolling.tileX++;
          if (ppu.scrolling.tileX > 31) {
            ppu.scrolling.tileX &= 31;
            ppu.scrolling.loopyT[10] =
                ~ppu.scrolling.loopyT[10] & 1; // flipping the low nametable bit.
          }
        }
        // wrapping the finex...
        ppu.scrolling.loopyX = (ppu.scrolling.loopyX + 1) & 7;
      }
      ppu.scrolling.fineY++; // always after a scanline the finey is increase.
      settedTileYFrom2006 = (ppu.scrolling.tileY > 29); // checking it it was setted by $2006.
      if (ppu.scrolling.fineY > 7) {
        // when finey wraps to 0, the tiley is increased.
        ppu.scrolling.fineY &= 7;
        ppu.scrolling.tileY++;
      }

      if (ppu.scrolling.tileY > 29 && !settedTileYFrom2006) {
        ppu.scrolling.tileY = 0;
        ppu.scrolling.loopyT[11] =
            ~ppu.scrolling.loopyT[11] & 1; // flipping the high nametable bit.
      } else if (ppu.scrolling.tileY > 29 && settedTileYFrom2006) {
        ppu.scrolling.tileY = 0;
      }
    }
  }