diff options
| author | John "Lameguy" Wilbert Villamor <lameguy64@gmail.com> | 2021-11-22 14:40:59 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-22 14:40:59 +0800 |
| commit | 45123e1b968d1883fed9b8526157ce2c4bffc4a7 (patch) | |
| tree | d20c80fbd4f5a5d1d3972669625972cea6b3684d /libpsn00b | |
| parent | 538f28cfbbbb8163ab8a96de77d6887123856c81 (diff) | |
| parent | 9b00e5f7ff163a8fc6f341dbf237d90c61dadddc (diff) | |
| download | psn00bsdk-45123e1b968d1883fed9b8526157ce2c4bffc4a7.tar.gz | |
Merge pull request #43 from spicyjpeg/cmake
Even more CMake fixes, submodules, pads example
Diffstat (limited to 'libpsn00b')
| -rw-r--r-- | libpsn00b/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | libpsn00b/cmake/internal_setup.cmake | 8 | ||||
| -rw-r--r-- | libpsn00b/cmake/sdk.cmake | 2 | ||||
| -rw-r--r-- | libpsn00b/cmake/virtual_targets.cmake | 4 | ||||
| -rw-r--r-- | libpsn00b/include/malloc.h | 14 | ||||
| -rw-r--r-- | libpsn00b/include/psxapi.h | 32 | ||||
| -rw-r--r-- | libpsn00b/include/psxpad.h | 203 | ||||
| -rw-r--r-- | libpsn00b/include/stdint.h | 16 | ||||
| -rw-r--r-- | libpsn00b/include/stdlib.h | 28 | ||||
| -rw-r--r-- | libpsn00b/include/sys/types.h | 16 | ||||
| -rw-r--r-- | libpsn00b/libc/c++-support.cxx | 3 | ||||
| -rw-r--r-- | libpsn00b/libc/start.c | 42 | ||||
| -rw-r--r-- | libpsn00b/libc/string.c | 2 | ||||
| -rw-r--r-- | libpsn00b/libc/vsprintf.c | 14 | ||||
| -rw-r--r-- | libpsn00b/lzp/compress.c | 1 | ||||
| -rw-r--r-- | libpsn00b/psxapi/sys/getsysteminfo.s | 10 | ||||
| -rw-r--r-- | libpsn00b/psxcd/isofs.c | 2 | ||||
| -rw-r--r-- | libpsn00b/psxetc/dl.c | 4 | ||||
| -rw-r--r-- | libpsn00b/psxgpu/font.c | 2 |
19 files changed, 271 insertions, 134 deletions
diff --git a/libpsn00b/CMakeLists.txt b/libpsn00b/CMakeLists.txt index 083208a..7b5f7a5 100644 --- a/libpsn00b/CMakeLists.txt +++ b/libpsn00b/CMakeLists.txt @@ -1,7 +1,7 @@ # libpsn00b build script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) # ${PROJECT_SOURCE_DIR} is not available until project() is called. set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/cmake/sdk.cmake) diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index 377afbc..b0c4591 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -4,7 +4,7 @@ # This script is included automatically when using the toolchain file and # defines helper functions. -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) include(GNUInstallDirs) # IMPORTANT TODO: set a version number @@ -86,16 +86,14 @@ function(psn00bsdk_add_executable name type) endif() add_executable (${name} ${ARGN}) - target_link_libraries(${name} psn00bsdk_${_type}_exe) + target_link_libraries(${name} psn00bsdk_${_type}_exe ${PSN00BSDK_LIBRARIES}) set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX ".elf") target_link_options (${name} PRIVATE -T${PSN00BSDK_LDSCRIPTS}/exe.ld) target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE}) # Add post-build steps to generate the .exe and symbol map once the - # executable is built. CMake 3.21 added support for target-dependent - # generator expressions (catchy name lol) in add_custom_command(), so I'm - # making heavy use of those here. + # executable is built. add_custom_command( TARGET ${name} POST_BUILD COMMAND ${ELF2X} -q ${name}.elf ${name}${PSN00BSDK_EXECUTABLE_SUFFIX} diff --git a/libpsn00b/cmake/sdk.cmake b/libpsn00b/cmake/sdk.cmake index 4c2f330..ae23a06 100644 --- a/libpsn00b/cmake/sdk.cmake +++ b/libpsn00b/cmake/sdk.cmake @@ -1,7 +1,7 @@ # PSn00bSDK toolchain setup file for CMake # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) set( PSN00BSDK_TC $ENV{PSN00BSDK_TC} diff --git a/libpsn00b/cmake/virtual_targets.cmake b/libpsn00b/cmake/virtual_targets.cmake index df1df79..9afcebd 100644 --- a/libpsn00b/cmake/virtual_targets.cmake +++ b/libpsn00b/cmake/virtual_targets.cmake @@ -72,7 +72,7 @@ set(_cflags -mno-abicalls -mgpopt -mno-extern-sdata) set(_cxxflags) set(_ldflags -G8 -static) -_add_interface_target(psn00bsdk_static_exe psn00bsdk_common ${PSN00BSDK_LIBRARIES}) +_add_interface_target(psn00bsdk_static_exe psn00bsdk_common) # Options for executables with support for dynamic linking: # - Position-independent code disabled @@ -83,7 +83,7 @@ set(_cflags -mno-abicalls -mno-gpopt) set(_cxxflags) set(_ldflags -G0 -static) -_add_interface_target(psn00bsdk_dynamic_exe psn00bsdk_common ${PSN00BSDK_LIBRARIES}) +_add_interface_target(psn00bsdk_dynamic_exe psn00bsdk_common) # Options for static libraries: # - GP-relative addressing disabled diff --git a/libpsn00b/include/malloc.h b/libpsn00b/include/malloc.h index d94823f..75c3711 100644 --- a/libpsn00b/include/malloc.h +++ b/libpsn00b/include/malloc.h @@ -1,18 +1,8 @@ #ifndef _MALLOC_H #define _MALLOC_H -#ifdef __cplusplus -extern "C" { -#endif +#warning "<malloc.h> is deprecated, include <stdlib.h> instead" -unsigned int *GetBSSend(); -void InitHeap(unsigned int *addr, int size); -int SetHeapSize(int size); -void *malloc(int size); -void free(void *ptr); - -#ifdef __cplusplus -} -#endif +#include <stdlib.h> #endif // _MALLOC_H
\ No newline at end of file diff --git a/libpsn00b/include/psxapi.h b/libpsn00b/include/psxapi.h index 9e92568..ec0dfea 100644 --- a/libpsn00b/include/psxapi.h +++ b/libpsn00b/include/psxapi.h @@ -32,6 +32,35 @@ #define RCntMdFR 0x0000 #define RCntMdGATE 0x0010 +typedef struct { // Thread control block + int status; + int mode; + union { + unsigned int reg[37]; + struct { + unsigned int zero, at; + unsigned int v0, v1; + unsigned int a0, a1, a2, a3; + unsigned int t0, t1, t2, t3, t4, t5, t6, t7; + unsigned int s0, s1, s2, s3, s4, s5, s6, s7; + unsigned int t8, t9; + unsigned int k0, k1; + unsigned int gp, sp, fp, ra; + + unsigned int cop0r14; + unsigned int hi; + unsigned int lo; + unsigned int cop0r12; + unsigned int cop0r13; + }; + }; + int _reserved[9]; +} TCB; + +typedef struct { // Process control block + TCB *thread; +} PCB; + typedef struct { // Device control block char *name; int flags; @@ -182,6 +211,9 @@ void ChangeClearRCnt(int t, int m); int Exec(struct EXEC *exec, int argc, char **argv); void FlushCache(void); +// Misc functions +int GetSystemInfo(int index); + void _boot(void); #ifdef __cplusplus diff --git a/libpsn00b/include/psxpad.h b/libpsn00b/include/psxpad.h index 01aff06..d152896 100644 --- a/libpsn00b/include/psxpad.h +++ b/libpsn00b/include/psxpad.h @@ -3,10 +3,12 @@ * 2019 Lameguy64 / Meido-Tek Productions * * Currently only provides a bunch of definitions and a few structs but no - * handling functions yet. Use the code in pad.s in one of the sample - * programs for the meantime instead. + * handling functions yet. See the io/pads example for a simple manual pollling + * implementation (with support for DualShock 2 controllers). * * Work in progress, subject to change significantly in future releases. + * + * Reference: https://gist.github.com/scanlime/5042071 */ #ifndef _PSXPAD_H @@ -50,58 +52,153 @@ #define GCON_TRIGGER 8192 #define GCON_B 16384 -// Struct for digital, joystick, dual analog and Dualshock controllers -typedef struct { - unsigned char stat; // Status - unsigned char len:4; // Data length (in halfwords) - unsigned char type:4; // Device type: - // 0x4 - digital pad - // 0x5 - analog joystick - // 0x7 - dual analog & Dualshock - unsigned short btn; // Button states - unsigned char rs_x,rs_y; // Right stick coordinates - unsigned char ls_x,ls_y; // Left stick coordinates +typedef enum { + PAD_ID_MOUSE = 0x1, // Sony PS1 mouse + PAD_ID_NEGCON = 0x2, // Namco neGcon + PAD_ID_IRQ10_GUN = 0x3, // "Konami" lightgun without composite video passthrough + PAD_ID_DIGITAL = 0x4, // Digital pad or Dual Analog/DualShock in digital mode + PAD_ID_ANALOG_STICK = 0x5, // Flight stick or Dual Analog in green LED mode + PAD_ID_GUNCON = 0x6, // Namco Guncon (lightgun with composite video passthrough) + PAD_ID_ANALOG = 0x7, // Dual Analog/DualShock in analog (red LED) mode + PAD_ID_MULTITAP = 0x8, // Multitap adapter (when tap_mode == 1) + 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; + +// 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 + 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_COMMAND; + +// 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; + +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) + }; + 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 + }; + }; + }; } PADTYPE; -// Struct for a mouse controller -typedef struct { - unsigned char stat; - unsigned char len:4; - unsigned char type:4; // Device type (0x1) - unsigned short btn; - char x_mov; // X movement of mouse - char y_mov; // Y movement of mouse -} MOUSETYPE; - -// Struct for a neGcon controller (for Namco neGcon) -typedef struct { - unsigned char stat; - unsigned char len:4; - unsigned char type:4; // (0x2) - unsigned short btn; - 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 -} NCONTYPE; - -// Struct for a Jogcon controller (for Namco Jogcon) -typedef struct { - unsigned char stat; - unsigned char len:4; - unsigned char type:4; // (0xE) - unsigned short btn; - unsigned short jog_rot; // Jog rotation -} JCONTYPE; - -// Struct for a Gun-Con controller (for Namco Gun-Con) -typedef struct { - unsigned char status; - unsigned char len:4; - unsigned char type:4; // (0x6) - unsigned short btn; - unsigned short gun_x; // Gun X position in dotclocks - unsigned short gun_y; // Gun Y position in scanlines -} GCONTYPE; +typedef struct _MCDRESPONSE { + unsigned char flags; // Status flags + unsigned char type1; // Must be 0x5a + unsigned char 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) + } 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) + } 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) + } 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; #endif
\ No newline at end of file diff --git a/libpsn00b/include/stdint.h b/libpsn00b/include/stdint.h new file mode 100644 index 0000000..83acb00 --- /dev/null +++ b/libpsn00b/include/stdint.h @@ -0,0 +1,16 @@ +#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 474eba6..de3ab47 100644 --- a/libpsn00b/include/stdlib.h +++ b/libpsn00b/include/stdlib.h @@ -19,34 +19,16 @@ extern long atol(char *s); extern char atob(char *s); // Is this right? */ -// Random number functions (not yet implemented) - -/* -int rand(); -void srand(unsigned int seed); -*/ - // Quick sort (not yet implemented) //void qsort(void *base , int nel , int width , int (*cmp)(const void *,const void *)); -// Memory allocation functions (not yet implemented, avoid using BIOS as they are reportedly buggy) - -/* -#warning "malloc() family of functions NEEDS MORE TESTING" - -void *malloc(int size); -void free(void *buf); -void *calloc(int number, int size); -void *realloc(void *buf , int n); -*/ - #ifdef __cplusplus extern "C" { #endif extern int __argc; -extern char __argv[]; +extern const char **__argv; int rand(); void srand(unsigned long seed); @@ -64,6 +46,14 @@ long atol(const char *s); double strtod(const char *nptr, char **endptr); float strtof(const char *nptr, char **endptr); +// Memory allocation functions +unsigned int *GetBSSend(); +void InitHeap(unsigned int *addr, int size); +int SetHeapSize(int size); +void *malloc(int size); +void *calloc(int number, int size); +void free(void *ptr); + #ifdef __cplusplus } #endif diff --git a/libpsn00b/include/sys/types.h b/libpsn00b/include/sys/types.h index aee197e..da43590 100644 --- a/libpsn00b/include/sys/types.h +++ b/libpsn00b/include/sys/types.h @@ -1,21 +1,13 @@ #ifndef _TYPES_H #define _TYPES_H +//#warning "<sys/types.h> and u_* types are deprecated, include <stdint.h> instead" + +//#include <stdint.h> + typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long; -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 // _TYPES_H
\ No newline at end of file diff --git a/libpsn00b/libc/c++-support.cxx b/libpsn00b/libc/c++-support.cxx index fcf7cfc..d169fdb 100644 --- a/libpsn00b/libc/c++-support.cxx +++ b/libpsn00b/libc/c++-support.cxx @@ -1,7 +1,6 @@ #include <assert.h> -#include <sys/types.h> +#include <stdint.h> #include <stdlib.h> -#include <malloc.h> extern "C" diff --git a/libpsn00b/libc/start.c b/libpsn00b/libc/start.c index c5872df..f190794 100644 --- a/libpsn00b/libc/start.c +++ b/libpsn00b/libc/start.c @@ -3,9 +3,9 @@ * (C) 2021 Lameguy64, spicyjpeg - MPL licensed */ -#include <sys/types.h> +#include <stdint.h> #include <string.h> -#include <malloc.h> +#include <stdlib.h> #define KERNEL_ARG_STRING ((const char *) 0x80000180) #define KERNEL_RETURN_VALUE ((volatile int *) 0x8000dffc) @@ -47,13 +47,7 @@ static void _parse_kernel_args() { } } -/* Main */ - -// How much space at the end of RAM to leave for the stack (instead of using it -// as heap). By default 128 KB are reserved for the stack, but this constant -// can be overridden in main.c (or anywhere else) simply by redeclaring it -// without the weak attribute. -const int32_t __attribute__((weak)) STACK_MAX_SIZE = 0x20000; +/* Heap initialization */ // These are defined by the linker script. Note that these are *NOT* pointers, // they are virtual symbols whose location matches their value. The simplest @@ -63,6 +57,20 @@ extern uint8_t __bss_start[]; extern uint8_t _end[]; //extern uint8_t _gp[]; +// This function should not be called manually in most cases. It might be +// 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; + + InitHeap(exe_end, ram_size - ram_used); +} + +/* Main */ + extern void (*__CTOR_LIST__[])(void); extern void (*__DTOR_LIST__[])(void); @@ -73,24 +81,16 @@ extern int32_t main(int32_t argc, const char* argv[]); // to overwrite the arg strings in kernel RAM. void _start(int32_t override_argc, const char **override_argv) { __asm__ volatile("la $gp, _gp;"); - - // Mem init assembly function (clears BSS and InitHeap to _end which is - // not possible to do purely in C because the linker complains about - // relocation truncated to fit: R_MIPS_GPREL16 against `_end' - // Workaround is to do it in assembly because la pseudo-op doesn't use - // stupid gp relative addressing - //_mem_init(); // Clear BSS 4 bytes at a time. BSS is always aligned to 4 bytes by the // linker script. for (uint32_t *i = (uint32_t *) __bss_start; i < (uint32_t *) _end; i++) *i = 0; - // Calculate how much RAM is available after the loaded executable and - // initialize heap accordingly. - void *exe_end = _end + 4; - unsigned int exe_size = (unsigned int) exe_end - (unsigned int) __text_start; - InitHeap(exe_end, 0x200000 - (exe_size + STACK_MAX_SIZE)); + // Initialize the heap, assuming 2 MB of RAM and reserving 128 KB for the + // stack. Note that _mem_init() can be called again in main() to change + // these values. + _mem_init(0x200000, 0x20000); if (override_argv) { __argc = override_argc; diff --git a/libpsn00b/libc/string.c b/libpsn00b/libc/string.c index e11ed67..445b227 100644 --- a/libpsn00b/libc/string.c +++ b/libpsn00b/libc/string.c @@ -6,7 +6,7 @@ #include <stdio.h> #include <string.h> -#include <malloc.h> +#include <stdlib.h> int tolower(int chr) { diff --git a/libpsn00b/libc/vsprintf.c b/libpsn00b/libc/vsprintf.c index 361b24e..0a99dcc 100644 --- a/libpsn00b/libc/vsprintf.c +++ b/libpsn00b/libc/vsprintf.c @@ -58,6 +58,15 @@ pad_quantity = (pad_quantity - 1) - last; \ if(pad_quantity < 0) pad_quantity = 0; +#define calculate_real_padding_bin() \ + last = 0; \ + for (x = 0; x < 32; x++) \ + if((arg >> x) & 1) \ + last = x; \ + \ + pad_quantity = (pad_quantity - 1) - last; \ + if(pad_quantity < 0) pad_quantity = 0; + #define write_padding() \ if(!(flags & SPRINTF_NEGFIELD_FLAG)) \ for(x = 0; x < pad_quantity; x++) \ @@ -703,6 +712,9 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap) //else // arg = va_arg(ap, unsigned long long); + calculate_real_padding_bin(); + write_padding(); + for(x=31;x>=0;x--) { y = (arg >> x); @@ -715,6 +727,8 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap) put_in_string(string, ssz, y + '0', string_pos++); } + write_neg_padding(); + directive_coming = 0; break; diff --git a/libpsn00b/lzp/compress.c b/libpsn00b/lzp/compress.c index 5969dd6..9cfc64d 100644 --- a/libpsn00b/lzp/compress.c +++ b/libpsn00b/lzp/compress.c @@ -3,7 +3,6 @@ #include <string.h> #if LZP_USE_MALLOC == TRUE #include <stdlib.h> -#include <malloc.h> #endif #include "lzconfig.h" diff --git a/libpsn00b/psxapi/sys/getsysteminfo.s b/libpsn00b/psxapi/sys/getsysteminfo.s new file mode 100644 index 0000000..60c1d43 --- /dev/null +++ b/libpsn00b/psxapi/sys/getsysteminfo.s @@ -0,0 +1,10 @@ +.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/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index dc0c5ca..40a40af 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -1,6 +1,6 @@ #include <sys/types.h> #include <stdio.h> -#include <malloc.h> +#include <stdlib.h> #include <string.h> #include <psxgpu.h> #include <psxsio.h> diff --git a/libpsn00b/psxetc/dl.c b/libpsn00b/psxetc/dl.c index 586e7e1..e43374f 100644 --- a/libpsn00b/psxetc/dl.c +++ b/libpsn00b/psxetc/dl.c @@ -23,9 +23,9 @@ * of entries */ -#include <sys/types.h> +#include <stdint.h> #include <stdio.h> -#include <malloc.h> +#include <stdlib.h> #include <ctype.h> #include <elf.h> #include <dlfcn.h> diff --git a/libpsn00b/psxgpu/font.c b/libpsn00b/psxgpu/font.c index 7d0dd89..4c715a9 100644 --- a/libpsn00b/psxgpu/font.c +++ b/libpsn00b/psxgpu/font.c @@ -1,7 +1,7 @@ #include <sys/types.h> #include <stdio.h> #include <string.h> -#include <malloc.h> +#include <stdlib.h> #include <ctype.h> #include <psxgpu.h> |
