Documentation
¶
Index ¶
- func SerializeSize() int
- type Bus
- func (b *Bus) AccessCycles(addr uint32, size uint32) uint32
- func (b *Bus) DMAWrite8(addr uint32, val uint8)
- func (b *Bus) DMAWrite16(addr uint32, val uint16)
- func (b *Bus) DMAWrite32(addr uint32, val uint32)
- func (b *Bus) GetBackupRAM() []byte
- func (b *Bus) MINITWritten() bool
- func (b *Bus) Read8(addr uint32) uint8
- func (b *Bus) Read16(addr uint32) uint16
- func (b *Bus) Read32(addr uint32) uint32
- func (b *Bus) ReadCacheLine(base uint32, dst *[16]byte)
- func (b *Bus) ReadRMW8(addr uint32) uint8
- func (b *Bus) SH2FillLine(base uint32, dst *[16]byte, frameCyc int64, slave bool) uint32
- func (b *Bus) SH2RMWRead(addr uint32, frameCyc int64, slave bool) (uint8, uint32)
- func (b *Bus) SH2RMWWrite(addr uint32, val uint8, frameCyc int64) uint32
- func (b *Bus) SH2Read8(addr uint32, frameCyc int64, slave bool) (uint8, uint32)
- func (b *Bus) SH2Read16(addr uint32, frameCyc int64, slave bool) (uint16, uint32)
- func (b *Bus) SH2Read32(addr uint32, frameCyc int64, slave bool) (uint32, uint32)
- func (b *Bus) SH2Write8(addr uint32, val uint8, frameCyc int64, slave bool) uint32
- func (b *Bus) SH2Write16(addr uint32, val uint16, frameCyc int64, slave bool) uint32
- func (b *Bus) SH2Write32(addr uint32, val uint32, frameCyc int64, slave bool) uint32
- func (b *Bus) SINITWritten() bool
- func (b *Bus) SetBIOS(data []byte) error
- func (b *Bus) SetBackupRAM(data []byte)
- func (b *Bus) Write8(addr uint32, val uint8)
- func (b *Bus) Write16(addr uint32, val uint16)
- func (b *Bus) Write32(addr uint32, val uint32)
- func (b *Bus) WriteAccessCycles(addr uint32, size uint32) uint32
- func (b *Bus) WriteRMW8(addr uint32, val uint8)
- type BusReadWriter
- type BusRegion
- type CDAudioSource
- type CDBlock
- func (cb *CDBlock) DrainAudio()
- func (cb *CDBlock) ExecuteCommand()
- func (cb *CDBlock) LoadFileByFID(fid uint32, dst []byte) (int, error)
- func (cb *CDBlock) MpegFrameRGB() (rgb []uint32, w, h int, ok bool)
- func (cb *CDBlock) MpegWindow() (dx, dy, dw, dh, sx, sy, ratX, ratY int, sized bool)
- func (cb *CDBlock) PopAudioSample() (left, right int16, valid bool)
- func (cb *CDBlock) QueueCommand()
- func (cb *CDBlock) Read(offset uint32) uint16
- func (cb *CDBlock) ReadDataTRNS() uint16
- func (cb *CDBlock) ReadDataTRNS32() uint32
- func (cb *CDBlock) RecalcTiming(systemCyclesPerSecond, fieldRateHz uint32)
- func (cb *CDBlock) SetDisc(d DiscReader)
- func (cb *CDBlock) TickSystemCycles(cycles uint32)
- func (cb *CDBlock) Write(offset uint32, val uint16)
- func (cb *CDBlock) Write32(offset uint32, val uint32)
- type DiscReader
- type Emulator
- func (e *Emulator) Close()
- func (e *Emulator) Deserialize(data []byte) error
- func (e *Emulator) GetActiveHeight() int
- func (e *Emulator) GetAudioSamples() []int16
- func (e *Emulator) GetFramebuffer() []byte
- func (e *Emulator) GetFramebufferStride() int
- func (e *Emulator) GetSRAM() []byte
- func (e *Emulator) GetTiming() Timing
- func (e *Emulator) PixelAspectRatio() float64
- func (e *Emulator) ReadMemory(addr uint32, buf []byte) uint32
- func (e *Emulator) ReadMemoryFlat(off uint32, buf []byte) uint32
- func (e *Emulator) Regions() []BusRegion
- func (e *Emulator) RunFrame()
- func (e *Emulator) Serialize() ([]byte, error)
- func (e *Emulator) SetBIOS(key string, data []byte) error
- func (e *Emulator) SetDisc(d DiscReader)
- func (e *Emulator) SetInput(player int, buttons uint32)
- func (e *Emulator) SetOption(key string, value string)
- func (e *Emulator) SetSH2Trace(master, slave func(pc uint32, op uint16))
- func (e *Emulator) SetSRAM(data []byte)
- func (e *Emulator) Start() error
- func (e *Emulator) VDP1SwapCount() uint64
- func (e *Emulator) WriteMemory(addr uint32, data []byte) uint32
- func (e *Emulator) WriteMemoryFlat(off uint32, data []byte) uint32
- type HLEBIOS
- type SCSP
- func (s *SCSP) InReset() bool
- func (s *SCSP) InstallSoundDriverStub()
- func (s *SCSP) M68KDeserialize(buf []byte) error
- func (s *SCSP) M68KSerialize() []byte
- func (s *SCSP) MixBuffer() []int16
- func (s *SCSP) Read(offset uint32) uint16
- func (s *SCSP) ReadRAM(addr uint32) uint8
- func (s *SCSP) ReadRAM16(addr uint32) uint16
- func (s *SCSP) ReadRAM32(addr uint32) uint32
- func (s *SCSP) RequestReset()
- func (s *SCSP) Reset()
- func (s *SCSP) ResetMixBuffer(capacity int)
- func (s *SCSP) SetCDAudioSource(src CDAudioSource)
- func (s *SCSP) SetInReset(reset bool)
- func (s *SCSP) StartFrame(systemCyclesPerFrame, samplesPerFrame, m68kCyclesPerFrame uint32)
- func (s *SCSP) TakePendingReset() bool
- func (s *SCSP) TickSamples(samples int)
- func (s *SCSP) TickSystemCycles(cycles uint32)
- func (s *SCSP) Write(offset uint32, val uint16)
- func (s *SCSP) WriteRAM(addr uint32, val uint8)
- func (s *SCSP) WriteRAM16(addr uint32, val uint16)
- func (s *SCSP) WriteRAM32(addr uint32, val uint32)
- type SCU
- func (s *SCU) AcknowledgeInterrupt(vec uint16)
- func (s *SCU) RaiseHBlankIN(line uint16)
- func (s *SCU) RaiseInterrupt(bit int)
- func (s *SCU) RaiseSoundRequest()
- func (s *SCU) RaiseSpriteDrawEnd()
- func (s *SCU) RaiseSystemManager()
- func (s *SCU) RaiseVBlankIN()
- func (s *SCU) RaiseVBlankOUT()
- func (s *SCU) Read(offset uint32) uint32
- func (s *SCU) ReadInternal(offset uint32) uint32
- func (s *SCU) Reset()
- func (s *SCU) SetBus(bus BusReadWriter)
- func (s *SCU) SetIRLHandler(set func(level uint8, vec uint16), clr func())
- func (s *SCU) TickSystemCycles(cycles uint32)
- func (s *SCU) Write(offset uint32, val uint32)
- type SMPC
- func (s *SMPC) PadData(port int) uint16
- func (s *SMPC) Read(offset uint8) uint8
- func (s *SMPC) SSHEnabled() bool
- func (s *SMPC) SetPadData(port int, data uint16)
- func (s *SMPC) SoundEnabled() bool
- func (s *SMPC) TickFrame()
- func (s *SMPC) TickScanline() bool
- func (s *SMPC) Write(offset uint8, val uint8)
- type Timing
- type TrackIndex
- type TrackInfo
- type VDP1
- func (v *VDP1) ConsumeFBSwap() bool
- func (v *VDP1) DisplayFB(field int) []byte
- func (v *VDP1) FBHeight() int
- func (v *VDP1) FBRotated() bool
- func (v *VDP1) FBWidth() int
- func (v *VDP1) InitCommandEndCodes()
- func (v *VDP1) Is8bpp() bool
- func (v *VDP1) PTM() uint16
- func (v *VDP1) PerformLateErase()
- func (v *VDP1) Read(offset uint32) uint16
- func (v *VDP1) ReadFB(addr uint32) uint8
- func (v *VDP1) ReadFB16(addr uint32) uint16
- func (v *VDP1) ReadFB32(addr uint32) uint32
- func (v *VDP1) ReadVRAM(addr uint32) uint8
- func (v *VDP1) ReadVRAM16(addr uint32) uint16
- func (v *VDP1) ReadVRAM32(addr uint32) uint32
- func (v *VDP1) Reset()
- func (v *VDP1) StartAutoDraw()
- func (v *VDP1) SwapCount() uint64
- func (v *VDP1) TickSystemCycles(cycles uint32)
- func (v *VDP1) VBlankIn()
- func (v *VDP1) VBlankOut()
- func (v *VDP1) Write(offset uint32, val uint16)
- func (v *VDP1) WriteFB(addr uint32, val uint8)
- func (v *VDP1) WriteFB16(addr uint32, val uint16)
- func (v *VDP1) WriteFB32(addr uint32, val uint32)
- func (v *VDP1) WriteVRAM(addr uint32, val uint8)
- func (v *VDP1) WriteVRAM16(addr uint32, val uint16)
- func (v *VDP1) WriteVRAM32(addr uint32, val uint32)
- type VDP2
- func (v *VDP2) ActiveLines() uint16
- func (v *VDP2) ActiveSystemCyclesPerLine() uint32
- func (v *VDP2) ActiveWidth() uint16
- func (v *VDP2) BeginFrame()
- func (v *VDP2) BeginLine(y int, fb vdp1FBView)
- func (v *VDP2) DisplayHeight() int
- func (v *VDP2) EndFrame()
- func (v *VDP2) EndLine()
- func (v *VDP2) FrameFieldBit() int
- func (v *VDP2) Framebuffer() []byte
- func (v *VDP2) FramebufferStride() int
- func (v *VDP2) Is352Clock() bool
- func (v *VDP2) IsPAL() bool
- func (v *VDP2) LinesPerFrame() uint16
- func (v *VDP2) Read(offset uint32) uint16
- func (v *VDP2) ReadCRAM(addr uint32) uint8
- func (v *VDP2) ReadCRAM16(addr uint32) uint16
- func (v *VDP2) ReadCRAM32(addr uint32) uint32
- func (v *VDP2) ReadInternal(offset uint32) uint16
- func (v *VDP2) ReadVRAM(addr uint32) uint8
- func (v *VDP2) ReadVRAM16(addr uint32) uint16
- func (v *VDP2) ReadVRAM32(addr uint32) uint32
- func (v *VDP2) RenderLine(y int, fb vdp1FBView)
- func (v *VDP2) RenderTo(x int)
- func (v *VDP2) Reset()
- func (v *VDP2) ResetRegisters()
- func (v *VDP2) ResetRotArm()
- func (v *VDP2) SetEXBGSource(src exbgSource)
- func (v *VDP2) SetPAL(pal bool)
- func (v *VDP2) TickSystemCycles(cycles uint32)
- func (v *VDP2) Write(offset uint32, val uint16)
- func (v *VDP2) WriteCRAM(addr uint32, val uint8)
- func (v *VDP2) WriteCRAM16(addr uint32, val uint16)
- func (v *VDP2) WriteCRAM32(addr uint32, val uint32)
- func (v *VDP2) WriteVRAM(addr uint32, val uint8)
- func (v *VDP2) WriteVRAM16(addr uint32, val uint16)
- func (v *VDP2) WriteVRAM32(addr uint32, val uint32)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SerializeSize ¶ added in v0.3.2
func SerializeSize() int
SerializeSize returns the per-state size figure front ends use to budget rewind ring buffers and estimate rewind duration. Serialize output is compressed, so the actual size varies with game content; this is a conservative estimate of a typical in-game state (the ~12 MB uncompressed body compresses well below this), not a bound.
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 ¶
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 ¶
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
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) DMAWrite16 ¶ added in v0.4.1
DMAWrite16 performs a bus-master (SCU-DMA) 16-bit write: one B-Bus write unit, so one burst-stall word of VDP1 draw contention.
func (*Bus) DMAWrite32 ¶ added in v0.3.0
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 ¶
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 ¶
MINITWritten returns whether MINIT was written since the last check and clears the flag.
func (*Bus) Read8 ¶
Read8 reads a byte from the given address, claiming the address's bus area for the duration of the access.
func (*Bus) Read16 ¶
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 ¶
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
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
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 (*Bus) SH2RMWRead ¶ added in v0.3.0
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 (*Bus) SH2Read32 ¶ added in v0.3.0
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) SH2Write16 ¶ added in v0.3.0
func (*Bus) SH2Write32 ¶ added in v0.3.0
func (*Bus) SINITWritten ¶
SINITWritten returns whether SINIT was written since the last check and clears the flag.
func (*Bus) SetBackupRAM ¶
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 ¶
Write8 writes a byte to the given address, claiming the address's bus area for the duration of the access.
func (*Bus) Write16 ¶
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 ¶
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
WriteAccessCycles is the write-direction companion to AccessCycles.
type BusReadWriter ¶
type BusReadWriter interface {
Read8(addr uint32) uint8
Read16(addr uint32) uint16
Read32(addr uint32) uint32
DMAWrite8(addr uint32, val uint8)
DMAWrite16(addr uint32, val uint16)
DMAWrite32(addr uint32, val uint32)
}
BusReadWriter provides the read/write interface needed by SCU DMA.
type BusRegion ¶ added in v0.4.0
type BusRegion struct {
Name string
Start uint32 // canonical native bus address of the region's first byte
Size uint32 // region size in bytes
}
BusRegion describes one region of the console's native address bus in canonical addresses.
type CDAudioSource ¶
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 ¶
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
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
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).
func (*CDBlock) MpegWindow ¶ added in v0.3.3
MpegWindow returns the latched $A1 display-window placement: display position (signed, in decoder raster coordinates - the origin is fixed in the card's output raster, not the VDP2 frame, so the consumer converts both axes per the screen mode), visible extent (exclusive), the source-side anchor, and the source step per display pixel in thousandths per axis (1000 = 1:1). sized is false when no window has been configured (the picture maps 1:1 from the origin).
func (*CDBlock) PopAudioSample ¶
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) ReadDataTRNS ¶
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 ¶
ReadDataTRNS32 returns two consecutive 16-bit FIFO words as a 32-bit value.
func (*CDBlock) RecalcTiming ¶
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 ¶
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.
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) Deserialize ¶ added in v0.3.2
Deserialize restores emulator state from a file produced by Serialize. Must be called at a frame boundary (between RunFrame calls) with the workers parked, the same constraint as Serialize, and with the same disc attached and the same BIOS loaded (both enforced via the header).
Validation is strict and runs before any mutation: header gates (version window, BIOS hash, gameID, CRC), framing, exact chunk and field sets, and range checks on every value used as an index after restore. Most errors are caught in this pre-mutation phase, but an m68k blob whose internal format check fails is detected during apply, after other chunks have been restored. On any error the emulator may be left partially modified and is in an inconsistent state: the caller must not continue running it and should discard it or reload a known-good state.
func (*Emulator) GetActiveHeight ¶
GetActiveHeight returns the current active display height.
func (*Emulator) GetAudioSamples ¶
GetAudioSamples returns the audio sample buffer for the current frame.
func (*Emulator) GetFramebuffer ¶
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 ¶
GetFramebufferStride returns the stride (bytes per row) of the framebuffer.
func (*Emulator) PixelAspectRatio ¶
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
ReadMemory reads guest RAM at a canonical native bus address into buf and returns the number of bytes read. Bytes come through the bus decode, so external reads see exactly what the emulated CPUs see. Reads clamp at the region end; addresses outside the canonical regions read nothing. Calls happen between frames with the emulation threads parked, so the lock-free and trace-free bus access is used.
func (*Emulator) ReadMemoryFlat ¶ added in v0.4.0
ReadMemoryFlat reads from the Saturn flat memory convention 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. The switch maps flat offsets to native addresses only; the bus decode selects every byte, matching ReadMemory.
func (*Emulator) RunFrame ¶
func (e *Emulator) RunFrame()
RunFrame executes one complete frame of emulation.
func (*Emulator) Serialize ¶ added in v0.3.2
Serialize captures the complete emulator state as a self-contained state file: header followed by the compressed chunk body. The returned bytes are the on-disk file format; callers write them verbatim. Must be called at a frame boundary (between RunFrame calls) with the workers parked, so all component state is stable. Not safe for concurrent calls: body assembly and compression reuse emulator-owned scratch (only the returned bytes are fresh).
Compression is S2 blocks segmented across parallel workers: front ends call Serialize at rewind-capture rates (up to every other frame), so the capture must fit inside a frame window.
func (*Emulator) SetBIOS ¶
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) SetOption ¶ added in v0.2.0
SetOption applies a core option change identified by key. Values are stored and applied when Start() is called.
func (*Emulator) SetSH2Trace ¶
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) Start ¶
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 ¶
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.
func (*Emulator) WriteMemory ¶ added in v0.4.0
WriteMemory writes data to guest RAM at a canonical native bus address and returns the number of bytes written. Bytes go through the bus decode, matching ReadMemory. Writes clamp at the region end; addresses outside the canonical regions write nothing.
func (*Emulator) WriteMemoryFlat ¶ added in v0.4.0
WriteMemoryFlat writes data to the Saturn flat memory convention and returns the number of bytes written, matching ReadMemoryFlat's layout and boundary behavior. The switch maps flat offsets to native addresses only; the bus decode selects every byte.
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
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
Boot performs the minimum-state High-Level Emulation of the Saturn BIOS startup against the provided IP image:
- Validates the bytes form a Saturn game image by checking the System ID hardware identifier.
- Copies the IP into Work-RAM-H at $06002000-$0600A000.
- Populates every BIOS-set Work-RAM-H data table that disc/SDK code expects to find pre-initialized.
- Registers every SYS_*/PER_*/BUP_* service hook.
- Wires CPU.HLEHook on master and slave.
- 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 SCSP ¶
type SCSP struct {
// contains filtered or unexported fields
}
SCSP implements the Saturn Custom Sound Processor.
func NewSCSP ¶
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) 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) M68KDeserialize ¶ added in v0.3.2
M68KDeserialize restores the sound CPU from a block produced by M68KSerialize. The chip validates size and format version itself.
func (*SCSP) M68KSerialize ¶ added in v0.2.0
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 ¶
MixBuffer returns the interleaved stereo audio samples produced this frame.
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 ¶
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 ¶
SetInReset sets the 68K reset state. When transitioning from reset to active, the 68K is reset to fetch its initial vectors.
func (*SCSP) StartFrame ¶
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
TakePendingReset clears and returns the deferred-reset request.
func (*SCSP) TickSamples ¶
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 ¶
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 ¶
Write stores a 16-bit value at the given byte offset from 0x100000. Certain registers have side-effects on write.
func (*SCSP) WriteRAM16 ¶
WriteRAM16 writes a big-endian 16-bit value to sound RAM.
func (*SCSP) WriteRAM32 ¶
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 (*SCU) AcknowledgeInterrupt ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 (*SMPC) PadData ¶ added in v0.2.0
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 ¶
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 ¶
SSHEnabled returns whether the slave SH-2 is enabled.
func (*SMPC) SetPadData ¶
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 ¶
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 ¶
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.
type TrackIndex ¶ added in v0.2.0
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 (*VDP1) ConsumeFBSwap ¶
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 ¶
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) FBRotated ¶ added in v0.3.3
FBRotated returns true when TVMR selects a rotation TV mode (TVM=010 rotation 16-bit or TVM=011 rotation 8-bit). Per VDP1 manual Sec 1.2, in these modes the display framebuffer read coordinates come from the VDP2.
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) PTM ¶
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 ¶
Read returns the 16-bit register value at the given byte offset. Write-only registers return 0.
func (*VDP1) ReadFB ¶
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 ¶
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 ¶
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) ReadVRAM16 ¶
ReadVRAM16 reads a big-endian 16-bit value from VDP1 VRAM.
func (*VDP1) ReadVRAM32 ¶
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 ¶
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 ¶
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 the last vblank, 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 ¶
Write stores a 16-bit value at the given byte offset. Read-only registers (0x10-0x16) ignore writes.
func (*VDP1) WriteFB ¶
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 ¶
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 ¶
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) WriteVRAM16 ¶
WriteVRAM16 writes a big-endian 16-bit value to VDP1 VRAM.
func (*VDP1) WriteVRAM32 ¶
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 (*VDP2) ActiveLines ¶
ActiveLines returns the number of active display lines.
func (*VDP2) ActiveSystemCyclesPerLine ¶
func (*VDP2) ActiveWidth ¶
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
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 ¶
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
FrameFieldBit returns the field bit latched by BeginFrame: the parity of the field being rendered this frame.
func (*VDP2) Framebuffer ¶
Framebuffer returns the RGBA8888 pixel output buffer.
func (*VDP2) FramebufferStride ¶
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
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) LinesPerFrame ¶
LinesPerFrame returns the total number of scanlines per frame.
func (*VDP2) Read ¶
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) ReadCRAM16 ¶
ReadCRAM16 reads a big-endian 16-bit value from VDP2 Color RAM.
func (*VDP2) ReadCRAM32 ¶
ReadCRAM32 reads a big-endian 32-bit value from VDP2 Color RAM.
func (*VDP2) ReadInternal ¶
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) ReadVRAM16 ¶
ReadVRAM16 reads a big-endian 16-bit value from VDP2 VRAM.
func (*VDP2) ReadVRAM32 ¶
ReadVRAM32 reads a big-endian 32-bit value from VDP2 VRAM.
func (*VDP2) RenderLine ¶ added in v0.3.0
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
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 register-write capture tables (RPRCTL re-read arms and NBG vertical-scroll reloads). 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) TickSystemCycles ¶
TickSystemCycles advances the intra-line cycle position (TVSTAT HBLANK, H/V latch) and raises H-Blank-IN as the line enters horizontal blanking. Line advancement is driven by EndLine/EndFrame from the emulator frame loop.
func (*VDP2) Write ¶
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 ¶
WriteCRAM writes a byte to VDP2 Color RAM. In CRAM mode 0, writes are mirrored between lower and upper 2KB halves.
func (*VDP2) WriteCRAM16 ¶
WriteCRAM16 writes a big-endian 16-bit value to VDP2 Color RAM.
func (*VDP2) WriteCRAM32 ¶
WriteCRAM32 writes a big-endian 32-bit value to VDP2 Color RAM.
func (*VDP2) WriteVRAM16 ¶
WriteVRAM16 writes a big-endian 16-bit value to VDP2 VRAM.
func (*VDP2) WriteVRAM32 ¶
WriteVRAM32 writes a big-endian 32-bit value to VDP2 VRAM.
Source Files
¶
- bus.go
- bus_timing.go
- busmap.go
- cdblock.go
- cdblock_cmd_auth.go
- cdblock_cmd_filesystem.go
- cdblock_cmd_mpeg.go
- cdblock_cmd_playback.go
- cdblock_cmd_sector.go
- cdblock_cmd_selector.go
- cdblock_cmd_status.go
- cdblock_mpeg_decode.go
- emulator.go
- fastboot.go
- frame.go
- hlebios.go
- hlebios_bup.go
- hlebios_per.go
- hlebios_services.go
- ramcart.go
- savestate.go
- scsp.go
- scsp_dsp.go
- scu.go
- scu_dsp.go
- smpc.go
- timing.go
- vdp1.go
- vdp1_draw.go
- vdp1_gouraud.go
- vdp1_helpers.go
- vdp1_line.go
- vdp1_polygon.go
- vdp1_sprite_distorted.go
- vdp1_sprite_normal.go
- vdp1_sprite_scaled.go
- vdp2.go
- vdp2_color.go
- vdp2_composite.go
- vdp2_nbg.go
- vdp2_rbg.go
- vdp2_render.go
- vdp2_sprite.go
- vdp2_window.go