core

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: GPL-3.0 Imports: 12 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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus struct {

	// ReadTrace, when non-nil, is called for every Read8/Read16/Read32.
	// Used for narrow-region debug tracing (e.g. discovering what a
	// game reads from BUP state buffers after a BUP slot returns).
	// Implementations should filter by address — the callback fires
	// for ALL reads so it's expensive when enabled.
	ReadTrace func(addr uint32, size int, value uint32)
	// contains filtered or unexported fields
}

Bus implements the Saturn system bus address decoder. It maps the SH-2's 32-bit address space to hardware regions. Peripherals not yet implemented return 0 on read and ignore writes.

func NewBus

func NewBus(scu *SCU, smpc *SMPC, vdp1 *VDP1, vdp2 *VDP2, scsp *SCSP, cdblock *CDBlock) *Bus

NewBus creates a new Saturn system bus with RAM allocated and the given subsystem references stored for address dispatch. The caller (typically NewEmulator) constructs the subsystems and is responsible for closing the SCU↔Bus loop via scu.SetBus(bus) and the SCSP↔CDBlock wiring via scsp.SetCDAudioSource(cdblock).

func (*Bus) AccessCycles

func (b *Bus) AccessCycles(addr uint32, size uint32) uint32

AccessCycles returns the CPU state count consumed by a single read transaction of the given size (bytes: 1/2/4, or 16 for a burst) at addr - a table lookup. Used by the SH-2 DMAC to accumulate per-unit bus-occupation stall. The 1 MB table granularity collapses the few sub-megabyte region tails to their block's cost.

func (*Bus) DMAWrite8 added in v0.3.0

func (b *Bus) DMAWrite8(addr uint32, val uint8)

DMAWrite8 performs a bus-master (SCU-DMA) byte write. A single byte is a sub-word B-Bus access whose burst cost rounds to zero, so no VDP1 draw stall is charged; the method exists so the DMA payload path uses one consistent bus-master write API.

func (*Bus) DMAWrite32 added in v0.3.0

func (b *Bus) DMAWrite32(addr uint32, val uint32)

DMAWrite32 performs a bus-master (SCU-DMA) 32-bit write. It mirrors Write32 but, like SH2Write32 for the SH-2, charges its access-class VDP1 draw contention for a B-Bus write: a continuous burst, so the 16-bit port costs vdp1DMABurstStallPerWord per word, two for a longword.

func (*Bus) GetBackupRAM

func (b *Bus) GetBackupRAM() []byte

GetBackupRAM returns a copy of the 32 KB internal backup RAM. The slice holds only the odd-byte storage as the bus presents it; even bytes always read back as 0xFF and are not stored.

func (*Bus) MINITWritten

func (b *Bus) MINITWritten() bool

MINITWritten returns whether MINIT was written since the last check and clears the flag.

func (*Bus) Read8

func (b *Bus) Read8(addr uint32) uint8

Read8 reads a byte from the given address, claiming the address's bus area for the duration of the access.

func (*Bus) Read16

func (b *Bus) Read16(addr uint32) uint16

Read16 reads a big-endian 16-bit value from the given address, claiming the address's bus area for the duration of the access.

func (*Bus) Read32

func (b *Bus) Read32(addr uint32) uint32

Read32 reads a big-endian 32-bit value from the given address, claiming the address's bus area for the duration of the access.

func (*Bus) ReadCacheLine added in v0.3.0

func (b *Bus) ReadCacheLine(base uint32, dst *[16]byte)

ReadCacheLine fills dst from the 16-byte-aligned line at base, holding the line's bus area across all four longwords. Per SH7604 Sec 8.4.1 a cache line fill reads four longwords consecutively in one bus tenure (an SDRAM burst for Work RAM-H, Sec 7.5.3-7.5.4), so another bus master cannot interleave a write between them - claiming the area once reproduces that, where four separate Read32 calls would release the bus three times mid-fill and admit a torn line.

func (*Bus) ReadRMW8 added in v0.3.0

func (b *Bus) ReadRMW8(addr uint32) uint8

ReadRMW8 begins a TAS.B read-modify-write: it claims the address's bus area and returns with the claim still held. WriteRMW8 completes the sequence and releases the claim. Per SH7604 Sec 7.10 the bus is not released between the read and write cycles of TAS.

func (*Bus) SH2FillLine added in v0.3.0

func (b *Bus) SH2FillLine(base uint32, dst *[16]byte, frameCyc int64, slave bool) uint32

func (*Bus) SH2RMWRead added in v0.3.0

func (b *Bus) SH2RMWRead(addr uint32, frameCyc int64, slave bool) (uint8, uint32)

SH2RMWRead begins a TAS.B: it charges the read access (cost + slave + wait) and holds the area. SH2RMWWrite completes it, re-extending busyUntil to cover the write so the peer waits for the whole RMW, and charges only the write cost (the slave handshake and contention wait were already paid on the read).

func (*Bus) SH2RMWWrite added in v0.3.0

func (b *Bus) SH2RMWWrite(addr uint32, val uint8, frameCyc int64) uint32

func (*Bus) SH2Read8 added in v0.3.0

func (b *Bus) SH2Read8(addr uint32, frameCyc int64, slave bool) (uint8, uint32)

func (*Bus) SH2Read16 added in v0.3.0

func (b *Bus) SH2Read16(addr uint32, frameCyc int64, slave bool) (uint16, uint32)

func (*Bus) SH2Read32 added in v0.3.0

func (b *Bus) SH2Read32(addr uint32, frameCyc int64, slave bool) (uint32, uint32)

The SH2* methods are the SH-2 instruction-execution access path: a data access and chargeAccess folded into one bus tenure, returning the stall the CPU adds to busStall (reads also return the value). frameCyc is the accessing CPU's frame-relative cycle; slave selects the arbitration penalty. Width is in the method name, matching the plain Read*/Write* in bus.go, which are the non-timed path (on-chip DMAC, HLE, SCU).

func (*Bus) SH2Write8 added in v0.3.0

func (b *Bus) SH2Write8(addr uint32, val uint8, frameCyc int64, slave bool) uint32

func (*Bus) SH2Write16 added in v0.3.0

func (b *Bus) SH2Write16(addr uint32, val uint16, frameCyc int64, slave bool) uint32

func (*Bus) SH2Write32 added in v0.3.0

func (b *Bus) SH2Write32(addr uint32, val uint32, frameCyc int64, slave bool) uint32

func (*Bus) SINITWritten

func (b *Bus) SINITWritten() bool

SINITWritten returns whether SINIT was written since the last check and clears the flag.

func (*Bus) SetBIOS

func (b *Bus) SetBIOS(data []byte) error

SetBIOS loads BIOS ROM data. The data must be exactly 512 KB.

