screen

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: GPL-3.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	LayerNBG0 = 0
	LayerNBG1 = 1
	LayerNBG2 = 2
	LayerNBG3 = 3
	LayerRBG0 = 4
	LayerRBG1 = 5
)

Layer buffer indices for CompositeParams.LayerBuf.

View Source
const (
	ShadowNone      = 0
	ShadowNormal    = 1 // darkens scroll screens and the back screen per SDCTL
	ShadowMSBSprite = 2 // a sprite pixel displayed with a shadow added
	ShadowMSBTransp = 3 // transparent dot projecting a shadow per SDCTL
	ShadowMSBNull   = 4 // transparent dot, no shadow (TPSDSL=0)
)

Shadow types of a sprite pixel (Sec 14).

View Source
const (
	SpriteReadNone    = 0 // no frame buffer, or the row is past it
	SpriteRead16      = 1 // 16-bit pixels, direct row read
	SpriteRead8       = 2 // 8-bit pixels, direct row read
	SpriteReadRotated = 3 // rotation parameter A drives the read coordinate
)

Sprite frame buffer read modes.

View Source
const CellDots = 8

CellDots is the dots across a cell, the VDP2's character pattern unit. A character is one cell or, with the 2x2 size, two across. A cell's dots share a pattern name, so it is also the run a cell span reads one pattern name for.

View Source
const ColorMask = 0xFFFFFF

ColorMask selects a decoded color's channel bits.

View Source
const GradationCarries = 16

GradationCarries is the number of pre-blur pixels a span carries to the next: two neighbors at the largest step, 8.

View Source
const LayerCCBit = 1 << 31

LayerCCBit marks a layer buffer pixel as color-calculation enabled, the bit the palette word also uses. Priority occupies bits 26:24 and the decoded color bits 23:0.

Variables

View Source
var Entries = [...]string{
	"NBGCellSpan", "NBGBitmapSpan", "RBGCellSpan", "RBGBitmapSpan", "GradationSpan", "CompositeSpan",
	"BuildPalette", "CopyVRAMPages", "CopyCRAMPages",
}

Entries names the package's entry points: the span entries a row's chain names, then the frame-level ones dispatched between rows. The order is this list's own. A renderer indexes them by name.

View Source
var Source embed.FS

Source is this package's Go source for the GPU renderer's compile stage.

The files are named one by one: the compile stage takes everything Source holds, so this file and the package's tests must stay out of it. TestEmbeddedSource holds the list against the directory.

Functions

func BitmapDot4

func BitmapDot4(vram *compute.VDP2VRAM, base, dot uint32) uint32

BitmapDot4, BitmapDot8, BitmapDot16, and BitmapDot32 read dot dot of the bitmap at base, the dot's index being its row times the bitmap's width plus its column, in the 4-bit, 8-bit, 16-bit, and 32-bit RGB formats. The bitmap's width is even, so a 4-bit dot's nibble follows its column's parity.

func BitmapDot8

func BitmapDot8(vram *compute.VDP2VRAM, base, dot uint32) uint32

func BitmapDot16

func BitmapDot16(vram *compute.VDP2VRAM, base, dot uint32) uint32

func BitmapDot32

func BitmapDot32(vram *compute.VDP2VRAM, base, dot uint32) (rgb uint32, opaque bool)

func BuildPalette

func BuildPalette(cram *compute.CRAM, pal *compute.Palette, p *PaletteParams, i uint32)

BuildPalette writes palette entry i. Entry point: one thread per entry.

func BuildWindowRuns

func BuildWindowRuns(w0, w1 LineWindow, width int32, out *WindowRuns)

BuildWindowRuns splits a row of the given width into runs at the edges of the two resolved windows.

func CellDot4

func CellDot4(vram *compute.VDP2VRAM, cellAddr uint32, dotX, dotY int32) uint32

CellDot4 reads one 4-bit dot of a character cell at cellAddr.

func CellDot8

func CellDot8(vram *compute.VDP2VRAM, cellAddr uint32, dotX, dotY int32) uint32

CellDot8 reads one 8-bit dot of a character cell.

func CellDot16

func CellDot16(vram *compute.VDP2VRAM, cellAddr uint32, dotX, dotY int32) uint32

CellDot16 reads one 16-bit dot of a character cell.

func CellDot32

func CellDot32(vram *compute.VDP2VRAM, cellAddr uint32, dotX, dotY int32) (rgb uint32, opaque bool)

