diff options
| author | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2022-03-12 14:28:11 +0100 |
|---|---|---|
| committer | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2022-03-12 14:28:11 +0100 |
| commit | 8c68b4b8a5bf7757b8e4d6bc2f68f10584b0deb1 (patch) | |
| tree | 71e7927f56c5f11350f236e32b396adac3f75e3a | |
| parent | 93f0a6d23ebed50833f565f949f351c2b80853ac (diff) | |
| download | psn00bsdk-8c68b4b8a5bf7757b8e4d6bc2f68f10584b0deb1.tar.gz | |
Minor fixes, add C++ placement new, n00bdemo 573 support
| -rw-r--r-- | examples/demos/n00bdemo/main.c | 46 | ||||
| -rw-r--r-- | examples/io/system573/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | examples/lowlevel/cartrom/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | examples/sound/spustream/main.c | 4 | ||||
| -rw-r--r-- | libpsn00b/include/elf.h | 2 | ||||
| -rw-r--r-- | libpsn00b/libc/abort.c | 14 | ||||
| -rw-r--r-- | libpsn00b/libc/c++-support.cxx | 39 | ||||
| -rw-r--r-- | libpsn00b/libc/putchar.s | 10 |
8 files changed, 85 insertions, 34 deletions
diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c index d2fe317..cb64c42 100644 --- a/examples/demos/n00bdemo/main.c +++ b/examples/demos/n00bdemo/main.c @@ -11,14 +11,19 @@ * * Changelog: * + * 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. * */ - + +// Comment to disable 573 support +#define SYSTEM_573_SUPPORT + #include <sys/types.h> #include <sys/fcntl.h> #include <stdio.h> @@ -27,7 +32,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> @@ -64,6 +71,34 @@ SPRT psn00b_sprite; void sort_overlay(int showlotl); void lightdemo(); +#ifdef SYSTEM_573_SUPPORT +#define K573_WATCHDOG *((volatile uint16_t *) 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() { + K573_WATCHDOG = 0; +} + +void system573Setup() { + EnterCriticalSection(); + + EXP1_ADDR = 0x1f000000; + EXP1_DELAY_SIZE = K573_EXP1_CFG; + 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); + ExitCriticalSection(); +} +#endif void UploadTIM(TIM_IMAGE *tim) { @@ -197,9 +232,10 @@ void unpackModels() { } void init() { - - int i; - +#ifdef SYSTEM_573_SUPPORT + system573Setup(); +#endif + // Init display initDisplay(); diff --git a/examples/io/system573/CMakeLists.txt b/examples/io/system573/CMakeLists.txt index 1c74347..2a362e8 100644 --- a/examples/io/system573/CMakeLists.txt +++ b/examples/io/system573/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) project( system573 diff --git a/examples/lowlevel/cartrom/CMakeLists.txt b/examples/lowlevel/cartrom/CMakeLists.txt index 107cc3d..7d5e86e 100644 --- a/examples/lowlevel/cartrom/CMakeLists.txt +++ b/examples/lowlevel/cartrom/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) project( cartrom diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c index 6284c6d..6b9db93 100644 --- a/examples/sound/spustream/main.c +++ b/examples/sound/spustream/main.c @@ -308,6 +308,10 @@ void init_stream(CdlFILE *file) { CdReadyCallback(&cd_event_handler); ExitCriticalSection(); + // Configure the CD drive to read 2048-byte sectors at 2x speed. + uint8_t mode = CdlModeSpeed; + CdControl(CdlSetmode, (const uint8_t *) &mode, 0); + // Set the initial LBA of the stream file, which is going to be incremented // as the stream is played. str_ctx.lba = CdPosToInt(&(file->pos)); diff --git a/libpsn00b/include/elf.h b/libpsn00b/include/elf.h index b4c4408..abfb3d5 100644 --- a/libpsn00b/include/elf.h +++ b/libpsn00b/include/elf.h @@ -12,7 +12,7 @@ #ifndef __ELF_H #define __ELF_H -#include <sys/types.h> +#include <stdint.h> typedef enum { DT_NULL = 0, /* Marks end of dynamic section */ diff --git a/libpsn00b/libc/abort.c b/libpsn00b/libc/abort.c index 1d07037..de4323d 100644 --- a/libpsn00b/libc/abort.c +++ b/libpsn00b/libc/abort.c @@ -1,5 +1,8 @@ + #include <stdio.h> +/* Standard abort */ + void abort() { printf("abort()\n"); @@ -7,9 +10,20 @@ void abort() { __asm__ volatile(""); } +/* Internal function used by assert() macro */ + void _assert_abort(const char *file, int line, const char *expr) { printf("%s:%d: assert(%s)\n", file, line, expr); for (;;) __asm__ volatile(""); } + +/* Pure virtual function call (C++) */ + +void __cxa_pure_virtual(void) { + printf("__cxa_pure_virtual()\n"); + + for (;;) + __asm__ volatile(""); +} diff --git a/libpsn00b/libc/c++-support.cxx b/libpsn00b/libc/c++-support.cxx index d0c0f3a..38354dd 100644 --- a/libpsn00b/libc/c++-support.cxx +++ b/libpsn00b/libc/c++-support.cxx @@ -1,39 +1,46 @@ + #include <stdint.h> #include <stdlib.h> #include <stdio.h> -extern "C" void __cxa_pure_virtual(void) { - printf("__cxa_pure_virtual()\n"); - - for (;;) - __asm__ volatile(""); -} +/* Default new/delete operators */ -void* operator new(size_t size) { +void *operator new(size_t size) noexcept { return malloc(size); } -void* operator new[](size_t size) { +void *operator new[](size_t size) noexcept { return malloc(size); } -void operator delete(void* ptr) { +void operator delete(void *ptr) noexcept { free(ptr); } -void operator delete[](void* ptr) { +void operator delete[](void *ptr) noexcept { free(ptr); } -/*- - * <https://en.cppreference.com/w/cpp/memory/new/operator_delete> +/* + * https://en.cppreference.com/w/cpp/memory/new/operator_delete * * Called if a user-defined replacement is provided, except that it's * unspecified whether other overloads or this overload is called when deleting - * objects of incomplete type and arrays of non-class and trivially-destructible - * class types. + * objects of incomplete type and arrays of non-class and trivially + * destructible class types. * - * A memory allocator can use the given size to be more efficient */ -void operator delete(void* ptr, unsigned int) { + * A memory allocator can use the given size to be more efficient. + */ +void operator delete(void *ptr, size_t size) noexcept { free(ptr); } + +/* Placement new operators */ + +void *operator new(size_t size, void *ptr) noexcept { + return ptr; +} + +void *operator new[](size_t size, void *ptr) noexcept { + return ptr; +} diff --git a/libpsn00b/libc/putchar.s b/libpsn00b/libc/putchar.s deleted file mode 100644 index a3f6c57..0000000 --- a/libpsn00b/libc/putchar.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global putchar -.type putchar, @function -putchar: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x3c -
\ No newline at end of file |