func (*Bus) SetBackupRAM

func (b *Bus) SetBackupRAM(data []byte)

SetBackupRAM loads previously persisted internal backup RAM. Data of any size other than the 32 KB backup region is ignored so a corrupt or stale save cannot desynchronize the odd-byte address decode.

func (*Bus) Write8

func (b *Bus) Write8(addr uint32, val uint8)

Write8 writes a byte to the given address, claiming the address's bus area for the duration of the access.

func (*Bus) Write16

func (b *Bus) Write16(addr uint32, val uint16)

Write16 writes a big-endian 16-bit value to the given address, claiming the address's bus area for the duration of the access.

func (*Bus) Write32

func (b *Bus) Write32(addr uint32, val uint32)

Write32 writes a big-endian 32-bit value to the given address, claiming the address's bus area for the duration of the access.

func (*Bus) WriteAccessCycles added in v0.3.0

func (b *Bus) WriteAccessCycles(addr uint32, size uint32) uint32

WriteAccessCycles is the write-direction companion to AccessCycles.

func (*Bus) WriteRMW8 added in v0.3.0

func (b *Bus) WriteRMW8(addr uint32, val uint8)

WriteRMW8 completes a TAS.B read-modify-write begun by ReadRMW8, writing the value and releasing the bus-area claim.

type BusReadWriter

type BusReadWriter interface {
	Read8(addr uint32) uint8
	Read32(addr uint32) uint32
	DMAWrite8(addr uint32, val uint8)
	DMAWrite32(addr uint32, val uint32)
}

BusReadWriter provides the read/write interface needed by SCU DMA.

type CDAudioSource

type CDAudioSource interface {
	PopAudioSample() (left, right int16, valid bool)
	DrainAudio()
}

CDAudioSource is the interface SCSP uses to pull CD-DA stereo samples for the EXTS external audio input. The CD block satisfies this interface. PopAudioSample returns valid=false when no sample is available; the SCSP treats that as silent for the current sample tick.

type CDBlock

type CDBlock struct {
	// contains filtered or unexported fields
}

CDBlock implements the Saturn CD Block subsystem. It handles command/response communication with the SH-2 via registers at A-Bus CS2 offset $90000.

func NewCDBlock

func NewCDBlock(scu *SCU) *CDBlock

NewCDBlock creates a new CD Block in power-on state. On real hardware, the CD Block (SH-1) autonomously runs its init sequence (~109ms). During this time it shows the "CDBLOCK" signature in the result registers. After init completes, it transitions to Busy+PERI status (with disc) or NoDisc+PERI (without disc).

func (*CDBlock) DrainAudio

func (cb *CDBlock) DrainAudio()

DrainAudio empties the audio queue. Called by SCSP on reset transitions and by the CD block itself on cmdInitCDSystem and SetDisc.

func (*CDBlock) ExecuteCommand

func (cb *CDBlock) ExecuteCommand()

ExecuteCommand dispatches the command in CR1 bits 15-8.

func (*CDBlock) LoadFileByFID added in v0.2.0

func (cb *CDBlock) LoadFileByFID(fid uint32, dst []byte) (int, error)

LoadFileByFID synchronously copies the disc file at the given CD-block file ID into dst. Mirrors the real-BIOS sub_2F48 path (ChangeDirectory root + GetFileInfo + ReadFile) without running the CD-block's async state machine: parses the file system if needed, looks up the file, and reads its sectors directly. Returns the number of bytes written to dst.

Used by the HLE BIOS sub_1C90 service so the BIOS-layer load goes through the CD-block's own file table (single source of truth for ISO9660 parsing and file-ID assignment) instead of reaching past it to the raw disc.

func (*CDBlock) MpegFrameRGB added in v0.3.1

func (cb *CDBlock) MpegFrameRGB() (rgb []uint32, w, h int, ok bool)

MpegFrameRGB returns the newest decoded picture, read in place. The returned slice is the consumer-owned slot: valid until the next call, never written by the producer while owned. ok is false when nothing has been decoded or the host has the display switched off ($A0). Called by VDP2 from the render walker.

func (*CDBlock) PopAudioSample

func (cb *CDBlock) PopAudioSample() (left, right int16, valid bool)

PopAudioSample returns the next stereo pair from the audio queue. Returns valid=false when the queue is empty (caller treats as silence). Implements the CDAudioSource interface in core/scsp.go.

func (*CDBlock) QueueCommand

func (cb *CDBlock) QueueCommand()

QueueCommand executes the command immediately. Called from the bus layer when CR4 is written.

func (*CDBlock) Read

func (cb *CDBlock) Read(offset uint32) uint16

Read returns the 16-bit value at the given register offset.

func (*CDBlock) ReadDataTRNS

func (cb *CDBlock) ReadDataTRNS() uint16

ReadDataTRNS returns the next 16-bit word from the data transfer buffer. Called once per word read by the bus layer, not per byte.

func (*CDBlock) ReadDataTRNS32

func (cb *CDBlock) ReadDataTRNS32() uint32

ReadDataTRNS32 returns two consecutive 16-bit FIFO words as a 32-bit value.

func (*CDBlock) RecalcTiming

func (cb *CDBlock) RecalcTiming(systemCyclesPerSecond, fieldRateHz uint32)

RecalcTiming refreshes the CD block's cycle thresholds from the emulator's current system clock rate and display field rate. Called by Emulator.recalcTiming at construction and whenever VDP2 mode changes, so CD pacing tracks the actual system clock rate (NTSC/PAL, 320/352).

fieldRateHz (60 NTSC, 50 PAL) paces the MPEG card's VSYNC operation-interval counter at the display field rate.

All physical CD events (sector reads, SCDQ frames, periodic status, boot/busy delays) are scaled from the new rate. In-flight countdowns (bootDelay, busyDelay, scdqCounter, periCounter, sectorAccum, seekAccum) are intentionally left untouched: a mode change mid-flight would otherwise warp pending events forward or backward, which is worse than letting them complete on the prior rate. New events use the refreshed values.

func (*CDBlock) SetDisc

func (cb *CDBlock) SetDisc(d DiscReader)

SetDisc attaches a disc reader. Pass nil to eject. With a disc present the drive is immediately ready (Pause) since emulated reads are instant - no spin-up time needed.

func (*CDBlock) TickSystemCycles

func (cb *CDBlock) TickSystemCycles(cycles uint32)

TickSystemCycles advances the CD Block by the given number of system cycles. Processes all internal timers: boot delay, command delay, BUSY transitions, seek, sector read pacing, SCDQ and periodic status.

func (*CDBlock) Write

func (cb *CDBlock) Write(offset uint32, val uint16)

Write sets the 16-bit value at the given register offset.

func (*CDBlock) Write32

