Files
psxrecomp/runtime/include/cpu_state.h
T
Matthew Stanley adaea3d8bf Salvage clean hardware sim from v2/v3: GTE, SW renderer, ISO reader, CRC32
Audited psxrecomp-v3 and psxrecomp-v2 hardware simulation files.
Carried forward only pure hardware simulation with zero HLE/BIOS
contamination. Each file was read in full and checked for:
- event_deliver / bios_ / interpreter_ references (none found)
- printf/fprintf (removed from GTE, none in others)
- stubs (return 0, TODO, FIXME) (none found)
- v3-specific state dependencies (removed psx_runtime.h, automation.h)

Added files:
- gte.cpp/h: COP2 coprocessor (876 lines, all GTE commands)
- gpu_sw_renderer.c/h: Software rasterizer with texture support (723 lines)
- crc32.c/h: CRC32 utility (27 lines)
- iso_reader.cpp/h + iso_reader_c.cpp: ISO 9660 reader (490 lines)

Modified:
- cpu_state.h: Added gte_data[32] and gte_ctrl[32] arrays
- CMakeLists.txt: Added new source files

Explicitly rejected (per CLAUDE.md rule 7):
- bios.c, events.c, threads.c, interpreter.c (HLE/kernel state)
- bios_trace.c, func_logger.c, main_runner.cpp (interpreter era)
- cdrom.c (has event_deliver + hard-coded RAM writes, needs surgery)
- spu.cpp from v2 (WinMM-only, needs SDL port)

Build verified: clean compile and link.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 20:57:41 -07:00

62 lines
2.5 KiB
C

/* ============================================================================
* cpu_state.h — Phase 2 runtime version
* ----------------------------------------------------------------------------
* This is the RUNTIME version of the CPUState header. It has the same struct
* layout as generated/cpu_state.h (Phase 1a compile-only artifact) but is
* intended to be linked into a runnable binary.
*
* The generated C files (SCPH1001_full.c, SCPH1001_dispatch.c) include
* "cpu_state.h" and the build uses -I runtime/include so they find this file.
* ========================================================================== */
#ifndef PSXRECOMP_V4_CPU_STATE_H
#define PSXRECOMP_V4_CPU_STATE_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct CPUState {
uint32_t gpr[32]; /* $0..$31; gpr[0] is hardwired zero, never written */
uint32_t pc; /* program counter */
uint32_t hi, lo; /* mult/div result registers */
uint32_t cop0[32]; /* COP0 system control registers (SR, Cause, EPC, ...) */
uint32_t gte_data[32]; /* COP2 (GTE) data registers */
uint32_t gte_ctrl[32]; /* COP2 (GTE) control registers */
/* Memory access function pointers -- wired at init to psx_read/psx_write. */
uint32_t (*read_word)(uint32_t addr);
void (*write_word)(uint32_t addr, uint32_t value);
uint16_t (*read_half)(uint32_t addr);
void (*write_half)(uint32_t addr, uint16_t value);
uint8_t (*read_byte)(uint32_t addr);
void (*write_byte)(uint32_t addr, uint8_t value);
} CPUState;
/* Trap trampolines — defined in runtime/src/traps.c */
extern void psx_syscall(CPUState* cpu, uint32_t code);
extern void psx_arith_overflow(CPUState* cpu);
extern void psx_unaligned_access(CPUState* cpu, uint32_t addr, uint32_t pc);
extern void psx_break(CPUState* cpu, uint32_t code, uint32_t pc);
/* Dispatch — defined in generated/SCPH1001_dispatch.c */
extern void psx_dispatch(CPUState* cpu, uint32_t target_addr);
/* Unknown dispatch — defined in runtime/src/traps.c */
extern void psx_unknown_dispatch(CPUState* cpu, uint32_t addr, uint32_t phys);
/* GTE (COP2) — defined in runtime/src/gte.cpp */
extern void gte_execute(CPUState* cpu, uint32_t cmd);
extern uint32_t gte_read_data(CPUState* cpu, uint8_t reg);
extern uint32_t gte_read_ctrl(CPUState* cpu, uint8_t reg);
extern void gte_write_data(CPUState* cpu, uint8_t reg, uint32_t val);
extern void gte_write_ctrl(CPUState* cpu, uint8_t reg, uint32_t val);
#ifdef __cplusplus
}
#endif
#endif /* PSXRECOMP_V4_CPU_STATE_H */