CellDot32 reads one 32-bit RGB dot of a character cell. Returns the decoded color and whether the dot is opaque.

func CoefAddr

func CoefAddr(kastFP int64, ktaof uint32, oneWord bool) uint32

CoefAddr converts a .10 coefficient address to a VRAM byte address per Sec 6.1: the integer part indexes the table, scaled by the entry size and offset by KTAOF.

func Coefficient

func Coefficient(vram *compute.VDP2VRAM, cram *compute.CRAM, addr uint32, oneWord, mode3, fromCRAM bool) (val int64, msb bool, lc uint32)

Coefficient reads a coefficient table entry from VRAM, or from the upper half of CRAM when CRKTE is set: the value (.16 for the scale modes, .10 for the Xp mode), the MSB (transparency or parameter switch), and the two-word format's 7-bit line color data.

func ColorB

func ColorB(c uint32) uint32

func ColorG

func ColorG(c uint32) uint32

func ColorR

func ColorR(c uint32) uint32

ColorR, ColorG, and ColorB extract a decoded color's channels.

func CompositeSpan

func CompositeSpan(in *CompositeInputs, out compute.Framebuffer, p *CompositeParams, x0, x1 int32)

CompositeSpan composes dots [x0, x1) of the row into the output frame: per dot the candidate gathering across the enabled layers and the sprite, the top three images by priority (Table 11.1), color calculation with the second image (Sec 12), color offset, and shadow (Sec 14), and one store of the result. The back screen is the bottom of the stack and is held as a value, so the frame is never read. Under LSMD=3 the first frame in a mode also writes the other field's row, so the display never shows a half-bright frame. Entry point.

func CopyCRAMPages

func CopyCRAMPages(cram *compute.CRAM, pages *CRAMPages, p *CopyParams, i uint32)

CopyCRAMPages writes word i of a band's staged pages into VDP2 CRAM. Entry point: one thread per word.

func CopyVRAMPages

func CopyVRAMPages(vram *compute.VDP2VRAM, pages *VRAMPages, p *CopyParams, i uint32)

CopyVRAMPages writes word i of a band's staged pages into VDP2 VRAM. Entry point: one thread per word.

func DecodePattern1Word

func DecodePattern1Word(pn, pncn, colorMode uint32, auxMode1, char2x2 bool) (charNum, palette uint32, hflip, vflip bool)

DecodePattern1Word extracts the character number, palette, and flips from a 1-word pattern name entry under the PNCN supplement bits, the color mode, the auxiliary mode, and the character size. In 2x2 character mode the character number is shifted left by 2 for the sub-cell index and the supplement character bits split around it.

func DecodePattern2Word

func DecodePattern2Word(msw, lsw uint32) (charNum, palette uint32, hflip, vflip, specialPri, specialCC bool)

DecodePattern2Word extracts the fields of a 2-word pattern name entry: flips in MSW bits 15 and 14, the special priority and special color calculation bits in 13 and 12, the palette in bits 6:0, and the character number in LSW bits 14:0.

func DisplayY

func DisplayY(p WindowParams, y int32) int32

DisplayY returns the displayed line for field-line y.

func GradationSpan

func GradationSpan(buf compute.Layer, p *GradationParams, st *GradationState, x0, x1 int32)

GradationSpan blurs pixels [x0, x1) of the row in place: pixel x becomes (x-2*Step + x-Step + 2x) / 4 per channel from the pre-blur values of its left neighbors, keeping its priority and color calculation bits, and transparent pixels stay transparent. Processing right to left within the span keeps the in-span neighbors original.

func LineTableY

func LineTableY(p WindowParams, y int32) int32

LineTableY returns the per-line table index for field-line y: single-density interlace halves y since each entry covers two field lines, double-density maps y to the displayed line 2*y + field.

func LineWindowX

func LineWindowX(p WindowParams, raw uint32) int32

LineWindowX converts a line window table word to a pixel coordinate. The words are signed 16-bit values: games exclude a line by storing start > end (an end of 0xFFFF reads as -1) and cover a full line with a negative start. In normal resolution bit 0 is invalid, so the signed word shifts right arithmetically by one.

func NBGBitmapSpan

func NBGBitmapSpan(vram *compute.VDP2VRAM, pal *compute.Palette, out compute.Layer, p *NBGParams, x0, x1 int32)

