From ba03884e3d52d47a4fa1b474ca7dc6b419ee6898 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 30 Dec 2021 14:56:55 +0100 Subject: Refactor dynamic linker API, fix system/dynlink example --- libpsn00b/include/dlfcn.h | 101 ++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 43 deletions(-) (limited to 'libpsn00b/include') diff --git a/libpsn00b/include/dlfcn.h b/libpsn00b/include/dlfcn.h index b3a5cec..6874d06 100644 --- a/libpsn00b/include/dlfcn.h +++ b/libpsn00b/include/dlfcn.h @@ -21,39 +21,39 @@ #define RTLD_DEFAULT ((DLL *) 0) typedef enum _DL_Error { - RTLD_E_NONE = 0, // No error - RTLD_E_FILE_OPEN = 1, // Unable to find or open file - RTLD_E_FILE_ALLOC = 2, // Unable to allocate buffer to load file into - RTLD_E_FILE_READ = 3, // Failed to read file - RTLD_E_NO_MAP = 4, // No symbol map has been loaded yet - RTLD_E_MAP_ALLOC = 5, // Unable to allocate symbol map structures - RTLD_E_NO_SYMBOLS = 6, // No symbols found in symbol map - RTLD_E_DLL_NULL = 7, // Unable to initialize DLL from null pointer - RTLD_E_DLL_ALLOC = 8, // Unable to allocate DLL metadata structures - RTLD_E_DLL_FORMAT = 9, // Unsupported DLL type or format - RTLD_E_NO_FILE_API = 10, // psxetc has been built without file support - RTLD_E_MAP_SYMBOL = 11, // Symbol not found in symbol map - RTLD_E_DLL_SYMBOL = 12, // Symbol not found in DLL - RTLD_E_HASH_LOOKUP = 13 // Hash table lookup failed due to internal error + RTLD_E_NONE = 0, // No error + RTLD_E_FILE_OPEN = 1, // Unable to find or open file + RTLD_E_FILE_ALLOC = 2, // Unable to allocate buffer to load file into + RTLD_E_FILE_READ = 3, // Failed to read file + RTLD_E_NO_MAP = 4, // No symbol map has been loaded yet + RTLD_E_MAP_ALLOC = 5, // Unable to allocate symbol map structures + RTLD_E_NO_SYMBOLS = 6, // No symbols found in symbol map + RTLD_E_DLL_NULL = 7, // Unable to initialize DLL from null pointer + RTLD_E_DLL_ALLOC = 8, // Unable to allocate DLL metadata structures + RTLD_E_DLL_FORMAT = 9, // Unsupported DLL type or format + RTLD_E_MAP_SYMBOL = 10, // Symbol not found in symbol map + RTLD_E_DLL_SYMBOL = 11, // Symbol not found in DLL + RTLD_E_HASH_LOOKUP = 12 // Hash table lookup failed due to internal error } DL_Error; typedef enum _DL_ResolveMode { - RTLD_LAZY = 1, // Resolve functions when they are first called (default) - RTLD_NOW = 2 // Resolve all symbols immediately on load + RTLD_LAZY = 1, // Resolve functions when they are first called (default) + RTLD_NOW = 2, // Resolve all symbols immediately on load + RTLD_FREE_ON_DESTROY = 4 // Automatically free DLL buffer when closing DLL } DL_ResolveMode; // Members of this struct should not be accessed directly in most cases, but // they are intentionally exposed for easier expandability. typedef struct _DLL { - void *ptr; - void *malloc_ptr; - size_t size; - const uint32_t *hash; - uint32_t *got; - Elf32_Sym *symtab; - const char *strtab; - uint16_t symbol_count; - uint16_t got_length; + void *ptr; + void *malloc_ptr; + size_t size; + const uint32_t *hash; + uint32_t *got; + Elf32_Sym *symtab; + const char *strtab; + uint16_t symbol_count; + uint16_t got_length; } DLL; /* API */ @@ -62,8 +62,6 @@ typedef struct _DLL { extern "C" { #endif -// TODO: rewrite these javadoc comments into proper documentation - /** * @brief Reads the symbol table from the provided string buffer (which may or * may not be null-terminated), parses it and stores the parsed entries into a @@ -80,13 +78,14 @@ extern "C" { * file in the appropriate format after building the executable, by using this * command: * - * mipsel-unknown-elf-nm -f posix -l -n executable.elf >executable.map + * mipsel-none-elf-nm -f posix -l -n executable.elf >executable.map * * @param ptr * @param size * @return -1 or number of entries parsed */ int32_t DL_ParseSymbolMap(const char *ptr, size_t size); + /** * @brief File wrapper around DL_ParseSymbolMap(). Allocates a temporary buffer * then loads the specified map file into it (using BIOS APIs) and calls @@ -96,14 +95,16 @@ int32_t DL_ParseSymbolMap(const char *ptr, size_t size); * @param filename Must always contain device name, e.g. "cdrom:MODULE.DLL;1" * @return -1 or number of entries parsed */ -int32_t DL_LoadSymbolMap(const char *filename); +//int32_t DL_LoadSymbolMapFromFile(const char *filename); + /** * @brief Frees internal buffers containing the currently loaded symbol map. * This is automatically done before loading a new symbol map so there is no * need to call this function in most cases, however it can still be useful to * free up space on the heap once the symbol map is no longer needed. */ -void DL_UnloadSymbolMap(void); +void DL_UnloadSymbolMap(void); + /** * @brief Queries the currently loaded symbol map for the symbol with the given * name and returns a pointer to it, which can then be used to directly access @@ -112,7 +113,8 @@ void DL_UnloadSymbolMap(void); * @param name * @return NULL or pointer to symbol (any type) */ -void *DL_GetSymbolByName(const char *name); +void *DL_GetSymbolByName(const char *name); + /** * @brief Sets a custom function to be called for resolving symbols in DLLs. * The function will be given a pointer to the current DLL and the unresolved @@ -123,7 +125,7 @@ void *DL_GetSymbolByName(const char *name); * * @param callback NULL or pointer to callback function */ -void DL_SetResolveCallback(void *(*callback)(DLL *, const char *)); +void DL_SetResolveCallback(void *(*callback)(DLL *, const char *)); /** * @brief Initializes a buffer holding the contents of a dynamically-loaded @@ -131,8 +133,8 @@ void DL_SetResolveCallback(void *(*callback)(DLL *, const char *)); * binary) *in-place*. A new DLL struct is allocated to store metadata but, * unlike DL_ParseSymbolMap(), the DLL's actual code, data and tables are * referenced directly from the provided buffer. The buffer must not be moved - * or deallocated, at least not before calling dlclose() on the DLL struct - * returned by this function. + * or deallocated, at least not before calling DL_DestroyDLL() on the DLL + * struct returned by this function. * * The third argument specifies when symbols in the DLL should be resolved. * Setting it to RTLD_LAZY defers resolution of undefined functions to when @@ -145,7 +147,8 @@ void DL_SetResolveCallback(void *(*callback)(DLL *, const char *)); * @param mode RTLD_LAZY or RTLD_NOW * @return NULL or pointer to a new DLL struct */ -DLL *dlinit(void *ptr, size_t size, DL_ResolveMode mode); +DLL *DL_CreateDLL(void *ptr, size_t size, DL_ResolveMode mode); + /** * @brief File wrapper around dlinit(). Allocates a new buffer, loads the * specified file into it (using BIOS APIs) and calls dlinit() on that. When @@ -153,19 +156,22 @@ DLL *dlinit(void *ptr, size_t size, DL_ResolveMode mode); * automatically destroyed. * * @param filename Must always contain device name, e.g. "cdrom:MODULE.DLL;1" - * @param mode RTLD_LAZY or RTLD_NOW + * @param mode RTLD_LAZY or RTLD_NOW + optionally RTLD_FREE_ON_DESTROY * @return NULL or pointer to a new DLL struct */ -DLL *dlopen(const char *filename, DL_ResolveMode mode); +//DLL *DL_LoadDLLFromFile(const char *filename, DL_ResolveMode mode); + /** * @brief Destroys a loaded DLL by calling its global destructors and freeing - * the buffer it's loaded in. Any pointer passed to dlclose() should no longer - * be used after the call. If the DLL was initialized in-place using dlinit(), - * dlclose() will *NOT* free the buffer initially passed to dlinit(). + * the buffer it's loaded in. Any pointer passed to DL_DestroyDLL() should no + * longer be used after the call. If the DLL was initialized in-place using + * DL_CreateDLL(), DL_DestroyDLL() will only free the buffer initially passed + * to DL_CreateDLL() if RTLD_FREE_ON_DESTROY was used. * * @param dll */ -void dlclose(DLL *dll); +void DL_DestroyDLL(DLL *dll); + /** * @brief Returns a pointer to the DLL symbol with the given name, or null if * it can't be found. If null or RTLD_DEFAULT is passed as first argument, the @@ -176,7 +182,8 @@ void dlclose(DLL *dll); * @param name * @return NULL or pointer to symbol (any type) */ -void *dlsym(DLL *dll, const char *name); +void *DL_GetDLLSymbol(const DLL *dll, const char *name); + /** * @brief Returns a code describing the last error that occurred, or DL_E_NONE * if no error has occurred since the last call to dlerror() (i.e. calling this @@ -184,7 +191,15 @@ void *dlsym(DLL *dll, const char *name); * * @return NULL or member of DL_Error enum */ -DL_Error dlerror(void); +DL_Error DL_GetLastError(void); + +/* POSIX "compatibility" macros */ + +#define dlinit(ptr, size, mode) DL_CreateDLL(ptr, size, mode) +//#define dlopen(filename, mode) DL_LoadDLLFromFile(filename, mode) +#define dlsym(dll, name) DL_GetDLLSymbol(dll, name) +#define dlclose(dll) DL_DestroyDLL(dll) +#define dlerror() DL_GetLastError() #ifdef __cplusplus } -- cgit v1.2.3 From de9047f568f2f3509b56a2b566d7353cae616eb7 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 30 Dec 2021 14:58:14 +0100 Subject: Add known_bugs.md, fix sound/vagsample and declarations --- CMakeLists.txt | 6 ++++ doc/known_bugs.md | 52 ++++++++++++++++++++++++++++++ examples/sound/vagsample/0proyt.h | 2 +- examples/sound/vagsample/threedeeffeggzz.h | 2 +- libpsn00b/include/psxcd.h | 6 ++-- libpsn00b/include/psxspu.h | 4 +-- libpsn00b/psxcd/psxcd.c | 8 ++--- 7 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 doc/known_bugs.md (limited to 'libpsn00b/include') diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a20a0e..2079fd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,12 @@ set( -DCMAKE_INSTALL_PREFIX:PATH=${PROJECT_BINARY_DIR}/examples ) +# Ensure PSn00bSDK isn't being built using the toolchain file from PSn00bSDK +# itself (or from another version of it). +if(CMAKE_TOOLCHAIN_FILE MATCHES ".*libpsn00b[/\\]cmake[/\\]sdk\.cmake$") + message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE is set to the toolchain file of an existing PSn00bSDK installation. It must be unset or overridden by passing '-DCMAKE_TOOLCHAIN_FILE=\"\"' to CMake.") +endif() + ## Subprojects if(NOT EXISTS ${PROJECT_SOURCE_DIR}/tools/mkpsxiso/CMakeLists.txt) diff --git a/doc/known_bugs.md b/doc/known_bugs.md new file mode 100644 index 0000000..2af9e3f --- /dev/null +++ b/doc/known_bugs.md @@ -0,0 +1,52 @@ + +# Known PSn00bSDK bugs + +This is an incomplete list of things that are currently broken (or not behaving +as they should, or untested on real hardware) and haven't yet been fixed. + +## Libraries + +`psxspu`: + +- Calls to `SpuSetTransferMode()` are ignored. SPU transfers are always + performed using DMA, which imposes limitations such as the data length having + to be a multiple of 64 bytes. + +`psxetc`: + +- `DL_LoadSymbolMapFromFile()`, `DL_LoadDLLFromFile()` and `dlopen()` have been + disabled due to bugs in the BIOS file APIs. The dynamic linker can still be + used by loading DLL binaries into RAM manually and calling `DL_CreateDLL()` + on them (see the `system/dynlink` example). + +## Tools + +- The `mkpsxiso` submodule is temporarily set to point to a fork of `mkpsxiso` + with bugfixed CMake scripts (the main repo is broken to the point it fails to + build). There is [another fork](https://github.com/CookiePLMonster/mkpsxiso) + which is currently work-in-progress and includes more fixes as well as a tool + to dump existing CD images: PSn00bSDK will switch back to the main `mkpsxiso` + repo once the changes get upstreamed. + +## Examples + +- `cdrom/cdxa` and `sound/spustream` demonstrate how to stream an audio file + from CD-ROM. Such a file isn't provided however, as PSn00bSDK does not yet + come with the tooling required for transcoding audio from a source file. In + order to run these examples you'll have to provide your own audio files, + convert them and build the CD image manually. + +- `demos/n00bdemo` suffers from flickering on real hardware, especially when + masking/stencil buffering is used. + +- `graphics/render2tex` gets stuck after initialization on real hardware. + +- `io/pads` seems to work on real hardware, but fails to automatically enable + analog mode on DualShock controllers. This example needs more testing with + official and unofficial controllers. + +- `io/system573` hasn't been tested on a real Konami System 573. It runs on + MAME, however MAME's System 573 emulation is *very* inaccurate. + +----------------------------------------- +_Last updated on 2021-12-30 by spicyjpeg_ diff --git a/examples/sound/vagsample/0proyt.h b/examples/sound/vagsample/0proyt.h index 4402b9a..73629f9 100644 --- a/examples/sound/vagsample/0proyt.h +++ b/examples/sound/vagsample/0proyt.h @@ -12616,6 +12616,6 @@ unsigned char proyt[] = { 0xf2,0xf0,0xf2,0x15,0xc2,0x1b,0x00,0x00,0x01,0xe3,0x31,0x13,0xf3,0x1f,0xe2, 0x2f,0x13,0xd6,0x20,0x6e,0x2d,0x1b,0x00,0x03,0x42,0xc3,0x14,0x30,0x20,0x21, 0x21,0x32,0x0e,0x32,0x12,0x42,0xf0,0x39,0x01,0x13,0x12,0x04,0xb3,0x06,0x1f, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x77,0x77,0x77,0x77,0x77, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x05,0x77,0x77,0x77,0x77,0x77, 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77 }; diff --git a/examples/sound/vagsample/threedeeffeggzz.h b/examples/sound/vagsample/threedeeffeggzz.h index ed0e098..f0815aa 100644 --- a/examples/sound/vagsample/threedeeffeggzz.h +++ b/examples/sound/vagsample/threedeeffeggzz.h @@ -15194,6 +15194,6 @@ unsigned char tdfx[] = { 0x0b,0x1e,0x21,0xa0,0x4f,0xe2,0x2d,0x17,0x00,0xd2,0x02,0x1d,0xd1,0xf0,0x21, 0xfa,0x2e,0xc4,0x1e,0xfe,0xf2,0x2f,0x24,0x17,0x00,0xef,0xee,0x1f,0xf2,0xce, 0x0d,0x25,0x01,0x3e,0xcb,0xe1,0x30,0xeb,0xc4,0x17,0x01,0x1f,0x1f,0xaf,0x22, -0xfd,0xe0,0xf3,0x0b,0x2e,0xdd,0xc3,0xde,0x12,0x2d,0x07,0x00,0x77,0x77,0x77, +0xfd,0xe0,0xf3,0x0b,0x2e,0xdd,0xc3,0xde,0x12,0x2d,0x07,0x05,0x77,0x77,0x77, 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77 }; diff --git a/libpsn00b/include/psxcd.h b/libpsn00b/include/psxcd.h index ffbe86b..3336963 100644 --- a/libpsn00b/include/psxcd.h +++ b/libpsn00b/include/psxcd.h @@ -132,9 +132,9 @@ CdlLOC* CdIntToPos(int i, CdlLOC *p); int CdPosToInt(CdlLOC *p); int CdGetToc(CdlLOC *toc); -int CdControl(u_char com, u_char *param, u_char *result); -int CdControlB(u_char com, u_char *param, u_char *result); -int CdControlF(u_char com, u_char *param); +int CdControl(u_char com, const void *param, u_char *result); +int CdControlB(u_char com, const void *param, u_char *result); +int CdControlF(u_char com, const void *param); int CdSync(int mode, u_char *result); u_long CdSyncCallback(CdlCB func); diff --git a/libpsn00b/include/psxspu.h b/libpsn00b/include/psxspu.h index a87e347..da000e3 100644 --- a/libpsn00b/include/psxspu.h +++ b/libpsn00b/include/psxspu.h @@ -115,7 +115,7 @@ extern "C" { void SpuInit(); -void SpuSetVoiceRaw( int voice, SpuVoiceRaw* param ); +void SpuSetVoiceRaw( int voice, const SpuVoiceRaw* param ); void SpuReverbOn( int voice ); void SpuSetReverb(); @@ -128,7 +128,7 @@ void SpuSetKey(int on_off, u_int voice_bit); // SPU transfer functions int SpuSetTransferMode(int mode); int SpuSetTransferStartAddr(int addr); -int SpuWrite(unsigned char* addr, int size); +int SpuWrite(const unsigned char* addr, int size); void SpuWait(); #ifdef __cplusplus diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index 76415f9..8f19c8d 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -21,7 +21,7 @@ volatile int _cd_last_sector_count; int _cd_media_changed; void _cd_init(void); -void _cd_control(unsigned char com, unsigned char *param, int plen); +void _cd_control(unsigned char com, const void *param, int plen); void _cd_wait_ack(void); void _cd_wait(void); @@ -50,7 +50,7 @@ int CdInit(void) return 1; } -int CdControl(unsigned char com, unsigned char *param, unsigned char *result) +int CdControl(unsigned char com, const void *param, unsigned char *result) { // Don't issue command if ack is not received yet if( _cd_ack_wait ) @@ -72,7 +72,7 @@ int CdControl(unsigned char com, unsigned char *param, unsigned char *result) return 1; } -int CdControlB(unsigned char com, unsigned char *param, unsigned char *result) +int CdControlB(unsigned char com, const void *param, unsigned char *result) { if( !CdControl(com, param, result) ) { @@ -83,7 +83,7 @@ int CdControlB(unsigned char com, unsigned char *param, unsigned char *result) return 1; } -int CdControlF(unsigned char com, unsigned char *param) +int CdControlF(unsigned char com, const void *param) { int param_len=0; -- cgit v1.2.3 From de38196a978548b61c4b45115d24ef743b9eef90 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Mon, 17 Jan 2022 15:57:04 +0100 Subject: Minor psxgpu/psxpad header changes --- examples/io/pads/main.c | 37 ++-- libpsn00b/include/psxgpu.h | 2 +- libpsn00b/include/psxpad.h | 328 ++++++++++++++++++--------------- libpsn00b/psxetc/_dl_resolve_wrapper.s | 6 +- libpsn00b/psxgpu/gettimimage.c | 2 +- 5 files changed, 203 insertions(+), 172 deletions(-) (limited to 'libpsn00b/include') diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c index 92beb1c..cc4ef56 100644 --- a/examples/io/pads/main.c +++ b/examples/io/pads/main.c @@ -118,16 +118,16 @@ static volatile uint8_t pad_buff[2][34]; static volatile size_t pad_buff_len[2]; static volatile uint32_t pad_digital_only[2] = { 0, 0 }; -// Just a wrapper around spi_new_request(). This does not send the command +// Just a wrapper around SPI_CreateRequest(). This does not send the command // immediately but adds it to the driver's request queue. void send_pad_cmd( - uint32_t port, - PAD_COMMAND cmd, - uint8_t arg1, - uint8_t arg2, - SPICALLBACK callback + uint32_t port, + PadCommand cmd, + uint8_t arg1, + uint8_t arg2, + SPI_Callback callback ) { - SPIREQUEST *req = spi_new_request(); + SPI_request *req = SPI_CreateRequest(); req->len = 9; req->port = port; @@ -150,12 +150,12 @@ void send_pad_cmd( // actually a DualShock in digital mode by checking if it started identifying // as CONFIG_MODE after receiving a configuration command. void dualshock_init_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { - PADTYPE *pad = (PADTYPE *) buff; + PadResponse *pad = (PadResponse *) buff; if ( (rx_len < 2) || - (pad->raw.prefix != 0x5a) || - (pad->raw.type != PAD_ID_CONFIG_MODE) + (pad->prefix != 0x5a) || + (pad->type != PAD_ID_CONFIG_MODE) ) { printf("no, pad is digital-only (len = %d)\n", rx_len); @@ -187,7 +187,7 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { if (rx_len) memcpy((void *) pad_buff[port], (void *) buff, rx_len); - PADTYPE *pad = (PADTYPE *) buff; + PadResponse *pad = (PadResponse *) buff; // If this pad identifies as a digital pad and hasn't been flagged as a // digital-only pad already, attempt to put it into analog mode by entering @@ -196,8 +196,8 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { // returning digital pad responses. if ( rx_len && - (pad->raw.prefix == 0x5a) && - (pad->raw.type == PAD_ID_DIGITAL) + (pad->prefix == 0x5a) && + (pad->type == PAD_ID_DIGITAL) ) { if (!pad_digital_only[port]) { printf("Detecting if pad %d supports config mode... ", port + 1); @@ -221,7 +221,7 @@ static CONTEXT ctx; int main(int argc, const char* argv[]) { init_context(&ctx); - spi_init(&poll_cb); + SPI_Init(&poll_cb); uint32_t counter = 0; @@ -238,15 +238,14 @@ int main(int argc, const char* argv[]) { continue; } - PADTYPE *pad = (PADTYPE *) pad_buff[port]; - PAD_TYPEID type = pad->raw.type; + PadResponse *pad = (PadResponse *) pad_buff[port]; // According to nocash docs, there is a hardware bug in DualShock // controllers that causes the prefix byte (normally 0x5a) to turn // into 0x00 if the analog button is pressed after configuration // commands have been used. Thus making sure the prefix is 0x5a // isn't enough to reliably detect pads. - /*if ((pad->raw.prefix != 0x5a) && (type != PAD_ID_ANALOG)) { + /*if ((pad->prefix != 0x5a) && (pad->type != PAD_ID_ANALOG)) { FntPrint(-1, "\n\nPORT %d: INVALID RESPONSE\n", port + 1); if ((counter % 64) < 32) FntPrint(-1, " CHECK CONNECTION..."); @@ -258,8 +257,8 @@ int main(int argc, const char* argv[]) { -1, "\n\nPORT %d: %s (TYPE=%d)\n", port + 1, - PAD_TYPEIDS[type], - type + PAD_TYPEIDS[pad->type], + pad->type ); // Print a hexdump of the payload returned by the pad. diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h index f50b841..f061219 100644 --- a/libpsn00b/include/psxgpu.h +++ b/libpsn00b/include/psxgpu.h @@ -609,7 +609,7 @@ void AddPrim(u_long* ot, void* pri); // Function definitions (C) -int GetTimInfo(u_long *tim, TIM_IMAGE *timimg); /* ORIGINAL */ +int GetTimInfo(const u_long *tim, TIM_IMAGE *timimg); /* ORIGINAL */ DISPENV *SetDefDispEnv(DISPENV *disp, int x, int y, int w, int h); DRAWENV *SetDefDrawEnv(DRAWENV *draw, int x, int y, int w, int h); diff --git a/libpsn00b/include/psxpad.h b/libpsn00b/include/psxpad.h index d152896..9638ec1 100644 --- a/libpsn00b/include/psxpad.h +++ b/libpsn00b/include/psxpad.h @@ -14,43 +14,48 @@ #ifndef _PSXPAD_H #define _PSXPAD_H -// Pad button definitions for digital pad, joystick, dual analog, -// Dualshock and Jogcon -#define PAD_SELECT 1 -#define PAD_L3 2 -#define PAD_R3 4 -#define PAD_START 8 -#define PAD_UP 16 -#define PAD_RIGHT 32 -#define PAD_DOWN 64 -#define PAD_LEFT 128 -#define PAD_L2 256 -#define PAD_R2 512 -#define PAD_L1 1024 -#define PAD_R1 2048 -#define PAD_TRIANGLE 4096 -#define PAD_CIRCLE 8192 -#define PAD_CROSS 16384 -#define PAD_SQUARE 32768 - -// Mouse button definitions -#define MOUSE_RIGHT 1024 -#define MOUSE_LEFT 2048 - -// neGcon button definitions -#define NCON_START 8 -#define NCON_UP 16 -#define NCON_RIGHT 32 -#define NCON_DOWN 64 -#define NCON_LEFT 128 -#define NCON_R 256 -#define NCON_B 512 -#define NCON_A 1024 - -// Guncon button definitions -#define GCON_A 8 -#define GCON_TRIGGER 8192 -#define GCON_B 16384 +#include + +/* Controller type and button definitions */ + +typedef enum { + // Standard pads, analog joystick, Jogcon + PAD_SELECT = 1 << 0, + PAD_L3 = 1 << 1, + PAD_R3 = 1 << 2, + PAD_START = 1 << 3, + PAD_UP = 1 << 4, + PAD_RIGHT = 1 << 5, + PAD_DOWN = 1 << 6, + PAD_LEFT = 1 << 7, + PAD_L2 = 1 << 8, + PAD_R2 = 1 << 9, + PAD_L1 = 1 << 10, + PAD_R1 = 1 << 11, + PAD_TRIANGLE = 1 << 12, + PAD_CIRCLE = 1 << 13, + PAD_CROSS = 1 << 14, + PAD_SQUARE = 1 << 15, + + // Mouse + MOUSE_LEFT = 1 << 10, + MOUSE_RIGHT = 1 << 11, + + // neGcon + NCON_START = 1 << 3, + NCON_UP = 1 << 4, + NCON_RIGHT = 1 << 5, + NCON_DOWN = 1 << 6, + NCON_LEFT = 1 << 7, + NCON_R = 1 << 8, + NCON_B = 1 << 9, + NCON_A = 1 << 10, + + // Guncon + GCON_A = 1 << 3, + GCON_TRIGGER = 1 << 13, + GCON_B = 1 << 14 +} PadButton; typedef enum { PAD_ID_MOUSE = 0x1, // Sony PS1 mouse @@ -64,9 +69,10 @@ typedef enum { PAD_ID_JOGCON = 0xe, // Namco Jogcon PAD_ID_CONFIG_MODE = 0xf, // Dual Analog/DualShock in config mode (if len == 0x3) PAD_ID_NONE = 0xf // No pad connected (if len == 0xf) -} PAD_TYPEID; +} PadTypeID; + +/* Pad and memory card commands */ -// Controller command definitions typedef enum { PAD_CMD_INIT_PRESSURE = '@', // Initialize DS2 button pressure sensors (in config mode) PAD_CMD_READ = 'B', // Read pad state and set rumble @@ -74,131 +80,155 @@ typedef enum { 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_COMMAND; + PAD_CMD_RESPONSE_CONFIG = 'O', // Configure response/unlock DS2 pressure (in config mode) -// Memory card command/response definitions -typedef enum { - MCD_CMD_READ = 'R', // Read sector - MCD_CMD_IDENTIFY = 'S', // Retrieve ID and card size information - MCD_CMD_WRITE = 'W' // Write sector -} MCD_COMMAND; + MCD_CMD_READ_SECTOR = 'R', // Read 128-byte sector + MCD_CMD_IDENTIFY = 'S', // Retrieve ID and card size information (Sony cards only) + MCD_CMD_WRITE_SECTOR = 'W' // Erase and write 128-byte sector +} PadCommand; typedef enum { MCD_STAT_OK = 'G', MCD_STAT_BAD_CHECKSUM = 'N', MCD_STAT_BAD_SECTOR = 0xff -} MCD_STATUS; - -#define MCD_CMD_READ_LEN 139 -#define MCD_CMD_IDENTIFY_LEN 9 -#define MCD_CMD_WRITE_LEN 137 - -// Memory card status flags -#define MCD_FLAG_WRITE_ERROR 4 // Last write command failed -#define MCD_FLAG_NOT_WRITTEN 8 // No writes have been issued yet -#define MCD_FLAG_UNKNOWN 16 // Might be set on third-party cards - -// Struct for data returned by controllers -typedef struct _PADTYPE { - union { // Header: - struct __attribute__((packed)) { // When parsing data returned by BIOS: - unsigned char stat; // Status - unsigned char len:4; // Payload length / 2, 0 for multitap - unsigned char type:4; // Device type (PAD_TYPEID) +} MemCardStatus; + +typedef enum { + MCD_FLAG_WRITE_ERROR = 1 << 2, // Last write command failed + MCD_FLAG_NOT_WRITTEN = 1 << 3, // No writes have been issued yet + MCD_FLAG_UNKNOWN = 1 << 4 // Might be set on third-party cards +} MemCardStatusFlag; + +#define MEMCARD_CMD_READ_LEN 139 +#define MEMCARD_CMD_IDENTIFY_LEN 9 +#define MEMCARD_CMD_WRITE_LEN 137 + +/* Controller response as returned by BIOS driver */ + +typedef struct __attribute__((packed)) _PADTYPE { + uint8_t stat; // Status + uint8_t len:4; // Payload length / 2, 0 for multitap + uint8_t type:4; // Device type (PadTypeID) + + uint16_t btn; // Button states + union { + struct { // Analog controller: + uint8_t rs_x,rs_y; // - Right stick coordinates + uint8_t ls_x,ls_y; // - Left stick coordinates + uint8_t press[12]; // - Button pressure (DualShock 2 only) }; - struct __attribute__((packed)) { // When parsing raw controller response: - unsigned char len:4; // Payload length / 2, 0 for multitap - unsigned char type:4; // Device type (PAD_TYPEID) - unsigned char prefix; // Must be 0x5a - } raw; - }; - struct { // Payload: - unsigned short btn; // Button states - union { - struct { // Analog controller: - unsigned char rs_x,rs_y; // Right stick coordinates - unsigned char ls_x,ls_y; // Left stick coordinates - unsigned char press[12]; // Button pressure (DualShock 2 only) - }; - struct { // Mouse: - char x_mov; // X movement of mouse - char y_mov; // Y movement of mouse - }; - struct { // neGcon: - unsigned char twist; // Controller twist - unsigned char btn_i; // I button value - unsigned char btn_ii; // II button value - unsigned char trg_l; // L trigger value - }; - struct { // Jogcon: - unsigned short jog_rot; // Jog rotation - }; - struct { // Guncon: - unsigned short gun_x; // Gun X position in dotclocks - unsigned short gun_y; // Gun Y position in scanlines - }; + struct { // Mouse: + int8_t x_mov; // - X movement of mouse + int8_t y_mov; // - Y movement of mouse + }; + struct { // neGcon: + uint8_t twist; // - Controller twist + uint8_t btn_i; // - I button value + uint8_t btn_ii; // - II button value + uint8_t trg_l; // - L trigger value + }; + struct { // Jogcon: + uint16_t jog_rot; // - Jog rotation + }; + struct { // Guncon: + uint16_t gun_x; // - Gun X position in dotclocks + uint16_t gun_y; // - Gun Y position in scanlines }; }; } PADTYPE; -typedef struct _MCDRESPONSE { - unsigned char flags; // Status flags - unsigned char type1; // Must be 0x5a - unsigned char type2; // Must be 0x5d +//typedef struct _PADTYPE MOUSETYPE; +//typedef struct _PADTYPE NCONTYPE; +//typedef struct _PADTYPE JCONTYPE; +//typedef struct _PADTYPE GCONTYPE; + +/* Raw responses */ + +typedef struct __attribute__((packed)) _PadResponse { + uint8_t len:4; // Payload length / 2, 0 for multitap + uint8_t type:4; // Device type (PadTypeID) + uint8_t prefix; // Must be 0x5a + + uint16_t btn; // Button states + union { + struct { // Analog controller: + uint8_t rs_x,rs_y; // - Right stick coordinates + uint8_t ls_x,ls_y; // - Left stick coordinates + uint8_t press[12]; // - Button pressure (DualShock 2 only) + }; + struct { // Mouse: + int8_t x_mov; // - X movement of mouse + int8_t y_mov; // - Y movement of mouse + }; + struct { // neGcon: + uint8_t twist; // - Controller twist + uint8_t btn_i; // - I button value + uint8_t btn_ii; // - II button value + uint8_t trg_l; // - L trigger value + }; + struct { // Jogcon: + uint16_t jog_rot; // - Jog rotation + }; + struct { // Guncon: + uint16_t gun_x; // - Gun X position in dotclocks + uint16_t gun_y; // - Gun Y position in scanlines + }; + }; +} PadResponse; + +typedef struct __attribute__((packed)) _MemCardResponse { + uint8_t flags; // Status flags (MemCardStatusFlag) + uint8_t type1; // Must be 0x5a + uint8_t type2; // Must be 0x5d + union { - struct { // MCD_CMD_READ response: - unsigned char dummy[2]; - unsigned char ack1; // Must be 0x5c - unsigned char ack2; // Must be 0x5d - unsigned char lba_h; - unsigned char lba_l; - unsigned char data[128]; - unsigned char checksum; // = lba_h ^ lba_l ^ data - unsigned char stat; // Status (MCD_STATUS) + struct { // CMD_READ response: + uint8_t dummy[2]; + uint8_t ack1; // Must be 0x5c + uint8_t ack2; // Must be 0x5d + uint8_t lba_h; + uint8_t lba_l; + uint8_t data[128]; + uint8_t checksum; // = lba_h ^ lba_l ^ data + uint8_t stat; // Status (MemCardStatus) } read; - struct { // MCD_CMD_IDENTIFY response: - unsigned char ack1; // Must be 0x5c - unsigned char ack2; // Must be 0x5d - unsigned char size_h; // Card capacity bits 8-15 (0x04 = 128KB) - unsigned char size_l; // Card capacity bits 0-7 (0x00 = 128KB) - unsigned char blksize_h; // Sector size bits 8-15 (must be 0x00) - unsigned char blksize_l; // Sector size bits 0-7 (must be 0x80) + struct { // CMD_IDENTIFY response: + uint8_t ack1; // Must be 0x5c + uint8_t ack2; // Must be 0x5d + uint8_t size_h; // Card capacity bits 8-15 (0x04 = 128KB) + uint8_t size_l; // Card capacity bits 0-7 (0x00 = 128KB) + uint8_t blksize_h; // Sector size bits 8-15 (must be 0x00) + uint8_t blksize_l; // Sector size bits 0-7 (must be 0x80) } identify; - struct { // MCD_CMD_WRITE response: - unsigned char dummy[131]; - unsigned char ack1; // Must be 0x5c - unsigned char ack2; // Must be 0x5d - unsigned char stat; // Status (MCD_STATUS) + struct { // CMD_WRITE response: + uint8_t dummy[131]; + uint8_t ack1; // Must be 0x5c + uint8_t ack2; // Must be 0x5d + uint8_t stat; // Status (MemCardStatus) } write; }; -} MCDRESPONSE; - -//typedef PADTYPE MOUSETYPE; -//typedef PADTYPE NCONTYPE; -//typedef PADTYPE JCONTYPE; -//typedef PADTYPE GCONTYPE; - -// Structs for raw controller request -typedef struct _PADREQUEST { - unsigned char addr; // Must be 0x01 (or 02/03/04 for multitap pads) - unsigned char cmd; // Command (PAD_COMMAND) - unsigned char tap_mode; // 0x01 to enable multitap response - unsigned char motor_r; // Right motor control (on/off) - unsigned char motor_l; // Left motor control (PWM) - unsigned char dummy[4]; -} PADREQUEST; - -// Structs for raw memory card request -typedef struct _MCDREQUEST { - unsigned char addr; // Must be 0x81 (or 02/03/04 for multitap cards) - unsigned char cmd; // Command (MCD_COMMAND) - unsigned char dummy[2]; - unsigned char lba_h; // Sector address bits 8-15 (dummy for CMD_IDENTIFY) - unsigned char lba_l; // Sector address bits 0-7 (dummy for CMD_IDENTIFY) - unsigned char data[128]; // Sector payload (dummy for CMD_READ/CMD_IDENTIFY) - unsigned char checksum; // = lba_h ^ lba_l ^ data (CMD_WRITE only) - unsigned char dummy2[3]; -} MCDREQUEST; +} MemCardResponse; + +/* Raw requests */ + +typedef struct __attribute__((packed)) _PadRequest { + uint8_t addr; // Must be 0x01 (or 02/03/04 for multitap pads) + uint8_t cmd; // Command (PadCommand) + uint8_t tap_mode; // 0x01 to enable multitap response + uint8_t motor_r; // Right motor control (on/off) + uint8_t motor_l; // Left motor control (PWM) + uint8_t dummy[4]; +} PadRequest; + +typedef struct __attribute__((packed)) _MemCardRequest { + uint8_t addr; // Must be 0x81 (or 02/03/04 for multitap cards) + uint8_t cmd; // Command (MemCardCommand) + uint8_t dummy[2]; + uint8_t lba_h; // Sector address bits 8-15 (dummy for CMD_IDENTIFY) + uint8_t lba_l; // Sector address bits 0-7 (dummy for CMD_IDENTIFY) + uint8_t data[128]; // Sector payload (dummy for CMD_READ/CMD_IDENTIFY) + uint8_t checksum; // = lba_h ^ lba_l ^ data (CMD_WRITE only) + uint8_t dummy2[3]; +} MemCardRequest; #endif \ No newline at end of file diff --git a/libpsn00b/psxetc/_dl_resolve_wrapper.s b/libpsn00b/psxetc/_dl_resolve_wrapper.s index 7f1132b..01ebf3a 100644 --- a/libpsn00b/psxetc/_dl_resolve_wrapper.s +++ b/libpsn00b/psxetc/_dl_resolve_wrapper.s @@ -48,7 +48,9 @@ _dl_resolve_wrapper: jr $t0 nop -.global _dl_credits -.type _dl_credits, @object +.section .data + +.global _dl_credits +.type _dl_credits, @object _dl_credits: .asciiz "psxetc runtime dynamic linker by spicyjpeg\n" diff --git a/libpsn00b/psxgpu/gettimimage.c b/libpsn00b/psxgpu/gettimimage.c index d9cf1bf..5598e07 100644 --- a/libpsn00b/psxgpu/gettimimage.c +++ b/libpsn00b/psxgpu/gettimimage.c @@ -1,7 +1,7 @@ #include #include -int GetTimInfo(u_long *tim, TIM_IMAGE *timimg) { +int GetTimInfo(const u_long *tim, TIM_IMAGE *timimg) { u_long *rtim; -- cgit v1.2.3