PSXSDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Macros | Enumerations | Functions | Variables
psx.h File Reference
#include <stdarg.h>
#include <psxbios.h>
#include <psxgpu.h>
#include <memcard.h>
#include <psxpad.h>
#include <psxspu.h>
#include <psxcdrom.h>
#include <psxsio.h>
#include <psxgte.h>

Go to the source code of this file.

Data Structures

struct  psx_info
 
struct  psx_info::kernel
 
struct  psx_info::system
 

Macros

#define true   1
 
#define TRUE   1
 
#define false   0
 
#define FALSE   0
 
#define PSXSDK_VERSION   0x0599
 PSXSDK version information in hexadecimal format.
 
#define PSXSDK_VERSION_STRING   "0.5.99"
 PSXSDK version information in string format.
 
#define PSXSDK_VERSION_DATE   0x20150729
 PSXSDK version date (BCD YYYY-MM-DD)
 

Enumerations

enum  cop0_register_numbers {
  COP0_BADVADDR = 8, COP0_SR = 12, COP0_CAUSE = 13, COP0_EPC = 14,
  COP0_PRID = 15
}
 Coprocessor 0 register numbers. More...
 
enum  psx_rcnt_specs { RCntCNT0 = 0xf2000000, RCntCNT1 = 0xf2000001, RCntCNT2 = 0xf2000002, RCntCNT3 = 0xf2000003 }
 Root counter specifications. More...
 
enum  psx_rcnt_modes { RCntIntr = 0x1000, RCntNotar = 0x0100, RCntStop = 0x0010, RCntSC = 0x0001 }
 Root counter modes. More...
 
enum  psx_init_flags { PSX_INIT_CD = 1, PSX_INIT_SAVESTATE = 2, PSX_INIT_NOBIOS = 4 }
 Flags for PSX_Init. More...
 

Functions

void PSX_Init (void)
 Initialize library.
 
void PSX_DeInit (void)
 Deinitialize library.
 
void PSX_InitEx (unsigned int flags)
 Initialize library (extended version)
 
void PSX_ReadPad (unsigned short *padbuf, unsigned short *padbuf2)
 Reads the status of the buttons of the two joypads.
 
void PSX_PollPad (int pad_num, psx_pad_state *pad_state)
 Polls a joypad for information.
 
void PSX_GetSysInfo (struct psx_info *info)
 Takes a pointer to a struct psx_info structure, and fills it with information about the PlayStation on which the program is running.
 
unsigned int get_cop0_status (void)
 Gets Coprocessor 0 status register.
 
unsigned int set_cop0_status (unsigned int sreg)
 Sets Coprocessor 0 status register.
 
unsigned int get_cop0_epc (void)
 Gets the contents of the program counter when the last exception happened.
 
unsigned int get_cop0_register (unsigned char register_num)
 Get value of specified Coprocessor 0 register.
 
void set_cop0_register (unsigned char register_num, unsigned int value)
 Set value of specified Coprocessor 0 register.
 
unsigned int get_cop_register (unsigned char cop_num, unsigned char register_num)
 Get value of the specified (data) register of a specified coprocessor.
 
unsigned int get_cop_ctrl_register (unsigned char cop_num, unsigned char register_num)
 Get value of the specified control register of a specified coprocessor.
 
void set_cop_register (unsigned char cop_num, unsigned char register_num, unsigned int value)
 Set value of the specified (data) register of a specified coprocessor.
 
void set_cop_ctrl_register (unsigned char cop_num, unsigned char register_num, unsigned int value)
 Set value of the specified control register of a specified coprocessor.
 
void run_cop_instruction (unsigned char cop_num, unsigned int operation)
 Make the specified coprocessor run the specified instruction.
 
int SetRCnt (int spec, unsigned short target, unsigned int mode)
 Set root counter (documentation TO DO)
 
int GetRCnt (int spec)
 Get root counter (documentation TO DO)
 
int StartRCnt (int spec)
 Start root counter (documentation TO DO)
 
int StopRCnt (int spec)
 Stop root counter (documentation TO DO)
 
int PSX_RestoreBiosState (void)
 Restores BIOS state to the one prior the initialization of the library.
 
unsigned int PSX_GetInitFlags (void)
 Gets the bitmask for the flags passed to PSX_InitEx()
 
void SetVBlankHandler (void(*h)())
 Sets an handler function for the VBlank interrupt.
 
void RemoveVBlankHandler (void)
 Removes a previously set VBlank handler.
 

