Files
psxrecomp/runtime/include/cdrom.h
T
Matthew Stanley 8b59da8202 Disc speed: post-BIOS switch via entry_pc, XA guard for FMVs
Boot stays at authentic 1x. Speed switch fires once when the game's
entry_pc is first dispatched — safely after the BIOS disc init and
Sony/PlayStation logo sequences complete. Uses entry_pc exact-match
rather than text range to avoid false-triggering on the BIOS shell
(RAM 0x30000-0x5B000 overlaps the game text range).

XA guard in apply_speed(): reverts to 1x whenever xa_stream_active,
protecting FMV playback from speed-up regardless of disc_speed setting.

CDROM_MIN_DELAY floor of 500 cycles prevents instant mode from firing
IRQs faster than the interrupt handler can process them.

Tomba game.toml: disc_speed = "4x" (instant proved too aggressive
for early game disc reads; 4x safe with XA guard protecting FMVs).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-05-29 23:59:35 -07:00

107 lines
2.5 KiB
C

#ifndef PSXRECOMP_CDROM_H
#define PSXRECOMP_CDROM_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void cdrom_init(const char* cue_path);
/* Set disc speed multiplier immediately. divisor=0 → instant, 1 → 1x, 2 → 2x. */
void cdrom_set_speed(int divisor);
/* Store configured game speed (applied post-BIOS via cdrom_notify_game_started). */
void cdrom_set_game_speed(int divisor);
/* Called by fntrace on first game-range dispatch; switches to game speed. */
void cdrom_notify_game_started(void);
/* MMIO read/write (0x1F801800-0x1F801803) */
uint32_t cdrom_read(uint32_t addr);
void cdrom_write(uint32_t addr, uint32_t value);
/* Advance CD-ROM state machine by guest CPU cycles. Sets i_stat IRQ_CDROM
* when a command completes or data is ready. */
void cdrom_advance(uint32_t cycles);
/* Legacy frame-paced entry point for interpreter/oracle builds. */
void cdrom_tick(void);
/* DMA channel 3 interface */
uint32_t cdrom_dma_read(void);
int cdrom_dma_ready(void);
typedef struct CDROMDebugState {
uint64_t seq;
uint8_t index_reg;
uint8_t stat_reg;
uint8_t irq_enable;
uint8_t irq_flag;
uint8_t mode_reg;
uint8_t seek_min;
uint8_t seek_sec;
uint8_t seek_sect;
uint8_t pending_cmd;
int has_disc;
int param_count;
int response_read;
int response_count;
int sector_read_pos;
int sector_available;
int sector_size;
int reading;
int read_min;
int read_sec;
int read_sect;
uint8_t read_cmd;
uint8_t filter_file;
uint8_t filter_channel;
uint8_t muted;
int read_delay;
int pending_pending;
int pending_delay;
int pending_phase;
uint32_t i_stat;
} CDROMDebugState;
typedef struct CDROMTraceEntry {
uint64_t seq;
uint32_t addr;
uint32_t val;
uint32_t func;
uint32_t pc;
uint32_t frame;
uint32_t i_stat;
uint8_t kind;
uint8_t width;
uint8_t index_reg;
uint8_t stat_reg;
uint8_t irq_enable;
uint8_t irq_flag;
uint8_t param_count;
uint8_t response_read;
uint8_t response_count;
uint8_t sector_available;
uint8_t mode_reg;
uint8_t pending_cmd;
uint8_t pending_pending;
uint8_t reading;
uint8_t read_cmd;
int sector_read_pos;
int sector_size;
int pending_delay;
int read_delay;
} CDROMTraceEntry;
#define CDROM_TRACE_CAP (1 << 16)
void cdrom_debug_snapshot(CDROMDebugState* out);
uint64_t cdrom_debug_get_trace(const CDROMTraceEntry** out_entries);
void cdrom_debug_clear_trace(void);
#ifdef __cplusplus
}
#endif
#endif /* PSXRECOMP_CDROM_H */