aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2022-03-23 23:40:15 +0100
committerspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2022-03-23 23:40:15 +0100
commit45168ae43e29aa5930ee5a206475ae836078915f (patch)
tree6584ce5b0dbe27a466c95c81fac61b0d90f627bd
parent6c19e712e2588b52791f604feb31273acb074d41 (diff)
downloadpsn00bsdk-45168ae43e29aa5930ee5a206475ae836078915f.tar.gz
Add FPS counter to n00bdemo, more psxpad commands
-rw-r--r--examples/demos/n00bdemo/main.c57
-rw-r--r--examples/demos/n00bdemo/overlay.c33
-rw-r--r--libpsn00b/include/psxpad.h10
3 files changed, 75 insertions, 25 deletions
diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c
index 439bccc..069b549 100644
--- a/examples/demos/n00bdemo/main.c
+++ b/examples/demos/n00bdemo/main.c
@@ -11,6 +11,8 @@
*
* 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.
@@ -21,8 +23,9 @@
*
*/
-// Comment to disable 573 support
-#define SYSTEM_573_SUPPORT
+// 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>
@@ -66,39 +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();
-#ifdef SYSTEM_573_SUPPORT
-#define K573_WATCHDOG *((volatile uint16_t *) 0x1f5c0000)
+#define K573_WATCHDOG *((volatile unsigned short *) 0x1f5c0000)
#define K573_EXP1_CFG 0x24173f47
-/*
- 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.
-*/
-void reset573Watchdog() {
+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 system573Setup() {
+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, &reset573Watchdog);
+ InterruptCallback(6, &timerTick);
ExitCriticalSection();
}
-#endif
void UploadTIM(TIM_IMAGE *tim) {
@@ -234,9 +248,7 @@ void unpackModels() {
void init() {
// Init display
initDisplay();
-#ifdef SYSTEM_573_SUPPORT
- system573Setup();
-#endif
+ timerSetup();
FntLoad( 960, 0 );
@@ -652,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(".");
}
@@ -681,6 +693,7 @@ int main(int argc, const char *argv[]) {
unpackModels();
// Demo sequence loop
+ timer_counter = 100;
while( 1 ) {
lightdemo();
diff --git a/examples/demos/n00bdemo/overlay.c b/examples/demos/n00bdemo/overlay.c
index 847bc96..0d2691f 100644
--- a/examples/demos/n00bdemo/overlay.c
+++ b/examples/demos/n00bdemo/overlay.c
@@ -7,6 +7,8 @@ extern const char scroll_text[];
extern unsigned short lamelotl_tpage,psn00b_tpage;
extern unsigned short font_tpage,font_clut;
+extern volatile int frame_counter, frame_rate;
+
extern SPRT llotl_sprite;
extern SPRT psn00b_sprite;
@@ -23,6 +25,35 @@ int scrolltext_pos = 640;
int scrolltext_cpos = 0;
int overlay_count = 0;
+void sort_fps_counter() {
+ int tens = frame_rate / 10, units = frame_rate % 10;
+ int x = 10;
+
+ SPRT_16 *spr16 = (SPRT_16 *) nextpri;
+
+ setSprt16(spr16);
+ setSemiTrans(spr16, 1);
+ setXY0(spr16, x, 56);
+ setUV0(spr16, tens << 4, 16);
+ setRGB0(spr16, 20, 20, 20);
+ spr16->clut = font_clut;
+ addPrim(ot[db], spr16);
+ spr16++;
+ x += font_width[16 | tens];
+
+ setSprt16(spr16);
+ setSemiTrans(spr16, 1);
+ setXY0(spr16, x, 56);
+ setUV0(spr16, units << 4, 16);
+ setRGB0(spr16, 20, 20, 20);
+ spr16->clut = font_clut;
+ addPrim(ot[db], spr16);
+ spr16++;
+
+ nextpri = (char *) spr16;
+ frame_counter++;
+}
+
void sort_overlay(int showlotl) {
SPRT *spr;
@@ -31,6 +62,8 @@ void sort_overlay(int showlotl) {
POLY_G4 *quad;
LINE_G2 *line;
+ sort_fps_counter();
+
int i = scrolltext_cpos;
int j, k, tx, par_end = 0;
diff --git a/libpsn00b/include/psxpad.h b/libpsn00b/include/psxpad.h
index 9638ec1..32f7f8a 100644
--- a/libpsn00b/include/psxpad.h
+++ b/libpsn00b/include/psxpad.h
@@ -75,12 +75,16 @@ typedef enum {
typedef enum {
PAD_CMD_INIT_PRESSURE = '@', // Initialize DS2 button pressure sensors (in config mode)
- PAD_CMD_READ = 'B', // Read pad state and set rumble
+ PAD_CMD_READ = 'B', // Read pad state (exchange poll request/response)
PAD_CMD_CONFIG_MODE = 'C', // Toggle DualShock configuration mode
PAD_CMD_SET_ANALOG = 'D', // Set analog mode/LED state (in config mode)
PAD_CMD_GET_ANALOG = 'E', // Get analog mode/LED state (in config mode)
- PAD_CMD_REQUEST_CONFIG = 'M', // Configure request/unlock vibration (in config mode)
- PAD_CMD_RESPONSE_CONFIG = 'O', // Configure response/unlock DS2 pressure (in config mode)
+ PAD_CMD_GET_MOTOR_INFO = 'F', // Get information about a vibration motor (in config mode)
+ PAD_CMD_GET_MOTOR_LIST = 'G', // Get list of all vibration motors (in config mode)
+ PAD_CMD_GET_MOTOR_STATE = 'H', // Get current state of vibration motors (in config mode)
+ PAD_CMD_GET_MODE = 'L', // Get list of supported controller modes? (in config mode)
+ PAD_CMD_REQUEST_CONFIG = 'M', // Configure poll request format (in config mode)
+ PAD_CMD_RESPONSE_CONFIG = 'O', // Configure poll response format (in config mode)
MCD_CMD_READ_SECTOR = 'R', // Read 128-byte sector
MCD_CMD_IDENTIFY = 'S', // Retrieve ID and card size information (Sony cards only)