Documentation
¶
Index ¶
- type Bus
- func (b *Bus) AccessCycles(addr uint32, size uint32) 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) 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)
- type BusReadWriter
- 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) 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 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) DumpMemory() MemoryDump
- 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) RunFrame()
- 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
- type HLEBIOS
- type MemoryDump
- type SCSP
- func (s *SCSP) InReset() bool
- 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) 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) 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()
- 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) RaiseTimer0()
- func (s *SCU) RaiseTimer1()
- 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
- 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) FBWidth() int
- 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) DisplayHeight() int
- func (v *VDP2) FieldBit() int
- func (v *VDP2) Framebuffer() []byte
- func (v *VDP2) FramebufferStride() int
- 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) RenderFrame()
- func (v *VDP2) Reset()
- func (v *VDP2) SetPAL(pal bool)
- func (v *VDP2) SetVDP1DisplayFB(fb []byte, is8bpp bool, fbWidth, fbHeight int)
- func (v *VDP2) SystemCyclesPerLine() uint32
- 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 ¶
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 ¶
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 bus transaction of the given size (bytes: 1, 2, 4, or 16) at the given address. Used by the SH-2 DMAC to accumulate per-unit bus-occupation stall.
SH-2 BSC WCR = 0x5555 (SH7604 manual Sec 7.2.3) SH-2 BSC MCR = 0x78 (SH7604 manual Sec 7.2.4) SCU ASR0 = 0x1FF01FF0 (SCU manual Sec 3, Fig 3.24) SCU ASR1 = 0x1FF01FF0
combined with the per-field formulas from the SH7604 and SCU user manuals. See each region's comment for the exact arithmetic.
These constants also serve as the correct defaults for a future HLE BIOS, which would skip the real BIOS init - the values are what every shipped Saturn BIOS configures at boot. If a specific game is ever found to reprogram BSC or SCU in a way that matters for DMA timing, switch to reading the live register state.
B-Bus costs (VDP1/VDP2/SCSP/CD) are not register-driven; they reflect the SCU's architectural arbitration overhead. Those numbers are educated estimates aligned with reference emulator behavior rather than decoded from registers.
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) 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.
type BusReadWriter ¶
type BusReadWriter interface {
Read8(addr uint32) uint8
Read16(addr uint32) uint16
Read32(addr uint32) uint32
Write8(addr uint32, val uint8)
Write16(addr uint32, val uint16)
Write32(addr uint32, val uint32)
}
BusReadWriter provides the read/write interface needed by SCU DMA.
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) 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. Called by Emulator.recalcTiming at construction and whenever VDP2 mode changes, so CD pacing tracks the actual system clock rate (NTSC/PAL, 320/352) rather than a fixed compile-time assumption.
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) 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 ¶
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 current frame.
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 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 ¶
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.
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 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
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 ¶
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) 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) 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) 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 ¶
func (s *SCU) AcknowledgeInterrupt()
AcknowledgeInterrupt clears the IST bit for the currently dispatched interrupt. Called by the SH-2 when it accepts an external interrupt. This prevents the same event from firing repeatedly while allowing the IRL to stay asserted until acknowledged.
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) RaiseTimer0 ¶
func (s *SCU) RaiseTimer0()
RaiseTimer0 raises the Timer 0 interrupt (bit 3) and checks for DMA start factor 3.
func (*SCU) RaiseTimer1 ¶
func (s *SCU) RaiseTimer1()
RaiseTimer1 raises the Timer 1 interrupt (bit 4) and checks for DMA start factor 4.
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 ¶
func (s *SMPC) TickScanline()
TickScanline advances the SMPC command-dispatch delay by one scanline. When the delay reaches zero, the pending command runs (which clears the SF flag). Called once per scanline from the emulator main loop.
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. The parity-pinning behavior of DIE=1 only takes effect when dieDoubled() is true (DIE=1 + TVM=1, the doubled-Y interlace model where each FB stores half-density rows). DIE=1 with TVM=0 is the "select which FB displays" pattern (e.g., Sonic Jam game-select) and uses the swap-managed displayFB like normal double buffering.
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 deferred manual-mode erase of displayFB if VBlankIn requested one. Called by the emulator after vdp2.RenderFrame() so the pre-erase content of displayFB is what VDP2 captured for this frame; the erase lands before the next frame's swap so the just-erased buffer becomes the new drawFB on the following FCT=1 swap.
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 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 ¶
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) 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.
func (*VDP2) FieldBit ¶
FieldBit exports the current field bit for cross-package consumers (notably VDP1, which selects the parity-matched framebuffer under DIE=1). Returns 0 outside effective LSMD=3.
func (*VDP2) Framebuffer ¶
Framebuffer returns the RGBA8888 pixel output buffer.
func (*VDP2) FramebufferStride ¶
FramebufferStride returns the stride (bytes per row) of the framebuffer.
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) RenderFrame ¶
func (v *VDP2) RenderFrame()
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) SetVDP1DisplayFB ¶
SetVDP1DisplayFB sets the VDP1 display frame buffer and its format for sprite overlay compositing.
func (*VDP2) SystemCyclesPerLine ¶
SystemCyclesPerLine returns the number of system clock cycles per scanline.
func (*VDP2) TickSystemCycles ¶
TickSystemCycles advances the VDP2 timing engine by the given number of system cycles. VDP2 and the SH-2 both run at the system clock.
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
- cdblock.go
- cdblock_cmd_auth.go
- cdblock_cmd_filesystem.go
- cdblock_cmd_playback.go
- cdblock_cmd_sector.go
- cdblock_cmd_selector.go
- cdblock_cmd_status.go
- dump.go
- emulator.go
- fastboot.go
- hlebios.go
- hlebios_bup.go
- hlebios_per.go
- hlebios_services.go
- scsp.go
- scsp_dsp.go
- scu.go
- scu_dsp.go
- smpc.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_render.go