NBGBitmapSpan renders dots [x0, x1) of the row of a bitmap-mode normal scroll screen into the layer buffer. The 16.7M-color bitmap reads linearly without the width wrap so line-scroll stride compensation lands pixels where the game placed them.

func NBGCellSpan

func NBGCellSpan(vram *compute.VDP2VRAM, pal *compute.Palette, out compute.Layer, p *NBGParams, st *NBGCellState, x0, x1 int32)

NBGCellSpan renders dots [x0, x1) of the row of a cell-mode normal scroll screen into the layer buffer. Entry point: the software renderer calls it per span, the GPU per segment of whole cells at the scale.

func PackColor

func PackColor(r, g, b uint32) uint32

PackColor packs 8-bit channels into a decoded color.

func PaletteColor

func PaletteColor(pal *compute.Palette, mode uint32, addr uint32) (rgb uint32, cc bool)

PaletteColor reads the color for a CRAM address in the mode: the decoded color and the color calculation bit.

func PaletteDot

func PaletteDot(pal *compute.Palette, cramMode uint32, dot, palette, cramOffset, colorMode uint32, transpOff bool) (rgb uint32, transp bool, cc bool)

PaletteDot resolves a palette-format dot to its color: dot 0 is transparent unless transparency is off; 16-color dots index a 16-entry palette, 256-color dots a 256-entry palette selected by the palette number's upper bits, wider dots index CRAM directly; the screen's CRAM offset adds 256 entries per step.

func PaletteEntry

func PaletteEntry(cram *compute.CRAM, mode uint32, i uint32) uint32

PaletteEntry decodes CRAM entry i for the mode into a palette word: bit 31 the color calculation bit and bits 23:0 the decoded color (Figure 3.9). In modes 0 and 1 an entry is 15-bit color data with the color calculation bit in bit 15; in modes 2 and 3 it is 24-bit color data with the bit in bit 31, the same layout as the palette word.

func PaletteMask

func PaletteMask(mode uint32) uint32

PaletteMask returns the entry index mask for a CRAM mode: 2048 entries in mode 1, 1024 otherwise.

func PrepareRBGRow

func PrepareRBGRow(p *RBGParams)

PrepareRBGRow derives the row constants the spans start from.

func RBGBitmapSpan

func RBGBitmapSpan(vram *compute.VDP2VRAM, cram *compute.CRAM, pal *compute.Palette, out compute.Layer, lcb compute.LineColor, p *RBGParams, x0, x1 int32)

RBGBitmapSpan renders dots [x0, x1) of the row of a bitmap-mode rotation scroll screen into the layer buffer. Screen-over wrap repeats the bitmap, mode 3 repeats it over the screenOverArea display area and is transparent past it (Plane Size Register note: a 256-dot bitmap shows two images), and the other modes leave an out-of-bitmap dot transparent. Entry point.

func RBGCellSpan

func RBGCellSpan(vram *compute.VDP2VRAM, cram *compute.CRAM, pal *compute.Palette, out compute.Layer, lcb compute.LineColor, p *RBGParams, x0, x1 int32)

RBGCellSpan renders dots [x0, x1) of the row of a cell-mode rotation scroll screen into the layer buffer, writing coefficient line color data into lcb. Entry point.

func RGB555To888

func RGB555To888(val uint32) uint32

RGB555To888 expands 15-bit color data (bit 15 ignored, bits 14:10 blue, 9:5 green, 4:0 red) to a decoded color. Each channel's 5 bits become the upper 5 bits of its 8 and the lower 3 bits are 0 (VDP2 manual Sec 3.4, "a 0 will be added to the lowest 3 bits"; Sec 4 RGB Format Dot Data; Figure 7.5).

func RGB888Dot

func RGB888Dot(w0, w1 uint32) (rgb uint32, opaque bool)

RGB888Dot decodes a 32-bit RGB dot's two words: word 0 holds the transparency bit (bit 15, set means opaque per Figure 4.6) and blue in bits 7:0, word 1 green in bits 15:8 and red in bits 7:0, so the dot's low 24 bits are the decoded color. Returns the decoded color and whether the dot is opaque.

func RPWindowB

func RPWindowB(w *RPWindow, x int32) bool

RPWindowB reports whether the rotation parameter window selects parameter B at dot x of the row.

func ResolveNBGLine

