diff options
Diffstat (limited to 'examples/demos/n00bdemo/main.c')
| -rw-r--r-- | examples/demos/n00bdemo/main.c | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c index d2fe317..069b549 100644 --- a/examples/demos/n00bdemo/main.c +++ b/examples/demos/n00bdemo/main.c @@ -11,14 +11,22 @@ * * Changelog: * + * Mar 24, 2022 - Added FPS counter. + * + * Mar 12, 2022 - Added Konami System 573 support. + * * May 10, 2021 - Variable types updated for psxgpu.h changes. * * Apr 4, 2019 - Some code clean-up and added more comments. * - * Mar 20, 2019 - Initial completed version. + * Mar 20, 2019 - Initial completed version. * */ - + +// Uncomment to enable Konami System 573 support +// (seems to break the demo when loading it using Caetla on a cheat cartridge) +//#define SYSTEM_573_SUPPORT + #include <sys/types.h> #include <sys/fcntl.h> #include <stdio.h> @@ -27,7 +35,9 @@ #include <psxgte.h> #include <psxgpu.h> #include <psxspu.h> +#include <psxapi.h> #include <inline_c.h> +#include <hwregs_c.h> #include <string.h> #include <lzp/lzp.h> #include <lzp/lzqlp.h> @@ -59,11 +69,50 @@ unsigned short font_tpage,font_clut; SPRT llotl_sprite; SPRT psn00b_sprite; +// Timer and FPS counter +volatile int timer_counter = 0, frame_counter = 0, frame_rate = 0; // Some function definition void sort_overlay(int showlotl); void lightdemo(); +#define K573_WATCHDOG *((volatile unsigned short *) 0x1f5c0000) +#define K573_EXP1_CFG 0x24173f47 + +void timerTick() { + if (!(--timer_counter)) { + timer_counter = 100; + frame_rate = frame_counter; + frame_counter = 0; + } + +#ifdef SYSTEM_573_SUPPORT + /* + The only thing required to support the 573 is to periodically reset the + watchdog. Hooking the vblank IRQ (through VSyncCallback) is the "right" + way to do it, however using a hardware timer running at a higher rate + (100 Hz) seems to improve stability. + */ + K573_WATCHDOG = 0; +#endif +} + +void timerSetup() { + EnterCriticalSection(); + +#ifdef SYSTEM_573_SUPPORT + EXP1_ADDR = 0x1f000000; + EXP1_DELAY_SIZE = K573_EXP1_CFG; +#endif + + TIMER_CTRL(2) = 0x0258; // CLK/8 input, IRQ on reload + TIMER_RELOAD(2) = (F_CPU / 8) / 100; // 100 Hz + + // Configure timer 2 IRQ + ChangeClearRCnt(2, 0); + InterruptCallback(6, &timerTick); + ExitCriticalSection(); +} void UploadTIM(TIM_IMAGE *tim) { @@ -197,11 +246,9 @@ void unpackModels() { } void init() { - - int i; - // Init display initDisplay(); + timerSetup(); FntLoad( 960, 0 ); @@ -617,11 +664,11 @@ void transition() { if( comp >= 16 ) break; - // FIXME: for some reason this loop glitches out and hangs indefinitely - // in no$psx, *unless* there's a function somewhere that gets called - // with a pointer/string as first argument... wtf. It works fine in - // other emulators. If you are reading this, please help and enlighten - // me. -- spicyjpeg + /* + 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("."); } @@ -646,6 +693,7 @@ int main(int argc, const char *argv[]) { unpackModels(); // Demo sequence loop + timer_counter = 100; while( 1 ) { lightdemo(); |