func (cb *CDBlock) Write32(offset uint32, val uint32)

Write32 handles a 32-bit write as two consecutive 16-bit writes.

type DiscReader

type DiscReader interface {
	ReadSector(lba int) ([]byte, error)
	NumTracks() int
	Track(i int) (number int, typ string, frames int, pregap int, startLBA int, control uint8)
	// NumTrackIndexes / TrackIndex expose the per-track index map (index
	// numbers >= 1, absolute LBA). Index 0 (pregap) is implied for any FAD
	// below the first entry. n is a 0-based ordinal into the exposed list.
	NumTrackIndexes(i int) int
	TrackIndex(i, n int) (indexNumber int, lba int)
}

DiscReader is the disc input to the emulator. It is primitive-only (no named aggregate in any signature) so a concrete reader - the streaming CHD reader supplied by the host - satisfies it structurally without this package and the host's disc/UI packages sharing a type. The track TOC is exposed as indexed scalar accessors; the CD block materializes it into []TrackInfo once via discTOC.

type Emulator

type Emulator struct {
	// contains filtered or unexported fields
}

Emulator ties together all Saturn components and runs one frame at a time.

func NewEmulator

func NewEmulator() *Emulator

NewEmulator creates a Saturn emulator with all components wired together. Call SetBIOS on the bus before running.

func (*Emulator) Close

func (e *Emulator) Close()

Close stops the frame workers spawned by Start. It must not run concurrently with RunFrame, and RunFrame must not be called after Close (its job-channel send would panic). Idempotent.

func (*Emulator) DumpMemory

func (e *Emulator) DumpMemory() MemoryDump

DumpMemory returns a deep-copy snapshot of every memory region. Safe to call between frames from the emulation goroutine.

func (*Emulator) GetActiveHeight

func (e *Emulator) GetActiveHeight() int

GetActiveHeight returns the current active display height.

func (*Emulator) GetAudioSamples

func (e *Emulator) GetAudioSamples() []int16

GetAudioSamples returns the audio sample buffer for the current frame.

func (*Emulator) GetFramebuffer

func (e *Emulator) GetFramebuffer() []byte

GetFramebuffer returns raw RGBA pixel data for the most recently completed frame. RunFrame waits for the VDP worker's frame walk before returning, so the buffer is complete and the worker parked while the host reads it.

func (*Emulator) GetFramebufferStride

func (e *Emulator) GetFramebufferStride() int

GetFramebufferStride returns the stride (bytes per row) of the framebuffer.

func (*Emulator) GetSRAM

func (e *Emulator) GetSRAM() []byte

GetSRAM returns a copy of the internal backup RAM.

func (*Emulator) GetTiming

func (e *Emulator) GetTiming() Timing

GetTiming returns the frame timing derived from VDP2 state.

func (*Emulator) PixelAspectRatio

func (e *Emulator) PixelAspectRatio() float64

PixelAspectRatio returns the pixel aspect ratio for the current video mode. The Saturn active picture is a fixed physical rectangle; the horizontal dot count (320/352/640/704) and vertical line count (224/240/256, doubled under double-density interlace) only change sampling density, not the displayed shape. So the pixel aspect is derived to keep the displayed picture aspect constant at the Saturn's 4:3 active area across every resolution and interlace mode: (W/H) * PAR == 4/3. Computed on demand so it always matches the currently reported framebuffer dimensions.

func (*Emulator) ReadMemory added in v0.2.0

func (e *Emulator) ReadMemory(addr uint32, buf []byte) uint32

ReadMemory reads from the RetroAchievements flat Saturn address space into buf and returns the number of bytes read. The flat layout matches the rcheevos Saturn memory map: 0x000000-0x0FFFFF is Work RAM-L (hardware 0x00200000) and 0x100000-0x1FFFFF is Work RAM-H (hardware 0x06000000). Reads stop at the first address outside that range.

func (*Emulator) RunFrame

func (e *Emulator) RunFrame()

RunFrame executes one complete frame of emulation.

func (*Emulator) SetBIOS

func (e *Emulator) SetBIOS(key string, data []byte) error

SetBIOS loads a BIOS image by key name. For main_bios, also sets the master SH-2 entry point from the reset vectors.

func (*Emulator) SetDisc

func (e *Emulator) SetDisc(d DiscReader)

SetDisc attaches a disc reader to the CD Block, caches the disc's IP image for later HLE-BIOS boot, and auto-detects the disc's region to set the SMPC area code and VDP2 PAL bit. The region step ensures BIOS and SYS_ARE region checks pass regardless of which BIOS region is loaded.

func (*Emulator) SetInput

func (e *Emulator) SetInput(player int, buttons uint32)

SetInput maps active-high button bits to SMPC active-low pad data.

func (*Emulator) SetOption added in v0.2.0

func (e *Emulator) SetOption(key string, value string)

SetOption applies a core option change identified by key. Values are stored and applied when Start() is called.

func (*Emulator) SetSH2Trace

func (e *Emulator) SetSH2Trace(master, slave func(pc uint32, op uint16))

SetSH2Trace installs per-instruction trace callbacks on the master and slave SH-2. Pass nil to clear. Must be called while the cores are not executing (between frames) so the assignment cannot race the per-instruction call site.

func (*Emulator) SetSRAM

func (e *Emulator) SetSRAM(data []byte)

SetSRAM loads previously persisted internal backup RAM.

func (*Emulator) Start

func (e *Emulator) Start() error

Start prepares the emulator for the first RunFrame. When no real BIOS was loaded via SetBIOS, it constructs an HLEBIOS in place and boots it from the cached disc IP image. The HLEBIOS instance is not retained on the emulator: it stays alive only through the closures it wires into master.HLEHook / slave.HLEHook, and is otherwise invisible to the rest of the emulator. Real-BIOS boots construct nothing and leave the CPU hooks nil.

func (*Emulator) VDP1SwapCount

func (e *Emulator) VDP1SwapCount() uint64

VDP1SwapCount returns the monotonic count of VDP1 FB swaps since reset. The host UI uses the delta between samples to derive a "game fps" value distinct from RunFrame fps - games can request fewer swaps than the emulator runs frames (e.g. a 30 fps game on a 60 fps emulator), and the swap rate is what the player sees.

type HLEBIOS added in v0.2.0

type HLEBIOS struct {
	// contains filtered or unexported fields
}

HLEBIOS replaces the real Saturn BIOS for boots that don't have a licensed BIOS image attached. It owns the SH-2 magic-address hook table and the Work-RAM-H data-table state the BIOS would normally publish.

Lifecycle: constructed locally in Emulator.Start when !hasBIOS, Boot is called once, and the struct is reached thereafter only through the closures held in CPU.HLEHook. The Emulator keeps no direct reference; the closure capture keeps the struct alive.