func ResolveNBGLine(vram *compute.VDP2VRAM, p *NBGParams)

ResolveNBGLine derives the row constants and reads the row's line scroll table entry for the row's scroll X, X increment, and source Y. Per VDP2 manual Sec 5.3 the table values are relative to the scroll registers, and the vertical coordinate increment advances Y within an entry only when the entry spans two or more lines. The bitmap form wraps the scroll X sum to 11 bits and sign-extends it, so a scroll of 2032 places the bitmap 16 dots left rather than at an aliased position.

At scale the row's scroll X and source Y are carried at ScaleShift more fraction bits, the bitmap's scroll X shifted after its wrap, and the source Y advances by SubRow vertical increments at that precision, which is sub-row SubRow's own position within the native row, where the next line's source Y is the row's plus one increment. A vertical mosaic block replicates its rows, so there it does not advance, and neither does it on the last line of a line scroll Y entry (every line at an interval of 1), since the next line's source Y is the next entry's, which the table sets freely: a row's sub-rows then repeat the row. The X increment stays native: a scaled column's step at the wider fraction is the native step.

func SFCodeMatches

func SFCodeMatches(sfcode, dotColor uint32) bool

SFCodeMatches reports whether a dot color's low 4 bits fall in a nibble pair the special function code enables: bit N of sfcode enables dots whose (color & 0xF) >> 1 is N.

func SpritePixel8

func SpritePixel8(fb compute.VDP1FB, r *SpriteRow, x int32) uint32

SpritePixel8 reads column x of an 8-bit direct-read row.

func SpritePixel16

func SpritePixel16(fb compute.VDP1FB, r *SpriteRow, x int32) uint32

SpritePixel16 reads column x of a 16-bit direct-read row: zero past the buffer width.

func SpritePixelRotated

func SpritePixelRotated(fb compute.VDP1FB, r *SpriteRow, x int32) uint32

SpritePixelRotated reads column x through the rotated read coordinate: zero outside the frame buffer. The coordinate lands on a physical row; in a doubled buffer the row read is that row's doubled row of the read's parity, the scaled sub-row kept.

func WindowX

func WindowX(p WindowParams, raw uint32) int32

WindowX converts a raw window horizontal coordinate (WPSX/WPEX) to a pixel coordinate per Table 8.1: hi-res uses bits 9:0, normal resolution bits 9:1.

func WindowY

func WindowY(p WindowParams, raw uint32) int32

WindowY converts a raw window vertical coordinate (WPSY/WPEY) to a displayed-line value per Table 8.2. In double-density interlace the least significant bit is invalid (the value is V7:V0 in bits 8:1), so the boundary aligns to an even displayed line; otherwise all 9 bits are valid.

Types

type CRAMPages

type CRAMPages struct {
	Store *compute.CRAMPageStore
	Table *compute.PageTable
}

CRAMPages is a submission's staged CRAM pages, in the form of VRAMPages.

type CompositeInputs

type CompositeInputs struct {
	Layers     [6]compute.Layer
	LineColors [2]compute.LineColor
	Sprite     compute.VDP1FB
	Palette    *compute.Palette
	VRAM       *compute.VDP2VRAM
}

CompositeInputs are the buffers the composite reads: the scroll layer buffers indexed by the Layer constants, the rotation screens' line color buffers (RBG0 then RBG1), the VDP1 frame buffer the sprite layer reads, the palette, and the VDP2 VRAM holding the line color table.

type CompositeParams

