mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-26 02:11:36 -04:00
b2929aa504
Reinstates the runtime-loaded overlay DLL cache (Layer A) and the offline overlay compilation pipeline that were built on the pruned codex/cache-discovery branch (tip 2bbafc2) and never merged. Ported onto current master; rebuilt rather than history-restored. Runtime (off by default, opt in via [runtime] overlay_cache = true): - overlay_loader.c/.h, overlay_api.h: CRC32-keyed DLL cache at cache/<game_id>/<region>_<crc>.dll. On a dirty-RAM dispatch miss the loader LoadLibrary's the matching DLL, wires runtime callbacks via overlay_init(), enumerates func_XXXXXXXX exports, and dispatches them BEFORE the interpreter. - overlay_capture.c/.h: write-once capture set; records overlay DMA bytes and writes overlay_captures.json (execution-verified seeds) at clean exit. - dma.c: capture + cd_dma_log hook at CD DMA completion (async model). - cdrom.c: cdrom_get_setloc_lba() for disc-position correlation. - dirty_ram_interp.c: g_dirty_ram_exec_pc_table (exec-verified PCs), a decodability guard on JAL-into-dirty targets, and the overlay dispatch hooks. - debug_server.c: cd_read_log + overlay_loader_status TCP commands. - config_loader: [runtime] overlay_cache flag (default false). Recompiler (compile_overlays.py / extract_overlays.py drive these): - main_psx.cpp --overlay-exact: analyze only explicit entries + direct JAL targets and set split_mid_function_targets=false, so overlay basic-block targets are NOT split into bogus standalone functions (the mid-function-seed failure mode that produced black-on-load / blue-on-new-game). - function_analysis.cpp: analyze_exact_entries(); code_generator.cpp: gate the mid-function split pre-pass behind split_mid_function_targets (default true, so normal main-EXE codegen is unchanged - Tomba still regens to 2854 funcs). Deltas from the original: save states dropped (never worked); overlay enable is runtime-config-gated (off by default) instead of a build-time define; loader stderr logging converted to the overlay_loader_status TCP path (CLAUDE.md Rule 3). Recovered from _backups/2026-06-06-consolidation/psxrecomp-all-PRE.bundle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
154 lines
4.0 KiB
C
154 lines
4.0 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);
|
|
/* LBA of the most recent SetLoc command (-1 if none yet). Used by the DMA
|
|
* ring buffer to correlate each sector transfer with its disc position. */
|
|
int cdrom_get_setloc_lba(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 request_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;
|
|
int last_sector_lba;
|
|
int last_sector_size;
|
|
uint32_t last_sector_frame;
|
|
uint8_t last_sector_mode;
|
|
uint8_t last_sector_have_raw;
|
|
} CDROMDebugState;
|
|
|
|
typedef struct CDROMSectorDebugState {
|
|
int current_available;
|
|
int current_read_pos;
|
|
int current_size;
|
|
int last_lba;
|
|
int last_size;
|
|
uint32_t last_frame;
|
|
uint8_t last_mode;
|
|
uint8_t last_have_raw;
|
|
} CDROMSectorDebugState;
|
|
|
|
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 request_reg;
|
|
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)
|
|
#define CDROM_SECTOR_HISTORY_CAP (1 << 10)
|
|
#define CDROM_SECTOR_HISTORY_BYTES 128
|
|
|
|
typedef struct CDROMSectorHistoryEntry {
|
|
uint64_t seq;
|
|
int lba;
|
|
int size;
|
|
uint32_t frame;
|
|
uint8_t mode;
|
|
uint8_t have_raw;
|
|
uint8_t raw_mode;
|
|
uint8_t xa_file;
|
|
uint8_t xa_channel;
|
|
uint8_t xa_submode;
|
|
uint8_t xa_coding;
|
|
uint8_t data_delivered;
|
|
uint8_t xa_audio_delivered;
|
|
uint8_t skip_reason;
|
|
uint16_t bytes_len;
|
|
uint8_t bytes[CDROM_SECTOR_HISTORY_BYTES];
|
|
} CDROMSectorHistoryEntry;
|
|
|
|
void cdrom_debug_snapshot(CDROMDebugState* out);
|
|
uint64_t cdrom_debug_get_trace(const CDROMTraceEntry** out_entries);
|
|
void cdrom_debug_clear_trace(void);
|
|
uint32_t cdrom_debug_copy_last_sector(uint32_t offset, uint32_t len,
|
|
uint8_t* out,
|
|
CDROMSectorDebugState* state);
|
|
uint64_t cdrom_debug_get_sector_history(const CDROMSectorHistoryEntry** out_entries);
|
|
void cdrom_debug_clear_sector_history(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* PSXRECOMP_CDROM_H */
|