func NewHLEBIOS added in v0.2.0

func NewHLEBIOS(bus *Bus, master, slave *sh2.CPU) *HLEBIOS

NewHLEBIOS constructs an HLEBIOS bound to a specific bus and the master/slave SH-2 pair. Boot must be called to actually publish the dispatch table and wire the CPU hooks.

func (*HLEBIOS) Boot added in v0.2.0

func (h *HLEBIOS) Boot(ip []byte) error

Boot performs the minimum-state High-Level Emulation of the Saturn BIOS startup against the provided IP image:

  1. Validates the bytes form a Saturn game image by checking the System ID hardware identifier.
  2. Copies the IP into Work-RAM-H at $06002000-$0600A000.
  3. Populates every BIOS-set Work-RAM-H data table that disc/SDK code expects to find pre-initialized.
  4. Registers every SYS_*/PER_*/BUP_* service hook.
  5. Wires CPU.HLEHook on master and slave.
  6. Sets master SH-2 PC=$06002100 (IP+$100, SYS_SEC entry) and R15=$06002000 (top of IP window).

Returns an error if no IP is provided or the bytes don't look like a Saturn game (HLE has no CD-player path; only a real BIOS can boot non-game discs).

type MemoryDump

type MemoryDump struct {
	BIOS          []byte // 512 KB system BIOS
	WRAMH         []byte // 1 MB Work RAM-H
	WRAML         []byte // 1 MB Work RAM-L
	BackupRAM     []byte // 32 KB internal backup RAM
	ExtRAM        []byte // 4 MB Extended RAM Cartridge
	VDP1VRAM      []byte // 512 KB VDP1 command/character VRAM
	VDP1DrawFB    []byte // 256 KB VDP1 draw framebuffer
	VDP1DisplayFB []byte // 256 KB VDP1 display framebuffer
	VDP2VRAM      []byte // 512 KB VDP2 VRAM
	VDP2CRAM      []byte // 4 KB VDP2 color RAM
	VDP2Regs      []byte // 288 B - 144 VDP2 registers, big-endian at hardware offsets
	VDP1Regs      []byte // 24 B - VDP1 register block (0x00-0x16), internal written values
	VDP1Shadow    []byte // 10 B - VDP1 deferred/pending latch values (no hardware address)
	SoundRAM      []byte // 512 KB SCSP sound RAM

	SCURegs     []byte // SCU register space 0x00-0xC8, big-endian longwords at hw offsets
	SCUInternal []byte // SCU emulation-internal DMA/IRQ/timer state (no hardware address)
	SCUDSP      []byte // SCU DSP program RAM, data RAM, and control/flag state

	SCSPRegs   []byte // SCSP register file, flat big-endian, maps to hardware offsets
	SCSPSlots  []byte // SCSP per-slot runtime playback/envelope state (32 slots)
	SCSPDSP    []byte // SCSP DSP coefficient/program/work state
	SCSPTimers []byte // SCSP timer counters and prescalers (not register-readable)

	SH2MasterRegs []byte // Master SH-2 programmer registers + cycles + halted
	SH2SlaveRegs  []byte // Slave SH-2 programmer registers + cycles + halted

	SH2MasterIRQ []byte // Master SH-2 IRL input + INTC registers
	SH2SlaveIRQ  []byte // Slave SH-2 IRL input + INTC registers

	SMPCState    []byte // SMPC internal command/enable/RTC state
	Coordination []byte // cross-goroutine boundary invariants (counters, FRT-capture flags, bus locks)

	M68KState []byte // MC68EC000 sound CPU state (m68k.CPU.Serialize)
}

MemoryDump is a point-in-time snapshot of every emulator memory region for debug inspection. Each field is an independent copy of the underlying bytes, safe to write to disk while the emulator continues running.

BIOS is included so a dump captures the exact ROM image that was active. Disc image is intentionally excluded - discs are external and identified by hash, not state.

type SCSP

type SCSP struct {
	// contains filtered or unexported fields
}

SCSP implements the Saturn Custom Sound Processor.

func NewSCSP

func NewSCSP(scu *SCU) *SCSP

NewSCSP creates a new SCSP with sound RAM, registers, and MC68EC000. The 68K is held in reset and not stepped until SMPC SNDON.

func (*SCSP) InReset

func (s *SCSP) InReset() bool

InReset returns whether the 68K sound CPU is held in reset.

func (*SCSP) InstallSoundDriverStub added in v0.3.0

func (s *SCSP) InstallSoundDriverStub()

InstallSoundDriverStub writes a minimal MC68EC000 program to sound RAM: valid reset vectors (SSP, PC) pointing at an idle loop. On hardware the BIOS leaves its own sound driver resident in sound RAM during boot; boot paths that skip the BIOS sound init (HLE, fast boot) call this so a game that resets the SCSP (SNDOFF/SNDON) before uploading its own driver runs a harmless idle loop instead of uninitialized RAM. The game's own driver overwrites it when loaded.

func (*SCSP) M68KSerialize added in v0.2.0

func (s *SCSP) M68KSerialize() []byte

M68KSerialize returns the sound CPU's full register/state block as produced by m68k.CPU.Serialize (D0-D7, A0-A7, PC, SR, USP, SSP, prevPC, etc.). Used by the memory dump to inspect 68K state.

func (*SCSP) MixBuffer

func (s *SCSP) MixBuffer() []int16

MixBuffer returns the interleaved stereo audio samples produced this frame.

func (*SCSP) Read

func (s *SCSP) Read(offset uint32) uint16

Read returns the 16-bit register at the given byte offset from 0x100000.

func (*SCSP) ReadRAM

func (s *SCSP) ReadRAM(addr uint32) uint8

ReadRAM reads a byte from sound RAM.

func (*SCSP) ReadRAM16

func (s *SCSP) ReadRAM16(addr uint32) uint16

ReadRAM16 reads a big-endian 16-bit value from sound RAM.

func (*SCSP) ReadRAM32

func (s *SCSP) ReadRAM32(addr uint32) uint32

ReadRAM32 reads a big-endian 32-bit value from sound RAM.

func (*SCSP) RequestReset added in v0.3.0

func (s *SCSP) RequestReset()

RequestReset flags a deferred SCSP reset, applied at the next RunFrame boundary. Used by the HLE SYS_CHGSYSCK service to reproduce the SMPC CKCHG hardware reset (which silences the sound generator).

func (*SCSP) Reset

func (s *SCSP) Reset()

Reset clears all SCSP registers, slot state, timers, and DSP to power-on defaults. Sound RAM is NOT cleared (only on power-up). Called during CKCHG/SYSRES system reset.

func (*SCSP) ResetMixBuffer

func (s *SCSP) ResetMixBuffer(capacity int)