type CompositeParams struct {
	Width          int32
	Y              int32  // the layer and line color buffer row read
	FBRow          int32  // output frame row
	FieldBootstrap uint32 // row xor mask of the other field's row, also written (first LSMD3 frame): 0 off, 1 native, N at scale N
	BackRGB        uint32 // back screen decoded color

	// Enabled scroll layers in candidate order: the buffer index, the
	// layer ID for windows and registers (0-3 NBG, 4 RBG0; RBG1 takes
	// 0), and the tie rank. Static: no layer has per-dot priority, so
	// the list is in display order.
	NLayers  int32
	LayerBuf [5]uint32
	LayerID  [5]uint32
	LayerTie [5]int32
	Static   bool

	// Windows: the row's runs and, per run, each window's state (0-3
	// NBG, 4 RBG0, 5 sprite, 6 color calculation).
	Runs     WindowRuns
	RunState [5][7]WindowState

	// Sprite layer.
	Sprite      SpriteDecode
	SpriteRow   SpriteRow
	SWBit       uint32 // frame buffer bit that is the sprite window bit
	SpriteCCOff bool   // hi-res palette restriction applies to sprites

	// Color calculation.
	CCMD       bool // add as is
	CCRTMD     bool // ratio from the second image
	EXCCEN     bool // extended color calculation
	LCCCEN     bool // line color screen's color calculation enable
	LayerIsRGB [6]bool
	LayerRatio [5]uint32
	CCRLB      uint32
	LNCLEN     uint32
	LCAddr     uint32 // the row's line color table entry address
	R1On       bool   // RBG1 occupies the NBG0 slot
	HiRes      bool
	CRAMMode   uint32

	// Color offset: enables and A/B selects per layer (bit 5 the back
	// screen, bit 6 the sprite layer), and the two offsets.
	CLOFEN uint32
	CLOFSL uint32
	COA    [3]int32
	COB    [3]int32

	SDCTL uint32
}

CompositeParams is the composite's configuration for one row.

type CopyParams

type CopyParams struct {
	Base uint32
}

CopyParams locates a band of staged pages: the slot of its first page in the page store and the page table. Slot s of the band holds the bytes of page table entry Base+s, and the copy writes them to that page of the memory. Applied in band order, the pages reproduce the memory as of the band's line.

type GradationParams

type GradationParams struct {
	Y     int32
	Width int32
	Step  int32
}

GradationParams describes the row the gradation blur runs over: the row of the layer buffer, its width, and the distance in dots to the blur's left neighbors (1 native, N at scale N, so a sub-pixel reads the same sub-pixel of the blocks one and two native pixels to its left). The buffer is the host's binding.

type GradationState

type GradationState struct {
	Carry [GradationCarries]uint32
}

GradationState carries the blur's carries across a row's spans: Carry[i] is the pre-blur value of the pixel i+1 left of the span, the first 2*Step of them used. It starts zero at the row's left edge, so the pixels left of the row read as transparent, and the spans of a row are consumed left to right.

type LineWindow

type LineWindow struct {
	On     bool
	SX, EX int32
}

LineWindow is W0 or W1 resolved for a row: whether the row lies in the window's vertical range with a non-empty horizontal range, and that range in pixels, inclusive.

func ResolveLineWindow

func ResolveLineWindow(vram *compute.VDP2VRAM, p WindowParams, y int32, w uint32) LineWindow

ResolveLineWindow resolves window w (0 or 1) for field-line y. The vertical range comes from WPSY/WPEY in displayed-line space. The horizontal range comes from the row's line window table entry when LWTAU bit 15 enables the line window, else from WPSX/WPEX. A start past the end on either axis, or a row outside the vertical range, leaves the window off for the row.

type NBGCellState

type NBGCellState struct {
	HaveCell bool
	SxCell   int32
	SyCell   int32
	CharNum  uint32
	Palette  uint32
	Flags    uint32 // bit 0 hflip, 1 vflip, 2 special priority, 3 special CC
}

NBGCellState is the cell span's row state: the last cell whose pattern name was fetched and its decode, kept across the software schedule's span calls on a row so a run of dots in one cell decodes it once. It starts empty for each row (and for each GPU thread) and is an optimization only: a miss recomputes.

type NBGParams

type NBGParams struct {
	Width  int32 // row width in dots
	Y      int32 // row of the layer buffer
	DispY  int32 // displayed line (2 * field line + field under double-density interlace)
	SubRow int32 // sub-row of the native row at scale, 0 at native

	Screen ScreenParams

	MapOffset   uint32 // MPOFN field
	MapRegs     [4]uint32
	PlanePagesH int32
	PlanePagesV int32
	MosaicH     int32 // 0 off, else block width
	MosaicV     int32

	VCSCEnabled   bool
	VCSCTableAddr uint32
	VCSCStride    uint32

	LineScrollX   bool
	LineScrollY   bool
	LineZoomX     bool
	LineInterval  int32
	LineTableAddr uint32
	ScrollXFP     int32 // register scroll X, 11.8
	ScrollYBaseFP int32 // frame vertical counter base, 11.8
	IncXFP        int32 // register increments, 3.8
	IncYFP        int32

	// Row values from ResolveNBGLine.
	LineScrollXFP int32 // row scroll X (bitmap: wrapped to 11 bits)
	LineIncXFP    int32
	BaseSyFP      int32 // cell: row source Y before the per-column vertical cell scroll
	BmpSy         int32 // bitmap: source row after the height wrap

	// Row constants from ResolveNBGLine, so a span call starts with
	// loads rather than derivations (the software schedule calls a
	// span for every few dots).
	PlaneCellsH int32
	PlaneCellsV int32
	PlaneSizeH  int32 // plane size in dots
	PlaneSizeV  int32
}

