Esempio n. 1
0
// Continuously update the screen with something interesting
func render() {
	counter := 0
	for {
		w, h := leggo.Dimensions()

		for y := 0; y < h; y += 1 {
			for x := 0; x < w; x += 1 {
				var r, g, b byte
				// Some random things to look at
				switch mode % 8 {
				case 0:
					r = byte(rand.Uint32())
					g = r
					b = r
				case 1:
					r = byte(rand.Uint32())
					g = byte(rand.Uint32())
					b = byte(rand.Uint32())
				case 2:
					r = byte(x * y)
				case 3:
					r = byte(x*y - int(rand.Uint32())%50)
				case 4:
					if x == counter%w {
						r = 255
						g = 255
						b = 255
					}
				case 5:
					if counter%2 == 1 {
						g = 255
					} else {
						r = 255
					}
					time.Sleep(10000)
				case 6:
					if x == w/2 {
						g = 255
					}
					if y == h/2 {
						r = 255
					}
				case 7:
					if x == y {
						b = 255
					}
				}

				leggo.WritePixel(x, y, r, g, b, 0)
			}
		}
		counter += 1
	}
}
Esempio n. 2
0
// Draw pattern to screen for debugging purposes
func (ppu *PPU) DrawPattern(pattern [8][8]uint8, offX int, offY int, tileAttr uint8) {
	for row := 0; row < 8; row += 1 {
		for column := 0; column < 8; column += 1 {
			// Lower 3 bits of color index
			index := pattern[7-column][7-row]
			/*
			   if index == 0 {
			       // TODO: 0 is transparent, don't draw it
			       continue
			   }*/

			// Combine with attribute table
			index |= tileAttr << 2

			// Lookup from internal "palette" table (really a lookup table)
			// TODO: background/sprite select. This one assumes background.
			color := ppu.Memory[IMAGE_PALETTE_1+uint16(index)]

			// Convert from color into RGB
			rgb := PPU_PALETTE_RGB[color]
			r, g, b := float(rgb[0])/255, float(rgb[1])/255, float(rgb[2])/255

			// Emphasize colors
			// Note: generating NTSC waveform and rendering it manually would be more accurate
			intensity := INTENSIFY_COEFFICIENTS[ppu.intensifyMask]
			ir, ig, ib := intensity[0], intensity[1], intensity[2]
			r *= ir
			g *= ig
			b *= ib

			// Clipping
			if row+offX > PIXELS_VISIBLE || column+offY > SCANLINES_VISIBLE {
				continue
			}

			drawX := row + offX
			drawY := (7 - column) + offY

			leggo.WritePixel(drawX, drawY, uint8(r*255), uint8(g*255), uint8(b*255), 0)
		}
	}
}