diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-08-10 22:49:49 +0200 |
|---|---|---|
| committer | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-08-10 22:49:49 +0200 |
| commit | a1081f296bca4f718cf31e5b6a262661d132e9e4 (patch) | |
| tree | ee979fe0120fed803d0c63ca824dbff3921dadc6 | |
| parent | ce33eee403c678d3e2850046955f265585af76d7 (diff) | |
| download | psn00bsdk-a1081f296bca4f718cf31e5b6a262661d132e9e4.tar.gz | |
Misc. fixes, add texturing to graphics/gte example
| -rw-r--r-- | examples/graphics/gte/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | examples/graphics/gte/main.c | 51 | ||||
| -rw-r--r-- | examples/graphics/gte/texture.tim | bin | 0 -> 16928 bytes | |||
| -rw-r--r-- | libpsn00b/cmake/sdk.cmake | 2 | ||||
| -rw-r--r-- | libpsn00b/include/psxspu.h | 2 | ||||
| -rw-r--r-- | libpsn00b/psxgpu/common.c | 9 | ||||
| -rw-r--r-- | libpsn00b/psxspu/common.c | 4 |
7 files changed, 50 insertions, 22 deletions
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 <sys/types.h> +#include <stdint.h> #include <stdio.h> #include <psxgpu.h> #include <psxgte.h> @@ -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; i<CUBE_FACES; i++ ) { @@ -192,7 +201,7 @@ int main() { continue; /* Initialize a quad primitive */ - setPolyF4( pol4 ); + setPolyFT4( pol4 ); /* Set the projected vertices to the primitive */ gte_stsxy0( &pol4->x0 ); @@ -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 Binary files differnew file mode 100644 index 0000000..54ce2f0 --- /dev/null +++ b/examples/graphics/gte/texture.tim 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) { |