Variables

unsigned char __scratchpad [1024]
 Scratch pad - unused data cache, that can be used as "fast RAM".
 

Macro Definition Documentation

#define false   0
#define FALSE   0
#define PSXSDK_VERSION   0x0599

PSXSDK version information in hexadecimal format.

An explanation of version numbers and how they relate to releases:

  • PSXSDK_VERSION undefined
    • PSXSDK 0.1
  • 0.1.99 (0x0199)
    • From PSXSDK releases 2012-03-03 up to 2013-01-14.
  • 0.2.99 (0x0299)
    • PSXSDK 2013-05-14
  • 0.3.99 (0x0399)
    • PSXSDK 2013-11-09
  • 0.4.99 (0x0499)
    • PSXSDK 2014-04-22
  • 0.5.99 (0x0599)
    • PSXSDK 2015-07-29
#define PSXSDK_VERSION_DATE   0x20150729

PSXSDK version date (BCD YYYY-MM-DD)

#define PSXSDK_VERSION_STRING   "0.5.99"

PSXSDK version information in string format.

#define true   1
#define TRUE   1

Enumeration Type Documentation

Coprocessor 0 register numbers.

Enumerator:
COP0_BADVADDR 

Contains the last invalid program address which caused a trap.

It is set by address errors of all kinds.

COP0_SR 

CPU mode flags (status register)

COP0_CAUSE 

Describes the most recently recognized exception.

COP0_EPC 

Return address from trap.

COP0_PRID 

COP0 type and revision level.

Flags for PSX_Init.

Enumerator:
PSX_INIT_CD 

PSX_INIT_CD - Initialize CDROM filesystem.

PSX_INIT_SAVESTATE 

PSX_INIT_SAVESTATE - Save BIOS state before initializing the library.

PSX_INIT_NOBIOS 

PSX_INIT_NOBIOS - Remove control from the BIOS and let PSXSDK be in complete control.

Root counter modes.

Enumerator:
RCntIntr 

Interrupt mode.

RCntNotar 

Ignore target and count to 65535 (hex: 0xFFFF)

RCntStop 

Timer stop mode.

RCntSC 

System Clock mode.

Root counter specifications.

Enumerator:
RCntCNT0 

Pixel clock.

RCntCNT1 

Horizontal sync.

RCntCNT2 

System clock / 8.

RCntCNT3 

VSync (VBlank)

Function Documentation

unsigned int get_cop0_epc ( void  )

Gets the contents of the program counter when the last exception happened.

Returns
Value of the program counter at the time of the last exception
unsigned int get_cop0_register ( unsigned char  register_num)

Get value of specified Coprocessor 0 register.

Parameters
register_numNumber of Coprocessor 0 register whose value must be retrieved
Returns
Value of specified Coprocessor 0 register
unsigned int get_cop0_status ( void  )

Gets Coprocessor 0 status register.

Returns
Value of Coprocessor 0 status register
unsigned int get_cop_ctrl_register ( unsigned char  cop_num,
unsigned char  register_num 
)

Get value of the specified control register of a specified coprocessor.

Parameters
cop_numCoprocessor number
register_numNumber of coprocessor register whose value must be retrieved
Returns
Value of specified coprocessor register
unsigned int get_cop_register ( unsigned char  cop_num,
unsigned char  register_num 
)

Get value of the specified (data) register of a specified coprocessor.

Parameters
cop_numCoprocessor number
register_numNumber of coprocessor register whose value must be retrieved
Returns
Value of specified coprocessor register
int GetRCnt ( int  spec)

Get root counter (documentation TO DO)

Parameters
specSpec
Returns
TO DO
void PSX_DeInit ( void  )

Deinitialize library.

unsigned int PSX_GetInitFlags ( void  )

Gets the bitmask for the flags passed to PSX_InitEx()

Returns
Flag bitmask
void PSX_GetSysInfo ( struct psx_info info)

Takes a pointer to a struct psx_info structure, and fills it with information about the PlayStation on which the program is running.

PS-OS kernel build date and version are reported among other things.

Parameters
infoPointer to struct psx_info structure which will be filled.
void PSX_Init ( void  )

Initialize library.

void PSX_InitEx ( unsigned int  flags)

Initialize library (extended version)

flags contains a bitmask specifying which flags are enabled

PSX_Init() is the same as PSX_InitEx(PSX_INIT_CD)