NBGParams is a normal scroll screen's configuration for one row: the screen's dot params, the register-decoded map and scroll setup, the frame's vertical counter base, and the row values ResolveNBGLine derives from the line scroll table.

type PaletteParams

type PaletteParams struct {
	Mode uint32
}

PaletteParams carries the CRAM mode (RAMCTL bits 13:12) for a palette build.

type RBGParams

type RBGParams struct {
	Width     int32
	Y         int32 // row of the layer and line color buffers
	DispY     int32
	HcntShift uint32 // 1 in hi-res: two native dots share one rotation step; at scale each native dot's sub-dots step within it

	Screen  ScreenParams
	MosaicH int32

	RPMode    uint32  // RPMD: 0 A, 1 B, 2 A with coefficient switch to B, 3 window
	CRKTE     bool    // coefficients from CRAM
	CoefDotOK [4]bool // per VRAM bank: the bank may be read for per-dot coefficients
	Window    RPWindow
	Param     [2]RotParam // A, B
}

RBGParams is a rotation scroll screen's configuration for one row: the screen's dot params, the rotation parameter selection, and the two parameter sets as the row sees them.

type RPWindow

type RPWindow struct {
	En, Area, On [2]bool
	SX, EX       [2]int32
	LogicAnd     bool
}

RPWindow is the rotation parameter window resolved for the row: each of W0 and W1 as an enable, an area bit, and the row's X range (the row is outside when On is false), plus the logic bit. Parameter B shows in the active area (Sec 6).

type RotParam

type RotParam struct {
	Xsp, Ysp    int64 // row start in map space, .10 plus ScaleShift
	DX, DY      int64 // per-dot step, .10
	Xp, Yp      int64 // rotation center, .10 plus ScaleShift
	Kx, Ky      int64 // scale, .16
	DKAx        int64 // coefficient address step per dot, .10
	LineKAst    int64 // row coefficient address, .10 plus ScaleShift
	LineCoef    int64 // row coefficient value when per-dot reads are not allowed
	LineCoefLC  uint32
	LineCoefMSB bool
	CoefEn      bool
	CoefOneWord bool
	CoefMode    uint32 // 0 kx and ky, 1 kx, 2 ky, 3 Xp
	KLCE        bool   // line color from the coefficient
	KTAOF       uint32 // coefficient table offset bits
	ScreenOver  uint32 // 0 wrap, 1 pattern, 2 transparent, 3 force 512x512
	OVPNR       uint32 // screen-over pattern name
	MapOffset   uint32
	MapRegs     [16]uint32
	PlanePagesH int32 // page count used for the plane's page offset
	PlaneCellsH int32 // cells per plane
	PlaneCellsV int32
	TotalPixH   int32 // map size in dots
	TotalPixV   int32
	BitmapBase  uint32
}

RotParam is one rotation parameter set as the row sees it: the host has applied the per-line re-reads and stepping, so these are the row's values (VDP2 manual Sec 6.1). The row start, the center, and the row coefficient address carry the screen's ScaleShift more fraction bits than their native .10; the steps stay .10.

type ScreenParams