ResetMixBuffer prepares the mix buffer for a new frame.

func (*SCSP) SetCDAudioSource

func (s *SCSP) SetCDAudioSource(src CDAudioSource)

SetCDAudioSource wires the CD block as the source for EXTS (external audio input). Called once at construction by the bus.

func (*SCSP) SetInReset

func (s *SCSP) SetInReset(reset bool)

SetInReset sets the 68K reset state. When transitioning from reset to active, the 68K is reset to fetch its initial vectors.

func (*SCSP) StartFrame

func (s *SCSP) StartFrame(systemCyclesPerFrame, samplesPerFrame, m68kCyclesPerFrame uint32)

StartFrame initializes per-frame target counters. Emulator calls this at the start of each RunFrame with the per-frame system-cycle budget and the target sample and m68k cycle counts for the current region. Subsequent TickSystemCycles calls distribute these totals across the segments such that the per-frame totals land exactly.

func (*SCSP) TakePendingReset added in v0.3.0

func (s *SCSP) TakePendingReset() bool

TakePendingReset clears and returns the deferred-reset request.

func (*SCSP) TickSamples

func (s *SCSP) TickSamples(samples int)

TickSamples advances the SCSP by the given number of 44.1 KHz sample ticks, updating timers, slot state, DSP, and mixer output. Does NOT drain the sound CPU; use TickSystemCycles for the full emulator-facing interface. This entry point is exposed for tests that drive SCSP by sample count directly.

func (*SCSP) TickSystemCycles

func (s *SCSP) TickSystemCycles(cycles uint32)

TickSystemCycles advances the SCSP by the given number of system cycles. Computes the cumulative expected sample and m68k counts based on system-cycles-elapsed-this-frame versus the frame target, and emits only the delta since the previous call. This produces exact per-frame totals (set by StartFrame) with zero fractional drift, and a smooth per-call distribution independent of how the emulator chooses to slice the frame into segments.

func (*SCSP) Write

func (s *SCSP) Write(offset uint32, val uint16)

Write stores a 16-bit value at the given byte offset from 0x100000. Certain registers have side-effects on write.

func (*SCSP) WriteRAM

func (s *SCSP) WriteRAM(addr uint32, val uint8)

WriteRAM writes a byte to sound RAM.

func (*SCSP) WriteRAM16

func (s *SCSP) WriteRAM16(addr uint32, val uint16)

WriteRAM16 writes a big-endian 16-bit value to sound RAM.

func (*SCSP) WriteRAM32

func (s *SCSP) WriteRAM32(addr uint32, val uint32)

WriteRAM32 writes a big-endian 32-bit value to sound RAM.

type SCU

type SCU struct {
	// contains filtered or unexported fields
}

SCU implements the System Control Unit for the Sega Saturn. It handles DMA transfers, interrupt masking, and routing to the master SH-2.

func NewSCU

func NewSCU() *SCU

NewSCU allocates a new SCU with correct initial state.

func (*SCU) AcknowledgeInterrupt

func (s *SCU) AcknowledgeInterrupt(vec uint16)

AcknowledgeInterrupt clears the IST bit for the interrupt the SH-2 dispatched, identified by its vector. It clears by the accepted vector The acknowledge also drops the IRL line and withholds further IRL assertion until the next IMS write (see irlWithheld); interrupts raised meanwhile stay latched in IST.

func (*SCU) RaiseHBlankIN

func (s *SCU) RaiseHBlankIN(line uint16)

RaiseHBlankIN raises the H-Blank-IN interrupt (bit 2), checks for DMA start factor 2, and advances SCU timers. line is the current scanline number (0-based).

func (*SCU) RaiseInterrupt

func (s *SCU) RaiseInterrupt(bit int)

RaiseInterrupt sets the given IST bit and checks for pending interrupts.

func (*SCU) RaiseSoundRequest

func (s *SCU) RaiseSoundRequest()

RaiseSoundRequest raises the Sound Request interrupt (bit 6) and checks for DMA start factor 5.

func (*SCU) RaiseSpriteDrawEnd

func (s *SCU) RaiseSpriteDrawEnd()

RaiseSpriteDrawEnd raises the Sprite Draw End interrupt (bit 13) and checks for DMA start factor 6.

func (*SCU) RaiseSystemManager

func (s *SCU) RaiseSystemManager()

RaiseSystemManager raises the System Manager interrupt (bit 7).

func (*SCU) RaiseVBlankIN

func (s *SCU) RaiseVBlankIN()

RaiseVBlankIN raises the V-Blank-IN interrupt (bit 0) and checks for DMA start factor 0.

func (*SCU) RaiseVBlankOUT

func (s *SCU) RaiseVBlankOUT()

RaiseVBlankOUT raises the V-Blank-OUT interrupt (bit 1), checks for DMA start factor 1, and resets the Timer 0 counter.

func (*SCU) Read

func (s *SCU) Read(offset uint32) uint32

Read returns the 32-bit value of the SCU register at the given offset. Write-only registers return 0. Unmapped offsets return 0.

func (*SCU) ReadInternal

func (s *SCU) ReadInternal(offset uint32) uint32

ReadInternal returns the stored value for any register, including write-only registers. Used by bus.go for byte-write composition.

func (*SCU) Reset

func (s *SCU) Reset()

Reset clears pending interrupts and DMA state to power-on defaults. Called during CKCHG to match real hardware behavior.

func (*SCU) SetBus

func (s *SCU) SetBus(bus BusReadWriter)

SetBus gives the SCU a reference to the system bus for DMA transfers.

func (*SCU) SetIRLHandler

func (s *SCU) SetIRLHandler(set func(level uint8, vec uint16), clr func())

SetIRLHandler sets the callbacks used to deliver IRL interrupts to the master SH-2. IRL is level-triggered: setIRL drives the current interrupt level, clearIRL deasserts when no interrupt is pending.

func (*SCU) TickSystemCycles

func (s *SCU) TickSystemCycles(cycles uint32)

TickSystemCycles advances DMA deferred interrupt countdowns by the given number of system cycles. When a countdown reaches zero the level is closed out via finishDMA, which raises the DMA-end interrupt and fires any pending start-factor trigger held during the transfer.

func (*SCU) Write

func (s *SCU) Write(offset uint32, val uint32)

Write stores a 32-bit value to the SCU register at the given offset. Read-only registers (DSTA, VER) are ignored. IST uses write-0-to-clear semantics: writing 0 clears the bit, writing 1 maintains current status.

type SMPC

type SMPC struct {
	// contains filtered or unexported fields
}

SMPC implements the System Manager and Peripheral Control for the Sega Saturn. It provides register storage and byte-level access on odd addresses within the 0x00100000-0x0010007F range (after bit 29 stripping).

func NewSMPC

