PSXSDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
psxsdk.c File Reference
#include <psx.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "exception.h"

Macros

#define IPENDING   *((unsigned int*)0x1f801070)
 
#define IMASK   *((unsigned int*)0x1f801074)
 
#define RCNT_COUNT(x)   *((unsigned int*)(0x1f801100 + (x<<4)))
 
#define RCNT_MODE(x)   *((unsigned int*)(0x1f801104 + (x<<4)))
 
#define RCNT_TARGET(x)   *((unsigned int*)(0x1f801108 + (x<<4)))
 

Functions

int * vblank_handler ()
 
int * rcnt_handler ()
 
void _internal_cdromlib_init (void)
 
void _96_remove (void)
 
void _96_init (void)
 
void InitCARD (void)
 
void StartCARD (void)
 
void StopCARD (void)
 
void _bu_init (void)
 
void BIOSWarmReboot (void)
 
void PSX_InitEx (unsigned int flags)
 Initialize library (extended version)
 
void PSX_Init (void)
 Initialize library.
 
void PSX_DeInit (void)
 Deinitialize library.
 
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.
 
int get_real_file_size (char *name)
 This function is like get_file_size() but doesn't round the file size to the block size.
 
int get_file_size (char *name)
 Gets the file size of the file named "name".
 
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)
 
void SetVBlankHandler (void(*callback)())
 Sets an handler function for the VBlank interrupt.
 
void RemoveVBlankHandler (void)
 Removes a previously set VBlank handler.
 
void SetRCntHandler (void(*callback)(), int spec, unsigned short target)
 
void RemoveRCntHandler (int spec)
 
const char * GetSystemRomVersion (void)
 Returns a pointer to a zero-terminated string which contains the system ROM version.
 
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 PSX_WarmReboot (void)
 

Variables

const char * sysromver_unavail = "System ROM Version Unavailable"
 
unsigned char padread_buf [2][8]
 
void(* vblank_handler_callback )()
 
void(* rcnt_handler_callback )()
 
unsigned int rcnt_handler_evfield
 
unsigned char psxsdkPadArr [PAD_READ_RAW_SIZE]
 

Macro Definition Documentation

#define IMASK   *((unsigned int*)0x1f801074)
#define IPENDING   *((unsigned int*)0x1f801070)
#define RCNT_COUNT (   x)    *((unsigned int*)(0x1f801100 + (x<<4)))
#define RCNT_MODE (   x)    *((unsigned int*)(0x1f801104 + (x<<4)))
#define RCNT_TARGET (   x)    *((unsigned int*)(0x1f801108 + (x<<4)))

Function Documentation

void _96_init ( void  )
void _96_remove ( void  )
void _bu_init ( void  )
void _internal_cdromlib_init ( void  )
void BIOSWarmReboot ( void  )
int get_file_size ( char *  name)

Gets the file size of the file named "name".

It is actually just a wrapper around firstfile. It rounds the file size to the block size (2048).

Parameters
nameFIle name string
Returns
File size in bytes, rounded.
int get_real_file_size ( char *  name)

This function is like get_file_size() but doesn't round the file size to the block size.

Parameters
nameFile name string
Returns
File size in bytes, unrounded.
int GetRCnt ( int  spec)

Get root counter (documentation TO DO)

Parameters
specSpec
Returns
TO DO
const char* GetSystemRomVersion ( void  )

Returns a pointer to a zero-terminated string which contains the system ROM version.

Returns
Zero-terminated string which contains the system ROM version.
void InitCARD ( void  )
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 PSX_WarmReboot ( void  )
int* rcnt_handler ( )
void RemoveRCntHandler ( int  spec)
void RemoveVBlankHandler ( void  )

Removes a previously set VBlank handler.

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

int SetRCnt ( int  spec,
unsigned short  target,
unsigned int  mode 
)

Set root counter (documentation TO DO)

Parameters
specSpec
targetTarget
modemode
void SetRCntHandler ( void(*)()  callback,
int  spec,
unsigned short  target 
)
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
void StartCARD ( void  )
int StartRCnt ( int  spec)

Start root counter (documentation TO DO)

Parameters
specSpec
Returns
TO DO
void StopCARD ( void  )
int StopRCnt ( int  spec)

Stop root counter (documentation TO DO)

Parameters
specSpec
Returns
TO DO
int* vblank_handler ( )

Variable Documentation

unsigned char padread_buf[2][8]
unsigned char psxsdkPadArr[PAD_READ_RAW_SIZE]
void(* rcnt_handler_callback)()
unsigned int rcnt_handler_evfield
const char* sysromver_unavail = "System ROM Version Unavailable"
void(* vblank_handler_callback)()