diff options
| author | John "Lameguy" Wilbert Villamor <lameguy64@gmail.com> | 2022-03-25 09:22:20 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-25 09:22:20 +0800 |
| commit | 975e614b3c840e2f717adac1d1cb9cee4e5e561b (patch) | |
| tree | 6584ce5b0dbe27a466c95c81fac61b0d90f627bd /libpsn00b | |
| parent | 05d44488bd5587786f4bd0286fc0f555c79aa46a (diff) | |
| parent | 45168ae43e29aa5930ee5a206475ae836078915f (diff) | |
| download | psn00bsdk-975e614b3c840e2f717adac1d1cb9cee4e5e561b.tar.gz | |
Merge pull request #46 from spicyjpeg/psxmdec
Critical ldscript fixes, initial MDEC support and CI updates
Diffstat (limited to 'libpsn00b')
116 files changed, 2089 insertions, 982 deletions
diff --git a/libpsn00b/CMakeLists.txt b/libpsn00b/CMakeLists.txt index 829a2f7..f9c4f9d 100644 --- a/libpsn00b/CMakeLists.txt +++ b/libpsn00b/CMakeLists.txt @@ -73,8 +73,17 @@ install( # Generate build.json. This file is used to determine the SDK version after # installation and may contain additional metadata about the build. -configure_file( - build.json.template build.json +file( + CONFIGURE + OUTPUT build.json + CONTENT [[{ + "version": "${PSN00BSDK_VERSION}", + "build_date": "${PSN00BSDK_BUILD_DATE}", + "git_tag": "${PSN00BSDK_GIT_TAG}", + "git_commit": "${PSN00BSDK_GIT_COMMIT}", + "cmake_version": "${CMAKE_VERSION}", + "host_system": "${CMAKE_HOST_SYSTEM_NAME}" +}]] ESCAPE_QUOTES NEWLINE_STYLE LF ) diff --git a/libpsn00b/build.json.template b/libpsn00b/build.json.template deleted file mode 100644 index 374b22a..0000000 --- a/libpsn00b/build.json.template +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": "${PSN00BSDK_VERSION}", - "build_date": "${PSN00BSDK_BUILD_DATE}", - "git_tag": "${PSN00BSDK_GIT_TAG}", - "git_commit": "${PSN00BSDK_GIT_COMMIT}", - "cmake_version": "${CMAKE_VERSION}", - "host_system": "${CMAKE_HOST_SYSTEM_NAME}" -} diff --git a/libpsn00b/cmake/flags.cmake b/libpsn00b/cmake/flags.cmake index 249c5b4..e31773f 100644 --- a/libpsn00b/cmake/flags.cmake +++ b/libpsn00b/cmake/flags.cmake @@ -5,10 +5,10 @@ # directories and compiler flags when a target is linked against them. The # following targets are currently defined: # - psn00bsdk_common -# - psn00bsdk_object_lib (same as psn00bsdk_common) # - psn00bsdk_static_exe # - psn00bsdk_dynamic_exe # - psn00bsdk_static_lib +# - psn00bsdk_object_lib (same as psn00bsdk_static_lib) # - psn00bsdk_shared_lib # - psn00bsdk_module_lib (same as psn00bsdk_shared_lib) # @@ -21,12 +21,7 @@ add_library(psn00bsdk_common INTERFACE) foreach( _target IN ITEMS - object_lib - static_exe - dynamic_exe - static_lib - shared_lib - module_lib + static_exe dynamic_exe static_lib object_lib shared_lib module_lib ) add_library (psn00bsdk_${_target} INTERFACE) target_link_libraries(psn00bsdk_${_target} INTERFACE psn00bsdk_common) @@ -128,6 +123,8 @@ target_compile_options( -Wa,--strip-local-absolute ) +target_link_libraries(psn00bsdk_object_lib INTERFACE psn00bsdk_static_lib) + # Options for dynamically-loaded libraries: # - Position-independent code enabled # - GP-relative addressing disabled (incompatible with ABI calls) diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index 7d6bfdd..d293127 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -26,7 +26,19 @@ set(PSN00BSDK_SYMBOL_MAP_SUFFIX ".map") ## SDK libraries # DON'T CHANGE THE ORDER or you'll break the libraries' internal dependencies. -set(PSN00BSDK_LIBRARIES psxgpu psxgte psxspu psxcd psxsio psxetc psxapi lzp c) +set( + PSN00BSDK_LIBRARIES + psxgpu + psxgte + psxspu + psxcd + psxpress + psxsio + psxetc + psxapi + lzp + c +) include(${CMAKE_CURRENT_LIST_DIR}/libpsn00b.cmake OPTIONAL) include(${CMAKE_CURRENT_LIST_DIR}/flags.cmake) @@ -166,12 +178,15 @@ function(psn00bsdk_add_cd_image name image_name config_file) message(FATAL_ERROR "Failed to locate mkpsxiso. If mkpsxiso wasn't installed alongside the SDK, check your PATH environment variable.") endif() - set(CD_IMAGE_NAME ${image_name}) - configure_file(${config_file} _gen_${config_file}) + cmake_path(HASH config_file _hash) + + set(CD_IMAGE_NAME ${image_name}) + set(CD_CONFIG_FILE cd_image_${_hash}.xml) + configure_file(${config_file} ${CD_CONFIG_FILE}) add_custom_target( ${name} ALL - COMMAND ${MKPSXISO} -y -q _gen_${config_file} + COMMAND ${MKPSXISO} -y ${CD_CONFIG_FILE} BYPRODUCTS ${image_name}.bin ${image_name}.cue COMMENT "Building CD image ${image_name}" ${ARGN} @@ -180,4 +195,72 @@ endfunction() ## Helper functions for assets -# TODO: add them +# psn00bsdk_target_incbin_a( +# <existing target name> <PRIVATE|PUBLIC|INTERFACE> +# <data symbol name> +# <size symbol name> +# <path to binary file> +# <linker section name> +# <alignment> +# ) +function(psn00bsdk_target_incbin_a name type symbol_name size_name path section align) + string(MAKE_C_IDENTIFIER ${symbol_name} _id) + string(MAKE_C_IDENTIFIER ${size_name} _size) + cmake_path(ABSOLUTE_PATH path OUTPUT_VARIABLE _path) + + # Generate an assembly source file that includes the binary file and add it + # to the target's sources. The file is also added as a depedency to ensure + # CMake builds it before the target (if it's not a static file). + set(_asm_file ${PROJECT_BINARY_DIR}/incbin_${name}_${_id}.s) + file( + CONFIGURE + OUTPUT ${_asm_file} + CONTENT [[ +.section ${section} +.balign ${align} + +.global ${_id} +.type ${_id}, @object +${_id}: + .incbin "${_path}" + +.local ${_id}_end +${_id}_end: + +.balign ${align} +.balign 4 + +.global ${_size} +.type ${_size}, @object +${_size}: + .int (${_id}_end - ${_id}) + +.size ${_id}, (${_id}_end - ${_id}) +.size ${_size}, 4 +]] + ESCAPE_QUOTES + NEWLINE_STYLE LF + ) + + target_sources(${name} ${type} ${_asm_file}) + set_source_files_properties(${_asm_file} PROPERTIES OBJECT_DEPENDS ${_path}) +endfunction() + +# psn00bsdk_target_incbin( +# <existing target name> <PRIVATE|PUBLIC|INTERFACE> +# <symbol name> +# <path to binary file> +# ) +function(psn00bsdk_target_incbin name type symbol_name path) + string(MAKE_C_IDENTIFIER ${symbol_name} _id) + + psn00bsdk_target_incbin_a( + ${name} + ${type} + ${_id} + ${_id}_size + ${path} + .data.${_id} + 4 + ) +endfunction() diff --git a/libpsn00b/include/assert.h b/libpsn00b/include/assert.h index 3114b57..e27f2ed 100644 --- a/libpsn00b/include/assert.h +++ b/libpsn00b/include/assert.h @@ -1,6 +1,20 @@ -#ifndef _ASSERT_H -#define _ASSERT_H +/* + * PSn00bSDK assert macro + * (C) 2022 spicyjpeg - MPL licensed + */ -void assert(int e); +#ifndef __ASSERT_H +#define __ASSERT_H -#endif
\ No newline at end of file +void _assert_abort(const char *file, int line, const char *expr); + +#ifdef DEBUG +#define assert(expr) { \ + if (!(expr)) \ + _assert_abort(__FILE__, __LINE__, #expr); \ +} +#else +#define assert(x) +#endif + +#endif diff --git a/libpsn00b/include/dlfcn.h b/libpsn00b/include/dlfcn.h index 6874d06..5848a95 100644 --- a/libpsn00b/include/dlfcn.h +++ b/libpsn00b/include/dlfcn.h @@ -1,19 +1,18 @@ /* * PSn00bSDK dynamic linker - * (C) 2021 spicyjpeg - MPL licensed + * (C) 2021-2022 spicyjpeg - MPL licensed */ #ifndef __DLFCN_H #define __DLFCN_H -#include <sys/types.h> +#include <stdint.h> #include <elf.h> /* Helper macro for setting $t9 before calling a function */ -#define DL_CALL(func, ...) { \ +#define DL_PRE_CALL(func) { \ __asm__ volatile("move $t9, %0;" :: "r"(func) : "$t9"); \ - func(__VA_ARGS__); \ } /* Types */ 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/include/hwregs_a.h b/libpsn00b/include/hwregs_a.h index 0680679..8a504f5 100644 --- a/libpsn00b/include/hwregs_a.h +++ b/libpsn00b/include/hwregs_a.h @@ -6,11 +6,13 @@ .set IOBASE, 0x1f80 # IO segment base -# GPU -.set GP0, 0x1810 # Also GPUREAD -.set GP1, 0x1814 # Also GPUSTAT +## GPU + +.set GPU_GP0, 0x1810 # Also GPUREAD +.set GPU_GP1, 0x1814 # Also GPUSTAT + +## CD drive -# CD .set CD_STAT, 0x1800 .set CD_CMD, 0x1801 # Also response FIFO .set CD_DATA, 0x1802 # Also parameters @@ -21,14 +23,14 @@ .set CD_REG2, 0x1802 .set CD_REG3, 0x1803 -.set SBUS_5, 0x1018 -.set COM_DELAY, 0x1020 +## SPU -# SPU (must be used with 16-bit load/store instructions) .set SPU_VOICE_BASE, 0x1c00 -.set SPU_MASTER_VOL, 0x1d80 -.set SPU_REVERB_VOL, 0x1d84 +.set SPU_MASTER_VOL_L, 0x1d80 +.set SPU_MASTER_VOL_R, 0x1d82 +.set SPU_REVERB_VOL_L, 0x1d84 +.set SPU_REVERB_VOL_R, 0x1d86 .set SPU_KEY_ON, 0x1d88 .set SPU_KEY_OFF, 0x1d8c .set SPU_FM_MODE, 0x1d90 @@ -41,81 +43,107 @@ .set SPU_ADDR, 0x1da6 .set SPU_DATA, 0x1da8 -.set SPUCNT, 0x1daa -.set SPUDTCNT, 0x1dac -.set SPUSTAT, 0x1dae +.set SPU_CTRL, 0x1daa +.set SPU_DMA_CTRL, 0x1dac +.set SPU_STAT, 0x1dae -.set SPU_CD_VOL, 0x1db0 -.set SPU_EXT_VOL, 0x1db4 -.set SPU_CURRENT_VOL, 0x1db8 +.set SPU_CD_VOL_L, 0x1db0 +.set SPU_CD_VOL_R, 0x1db2 +.set SPU_EXT_VOL_L, 0x1db4 +.set SPU_EXT_VOL_R, 0x1db6 +.set SPU_CURRENT_VOL_L, 0x1db8 +.set SPU_CURRENT_VOL_R, 0x1dba .set SPU_VOICE_VOL_L, 0x00 .set SPU_VOICE_VOL_R, 0x02 .set SPU_VOICE_FREQ, 0x04 .set SPU_VOICE_ADDR, 0x06 .set SPU_VOICE_ADSR_L, 0x08 -.set SPU_VOICE_ADSR_H, 0x0a +.set SPU_VOICE_ADSR_H, 0x0a .set SPU_VOICE_LOOP, 0x0e -# MDEC +## MDEC + .set MDEC0, 0x1820 .set MDEC1, 0x1824 -# Pads -.set JOY_TXRX, 0x1040 -.set JOY_STAT, 0x1044 -.set JOY_MODE, 0x1048 -.set JOY_CTRL, 0x104A -.set JOY_BAUD, 0x104E - -# Serial -.set SIO_TXRX, 0x1050 -.set SIO_STAT, 0x1054 -.set SIO_MODE, 0x1058 -.set SIO_CTRL, 0x105a -.set SIO_BAUD, 0x105e - -# IRQ -.set ISTAT, 0x1070 -.set IMASK, 0x1074 - -# DMA -.set DPCR, 0x10f0 -.set DICR, 0x10f4 - -.set D0_MADR, 0x1080 -.set D0_BCR, 0x1084 -.set D0_CHCR, 0x1088 - -.set D1_MADR, 0x1090 -.set D1_BCR, 0x1094 -.set D1_CHCR, 0x1098 - -.set D2_MADR, 0x10a0 -.set D2_BCR, 0x10a4 -.set D2_CHCR, 0x10a8 - -.set D3_MADR, 0x10b0 -.set D3_BCR, 0x10b4 -.set D3_CHCR, 0x10b8 - -.set D4_MADR, 0x10c0 -.set D4_BCR, 0x10c4 -.set D4_CHCR, 0x10c8 - -.set D6_MADR, 0x10e0 -.set D6_BCR, 0x10e4 -.set D6_CHCR, 0x10e8 - -# Timers -.set T0_CNT, 0x1100 -.set T0_MODE, 0x1104 -.set T0_TGT, 0x1108 - -.set T1_CNT, 0x1110 -.set T1_MODE, 0x1114 -.set T1_TGT, 0x1118 - -.set T2_CNT, 0x1120 -.set T2_MODE, 0x1124 -.set T2_TGT, 0x1128 +## SPI controller port + +.set JOY_TXRX, 0x1040 +.set JOY_STAT, 0x1044 +.set JOY_MODE, 0x1048 +.set JOY_CTRL, 0x104a +.set JOY_BAUD, 0x104e + +## Serial port + +.set SIO_TXRX, 0x1050 +.set SIO_STAT, 0x1054 +.set SIO_MODE, 0x1058 +.set SIO_CTRL, 0x105a +.set SIO_BAUD, 0x105e + +## IRQ controller + +.set IRQ_STAT, 0x1070 +.set IRQ_MASK, 0x1074 + +## DMA + +.set DMA_DPCR, 0x10f0 +.set DMA_DICR, 0x10f4 + +.set DMA0_MADR, 0x1080 +.set DMA0_BCR, 0x1084 +.set DMA0_CHCR, 0x1088 + +.set DMA1_MADR, 0x1090 +.set DMA1_BCR, 0x1094 +.set DMA1_CHCR, 0x1098 + +.set DMA2_MADR, 0x10a0 +.set DMA2_BCR, 0x10a4 +.set DMA2_CHCR, 0x10a8 + +.set DMA3_MADR, 0x10b0 +.set DMA3_BCR, 0x10b4 +.set DMA3_CHCR, 0x10b8 + +.set DMA4_MADR, 0x10c0 +.set DMA4_BCR, 0x10c4 +.set DMA4_CHCR, 0x10c8 + +.set DMA5_MADR, 0x10d0 +.set DMA5_BCR, 0x10d4 +.set DMA5_CHCR, 0x10d8 + +.set DMA6_MADR, 0x10e0 +.set DMA6_BCR, 0x10e4 +.set DMA6_CHCR, 0x10e8 + +## Timers + +.set TIMER0_VALUE, 0x1100 +.set TIMER0_CTRL, 0x1104 +.set TIMER0_RELOAD, 0x1108 + +.set TIMER1_VALUE, 0x1110 +.set TIMER1_CTRL, 0x1114 +.set TIMER1_RELOAD, 0x1118 + +.set TIMER2_VALUE, 0x1120 +.set TIMER2_CTRL, 0x1124 +.set TIMER2_RELOAD, 0x1128 + +## Memory control + +.set EXP1_ADDR, 0x1000 +.set EXP2_ADDR, 0x1004 +.set EXP1_DELAY_SIZE, 0x1008 +.set EXP3_DELAY_SIZE, 0x100c +.set BIOS_DELAY_SIZE, 0x1010 +.set SPU_DELAY_SIZE, 0x1014 +.set CD_DELAY_SIZE, 0x1018 +.set EXP2_DELAY_SIZE, 0x101c +.set COM_DELAY_CFG, 0x1020 +.set RAM_SIZE_CFG, 0x1060 diff --git a/libpsn00b/include/hwregs_c.h b/libpsn00b/include/hwregs_c.h new file mode 100644 index 0000000..e533c56 --- /dev/null +++ b/libpsn00b/include/hwregs_c.h @@ -0,0 +1,129 @@ +/* + * PSn00bSDK hardware registers definitions + * (C) 2022 spicyjpeg - MPL licensed + */ + +#ifndef __HWREGS_C_H +#define __HWREGS_C_H + +#include <stdint.h> + +#define _MMIO8(addr) *((volatile uint8_t *) (addr)) +#define _MMIO16(addr) *((volatile uint16_t *) (addr)) +#define _MMIO32(addr) *((volatile uint32_t *) (addr)) + +/* Constants */ + +#define F_CPU 33868800UL +#define F_GPU 53222400UL + +/* GPU */ + +#define GPU_GP0 _MMIO32(0x1f801810) +#define GPU_GP1 _MMIO32(0x1f801814) + +/* CD drive */ + +#define CD_STAT _MMIO8(0x1f801800) +#define CD_CMD _MMIO8(0x1f801801) +#define CD_DATA _MMIO8(0x1f801802) +#define CD_IRQ _MMIO8(0x1f801803) + +#define CD_REG(N) _MMIO8(0x1f801800 + (N)) + +/* SPU */ + +#define SPU_MASTER_VOL_L _MMIO16(0x1f801d80) +#define SPU_MASTER_VOL_R _MMIO16(0x1f801d82) +#define SPU_REVERB_VOL_L _MMIO16(0x1f801d84) +#define SPU_REVERB_VOL_R _MMIO16(0x1f801d86) +#define SPU_KEY_ON _MMIO32(0x1f801d88) +#define SPU_KEY_OFF _MMIO32(0x1f801d8c) +#define SPU_FM_MODE _MMIO32(0x1f801d90) +#define SPU_NOISE_MODE _MMIO32(0x1f801d94) +#define SPU_REVERB_ON _MMIO32(0x1f801d98) +#define SPU_CHAN_STATUS _MMIO32(0x1f801d9c) + +#define SPU_REVERB_ADDR _MMIO16(0x1f801da2) +#define SPU_IRQ_ADDR _MMIO16(0x1f801da4) +#define SPU_ADDR _MMIO16(0x1f801da6) +#define SPU_DATA _MMIO16(0x1f801da8) + +#define SPU_CTRL _MMIO16(0x1f801daa) +#define SPU_DMA_CTRL _MMIO16(0x1f801dac) +#define SPU_STAT _MMIO16(0x1f801dae) + +#define SPU_CD_VOL_L _MMIO16(0x1f801db0) +#define SPU_CD_VOL_R _MMIO16(0x1f801db2) +#define SPU_EXT_VOL_L _MMIO16(0x1f801db4) +#define SPU_EXT_VOL_R _MMIO16(0x1f801db6) +#define SPU_CURRENT_VOL_L _MMIO16(0x1f801db8) +#define SPU_CURRENT_VOL_R _MMIO16(0x1f801dba) + +// These are not named SPU_VOICE_* to avoid name clashes with SPU attribute +// flags defined in psxspu.h. +#define SPU_CH_VOL_L(N) _MMIO16(0x1f801c00 + 16 * (N)) +#define SPU_CH_VOL_R(N) _MMIO16(0x1f801c02 + 16 * (N)) +#define SPU_CH_FREQ(N) _MMIO16(0x1f801c04 + 16 * (N)) +#define SPU_CH_ADDR(N) _MMIO16(0x1f801c06 + 16 * (N)) +#define SPU_CH_ADSR(N) _MMIO32(0x1f801c08 + 16 * (N)) +#define SPU_CH_LOOP_ADDR(N) _MMIO16(0x1f801c0e + 16 * (N)) + +/* MDEC */ + +#define MDEC0 _MMIO32(0x1f801820) +#define MDEC1 _MMIO32(0x1f801824) + +/* SPI controller port */ + +// IMPORTANT: even though JOY_TXRX is a 32-bit register, it should only be +// accessed as 8-bit. Reading it as 16 or 32-bit works fine on real hardware, +// but leads to problems in some emulators. +#define JOY_TXRX _MMIO8(0x1f801040) +#define JOY_STAT _MMIO16(0x1f801044) +#define JOY_MODE _MMIO16(0x1f801048) +#define JOY_CTRL _MMIO16(0x1f80104a) +#define JOY_BAUD _MMIO16(0x1f80104e) + +/* Serial port */ + +#define SIO_TXRX _MMIO8(0x1f801050) +#define SIO_STAT _MMIO16(0x1f801054) +#define SIO_MODE _MMIO16(0x1f801058) +#define SIO_CTRL _MMIO16(0x1f80105a) +#define SIO_BAUD _MMIO16(0x1f80105e) + +/* IRQ controller */ + +#define IRQ_STAT _MMIO32(0x1f801070) +#define IRQ_MASK _MMIO32(0x1f801074) + +/* DMA */ + +#define DMA_DPCR _MMIO32(0x1f8010f0) +#define DMA_DICR _MMIO32(0x1f8010f4) + +#define DMA_MADR(N) _MMIO32(0x1f801080 + 16 * (N)) +#define DMA_BCR(N) _MMIO32(0x1f801084 + 16 * (N)) +#define DMA_CHCR(N) _MMIO32(0x1f801088 + 16 * (N)) + +/* Timers */ + +#define TIMER_VALUE(N) _MMIO32(0x1f801100 + 16 * (N)) +#define TIMER_CTRL(N) _MMIO32(0x1f801104 + 16 * (N)) +#define TIMER_RELOAD(N) _MMIO32(0x1f801108 + 16 * (N)) + +/* Memory control */ + +#define EXP1_ADDR _MMIO32(0x1f801000) +#define EXP2_ADDR _MMIO32(0x1f801004) +#define EXP1_DELAY_SIZE _MMIO32(0x1f801008) +#define EXP3_DELAY_SIZE _MMIO32(0x1f80100c) +#define BIOS_DELAY_SIZE _MMIO32(0x1f801010) +#define SPU_DELAY_SIZE _MMIO32(0x1f801014) +#define CD_DELAY_SIZE _MMIO32(0x1f801018) +#define EXP2_DELAY_SIZE _MMIO32(0x1f80101c) +#define COM_DELAY_CFG _MMIO32(0x1f801020) +#define RAM_SIZE_CFG _MMIO32(0x1f801060) + +#endif diff --git a/libpsn00b/include/psxapi.h b/libpsn00b/include/psxapi.h index ec0dfea..1298d29 100644 --- a/libpsn00b/include/psxapi.h +++ b/libpsn00b/include/psxapi.h @@ -121,6 +121,12 @@ struct EXEC { unsigned int sp,fp,rp,ret,base; }; +struct JMP_BUF { + unsigned int ra, sp, fp; + unsigned int s0, s1, s2, s3, s4, s5, s6, s7; + unsigned int gp; +}; + // Not recommended to use these functions to install IRQ handlers typedef struct { @@ -211,8 +217,19 @@ void ChangeClearRCnt(int t, int m); int Exec(struct EXEC *exec, int argc, char **argv); void FlushCache(void); +// BIOS setjmp functions +void b_setjmp(struct JMP_BUF *buf); +void b_longjmp(struct JMP_BUF *buf, int param); +void SetDefaultExitFromException(void); +void SetCustomExitFromException(struct JMP_BUF *buf); + // Misc functions int GetSystemInfo(int index); +void *GetB0Table(void); +void *GetC0Table(void); + +void *_kernel_malloc(int size); +void _kernel_free(void *ptr); void _boot(void); 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) diff --git a/libpsn00b/include/psxpress.h b/libpsn00b/include/psxpress.h new file mode 100644 index 0000000..b060170 --- /dev/null +++ b/libpsn00b/include/psxpress.h @@ -0,0 +1,153 @@ +/* + * PSn00bSDK MDEC library + * (C) 2022 spicyjpeg - MPL licensed + */ + +#ifndef __PSXPRESS_H +#define __PSXPRESS_H + +#include <stdint.h> +#include <stddef.h> + +/* Structure definitions */ + +typedef struct _DECDCTENV { + uint8_t iq_y[64]; // Luma quantization table, stored in zigzag order + uint8_t iq_c[64]; // Chroma quantization table, stored in zigzag order + int16_t dct[64]; // Inverse DCT matrix (2.14 fixed-point) +} DECDCTENV; + +typedef enum _DECDCTMODE { + DECDCT_MODE_24BPP = 1, + DECDCT_MODE_16BPP = 0, + DECDCT_MODE_16BPP_BIT15 = 2, + DECDCT_MODE_RAW = -1 +} DECDCTMODE; + +/* Public API */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Resets the MDEC and aborts any MDEC DMA transfers. If mode = 0, the + * default IDCT matrix and quantization tables are also loaded and the MDEC is + * put into color output mode, discarding any custom environment previously set + * with DecDCTPutEnv(). + * + * DecDCTReset(0) must be called at least once prior to using the MDEC. + * + * @param mode + */ +void DecDCTReset(int32_t mode); + +/** + * @brief Uploads the specified decoding environment's quantization tables and + * IDCT matrix to the MDEC, or restores the default tables if a null pointer is + * passed. Calling this function is normally not required as DecDCTReset(0) + * initializes the MDEC with the default tables, but it may be useful for e.g. + * decoding JPEG or a format with custom quantization tables. + * + * The second argument, not present in the official SDK, specifies whether the + * MDEC shall be put into color (0) or monochrome (1) output mode. In + * monochrome mode each DCT block decoded from the input stream is transformed + * into an 8x8x8bpp bitmap, while in color mode each group of 6 DCT blocks (Cr, + * Cb, Y1-4) is used to form a 16x16 RGB bitmap. + * + * This function uses DecDCTinSync() to wait for the MDEC to become ready and + * should not be called during decoding or after calling DecDCTin(). + * + * @param env Pointer to DECDCTENV or 0 for default tables + * @param mono 0 for color (normal), 1 for monochrome + */ +void DecDCTPutEnv(const DECDCTENV *env, int32_t mono); + +/** + * @brief Sets up the MDEC to start fetching and decoding a stream from the + * given address in main RAM. The first 32-bit word is initially copied to the + * MDEC0 register, then all subsequent data is read in 128-byte (32-word) + * chunks. The length of the stream (in 32-bit units, minus the first word) + * must be encoded in the lower 16 bits of the first word, as expected by the + * MDEC. + * + * The mode argument optionally specifies the output color depth (0 for 16bpp, + * 1 for 24bpp) if not already set in the first word. Passing -1 will result in + * DecDCTin() copying the first word as-is to MDEC0 without manipulating any of + * its bits. + * + * @param data + * @param mode DECDCT_MODE_* or -1 + */ +void DecDCTin(const uint32_t *data, int32_t mode); + +/** + * @brief Configures the MDEC to automatically fetch data (the input stream, + * IDCT matrix or quantization tables) in 128-byte (32-word) chunks from the + * specified address in main RAM. The transfer is stopped, and any callback + * registered with DMACallback(0) is fired, once a certain number of 32-bit + * words have been read; usually the length should match the number of input + * words expected by the MDEC. If the MDEC expects more data its operation will + * be paused and can be resumed by calling DecDCTinRaw() again. + * + * This is a low-level variant of DecDCTin() that only sets up the DMA transfer + * and does not write anything to the MDEC0 register. The actual transfer won't + * start until the MDEC is given a valid command. + * + * @param data + * @param length Number of 32-bit words to read (must be multiple of 32) + */ +void DecDCTinRaw(const uint32_t *data, size_t length); + +/** + * @brief Waits for the MDEC to finish decoding the input stream (if mode = 0) + * or returns whether it is busy (if mode = 1). MDEC commands can be issued + * only when the MDEC isn't busy. + * + * WARNING: DecDCTinSync(0) might time out and return -1 if the MDEC can't + * output decoded data, e.g. if the length passed DecDCTout() was too small and + * no callback is registered to set up further transfers. DecDCTinSync(0) shall + * only be used alongside DMACallback(1) or if the entirety of the decoded + * stream (usually a whole frame) is being written to main RAM. + * + * @param mode + * @return 0 or -1 in case of a timeout (mode = 0) / MDEC busy flag (mode = 1) + */ +int32_t DecDCTinSync(int32_t mode); + +/** + * @brief Configures the MDEC to automatically transfer decoded image data in + * 128-byte (32-word) chunks to the specified address in main RAM. MDEC + * operation is paused once a certain number of 32-bit words have been output + * and can be resumed by calling DecDCTout() again: the MDEC will continue + * decoding the input stream from where it left off. Any callback registered + * with DMACallback(1) is also fired whenever the transfer ends. + * + * This behavior allows the MDEC's output to be buffered into 16-pixel-wide + * vertical strips in main RAM, which can then be uploaded to VRAM using + * LoadImage(). + * + * @param data + * @param length Number of 32-bit words to output (must be multiple of 32) + */ +void DecDCTout(uint32_t *data, size_t length); + +/** + * @brief Waits until the transfer set up by DecDCTout() finishes (if mode = 0) + * or returns whether it is still in progress (if mode = 1). + * + * WARNING: DecDCToutSync(0) might time out and return -1 if the MDEC is unable + * to consume enough input data in order to produce the desired amount of data. + * If the input stream isn't contiguous in memory, DMACallback(0) shall be used + * to register a callback that calls DecDCTin() to feed the MDEC. + * + * @param mode + * @return 0 or -1 in case of a timeout (mode = 0) / DMA busy flag (mode = 1) + */ +int32_t DecDCToutSync(int32_t mode); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libpsn00b/include/stdint.h b/libpsn00b/include/stdint.h deleted file mode 100644 index 83acb00..0000000 --- a/libpsn00b/include/stdint.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _STDINT_H -#define _STDINT_H - -typedef unsigned int size_t; - -typedef char int8_t; -typedef short int16_t; -typedef int int32_t; -typedef long long int64_t; - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; - -#endif // _STDINT_H
\ No newline at end of file diff --git a/libpsn00b/include/stdlib.h b/libpsn00b/include/stdlib.h index de3ab47..4c4fcd3 100644 --- a/libpsn00b/include/stdlib.h +++ b/libpsn00b/include/stdlib.h @@ -38,16 +38,13 @@ long labs(long i); long long strtoll(const char *nptr, char **endptr, int base); long strtol(const char *nptr, char **endptr, int base); long double strtold(const char *nptr, char **endptr); -// BIOS temporary -int atoi(const char *s); -long atol(const char *s); // Note: these use floats internally! double strtod(const char *nptr, char **endptr); float strtof(const char *nptr, char **endptr); // Memory allocation functions -unsigned int *GetBSSend(); +void _mem_init(int ram_size, int stack_max_size); void InitHeap(unsigned int *addr, int size); int SetHeapSize(int size); void *malloc(int size); diff --git a/libpsn00b/ldscripts/dll.ld b/libpsn00b/ldscripts/dll.ld index a03a504..15158e4 100644 --- a/libpsn00b/ldscripts/dll.ld +++ b/libpsn00b/ldscripts/dll.ld @@ -86,6 +86,7 @@ SECTIONS { * as we don't have to worry about managing .bss separately from the * main DLL blob. */ + . = ALIGN((. != 0) ? 4 : 1); __bss_start = .; *(.bss .bss.* .gnu.linkonce.b.*) diff --git a/libpsn00b/ldscripts/exe.ld b/libpsn00b/ldscripts/exe.ld index c6b9f29..583d76a 100644 --- a/libpsn00b/ldscripts/exe.ld +++ b/libpsn00b/ldscripts/exe.ld @@ -82,6 +82,11 @@ SECTIONS { /* BSS sections, i.e. uninitialized variables */ + /* + * Align all BSS sections to 4 bytes to ensure _start() doesn't perform + * unaligned memory accesses when clearing them. + */ + . = ALIGN((. != 0) ? 4 : 1); __bss_start = .; .sbss (NOLOAD) : { @@ -91,13 +96,9 @@ SECTIONS { .bss (NOLOAD) : { *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) - - /* - * This crap was in the stock GCC linker script. - */ - . = ALIGN((. != 0) ? 4 : 1); } > APP_RAM + . = ALIGN((. != 0) ? 4 : 1); _end = .; /* Dummy section */ diff --git a/libpsn00b/libc/abort.c b/libpsn00b/libc/abort.c index ca5ab1d..de4323d 100644 --- a/libpsn00b/libc/abort.c +++ b/libpsn00b/libc/abort.c @@ -1,9 +1,29 @@ + #include <stdio.h> -void abort() { +/* Standard abort */ +void abort() { printf("abort()\n"); - - while(1); -}
\ No newline at end of file + for (;;) + __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 d169fdb..38354dd 100644 --- a/libpsn00b/libc/c++-support.cxx +++ b/libpsn00b/libc/c++-support.cxx @@ -1,39 +1,46 @@ -#include <assert.h> + #include <stdint.h> #include <stdlib.h> +#include <stdio.h> -extern "C" - -void __cxa_pure_virtual(void) { - /* Pure C++ virtual call; abort! */ - assert(false); -} +/* Default new/delete operators */ -void* operator new(size_t size) { - return malloc(size); +void *operator new(size_t size) noexcept { + return malloc(size); } -void* operator new[](size_t size) { - return malloc(size); +void *operator new[](size_t size) noexcept { + return malloc(size); } -void operator delete(void* ptr) { - free(ptr); +void operator delete(void *ptr) noexcept { + free(ptr); } -void operator delete[](void* ptr) { - free(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) { - free(ptr); -}
\ No newline at end of file + * 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 diff --git a/libpsn00b/libc/start.c b/libpsn00b/libc/start.c index f190794..fd6fe33 100644 --- a/libpsn00b/libc/start.c +++ b/libpsn00b/libc/start.c @@ -6,19 +6,20 @@ #include <stdint.h> #include <string.h> #include <stdlib.h> +#include <stddef.h> -#define KERNEL_ARG_STRING ((const char *) 0x80000180) -#define KERNEL_RETURN_VALUE ((volatile int *) 0x8000dffc) +#define KERNEL_ARG_STRING ((const char *) 0x80000180) +#define KERNEL_RETURN_VALUE ((volatile int *) 0x8000dffc) /* Argument parsing */ -int32_t __argc; -const char **__argv; +int __argc; +const char **__argv; #define ARGC_MAX 16 -static const char *_argv_buffer[ARGC_MAX]; -static char _arg_string_buffer[132]; +static const char *_argv_buffer[ARGC_MAX]; +static char _arg_string_buffer[132]; static void _parse_kernel_args() { // Copy the argument string from kernel memory into a private buffer (which @@ -61,10 +62,10 @@ extern uint8_t _end[]; // useful though to change the stack size and/or reinitialize the heap on // systems that have more than 2 MB of RAM (e.g. emulators, devkits, PS1-based // arcade boards). -void _mem_init(size_t ram_size, size_t stack_max_size) { - void *exe_end = _end + 4; - size_t exe_size = (size_t) exe_end - (size_t) __text_start; - size_t ram_used = (0x10000 + exe_size + stack_max_size) & 0xfffffffc; +void _mem_init(int ram_size, int stack_max_size) { + void *exe_end = _end + 4; + int exe_size = (int) exe_end - (int) __text_start; + int ram_used = (0x10000 + exe_size + stack_max_size) & 0xfffffffc; InitHeap(exe_end, ram_size - ram_used); } @@ -74,7 +75,7 @@ void _mem_init(size_t ram_size, size_t stack_max_size) { extern void (*__CTOR_LIST__[])(void); extern void (*__DTOR_LIST__[])(void); -extern int32_t main(int32_t argc, const char* argv[]); +extern int main(int argc, const char* argv[]); // Even though _start() usually takes no arguments, this implementation allows // parent executables to pass args directly to child executables without having diff --git a/libpsn00b/psxapi/fs/_InitCd.s b/libpsn00b/psxapi/_initcd.s index decf2bd..c3a2861 100644 --- a/libpsn00b/psxapi/fs/_InitCd.s +++ b/libpsn00b/psxapi/_initcd.s @@ -11,7 +11,7 @@ _InitCd: lui $a0, IOBASE # Load IOBASE value - lw $v0, DPCR($a0) # Get current DMA settings + lw $v0, DMA_DPCR($a0) # Get current DMA settings nop sw $v0, 4($sp) # Save to stack @@ -21,14 +21,14 @@ _InitCd: lui $a0, IOBASE # Load IOBASE again lw $v0, 4($sp) # Get old DMA control settings - lw $v1, DPCR($a0) # Get DMA settings by _96_init() + lw $v1, DMA_DPCR($a0) # Get DMA settings by _96_init() lui $a1, 0xffff # Mask out settings for CD DMA ori $a1, 0x0f00 and $v0, $a1 or $v0, $v1 # Merge and set new DMA settings - sw $v0, DPCR($a0) + sw $v0, DMA_DPCR($a0) lw $ra, 0($sp) addiu $sp, 8 diff --git a/libpsn00b/psxapi/drivers.s b/libpsn00b/psxapi/drivers.s new file mode 100644 index 0000000..1cf5050 --- /dev/null +++ b/libpsn00b/psxapi/drivers.s @@ -0,0 +1,164 @@ +# PSn00bSDK BIOS API stubs +# (C) 2022 spicyjpeg - MPL licensed + +# This file has been generated automatically. Each function is placed in its +# own section to allow the linker to strip unused functions. + +.set noreorder + +## A0 table functions (7) + +.section .text._bu_init +.global _bu_init +.type _bu_init, @function +_bu_init: + li $t2, 0xa0 + jr $t2 + li $t1, 0x55 + +.section .text._96_init +.global _96_init +.type _96_init, @function +_96_init: + li $t2, 0xa0 + jr $t2 + li $t1, 0x71 + +.section .text._96_remove +.global _96_remove +.type _96_remove, @function +_96_remove: + li $t2, 0xa0 + jr $t2 + li $t1, 0x72 + +.section .text.AddDummyTty +.global AddDummyTty +.type AddDummyTty, @function +AddDummyTty: + li $t2, 0xa0 + jr $t2 + li $t1, 0x99 + +.section .text._card_info +.global _card_info +.type _card_info, @function +_card_info: + li $t2, 0xa0 + jr $t2 + li $t1, 0xab + +.section .text._card_load +.global _card_load +.type _card_load, @function +_card_load: + li $t2, 0xa0 + jr $t2 + li $t1, 0xac + +.section .text._card_clear +.global _card_clear +.type _card_clear, @function +_card_clear: + li $t2, 0xa0 + jr $t2 + li $t1, 0xaf + +## B0 table functions (12) + +.section .text.AddDev +.global AddDev +.type AddDev, @function +AddDev: + li $t2, 0xb0 + jr $t2 + li $t1, 0x47 + +.section .text.DelDev +.global DelDev +.type DelDev, @function +DelDev: + li $t2, 0xb0 + jr $t2 + li $t1, 0x48 + +.section .text.ListDev +.global ListDev +.type ListDev, @function +ListDev: + li $t2, 0xb0 + jr $t2 + li $t1, 0x49 + +.section .text.InitCard +.global InitCard +.type InitCard, @function +InitCard: + li $t2, 0xb0 + jr $t2 + li $t1, 0x4a + +.section .text.StartCard +.global StartCard +.type StartCard, @function +StartCard: + li $t2, 0xb0 + jr $t2 + li $t1, 0x4b + +.section .text.StopCard +.global StopCard +.type StopCard, @function +StopCard: + li $t2, 0xb0 + jr $t2 + li $t1, 0x4c + +.section .text._card_write +.global _card_write +.type _card_write, @function +_card_write: + li $t2, 0xb0 + jr $t2 + li $t1, 0x4e + +.section .text._card_read +.global _card_read +.type _card_read, @function +_card_read: + li $t2, 0xb0 + jr $t2 + li $t1, 0x4f + +.section .text._new_card +.global _new_card +.type _new_card, @function +_new_card: + li $t2, 0xb0 + jr $t2 + li $t1, 0x50 + +.section .text._card_chan +.global _card_chan +.type _card_chan, @function +_card_chan: + li $t2, 0xb0 + jr $t2 + li $t1, 0x58 + +.section .text._card_status +.global _card_status +.type _card_status, @function +_card_status: + li $t2, 0xb0 + jr $t2 + li $t1, 0x5c + +.section .text._card_wait +.global _card_wait +.type _card_wait, @function +_card_wait: + li $t2, 0xb0 + jr $t2 + li $t1, 0x5d + diff --git a/libpsn00b/psxapi/fs.s b/libpsn00b/psxapi/fs.s new file mode 100644 index 0000000..f225d64 --- /dev/null +++ b/libpsn00b/psxapi/fs.s @@ -0,0 +1,50 @@ +# PSn00bSDK BIOS API stubs +# (C) 2022 spicyjpeg - MPL licensed + +# This file has been generated automatically. Each function is placed in its +# own section to allow the linker to strip unused functions. + +.set noreorder + +## B0 table functions (5) + +.section .text.chdir +.global chdir +.type chdir, @function +chdir: + li $t2, 0xb0 + jr $t2 + li $t1, 0x40 + +.section .text.firstfile +.global firstfile +.type firstfile, @function +firstfile: + li $t2, 0xb0 + jr $t2 + li $t1, 0x42 + +.section .text.nextfile +.global nextfile +.type nextfile, @function +nextfile: + li $t2, 0xb0 + jr $t2 + li $t1, 0x43 + +.section .text.rename +.global rename +.type rename, @function +rename: + li $t2, 0xb0 + jr $t2 + li $t1, 0x44 + +.section .text.erase +.global erase +.type erase, @function +erase: + li $t2, 0xb0 + jr $t2 + li $t1, 0x45 + diff --git a/libpsn00b/psxapi/fs/_96_init.s b/libpsn00b/psxapi/fs/_96_init.s deleted file mode 100644 index ac35d6b..0000000 --- a/libpsn00b/psxapi/fs/_96_init.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _96_init -.type _96_init, @function -_96_init: - addiu $t2, $0 , 0xa0 - jr $t2 - addiu $t1, $0 , 0x71 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/fs/_96_remove.s b/libpsn00b/psxapi/fs/_96_remove.s deleted file mode 100644 index a65c0ba..0000000 --- a/libpsn00b/psxapi/fs/_96_remove.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _96_remove -.type _96_remove, @function -_96_remove: - addiu $t2, $0 , 0xa0 - jr $t2 - addiu $t1, $0 , 0x72 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/fs/chdir.s b/libpsn00b/psxapi/fs/chdir.s deleted file mode 100644 index 83abf70..0000000 --- a/libpsn00b/psxapi/fs/chdir.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global chdir -.type chdir, @function -chdir: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x40 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/fs/erase.s b/libpsn00b/psxapi/fs/erase.s deleted file mode 100644 index 0ddd05f..0000000 --- a/libpsn00b/psxapi/fs/erase.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global erase -.type erase, @function -erase: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x45 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/fs/firstfile.s b/libpsn00b/psxapi/fs/firstfile.s deleted file mode 100644 index 2d1c1cd..0000000 --- a/libpsn00b/psxapi/fs/firstfile.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global firstfile -.type firstfile, @function -firstfile: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x42 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/fs/nextfile.s b/libpsn00b/psxapi/fs/nextfile.s deleted file mode 100644 index 51a285a..0000000 --- a/libpsn00b/psxapi/fs/nextfile.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global nextfile -.type nextfile, @function -nextfile: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x43 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/fs/rename.s b/libpsn00b/psxapi/fs/rename.s deleted file mode 100644 index 5815dba..0000000 --- a/libpsn00b/psxapi/fs/rename.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global rename -.type rename, @function -rename: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x44 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/generate_stubs.py b/libpsn00b/psxapi/generate_stubs.py new file mode 100644 index 0000000..9db60de --- /dev/null +++ b/libpsn00b/psxapi/generate_stubs.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 +# PSn00bSDK BIOS stub generator +# (C) 2022 spicyjpeg - MPL licensed + +import os, sys, json +from argparse import ArgumentParser, FileType + +## Listing section generation + +SECTION_TEMPLATE = """## {title} ({count}) + +{body}""" +FUNCTION_TEMPLATE = """.section .text.{name} +.global {name} +.type {name}, @function +{name}: + li $t2, 0x{address:02x} + jr $t2 + li $t1, 0x{id:02x} + +""" +SYSCALL_TEMPLATE = """.section .text.{name} +.global {name} +.type {name}, @function +{name}: + li $a0, 0x{id:02x} + syscall 0 + jr $ra + nop + +""" + +STUB_TYPES = { + "a": ( 0xa0, FUNCTION_TEMPLATE, "A0 table functions" ), + "b": ( 0xb0, FUNCTION_TEMPLATE, "B0 table functions" ), + "c": ( 0xc0, FUNCTION_TEMPLATE, "C0 table functions" ), + "syscall": ( 0x00, SYSCALL_TEMPLATE, "Syscalls" ) +} + +def generate_section(_type, entries): + address, template, title = STUB_TYPES[_type] + body = "" + + for entry in entries: + if entry.get("comment", None): + body += f"# {entry['comment'].strip()}\n" + + body += template.format( + name = entry["name"].strip(), + address = address, + id = entry["id"] + ) + + return SECTION_TEMPLATE.format( + title = title, + count = len(entries), + body = body + ) + +## Main + +HEADER_TEMPLATE = """# PSn00bSDK BIOS API stubs +# (C) 2022 spicyjpeg - MPL licensed + +# This file has been generated automatically. Each function is placed in its +# own section to allow the linker to strip unused functions. + +.set noreorder + +""" + +def get_args(): + parser = ArgumentParser( + description = "Generates MIPS assembly listings of BIOS API stubs." + ) + parser.add_argument( + "json_list", + type = FileType("rt"), + help = "path to JSON list of stubs to generate" + ) + parser.add_argument( + "-o", "--output", + type = str, + default = os.curdir, + help = "where to save generated files (current directory by default)", + metavar = "directory" + ) + + return parser.parse_args() + +def main(): + args = get_args() + + with args.json_list as _file: + all_entries = json.load(_file) + + # { file: { type: [ entry, ... ], ... }, ... } + files = {} + + # Sort all functions by the file they are going to be put in, and by the + # type within the file. + for entry in all_entries: + _type = entry["type"].strip().lower() + _file = entry["file"].strip() + + if type(entry["id"]) is str: + entry["id"] = int(entry["id"], 0) + + if _file not in files: + files[_file] = { _type: [] for _type in STUB_TYPES.keys() } + + files[_file][_type].append(entry) + + for path, types in files.items(): + full_path = os.path.normpath(os.path.join(args.output, path)) + listing = HEADER_TEMPLATE + + for _type, entries in types.items(): + if not entries: + continue + + entries.sort(key = lambda entry: entry["id"]) + listing += generate_section(_type, entries) + + with open(full_path, "wt", newline = "\n") as _file: + _file.write(listing) + +if __name__ == "__main__": + main() diff --git a/libpsn00b/psxapi/stdio.s b/libpsn00b/psxapi/stdio.s new file mode 100644 index 0000000..e65f871 --- /dev/null +++ b/libpsn00b/psxapi/stdio.s @@ -0,0 +1,114 @@ +# PSn00bSDK BIOS API stubs +# (C) 2022 spicyjpeg - MPL licensed + +# This file has been generated automatically. Each function is placed in its +# own section to allow the linker to strip unused functions. + +.set noreorder + +## A0 table functions (13) + +.section .text.open +.global open +.type open, @function +open: + li $t2, 0xa0 + jr $t2 + li $t1, 0x00 + +.section .text.seek +.global seek +.type seek, @function +seek: + li $t2, 0xa0 + jr $t2 + li $t1, 0x01 + +.section .text.read +.global read +.type read, @function +read: + li $t2, 0xa0 + jr $t2 + li $t1, 0x02 + +.section .text.write +.global write +.type write, @function +write: + li $t2, 0xa0 + jr $t2 + li $t1, 0x03 + +.section .text.close +.global close +.type close, @function +close: + li $t2, 0xa0 + jr $t2 + li $t1, 0x04 + +.section .text.ioctl +.global ioctl +.type ioctl, @function +ioctl: + li $t2, 0xa0 + jr $t2 + li $t1, 0x05 + +.section .text.getc +.global getc +.type getc, @function +getc: + li $t2, 0xa0 + jr $t2 + li $t1, 0x08 + +.section .text.putc +.global putc +.type putc, @function +putc: + li $t2, 0xa0 + jr $t2 + li $t1, 0x09 + +.section .text.getchar +.global getchar +.type getchar, @function +getchar: + li $t2, 0xa0 + jr $t2 + li $t1, 0x3b + +.section .text.putchar +.global putchar +.type putchar, @function +putchar: + li $t2, 0xa0 + jr $t2 + li $t1, 0x3c + +.section .text.gets +.global gets +.type gets, @function +gets: + li $t2, 0xa0 + jr $t2 + li $t1, 0x3d + +.section .text.puts +.global puts +.type puts, @function +puts: + li $t2, 0xa0 + jr $t2 + li $t1, 0x3e + +.section .text.printf +.global printf +.type printf, @function +printf: + li $t2, 0xa0 + jr $t2 + li $t1, 0x3f + diff --git a/libpsn00b/psxapi/stdio/atoi.s b/libpsn00b/psxapi/stdio/atoi.s deleted file mode 100644 index 74c4ae7..0000000 --- a/libpsn00b/psxapi/stdio/atoi.s +++ /dev/null @@ -1,9 +0,0 @@ -.set noreorder -.section .text - -.global atoi -.type atoi, @function -atoi: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x10 diff --git a/libpsn00b/psxapi/stdio/atol.s b/libpsn00b/psxapi/stdio/atol.s deleted file mode 100644 index f0da653..0000000 --- a/libpsn00b/psxapi/stdio/atol.s +++ /dev/null @@ -1,9 +0,0 @@ -.set noreorder -.section .text - -.global atol -.type atol, @function -atol: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x11 diff --git a/libpsn00b/psxapi/stdio/close.s b/libpsn00b/psxapi/stdio/close.s deleted file mode 100644 index 6d52762..0000000 --- a/libpsn00b/psxapi/stdio/close.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global close -.type close, @function -close: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x04 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/getc.s b/libpsn00b/psxapi/stdio/getc.s deleted file mode 100644 index 2a93af6..0000000 --- a/libpsn00b/psxapi/stdio/getc.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global getc -.type getc, @function -getc: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x08 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/getchar.s b/libpsn00b/psxapi/stdio/getchar.s deleted file mode 100644 index ad645c0..0000000 --- a/libpsn00b/psxapi/stdio/getchar.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global getchar -.type getchar, @function -getchar: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x3b -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/gets.s b/libpsn00b/psxapi/stdio/gets.s deleted file mode 100644 index ba423ef..0000000 --- a/libpsn00b/psxapi/stdio/gets.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global gets -.type gets, @function -gets: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x3d -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/ioctl.s b/libpsn00b/psxapi/stdio/ioctl.s deleted file mode 100644 index 9ba17e6..0000000 --- a/libpsn00b/psxapi/stdio/ioctl.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global ioctl -.type ioctl, @function -ioctl: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x05 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/open.s b/libpsn00b/psxapi/stdio/open.s deleted file mode 100644 index ce8c684..0000000 --- a/libpsn00b/psxapi/stdio/open.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global open -.type open, @function -open: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x00 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/printf.s b/libpsn00b/psxapi/stdio/printf.s deleted file mode 100644 index 64f1390..0000000 --- a/libpsn00b/psxapi/stdio/printf.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global printf -.type printf, @function -printf: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x3f -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/putc.s b/libpsn00b/psxapi/stdio/putc.s deleted file mode 100644 index 1c6d916..0000000 --- a/libpsn00b/psxapi/stdio/putc.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global putc -.type putc, @function -putc: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x09 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/puts.s b/libpsn00b/psxapi/stdio/puts.s deleted file mode 100644 index 96815eb..0000000 --- a/libpsn00b/psxapi/stdio/puts.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global puts -.type puts, @function -puts: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x3e -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/read.s b/libpsn00b/psxapi/stdio/read.s deleted file mode 100644 index 4209232..0000000 --- a/libpsn00b/psxapi/stdio/read.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global read -.type read, @function -read: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x02 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/seek.s b/libpsn00b/psxapi/stdio/seek.s deleted file mode 100644 index 944afd9..0000000 --- a/libpsn00b/psxapi/stdio/seek.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global seek -.type seek, @function -seek: - addiu $t2, $0, 0xA0 - jr $t2 - addiu $t1, $0, 0x01 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stdio/write.s b/libpsn00b/psxapi/stdio/write.s deleted file mode 100644 index c451952..0000000 --- a/libpsn00b/psxapi/stdio/write.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global write -.type write, @function -write: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x03 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/stubs.json b/libpsn00b/psxapi/stubs.json new file mode 100644 index 0000000..9198b06 --- /dev/null +++ b/libpsn00b/psxapi/stubs.json @@ -0,0 +1,410 @@ +[ + { + "type": "a", + "id": 0, + "name": "open", + "file": "stdio.s" + }, + { + "type": "a", + "id": 1, + "name": "seek", + "file": "stdio.s" + }, + { + "type": "a", + "id": 2, + "name": "read", + "file": "stdio.s" + }, + { + "type": "a", + "id": 3, + "name": "write", + "file": "stdio.s" + }, + { + "type": "a", + "id": 4, + "name": "close", + "file": "stdio.s" + }, + { + "type": "a", + "id": 5, + "name": "ioctl", + "file": "stdio.s" + }, + { + "type": "a", + "id": 8, + "name": "getc", + "file": "stdio.s" + }, + { + "type": "a", + "id": 9, + "name": "putc", + "file": "stdio.s" + }, + { + "type": "a", + "id": 19, + "name": "b_setjmp", + "file": "sys.s" + }, + { + "type": "a", + "id": 20, + "name": "b_longjmp", + "file": "sys.s" + }, + { + "type": "a", + "id": 57, + "name": "b_InitHeap", + "file": "sys.s" + }, + { + "type": "a", + "id": 59, + "name": "getchar", + "file": "stdio.s" + }, + { + "type": "a", + "id": 60, + "name": "putchar", + "file": "stdio.s" + }, + { + "type": "a", + "id": 61, + "name": "gets", + "file": "stdio.s" + }, + { + "type": "a", + "id": 62, + "name": "puts", + "file": "stdio.s" + }, + { + "type": "a", + "id": 63, + "name": "printf", + "file": "stdio.s" + }, + { + "type": "a", + "id": 67, + "name": "Exec", + "file": "sys.s" + }, + { + "type": "a", + "id": 68, + "name": "FlushCache", + "file": "sys.s" + }, + { + "type": "a", + "id": 85, + "name": "_bu_init", + "file": "drivers.s" + }, + { + "type": "a", + "id": 113, + "name": "_96_init", + "file": "drivers.s" + }, + { + "type": "a", + "id": 114, + "name": "_96_remove", + "file": "drivers.s" + }, + { + "type": "a", + "id": 153, + "name": "AddDummyTty", + "file": "drivers.s" + }, + { + "type": "a", + "id": 160, + "name": "_boot", + "file": "sys.s" + }, + { + "type": "a", + "id": 171, + "name": "_card_info", + "file": "drivers.s" + }, + { + "type": "a", + "id": 172, + "name": "_card_load", + "file": "drivers.s" + }, + { + "type": "a", + "id": 175, + "name": "_card_clear", + "file": "drivers.s" + }, + { + "type": "a", + "id": 180, + "name": "GetSystemInfo", + "file": "sys.s" + }, + { + "type": "b", + "id": 0, + "name": "_kernel_malloc", + "file": "sys.s" + }, + { + "type": "b", + "id": 1, + "name": "_kernel_free", + "file": "sys.s" + }, + { + "type": "b", + "id": 2, + "name": "SetRCnt", + "file": "sys.s" + }, + { + "type": "b", + "id": 3, + "name": "GetRCnt", + "file": "sys.s" + }, + { + "type": "b", + "id": 4, + "name": "StartRCnt", + "file": "sys.s" + }, + { + "type": "b", + "id": 5, + "name": "StopRCnt", + "file": "sys.s" + }, + { + "type": "b", + "id": 6, + "name": "ResetRCnt", + "file": "sys.s" + }, + { + "type": "b", + "id": 8, + "name": "OpenEvent", + "file": "sys.s" + }, + { + "type": "b", + "id": 12, + "name": "EnableEvent", + "file": "sys.s" + }, + { + "type": "b", + "id": 13, + "name": "DisableEvent", + "file": "sys.s" + }, + { + "type": "b", + "id": 18, + "name": "InitPAD", + "file": "sys.s" + }, + { + "type": "b", + "id": 19, + "name": "StartPAD", + "file": "sys.s" + }, + { + "type": "b", + "id": 20, + "name": "StopPAD", + "file": "sys.s" + }, + { + "type": "b", + "id": 23, + "name": "ReturnFromException", + "file": "sys.s" + }, + { + "type": "b", + "id": 24, + "name": "SetDefaultExitFromException", + "file": "sys.s" + }, + { + "type": "b", + "id": 25, + "name": "SetCustomExitFromException", + "file": "sys.s" + }, + { + "type": "b", + "id": 64, + "name": "chdir", + "file": "fs.s" + }, + { + "type": "b", + "id": 66, + "name": "firstfile", + "file": "fs.s" + }, + { + "type": "b", + "id": 67, + "name": "nextfile", + "file": "fs.s" + }, + { + "type": "b", + "id": 68, + "name": "rename", + "file": "fs.s" + }, + { + "type": "b", + "id": 69, + "name": "erase", + "file": "fs.s" + }, + { + "type": "b", + "id": 71, + "name": "AddDev", + "file": "drivers.s" + }, + { + "type": "b", + "id": 72, + "name": "DelDev", + "file": "drivers.s" + }, + { + "type": "b", + "id": 73, + "name": "ListDev", + "file": "drivers.s" + }, + { + "type": "b", + "id": 74, + "name": "InitCard", + "file": "drivers.s" + }, + { + "type": "b", + "id": 75, + "name": "StartCard", + "file": "drivers.s" + }, + { + "type": "b", + "id": 76, + "name": "StopCard", + "file": "drivers.s" + }, + { + "type": "b", + "id": 78, + "name": "_card_write", + "file": "drivers.s" + }, + { + "type": "b", + "id": 79, + "name": "_card_read", + "file": "drivers.s" + }, + { + "type": "b", + "id": 80, + "name": "_new_card", + "file": "drivers.s" + }, + { + "type": "b", + "id": 86, + "name": "GetC0Table", + "file": "sys.s" + }, + { + "type": "b", + "id": 87, + "name": "GetB0Table", + "file": "sys.s" + }, + { + "type": "b", + "id": 88, + "name": "_card_chan", + "file": "drivers.s" + }, + { + "type": "b", + "id": 91, + "name": "ChangeClearPAD", + "file": "sys.s" + }, + { + "type": "b", + "id": 92, + "name": "_card_status", + "file": "drivers.s" + }, + { + "type": "b", + "id": 93, + "name": "_card_wait", + "file": "drivers.s" + }, + { + "type": "c", + "id": 2, + "name": "SysEnqIntRP", + "file": "sys.s" + }, + { + "type": "c", + "id": 3, + "name": "SysDeqIntRP", + "file": "sys.s" + }, + { + "type": "c", + "id": 10, + "name": "ChangeClearRCnt", + "file": "sys.s" + }, + { + "type": "syscall", + "id": 1, + "name": "EnterCriticalSection", + "file": "sys.s" + }, + { + "type": "syscall", + "id": 2, + "name": "ExitCriticalSection", + "file": "sys.s" + } +] diff --git a/libpsn00b/psxapi/sys.s b/libpsn00b/psxapi/sys.s new file mode 100644 index 0000000..e54bd98 --- /dev/null +++ b/libpsn00b/psxapi/sys.s @@ -0,0 +1,266 @@ +# PSn00bSDK BIOS API stubs +# (C) 2022 spicyjpeg - MPL licensed + +# This file has been generated automatically. Each function is placed in its +# own section to allow the linker to strip unused functions. + +.set noreorder + +## A0 table functions (7) + +.section .text.b_setjmp +.global b_setjmp +.type b_setjmp, @function +b_setjmp: + li $t2, 0xa0 + jr $t2 + li $t1, 0x13 + +.section .text.b_longjmp +.global b_longjmp +.type b_longjmp, @function +b_longjmp: + li $t2, 0xa0 + jr $t2 + li $t1, 0x14 + +.section .text.b_InitHeap +.global b_InitHeap +.type b_InitHeap, @function +b_InitHeap: + li $t2, 0xa0 + jr $t2 + li $t1, 0x39 + +.section .text.Exec +.global Exec +.type Exec, @function +Exec: + li $t2, 0xa0 + jr $t2 + li $t1, 0x43 + +.section .text.FlushCache +.global FlushCache +.type FlushCache, @function +FlushCache: + li $t2, 0xa0 + jr $t2 + li $t1, 0x44 + +.section .text._boot +.global _boot +.type _boot, @function +_boot: + li $t2, 0xa0 + jr $t2 + li $t1, 0xa0 + +.section .text.GetSystemInfo +.global GetSystemInfo +.type GetSystemInfo, @function +GetSystemInfo: + li $t2, 0xa0 + jr $t2 + li $t1, 0xb4 + +## B0 table functions (19) + +.section .text._kernel_malloc +.global _kernel_malloc +.type _kernel_malloc, @function +_kernel_malloc: + li $t2, 0xb0 + jr $t2 + li $t1, 0x00 + +.section .text._kernel_free +.global _kernel_free +.type _kernel_free, @function +_kernel_free: + li $t2, 0xb0 + jr $t2 + li $t1, 0x01 + +.section .text.SetRCnt +.global SetRCnt +.type SetRCnt, @function +SetRCnt: + li $t2, 0xb0 + jr $t2 + li $t1, 0x02 + +.section .text.GetRCnt +.global GetRCnt +.type GetRCnt, @function +GetRCnt: + li $t2, 0xb0 + jr $t2 + li $t1, 0x03 + +.section .text.StartRCnt +.global StartRCnt +.type StartRCnt, @function +StartRCnt: + li $t2, 0xb0 + jr $t2 + li $t1, 0x04 + +.section .text.StopRCnt +.global StopRCnt +.type StopRCnt, @function +StopRCnt: + li $t2, 0xb0 + jr $t2 + li $t1, 0x05 + +.section .text.ResetRCnt +.global ResetRCnt +.type ResetRCnt, @function +ResetRCnt: + li $t2, 0xb0 + jr $t2 + li $t1, 0x06 + +.section .text.OpenEvent +.global OpenEvent +.type OpenEvent, @function +OpenEvent: + li $t2, 0xb0 + jr $t2 + li $t1, 0x08 + +.section .text.EnableEvent +.global EnableEvent +.type EnableEvent, @function +EnableEvent: + li $t2, 0xb0 + jr $t2 + li $t1, 0x0c + +.section .text.DisableEvent +.global DisableEvent +.type DisableEvent, @function +DisableEvent: + li $t2, 0xb0 + jr $t2 + li $t1, 0x0d + +.section .text.InitPAD +.global InitPAD +.type InitPAD, @function +InitPAD: + li $t2, 0xb0 + jr $t2 + li $t1, 0x12 + +.section .text.StartPAD +.global StartPAD +.type StartPAD, @function +StartPAD: + li $t2, 0xb0 + jr $t2 + li $t1, 0x13 + +.section .text.StopPAD +.global StopPAD +.type StopPAD, @function +StopPAD: + li $t2, 0xb0 + jr $t2 + li $t1, 0x14 + +.section .text.ReturnFromException +.global ReturnFromException +.type ReturnFromException, @function +ReturnFromException: + li $t2, 0xb0 + jr $t2 + li $t1, 0x17 + +.section .text.SetDefaultExitFromException +.global SetDefaultExitFromException +.type SetDefaultExitFromException, @function +SetDefaultExitFromException: + li $t2, 0xb0 + jr $t2 + li $t1, 0x18 + +.section .text.SetCustomExitFromException +.global SetCustomExitFromException +.type SetCustomExitFromException, @function +SetCustomExitFromException: + li $t2, 0xb0 + jr $t2 + li $t1, 0x19 + +.section .text.GetC0Table +.global GetC0Table +.type GetC0Table, @function +GetC0Table: + li $t2, 0xb0 + jr $t2 + li $t1, 0x56 + +.section .text.GetB0Table +.global GetB0Table +.type GetB0Table, @function +GetB0Table: + li $t2, 0xb0 + jr $t2 + li $t1, 0x57 + +.section .text.ChangeClearPAD +.global ChangeClearPAD +.type ChangeClearPAD, @function +ChangeClearPAD: + li $t2, 0xb0 + jr $t2 + li $t1, 0x5b + +## C0 table functions (3) + +.section .text.SysEnqIntRP +.global SysEnqIntRP +.type SysEnqIntRP, @function +SysEnqIntRP: + li $t2, 0xc0 + jr $t2 + li $t1, 0x02 + +.section .text.SysDeqIntRP +.global SysDeqIntRP +.type SysDeqIntRP, @function +SysDeqIntRP: + li $t2, 0xc0 + jr $t2 + li $t1, 0x03 + +.section .text.ChangeClearRCnt +.global ChangeClearRCnt +.type ChangeClearRCnt, @function +ChangeClearRCnt: + li $t2, 0xc0 + jr $t2 + li $t1, 0x0a + +## Syscalls (2) + +.section .text.EnterCriticalSection +.global EnterCriticalSection +.type EnterCriticalSection, @function +EnterCriticalSection: + li $a0, 0x01 + syscall 0 + jr $ra + nop + +.section .text.ExitCriticalSection +.global ExitCriticalSection +.type ExitCriticalSection, @function +ExitCriticalSection: + li $a0, 0x02 + syscall 0 + jr $ra + nop + diff --git a/libpsn00b/psxapi/sys/_boot.s b/libpsn00b/psxapi/sys/_boot.s deleted file mode 100644 index 9052772..0000000 --- a/libpsn00b/psxapi/sys/_boot.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _boot -.type _boot, @function -_boot: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0xa0 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_bu_init.s b/libpsn00b/psxapi/sys/_bu_init.s deleted file mode 100644 index f074899..0000000 --- a/libpsn00b/psxapi/sys/_bu_init.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _bu_init -.type _bu_init, @function -_bu_init: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x55 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_card_chan.s b/libpsn00b/psxapi/sys/_card_chan.s deleted file mode 100644 index 7847820..0000000 --- a/libpsn00b/psxapi/sys/_card_chan.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _card_chan -.type _card_chan, @function -_card_chan: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x58 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_card_clear.s b/libpsn00b/psxapi/sys/_card_clear.s deleted file mode 100644 index 163415c..0000000 --- a/libpsn00b/psxapi/sys/_card_clear.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _card_clear -.type _card_clear, @function -_card_clear: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0xaf -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_card_info.s b/libpsn00b/psxapi/sys/_card_info.s deleted file mode 100644 index 5e6720f..0000000 --- a/libpsn00b/psxapi/sys/_card_info.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _card_info -.type _card_info, @function -_card_info: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0xab -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_card_load.s b/libpsn00b/psxapi/sys/_card_load.s deleted file mode 100644 index 0e871cb..0000000 --- a/libpsn00b/psxapi/sys/_card_load.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _card_load -.type _card_load, @function -_card_load: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0xac -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_card_read.s b/libpsn00b/psxapi/sys/_card_read.s deleted file mode 100644 index 9026c63..0000000 --- a/libpsn00b/psxapi/sys/_card_read.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _card_read -.type _card_read, @function -_card_read: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x4f -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_card_status.s b/libpsn00b/psxapi/sys/_card_status.s deleted file mode 100644 index 1dd37aa..0000000 --- a/libpsn00b/psxapi/sys/_card_status.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _card_status -.type _card_status, @function -_card_status: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x5c -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_card_wait.s b/libpsn00b/psxapi/sys/_card_wait.s deleted file mode 100644 index 5ceb4d5..0000000 --- a/libpsn00b/psxapi/sys/_card_wait.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _card_wait -.type _card_wait, @function -_card_wait: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x5d -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_card_write.s b/libpsn00b/psxapi/sys/_card_write.s deleted file mode 100644 index 5e1450b..0000000 --- a/libpsn00b/psxapi/sys/_card_write.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _card_write -.type _card_write, @function -_card_write: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x4e -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/_new_card.s b/libpsn00b/psxapi/sys/_new_card.s deleted file mode 100644 index cfd6f57..0000000 --- a/libpsn00b/psxapi/sys/_new_card.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global _new_card -.type _new_card, @function -_new_card: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x50 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/adddev.s b/libpsn00b/psxapi/sys/adddev.s deleted file mode 100644 index 7fa717d..0000000 --- a/libpsn00b/psxapi/sys/adddev.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global AddDev -.type AddDev, @function -AddDev: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x47
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/adddummytty.s b/libpsn00b/psxapi/sys/adddummytty.s deleted file mode 100644 index a569d38..0000000 --- a/libpsn00b/psxapi/sys/adddummytty.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global AddDummyTty -.type AddDummyTty, @function -AddDummyTty: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x99 diff --git a/libpsn00b/psxapi/sys/b_initheap.s b/libpsn00b/psxapi/sys/b_initheap.s deleted file mode 100644 index 7411dd6..0000000 --- a/libpsn00b/psxapi/sys/b_initheap.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global b_InitHeap -.type b_InitHeap, @function -b_InitHeap: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x39 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/changeclearpad.s b/libpsn00b/psxapi/sys/changeclearpad.s deleted file mode 100644 index 509b03f..0000000 --- a/libpsn00b/psxapi/sys/changeclearpad.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global ChangeClearPAD -.type ChangeClearPAD, @function -ChangeClearPAD: - addiu $t2, $0 , 0xb0 - jr $t2 - addiu $t1, $0 , 0x5b -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/changeclearrcnt.s b/libpsn00b/psxapi/sys/changeclearrcnt.s deleted file mode 100644 index a65676d..0000000 --- a/libpsn00b/psxapi/sys/changeclearrcnt.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global ChangeClearRCnt -.type ChangeClearRCnt, @function -ChangeClearRCnt: - addiu $t2, $0 , 0xc0 - jr $t2 - addiu $t1, $0 , 0x0a -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/deldev.s b/libpsn00b/psxapi/sys/deldev.s deleted file mode 100644 index 185cd32..0000000 --- a/libpsn00b/psxapi/sys/deldev.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global DelDev -.type DelDev, @function -DelDev: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x48
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/disableevent.s b/libpsn00b/psxapi/sys/disableevent.s deleted file mode 100644 index fb60549..0000000 --- a/libpsn00b/psxapi/sys/disableevent.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global DisableEvent -.type DisableEvent, @function -DisableEvent: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x0d -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/enableevent.s b/libpsn00b/psxapi/sys/enableevent.s deleted file mode 100644 index a95e1fc..0000000 --- a/libpsn00b/psxapi/sys/enableevent.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global EnableEvent -.type EnableEvent, @function -EnableEvent: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x0c -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/entercriticalsection.s b/libpsn00b/psxapi/sys/entercriticalsection.s deleted file mode 100644 index ce9a368..0000000 --- a/libpsn00b/psxapi/sys/entercriticalsection.s +++ /dev/null @@ -1,11 +0,0 @@ -.set noreorder -.section .text - -.global EnterCriticalSection -.type EnterCriticalSection, @function -EnterCriticalSection: - addiu $a0, $0, 1 - syscall 0 - jr $ra - nop -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/exec.s b/libpsn00b/psxapi/sys/exec.s deleted file mode 100644 index dacce7e..0000000 --- a/libpsn00b/psxapi/sys/exec.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global Exec -.type Exec, @function -Exec: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x43
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/exitcriticalsection.s b/libpsn00b/psxapi/sys/exitcriticalsection.s deleted file mode 100644 index e2ee060..0000000 --- a/libpsn00b/psxapi/sys/exitcriticalsection.s +++ /dev/null @@ -1,11 +0,0 @@ -.set noreorder -.section .text - -.global ExitCriticalSection -.type ExitCriticalSection, @function -ExitCriticalSection: - addiu $a0, $0, 2 - syscall 0 - jr $ra - nop -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/flushcache.s b/libpsn00b/psxapi/sys/flushcache.s deleted file mode 100644 index 7eeb510..0000000 --- a/libpsn00b/psxapi/sys/flushcache.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global FlushCache -.type FlushCache, @function -FlushCache: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x44 diff --git a/libpsn00b/psxapi/sys/getrcnt.s b/libpsn00b/psxapi/sys/getrcnt.s deleted file mode 100644 index 0b035ed..0000000 --- a/libpsn00b/psxapi/sys/getrcnt.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global GetRCnt -.type GetRCnt, @function -GetRCnt: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x03
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/getsysteminfo.s b/libpsn00b/psxapi/sys/getsysteminfo.s deleted file mode 100644 index 60c1d43..0000000 --- a/libpsn00b/psxapi/sys/getsysteminfo.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global GetSystemInfo -.type GetSystemInfo, @function -GetSystemInfo: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0xb4
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/initcard.s b/libpsn00b/psxapi/sys/initcard.s deleted file mode 100644 index bdc3ffd..0000000 --- a/libpsn00b/psxapi/sys/initcard.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global InitCARD -.type InitCARD, @function -InitCARD: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x4a -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/initpad.s b/libpsn00b/psxapi/sys/initpad.s deleted file mode 100644 index f2a6642..0000000 --- a/libpsn00b/psxapi/sys/initpad.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global InitPAD -.type InitPAD, @function -InitPAD: - addiu $t2, $0 , 0xb0 - jr $t2 - addiu $t1, $0 , 0x12 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/listdev.s b/libpsn00b/psxapi/sys/listdev.s deleted file mode 100644 index fa3afec..0000000 --- a/libpsn00b/psxapi/sys/listdev.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global ListDev -.type ListDev, @function -ListDev: - addiu $t2, $0 , 0xb0 - jr $t2 - addiu $t1, $0 , 0x49 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/openevent.s b/libpsn00b/psxapi/sys/openevent.s deleted file mode 100644 index 9be0a3e..0000000 --- a/libpsn00b/psxapi/sys/openevent.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global OpenEvent -.type OpenEvent, @function -OpenEvent: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x08 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/resetrcnt.s b/libpsn00b/psxapi/sys/resetrcnt.s deleted file mode 100644 index 5811625..0000000 --- a/libpsn00b/psxapi/sys/resetrcnt.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global ResetRCnt -.type ResetRCnt, @function -ResetRCnt: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x06
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/returnfromexception.s b/libpsn00b/psxapi/sys/returnfromexception.s deleted file mode 100644 index ec67b64..0000000 --- a/libpsn00b/psxapi/sys/returnfromexception.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global ReturnFromException -.type ReturnFromException, @function -ReturnFromException: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x17 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/setcustomexitfromexception.s b/libpsn00b/psxapi/sys/setcustomexitfromexception.s deleted file mode 100644 index bcba057..0000000 --- a/libpsn00b/psxapi/sys/setcustomexitfromexception.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global SetCustomExitFromException -.type SetCustomExitFromException, @function -SetCustomExitFromException: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x19 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/setdefaultexitfromexception.s b/libpsn00b/psxapi/sys/setdefaultexitfromexception.s deleted file mode 100644 index baaf591..0000000 --- a/libpsn00b/psxapi/sys/setdefaultexitfromexception.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global SetDefaultExitFromException -.type SetDefaultExitFromException, @function -SetDefaultExitFromException: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x18 - diff --git a/libpsn00b/psxapi/sys/setrcnt.s b/libpsn00b/psxapi/sys/setrcnt.s deleted file mode 100644 index ec6180a..0000000 --- a/libpsn00b/psxapi/sys/setrcnt.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global SetRCnt -.type SetRCnt, @function -SetRCnt: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x02
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/startcard.s b/libpsn00b/psxapi/sys/startcard.s deleted file mode 100644 index 44f1676..0000000 --- a/libpsn00b/psxapi/sys/startcard.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global StartCARD -.type StartCARD, @function -StartCARD: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x4b -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/startpad.s b/libpsn00b/psxapi/sys/startpad.s deleted file mode 100644 index fdd380f..0000000 --- a/libpsn00b/psxapi/sys/startpad.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global StartPAD -.type StartPAD, @function -StartPAD: - addiu $t2, $0 , 0xb0 - jr $t2 - addiu $t1, $0 , 0x13 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/startrcnt.s b/libpsn00b/psxapi/sys/startrcnt.s deleted file mode 100644 index 0fd5c33..0000000 --- a/libpsn00b/psxapi/sys/startrcnt.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global StartRCnt -.type StartRCnt, @function -StartRCnt: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x04
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/stopcard.s b/libpsn00b/psxapi/sys/stopcard.s deleted file mode 100644 index 9c38d5d..0000000 --- a/libpsn00b/psxapi/sys/stopcard.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global StopCARD -.type StopCARD, @function -StopCARD: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x4c -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/stoppad.s b/libpsn00b/psxapi/sys/stoppad.s deleted file mode 100644 index 5e77a43..0000000 --- a/libpsn00b/psxapi/sys/stoppad.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global StopPAD -.type StopPAD, @function -StopPAD: - addiu $t2, $0 , 0xb0 - jr $t2 - addiu $t1, $0 , 0x14 -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/stoprcnt.s b/libpsn00b/psxapi/sys/stoprcnt.s deleted file mode 100644 index 4af94da..0000000 --- a/libpsn00b/psxapi/sys/stoprcnt.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder - -.section .text - -.global StopRCnt -.type StopRCnt, @function -StopRCnt: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x05
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/sysenqintrp.s b/libpsn00b/psxapi/sys/sysenqintrp.s deleted file mode 100644 index b1efe65..0000000 --- a/libpsn00b/psxapi/sys/sysenqintrp.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global SysEnqIntRP -.type SysEnqIntRP, @function -SysEnqIntRP: - addiu $t2, $0, 0xc0 - jr $t2 - addiu $t1, $0, 0x02 -
\ No newline at end of file diff --git a/libpsn00b/psxcd/cdgetsector.s b/libpsn00b/psxcd/cdgetsector.s index dbe95cb..9f38e7a 100644 --- a/libpsn00b/psxcd/cdgetsector.s +++ b/libpsn00b/psxcd/cdgetsector.s @@ -21,16 +21,16 @@ CdGetSector: # srl $a1, 2 # (the official implementation expects $a1/size # to be in 32-bit words rather than bytes) or $v0, $a1 - sw $a0, D3_MADR($a2) # Set DMA base address and transfer length - sw $v0, D3_BCR($a2) + sw $a0, DMA3_MADR($a2) # Set DMA base address and transfer length + sw $v0, DMA3_BCR($a2) lui $v0, 0x1100 # Start DMA transfer - sw $v0, D3_CHCR($a2) + sw $v0, DMA3_CHCR($a2) nop nop .Ldma_wait: # Ensure DMA transfer has completed - lw $v0, D3_CHCR($a2) + lw $v0, DMA3_CHCR($a2) nop srl $v0, 24 andi $v0, 0x1 diff --git a/libpsn00b/psxcd/psxcd_asm.s b/libpsn00b/psxcd/psxcd_asm.s index 1dbf542..129bc89 100644 --- a/libpsn00b/psxcd/psxcd_asm.s +++ b/libpsn00b/psxcd/psxcd_asm.s @@ -17,9 +17,9 @@ _cd_init: lui $a3, IOBASE # Acknowledge all CD IRQs li $v0, 0x20943 # Set CD-ROM Delay/Size and common delay - sw $v0, SBUS_5($a3) + sw $v0, CD_DELAY_SIZE($a3) li $v0, 0x1325 - sw $v0, COM_DELAY($a3) + sw $v0, COM_DELAY_CFG($a3) li $v0, 1 sb $v0, CD_REG0($a3) @@ -71,10 +71,10 @@ _cd_init: la $v0, _cd_read_cb sw $0 , 0($v0) - lw $v0, DPCR($a3) + lw $v0, DMA_DPCR($a3) li $v1, 0xB000 or $v0, $v1 - sw $v0, DPCR($a3) + sw $v0, DMA_DPCR($a3) jal ExitCriticalSection nop diff --git a/libpsn00b/psxetc/dl.c b/libpsn00b/psxetc/dl.c index cbdcb66..6d37605 100644 --- a/libpsn00b/psxetc/dl.c +++ b/libpsn00b/psxetc/dl.c @@ -587,7 +587,8 @@ DLL *DL_CreateDLL(void *ptr, size_t size, DL_ResolveMode mode) { if (ctor_list) { for (uint32_t i = ((uint32_t) ctor_list[0]); i >= 1; i--) { void (*ctor)(void) = (void (*)(void)) ctor_list[i]; - DL_CALL(ctor); + DL_PRE_CALL(ctor); + ctor(); } } @@ -619,7 +620,8 @@ void DL_DestroyDLL(DLL *dll) { if (dtor_list) { for (uint32_t i = 0; i < ((uint32_t) dtor_list[0]); i++) { void (*dtor)(void) = (void (*)(void)) dtor_list[i + 1]; - DL_CALL(dtor); + DL_PRE_CALL(dtor); + dtor(); } } } diff --git a/libpsn00b/psxetc/dmacallback.s b/libpsn00b/psxetc/dmacallback.s index b2f86cf..8ea8ec0 100644 --- a/libpsn00b/psxetc/dmacallback.s +++ b/libpsn00b/psxetc/dmacallback.s @@ -46,13 +46,13 @@ DMACallback: lui $a2, IOBASE - lw $v0, DICR($a2) # Enable DMA interrupt + lw $v0, DMA_DICR($a2) # Enable DMA interrupt lui $v1, 0x1 sll $v1, $a0 or $v0, $v1 lui $v1, 0x80 or $v0, $v1 - sw $v0, DICR($a2) + sw $v0, DMA_DICR($a2) b .Lskip_remove nop @@ -67,7 +67,7 @@ DMACallback: sw $v1, 4($sp) lui $a2, IOBASE # Disable DMA interrupt - lw $v0, DICR($a2) + lw $v0, DMA_DICR($a2) lui $v1, 0x1 sll $v1, $a0 .set noat @@ -78,13 +78,13 @@ DMACallback: xor $v1, $at and $v0, $v1 .set at - sw $v0, DICR($a2) + sw $v0, DMA_DICR($a2) jal _dma_has_cb # Check if callbacks are present nop bnez $v0, .Lskip_remove nop - sw $0 , DICR($a2) + sw $0 , DMA_DICR($a2) jal GetInterruptCallback # Check if callback is the DMA handler li $a0, 3 @@ -143,7 +143,7 @@ _dma_handler: .Lhandler_loop: lui $a0, IOBASE - lw $v0, DICR($a0) + lw $v0, DMA_DICR($a0) li $v1, 24 addu $v1, $s0 srl $v0, $v1 @@ -166,9 +166,9 @@ _dma_handler: addi $s0, 1 lui $a0, IOBASE - lw $v0, DICR($a0) + lw $v0, DMA_DICR($a0) nop - sw $v0, DICR($a0) + sw $v0, DMA_DICR($a0) lw $ra, 0($sp) lw $s0, 4($sp) diff --git a/libpsn00b/psxetc/interruptcallback.s b/libpsn00b/psxetc/interruptcallback.s index 8e912d8..78e5e6e 100644 --- a/libpsn00b/psxetc/interruptcallback.s +++ b/libpsn00b/psxetc/interruptcallback.s @@ -16,25 +16,25 @@ InterruptCallback: beqz $a1, .Ldisable_irq nop - lw $v0, IMASK($a2) # Enable interrupt mask + lw $v0, IRQ_MASK($a2) # Enable interrupt mask li $v1, 1 sll $v1, $a0 or $v0, $v1 b .Lcont - sw $v0, IMASK($a2) + sw $v0, IRQ_MASK($a2) .Ldisable_irq: .set noat - lw $v0, IMASK($a2) # Disable interrupt mask + lw $v0, IRQ_MASK($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) + sw $v0, IRQ_MASK($a2) .Lcont: diff --git a/libpsn00b/psxetc/isr.s b/libpsn00b/psxetc/isr.s index 00428a4..440be50 100644 --- a/libpsn00b/psxetc/isr.s +++ b/libpsn00b/psxetc/isr.s @@ -20,7 +20,7 @@ _global_isr: # changed elsewhere sometimes lui $a0, IOBASE # Get IRQ status - lw $v0, IMASK($a0) + lw $v0, IRQ_MASK($a0) nop srl $v0, $s1 # Check IRQ mask bit if set @@ -29,7 +29,7 @@ _global_isr: beqz $v0, .Lno_irq # Don't execute callback if IRQ not enabled nop - lw $v0, ISTAT($a0) + lw $v0, IRQ_STAT($a0) nop srl $v0, $s1 # Check IRQ status bit if set andi $v0, 0x1 @@ -39,12 +39,12 @@ _global_isr: lw $v1, 0($s0) # Load IRQ callback function nop - lw $v0, ISTAT($a0) # Acknowledge the IRQ (by writing a 0 bit) + lw $v0, IRQ_STAT($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) + sw $a1, IRQ_STAT($a0) beqz $v1, .Lno_irq # Don't execute if callback is not set nop diff --git a/libpsn00b/psxetc/restartcallback.s b/libpsn00b/psxetc/restartcallback.s index 151d78e..036a5a0 100644 --- a/libpsn00b/psxetc/restartcallback.s +++ b/libpsn00b/psxetc/restartcallback.s @@ -44,8 +44,8 @@ RestartCallback: addiu $a1, 1 lui $a0, IOBASE - sw $0 , ISTAT($a0) - sw $v0, IMASK($a0) + sw $0 , IRQ_STAT($a0) + sw $v0, IRQ_MASK($a0) lw $ra, 0($sp) addiu $sp, 4 diff --git a/libpsn00b/psxgpu/clearotagr.s b/libpsn00b/psxgpu/clearotagr.s index 3e888f1..562cad4 100644 --- a/libpsn00b/psxgpu/clearotagr.s +++ b/libpsn00b/psxgpu/clearotagr.s @@ -8,14 +8,14 @@ .global ClearOTagR .type ClearOTagR, @function ClearOTagR: - lui $a2, 0x1f80 + lui $a2, IOBASE addi $v0, $a1, -1 sll $v0, 2 addu $a0, $v0 - sw $a0, D6_MADR($a2) + sw $a0, DMA6_MADR($a2) andi $a1, 0xffff - sw $a1, D6_BCR($a2) + sw $a1, DMA6_BCR($a2) lui $v0, 0x1100 addiu $v0, 2 jr $ra - sw $v0, D6_CHCR($a2) + sw $v0, DMA6_CHCR($a2) diff --git a/libpsn00b/psxgpu/drawotag.s b/libpsn00b/psxgpu/drawotag.s index ba771fc..3cb0db0 100644 --- a/libpsn00b/psxgpu/drawotag.s +++ b/libpsn00b/psxgpu/drawotag.s @@ -11,11 +11,11 @@ DrawOTag: addiu $sp, -4 sw $ra, 0($sp) - lui $a3, 0x1f80 # I/O segment base + lui $a3, IOBASE # I/O segment base lui $v0, 0x0400 # Set DMA direction to CPUtoGPU ori $v0, 0x2 - sw $v0, GP1($a3) + sw $v0, GPU_GP1($a3) .Lgpu_wait: # Wait for GPU to be ready for commands & DMA jal ReadGPUstat @@ -25,12 +25,12 @@ DrawOTag: beqz $v0, .Lgpu_wait nop - sw $a0, D2_MADR($a3) # Set DMA base address to specified OT - sw $0 , D2_BCR($a3) + sw $a0, DMA2_MADR($a3) # Set DMA base address to specified OT + sw $0 , DMA2_BCR($a3) lui $v0, 0x0100 # Begin OT transfer! ori $v0, 0x0401 - sw $v0, D2_CHCR($a3) + sw $v0, DMA2_CHCR($a3) lw $ra, 0($sp) addiu $sp, 4 diff --git a/libpsn00b/psxgpu/drawprim.s b/libpsn00b/psxgpu/drawprim.s index de5afbd..d62c202 100644 --- a/libpsn00b/psxgpu/drawprim.s +++ b/libpsn00b/psxgpu/drawprim.s @@ -18,7 +18,7 @@ DrawPrim: lui $a3, IOBASE lui $v0, 0x0400 # Set transfer direction to off - sw $v0, GP1($a3) + sw $v0, GPU_GP1($a3) move $a0, $s0 lbu $a1, 3($a0) # Get length of primitive packet @@ -28,7 +28,7 @@ DrawPrim: .Ltransfer_loop: lw $v0, 0($a0) addiu $a0, 4 - sw $v0, GP0($a3) + sw $v0, GPU_GP0($a3) bgtz $a1, .Ltransfer_loop addiu $a1, -1 diff --git a/libpsn00b/psxgpu/drawsync.s b/libpsn00b/psxgpu/drawsync.s index 2e29381..b671b03 100644 --- a/libpsn00b/psxgpu/drawsync.s +++ b/libpsn00b/psxgpu/drawsync.s @@ -24,7 +24,7 @@ DrawSync: nop .Ldma_wait: - lw $v0, D2_CHCR($a0) + lw $v0, DMA2_CHCR($a0) nop srl $v0, 24 andi $v0, 0x1 @@ -59,7 +59,7 @@ DrawSync: .Lgetwords: - lw $v0, D2_BCR($a0) + lw $v0, DMA2_BCR($a0) nop jr $ra diff --git a/libpsn00b/psxgpu/drawsynccallback.s b/libpsn00b/psxgpu/drawsynccallback.s index 37c0375..22cfb7d 100644 --- a/libpsn00b/psxgpu/drawsynccallback.s +++ b/libpsn00b/psxgpu/drawsynccallback.s @@ -64,7 +64,7 @@ _drawsync_handler: addiu $sp, -4 sw $ra, 0($sp) - lw $v0, D2_CHCR($a0) + lw $v0, DMA2_CHCR($a0) nop srl $v0, 24 andi $v0, 0x1 @@ -84,7 +84,7 @@ _drawsync_handler: lw $v1, 0($v1) lui $v0, 0x0400 # Set DMA direction to off - sw $v0, GP1($a0) + sw $v0, GPU_GP1($a0) jalr $v1 nop diff --git a/libpsn00b/psxgpu/loadimage.s b/libpsn00b/psxgpu/loadimage.s index 4a3b4e0..45f152f 100644 --- a/libpsn00b/psxgpu/loadimage.s +++ b/libpsn00b/psxgpu/loadimage.s @@ -17,7 +17,7 @@ LoadImage: sw $ra, 0($sp) sw $s0, 4($sp) - lui $s0, 0x1f80 # Set I/O segment base address + lui $s0, IOBASE # Set I/O segment base address .Lgpu_wait: # Wait for GPU to be ready for commands and DMA jal ReadGPUstat @@ -31,21 +31,21 @@ LoadImage: nop lui $v0, 0x400 # Set DMA direction to off - sw $v0, GP1($s0) + sw $v0, GPU_GP1($s0) lui $v0, 0x0100 # Clear GPU cache - sw $v0, GP0($s0) + sw $v0, GPU_GP0($s0) lui $v1, 0xa000 # Load image to VRAM - sw $v1, GP0($s0) + sw $v1, GPU_GP0($s0) lw $v0, RECT_x($a0) # Set XY and dimensions of image lw $v1, RECT_w($a0) - sw $v0, GP0($s0) - sw $v1, GP0($s0) + sw $v0, GPU_GP0($s0) + sw $v1, GPU_GP0($s0) lui $v0, 0x400 # Set DMA direction to CPUtoVRAM ori $v0, 0x2 - sw $v0, GP1($s0) + sw $v0, GPU_GP1($s0) lhu $v0, RECT_w($a0) # Get rectangle size lhu $v1, RECT_h($a0) @@ -56,12 +56,12 @@ LoadImage: sll $v1, 0x10 ori $v1, 0x8 - sw $a1, D2_MADR($s0) # Set DMA base address and transfer length - sw $v1, D2_BCR($s0) + sw $a1, DMA2_MADR($s0) # Set DMA base address and transfer length + sw $v1, DMA2_BCR($s0) lui $v0, 0x100 # Start DMA transfer ori $v0, 0x201 - sw $v0, D2_CHCR($s0) + sw $v0, DMA2_CHCR($s0) lw $ra, 0($sp) lw $s0, 4($sp) diff --git a/libpsn00b/psxgpu/putdispenv.s b/libpsn00b/psxgpu/putdispenv.s index 4baa20e..fc09454 100644 --- a/libpsn00b/psxgpu/putdispenv.s +++ b/libpsn00b/psxgpu/putdispenv.s @@ -102,7 +102,7 @@ PutDispEnv: or $a2, $v0 lui $v0, 0x0600 or $v0, $a2 - sw $v0, GP1($a3) + sw $v0, GPU_GP1($a3) # Vertical resolution @@ -127,7 +127,7 @@ PutDispEnv: or $v1, $a2 lui $v0, 0x0700 or $v1, $v0 - sw $v1, GP1($a3) + sw $v1, GPU_GP1($a3) # Video mode @@ -159,7 +159,7 @@ PutDispEnv: lui $v0, 0x800 # Apply mode or $a1, $v0 - sw $a1, GP1($a3) + sw $a1, GPU_GP1($a3) lhu $v0, DISP_dx($a0) # Set VRAM XY offset lhu $v1, DISP_dy($a0) @@ -171,4 +171,4 @@ PutDispEnv: or $v0, $v1 jr $ra - sw $v0, GP1($a3) + sw $v0, GPU_GP1($a3) diff --git a/libpsn00b/psxgpu/putdispenvraw.s b/libpsn00b/psxgpu/putdispenvraw.s index 157150d..747796f 100644 --- a/libpsn00b/psxgpu/putdispenvraw.s +++ b/libpsn00b/psxgpu/putdispenvraw.s @@ -19,7 +19,7 @@ PutDispEnvRaw: sw $ra, 0($sp) sw $s0, 4($sp) - lui $s0, 0x1f80 + lui $s0, IOBASE lh $at, DISP_vxpos($a0) # Set horizontal display range li $v0, 608 @@ -30,7 +30,7 @@ PutDispEnvRaw: or $v0, $v1 lui $v1, 0x600 or $v1, $v0 - sw $v1, GP1($s0) + sw $v1, GPU_GP1($s0) lh $at, DISP_vypos($a0) # Set vertical display range (for NTSC) li $v1, 120 # (values differet for PAL modes) @@ -47,12 +47,12 @@ PutDispEnvRaw: or $v0, $at lui $at, 0x700 or $v0, $at - sw $v0, GP1($s0) + sw $v0, GPU_GP1($s0) lw $v0, DISP_mode($a0) # Set video mode lui $at, 0x800 or $v0, $at - sw $v0, GP1($s0) + sw $v0, GPU_GP1($s0) lhu $v0, DISP_fbx($a0) # Set VRAM XY offset lhu $v1, DISP_fby($a0) @@ -62,7 +62,7 @@ PutDispEnvRaw: or $v0, $v1 lui $v1, 0x500 or $v0, $v1 - sw $v0, GP1($s0) + sw $v0, GPU_GP1($s0) lw $ra, 0($sp) lw $s0, 4($sp) diff --git a/libpsn00b/psxgpu/readgpustat.s b/libpsn00b/psxgpu/readgpustat.s index c587cfb..ffff4d7 100644 --- a/libpsn00b/psxgpu/readgpustat.s +++ b/libpsn00b/psxgpu/readgpustat.s @@ -8,7 +8,7 @@ .global ReadGPUstat .type ReadGPUstat, @function ReadGPUstat: - lui $v0, 0x1f80 - lw $v0, GP1($v0) + lui $v0, IOBASE + lw $v0, GPU_GP1($v0) jr $ra nop diff --git a/libpsn00b/psxgpu/resetgraph.s b/libpsn00b/psxgpu/resetgraph.s index f469fbe..6327f02 100644 --- a/libpsn00b/psxgpu/resetgraph.s +++ b/libpsn00b/psxgpu/resetgraph.s @@ -38,14 +38,14 @@ ResetGraph: nop # interrupts enabled when transferring # execution to the loaded program - lui $a3, 0x1f80 # Base address for I/O + lui $a3, IOBASE # Base address for I/O lui $v0, 0x3b33 # Enables DMA channel 6 (for ClearOTag) ori $v0, 0x3b33 # Enables DMA channel 2 - sw $v0, DPCR($a3) - sw $0 , DICR($a3) # Clear DICR (not needed) + sw $v0, DMA_DPCR($a3) + sw $0 , DMA_DICR($a3) # Clear DICR (not needed) - sw $0 , IMASK($a3) # Clear IRQ settings + sw $0 , IRQ_MASK($a3) # Clear IRQ settings la $v0, _hooks_installed # Set installed flag li $v1, 0x1 @@ -84,9 +84,9 @@ ResetGraph: .Lskip_hook_init: - lui $a3, 0x1f80 + lui $a3, IOBASE - lw $v0, GP1($a3) # Get video standard + lw $v0, GPU_GP1($a3) # Get video standard lui $v1, 0x0010 and $v0, $v1 la $v1, _gpu_standard @@ -98,30 +98,30 @@ ResetGraph: lw $a0, 4($sp) # Get argument value - lui $a3, 0x1f80 # Set base I/O again (likely destroyed + lui $a3, IOBASE # Set base I/O again (likely destroyed # by previous calls) li $v0, 0x1d00 # Configure timer 1 as Hblank counter - sw $v0, T1_MODE($a3) # Set timer 1 value + sw $v0, TIMER1_CTRL($a3) # Set timer 1 value beq $a0, 1, .Lgpu_init_1 nop beq $a0, 3, .Lgpu_init_3 nop - sw $0 , GP1($a3) # Reset the GPU + sw $0 , GPU_GP1($a3) # Reset the GPU b .Linit_done nop .Lgpu_init_1: - sw $0 , D2_CHCR($a3) # Stop any DMA + sw $0 , DMA2_CHCR($a3) # Stop any DMA .Lgpu_init_3: li $v0, 0x1 # Reset the command buffer - sw $v0, GP1($a3) + sw $v0, GPU_GP1($a3) .Linit_done: @@ -140,12 +140,12 @@ VSync: sw $s0, 4($sp) lui $a3, IOBASE # Get GPU status (for interlace sync) - lw $s0, GP1($a3) + lw $s0, GPU_GP1($a3) .Lhwait_loop: # Get Hblank time - lw $v0, T1_CNT($a3) + lw $v0, TIMER1_VALUE($a3) nop - lw $v1, T1_CNT($a3) + lw $v1, TIMER1_VALUE($a3) nop bne $v0, $v1, .Lhwait_loop nop @@ -189,14 +189,14 @@ VSync: lui $a3, IOBASE # Interlace wait logic - lw $v0, GP1($a3) + lw $v0, GPU_GP1($a3) nop xor $v0, $s0, $v0 bltz $v0, .Lhblank_exit lui $a0, 0x8000 .Linterlace_wait: - lw $v0, GP1($a3) + lw $v0, GPU_GP1($a3) nop xor $v0, $s0, $v0 and $v0, $a0 @@ -208,9 +208,9 @@ VSync: la $a2, _vsync_lasthblank .Lhwait2_loop: - lw $v0, T1_CNT($a3) + lw $v0, TIMER1_VALUE($a3) nop - lw $v1, T1_CNT($a3) + lw $v1, TIMER1_VALUE($a3) sw $v0, 0($a2) bne $v0, $v1, .Lhwait2_loop nop diff --git a/libpsn00b/psxgpu/setdispmask.s b/libpsn00b/psxgpu/setdispmask.s index 77ceb04..d79006c 100644 --- a/libpsn00b/psxgpu/setdispmask.s +++ b/libpsn00b/psxgpu/setdispmask.s @@ -8,12 +8,12 @@ .global SetDispMask .type SetDispMask, @function SetDispMask: - lui $v1, 0x1f80 + lui $v1, IOBASE andi $a0, 0x1 lui $v0, 0x300 ori $v0, 0x1 sub $v0, $a0 - sw $v0, GP1($v1) + sw $v0, GPU_GP1($v1) jr $ra nop diff --git a/libpsn00b/psxgpu/setvideomode.s b/libpsn00b/psxgpu/setvideomode.s index 4395f0a..b89b285 100644 --- a/libpsn00b/psxgpu/setvideomode.s +++ b/libpsn00b/psxgpu/setvideomode.s @@ -41,7 +41,7 @@ SetVideoMode: lui $v0, 0x800 # Apply new mode or $a1, $v0 lui $v0, IOBASE - sw $a1, GP1($v0) + sw $a1, GPU_GP1($v0) lw $ra, 0($sp) addiu $sp, 4 diff --git a/libpsn00b/psxgpu/storeimage.s b/libpsn00b/psxgpu/storeimage.s index 5d4c793..554e83c 100644 --- a/libpsn00b/psxgpu/storeimage.s +++ b/libpsn00b/psxgpu/storeimage.s @@ -17,7 +17,7 @@ StoreImage: sw $ra, 0($sp) sw $s0, 4($sp) - lui $s0, 0x1f80 # Set I/O segment base address + lui $s0, IOBASE # Set I/O segment base address .Lgpu_wait: # Wait for GPU to be ready for commands and DMA jal ReadGPUstat @@ -29,21 +29,21 @@ StoreImage: nop lui $v0, 0x400 # Set DMA direction to off - sw $v0, GP1($s0) + sw $v0, GPU_GP1($s0) lui $v0, 0x0100 # Clear GPU cache - sw $v0, GP0($s0) + sw $v0, GPU_GP0($s0) lui $v1, 0xc000 # Store image from VRAM - sw $v1, GP0($s0) + sw $v1, GPU_GP0($s0) lw $v0, RECT_x($a0) # Set XY and dimensions of image lw $v1, RECT_w($a0) - sw $v0, GP0($s0) - sw $v1, GP0($s0) + sw $v0, GPU_GP0($s0) + sw $v1, GPU_GP0($s0) lui $v0, 0x400 # Set DMA direction to VRAMtoCPU ori $v0, 0x3 - sw $v0, GP1($s0) + sw $v0, GPU_GP1($s0) lhu $v0, RECT_w($a0) # Get rectangle size lhu $v1, RECT_h($a0) @@ -54,8 +54,8 @@ StoreImage: sll $v1, 0x10 ori $v1, 0x8 - sw $a1, D2_MADR($s0) # Set DMA base address and transfer length - sw $v1, D2_BCR($s0) + sw $a1, DMA2_MADR($s0) # Set DMA base address and transfer length + sw $v1, DMA2_BCR($s0) .Lgpu_wait_2: # Wait for GPU to be ready for commands and DMA jal ReadGPUstat @@ -67,7 +67,7 @@ StoreImage: lui $v0, 0x100 # Start DMA transfer ori $v0, 0x200 - sw $v0, D2_CHCR($s0) + sw $v0, DMA2_CHCR($s0) lw $ra, 0($sp) lw $s0, 4($sp) diff --git a/libpsn00b/psxpress/mdec.c b/libpsn00b/psxpress/mdec.c new file mode 100644 index 0000000..ca4c75a --- /dev/null +++ b/libpsn00b/psxpress/mdec.c @@ -0,0 +1,173 @@ +/* + * PSn00bSDK MDEC library (low-level MDEC/DMA API) + * (C) 2022 spicyjpeg - MPL licensed + */ + +#include <stdint.h> +#include <stdio.h> +#include <psxapi.h> +#include <psxpress.h> +#include <hwregs_c.h> + +#define MDEC_SYNC_TIMEOUT 0x1000000 + +/* Default IDCT matrix and quantization tables */ + +#define S0 0x5a82 // 0x4000 * cos(0/16 * pi) * sqrt(2) +#define S1 0x7d8a // 0x4000 * cos(1/16 * pi) * 2 +#define S2 0x7641 // 0x4000 * cos(2/16 * pi) * 2 +#define S3 0x6a6d // 0x4000 * cos(3/16 * pi) * 2 +#define S4 0x5a82 // 0x4000 * cos(4/16 * pi) * 2 +#define S5 0x471c // 0x4000 * cos(5/16 * pi) * 2 +#define S6 0x30fb // 0x4000 * cos(6/16 * pi) * 2 +#define S7 0x18f8 // 0x4000 * cos(7/16 * pi) * 2 + +static const DECDCTENV _default_mdec_env = { + // The default luma and chroma quantization table is based on the MPEG-1 + // quantization table, with the only difference being the first value (2 + // instead of 8). Note that quantization tables are stored in zigzag order + // rather than row- or column-major. + // https://problemkaputt.de/psx-spx.htm#mdecdecompression + .iq_y = { + 2, 16, 16, 19, 16, 19, 22, 22, + 22, 22, 22, 22, 26, 24, 26, 27, + 27, 27, 26, 26, 26, 26, 27, 27, + 27, 29, 29, 29, 34, 34, 34, 29, + 29, 29, 27, 27, 29, 29, 32, 32, + 34, 34, 37, 38, 37, 35, 35, 34, + 35, 38, 38, 40, 40, 40, 48, 48, + 46, 46, 56, 56, 58, 69, 69, 83 + }, + .iq_c = { + 2, 16, 16, 19, 16, 19, 22, 22, + 22, 22, 22, 22, 26, 24, 26, 27, + 27, 27, 26, 26, 26, 26, 27, 27, + 27, 29, 29, 29, 34, 34, 34, 29, + 29, 29, 27, 27, 29, 29, 32, 32, + 34, 34, 37, 38, 37, 35, 35, 34, + 35, 38, 38, 40, 40, 40, 48, 48, + 46, 46, 56, 56, 58, 69, 69, 83 + }, + /*.iq_y = { + 16, 11, 12, 14, 12, 10, 16, 14, + 13, 14, 18, 17, 16, 19, 24, 40, + 26, 24, 22, 22, 24, 49, 35, 37, + 29, 40, 58, 51, 61, 60, 57, 51, + 56, 55, 64, 72, 92, 78, 64, 68, + 87, 69, 55, 56, 80, 109, 81, 87, + 95, 98, 103, 104, 103, 62, 77, 113, + 121, 112, 100, 120, 92, 101, 103, 99 + }, + .iq_c = { + 17, 18, 18, 24, 21, 24, 47, 26, + 26, 47, 99, 66, 56, 66, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99 + },*/ + .dct = { + S0, S0, S0, S0, S0, S0, S0, S0, + S1, S3, S5, S7, -S7, -S5, -S3, -S1, + S2, S6, -S6, -S2, -S2, -S6, S6, S2, + S3, -S7, -S1, -S5, S5, S1, S7, -S3, + S4, -S4, -S4, S4, S4, -S4, -S4, S4, + S5, -S1, S7, S3, -S3, -S7, S1, -S5, + S6, -S2, S2, -S6, -S6, S2, -S2, S6, + S7, -S5, S3, -S1, S1, -S3, S5, -S7 + } +}; + +/* Public API */ + +void DecDCTReset(int32_t mode) { + EnterCriticalSection(); + + DMA_DPCR |= 0x000000bb; // Enable DMA0 and DMA1 + DMA_CHCR(0) = 0x00000201; // Stop DMA0 + DMA_CHCR(1) = 0x00000200; // Stop DMA1 + MDEC1 = 0x80000000; // Reset MDEC + MDEC1 = 0x60000000; // Enable DMA in/out requests + + ExitCriticalSection(); + if (!mode) + DecDCTPutEnv(0, 0); +} + +void DecDCTPutEnv(const DECDCTENV *env, int32_t mono) { + const DECDCTENV *_env = env ? env : &_default_mdec_env; + DecDCTinSync(0); + + MDEC0 = 0x60000000; // Set IDCT matrix + DecDCTinRaw((const uint32_t *) _env->dct, 32); + DecDCTinSync(0); + + MDEC0 = 0x40000000 | (mono ? 0 : 1); // Set table(s) + DecDCTinRaw((const uint32_t *) _env->iq_y, mono ? 16 : 32); + DecDCTinSync(0); +} + +void DecDCTin(const uint32_t *data, int32_t mode) { + uint32_t header = *data; + if (mode == DECDCT_MODE_RAW) + MDEC0 = header; + else if (mode & DECDCT_MODE_24BPP) + MDEC0 = header | 0x30000000; + else + MDEC0 = header | 0x38000000 | ((mode & 2) << 24); // Bit 25 = mask + + DecDCTinRaw((const uint32_t *) &(data[1]), header & 0xffff); +} + +// This is a PSn00bSDK-only function that behaves like DecDCTout(), taking the +// data length as an argument rather than parsing it from the first 4 bytes of +// the stream. +void DecDCTinRaw(const uint32_t *data, size_t length) { + DMA_MADR(0) = (uint32_t) data; + if (length < 32) + DMA_BCR(0) = 0x00010000 | length; + else + DMA_BCR(0) = 0x00000020 | ((length / 32) << 16); + + DMA_CHCR(0) = 0x01000201; +} + +int32_t DecDCTinSync(int32_t mode) { + if (mode) + return (MDEC1 >> 29) & 1; + + for (uint32_t i = MDEC_SYNC_TIMEOUT; i; i--) { + if (!(MDEC1 & (1 << 29))) + return 0; + } + + printf("psxpress: DecDCTinSync() timeout\n"); + return -1; +} + +void DecDCTout(uint32_t *data, size_t length) { + DecDCToutSync(0); + + DMA_MADR(1) = (uint32_t) data; + if (length < 32) + DMA_BCR(1) = 0x00010000 | length; + else + DMA_BCR(1) = 0x00000020 | ((length / 32) << 16); + + DMA_CHCR(1) = 0x01000200; +} + +int32_t DecDCToutSync(int32_t mode) { + if (mode) + return (DMA_CHCR(1) >> 24) & 1; + + for (uint32_t i = MDEC_SYNC_TIMEOUT; i; i--) { + if (!(DMA_CHCR(1) & (1 << 24))) + return 0; + } + + printf("psxpress: DecDCToutSync() timeout\n"); + return -1; +} diff --git a/libpsn00b/psxspu/spuinit.s b/libpsn00b/psxspu/spuinit.s index 42f302a..6966213 100644 --- a/libpsn00b/psxspu/spuinit.s +++ b/libpsn00b/psxspu/spuinit.s @@ -17,30 +17,25 @@ SpuInit: # Stop and mute everything - sh $0 , SPUCNT($v1) # Clear control settings + sh $0 , SPU_CTRL($v1) # Clear control settings jal SpuCtrlSync move $a0, $0 - sh $0 , SPU_MASTER_VOL($v1) # Clear master volume - sh $0 , SPU_MASTER_VOL+2($v1) + sh $0 , SPU_MASTER_VOL_L($v1) # Clear master volume + sh $0 , SPU_MASTER_VOL_R($v1) - sh $0 , SPU_REVERB_VOL($v1) # Clear reverb volume - sh $0 , SPU_REVERB_VOL+2($v1) + sh $0 , SPU_REVERB_VOL_L($v1) # Clear reverb volume + sh $0 , SPU_REVERB_VOL_R($v1) - sh $0 , SPU_CD_VOL($v1) # Clear CD volume - sh $0 , SPU_CD_VOL+2($v1) + sh $0 , SPU_CD_VOL_L($v1) # Clear CD volume + sh $0 , SPU_CD_VOL_R($v1) - sh $0 , SPU_EXT_VOL($v1) # Clear external audio volume - sh $0 , SPU_EXT_VOL+2($v1) + sh $0 , SPU_EXT_VOL_L($v1) # Clear external audio volume + sh $0 , SPU_EXT_VOL_R($v1) - sh $0 , SPU_FM_MODE($v1) # Turn off FM modes - sh $0 , SPU_FM_MODE+2($v1) - - sh $0 , SPU_NOISE_MODE($v1) # Turn off noise modes - sh $0 , SPU_NOISE_MODE+2($v1) - - sh $0 , SPU_REVERB_ON($v1) # Turn off reverb modes - sh $0 , SPU_REVERB_ON+2($v1) + sw $0 , SPU_FM_MODE($v1) # Turn off FM modes + sw $0 , SPU_NOISE_MODE($v1) # Turn off noise modes + sw $0 , SPU_REVERB_ON($v1) # Turn off reverb modes li $v0, 0xfffe sh $v0, SPU_REVERB_ADDR($v1) @@ -65,32 +60,28 @@ SpuInit: bgez $a2, .Lclear_voices nop - li $v0, 0xffff # Set all keys to off - sh $v0, SPU_KEY_OFF($v1) - sh $v0, SPU_KEY_OFF+2($v1) + addiu $v0, $0, -1 # Set all keys to off + sw $v0, SPU_KEY_OFF($v1) li $v0, 0x4 # Set SPU data transfer control - sh $v0, SPUDTCNT($v1) # (usually always 0x4) + sh $v0, SPU_DMA_CTRL($v1) # (usually always 0x4) - lw $v0, DPCR($v1) # Enable DMA channel 4 (SPU DMA) + lw $v0, DMA_DPCR($v1) # Enable DMA channel 4 (SPU DMA) lui $at, 0xb or $v0, $at - sw $v0, DPCR($v1) + sw $v0, DMA_DPCR($v1) li $v0, 0xC001 # Enable SPU - sh $v0, SPUCNT($v1) + sh $v0, SPU_CTRL($v1) jal SpuCtrlSync move $a0, $v0 li $v0, 0x3fff # Activate master volume - sh $v0, SPU_MASTER_VOL($v1) - sh $v0, SPU_MASTER_VOL+2($v1) - - sh $v0, SPU_CD_VOL($v1) # Activate CD volume - sh $v0, SPU_CD_VOL+2($v1) + sh $v0, SPU_MASTER_VOL_L($v1) + sh $v0, SPU_MASTER_VOL_R($v1) - sh $v0, SPU_CD_VOL($v1) # Activate CD volume - sh $v0, SPU_CD_VOL+2($v1) + sh $v0, SPU_CD_VOL_L($v1) # Activate CD volume + sh $v0, SPU_CD_VOL_R($v1) lw $ra, 0($sp) addiu $sp, 4 @@ -108,7 +99,7 @@ SpuCtrlSync: lui $v1, IOBASE andi $a0, 0x3f .Lctrl_wait: - lhu $v0, SPUSTAT($v1) # Get SPUSTAT value + lhu $v0, SPU_STAT($v1) # Get SPUSTAT value nop andi $v0, 0x3f bne $v0, $a0, .Lctrl_wait # Wait until SPUCNT and SPUSTAT are equal @@ -123,7 +114,7 @@ SpuCtrlSync: .type SpuWait, @function SpuWait: lui $v0, IOBASE - lhu $v0, SPUSTAT($v0) + lhu $v0, SPU_STAT($v0) nop andi $v0, 0x400 bnez $v0, SpuWait diff --git a/libpsn00b/psxspu/spureverbon.s b/libpsn00b/psxspu/spureverbon.s index 852bff3..635fac3 100644 --- a/libpsn00b/psxspu/spureverbon.s +++ b/libpsn00b/psxspu/spureverbon.s @@ -11,6 +11,6 @@ SpuReverbOn: lui $v1, IOBASE li $v0, 1 sll $v0, $a0 - sh $v0, SPU_REVERB_ON($v1) + sw $v0, SPU_REVERB_ON($v1) jr $ra nop
\ No newline at end of file diff --git a/libpsn00b/psxspu/spusetreverb.s b/libpsn00b/psxspu/spusetreverb.s index 993b166..8257812 100644 --- a/libpsn00b/psxspu/spusetreverb.s +++ b/libpsn00b/psxspu/spusetreverb.s @@ -10,11 +10,12 @@ SpuSetReverb: addiu $sp, -4 sw $ra, 0($sp) - - lhu $v0, SPUCNT($v1) + + lui $v1, IOBASE + lhu $v0, SPU_CTRL($v1) nop ori $v0, 0x80 # Enable reverb - sh $v0, SPUCNT($v1) + sh $v0, SPU_CTRL($v1) jal SpuCtrlSync move $a0, $v0 diff --git a/libpsn00b/psxspu/spusetreverbaddr.s b/libpsn00b/psxspu/spusetreverbaddr.s index 6ddbf44..089a91a 100644 --- a/libpsn00b/psxspu/spusetreverbaddr.s +++ b/libpsn00b/psxspu/spusetreverbaddr.s @@ -8,7 +8,7 @@ .global SpuSetReverbAddr .type SpuSetReverbAddr, @function SpuSetReverbAddr: - lui $a3, 0x1f80 + lui $a3, IOBASE srl $a0, 3 sh $a0, SPU_REVERB_ADDR($a3) jr $ra @@ -18,8 +18,8 @@ SpuSetReverbAddr: .global SpuSetReverbVolume .type SpuSetReverbVolume, @function SpuSetReverbVolume: - lui $a3, 0x1f80 - sh $a0, SPU_REVERB_VOL($a3) - sh $a1, SPU_REVERB_VOL+2($a3) + lui $a3, IOBASE + sh $a0, SPU_REVERB_VOL_L($a3) + sh $a1, SPU_REVERB_VOL_R($a3) jr $ra nop
\ No newline at end of file diff --git a/libpsn00b/psxspu/transfer.s b/libpsn00b/psxspu/transfer.s index 5b62c28..adcdb33 100644 --- a/libpsn00b/psxspu/transfer.s +++ b/libpsn00b/psxspu/transfer.s @@ -46,10 +46,10 @@ SpuWrite: lui $a3, IOBASE - lhu $v0, SPUCNT($a3) # Set transfer mode to Stop + lhu $v0, SPU_CTRL($a3) # Set transfer mode to Stop nop andi $v0, 0xffcf - sh $v0, SPUCNT($a3) + sh $v0, SPU_CTRL($a3) jal SpuCtrlSync move $a0, $v0 @@ -58,10 +58,10 @@ SpuWrite: nop sh $v1, SPU_ADDR($a3) - lhu $v0, SPUCNT($a3) # Set transfer mode to DMA write + lhu $v0, SPU_CTRL($a3) # Set transfer mode to DMA write nop ori $v0, 0x20 - sh $v0, SPUCNT($a3) + sh $v0, SPU_CTRL($a3) #jal SpuCtrlSync # Locks up on most emulators (bit 5 in #move $a0, $v0 # SPUSTAT likely not updating, seems to # be okay to not wait for it on real HW) @@ -69,13 +69,13 @@ SpuWrite: lw $a0, 4($sp) .Ldma_wait: # Wait for SPU to be ready for DMA - lhu $v0, SPUSTAT($a3) + lhu $v0, SPU_STAT($a3) nop andi $v0, 0x400 # Bit 8 in SPUSTAT never changes to 1 on bnez $v0, .Ldma_wait # emulators so use bit 10 instead nop - sw $a0, D4_MADR($a3) # Set DMA source address + sw $a0, DMA4_MADR($a3) # Set DMA source address li $v0, 0x10 # 16 words per block (64 bytes) addiu $a1, 63 # Add by 63 to ensure all bytes get sent @@ -83,11 +83,11 @@ SpuWrite: andi $a1, 0xffff sll $a1, 16 or $v0, $a1 - sw $v0, D4_BCR($a3) + sw $v0, DMA4_BCR($a3) lui $v0, 0x0100 # Commence transfer ori $v0, 0x0201 - sw $v0, D4_CHCR($a3) + sw $v0, DMA4_CHCR($a3) lw $ra, 0($sp) addiu $sp, 8 diff --git a/libpsn00b/readme.txt b/libpsn00b/readme.txt index cfff733..6a6be5a 100644 --- a/libpsn00b/readme.txt +++ b/libpsn00b/readme.txt @@ -18,33 +18,39 @@ recommended version as that is what LibPSn00b is most tested most on. Brief summary of libraries: - libc - Standard C library. Covers only a small subset of the full - standard C library such as basic string and memory manipulation - functions. Should include libgcc to avoid libc/libgcc linker - hell (endless cross referencing). - - psxgpu - GPU library for video, graphics control, and interrupt service - subsystem that other libraries that uses interrupts depend on. - - psxgte - GTE library for hardware accelerated vector transformations - that are integral for high performance 3D graphics on the PS1 - (it is a Geometry Transformation Engine, NOT Transfer Engine). - - psxapi - Provides function calls for using functions provided by the PS1 - BIOS. - - psxetc - Provides some miscellaneous features used by the other libraries - as well as a dynamic linker for loading DLLs at runtime. - - psxspu - SPU library (work in progress). Currently supports hardware - init, sample data upload via DMA and playing sound samples. - Lacks support for reverb and a sequenced music subsystem. - - psxcd - CD-ROM library for loading files, parsing directories - (PSn00bSDK addition), CD Audio/XA playback with provisions for - data streaming. Also supports multi-session discs (must be - selected manually). - + libc - Standard C library. Covers only a small subset of the full + standard C library such as basic string and memory manipulation + functions. Should include libgcc to avoid libc/libgcc linker + hell (endless cross referencing). + + psxgpu - GPU library for video, graphics control, and interrupt service + subsystem that other libraries that uses interrupts depend on. + + psxgte - GTE library for hardware accelerated vector transformations + that are integral for high performance 3D graphics on the PS1 + (it is a Geometry Transformation Engine, NOT Transfer Engine). + + psxapi - Provides function calls for using functions provided by the PS1 + BIOS. + + psxetc - Provides some miscellaneous features used by the other libraries + as well as a dynamic linker for loading DLLs at runtime. + + psxspu - SPU library (work in progress). Currently supports hardware + init, sample data upload via DMA and playing sound samples. + Lacks support for reverb and a sequenced music subsystem. + + psxcd - CD-ROM library for loading files, parsing directories + (PSn00bSDK addition), CD Audio/XA playback with provisions for + data streaming. Also supports multi-session discs (must be + selected manually). + + psxpress - Experimental MDEC library. Currently provides APIs to feed data + to the MDEC and retrieve decoded images, as well as a + decompressor for the Huffman encoding used in FMVs encoded using + Sony tools. A custom decompressor based on arithmetic coding + might be implemented in the future. + Each library has its own readme file that contains a todo list, credits and some additional details of the library. Changes of all the libraries must be covered in the changelog.txt file. @@ -52,7 +58,7 @@ Brief summary of libraries: Compiling: - Refer to INSTALL.md in the parent directory for up-to-date installation + Refer to installation.md in the doc directory for up-to-date installation instructions. --- THE SECTION BELOW IS OUTDATED AND ONLY KEPT FOR REFERENCE --- @@ -144,11 +150,6 @@ LibPSn00b Library to-do list: psxmcrd - Better and faster memory card library with provisions for low-level card access. The psxpad library would provide communication routines for the card library. - - psxpress - MDEC and data decompression library. May use DEFLATE or LZ77 - for compressing MDEC data instead of Huffman as used in the - official libraries. It may yield better compression which may - potentially result in higher quality FMVs. psxexp - Support library for various devices connected to the serial or expansion port, including both official ones (e.g. PCMCIA cards |
