aboutsummaryrefslogtreecommitdiff
path: root/examples/demos
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2022-03-25 09:22:20 +0800
committerGitHub <noreply@github.com>2022-03-25 09:22:20 +0800
commit975e614b3c840e2f717adac1d1cb9cee4e5e561b (patch)
tree6584ce5b0dbe27a466c95c81fac61b0d90f627bd /examples/demos
parent05d44488bd5587786f4bd0286fc0f555c79aa46a (diff)
parent45168ae43e29aa5930ee5a206475ae836078915f (diff)
downloadpsn00bsdk-975e614b3c840e2f717adac1d1cb9cee4e5e561b.tar.gz
Merge pull request #46 from spicyjpeg/psxmdec
Critical ldscript fixes, initial MDEC support and CI updates
Diffstat (limited to 'examples/demos')
-rw-r--r--examples/demos/n00bdemo/CMakeLists.txt28
-rw-r--r--examples/demos/n00bdemo/data.s.template31
-rw-r--r--examples/demos/n00bdemo/data.xml (renamed from examples/demos/n00bdemo/data.xml.template)0
-rw-r--r--examples/demos/n00bdemo/logo.c4
-rw-r--r--examples/demos/n00bdemo/main.c68
-rw-r--r--examples/demos/n00bdemo/overlay.c33
6 files changed, 105 insertions, 59 deletions
diff --git a/examples/demos/n00bdemo/CMakeLists.txt b/examples/demos/n00bdemo/CMakeLists.txt
index 1c211b3..a54c198 100644
--- a/examples/demos/n00bdemo/CMakeLists.txt
+++ b/examples/demos/n00bdemo/CMakeLists.txt
@@ -13,16 +13,14 @@ project(
set(DATA_DIR ${PROJECT_SOURCE_DIR}/data)
-configure_file(data.s.template data.s)
-configure_file(data.xml.template data.xml)
+configure_file(data.xml _data.xml)
-# Add a build step to pack assets into a single .LZP file. This archive is then
-# embedded into the binary through data.s, which is in turn generated from
-# data.s.template. Note that, since we specify dependencies, CMake can detect
-# when source assets are edited and rebuild the archive automatically.
+# Add a build step to pack assets into a single .LZP file. Note that, since we
+# are specifying dependencies, CMake can detect when source assets are edited
+# and rebuild the archive automatically.
file(GLOB _assets ${DATA_DIR}/*.tim ${DATA_DIR}/*.smd)
add_custom_command(
- COMMAND ${LZPACK} -y data.xml
+ COMMAND ${LZPACK} -y _data.xml
OUTPUT data.lzp
BYPRODUCTS textures.qlp
DEPENDS ${_assets}
@@ -30,17 +28,13 @@ add_custom_command(
)
file(GLOB _sources *.s *.c)
-psn00bsdk_add_executable(
- n00bdemo STATIC
- ${_sources}
- ${PROJECT_BINARY_DIR}/data.s
-)
-target_include_directories(n00bdemo PRIVATE ${PROJECT_SOURCE_DIR})
+psn00bsdk_add_executable(n00bdemo STATIC ${_sources})
#psn00bsdk_add_cd_image(n00bdemo_iso n00bdemo iso.xml DEPENDS n00bdemo)
-# Ensure data.lzp is built before the executable. Due to CMake's limitations we
-# actually have to wrap it in a dummy target.
-add_custom_target(n00bdemo_data DEPENDS data.lzp)
-add_dependencies(n00bdemo n00bdemo_data)
+target_include_directories(n00bdemo PRIVATE ${PROJECT_SOURCE_DIR})
+psn00bsdk_target_incbin(
+ n00bdemo PRIVATE _lz_resources
+ ${PROJECT_BINARY_DIR}/data.lzp
+)
install(FILES ${PROJECT_BINARY_DIR}/n00bdemo.exe TYPE BIN)
diff --git a/examples/demos/n00bdemo/data.s.template b/examples/demos/n00bdemo/data.s.template
deleted file mode 100644
index 9fbef2e..0000000
--- a/examples/demos/n00bdemo/data.s.template
+++ /dev/null
@@ -1,31 +0,0 @@
-.section .data
-
-.global _lz_resources
-.type _lz_resources, @object
-_lz_resources:
- .incbin "${PROJECT_BINARY_DIR}/data.lzp"
-
-#.global smd_mtekdisk
-#.type smd_mtekdisk, @object
-#smd_mtekdisk:
-# .incbin "data/mtekdisk.smd"
-
-#.global smd_mtektext
-#.type smd_mtektext, @object
-#smd_mtektext:
-# .incbin "data/mtektext.smd"
-
-#.global smd_star
-#.type smd_star, @object
-#smd_star:
-# .incbin "data/star.smd"
-
-#.global smd_psn00b
-#.type smd_psn00b, @object
-#smd_psn00b:
-# .incbin "data/psn00blogo.smd"
-
-#.global smd_scarletlogo
-#.type smd_scarletlogo, @object
-#smd_scarletlogo:
-# .incbin "data/scarletlogo.smd" \ No newline at end of file
diff --git a/examples/demos/n00bdemo/data.xml.template b/examples/demos/n00bdemo/data.xml
index 057d6a6..057d6a6 100644
--- a/examples/demos/n00bdemo/data.xml.template
+++ b/examples/demos/n00bdemo/data.xml
diff --git a/examples/demos/n00bdemo/logo.c b/examples/demos/n00bdemo/logo.c
index 40160e7..784c9e1 100644
--- a/examples/demos/n00bdemo/logo.c
+++ b/examples/demos/n00bdemo/logo.c
@@ -51,9 +51,11 @@ typedef struct {
int size;
} NODE;
+extern NODE _end[];
+
void DumpHeap() {
- NODE *n = (NODE*)GetBSSend();
+ NODE *n = _end;
printf( "--\n" );
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();
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;