type ScreenParams struct {
	ColorMode  uint32 // 0 16-color, 1 256, 2 2048, 3 32K, 4 16.7M
	Char2x2    bool   // 16x16 characters
	PNWord1    bool   // 1-word pattern names
	AuxMode1   bool   // auxiliary mode 1 pattern names
	PNCN       uint32 // pattern name control register
	Priority   uint32
	CRAMOffset uint32
	CRAMMode   uint32
	TranspOff  bool
	SFPRMD     uint32 // special priority mode
	SFCCMD     uint32 // special color calculation mode
	SFCode     uint32 // the screen's special function code
	ScreenCC   bool   // CCCTL enable for the screen

	// ScaleShift is log2 of the render scale N (N = 1 << ScaleShift),
	// 0 at native: a source position is the native fixed-point value
	// carried at ScaleShift more fraction bits, so the spans extract
	// its integer part with a shift that much wider.
	ScaleShift uint32

	Bitmap        bool
	BmpWidth      int32
	BmpHeight     int32
	BmpPalette    uint32
	BmpSpecialPri bool
	BmpSpecialCC  bool

	// Row constants from prepareScreenRow, so a span call starts with
	// loads rather than derivations (the software schedule calls a
	// span for every few dots).
	Plain        bool   // no special priority or color calculation mode
	PlainBase    uint32 // priority and screen CC bits for plain dots
	SubCellScale uint32 // character units between a 2x2 character's sub-cells
	EntrySize    uint32 // pattern name entry bytes
	CharPx       int32  // character size in dots
	MapDim       int32  // cells per page side
	PageBoundary uint32 // page bytes
}

ScreenParams is what a scroll screen's dots share whichever screen draws them: the character and pattern name format, the color format, the priority and color calculation rules, the bitmap form, and the row constants prepareScreenRow derives. A normal and a rotation screen's row params each hold one, and the spans and the dot functions below read the screen through it.

type SpriteDecode

type SpriteDecode struct {
	Type    uint32
	Mixed   bool // SPCLMD: MSB-set pixels are RGB
	SPWinEn bool // SPWINEN: the MSB is the sprite window bit (types 2-7)

	// Palette-format field extraction.
	PRShift, CCShift uint32
	PRMask, CCMask   uint32
	DCMask, MSBBit   uint32
	CRAMOff          uint32 // sprite CRAM offset (SPCAOS) in entries

	RGBPri uint32    // priority of an RGB pixel: PRISA low field
	Pri    [8]uint32 // priority per PR value (PRISA-D fields)
	Ratio  [8]uint32 // color calculation ratio per CC value (CCRSA-D)

	// Color calculation condition: SPCCCS/SPCCN against the resolved
	// priority (CCByPri) or the dot color MSB (CCMode3), both false
	// when CCCTL disables sprite color calculation.
	CCMode3 bool
	CCByPri [8]bool

	// Shadow rules (Sec 14).
	MSBShadow bool // MSB shadow exists: types 2-7 outside mixed mode
	TPSDSL    bool // SDCTL TPSDSL: MSB transparent shadow projects
}

SpriteDecode is a row's sprite decode: everything the per-pixel sprite path derives from registers, resolved once by BuildSpriteDecode. Per pixel only the framebuffer value varies.

func BuildSpriteDecode

func BuildSpriteDecode(r SpriteRegs) SpriteDecode

BuildSpriteDecode resolves the sprite decode from the registers.

func (*SpriteDecode) CCEnabled

func (d *SpriteDecode) CCEnabled(priority uint32, colorMSB bool) bool

CCEnabled evaluates the SPCCCS condition for a sprite pixel with the resolved priority and dot color MSB.

func (*SpriteDecode) Decode

func (d *SpriteDecode) Decode(pal *compute.Palette, cramMode uint32, pixel uint32) (priority, ccBits uint32, colorMSB bool, rgb uint32)

Decode resolves a sprite pixel to its priority, color calculation bits, dot color MSB, and decoded color. A zero pixel is transparent (priority 0).

When the sprite window is enabled (SPWINEN) the MSB of sprite types 2-7 is the sprite-window bit (Sec 8.1, Sprite Window), so a pixel whose low 15 bits are all zero is a window mark over a transparent dot (Table 4.3, palette dot color 0) and not a dot of its own: priority 0 marks it transparent so lower layers show through. This holds in mixed mode (SPCLMD=1) too, where an MSB-set pixel is otherwise RGB and such a pixel would read as opaque RGB black; hardware honors it even though the manual discourages pairing SPWINEN with SPCLMD=1.

func (*SpriteDecode) Shadow

func (d *SpriteDecode) Shadow(pixel uint32) uint32

Shadow classifies a sprite pixel's shadow type. Normal shadow (Figure 14.3) is judged from the dot color field (Figure 9.1): every bit set except the LSB. MSB shadow applies only to types 2-7 with the MSB set while the sprite window is off (MSBShadow). Normal shadow takes precedence over MSB shadow per Sec 14.

In SPCLMD=1 mixed mode bit 15 is the format discriminator (1=RGB, 0=palette), not the shadow bit: per Sec 9.1 an RGB pixel's shadow bits are considered 0, so it never shadows, while a palette pixel still matches the normal shadow pattern (the mixed-mode "MSB as 0" rule suppresses only the MSB shadow bit, not the DC field).

