diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2023-05-11 23:42:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-11 23:42:43 +0200 |
| commit | 04d7728350cbd04dd86cd894e906c98673e3f9a7 (patch) | |
| tree | 08e8c7dd495d1c4c6fcf5f7ba6b4b10693dc42f6 /examples | |
| parent | eaec942f56ceec9c14de5c4185a02602abadd50a (diff) | |
| parent | 58a8306d24fe29d965aa8b40ddc37c3163c0a2f9 (diff) | |
| download | psn00bsdk-04d7728350cbd04dd86cd894e906c98673e3f9a7.tar.gz | |
Merge pull request #70 from Lameguy64/v0.23-wip
Header cleanups, PCDRV, more safety checks, libc and mkpsxiso fixes (v0.23)
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/beginner/cppdemo/main.cpp | 274 | ||||
| -rw-r--r-- | examples/cdrom/cdbrowse/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | examples/cdrom/cdbrowse/iso.xml | 5 | ||||
| -rw-r--r-- | examples/cdrom/cdxa/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | examples/cdrom/cdxa/iso.xml | 5 | ||||
| -rw-r--r-- | examples/demos/n00bdemo/main.c | 43 | ||||
| -rw-r--r-- | examples/graphics/billboard/billboard.c | 2 | ||||
| -rw-r--r-- | examples/io/system573/iso.xml | 13 | ||||
| -rw-r--r-- | examples/mdec/strvideo/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | examples/mdec/strvideo/iso.xml | 5 | ||||
| -rw-r--r-- | examples/mdec/strvideo/main.c | 93 | ||||
| -rw-r--r-- | examples/sound/cdstream/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | examples/sound/cdstream/iso.xml | 5 | ||||
| -rw-r--r-- | examples/sound/cdstream/main.c | 2 | ||||
| -rw-r--r-- | examples/system/childexec/child/child.c | 8 | ||||
| -rw-r--r-- | examples/system/childexec/parent.c | 24 | ||||
| -rw-r--r-- | examples/system/console/main.c | 2 | ||||
| -rw-r--r-- | examples/system/dynlink/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | examples/system/dynlink/iso.xml | 5 |
19 files changed, 254 insertions, 255 deletions
diff --git a/examples/beginner/cppdemo/main.cpp b/examples/beginner/cppdemo/main.cpp index fd2e3a8..f55f952 100644 --- a/examples/beginner/cppdemo/main.cpp +++ b/examples/beginner/cppdemo/main.cpp @@ -1,157 +1,151 @@ -/* Work in progress example, need to add comments. +/* Work in progress example, need to add comments. * * Basically a quick little example that showcases C++ classes are * functioning in PSn00bSDK. - Lameguy64 * - * First written in December 18, 2020. + * First written in December 18, 2020. * * Changelog: * - * May 10, 2021 - Variable types updated for psxgpu.h changes. + * May 11, 2023 - Updated the example to use C++ standard library headers, + * renamed the class and cleaned up some methods. + * May 10, 2021 - Variable types updated for psxgpu.h changes. * */ - -#include <sys/types.h> -#include <stdio.h> -#include <stdlib.h> + +#include <cstddef> +#include <cstdint> +#include <cstdio> +#include <cstdlib> #include <psxgte.h> #include <psxgpu.h> -class GraphClass -{ - u_long *_ot[2]; - u_char *_pri[2]; - u_char *_nextpri; +/* Example class */ + +class RenderContext { +private: + std::uint32_t *_ot[2]; + std::uint8_t *_pri[2]; + std::uint8_t *_nextpri; + + int _ot_count, _db; - int _ot_count; - int _db; - - DISPENV _disp[2]; + DISPENV _disp[2]; DRAWENV _draw[2]; - + public: + RenderContext(std::size_t ot_len = 8, std::size_t pri_len = 8192); + ~RenderContext(void); + void setupBuffers(int w, int h, int r, int g, int b); + void flip(void); + + template<typename T> inline T *addPrimitive(void) { + auto pri = reinterpret_cast<T *>(_nextpri); + addPrim(_ot[_db], pri); + + _nextpri += sizeof(T); + return pri; + } +}; + +RenderContext::RenderContext(std::size_t ot_len, std::size_t pri_len) { + _ot[0] = new std::uint32_t[ot_len]; + _ot[1] = new std::uint32_t[ot_len]; + + _db = 0; + _ot_count = ot_len; + ClearOTagR(_ot[0], _ot_count); + ClearOTagR(_ot[1], _ot_count); + + _pri[0] = new std::uint8_t[pri_len]; + _pri[1] = new std::uint8_t[pri_len]; + + _nextpri = _pri[0]; + + std::printf("RenderContext::RenderContext: Buffers allocated.\n"); +} + +RenderContext::~RenderContext(void) { + delete[] _ot[0]; + delete[] _ot[1]; + + delete[] _pri[0]; + delete[] _pri[1]; + + std::printf("RenderContext::RenderContext: Buffers freed.\n"); +} + +void RenderContext::setupBuffers(int w, int h, int r, int g, int b) { + SetDefDispEnv(&_disp[0], 0, h, w, h); + SetDefDispEnv(&_disp[1], 0, 0, w, h); + SetDefDrawEnv(&_draw[0], 0, 0, w, h); + SetDefDrawEnv(&_draw[1], 0, h, w, h); + + setRGB0(&_draw[0], r, g, b); + _draw[0].isbg = 1; + _draw[0].dtd = 1; - GraphClass( int ot_len = 8, int pri_len = 8192 ) - { - _ot[0] = (u_long*)malloc( sizeof(u_long)*ot_len ); - _ot[1] = (u_long*)malloc( sizeof(u_long)*ot_len ); - - _db = 0; - _ot_count = ot_len; - ClearOTagR( _ot[0], _ot_count ); - ClearOTagR( _ot[1], _ot_count ); - - _pri[0] = (u_char*)malloc( pri_len ); - _pri[1] = (u_char*)malloc( pri_len ); - - _nextpri = _pri[0]; - - printf( "GraphClass::GraphClass: Buffers allocated.\n" ); - - } /* GraphClass */ - - virtual ~GraphClass() - { - /* free the OTs and primitive buffers */ - free( _ot[0] ); - free( _ot[1] ); - - free( _pri[0] ); - free( _pri[1] ); - - printf( "GraphClass::GraphClass: Buffers freed.\n" ); - - } /* ~GraphClass */ - - void SetRes( int w, int h ) - { - SetDefDispEnv( &_disp[0], 0, h, w, h ); - SetDefDispEnv( &_disp[1], 0, 0, w, h ); - - SetDefDrawEnv( &_draw[0], 0, 0, w, h ); - SetDefDrawEnv( &_draw[1], 0, h, w, h ); - - setRGB0( &_draw[0], 63, 0, 127 ); - _draw[0].isbg = 1; - _draw[0].dtd = 1; - setRGB0( &_draw[1], 63, 0, 127 ); - _draw[1].isbg = 1; - _draw[1].dtd = 1; - - PutDispEnv( &_disp[0] ); - PutDrawEnv( &_draw[0] ); - - } /* SetRes */ - - void IncPri( int bytes ) - { - _nextpri += bytes; - - } /* IncPri */ - - void SetPri( u_char *ptr ) - { - _nextpri = ptr; - - } /* SetPri */ - - u_char *GetNextPri( void ) - { - return( _nextpri ); - - } /* GetNextPri */ - - u_long *GetOt( void ) - { - return( _ot[_db] ); - - } /* GetOt */ - - void Display( void ) - { - VSync( 0 ); - DrawSync( 0 ); - SetDispMask( 1 ); - - _db = !_db; - - PutDispEnv( &_disp[_db] ); - PutDrawEnv( &_draw[_db] ); - - DrawOTag( _ot[!_db]+(_ot_count-1) ); - - ClearOTagR( _ot[_db], _ot_count ); - _nextpri = _pri[_db]; - - } /* Display */ - -}; /* GraphClass */ - -GraphClass *otable; - -int main( int argc, const char *argv[] ) -{ - TILE *tile; - - ResetGraph( 0 ); - - otable = new GraphClass(); - - otable->SetRes( 320, 240 ); - - while( 1 ) - { - tile = (TILE*)otable->GetNextPri(); - setTile( tile ); - setXY0( tile, 32, 32 ); - setWH( tile, 128, 128 ); - setRGB0( tile, 255, 255, 0 ); - addPrim( otable->GetOt(), tile ); - otable->IncPri( sizeof(TILE) ); - - otable->Display(); + setRGB0(&_draw[1], r, g, b); + _draw[1].isbg = 1; + _draw[1].dtd = 1; + + PutDispEnv(&_disp[0]); + PutDrawEnv(&_draw[0]); +} + +void RenderContext::flip(void) { + DrawSync(0); + VSync(0); + + _db ^= 1; + + PutDispEnv(&_disp[_db]); + PutDrawEnv(&_draw[_db]); + + DrawOTag(_ot[_db ^ 1] + _ot_count - 1); + ClearOTagR(_ot[_db], _ot_count); + + _nextpri = _pri[_db]; +} + +/* Main */ + +static constexpr int SCREEN_XRES = 320; +static constexpr int SCREEN_YRES = 240; + +static constexpr int BGCOLOR_R = 63; +static constexpr int BGCOLOR_G = 0; +static constexpr int BGCOLOR_B = 127; + +int main(int argc, const char **argv) { + ResetGraph(0); + SetDispMask(1); + + RenderContext ctx; + ctx.setupBuffers(SCREEN_XRES, SCREEN_YRES, BGCOLOR_R, BGCOLOR_G, BGCOLOR_B); + + int x = 0, y = 0; + int dx = 1, dy = 1; + + for (;;) { + // Update the position and velocity of the bouncing square. + if (x < 0 || x > (SCREEN_XRES - 64)) + dx = -dx; + if (y < 0 || y > (SCREEN_YRES - 64)) + dy = -dy; + + x += dx; + y += dy; + + // Draw the square. + auto tile = ctx.addPrimitive<TILE>(); + setTile(tile); + setXY0 (tile, x, y); + setWH (tile, 64, 64); + setRGB0(tile, 255, 255, 0); + + ctx.flip(); } - - return( 0 ); - -} /* main */
\ No newline at end of file + + return 0; +} diff --git a/examples/cdrom/cdbrowse/CMakeLists.txt b/examples/cdrom/cdbrowse/CMakeLists.txt index 0cc091f..70a4585 100644 --- a/examples/cdrom/cdbrowse/CMakeLists.txt +++ b/examples/cdrom/cdbrowse/CMakeLists.txt @@ -13,7 +13,10 @@ project( file(GLOB _sources *.c) psn00bsdk_add_executable(cdbrowse GPREL ${_sources}) -psn00bsdk_add_cd_image(cdbrowse_iso cdbrowse iso.xml DEPENDS cdbrowse) +psn00bsdk_add_cd_image( + cdbrowse_iso cdbrowse iso.xml + DEPENDS cdbrowse system.cnf +) psn00bsdk_target_incbin(cdbrowse PRIVATE ball16c ball16c.tim) diff --git a/examples/cdrom/cdbrowse/iso.xml b/examples/cdrom/cdbrowse/iso.xml index 771b0e9..f1c00f7 100644 --- a/examples/cdrom/cdbrowse/iso.xml +++ b/examples/cdrom/cdbrowse/iso.xml @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<iso_project - image_name="${CD_IMAGE_NAME}.bin" - cue_sheet="${CD_IMAGE_NAME}.cue" -> +<iso_project> <track type="data"> <identifiers system ="PLAYSTATION" diff --git a/examples/cdrom/cdxa/CMakeLists.txt b/examples/cdrom/cdxa/CMakeLists.txt index fd2f653..07e6ae4 100644 --- a/examples/cdrom/cdxa/CMakeLists.txt +++ b/examples/cdrom/cdxa/CMakeLists.txt @@ -11,10 +11,12 @@ project( HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" ) -# TODO: add rules to actually generate a valid .XA file file(GLOB _sources *.c) psn00bsdk_add_executable(cdxa GPREL ${_sources}) -#psn00bsdk_add_cd_image(cdxa_iso cdxa iso.xml DEPENDS cdxa) +#psn00bsdk_add_cd_image( + #cdxa_iso cdxa iso.xml + #DEPENDS cdxa system.cnf xasample.xa +#) psn00bsdk_target_incbin(cdxa PRIVATE ball16c ball16c.tim) diff --git a/examples/cdrom/cdxa/iso.xml b/examples/cdrom/cdxa/iso.xml index 6715f94..f935d26 100644 --- a/examples/cdrom/cdxa/iso.xml +++ b/examples/cdrom/cdxa/iso.xml @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<iso_project - image_name="${CD_IMAGE_NAME}.bin" - cue_sheet="${CD_IMAGE_NAME}.cue" -> +<iso_project> <track type="data"> <identifiers system ="PLAYSTATION" diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c index 6d0be3c..55dbbc4 100644 --- a/examples/demos/n00bdemo/main.c +++ b/examples/demos/n00bdemo/main.c @@ -358,10 +358,9 @@ void stencilstuff() { /* The stencil demo is achieved by utilizing the mask bit setting primitive GP0(E6h). The structure of this primitive is defined as - DR_MASK initialized and set by setDrawMask(). These are not available - in Sony's SDK by default. + DR_STP initialized and set by setDrawStp(). - The DR_MASK primitive controls mask bit operations for drawing + The DR_STP primitive controls mask bit operations for drawing primitives such as setting mask bits on every pixel drawn or mask bit test where pixels won't be drawn on pixels with the mask bit set. It applies to most graphics drawing primitives except VRAM fill. @@ -373,10 +372,10 @@ void stencilstuff() { bit operation disabled. The stencil effect featured in this demo is achieved by enabling set - mask bit with DR_MASK, drawing semi-transparent primitives using + mask bit with DR_STP, drawing semi-transparent primitives using additive blending but color is all zero to make it completely invisible but is enough to update the mask bits, disable mask set bit but enable - mask test with DR_MASK and then drawing a rectangle that fills the + mask test with DR_STP and then drawing a rectangle that fills the entire screen. Semi-transparency mask in textures must not be used when drawing the scene that will be 'below' the mask layer. */ @@ -384,7 +383,7 @@ void stencilstuff() { int spin=0; - DR_MASK *mask; + DR_STP *mask; TILE *rect; SC_OT s_ot; @@ -430,10 +429,10 @@ void stencilstuff() { // Sort mask primitive that enables setting mask bits - mask = (DR_MASK*)nextpri; - setDrawMask( mask, 1, 0 ); + mask = (DR_STP*)nextpri; + setDrawStp( mask, 1, 0 ); addPrim( ot[db]+20, mask ); - nextpri += sizeof(DR_MASK); + nextpri += sizeof(DR_STP); // Sort the stars @@ -465,10 +464,10 @@ void stencilstuff() { // Sort mask primitive that enables mask bit test - mask = (DR_MASK*)nextpri; - setDrawMask( mask, 0, 1 ); + mask = (DR_STP*)nextpri; + setDrawStp( mask, 0, 1 ); addPrim( ot[db]+18, mask ); - nextpri += sizeof(DR_MASK); + nextpri += sizeof(DR_STP); // Sort rectangle that fills the screen @@ -482,10 +481,10 @@ void stencilstuff() { // Clear all mask settings - mask = (DR_MASK*)nextpri; - setDrawMask( mask, 0, 0 ); + mask = (DR_STP*)nextpri; + setDrawStp( mask, 0, 0 ); addPrim( ot[db]+15, mask ); - nextpri += sizeof(DR_MASK); + nextpri += sizeof(DR_STP); // Sort overlay then display @@ -624,7 +623,7 @@ void plasmastuff() { // Simple stripe transition effect void transition() { - int i,count,comp; + int count = 0; int bheight[16] = { 0 }; TILE *tile = (TILE*)nextpri; @@ -632,9 +631,9 @@ void transition() { while( 1 ) { - comp = 0; + int comp = 0; - for( i=0; i<16; i++ ) { + for( int i=0; i<16; i++ ) { if( bheight[i] > 0 ) { @@ -657,19 +656,11 @@ void transition() { if( bheight[count>>1] == 0 ) bheight[count>>1] = 1; - display(); count++; if( comp >= 16 ) break; - - /* - I haven't yet managed to figure out why this loop hangs on no$psx - if I comment out this completely useless call to puts(). Some - alignment or timing crap perhaps? -- spicyjpeg - */ - puts("."); } DrawSync(0); diff --git a/examples/graphics/billboard/billboard.c b/examples/graphics/billboard/billboard.c index ea98b28..1ddc4dc 100644 --- a/examples/graphics/billboard/billboard.c +++ b/examples/graphics/billboard/billboard.c @@ -152,7 +152,7 @@ int main() { setRGB0(quad, 128, 128, 128); // Set tpage - quad->tpage = getTPage(tim.mode&0x8, 0, tim.prect->x, tim.prect->y); + quad->tpage = getTPage(tim.mode, 0, tim.prect->x, tim.prect->y); // Set CLUT setClut(quad, tim.crect->x, tim.crect->y); diff --git a/examples/io/system573/iso.xml b/examples/io/system573/iso.xml index 2226089..d22665c 100644 --- a/examples/io/system573/iso.xml +++ b/examples/io/system573/iso.xml @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<iso_project - image_name="${CD_IMAGE_NAME}.bin" - cue_sheet="${CD_IMAGE_NAME}.cue" -> +<iso_project> <track type="data"> <identifiers system ="PLAYSTATION" @@ -19,9 +16,9 @@ The System 573 BIOS does not parse SYSTEM.CNF, it's instead hardcoded to look for an executable named PSX.EXE. Some modded or hacked BIOS variants may instead look for slightly altered - file names (QSY.DXD, SSW.BXF, TSV.AXG) as an obfuscation - measure, so it's recommended to have multiple copies of the - executable on the disc. + file names (QSY.DXD, SSW.BXF, TSV.AXG, GSE.NXX, NSE.GXX) as an + obfuscation measure, so it's recommended to have multiple + copies of the executable on the disc. Note that this behavior can be abused to make multi-system CDs with different executables for PS1 and 573 (i.e. have both @@ -33,6 +30,8 @@ <file name="QSY.DXD" type="data" source="system573.exe" /> <file name="SSW.BXF" type="data" source="system573.exe" /> <file name="TSV.AXG" type="data" source="system573.exe" /> + <file name="GSE.NXX" type="data" source="system573.exe" /> + <file name="NSE.GXX" type="data" source="system573.exe" /> <dummy sectors="1024"/> </directory_tree> diff --git a/examples/mdec/strvideo/CMakeLists.txt b/examples/mdec/strvideo/CMakeLists.txt index d41556b..f6695c0 100644 --- a/examples/mdec/strvideo/CMakeLists.txt +++ b/examples/mdec/strvideo/CMakeLists.txt @@ -13,7 +13,10 @@ project( file(GLOB _sources *.c) psn00bsdk_add_executable(strvideo GPREL ${_sources}) -#psn00bsdk_add_cd_image(strvideo_iso strvideo iso.xml DEPENDS strvideo) +#psn00bsdk_add_cd_image( + #strvideo_iso strvideo iso.xml + #DEPENDS strvideo system.cnf video.str +#) install( FILES diff --git a/examples/mdec/strvideo/iso.xml b/examples/mdec/strvideo/iso.xml index 65e0ff5..8ba67dd 100644 --- a/examples/mdec/strvideo/iso.xml +++ b/examples/mdec/strvideo/iso.xml @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<iso_project - image_name="${CD_IMAGE_NAME}.bin" - cue_sheet="${CD_IMAGE_NAME}.cue" -> +<iso_project> <track type="data"> <identifiers system ="PLAYSTATION" diff --git a/examples/mdec/strvideo/main.c b/examples/mdec/strvideo/main.c index 28d39b2..853e0c2 100644 --- a/examples/mdec/strvideo/main.c +++ b/examples/mdec/strvideo/main.c @@ -1,6 +1,6 @@ /* * PSn00bSDK .STR FMV playback example - * (C) 2022 spicyjpeg - MPL licensed + * (C) 2022-2023 spicyjpeg - MPL licensed * * This example demonstrates playback of full-motion video in the standard .STR * format, using the MDEC for frame decoding and XA for audio. Decoded frames @@ -34,9 +34,10 @@ * Playback is stopped once the .STR header is no longer present in sectors * read. * - * Note that PSn00bSDK's bitstream decoding API only supports version 1 and 2 - * bitstreams currently, so make sure your .STR files are encoded as v2 and not - * v3. + * PSn00bSDK's bitstream decoding API supports both version 2 and 3 bitstreams. + * Encoding your .STR files as v3 may result in slightly higher quality + * depending on the encoder, but also higher CPU usage during playback compared + * to the older v2. */ #include <stdint.h> @@ -102,13 +103,12 @@ void init_context(RenderContext *ctx) { FntOpen(4, 12, 312, 16, 2, 256); } -void display(RenderContext *ctx, int sync) { +void display(RenderContext *ctx) { Framebuffer *db; ctx->db_active ^= 1; DrawSync(0); - if (sync) - VSync(0); + //VSync(0); db = &(ctx->db[ctx->db_active]); PutDrawEnv(&(db->draw)); @@ -163,13 +163,13 @@ typedef struct { volatile int8_t cur_frame, cur_slice; } StreamContext; -StreamContext str_ctx; +static StreamContext str_ctx; // This buffer is used by cd_sector_handler() as a temporary area for sectors // read from the CD. Due to DMA limitations it can't be allocated on the stack // (especially not in the interrupt callbacks' stack, whose size is very // limited). -STR_Header sector_header; +static STR_Header sector_header; void cd_sector_handler(void) { StreamBuffer *frame = &str_ctx.frames[str_ctx.cur_frame]; @@ -189,8 +189,15 @@ void cd_sector_handler(void) { return; // If this sector is actually part of a new frame, validate the sectors - // that have been read so far and flip the bitstream data buffers. - if (sector_header.frame_id != str_ctx.frame_id) { + // that have been read so far and flip the bitstream data buffers. If the + // frame number is actually lower than the current one, assume the drive + // has started reading another .STR file and stop playback. + if ((int) sector_header.frame_id < str_ctx.frame_id) { + str_ctx.frame_ready = -1; + return; + } + + if ((int) sector_header.frame_id > str_ctx.frame_id) { // Do not set the ready flag if any sector has been missed. if (str_ctx.sector_count) str_ctx.dropped_frames++; @@ -263,12 +270,10 @@ void init_stream(void) { CdReadyCallback(&cd_event_handler); ExitCriticalSection(); - // Set the maximum amount of data DecDCTvlc() can output and copy the - // lookup table used for decompression to the scratchpad area. This is - // optional but makes the decompressor slightly faster. See the libpsxpress - // documentation for more details. - DecDCTvlcSize(0x8000); - DecDCTvlcCopyTable((DECDCTTAB *) 0x1f800000); + // Copy the lookup table used for frame decompression to the scratchpad + // area. This is optional but makes the decompressor slightly faster. See + // the libpsxpress documentation for more details. + DecDCTvlcCopyTableV3((VLC_TableV3 *) 0x1f800000); str_ctx.cur_frame = 0; str_ctx.cur_slice = 0; @@ -309,7 +314,7 @@ void start_stream(CdlFILE *file) { static RenderContext ctx; -#define SHOW_STATUS(...) { FntPrint(-1, __VA_ARGS__); FntFlush(-1); display(&ctx, 1); } +#define SHOW_STATUS(...) { FntPrint(-1, __VA_ARGS__); FntFlush(-1); display(&ctx); } #define SHOW_ERROR(...) { SHOW_STATUS(__VA_ARGS__); while (1) __asm__("nop"); } int main(int argc, const char* argv[]) { @@ -318,7 +323,7 @@ int main(int argc, const char* argv[]) { SHOW_STATUS("INITIALIZING\n"); SpuInit(); CdInit(); - InitGeom(); // Required for PSn00bSDK's DecDCTvlc() + InitGeom(); // GTE initialization required by the VLC decompressor DecDCTReset(0); SHOW_STATUS("OPENING VIDEO FILE\n"); @@ -330,8 +335,9 @@ int main(int argc, const char* argv[]) { init_stream(); start_stream(&file); - // Disable framebuffer clearing to get rid of flickering during playback. - display(&ctx, 1); + // Clear the screen, then disable framebuffer clearing to get rid of + // flickering during playback. + display(&ctx); ctx.db[0].draw.isbg = 0; ctx.db[1].draw.isbg = 0; #ifdef DISP_24BPP @@ -339,9 +345,13 @@ int main(int argc, const char* argv[]) { ctx.db[1].disp.isrgb24 = 1; #endif - int decode_errors = 0; + int frame_time = 1, decode_errors = 0; while (1) { +#ifdef DRAW_OVERLAY + int frame_start = TIMER_VALUE(1); +#endif + // Wait for a full frame to be read from the disc and decompress the // bitstream into the format expected by the MDEC. If the video has // ended, restart playback from the beginning. @@ -355,38 +365,45 @@ int main(int argc, const char* argv[]) { } #ifdef DRAW_OVERLAY - // Measure CPU usage of the decompressor using the hblank counter. - int total_time = TIMER_VALUE(1) + 1; - TIMER_VALUE(1) = 0; + int decode_time = TIMER_VALUE(1); #endif - if (DecDCTvlc(frame->bs_data, frame->mdec_data)) { + VLC_Context vlc_ctx; + if (DecDCTvlcStart( + &vlc_ctx, + frame->mdec_data, + sizeof(frame->mdec_data) / 4, + frame->bs_data + )) { decode_errors++; continue; } #ifdef DRAW_OVERLAY - int cpu_usage = TIMER_VALUE(1) * 100 / total_time; + // Calculate CPU usage of the decompressor. + decode_time = (TIMER_VALUE(1) - decode_time) & 0xffff; + int cpu_usage = decode_time * 100 / frame_time; #endif // Wait for the MDEC to finish decoding the previous frame, then flip // the framebuffers to display it and prepare the buffer for the next // frame. - // NOTE: you should *not* call VSync(0) during playback, as the refresh - // rate of the GPU is not synced to the video's frame rate. If you want - // to minimize screen tearing, consider triple buffering instead (i.e. - // always keep 2 fully decoded frames in VRAM and use VSyncCallback() - // to register a function that displays the next decoded frame whenever - // vblank occurs). + // NOTE: as the refresh rate of the GPU is not synced to the video's + // frame rate, this VSync(0) call may potentially end up waiting too + // long and desynchronizing playback. A better solution would be to + // implement triple buffering (i.e. always keep 2 fully decoded frames + // in VRAM and use VSyncCallback() to register a function that displays + // the next decoded frame if available whenever vblank occurs). + VSync(0); DecDCTinSync(0); DecDCToutSync(0); #ifdef DRAW_OVERLAY - FntPrint(-1, "FRAME:%5d READ ERRORS: %5d\n", str_ctx.frame_id, str_ctx.dropped_frames); - FntPrint(-1, "CPU: %5d%% DECODE ERRORS:%5d\n", cpu_usage, decode_errors); + FntPrint(-1, "FRAME:%6d READ ERRORS: %6d\n", str_ctx.frame_id, str_ctx.dropped_frames); + FntPrint(-1, "CPU: %6d%% DECODE ERRORS:%6d\n", cpu_usage, decode_errors); FntFlush(-1); #endif - display(&ctx, 0); + display(&ctx); // Feed the newly decompressed frame to the MDEC. The MDEC will not // actually start decoding it until an output buffer is also configured @@ -414,6 +431,10 @@ int main(int argc, const char* argv[]) { str_ctx.slices[str_ctx.cur_slice], BLOCK_SIZE * str_ctx.slice_pos.h / 2 ); + +#ifdef DRAW_OVERLAY + frame_time = (TIMER_VALUE(1) - frame_start) & 0xffff; +#endif } return 0; diff --git a/examples/sound/cdstream/CMakeLists.txt b/examples/sound/cdstream/CMakeLists.txt index e569449..d04761c 100644 --- a/examples/sound/cdstream/CMakeLists.txt +++ b/examples/sound/cdstream/CMakeLists.txt @@ -13,7 +13,10 @@ project( file(GLOB _sources *.c) psn00bsdk_add_executable(cdstream GPREL ${_sources}) -psn00bsdk_add_cd_image(cdstream_iso cdstream iso.xml DEPENDS cdstream) +psn00bsdk_add_cd_image( + cdstream_iso cdstream iso.xml + DEPENDS cdstream system.cnf stream.vag +) install( FILES diff --git a/examples/sound/cdstream/iso.xml b/examples/sound/cdstream/iso.xml index 66f1f74..10128eb 100644 --- a/examples/sound/cdstream/iso.xml +++ b/examples/sound/cdstream/iso.xml @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<iso_project - image_name="${CD_IMAGE_NAME}.bin" - cue_sheet="${CD_IMAGE_NAME}.cue" -> +<iso_project> <track type="data"> <identifiers system ="PLAYSTATION" diff --git a/examples/sound/cdstream/main.c b/examples/sound/cdstream/main.c index 324abb2..53b88e6 100644 --- a/examples/sound/cdstream/main.c +++ b/examples/sound/cdstream/main.c @@ -212,7 +212,7 @@ void spu_irq_handler(void) { // if str_ctx.state is set to STATE_DATA_NEEDED and fetch the next chunk. } -void cd_read_handler(int event, uint8_t *payload) { +void cd_read_handler(CdlIntrResult event, uint8_t *payload) { // Attempt to read the chunk again if an error has occurred, otherwise // start uploading it to SPU RAM. if (event == CdlDiskError) { diff --git a/examples/system/childexec/child/child.c b/examples/system/childexec/child/child.c index dcfbfaf..e5e16b9 100644 --- a/examples/system/childexec/child/child.c +++ b/examples/system/childexec/child/child.c @@ -1,5 +1,6 @@ #include <stdint.h> #include <stdio.h> +#include <psxetc.h> #include <psxapi.h> #include <psxgpu.h> #include <psxgte.h> @@ -238,11 +239,12 @@ int main(int argc, const char *argv[]) { display(); } - + + DrawSync(0); StopPAD(); - + StopCallback(); + return 0; - } void init(void) { diff --git a/examples/system/childexec/parent.c b/examples/system/childexec/parent.c index 83d964c..cfed11c 100644 --- a/examples/system/childexec/parent.c +++ b/examples/system/childexec/parent.c @@ -273,7 +273,7 @@ extern char child_exe[]; void run_child(void) { // Arguments for the child program - char *args[] = + const char *args[] = { "SAMPLE=0", "SESSION=1", @@ -285,31 +285,27 @@ void run_child(void) { // Copy child executable to its intended adddress memcpy((void*)exe->param.t_addr, child_exe+2048, exe->param.t_size); - - // Prepare for program execution and disable interrupts - //EnterCriticalSection(); - StopCallback(); - // Stop pads, enable auto acknowledge + // Prepare for program execution and disable interrupts + DrawSync(0); StopPAD(); - ChangeClearPAD(1); - ChangeClearRCnt(3, 1); + StopCallback(); + FlushCache(); // Execute child - printf("Child exec!\n"); + printf("Executing child...\n"); Exec(&exe->param, 3, args); - + // Restore interrupts for this PS-EXE RestartCallback(); - //ExitCriticalSection(); - + printf("Child returned\n"); + // Re-init and re-enable pads InitPAD(pad_buff[0], 34, pad_buff[1], 34); StartPAD(); ChangeClearPAD(0); - + // Set this program's display mode SetDispMask(0); PutDispEnv(&disp); - } diff --git a/examples/system/console/main.c b/examples/system/console/main.c index b4f91b4..845ca95 100644 --- a/examples/system/console/main.c +++ b/examples/system/console/main.c @@ -25,7 +25,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ioctl.h> +#include <sys/ioctl.h> #include <sys/fcntl.h> #include <psxapi.h> #include <psxetc.h> diff --git a/examples/system/dynlink/CMakeLists.txt b/examples/system/dynlink/CMakeLists.txt index e750fd1..a1fd24e 100644 --- a/examples/system/dynlink/CMakeLists.txt +++ b/examples/system/dynlink/CMakeLists.txt @@ -17,7 +17,7 @@ psn00bsdk_add_library (dynlink_cube SHARED library/cube.c) psn00bsdk_add_library (dynlink_balls SHARED library/balls.c) psn00bsdk_add_cd_image( dynlink_iso dynlink iso.xml - DEPENDS dynlink_main dynlink_cube dynlink_balls + DEPENDS dynlink_main dynlink_cube dynlink_balls system.cnf ) psn00bsdk_target_incbin(dynlink_balls PRIVATE ball16c library/ball16c.tim) diff --git a/examples/system/dynlink/iso.xml b/examples/system/dynlink/iso.xml index 8f40510..93cb948 100644 --- a/examples/system/dynlink/iso.xml +++ b/examples/system/dynlink/iso.xml @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<iso_project - image_name="${CD_IMAGE_NAME}.bin" - cue_sheet="${CD_IMAGE_NAME}.cue" -> +<iso_project> <track type="data"> <identifiers system ="PLAYSTATION" |
