コード例 #1
0
ファイル: RenderScanline.java プロジェクト: LCClyde/jnesbr
  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;
      }
    }
  }
コード例 #2
0
ファイル: RenderScanline.java プロジェクト: LCClyde/jnesbr
  private final void renderLayer(final int layer, final Iterator<Sprite> iterator) {
    if (ppu.ppuMask.spriteRenderingEnable == 1) {
      while (iterator.hasNext()) {
        sprite = iterator.next();

        lineToRender = y - sprite.yCoordinate;
        tile = ppu.getTile(sprite.patternTable, sprite.tileNumber0);
        // todo: who cames first?
        if (sprite.horizontalFlip == 1) {
          tile = flipHorizontal(tile);
        }
        if (sprite.verticalFlip == 1) {
          tile = flipVertical(tile);
        }
        if (sprite.index == 0) {
          realSpriteZeroRendering(layer);
        } else {
          realSpriteRendering(layer);
        }
      }
    }
  }