func NewSMPC() *SMPC

NewSMPC allocates an SMPC with correct initial state.

func (*SMPC) PadData added in v0.2.0

func (s *SMPC) PadData(port int) uint16

PadData returns the current active-low 16-bit pad button state for port 0 or 1. Used by HLE BIOS PER_* services to fabricate peripheral records without going through the full SMPC INTBACK sequence. Returns $FFFF (all released) for out-of-range ports.

func (*SMPC) Read

func (s *SMPC) Read(offset uint8) uint8

Read returns the value of the SMPC register at the given byte offset. Even offsets return 0. Write-only registers return 0.

func (*SMPC) SSHEnabled

func (s *SMPC) SSHEnabled() bool

SSHEnabled returns whether the slave SH-2 is enabled.

func (*SMPC) SetPadData

func (s *SMPC) SetPadData(port int, data uint16)

SetPadData sets the active-low button data for the given port (0 or 1). The upper 8 bits are button data byte 1 (directions + Start/A/C/B), the lower 8 bits are button data byte 2 (R/X/Y/Z/L + unused). Buttons are active-low: 0 = pressed, 1 = not pressed.

func (*SMPC) SoundEnabled

func (s *SMPC) SoundEnabled() bool

SoundEnabled returns whether the sound CPU is enabled.

func (*SMPC) TickFrame

func (s *SMPC) TickFrame()

TickFrame advances the emulated RTC by one frame. Called once per emulated frame so the RTC tracks emulation time, not wall clock time.

func (*SMPC) TickScanline

func (s *SMPC) TickScanline() bool

TickScanline advances the command-dispatch delay by one scanline and runs the pending command when it elapses (which clears SF). Returns true when the command requires the SCU System Manager interrupt (INTBACK); the caller raises it.

func (*SMPC) Write

func (s *SMPC) Write(offset uint8, val uint8)

Write stores a value to the SMPC register at the given byte offset. Even offsets are ignored. Read-only registers are ignored.

type Timing

type Timing struct {
	FPS       int
	Scanlines int
}

Timing holds frame rate and scanline count for a region.

type TrackIndex added in v0.2.0

type TrackIndex struct {
	Number uint8
	FAD    uint32
}

TrackIndex is one exposed index point within a track: its index number (>= 1) and its absolute FAD. Index 0 (pregap) is not stored; it is the implied default for any FAD below the first entry.

type TrackInfo

type TrackInfo struct {
	Number   int
	Type     string
	Frames   int
	Pregap   int
	StartLBA int
	Control  uint8        // CTRL/ADR byte (0x41=data, 0x01=audio)
	Indexes  []TrackIndex // index numbers >= 1, ascending by FAD
}

TrackInfo describes a single disc track for the CDBlock.

type VDP1

type VDP1 struct {
	// contains filtered or unexported fields
}

VDP1 implements the Sega Saturn Video Display Processor 1.

func NewVDP1

func NewVDP1(scu *SCU) *VDP1

NewVDP1 creates a new VDP1 instance with VRAM and frame buffers allocated.

func (*VDP1) ConsumeFBSwap

func (v *VDP1) ConsumeFBSwap() bool

ConsumeFBSwap returns whether VBlankIn performed an FB swap since the last consume, and clears the flag. The emulator gates the PTM=10 auto-trigger on this per VDP1 manual Sec.4.3.

func (*VDP1) DisplayFB

func (v *VDP1) DisplayFB(field int) []byte

DisplayFB returns the framebuffer VDP2 should sample for the given field. Under double interlace (DIE=1) each FB stores one parity of half-density rows and both are combined to form the frame (manual Table 1.2 and Sec 4.2): the even field samples the buffer drawn with DIL=0 and the odd field the buffer drawn with DIL=1. Without DIE the swap-managed displayFB is used like normal double buffering.

func (*VDP1) FBHeight

func (v *VDP1) FBHeight() int

FBHeight returns the framebuffer height in pixels.

func (*VDP1) FBWidth

func (v *VDP1) FBWidth() int

FBWidth returns the framebuffer width in pixels.

func (*VDP1) InitCommandEndCodes added in v0.3.0

func (v *VDP1) InitCommandEndCodes()

InitCommandEndCodes writes a draw-end command word (CMDCTRL with the end bit set, 0x8000) into the control word of every 0x20-byte command slot across all of VDP1 VRAM.

func (*VDP1) Is8bpp

func (v *VDP1) Is8bpp() bool

Is8bpp returns true when the framebuffer uses 8-bit pixels.

func (*VDP1) PTM

func (v *VDP1) PTM() uint16

PTM returns the current plot trigger mode (PTMR bits 1:0). Used by the emulator to detect PTM=10 auto-trigger at V-Blank-IN.

func (*VDP1) PerformLateErase

func (v *VDP1) PerformLateErase()

PerformLateErase performs the pending manual-mode erase on the buffer captured at request time. Called by the emulator at the next frame's VBlankIn boundary (after that frame's lines have composited and before the swap), and by the swap sites when the captured buffer is about to become the draw target.

func (*VDP1) Read

func (v *VDP1) Read(offset uint32) uint16

Read returns the 16-bit register value at the given byte offset. Write-only registers return 0.

func (*VDP1) ReadFB

func (v *VDP1) ReadFB(addr uint32) uint8

ReadFB reads a byte from the VDP1 framebuffer. Under DIE=1 it targets the parity-pinned FB matching the current DIL setting.

func (*VDP1) ReadFB16

func (v *VDP1) ReadFB16(addr uint32) uint16

ReadFB16 reads a big-endian 16-bit value from the VDP1 framebuffer. Under DIE=1 it targets the parity-pinned FB matching DIL.

func (*VDP1) ReadFB32

func (v *VDP1) ReadFB32(addr uint32) uint32

ReadFB32 reads a big-endian 32-bit value from the VDP1 framebuffer. Under DIE=1 it targets the parity-pinned FB matching DIL.

func (*VDP1) ReadVRAM

func (v *VDP1) ReadVRAM(addr uint32) uint8

ReadVRAM reads a byte from VDP1 VRAM.

func (*VDP1) ReadVRAM16

func (v *VDP1) ReadVRAM16(addr uint32) uint16

ReadVRAM16 reads a big-endian 16-bit value from VDP1 VRAM.

func (*VDP1) ReadVRAM32

func (v *VDP1) ReadVRAM32(addr uint32) uint32

ReadVRAM32 reads a big-endian 32-bit value from VDP1 VRAM.

func (*VDP1) Reset

func (v *VDP1) Reset()

Reset clears VDP1 registers to power-on defaults. Called during CKCHG to match real hardware behavior.

func (*VDP1) StartAutoDraw

func (v *VDP1) StartAutoDraw()