Parameters
flagsFlag bitmask (flags are to be OR'd)
void PSX_PollPad ( int  pad_num,
psx_pad_state pad_state 
)

Polls a joypad for information.

Attention
Note that some joypads, like the official ones from Sony, do not like to be polled more than once every 1/60th of a second and if this limitation is not considered the data they return is undefined. Other joypads do not have this limitation but in any case err on the safe side.
Parameters
pad_numNumber of the pad to poll (0 = pad #1, 1 = pad #2, etc.)
pad_statePointer to a psx_pad_state structure in which to store information for the pad.
void PSX_ReadPad ( unsigned short *  padbuf,
unsigned short *  padbuf2 
)

Reads the status of the buttons of the two joypads.

Takes two pointers for 16-bit bitmasks, one for the first player's joypad, and one for the second one. Their bits are updated to show which buttons were pressed.

This function only supplies basic functionality, adequate for a normal digital pad.

If more advanced functionality is desired, use PSX_PollPad() instead of this function.

Attention
Note that some joypads, like the official ones from Sony, do not like to be polled more than once every 1/60th of a second and if this limitation is not considered the data they return is undefined. Other joypads do not have this limitation but in any case err on the safe side.
Parameters
padbufPointer to 16-bit variable where bitmask for pad #1 will be stored. If NULL is passed, this argument is ignored.
padbuf2Pointer to 16-bit variable where bitmask for pad #2 will be stored If NULL is passed, this argument is ignored.
int PSX_RestoreBiosState ( void  )

Restores BIOS state to the one prior the initialization of the library.

This function can only be used if PSX_InitEx() was called with the PSX_INIT_SAVESTATE flag. It is usually called by PSX_DeInit() automatically, so unless you know what you are doing, you do not need to call it yourself.

Returns
1 on success, 0 on failure, such as the fact that PSX_InitEx() wasn't called with the PSX_INIT_SAVESTATE flag.
void RemoveVBlankHandler ( void  )

Removes a previously set VBlank handler.

If SetVBlankHandler() was not called before, calling this function has no effect.

void run_cop_instruction ( unsigned char  cop_num,
unsigned int  operation 
)

Make the specified coprocessor run the specified instruction.

Parameters
operationOperation number for the instruction
void set_cop0_register ( unsigned char  register_num,
unsigned int  value 
)

Set value of specified Coprocessor 0 register.

Parameters
register_numNumber of Coprocessor 0 register whose value must be set
valueNew value of specified Coprocessor 0 register
unsigned int set_cop0_status ( unsigned int  sreg)

Sets Coprocessor 0 status register.

Parameters
sregNew value of Coprocessor 0 status register
Returns
[[ check: maybe this is a void function ]]
void set_cop_ctrl_register ( unsigned char  cop_num,
unsigned char  register_num,
unsigned int  value 
)

Set value of the specified control register of a specified coprocessor.

Parameters
cop_numCoprocessor number
register_numNumber of Coprocessor 0 register whose value must be set
valueNew value of specified Coprocessor 0 register
void set_cop_register ( unsigned char  cop_num,
unsigned char  register_num,
unsigned int  value 
)

Set value of the specified (data) register of a specified coprocessor.

Parameters
cop_numCoprocessor number
register_numNumber of Coprocessor 0 register whose value must be set
valueNew value of specified Coprocessor 0 register
int SetRCnt ( int  spec,
unsigned short  target,
unsigned int  mode 
)

Set root counter (documentation TO DO)

Parameters
specSpec
targetTarget
modemode
void SetVBlankHandler ( void(*)()  h)

Sets an handler function for the VBlank interrupt.

Used for simple, inaccurate timing - the handler function gets called 60 times a second in NTSC video mode and 50 times a second in PAL video mode.

While most games use the VBlank interrupt for timing as they don't require high precision and have mechanisms to keep up with the different speed in PAL or NTSC video mode, for precise timing VBlank is inadequate. It is better to look at root counters if you desire precision.

If there is already a VBlank handler set, this function replaces the current handler with the specified one.

Parameters
hPointer to (new) VBlank handler function
int StartRCnt ( int  spec)

Start root counter (documentation TO DO)

Parameters
specSpec
Returns
TO DO
int StopRCnt ( int  spec)

Stop root counter (documentation TO DO)

Parameters
specSpec
Returns
TO DO

Variable Documentation

unsigned char __scratchpad[1024]

Scratch pad - unused data cache, that can be used as "fast RAM".