MSB transparent shadow (bits 14:0 zero) is always a transparent dot (Sec 14.1, Figure 14.4); TPSDSL only selects whether it projects a shadow on the screens below. With TPSDSL=0 the shadow is nullified but the dot must not become a displayable palette-0 color.

type SpriteRegs

type SpriteRegs struct {
	SPCTL  uint32
	CRAOFB uint32
	PRIS   [4]uint32 // PRISA-D
	CCRS   [4]uint32 // CCRSA-D
	CCCTL  uint32
	SDCTL  uint32
}

SpriteRegs carries the registers the sprite decode derives from.

type SpriteRow

type SpriteRow struct {
	Mode    uint32
	Width   int32
	Height  int32
	Row     uint32
	Halve   uint32
	Shift   uint32
	Doubled uint32
	Parity  uint32
	Is8bpp  bool
	BaseX   int64
	BaseY   int64
	DX      int64
	DY      int64
}

SpriteRow describes the VDP1 frame buffer read for one row: the mode, the buffer geometry, the row's byte offset for the direct reads, whether hi-res halves the column (a 512-wide 16-bit buffer under 640 columns), and for the rotated read the coordinate at column 0 and its per-column step from rotation parameter A (VDP1 manual Sec 1.2; rotation is prohibited in hi-res). The coordinate is .10 at native and carried at 10 + Shift fraction bits at scale, Shift being the scale shift, so the shift down by 10 lands in the scaled frame buffer. The step stays native and is applied per scaled column. Height is the buffer's physical rows at the scale. Doubled is 1 when the buffer holds every row of the doubled Y range under double interlace, physical row r at doubled rows 2r and 2r + 1: the rotated read then takes doubled row 2r + Parity of the physical row r its coordinate lands on, with the scaled sub-row kept.

type VRAMPages

type VRAMPages struct {
	Store *compute.PageStore
	Table *compute.PageTable
}

VRAMPages is a submission's staged VDP2 VRAM pages: the page store, a whole page per slot in memory order, and the page table, the destination page number of each slot.

type WindowParams

type WindowParams struct {
	WPSX, WPSY, WPEX, WPEY [2]uint32
	LWTAU, LWTAL           [2]uint32
	HiRes                  bool   // 640 or 704 dots: X registers hold H9:H0
	LSMD3                  bool   // double-density interlace
	Field                  uint32 // field being rendered under LSMD3
	Intl2                  bool   // single-density interlace: per-line tables are indexed by y/2
}

WindowParams carries the window registers and the display state they are interpreted under (VDP2 manual Sec 8.1). Each of the two windows has a start and end X and Y register and a line window table address; W1 uses index 1.

type WindowRun

type WindowRun struct {
	X0, X1 int32
	W0, W1 bool // the run lies inside the window
}

WindowRun is a horizontal run [X0, X1) of a row over which the W0 and W1 inside states are constant.

type WindowRuns

type WindowRuns struct {
	N    int32
	Runs [5]WindowRun
}

WindowRuns is a row split into runs at the window edges: at most five, since two windows contribute at most four edges.

type WindowState

type WindowState struct {
	Partial  bool
	SWEn     bool
	SWArea   bool
	LogicAnd bool
}

WindowState is one window control byte evaluated over one run. Partial is the combination of the enabled W0 and W1 terms, or the operator's identity when neither is enabled (with every enable off the active area is the whole screen under AND and nothing under OR, Sec 8.1), and the sprite window flags say how the per-pixel sprite term joins it.

func WindowRunState

func WindowRunState(wctl uint32, w0In, w1In bool) WindowState

WindowRunState evaluates control byte wctl (Sec 8.1 layout: W0A=0x01, W0E=0x02, W1A=0x04, W1E=0x08, SWA=0x10, SWE=0x20, LOG=0x80; area bits 0=inside, 1=outside; LOG 0=OR, 1=AND) over a run where the W0 and W1 inside states are w0In and w1In.

func (WindowState) Active

func (m WindowState) Active(swInside bool) bool

Active returns whether a pixel whose sprite window bit is swInside lies in the window's active area. For a layer window the active area is the masked area; for the color calculation window it is where color calculation is suppressed (Sec 8.2).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL