From ef776e728cfa67fbca38bb375152b336fa0b5200 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Mon, 27 Jun 2022 22:18:11 +0200 Subject: Clean up io/system573 example and libpsxpress --- examples/io/system573/k573io.c | 7 ++++++- examples/io/system573/k573io.h | 38 +++++++++++++++++++++----------------- examples/io/system573/main.c | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) (limited to 'examples') diff --git a/examples/io/system573/k573io.c b/examples/io/system573/k573io.c index bc13852..53c109f 100644 --- a/examples/io/system573/k573io.c +++ b/examples/io/system573/k573io.c @@ -75,7 +75,7 @@ uint32_t K573_GetJAMMAInputs(void) { inputs |= ((K573_IO_CHIP[IO_REG_IN1_HIGH] >> 8) & 0x1f) << 24; inputs |= (K573_IO_CHIP[IO_REG_IN1_LOW] & 0x07) << 29; - return inputs; + return ~inputs; } void K573_SetLights(uint32_t lights) { @@ -120,5 +120,10 @@ void K573_Init(void) { EXP1_ADDR = 0x1f000000; EXP1_DELAY_SIZE = 0x24173f47; // 573 BIOS uses this value + // Bit 6 of this register controls the audio DAC and must be set, otherwise + // no sound will be output. Most of the other bits are data clocks/strobes + // and should be pulled high when not in use. + K573_IO_CHIP[IO_REG_OUT0] = 0x01e7; + K573_RESET_WATCHDOG(); } diff --git a/examples/io/system573/k573io.h b/examples/io/system573/k573io.h index 7095a7c..424e3e4 100644 --- a/examples/io/system573/k573io.h +++ b/examples/io/system573/k573io.h @@ -25,6 +25,7 @@ #define K573_IO_BOARD ((volatile uint16_t *) 0x1f640000) typedef enum _K573_IOChipRegister { + IO_REG_OUT0 = 0x0, IO_REG_IN0 = 0x0, IO_REG_IN1_LOW = 0x2, IO_REG_IN1_HIGH = 0x3, @@ -34,26 +35,29 @@ typedef enum _K573_IOChipRegister { } K573_IOChipRegister; typedef enum _K573_IOBoardRegister { - ANALOG_IO_REG_LIGHTS0 = 0x40, - ANALOG_IO_REG_LIGHTS1 = 0x44, - ANALOG_IO_REG_LIGHTS2 = 0x48, - ANALOG_IO_REG_LIGHTS3 = 0x4c, + ANALOG_IO_REG_LIGHTS0 = 0x40, + ANALOG_IO_REG_LIGHTS1 = 0x44, + ANALOG_IO_REG_LIGHTS2 = 0x48, + ANALOG_IO_REG_LIGHTS3 = 0x4c, // The digital I/O board has a lot more registers than these, but there // seems to be no DIGITAL_IO_LIGHTS6 register. WTF - DIGITAL_IO_REG_LIGHTS1 = 0x70, - DIGITAL_IO_REG_LIGHTS0 = 0x71, - DIGITAL_IO_REG_LIGHTS3 = 0x72, - DIGITAL_IO_REG_LIGHTS7 = 0x73, - DIGITAL_IO_REG_LIGHTS4 = 0x7d, - DIGITAL_IO_REG_LIGHTS5 = 0x7e, - DIGITAL_IO_REG_LIGHTS2 = 0x7f, - - FISHBAIT_IO_REG_UNKNOWN = 0x08, - FISHBAIT_IO_REG_MOTOR = 0x40, - FISHBAIT_IO_REG_BRAKE = 0x44, - FISHBAIT_IO_REG_ENCODER = 0x4c, - FISHBAIT_IO_REG_RESET_Y = 0x50 + DIGITAL_IO_REG_LIGHTS1 = 0x70, + DIGITAL_IO_REG_LIGHTS0 = 0x71, + DIGITAL_IO_REG_LIGHTS3 = 0x72, + DIGITAL_IO_REG_LIGHTS7 = 0x73, + DIGITAL_IO_REG_DS2401 = 0x77, + DIGITAL_IO_REG_FPGA_STATUS = 0x7b, + DIGITAL_IO_REG_FPGA_UPLOAD = 0x7c, + DIGITAL_IO_REG_LIGHTS4 = 0x7d, + DIGITAL_IO_REG_LIGHTS5 = 0x7e, + DIGITAL_IO_REG_LIGHTS2 = 0x7f, + + FISHBAIT_IO_REG_UNKNOWN = 0x08, + FISHBAIT_IO_REG_MOTOR = 0x40, + FISHBAIT_IO_REG_BRAKE = 0x44, + FISHBAIT_IO_REG_ENCODER = 0x4c, + FISHBAIT_IO_REG_RESET_Y = 0x50 } K573_IOBoardRegister; // The 573's real-time clock chip is an M48T58, which behaves like a standard diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c index 64722d7..3404ee4 100644 --- a/examples/io/system573/main.c +++ b/examples/io/system573/main.c @@ -207,7 +207,7 @@ int main(int argc, const char* argv[]) { // Change the currently active light if the test button on the 573's // front panel is pressed. DDR non-light outputs are skipped. - if ((last_inputs & JAMMA_TEST) && !(inputs & JAMMA_TEST)) { + if (!(last_inputs & JAMMA_TEST) && (inputs & JAMMA_TEST)) { current_light++; if ( (current_light == 4) || // DDR_LIGHT_P1_MUX_DATA -- cgit v1.2.3 From 6120304537470e7e5ff94b3bf19a33787ca69083 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Wed, 29 Jun 2022 12:40:46 +0200 Subject: Refactor libpsxgpu in C, add OT drawing queue --- examples/demos/n00bdemo/disp.c | 2 +- examples/sound/vagsample/main.c | 2 +- libpsn00b/CMakeLists.txt | 2 + libpsn00b/include/psxgpu.h | 69 ++++--- libpsn00b/psxgpu/addprim.s | 26 --- libpsn00b/psxgpu/clearotagr.s | 21 --- libpsn00b/psxgpu/common.c | 293 +++++++++++++++++++++++++++++ libpsn00b/psxgpu/dbugfont.c | 144 -------------- libpsn00b/psxgpu/drawotag.s | 38 ---- libpsn00b/psxgpu/drawprim.s | 41 ---- libpsn00b/psxgpu/drawsync.s | 67 ------- libpsn00b/psxgpu/drawsynccallback.s | 105 ----------- libpsn00b/psxgpu/env.c | 213 +++++++++++++++++++++ libpsn00b/psxgpu/fntsort.c | 48 ----- libpsn00b/psxgpu/font.c | 47 ++++- libpsn00b/psxgpu/getode.s | 20 -- libpsn00b/psxgpu/gettimimage.c | 40 ---- libpsn00b/psxgpu/getvideomode.s | 14 -- libpsn00b/psxgpu/image.c | 116 ++++++++++++ libpsn00b/psxgpu/loadimage.s | 70 ------- libpsn00b/psxgpu/putdispenv.s | 174 ----------------- libpsn00b/psxgpu/putdispenvraw.s | 71 ------- libpsn00b/psxgpu/putdrawenv.s | 142 -------------- libpsn00b/psxgpu/readgpustat.s | 14 -- libpsn00b/psxgpu/readme.txt | 22 +-- libpsn00b/psxgpu/resetgraph.s | 363 ------------------------------------ libpsn00b/psxgpu/setdefdispenv.c | 22 --- libpsn00b/psxgpu/setdefdrawenv.c | 27 --- libpsn00b/psxgpu/setdispmask.s | 19 -- libpsn00b/psxgpu/setvideomode.s | 50 ----- libpsn00b/psxgpu/storeimage.s | 76 -------- libpsn00b/psxgpu/vsynccallback.s | 25 --- 32 files changed, 722 insertions(+), 1661 deletions(-) delete mode 100644 libpsn00b/psxgpu/addprim.s delete mode 100644 libpsn00b/psxgpu/clearotagr.s create mode 100644 libpsn00b/psxgpu/common.c delete mode 100644 libpsn00b/psxgpu/dbugfont.c delete mode 100644 libpsn00b/psxgpu/drawotag.s delete mode 100644 libpsn00b/psxgpu/drawprim.s delete mode 100644 libpsn00b/psxgpu/drawsync.s delete mode 100644 libpsn00b/psxgpu/drawsynccallback.s create mode 100644 libpsn00b/psxgpu/env.c delete mode 100644 libpsn00b/psxgpu/fntsort.c delete mode 100644 libpsn00b/psxgpu/getode.s delete mode 100644 libpsn00b/psxgpu/gettimimage.c delete mode 100644 libpsn00b/psxgpu/getvideomode.s create mode 100644 libpsn00b/psxgpu/image.c delete mode 100644 libpsn00b/psxgpu/loadimage.s delete mode 100644 libpsn00b/psxgpu/putdispenv.s delete mode 100644 libpsn00b/psxgpu/putdispenvraw.s delete mode 100644 libpsn00b/psxgpu/putdrawenv.s delete mode 100644 libpsn00b/psxgpu/readgpustat.s delete mode 100644 libpsn00b/psxgpu/resetgraph.s delete mode 100644 libpsn00b/psxgpu/setdefdispenv.c delete mode 100644 libpsn00b/psxgpu/setdefdrawenv.c delete mode 100644 libpsn00b/psxgpu/setdispmask.s delete mode 100644 libpsn00b/psxgpu/setvideomode.s delete mode 100644 libpsn00b/psxgpu/storeimage.s delete mode 100644 libpsn00b/psxgpu/vsynccallback.s (limited to 'examples') diff --git a/examples/demos/n00bdemo/disp.c b/examples/demos/n00bdemo/disp.c index c134163..d8d2bbf 100644 --- a/examples/demos/n00bdemo/disp.c +++ b/examples/demos/n00bdemo/disp.c @@ -19,7 +19,7 @@ MATRIX mtx; void initDisplay() { - ResetGraph( 3 ); + ResetGraph( 0 ); if( GetVideoMode() == MODE_NTSC ) { SetDefDispEnv( &disp, 0, 0, 640, 480 ); diff --git a/examples/sound/vagsample/main.c b/examples/sound/vagsample/main.c index 2b04c34..5764541 100644 --- a/examples/sound/vagsample/main.c +++ b/examples/sound/vagsample/main.c @@ -127,7 +127,7 @@ void init(void) // Begin pad polling InitPAD( pad_buff[0], 34, pad_buff[1], 34 ); StartPAD(); - + ChangeClearPAD(0); } /* init */ // Display function diff --git a/libpsn00b/CMakeLists.txt b/libpsn00b/CMakeLists.txt index f9c4f9d..a662448 100644 --- a/libpsn00b/CMakeLists.txt +++ b/libpsn00b/CMakeLists.txt @@ -40,6 +40,8 @@ foreach(_library IN LISTS PSN00BSDK_LIBRARIES) psn00bsdk_add_library(${_library} STATIC ${_sources}) endforeach() +psn00bsdk_target_incbin(psxgpu PRIVATE _gpu_debug_font psxgpu/dbugfont.tim) + # Extract libgcc's contents and merge them into libc after building. # Unfortunately glob expressions won't work on Windows, so we have to manually # enumerate the contents of libgcc and save the list to a temporary file (as it diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h index f061219..53a24c9 100644 --- a/libpsn00b/include/psxgpu.h +++ b/libpsn00b/include/psxgpu.h @@ -1,6 +1,7 @@ #ifndef __PSXGPU_H #define __PSXGPU_H +#include #include // Low-level display parameters for DISPENV_RAW. A leftover from prototyping @@ -17,10 +18,11 @@ #define DISP_MODE_NTSC 0 #define DISP_MODE_PAL 8 - -#define MODE_NTSC 0 -#define MODE_PAL 1 - +typedef enum _VIDEO_MODE +{ + MODE_NTSC = 0, + MODE_PAL = 1 +} VIDEO_MODE; // Vector macros @@ -89,6 +91,12 @@ #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) + /* * Set texture coordinates */ @@ -569,50 +577,61 @@ typedef struct _TIM_IMAGE u_long *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; +} GsIMAGE; #ifdef __cplusplus extern "C" { #endif -// Function definitions (asm) +// Function definitions void ResetGraph(int mode); -int GetVideoMode(void); -void SetVideoMode(int mode); +VIDEO_MODE GetVideoMode(void); +void SetVideoMode(VIDEO_MODE mode); int GetODE(void); -void PutDispEnvRaw(DISPENV_RAW *disp); /* obsolete */ -void PutDispEnv(DISPENV *disp); -void PutDrawEnv(DRAWENV *draw); +void PutDispEnvRaw(const DISPENV_RAW *env); /* obsolete */ +void PutDispEnv(const DISPENV *env); +void PutDrawEnv(DRAWENV *env); +void PutDrawEnvFast(DRAWENV *env); void SetDispMask(int mask); -int VSync(int m); -int DrawSync(int m); -void WaitGPUcmd(void); -void WaitGPUdma(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(RECT *rect, u_long *data); -void StoreImage(RECT *rect, u_long *data); - -void ClearOTagR(u_long* ot, int n); -void DrawOTag(u_long* ot); -void DrawPrim(void *pri); +void LoadImage(const RECT *rect, const u_long *data); +void StoreImage(const RECT *rect, u_long *data); -void AddPrim(u_long* ot, void* pri); +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); -// Function definitions (C) +void AddPrim(u_long *ot, const void *pri); -int GetTimInfo(const u_long *tim, TIM_IMAGE *timimg); /* ORIGINAL */ +int GsGetTimInfo(const u_long *tim, GsIMAGE *info); +int GetTimInfo(const u_long *tim, TIM_IMAGE *info); /* deprecated */ -DISPENV *SetDefDispEnv(DISPENV *disp, int x, int y, int w, int h); -DRAWENV *SetDefDrawEnv(DRAWENV *draw, int x, int y, int w, int h); +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 diff --git a/libpsn00b/psxgpu/addprim.s b/libpsn00b/psxgpu/addprim.s deleted file mode 100644 index 1b66274..0000000 --- a/libpsn00b/psxgpu/addprim.s +++ /dev/null @@ -1,26 +0,0 @@ -.set noreorder -.set noat - -.section .text - - -.global AddPrim -.type AddPrim, @function -AddPrim: - - lw $v0, 0($a0) # Load OT entry - lw $v1, 0($a1) # Set packet length value (in words) - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at # Mask off the upper 8 bits of OT entry - or $v1, $v0 # OR values together - sw $v1, 0($a1) # Store new address to primitive tag - lw $v0, 0($a0) # Load OT entry - and $a1, $at # Mask off the upper 8 bits of primitive tag - lui $at, 0xff00 - and $v0, $at # Mask off the first 24 bits of OT entry - or $v0, $a1 # OR values together - - jr $ra - sw $v0, 0($a0) # Store result to OT - diff --git a/libpsn00b/psxgpu/clearotagr.s b/libpsn00b/psxgpu/clearotagr.s deleted file mode 100644 index 562cad4..0000000 --- a/libpsn00b/psxgpu/clearotagr.s +++ /dev/null @@ -1,21 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .text - - -.global ClearOTagR -.type ClearOTagR, @function -ClearOTagR: - lui $a2, IOBASE - addi $v0, $a1, -1 - sll $v0, 2 - addu $a0, $v0 - sw $a0, DMA6_MADR($a2) - andi $a1, 0xffff - sw $a1, DMA6_BCR($a2) - lui $v0, 0x1100 - addiu $v0, 2 - jr $ra - sw $v0, DMA6_CHCR($a2) diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c new file mode 100644 index 0000000..ee90225 --- /dev/null +++ b/libpsn00b/psxgpu/common.c @@ -0,0 +1,293 @@ +/* + * PSn00bSDK GPU library (common functions) + * (C) 2022 spicyjpeg - MPL licensed + */ + +#include +#include +#include +#include +#include +#include +#include + +#define QUEUE_LENGTH 8 +#define DMA_CHUNK_LENGTH 8 +#define VSYNC_TIMEOUT 0x100000 + +/* Internal globals */ + +VIDEO_MODE _gpu_video_mode; + +static void (*_vsync_callback)(void); +static void (*_drawsync_callback)(void); + +static const u_long *volatile _draw_queue[QUEUE_LENGTH]; +static volatile uint8_t _queue_head, _queue_tail, _queue_length; +static volatile uint32_t _vblank_counter, _last_hblank; + +/* Interrupt handlers */ + +static void _vblank_handler(void) { + _vblank_counter++; + + if (_vsync_callback) + _vsync_callback(); +} + +static void _gpu_dma_handler(void) { + //while (DMA_CHCR(2) & (1 << 24)) + //__asm__ volatile(""); + while (!(GPU_GP1 & (1 << 28))) + __asm__ volatile(""); + + if (_queue_length) { + DrawOTag2(_draw_queue[_queue_head++]); + + _queue_length--; + _queue_head %= QUEUE_LENGTH; + } else { + GPU_GP1 = 0x04000000; // Disable DMA request + + if (_drawsync_callback) + _drawsync_callback(); + } +} + +/* GPU reset and system initialization */ + +void ResetGraph(int mode) { + // Perform some basic system initialization when ResetGraph() is called for + // the first time. + static int setup_done = 0; + if (!setup_done) { + EnterCriticalSection(); + + DMA_DPCR = 0x03333333; + DMA_DICR = 0; + IRQ_MASK = 0; + + InterruptCallback(0, &_vblank_handler); + DMACallback(2, &_gpu_dma_handler); + RestartCallback(); + _96_remove(); + + _gpu_video_mode = (GPU_GP1 >> 20) & 1; + setup_done = 1; + + ExitCriticalSection(); + printf("psxgpu: setup done, default mode is %s\n", _gpu_video_mode ? "PAL" : "NTSC"); + } + + if (mode == 3) { + GPU_GP1 = 0x01000000; // Reset command buffer + return; + } + + DMA_DPCR |= 0x0b000b00; // Enable DMA2 and DMA6 + DMA_CHCR(2) = 0x00000201; // Stop DMA2 + DMA_CHCR(6) = 0x00000200; // Stop DMA6 + + if (mode == 1) { + GPU_GP1 = 0x01000000; // Reset command buffer + return; + } + + GPU_GP1 = 0x00000000; // Reset GPU + TIMER_CTRL(0) = 0x0500; + TIMER_CTRL(1) = 0x0500; + + _queue_head = 0; + _queue_tail = 0; + _queue_length = 0; + _vblank_counter = 0; + _last_hblank = 0; +} + +/* Syncing API */ + +// TODO: add support for no$psx's "halt" register +static void _vsync_halt(void) { + int counter = _vblank_counter; + + for (int i = VSYNC_TIMEOUT; i; i--) { + if (counter != _vblank_counter) + return; + } + + printf("psxgpu: VSync() timeout\n"); + ChangeClearPAD(0); + ChangeClearRCnt(3, 0); + return; +} + +int VSync(int mode) { + if (mode < 0) + return _vblank_counter; + + uint32_t status = GPU_GP1; + + // If mode = 0, wait for one vertical blank event to occur. If mode = 1, do + // not wait. + for (int i = ((mode < 2) ? (mode ^ 1) : mode); i; i--) { + _vsync_halt(); + + // If interlaced mode is enabled, wait until the GPU starts displaying + // the next field. + if (status & (1 << 22)) { + while (!((GPU_GP1 ^ status) & (1 << 31))) + __asm__ volatile(""); + } + } + + // Update the horizontal blank counter and return the time elapsed since + // the last time it was updated. + uint16_t counter = TIMER_VALUE(1); + uint16_t delta = counter - _last_hblank; + + _last_hblank = counter; + return delta; +} + +int DrawSync(int mode) { + if (mode) + return (DMA_BCR(2) >> 16); + + // Wait for the queue to become empty, to make sure no . + // TODO: add a timeout + while (_queue_length) + __asm__ volatile(""); + + // Wait for any DMA transfer to finish if DMA is enabled. + if (GPU_GP1 & (3 << 29)) { + while (DMA_CHCR(2) & (1 << 24)) + __asm__ volatile(""); + while (!(GPU_GP1 & (1 << 28))) + __asm__ volatile(""); + } + + while (!(GPU_GP1 & (1 << 26))) + __asm__ volatile(""); + + return 0; +} + +void *VSyncCallback(void (*func)(void)) { + EnterCriticalSection(); + + void *old_callback = _vsync_callback; + _vsync_callback = func; + + ExitCriticalSection(); + return old_callback; +} + +void *DrawSyncCallback(void (*func)(void)) { + EnterCriticalSection(); + + void *old_callback = _drawsync_callback; + _drawsync_callback = func; + + ExitCriticalSection(); + return old_callback; +} + +/* OT and primitive drawing API */ + +void ClearOTagR(u_long *ot, size_t length) { + DMA_MADR(6) = (uint32_t) &ot[length - 1]; + DMA_BCR(6) = length & 0xffff; + DMA_CHCR(6) = 0x11000002; + + //while (DMA_CHCR(6) & (1 << 24)) + //__asm__ volatile(""); +} + +void ClearOTag(u_long *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[length - 1] = 0x00ffffff; +} + +void DrawOTag(const u_long *ot) { + // If GPU DMA is currently busy, append the OT to the queue instead of + // drawing it immediately. + if (DMA_CHCR(2) & (1 << 24)) { + if (_queue_length >= QUEUE_LENGTH) { + printf("psxgpu: DrawOTag() failed, draw queue full\n"); + return; + } + + _draw_queue[_queue_tail++] = ot; + _queue_length++; + _queue_tail %= QUEUE_LENGTH; + return; + } + + DrawOTag2(ot); +} + +void DrawOTag2(const u_long *ot) { + GPU_GP1 = 0x04000002; + + while (!(GPU_GP1 & (1 << 26))) + __asm__ volatile(""); + + DMA_MADR(2) = (uint32_t) ot; + DMA_BCR(2) = 0; + DMA_CHCR(2) = 0x01000401; +} + +void DrawPrim(const u_long *pri) { + size_t length = getlen(pri); + + DrawSync(0); + GPU_GP1 = 0x04000002; + + // NOTE: if length >= DMA_CHUNK_LENGTH then it also has to be a multiple of + // DMA_CHUNK_LENGTH, otherwise the DMA channel will get stuck waiting for + // more data indefinitely. + DMA_MADR(2) = (uint32_t) &pri[1]; + if (length < DMA_CHUNK_LENGTH) + DMA_BCR(2) = 0x00010000 | length; + else + DMA_BCR(2) = DMA_CHUNK_LENGTH | ((length / DMA_CHUNK_LENGTH) << 16); + + DMA_CHCR(2) = 0x01000201; +} + +void AddPrim(u_long *ot, const void *pri) { + addPrim(ot, pri); +} + +/* Misc. functions */ + +VIDEO_MODE GetVideoMode(void) { + return _gpu_video_mode; +} + +void SetVideoMode(VIDEO_MODE mode) { + uint32_t _mode, stat = GPU_GP1; + + _gpu_video_mode = mode & 1; + + _mode = (mode & 1) << 3; + _mode |= (stat >> 17) & 0x37; // GPUSTAT 17-22 -> cmd bits 0-5 + _mode |= (stat >> 10) & 0x40; // GPUSTAT bit 16 -> cmd bit 6 + _mode |= (stat >> 7) & 0x80; // GPUSTAT bit 14 -> cmd bit 7 + + GPU_GP1 = 0x08000000 | mode; +} + +int GetODE(void) { + return (GPU_GP1 >> 31); +} + +void SetDispMask(int mask) { + GPU_GP1 = 0x03000000 | (mask ? 0 : 1); +} diff --git a/libpsn00b/psxgpu/dbugfont.c b/libpsn00b/psxgpu/dbugfont.c deleted file mode 100644 index ff21d84..0000000 --- a/libpsn00b/psxgpu/dbugfont.c +++ /dev/null @@ -1,144 +0,0 @@ -unsigned int dbugfont_size=2112; -unsigned char dbugfont[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x00,0x00,0xe0, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x08,0x00,0x00,0x80,0x02,0x00,0x00, -0x20,0x00,0x20,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01, -0x00,0x10,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x11, -0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x11,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01, -0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x10,0x00,0x10,0x00,0x10,0x00, -0x01,0x00,0x00,0x11,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x01,0x00, -0x00,0x00,0x00,0x00,0x00,0x10,0x11,0x11,0x00,0x01,0x01,0x00,0x00,0x11,0x01, -0x01,0x00,0x10,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x10,0x00,0x00,0x00,0x00, -0x10,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x10,0x00,0x11, -0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x10,0x11, -0x00,0x00,0x10,0x10,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x10, -0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x11,0x00,0x00,0x11,0x11,0x01,0x00, -0x00,0x00,0x00,0x00,0x11,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00, -0x00,0x10,0x10,0x10,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x11, -0x11,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,0x10,0x01,0x00,0x00, -0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x01,0x01,0x01,0x00, -0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x01,0x00,0x00,0x10,0x01,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x10,0x10,0x11,0x00,0x01, -0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00, -0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x11,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x01, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x10,0x11,0x00,0x00,0x01, -0x00,0x01,0x00,0x10,0x01,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00, -0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x11, -0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x10,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x11,0x01,0x00,0x00, -0x11,0x01,0x00,0x00,0x10,0x01,0x00,0x10,0x11,0x11,0x00,0x00,0x10,0x01,0x00, -0x10,0x11,0x11,0x00,0x00,0x11,0x01,0x00,0x00,0x11,0x01,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x00, -0x00,0x00,0x00,0x11,0x01,0x00,0x00,0x11,0x11,0x00,0x00,0x11,0x00,0x00,0x10, -0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x01,0x01,0x00,0x10,0x00,0x00,0x00, -0x00,0x01,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10, -0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x01,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x01,0x10, -0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x01,0x00, -0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10, -0x00,0x10,0x00,0x10,0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x01, -0x00,0x00,0x10,0x11,0x11,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x10, -0x10,0x01,0x01,0x00,0x10,0x00,0x00,0x00,0x10,0x01,0x00,0x00,0x10,0x01,0x00, -0x10,0x11,0x11,0x00,0x10,0x11,0x01,0x00,0x10,0x11,0x01,0x00,0x00,0x00,0x01, -0x00,0x00,0x11,0x01,0x00,0x00,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, -0x00,0x01,0x00,0x10,0x10,0x01,0x01,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00, -0x00,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10, -0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x10,0x11,0x11,0x00,0x00, -0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x10,0x11,0x00,0x00,0x10,0x00,0x00, -0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x10, -0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00, -0x01,0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x10,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00, -0x10,0x11,0x11,0x00,0x10,0x11,0x11,0x00,0x00,0x11,0x01,0x00,0x00,0x00,0x01, -0x00,0x10,0x11,0x01,0x00,0x00,0x11,0x01,0x00,0x00,0x10,0x00,0x00,0x00,0x11, -0x01,0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00, -0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x00, -0x00,0x11,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10, -0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x11,0x01, -0x00,0x00,0x11,0x01,0x00,0x10,0x11,0x01,0x00,0x10,0x11,0x11,0x00,0x10,0x11, -0x11,0x00,0x00,0x11,0x11,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x11,0x00,0x00, -0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00, -0x10,0x00,0x10,0x00,0x00,0x11,0x01,0x00,0x10,0x11,0x01,0x00,0x00,0x01,0x01, -0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00, -0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00, -0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00, -0x10,0x01,0x11,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10, -0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00, -0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10, -0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x01,0x00, -0x10,0x00,0x00,0x00,0x10,0x10,0x10,0x00,0x10,0x01,0x10,0x00,0x10,0x00,0x10, -0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x01,0x00,0x10,0x00, -0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x00,0x00,0x10,0x11,0x00,0x00,0x10, -0x10,0x11,0x00,0x10,0x11,0x11,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00, -0x10,0x11,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x10,0x10, -0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x11,0x00,0x10,0x00, -0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10, -0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00, -0x10,0x00,0x10,0x00,0x10,0x00,0x01,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10, -0x00,0x10,0x00,0x11,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x01,0x00,0x10,0x00, -0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10, -0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00, -0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00, -0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00, -0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x01,0x00,0x00,0x11,0x01,0x00,0x10, -0x11,0x01,0x00,0x10,0x11,0x11,0x00,0x10,0x00,0x00,0x00,0x00,0x11,0x01,0x00, -0x10,0x00,0x10,0x00,0x10,0x11,0x11,0x00,0x00,0x11,0x01,0x00,0x10,0x00,0x10, -0x00,0x10,0x11,0x11,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x11, -0x01,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x01,0x00,0x10, -0x11,0x01,0x00,0x00,0x11,0x01,0x00,0x10,0x11,0x11,0x00,0x10,0x00,0x10,0x00, -0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10, -0x00,0x10,0x11,0x11,0x00,0x00,0x11,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x11, -0x01,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x00,0x10, -0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00, -0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10, -0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x01,0x00,0x00,0x10,0x00, -0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x11,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00, -0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10, -0x00,0x00,0x01,0x01,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0x01, -0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x10,0x01,0x11,0x00,0x00, -0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x01,0x00, -0x00,0x11,0x01,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10, -0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x10, -0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x01,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x00, -0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10, -0x00,0x10,0x00,0x10,0x00,0x10,0x10,0x10,0x00,0x00,0x01,0x01,0x00,0x00,0x10, -0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x00, -0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x10,0x00,0x01,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00, -0x00,0x10,0x00,0x10,0x00,0x00,0x01,0x01,0x00,0x10,0x01,0x11,0x00,0x10,0x00, -0x10,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x11,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x11,0x01, -0x00,0x00,0x10,0x00,0x00,0x00,0x11,0x01,0x00,0x00,0x10,0x00,0x00,0x10,0x00, -0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x10,0x11,0x11,0x00,0x00, -0x11,0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x11,0x01,0x00,0x00,0x00,0x00,0x00, -0x11,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -}; diff --git a/libpsn00b/psxgpu/drawotag.s b/libpsn00b/psxgpu/drawotag.s deleted file mode 100644 index 3cb0db0..0000000 --- a/libpsn00b/psxgpu/drawotag.s +++ /dev/null @@ -1,38 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .text - - -.global DrawOTag -.type DrawOTag, @function -DrawOTag: - addiu $sp, -4 - sw $ra, 0($sp) - - lui $a3, IOBASE # I/O segment base - - lui $v0, 0x0400 # Set DMA direction to CPUtoGPU - ori $v0, 0x2 - sw $v0, GPU_GP1($a3) - -.Lgpu_wait: # Wait for GPU to be ready for commands & DMA - jal ReadGPUstat - nop - srl $v0, 26 - andi $v0, 1 - beqz $v0, .Lgpu_wait - nop - - sw $a0, DMA2_MADR($a3) # Set DMA base address to specified OT - sw $0 , DMA2_BCR($a3) - - lui $v0, 0x0100 # Begin OT transfer! - ori $v0, 0x0401 - sw $v0, DMA2_CHCR($a3) - - lw $ra, 0($sp) - addiu $sp, 4 - jr $ra - nop diff --git a/libpsn00b/psxgpu/drawprim.s b/libpsn00b/psxgpu/drawprim.s deleted file mode 100644 index d62c202..0000000 --- a/libpsn00b/psxgpu/drawprim.s +++ /dev/null @@ -1,41 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.text - -.global DrawPrim -.type DrawPrim, @function -DrawPrim: - - addiu $sp, -8 - sw $ra, 0($sp) - sw $s0, 4($sp) - - move $s0, $a0 # Wait for GPU to complete - jal DrawSync - move $a0, $0 - - lui $a3, IOBASE - lui $v0, 0x0400 # Set transfer direction to off - sw $v0, GPU_GP1($a3) - - move $a0, $s0 - lbu $a1, 3($a0) # Get length of primitive packet - addiu $a0, 4 - addiu $a1, -1 - -.Ltransfer_loop: - lw $v0, 0($a0) - addiu $a0, 4 - sw $v0, GPU_GP0($a3) - bgtz $a1, .Ltransfer_loop - addiu $a1, -1 - - jal DrawSync - move $a0, $0 - - lw $ra, 0($sp) - lw $s0, 4($sp) - jr $ra - addiu $sp, 8 \ No newline at end of file diff --git a/libpsn00b/psxgpu/drawsync.s b/libpsn00b/psxgpu/drawsync.s deleted file mode 100644 index b671b03..0000000 --- a/libpsn00b/psxgpu/drawsync.s +++ /dev/null @@ -1,67 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .text - - -.global DrawSync -.type DrawSync, @function -DrawSync: - - bnez $a0, .Lgetwords - lui $a0, IOBASE - - addiu $sp, -4 - sw $ra, 0($sp) - - jal ReadGPUstat # Check if DMA enabled - nop - srl $v0, 29 - andi $v0, 0x3 - - beqz $v0, .Lsimple_wait - nop - -.Ldma_wait: - lw $v0, DMA2_CHCR($a0) - nop - srl $v0, 24 - andi $v0, 0x1 - bnez $v0, .Ldma_wait - nop - -.Lgpu_wait: - jal ReadGPUstat - nop - srl $v0, 26 - andi $v0, 0x5 - bne $v0, 5, .Lgpu_wait - nop - - b .Lexit - nop - -.Lsimple_wait: # Wait for GPU to be ready for next DMA - jal ReadGPUstat - nop - srl $v0, 28 - andi $v0, 0x1 - beqz $v0, .Lsimple_wait - nop - -.Lexit: - - lw $ra, 0($sp) - addiu $sp, 4 - jr $ra - nop - -.Lgetwords: - - lw $v0, DMA2_BCR($a0) - nop - - jr $ra - srl $v0, 16 - diff --git a/libpsn00b/psxgpu/drawsynccallback.s b/libpsn00b/psxgpu/drawsynccallback.s deleted file mode 100644 index 22cfb7d..0000000 --- a/libpsn00b/psxgpu/drawsynccallback.s +++ /dev/null @@ -1,105 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.text - -.global DrawSyncCallback -.type DrawSyncCallback, @function -DrawSyncCallback: - - addiu $sp, -8 - sw $ra, 0($sp) - sw $a0, 4($sp) - - jal EnterCriticalSection - nop - - beqz $a0, .Luninstall - nop - - la $a1, _drawsync_handler - lw $a1, 4($sp) - jal DMACallback - li $a0, 2 - - b .Lcontinue - nop - -.Luninstall: - - move $a1, $0 - jal DMACallback - li $a0, 2 - -.Lcontinue: - - lw $a0, 4($sp) - la $v1, _drawsync_func - lw $v0, 0($v1) - sw $a0, 0($v1) - sw $v0, 4($sp) - -.Lexit: - - jal ExitCriticalSection - nop - - lw $ra, 0($sp) - lw $v0, 4($sp) - jr $ra - addiu $sp, 8 - - -.type _drawsync_handler, @function -_drawsync_handler: - -.Ldma_wait: - la $v0, _drawsync_func - lw $v0, 0($v0) - nop - beqz $v0, .Lskip - nop - - addiu $sp, -4 - sw $ra, 0($sp) - - lw $v0, DMA2_CHCR($a0) - nop - srl $v0, 24 - andi $v0, 0x1 - - bnez $v0, .Ldma_wait - nop - -.Lgpu_wait: - jal ReadGPUstat - nop - srl $v0, 28 - andi $v0, 0x1 - beqz $v0, .Lgpu_wait - nop - - la $v1, _drawsync_func - lw $v1, 0($v1) - - lui $v0, 0x0400 # Set DMA direction to off - sw $v0, GPU_GP1($a0) - - jalr $v1 - nop - - lw $ra, 0($sp) - addiu $sp, 4 - -.Lskip: - - jr $ra - nop - - -.data - -_drawsync_func: - .word 0 - \ No newline at end of file diff --git a/libpsn00b/psxgpu/env.c b/libpsn00b/psxgpu/env.c new file mode 100644 index 0000000..8a74b7e --- /dev/null +++ b/libpsn00b/psxgpu/env.c @@ -0,0 +1,213 @@ +/* + * PSn00bSDK GPU library (DRAWENV/DISPENV functions) + * (C) 2022 spicyjpeg - MPL licensed + */ + +#include +#include +#include +#include + +#define _min(x, y) (((x) < (y)) ? (x) : (y)) + +extern VIDEO_MODE _gpu_video_mode; + +/* Drawing API */ + +DRAWENV *SetDefDrawEnv(DRAWENV *env, int x, int y, int w, int h) { + env->clip.x = x; + env->clip.y = y; + env->clip.w = w; + env->clip.h = h; + + env->ofs[0] = 0; + env->ofs[1] = 0; + + env->tw.x = 0; + env->tw.y = 0; + env->tw.w = 0; + env->tw.h = 0; + + env->tpage = 0x0a; + env->dtd = 1; + env->dfe = 0; + env->isbg = 0; + setRGB0(env, 0, 0, 0); + + env->dr_env.tag = 0; + return env; +} + +void DrawOTagEnv(const u_long *ot, DRAWENV *env) { + DR_ENV *prim = &(env->dr_env); + + // All commands are grouped into a single display list packet for + // performance reasons (keep in mind that the GPU doesn't care about this + // as the display list is parsed by the DMA unit in the CPU and only the + // payload is sent to the GPU). + setaddr(prim, ot); + setlen(prim, 4); + + // Set drawing area top left + prim->code[0] = 0xe3000000; + prim->code[0] |= env->clip.x & 0x3ff; + prim->code[0] |= (env->clip.y & 0x3ff) << 10; + + // Set drawing area bottom right + prim->code[1] = 0xe4000000; + prim->code[1] |= (env->clip.x + (env->clip.w - 1)) & 0x3ff; + prim->code[1] |= ((env->clip.y + (env->clip.h - 1)) & 0x3ff) << 10; + + // Set drawing offset + prim->code[2] = 0xe5000000; + prim->code[2] |= (env->clip.x + env->ofs[0]) & 0x7ff; + prim->code[2] |= ((env->clip.y + env->ofs[1]) & 0x7ff) << 11; + + // Texture page (reset active page and set dither/mask bits) + prim->code[3] = 0xe1000000; + prim->code[3] |= (env->dtd & 1) << 9; + prim->code[3] |= (env->dfe & 1) << 10; + + if (env->isbg) { + setlen(prim, 7); + + // Rectangle fill + // FIXME: reportedly this command doesn't accept height values >511... + prim->code[4] = 0x02000000; + //prim->code[4] |= env->r0 | (env->g0 << 8) | (env->b0 << 16); + prim->code[4] |= *((const uint32_t *) &(env->isbg)) >> 8; + //prim->code[5] = env->clip.x; + //prim->code[5] |= env->clip.y << 16; + prim->code[5] = *((const uint32_t *) &(env->clip.x)); + prim->code[6] = env->clip.w; + prim->code[6] |= _min(env->clip.h, 0x1ff) << 16; + } + + //while (!(GPU_GP1 & (1 << 26))) + //__asm__ volatile(""); + + DrawOTag(prim); +} + +void PutDrawEnv(DRAWENV *env) { + DrawOTagEnv((const u_long *) 0x00ffffff, env); +} + +// This function skips rebuilding the cached packet whenever possible and is +// useful if the DRAWENV structure is never modified (which is the case most of +// the time). +void PutDrawEnvFast(DRAWENV *env) { + if (!(env->dr_env.tag)) { + DrawOTagEnv((const u_long *) 0x00ffffff, env); + return; + } + + DrawOTag(&(env->dr_env)); +} + +/* Display API */ + +DISPENV *SetDefDispEnv(DISPENV *env, int x, int y, int w, int h) { + env->disp.x = x; + env->disp.y = y; + env->disp.w = w; + env->disp.h = h; + + env->screen.x = 0; + env->screen.y = 0; + env->screen.w = 0; + env->screen.h = 0; + + env->isinter = 0; + env->isrgb24 = 0; + env->reverse = 0; + + return env; +} + +void PutDispEnv(const DISPENV *env) { + uint32_t h_range, v_range, mode, fb_pos; + + mode = _gpu_video_mode << 3; + mode |= (env->isrgb24 & 1) << 4; + mode |= (env->isinter & 1) << 5; + mode |= (env->reverse & 1) << 7; + + if (env->disp.h >= 256) + mode |= 1 << 2; + + // Calculate the horizontal display range values. The original code was + // this bad; in actual fact it was even worse due to being written in + // assembly and using slow multiplication even when not necessary. + int offset, span, default_span = 2560; + + if (env->disp.w > 560) { + // 640 pixels + mode |= 3; + offset = 620; + span = env->screen.w * 4; + } else if (env->disp.w > 400) { + // 512 pixels + mode |= 2; + offset = 615; + span = env->screen.w * 4 + env->screen.w; + } else if (env->disp.w > 352) { + // 384 pixels (this mode is weird) + mode |= 1 << 6; + offset = 539; + span = env->screen.w * 8 - env->screen.w; + default_span = 2688; + } else if (env->disp.w > 280) { + // 320 pixels + mode |= 1; + offset = 600; + span = env->screen.w * 8; + } else { + // 256 pixels + offset = 590; + span = env->screen.w * 8 + env->screen.w * 2; + } + + offset += env->screen.x * 4; + if (!span) + span = default_span; + + h_range = offset & 0xfff; + h_range |= ((offset + span) & 0xfff) << 12; + + // Calculate the vertical display range values. + offset = 16 + env->screen.y; + span = env->screen.h ? env->screen.h : 240; + + v_range = offset & 0x3ff; + v_range |= ((offset + span) & 0x3ff) << 10; + + fb_pos = env->disp.x & 0x3ff; + fb_pos |= (env->disp.y & 0x1ff) << 10; + + GPU_GP1 = 0x06000000 | h_range; // Set horizontal display range + GPU_GP1 = 0x07000000 | v_range; // Set vertical display range + GPU_GP1 = 0x08000000 | mode; // Set video mode + GPU_GP1 = 0x05000000 | fb_pos; // Set VRAM location to display +} + +/* Deprecated "raw" display API */ + +void PutDispEnvRaw(const DISPENV_RAW *env) { + uint32_t h_range, v_range, fb_pos; + + h_range = 608 + env->vid_xpos; + h_range |= (3168 + env->vid_xpos) << 12; + + // FIXME: these hardcoded values are for NTSC displays. + v_range = (136 - 120 + env->vid_ypos) & 0x3ff; + v_range |= ((136 + 120 + env->vid_ypos) & 0x3ff) << 12; + + fb_pos = env->fb_x & 0x3ff; + fb_pos |= (env->fb_y & 0x1ff) << 10; + + GPU_GP1 = 0x06000000 | h_range; // Set horizontal display range + GPU_GP1 = 0x07000000 | v_range; // Set vertical display range + GPU_GP1 = 0x08000000 | env->vid_mode; // Set video mode + GPU_GP1 = 0x05000000 | fb_pos; // Set VRAM location to display +} diff --git a/libpsn00b/psxgpu/fntsort.c b/libpsn00b/psxgpu/fntsort.c deleted file mode 100644 index 9358793..0000000 --- a/libpsn00b/psxgpu/fntsort.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include - -extern unsigned short _font_tpage; -extern unsigned short _font_clut; - -char *FntSort(u_long *ot, char *pri, int x, int y, const char *text) { - - DR_TPAGE *tpage; - SPRT_8 *sprt = (SPRT_8*)pri; - int i; - - while( *text != 0 ) { - - i = toupper( *text )-32; - - if( i > 0 ) { - - i--; - setSprt8( sprt ); - setRGB0( sprt, 128, 128, 128 ); - setXY0( sprt, x, y ); - setUV0( sprt, (i%16)<<3, (i>>4)<<3 ); - sprt->clut = _font_clut; - addPrim( ot, sprt ); - sprt++; - - } - - x += 8; - text++; - - } - - pri = (char*)sprt; - - tpage = (DR_TPAGE*)pri; - tpage->code[0] = _font_tpage; - setlen( tpage, 1 ); - setcode( tpage, 0xe1 ); - addPrim( ot, pri ); - pri += sizeof(DR_TPAGE); - - return pri; - -} \ No newline at end of file diff --git a/libpsn00b/psxgpu/font.c b/libpsn00b/psxgpu/font.c index 4c715a9..7a8137c 100644 --- a/libpsn00b/psxgpu/font.c +++ b/libpsn00b/psxgpu/font.c @@ -21,14 +21,14 @@ static int _nstreams = 0; u_short _font_tpage; u_short _font_clut; -extern u_char dbugfont[]; +extern u_char _gpu_debug_font[]; void FntLoad(int x, int y) { RECT pos; TIM_IMAGE tim; - GetTimInfo( (u_long*)dbugfont, &tim ); + GetTimInfo( (const u_long *) _gpu_debug_font, &tim ); // Load font image pos = *tim.prect; @@ -223,4 +223,45 @@ char *FntFlush(int id) { return _stream[id].pribuff; -} \ No newline at end of file +} + +char *FntSort(u_long *ot, char *pri, int x, int y, const char *text) { + + DR_TPAGE *tpage; + SPRT_8 *sprt = (SPRT_8*)pri; + int i; + + while( *text != 0 ) { + + i = toupper( *text )-32; + + if( i > 0 ) { + + i--; + setSprt8( sprt ); + setRGB0( sprt, 128, 128, 128 ); + setXY0( sprt, x, y ); + setUV0( sprt, (i%16)<<3, (i>>4)<<3 ); + sprt->clut = _font_clut; + addPrim( ot, sprt ); + sprt++; + + } + + x += 8; + text++; + + } + + pri = (char*)sprt; + + tpage = (DR_TPAGE*)pri; + tpage->code[0] = _font_tpage; + setlen( tpage, 1 ); + setcode( tpage, 0xe1 ); + addPrim( ot, pri ); + pri += sizeof(DR_TPAGE); + + return pri; + +} diff --git a/libpsn00b/psxgpu/getode.s b/libpsn00b/psxgpu/getode.s deleted file mode 100644 index 5dc1e70..0000000 --- a/libpsn00b/psxgpu/getode.s +++ /dev/null @@ -1,20 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .text - - -.global GetODE -.type GetODE, @function -GetODE: - addiu $sp, -4 - sw $ra, 0($sp) - jal ReadGPUstat - nop - srl $v0, 31 - andi $v0, 1 - lw $ra, 0($sp) - addiu $sp, 4 - jr $ra - nop diff --git a/libpsn00b/psxgpu/gettimimage.c b/libpsn00b/psxgpu/gettimimage.c deleted file mode 100644 index 5598e07..0000000 --- a/libpsn00b/psxgpu/gettimimage.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include - -int GetTimInfo(const u_long *tim, TIM_IMAGE *timimg) { - - u_long *rtim; - - // Check ID - if( ( tim[0]&0xff ) != 0x10 ) { - return 1; - } - - // Check version - if( ( (tim[0]>>8)&0xff ) != 0x0 ) { - return 2; - } - - timimg->mode = tim[1]; - rtim = tim+2; - - // Clut present? - if( timimg->mode & 0x8 ) { - - timimg->crect = (RECT*)(rtim+1); - timimg->caddr = (u_long*)(rtim+3); - - rtim += rtim[0]>>2; - - } else { - - timimg->caddr = 0; - - } - - timimg->prect = (RECT*)(rtim+1); - timimg->paddr = (u_long*)(rtim+3); - - return 0; - -} diff --git a/libpsn00b/psxgpu/getvideomode.s b/libpsn00b/psxgpu/getvideomode.s deleted file mode 100644 index 6f1613c..0000000 --- a/libpsn00b/psxgpu/getvideomode.s +++ /dev/null @@ -1,14 +0,0 @@ -.set noreorder - - -.section .text - -.global GetVideoMode -.type GetVideoMode, @function -GetVideoMode: - - la $v0, _gpu_standard - lw $v0, 0($v0) - - jr $ra - nop diff --git a/libpsn00b/psxgpu/image.c b/libpsn00b/psxgpu/image.c new file mode 100644 index 0000000..3633c7c --- /dev/null +++ b/libpsn00b/psxgpu/image.c @@ -0,0 +1,116 @@ +/* + * PSn00bSDK GPU library (image and VRAM transfer functions) + * (C) 2022 spicyjpeg - MPL licensed + */ + +#include +#include +#include +#include +#include + +#define DMA_CHUNK_LENGTH 8 + +/* Common internal load/store function */ + +static void _load_store_image( + uint32_t command, + int mode, + const RECT *rect, + uint32_t *data +) { + size_t length = rect->w * rect->h; + if (length % 2) + printf("psxgpu: can't transfer an odd number of pixels\n"); + + length /= 2; + if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) + printf("psxgpu: transfer data length (%d) is not a multiple of %d\n", length, DMA_CHUNK_LENGTH); + + DrawSync(0); + GPU_GP1 = 0x04000000; // Disable DMA request + GPU_GP0 = 0x01000000; // Flush cache + + GPU_GP0 = command; + //GPU_GP0 = rect->x | (rect->y << 16); + GPU_GP0 = *((const uint32_t *) &(rect->x)); + //GPU_GP0 = rect->w | (rect->h << 16); + GPU_GP0 = *((const uint32_t *) &(rect->w)); + + // Enable DMA request, route to GP0 (2) or from GPU_READ (3) + GPU_GP1 = 0x04000000 | mode; + + DMA_MADR(2) = (uint32_t) data; + if (length < DMA_CHUNK_LENGTH) + DMA_BCR(2) = 0x00010000 | length; + else + DMA_BCR(2) = DMA_CHUNK_LENGTH | ((length / DMA_CHUNK_LENGTH) << 16); + + DMA_CHCR(2) = 0x01000200 | !(mode & 1); +} + +/* Public VRAM API */ + +void LoadImage(const RECT *rect, const u_long *data) { + _load_store_image(0xa0000000, 2, rect, (uint32_t *) data); +} + +void StoreImage(const RECT *rect, u_long *data) { + _load_store_image(0xc0000000, 3, rect, (uint32_t *) data); +} + +/* .TIM image parsers */ + +// This is the only libgs function PSn00bSDK is ever going to implement. The +// 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) { + if ((*(tim++) & 0xffff) != 0x0010) + return 1; + + info->pmode = *(tim++); + if (info->pmode & 8) { + const u_long *palette_end = tim; + palette_end += *(tim++) / 4; + + *((u_long *) &(info->cx)) = *(tim++); + *((u_long *) &(info->cw)) = *(tim++); + info->clut = (u_long *) tim; + + tim = palette_end; + } else { + info->clut = 0; + } + + tim++; + *((u_long *) &(info->px)) = *(tim++); + *((u_long *) &(info->pw)) = *(tim++); + info->pixel = (u_long *) tim; + + return 0; +} + +int GetTimInfo(const u_long *tim, TIM_IMAGE *info) { + if ((*(tim++) & 0xffff) != 0x0010) + return 1; + + info->mode = *(tim++); + if (info->mode & 8) { + const u_long *palette_end = tim; + palette_end += *(tim++) / 4; + + info->crect = (RECT *) tim; + info->caddr = (u_long *) &tim[2]; + + tim = palette_end; + } else { + info->caddr = 0; + } + + tim++; + info->prect = (RECT *) tim; + info->paddr = (u_long *) &tim[2]; + + return 0; +} diff --git a/libpsn00b/psxgpu/loadimage.s b/libpsn00b/psxgpu/loadimage.s deleted file mode 100644 index 45f152f..0000000 --- a/libpsn00b/psxgpu/loadimage.s +++ /dev/null @@ -1,70 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.set RECT_x, 0 -.set RECT_y, 2 -.set RECT_w, 4 -.set RECT_h, 6 - -.section .text - - -.global LoadImage -.type LoadImage, @function -LoadImage: - addiu $sp, -8 - sw $ra, 0($sp) - sw $s0, 4($sp) - - lui $s0, IOBASE # Set I/O segment base address - -.Lgpu_wait: # Wait for GPU to be ready for commands and DMA - jal ReadGPUstat - nop - srl $v0, 0x1a - andi $v0, 0x5 - li $v1, 5 - #srl $v0, 28 - #andi $v0, 1 - bne $v0, $v1, .Lgpu_wait - nop - - lui $v0, 0x400 # Set DMA direction to off - sw $v0, GPU_GP1($s0) - - lui $v0, 0x0100 # Clear GPU cache - sw $v0, GPU_GP0($s0) - - lui $v1, 0xa000 # Load image to VRAM - sw $v1, GPU_GP0($s0) - lw $v0, RECT_x($a0) # Set XY and dimensions of image - lw $v1, RECT_w($a0) - sw $v0, GPU_GP0($s0) - sw $v1, GPU_GP0($s0) - - lui $v0, 0x400 # Set DMA direction to CPUtoVRAM - ori $v0, 0x2 - sw $v0, GPU_GP1($s0) - - lhu $v0, RECT_w($a0) # Get rectangle size - lhu $v1, RECT_h($a0) - nop - mult $v0, $v1 # Calculate BCR value - mflo $v1 - srl $v1, 0x4 - sll $v1, 0x10 - ori $v1, 0x8 - - sw $a1, DMA2_MADR($s0) # Set DMA base address and transfer length - sw $v1, DMA2_BCR($s0) - - lui $v0, 0x100 # Start DMA transfer - ori $v0, 0x201 - sw $v0, DMA2_CHCR($s0) - - lw $ra, 0($sp) - lw $s0, 4($sp) - jr $ra - addiu $sp, 8 - diff --git a/libpsn00b/psxgpu/putdispenv.s b/libpsn00b/psxgpu/putdispenv.s deleted file mode 100644 index fc09454..0000000 --- a/libpsn00b/psxgpu/putdispenv.s +++ /dev/null @@ -1,174 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.set DISP_dx, 0 -.set DISP_dy, 2 -.set DISP_dw, 4 -.set DISP_dh, 6 -.set DISP_sx, 8 -.set DISP_sy, 10 -.set DISP_sw, 12 -.set DISP_sh, 14 -.set DISP_inter, 16 -.set DISP_isrgb24, 17 -.set DISP_reverse, 18 - -.section .text - - -.global PutDispEnv -.type PutDispEnv, @function -PutDispEnv: - - lui $a3, IOBASE - - # Horizontal resolution stuff - - lh $a2, DISP_dw($a0) # Get X resolution - - lh $v0, DISP_sx($a0) - lh $v1, DISP_sw($a0) # Get X screen width - - move $a1, $0 # To use as mode value - - bgt $a2, 560, .Lmode_640 - nop - bgt $a2, 400, .Lmode_512 - nop - bgt $a2, 352, .Lmode_384 - nop - bgt $a2, 280, .Lmode_320 - nop - - .set noat - -.Lmode_256: - li $at, 10 - mult $at, $v1 - li $a2, 0x24e - sll $v0, 2 - add $a2, $v0 - b .Lmode_end - li $v1, 0xa00 -.Lmode_320: - li $at, 8 - mult $at, $v1 - li $a2, 0x258 - ori $a1, 0x01 - sll $v0, 2 - add $a2, $v0 - b .Lmode_end - li $v1, 0xa00 -.Lmode_384: - li $at, 7 - mult $at, $v1 - li $a2, 0x21b - ori $a1, 0x64 - sll $v0, 2 - add $a2, $v0 - b .Lmode_end - li $v1, 0xa80 -.Lmode_512: - li $at, 5 - mult $at, $v1 - li $a2, 0x267 - ori $a1, 0x02 - sll $v0, 2 - add $a2, $v0 - b .Lmode_end - li $v1, 0xa00 -.Lmode_640: - li $at, 4 - mult $at, $v1 - li $a2, 0x26c - ori $a1, 0x03 - sll $v0, 2 - add $a2, $v0 - li $v1, 0xa00 -.Lmode_end: - - .set at - - mflo $v0 - bnez $v0, .Lno_default # Check if screen with is non zero - nop - move $v0, $v1 # Use default if screen width is 0 -.Lno_default: - - addu $v0, $a2 # Apply horizontal display coordinates - sll $v0, 12 - andi $a2, 0xfff - or $a2, $v0 - lui $v0, 0x0600 - or $v0, $a2 - sw $v0, GPU_GP1($a3) - - # Vertical resolution - - lh $v0, DISP_dh($a0) - li $a2, 0x10 - ble $v0, 256, .Lmode_low - nop - -.Lmode_high: - ori $a1, 0x04 -.Lmode_low: - lh $v0, DISP_sy($a0) - lh $v1, DISP_sh($a0) - add $a2, $v0 - bnez $v1, .Lno_default_vert - nop - li $v1, 0xf0 -.Lno_default_vert: - add $v1, $a2 - and $a2, 0x3ff - sll $v1, 10 - or $v1, $a2 - lui $v0, 0x0700 - or $v1, $v0 - sw $v1, GPU_GP1($a3) - - # Video mode - - la $v0, _gpu_standard - lbu $v0, 0($v0) - nop - beqz $v0, .Lconfig_ntsc - nop -.Lconfig_pal: - ori $a1, 0x08 -.Lconfig_ntsc: - - lbu $v0, DISP_inter($a0) - lbu $v1, DISP_isrgb24($a0) - beqz $v0, .Lno_inter - nop - or $a1, 0x20 -.Lno_inter: - beqz $v1, .Lno_rgb24 - nop - or $a1, 0x10 -.Lno_rgb24: - lbu $v0, DISP_inter($a0) - nop - beqz $v0, .Lno_reverse - nop - or $a1, 0x80 -.Lno_reverse: - - lui $v0, 0x800 # Apply mode - or $a1, $v0 - sw $a1, GPU_GP1($a3) - - lhu $v0, DISP_dx($a0) # Set VRAM XY offset - lhu $v1, DISP_dy($a0) - andi $v0, 0x3ff - andi $v1, 0x1ff - sll $v1, 10 - or $v0, $v1 - lui $v1, 0x500 - or $v0, $v1 - - jr $ra - sw $v0, GPU_GP1($a3) diff --git a/libpsn00b/psxgpu/putdispenvraw.s b/libpsn00b/psxgpu/putdispenvraw.s deleted file mode 100644 index 747796f..0000000 --- a/libpsn00b/psxgpu/putdispenvraw.s +++ /dev/null @@ -1,71 +0,0 @@ -.set noreorder -.set noat - -.include "hwregs_a.h" - -.set DISP_mode, 0 -.set DISP_vxpos, 4 -.set DISP_vypos, 6 -.set DISP_fbx, 8 -.set DISP_fby, 10 - -.section .text - - -.global PutDispEnvRaw -.type PutDispEnvRaw, @function -PutDispEnvRaw: - addiu $sp, -8 - sw $ra, 0($sp) - sw $s0, 4($sp) - - lui $s0, IOBASE - - lh $at, DISP_vxpos($a0) # Set horizontal display range - li $v0, 608 - add $v0, $at - li $v1, 3168 - add $v1, $at - sll $v1, 12 - or $v0, $v1 - lui $v1, 0x600 - or $v1, $v0 - sw $v1, GPU_GP1($s0) - - lh $at, DISP_vypos($a0) # Set vertical display range (for NTSC) - li $v1, 120 # (values differet for PAL modes) - sub $v1, $at - li $v0, 136 - sub $v0, $v1 - andi $v0, 0x1ff - li $v1, 120 - add $v1, $at - li $at, 136 - add $at, $v1 - andi $at, 0x1ff - sll $at, 10 - or $v0, $at - lui $at, 0x700 - or $v0, $at - sw $v0, GPU_GP1($s0) - - lw $v0, DISP_mode($a0) # Set video mode - lui $at, 0x800 - or $v0, $at - sw $v0, GPU_GP1($s0) - - lhu $v0, DISP_fbx($a0) # Set VRAM XY offset - lhu $v1, DISP_fby($a0) - andi $v0, 0x3ff - andi $v1, 0x1ff - sll $v1, 10 - or $v0, $v1 - lui $v1, 0x500 - or $v0, $v1 - sw $v0, GPU_GP1($s0) - - lw $ra, 0($sp) - lw $s0, 4($sp) - jr $ra - addiu $sp, 8 - diff --git a/libpsn00b/psxgpu/putdrawenv.s b/libpsn00b/psxgpu/putdrawenv.s deleted file mode 100644 index c0d5676..0000000 --- a/libpsn00b/psxgpu/putdrawenv.s +++ /dev/null @@ -1,142 +0,0 @@ -.set noreorder -.set noat - -.include "hwregs_a.h" - -.set DRAW_x, 0 # Drawing area -.set DRAW_y, 2 -.set DRAW_w, 4 -.set DRAW_h, 6 -.set DRAW_ofx, 8 # Draw offset -.set DRAW_ofy, 10 -.set DRAW_tx, 12 # Texture window -.set DRAW_ty, 14 -.set DRAW_tw, 16 -.set DRAW_th, 18 -.set DRAW_tpage, 20 # TPage values -.set DRAW_dtd, 22 -.set DRAW_dfe, 23 -.set DRAW_isbg, 24 # Clear draw area -.set DRAW_r0, 25 -.set DRAW_g0, 26 -.set DRAW_b0, 27 -.set DRAW_env, 28 - - -.section .text - -.global PutDrawEnv -.type PutDrawEnv, @function -PutDrawEnv: - addiu $sp, -4 - sw $ra, 0($sp) - - addiu $a1, $a0, DRAW_env - - li $v0, 0x04ffffff # Packet header (length+terminator) - sw $v0, 0($a1) - - lhu $v0, DRAW_x($a0) # Set draw area top-left - lhu $v1, DRAW_y($a0) - andi $v0, 0x3ff - andi $v1, 0x1ff - sll $v1, 10 - or $v0, $v1 - lui $v1, 0xe300 - or $v0, $v1 - sw $v0, 4($a1) # 1 - - .set noat - - lhu $v0, DRAW_w($a0) # Set draw area bottom-right - lhu $at, DRAW_x($a0) - addiu $v0, -1 - addu $at, $v0 - andi $at, 0x3ff - lhu $v1, DRAW_h($a0) - lhu $v0, DRAW_y($a0) - addiu $v1, -1 - addu $v0, $v1 - andi $v0, 0x1ff - sll $v0, 10 - or $at, $v0 - lui $v0, 0xe400 - or $at, $v0 - sw $at, 8($a1) # 2 - - lhu $v0, DRAW_x($a0) # Set drawing offset - lhu $v1, DRAW_ofx($a0) - nop - add $v0, $v1 - andi $at, $v0, 0x7ff - lhu $v0, DRAW_y($a0) - lhu $v1, DRAW_ofy($a0) - nop - add $v0, $v1 - andi $v0, 0x7ff - sll $v0, 11 - or $at, $v0 - lui $v0, 0xe500 - or $at, $v0 - sw $at, 12($a1) # 3 - - lhu $at, DRAW_tpage($a0) # Set tpage - lbu $v0, DRAW_dtd($a0) - lbu $v1, DRAW_dfe($a0) - andi $v0, 1 - and $v1, 1 - sll $v0, 9 - sll $v1, 10 - or $at, $v0 - or $at, $v1 - lui $v0, 0xe100 - or $at, $v0 - sw $at, 16($a1) # 4 - - .set at - - lbu $v0, DRAW_isbg($a0) - nop - beqz $v0, .Lno_fillVRAM - nop - - lw $v0, DRAW_isbg($a0) # FillVRAM - lui $v1, 0x0200 - srl $v0, 8 - or $v0, $v1 - sw $v0, 20($a1) # 5 - lw $v0, DRAW_x($a0) - lw $v1, DRAW_w($a0) - sw $v0, 24($a1) # 6 - - srl $v0, $v1, 16 # Workaround as rectangle primitives - blt $v0, 511, .Lno_overflow # don't accept a height of 512 - nop - - li $v0, 511 - sll $v0, 16 - andi $v1, 0xffff - or $v1, $v0 - -.Lno_overflow: - sw $v1, 28($a1) # 7 - li $v0, 0x07ffffff # Packet header (length+terminator) - sw $v0, 0($a1) - -.Lno_fillVRAM: - -.Lgpu_wait: # Wait for GPU to become ready for commands and DMA - jal ReadGPUstat - nop - srl $v0, 26 - andi $v0, 1 - beqz $v0, .Lgpu_wait - nop - - jal DrawOTag - move $a0, $a1 - - lw $ra, 0($sp) - addiu $sp, 4 - jr $ra - nop diff --git a/libpsn00b/psxgpu/readgpustat.s b/libpsn00b/psxgpu/readgpustat.s deleted file mode 100644 index ffff4d7..0000000 --- a/libpsn00b/psxgpu/readgpustat.s +++ /dev/null @@ -1,14 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .text - - -.global ReadGPUstat -.type ReadGPUstat, @function -ReadGPUstat: - lui $v0, IOBASE - lw $v0, GPU_GP1($v0) - jr $ra - nop diff --git a/libpsn00b/psxgpu/readme.txt b/libpsn00b/psxgpu/readme.txt index b626e1d..2963b6a 100644 --- a/libpsn00b/psxgpu/readme.txt +++ b/libpsn00b/psxgpu/readme.txt @@ -3,25 +3,19 @@ PSX GPU library, part of PSn00bSDK Licensed under Mozilla Public License - Open source implementation of the GPU library written mostly in MIPS -assembly. Supports DMA transfers for ordering table draw and transferring -image data to and from VRAM. The syntax is intentionally made to closely -resemble Sony's syntax for familiarity and to make porting homebrew made -using the official SDK to PSn00bSDK a little easier. - +Open source implementation of the GPU library written entirely in C. Supports +DMA transfers for drawing OTs (with an internal queue so DrawOTag() can be +called even when another OT is being drawn) and transferring image data to and +from VRAM. The syntax is intentionally made to closely resemble Sony's syntax +for familiarity and to make porting homebrew made using the official SDK to +PSn00bSDK a little easier. Library developer(s): - Lameguy64 - + Lameguy64 (initial implementation in assembly, debug font API) + spicyjpeg Library header(s): hwregs_a.h (GNU assembler port defs) psxgpu.h - - -Todo list: - - * ClearOTag() function (non reverse version of ClearOTagR()) yet to be - implemented (but should be trivial). diff --git a/libpsn00b/psxgpu/resetgraph.s b/libpsn00b/psxgpu/resetgraph.s deleted file mode 100644 index 6327f02..0000000 --- a/libpsn00b/psxgpu/resetgraph.s +++ /dev/null @@ -1,363 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .text - -.set ISR_STACK_SIZE, 4096 - -.global ResetGraph # Resets the GPU and installs a -.type ResetGraph, @function # VSync event handler -ResetGraph: - addiu $sp, -8 # C style stack allocation (required if - sw $ra, 0($sp) # you call BIOS functions from asm) - sw $a0, 4($sp) - - la $a0, resetgraph_msg - move $a1, $0 - move $a2, $0 - la $a1, _irq_func_table - la $a2, _custom_exit - jal printf - addiu $sp, -16 - addiu $sp, 16 - - la $a0, sr_msg - mfc0 $a1, $12 - jal printf - addiu $sp, -16 - addiu $sp, 16 - - la $v0, _hooks_installed # Skip installing hooks if this function - lbu $v0, 0($v0) # has already been called before once - nop - bnez $v0, .Lskip_hook_init - nop - - jal EnterCriticalSection # Disable interrupts as LoadExec() keeps - nop # interrupts enabled when transferring - # execution to the loaded program - - lui $a3, IOBASE # Base address for I/O - - lui $v0, 0x3b33 # Enables DMA channel 6 (for ClearOTag) - ori $v0, 0x3b33 # Enables DMA channel 2 - sw $v0, DMA_DPCR($a3) - sw $0 , DMA_DICR($a3) # Clear DICR (not needed) - - sw $0 , IRQ_MASK($a3) # Clear IRQ settings - - la $v0, _hooks_installed # Set installed flag - li $v1, 0x1 - sb $v1, 0($v0) - - la $v0, _vsync_cb_func # Clear VSync callback function - sw $0 , 0($v0) - - la $a1, _vsync_irq_callback # Install VSync interrupt callback - jal InterruptCallback - li $a0, 0 - - jal RestartCallback - nop - - la $a0, cbhooks_msg - jal printf - addiu $sp, -16 - addiu $sp, 16 - - jal _96_remove # Remove CD handling left by the BIOS - nop - - la $a0, abouttoen_msg - jal printf - addiu $sp, -16 - addiu $sp, 16 - - jal ExitCriticalSection # Re-enable interrupts - nop - - la $a0, enableint_msg - jal printf - addiu $sp, -16 - addiu $sp, 16 - -.Lskip_hook_init: - - lui $a3, IOBASE - - lw $v0, GPU_GP1($a3) # Get video standard - lui $v1, 0x0010 - and $v0, $v1 - la $v1, _gpu_standard - beqz $v0, .Lnot_pal - sw $0 , 0($v1) - li $v0, 1 - sw $v0, 0($v1) -.Lnot_pal: - - lw $a0, 4($sp) # Get argument value - - lui $a3, IOBASE # Set base I/O again (likely destroyed - # by previous calls) - - li $v0, 0x1d00 # Configure timer 1 as Hblank counter - sw $v0, TIMER1_CTRL($a3) # Set timer 1 value - - beq $a0, 1, .Lgpu_init_1 - nop - beq $a0, 3, .Lgpu_init_3 - nop - - sw $0 , GPU_GP1($a3) # Reset the GPU - - b .Linit_done - nop - -.Lgpu_init_1: - - sw $0 , DMA2_CHCR($a3) # Stop any DMA - -.Lgpu_init_3: - - li $v0, 0x1 # Reset the command buffer - sw $v0, GPU_GP1($a3) - -.Linit_done: - - lw $ra, 0($sp) - lw $a0, 4($sp) # Return - jr $ra - addiu $sp, 8 - - -.global VSync # VSync function -.type VSync, @function -VSync: - - addiu $sp, -12 - sw $ra, 0($sp) - sw $s0, 4($sp) - - lui $a3, IOBASE # Get GPU status (for interlace sync) - lw $s0, GPU_GP1($a3) - -.Lhwait_loop: # Get Hblank time - lw $v0, TIMER1_VALUE($a3) - nop - lw $v1, TIMER1_VALUE($a3) - nop - bne $v0, $v1, .Lhwait_loop - nop - - la $a3, _vsync_lasthblank # Calculate Hblank time since last - lw $v1, 0($a3) - nop - subu $v0, $v1 - andi $v0, 0xffff - - beq $a0, 1, .Lhblank_exit # Return Hblank time only, no VSync - sw $v0, 8($sp) # Stored as return value - - bgez $a0, .Lvsync # Vsync if argument is 0 and up - nop - - la $v0, _vsync_rcnt # Return VSync count only - lw $v0, 0($v0) - nop - b .Lvsync_exit - sw $v0, 8($sp) - -.Lvsync: - - bnez $a0, .Lnot_zero - nop - li $a0, 1 - -.Lnot_zero: - - la $v0, _vsync_rcnt # Call vsync sub function (with timeout) - lw $v0, 0($v0) - addiu $a1, $a0, 1 - jal _vsync_sub - addu $a0, $v0, $a0 - - lui $v0, 0x40 - and $v0, $s0, $v0 - beqz $v0, .Lhblank_exit - nop - - lui $a3, IOBASE # Interlace wait logic - - lw $v0, GPU_GP1($a3) - nop - xor $v0, $s0, $v0 - bltz $v0, .Lhblank_exit - lui $a0, 0x8000 - -.Linterlace_wait: - lw $v0, GPU_GP1($a3) - nop - xor $v0, $s0, $v0 - and $v0, $a0 - beqz $v0, .Linterlace_wait - nop - -.Lhblank_exit: # Set current Hblank as last value - - la $a2, _vsync_lasthblank - -.Lhwait2_loop: - lw $v0, TIMER1_VALUE($a3) - nop - lw $v1, TIMER1_VALUE($a3) - sw $v0, 0($a2) - bne $v0, $v1, .Lhwait2_loop - nop - -.Lvsync_exit: - - lw $ra, 0($sp) - lw $s0, 4($sp) - lw $v0, 8($sp) - jr $ra - addiu $sp, 12 - - -.type _vsync_sub, @function -_vsync_sub: - - # a0 - VSync destination count - # a1 - Timeout ratio (number of vsyncs to wait relative to vsync count) - - addiu $sp, -4 - sw $ra, 0($sp) - - sll $a1, 15 # Timeout counter - - la $v0, _vsync_rcnt - lw $v0, 0($v0) - nop - bge $v0, $a0, .Lvsync_sub_exit - nop - -.Lvsync_wait: - - addiu $a1, -1 - - la $v1, 0xffffffff - bne $a1, $v1, .Lnot_timeout - nop - - la $a0, vsynctimeout_msg - jal puts - addiu $sp, -8 - - jal ChangeClearPAD - move $a0, $0 - - li $a0, 3 - jal ChangeClearRCnt - move $a1, $0 - - addiu $sp, 8 - b .Lvsync_sub_exit - li $v0, -1 - -.Lnot_timeout: - - la $v0, _vsync_rcnt - lw $v0, 0($v0) - nop - blt $v0, $a0, .Lvsync_wait - nop - -.Lvsync_sub_exit: - - lw $ra, 0($sp) - addiu $sp, 4 - jr $ra - move $v0, $0 - - - -.type _vsync_irq_callback, @function -_vsync_irq_callback: - - lui $a0, IOBASE - - la $v1, _vsync_rcnt # Increment VSync root counter - lw $v0, 0($v1) - nop - addiu $v0, 1 - sw $v0, 0($v1) - - la $v0, _vsync_cb_func # Check if a callback function is set - lw $v0, 0($v0) - nop - beqz $v0, .Lno_callback - nop - - addiu $sp, -4 # Save return address - sw $ra, 0($sp) - jalr $v0 # Execute user callback function - nop - lw $ra, 0($sp) # Restore previous return address - addiu $sp, 4 - - lui $a0, IOBASE - -.Lno_callback: - - jr $ra - nop - - -.section .data - -# VSync root counter -.type _vsync_rcnt, @object -_vsync_rcnt: - .word 0 - -.type _vsync_lasthblank, @object -_vsync_lasthblank: - .word 0 - -.comm _vsync_cb_func, 4, 4 - -.comm _gpu_standard, 4, 4 -.comm _gpu_current_field, 4, 4 -.comm _hooks_installed, 4, 4 - - -.type vsynctimeout_msg, @object -vsynctimeout_msg: - .asciiz "VSync: timeout\n" - -.type resetgraph_msg, @object -resetgraph_msg: - .asciiz "ResetGraph:itb=%08x,ehk=%08x\n" - -.type enableint_msg, @object -enableint_msg: - .asciiz "ResetGraph:Interrupts enabled!\n" - -.type cbhooks_msg, @object -cbhooks_msg: - .asciiz "ResetGraph:Interrupt hooks enabled.\n" - -.type abouttoen_msg, @object -abouttoen_msg: - .asciiz "ResetGraph:About to init interrupts.\n" - -.type sr_msg, @object -sr_msg: - .asciiz "ResetGraph:SR=%x\n" - -.global psxgpu_credits -.type psxgpu_credits, @object -psxgpu_credits: - .ascii "psxgpu programs by Lameguy64\n" - .asciiz "2020 PSn00bSDK Project / Meido-Tek Productions\n" - \ No newline at end of file diff --git a/libpsn00b/psxgpu/setdefdispenv.c b/libpsn00b/psxgpu/setdefdispenv.c deleted file mode 100644 index 2d7b2b4..0000000 --- a/libpsn00b/psxgpu/setdefdispenv.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -DISPENV *SetDefDispEnv(DISPENV *disp, int x, int y, int w, int h) { - - disp->disp.x = x; - disp->disp.y = y; - disp->disp.w = w; - disp->disp.h = h; - - disp->screen.x = 0; - disp->screen.y = 0; - disp->screen.w = 0; - disp->screen.h = 0; - - disp->isinter = 0; - disp->isrgb24 = 0; - disp->reverse = 0; - - return disp; - -} diff --git a/libpsn00b/psxgpu/setdefdrawenv.c b/libpsn00b/psxgpu/setdefdrawenv.c deleted file mode 100644 index 6fd6086..0000000 --- a/libpsn00b/psxgpu/setdefdrawenv.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -DRAWENV *SetDefDrawEnv(DRAWENV *draw, int x, int y, int w, int h) { - - draw->clip.x = x; - draw->clip.y = y; - draw->clip.w = w; - draw->clip.h = h; - - draw->ofs[0] = 0; - draw->ofs[1] = 0; - - draw->tw.x = 0; - draw->tw.y = 0; - draw->tw.w = 0; - draw->tw.h = 0; - - draw->tpage = 0x0a; - draw->dtd = 1; - draw->dfe = 0; - draw->isbg = 0; - setRGB0( draw, 0, 0, 0 ); - - return draw; - -} diff --git a/libpsn00b/psxgpu/setdispmask.s b/libpsn00b/psxgpu/setdispmask.s deleted file mode 100644 index d79006c..0000000 --- a/libpsn00b/psxgpu/setdispmask.s +++ /dev/null @@ -1,19 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .text - - -.global SetDispMask -.type SetDispMask, @function -SetDispMask: - lui $v1, IOBASE - andi $a0, 0x1 - lui $v0, 0x300 - ori $v0, 0x1 - sub $v0, $a0 - sw $v0, GPU_GP1($v1) - jr $ra - nop - diff --git a/libpsn00b/psxgpu/setvideomode.s b/libpsn00b/psxgpu/setvideomode.s deleted file mode 100644 index b89b285..0000000 --- a/libpsn00b/psxgpu/setvideomode.s +++ /dev/null @@ -1,50 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - - -.section .text - -.global SetVideoMode -.type SetVideoMode, @function -SetVideoMode: - addiu $sp, -4 - sw $ra, 0($sp) - - jal ReadGPUstat - nop - - srl $a1, $v0, 17 - andi $a1, 0x1f - - srl $v1, $v0, 14 # Reverse flag - andi $v1, 1 - sll $v1, 6 - or $a1, $v1 - - srl $v1, $v0, 16 # Horizontal resolution 2 - andi $v1, 1 - sll $v1, 6 - or $a1, $v1 - - andi $a1, 0xf7 # Mask off PAL bit - - la $v0, _gpu_standard - beqz $a0, .Lset_done - sw $0 , 0($v0) - li $v1, 1 - sw $v1, 0($v0) - b .Lset_done - or $a1, 0x8 -.Lset_done: - - lui $v0, 0x800 # Apply new mode - or $a1, $v0 - lui $v0, IOBASE - sw $a1, GPU_GP1($v0) - - lw $ra, 0($sp) - addiu $sp, 4 - jr $ra - nop - diff --git a/libpsn00b/psxgpu/storeimage.s b/libpsn00b/psxgpu/storeimage.s deleted file mode 100644 index 554e83c..0000000 --- a/libpsn00b/psxgpu/storeimage.s +++ /dev/null @@ -1,76 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.set RECT_x, 0 -.set RECT_y, 2 -.set RECT_w, 4 -.set RECT_h, 6 - -.section .text - - -.global StoreImage -.type StoreImage, @function -StoreImage: - addiu $sp, -8 - sw $ra, 0($sp) - sw $s0, 4($sp) - - lui $s0, IOBASE # Set I/O segment base address - -.Lgpu_wait: # Wait for GPU to be ready for commands and DMA - jal ReadGPUstat - nop - srl $v0, 0x1a - andi $v0, 0x5 - li $v1, 5 - bne $v0, $v1, .Lgpu_wait - nop - - lui $v0, 0x400 # Set DMA direction to off - sw $v0, GPU_GP1($s0) - - lui $v0, 0x0100 # Clear GPU cache - sw $v0, GPU_GP0($s0) - - lui $v1, 0xc000 # Store image from VRAM - sw $v1, GPU_GP0($s0) - lw $v0, RECT_x($a0) # Set XY and dimensions of image - lw $v1, RECT_w($a0) - sw $v0, GPU_GP0($s0) - sw $v1, GPU_GP0($s0) - - lui $v0, 0x400 # Set DMA direction to VRAMtoCPU - ori $v0, 0x3 - sw $v0, GPU_GP1($s0) - - lhu $v0, RECT_w($a0) # Get rectangle size - lhu $v1, RECT_h($a0) - nop - mult $v0, $v1 # Calculate BCR value - mflo $v1 - srl $v1, 0x4 - sll $v1, 0x10 - ori $v1, 0x8 - - sw $a1, DMA2_MADR($s0) # Set DMA base address and transfer length - sw $v1, DMA2_BCR($s0) - -.Lgpu_wait_2: # Wait for GPU to be ready for commands and DMA - jal ReadGPUstat - nop - srl $v0, 27 - andi $v0, 0x1 - beqz $v0, .Lgpu_wait_2 - nop - - lui $v0, 0x100 # Start DMA transfer - ori $v0, 0x200 - sw $v0, DMA2_CHCR($s0) - - lw $ra, 0($sp) - lw $s0, 4($sp) - jr $ra - addiu $sp, 8 - diff --git a/libpsn00b/psxgpu/vsynccallback.s b/libpsn00b/psxgpu/vsynccallback.s deleted file mode 100644 index 4be29c8..0000000 --- a/libpsn00b/psxgpu/vsynccallback.s +++ /dev/null @@ -1,25 +0,0 @@ -.set noreorder - -.section .text - -.global VSyncCallback -.type VSyncCallback, @function -VSyncCallback: - addiu $sp, -8 - sw $ra, 0($sp) - - jal EnterCriticalSection - sw $a0, 4($sp) - - lw $a0, 4($sp) - la $v0, _vsync_cb_func - sw $a0, 0($v0) - - jal ExitCriticalSection - nop - - lw $ra, 0($sp) - addiu $sp, 8 - jr $ra - nop - -- cgit v1.2.3 From c800972bc13ad0c7015b7d44fe9f124b719e792e Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Sun, 17 Jul 2022 11:40:02 +0200 Subject: Change I/O base address to 0xbf80, use size_t in stdlib --- examples/io/system573/k573io.h | 26 ++++---- libpsn00b/include/hwregs_a.h | 2 +- libpsn00b/include/hwregs_c.h | 142 ++++++++++++++++++++--------------------- libpsn00b/include/stdlib.h | 14 ++-- libpsn00b/libc/start.c | 8 +-- libpsn00b/psxpress/mdec.c | 8 +-- 6 files changed, 101 insertions(+), 99 deletions(-) (limited to 'examples') diff --git a/examples/io/system573/k573io.h b/examples/io/system573/k573io.h index 424e3e4..8655237 100644 --- a/examples/io/system573/k573io.h +++ b/examples/io/system573/k573io.h @@ -10,19 +10,19 @@ /* Register definitions */ -#define K573_BANK_SWITCH *((volatile uint16_t *) 0x1f500000) -#define K573_IDE_RESET *((volatile uint16_t *) 0x1f560000) -#define K573_WATCHDOG *((volatile uint16_t *) 0x1f5c0000) -#define K573_EXT_OUT *((volatile uint16_t *) 0x1f600000) -#define K573_JVS_INPUT *((volatile uint16_t *) 0x1f680000) -#define K573_SECURITY_OUT *((volatile uint16_t *) 0x1f6a0000) - -#define K573_FLASH ((volatile uint16_t *) 0x1f000000) -#define K573_IO_CHIP ((volatile uint16_t *) 0x1f400000) -#define K573_IDE_CS0 ((volatile uint16_t *) 0x1f480000) -#define K573_IDE_CS1 ((volatile uint16_t *) 0x1f4c0000) -#define K573_RTC ((volatile uint16_t *) 0x1f620000) -#define K573_IO_BOARD ((volatile uint16_t *) 0x1f640000) +#define K573_BANK_SWITCH *((volatile uint16_t *) 0xbf500000) +#define K573_IDE_RESET *((volatile uint16_t *) 0xbf560000) +#define K573_WATCHDOG *((volatile uint16_t *) 0xbf5c0000) +#define K573_EXT_OUT *((volatile uint16_t *) 0xbf600000) +#define K573_JVS_INPUT *((volatile uint16_t *) 0xbf680000) +#define K573_SECURITY_OUT *((volatile uint16_t *) 0xbf6a0000) + +#define K573_FLASH ((volatile uint16_t *) 0xbf000000) +#define K573_IO_CHIP ((volatile uint16_t *) 0xbf400000) +#define K573_IDE_CS0 ((volatile uint16_t *) 0xbf480000) +#define K573_IDE_CS1 ((volatile uint16_t *) 0xbf4c0000) +#define K573_RTC ((volatile uint16_t *) 0xbf620000) +#define K573_IO_BOARD ((volatile uint16_t *) 0xbf640000) typedef enum _K573_IOChipRegister { IO_REG_OUT0 = 0x0, diff --git a/libpsn00b/include/hwregs_a.h b/libpsn00b/include/hwregs_a.h index 8a504f5..d8f6c72 100644 --- a/libpsn00b/include/hwregs_a.h +++ b/libpsn00b/include/hwregs_a.h @@ -4,7 +4,7 @@ # 2019 Meido-Tek Productions -.set IOBASE, 0x1f80 # IO segment base +.set IOBASE, 0xbf80 # IO segment base (KSEG1) ## GPU diff --git a/libpsn00b/include/hwregs_c.h b/libpsn00b/include/hwregs_c.h index e533c56..a9f4ee3 100644 --- a/libpsn00b/include/hwregs_c.h +++ b/libpsn00b/include/hwregs_c.h @@ -19,111 +19,111 @@ /* GPU */ -#define GPU_GP0 _MMIO32(0x1f801810) -#define GPU_GP1 _MMIO32(0x1f801814) +#define GPU_GP0 _MMIO32(0xbf801810) +#define GPU_GP1 _MMIO32(0xbf801814) /* CD drive */ -#define CD_STAT _MMIO8(0x1f801800) -#define CD_CMD _MMIO8(0x1f801801) -#define CD_DATA _MMIO8(0x1f801802) -#define CD_IRQ _MMIO8(0x1f801803) +#define CD_STAT _MMIO8(0xbf801800) +#define CD_CMD _MMIO8(0xbf801801) +#define CD_DATA _MMIO8(0xbf801802) +#define CD_IRQ _MMIO8(0xbf801803) -#define CD_REG(N) _MMIO8(0x1f801800 + (N)) +#define CD_REG(N) _MMIO8(0xbf801800 + (N)) /* SPU */ -#define SPU_MASTER_VOL_L _MMIO16(0x1f801d80) -#define SPU_MASTER_VOL_R _MMIO16(0x1f801d82) -#define SPU_REVERB_VOL_L _MMIO16(0x1f801d84) -#define SPU_REVERB_VOL_R _MMIO16(0x1f801d86) -#define SPU_KEY_ON _MMIO32(0x1f801d88) -#define SPU_KEY_OFF _MMIO32(0x1f801d8c) -#define SPU_FM_MODE _MMIO32(0x1f801d90) -#define SPU_NOISE_MODE _MMIO32(0x1f801d94) -#define SPU_REVERB_ON _MMIO32(0x1f801d98) -#define SPU_CHAN_STATUS _MMIO32(0x1f801d9c) - -#define SPU_REVERB_ADDR _MMIO16(0x1f801da2) -#define SPU_IRQ_ADDR _MMIO16(0x1f801da4) -#define SPU_ADDR _MMIO16(0x1f801da6) -#define SPU_DATA _MMIO16(0x1f801da8) - -#define SPU_CTRL _MMIO16(0x1f801daa) -#define SPU_DMA_CTRL _MMIO16(0x1f801dac) -#define SPU_STAT _MMIO16(0x1f801dae) - -#define SPU_CD_VOL_L _MMIO16(0x1f801db0) -#define SPU_CD_VOL_R _MMIO16(0x1f801db2) -#define SPU_EXT_VOL_L _MMIO16(0x1f801db4) -#define SPU_EXT_VOL_R _MMIO16(0x1f801db6) -#define SPU_CURRENT_VOL_L _MMIO16(0x1f801db8) -#define SPU_CURRENT_VOL_R _MMIO16(0x1f801dba) +#define SPU_MASTER_VOL_L _MMIO16(0xbf801d80) +#define SPU_MASTER_VOL_R _MMIO16(0xbf801d82) +#define SPU_REVERB_VOL_L _MMIO16(0xbf801d84) +#define SPU_REVERB_VOL_R _MMIO16(0xbf801d86) +#define SPU_KEY_ON _MMIO32(0xbf801d88) +#define SPU_KEY_OFF _MMIO32(0xbf801d8c) +#define SPU_FM_MODE _MMIO32(0xbf801d90) +#define SPU_NOISE_MODE _MMIO32(0xbf801d94) +#define SPU_REVERB_ON _MMIO32(0xbf801d98) +#define SPU_CHAN_STATUS _MMIO32(0xbf801d9c) + +#define SPU_REVERB_ADDR _MMIO16(0xbf801da2) +#define SPU_IRQ_ADDR _MMIO16(0xbf801da4) +#define SPU_ADDR _MMIO16(0xbf801da6) +#define SPU_DATA _MMIO16(0xbf801da8) + +#define SPU_CTRL _MMIO16(0xbf801daa) +#define SPU_DMA_CTRL _MMIO16(0xbf801dac) +#define SPU_STAT _MMIO16(0xbf801dae) + +#define SPU_CD_VOL_L _MMIO16(0xbf801db0) +#define SPU_CD_VOL_R _MMIO16(0xbf801db2) +#define SPU_EXT_VOL_L _MMIO16(0xbf801db4) +#define SPU_EXT_VOL_R _MMIO16(0xbf801db6) +#define SPU_CURRENT_VOL_L _MMIO16(0xbf801db8) +#define SPU_CURRENT_VOL_R _MMIO16(0xbf801dba) // These are not named SPU_VOICE_* to avoid name clashes with SPU attribute // flags defined in psxspu.h. -#define SPU_CH_VOL_L(N) _MMIO16(0x1f801c00 + 16 * (N)) -#define SPU_CH_VOL_R(N) _MMIO16(0x1f801c02 + 16 * (N)) -#define SPU_CH_FREQ(N) _MMIO16(0x1f801c04 + 16 * (N)) -#define SPU_CH_ADDR(N) _MMIO16(0x1f801c06 + 16 * (N)) -#define SPU_CH_ADSR(N) _MMIO32(0x1f801c08 + 16 * (N)) -#define SPU_CH_LOOP_ADDR(N) _MMIO16(0x1f801c0e + 16 * (N)) +#define SPU_CH_VOL_L(N) _MMIO16(0xbf801c00 + 16 * (N)) +#define SPU_CH_VOL_R(N) _MMIO16(0xbf801c02 + 16 * (N)) +#define SPU_CH_FREQ(N) _MMIO16(0xbf801c04 + 16 * (N)) +#define SPU_CH_ADDR(N) _MMIO16(0xbf801c06 + 16 * (N)) +#define SPU_CH_ADSR(N) _MMIO32(0xbf801c08 + 16 * (N)) +#define SPU_CH_LOOP_ADDR(N) _MMIO16(0xbf801c0e + 16 * (N)) /* MDEC */ -#define MDEC0 _MMIO32(0x1f801820) -#define MDEC1 _MMIO32(0x1f801824) +#define MDEC0 _MMIO32(0xbf801820) +#define MDEC1 _MMIO32(0xbf801824) /* SPI controller port */ // IMPORTANT: even though JOY_TXRX is a 32-bit register, it should only be // accessed as 8-bit. Reading it as 16 or 32-bit works fine on real hardware, // but leads to problems in some emulators. -#define JOY_TXRX _MMIO8(0x1f801040) -#define JOY_STAT _MMIO16(0x1f801044) -#define JOY_MODE _MMIO16(0x1f801048) -#define JOY_CTRL _MMIO16(0x1f80104a) -#define JOY_BAUD _MMIO16(0x1f80104e) +#define JOY_TXRX _MMIO8(0xbf801040) +#define JOY_STAT _MMIO16(0xbf801044) +#define JOY_MODE _MMIO16(0xbf801048) +#define JOY_CTRL _MMIO16(0xbf80104a) +#define JOY_BAUD _MMIO16(0xbf80104e) /* Serial port */ -#define SIO_TXRX _MMIO8(0x1f801050) -#define SIO_STAT _MMIO16(0x1f801054) -#define SIO_MODE _MMIO16(0x1f801058) -#define SIO_CTRL _MMIO16(0x1f80105a) -#define SIO_BAUD _MMIO16(0x1f80105e) +#define SIO_TXRX _MMIO8(0xbf801050) +#define SIO_STAT _MMIO16(0xbf801054) +#define SIO_MODE _MMIO16(0xbf801058) +#define SIO_CTRL _MMIO16(0xbf80105a) +#define SIO_BAUD _MMIO16(0xbf80105e) /* IRQ controller */ -#define IRQ_STAT _MMIO32(0x1f801070) -#define IRQ_MASK _MMIO32(0x1f801074) +#define IRQ_STAT _MMIO32(0xbf801070) +#define IRQ_MASK _MMIO32(0xbf801074) /* DMA */ -#define DMA_DPCR _MMIO32(0x1f8010f0) -#define DMA_DICR _MMIO32(0x1f8010f4) +#define DMA_DPCR _MMIO32(0xbf8010f0) +#define DMA_DICR _MMIO32(0xbf8010f4) -#define DMA_MADR(N) _MMIO32(0x1f801080 + 16 * (N)) -#define DMA_BCR(N) _MMIO32(0x1f801084 + 16 * (N)) -#define DMA_CHCR(N) _MMIO32(0x1f801088 + 16 * (N)) +#define DMA_MADR(N) _MMIO32(0xbf801080 + 16 * (N)) +#define DMA_BCR(N) _MMIO32(0xbf801084 + 16 * (N)) +#define DMA_CHCR(N) _MMIO32(0xbf801088 + 16 * (N)) /* Timers */ -#define TIMER_VALUE(N) _MMIO32(0x1f801100 + 16 * (N)) -#define TIMER_CTRL(N) _MMIO32(0x1f801104 + 16 * (N)) -#define TIMER_RELOAD(N) _MMIO32(0x1f801108 + 16 * (N)) +#define TIMER_VALUE(N) _MMIO32(0xbf801100 + 16 * (N)) +#define TIMER_CTRL(N) _MMIO32(0xbf801104 + 16 * (N)) +#define TIMER_RELOAD(N) _MMIO32(0xbf801108 + 16 * (N)) /* Memory control */ -#define EXP1_ADDR _MMIO32(0x1f801000) -#define EXP2_ADDR _MMIO32(0x1f801004) -#define EXP1_DELAY_SIZE _MMIO32(0x1f801008) -#define EXP3_DELAY_SIZE _MMIO32(0x1f80100c) -#define BIOS_DELAY_SIZE _MMIO32(0x1f801010) -#define SPU_DELAY_SIZE _MMIO32(0x1f801014) -#define CD_DELAY_SIZE _MMIO32(0x1f801018) -#define EXP2_DELAY_SIZE _MMIO32(0x1f80101c) -#define COM_DELAY_CFG _MMIO32(0x1f801020) -#define RAM_SIZE_CFG _MMIO32(0x1f801060) +#define EXP1_ADDR _MMIO32(0xbf801000) +#define EXP2_ADDR _MMIO32(0xbf801004) +#define EXP1_DELAY_SIZE _MMIO32(0xbf801008) +#define EXP3_DELAY_SIZE _MMIO32(0xbf80100c) +#define BIOS_DELAY_SIZE _MMIO32(0xbf801010) +#define SPU_DELAY_SIZE _MMIO32(0xbf801014) +#define CD_DELAY_SIZE _MMIO32(0xbf801018) +#define EXP2_DELAY_SIZE _MMIO32(0xbf80101c) +#define COM_DELAY_CFG _MMIO32(0xbf801020) +#define RAM_SIZE_CFG _MMIO32(0xbf801060) #endif diff --git a/libpsn00b/include/stdlib.h b/libpsn00b/include/stdlib.h index 4c4fcd3..fd4b36c 100644 --- a/libpsn00b/include/stdlib.h +++ b/libpsn00b/include/stdlib.h @@ -9,6 +9,8 @@ #ifndef _STDLIB_H #define _STDLIB_H +#include + #define RAND_MAX 0x7fff /* Conversion functions (not yet implemented) */ @@ -30,7 +32,7 @@ extern "C" { extern int __argc; extern const char **__argv; -int rand(); +int rand(void); void srand(unsigned long seed); int abs(int j); @@ -44,11 +46,11 @@ double strtod(const char *nptr, char **endptr); float strtof(const char *nptr, char **endptr); // Memory allocation functions -void _mem_init(int ram_size, int stack_max_size); -void InitHeap(unsigned int *addr, int size); -int SetHeapSize(int size); -void *malloc(int size); -void *calloc(int number, int size); +void _mem_init(size_t ram_size, size_t stack_max_size); +void InitHeap(void *addr, size_t size); +int SetHeapSize(size_t size); +void *malloc(size_t size); +void *calloc(size_t number, size_t size); void free(void *ptr); #ifdef __cplusplus diff --git a/libpsn00b/libc/start.c b/libpsn00b/libc/start.c index bfe9c9b..87ac951 100644 --- a/libpsn00b/libc/start.c +++ b/libpsn00b/libc/start.c @@ -62,10 +62,10 @@ extern uint8_t _end[]; // useful though to change the stack size and/or reinitialize the heap on // systems that have more than 2 MB of RAM (e.g. emulators, devkits, PS1-based // arcade boards). -void _mem_init(int ram_size, int stack_max_size) { - void *exe_end = _end + 4; - int exe_size = (int) exe_end - (int) __text_start; - int ram_used = (0x10000 + exe_size + stack_max_size) & 0xfffffffc; +void _mem_init(size_t ram_size, size_t stack_max_size) { + void *exe_end = _end + 4; + size_t exe_size = (size_t) exe_end - (size_t) __text_start; + size_t ram_used = (0x10000 + exe_size + stack_max_size) & 0xfffffffc; InitHeap(exe_end, ram_size - ram_used); } diff --git a/libpsn00b/psxpress/mdec.c b/libpsn00b/psxpress/mdec.c index ba190d4..b8d16b5 100644 --- a/libpsn00b/psxpress/mdec.c +++ b/libpsn00b/psxpress/mdec.c @@ -115,9 +115,9 @@ void DecDCTin(const uint32_t *data, int mode) { if (mode == DECDCT_MODE_RAW) MDEC0 = header; else if (mode & DECDCT_MODE_24BPP) - MDEC0 = header | 0x30000000; + MDEC0 = 0x30000000 | (header & 0xffff); else - MDEC0 = header | 0x38000000 | ((mode & 2) << 24); // Bit 25 = mask + MDEC0 = 0x38000000 | (header & 0xffff) | ((mode & 2) << 24); // Bit 25 = mask DecDCTinRaw((const uint32_t *) &(data[1]), header & 0xffff); } @@ -142,7 +142,7 @@ int DecDCTinSync(int mode) { if (mode) return (MDEC1 >> 29) & 1; - for (uint32_t i = MDEC_SYNC_TIMEOUT; i; i--) { + for (int i = MDEC_SYNC_TIMEOUT; i; i--) { if (!(MDEC1 & (1 << 29))) return 0; } @@ -167,7 +167,7 @@ int DecDCToutSync(int mode) { if (mode) return (DMA_CHCR(1) >> 24) & 1; - for (uint32_t i = MDEC_SYNC_TIMEOUT; i; i--) { + for (int i = MDEC_SYNC_TIMEOUT; i; i--) { if (!(DMA_CHCR(1) & (1 << 24))) return 0; } -- cgit v1.2.3 From 073a859acf16ccbc0f49364e38126bf2bf03aa3d Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sat, 30 Jul 2022 00:53:31 +0200 Subject: Deprecate u_short, u_int and u_long types in libpsn00b --- examples/mdec/mdecimage/main.c | 2 +- examples/sound/vagsample/main.c | 61 +-- examples/system/dynlink/library/balls.c | 2 +- examples/system/dynlink/main.c | 8 +- libpsn00b/include/lzp/lzp.h | 20 +- libpsn00b/include/lzp/lzqlp.h | 12 +- libpsn00b/include/psxapi.h | 156 +++--- libpsn00b/include/psxcd.h | 95 ++-- libpsn00b/include/psxgpu.h | 906 ++++++++++++++------------------ libpsn00b/include/psxgte.h | 54 +- libpsn00b/include/psxspu.h | 189 +++---- libpsn00b/lzp/crc.c | 29 +- libpsn00b/lzp/lzp.h | 20 +- libpsn00b/lzp/lzqlp.h | 12 +- libpsn00b/psxcd/isofs.c | 40 +- libpsn00b/psxcd/psxcd.c | 38 +- libpsn00b/psxgpu/common.c | 23 +- libpsn00b/psxgpu/env.c | 13 +- libpsn00b/psxgpu/font.c | 27 +- libpsn00b/psxgpu/image.c | 33 +- tools/lzpack/main.cpp | 8 +- 21 files changed, 792 insertions(+), 956 deletions(-) (limited to 'examples') 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 #include #include +#include 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< 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< 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 +#include #ifdef _WIN32 #include #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 +#include #ifdef _WIN32 #include #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 +#include + +/* 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 +#ifndef __PSXCD_H +#define __PSXCD_H + +#include /* * 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 #include -#include - -// 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 +#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 - -// 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 + +/* 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 #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> 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>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 +#include #ifdef _WIN32 #include #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 +#include #ifdef _WIN32 #include #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 +#include #include #include #include @@ -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 +#include #include #include #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 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 -#include #include #include #include @@ -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 -#include #include #include #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 +#include #include #include #include @@ -6,29 +6,28 @@ #include 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 -#include #include #include #include @@ -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; -- cgit v1.2.3 From 9560a1427aec1681c5d0c2bc30190ce4b1ad8557 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sun, 31 Jul 2022 18:04:59 +0200 Subject: Rewrite libpsxspu in C and update sound examples --- examples/sound/spustream/main.c | 48 ++++------- examples/sound/vagsample/main.c | 10 +-- libpsn00b/include/hwregs_a.h | 11 +-- libpsn00b/include/hwregs_c.h | 143 ++++++++++++++++----------------- libpsn00b/include/psxspu.h | 55 ++++++++++--- libpsn00b/psxgpu/common.c | 3 +- libpsn00b/psxgpu/image.c | 14 ++-- libpsn00b/psxpress/mdec.c | 8 +- libpsn00b/psxspu/common.c | 154 ++++++++++++++++++++++++++++++++++++ libpsn00b/psxspu/readme.txt | 21 ++--- libpsn00b/psxspu/spuinit.s | 124 ----------------------------- libpsn00b/psxspu/spukeyon.s | 17 ---- libpsn00b/psxspu/spureverbon.s | 16 ---- libpsn00b/psxspu/spusetkey.s | 26 ------ libpsn00b/psxspu/spusetreverb.s | 25 ------ libpsn00b/psxspu/spusetreverbaddr.s | 25 ------ libpsn00b/psxspu/spusetvoiceraw.s | 60 -------------- libpsn00b/psxspu/transfer.s | 108 ------------------------- 18 files changed, 318 insertions(+), 550 deletions(-) create mode 100644 libpsn00b/psxspu/common.c delete mode 100644 libpsn00b/psxspu/spuinit.s delete mode 100644 libpsn00b/psxspu/spukeyon.s delete mode 100644 libpsn00b/psxspu/spureverbon.s delete mode 100644 libpsn00b/psxspu/spusetkey.s delete mode 100644 libpsn00b/psxspu/spusetreverb.s delete mode 100644 libpsn00b/psxspu/spusetreverbaddr.s delete mode 100644 libpsn00b/psxspu/spusetvoiceraw.s delete mode 100644 libpsn00b/psxspu/transfer.s (limited to 'examples') diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c index 6b9db93..2ad122c 100644 --- a/examples/sound/spustream/main.c +++ b/examples/sound/spustream/main.c @@ -123,8 +123,8 @@ typedef struct { } DB; typedef struct { - DB db[2]; - uint32_t db_active; + DB db[2]; + int db_active; } CONTEXT; void init_context(CONTEXT *ctx) { @@ -170,23 +170,13 @@ void display(CONTEXT *ctx) { /* Stream interrupt handlers */ -// This is a silent looping sample used to keep unused SPU channels busy, -// preventing them from accidentally triggering the SPU RAM interrupt and -// throwing off the timing (all channels are always reading sample data, even -// when "stopped"). It is 64 bytes as that is the minimum size for SPU DMA -// transfers, however only the first 16 bytes are kept. The rest is going to be -// overwritten by chunks. -// https://problemkaputt.de/psx-spx.htm#spuinterrupt -const uint8_t SPU_DUMMY_BLOCK[] = { - 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - // The first 4 KB of SPU RAM are reserved for capture buffers, so we have to -// place stream buffers after those. Sony's SPU library additionally places a -// dummy sample at 0x1000; we are going to do the same with the block above. +// place stream buffers after those. A dummy sample is additionally placed by +// default by the SPU library at 0x1000; it is going to be used here to keep +// unused SPU channels busy, preventing them from accidentally triggering the +// SPU RAM interrupt and throwing off the timing (all channels are always +// reading sample data, even when "stopped"). +// https://problemkaputt.de/psx-spx.htm#spuinterrupt #define DUMMY_BLOCK_ADDR 0x1000 #define BUFFER_START_ADDR 0x1010 #define CHUNK_SIZE (BUFFER_SIZE * NUM_CHANNELS) @@ -207,7 +197,7 @@ static volatile StreamContext str_ctx; // read from the CD and uploaded to SPU RAM. Due to DMA limitations it can't be // allocated on the stack (especially not in the interrupt callbacks' stack, // whose size is very limited). -static uint8_t sector_buffer[2048]; +static uint32_t sector_buffer[512]; void spu_irq_handler(void) { // Acknowledge the interrupt to ensure it can be triggered again. The only @@ -231,7 +221,7 @@ void spu_irq_handler(void) { str_ctx.spu_addr = BUFFER_START_ADDR + CHUNK_SIZE * str_ctx.db_active; SPU_IRQ_ADDR = SPU_RAM_ADDR(str_ctx.spu_addr); - for (uint32_t i = 0; i < NUM_CHANNELS; i++) + for (int i = 0; i < NUM_CHANNELS; i++) SPU_CH_LOOP_ADDR(i) = SPU_RAM_ADDR(str_ctx.spu_addr + BUFFER_SIZE * i); // Start loading the next chunk. cd_event_handler() will be called @@ -241,7 +231,7 @@ void spu_irq_handler(void) { CdControlF(CdlReadN, &pos); } -void cd_event_handler(int32_t event, uint8_t *payload) { +void cd_event_handler(int event, uint8_t *payload) { // Ignore all events other than a sector being ready. // TODO: read errors should be handled properly if (event != CdlDataReady) @@ -255,7 +245,7 @@ void cd_event_handler(int32_t event, uint8_t *payload) { // other buffer, as we're overriding loop addresses) at the end. // NOTE: this isn't actually necessary here as the stream converter script // already sets these flags in the file. - /*for (uint32_t i = 0; i < NUM_CHANNELS; i++) { + /*for (int i = 0; i < NUM_CHANNELS; i++) { if ( str_ctx.spu_pos >= (BUFFER_SIZE * i - 2048) && str_ctx.spu_pos < (BUFFER_SIZE * i) @@ -268,7 +258,7 @@ void cd_event_handler(int32_t event, uint8_t *payload) { // just treat the chunk as a single blob of data and copy it as-is; we only // have to trim the padding at the end (if any) to avoid overwriting other // data in SPU RAM. - uint32_t length = CHUNK_SIZE - str_ctx.spu_pos; + size_t length = CHUNK_SIZE - str_ctx.spu_pos; if (length > 2048) length = 2048; @@ -288,15 +278,9 @@ void cd_event_handler(int32_t event, uint8_t *payload) { /* Stream helpers */ void init_spu_channels(void) { - // Upload the dummy block to the SPU and play it on all channels, locking - // them up and stopping them from messing with the SPU interrupt. - // TODO: is this really necessary? (needs testing on real hardware) - SpuSetTransferStartAddr(DUMMY_BLOCK_ADDR); - SpuWrite(SPU_DUMMY_BLOCK, 64); - SPU_KEY_OFF = 0x00ffffff; - for (uint32_t i = 0; i < 24; i++) + for (int i = 0; i < 24; i++) SPU_CH_ADDR(i) = SPU_RAM_ADDR(DUMMY_BLOCK_ADDR); SPU_KEY_ON = 0x00ffffff; @@ -330,7 +314,7 @@ void init_stream(CdlFILE *file) { void start_stream(void) { SPU_KEY_OFF = CHANNEL_MASK; - for (uint32_t i = 0; i < NUM_CHANNELS; i++) { + for (int i = 0; i < NUM_CHANNELS; i++) { SPU_CH_ADDR(i) = SPU_RAM_ADDR(BUFFER_START_ADDR + BUFFER_SIZE * i); SPU_CH_FREQ(i) = SAMPLE_RATE; SPU_CH_ADSR(i) = 0x1fee80ff; // or 0x9fc080ff, 0xdff18087 @@ -429,7 +413,7 @@ int main(int argc, const char* argv[]) { // Only set the sample rate registers if necessary. if (pad->btn != 0xffff) { - for (uint32_t i = 0; i < NUM_CHANNELS; i++) + for (int i = 0; i < NUM_CHANNELS; i++) SPU_CH_FREQ(i) = sample_rate; } diff --git a/examples/sound/vagsample/main.c b/examples/sound/vagsample/main.c index 1ec3b8a..c79e68e 100644 --- a/examples/sound/vagsample/main.c +++ b/examples/sound/vagsample/main.c @@ -32,7 +32,7 @@ */ #include -#include +#include #include #include #include @@ -104,8 +104,8 @@ void init(void) SpuSetTransferStartAddr(addr_temp); // Upload first sound clip and wait for transfer to finish - SpuWrite(((unsigned char*)proyt)+48, proyt_size-48); - SpuWait(); + SpuWrite((const uint32_t *) &proyt[48], proyt_size-48); + SpuIsTransferCompleted(SPU_TRANSFER_WAIT); // Obtain the address of the sound and advance address for the next one // Samples are addressed in 8-byte units, so it'll have to be divided by 8 @@ -116,8 +116,8 @@ void init(void) // Upload second sound clip SpuSetTransferStartAddr(addr_temp); - SpuWrite(((unsigned char*)tdfx)+48, tdfx_size-48); - SpuWait(); + SpuWrite((const uint32_t *) &tdfx[48], tdfx_size-48); + SpuIsTransferCompleted(SPU_TRANSFER_WAIT); // Obtain the address of the second sound clip tdfx_addr = addr_temp/8; diff --git a/libpsn00b/include/hwregs_a.h b/libpsn00b/include/hwregs_a.h index d8f6c72..c78b41a 100644 --- a/libpsn00b/include/hwregs_a.h +++ b/libpsn00b/include/hwregs_a.h @@ -1,10 +1,11 @@ -# Hardware register definitions for GNU assembler (as) -# -# Part of the PSn00bSDK Project by Lameguy64 -# 2019 Meido-Tek Productions +# PSn00bSDK hardware registers definitions +# (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed +## Constants -.set IOBASE, 0xbf80 # IO segment base (KSEG1) +.set IOBASE, 0x1f80 +.set F_CPU, 33868800 +.set F_GPU, 53222400 ## GPU diff --git a/libpsn00b/include/hwregs_c.h b/libpsn00b/include/hwregs_c.h index a9f4ee3..7b80590 100644 --- a/libpsn00b/include/hwregs_c.h +++ b/libpsn00b/include/hwregs_c.h @@ -14,116 +14,117 @@ /* Constants */ +#define IOBASE 0x1f800000 #define F_CPU 33868800UL #define F_GPU 53222400UL /* GPU */ -#define GPU_GP0 _MMIO32(0xbf801810) -#define GPU_GP1 _MMIO32(0xbf801814) +#define GPU_GP0 _MMIO32(IOBASE | 0x1810) +#define GPU_GP1 _MMIO32(IOBASE | 0x1814) /* CD drive */ -#define CD_STAT _MMIO8(0xbf801800) -#define CD_CMD _MMIO8(0xbf801801) -#define CD_DATA _MMIO8(0xbf801802) -#define CD_IRQ _MMIO8(0xbf801803) +#define CD_STAT _MMIO8(IOBASE | 0x1800) +#define CD_CMD _MMIO8(IOBASE | 0x1801) +#define CD_DATA _MMIO8(IOBASE | 0x1802) +#define CD_IRQ _MMIO8(IOBASE | 0x1803) -#define CD_REG(N) _MMIO8(0xbf801800 + (N)) +#define CD_REG(N) _MMIO8(IOBASE | 0x1800 + (N)) /* SPU */ -#define SPU_MASTER_VOL_L _MMIO16(0xbf801d80) -#define SPU_MASTER_VOL_R _MMIO16(0xbf801d82) -#define SPU_REVERB_VOL_L _MMIO16(0xbf801d84) -#define SPU_REVERB_VOL_R _MMIO16(0xbf801d86) -#define SPU_KEY_ON _MMIO32(0xbf801d88) -#define SPU_KEY_OFF _MMIO32(0xbf801d8c) -#define SPU_FM_MODE _MMIO32(0xbf801d90) -#define SPU_NOISE_MODE _MMIO32(0xbf801d94) -#define SPU_REVERB_ON _MMIO32(0xbf801d98) -#define SPU_CHAN_STATUS _MMIO32(0xbf801d9c) - -#define SPU_REVERB_ADDR _MMIO16(0xbf801da2) -#define SPU_IRQ_ADDR _MMIO16(0xbf801da4) -#define SPU_ADDR _MMIO16(0xbf801da6) -#define SPU_DATA _MMIO16(0xbf801da8) - -#define SPU_CTRL _MMIO16(0xbf801daa) -#define SPU_DMA_CTRL _MMIO16(0xbf801dac) -#define SPU_STAT _MMIO16(0xbf801dae) - -#define SPU_CD_VOL_L _MMIO16(0xbf801db0) -#define SPU_CD_VOL_R _MMIO16(0xbf801db2) -#define SPU_EXT_VOL_L _MMIO16(0xbf801db4) -#define SPU_EXT_VOL_R _MMIO16(0xbf801db6) -#define SPU_CURRENT_VOL_L _MMIO16(0xbf801db8) -#define SPU_CURRENT_VOL_R _MMIO16(0xbf801dba) +#define SPU_MASTER_VOL_L _MMIO16(IOBASE | 0x1d80) +#define SPU_MASTER_VOL_R _MMIO16(IOBASE | 0x1d82) +#define SPU_REVERB_VOL_L _MMIO16(IOBASE | 0x1d84) +#define SPU_REVERB_VOL_R _MMIO16(IOBASE | 0x1d86) +#define SPU_KEY_ON _MMIO32(IOBASE | 0x1d88) +#define SPU_KEY_OFF _MMIO32(IOBASE | 0x1d8c) +#define SPU_FM_MODE _MMIO32(IOBASE | 0x1d90) +#define SPU_NOISE_MODE _MMIO32(IOBASE | 0x1d94) +#define SPU_REVERB_ON _MMIO32(IOBASE | 0x1d98) +#define SPU_CHAN_STATUS _MMIO32(IOBASE | 0x1d9c) + +#define SPU_REVERB_ADDR _MMIO16(IOBASE | 0x1da2) +#define SPU_IRQ_ADDR _MMIO16(IOBASE | 0x1da4) +#define SPU_ADDR _MMIO16(IOBASE | 0x1da6) +#define SPU_DATA _MMIO16(IOBASE | 0x1da8) + +#define SPU_CTRL _MMIO16(IOBASE | 0x1daa) +#define SPU_DMA_CTRL _MMIO16(IOBASE | 0x1dac) +#define SPU_STAT _MMIO16(IOBASE | 0x1dae) + +#define SPU_CD_VOL_L _MMIO16(IOBASE | 0x1db0) +#define SPU_CD_VOL_R _MMIO16(IOBASE | 0x1db2) +#define SPU_EXT_VOL_L _MMIO16(IOBASE | 0x1db4) +#define SPU_EXT_VOL_R _MMIO16(IOBASE | 0x1db6) +#define SPU_CURRENT_VOL_L _MMIO16(IOBASE | 0x1db8) +#define SPU_CURRENT_VOL_R _MMIO16(IOBASE | 0x1dba) // These are not named SPU_VOICE_* to avoid name clashes with SPU attribute // flags defined in psxspu.h. -#define SPU_CH_VOL_L(N) _MMIO16(0xbf801c00 + 16 * (N)) -#define SPU_CH_VOL_R(N) _MMIO16(0xbf801c02 + 16 * (N)) -#define SPU_CH_FREQ(N) _MMIO16(0xbf801c04 + 16 * (N)) -#define SPU_CH_ADDR(N) _MMIO16(0xbf801c06 + 16 * (N)) -#define SPU_CH_ADSR(N) _MMIO32(0xbf801c08 + 16 * (N)) -#define SPU_CH_LOOP_ADDR(N) _MMIO16(0xbf801c0e + 16 * (N)) +#define SPU_CH_VOL_L(N) _MMIO16(IOBASE | 0x1c00 + 16 * (N)) +#define SPU_CH_VOL_R(N) _MMIO16(IOBASE | 0x1c02 + 16 * (N)) +#define SPU_CH_FREQ(N) _MMIO16(IOBASE | 0x1c04 + 16 * (N)) +#define SPU_CH_ADDR(N) _MMIO16(IOBASE | 0x1c06 + 16 * (N)) +#define SPU_CH_ADSR(N) _MMIO32(IOBASE | 0x1c08 + 16 * (N)) +#define SPU_CH_LOOP_ADDR(N) _MMIO16(IOBASE | 0x1c0e + 16 * (N)) /* MDEC */ -#define MDEC0 _MMIO32(0xbf801820) -#define MDEC1 _MMIO32(0xbf801824) +#define MDEC0 _MMIO32(IOBASE | 0x1820) +#define MDEC1 _MMIO32(IOBASE | 0x1824) /* SPI controller port */ // IMPORTANT: even though JOY_TXRX is a 32-bit register, it should only be // accessed as 8-bit. Reading it as 16 or 32-bit works fine on real hardware, // but leads to problems in some emulators. -#define JOY_TXRX _MMIO8(0xbf801040) -#define JOY_STAT _MMIO16(0xbf801044) -#define JOY_MODE _MMIO16(0xbf801048) -#define JOY_CTRL _MMIO16(0xbf80104a) -#define JOY_BAUD _MMIO16(0xbf80104e) +#define JOY_TXRX _MMIO8 (IOBASE | 0x1040) +#define JOY_STAT _MMIO16(IOBASE | 0x1044) +#define JOY_MODE _MMIO16(IOBASE | 0x1048) +#define JOY_CTRL _MMIO16(IOBASE | 0x104a) +#define JOY_BAUD _MMIO16(IOBASE | 0x104e) /* Serial port */ -#define SIO_TXRX _MMIO8(0xbf801050) -#define SIO_STAT _MMIO16(0xbf801054) -#define SIO_MODE _MMIO16(0xbf801058) -#define SIO_CTRL _MMIO16(0xbf80105a) -#define SIO_BAUD _MMIO16(0xbf80105e) +#define SIO_TXRX _MMIO8 (IOBASE | 0x1050) +#define SIO_STAT _MMIO16(IOBASE | 0x1054) +#define SIO_MODE _MMIO16(IOBASE | 0x1058) +#define SIO_CTRL _MMIO16(IOBASE | 0x105a) +#define SIO_BAUD _MMIO16(IOBASE | 0x105e) /* IRQ controller */ -#define IRQ_STAT _MMIO32(0xbf801070) -#define IRQ_MASK _MMIO32(0xbf801074) +#define IRQ_STAT _MMIO32(IOBASE | 0x1070) +#define IRQ_MASK _MMIO32(IOBASE | 0x1074) /* DMA */ -#define DMA_DPCR _MMIO32(0xbf8010f0) -#define DMA_DICR _MMIO32(0xbf8010f4) +#define DMA_DPCR _MMIO32(IOBASE | 0x10f0) +#define DMA_DICR _MMIO32(IOBASE | 0x10f4) -#define DMA_MADR(N) _MMIO32(0xbf801080 + 16 * (N)) -#define DMA_BCR(N) _MMIO32(0xbf801084 + 16 * (N)) -#define DMA_CHCR(N) _MMIO32(0xbf801088 + 16 * (N)) +#define DMA_MADR(N) _MMIO32(IOBASE | 0x1080 + 16 * (N)) +#define DMA_BCR(N) _MMIO32(IOBASE | 0x1084 + 16 * (N)) +#define DMA_CHCR(N) _MMIO32(IOBASE | 0x1088 + 16 * (N)) /* Timers */ -#define TIMER_VALUE(N) _MMIO32(0xbf801100 + 16 * (N)) -#define TIMER_CTRL(N) _MMIO32(0xbf801104 + 16 * (N)) -#define TIMER_RELOAD(N) _MMIO32(0xbf801108 + 16 * (N)) +#define TIMER_VALUE(N) _MMIO32(IOBASE | 0x1100 + 16 * (N)) +#define TIMER_CTRL(N) _MMIO32(IOBASE | 0x1104 + 16 * (N)) +#define TIMER_RELOAD(N) _MMIO32(IOBASE | 0x1108 + 16 * (N)) /* Memory control */ -#define EXP1_ADDR _MMIO32(0xbf801000) -#define EXP2_ADDR _MMIO32(0xbf801004) -#define EXP1_DELAY_SIZE _MMIO32(0xbf801008) -#define EXP3_DELAY_SIZE _MMIO32(0xbf80100c) -#define BIOS_DELAY_SIZE _MMIO32(0xbf801010) -#define SPU_DELAY_SIZE _MMIO32(0xbf801014) -#define CD_DELAY_SIZE _MMIO32(0xbf801018) -#define EXP2_DELAY_SIZE _MMIO32(0xbf80101c) -#define COM_DELAY_CFG _MMIO32(0xbf801020) -#define RAM_SIZE_CFG _MMIO32(0xbf801060) +#define EXP1_ADDR _MMIO32(IOBASE | 0x1000) +#define EXP2_ADDR _MMIO32(IOBASE | 0x1004) +#define EXP1_DELAY_SIZE _MMIO32(IOBASE | 0x1008) +#define EXP3_DELAY_SIZE _MMIO32(IOBASE | 0x100c) +#define BIOS_DELAY_SIZE _MMIO32(IOBASE | 0x1010) +#define SPU_DELAY_SIZE _MMIO32(IOBASE | 0x1014) +#define CD_DELAY_SIZE _MMIO32(IOBASE | 0x1018) +#define EXP2_DELAY_SIZE _MMIO32(IOBASE | 0x101c) +#define COM_DELAY_CFG _MMIO32(IOBASE | 0x1020) +#define RAM_SIZE_CFG _MMIO32(IOBASE | 0x1060) #endif diff --git a/libpsn00b/include/psxspu.h b/libpsn00b/include/psxspu.h index 36bbe70..e4c667a 100644 --- a/libpsn00b/include/psxspu.h +++ b/libpsn00b/include/psxspu.h @@ -7,6 +7,8 @@ #define __PSXSPU_H #include +#include +#include /* Definitions */ @@ -33,10 +35,15 @@ typedef enum _SPU_AttrMask { } SPU_AttrMask; typedef enum _SPU_TransferMode { - SPU_TRANSFER_BY_DMA = 0, - SPU_TRANSFER_BY_IO = 1 + SPU_TRANSFER_BY_DMA = 0, + SPU_TRANSFER_BY_IO = 1 } SPU_TransferMode; +typedef enum _SPU_WaitMode { + SPU_TRANSFER_PEEK = 0, + SPU_TRANSFER_WAIT = 1 +} SPU_WaitMode; + /* Structure definitions */ typedef struct _SpuVolume { @@ -66,6 +73,36 @@ typedef struct _SpuCommonAttr { SpuExtAttr cd, ext; } SpuCommonAttr; +/* "Useless" macros for official SDK compatibility */ + +#define SpuSetCommonMasterVolume(left, right) \ + (SPU_MASTER_VOL_L = (left), SPU_MASTER_VOL_R = (right)) +#define SpuSetCommonCDVolume(left, right) \ + (SPU_CD_VOL_L = (left), SPU_CD_VOL_R = (right)) +#define SpuSetCommonCDReverb(enable) \ + ((enable) ? (SPU_CTRL |= 0x0004) : (SPU_CTRL &= 0xfffb)) +#define SpuSetCommonExtVolume(left, right) \ + (SPU_EXT_VOL_L = (left), SPU_EXT_VOL_R = (right)) +#define SpuSetCommonExtReverb(enable) \ + ((enable) ? (SPU_CTRL |= 0x0002) : (SPU_CTRL &= 0xfffd)) + +#define SpuSetReverbAddr(addr) \ + (SPU_REVERB_ADDR = ((addr) + 7) / 8) +#define SpuSetIRQAddr(addr) \ + (SPU_IRQ_ADDR = ((addr) + 7) / 8) + +#define SpuSetVoiceVolume(ch, left, right) \ + (SPU_CH_VOL_L(ch) = (left), SPU_CH_VOL_R(ch) = (right)) +#define SpuSetVoicePitch(ch, pitch) \ + (SPU_CH_FREQ(ch) = (pitch)) +#define SpuSetVoiceStartAddr(ch, addr) \ + (SPU_CH_ADDR(ch) = ((addr) + 7) / 8) +#define SpuSetVoiceADSR(ch, ar, dr, sr, rr, sl) \ + (SPU_CH_ADSR(ch) = ((sl)) | ((dr) << 4) | ((ar) << 8) | ((rr) << 16) | ((sr) << 22) | (1 << 30)) + +#define SpuSetKey(enable, voice_bit) \ + ((enable) ? (SPU_KEY_ON = (voice_bit)) : (SPU_KEY_OFF = (voice_bit))) + /* Public API */ #ifdef __cplusplus @@ -74,15 +111,11 @@ extern "C" { void SpuInit(void); -void SpuReverbOn(int voice); -void SpuSetReverbAddr(int addr); -void SpuSetReverbVolume(int left, int right); -void SpuSetKey(int on_off, uint32_t voice_bit); - -int SpuSetTransferMode(int mode); -int SpuSetTransferStartAddr(int addr); -int SpuWrite(const uint8_t *addr, int size); -void SpuWait(void); +void SpuRead(const uint32_t *data, size_t size); +void SpuWrite(const uint32_t *data, size_t size); +SPU_TransferMode SpuSetTransferMode(SPU_TransferMode mode); +uint32_t SpuSetTransferStartAddr(uint32_t addr); +int SpuIsTransferCompleted(int mode); #ifdef __cplusplus } diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c index bf115a1..a65e0c9 100644 --- a/libpsn00b/psxgpu/common.c +++ b/libpsn00b/psxgpu/common.c @@ -117,7 +117,6 @@ static void _vsync_halt(void) { printf("psxgpu: VSync() timeout\n"); ChangeClearPAD(0); ChangeClearRCnt(3, 0); - return; } int VSync(int mode) { @@ -152,7 +151,7 @@ int DrawSync(int mode) { if (mode) return (DMA_BCR(2) >> 16); - // Wait for the queue to become empty, to make sure no . + // Wait for the queue to become empty. // TODO: add a timeout while (_queue_length) __asm__ volatile(""); diff --git a/libpsn00b/psxgpu/image.c b/libpsn00b/psxgpu/image.c index b3e5678..da51e7d 100644 --- a/libpsn00b/psxgpu/image.c +++ b/libpsn00b/psxgpu/image.c @@ -10,7 +10,7 @@ #define DMA_CHUNK_LENGTH 8 -/* Common internal load/store function */ +/* VRAM transfer API */ static void _load_store_image( uint32_t command, @@ -23,8 +23,10 @@ static void _load_store_image( printf("psxgpu: can't transfer an odd number of pixels\n"); length /= 2; - if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) - printf("psxgpu: transfer data length (%d) is not a multiple of %d\n", length, DMA_CHUNK_LENGTH); + if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) { + printf("psxgpu: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH); + length += DMA_CHUNK_LENGTH - 1; + } DrawSync(0); GPU_GP1 = 0x04000000; // Disable DMA request @@ -45,17 +47,15 @@ static void _load_store_image( else DMA_BCR(2) = DMA_CHUNK_LENGTH | ((length / DMA_CHUNK_LENGTH) << 16); - DMA_CHCR(2) = 0x01000200 | !(mode & 1); + DMA_CHCR(2) = 0x01000200 | ((mode & 1) ^ 1); } -/* Public VRAM API */ - void LoadImage(const RECT *rect, const uint32_t *data) { _load_store_image(0xa0000000, 2, rect, (uint32_t *) data); } void StoreImage(const RECT *rect, uint32_t *data) { - _load_store_image(0xc0000000, 3, rect, (uint32_t *) data); + _load_store_image(0xc0000000, 3, rect, data); } /* .TIM image parsers */ diff --git a/libpsn00b/psxpress/mdec.c b/libpsn00b/psxpress/mdec.c index b8d16b5..9c82d6b 100644 --- a/libpsn00b/psxpress/mdec.c +++ b/libpsn00b/psxpress/mdec.c @@ -126,9 +126,11 @@ void DecDCTin(const uint32_t *data, int mode) { // data length as an argument rather than parsing it from the first 4 bytes of // the stream. void DecDCTinRaw(const uint32_t *data, size_t length) { - // NOTE: if length >= DMA_CHUNK_LENGTH then it also has to be a multiple of - // DMA_CHUNK_LENGTH, otherwise the DMA channel will get stuck waiting for - // more data indefinitely. + if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) { + printf("psxmdec: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH); + length += DMA_CHUNK_LENGTH - 1; + } + DMA_MADR(0) = (uint32_t) data; if (length < DMA_CHUNK_LENGTH) DMA_BCR(0) = 0x00010000 | length; diff --git a/libpsn00b/psxspu/common.c b/libpsn00b/psxspu/common.c new file mode 100644 index 0000000..306cfd2 --- /dev/null +++ b/libpsn00b/psxspu/common.c @@ -0,0 +1,154 @@ +/* + * PSn00bSDK SPU library (common functions) + * (C) 2022 spicyjpeg - MPL licensed + */ + +#include +#include +#include +#include + +#define WRITABLE_AREA_ADDR 0x200 +#define DMA_CHUNK_LENGTH 16 +#define STATUS_TIMEOUT 0x100000 + +/* Internal globals */ + +static SPU_TransferMode _transfer_mode = SPU_TRANSFER_BY_DMA; +static uint16_t _transfer_addr = WRITABLE_AREA_ADDR; + +/* SPU initialization */ + +static void _wait_status(uint16_t mask, uint16_t value) { + for (int i = STATUS_TIMEOUT; i; i--) { + if ((SPU_STAT & mask) == value) + return; + } + + printf("psxspu: status register timeout (0x%04x)\n", SPU_STAT); +} + +void SpuInit(void) { + SPU_CTRL = 0x0000; // SPU disabled + _wait_status(0x001f, 0x0000); + + SPU_MASTER_VOL_L = 0; + SPU_MASTER_VOL_R = 0; + SPU_REVERB_VOL_L = 0; + SPU_REVERB_VOL_R = 0; + SPU_KEY_OFF = 0x00ffffff; + SPU_FM_MODE = 0; + SPU_NOISE_MODE = 0; + SPU_REVERB_ON = 0; + SPU_REVERB_ADDR = 0xfffe; + SPU_CD_VOL_L = 0; + SPU_CD_VOL_R = 0; + SPU_EXT_VOL_L = 0; + SPU_EXT_VOL_R = 0; + + for (int i = 0; i < 24; i++) { + SPU_CH_VOL_L(i) = 0; + SPU_CH_VOL_R(i) = 0; + SPU_CH_FREQ(i) = 0; + SPU_CH_ADDR(i) = 0; + } + + DMA_DPCR |= 0x000b0000; // Enable DMA4 + DMA_CHCR(4) = 0x00000201; // Stop DMA4 + + SPU_CTRL = 0xc011; // Enable SPU, DAC, CD audio, set manual transfer mode + _wait_status(0x001f, 0x0011); + + // Upload a dummy ADPCM block to the first 16 bytes of SPU RAM. This may be + // freely used or overwritten. + SPU_ADDR = WRITABLE_AREA_ADDR; + _wait_status(0x0400, 0x0000); + + SPU_DATA = 0x0500; + for (int i = 7; i; i--) + SPU_DATA = 0x0000; + + // Sony's implementation leaves everything muted, however it makes sense to + // turn up at least the master and CD audio volume by default. + SPU_MASTER_VOL_L = 0x3fff; + SPU_MASTER_VOL_R = 0x3fff; + SPU_CD_VOL_L = 0x3fff; + SPU_CD_VOL_R = 0x3fff; +} + +/* SPU RAM transfer API */ + +static void _load_store_data(uint32_t *data, size_t length, int mode) { + if (length % 4) + printf("psxspu: can't transfer a number of bytes that isn't multiple of 4\n"); + + length /= 4; + if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) { + printf("psxspu: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH); + length += DMA_CHUNK_LENGTH - 1; + } + + SPU_CTRL &= 0xffcf; // Disable DMA request + _wait_status(0x0030, 0x0000); + + // Enable DMA request for writing (2) or reading (3) + SPU_ADDR = _transfer_addr; + SPU_CTRL |= mode << 4; + _wait_status(0x0400, 0x0000); + + DMA_MADR(4) = (uint32_t) data; + if (length < DMA_CHUNK_LENGTH) + DMA_BCR(4) = 0x00010000 | length; + else + DMA_BCR(4) = DMA_CHUNK_LENGTH | ((length / DMA_CHUNK_LENGTH) << 16); + + DMA_CHCR(4) = 0x01000200 | ((mode & 1) ^ 1); +} + +void SpuRead(const uint32_t *data, size_t size) { + _load_store_data(data, size, 3); +} + +void SpuWrite(const uint32_t *data, size_t size) { + if (_transfer_addr < WRITABLE_AREA_ADDR) + return; + + // I/O transfer mode is not that useful, but whatever. + if (_transfer_mode) { + SPU_ADDR = _transfer_addr; + SPU_CTRL = (SPU_CTRL & 0xffcf) | 0x0010; // Manual transfer mode + _wait_status(0x0400, 0x0000); + + for (int i = size; i; i -= 4) { + uint32_t value = *(data++); + + SPU_DATA = (uint16_t) value; + SPU_DATA = (uint16_t) (value >> 16); + } + + return; + } + + _load_store_data(data, size, 2); +} + +SPU_TransferMode SpuSetTransferMode(SPU_TransferMode mode) { + _transfer_mode = mode; + return mode; +} + +uint32_t SpuSetTransferStartAddr(uint32_t addr) { + if (addr > 0x7ffff) + return 0; + + _transfer_addr = (addr + 7) / 8; + return addr; +} + +int SpuIsTransferCompleted(int mode) { + if (!mode) + return ((SPU_STAT >> 10) & 1) ^ 1; + + _wait_status(0x0400, 0x0000); + return 1; +} diff --git a/libpsn00b/psxspu/readme.txt b/libpsn00b/psxspu/readme.txt index 3ed90d0..07bbf97 100644 --- a/libpsn00b/psxspu/readme.txt +++ b/libpsn00b/psxspu/readme.txt @@ -3,29 +3,24 @@ PSX SPU Library, part of PSn00bSDK Licensed under Mozilla Public License - Open source implementation of the SPU library written mostly in MIPS -assembly. Currently only supports SPU init, uploading sample data using DMA -transfer and basic sample playback but is currently lacking a bunch of -important functions. - - Very work in progress currently. - +Open source implementation of the SPU library written entirely in C. Currently +only supports SPU initialization, reading/writing SPU RAM using DMA and basic +sample playback. Most of the official API is not going to be implemented as the +vast majority of it is just inefficient wrappers around accessing SPU registers +directly, which can be done already using the macros defined in hwregs_c.h. Library developer(s): - Lameguy64 - - + Lameguy64 (initial implementation in assembly) + spicyjpeg + Library header(s): psxspu.h - Todo list: * SPU RAM allocation routines yet to be implemented (heap must only be stored in main RAM and not SPU RAM like in the official SDK). - * SpuKeyOn() is actually not part of the official library. - * SPU reverb configuration functions yet to be implemented. diff --git a/libpsn00b/psxspu/spuinit.s b/libpsn00b/psxspu/spuinit.s deleted file mode 100644 index 6966213..0000000 --- a/libpsn00b/psxspu/spuinit.s +++ /dev/null @@ -1,124 +0,0 @@ -.set noreorder -.set noat - -.include "hwregs_a.h" - -.section .text - - -.global SpuInit -.type SpuInit, @function -SpuInit: - - addiu $sp, -4 - sw $ra, 0($sp) - - lui $v1, IOBASE - - # Stop and mute everything - - sh $0 , SPU_CTRL($v1) # Clear control settings - jal SpuCtrlSync - move $a0, $0 - - sh $0 , SPU_MASTER_VOL_L($v1) # Clear master volume - sh $0 , SPU_MASTER_VOL_R($v1) - - sh $0 , SPU_REVERB_VOL_L($v1) # Clear reverb volume - sh $0 , SPU_REVERB_VOL_R($v1) - - sh $0 , SPU_CD_VOL_L($v1) # Clear CD volume - sh $0 , SPU_CD_VOL_R($v1) - - sh $0 , SPU_EXT_VOL_L($v1) # Clear external audio volume - sh $0 , SPU_EXT_VOL_R($v1) - - sw $0 , SPU_FM_MODE($v1) # Turn off FM modes - sw $0 , SPU_NOISE_MODE($v1) # Turn off noise modes - sw $0 , SPU_REVERB_ON($v1) # Turn off reverb modes - - li $v0, 0xfffe - sh $v0, SPU_REVERB_ADDR($v1) - - lui $v0, 0x0200; - ori $v0, 0x3fff; - - # Clear all voices - - addiu $a1, $sp, -20 - sw $0 , 0($a1) - sw $0 , 4($a1) - sw $0 , 8($a1) - sw $0 , 12($a1) - - li $a2, 23 - -.Lclear_voices: - jal SpuSetVoiceRaw - move $a0, $a2 - addiu $a2, -1 - bgez $a2, .Lclear_voices - nop - - addiu $v0, $0, -1 # Set all keys to off - sw $v0, SPU_KEY_OFF($v1) - - li $v0, 0x4 # Set SPU data transfer control - sh $v0, SPU_DMA_CTRL($v1) # (usually always 0x4) - - lw $v0, DMA_DPCR($v1) # Enable DMA channel 4 (SPU DMA) - lui $at, 0xb - or $v0, $at - sw $v0, DMA_DPCR($v1) - - li $v0, 0xC001 # Enable SPU - sh $v0, SPU_CTRL($v1) - jal SpuCtrlSync - move $a0, $v0 - - li $v0, 0x3fff # Activate master volume - sh $v0, SPU_MASTER_VOL_L($v1) - sh $v0, SPU_MASTER_VOL_R($v1) - - sh $v0, SPU_CD_VOL_L($v1) # Activate CD volume - sh $v0, SPU_CD_VOL_R($v1) - - lw $ra, 0($sp) - addiu $sp, 4 - jr $ra - nop - - -# Waits until bits 0-5 of SPUSTAT are equal to SPUCNT -# -# Destroys v0, v1, a0 -# -.global SpuCtrlSync -.type SpuCtrlSync, @function -SpuCtrlSync: - lui $v1, IOBASE - andi $a0, 0x3f -.Lctrl_wait: - lhu $v0, SPU_STAT($v1) # Get SPUSTAT value - nop - andi $v0, 0x3f - bne $v0, $a0, .Lctrl_wait # Wait until SPUCNT and SPUSTAT are equal - nop - jr $ra - nop - - -# Waits until SPU has finished transfers -# -.global SpuWait -.type SpuWait, @function -SpuWait: - lui $v0, IOBASE - lhu $v0, SPU_STAT($v0) - nop - andi $v0, 0x400 - bnez $v0, SpuWait - nop - jr $ra - nop - \ No newline at end of file diff --git a/libpsn00b/psxspu/spukeyon.s b/libpsn00b/psxspu/spukeyon.s deleted file mode 100644 index 33592c2..0000000 --- a/libpsn00b/psxspu/spukeyon.s +++ /dev/null @@ -1,17 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .data - - -.global SpuKeyOn -.type SpuKeyOn, @function -SpuKeyOn: - lui $v1, IOBASE - li $v0, 1 - sll $v0, $a0 - sw $v0, SPU_KEY_ON($v1) - sw $v0, SPU_KEY_ON($v1) - jr $ra - nop \ No newline at end of file diff --git a/libpsn00b/psxspu/spureverbon.s b/libpsn00b/psxspu/spureverbon.s deleted file mode 100644 index 635fac3..0000000 --- a/libpsn00b/psxspu/spureverbon.s +++ /dev/null @@ -1,16 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .data - - -.global SpuReverbOn -.type SpuReverbOn, @function -SpuReverbOn: - lui $v1, IOBASE - li $v0, 1 - sll $v0, $a0 - sw $v0, SPU_REVERB_ON($v1) - jr $ra - nop \ No newline at end of file diff --git a/libpsn00b/psxspu/spusetkey.s b/libpsn00b/psxspu/spusetkey.s deleted file mode 100644 index 4ad0cff..0000000 --- a/libpsn00b/psxspu/spusetkey.s +++ /dev/null @@ -1,26 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .data - - -.global SpuSetKey -.type SpuSetKey, @function -SpuSetKey: - # a0 - 0: key off, 1: key on - # a1 - Voice bit mask - - lui $a2, IOBASE - - beqz $a0, .Lkey_off - nop - - jr $ra - sw $a1, SPU_KEY_ON($a2) - -.Lkey_off: - - jr $ra - sw $a1, SPU_KEY_OFF($a2) - \ No newline at end of file diff --git a/libpsn00b/psxspu/spusetreverb.s b/libpsn00b/psxspu/spusetreverb.s deleted file mode 100644 index 8257812..0000000 --- a/libpsn00b/psxspu/spusetreverb.s +++ /dev/null @@ -1,25 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - -.section .data - - -.global SpuSetReverb -.type SpuSetReverb, @function -SpuSetReverb: - addiu $sp, -4 - sw $ra, 0($sp) - - lui $v1, IOBASE - lhu $v0, SPU_CTRL($v1) - nop - ori $v0, 0x80 # Enable reverb - sh $v0, SPU_CTRL($v1) - jal SpuCtrlSync - move $a0, $v0 - - lw $ra, 0($sp) - addiu $sp, 4 - jr $ra - nop \ No newline at end of file diff --git a/libpsn00b/psxspu/spusetreverbaddr.s b/libpsn00b/psxspu/spusetreverbaddr.s deleted file mode 100644 index 089a91a..0000000 --- a/libpsn00b/psxspu/spusetreverbaddr.s +++ /dev/null @@ -1,25 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - - -.section .text - -.global SpuSetReverbAddr -.type SpuSetReverbAddr, @function -SpuSetReverbAddr: - lui $a3, IOBASE - srl $a0, 3 - sh $a0, SPU_REVERB_ADDR($a3) - jr $ra - nop - - -.global SpuSetReverbVolume -.type SpuSetReverbVolume, @function -SpuSetReverbVolume: - lui $a3, IOBASE - sh $a0, SPU_REVERB_VOL_L($a3) - sh $a1, SPU_REVERB_VOL_R($a3) - jr $ra - nop \ No newline at end of file diff --git a/libpsn00b/psxspu/spusetvoiceraw.s b/libpsn00b/psxspu/spusetvoiceraw.s deleted file mode 100644 index 43450f6..0000000 --- a/libpsn00b/psxspu/spusetvoiceraw.s +++ /dev/null @@ -1,60 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - - -.set PARAM_L, 0 -.set PARAM_R, 2 -.set PARAM_FREQ, 4 -.set PARAM_ADDR, 6 -.set PARAM_LOOP, 8 -.set PARAM_RES, 10 -.set PARAM_ADSR, 12 - - -.section .text - -.global SpuSetVoiceRaw -.type SpuSetVoiceRaw, @function -SpuSetVoiceRaw: - - # a0 - Voice number - # a1 - Address to parameters - - sll $a0, 4 - addiu $a0, SPU_VOICE_BASE - - lui $v1, IOBASE - or $a0, $v1 - - lhu $v0, PARAM_L($a1) - nop - sh $v0, SPU_VOICE_VOL_L($a0) - - lhu $v0, PARAM_R($a1) - nop - sh $v0, SPU_VOICE_VOL_R($a0) - - lhu $v0, PARAM_FREQ($a1) - nop - sh $v0, SPU_VOICE_FREQ($a0) - - lhu $v0, PARAM_ADDR($a1) - nop - sh $v0, SPU_VOICE_ADDR($a0) - - lhu $v0, PARAM_LOOP($a1) - nop - sh $v0, SPU_VOICE_LOOP($a0) - - - lw $v0, PARAM_ADSR($a1) - nop - sh $v0, SPU_VOICE_ADSR_L($a0) - srl $v0, 16 - sh $v0, SPU_VOICE_ADSR_H($a0) - - - jr $ra - nop - \ No newline at end of file diff --git a/libpsn00b/psxspu/transfer.s b/libpsn00b/psxspu/transfer.s deleted file mode 100644 index adcdb33..0000000 --- a/libpsn00b/psxspu/transfer.s +++ /dev/null @@ -1,108 +0,0 @@ -.set noreorder - -.include "hwregs_a.h" - - -.section .text - -.global SpuSetTransferMode -.type SpuSetTransferMode, @function -SpuSetTransferMode: - la $v0, _spu_transfer_mode - sb $a0, 0($v0) - jr $ra - move $v0, $a0 - - -.global SpuSetTransferStartAddr -.type SpuSetTransferStartAddr, @function -SpuSetTransferStartAddr: - li $v0, 0x1000 # Check if value is valid - blt $a0, $v0, .Lbad_value - nop - lui $v0, 8 # 0x7ffff = (8<<16)-1 - addiu $v0, -1 - bgt $a0, $v0, .Lbad_value - nop - - la $v1, _spu_transfer_addr - srl $v0, $a0, 3 # Set transfer destination address - sh $v0, 0($v1) - - jr $ra - move $v0, $a0 - -.Lbad_value: - jr $ra - move $v0, $0 - - -.global SpuWrite -.type SpuWrite, @function -SpuWrite: - addiu $sp, -8 - sw $ra, 0($sp) - sw $a0, 4($sp) - - lui $a3, IOBASE - - lhu $v0, SPU_CTRL($a3) # Set transfer mode to Stop - nop - andi $v0, 0xffcf - sh $v0, SPU_CTRL($a3) - jal SpuCtrlSync - move $a0, $v0 - - la $v1, _spu_transfer_addr # Set SPU write address - lhu $v1, 0($v1) - nop - sh $v1, SPU_ADDR($a3) - - lhu $v0, SPU_CTRL($a3) # Set transfer mode to DMA write - nop - ori $v0, 0x20 - sh $v0, SPU_CTRL($a3) - #jal SpuCtrlSync # Locks up on most emulators (bit 5 in - #move $a0, $v0 # SPUSTAT likely not updating, seems to - # be okay to not wait for it on real HW) - - lw $a0, 4($sp) - -.Ldma_wait: # Wait for SPU to be ready for DMA - lhu $v0, SPU_STAT($a3) - nop - andi $v0, 0x400 # Bit 8 in SPUSTAT never changes to 1 on - bnez $v0, .Ldma_wait # emulators so use bit 10 instead - nop - - sw $a0, DMA4_MADR($a3) # Set DMA source address - - li $v0, 0x10 # 16 words per block (64 bytes) - addiu $a1, 63 # Add by 63 to ensure all bytes get sent - srl $a1, 6 # Equivalent to divide by 64 - andi $a1, 0xffff - sll $a1, 16 - or $v0, $a1 - sw $v0, DMA4_BCR($a3) - - lui $v0, 0x0100 # Commence transfer - ori $v0, 0x0201 - sw $v0, DMA4_CHCR($a3) - - lw $ra, 0($sp) - addiu $sp, 8 - jr $ra - nop - - -.section .data - -.global _spu_transfer_mode -.type _spu_transfer_mode, @object -_spu_transfer_mode: - .word 0x0 - -.global _spu_transfer_addr -.type _spu_transfer_addr, @object -_spu_transfer_addr: - .word 0x200 \ No newline at end of file -- cgit v1.2.3 From a1081f296bca4f718cf31e5b6a262661d132e9e4 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Wed, 10 Aug 2022 22:49:49 +0200 Subject: Misc. fixes, add texturing to graphics/gte example --- examples/graphics/gte/CMakeLists.txt | 4 ++- examples/graphics/gte/main.c | 51 +++++++++++++++++++++++++---------- examples/graphics/gte/texture.tim | Bin 0 -> 16928 bytes libpsn00b/cmake/sdk.cmake | 2 ++ libpsn00b/include/psxspu.h | 2 +- libpsn00b/psxgpu/common.c | 9 ++++--- libpsn00b/psxspu/common.c | 4 +-- 7 files changed, 50 insertions(+), 22 deletions(-) create mode 100644 examples/graphics/gte/texture.tim (limited to 'examples') diff --git a/examples/graphics/gte/CMakeLists.txt b/examples/graphics/gte/CMakeLists.txt index f95c5ff..90d897b 100644 --- a/examples/graphics/gte/CMakeLists.txt +++ b/examples/graphics/gte/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20) project( gte - LANGUAGES C + LANGUAGES C ASM VERSION 1.0.0 DESCRIPTION "PSn00bSDK GTE 3D cube example" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" @@ -15,4 +15,6 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(gte STATIC ${_sources}) #psn00bsdk_add_cd_image(gte_iso gte iso.xml DEPENDS gte) +psn00bsdk_target_incbin(gte PRIVATE tim_texture texture.tim) + install(FILES ${PROJECT_BINARY_DIR}/gte.exe TYPE BIN) diff --git a/examples/graphics/gte/main.c b/examples/graphics/gte/main.c index a7ddb6b..ba96ace 100644 --- a/examples/graphics/gte/main.c +++ b/examples/graphics/gte/main.c @@ -12,13 +12,15 @@ * * Changelog: * - * May 10, 2021 - Variable types updated for psxgpu.h changes. + * Aug 10, 2022 - Added texture to cube faces. + * + * May 10, 2021 - Variable types updated for psxgpu.h changes. * * Jan 26, 2019 - Initial version. * */ -#include +#include #include #include #include @@ -39,10 +41,10 @@ /* Double buffer structure */ typedef struct { - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ - u_long ot[OT_LEN]; /* Ordering table */ - char p[PACKET_LEN]; /* Packet buffer */ + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + uint32_t ot[OT_LEN]; /* Ordering table */ + char p[PACKET_LEN]; /* Packet buffer */ } DB; /* Double buffer variables */ @@ -98,9 +100,9 @@ INDEX cube_indices[] = { /* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ /* A column of zeroes disables the light source. */ MATRIX color_mtx = { - ONE, 0, 0, /* Red */ - ONE, 0, 0, /* Green */ - ONE, 0, 0 /* Blue */ + ONE / 2, 0, 0, /* Red */ + ONE / 2, 0, 0, /* Green */ + ONE / 2, 0, 0 /* Blue */ }; /* Light matrix */ @@ -114,6 +116,13 @@ MATRIX light_mtx = { }; +/* Reference texture data */ +extern uint32_t tim_texture[]; + +/* TPage and CLUT values */ +uint16_t texture_tpage; /* For the scrolling blending pattern */ +uint16_t texture_clut; + /* Function declarations */ void init(); void display(); @@ -128,7 +137,7 @@ int main() { VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ - POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ + POLY_FT4 *pol4; /* Flat shaded textured quad primitive pointer */ /* Init graphics and GTE */ @@ -159,7 +168,7 @@ int main() { /* Draw the cube */ - pol4 = (POLY_F4*)db_nextpri; + pol4 = (POLY_FT4*)db_nextpri; for( i=0; ix0 ); @@ -218,6 +227,11 @@ int main() { /* Store result to the primitive */ gte_strgb( &pol4->r0 ); + /* Set face texture */ + setUVWH( pol4, 0, 1, 128, 128 ); + pol4->tpage = texture_tpage; + pol4->clut = texture_clut; + /* Sort primitive to the ordering table */ addPrim( db[db_active].ot+(p>>2), pol4 ); @@ -240,6 +254,7 @@ int main() { } void init() { + TIM_IMAGE tim; /* Reset the GPU, also installs a VSync event handler */ ResetGraph( 0 ); @@ -250,7 +265,7 @@ void init() { SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); /* Enable draw area clear and dither processing */ - setRGB0( &db[0].draw, 63, 0, 127 ); + setRGB0( &db[0].draw, 0, 255, 0 ); db[0].draw.isbg = 1; db[0].draw.dtd = 1; @@ -287,7 +302,15 @@ void init() { /* Set light ambient color and light color matrix */ gte_SetBackColor( 63, 63, 63 ); gte_SetColorMatrix( &color_mtx ); + + /* Load .TIM file */ + GetTimInfo(tim_texture, &tim); + if( tim.mode & 0x8 ) + LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ + LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ + texture_tpage = getTPage(tim.mode, 1, tim.prect->x, tim.prect->y); + texture_clut = getClut(tim.crect->x, tim.crect->y); } void display() { @@ -313,4 +336,4 @@ void display() { /* Start drawing the OT of the last buffer */ DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); -} \ No newline at end of file +} diff --git a/examples/graphics/gte/texture.tim b/examples/graphics/gte/texture.tim new file mode 100644 index 0000000..54ce2f0 Binary files /dev/null and b/examples/graphics/gte/texture.tim differ diff --git a/libpsn00b/cmake/sdk.cmake b/libpsn00b/cmake/sdk.cmake index d6d9bcd..8965e79 100644 --- a/libpsn00b/cmake/sdk.cmake +++ b/libpsn00b/cmake/sdk.cmake @@ -38,6 +38,8 @@ find_program( HINTS ${PSN00BSDK_TC}/bin ${PSN00BSDK_TC}/../bin + # Same as ${CMAKE_INSTALL_PREFIX}/bin + ${CMAKE_CURRENT_LIST_DIR}/../../../bin # Same as ${CMAKE_INSTALL_PREFIX}/${PSN00BSDK_TARGET}/bin ${CMAKE_CURRENT_LIST_DIR}/../../../${PSN00BSDK_TARGET}/bin PATHS diff --git a/libpsn00b/include/psxspu.h b/libpsn00b/include/psxspu.h index e4c667a..cf78e3d 100644 --- a/libpsn00b/include/psxspu.h +++ b/libpsn00b/include/psxspu.h @@ -111,7 +111,7 @@ extern "C" { void SpuInit(void); -void SpuRead(const uint32_t *data, size_t size); +void SpuRead(uint32_t *data, size_t size); void SpuWrite(const uint32_t *data, size_t size); SPU_TransferMode SpuSetTransferMode(SPU_TransferMode mode); uint32_t SpuSetTransferStartAddr(uint32_t addr); diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c index a65e0c9..4591012 100644 --- a/libpsn00b/psxgpu/common.c +++ b/libpsn00b/psxgpu/common.c @@ -122,12 +122,13 @@ static void _vsync_halt(void) { int VSync(int mode) { if (mode < 0) return _vblank_counter; + if (mode == 1) + return TIMER_VALUE(1) - _last_hblank; uint32_t status = GPU_GP1; - // If mode = 0, wait for one vertical blank event to occur. If mode = 1, do - // not wait. - for (int i = ((mode < 2) ? (mode ^ 1) : mode); i; i--) { + // Wait for at least one vertical blank event to occur. + do { _vsync_halt(); // If interlaced mode is enabled, wait until the GPU starts displaying @@ -136,7 +137,7 @@ int VSync(int mode) { while (!((GPU_GP1 ^ status) & (1 << 31))) __asm__ volatile(""); } - } + } while ((--mode) > 0); // Update the horizontal blank counter and return the time elapsed since // the last time it was updated. diff --git a/libpsn00b/psxspu/common.c b/libpsn00b/psxspu/common.c index 306cfd2..c1e8cab 100644 --- a/libpsn00b/psxspu/common.c +++ b/libpsn00b/psxspu/common.c @@ -105,7 +105,7 @@ static void _load_store_data(uint32_t *data, size_t length, int mode) { DMA_CHCR(4) = 0x01000200 | ((mode & 1) ^ 1); } -void SpuRead(const uint32_t *data, size_t size) { +void SpuRead(uint32_t *data, size_t size) { _load_store_data(data, size, 3); } @@ -129,7 +129,7 @@ void SpuWrite(const uint32_t *data, size_t size) { return; } - _load_store_data(data, size, 2); + _load_store_data((uint32_t *) data, size, 2); } SPU_TransferMode SpuSetTransferMode(SPU_TransferMode mode) { -- cgit v1.2.3 From 7abb3b78727c8d4672197951e62b1c5916b3a54a Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Thu, 11 Aug 2022 14:23:05 +0200 Subject: Clean up and add audio file to sound/spustream example --- examples/README.md | 11 +++++------ examples/graphics/gte/main.c | 2 +- examples/sound/spustream/CMakeLists.txt | 7 +++---- examples/sound/spustream/main.c | 28 ++++++++++++++++------------ examples/sound/spustream/stream.bin | Bin 0 -> 4685824 bytes libpsn00b/psxspu/common.c | 17 ++++++++++------- 6 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 examples/sound/spustream/stream.bin (limited to 'examples') diff --git a/examples/README.md b/examples/README.md index 4025a56..82d7698 100644 --- a/examples/README.md +++ b/examples/README.md @@ -25,7 +25,7 @@ Additional information may be found in the source code of each example. | [`io/system573`](./io/system573) | Konami System 573 (PS1-based arcade board) example | CD | | | [`lowlevel/cartrom`](./lowlevel/cartrom) | ROM firmware for cheat devices written using GNU GAS | ROM | 4 | | [`mdec/mdecimage`](./mdec/mdecimage) | Displays a (raw) MDEC format image using libpsxpress | EXE | | -| [`sound/spustream`](./sound/spustream) | Custom (non XA) CD-ROM audio streaming using the SPU | CD | 1 | +| [`sound/spustream`](./sound/spustream) | Custom (non XA) CD-ROM audio streaming using the SPU | CD | | | [`sound/vagsample`](./sound/vagsample) | Demonstrates playing VAG sound files using the SPU | EXE | | | [`system/childexec`](./system/childexec) | Loading a child program and returning to parent | EXE | | | [`system/console`](./system/console) | TTY based text console that interrupts gameplay | EXE | | @@ -35,10 +35,9 @@ Additional information may be found in the source code of each example. Notes: -1. `cdrom/cdxa` and `sound/spustream` do not come with example audio files. In - order to run these examples you'll have to provide your own files (and, in - the case of `spustream`, convert them using the included Python script) and - build the CD image manually. +1. `cdrom/cdxa` does not come with an example XA audio file. In order to run + this example you'll have to provide your own file and build the CD image + manually. 2. `demos/n00bdemo` suffers from flickering on real hardware, especially when masking/stencil buffering is used. 3. `io/pads` seems to work on real hardware, but fails to automatically enable @@ -85,4 +84,4 @@ are for rebuilding the examples *after* the SDK has been installed. CD images for each example. ----------------------------------------- -_Last updated on 2022-02-06 by spicyjpeg_ +_Last updated on 2022-08-11 by spicyjpeg_ diff --git a/examples/graphics/gte/main.c b/examples/graphics/gte/main.c index ba96ace..1257c88 100644 --- a/examples/graphics/gte/main.c +++ b/examples/graphics/gte/main.c @@ -265,7 +265,7 @@ void init() { SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); /* Enable draw area clear and dither processing */ - setRGB0( &db[0].draw, 0, 255, 0 ); + setRGB0( &db[0].draw, 63, 0, 127 ); db[0].draw.isbg = 1; db[0].draw.dtd = 1; diff --git a/examples/sound/spustream/CMakeLists.txt b/examples/sound/spustream/CMakeLists.txt index 9e84fa3..397796a 100644 --- a/examples/sound/spustream/CMakeLists.txt +++ b/examples/sound/spustream/CMakeLists.txt @@ -14,12 +14,11 @@ project( # TODO: add rules to actually generate a valid STREAM.BIN file file(GLOB _sources *.c) psn00bsdk_add_executable(spustream STATIC ${_sources}) -#psn00bsdk_add_cd_image(spustream_iso spustream iso.xml DEPENDS spustream) +psn00bsdk_add_cd_image(spustream_iso spustream iso.xml DEPENDS spustream) install( FILES - #${PROJECT_BINARY_DIR}/spustream.bin - #${PROJECT_BINARY_DIR}/spustream.cue - ${PROJECT_BINARY_DIR}/spustream.exe + ${PROJECT_BINARY_DIR}/spustream.bin + ${PROJECT_BINARY_DIR}/spustream.cue TYPE BIN ) diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c index 2ad122c..6179179 100644 --- a/examples/sound/spustream/main.c +++ b/examples/sound/spustream/main.c @@ -51,10 +51,9 @@ * +----------+----------+----------+----------+----------+----------+---- * \________________________Chunk________________________/ * - * Such file isn't provided as PSn00bSDK doesn't yet have a tool for audio - * transcoding. A Python script is included to generate STREAM.BIN from one or - * more SPU ADPCM (.VAG) files, one for each channel (the .VAG format only - * supports mono). + * A Python script is included to generate STREAM.BIN from one or more SPU + * ADPCM (.VAG) files, one for each channel (the .VAG format only supports + * mono). * * Of course SPU streaming isn't the only way to play music, as the CD drive * can play CD-DA tracks and XA files natively with zero CPU overhead. However @@ -101,7 +100,7 @@ // size can be increased to get more idle time between CD reads, however it is // usually best to keep it to 1-2 seconds as SPU RAM is only 512 KB. #define SAMPLE_RATE 0x1000 // 44100 Hz -#define BUFFER_SIZE 26624 // (26624 / 16 * 28) / 44100 = 1.05 seconds +#define BUFFER_SIZE 0x6800 // (0x6800 / 16 * 28) / 44100 = 1.05 seconds #define NUM_CHANNELS 2 #define CHANNEL_MASK 0x03 @@ -250,7 +249,7 @@ void cd_event_handler(int event, uint8_t *payload) { str_ctx.spu_pos >= (BUFFER_SIZE * i - 2048) && str_ctx.spu_pos < (BUFFER_SIZE * i) ) - sector[(BUFFER_SIZE * i - str_ctx.spu_pos) - 15] = 0x03; + sector_buffer[(BUFFER_SIZE * i - str_ctx.spu_pos) - 15] = 0x03; }*/ // Copy the sector to SPU RAM, appending it to the buffer that is not @@ -268,7 +267,6 @@ void cd_event_handler(int event, uint8_t *payload) { // If the buffer has been filled completely, stop reading and re-enable the // SPU IRQ. - // TODO TODO: preload first sector if (str_ctx.spu_pos >= CHUNK_SIZE) { CdControlF(CdlPause, 0); SPU_CTRL |= 0x0040; @@ -277,11 +275,17 @@ void cd_event_handler(int event, uint8_t *payload) { /* Stream helpers */ -void init_spu_channels(void) { +// This isn't actually required for this example, however it is necessary if +// you want to allocate the stream buffers into a region of SPU RAM that was +// previously used (to make sure the IRQ isn't going to be triggered by any +// inactive channels). +void reset_spu_channels(void) { SPU_KEY_OFF = 0x00ffffff; - for (int i = 0; i < 24; i++) + for (int i = 0; i < 24; i++) { SPU_CH_ADDR(i) = SPU_RAM_ADDR(DUMMY_BLOCK_ADDR); + SPU_CH_FREQ(i) = 0x1000; + } SPU_KEY_ON = 0x00ffffff; } @@ -308,7 +312,7 @@ void init_stream(CdlFILE *file) { spu_irq_handler(); while (str_ctx.spu_pos < CHUNK_SIZE) - __asm__("nop"); + __asm__ volatile(""); } void start_stream(void) { @@ -317,7 +321,7 @@ void start_stream(void) { for (int i = 0; i < NUM_CHANNELS; i++) { SPU_CH_ADDR(i) = SPU_RAM_ADDR(BUFFER_START_ADDR + BUFFER_SIZE * i); SPU_CH_FREQ(i) = SAMPLE_RATE; - SPU_CH_ADSR(i) = 0x1fee80ff; // or 0x9fc080ff, 0xdff18087 + SPU_CH_ADSR(i) = 0x1fee80ff; } // Unmute the channels and route them for stereo output. You'll want to @@ -345,7 +349,7 @@ int main(int argc, const char* argv[]) { SHOW_STATUS("INITIALIZING\n"); SpuInit(); CdInit(); - init_spu_channels(); + reset_spu_channels(); SHOW_STATUS("LOCATING STREAM FILE\n"); diff --git a/examples/sound/spustream/stream.bin b/examples/sound/spustream/stream.bin new file mode 100644 index 0000000..e53b726 Binary files /dev/null and b/examples/sound/spustream/stream.bin differ diff --git a/libpsn00b/psxspu/common.c b/libpsn00b/psxspu/common.c index c1e8cab..55a3dba 100644 --- a/libpsn00b/psxspu/common.c +++ b/libpsn00b/psxspu/common.c @@ -46,13 +46,6 @@ void SpuInit(void) { SPU_EXT_VOL_L = 0; SPU_EXT_VOL_R = 0; - for (int i = 0; i < 24; i++) { - SPU_CH_VOL_L(i) = 0; - SPU_CH_VOL_R(i) = 0; - SPU_CH_FREQ(i) = 0; - SPU_CH_ADDR(i) = 0; - } - DMA_DPCR |= 0x000b0000; // Enable DMA4 DMA_CHCR(4) = 0x00000201; // Stop DMA4 @@ -68,8 +61,18 @@ void SpuInit(void) { for (int i = 7; i; i--) SPU_DATA = 0x0000; + // "Play" the dummy block on all channels. This will reset the start + // address and ADSR envelope status of each channel. + for (int i = 0; i < 24; i++) { + SPU_CH_VOL_L(i) = 0; + SPU_CH_VOL_R(i) = 0; + SPU_CH_FREQ(i) = 0x1000; + SPU_CH_ADDR(i) = WRITABLE_AREA_ADDR; + } + // Sony's implementation leaves everything muted, however it makes sense to // turn up at least the master and CD audio volume by default. + SPU_KEY_ON = 0x00ffffff; SPU_MASTER_VOL_L = 0x3fff; SPU_MASTER_VOL_R = 0x3fff; SPU_CD_VOL_L = 0x3fff; -- cgit v1.2.3 From edb967394d22420c9aaad529862a670c016cc2c7 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Fri, 12 Aug 2022 11:27:55 +0200 Subject: Replace ball16c.h headers in examples with .TIM files --- examples/cdrom/cdbrowse/CMakeLists.txt | 4 +++- examples/cdrom/cdbrowse/ball16c.h | 16 --------------- examples/cdrom/cdbrowse/ball16c.tim | Bin 0 -> 192 bytes examples/cdrom/cdbrowse/main.c | 11 +++++----- examples/cdrom/cdxa/CMakeLists.txt | 4 +++- examples/cdrom/cdxa/ball16c.h | 16 --------------- examples/cdrom/cdxa/ball16c.tim | Bin 0 -> 192 bytes examples/cdrom/cdxa/main.c | 30 +++++++++++++--------------- examples/graphics/balls/CMakeLists.txt | 4 +++- examples/graphics/balls/ball16c.h | 16 --------------- examples/graphics/balls/main.c | 16 +++++++-------- examples/graphics/gte/main.c | 2 +- examples/system/childexec/CMakeLists.txt | 1 + examples/system/childexec/ball16c.h | 16 --------------- examples/system/childexec/ball16c.tim | Bin 0 -> 192 bytes examples/system/childexec/child/child.c | 10 +++++----- examples/system/childexec/parent.c | 10 +++++----- examples/system/console/CMakeLists.txt | 4 +++- examples/system/console/ball16c.h | 16 --------------- examples/system/console/ball16c.tim | Bin 0 -> 192 bytes examples/system/console/main.c | 16 +++++++-------- examples/system/dynlink/CMakeLists.txt | 4 +++- examples/system/dynlink/library/ball16c.h | 16 --------------- examples/system/dynlink/library/ball16c.tim | Bin 0 -> 192 bytes examples/system/dynlink/library/balls.c | 5 +++-- 25 files changed, 65 insertions(+), 152 deletions(-) delete mode 100644 examples/cdrom/cdbrowse/ball16c.h create mode 100644 examples/cdrom/cdbrowse/ball16c.tim delete mode 100644 examples/cdrom/cdxa/ball16c.h create mode 100644 examples/cdrom/cdxa/ball16c.tim delete mode 100644 examples/graphics/balls/ball16c.h delete mode 100644 examples/system/childexec/ball16c.h create mode 100644 examples/system/childexec/ball16c.tim delete mode 100644 examples/system/console/ball16c.h create mode 100644 examples/system/console/ball16c.tim delete mode 100644 examples/system/dynlink/library/ball16c.h create mode 100644 examples/system/dynlink/library/ball16c.tim (limited to 'examples') diff --git a/examples/cdrom/cdbrowse/CMakeLists.txt b/examples/cdrom/cdbrowse/CMakeLists.txt index e36407d..c2e93fc 100644 --- a/examples/cdrom/cdbrowse/CMakeLists.txt +++ b/examples/cdrom/cdbrowse/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20) project( cdbrowse - LANGUAGES C + LANGUAGES C ASM VERSION 1.0.0 DESCRIPTION "PSn00bSDK CD file browser example" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" @@ -15,6 +15,8 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(cdbrowse STATIC ${_sources}) psn00bsdk_add_cd_image(cdbrowse_iso cdbrowse iso.xml DEPENDS cdbrowse) +psn00bsdk_target_incbin(cdbrowse PRIVATE ball16c ball16c.tim) + install( FILES ${PROJECT_BINARY_DIR}/cdbrowse.bin diff --git a/examples/cdrom/cdbrowse/ball16c.h b/examples/cdrom/cdbrowse/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/cdrom/cdbrowse/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/cdrom/cdbrowse/ball16c.tim b/examples/cdrom/cdbrowse/ball16c.tim new file mode 100644 index 0000000..e2a5d17 Binary files /dev/null and b/examples/cdrom/cdbrowse/ball16c.tim differ diff --git a/examples/cdrom/cdbrowse/main.c b/examples/cdrom/cdbrowse/main.c index 9a1dbd0..f614f1d 100644 --- a/examples/cdrom/cdbrowse/main.c +++ b/examples/cdrom/cdbrowse/main.c @@ -54,7 +54,7 @@ * July 12, 2020: Updated CD-ROM directory query logic on disc change slightly. */ -#include +#include #include #include #include @@ -67,9 +67,6 @@ #include #include -#include "ball16c.h" - - #define MAX_BALLS 1536 /* Number of balls to display */ #define OT_LEN 8 /* Ordering table length */ @@ -87,7 +84,7 @@ DISPENV disp[2]; DRAWENV draw[2]; char pribuff[2][65536]; /* Primitive packet buffers */ -u_long ot[2][OT_LEN]; /* Ordering tables */ +uint32_t ot[2][OT_LEN]; /* Ordering tables */ char *nextpri; /* Pointer to next packet buffer offset */ int db = 0; /* Double buffer index */ @@ -102,6 +99,8 @@ typedef struct BALL_TYPE BALL_TYPE balls[MAX_BALLS]; +/* Ball texture reference */ +extern const uint32_t ball16c[]; /* TIM image parameters for loading the ball texture and drawing sprites */ TIM_IMAGE tim; @@ -192,7 +191,7 @@ void init() /* Upload the ball texture */ - GetTimInfo((u_long*)ball16c, &tim); /* Get TIM parameters */ + GetTimInfo(ball16c, &tim); /* Get TIM parameters */ LoadImage(tim.prect, tim.paddr); /* Upload texture to VRAM */ if( tim.mode & 0x8 ) { diff --git a/examples/cdrom/cdxa/CMakeLists.txt b/examples/cdrom/cdxa/CMakeLists.txt index 7b90f59..70ef77c 100644 --- a/examples/cdrom/cdxa/CMakeLists.txt +++ b/examples/cdrom/cdxa/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20) project( cdxa - LANGUAGES C + LANGUAGES C ASM VERSION 1.0.0 DESCRIPTION "PSn00bSDK CD-XA playback example" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" @@ -16,6 +16,8 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(cdxa STATIC ${_sources}) #psn00bsdk_add_cd_image(cdxa_iso cdxa iso.xml DEPENDS cdxa) +psn00bsdk_target_incbin(cdxa PRIVATE ball16c ball16c.tim) + install( FILES #${PROJECT_BINARY_DIR}/cdxa.bin diff --git a/examples/cdrom/cdxa/ball16c.h b/examples/cdrom/cdxa/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/cdrom/cdxa/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/cdrom/cdxa/ball16c.tim b/examples/cdrom/cdxa/ball16c.tim new file mode 100644 index 0000000..e2a5d17 Binary files /dev/null and b/examples/cdrom/cdxa/ball16c.tim differ diff --git a/examples/cdrom/cdxa/main.c b/examples/cdrom/cdxa/main.c index 284b92f..4921658 100644 --- a/examples/cdrom/cdxa/main.c +++ b/examples/cdrom/cdxa/main.c @@ -116,7 +116,7 @@ * */ -#include +#include #include #include #include @@ -129,14 +129,10 @@ #include #include -#include "ball16c.h" - - #define MAX_BALLS 1536 /* Number of balls to display */ #define OT_LEN 8 /* Ordering table length */ - /* Screen coordinates */ #define SCREEN_XRES 320 #define SCREEN_YRES 240 @@ -150,7 +146,7 @@ DISPENV disp[2]; DRAWENV draw[2]; char pribuff[2][65536]; /* Primitive packet buffers */ -u_long ot[2][OT_LEN]; /* Ordering tables */ +uint32_t ot[2][OT_LEN]; /* Ordering tables */ char *nextpri; /* Pointer to next packet buffer offset */ int db = 0; /* Double buffer index */ @@ -165,6 +161,8 @@ typedef struct BALL_TYPE BALL_TYPE balls[MAX_BALLS]; +/* Ball texture reference */ +extern const uint32_t ball16c[]; /* TIM image parameters for loading the ball texture and drawing sprites */ TIM_IMAGE tim; @@ -179,9 +177,9 @@ CdlLOC xa_loc; /* XA data start location /* Sector header structure for video sector terminator */ typedef struct SECTOR_HEAD { - u_short id; - u_short chan; - u_char pad[28]; + uint16_t id; + uint16_t chan; + uint8_t pad[28]; } SECTOR_HEAD; @@ -199,7 +197,7 @@ void xa_callback(int intr, unsigned char *result) if (intr == CdlDataReady) { /* Fetch data sector */ - CdGetSector((u_long*)&xa_sector_buff, 512); + CdGetSector(&xa_sector_buff, 512); /* Quirk: This CdGetSector() implementation must fetch 2048 bytes */ /* or more otherwise the following sectors will be read in an */ @@ -224,7 +222,7 @@ void xa_callback(int intr, unsigned char *result) num_loops++; /* Retry playback by seeking to start of XA data and stream */ - CdControlF(CdlReadS, (u_char*)&xa_loc); + CdControlF(CdlReadS, &xa_loc); /* Stop playback */ //CdControlF(CdlPause, 0); @@ -276,7 +274,7 @@ void init() /* Upload the ball texture */ - GetTimInfo((u_long*)ball16c, &tim); /* Get TIM parameters */ + GetTimInfo(ball16c, &tim); /* Get TIM parameters */ LoadImage(tim.prect, tim.paddr); /* Upload texture to VRAM */ if( tim.mode & 0x8 ) { @@ -355,7 +353,7 @@ int main(int argc, const char* argv[]) /* Set CD mode for XA streaming (2x speed, send XA to SPU, enable filter */ i = CdlModeSpeed|CdlModeRT|CdlModeSF; - CdControl(CdlSetmode, (u_char*)&i, 0); + CdControl(CdlSetmode, &i, 0); /* Set file 1 on filter for channels 0-7 */ filter.file = 1; @@ -410,8 +408,8 @@ int main(int argc, const char* argv[]) if( !p_cross ) { filter.chan = sel_channel; - CdControl(CdlSetfilter, (u_char*)&filter, 0); - CdControl(CdlReadS, (u_char*)&xa_loc, 0); + CdControl(CdlSetfilter, &filter, 0); + CdControl(CdlReadS, &xa_loc, 0); xa_play_channel = sel_channel; p_cross = 1; } @@ -441,7 +439,7 @@ int main(int argc, const char* argv[]) if( !p_right ) { filter.chan = sel_channel; - CdControl(CdlSetfilter, (u_char*)&filter, 0); + CdControl(CdlSetfilter, &filter, 0); xa_play_channel = sel_channel; p_right = 1; } diff --git a/examples/graphics/balls/CMakeLists.txt b/examples/graphics/balls/CMakeLists.txt index f5297c3..deee473 100644 --- a/examples/graphics/balls/CMakeLists.txt +++ b/examples/graphics/balls/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20) project( balls - LANGUAGES C + LANGUAGES C ASM VERSION 1.0.0 DESCRIPTION "PSn00bSDK sprites example" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" @@ -15,4 +15,6 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(balls STATIC ${_sources}) #psn00bsdk_add_cd_image(balls_iso balls iso.xml DEPENDS balls) +psn00bsdk_target_incbin(balls PRIVATE ball16c ball16c.tim) + install(FILES ${PROJECT_BINARY_DIR}/balls.exe TYPE BIN) diff --git a/examples/graphics/balls/ball16c.h b/examples/graphics/balls/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/graphics/balls/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/graphics/balls/main.c b/examples/graphics/balls/main.c index e429a4b..5af0bfb 100644 --- a/examples/graphics/balls/main.c +++ b/examples/graphics/balls/main.c @@ -18,14 +18,12 @@ * */ -#include +#include #include #include #include #include #include -#include "ball16c.h" - #define MAX_BALLS 1024 @@ -42,10 +40,10 @@ DISPENV disp; DRAWENV draw; -char pribuff[2][65536]; /* Primitive packet buffers */ -u_long ot[2][OT_LEN]; /* Ordering tables */ -char *nextpri; /* Pointer to next packet buffer offset */ -int db = 0; /* Double buffer index */ +char pribuff[2][65536]; /* Primitive packet buffers */ +uint32_t ot[2][OT_LEN]; /* Ordering tables */ +char *nextpri; /* Pointer to next packet buffer offset */ +int db = 0; /* Double buffer index */ /* Ball struct and array */ @@ -57,6 +55,8 @@ typedef struct { BALL_TYPE balls[MAX_BALLS]; +/* Ball texture reference */ +extern const uint32_t ball16c[]; /* TIM image parameters for loading the ball texture and drawing sprites */ TIM_IMAGE tim; @@ -96,7 +96,7 @@ void init() { /* Upload the ball texture */ printf("Upload texture... "); - GetTimInfo( (u_long*)ball16c, &tim ); /* Get TIM parameters */ + GetTimInfo( ball16c, &tim ); /* Get TIM parameters */ LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ if( tim.mode & 0x8 ) { diff --git a/examples/graphics/gte/main.c b/examples/graphics/gte/main.c index 1257c88..6907c84 100644 --- a/examples/graphics/gte/main.c +++ b/examples/graphics/gte/main.c @@ -117,7 +117,7 @@ MATRIX light_mtx = { /* Reference texture data */ -extern uint32_t tim_texture[]; +extern const uint32_t tim_texture[]; /* TPage and CLUT values */ uint16_t texture_tpage; /* For the scrolling blending pattern */ diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt index b781dea..7e91589 100644 --- a/examples/system/childexec/CMakeLists.txt +++ b/examples/system/childexec/CMakeLists.txt @@ -17,6 +17,7 @@ psn00bsdk_add_executable(parent STATIC ${_sources}) psn00bsdk_add_executable(child STATIC ${_child_sources}) #psn00bsdk_add_cd_image(childexec_iso childexec iso.xml DEPENDS parent) +psn00bsdk_target_incbin(parent PRIVATE ball16c ball16c.tim) psn00bsdk_target_incbin( parent PRIVATE child_exe ${PROJECT_BINARY_DIR}/child.exe diff --git a/examples/system/childexec/ball16c.h b/examples/system/childexec/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/system/childexec/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/system/childexec/ball16c.tim b/examples/system/childexec/ball16c.tim new file mode 100644 index 0000000..e2a5d17 Binary files /dev/null and b/examples/system/childexec/ball16c.tim differ diff --git a/examples/system/childexec/child/child.c b/examples/system/childexec/child/child.c index 2ddfa73..bd17440 100644 --- a/examples/system/childexec/child/child.c +++ b/examples/system/childexec/child/child.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -21,10 +21,10 @@ /* Double buffer structure */ typedef struct { - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ - u_long ot[OT_LEN]; /* Ordering table */ - char p[PACKET_LEN]; /* Packet buffer */ + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + uint32_t ot[OT_LEN]; /* Ordering table */ + char p[PACKET_LEN]; /* Packet buffer */ } DB; /* Double buffer variables */ diff --git a/examples/system/childexec/parent.c b/examples/system/childexec/parent.c index 58f03f7..3e7d218 100644 --- a/examples/system/childexec/parent.c +++ b/examples/system/childexec/parent.c @@ -20,7 +20,7 @@ * */ -#include +#include #include #include #include @@ -29,8 +29,6 @@ #include #include #include -#include "ball16c.h" - #define MAX_BALLS 1024 @@ -48,7 +46,7 @@ DISPENV disp; DRAWENV draw; char pribuff[2][65536]; /* Primitive packet buffers */ -u_long ot[2][OT_LEN]; /* Ordering tables */ +uint32_t ot[2][OT_LEN]; /* Ordering tables */ char *nextpri; /* Pointer to next packet buffer offset */ int db = 0; /* Double buffer index */ @@ -62,6 +60,8 @@ typedef struct { BALL_TYPE balls[MAX_BALLS]; +/* Ball texture reference */ +extern const uint32_t ball16c[]; /* TIM image parameters for loading the ball texture and drawing sprites */ TIM_IMAGE tim; @@ -103,7 +103,7 @@ void init() { /* Upload the ball texture */ printf("Upload texture... "); - GetTimInfo( (u_long*)ball16c, &tim ); /* Get TIM parameters */ + GetTimInfo( ball16c, &tim ); /* Get TIM parameters */ LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ if( tim.mode & 0x8 ) { diff --git a/examples/system/console/CMakeLists.txt b/examples/system/console/CMakeLists.txt index d58f212..eeb8e62 100644 --- a/examples/system/console/CMakeLists.txt +++ b/examples/system/console/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20) project( console - LANGUAGES C + LANGUAGES C ASM VERSION 1.0.0 DESCRIPTION "PSn00bSDK stdio console example" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" @@ -15,4 +15,6 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(console STATIC ${_sources}) #psn00bsdk_add_cd_image(console_iso console iso.xml DEPENDS console) +psn00bsdk_target_incbin(console PRIVATE ball16c ball16c.tim) + install(FILES ${PROJECT_BINARY_DIR}/console.exe TYPE BIN) diff --git a/examples/system/console/ball16c.h b/examples/system/console/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/system/console/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/system/console/ball16c.tim b/examples/system/console/ball16c.tim new file mode 100644 index 0000000..e2a5d17 Binary files /dev/null and b/examples/system/console/ball16c.tim differ diff --git a/examples/system/console/main.c b/examples/system/console/main.c index 92df0a8..b4f91b4 100644 --- a/examples/system/console/main.c +++ b/examples/system/console/main.c @@ -21,7 +21,7 @@ * */ -#include +#include #include #include #include @@ -32,8 +32,6 @@ #include #include #include -#include "ball16c.h" - #define MAX_BALLS 1024 @@ -50,10 +48,10 @@ DISPENV disp; DRAWENV draw; -char pribuff[2][65536]; /* Primitive packet buffers */ -u_long ot[2][OT_LEN]; /* Ordering tables */ -char *nextpri; /* Pointer to next packet buffer offset */ -int db = 0; /* Double buffer index */ +char pribuff[2][65536]; /* Primitive packet buffers */ +uint32_t ot[2][OT_LEN]; /* Ordering tables */ +char *nextpri; /* Pointer to next packet buffer offset */ +int db = 0; /* Double buffer index */ /* Ball struct and array */ @@ -65,6 +63,8 @@ typedef struct { BALL_TYPE balls[MAX_BALLS]; +/* Ball texture reference */ +extern const uint32_t ball16c[]; /* TIM image parameters for loading the ball texture and drawing sprites */ TIM_IMAGE tim; @@ -104,7 +104,7 @@ void init() { /* Upload the ball texture */ printf("Upload texture... "); - GetTimInfo( (u_long*)ball16c, &tim ); /* Get TIM parameters */ + GetTimInfo( ball16c, &tim ); /* Get TIM parameters */ LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ if( tim.mode & 0x8 ) { diff --git a/examples/system/dynlink/CMakeLists.txt b/examples/system/dynlink/CMakeLists.txt index aae3bb3..f5f4ea8 100644 --- a/examples/system/dynlink/CMakeLists.txt +++ b/examples/system/dynlink/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20) project( dynlink - LANGUAGES C + LANGUAGES C ASM VERSION 1.0.0 DESCRIPTION "PSn00bSDK dynamic linker example" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" @@ -20,6 +20,8 @@ psn00bsdk_add_cd_image( DEPENDS dynlink_main dynlink_cube dynlink_balls ) +psn00bsdk_target_incbin(dynlink_balls PRIVATE ball16c library/ball16c.tim) + install( FILES ${PROJECT_BINARY_DIR}/dynlink.bin diff --git a/examples/system/dynlink/library/ball16c.h b/examples/system/dynlink/library/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/system/dynlink/library/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/system/dynlink/library/ball16c.tim b/examples/system/dynlink/library/ball16c.tim new file mode 100644 index 0000000..e2a5d17 Binary files /dev/null and b/examples/system/dynlink/library/ball16c.tim differ diff --git a/examples/system/dynlink/library/balls.c b/examples/system/dynlink/library/balls.c index cfc7f58..c537167 100644 --- a/examples/system/dynlink/library/balls.c +++ b/examples/system/dynlink/library/balls.c @@ -12,7 +12,8 @@ #include #include "dll_common.h" -#include "ball16c.h" + +extern const uint32_t ball16c[]; /* Balls data */ @@ -38,7 +39,7 @@ static BALL_TYPE balls[MAX_BALLS]; static TIM_IMAGE ball_tim; void init(CONTEXT *ctx) { - GetTimInfo((const uint32_t *) ball16c, &ball_tim); + GetTimInfo(ball16c, &ball_tim); LoadImage(ball_tim.prect, ball_tim.paddr); if (ball_tim.mode & 8) -- cgit v1.2.3 From 86f0064afb8200e60dd80827535cac30d0eab028 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Thu, 22 Sep 2022 21:36:29 +0200 Subject: Update version number, clean up old headers --- CHANGELOG.md | 10 ++ CMakeLists.txt | 2 +- examples/demos/n00bdemo/smd.s | 4 +- examples/demos/n00bdemo/smd_cel.s | 4 +- examples/demos/n00bdemo/smd_flat.s | 4 +- libpsn00b/include/ctype.h | 23 +++- libpsn00b/include/gtereg.h | 81 ------------- libpsn00b/include/gtereg.inc | 81 +++++++++++++ libpsn00b/include/hwregs_a.h | 150 ------------------------ libpsn00b/include/hwregs_a.inc | 150 ++++++++++++++++++++++++ libpsn00b/include/inline_s.h | 230 ------------------------------------- libpsn00b/include/inline_s.inc | 230 +++++++++++++++++++++++++++++++++++++ libpsn00b/include/string.h | 20 +--- libpsn00b/include/strings.h | 23 ++-- libpsn00b/psxapi/_initcd.s | 2 +- libpsn00b/psxcd/_cd_control.s | 2 +- libpsn00b/psxcd/cdgetsector.s | 2 +- libpsn00b/psxcd/cdmix.s | 2 +- libpsn00b/psxcd/psxcd_asm.s | 2 +- libpsn00b/psxgpu/readme.txt | 1 - libpsn00b/psxgte/applymatrixlv.s | 4 +- libpsn00b/psxgte/compmatrixlv.s | 4 +- libpsn00b/psxgte/initgeom.s | 2 +- libpsn00b/psxgte/mulmatrix.s | 4 +- libpsn00b/psxgte/mulmatrix0.s | 4 +- libpsn00b/psxgte/pushpopmatrix.s | 4 +- libpsn00b/psxgte/readme.txt | 4 +- libpsn00b/psxgte/scalematrix.s | 4 +- libpsn00b/psxgte/scalematrixl.s | 4 +- libpsn00b/psxgte/square0.s | 4 +- libpsn00b/psxgte/squareroot.s | 4 +- libpsn00b/psxgte/vectornormals.s | 4 +- libpsn00b/psxsio/_sio_control.s | 2 +- 33 files changed, 541 insertions(+), 530 deletions(-) delete mode 100644 libpsn00b/include/gtereg.h create mode 100644 libpsn00b/include/gtereg.inc delete mode 100644 libpsn00b/include/hwregs_a.h create mode 100644 libpsn00b/include/hwregs_a.inc delete mode 100644 libpsn00b/include/inline_s.h create mode 100644 libpsn00b/include/inline_s.inc (limited to 'examples') diff --git a/CHANGELOG.md b/CHANGELOG.md index b477b54..f7f4f93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,16 @@ to ensure the changelog can be parsed correctly. ------------------------------------------------------------------------------- +## 2022-09-22 + +spicyjpeg: + +- libpsn00b: Changed the extension of `gtereg.h`, `hwregs_a.h` and `inline_s.h` + to `.inc`. Cleaned up old leftover PSXSDK headers. + +- Updated documentation and added detailed instructions on how to install + prebuilt releases. + ## 2022-08-21: 0.20 spicyjpeg: diff --git a/CMakeLists.txt b/CMakeLists.txt index 181375c..4f255a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ include(ExternalProject) project( PSn00bSDK LANGUAGES NONE - VERSION 0.19 + VERSION 0.20 DESCRIPTION "Open source PlayStation 1 SDK" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" ) diff --git a/examples/demos/n00bdemo/smd.s b/examples/demos/n00bdemo/smd.s index f9cf2fe..d25f760 100644 --- a/examples/demos/n00bdemo/smd.s +++ b/examples/demos/n00bdemo/smd.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .include "smd_s.h" diff --git a/examples/demos/n00bdemo/smd_cel.s b/examples/demos/n00bdemo/smd_cel.s index ece0dd8..383f043 100644 --- a/examples/demos/n00bdemo/smd_cel.s +++ b/examples/demos/n00bdemo/smd_cel.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .include "smd_s.h" diff --git a/examples/demos/n00bdemo/smd_flat.s b/examples/demos/n00bdemo/smd_flat.s index 0d48c63..4b47be4 100644 --- a/examples/demos/n00bdemo/smd_flat.s +++ b/examples/demos/n00bdemo/smd_flat.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .include "smd_s.h" diff --git a/libpsn00b/include/ctype.h b/libpsn00b/include/ctype.h index b79498a..24ee9d9 100644 --- a/libpsn00b/include/ctype.h +++ b/libpsn00b/include/ctype.h @@ -1,7 +1,20 @@ -#ifndef _CTYPE_H -#define _CTYPE_H +/* + * PSn00bSDK standard library + * (C) 2019-2022 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed + */ -extern int tolower(int chr); -extern int toupper(int chr); +#ifndef __CTYPE_H +#define __CTYPE_H -#endif \ No newline at end of file +#ifdef __cplusplus +extern "C" { +#endif + +int tolower(int chr); +int toupper(int chr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libpsn00b/include/gtereg.h b/libpsn00b/include/gtereg.h deleted file mode 100644 index 0d051fc..0000000 --- a/libpsn00b/include/gtereg.h +++ /dev/null @@ -1,81 +0,0 @@ -# GTE register definitions for GNU assembler (as). -# -# Part of the PSn00bSDK Project by Lameguy64. -# 2019 Meido-Tek Productions - -# -# GTE data registers (use mfc2, mtc2, lwc2, swc2) -# -.set C2_VXY0, $0 -.set C2_VZ0, $1 -.set C2_VXY1, $2 -.set C2_VZ1, $3 -.set C2_VXY2, $4 -.set C2_VZ2, $5 -.set C2_RGB, $6 -.set C2_OTZ, $7 - -.set C2_IR0, $8 -.set C2_IR1, $9 -.set C2_IR2, $10 -.set C2_IR3, $11 -.set C2_SXY0, $12 -.set C2_SXY1, $13 -.set C2_SXY2, $14 -.set C2_SXYP, $15 - -.set C2_SZ0, $16 -.set C2_SZ1, $17 -.set C2_SZ2, $18 -.set C2_SZ3, $19 -.set C2_RGB0, $20 -.set C2_RGB1, $21 -.set C2_RGB2, $22 - -.set C2_MAC0, $24 -.set C2_MAC1, $25 -.set C2_MAC2, $26 -.set C2_MAC3, $27 -.set C2_IRGB, $28 -.set C2_ORGB, $29 -.set C2_LZCS, $30 -.set C2_LZCR, $31 - -# -# GTE control registers (use cfc2/ctc2) -# -.set C2_R11R12, $0 -.set C2_R13R21, $1 -.set C2_R22R23, $2 -.set C2_R31R32, $3 -.set C2_R33, $4 -.set C2_TRX, $5 -.set C2_TRY, $6 -.set C2_TRZ, $7 - -.set C2_L11L12, $8 -.set C2_L13L21, $9 -.set C2_L22L23, $10 -.set C2_L31L32, $11 -.set C2_L33, $12 -.set C2_RBK, $13 -.set C2_GBK, $14 -.set C2_BBK, $15 - -.set C2_LR1LR2, $16 -.set C2_LR3LG1, $17 -.set C2_LG2LG3, $18 -.set C2_LB1LB2, $19 -.set C2_LB3, $20 -.set C2_RFC, $21 -.set C2_GFC, $22 -.set C2_BFC, $23 - -.set C2_OFX, $24 -.set C2_OFY, $25 -.set C2_H, $26 -.set C2_DQA, $27 -.set C2_DQB, $28 -.set C2_ZSF3, $29 -.set C2_ZSF4, $30 -.set C2_FLAG, $31 diff --git a/libpsn00b/include/gtereg.inc b/libpsn00b/include/gtereg.inc new file mode 100644 index 0000000..0d051fc --- /dev/null +++ b/libpsn00b/include/gtereg.inc @@ -0,0 +1,81 @@ +# GTE register definitions for GNU assembler (as). +# +# Part of the PSn00bSDK Project by Lameguy64. +# 2019 Meido-Tek Productions + +# +# GTE data registers (use mfc2, mtc2, lwc2, swc2) +# +.set C2_VXY0, $0 +.set C2_VZ0, $1 +.set C2_VXY1, $2 +.set C2_VZ1, $3 +.set C2_VXY2, $4 +.set C2_VZ2, $5 +.set C2_RGB, $6 +.set C2_OTZ, $7 + +.set C2_IR0, $8 +.set C2_IR1, $9 +.set C2_IR2, $10 +.set C2_IR3, $11 +.set C2_SXY0, $12 +.set C2_SXY1, $13 +.set C2_SXY2, $14 +.set C2_SXYP, $15 + +.set C2_SZ0, $16 +.set C2_SZ1, $17 +.set C2_SZ2, $18 +.set C2_SZ3, $19 +.set C2_RGB0, $20 +.set C2_RGB1, $21 +.set C2_RGB2, $22 + +.set C2_MAC0, $24 +.set C2_MAC1, $25 +.set C2_MAC2, $26 +.set C2_MAC3, $27 +.set C2_IRGB, $28 +.set C2_ORGB, $29 +.set C2_LZCS, $30 +.set C2_LZCR, $31 + +# +# GTE control registers (use cfc2/ctc2) +# +.set C2_R11R12, $0 +.set C2_R13R21, $1 +.set C2_R22R23, $2 +.set C2_R31R32, $3 +.set C2_R33, $4 +.set C2_TRX, $5 +.set C2_TRY, $6 +.set C2_TRZ, $7 + +.set C2_L11L12, $8 +.set C2_L13L21, $9 +.set C2_L22L23, $10 +.set C2_L31L32, $11 +.set C2_L33, $12 +.set C2_RBK, $13 +.set C2_GBK, $14 +.set C2_BBK, $15 + +.set C2_LR1LR2, $16 +.set C2_LR3LG1, $17 +.set C2_LG2LG3, $18 +.set C2_LB1LB2, $19 +.set C2_LB3, $20 +.set C2_RFC, $21 +.set C2_GFC, $22 +.set C2_BFC, $23 + +.set C2_OFX, $24 +.set C2_OFY, $25 +.set C2_H, $26 +.set C2_DQA, $27 +.set C2_DQB, $28 +.set C2_ZSF3, $29 +.set C2_ZSF4, $30 +.set C2_FLAG, $31 diff --git a/libpsn00b/include/hwregs_a.h b/libpsn00b/include/hwregs_a.h deleted file mode 100644 index c78b41a..0000000 --- a/libpsn00b/include/hwregs_a.h +++ /dev/null @@ -1,150 +0,0 @@ -# PSn00bSDK hardware registers definitions -# (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed - -## Constants - -.set IOBASE, 0x1f80 -.set F_CPU, 33868800 -.set F_GPU, 53222400 - -## GPU - -.set GPU_GP0, 0x1810 # Also GPUREAD -.set GPU_GP1, 0x1814 # Also GPUSTAT - -## CD drive - -.set CD_STAT, 0x1800 -.set CD_CMD, 0x1801 # Also response FIFO -.set CD_DATA, 0x1802 # Also parameters -.set CD_IRQ, 0x1803 - -.set CD_REG0, 0x1800 -.set CD_REG1, 0x1801 -.set CD_REG2, 0x1802 -.set CD_REG3, 0x1803 - -## SPU - -.set SPU_VOICE_BASE, 0x1c00 - -.set SPU_MASTER_VOL_L, 0x1d80 -.set SPU_MASTER_VOL_R, 0x1d82 -.set SPU_REVERB_VOL_L, 0x1d84 -.set SPU_REVERB_VOL_R, 0x1d86 -.set SPU_KEY_ON, 0x1d88 -.set SPU_KEY_OFF, 0x1d8c -.set SPU_FM_MODE, 0x1d90 -.set SPU_NOISE_MODE, 0x1d94 -.set SPU_REVERB_ON, 0x1d98 -.set SPU_CHAN_STATUS, 0x1d9c - -.set SPU_REVERB_ADDR, 0x1da2 -.set SPU_IRQ_ADDR, 0x1da4 -.set SPU_ADDR, 0x1da6 -.set SPU_DATA, 0x1da8 - -.set SPU_CTRL, 0x1daa -.set SPU_DMA_CTRL, 0x1dac -.set SPU_STAT, 0x1dae - -.set SPU_CD_VOL_L, 0x1db0 -.set SPU_CD_VOL_R, 0x1db2 -.set SPU_EXT_VOL_L, 0x1db4 -.set SPU_EXT_VOL_R, 0x1db6 -.set SPU_CURRENT_VOL_L, 0x1db8 -.set SPU_CURRENT_VOL_R, 0x1dba - -.set SPU_VOICE_VOL_L, 0x00 -.set SPU_VOICE_VOL_R, 0x02 -.set SPU_VOICE_FREQ, 0x04 -.set SPU_VOICE_ADDR, 0x06 -.set SPU_VOICE_ADSR_L, 0x08 -.set SPU_VOICE_ADSR_H, 0x0a -.set SPU_VOICE_LOOP, 0x0e - -## MDEC - -.set MDEC0, 0x1820 -.set MDEC1, 0x1824 - -## SPI controller port - -.set JOY_TXRX, 0x1040 -.set JOY_STAT, 0x1044 -.set JOY_MODE, 0x1048 -.set JOY_CTRL, 0x104a -.set JOY_BAUD, 0x104e - -## Serial port - -.set SIO_TXRX, 0x1050 -.set SIO_STAT, 0x1054 -.set SIO_MODE, 0x1058 -.set SIO_CTRL, 0x105a -.set SIO_BAUD, 0x105e - -## IRQ controller - -.set IRQ_STAT, 0x1070 -.set IRQ_MASK, 0x1074 - -## DMA - -.set DMA_DPCR, 0x10f0 -.set DMA_DICR, 0x10f4 - -.set DMA0_MADR, 0x1080 -.set DMA0_BCR, 0x1084 -.set DMA0_CHCR, 0x1088 - -.set DMA1_MADR, 0x1090 -.set DMA1_BCR, 0x1094 -.set DMA1_CHCR, 0x1098 - -.set DMA2_MADR, 0x10a0 -.set DMA2_BCR, 0x10a4 -.set DMA2_CHCR, 0x10a8 - -.set DMA3_MADR, 0x10b0 -.set DMA3_BCR, 0x10b4 -.set DMA3_CHCR, 0x10b8 - -.set DMA4_MADR, 0x10c0 -.set DMA4_BCR, 0x10c4 -.set DMA4_CHCR, 0x10c8 - -.set DMA5_MADR, 0x10d0 -.set DMA5_BCR, 0x10d4 -.set DMA5_CHCR, 0x10d8 - -.set DMA6_MADR, 0x10e0 -.set DMA6_BCR, 0x10e4 -.set DMA6_CHCR, 0x10e8 - -## Timers - -.set TIMER0_VALUE, 0x1100 -.set TIMER0_CTRL, 0x1104 -.set TIMER0_RELOAD, 0x1108 - -.set TIMER1_VALUE, 0x1110 -.set TIMER1_CTRL, 0x1114 -.set TIMER1_RELOAD, 0x1118 - -.set TIMER2_VALUE, 0x1120 -.set TIMER2_CTRL, 0x1124 -.set TIMER2_RELOAD, 0x1128 - -## Memory control - -.set EXP1_ADDR, 0x1000 -.set EXP2_ADDR, 0x1004 -.set EXP1_DELAY_SIZE, 0x1008 -.set EXP3_DELAY_SIZE, 0x100c -.set BIOS_DELAY_SIZE, 0x1010 -.set SPU_DELAY_SIZE, 0x1014 -.set CD_DELAY_SIZE, 0x1018 -.set EXP2_DELAY_SIZE, 0x101c -.set COM_DELAY_CFG, 0x1020 -.set RAM_SIZE_CFG, 0x1060 diff --git a/libpsn00b/include/hwregs_a.inc b/libpsn00b/include/hwregs_a.inc new file mode 100644 index 0000000..c78b41a --- /dev/null +++ b/libpsn00b/include/hwregs_a.inc @@ -0,0 +1,150 @@ +# PSn00bSDK hardware registers definitions +# (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed + +## Constants + +.set IOBASE, 0x1f80 +.set F_CPU, 33868800 +.set F_GPU, 53222400 + +## GPU + +.set GPU_GP0, 0x1810 # Also GPUREAD +.set GPU_GP1, 0x1814 # Also GPUSTAT + +## CD drive + +.set CD_STAT, 0x1800 +.set CD_CMD, 0x1801 # Also response FIFO +.set CD_DATA, 0x1802 # Also parameters +.set CD_IRQ, 0x1803 + +.set CD_REG0, 0x1800 +.set CD_REG1, 0x1801 +.set CD_REG2, 0x1802 +.set CD_REG3, 0x1803 + +## SPU + +.set SPU_VOICE_BASE, 0x1c00 + +.set SPU_MASTER_VOL_L, 0x1d80 +.set SPU_MASTER_VOL_R, 0x1d82 +.set SPU_REVERB_VOL_L, 0x1d84 +.set SPU_REVERB_VOL_R, 0x1d86 +.set SPU_KEY_ON, 0x1d88 +.set SPU_KEY_OFF, 0x1d8c +.set SPU_FM_MODE, 0x1d90 +.set SPU_NOISE_MODE, 0x1d94 +.set SPU_REVERB_ON, 0x1d98 +.set SPU_CHAN_STATUS, 0x1d9c + +.set SPU_REVERB_ADDR, 0x1da2 +.set SPU_IRQ_ADDR, 0x1da4 +.set SPU_ADDR, 0x1da6 +.set SPU_DATA, 0x1da8 + +.set SPU_CTRL, 0x1daa +.set SPU_DMA_CTRL, 0x1dac +.set SPU_STAT, 0x1dae + +.set SPU_CD_VOL_L, 0x1db0 +.set SPU_CD_VOL_R, 0x1db2 +.set SPU_EXT_VOL_L, 0x1db4 +.set SPU_EXT_VOL_R, 0x1db6 +.set SPU_CURRENT_VOL_L, 0x1db8 +.set SPU_CURRENT_VOL_R, 0x1dba + +.set SPU_VOICE_VOL_L, 0x00 +.set SPU_VOICE_VOL_R, 0x02 +.set SPU_VOICE_FREQ, 0x04 +.set SPU_VOICE_ADDR, 0x06 +.set SPU_VOICE_ADSR_L, 0x08 +.set SPU_VOICE_ADSR_H, 0x0a +.set SPU_VOICE_LOOP, 0x0e + +## MDEC + +.set MDEC0, 0x1820 +.set MDEC1, 0x1824 + +## SPI controller port + +.set JOY_TXRX, 0x1040 +.set JOY_STAT, 0x1044 +.set JOY_MODE, 0x1048 +.set JOY_CTRL, 0x104a +.set JOY_BAUD, 0x104e + +## Serial port + +.set SIO_TXRX, 0x1050 +.set SIO_STAT, 0x1054 +.set SIO_MODE, 0x1058 +.set SIO_CTRL, 0x105a +.set SIO_BAUD, 0x105e + +## IRQ controller + +.set IRQ_STAT, 0x1070 +.set IRQ_MASK, 0x1074 + +## DMA + +.set DMA_DPCR, 0x10f0 +.set DMA_DICR, 0x10f4 + +.set DMA0_MADR, 0x1080 +.set DMA0_BCR, 0x1084 +.set DMA0_CHCR, 0x1088 + +.set DMA1_MADR, 0x1090 +.set DMA1_BCR, 0x1094 +.set DMA1_CHCR, 0x1098 + +.set DMA2_MADR, 0x10a0 +.set DMA2_BCR, 0x10a4 +.set DMA2_CHCR, 0x10a8 + +.set DMA3_MADR, 0x10b0 +.set DMA3_BCR, 0x10b4 +.set DMA3_CHCR, 0x10b8 + +.set DMA4_MADR, 0x10c0 +.set DMA4_BCR, 0x10c4 +.set DMA4_CHCR, 0x10c8 + +.set DMA5_MADR, 0x10d0 +.set DMA5_BCR, 0x10d4 +.set DMA5_CHCR, 0x10d8 + +.set DMA6_MADR, 0x10e0 +.set DMA6_BCR, 0x10e4 +.set DMA6_CHCR, 0x10e8 + +## Timers + +.set TIMER0_VALUE, 0x1100 +.set TIMER0_CTRL, 0x1104 +.set TIMER0_RELOAD, 0x1108 + +.set TIMER1_VALUE, 0x1110 +.set TIMER1_CTRL, 0x1114 +.set TIMER1_RELOAD, 0x1118 + +.set TIMER2_VALUE, 0x1120 +.set TIMER2_CTRL, 0x1124 +.set TIMER2_RELOAD, 0x1128 + +## Memory control + +.set EXP1_ADDR, 0x1000 +.set EXP2_ADDR, 0x1004 +.set EXP1_DELAY_SIZE, 0x1008 +.set EXP3_DELAY_SIZE, 0x100c +.set BIOS_DELAY_SIZE, 0x1010 +.set SPU_DELAY_SIZE, 0x1014 +.set CD_DELAY_SIZE, 0x1018 +.set EXP2_DELAY_SIZE, 0x101c +.set COM_DELAY_CFG, 0x1020 +.set RAM_SIZE_CFG, 0x1060 diff --git a/libpsn00b/include/inline_s.h b/libpsn00b/include/inline_s.h deleted file mode 100644 index 68e0d07..0000000 --- a/libpsn00b/include/inline_s.h +++ /dev/null @@ -1,230 +0,0 @@ -# Inline GTE macros for GNU assembler (as). -# -# Part of the PSn00bSDK Project by Lameguy64. -# 2019 Meido-Tek Productions -# -# Similar to inline_c.h, it does not require running your object file -# through some silly tool. - -.macro nRTPS - nop - nop - cop2 0x0180001 -.endm - -.macro nRTPT - nop - nop - cop2 0x0280030 -.endm - -.macro nNCLIP - nop - nop - cop2 0x1400006 -.endm - -.macro nAVSZ3 - nop - nop - cop2 0x158002D -.endm - -.macro nAVSZ4 - nop - nop - cop2 0x168002E -.endm - -.macro nMVMVA sf mx v cv lm - nop - nop - cop2 0x0400012|(\sf<<19)|(\mx<<17)|(\v<<15)|(\cv<<13)|(\lm<<10) -.endm - -.macro nSQR sf - nop - nop - cop2 0x0A00428|(\sf<<19) -.endm - -.macro nnOP sf lm # extra n to prevent conflict with the nop opcode - nop - nop - cop2 0x170000C|(\sf<<19)|(\lm<<10) -.endm - -.macro nNCS - nop - nop - cop2 0x0C8041E -.endm - -.macro nNCT - nop - nop - cop2 0x0D80420 -.endm - -.macro nNCCS - nop - nop - cop2 0x108041B -.endm - -.macro nNCCT - nop - nop - cop2 0x118043F -.endm - -.macro nNCDS - nop - nop - cop2 0x0E80413 -.endm - -.macro nNCDT - nop - nop - cop2 0x0F80416 -.endm - -.macro nCC - nop - nop - cop2 0x138041C -.endm - -.macro nCDP - nop - nop - cop2 0x1280414 -.endm - -.macro nDCPL - nop - nop - cop2 0x0680029 -.endm - -.macro nDPCS - nop - nop - cop2 0x0780010 -.endm - -.macro nDPCT - nop - nop - cop2 0x0180001 -.endm - -.macro nINTPL - nop - nop - cop2 0x0980011 -.endm - -.macro nGPF sf - nop - nop - cop2 0x190003D|(\sf<<19) -.endm - -.macro nGPL sf - nop - nop - cop2 0x1A0003E|(\sf<<19) -.endm - -# -# Macros without leading nops (for optimized usage) -# -.macro RTPS - cop2 0x0180001 -.endm - -.macro RTPT - cop2 0x0280030 -.endm - -.macro NCLIP - cop2 0x1400006 -.endm - -.macro AVSZ3 - cop2 0x158002D -.endm - -.macro AVSZ4 - cop2 0x168002E -.endm - -.macro MVMVA sf mx v cv lm - cop2 0x0400012|(\sf<<19)|(\mx<<17)|(\v<<15)|(\cv<<13)|(\lm<<10) -.endm - -.macro SQR sf - cop2 0x0A00428|(\sf<<19) -.endm - -.macro OP sf lm - cop2 0x170000C|(\sf<<19)|(\lm<<10) -.endm - -.macro NCS - cop2 0x0C8041E -.endm - -.macro NCT - cop2 0x0D80420 -.endm - -.macro NCCS - cop2 0x108041B -.endm - -.macro NCCT - cop2 0x118043F -.endm - -.macro NCDS - cop2 0x0E80413 -.endm - -.macro NCDT - cop2 0x0F80416 -.endm - -.macro CC - cop2 0x138041C -.endm - -.macro CDP - cop2 0x1280414 -.endm - -.macro DCPL - cop2 0x0680029 -.endm - -.macro DPCS - cop2 0x0780010 -.endm - -.macro DPCT - cop2 0x0180001 -.endm - -.macro INTPL - cop2 0x0980011 -.endm - -.macro GPF sf - cop2 0x190003D|(\sf<<19) -.endm - -.macro GPL sf - cop2 0x1A0003E|(\sf<<19) -.endm diff --git a/libpsn00b/include/inline_s.inc b/libpsn00b/include/inline_s.inc new file mode 100644 index 0000000..68e0d07 --- /dev/null +++ b/libpsn00b/include/inline_s.inc @@ -0,0 +1,230 @@ +# Inline GTE macros for GNU assembler (as). +# +# Part of the PSn00bSDK Project by Lameguy64. +# 2019 Meido-Tek Productions +# +# Similar to inline_c.h, it does not require running your object file +# through some silly tool. + +.macro nRTPS + nop + nop + cop2 0x0180001 +.endm + +.macro nRTPT + nop + nop + cop2 0x0280030 +.endm + +.macro nNCLIP + nop + nop + cop2 0x1400006 +.endm + +.macro nAVSZ3 + nop + nop + cop2 0x158002D +.endm + +.macro nAVSZ4 + nop + nop + cop2 0x168002E +.endm + +.macro nMVMVA sf mx v cv lm + nop + nop + cop2 0x0400012|(\sf<<19)|(\mx<<17)|(\v<<15)|(\cv<<13)|(\lm<<10) +.endm + +.macro nSQR sf + nop + nop + cop2 0x0A00428|(\sf<<19) +.endm + +.macro nnOP sf lm # extra n to prevent conflict with the nop opcode + nop + nop + cop2 0x170000C|(\sf<<19)|(\lm<<10) +.endm + +.macro nNCS + nop + nop + cop2 0x0C8041E +.endm + +.macro nNCT + nop + nop + cop2 0x0D80420 +.endm + +.macro nNCCS + nop + nop + cop2 0x108041B +.endm + +.macro nNCCT + nop + nop + cop2 0x118043F +.endm + +.macro nNCDS + nop + nop + cop2 0x0E80413 +.endm + +.macro nNCDT + nop + nop + cop2 0x0F80416 +.endm + +.macro nCC + nop + nop + cop2 0x138041C +.endm + +.macro nCDP + nop + nop + cop2 0x1280414 +.endm + +.macro nDCPL + nop + nop + cop2 0x0680029 +.endm + +.macro nDPCS + nop + nop + cop2 0x0780010 +.endm + +.macro nDPCT + nop + nop + cop2 0x0180001 +.endm + +.macro nINTPL + nop + nop + cop2 0x0980011 +.endm + +.macro nGPF sf + nop + nop + cop2 0x190003D|(\sf<<19) +.endm + +.macro nGPL sf + nop + nop + cop2 0x1A0003E|(\sf<<19) +.endm + +# +# Macros without leading nops (for optimized usage) +# +.macro RTPS + cop2 0x0180001 +.endm + +.macro RTPT + cop2 0x0280030 +.endm + +.macro NCLIP + cop2 0x1400006 +.endm + +.macro AVSZ3 + cop2 0x158002D +.endm + +.macro AVSZ4 + cop2 0x168002E +.endm + +.macro MVMVA sf mx v cv lm + cop2 0x0400012|(\sf<<19)|(\mx<<17)|(\v<<15)|(\cv<<13)|(\lm<<10) +.endm + +.macro SQR sf + cop2 0x0A00428|(\sf<<19) +.endm + +.macro OP sf lm + cop2 0x170000C|(\sf<<19)|(\lm<<10) +.endm + +.macro NCS + cop2 0x0C8041E +.endm + +.macro NCT + cop2 0x0D80420 +.endm + +.macro NCCS + cop2 0x108041B +.endm + +.macro NCCT + cop2 0x118043F +.endm + +.macro NCDS + cop2 0x0E80413 +.endm + +.macro NCDT + cop2 0x0F80416 +.endm + +.macro CC + cop2 0x138041C +.endm + +.macro CDP + cop2 0x1280414 +.endm + +.macro DCPL + cop2 0x0680029 +.endm + +.macro DPCS + cop2 0x0780010 +.endm + +.macro DPCT + cop2 0x0180001 +.endm + +.macro INTPL + cop2 0x0980011 +.endm + +.macro GPF sf + cop2 0x190003D|(\sf<<19) +.endm + +.macro GPL sf + cop2 0x1A0003E|(\sf<<19) +.endm diff --git a/libpsn00b/include/string.h b/libpsn00b/include/string.h index 365d238..ceee066 100644 --- a/libpsn00b/include/string.h +++ b/libpsn00b/include/string.h @@ -1,13 +1,10 @@ /* - * string.h - * - * Prototypes for string functions of the C library - * - * PSXSDK + * PSn00bSDK standard library + * (C) 2019-2022 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed */ -#ifndef _STRING_H -#define _STRING_H +#ifndef __STRING_H +#define __STRING_H #ifdef __cplusplus extern "C" { @@ -19,11 +16,6 @@ char *strpbrk(const char *dst , const char *src); char *strtok(char *s , char *set); char *strstr(const char *big , const char *little); -//int strspn(char *s , char *set); -//int strcspn(char *s , char *set); -//int index(char *s , int c); -//int rindex(char *s , int c); - char *strcat(char *s , const char *append); char *strncat(char *s , const char *append, int n); char *strcpy(char *dst , const char *src); @@ -34,9 +26,6 @@ char *strrchr(const char *s , int c); void *memmove(void *dst , const void *src , int n); void *memchr(void *s , int c , int n); - -// Functions converted to ASM - void *memcpy(void *dst , const void *src , int n); void *memset(void *dst , char c , int n); int memcmp(const void *b1 , const void *b2 , int n); @@ -46,4 +35,3 @@ int memcmp(const void *b1 , const void *b2 , int n); #endif #endif - diff --git a/libpsn00b/include/strings.h b/libpsn00b/include/strings.h index e5e88d4..7223ab9 100644 --- a/libpsn00b/include/strings.h +++ b/libpsn00b/include/strings.h @@ -1,18 +1,19 @@ -/* - * strings.h - * - * PSXSDK +/* + * PSn00bSDK standard library + * (C) 2019-2022 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed */ -#ifndef _STRINGS_H -#define _STRINGS_H +#ifndef __STRINGS_H +#define __STRINGS_H #include -#define bcopy(src,dst,len) memmove(dst,src,len) -#define bzero(ptr, len) memset(ptr, 0, len) -#define bcmp(b1,b2,len) memcmp(b1,b2,len) -#define index(s, c) strchr(s, c) -#define rindex(s, c) strrchr(s, c) +/* Compatibility macros (this header is useless) */ + +#define bcopy(src, dst, len) memmove(dst, src, len) +#define bzero(ptr, len) memset(ptr, 0, len) +#define bcmp(b1, b2, len) memcmp(b1, b2, len) +#define index(s, c) strchr(s, c) +#define rindex(s, c) strrchr(s, c) #endif diff --git a/libpsn00b/psxapi/_initcd.s b/libpsn00b/psxapi/_initcd.s index c3a2861..600d686 100644 --- a/libpsn00b/psxapi/_initcd.s +++ b/libpsn00b/psxapi/_initcd.s @@ -1,7 +1,7 @@ .section .text .set noreorder -.include "hwregs_a.h" +.include "hwregs_a.inc" .global _InitCd .type _InitCd, @function diff --git a/libpsn00b/psxcd/_cd_control.s b/libpsn00b/psxcd/_cd_control.s index c4153ff..5fa336a 100644 --- a/libpsn00b/psxcd/_cd_control.s +++ b/libpsn00b/psxcd/_cd_control.s @@ -1,6 +1,6 @@ .set noreorder -.include "hwregs_a.h" +.include "hwregs_a.inc" .section .text diff --git a/libpsn00b/psxcd/cdgetsector.s b/libpsn00b/psxcd/cdgetsector.s index 9f38e7a..6a29069 100644 --- a/libpsn00b/psxcd/cdgetsector.s +++ b/libpsn00b/psxcd/cdgetsector.s @@ -1,6 +1,6 @@ .set noreorder -.include "hwregs_a.h" +.include "hwregs_a.inc" .section .text diff --git a/libpsn00b/psxcd/cdmix.s b/libpsn00b/psxcd/cdmix.s index 745fb65..40cd181 100644 --- a/libpsn00b/psxcd/cdmix.s +++ b/libpsn00b/psxcd/cdmix.s @@ -1,6 +1,6 @@ .set noreorder -.include "hwregs_a.h" +.include "hwregs_a.inc" .section .text diff --git a/libpsn00b/psxcd/psxcd_asm.s b/libpsn00b/psxcd/psxcd_asm.s index 129bc89..906ab32 100644 --- a/libpsn00b/psxcd/psxcd_asm.s +++ b/libpsn00b/psxcd/psxcd_asm.s @@ -1,6 +1,6 @@ .set noreorder -.include "hwregs_a.h" +.include "hwregs_a.inc" .section .text diff --git a/libpsn00b/psxgpu/readme.txt b/libpsn00b/psxgpu/readme.txt index 2963b6a..67aa110 100644 --- a/libpsn00b/psxgpu/readme.txt +++ b/libpsn00b/psxgpu/readme.txt @@ -17,5 +17,4 @@ Library developer(s): Library header(s): - hwregs_a.h (GNU assembler port defs) psxgpu.h diff --git a/libpsn00b/psxgte/applymatrixlv.s b/libpsn00b/psxgte/applymatrixlv.s index 332a2f8..3180d0f 100644 --- a/libpsn00b/psxgte/applymatrixlv.s +++ b/libpsn00b/psxgte/applymatrixlv.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .section .text diff --git a/libpsn00b/psxgte/compmatrixlv.s b/libpsn00b/psxgte/compmatrixlv.s index 95da5e9..2908eb9 100644 --- a/libpsn00b/psxgte/compmatrixlv.s +++ b/libpsn00b/psxgte/compmatrixlv.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .set MATRIX_r11r12, 0 .set MATRIX_r13r21, 4 diff --git a/libpsn00b/psxgte/initgeom.s b/libpsn00b/psxgte/initgeom.s index 14ca293..d004ecc 100644 --- a/libpsn00b/psxgte/initgeom.s +++ b/libpsn00b/psxgte/initgeom.s @@ -1,6 +1,6 @@ .set noreorder -.include "gtereg.h" +.include "gtereg.inc" .section .text diff --git a/libpsn00b/psxgte/mulmatrix.s b/libpsn00b/psxgte/mulmatrix.s index 19dabe8..08c79c2 100644 --- a/libpsn00b/psxgte/mulmatrix.s +++ b/libpsn00b/psxgte/mulmatrix.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .section .text diff --git a/libpsn00b/psxgte/mulmatrix0.s b/libpsn00b/psxgte/mulmatrix0.s index 874226b..c2fd859 100644 --- a/libpsn00b/psxgte/mulmatrix0.s +++ b/libpsn00b/psxgte/mulmatrix0.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .section .text diff --git a/libpsn00b/psxgte/pushpopmatrix.s b/libpsn00b/psxgte/pushpopmatrix.s index d10687a..ca6b992 100644 --- a/libpsn00b/psxgte/pushpopmatrix.s +++ b/libpsn00b/psxgte/pushpopmatrix.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .section .text diff --git a/libpsn00b/psxgte/readme.txt b/libpsn00b/psxgte/readme.txt index 13067ee..3242474 100644 --- a/libpsn00b/psxgte/readme.txt +++ b/libpsn00b/psxgte/readme.txt @@ -21,9 +21,9 @@ Library developer(s): Library header(s): - gtereg.h + gtereg.inc inline_c.h - inline_s.h + inline_s.inc psxgte.h diff --git a/libpsn00b/psxgte/scalematrix.s b/libpsn00b/psxgte/scalematrix.s index 3e83800..1b2b6dd 100644 --- a/libpsn00b/psxgte/scalematrix.s +++ b/libpsn00b/psxgte/scalematrix.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .section .text diff --git a/libpsn00b/psxgte/scalematrixl.s b/libpsn00b/psxgte/scalematrixl.s index 014b85a..53c2d14 100644 --- a/libpsn00b/psxgte/scalematrixl.s +++ b/libpsn00b/psxgte/scalematrixl.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .section .text diff --git a/libpsn00b/psxgte/square0.s b/libpsn00b/psxgte/square0.s index d037b7e..a8ca107 100644 --- a/libpsn00b/psxgte/square0.s +++ b/libpsn00b/psxgte/square0.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .section .text diff --git a/libpsn00b/psxgte/squareroot.s b/libpsn00b/psxgte/squareroot.s index a038e18..72198b4 100644 --- a/libpsn00b/psxgte/squareroot.s +++ b/libpsn00b/psxgte/squareroot.s @@ -1,7 +1,7 @@ .set noreorder -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .section .text diff --git a/libpsn00b/psxgte/vectornormals.s b/libpsn00b/psxgte/vectornormals.s index 939c4d1..85e94e6 100644 --- a/libpsn00b/psxgte/vectornormals.s +++ b/libpsn00b/psxgte/vectornormals.s @@ -1,8 +1,8 @@ .set noreorder .set noat -.include "gtereg.h" -.include "inline_s.h" +.include "gtereg.inc" +.include "inline_s.inc" .section .text diff --git a/libpsn00b/psxsio/_sio_control.s b/libpsn00b/psxsio/_sio_control.s index bf3b9b9..6378def 100644 --- a/libpsn00b/psxsio/_sio_control.s +++ b/libpsn00b/psxsio/_sio_control.s @@ -1,6 +1,6 @@ .set noreorder -.include "hwregs_a.h" +.include "hwregs_a.inc" .section .text -- cgit v1.2.3