aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/psxetc
diff options
context:
space:
mode:
authorJohn Wilbert M. Villamor <lameguy64@gmail.com>2020-09-19 20:43:05 +0800
committerJohn Wilbert M. Villamor <lameguy64@gmail.com>2020-09-19 20:43:05 +0800
commit9f4891f95070c66ea9f1aba99d72724d4ab24e5a (patch)
tree723e3ef2118a3d1a9e6dafa811ed1b8b1bc9196e /libpsn00b/psxetc
parent6762c39551ded059450d17d8bb0cb80642c8aaab (diff)
downloadpsn00bsdk-9f4891f95070c66ea9f1aba99d72724d4ab24e5a.tar.gz
Revised makefiles, added strtok(), command line arguments, SetHeapSize(), moved ISR and callback system to psxetc, moved debug font to psxgpu, fixed CD-ROM library crashing on PSIO, fixed interrupt callback setup to fix crashing on ResetGraph()
Diffstat (limited to 'libpsn00b/psxetc')
-rw-r--r--libpsn00b/psxetc/dbugfont.c144
-rw-r--r--libpsn00b/psxetc/dbugfont.timbin2112 -> 0 bytes
-rw-r--r--libpsn00b/psxetc/dmacallback.s191
-rw-r--r--libpsn00b/psxetc/fntsort.c47
-rw-r--r--libpsn00b/psxetc/font.c225
-rw-r--r--libpsn00b/psxetc/getinterruptcallback.s19
-rw-r--r--libpsn00b/psxetc/interruptcallback.s48
-rw-r--r--libpsn00b/psxetc/isr.s107
-rw-r--r--libpsn00b/psxetc/makefile26
-rw-r--r--libpsn00b/psxetc/restartcallback.s54
10 files changed, 437 insertions, 424 deletions
diff --git a/libpsn00b/psxetc/dbugfont.c b/libpsn00b/psxetc/dbugfont.c
deleted file mode 100644
index ff21d84..0000000
--- a/libpsn00b/psxetc/dbugfont.c
+++ /dev/null
@@ -1,144 +0,0 @@
-unsigned int dbugfont_size=2112;
-unsigned char dbugfont[] = {
-0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x00,0x00,0xe0,
-0x01,0x10,0x00,0x01,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x08,0x00,0x00,0x80,0x02,0x00,0x00,
-0x20,0x00,0x20,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,
-0x00,0x10,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x11,
-0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x11,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,
-0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
-0x01,0x00,0x00,0x11,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
-0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x01,0x00,
-0x00,0x00,0x00,0x00,0x00,0x10,0x11,0x11,0x00,0x01,0x01,0x00,0x00,0x11,0x01,
-0x01,0x00,0x10,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x10,0x00,0x00,0x00,0x00,
-0x10,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x10,0x00,0x11,
-0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x10,0x11,
-0x00,0x00,0x10,0x10,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x10,
-0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x11,0x00,0x00,0x11,0x11,0x01,0x00,
-0x00,0x00,0x00,0x00,0x11,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,
-0x00,0x10,0x10,0x10,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x11,
-0x11,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,0x10,0x01,0x00,0x00,
-0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x01,0x01,0x01,0x00,
-0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x01,0x00,0x00,0x10,0x01,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x10,0x10,0x11,0x00,0x01,
-0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,
-0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x11,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x01,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x10,0x11,0x00,0x00,0x01,
-0x00,0x01,0x00,0x10,0x01,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
-0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x11,
-0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x10,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x11,0x01,0x00,0x00,
-0x11,0x01,0x00,0x00,0x10,0x01,0x00,0x10,0x11,0x11,0x00,0x00,0x10,0x01,0x00,
-0x10,0x11,0x11,0x00,0x00,0x11,0x01,0x00,0x00,0x11,0x01,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x00,
-0x00,0x00,0x00,0x11,0x01,0x00,0x00,0x11,0x11,0x00,0x00,0x11,0x00,0x00,0x10,
-0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x01,0x01,0x00,0x10,0x00,0x00,0x00,
-0x00,0x01,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,
-0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x01,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x01,0x10,
-0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x01,0x00,
-0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,
-0x00,0x10,0x00,0x10,0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x01,
-0x00,0x00,0x10,0x11,0x11,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x10,
-0x10,0x01,0x01,0x00,0x10,0x00,0x00,0x00,0x10,0x01,0x00,0x00,0x10,0x01,0x00,
-0x10,0x11,0x11,0x00,0x10,0x11,0x01,0x00,0x10,0x11,0x01,0x00,0x00,0x00,0x01,
-0x00,0x00,0x11,0x01,0x00,0x00,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,
-0x00,0x01,0x00,0x10,0x10,0x01,0x01,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,
-0x00,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,
-0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x10,0x11,0x11,0x00,0x00,
-0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x10,0x11,0x00,0x00,0x10,0x00,0x00,
-0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x10,
-0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,
-0x01,0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
-0x10,0x11,0x11,0x00,0x10,0x11,0x11,0x00,0x00,0x11,0x01,0x00,0x00,0x00,0x01,
-0x00,0x10,0x11,0x01,0x00,0x00,0x11,0x01,0x00,0x00,0x10,0x00,0x00,0x00,0x11,
-0x01,0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x11,0x00,0x00,0x00,
-0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
-0x00,0x11,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
-0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x11,0x01,
-0x00,0x00,0x11,0x01,0x00,0x10,0x11,0x01,0x00,0x10,0x11,0x11,0x00,0x10,0x11,
-0x11,0x00,0x00,0x11,0x11,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x11,0x00,0x00,
-0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,
-0x10,0x00,0x10,0x00,0x00,0x11,0x01,0x00,0x10,0x11,0x01,0x00,0x00,0x01,0x01,
-0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
-0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,
-0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,
-0x10,0x01,0x11,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,
-0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,
-0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,
-0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x01,0x00,
-0x10,0x00,0x00,0x00,0x10,0x10,0x10,0x00,0x10,0x01,0x10,0x00,0x10,0x00,0x10,
-0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x01,0x00,0x10,0x00,
-0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x00,0x00,0x10,0x11,0x00,0x00,0x10,
-0x10,0x11,0x00,0x10,0x11,0x11,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,
-0x10,0x11,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x10,0x10,
-0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x11,0x00,0x10,0x00,
-0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,
-0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00,
-0x10,0x00,0x10,0x00,0x10,0x00,0x01,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,
-0x00,0x10,0x00,0x11,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x01,0x00,0x10,0x00,
-0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,
-0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
-0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,
-0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
-0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x01,0x00,0x00,0x11,0x01,0x00,0x10,
-0x11,0x01,0x00,0x10,0x11,0x11,0x00,0x10,0x00,0x00,0x00,0x00,0x11,0x01,0x00,
-0x10,0x00,0x10,0x00,0x10,0x11,0x11,0x00,0x00,0x11,0x01,0x00,0x10,0x00,0x10,
-0x00,0x10,0x11,0x11,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x11,
-0x01,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x01,0x00,0x10,
-0x11,0x01,0x00,0x00,0x11,0x01,0x00,0x10,0x11,0x11,0x00,0x10,0x00,0x10,0x00,
-0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,
-0x00,0x10,0x11,0x11,0x00,0x00,0x11,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x11,
-0x01,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x00,0x10,
-0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00,
-0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,
-0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x01,0x00,0x00,0x10,0x00,
-0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
-0x11,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,
-0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,
-0x00,0x00,0x01,0x01,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0x01,
-0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x10,0x01,0x11,0x00,0x00,
-0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x11,0x01,0x00,
-0x00,0x11,0x01,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,
-0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x10,
-0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x01,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x00,
-0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x10,
-0x00,0x10,0x00,0x10,0x00,0x10,0x10,0x10,0x00,0x00,0x01,0x01,0x00,0x00,0x10,
-0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x00,
-0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x10,0x00,0x01,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,
-0x00,0x10,0x00,0x10,0x00,0x00,0x01,0x01,0x00,0x10,0x01,0x11,0x00,0x10,0x00,
-0x10,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
-0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x11,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x11,0x01,
-0x00,0x00,0x10,0x00,0x00,0x00,0x11,0x01,0x00,0x00,0x10,0x00,0x00,0x10,0x00,
-0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x10,0x11,0x11,0x00,0x00,
-0x11,0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x11,0x01,0x00,0x00,0x00,0x00,0x00,
-0x11,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
-};
diff --git a/libpsn00b/psxetc/dbugfont.tim b/libpsn00b/psxetc/dbugfont.tim
deleted file mode 100644
index 4e6cce2..0000000
--- a/libpsn00b/psxetc/dbugfont.tim
+++ /dev/null
Binary files differ
diff --git a/libpsn00b/psxetc/dmacallback.s b/libpsn00b/psxetc/dmacallback.s
new file mode 100644
index 0000000..b2f86cf
--- /dev/null
+++ b/libpsn00b/psxetc/dmacallback.s
@@ -0,0 +1,191 @@
+.set noreorder
+
+.include "hwregs_a.h"
+
+.section .text
+
+.global DMACallback
+.type DMACallback, @function
+DMACallback:
+
+ # a0 - DMA channel
+ # a1 - Callback function
+
+ addiu $sp, -8
+ sw $ra, 0($sp)
+
+ beqz $a1, .Lremove_cb # Remove callback if function is NULL
+ nop
+
+ addiu $sp, -8 # Install IRQ handler for DMA handler
+ sw $a0, 0($sp) # if not set installed yet
+ sw $a1, 4($sp)
+
+ jal GetInterruptCallback
+ li $a0, 3
+
+ bnez $v0, .Lskip_install
+ nop
+
+ la $a1, _dma_handler
+ jal InterruptCallback
+ li $a0, 3
+
+.Lskip_install:
+
+ lw $a0, 0($sp)
+ lw $a1, 4($sp)
+ addiu $sp, 8
+
+ la $v0, _dma_func_table
+ sll $v1, $a0, 2
+ addu $v0, $v1
+ lw $v1, 0($v0)
+ sw $a1, 0($v0)
+ sw $v1, 4($sp)
+
+ lui $a2, IOBASE
+
+ lw $v0, DICR($a2) # Enable DMA interrupt
+ lui $v1, 0x1
+ sll $v1, $a0
+ or $v0, $v1
+ lui $v1, 0x80
+ or $v0, $v1
+ sw $v0, DICR($a2)
+
+ b .Lskip_remove
+ nop
+
+.Lremove_cb:
+
+ la $v0, _dma_func_table # Set callback address
+ sll $v1, $a0, 2
+ addu $v0, $v1
+ lw $v1, 0($v0)
+ sw $a1, 0($v0)
+ sw $v1, 4($sp)
+
+ lui $a2, IOBASE # Disable DMA interrupt
+ lw $v0, DICR($a2)
+ lui $v1, 0x1
+ sll $v1, $a0
+ .set noat
+ addiu $at, $0, -1
+ xor $v1, $at
+ and $v0, $v1
+ lui $v1, 0x7f00
+ xor $v1, $at
+ and $v0, $v1
+ .set at
+ sw $v0, DICR($a2)
+
+ jal _dma_has_cb # Check if callbacks are present
+ nop
+ bnez $v0, .Lskip_remove
+ nop
+ sw $0 , DICR($a2)
+
+ jal GetInterruptCallback # Check if callback is the DMA handler
+ li $a0, 3
+ la $v1, _dma_handler
+ bne $v0, $v1, .Lskip_remove
+ nop
+
+ li $a0, 3
+ jal InterruptCallback
+ move $a1, $0
+
+.Lskip_remove:
+
+ lw $ra, 0($sp)
+ lw $v0, 4($sp)
+ jr $ra
+ addiu $sp, 8
+
+
+.type _dma_has_cb, @function
+_dma_has_cb:
+
+ la $v1, _dma_func_table
+ li $t0, 6
+
+.Lscan_loop:
+
+ lw $v0, 0($v1)
+ addiu $v1, 4
+ bnez $v0, .Lhas_cb
+ nop
+
+ bgtz $t0, .Lscan_loop
+ addiu $t0, -1
+
+ jr $ra
+ move $v0, $0
+
+.Lhas_cb:
+
+ jr $ra
+ li $v0, 1
+
+
+.type _dma_handler, @function
+_dma_handler:
+
+ addiu $sp, -12
+ sw $ra, 0($sp)
+ sw $s0, 4($sp)
+ sw $s1, 8($sp)
+
+ move $s0, $0
+ la $s1, _dma_func_table
+
+.Lhandler_loop:
+
+ lui $a0, IOBASE
+ lw $v0, DICR($a0)
+ li $v1, 24
+ addu $v1, $s0
+ srl $v0, $v1
+ andi $v0, 0x1
+
+ lw $v1, 0($s1)
+
+ beqz $v0, .Lno_irq
+ addiu $s1, 4
+
+ beqz $v1, .Lno_irq
+ nop
+
+ jalr $v1
+ nop
+
+.Lno_irq:
+
+ blt $s0, 6, .Lhandler_loop
+ addi $s0, 1
+
+ lui $a0, IOBASE
+ lw $v0, DICR($a0)
+ nop
+ sw $v0, DICR($a0)
+
+ lw $ra, 0($sp)
+ lw $s0, 4($sp)
+ lw $s1, 8($sp)
+
+ jr $ra
+ addiu $sp, -12
+
+
+.section .data
+
+_dma_func_table:
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ \ No newline at end of file
diff --git a/libpsn00b/psxetc/fntsort.c b/libpsn00b/psxetc/fntsort.c
deleted file mode 100644
index 3890ebb..0000000
--- a/libpsn00b/psxetc/fntsort.c
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <stdio.h>
-#include <ctype.h>
-#include <psxgpu.h>
-
-extern unsigned short _font_tpage;
-extern unsigned short _font_clut;
-
-char *FntSort(unsigned int *ot, char *pri, int x, int y, const char *text) {
-
- DR_TPAGE *tpage;
- SPRT_8 *sprt = (SPRT_8*)pri;
- int i;
-
- while( *text != 0 ) {
-
- i = toupper( *text )-32;
-
- if( i > 0 ) {
-
- i--;
- setSprt8( sprt );
- setRGB0( sprt, 128, 128, 128 );
- setXY0( sprt, x, y );
- setUV0( sprt, (i%16)<<3, (i>>4)<<3 );
- sprt->clut = _font_clut;
- addPrim( ot, sprt );
- sprt++;
-
- }
-
- x += 8;
- text++;
-
- }
-
- pri = (char*)sprt;
-
- tpage = (DR_TPAGE*)pri;
- tpage->code[0] = _font_tpage;
- setlen( tpage, 1 );
- setcode( tpage, 0xe1 );
- addPrim( ot, pri );
- pri += sizeof(DR_TPAGE);
-
- return pri;
-
-} \ No newline at end of file
diff --git a/libpsn00b/psxetc/font.c b/libpsn00b/psxetc/font.c
deleted file mode 100644
index cd4acab..0000000
--- a/libpsn00b/psxetc/font.c
+++ /dev/null
@@ -1,225 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <malloc.h>
-#include <ctype.h>
-#include <psxgpu.h>
-
-typedef struct _fnt_stream {
- char *txtbuff;
- char *txtnext;
- char *pribuff;
- short x,y;
- short w,h;
- int bg;
- int maxchars;
-} _fnt_stream;
-
-static _fnt_stream _stream[8];
-static int _nstreams = 0;
-
-unsigned short _font_tpage;
-unsigned short _font_clut;
-
-extern unsigned char dbugfont[];
-
-void FntLoad(int x, int y) {
-
- RECT pos;
- TIM_IMAGE tim;
-
- GetTimInfo( (unsigned int*)dbugfont, &tim );
-
- // Load font image
- pos = *tim.prect;
- pos.x = x;
- pos.y = y;
-
- _font_tpage = getTPage( 0, 0, pos.x, pos.y );
-
- LoadImage( &pos, tim.paddr );
- DrawSync(0);
-
- // Load font clut
- pos = *tim.crect;
- pos.x = x;
- pos.y = y+tim.prect->h;
-
- _font_clut = getClut( pos.x, pos.y );
-
- LoadImage( &pos, tim.caddr );
- DrawSync(0);
-
- // Clear previously opened text streams
- if( _nstreams ) {
-
- int i;
-
- for( i=0; i<_nstreams; i++ ) {
- free(_stream[i].txtbuff);
- free(_stream[i].pribuff);
- }
-
- _nstreams = 0;
-
- }
-
-}
-
-int FntOpen(int x, int y, int w, int h, int isbg, int n) {
-
- int i;
-
- // Initialize a text stream
- _stream[_nstreams].x = x;
- _stream[_nstreams].y = y;
- _stream[_nstreams].w = w;
- _stream[_nstreams].h = h;
-
- _stream[_nstreams].txtbuff = (char*)malloc(n+1);
-
- i = (sizeof(SPRT_8)*n)+sizeof(DR_TPAGE);
-
- if( isbg ) {
- i += sizeof(TILE);
- }
-
- _stream[_nstreams].pribuff = (char*)malloc(i);
- _stream[_nstreams].maxchars = n;
-
- _stream[_nstreams].txtbuff[0] = 0x0;
- _stream[_nstreams].txtnext = _stream[_nstreams].txtbuff;
- _stream[_nstreams].bg = isbg;
-
- n = _nstreams;
- _nstreams++;
-
- return n;
-
-}
-
-int FntPrint(int id, const char *fmt, ...) {
-
- int n;
- va_list ap;
-
- if( id < 0 )
- id = _nstreams-1;
-
- n = strlen(_stream[id].txtbuff);
-
- if( n >= _stream[id].maxchars ) {
- return n;
- }
-
- va_start(ap, fmt);
-
- n = vsnprintf(_stream[id].txtnext, _stream[id].maxchars-n, fmt, ap);
-
- _stream[id].txtnext += n;
-
- va_end(ap);
-
- return strlen(_stream[id].txtbuff);
-
-}
-
-char *FntFlush(int id) {
-
- char *opri;
- SPRT_8 *sprt;
- DR_TPAGE *tpage;
- char *text;
- int i,sx,sy;
-
- if( id < 0 )
- id = _nstreams-1;
-
- sx = _stream[id].x;
- sy = _stream[id].y;
-
- text = _stream[id].txtbuff;
-
- opri = _stream[id].pribuff;
-
- // Create TPage primitive
- tpage = (DR_TPAGE*)opri;
- setDrawTPage(tpage, 0, 0, _font_tpage);
-
- // Create a black rectangle background when enabled
- if( _stream[id].bg ) {
-
- TILE *tile;
- opri += sizeof(DR_TPAGE);
- tile = (TILE*)opri;
-
- setTile(tile);
-
- if( _stream[id].bg == 2 )
- setSemiTrans(tile, 1);
-
- setXY0(tile, _stream[id].x, _stream[id].y);
- setWH(tile, _stream[id].w, _stream[id].h);
- setRGB0(tile, 0, 0, 0);
- setaddr(tpage, tile);
- opri = (char*)tile;
-
- sprt = (SPRT_8*)(opri+sizeof(TILE));
-
- } else {
-
- sprt = (SPRT_8*)(opri+sizeof(DR_TPAGE));
-
- }
-
- // Create the sprite primitives
- while( *text != 0 ) {
-
- if( ( *text == '\n' ) || ( ( sx-_stream[id].x ) > _stream[id].w-8 ) ) {
- sx = _stream[id].x;
- sy += 8;
-
- if( *text == '\n' )
- text++;
-
- continue;
- }
-
- if( ( sy-_stream[id].y ) > _stream[id].h-8 ) {
- break;
- }
-
- i = toupper( *text )-32;
-
- if( i > 0 ) {
-
- i--;
- setSprt8( sprt );
- setRGB0( sprt, 128, 128, 128 );
- setXY0( sprt, sx, sy );
- setUV0( sprt, (i%16)<<3, (i>>4)<<3 );
- sprt->clut = _font_clut;
- setaddr(opri, sprt);
- opri = (char*)sprt;
- sprt++;
-
- }
-
- sx += 8;
- text++;
-
- }
-
- // Set a terminator value to the last primitive
- termPrim(opri);
-
- // Draw the primitives
- DrawSync(0);
- DrawOTag((unsigned int*)_stream[id].pribuff);
- DrawSync(0);
-
- _stream[id].txtnext = _stream[id].txtbuff;
- _stream[id].txtbuff[0] = 0;
-
- return _stream[id].pribuff;
-
-} \ No newline at end of file
diff --git a/libpsn00b/psxetc/getinterruptcallback.s b/libpsn00b/psxetc/getinterruptcallback.s
new file mode 100644
index 0000000..510447f
--- /dev/null
+++ b/libpsn00b/psxetc/getinterruptcallback.s
@@ -0,0 +1,19 @@
+.set noreorder
+
+.section .text
+
+.global GetInterruptCallback
+.type GetInterruptCallback, @function
+GetInterruptCallback:
+
+ # a0 - Interrupt number
+
+ la $a1, _irq_func_table
+ sll $a0, 2
+ addu $a1, $a0
+ lw $v0, 0($a1)
+ nop
+ jr $ra
+ nop
+
+ \ No newline at end of file
diff --git a/libpsn00b/psxetc/interruptcallback.s b/libpsn00b/psxetc/interruptcallback.s
new file mode 100644
index 0000000..8e912d8
--- /dev/null
+++ b/libpsn00b/psxetc/interruptcallback.s
@@ -0,0 +1,48 @@
+.set noreorder
+
+.include "hwregs_a.h"
+
+.section .text
+
+.global InterruptCallback
+.type InterruptCallback, @function
+InterruptCallback:
+
+ # a0 - Interrupt number
+ # a1 - Callback function
+
+ lui $a2, IOBASE
+
+ beqz $a1, .Ldisable_irq
+ nop
+
+ lw $v0, IMASK($a2) # Enable interrupt mask
+ li $v1, 1
+ sll $v1, $a0
+ or $v0, $v1
+
+ b .Lcont
+ sw $v0, IMASK($a2)
+
+.Ldisable_irq:
+
+.set noat
+ lw $v0, IMASK($a2) # Disable interrupt mask
+ li $v1, 1
+ sll $v1, $a0
+ addiu $at, $0 , -1
+ xor $v1, $at
+.set at
+ and $v0, $v1
+ sw $v0, IMASK($a2)
+
+.Lcont:
+
+ la $a2, _irq_func_table # Get address to IRQ function table
+
+ sll $v1, $a0, 2 # Compute the slot
+ addu $v1, $a2, $v1
+ lw $v0, 0($v1) # Get old handler address
+
+ jr $ra # Return and set new IRQ handler
+ sw $a1, 0($v1)
diff --git a/libpsn00b/psxetc/isr.s b/libpsn00b/psxetc/isr.s
new file mode 100644
index 0000000..00428a4
--- /dev/null
+++ b/libpsn00b/psxetc/isr.s
@@ -0,0 +1,107 @@
+.set noreorder
+
+.include "hwregs_a.h"
+
+.set ISR_STACK_SIZE, 4096
+
+
+.section .text
+
+# Global ISR handler of PSn00bSDK
+
+.set at
+
+.type _global_isr, @function
+_global_isr:
+
+.Lisr_loop:
+
+ #la $gp, _gp # Keep restoring GP since it gets
+ # changed elsewhere sometimes
+
+ lui $a0, IOBASE # Get IRQ status
+ lw $v0, IMASK($a0)
+ nop
+
+ srl $v0, $s1 # Check IRQ mask bit if set
+ andi $v0, 0x1
+
+ beqz $v0, .Lno_irq # Don't execute callback if IRQ not enabled
+ nop
+
+ lw $v0, ISTAT($a0)
+ nop
+ srl $v0, $s1 # Check IRQ status bit if set
+ andi $v0, 0x1
+ beqz $v0, .Lno_irq # Don't execute callback if no IRQ
+ nop
+
+ lw $v1, 0($s0) # Load IRQ callback function
+ nop
+
+ lw $v0, ISTAT($a0) # Acknowledge the IRQ (by writing a 0 bit)
+ li $a1, 1
+ sll $a1, $s1
+ addiu $a2, $0 , -1
+ xor $a1, $a2
+ sw $a1, ISTAT($a0)
+
+ beqz $v1, .Lno_irq # Don't execute if callback is not set
+ nop
+
+ jalr $v1 # Call interrupt handler
+ nop
+
+.Lno_irq:
+
+ addiu $s0, 4
+
+ blt $s1, 11, .Lisr_loop
+ addiu $s1, 1
+
+ j ReturnFromException
+ nop
+
+
+.section .data
+
+# Global ISR callback table
+
+.global _irq_func_table
+.type _irq_func_table, @object
+_irq_func_table:
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+
+# Global ISR hook structure
+.global _custom_exit
+.type _custom_exit, @object
+_custom_exit:
+ .word _global_isr # pc
+ .word _isr_stack+ISR_STACK_SIZE # sp
+ .word 0 # fp
+ .word _irq_func_table # s0
+ .word 0 # s1
+ .word 0 # s2
+ .word 0 # s3
+ .word 0 # s4
+ .word 0 # s5
+ .word 0 # s6
+ .word 0 # s7
+ .word _gp # gp
+
+# Global ISR stack
+# .fill 1024
+#_custom_exit_stack:
+# .fill 4
+.comm _isr_stack, ISR_STACK_SIZE+4
diff --git a/libpsn00b/psxetc/makefile b/libpsn00b/psxetc/makefile
index 399fb91..3f938a6 100644
--- a/libpsn00b/psxetc/makefile
+++ b/libpsn00b/psxetc/makefile
@@ -1,22 +1,26 @@
# Run using make (Linux) or gmake (BSD)
# Part of the PSn00bSDK Project
-# 2019 Lameguy64 / Meido-Tek Productions
+# 2019 - 2020 Lameguy64 / Meido-Tek Productions
-include ../common.mk
+include ../../psn00bsdk-setup.mk
-TARGET = ../libpsxetc.a
+TARGET = libpsxetc.a
CFILES = $(notdir $(wildcard ./*.c))
AFILES = $(notdir $(wildcard ./*.s))
OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o))
-CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections -ffunction-sections -Wa,--strip-local-absolute
+CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections \
+ -ffunction-sections -Wa,--strip-local-absolute
AFLAGS = -g -msoft-float -strip-local-absolute
-CC = $(PREFIX)gcc
-AS = $(PREFIX)as
-AR = $(PREFIX)ar
-RANLIB = $(PREFIX)ranlib
+INCLUDE = -I../include
+
+ifndef PSN00BSDK_LIBS
+
+PSN00BSDK_LIBS = ..
+
+endif
all: $(TARGET)
@@ -32,5 +36,11 @@ build/%.o: %.s
@mkdir -p $(dir $@)
$(AS) $(AFLAGS) $(INCLUDE) $< -o $@
+install:
+ifneq ($(PSN00BSDK_LIBS), "..")
+ @mkdir -p $(PSN00BSDK_LIBS)
+endif
+ cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
+
clean:
rm -Rf build $(TARGET)
diff --git a/libpsn00b/psxetc/restartcallback.s b/libpsn00b/psxetc/restartcallback.s
new file mode 100644
index 0000000..151d78e
--- /dev/null
+++ b/libpsn00b/psxetc/restartcallback.s
@@ -0,0 +1,54 @@
+.set noreorder
+
+.include "hwregs_a.h"
+
+.section .text
+
+.global RestartCallback
+.type RestartCallback, @function
+RestartCallback:
+
+ addiu $sp, -4
+ sw $ra, 0($sp)
+
+ la $a0, _custom_exit
+ jal SetCustomExitFromException
+ addiu $sp, -4
+ addiu $sp, 4
+
+ move $a0, $0
+ jal ChangeClearPAD
+ addiu $sp, -4
+ addiu $sp, 4
+
+ li $a0, 3
+ move $a1, $0
+ jal ChangeClearRCnt
+ addiu $sp, -8
+ addiu $sp, 8
+
+ la $a0, _irq_func_table
+ move $a1, $0
+ move $v0, $0
+
+.Lcheck_cbs: # Set up the interrupt masks
+ lw $v1, 0($a0)
+ nop
+ beqz $v1, .Lno_cb
+ addiu $a0, 4
+ li $v1, 1
+ sll $v1, $a1
+ or $v0, $v1
+.Lno_cb:
+ blt $a1, 10, .Lcheck_cbs
+ addiu $a1, 1
+
+ lui $a0, IOBASE
+ sw $0 , ISTAT($a0)
+ sw $v0, IMASK($a0)
+
+ lw $ra, 0($sp)
+ addiu $sp, 4
+ jr $ra
+ nop
+ \ No newline at end of file