Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
gpdplayer.h
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2026 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <stdint.h>
30
31// Player for GPUDUMP streams, as described in
32// https://github.com/ps1dev/standards/blob/main/GPUDUMP.md
33// The stream is consumed through a reader
34// callback, so it can come from memory, from the host through
35// pcdrv, or from the CD-ROM through the BIOS file API, and is
36// never required to fit in memory: packets are streamed through
37// a small internal buffer, whatever their size.
38
39// Reads up to `bytes` bytes into `dst`. Returns the number of bytes
40// read, which may be less than requested, or 0 or a negative
41// value at the end of the stream or on error.
42typedef int (*GPD_ReadFn)(void* ctx, void* dst, int bytes);
43
44// GPU version from the stream's 0x06 packet, or 0 if none was seen.
45// 1 = GPU v1 with 1MB of VRAM, 2 = GPU v2 with 1MB, 3 = GPU v2 with 2MB.
47
48// Number of vsync packets consumed so far.
49extern uint32_t GPD_Frame;
50
51// Validates the 16 bytes magic header of a GPUDUMP stream.
52// Returns 1 if valid, 0 if not.
53int GPD_Check(const void* header16);
54
55// Starts playing a stream from an arbitrary reader. Reads the magic
56// header and validates it. Returns 1 on success, 0 if the stream is
57// invalid. The ctx pointer is passed as-is to the reader.
58int GPD_Init(GPD_ReadFn fn, void* ctx);
59
60// Starts playing a stream stored in memory. The data needs to stay
61// valid for the duration of the playback.
62int GPD_InitMemory(const void* data, uint32_t size);
63
64// Starts playing a stream from a file on the host, through pcdrv.
65// Returns 0 if pcdrv is unavailable, the file can't be opened, or
66// the stream is invalid.
67int GPD_InitPCdrv(const char* hostPath);
68
69// Starts playing a stream from a file on the CD-ROM, using the
70// BIOS file API. The path is a BIOS path, for instance
71// "cdrom:\\FILE.GPD;1". Returns 0 on error. The BIOS CD-ROM code
72// needs interrupts, so this call and the subsequent GPD_PlayFrame
73// calls must be done outside of a critical section.
74int GPD_InitCDRom(const char* path);
75
76// Closes the current stream, if it was opened by GPD_InitPCdrv
77// or GPD_InitCDRom. Safe to call at any time.
78void GPD_Close();
79
80// Pushes packets to the GPU until the next vsync packet, or the end
81// of the stream. The first call goes through the state restoration
82// part of the stream, up to and past the trace begin packet. The
83// caller is expected to wait for a vblank between calls.
84// Returns 1 if a vsync packet was reached, 0 at the end of the
85// stream, or if the stream is truncated.
86int GPD_PlayFrame();
static int size
Definition string.h:142
uint32_t GPD_GPUVersion
Definition gpdplayer.c:72
int GPD_InitCDRom(const char *path)
Definition gpdplayer.c:412
int GPD_InitMemory(const void *data, uint32_t size)
Definition gpdplayer.c:344
uint32_t GPD_Frame
Definition gpdplayer.c:73
void GPD_Close()
Definition gpdplayer.c:426
int GPD_PlayFrame()
Definition gpdplayer.c:280
int GPD_InitPCdrv(const char *hostPath)
Definition gpdplayer.c:360
int(* GPD_ReadFn)(void *ctx, void *dst, int bytes)
Definition gpdplayer.h:42
int GPD_Init(GPD_ReadFn fn, void *ctx)
Definition gpdplayer.c:262
int GPD_Check(const void *header16)
Definition gpdplayer.c:254
struct Registers * ctx
Definition monitor.c:73
void int(code1, code2)
void uint32_t(classId, spec)