diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-07-30 00:53:31 +0200 |
|---|---|---|
| committer | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-07-30 00:53:31 +0200 |
| commit | 073a859acf16ccbc0f49364e38126bf2bf03aa3d (patch) | |
| tree | 90fac6072c5fe3ccee0505c881f89aa262d4eed7 | |
| parent | 0e755e9801a2dcf7b9827c90cc38e9f532d06393 (diff) | |
| download | psn00bsdk-073a859acf16ccbc0f49364e38126bf2bf03aa3d.tar.gz | |
Deprecate u_short, u_int and u_long types in libpsn00b
| -rw-r--r-- | examples/mdec/mdecimage/main.c | 2 | ||||
| -rw-r--r-- | examples/sound/vagsample/main.c | 61 | ||||
| -rw-r--r-- | examples/system/dynlink/library/balls.c | 2 | ||||
| -rw-r--r-- | examples/system/dynlink/main.c | 8 | ||||
| -rw-r--r-- | libpsn00b/include/lzp/lzp.h | 20 | ||||
| -rw-r--r-- | libpsn00b/include/lzp/lzqlp.h | 12 | ||||
| -rw-r--r-- | libpsn00b/include/psxapi.h | 156 | ||||
| -rw-r--r-- | libpsn00b/include/psxcd.h | 95 | ||||
| -rw-r--r-- | libpsn00b/include/psxgpu.h | 906 | ||||
| -rw-r--r-- | libpsn00b/include/psxgte.h | 54 | ||||
| -rw-r--r-- | libpsn00b/include/psxspu.h | 189 | ||||
| -rw-r--r-- | libpsn00b/lzp/crc.c | 29 | ||||
| -rw-r--r-- | libpsn00b/lzp/lzp.h | 20 | ||||
| -rw-r--r-- | libpsn00b/lzp/lzqlp.h | 12 | ||||
| -rw-r--r-- | libpsn00b/psxcd/isofs.c | 40 | ||||
| -rw-r--r-- | libpsn00b/psxcd/psxcd.c | 38 | ||||
| -rw-r--r-- | libpsn00b/psxgpu/common.c | 23 | ||||
| -rw-r--r-- | libpsn00b/psxgpu/env.c | 13 | ||||
| -rw-r--r-- | libpsn00b/psxgpu/font.c | 27 | ||||
| -rw-r--r-- | libpsn00b/psxgpu/image.c | 33 | ||||
| -rw-r--r-- | tools/lzpack/main.cpp | 8 |
21 files changed, 792 insertions, 956 deletions
diff --git a/examples/mdec/mdecimage/main.c b/examples/mdec/mdecimage/main.c index b59fdaf..1ad02d9 100644 --- a/examples/mdec/mdecimage/main.c +++ b/examples/mdec/mdecimage/main.c @@ -71,7 +71,7 @@ int main(int argc, const char* argv[]) { DecDCTout(slice, BLOCK_SIZE * SCREEN_YRES / 2); DecDCToutSync(0); - LoadImage(&rect, (u_long *) slice); + LoadImage(&rect, slice); DrawSync(0); } diff --git a/examples/sound/vagsample/main.c b/examples/sound/vagsample/main.c index 5764541..1ec3b8a 100644 --- a/examples/sound/vagsample/main.c +++ b/examples/sound/vagsample/main.c @@ -39,6 +39,7 @@ #include <psxpad.h> #include <psxapi.h> #include <psxspu.h> +#include <hwregs_c.h> extern const unsigned char proyt[]; extern const int proyt_size; @@ -158,27 +159,17 @@ int main(int argc, const char *argv[]) int counter,nextchan; int cross_pressed; int circle_pressed; - PADTYPE *pad; - SpuVoiceRaw voice; // Init stuff init(); - - // Set common values for the SpuVoiceRaw stuct - // Technically one struct can be used to play all sounds as the - // parameters are copied to the SPU registers - - voice.vol.left = 0x3FFE; // Left voice volume, 3FFEh = max - voice.vol.right = 0x3FFE; // Right voice volume, 3FFEh = max - voice.adsr_param = 0xdff18087; // ADSR parameters - + // Main loop counter = 0; nextchan = 0; cross_pressed = 0; circle_pressed = 0; - + while(1) { pad = (PADTYPE*)&pad_buff[0][0]; @@ -194,22 +185,24 @@ int main(int argc, const char *argv[]) if( !cross_pressed ) { // Voice frequency - // (400h = 11.25KHz, 1000h = 44.1KHz) - voice.freq = 0x800; + // (800h = 22.05KHz) + SPU_CH_FREQ(nextchan) = 0x800; // Voice start playback address // (transfer address / 8) - voice.addr = proyt_addr; + SPU_CH_ADDR(nextchan) = proyt_addr; // Voice loop address // (transfer address / 8) - voice.loop_addr = proyt_addr; - + SPU_CH_LOOP_ADDR(nextchan) = proyt_addr; + // Voice volume and envelope + SPU_CH_VOL_L(nextchan) = 0x3fff; + SPU_CH_VOL_R(nextchan) = 0x3fff; + SPU_CH_ADSR(nextchan) = 0x1fee80ff; + // Set voice to key-off to allow restart - SpuSetKey(0, 1<<nextchan); - // Set voice parameters - SpuSetVoiceRaw(nextchan, &voice); + SPU_KEY_OFF = 1 << nextchan; // Set voice to key-on - SpuSetKey(1, 1<<nextchan); - + SPU_KEY_ON = 1 << nextchan; + // Advance to next voice nextchan++; if( nextchan > 23 ) @@ -229,27 +222,29 @@ int main(int argc, const char *argv[]) if( !circle_pressed ) { // Voice frequency - // (400h = 11.25KHz, 1000h = 44.1KHz) - voice.freq = 0x1000; + // (1000h = 44.1KHz) + SPU_CH_FREQ(nextchan) = 0x1000; // Voice start playback address // (transfer address / 8) - voice.addr = tdfx_addr; + SPU_CH_ADDR(nextchan) = tdfx_addr; // Voice loop address // (transfer address / 8) - voice.loop_addr = tdfx_addr; - + SPU_CH_LOOP_ADDR(nextchan) = tdfx_addr; + // Voice volume and envelope + SPU_CH_VOL_L(nextchan) = 0x3fff; + SPU_CH_VOL_R(nextchan) = 0x3fff; + SPU_CH_ADSR(nextchan) = 0x1fee80ff; + // Set voice to key-off to allow restart - SpuSetKey(0, 1<<nextchan); - // Set voice parameters - SpuSetVoiceRaw(nextchan, &voice); + SPU_KEY_OFF = 1 << nextchan; // Set voice to key-on - SpuSetKey(1, 1<<nextchan); - + SPU_KEY_ON = 1 << nextchan; + // Advance to next voice nextchan++; if( nextchan > 23 ) nextchan = 0; - + circle_pressed = 1; } } diff --git a/examples/system/dynlink/library/balls.c b/examples/system/dynlink/library/balls.c index ef6993e..cfc7f58 100644 --- a/examples/system/dynlink/library/balls.c +++ b/examples/system/dynlink/library/balls.c @@ -38,7 +38,7 @@ static BALL_TYPE balls[MAX_BALLS]; static TIM_IMAGE ball_tim; void init(CONTEXT *ctx) { - GetTimInfo((u_long *) ball16c, &ball_tim); + GetTimInfo((const uint32_t *) ball16c, &ball_tim); LoadImage(ball_tim.prect, ball_tim.paddr); if (ball_tim.mode & 8) diff --git a/examples/system/dynlink/main.c b/examples/system/dynlink/main.c index 9b94b30..fff7aa5 100644 --- a/examples/system/dynlink/main.c +++ b/examples/system/dynlink/main.c @@ -108,13 +108,13 @@ void init_context(CONTEXT *ctx) { // Set up the ordering tables and primitive buffers. db = &(ctx->db[0]); ctx->db_nextpri = db->p; - ClearOTagR((u_long *) db->ot, OT_LEN); + ClearOTagR(db->ot, OT_LEN); PutDrawEnv(&(db->draw)); //PutDispEnv(&(db->disp)); db = &(ctx->db[1]); - ClearOTagR((u_long *) db->ot, OT_LEN); + ClearOTagR(db->ot, OT_LEN); // Create a text stream at the top of the screen. FntLoad(960, 0); @@ -130,14 +130,14 @@ void display(CONTEXT *ctx) { db = &(ctx->db[ctx->db_active]); ctx->db_nextpri = db->p; - ClearOTagR((u_long *) db->ot, OT_LEN); + ClearOTagR(db->ot, OT_LEN); PutDrawEnv(&(db->draw)); PutDispEnv(&(db->disp)); SetDispMask(1); db = &(ctx->db[!ctx->db_active]); - DrawOTag((u_long *) &(db->ot[OT_LEN - 1])); + DrawOTag(&(db->ot[OT_LEN - 1])); } /* Symbol overriding example */ diff --git a/libpsn00b/include/lzp/lzp.h b/libpsn00b/include/lzp/lzp.h index cfeeb72..456de02 100644 --- a/libpsn00b/include/lzp/lzp.h +++ b/libpsn00b/include/lzp/lzp.h @@ -16,7 +16,7 @@ #ifndef _LZPACK_H #define _LZPACK_H -#include <sys/types.h> +#include <stdint.h> #ifdef _WIN32 #include <windows.h> #endif @@ -64,9 +64,9 @@ typedef struct { //! File ID (must always be 'LZP') - char id[3]; + char id[3]; //! File count - u_char numFiles; + uint8_t numFiles; } LZP_HEAD; @@ -74,15 +74,15 @@ typedef struct { typedef struct { //! File name - char fileName[16]; + char fileName[16]; //! CRC32 checksum of file - u_int crc; + uint32_t crc; //! Original size of file in bytes - u_int fileSize; + uint32_t fileSize; //! Compressed size of file - u_int packedSize; + uint32_t packedSize; //! File data offset - u_int offset; + uint32_t offset; } LZP_FILE; @@ -162,7 +162,7 @@ void lzResetHashSizes(); * * \returns CRC16 hash of specified buffer. */ -unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc); +uint16_t lzCRC16(const void* buff, int bytes, uint16_t crc); /*! Calculates a CRC32 hash of the specified buffer. * @@ -172,7 +172,7 @@ unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc); * * \returns CRC32 hash of specified buffer. */ -unsigned int lzCRC32(const void* buff, int bytes, unsigned int crc); +uint32_t lzCRC32(const void* buff, int bytes, uint32_t crc); /*! @} */ diff --git a/libpsn00b/include/lzp/lzqlp.h b/libpsn00b/include/lzp/lzqlp.h index 5b70b40..32ce0d7 100644 --- a/libpsn00b/include/lzp/lzqlp.h +++ b/libpsn00b/include/lzp/lzqlp.h @@ -1,7 +1,7 @@ #ifndef _QLP_H #define _QLP_H -#include <sys/types.h> +#include <stdint.h> #ifdef _WIN32 #include <windows.h> #endif @@ -13,14 +13,14 @@ #define PACK_ERR_READ_FAULT -4 typedef struct { - char id[3]; - u_char numfiles; + char id[3]; + uint8_t numfiles; } QLP_HEAD; typedef struct { - char name[16]; - u_int size; - u_int offs; + char name[16]; + uint32_t size; + uint32_t offs; } QLP_FILE; int qlpFileCount(const QLP_HEAD* qlpfile); diff --git a/libpsn00b/include/psxapi.h b/libpsn00b/include/psxapi.h index 1298d29..1bdbdbf 100644 --- a/libpsn00b/include/psxapi.h +++ b/libpsn00b/include/psxapi.h @@ -1,5 +1,15 @@ -#ifndef __PSXAPI__ -#define __PSXAPI__ +/* + * PSn00bSDK kernel API library + * (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed + */ + +#ifndef __PSXAPI_H +#define __PSXAPI_H + +#include <stdint.h> +#include <stddef.h> + +/* Definitions */ #define DescHW 0xf0000000 #define DescSW 0xf4000000 @@ -32,29 +42,31 @@ #define RCntMdFR 0x0000 #define RCntMdGATE 0x0010 +/* Structure definitions */ + typedef struct { // Thread control block - int status; - int mode; + int status; + int mode; union { - unsigned int reg[37]; + uint32_t reg[37]; struct { - unsigned int zero, at; - unsigned int v0, v1; - unsigned int a0, a1, a2, a3; - unsigned int t0, t1, t2, t3, t4, t5, t6, t7; - unsigned int s0, s1, s2, s3, s4, s5, s6, s7; - unsigned int t8, t9; - unsigned int k0, k1; - unsigned int gp, sp, fp, ra; - - unsigned int cop0r14; - unsigned int hi; - unsigned int lo; - unsigned int cop0r12; - unsigned int cop0r13; + uint32_t zero, at; + uint32_t v0, v1; + uint32_t a0, a1, a2, a3; + uint32_t t0, t1, t2, t3, t4, t5, t6, t7; + uint32_t s0, s1, s2, s3, s4, s5, s6, s7; + uint32_t t8, t9; + uint32_t k0, k1; + uint32_t gp, sp, fp, ra; + + uint32_t cop0r14; + uint32_t hi; + uint32_t lo; + uint32_t cop0r12; + uint32_t cop0r13; }; }; - int _reserved[9]; + int _reserved[9]; } TCB; typedef struct { // Process control block @@ -85,17 +97,17 @@ typedef struct { // Device control block } DCB; typedef struct { // File control block - int status; - unsigned int diskid; - void *trns_addr; - unsigned int trns_len; - unsigned int filepos; - unsigned int flags; - unsigned int lasterr; - DCB *dcb; - unsigned int filesize; - unsigned int lba; - unsigned int fcbnum; + int status; + uint32_t diskid; + void *trns_addr; + uint32_t trns_len; + uint32_t filepos; + uint32_t flags; + uint32_t lasterr; + DCB *dcb; + uint32_t filesize; + uint32_t lba; + uint32_t fcbnum; } FCB; struct DIRENTRY { // Directory entry @@ -108,34 +120,31 @@ struct DIRENTRY { // Directory entry }; struct EXEC { - unsigned int pc0; - unsigned int gp0; - unsigned int t_addr; - unsigned int t_size; - unsigned int d_addr; - unsigned int d_size; - unsigned int b_addr; - unsigned int b_size; - unsigned int s_addr; - unsigned int s_size; - unsigned int sp,fp,rp,ret,base; + uint32_t pc0, gp0; + uint32_t t_addr, t_size; + uint32_t d_addr, d_size; + uint32_t b_addr, b_size; + uint32_t s_addr, s_size; + uint32_t sp, fp, rp, ret, base; }; struct JMP_BUF { - unsigned int ra, sp, fp; - unsigned int s0, s1, s2, s3, s4, s5, s6, s7; - unsigned int gp; + uint32_t ra, sp, fp; + uint32_t s0, s1, s2, s3, s4, s5, s6, s7; + uint32_t gp; }; // Not recommended to use these functions to install IRQ handlers typedef struct { - unsigned int* next; - unsigned int* func2; - unsigned int* func1; - unsigned int pad; + uint32_t *next; + uint32_t *func2; + uint32_t *func1; + int _reserved; } INT_RP; +/* API */ + #ifdef __cplusplus extern "C" { #endif @@ -143,30 +152,27 @@ extern "C" { void SysEnqIntRP(int pri, INT_RP *rp); void SysDeqIntRP(int pri, INT_RP *rp); -// Event handler stuff - -int OpenEvent(unsigned int cl, int spec, int mode, void (*func)()); -int CloseEvent(int ev_desc); -int EnableEvent(int ev_desc); -int DisableEvent(int ev_desc); - -// BIOS file functions +int OpenEvent(uint32_t cl, uint32_t spec, int mode, void (*func)()); +int CloseEvent(int event); +int WaitEvent(int event); +int TestEvent(int event); +int EnableEvent(int event); +int DisableEvent(int event); +void DeliverEvent(uint32_t cl, uint32_t spec); +void UnDeliverEvent(uint32_t cl, uint32_t spec); int open(const char *name, int mode); int close(int fd); -int seek(int fd, unsigned int offset, int mode); -int read(int fd, char *buff, unsigned int len); -int write(int fd, const char *buff, unsigned int len); +int seek(int fd, uint32_t offset, int mode); +int read(int fd, uint8_t *buff, size_t len); +int write(int fd, const uint8_t *buff, size_t len); int ioctl(int fd, int cmd, int arg); struct DIRENTRY *firstfile(const char *wildcard, struct DIRENTRY *entry); struct DIRENTRY *nextfile(struct DIRENTRY *entry); int erase(const char *name); int chdir(const char *path); -//#define delete( p ) erase( p ) // May conflict with delete operator in C++ -#define cd( p ) chdir( p ) // For compatibility - -// BIOS device functions +//#define cd(p) chdir(p) int AddDev(DCB *dcb); int DelDev(const char *name); @@ -175,18 +181,17 @@ void AddDummyTty(void); void EnterCriticalSection(void); void ExitCriticalSection(void); +void SwEnterCriticalSection(void); +void SwExitCriticalSection(void); -// BIOS CD functions void _InitCd(void); void _96_init(void); void _96_remove(void); -// BIOS pad functions -void InitPAD(char *buff1, int len1, char *buff2, int len2); +void InitPAD(uint8_t *buff1, int len1, uint8_t *buff2, int len2); void StartPAD(void); void StopPAD(void); -// BIOS memory card functions void InitCARD(int pad_enable); void StartCARD(void); void StopCARD(void); @@ -198,32 +203,31 @@ int _card_status(int chan); int _card_wait(int chan); int _card_clear(int chan); int _card_chan(void); -int _card_read(int chan, int sector, unsigned char *buf); -int _card_write(int chan, int sector, unsigned char *buf); +int _card_read(int chan, int sector, uint8_t *buf); +int _card_write(int chan, int sector, uint8_t *buf); void _new_card(void); -// Timers -int SetRCnt(int spec, unsigned short target, int mode); +int SetRCnt(int spec, uint16_t target, int mode); int GetRCnt(int spec); int StartRCnt(int spec); int StopRCnt(int spec); int ResetRCnt(int spec); -// BIOS IRQ acknowledge control void ChangeClearPAD(int mode); void ChangeClearRCnt(int t, int m); -// Executable functions +uint32_t OpenTh(uint32_t (*func)(), uint32_t sp, uint32_t gp); +int CloseTh(uint32_t thread); +int ChangeTh(uint32_t thread); + int Exec(struct EXEC *exec, int argc, char **argv); void FlushCache(void); -// BIOS setjmp functions void b_setjmp(struct JMP_BUF *buf); void b_longjmp(struct JMP_BUF *buf, int param); void SetDefaultExitFromException(void); void SetCustomExitFromException(struct JMP_BUF *buf); -// Misc functions int GetSystemInfo(int index); void *GetB0Table(void); void *GetC0Table(void); diff --git a/libpsn00b/include/psxcd.h b/libpsn00b/include/psxcd.h index 3336963..03ee792 100644 --- a/libpsn00b/include/psxcd.h +++ b/libpsn00b/include/psxcd.h @@ -1,7 +1,12 @@ -#ifndef _LIBPSXCD_H -#define _LIBPSXCD_H +/* + * PSn00bSDK CD-ROM drive library + * (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed + */ -#include <sys/types.h> +#ifndef __PSXCD_H +#define __PSXCD_H + +#include <stdint.h> /* * CD-ROM control commands @@ -74,18 +79,18 @@ #define CdlIsoInvalidFs 0x03 #define CdlIsoLidOpen 0x04 -#define btoi(b) ((b)/16*10+(b)%16) /* Convert BCD value to integer */ -#define itob(i) ((i)/10*16+(i)%10) /* Convert integer to BCD value */ +#define btoi(b) ((b)/16*10+(b)%16) /* Convert BCD value to integer */ +#define itob(i) ((i)/10*16+(i)%10) /* Convert integer to BCD value */ /* * CD-ROM disc location struct */ typedef struct _CdlLOC { - u_char minute; - u_char second; - u_char sector; - u_char track; + uint8_t minute; + uint8_t second; + uint8_t sector; + uint8_t track; } CdlLOC; /* @@ -93,10 +98,10 @@ typedef struct _CdlLOC */ typedef struct _CdlATV { - u_char val0; /* L -> SPU L */ - u_char val1; /* L -> SPU R */ - u_char val2; /* R -> SPU R */ - u_char val3; /* R -> SPU L */ + uint8_t val0; /* L -> SPU L */ + uint8_t val1; /* L -> SPU R */ + uint8_t val2; /* R -> SPU R */ + uint8_t val3; /* R -> SPU L */ } CdlATV; /* @@ -104,68 +109,68 @@ typedef struct _CdlATV */ typedef struct _CdlFILE { - CdlLOC pos; - u_long size; - char name[16]; + CdlLOC pos; + uint32_t size; + char name[16]; } CdlFILE; typedef struct _CdlFILTER { - u_char file; - u_char chan; - u_short pad; + uint8_t file; + uint8_t chan; + uint16_t pad; } CdlFILTER; /* Directory query context */ typedef void* CdlDIR; /* Data callback */ -typedef void (*CdlCB)(int, u_char *); +typedef void (*CdlCB)(int, uint8_t *); #ifdef __cplusplus extern "C" { #endif -int CdInit(void); +int CdInit(void); -CdlLOC* CdIntToPos(int i, CdlLOC *p); -int CdPosToInt(CdlLOC *p); -int CdGetToc(CdlLOC *toc); +CdlLOC* CdIntToPos(int i, CdlLOC *p); +int CdPosToInt(CdlLOC *p); +int CdGetToc(CdlLOC *toc); -int CdControl(u_char com, const void *param, u_char *result); -int CdControlB(u_char com, const void *param, u_char *result); -int CdControlF(u_char com, const void *param); -int CdSync(int mode, u_char *result); -u_long CdSyncCallback(CdlCB func); +int CdControl(uint8_t com, const void *param, uint8_t *result); +int CdControlB(uint8_t com, const void *param, uint8_t *result); +int CdControlF(uint8_t com, const void *param); +int CdSync(int mode, uint8_t *result); +uint32_t CdSyncCallback(CdlCB func); -long CdReadyCallback(CdlCB func); -int CdGetSector(void *madr, int size); +long CdReadyCallback(CdlCB func); +int CdGetSector(void *madr, int size); CdlFILE* CdSearchFile(CdlFILE *loc, const char *filename); -int CdRead(int sectors, u_long *buf, int mode); -int CdReadSync(int mode, u_char *result); -u_long CdReadCallback(CdlCB func); +int CdRead(int sectors, uint32_t *buf, int mode); +int CdReadSync(int mode, uint8_t *result); +uint32_t CdReadCallback(CdlCB func); -int CdStatus(void); -int CdMode(void); +int CdStatus(void); +int CdMode(void); -int CdMix(CdlATV *vol); +int CdMix(CdlATV *vol); /* ORIGINAL CODE */ -CdlDIR* CdOpenDir(const char* path); -int CdReadDir(CdlDIR* dir, CdlFILE* file); -void CdCloseDir(CdlDIR* dir); +CdlDIR* CdOpenDir(const char* path); +int CdReadDir(CdlDIR* dir, CdlFILE* file); +void CdCloseDir(CdlDIR* dir); -int CdGetVolumeLabel(char* label); +int CdGetVolumeLabel(char* label); -long* CdAutoPauseCallback(void(*func)()); -int CdIsoError(); +long* CdAutoPauseCallback(void(*func)()); +int CdIsoError(); -int CdLoadSession(int session); +int CdLoadSession(int session); #ifdef __cplusplus } #endif -#endif /* _LIBPSXCD_H */ +#endif diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h index 53a24c9..f1e5da8 100644 --- a/libpsn00b/include/psxgpu.h +++ b/libpsn00b/include/psxgpu.h @@ -1,642 +1,518 @@ +/* + * PSn00bSDK GPU library + * (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed + */ + #ifndef __PSXGPU_H #define __PSXGPU_H +#include <stdint.h> #include <stddef.h> -#include <sys/types.h> - -// Low-level display parameters for DISPENV_RAW. A leftover from prototyping -#define DISP_WIDTH_256 0 -#define DISP_WIDTH_320 1 -#define DISP_WIDTH_384 64 -#define DISP_WIDTH_512 2 -#define DISP_WIDTH_640 3 - -#define DISP_HEIGHT_LOW 0 // Could be 240 for NTSC, 256 for PAL -#define DISP_HEIGHT_HIGH 4 // Could be 480 for NTSC, 512 for PAL -#define DISP_INTERLACE 32 -#define DISP_24BIT_COLOR 16 -#define DISP_MODE_NTSC 0 -#define DISP_MODE_PAL 8 - -typedef enum _VIDEO_MODE -{ + +/* Definitions */ + +typedef enum _GPU_DispFlags { + DISP_WIDTH_256 = 0, + DISP_WIDTH_320 = 1, + DISP_WIDTH_512 = 2, + DISP_WIDTH_640 = 3, + DISP_HEIGHT_HIGH = 1 << 2, + DISP_MODE_PAL = 1 << 3, + DISP_24BIT_COLOR = 1 << 4, + DISP_INTERLACE = 1 << 5, + DISP_WIDTH_384 = 1 << 6 +} GPU_DispFlags; + +typedef enum _GPU_VideoMode { MODE_NTSC = 0, MODE_PAL = 1 -} VIDEO_MODE; +} GPU_VideoMode; -// Vector macros +/* Structure macros */ -#define setVector( v, _x, _y, _z ) \ +#define setVector(v, _x, _y, _z) \ (v)->vx = _x, (v)->vy = _y, (v)->vz = _z -#define setRECT( v, _x, _y, _w, _h ) \ +#define setRECT(v, _x, _y, _w, _h) \ (v)->x = _x, (v)->y = _y, (v)->w = _w, (v)->h = _h +#define setTPage(p, tp, abr, x, y) ((p)->tpage = getTPage(tp, abr, x, y)) +#define setClut(p, x, y) ((p)->clut = getClut(x, y)) -// Primitive macros - -#define setDrawTPage( p, dfe, dtd, tpage ) \ - ( (p)->code[0] = tpage|(dfe<<10)|(dtd<<9), \ - setlen( p, 1 ), setcode( p, 0xe1 ) ) - -/*#define setVram2Vram( p ) ( setlen( p, 8 ), setcode( p, 0x80 ), \ - (p)->nop[0] = 0, (p)->nop[1] = 0, (p)->nop[2] = 0, (p)->nop[3] = 0 )*/ - -/* - -#define setTPagePri2( p, dth, tp, abr, x, y ) \ - ( (p)->code[0] = getTPage( tp, abr, x, y )|(dth<<9), \ - setlen( p, 1 ), setcode( p, 0xe1 ) )*/ - -/* - * Set primitive attributes - */ -#define setTPage( p, tp, abr, x, y ) \ - ( (p)->tpage = getTPage( tp, abr, x, y ) ) - -#define setClut( p, x, y ) \ - ( (p)->clut = getClut(x, y) ) - - -/* - * Set primitive colors - */ -#define setRGB0( p, r, g, b ) ( (p)->r0 = r, (p)->g0 = g, (p)->b0 = b ) -#define setRGB1( p, r, g, b ) ( (p)->r1 = r, (p)->g1 = g, (p)->b1 = b ) -#define setRGB2( p, r, g, b ) ( (p)->r2 = r, (p)->g2 = g, (p)->b2 = b ) -#define setRGB3( p, r, g, b ) ( (p)->r3 = r, (p)->g3 = g, (p)->b3 = b ) - +#define setRGB0(p, r, g, b) ((p)->r0 = r, (p)->g0 = g, (p)->b0 = b) +#define setRGB1(p, r, g, b) ((p)->r1 = r, (p)->g1 = g, (p)->b1 = b) +#define setRGB2(p, r, g, b) ((p)->r2 = r, (p)->g2 = g, (p)->b2 = b) +#define setRGB3(p, r, g, b) ((p)->r3 = r, (p)->g3 = g, (p)->b3 = b) -/* - * Set primitive screen coordinates - */ -#define setXY0( p, _x0, _y0 ) \ +#define setXY0(p, _x0, _y0) \ (p)->x0 = _x0, (p)->y0 = _y0 -#define setXY2( p, _x0, _y0, _x1, _y1 ) \ +#define setXY2(p, _x0, _y0, _x1, _y1) \ (p)->x0 = _x0, (p)->y0 = _y0, \ (p)->x1 = _x1, (p)->y1 = _y1 - -#define setXY3( p, _x0, _y0, _x1, _y1, _x2, _y2 ) \ + +#define setXY3(p, _x0, _y0, _x1, _y1, _x2, _y2) \ (p)->x0 = _x0, (p)->y0 = _y0, \ (p)->x1 = _x1, (p)->y1 = _y1, \ (p)->x2 = _x2, (p)->y2 = _y2 -#define setXY4( p, _x0, _y0, _x1, _y1, _x2, _y2, _x3, _y3 ) \ +#define setXY4(p, _x0, _y0, _x1, _y1, _x2, _y2, _x3, _y3) \ (p)->x0 = _x0, (p)->y0 = _y0, \ (p)->x1 = _x1, (p)->y1 = _y1, \ (p)->x2 = _x2, (p)->y2 = _y2, \ (p)->x3 = _x3, (p)->y3 = _y3 -#define setWH( p, _w, _h ) \ +#define setWH(p, _w, _h) \ (p)->w = _w, (p)->h = _h -#define setXYWH( p, _x0, _y0, _w, _h ) \ - (p)->x0 = _x0, (p)->y0 = _y0, \ - (p)->x1 = _x0+(_w), (p)->y1 = _y0, \ - (p)->x2 = _x0, (p)->y2 = _y0+(_h), \ - (p)->x3 = _x0+(_w), (p)->y3 = _y0+(_h) +#define setXYWH(p, _x0, _y0, _w, _h) \ + (p)->x0 = _x0, (p)->y0 = _y0, \ + (p)->x1 = (_x0 + (_w)), (p)->y1 = _y0, \ + (p)->x2 = _x0, (p)->y2 = (_y0 + (_h)), \ + (p)->x3 = (_x0 + (_w)), (p)->y3 = (_y0 + (_h)) -/* - * Set texture coordinates - */ -#define setUV0( p, _u0, _v0 ) \ +#define setUV0(p, _u0, _v0) \ (p)->u0 = _u0, (p)->v0 = _v0 -#define setUV3( p, _u0, _v0, _u1, _v1, _u2, _v2 ) \ - (p)->u0 = _u0, (p)->v0 = _v0, \ - (p)->u1 = _u1, (p)->v1 = _v1, \ +#define setUV3(p, _u0, _v0, _u1, _v1, _u2, _v2) \ + (p)->u0 = _u0, (p)->v0 = _v0, \ + (p)->u1 = _u1, (p)->v1 = _v1, \ (p)->u2 = _u2, (p)->v2 = _v2 -#define setUV4( p, _u0, _v0, _u1, _v1, _u2, _v2, _u3, _v3 ) \ - (p)->u0 = _u0, (p)->v0 = _v0, \ - (p)->u1 = _u1, (p)->v1 = _v1, \ - (p)->u2 = _u2, (p)->v2 = _v2, \ +#define setUV4(p, _u0, _v0, _u1, _v1, _u2, _v2, _u3, _v3) \ + (p)->u0 = _u0, (p)->v0 = _v0, \ + (p)->u1 = _u1, (p)->v1 = _v1, \ + (p)->u2 = _u2, (p)->v2 = _v2, \ (p)->u3 = _u3, (p)->v3 = _v3 -#define setUVWH( p, _u0, _v0, _w, _h ) \ - (p)->u0 = _u0, (p)->v0 = _v0, \ - (p)->u1 = _u0+(_w), (p)->v1 = _v0, \ - (p)->u2 = _u0, (p)->v2 = _v0+(_h), \ - (p)->u3 = _u0+(_w), (p)->v3 = _v0+(_h) - - -/* - * Primitive handling macros - */ -#define setlen( p, _len ) ( ((P_TAG*)(p))->len = (unsigned char)(_len) ) -#define setaddr( p, _addr ) ( ((P_TAG*)(p))->addr = (unsigned int)(_addr) ) -#define setcode( p, _code ) ( ((P_TAG*)(p))->code = (unsigned char)(_code) ) - -#define getlen( p ) ( ((P_TAG*)(p))->len ) -#define getaddr( p ) ( ((P_TAG*)(p))->addr ) -#define getcode( p ) ( ((P_TAG*)(p))->code ) - -#define nextPrim( p ) (void*)((((P_TAG*)(p))->addr)|0x80000000) -#define isendprim( p ) ((((P_TAG*)(p))->addr)==0xffffff) - -#define addPrim( ot, p ) setaddr( p, getaddr( ot ) ), setaddr( ot, p ) -#define addPrims( ot, p0, p1 ) setaddr( p1, getaddr( ot ) ), setaddr( ot, p0 ) - -#define catPrim( p0, p1 ) setaddr( p0, p1 ) -#define termPrim( p ) setaddr( p, 0xffffff ) - -#define setSemiTrans( p, abe ) \ - ( (abe)?setcode( p, getcode( p )|0x2 ):setcode( p, getcode( p )&~0x2 ) ) - -#define setShadeTex( p, tge ) \ - ( (tge)?setcode( p, getcode( p )|0x1 ):setcode( p, getcode( p )&~0x1 ) ) - - -/* ORIGINAl CODE */ -#define setDrawMask( p, sb, mt ) \ - setlen( p, 1 ), (p)->code[0] = sb|(mt<<1), \ - setcode( p, 0xe6 ) - - -#define getTPage( tp, abr, x, y ) \ - ( (((x)&0x3ff)>>6) | (((y)>>8)<<4) | (((abr)&0x3)<<5) | (((tp)&0x3)<<7) ) - -#define getClut( x, y ) \ - ( ((y)<<6)|(((x)>>4)&0x3f) ) - - -/* - * Primitive initializers - */ -#define setPolyF3( p ) setlen( p, 4 ), setcode( p, 0x20 ) -#define setPolyFT3( p ) setlen( p, 7 ), setcode( p, 0x24 ) -#define setPolyG3( p ) setlen( p, 6 ), setcode( p, 0x30 ) -#define setPolyGT3( p ) setlen( p, 9 ), setcode( p, 0x34 ) - -#define setPolyF4( p ) setlen( p, 5 ), setcode( p, 0x28 ) -#define setPolyFT4( p ) setlen( p, 9 ), setcode( p, 0x2c ) -#define setPolyG4( p ) setlen( p, 8 ), setcode( p, 0x38 ) -#define setPolyGT4( p ) setlen( p, 12 ), setcode( p, 0x3c ) - -#define setSprt8( p ) setlen( p, 3 ), setcode( p, 0x74 ) -#define setSprt16( p ) setlen( p, 3 ), setcode( p, 0x7c ) -#define setSprt( p ) setlen( p, 4 ), setcode( p, 0x64 ) - -#define setTile1( p ) setlen( p, 2 ), setcode( p, 0x68 ) -#define setTile8( p ) setlen( p, 2 ), setcode( p, 0x70 ) -#define setTile16( p ) setlen( p, 2 ), setcode( p, 0x78 ) -#define setTile( p ) setlen( p, 3 ), setcode( p, 0x60 ) - -#define setLineF2( p ) setlen( p, 3 ), setcode( p, 0x40 ) -#define setLineG2( p ) setlen( p, 4 ), setcode( p, 0x50 ) - -#define setLineF3( p ) setlen( p, 5 ), setcode( p, 0x48 ), (p)->pad = 0x55555555 -#define setLineG3( p ) setlen( p, 7 ), setcode( p, 0x58 ), (p)->pad = 0x55555555, \ - (p)->p1 = 0, (p)->p2 = 0 - -#define setLineF4( p ) setlen( p, 6 ), setcode( p, 0x4c ), (p)->pad = 0x55555555 -#define setLineG4( p ) setlen( p, 9 ), setcode( p, 0x5c ), (p)->pad = 0x55555555, \ - (p)->p1 = 0, (p)->p2 = 0, (p)->p3 = 0 - -#define setFill( p ) setlen( p, 3 ), setcode( p, 0x02 ) - -#define setDrawOffset( p, _x, _y ) \ - setlen( p, 1 ), \ - (p)->code[0] = (_x&0x3FF)|((_y&0x3FF)<<11), \ - ((char*)(p)->code)[3] = 0xE5 - -#define setDrawArea( p, r ) \ - setlen( p, 2 ), \ - (p)->code[0] = ((r)->x&0x3FF)|(((r)->y&0x1FF)<<10), \ - (p)->code[1] = (((r)->x+(r)->w-1)&0x3FF)|((((r)->y+(r)->h-1)&0x1FF)<<10), \ - ((char*)&(p)->code[0])[3] = 0xE3, \ - ((char*)&(p)->code[1])[3] = 0xE4 - -#define setTexWindow( p, r ) \ - setlen( p, 1 ), \ - (p)->code[0] = ((r)->w&0x1F)|(((r)->h&0x1F)<<5)|(((r)->x&0x1F)<<10)|(((r)->y&0x1F)<<15), \ - ((char*)&(p)->code[0])[3] = 0xE2 - -/* - * Primitive definitions - */ -typedef struct _P_TAG -{ - unsigned addr:24; - unsigned len:8; - u_char r,g,b,code; +#define setUVWH(p, _u0, _v0, _w, _h) \ + (p)->u0 = _u0, (p)->v0 = _v0, \ + (p)->u1 = (_u0 + (_w)), (p)->v1 = _v0, \ + (p)->u2 = _u0, (p)->v2 = (_v0 + (_h)), \ + (p)->u3 = (_u0 + (_w)), (p)->v3 = (_v0 + (_h)) + +/* Primitive handling macros */ + +#define setlen(p, _len) (((P_TAG *) (p))->len = (uint8_t) (_len)) +#define setaddr(p, _addr) (((P_TAG *) (p))->addr = (uint32_t) (_addr)) +#define setcode(p, _code) (((P_TAG *) (p))->code = (uint8_t) (_code)) +#define getlen(p) (((P_TAG *) (p))->len) +#define getaddr(p) (((P_TAG *) (p))->addr) +#define getcode(p) (((P_TAG *) (p))->code) + +#define nextPrim(p) (void *) (0x80000000 | (((P_TAG *) (p))->addr)) +#define isendprim(p) ((((P_TAG *) (p))->addr) == 0xffffff) +#define addPrim(ot, p) setaddr(p, getaddr(ot)), setaddr(ot, p) +#define addPrims(ot, a, b) setaddr(b, getaddr(ot)), setaddr(ot, a) +#define catPrim(a, b) setaddr(a, b) +#define termPrim(p) setaddr(p, 0xffffff) + +#define setSemiTrans(p, abe) \ + ((abe) ? (getcode(p) |= 2) : (getcode(p) &= ~2)) + +#define setShadeTex(p, tge) \ + ((tge) ? (getcode(p) |= 1) : (getcode(p) &= ~1)) + +#define getTPage(tp, abr, x, y) \ + ((((x) & 0x3ff) >> 6) | (((y) >> 8) << 4) | (((abr) & 3) << 5) | (((tp) & 3) << 7)) + +#define getClut(x, y) (((y) << 6) | (((x) >> 4) & 0x3f)) + +/* Primitive initializer macros */ + +#define setPolyF3(p) setlen(p, 4), setcode(p, 0x20) +#define setPolyFT3(p) setlen(p, 7), setcode(p, 0x24) +#define setPolyG3(p) setlen(p, 6), setcode(p, 0x30) +#define setPolyGT3(p) setlen(p, 9), setcode(p, 0x34) +#define setPolyF4(p) setlen(p, 5), setcode(p, 0x28) +#define setPolyFT4(p) setlen(p, 9), setcode(p, 0x2c) +#define setPolyG4(p) setlen(p, 8), setcode(p, 0x38) +#define setPolyGT4(p) setlen(p, 12), setcode(p, 0x3c) +#define setSprt8(p) setlen(p, 3), setcode(p, 0x74) +#define setSprt16(p) setlen(p, 3), setcode(p, 0x7c) +#define setSprt(p) setlen(p, 4), setcode(p, 0x64) +#define setTile1(p) setlen(p, 2), setcode(p, 0x68) +#define setTile8(p) setlen(p, 2), setcode(p, 0x70) +#define setTile16(p) setlen(p, 2), setcode(p, 0x78) +#define setTile(p) setlen(p, 3), setcode(p, 0x60) +#define setLineF2(p) setlen(p, 3), setcode(p, 0x40) +#define setLineG2(p) setlen(p, 4), setcode(p, 0x50) +#define setLineF3(p) setlen(p, 5), setcode(p, 0x48), \ + (p)->pad = 0x55555555 +#define setLineG3(p) setlen(p, 7), setcode(p, 0x58), \ + (p)->pad = 0x55555555, (p)->p1 = 0, (p)->p2 = 0 +#define setLineF4(p) setlen(p, 6), setcode(p, 0x4c), \ + (p)->pad = 0x55555555 +#define setLineG4(p) setlen(p, 9), setcode(p, 0x5c), \ + (p)->pad = 0x55555555, (p)->p1 = 0, (p)->p2 = 0, (p)->p3 = 0 +#define setFill(p) setlen(p, 3), setcode(p, 0x02) +#define setVram2Vram(p) setlen(p, 8), setcode(p, 0x80), \ + (p)->pad[0] = 0, (p)->pad[1] = 0, (p)->pad[2] = 0, (p)->pad[3] = 0 + +#define setDrawTPage(p, dfe, dtd, tpage) \ + setlen(p, 1), \ + (p)->code[0] = 0xe1000000 | tpage | (dfe << 10) | (dtd << 9) + +#define setDrawOffset(p, _x, _y) \ + setlen(p, 1), \ + (p)->code[0] = 0xe5000000 | (_x & 0x3ff) | ((_y & 0x3ff) << 11) + +#define setDrawMask(p, sb, mt) \ + setlen(p, 1), \ + (p)->code[0] = 0xe6000000 | sb | (mt << 1) + +#define setDrawArea(p, r) \ + setlen(p, 2), \ + (p)->code[0] = 0xe3000000 | ((r)->x & 0x3ff) | (((r)->y & 0x1ff) << 10), \ + (p)->code[1] = 0xe4000000 | (((r)->x + (r)->w - 1) & 0x3ff) | ((((r)->y + (r)->h - 1) & 0x1ff) << 10) + +#define setTexWindow(p, r) \ + setlen(p, 1), \ + (p)->code[0] = 0xe2000000 | ((r)->w & 0x1f) | (((r)->h & 0x1f) << 5) | (((r)->x & 0x1f) << 10) | (((r)->y & 0x1f) << 15) + +/* Primitive structure definitions */ + +typedef struct _P_TAG { + uint32_t addr:24; + uint32_t len:8; + uint8_t r, g, b, code; } P_TAG; -/* - * Polygon primitive definitions - */ -typedef struct _POLY_F3 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - short x1,y1; - short x2,y2; +typedef struct _POLY_F3 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + int16_t x1, y1; + int16_t x2, y2; } POLY_F3; -typedef struct _POLY_F4 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - short x1,y1; - short x2,y2; - short x3,y3; +typedef struct _POLY_F4 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + int16_t x1, y1; + int16_t x2, y2; + int16_t x3, y3; } POLY_F4; -typedef struct _POLY_FT3 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char u0,v0; - u_short clut; - short x1,y1; - u_char u1,v1; - u_short tpage; - short x2,y2; - u_char u2,v2; - u_short pad; +typedef struct _POLY_FT3 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t u0, v0; + uint16_t clut; + int16_t x1, y1; + uint8_t u1, v1; + uint16_t tpage; + int16_t x2, y2; + uint8_t u2, v2; + uint16_t pad; } POLY_FT3; -typedef struct _POLY_FT4 -{ - u_long tag; - u_char r0,g0,b0,code; - u_short x0,y0; - u_char u0,v0; - u_short clut; - short x1,y1; - u_char u1,v1; - u_short tpage; - short x2,y2; - u_char u2,v2; - u_short pad0; - short x3,y3; - u_char u3,v3; - u_short pad1; +typedef struct _POLY_FT4 { + uint32_t tag; + uint8_t r0, g0, b0, code; + uint16_t x0, y0; + uint8_t u0, v0; + uint16_t clut; + int16_t x1, y1; + uint8_t u1, v1; + uint16_t tpage; + int16_t x2, y2; + uint8_t u2, v2; + uint16_t pad0; + int16_t x3, y3; + uint8_t u3, v3; + uint16_t pad1; } POLY_FT4; -typedef struct _POLY_G3 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char r1,g1,b1,pad0; - short x1,y1; - u_char r2,g2,b2,pad1; - short x2,y2; +typedef struct _POLY_G3 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t r1, g1, b1, pad0; + int16_t x1, y1; + uint8_t r2, g2, b2, pad1; + int16_t x2, y2; } POLY_G3; -typedef struct _POLY_G4 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char r1,g1,b1,pad0; - short x1,y1; - u_char r2,g2,b2,pad1; - short x2,y2; - u_char r3,g3,b3,pad2; - short x3,y3; +typedef struct _POLY_G4 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t r1, g1, b1, pad0; + int16_t x1, y1; + uint8_t r2, g2, b2, pad1; + int16_t x2, y2; + uint8_t r3, g3, b3, pad2; + int16_t x3, y3; } POLY_G4; -typedef struct _POLY_GT3 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char u0,v0; - u_short clut; - u_char r1,g1,b1,pad0; - short x1,y1; - u_char u1,v1; - u_short tpage; - u_char r2,g2,b2,pad1; - short x2,y2; - u_char u2,v2; - u_short pad2; +typedef struct _POLY_GT3 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t u0, v0; + uint16_t clut; + uint8_t r1, g1, b1, pad0; + int16_t x1, y1; + uint8_t u1, v1; + uint16_t tpage; + uint8_t r2, g2, b2, pad1; + int16_t x2, y2; + uint8_t u2, v2; + uint16_t pad2; } POLY_GT3; -typedef struct _POLY_GT4 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char u0,v0; - u_short clut; - u_char r1,g1,b1,pad0; - short x1,y1; - u_char u1,v1; - u_short tpage; - u_char r2,g2,b2,pad1; - short x2,y2; - u_char u2,v2; - u_short pad2; - u_char r3,g3,b3,pad3; - short x3,y3; - u_char u3,v3; - u_short pad4; +typedef struct _POLY_GT4 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t u0, v0; + uint16_t clut; + uint8_t r1, g1, b1, pad0; + int16_t x1, y1; + uint8_t u1, v1; + uint16_t tpage; + uint8_t r2, g2, b2, pad1; + int16_t x2, y2; + uint8_t u2, v2; + uint16_t pad2; + uint8_t r3, g3, b3, pad3; + int16_t x3, y3; + uint8_t u3, v3; + uint16_t pad4; } POLY_GT4; -/* - * Line primitive definitions - */ -typedef struct _LINE_F2 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - short x1,y1; +typedef struct _LINE_F2 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + int16_t x1, y1; } LINE_F2; -typedef struct _LINE_G2 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char r1,g1,b1,p1; - short x1,y1; +typedef struct _LINE_G2 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t r1, g1, b1, p1; + int16_t x1, y1; } LINE_G2; -typedef struct _LINE_F3 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - short x1,y1; - short x2,y2; - u_long pad; /* actually a terminator for line loops */ +typedef struct _LINE_F3 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + int16_t x1, y1; + int16_t x2, y2; + uint32_t pad; } LINE_F3; -typedef struct _LINE_G3 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char r1,g1,b1,p1; - short x1,y1; - u_char r2,g2,b2,p2; - short x2,y2; - u_long pad; /* actually a terminator for line loops */ +typedef struct _LINE_G3 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t r1, g1, b1, p1; + int16_t x1, y1; + uint8_t r2, g2, b2, p2; + int16_t x2, y2; + uint32_t pad; } LINE_G3; -typedef struct _LINE_F4 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - short x1,y1; - short x2,y2; - short x3,y3; - u_long pad; +typedef struct _LINE_F4 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + int16_t x1, y1; + int16_t x2, y2; + int16_t x3, y3; + uint32_t pad; } LINE_F4; -typedef struct _LINE_G4 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char r1,g1,b1,p1; - short x1,y1; - u_char r2,g2,b2,p2; - short x2,y2; - u_char r3,g3,b3,p3; - short x3,y3; - u_long pad; +typedef struct _LINE_G4 { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t r1, g1, b1, p1; + int16_t x1, y1; + uint8_t r2, g2, b2, p2; + int16_t x2, y2; + uint8_t r3, g3, b3, p3; + int16_t x3, y3; + uint32_t pad; } LINE_G4; -/* - * Tile and sprite primitive definitions - */ -typedef struct _TILE -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - short w,h; +typedef struct _TILE { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + int16_t w, h; } TILE; -typedef struct _TILE_1 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; -} TILE_1; - -typedef struct _TILE_8 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; -} TILE_8; - -typedef struct _TILE_16 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; -} TILE_16; - -/* - * Sprite primitive definitions - */ -typedef struct _SPRT -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char u0,v0; - u_short clut; - u_short w,h; +struct _TILE_FIXED { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; +}; +typedef struct _TILE_FIXED TILE_1; +typedef struct _TILE_FIXED TILE_8; +typedef struct _TILE_FIXED TILE_16; + +typedef struct _SPRT { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t u0, v0; + uint16_t clut; + uint16_t w, h; } SPRT; -typedef struct _SPRT_8 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char u0,v0; - u_short clut; -} SPRT_8; - -typedef struct _SPRT_16 -{ - u_long tag; - u_char r0,g0,b0,code; - short x0,y0; - u_char u0,v0; - u_short clut; -} SPRT_16; - -/* - * VRAM fill and transfer primitive definitions - */ - -typedef struct _DR_ENV -{ - u_long tag; - u_long code[15]; +struct _SPRT_FIXED { + uint32_t tag; + uint8_t r0, g0, b0, code; + int16_t x0, y0; + uint8_t u0, v0; + uint16_t clut; +}; +typedef struct _SPRT_FIXED SPRT_8; +typedef struct _SPRT_FIXED SPRT_16; + +typedef struct _DR_ENV { + uint32_t tag; + uint32_t code[15]; } DR_ENV; -typedef struct _DR_AREA -{ - u_long tag; - u_long code[2]; +typedef struct _DR_AREA { + uint32_t tag; + uint32_t code[2]; } DR_AREA; -typedef struct _DR_OFFSET -{ - u_long tag; - u_long code[1]; +typedef struct _DR_OFFSET { + uint32_t tag; + uint32_t code[1]; } DR_OFFSET; -typedef struct _DR_TWIN -{ - u_long tag; - u_long code[2]; +typedef struct _DR_TWIN { + uint32_t tag; + uint32_t code[2]; } DR_TWIN; -typedef struct _DR_TPAGE -{ - u_long tag; - u_long code[1]; +typedef struct _DR_TPAGE { + uint32_t tag; + uint32_t code[1]; } DR_TPAGE; -typedef struct _DR_MASK /* ORIGINAL */ -{ - u_long tag; - u_long code[1]; +typedef struct _DR_MASK { + uint32_t tag; + uint32_t code[1]; } DR_MASK; -typedef struct _FILL /* ORIGINAL */ -{ - u_long tag; - u_char r0,g0,b0,code; - u_short x0,y0; // Note: coordinates must be in 16 pixel steps - u_short w,h; +typedef struct _FILL { + uint32_t tag; + uint8_t r0, g0, b0, code; + uint16_t x0, y0; // Note: coordinates must be in 16 pixel steps + uint16_t w, h; } FILL; -typedef struct _VRAM2VRAM /* ORIGINAL */ -{ - u_long tag; - u_char p0,p1,p2,code; - u_short x0,y0; - u_short x1,y1; - u_short w,h; - u_long nop[4]; +typedef struct _VRAM2VRAM { + uint32_t tag; + uint8_t p0, p1, p2, code; + uint16_t x0, y0; + uint16_t x1, y1; + uint16_t w, h; + uint32_t pad[4]; } VRAM2VRAM; -/* - * General structs - */ +/* Structure definitions */ -typedef struct _RECT -{ - short x,y; - short w,h; +typedef struct _RECT { + int16_t x, y, w, h; } RECT; -typedef struct _DISPENV_RAW /* obsolete */ -{ - unsigned int vid_mode; // Video mode - short vid_xpos,vid_ypos; // Video position (not framebuffer) - short fb_x,fb_y; // Framebuffer display position +typedef struct _DISPENV_RAW { + uint32_t vid_mode; + int16_t vid_xpos, vid_ypos; + int16_t fb_x, fb_y; } DISPENV_RAW; -typedef struct _DISPENV -{ - RECT disp; - RECT screen; - char isinter; - char isrgb24; - char reverse; - char pad; +typedef struct _DISPENV { + RECT disp, screen; + uint8_t isinter, isrgb24, reverse; + uint8_t _reserved; } DISPENV; -typedef struct _DRAWENV -{ - RECT clip; // Drawing area - short ofs[2]; // GPU draw offset (relative to draw area) - RECT tw; // Texture window (doesn't do anything atm) - u_short tpage; // Initial tpage value - u_char dtd; // Dither processing flag (simply OR'ed to tpage) - u_char dfe; // Drawing to display area blocked/allowed (simply OR'ed to tpage) - u_char isbg; // Clear draw area if non-zero - u_char r0,g0,b0; // Draw area clear color (if isbg iz nonzero) - DR_ENV dr_env; // Draw mode packet area (used by PutDrawEnv) +typedef struct _DRAWENV { + RECT clip; // Drawing area + int16_t ofs[2]; // GPU draw offset (relative to draw area) + RECT tw; // Texture window (doesn't do anything atm) + uint16_t tpage; // Initial tpage value + uint8_t dtd; // Dither processing flag (simply OR'ed to tpage) + uint8_t dfe; // Drawing to display area blocked/allowed (simply OR'ed to tpage) + uint8_t isbg; // Clear draw area if non-zero + uint8_t r0, g0, b0; // Draw area clear color (if isbg iz nonzero) + DR_ENV dr_env; // Draw mode packet area (used by PutDrawEnv) } DRAWENV; -typedef struct _TIM_IMAGE -{ - u_long mode; - RECT *crect; - u_long *caddr; - RECT *prect; - u_long *paddr; +typedef struct _TIM_IMAGE { + uint32_t mode; + RECT *crect; + uint32_t *caddr; + RECT *prect; + uint32_t *paddr; } TIM_IMAGE; -typedef struct _GsIMAGE -{ - u_long pmode; - short px, py, pw, ph; - u_long *pixel; - short cx, cy, cw, ch; - u_long *clut; +typedef struct _GsIMAGE { + uint32_t pmode; + int16_t px, py, pw, ph; + uint32_t *pixel; + int16_t cx, cy, cw, ch; + uint32_t *clut; } GsIMAGE; +/* Public API */ + #ifdef __cplusplus extern "C" { #endif -// Function definitions - void ResetGraph(int mode); -VIDEO_MODE GetVideoMode(void); -void SetVideoMode(VIDEO_MODE mode); - -int GetODE(void); +GPU_VideoMode GetVideoMode(void); +void SetVideoMode(GPU_VideoMode mode); +void SetDispMask(int mask); -void PutDispEnvRaw(const DISPENV_RAW *env); /* obsolete */ +//void PutDispEnvRaw(const DISPENV_RAW *env); void PutDispEnv(const DISPENV *env); void PutDrawEnv(DRAWENV *env); void PutDrawEnvFast(DRAWENV *env); -void SetDispMask(int mask); - +int GetODE(void); int VSync(int mode); int DrawSync(int mode); -//void WaitGPUcmd(void); -//void WaitGPUdma(void); -// Callback hook functions void *VSyncCallback(void (*func)(void)); void *DrawSyncCallback(void (*func)(void)); -void LoadImage(const RECT *rect, const u_long *data); -void StoreImage(const RECT *rect, u_long *data); +void LoadImage(const RECT *rect, const uint32_t *data); +void StoreImage(const RECT *rect, uint32_t *data); -void ClearOTagR(u_long *ot, size_t length); -void ClearOTag(u_long *ot, size_t length); -void DrawOTag(const u_long *ot); -void DrawOTag2(const u_long *ot); -void DrawOTagEnv(const u_long *ot, DRAWENV *env); -void DrawPrim(const u_long *pri); +void ClearOTagR(uint32_t *ot, size_t length); +void ClearOTag(uint32_t *ot, size_t length); +void DrawOTag(const uint32_t *ot); +void DrawOTag2(const uint32_t *ot); +void DrawOTagEnv(const uint32_t *ot, DRAWENV *env); +void DrawPrim(const uint32_t *pri); -void AddPrim(u_long *ot, const void *pri); +void AddPrim(uint32_t *ot, const void *pri); -int GsGetTimInfo(const u_long *tim, GsIMAGE *info); -int GetTimInfo(const u_long *tim, TIM_IMAGE *info); /* deprecated */ +int GsGetTimInfo(const uint32_t *tim, GsIMAGE *info); +int GetTimInfo(const uint32_t *tim, TIM_IMAGE *info); DISPENV *SetDefDispEnv(DISPENV *env, int x, int y, int w, int h); DRAWENV *SetDefDrawEnv(DRAWENV *env, int x, int y, int w, int h); -// Debug font functions - void FntLoad(int x, int y); -char *FntSort(u_long *ot, char *pri, int x, int y, const char *text); +char *FntSort(uint32_t *ot, char *pri, int x, int y, const char *text); int FntOpen(int x, int y, int w, int h, int isbg, int n); int FntPrint(int id, const char *fmt, ...); char *FntFlush(int id); diff --git a/libpsn00b/include/psxgte.h b/libpsn00b/include/psxgte.h index 7c10533..ddc988d 100644 --- a/libpsn00b/include/psxgte.h +++ b/libpsn00b/include/psxgte.h @@ -1,44 +1,45 @@ -#ifndef _PSXGTE_H -#define _PSXGTE_H +/* + * PSn00bSDK GTE library + * (C) 2019-2022 Lameguy64 - MPL licensed + */ +#ifndef __PSXGTE_H +#define __PSXGTE_H -#define ONE 4096 +#include <stdint.h> +#define ONE (1 << 12) -// For compatibility with official library syntax -#define csin(a) isin(a) -#define ccos(a) icos(a) -#define rsin(a) isin(a) -#define rcos(a) icos(a) - +/* Structure definitions */ -typedef struct MATRIX { - short m[3][3]; - int t[3]; +typedef struct _MATRIX { + int16_t m[3][3]; + int32_t t[3]; } MATRIX; -typedef struct VECTOR { - int vx, vy, vz; +typedef struct _VECTOR { + int32_t vx, vy, vz; } VECTOR; -typedef struct SVECTOR { - short vx, vy, vz, pad; +typedef struct _SVECTOR { + int16_t vx, vy, vz, pad; } SVECTOR; -typedef struct CVECTOR { - unsigned char r, g, b, cd; +typedef struct _CVECTOR { + uint8_t r, g, b, cd; } CVECTOR; -typedef struct DVECTOR { - short vx, vy; +typedef struct _DVECTOR { + int16_t vx, vy; } DVECTOR; +/* Public API */ #ifdef __cplusplus extern "C" { #endif -void InitGeom(); +void InitGeom(void); // Integer SIN/COS functions (4096 = 360 degrees) // Does not use tables! @@ -70,11 +71,16 @@ void VectorNormalS(VECTOR *v0, SVECTOR *v1); void Square0(VECTOR *v0, VECTOR *v1); -int SquareRoot12( int v ); -int SquareRoot0( int v ); +int SquareRoot12(int v); +int SquareRoot0(int v); + +#define csin(a) isin(a) +#define ccos(a) icos(a) +#define rsin(a) isin(a) +#define rcos(a) icos(a) #ifdef __cplusplus } #endif -#endif // _PSXGTE_H +#endif diff --git a/libpsn00b/include/psxspu.h b/libpsn00b/include/psxspu.h index da000e3..36bbe70 100644 --- a/libpsn00b/include/psxspu.h +++ b/libpsn00b/include/psxspu.h @@ -1,138 +1,91 @@ +/* + * PSn00bSDK SPU library + * (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed + */ + #ifndef __PSXSPU_H #define __PSXSPU_H -#include <sys/types.h> - -// Mask settings bits for specifying voice channels - -#define SPU_00CH (1<<0) -#define SPU_01CH (1<<1) -#define SPU_02CH (1<<2) -#define SPU_03CH (1<<3) -#define SPU_04CH (1<<4) -#define SPU_05CH (1<<5) -#define SPU_06CH (1<<6) -#define SPU_07CH (1<<7) -#define SPU_08CH (1<<8) -#define SPU_09CH (1<<9) -#define SPU_10CH (1<<10) -#define SPU_11CH (1<<11) -#define SPU_12CH (1<<12) -#define SPU_13CH (1<<13) -#define SPU_14CH (1<<14) -#define SPU_15CH (1<<15) -#define SPU_16CH (1<<16) -#define SPU_17CH (1<<17) -#define SPU_18CH (1<<18) -#define SPU_19CH (1<<19) -#define SPU_20CH (1<<20) -#define SPU_21CH (1<<21) -#define SPU_22CH (1<<22) -#define SPU_23CH (1<<23) - -#define SPU_0CH SPU_00CH -#define SPU_1CH SPU_01CH -#define SPU_2CH SPU_02CH -#define SPU_3CH SPU_03CH -#define SPU_4CH SPU_04CH -#define SPU_5CH SPU_05CH -#define SPU_6CH SPU_06CH -#define SPU_7CH SPU_07CH -#define SPU_8CH SPU_08CH -#define SPU_9CH SPU_09CH - -#define SPU_KEYCH(x) (1<<(x)) -#define SPU_VOICECH(x) SPU_KEYCH(x) - - -// Mask setting bits for SpuVoiceAttr.mask - -#define SPU_VOICE_VOLL (1<<0) // Left volume -#define SPU_VOICE_VOLR (1<<1) // Right volume -#define SPU_VOICE_VOLMODEL (1<<2) // Left volume mode -#define SPU_VOICE_VOLMODER (1<<3) // Right volume mode -#define SPU_VOICE_PITCH (1<<4) // Pitch tone -#define SPU_VOICE_NOTE (1<<5) // Pitch note -#define SPU_VOICE_SAMPLE_NOTE (1<<6) // Sample base frequency? -#define SPU_VOICE_WDSA (1<<7) // Sample start address (in SPU RAM) -#define SPU_VOICE_ADSR_AMODE (1<<8) // ADSR attack mode -#define SPU_VOICE_ADSR_SMODE (1<<9) // ADSR sustain mode -#define SPU_VOICE_ADSR_RMODE (1<<10) // ADSR release mode -#define SPU_VOICE_ADSR_AR (1<<11) // ADSR attack rate -#define SPU_VOICE_ADSR_DR (1<<12) // ADSR decay rate -#define SPU_VOICE_ADSR_SR (1<<13) // ADSR sustain rate -#define SPU_VOICE_ADSR_RR (1<<14) // ADSR release rate -#define SPU_VOICE_ADSR_SL (1<<15) // ADSR sustain level -#define SPU_VOICE_LSAX (1<<16) // Loop start address (in SPU RAM) -#define SPU_VOICE_ADSR_ADSR1 (1<<17) // adsr1 for VagAtr (?) -#define SPU_VOICE_ADSR_ADSR2 (1<<18) // adsr2 for VagAtr (?) - - -#define SPU_TRANSFER_BY_DMA 0 - - -typedef struct { - short left; - short right; +#include <stdint.h> + +/* Definitions */ + +typedef enum _SPU_AttrMask { + SPU_VOICE_VOLL = 1 << 0, // Left volume + SPU_VOICE_VOLR = 1 << 1, // Right volume + SPU_VOICE_VOLMODEL = 1 << 2, // Left volume mode + SPU_VOICE_VOLMODER = 1 << 3, // Right volume mode + SPU_VOICE_PITCH = 1 << 4, // Pitch tone + SPU_VOICE_NOTE = 1 << 5, // Pitch note + SPU_VOICE_SAMPLE_NOTE = 1 << 6, // Sample base frequency? + SPU_VOICE_WDSA = 1 << 7, // Sample start address (in SPU RAM) + SPU_VOICE_ADSR_AMODE = 1 << 8, // ADSR attack mode + SPU_VOICE_ADSR_SMODE = 1 << 9, // ADSR sustain mode + SPU_VOICE_ADSR_RMODE = 1 << 10, // ADSR release mode + SPU_VOICE_ADSR_AR = 1 << 11, // ADSR attack rate + SPU_VOICE_ADSR_DR = 1 << 12, // ADSR decay rate + SPU_VOICE_ADSR_SR = 1 << 13, // ADSR sustain rate + SPU_VOICE_ADSR_RR = 1 << 14, // ADSR release rate + SPU_VOICE_ADSR_SL = 1 << 15, // ADSR sustain level + SPU_VOICE_LSAX = 1 << 16, // Loop start address (in SPU RAM) + SPU_VOICE_ADSR_ADSR1 = 1 << 17, + SPU_VOICE_ADSR_ADSR2 = 1 << 18 +} SPU_AttrMask; + +typedef enum _SPU_TransferMode { + SPU_TRANSFER_BY_DMA = 0, + SPU_TRANSFER_BY_IO = 1 +} SPU_TransferMode; + +/* Structure definitions */ + +typedef struct _SpuVolume { + int16_t left, right; } SpuVolume; -typedef struct { - SpuVolume vol; // 0 - unsigned short freq; // 4 - unsigned short addr; // 6 - unsigned short loop_addr; // 8 - unsigned short res; // 10 - unsigned int adsr_param; // 12 -} SpuVoiceRaw; - -typedef struct { - u_int voice; - u_int mask; - SpuVolume volume; - SpuVolume volmode; - SpuVolume volumex; - u_short pitch; - u_short note; - u_short sample_note; - short envx; - u_int addr; - u_int loop_addr; - int a_mode; - int s_mode; - int r_mode; - u_short ar; - u_short dr; - u_short sr; - u_short rr; - u_short sl; - u_short adsr1; - u_short adsr2; +typedef struct _SpuVoiceAttr { + uint32_t voice; + uint32_t mask; + SpuVolume volume, volmode, volumex; + uint16_t pitch, note, sample_note; + int16_t envx; + uint32_t addr, loop_addr; + int a_mode, s_mode, r_mode; + uint16_t ar, dr, sr, rr, sl; + uint16_t adsr1, adsr2; } SpuVoiceAttr; -#ifdef __cplusplus -extern "C" { -#endif +typedef struct _SpuExtAttr { + SpuVolume volume; + int reverb, mix; +} SpuExtAttr; -void SpuInit(); +typedef struct _SpuCommonAttr { + uint32_t mask; + SpuVolume mvol, mvolmode, mvolx; + SpuExtAttr cd, ext; +} SpuCommonAttr; -void SpuSetVoiceRaw( int voice, const SpuVoiceRaw* param ); -void SpuReverbOn( int voice ); -void SpuSetReverb(); +/* Public API */ -void SpuSetReverbAddr( int addr ); -void SpuSetReverbVolume( int left, int right ); +#ifdef __cplusplus +extern "C" { +#endif +void SpuInit(void); -void SpuSetKey(int on_off, u_int voice_bit); +void SpuReverbOn(int voice); +void SpuSetReverbAddr(int addr); +void SpuSetReverbVolume(int left, int right); +void SpuSetKey(int on_off, uint32_t voice_bit); -// SPU transfer functions int SpuSetTransferMode(int mode); int SpuSetTransferStartAddr(int addr); -int SpuWrite(const unsigned char* addr, int size); -void SpuWait(); +int SpuWrite(const uint8_t *addr, int size); +void SpuWait(void); #ifdef __cplusplus } #endif -#endif
\ No newline at end of file +#endif diff --git a/libpsn00b/lzp/crc.c b/libpsn00b/lzp/crc.c index 3c1ae57..6b00c8e 100644 --- a/libpsn00b/lzp/crc.c +++ b/libpsn00b/lzp/crc.c @@ -1,14 +1,15 @@ +#include <stdint.h> #include "lzp.h" -void initTable16(unsigned short* table) { +void initTable16(uint16_t *table) { int i, j; - unsigned short crc, c; + uint16_t crc, c; for (i=0; i<256; i++) { crc = 0; - c = (unsigned short) i; + c = (uint16_t) i; for (j=0; j<8; j++) { @@ -25,10 +26,10 @@ void initTable16(unsigned short* table) { } -void initTable32(unsigned int* table) { +void initTable32(uint32_t *table) { int i,j; - unsigned int crcVal; + uint32_t crcVal; for(i=0; i<256; i++) { @@ -49,17 +50,17 @@ void initTable32(unsigned int* table) { } -unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc) { +uint16_t lzCRC16(const void* buff, int bytes, uint16_t crc) { int i; - unsigned short tmp, short_c; - unsigned short crcTable[256]; + uint16_t tmp, short_c; + uint16_t crcTable[256]; initTable16(crcTable); for(i=0; i<bytes; i++) { - short_c = 0x00ff & (unsigned short)((const unsigned char*)buff)[i]; + short_c = 0x00ff & (uint16_t)((const uint8_t *)buff)[i]; tmp = crc ^ short_c; crc = (crc >> 8) ^ crcTable[tmp&0xff]; @@ -70,18 +71,18 @@ unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc) { } -unsigned int lzCRC32(const void* buff, int bytes, unsigned int crc) { +uint32_t lzCRC32(const void* buff, int bytes, uint32_t crc) { int i; - const unsigned char* byteBuff = (const unsigned char*)buff; - unsigned int byte; - unsigned int crcTable[256]; + const uint8_t *byteBuff = (const uint8_t *)buff; + uint32_t byte; + uint32_t crcTable[256]; initTable32(crcTable); for(i=0; i<bytes; i++) { - byte = 0x000000ffL&(unsigned int)byteBuff[i]; + byte = 0x000000ffL&(uint32_t)byteBuff[i]; crc = (crc>>8)^crcTable[(crc^byte)&0xff]; } diff --git a/libpsn00b/lzp/lzp.h b/libpsn00b/lzp/lzp.h index cfeeb72..456de02 100644 --- a/libpsn00b/lzp/lzp.h +++ b/libpsn00b/lzp/lzp.h @@ -16,7 +16,7 @@ #ifndef _LZPACK_H #define _LZPACK_H -#include <sys/types.h> +#include <stdint.h> #ifdef _WIN32 #include <windows.h> #endif @@ -64,9 +64,9 @@ typedef struct { //! File ID (must always be 'LZP') - char id[3]; + char id[3]; //! File count - u_char numFiles; + uint8_t numFiles; } LZP_HEAD; @@ -74,15 +74,15 @@ typedef struct { typedef struct { //! File name - char fileName[16]; + char fileName[16]; //! CRC32 checksum of file - u_int crc; + uint32_t crc; //! Original size of file in bytes - u_int fileSize; + uint32_t fileSize; //! Compressed size of file - u_int packedSize; + uint32_t packedSize; //! File data offset - u_int offset; + uint32_t offset; } LZP_FILE; @@ -162,7 +162,7 @@ void lzResetHashSizes(); * * \returns CRC16 hash of specified buffer. */ -unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc); +uint16_t lzCRC16(const void* buff, int bytes, uint16_t crc); /*! Calculates a CRC32 hash of the specified buffer. * @@ -172,7 +172,7 @@ unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc); * * \returns CRC32 hash of specified buffer. */ -unsigned int lzCRC32(const void* buff, int bytes, unsigned int crc); +uint32_t lzCRC32(const void* buff, int bytes, uint32_t crc); /*! @} */ diff --git a/libpsn00b/lzp/lzqlp.h b/libpsn00b/lzp/lzqlp.h index 5b70b40..32ce0d7 100644 --- a/libpsn00b/lzp/lzqlp.h +++ b/libpsn00b/lzp/lzqlp.h @@ -1,7 +1,7 @@ #ifndef _QLP_H #define _QLP_H -#include <sys/types.h> +#include <stdint.h> #ifdef _WIN32 #include <windows.h> #endif @@ -13,14 +13,14 @@ #define PACK_ERR_READ_FAULT -4 typedef struct { - char id[3]; - u_char numfiles; + char id[3]; + uint8_t numfiles; } QLP_HEAD; typedef struct { - char name[16]; - u_int size; - u_int offs; + char name[16]; + uint32_t size; + uint32_t offs; } QLP_FILE; int qlpFileCount(const QLP_HEAD* qlpfile); diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index d1c1b18..582b8d9 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -1,4 +1,4 @@ -#include <sys/types.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -15,18 +15,18 @@ typedef struct _CdlDIR_INT { - u_long _pos; - u_long _len; - u_char* _dir; + uint32_t _pos; + uint32_t _len; + uint8_t *_dir; } CdlDIR_INT; extern int _cd_media_changed; static int _cd_iso_last_dir_lba; -static u_char _cd_iso_descriptor_buff[2048]; -static u_char* _cd_iso_pathtable_buff=NULL; -static u_char* _cd_iso_directory_buff=NULL; +static uint8_t _cd_iso_descriptor_buff[2048]; +static uint8_t *_cd_iso_pathtable_buff=NULL; +static uint8_t *_cd_iso_directory_buff=NULL; static int _cd_iso_directory_len; static int _cd_iso_error=0; @@ -68,7 +68,7 @@ static int _CdReadIsoDescriptor(int session_offs) // Seek to volume descriptor CdIntToPos(16+session_offs, &loc); - if( !CdControl(CdlSetloc, (u_char*)&loc, 0) ) + if( !CdControl(CdlSetloc, (uint8_t*)&loc, 0) ) { #ifdef DEBUG printf("psxcd: Could not set seek destination.\n"); @@ -85,7 +85,7 @@ static int _CdReadIsoDescriptor(int session_offs) printf("psxcd: Read sectors.\n"); #endif // Read volume descriptor - CdRead(1, (u_long*)_cd_iso_descriptor_buff, CdlModeSpeed); + CdRead(1, (uint32_t*)_cd_iso_descriptor_buff, CdlModeSpeed); if( CdReadSync(0, 0) ) { @@ -122,7 +122,7 @@ static int _CdReadIsoDescriptor(int session_offs) { free(_cd_iso_pathtable_buff); } - _cd_iso_pathtable_buff = (u_char*)malloc(i); + _cd_iso_pathtable_buff = (uint8_t*)malloc(i); #ifdef DEBUG printf("psxcd_dbg: Allocated %d bytes for path table.\n", i); @@ -130,8 +130,8 @@ static int _CdReadIsoDescriptor(int session_offs) // Read path table CdIntToPos(descriptor->pathTable1Offs, &loc); - CdControl(CdlSetloc, (u_char*)&loc, 0); - CdRead(i>>11, (u_long*)_cd_iso_pathtable_buff, CdlModeSpeed); + CdControl(CdlSetloc, (uint8_t*)&loc, 0); + CdRead(i>>11, (uint32_t*)_cd_iso_pathtable_buff, CdlModeSpeed); if( CdReadSync(0, 0) ) { #ifdef DEBUG @@ -165,7 +165,7 @@ static int _CdReadIsoDirectory(int lba) #ifdef DEBUG printf("psxcd_dbg: Seek to sector %d\n", i); #endif - if( !CdControl(CdlSetloc, (u_char*)&loc, 0) ) + if( !CdControl(CdlSetloc, (uint8_t*)&loc, 0) ) { #ifdef DEBUG printf("psxcd: Could not set seek destination.\n"); @@ -180,8 +180,8 @@ static int _CdReadIsoDirectory(int lba) } // Read first sector of directory record - _cd_iso_directory_buff = (u_char*)malloc(2048); - CdRead(1, (u_long*)_cd_iso_directory_buff, CdlModeSpeed); + _cd_iso_directory_buff = (uint8_t*)malloc(2048); + CdRead(1, (uint32_t*)_cd_iso_directory_buff, CdlModeSpeed); if( CdReadSync(0, 0) ) { #ifdef DEBUG @@ -201,7 +201,7 @@ static int _CdReadIsoDirectory(int lba) if( _cd_iso_directory_len > 2048 ) { - if( !CdControl(CdlSetloc, (u_char*)&loc, 0) ) + if( !CdControl(CdlSetloc, (uint8_t*)&loc, 0) ) { #ifdef DEBUG printf("psxcd: Could not set seek destination.\n"); @@ -212,12 +212,12 @@ static int _CdReadIsoDirectory(int lba) free(_cd_iso_directory_buff); i = ((2047+_cd_iso_directory_len)>>11)<<11; - _cd_iso_directory_buff = (u_char*)malloc(i); + _cd_iso_directory_buff = (uint8_t*)malloc(i); #ifdef DEBUG printf("psxcd_dbg: Allocated %d bytes for directory record.\n", i); #endif - CdRead(i>>11, (u_long*)_cd_iso_directory_buff, CdlModeSpeed); + CdRead(i>>11, (uint32_t*)_cd_iso_directory_buff, CdlModeSpeed); if( CdReadSync(0, 0) ) { #ifdef DEBUG @@ -279,7 +279,7 @@ static void dump_directory(void) static void dump_pathtable(void) { - u_char *tbl_pos; + uint8_t *tbl_pos; ISO_PATHTABLE_ENTRY *tbl_entry; ISO_DESCRIPTOR *descriptor; char namebuff[16]; @@ -314,7 +314,7 @@ static void dump_pathtable(void) static int get_pathtable_entry(int entry, ISO_PATHTABLE_ENTRY *tbl, char *namebuff) { int i; - u_char *tbl_pos; + uint8_t *tbl_pos; ISO_PATHTABLE_ENTRY *tbl_entry; ISO_DESCRIPTOR *descriptor; diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index 8f19c8d..6340638 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -1,4 +1,4 @@ -#include <sys/types.h> +#include <stdint.h> #include <stdio.h> #include <psxgpu.h> #include "psxcd.h" @@ -6,16 +6,16 @@ #define READ_TIMEOUT 600 // 10 seconds for NTSC extern volatile char _cd_ack_wait; -extern volatile u_char _cd_last_int; -extern volatile u_char _cd_last_mode; -extern volatile u_char _cd_status; +extern volatile uint8_t _cd_last_int; +extern volatile uint8_t _cd_last_mode; +extern volatile uint8_t _cd_status; extern volatile CdlCB _cd_callback_int1_data; -volatile u_char *_cd_result_ptr; +volatile uint8_t *_cd_result_ptr; // For read retry volatile CdlLOC _cd_last_setloc; -volatile u_long *_cd_last_read_addr; +volatile uint32_t *_cd_last_read_addr; volatile int _cd_last_sector_count; int _cd_media_changed; @@ -169,7 +169,7 @@ int CdSync(int mode, unsigned char *result) int CdGetToc(CdlLOC *toc) { - u_char track_info[8]; + uint8_t track_info[8]; int i,tracks; // Get number of tracks @@ -189,7 +189,7 @@ int CdGetToc(CdlLOC *toc) for(i=0; i<tracks; i++) { int t = itob(1+i); - if( !CdControl(CdlGetTD, (u_char*)&t, (u_char*)&toc[i]) ) + if( !CdControl(CdlGetTD, (uint8_t*)&t, (uint8_t*)&toc[i]) ) { return 0; } @@ -234,11 +234,11 @@ int CdMode(void) // CD data read routines volatile int _cd_sector_count = 0; -volatile u_long *_cd_read_addr; -volatile u_char _cd_read_result[8]; -volatile u_long _cd_read_oldcb; -volatile u_long _cd_read_sector_sz; -volatile u_long _cd_read_counter; +volatile uint32_t *_cd_read_addr; +volatile uint8_t _cd_read_result[8]; +volatile uint32_t _cd_read_oldcb; +volatile uint32_t _cd_read_sector_sz; +volatile uint32_t _cd_read_counter; @@ -279,7 +279,7 @@ static void _CdReadReadyCallback(int status, unsigned char *result) } } -int CdRead(int sectors, u_long *buf, int mode) +int CdRead(int sectors, uint32_t *buf, int mode) { // Set sectors to read count _cd_sector_count = sectors; @@ -307,10 +307,10 @@ int CdRead(int sectors, u_long *buf, int mode) _cd_read_oldcb = CdReadyCallback(_CdReadReadyCallback); // Set specified mode - CdControl(CdlSetmode, (u_char*)&mode, 0); + CdControl(CdlSetmode, (uint8_t*)&mode, 0); // Begin reading sectors - CdControl(CdlReadN, 0, (u_char*)_cd_read_result); + CdControl(CdlReadN, 0, (uint8_t*)_cd_read_result); return 0; } @@ -336,10 +336,10 @@ static void CdDoRetry() // Retry read CdControl(CdlSetloc, (void*)&_cd_last_setloc, 0); - CdControl(CdlReadN, 0, (u_char*)_cd_read_result); + CdControl(CdlReadN, 0, (uint8_t*)_cd_read_result); } -int CdReadSync(int mode, u_char *result) +int CdReadSync(int mode, uint8_t *result) { if( (VSync(-1)-_cd_read_counter) > READ_TIMEOUT ) { @@ -371,7 +371,7 @@ int CdReadSync(int mode, u_char *result) return 0; } -u_long CdReadCallback(CdlCB func) +uint32_t CdReadCallback(CdlCB func) { unsigned int old_func; diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c index ee90225..bf115a1 100644 --- a/libpsn00b/psxgpu/common.c +++ b/libpsn00b/psxgpu/common.c @@ -4,7 +4,6 @@ */ #include <stdint.h> -#include <sys/types.h> #include <stdio.h> #include <psxetc.h> #include <psxapi.h> @@ -17,12 +16,12 @@ /* Internal globals */ -VIDEO_MODE _gpu_video_mode; +GPU_VideoMode _gpu_video_mode; static void (*_vsync_callback)(void); static void (*_drawsync_callback)(void); -static const u_long *volatile _draw_queue[QUEUE_LENGTH]; +static const uint32_t *volatile _draw_queue[QUEUE_LENGTH]; static volatile uint8_t _queue_head, _queue_tail, _queue_length; static volatile uint32_t _vblank_counter, _last_hblank; @@ -194,7 +193,7 @@ void *DrawSyncCallback(void (*func)(void)) { /* OT and primitive drawing API */ -void ClearOTagR(u_long *ot, size_t length) { +void ClearOTagR(uint32_t *ot, size_t length) { DMA_MADR(6) = (uint32_t) &ot[length - 1]; DMA_BCR(6) = length & 0xffff; DMA_CHCR(6) = 0x11000002; @@ -203,18 +202,18 @@ void ClearOTagR(u_long *ot, size_t length) { //__asm__ volatile(""); } -void ClearOTag(u_long *ot, size_t length) { +void ClearOTag(uint32_t *ot, size_t length) { // DMA6 only supports writing to RAM in reverse order (last to first), so // the OT has to be cleared in software here. This function is thus much // slower than ClearOTagR(). // https://problemkaputt.de/psx-spx.htm#dmachannels for (int i = 0; i < (length - 1); i++) - ot[i] = (u_long) &ot[i + 1] & 0x00ffffff; + ot[i] = (uint32_t) &ot[i + 1] & 0x00ffffff; ot[length - 1] = 0x00ffffff; } -void DrawOTag(const u_long *ot) { +void DrawOTag(const uint32_t *ot) { // If GPU DMA is currently busy, append the OT to the queue instead of // drawing it immediately. if (DMA_CHCR(2) & (1 << 24)) { @@ -232,7 +231,7 @@ void DrawOTag(const u_long *ot) { DrawOTag2(ot); } -void DrawOTag2(const u_long *ot) { +void DrawOTag2(const uint32_t *ot) { GPU_GP1 = 0x04000002; while (!(GPU_GP1 & (1 << 26))) @@ -243,7 +242,7 @@ void DrawOTag2(const u_long *ot) { DMA_CHCR(2) = 0x01000401; } -void DrawPrim(const u_long *pri) { +void DrawPrim(const uint32_t *pri) { size_t length = getlen(pri); DrawSync(0); @@ -261,17 +260,17 @@ void DrawPrim(const u_long *pri) { DMA_CHCR(2) = 0x01000201; } -void AddPrim(u_long *ot, const void *pri) { +void AddPrim(uint32_t *ot, const void *pri) { addPrim(ot, pri); } /* Misc. functions */ -VIDEO_MODE GetVideoMode(void) { +GPU_VideoMode GetVideoMode(void) { return _gpu_video_mode; } -void SetVideoMode(VIDEO_MODE mode) { +void SetVideoMode(GPU_VideoMode mode) { uint32_t _mode, stat = GPU_GP1; _gpu_video_mode = mode & 1; diff --git a/libpsn00b/psxgpu/env.c b/libpsn00b/psxgpu/env.c index 8a74b7e..5642ad4 100644 --- a/libpsn00b/psxgpu/env.c +++ b/libpsn00b/psxgpu/env.c @@ -4,13 +4,12 @@ */ #include <stdint.h> -#include <sys/types.h> #include <psxgpu.h> #include <hwregs_c.h> #define _min(x, y) (((x) < (y)) ? (x) : (y)) -extern VIDEO_MODE _gpu_video_mode; +extern GPU_VideoMode _gpu_video_mode; /* Drawing API */ @@ -38,7 +37,7 @@ DRAWENV *SetDefDrawEnv(DRAWENV *env, int x, int y, int w, int h) { return env; } -void DrawOTagEnv(const u_long *ot, DRAWENV *env) { +void DrawOTagEnv(const uint32_t *ot, DRAWENV *env) { DR_ENV *prim = &(env->dr_env); // All commands are grouped into a single display list packet for @@ -86,11 +85,11 @@ void DrawOTagEnv(const u_long *ot, DRAWENV *env) { //while (!(GPU_GP1 & (1 << 26))) //__asm__ volatile(""); - DrawOTag(prim); + DrawOTag((const uint32_t *) prim); } void PutDrawEnv(DRAWENV *env) { - DrawOTagEnv((const u_long *) 0x00ffffff, env); + DrawOTagEnv((const uint32_t *) 0x00ffffff, env); } // This function skips rebuilding the cached packet whenever possible and is @@ -98,11 +97,11 @@ void PutDrawEnv(DRAWENV *env) { // the time). void PutDrawEnvFast(DRAWENV *env) { if (!(env->dr_env.tag)) { - DrawOTagEnv((const u_long *) 0x00ffffff, env); + DrawOTagEnv((const uint32_t *) 0x00ffffff, env); return; } - DrawOTag(&(env->dr_env)); + DrawOTag((const uint32_t *) &(env->dr_env)); } /* Display API */ diff --git a/libpsn00b/psxgpu/font.c b/libpsn00b/psxgpu/font.c index 7a8137c..2d4105f 100644 --- a/libpsn00b/psxgpu/font.c +++ b/libpsn00b/psxgpu/font.c @@ -1,4 +1,4 @@ -#include <sys/types.h> +#include <stdint.h> #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -6,29 +6,28 @@ #include <psxgpu.h> typedef struct _fnt_stream { - char *txtbuff; - char *txtnext; - char *pribuff; - short x,y; - short w,h; - int bg; - int maxchars; + char *txtbuff; + char *txtnext; + char *pribuff; + int16_t x, y; + int16_t w, h; + int bg, maxchars; } _fnt_stream; static _fnt_stream _stream[8]; static int _nstreams = 0; -u_short _font_tpage; -u_short _font_clut; +uint16_t _font_tpage; +uint16_t _font_clut; -extern u_char _gpu_debug_font[]; +extern uint8_t _gpu_debug_font[]; void FntLoad(int x, int y) { RECT pos; TIM_IMAGE tim; - GetTimInfo( (const u_long *) _gpu_debug_font, &tim ); + GetTimInfo( (const uint32_t *) _gpu_debug_font, &tim ); // Load font image pos = *tim.prect; @@ -215,7 +214,7 @@ char *FntFlush(int id) { // Draw the primitives DrawSync(0); - DrawOTag((u_long*)_stream[id].pribuff); + DrawOTag((uint32_t*)_stream[id].pribuff); DrawSync(0); _stream[id].txtnext = _stream[id].txtbuff; @@ -225,7 +224,7 @@ char *FntFlush(int id) { } -char *FntSort(u_long *ot, char *pri, int x, int y, const char *text) { +char *FntSort(uint32_t *ot, char *pri, int x, int y, const char *text) { DR_TPAGE *tpage; SPRT_8 *sprt = (SPRT_8*)pri; diff --git a/libpsn00b/psxgpu/image.c b/libpsn00b/psxgpu/image.c index 3633c7c..b3e5678 100644 --- a/libpsn00b/psxgpu/image.c +++ b/libpsn00b/psxgpu/image.c @@ -4,7 +4,6 @@ */ #include <stdint.h> -#include <sys/types.h> #include <stdio.h> #include <psxgpu.h> #include <hwregs_c.h> @@ -51,11 +50,11 @@ static void _load_store_image( /* Public VRAM API */ -void LoadImage(const RECT *rect, const u_long *data) { +void LoadImage(const RECT *rect, const uint32_t *data) { _load_store_image(0xa0000000, 2, rect, (uint32_t *) data); } -void StoreImage(const RECT *rect, u_long *data) { +void StoreImage(const RECT *rect, uint32_t *data) { _load_store_image(0xc0000000, 3, rect, (uint32_t *) data); } @@ -65,18 +64,18 @@ void StoreImage(const RECT *rect, u_long *data) { // difference from GetTimInfo() is that it copies RECTs rather than merely // returning pointers to them, which become useless once the .TIM file is // unloaded from main RAM. -int GsGetTimInfo(const u_long *tim, GsIMAGE *info) { +int GsGetTimInfo(const uint32_t *tim, GsIMAGE *info) { if ((*(tim++) & 0xffff) != 0x0010) return 1; info->pmode = *(tim++); if (info->pmode & 8) { - const u_long *palette_end = tim; + const uint32_t *palette_end = tim; palette_end += *(tim++) / 4; - *((u_long *) &(info->cx)) = *(tim++); - *((u_long *) &(info->cw)) = *(tim++); - info->clut = (u_long *) tim; + *((uint32_t *) &(info->cx)) = *(tim++); + *((uint32_t *) &(info->cw)) = *(tim++); + info->clut = (uint32_t *) tim; tim = palette_end; } else { @@ -84,24 +83,24 @@ int GsGetTimInfo(const u_long *tim, GsIMAGE *info) { } tim++; - *((u_long *) &(info->px)) = *(tim++); - *((u_long *) &(info->pw)) = *(tim++); - info->pixel = (u_long *) tim; + *((uint32_t *) &(info->px)) = *(tim++); + *((uint32_t *) &(info->pw)) = *(tim++); + info->pixel = (uint32_t *) tim; return 0; } -int GetTimInfo(const u_long *tim, TIM_IMAGE *info) { +int GetTimInfo(const uint32_t *tim, TIM_IMAGE *info) { if ((*(tim++) & 0xffff) != 0x0010) return 1; info->mode = *(tim++); if (info->mode & 8) { - const u_long *palette_end = tim; + const uint32_t *palette_end = tim; palette_end += *(tim++) / 4; - info->crect = (RECT *) tim; - info->caddr = (u_long *) &tim[2]; + info->crect = (RECT *) tim; + info->caddr = (uint32_t *) &tim[2]; tim = palette_end; } else { @@ -109,8 +108,8 @@ int GetTimInfo(const u_long *tim, TIM_IMAGE *info) { } tim++; - info->prect = (RECT *) tim; - info->paddr = (u_long *) &tim[2]; + info->prect = (RECT *) tim; + info->paddr = (uint32_t *) &tim[2]; return 0; } diff --git a/tools/lzpack/main.cpp b/tools/lzpack/main.cpp index 506b76c..798408c 100644 --- a/tools/lzpack/main.cpp +++ b/tools/lzpack/main.cpp @@ -28,10 +28,10 @@ typedef struct { } PCK_FILE; typedef struct { - char id[3]; - u_char numFiles; - PCK_FILE file[85]; // File entries - int lba; // LBA of the PCK file (in 2048 byte sector units) + char id[3]; + unsigned char numFiles; + PCK_FILE file[85]; // File entries + int lba; // LBA of the PCK file (in 2048 byte sector units) } PCK_TOC; |
