GameBoy\Core::drawBackgroundForLine PHP Method

drawBackgroundForLine() public method

public drawBackgroundForLine ( $line, $windowLeft, $priority )
    public function drawBackgroundForLine($line, $windowLeft, $priority)
    {
        $skippedTile = false;
        $tileNum = 0;
        $tileXCoord = 0;
        $tileAttrib = 0;
        $sourceY = $line + $this->memory[0xff42];
        $sourceImageLine = $sourceY & 0x7;
        $tileX = $this->memory[0xff43] >> 3;
        $memStart = ($this->gfxBackgroundY ? 0x1c00 : 0x1800) + (($sourceY & 0xf8) << 2);
        $screenX = -($this->memory[0xff43] & 7);
        for (; $screenX < $windowLeft; $tileX++, $screenX += 8) {
            $tileXCoord = $tileX & 0x1f;
            $baseaddr = $this->memory[0x8000 + $memStart + $tileXCoord];
            $tileNum = $this->gfxBackgroundX ? $baseaddr : ($baseaddr > 0x7f ? ($baseaddr & 0x7f) + 0x80 : $baseaddr + 0x100);
            if ($this->cGBC) {
                $mapAttrib = $this->VRAM[$memStart + $tileXCoord];
                if (($mapAttrib & 0x80) != $priority) {
                    $skippedTile = true;
                    continue;
                }
                $tileAttrib = (($mapAttrib & 0x7) << 2) + ($mapAttrib >> 5 & 0x3);
                $tileNum += 384 * ($mapAttrib >> 3 & 0x1);
                // tile vram bank
            }
            $this->drawPartCopy($tileNum, $screenX, $line, $sourceImageLine, $tileAttrib);
        }
        if ($windowLeft < 160) {
            // window!
            $windowStartAddress = $this->gfxWindowY ? 0x1c00 : 0x1800;
            $windowSourceTileY = $this->windowSourceLine >> 3;
            $tileAddress = $windowStartAddress + $windowSourceTileY * 0x20;
            $windowSourceTileLine = $this->windowSourceLine & 0x7;
            for ($screenX = $windowLeft; $screenX < 160; $tileAddress++, $screenX += 8) {
                $baseaddr = $this->memory[0x8000 + $tileAddress];
                $tileNum = $this->gfxBackgroundX ? $baseaddr : ($baseaddr > 0x7f ? ($baseaddr & 0x7f) + 0x80 : $baseaddr + 0x100);
                if ($this->cGBC) {
                    $mapAttrib = $this->VRAM[$tileAddress];
                    if (($mapAttrib & 0x80) != $priority) {
                        $skippedTile = true;
                        continue;
                    }
                    $tileAttrib = (($mapAttrib & 0x7) << 2) + ($mapAttrib >> 5 & 0x3);
                    // mirroring
                    $tileNum += 384 * ($mapAttrib >> 3 & 0x1);
                    // tile vram bank
                }
                $this->drawPartCopy($tileNum, $screenX, $line, $windowSourceTileLine, $tileAttrib);
            }
        }
        return $skippedTile;
    }