aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/include/psxsn.h
blob: f14db1279a8618f14d0f5d004bd480258a13f212 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * PSn00bSDK kernel API library (host file access)
 * (C) 2023 spicyjpeg - MPL licensed
 */

/**
 * @file psxsn.h
 * @brief Host file access API header
 *
 * @details This header provides stubs for the PCDRV API, which grants read and
 * write access to a directory on the host's filesystem when the executable is
 * running on an emulator or through a debugger that supports the PCDRV
 * protocol, such as Unirom or pcsx-redux. These functions are completely
 * separate and independent from the file APIs provided by the BIOS and do not
 * register any device drivers.
 *
 * Note that in the official SDK these functions are provided by libsn, while
 * in PSn00bSDK they are part of libpsxapi.
 *
 * IMPORTANT: as these function rely on break instructions internally, calling
 * them on real hardware without a PCDRV handler installed or on an emulator
 * that does not support the API will result in an uncaught break exception,
 * which will cause the BIOS to get stuck in an infinite loop.
 */

#pragma once

#include <stddef.h>

typedef enum {
	PCDRV_MODE_READ       = 0,
	PCDRV_MODE_WRITE      = 1,
	PCDRV_MODE_READ_WRITE = 2
} PCDRV_OpenMode;

typedef enum {
	PCDRV_SEEK_SET = 0,
	PCDRV_SEEK_CUR = 1,
	PCDRV_SEEK_END = 2
} PCDRV_SeekMode;

#ifdef __cplusplus
extern "C" {
#endif

int PCinit(void);
int PCcreat(const char *path);
int PCopen(const char *path, PCDRV_OpenMode mode);
int PCclose(int fd);
int PCread(int fd, void *data, size_t length);
int PCwrite(int fd, const void *data, size_t length);
int PClseek(int fd, int offset, PCDRV_SeekMode mode);

#ifdef __cplusplus
}
#endif