From aca79b2a75c9a6106bc0047f767a475a2c3aaf8e Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Wed, 9 Feb 2022 22:59:16 +0100 Subject: Rename hwregs_a definitions, add hwregs_c, fix io/pads --- examples/io/pads/main.c | 57 +++++++++++++++------------ examples/io/pads/spi.c | 103 +++++++++++++++++++++--------------------------- examples/io/pads/spi.h | 15 +++++-- 3 files changed, 89 insertions(+), 86 deletions(-) (limited to 'examples/io/pads') diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c index d100482..17bf331 100644 --- a/examples/io/pads/main.c +++ b/examples/io/pads/main.c @@ -15,12 +15,12 @@ * but the code in spi.c can be used to read/write sectors on a memory card and * combined with a higher-level filesystem driver for full support. * - * IMPORTANT: this example hasn't yet been tested on real hardware and/or with - * unofficial controllers, which might behave differently at higher poll rates. - * Also keep in mind that many emulators emulate controllers and memory cards - * inaccurately. It is thus recommended to test controller I/O code extensively - * and handle as many edge cases as possible (e.g. partial but valid responses, - * zerofilled responses, slow replies) for maximum compatibility. + * IMPORTANT: some controller models seem to be unable to respond to config + * mode commands reliably, even though simple high-speed polling usually works + * without issues. Also keep in mind that many emulators emulate controllers + * and memory cards inaccurately. It is thus recommended to test controller I/O + * code extensively and handle as many edge cases as possible (e.g. partial but + * valid responses, zerofilled responses, slow replies) for best compatibility. */ #include @@ -116,7 +116,7 @@ void display(CONTEXT *ctx) { 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 }; +static volatile uint32_t pad_config_attempt[2] = { 0, 0 }; // Just a wrapper around SPI_CreateRequest(). This does not send the command // immediately but adds it to the driver's request queue. @@ -148,7 +148,8 @@ void send_pad_cmd( // This callback determines whether a pad that identified as digital is // actually a DualShock in digital mode by checking if it started identifying -// as CONFIG_MODE after receiving a configuration command. +// as CONFIG_MODE after receiving a configuration command. Calls to printf() +// had to be commented out due to them being too slow. void dualshock_init_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { PadResponse *pad = (PadResponse *) buff; @@ -157,13 +158,13 @@ void dualshock_init_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_le (pad->prefix != 0x5a) || (pad->type != PAD_ID_CONFIG_MODE) ) { - printf("no, pad is digital-only (len = %d)\n", rx_len); + //printf("no, pad is digital-only (len = %d)\n", rx_len); - pad_digital_only[port] = 1; + pad_config_attempt[port]++; return; } - printf("yes, forcing analog mode (len = %d)\n", rx_len); + //printf("yes, forcing analog mode (len = %d)\n", rx_len); // Issue further commands to force analog mode on, unlock rumble (not used // in this example) and enable longer responses containing button pressure @@ -171,6 +172,7 @@ void dualshock_init_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_le // TODO: find out if passing 0x03 instead of 0x02 in PAD_CMD_SET_ANALOG // locks the analog button, as emulated by DuckStation... // https://gist.github.com/scanlime/5042071 + send_pad_cmd(port, PAD_CMD_CONFIG_MODE, 0x01, 0x00, 0); send_pad_cmd(port, PAD_CMD_SET_ANALOG, 0x01, 0x02, 0); send_pad_cmd(port, PAD_CMD_INIT_PRESSURE, 0x00, 0x00, 0); // Ignored by DualShock 1 send_pad_cmd(port, PAD_CMD_REQUEST_CONFIG, 0x00, 0x01, 0); @@ -189,29 +191,37 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { 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 - // configuration mode. It this fails, it will be flagged as digital-only. - // The digital-only flag is reset when the controller is unplugged or stops + // If this pad identifies as a digital pad, attempt to put it into analog + // mode up to 3 times by entering configuration mode. Once the attempt + // counter exceeds the threshold, it will be treated as digital-only. The + // attempt counter is reset when the controller is unplugged or stops // returning digital pad responses. + // NOTE: 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 config commands have been + // used. if ( rx_len && - (pad->prefix == 0x5a) && + ((pad->prefix == 0x5a) || !(pad->prefix)) && (pad->type == PAD_ID_DIGITAL) ) { - if (!pad_digital_only[port]) { - printf("Detecting if pad %d supports config mode... ", port + 1); + if (pad_config_attempt[port] < 3) { + /*printf( + "Detecting if pad %d supports config mode: attempt %d... ", + port + 1, + pad_config_attempt[port] + 1 + );*/ // The pad only identifies as CONFIG_MODE after at least another // command is sent. send_pad_cmd(port, PAD_CMD_CONFIG_MODE, 0x01, 0x00, 0); - send_pad_cmd(port, PAD_CMD_CONFIG_MODE, 0x01, 0x00, &dualshock_init_cb); + send_pad_cmd(port, PAD_CMD_READ, 0x00, 0x00, &dualshock_init_cb); } } else { - //printf("Clearing digital-only flag for pad %d\n", port + 1); + //printf("Clearing attempt counter for pad %d\n", port + 1); - pad_digital_only[port] = 0; + pad_config_attempt[port] = 0; } } @@ -240,11 +250,6 @@ int main(int argc, const char* argv[]) { 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->prefix != 0x5a) && (pad->type != PAD_ID_ANALOG)) { FntPrint(-1, "\n\nPORT %d: INVALID RESPONSE\n", port + 1); if ((counter % 64) < 32) diff --git a/examples/io/pads/spi.c b/examples/io/pads/spi.c index ef75ffc..05a0e59 100644 --- a/examples/io/pads/spi.c +++ b/examples/io/pads/spi.c @@ -32,43 +32,27 @@ #include #include #include +#include #include "spi.h" -/* Register definitions */ - -#define F_CPU 33868800UL - -#define TIM_VALUE(N) *((volatile uint32_t *) 0x1f801100 + 4 * (N)) -#define TIM_CTRL(N) *((volatile uint32_t *) 0x1f801104 + 4 * (N)) -#define TIM_RELOAD(N) *((volatile uint32_t *) 0x1f801108 + 4 * (N)) - -// 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 *((volatile uint8_t *) 0x1f801040) -#define JOY_STAT *((volatile uint16_t *) 0x1f801044) -#define JOY_MODE *((volatile uint16_t *) 0x1f801048) -#define JOY_CTRL *((volatile uint16_t *) 0x1f80104a) -#define JOY_BAUD *((volatile uint16_t *) 0x1f80104e) - /* Internal structures and globals */ -typedef struct _SPI_CONTEXT { +typedef struct _SPI_Context { uint8_t tx_buff[SPI_BUFF_LEN]; uint8_t rx_buff[SPI_BUFF_LEN]; uint32_t tx_len, rx_len, port; SPI_Callback callback; } SPI_Context; -static volatile SPI_Context ctx; -static volatile SPI_Request volatile *current_req; -static SPI_Callback default_cb; +static volatile SPI_Context _context; +static volatile SPI_Request volatile *_current_req; +static volatile SPI_Callback _default_cb; /* Request queue management */ static void _spi_create_poll_req(void) { - PadRequest *req = (PadRequest *) ctx.tx_buff; + PadRequest *req = (PadRequest *) _context.tx_buff; req->addr = 0x01; req->cmd = PAD_CMD_READ; @@ -76,27 +60,31 @@ static void _spi_create_poll_req(void) { req->motor_l = 0x00; req->motor_r = 0x00; - ctx.tx_len = 4; - ctx.rx_len = 0; - ctx.port ^= 1; - ctx.callback = default_cb; + _context.tx_len = 4; + _context.rx_len = 0; + _context.port ^= 1; + _context.callback = _default_cb; } static void _spi_next_req(void) { // Copy the contents of the first request in the queue into the TX buffer. - memcpy((void *) ctx.tx_buff, (void *) current_req->data, current_req->len); + memcpy( + (void *) _context.tx_buff, + (void *) _current_req->data, + _current_req->len + ); - ctx.tx_len = current_req->len; - ctx.rx_len = 0; - ctx.port = current_req->port; - ctx.callback = current_req->callback; + _context.tx_len = _current_req->len; + _context.rx_len = 0; + _context.port = _current_req->port; + _context.callback = _current_req->callback; // Pop the first request from the queue by deallocating it and adjusting // the pointer to the first queue item. - SPI_Request *next = current_req->next; + SPI_Request *next = _current_req->next; - free((void *) current_req); - current_req = next; + free((void *) _current_req); + _current_req = next; } /* Interrupt handlers */ @@ -105,13 +93,13 @@ static void _spi_poll_irq_handler(void) { // Fetch the last response byte, which wasn't followed by a pulse on /ACK, // from the RX FIFO. if (JOY_STAT & 0x0002) - ctx.rx_buff[ctx.rx_len - 1] = (uint8_t) JOY_TXRX; + _context.rx_buff[_context.rx_len - 1] = (uint8_t) JOY_TXRX; - if (ctx.callback) - ctx.callback(ctx.port, ctx.rx_buff, ctx.rx_len); + if (_context.callback) + _context.callback(_context.port, _context.rx_buff, _context.rx_len); // If the request queue is empty, create a pad polling request. - if (current_req) + if (_current_req) _spi_next_req(); else _spi_create_poll_req(); @@ -119,17 +107,18 @@ static void _spi_poll_irq_handler(void) { // Prepare the SPI port by clearing any pending IRQ, pulling /CS high and // enabling the /ACK IRQ. In order to communicate with controllers, /CS has // to be driven low again for about 20 us before sending the first byte. + // TODO: these delays can be probably tweaked for better performance JOY_CTRL = 0x0010; - for (uint32_t i = 0; i < 50; i++) - __asm__("nop"); + for (uint32_t i = 0; i < 1000; i++) + __asm__ volatile(""); - JOY_CTRL = 0x1003 | (ctx.port << 13); - for (uint32_t i = 0; i < 500; i++) - __asm__("nop"); + JOY_CTRL = 0x1003 | (_context.port << 13); + for (uint32_t i = 0; i < 2000; i++) + __asm__ volatile(""); // Send the first byte indicating which device to address. If the matching // device is connected, it will reply by triggering the /ACK IRQ. - JOY_TXRX = ctx.tx_buff[0]; + JOY_TXRX = _context.tx_buff[0]; } static void _spi_ack_irq_handler(void) { @@ -137,29 +126,29 @@ static void _spi_ack_irq_handler(void) { // byte. According to nocash docs, this has to be done before resetting the // IRQ. while (JOY_STAT & 0x0080) - __asm__("nop"); + __asm__ volatile(""); // Keep /CS pulled low and acknowledge the IRQ (bit 4) to ensure it can be // triggered again. - JOY_CTRL = 0x1013 | (ctx.port << 13); + JOY_CTRL = 0x1013 | (_context.port << 13); - if (!ctx.rx_len) { + if (!_context.rx_len) { // We just sent the first address byte. Obviously the response we // received was read from an open bus, so the SPI port's internal FIFO // must be flushed (by performing dummy reads) to ensure we are only // going to read valid data from now on. JOY_TXRX; - } else if (ctx.rx_len <= SPI_BUFF_LEN) { + } else if (_context.rx_len <= SPI_BUFF_LEN) { // If this is not the first byte, put it in the RX buffer. - ctx.rx_buff[ctx.rx_len - 1] = (uint8_t) JOY_TXRX; + _context.rx_buff[_context.rx_len - 1] = (uint8_t) JOY_TXRX; } // Send the next byte, or a null byte if there is no more data to send and // we're just reading a response. - ctx.rx_len++; - if (ctx.rx_len < ctx.tx_len) - JOY_TXRX = (uint32_t) ctx.tx_buff[ctx.rx_len]; + _context.rx_len++; + if (_context.rx_len < _context.tx_len) + JOY_TXRX = (uint32_t) _context.tx_buff[_context.rx_len]; else JOY_TXRX = 0x00; } @@ -176,10 +165,10 @@ SPI_Request *SPI_CreateRequest(void) { // Find the last queued request by traversing the linked list and append a // pointer to the new request. - if (!current_req) { - current_req = req; + if (!_current_req) { + _current_req = req; } else { - volatile SPI_Request *volatile last = current_req; + volatile SPI_Request *volatile last = _current_req; while (last->next) last = last->next; @@ -213,6 +202,6 @@ void SPI_Init(SPI_Callback callback) { JOY_BAUD = 0x0088; // 250000 bps SPI_SetPollRate(250); - current_req = 0; - default_cb = callback; + _current_req = 0; + _default_cb = callback; } diff --git a/examples/io/pads/spi.h b/examples/io/pads/spi.h index c50e065..7d4d75b 100644 --- a/examples/io/pads/spi.h +++ b/examples/io/pads/spi.h @@ -9,8 +9,9 @@ #include #include -// Maximum request/response length (34 bytes for pads, 140 for memory cards) -//#define SPI_BUFF_LEN 34 +// Maximum request/response length (34 bytes for pads, 140 for memory cards). +// Must be a multiple of 4 to avoid memory alignment issues. +//#define SPI_BUFF_LEN 36 #define SPI_BUFF_LEN 140 /* Request structures */ @@ -30,6 +31,10 @@ typedef struct _SPI_Request { /* Public API */ +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Allocates a new request object and adds it to the request queue. The * object must be populated afterwards by setting the length, callback and @@ -49,7 +54,7 @@ void SPI_SetPollRate(uint32_t value); /** * @brief Installs the SPI and timer 2 interrupt handlers and starts the poll * timer. By default the polling rate is set to 250 Hz (125 Hz per port), - * however it can be changed at any time by calling spi_set_poll_rate(). + * however it can be changed at any time by calling SPI_SetPollRate(). * * The provided callback (if any) is called to report the result of poll * requests, which are issued automatically when no other request is in the @@ -59,4 +64,8 @@ void SPI_SetPollRate(uint32_t value); */ void SPI_Init(SPI_Callback callback); +#ifdef __cplusplus +} +#endif + #endif -- cgit v1.2.3 From 69a364049a3958396d2d083c660591dad9ec257d Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Sun, 27 Feb 2022 19:45:38 +0100 Subject: Rename some hwregs_c.h and hwregs.a definitions --- examples/graphics/rgb24/bunpattern.png | Bin 0 -> 59932 bytes examples/io/pads/spi.c | 6 +++--- examples/system/timer/main.c | 5 +++-- libpsn00b/include/hwregs_a.h | 22 +++++++++++----------- libpsn00b/include/hwregs_c.h | 10 +++++----- libpsn00b/psxgpu/clearotagr.s | 2 +- libpsn00b/psxgpu/drawotag.s | 4 ++-- libpsn00b/psxgpu/drawprim.s | 4 ++-- libpsn00b/psxgpu/drawsynccallback.s | 2 +- libpsn00b/psxgpu/loadimage.s | 14 +++++++------- libpsn00b/psxgpu/putdispenv.s | 8 ++++---- libpsn00b/psxgpu/putdispenvraw.s | 10 +++++----- libpsn00b/psxgpu/readgpustat.s | 4 ++-- libpsn00b/psxgpu/resetgraph.s | 28 ++++++++++++++-------------- libpsn00b/psxgpu/setdispmask.s | 4 ++-- libpsn00b/psxgpu/setvideomode.s | 2 +- libpsn00b/psxgpu/storeimage.s | 14 +++++++------- 17 files changed, 70 insertions(+), 69 deletions(-) create mode 100644 examples/graphics/rgb24/bunpattern.png (limited to 'examples/io/pads') diff --git a/examples/graphics/rgb24/bunpattern.png b/examples/graphics/rgb24/bunpattern.png new file mode 100644 index 0000000..61524f8 Binary files /dev/null and b/examples/graphics/rgb24/bunpattern.png differ diff --git a/examples/io/pads/spi.c b/examples/io/pads/spi.c index 05a0e59..43b5bc3 100644 --- a/examples/io/pads/spi.c +++ b/examples/io/pads/spi.c @@ -179,12 +179,12 @@ SPI_Request *SPI_CreateRequest(void) { } void SPI_SetPollRate(uint32_t value) { - TIM_CTRL(2) = 0x0258; // CLK/8 input, IRQ on reload, disable one-shot IRQ + TIMER_CTRL(2) = 0x0258; // CLK/8 input, IRQ on reload, disable one-shot IRQ if (value < 65) - TIM_RELOAD(2) = 0xffff; + TIMER_RELOAD(2) = 0xffff; else - TIM_RELOAD(2) = (F_CPU / 8) / value; + TIMER_RELOAD(2) = (F_CPU / 8) / value; } void SPI_Init(SPI_Callback callback) { diff --git a/examples/system/timer/main.c b/examples/system/timer/main.c index 8153581..eb62712 100644 --- a/examples/system/timer/main.c +++ b/examples/system/timer/main.c @@ -3,6 +3,7 @@ #include #include #include +#include /* OT and Packet Buffer sizes */ #define OT_LEN 256 @@ -34,7 +35,7 @@ void display(); volatile int timer_calls = 0; -volatile short *timer2_ctrl = (short*)0x1F801124; + void timer_func() { timer_calls++; @@ -74,7 +75,7 @@ int main() { //counter = 5163000/560; SetRCnt(RCntCNT2, counter, RCntMdINTR); - *timer2_ctrl = 0x1E58; + TIMER_CTRL(2) = 0x1E58; InterruptCallback(6, timer_func); StartRCnt(RCntCNT2); ChangeClearRCnt(2, 0); diff --git a/libpsn00b/include/hwregs_a.h b/libpsn00b/include/hwregs_a.h index 4d0bade..8a504f5 100644 --- a/libpsn00b/include/hwregs_a.h +++ b/libpsn00b/include/hwregs_a.h @@ -8,8 +8,8 @@ ## GPU -.set GP0, 0x1810 # Also GPUREAD -.set GP1, 0x1814 # Also GPUSTAT +.set GPU_GP0, 0x1810 # Also GPUREAD +.set GPU_GP1, 0x1814 # Also GPUSTAT ## CD drive @@ -123,17 +123,17 @@ ## Timers -.set TIM0_VALUE, 0x1100 -.set TIM0_CTRL, 0x1104 -.set TIM0_RELOAD, 0x1108 +.set TIMER0_VALUE, 0x1100 +.set TIMER0_CTRL, 0x1104 +.set TIMER0_RELOAD, 0x1108 -.set TIM1_VALUE, 0x1110 -.set TIM1_CTRL, 0x1114 -.set TIM1_RELOAD, 0x1118 +.set TIMER1_VALUE, 0x1110 +.set TIMER1_CTRL, 0x1114 +.set TIMER1_RELOAD, 0x1118 -.set TIM2_VALUE, 0x1120 -.set TIM2_CTRL, 0x1124 -.set TIM2_RELOAD, 0x1128 +.set TIMER2_VALUE, 0x1120 +.set TIMER2_CTRL, 0x1124 +.set TIMER2_RELOAD, 0x1128 ## Memory control diff --git a/libpsn00b/include/hwregs_c.h b/libpsn00b/include/hwregs_c.h index 4222a22..e533c56 100644 --- a/libpsn00b/include/hwregs_c.h +++ b/libpsn00b/include/hwregs_c.h @@ -19,8 +19,8 @@ /* GPU */ -#define GP0 _MMIO32(0x1f801810) -#define GP1 _MMIO32(0x1f801814) +#define GPU_GP0 _MMIO32(0x1f801810) +#define GPU_GP1 _MMIO32(0x1f801814) /* CD drive */ @@ -109,9 +109,9 @@ /* Timers */ -#define TIM_VALUE(N) _MMIO32(0x1f801100 + 16 * (N)) -#define TIM_CTRL(N) _MMIO32(0x1f801104 + 16 * (N)) -#define TIM_RELOAD(N) _MMIO32(0x1f801108 + 16 * (N)) +#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 */ diff --git a/libpsn00b/psxgpu/clearotagr.s b/libpsn00b/psxgpu/clearotagr.s index 832e54c..562cad4 100644 --- a/libpsn00b/psxgpu/clearotagr.s +++ b/libpsn00b/psxgpu/clearotagr.s @@ -8,7 +8,7 @@ .global ClearOTagR .type ClearOTagR, @function ClearOTagR: - lui $a2, 0x1f80 + lui $a2, IOBASE addi $v0, $a1, -1 sll $v0, 2 addu $a0, $v0 diff --git a/libpsn00b/psxgpu/drawotag.s b/libpsn00b/psxgpu/drawotag.s index 595fcd5..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 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/drawsynccallback.s b/libpsn00b/psxgpu/drawsynccallback.s index 2b2c172..22cfb7d 100644 --- a/libpsn00b/psxgpu/drawsynccallback.s +++ b/libpsn00b/psxgpu/drawsynccallback.s @@ -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 e2a5be5..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) 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 eae854c..6327f02 100644 --- a/libpsn00b/psxgpu/resetgraph.s +++ b/libpsn00b/psxgpu/resetgraph.s @@ -38,7 +38,7 @@ 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 @@ -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,18 +98,18 @@ 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, TIM1_CTRL($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 @@ -121,7 +121,7 @@ ResetGraph: .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, TIM1_VALUE($a3) + lw $v0, TIMER1_VALUE($a3) nop - lw $v1, TIM1_VALUE($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, TIM1_VALUE($a3) + lw $v0, TIMER1_VALUE($a3) nop - lw $v1, TIM1_VALUE($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 933b14c..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) -- cgit v1.2.3 From 4bbfe640a8c357137524e797a8d2bd0a94d3abfa Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Sun, 20 Mar 2022 10:56:23 +0100 Subject: Remove stdint.h, fix n00bdemo crashing --- examples/demos/n00bdemo/logo.c | 4 +++- examples/demos/n00bdemo/main.c | 5 ++--- examples/io/pads/spi.c | 1 + examples/io/pads/spi.h | 1 + libpsn00b/include/stdint.h | 16 ---------------- libpsn00b/include/stdlib.h | 2 +- libpsn00b/libc/start.c | 23 ++++++++++++----------- 7 files changed, 20 insertions(+), 32 deletions(-) delete mode 100644 libpsn00b/include/stdint.h (limited to 'examples/io/pads') diff --git a/examples/demos/n00bdemo/logo.c b/examples/demos/n00bdemo/logo.c index 40160e7..784c9e1 100644 --- a/examples/demos/n00bdemo/logo.c +++ b/examples/demos/n00bdemo/logo.c @@ -51,9 +51,11 @@ typedef struct { int size; } NODE; +extern NODE _end[]; + void DumpHeap() { - NODE *n = (NODE*)GetBSSend(); + NODE *n = _end; printf( "--\n" ); diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c index cb64c42..439bccc 100644 --- a/examples/demos/n00bdemo/main.c +++ b/examples/demos/n00bdemo/main.c @@ -232,12 +232,11 @@ void unpackModels() { } void init() { + // Init display + initDisplay(); #ifdef SYSTEM_573_SUPPORT system573Setup(); #endif - - // Init display - initDisplay(); FntLoad( 960, 0 ); diff --git a/examples/io/pads/spi.c b/examples/io/pads/spi.c index 43b5bc3..133782c 100644 --- a/examples/io/pads/spi.c +++ b/examples/io/pads/spi.c @@ -27,6 +27,7 @@ */ #include +#include #include #include #include diff --git a/examples/io/pads/spi.h b/examples/io/pads/spi.h index 7d4d75b..8c17df3 100644 --- a/examples/io/pads/spi.h +++ b/examples/io/pads/spi.h @@ -7,6 +7,7 @@ #define __SPI_H #include +#include #include // Maximum request/response length (34 bytes for pads, 140 for memory cards). 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 b187a6f..4c4fcd3 100644 --- a/libpsn00b/include/stdlib.h +++ b/libpsn00b/include/stdlib.h @@ -44,7 +44,7 @@ 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/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 #include #include +#include -#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 -- cgit v1.2.3