StartAutoDraw is invoked by the emulator at vblank-OUT when PTM=10 is set AND an FB swap actually occurred during the prior VBlankIn. Per VDP1 manual Sec.4.3 this restarts command processing at address 0; an in-progress draw from the previous frame (transfer-over) is abandoned.

func (*VDP1) SwapCount

func (v *VDP1) SwapCount() uint64

SwapCount returns the monotonic count of FB swaps performed since reset. Used by the host UI to derive a "game fps" metric distinct from the emulator's RunFrame fps.

func (*VDP1) TickSystemCycles

func (v *VDP1) TickSystemCycles(cycles uint32)

TickSystemCycles advances the VDP1 command processor by up to `cycles` system cycles. Consumes the drawPending latch (PTM=01 trigger) on entry. Returns immediately if no draw is active. State (current command address, return address, overshoot debt) persists across calls so a list spanning multiple segments completes naturally. If the end-bit is fetched within budget, EDSR.CEF is set and the sprite-end interrupt is raised. Budget exhaustion before end-bit leaves CEF clear (transfer-over per VDP1 manual Sec 4.6).

A primitive that consumes more cycles than the remaining budget is allowed to complete; the overshoot is recorded in systemCycleDebt and absorbed by the next TickSystemCycles call before any new commands are processed.

func (*VDP1) VBlankIn

func (v *VDP1) VBlankIn()

VBlankIn handles frame buffer lifecycle at the VBlank boundary. Called once per field. Handles erase and/or swap based on FBCR (FCM/FCT) and TVMR (VBE). Also updates EDSR BEF/CEF.

Under DIE=1 (double-density interlace draw mode) the buffers are pinned to fixed parity roles (drawFB=even, displayFB=odd) and the 1-cycle swap is suppressed. Erase clears only the DIL-matched FB so the OTHER field's previous draw is preserved for VDP2 composite this field.

func (*VDP1) VBlankOut

func (v *VDP1) VBlankOut()

VBlankOut handles a deferred FCM=1 + FCT=1 swap at the start of the new frame, after the SH-2's vbout handler has had a chance to write FBCR FCT=1 in response to the just-raised vbout IRQ. This catches the case where the SH-2 sets up "swap + auto-draw" entirely from inside its vbout handler at line 0; without this path the swap would not occur until the next frame's VBlankIn, costing a Saturn frame of latency in the SH-2's drawing pipeline.

VBlankIn already consumed any FCT=1 written before line 224 of the previous frame, so when VBlankOut sees FCT=1 here it is necessarily a "new" write made by the vbout handler. FCM=0 auto-swap is never handled here; it is fully owned by VBlankIn.

func (*VDP1) Write

func (v *VDP1) Write(offset uint32, val uint16)

Write stores a 16-bit value at the given byte offset. Read-only registers (0x10-0x16) ignore writes.

func (*VDP1) WriteFB

func (v *VDP1) WriteFB(addr uint32, val uint8)

WriteFB writes a byte to the VDP1 framebuffer. Under DIE=1 it targets the parity-pinned FB matching the current DIL setting.

func (*VDP1) WriteFB16

func (v *VDP1) WriteFB16(addr uint32, val uint16)

WriteFB16 writes a big-endian 16-bit value to the VDP1 framebuffer. Under DIE=1 it targets the parity-pinned FB matching DIL.

func (*VDP1) WriteFB32

func (v *VDP1) WriteFB32(addr uint32, val uint32)

WriteFB32 writes a big-endian 32-bit value to the VDP1 framebuffer. Under DIE=1 it targets the parity-pinned FB matching DIL.

func (*VDP1) WriteVRAM

func (v *VDP1) WriteVRAM(addr uint32, val uint8)

WriteVRAM writes a byte to VDP1 VRAM.

func (*VDP1) WriteVRAM16

func (v *VDP1) WriteVRAM16(addr uint32, val uint16)

WriteVRAM16 writes a big-endian 16-bit value to VDP1 VRAM.

func (*VDP1) WriteVRAM32

func (v *VDP1) WriteVRAM32(addr uint32, val uint32)

WriteVRAM32 writes a big-endian 32-bit value to VDP1 VRAM.

type VDP2

type VDP2 struct {
	// contains filtered or unexported fields
}

VDP2 implements the Sega Saturn Video Display Processor 2.

func NewVDP2

func NewVDP2(scu *SCU) *VDP2

NewVDP2 creates a new VDP2 instance with VRAM and CRAM allocated.

func (*VDP2) ActiveLines

func (v *VDP2) ActiveLines() uint16

ActiveLines returns the number of active display lines.

func (*VDP2) ActiveSystemCyclesPerLine

func (v *VDP2) ActiveSystemCyclesPerLine() uint32

func (*VDP2) ActiveWidth

func (v *VDP2) ActiveWidth() uint16

ActiveWidth returns the number of active pixels per line.

func (*VDP2) BeginFrame added in v0.3.0

func (v *VDP2) BeginFrame()

BeginFrame samples the frame-scoped render state: output geometry (with the geometry-change blank), field parity, DISP (blanking the output while the display is off), and the RBG configuration and rotation parameter tables. It also refreshes the register snapshot; the per-line state is decoded by BeginLine.

func (*VDP2) BeginLine added in v0.3.0

func (v *VDP2) BeginLine(y int, fb vdp1FBView)

BeginLine prepares row y: it refreshes the register snapshot (writes since the previous line take effect from this row), rebuilds the CRAM cache if CRAM was written, re-decodes the register-derived line state if registers were written, and builds the row's span renderer chain - enabled layers, gradation, composite - with each renderer's per-line setup (line scroll tables, rotation per-line stepping, back-screen color) done here. fb is the VDP1 display framebuffer view the row's sprite layer samples.

func (*VDP2) DisplayHeight

func (v *VDP2) DisplayHeight() int

DisplayHeight returns the number of rows in the output framebuffer. LSMD=3 double-density interlace doubles the displayed vertical resolution; LSMD=3 with NBG mosaic enabled falls back to single-density (non-doubled) per VDP2 manual section 4.11.

Reads the BeginFrame sample, not live registers: the value must describe the frame that was actually rendered, or a mid-frame mode change would make the host interpret the framebuffer with geometry the renderer did not use (sheared/garbled output for that frame).

func (*VDP2) EndFrame added in v0.3.0

func (v *VDP2) EndFrame()

EndFrame wraps the line counter at the frame boundary. Called by the frame loop after the last line of the frame.

func (*VDP2) EndLine added in v0.3.0

func (v *VDP2) EndLine()

EndLine advances the line counter at a scanline boundary. Called by the frame loop for every line except the last of the frame.

func (*VDP2) FrameFieldBit added in v0.3.0

func (v *VDP2) FrameFieldBit() int

