aboutsummaryrefslogtreecommitdiff
path: root/examples/system
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/system
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/system')
-rw-r--r--examples/system/childexec/CMakeLists.txt16
-rw-r--r--examples/system/childexec/child_exe.s.template6
-rw-r--r--examples/system/dynlink/main.c19
-rw-r--r--examples/system/timer/main.c5
4 files changed, 22 insertions, 24 deletions
diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt
index ca0c110..b781dea 100644
--- a/examples/system/childexec/CMakeLists.txt
+++ b/examples/system/childexec/CMakeLists.txt
@@ -11,18 +11,17 @@ project(
HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
)
-configure_file(child_exe.s.template child_exe.s)
-
file(GLOB _sources *.c)
file(GLOB _child_sources child/*.c)
-psn00bsdk_add_executable(
- parent STATIC
- ${_sources}
- ${PROJECT_BINARY_DIR}/child_exe.s
-)
+psn00bsdk_add_executable(parent STATIC ${_sources})
psn00bsdk_add_executable(child STATIC ${_child_sources})
#psn00bsdk_add_cd_image(childexec_iso childexec iso.xml DEPENDS parent)
+psn00bsdk_target_incbin(
+ parent PRIVATE child_exe
+ ${PROJECT_BINARY_DIR}/child.exe
+)
+
# Relocate the child executable to a non-default address to prevent it from
# overlapping with the main one at 0x80010000.
# NOTE: child executables are not position-independent and can't be relocated
@@ -30,8 +29,7 @@ psn00bsdk_add_executable(child STATIC ${_child_sources})
# dynamically-allocated buffer), consider using a DLL instead.
target_link_options(child PRIVATE -Ttext=0x80030000)
-# Make sure the child executable is built before the parent (so it can be
-# embedded via child_exe.s).
+# Make sure the child executable is built before the parent.
add_dependencies(parent child)
install(FILES ${PROJECT_BINARY_DIR}/parent.exe TYPE BIN)
diff --git a/examples/system/childexec/child_exe.s.template b/examples/system/childexec/child_exe.s.template
deleted file mode 100644
index f76bb3d..0000000
--- a/examples/system/childexec/child_exe.s.template
+++ /dev/null
@@ -1,6 +0,0 @@
-.section .data
-
-.global child_exe # Insert spoopypasta
-.type child_exe, @object
-child_exe:
- .incbin "${PROJECT_BINARY_DIR}/child.exe"
diff --git a/examples/system/dynlink/main.c b/examples/system/dynlink/main.c
index 690371e..9b94b30 100644
--- a/examples/system/dynlink/main.c
+++ b/examples/system/dynlink/main.c
@@ -57,7 +57,7 @@
// call them. Placing this array in the .dummy section (as defined in the
// PSn00bSDK linker script) ensures it won't be stripped away until all
// functions are in place.
-const void *const DO_NOT_STRIP[] __attribute__((section(".dummy"))) = {
+void *DO_NOT_STRIP[] __attribute__((section(".dummy"))) = {
&rand,
&InitGeom,
&RotMatrix,
@@ -244,14 +244,18 @@ void load_dll(const char *filename) {
printf("DLL init() @ %08x, render() @ %08x\n", dll_api.init, dll_api.render);
// Unfortunately, due to how position-independent code works, function
- // pointers returned by DL_GetDLLSymbol() can't be called directly. We have
- // to use the DL_CALL() macro instead, which sets up register $t9 to ensure
- // the function can locate and reference the DLL's relocation table.
- DL_CALL(dll_api.init, &ctx);
-
+ // pointers returned by DL_GetDLLSymbol() can't be called without first
+ // initializing register $t9. We have to use the DL_PRE_CALL() macro, which
+ // sets up $t9 to ensure the function can locate and reference the DLL's
+ // relocation table.
+ DL_PRE_CALL(dll_api.init);
+ dll_api.init(&ctx);
}
int main(int argc, const char* argv[]) {
+ // Reference the dummy array to prevent it from being stripped.
+ void **dummy = DO_NOT_STRIP;
+
init_context(&ctx);
SHOW_STATUS("INITIALIZING CD\n");
@@ -289,7 +293,8 @@ int main(int argc, const char* argv[]) {
while (1) {
// Use the currently loaded DLL to render a frame.
- DL_CALL(dll_api.render, &ctx, last_buttons);
+ DL_PRE_CALL(dll_api.render);
+ dll_api.render(&ctx, last_buttons);
FntPrint(-1, "MAIN: DLL ADDR=%08x SIZE=%d\n", dll->ptr, dll->size);
FntPrint(-1, "MAIN: %d FUNCTIONS RESOLVED\n", resolve_counter);
diff --git a/examples/system/timer/main.c b/examples/system/timer/main.c
index 8153581..eb62712 100644
--- a/examples/system/timer/main.c
+++ b/examples/system/timer/main.c
@@ -3,6 +3,7 @@
#include <psxgpu.h>
#include <psxapi.h>
#include <psxetc.h>
+#include <hwregs_c.h>
/* OT and Packet Buffer sizes */
#define OT_LEN 256
@@ -34,7 +35,7 @@ void display();
volatile int timer_calls = 0;
-volatile short *timer2_ctrl = (short*)0x1F801124;
+
void timer_func()
{
timer_calls++;
@@ -74,7 +75,7 @@ int main() {
//counter = 5163000/560;
SetRCnt(RCntCNT2, counter, RCntMdINTR);
- *timer2_ctrl = 0x1E58;
+ TIMER_CTRL(2) = 0x1E58;
InterruptCallback(6, timer_func);
StartRCnt(RCntCNT2);
ChangeClearRCnt(2, 0);