FrameFieldBit returns the field bit latched by BeginFrame: the parity of the field being rendered this frame.

func (*VDP2) Framebuffer

func (v *VDP2) Framebuffer() []byte

Framebuffer returns the RGBA8888 pixel output buffer.

func (*VDP2) FramebufferStride

func (v *VDP2) FramebufferStride() int

FramebufferStride returns the stride (bytes per row) of the framebuffer. Reads the BeginFrame sample for the same reason as DisplayHeight: it must match the geometry the frame was rendered at.

func (*VDP2) Is352Clock added in v0.3.0

func (v *VDP2) Is352Clock() bool

Is352Clock reports whether the current horizontal mode runs on the 352 system clock (352/704). False means the 320 clock (320/640). The Emulator uses this plus IsPAL to select the documented crystal frequency.

func (*VDP2) IsPAL

func (v *VDP2) IsPAL() bool

IsPAL reports whether VDP2 is configured for PAL (vs NTSC).

func (*VDP2) LinesPerFrame

func (v *VDP2) LinesPerFrame() uint16

LinesPerFrame returns the total number of scanlines per frame.

func (*VDP2) Read

func (v *VDP2) Read(offset uint32) uint16

Read returns the 16-bit register value at the given byte offset. TVSTAT, HCNT, and VCNT are computed from timing state. Reading EXTEN with EXLTEN=0 latches the HV counters. Reading TVSTAT clears the EXLTFG flag.

func (*VDP2) ReadCRAM

func (v *VDP2) ReadCRAM(addr uint32) uint8

ReadCRAM reads a byte from VDP2 Color RAM.

func (*VDP2) ReadCRAM16

func (v *VDP2) ReadCRAM16(addr uint32) uint16

ReadCRAM16 reads a big-endian 16-bit value from VDP2 Color RAM.

func (*VDP2) ReadCRAM32

func (v *VDP2) ReadCRAM32(addr uint32) uint32

ReadCRAM32 reads a big-endian 32-bit value from VDP2 Color RAM.

func (*VDP2) ReadInternal

func (v *VDP2) ReadInternal(offset uint32) uint16

ReadInternal returns the stored register value with no side effects. Used by bus byte-write RMW paths that must not disturb latch state.

func (*VDP2) ReadVRAM

func (v *VDP2) ReadVRAM(addr uint32) uint8

ReadVRAM reads a byte from VDP2 VRAM.

func (*VDP2) ReadVRAM16

func (v *VDP2) ReadVRAM16(addr uint32) uint16

ReadVRAM16 reads a big-endian 16-bit value from VDP2 VRAM.

func (*VDP2) ReadVRAM32

func (v *VDP2) ReadVRAM32(addr uint32) uint32

ReadVRAM32 reads a big-endian 32-bit value from VDP2 VRAM.

func (*VDP2) RenderLine added in v0.3.0

func (v *VDP2) RenderLine(y int, fb vdp1FBView)

RenderLine produces the complete framebuffer row y in one call: BeginLine plus a full-width RenderTo. A row writes only the layer buffers, the RBG line-color buffers, and framebuffer row frameOutRow(y).

func (*VDP2) RenderTo added in v0.3.0

func (v *VDP2) RenderTo(x int)

RenderTo renders the prepared row's pixels up to x (exclusive), continuing from the previous RenderTo call: each span renderer in the line's chain advances through [lineSpanX, x). Layer pixels and VRAM table data are read at call time, so writes landing between calls are visible to the row's later pixels.

func (*VDP2) Reset

func (v *VDP2) Reset()

Reset clears the VDP2 registers, VRAM/CRAM, and field-parity state to power-on defaults. Called during CKCHG/SYSRES. The line counter (vLine, lineCycle) is intentionally preserved: it represents the emulator's continuous scanline-time position, not register state. Zeroing it mid-RunFrame would desynchronize it from the outer-loop counter that drives per-line tier ticks and VBI/VBO dispatch, shifting drawing windows for games that issue CKCHG during boot.

func (*VDP2) ResetRegisters added in v0.3.0

func (v *VDP2) ResetRegisters()

ResetRegisters zeros the register file to power-on values, leaving VRAM, CRAM, and the field/line counters intact. Models the VDP2 register reset the SMPC CKCHG performs; VRAM is reloaded by the game after the clock change and the line counters must survive a mid-frame reset.

func (*VDP2) ResetRotArm added in v0.3.0

func (v *VDP2) ResetRotArm()

ResetRotArm clears the per-scanline RPRCTL re-read arm table. Called by RunFrame at frame start with both workers parked so it cannot race the SH-2's arming writes or the VDP worker's per-line consumption.

func (*VDP2) SetEXBGSource added in v0.3.1

func (v *VDP2) SetEXBGSource(src exbgSource)

SetEXBGSource wires the external-image provider (the CD block's MPEG frame latch). Called once at emulator construction.

func (*VDP2) SetPAL

func (v *VDP2) SetPAL(pal bool)

SetPAL sets the PAL/NTSC mode and recalculates timing parameters.

func (*VDP2) TickSystemCycles

func (v *VDP2) TickSystemCycles(cycles uint32)

TickSystemCycles advances the intra-line cycle position (TVSTAT HBLANK, H/V latch). Line advancement is driven by EndLine/EndFrame from the emulator frame loop.

func (*VDP2) Write

func (v *VDP2) Write(offset uint32, val uint16)

Write stores a 16-bit value at the given byte offset. Writes to read-only registers (TVSTAT, HCNT, VCNT, VRSIZE) are ignored.

func (*VDP2) WriteCRAM

func (v *VDP2) WriteCRAM(addr uint32, val uint8)

WriteCRAM writes a byte to VDP2 Color RAM. In CRAM mode 0, writes are mirrored between lower and upper 2KB halves.

func (*VDP2) WriteCRAM16

func (v *VDP2) WriteCRAM16(addr uint32, val uint16)

WriteCRAM16 writes a big-endian 16-bit value to VDP2 Color RAM.

func (*VDP2) WriteCRAM32

func (v *VDP2) WriteCRAM32(addr uint32, val uint32)

WriteCRAM32 writes a big-endian 32-bit value to VDP2 Color RAM.

func (*VDP2) WriteVRAM

func (v *VDP2) WriteVRAM(addr uint32, val uint8)

WriteVRAM writes a byte to VDP2 VRAM.

func (*VDP2) WriteVRAM16

func (v *VDP2) WriteVRAM16(addr uint32, val uint16)

WriteVRAM16 writes a big-endian 16-bit value to VDP2 VRAM.

func (*VDP2) WriteVRAM32

func (v *VDP2) WriteVRAM32(addr uint32, val uint32)

WriteVRAM32 writes a big-endian 32-bit value to VDP2 VRAM.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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