From b3ef4c5874f579c968f2d26843d0db420e9ed40e Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Sun, 7 Nov 2021 18:57:48 +0100 Subject: Added io/pads example, psxpad.h definitions, bugfixes --- examples/demos/n00bdemo/main.c | 8 +- examples/io/pads/CMakeLists.txt | 22 ++++ examples/io/pads/main.c | 259 ++++++++++++++++++++++++++++++++++++++++ examples/io/pads/spi.c | 216 +++++++++++++++++++++++++++++++++ examples/io/pads/spi.h | 60 ++++++++++ 5 files changed, 564 insertions(+), 1 deletion(-) create mode 100644 examples/io/pads/CMakeLists.txt create mode 100644 examples/io/pads/main.c create mode 100644 examples/io/pads/spi.c create mode 100644 examples/io/pads/spi.h (limited to 'examples') diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c index ba21d88..e9dd336 100644 --- a/examples/demos/n00bdemo/main.c +++ b/examples/demos/n00bdemo/main.c @@ -617,7 +617,13 @@ void transition() { if( comp >= 16 ) break; - + + // FIXME: for some reason this loop glitches out and hangs indefinitely + // in no$psx, *unless* there's a function somewhere that gets called + // with a pointer/string as first argument... wtf. It works fine in + // other emulators. If you are reading this, please help and enlighten + // me. -- spicyjpeg + puts("."); } DrawSync(0); diff --git a/examples/io/pads/CMakeLists.txt b/examples/io/pads/CMakeLists.txt new file mode 100644 index 0000000..124d62b --- /dev/null +++ b/examples/io/pads/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + pads + LANGUAGES C ASM + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK controller polling example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c *.s) +psn00bsdk_add_executable(pads STATIC ${_sources}) +#psn00bsdk_add_cd_image(pads_iso pads iso.xml DEPENDS pads) + +install(FILES ${PROJECT_BINARY_DIR}/pads.exe DESTINATION .) diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c new file mode 100644 index 0000000..bb56a27 --- /dev/null +++ b/examples/io/pads/main.c @@ -0,0 +1,259 @@ +/* + * PSn00bSDK controller polling example + * (C) 2021 spicyjpeg - MPL licensed + * + * This example shows how to poll controllers at high speeds (250 Hz) by using + * timer interrupts and communicating with devices on the SPI controller bus + * manually rather than relying on the BIOS pad driver, which is limited to + * 50/60 Hz and does not support custom commands. The example also demonstrates + * using configuration mode commands to force DualShock pads into analog mode + * and enable button pressure sensing on DualShock 2 (PS2) controllers. + * + * See spi.c for details on how the low-level SPI communication driver works. + * The DualShock handshaking logic is implemented here (see poll_cb() and + * dualshock_init_cb()). There is no support for memory cards in this example, + * 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 doesn't work on pcsx-redux, and hasn't yet been + * tested on real hardware and/or with unofficial controllers. It works on + * DuckStation and no$psx though. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "spi.h" + +static const char *const PAD_TYPEIDS[] = { + "[UNKNOWN]", + "MOUSE", + "NEGCON", + "IRQ10_GUN", + "DIGITAL", + "ANALOG_STICK", + "GUNCON", + "ANALOG", + "MULTITAP", + "[UNKNOWN]", + "[UNKNOWN]", + "[UNKNOWN]", + "[UNKNOWN]", + "[UNKNOWN]", + "JOGCON", + "CONFIG_MODE" +}; + +/* Display/GPU context utilities */ + +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +typedef struct { + DISPENV disp; + DRAWENV draw; +} DB; + +typedef struct { + DB db[2]; + uint32_t db_active; +} CONTEXT; + +void init_context(CONTEXT *ctx) { + DB *db; + + ResetGraph(0); + ctx->db_active = 0; + + db = &(ctx->db[0]); + SetDefDispEnv(&(db->disp), 0, 0, SCREEN_XRES, SCREEN_YRES); + SetDefDrawEnv(&(db->draw), SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES); + setRGB0(&(db->draw), 63, 0, 127); + db->draw.isbg = 1; + db->draw.dtd = 1; + + db = &(ctx->db[1]); + SetDefDispEnv(&(db->disp), SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES); + SetDefDrawEnv(&(db->draw), 0, 0, SCREEN_XRES, SCREEN_YRES); + setRGB0(&(db->draw), 63, 0, 127); + db->draw.isbg = 1; + db->draw.dtd = 1; + + PutDrawEnv(&(db->draw)); + //PutDispEnv(&(db->disp)); + + // Create a text stream at the top of the screen. + FntLoad(960, 0); + FntOpen(8, 16, 304, 208, 2, 512); +} + +void display(CONTEXT *ctx) { + DB *db; + + DrawSync(0); + VSync(0); + ctx->db_active ^= 1; + + db = &(ctx->db[ctx->db_active]); + PutDrawEnv(&(db->draw)); + PutDispEnv(&(db->disp)); + SetDispMask(1); +} + +/* Pad buffers and callback */ + +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 +// 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 +) { + SPIREQUEST *req = spi_new_request(); + + req->len = 9; + req->port = port; + req->callback = callback; + req->pad_req.addr = 0x01; + req->pad_req.cmd = cmd; + req->pad_req.tap_mode = 0x00; + req->pad_req.motor_r = arg1; + req->pad_req.motor_l = arg2; + + // The padding bytes must be 0xff when unlocking vibration motors. + memset( + req->pad_req.dummy, + (cmd == PAD_CMD_REQUEST_CONFIG) ? 0xff : 0x00, + 4 + ); +} + +// This callback determines whether a pad that identifies as digital is +// actually a DualShock in digital mode by checking how it replied to the +// CONFIG_MODE command. +void dualshock_init_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { + // Flag the pad as digital-only if it didn't reply. + // FIXME: rx_len should be 8 for digital pads, but sometimes it's only 4 + if (rx_len < 4) { + printf("no, pad is digital-only (len = %d)\n", rx_len); + + pad_digital_only[port] = 1; + return; + } + + printf("yes, forcing analog mode (len = %d)\n", rx_len); + + // Issue further commands to finish configuring the controller. + // https://gist.github.com/scanlime/5042071 + send_pad_cmd(port, PAD_CMD_SET_ANALOG, 0x01, 0x02, 0); // 0x03 disables analog button...? + 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); + send_pad_cmd(port, PAD_CMD_RESPONSE_CONFIG, 0xff, 0xff, 0); // Ignored by DualShock 1 + send_pad_cmd(port, PAD_CMD_CONFIG_MODE, 0x00, 0x00, 0); +} + +// This function is called by the pad timer ISR each time a pad is polled and a +// response (even an invalid/incomplete one) is received. +void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { + // Copy the response to a persistent buffer so it can be accessed from the + // main loop and displayed on screen. + pad_buff_len[port] = rx_len; + if (rx_len) + memcpy((void *) pad_buff[port], (void *) buff, rx_len); + + PADTYPE *pad = (PADTYPE *) 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 + // returning digital pad responses. + if ((pad->raw.prefix == 0x5a) && (pad->raw.type == PAD_ID_DIGITAL)) { + if (!pad_digital_only[port]) { + printf("Detecting if pad %d supports config mode... ", port + 1); + + send_pad_cmd( + port, + PAD_CMD_CONFIG_MODE, + 0x01, + 0x00, + &dualshock_init_cb + ); + } + + } else if (pad_digital_only[port]) { + printf("Clearing digital-only flag for pad %d\n", port + 1); + + pad_digital_only[port] = 0; + } +} + +/* Main */ + +static CONTEXT ctx; + +int main(int argc, const char* argv[]) { + init_context(&ctx); + spi_init(&poll_cb); + + uint32_t counter = 0; + + while (1) { + FntPrint(-1, "COUNTER=%d", counter++); + + for (uint32_t port = 0; port < 2; port++) { + PADTYPE *pad = (PADTYPE *) 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. + //if (!pad->raw.prefix != 0x5a) { + if (!pad_buff_len[port]) { + FntPrint(-1, "\n\nPORT %d: NO DEVICE FOUND\n", port + 1); + if ((counter % 64) < 32) + FntPrint(-1, " CONNECT PAD NOW..."); + + continue; + } + + uint32_t type = pad->raw.type; + uint32_t len = pad->raw.len * 2; + if (type == PAD_ID_MULTITAP) + len = 32; + + FntPrint( + -1, + "\n\nPORT %d: %s\n TYPE=%d LEN=%d", + port + 1, + PAD_TYPEIDS[type], + type, + len + ); + + // Print a hexdump of the payload returned by the pad. + for (uint32_t i = 0; i < len; i++) + FntPrint( + -1, + (i % 8) ? " %02x" : "\n %02x", + pad_buff[port][i + 2] + ); + } + + FntFlush(-1); + display(&ctx); + } + + return 0; +} diff --git a/examples/io/pads/spi.c b/examples/io/pads/spi.c new file mode 100644 index 0000000..4728626 --- /dev/null +++ b/examples/io/pads/spi.c @@ -0,0 +1,216 @@ +/* + * PSn00bSDK controller polling example (SPI driver) + * (C) 2021 spicyjpeg - MPL licensed + * + * This is a fairly complete timer driven high-speed SPI driver, with support + * for sending custom commands (including memory card reads/writes), in about + * 200 lines of code. Feel free to copypaste and adapt it. + * + * The way this works is by maintaining a queue of requests to send, each with + * its own payload and callback. Timer 2 is configured to trigger an IRQ at + * regular intervals. On each tick, the next request in the queue (or a poll + * command if no request is pending) is prepared and the first byte is + * sent; if the controller asks for more data by pulling /ACK low, the next + * byte is sent and the received byte is placed into a buffer. This goes on + * until the last byte is exchanged and the controller stops asserting /ACK. + * + * On the next tick, the response buffer is passed to the request's callback + * and reset, and the next request in the queue is sent. This blindly assumes + * it only takes one tick for a request/response to be sent, which is the case + * for controllers' very small packets but not for memory cards. It is + * advisable to call spi_set_poll_rate() to temporarily reduce poll rate while + * accessing memory cards. + * + * Note that this driver completely takes over the SPI bus, so you won't be + * able to use any BIOS functions that rely on SPI access (i.e. pad and memory + * card APIs) alongside it. + */ + +#include +#include +#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)) +#define JOY_TXRX *((volatile uint32_t *) 0x1f801040) +#define JOY_STAT *((volatile uint32_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 _SPICONTEXT { + uint8_t tx_buff[SPI_BUFF_LEN]; + uint8_t rx_buff[SPI_BUFF_LEN]; + uint32_t tx_len, rx_len, port; + SPICALLBACK callback; +} SPICONTEXT; + +static volatile SPICONTEXT ctx; +static volatile SPIREQUEST volatile *current_req; +static SPICALLBACK default_cb; + +/* Request queue management */ + +static void prepare_poll_req(void) { + PADREQUEST *req = (PADREQUEST *) ctx.tx_buff; + + req->addr = 0x01; + req->cmd = PAD_CMD_READ; + req->tap_mode = 0x00; // 0x01 to enable extended multitap response + req->motor_l = 0x00; + req->motor_r = 0x00; + + ctx.tx_len = 4; + ctx.rx_len = 0; + ctx.port ^= 1; + ctx.callback = default_cb; +} + +static void prepare_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); + + ctx.tx_len = current_req->len; + ctx.rx_len = 0; + ctx.port = current_req->port; + ctx.callback = current_req->callback; + + // Pop the first request from the queue by deallocating it and adjusting + // the pointer to the first queue item. + SPIREQUEST *next = current_req->next; + + free((void *) current_req); + current_req = next; +} + +/* Interrupt handlers */ + +static void poll_timer_tick(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; + + if (ctx.callback) + ctx.callback(ctx.port, ctx.rx_buff, ctx.rx_len); + + // If the request queue is empty, create a pad polling request. + if (current_req) + prepare_next_req(); + else + prepare_poll_req(); + + // 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. + JOY_CTRL = 0x0010; + for (uint32_t i = 0; i < 50; i++) + __asm__("nop"); + + JOY_CTRL = 0x1003 | (ctx.port << 13); + for (uint32_t i = 0; i < 500; i++) + __asm__("nop"); + + // 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]; +} + +static void spi_ack_handler(void) { + // Wait until /ACK is pulled up by the controller before sending the next + // byte. According to nocash docs, this has to be done before resetting the + // IRQ. + while (JOY_STAT & 0x0080) + __asm__("nop"); + + // Keep /CS pulled low and acknowledge the IRQ (bit 4) to ensure it can be + // triggered again. + JOY_CTRL = 0x1013 | (ctx.port << 13); + + if (!ctx.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 to ensure we are only going to read valid data from + // now on. + volatile uint32_t dummy; + while (JOY_STAT & 0x0002) + dummy = JOY_TXRX; + + } else if (ctx.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; + } + + // 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]; + else + JOY_TXRX = 0x00; +} + +/* Public API */ + +SPIREQUEST *spi_new_request(void) { + SPIREQUEST *req = malloc(sizeof(SPIREQUEST)); + + req->len = 0; + req->port = 0; + req->callback = 0; + req->next = 0; + + // Find the last queued request by traversing the linked list and append a + // pointer to the new request. + if (!current_req) { + current_req = req; + } else { + volatile SPIREQUEST *volatile last = current_req; + while (last->next) + last = last->next; + + last->next = req; + } + + return req; +} + +void spi_set_poll_rate(uint32_t value) { + TIM_CTRL(2) = 0x0258; // CLK/8 input, IRQ on reload, disable one-shot IRQ + + if (value < 65) + TIM_RELOAD(2) = 0xffff; + else + TIM_RELOAD(2) = (F_CPU / 8) / value; +} + +void spi_init(SPICALLBACK callback) { + // Disable the BIOS timer handler (which for some stupid reason is enabled + // by default, even though it does nothing) and set up custom interrupt + // handlers. + EnterCriticalSection(); + ChangeClearRCnt(2, 0); + InterruptCallback(6, &poll_timer_tick); + InterruptCallback(7, &spi_ack_handler); + ExitCriticalSection(); + + JOY_CTRL = 0x0040; // Reset all registers + JOY_MODE = 0x000d; // 1x multiplier, 8 data bits, no parity + JOY_BAUD = 0x0088; // 250000 bps + + spi_set_poll_rate(250); + current_req = 0; + default_cb = callback; +} diff --git a/examples/io/pads/spi.h b/examples/io/pads/spi.h new file mode 100644 index 0000000..09223e2 --- /dev/null +++ b/examples/io/pads/spi.h @@ -0,0 +1,60 @@ +/* + * PSn00bSDK controller polling example (SPI driver) + * (C) 2021 spicyjpeg - MPL licensed + */ + +#ifndef __SPI_H +#define __SPI_H + +#include + +//#define SPI_BUFF_LEN 34 +#define SPI_BUFF_LEN 140 + +/* Request structures */ + +typedef void (*SPICALLBACK)(uint32_t port, const volatile uint8_t *buff, size_t rx_len); + +typedef struct _SPIREQUEST { + union { + uint8_t data[SPI_BUFF_LEN]; + PADREQUEST pad_req; + MCDREQUEST mcd_req; + }; + uint32_t len, port; + SPICALLBACK callback; + struct _SPIREQUEST *next; +} SPIREQUEST; + +/* Public API */ + +/** + * @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 + * filling in the TX data buffer. + */ +SPIREQUEST *spi_new_request(void); + +/** + * @brief Changes the controller polling rate. The lowest supported rate is 65 + * Hz (requests sent every 1/65th of a second, each port polled at 32.5 Hz when + * no request is pending). + * + * @param value + */ +void spi_set_poll_rate(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(). + * + * 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 + * queue. Passing NULL as callback does not disable auto-polling. + * + * @param callback + */ +void spi_init(SPICALLBACK callback); + +#endif -- cgit v1.2.3 From c61d83010a1d83513623724f908f0903e90966e2 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Mon, 8 Nov 2021 13:59:21 +0100 Subject: Rolled back minimum required CMake version to 3.20 --- CMakeLists.txt | 2 +- cpack/fakeroot_fix.cmake | 2 +- cpack/setup.cmake | 2 +- examples/CMakeLists.txt | 2 +- examples/beginner/cppdemo/CMakeLists.txt | 2 +- examples/beginner/hello/CMakeLists.txt | 2 +- examples/cdrom/cdbrowse/CMakeLists.txt | 2 +- examples/cdrom/cdxa/CMakeLists.txt | 2 +- examples/demos/n00bdemo/CMakeLists.txt | 2 +- examples/graphics/balls/CMakeLists.txt | 2 +- examples/graphics/billboard/CMakeLists.txt | 2 +- examples/graphics/fpscam/CMakeLists.txt | 2 +- examples/graphics/gte/CMakeLists.txt | 2 +- examples/graphics/hdtv/CMakeLists.txt | 2 +- examples/graphics/render2tex/CMakeLists.txt | 2 +- examples/graphics/rgb24/CMakeLists.txt | 2 +- examples/io/pads/CMakeLists.txt | 2 +- examples/sound/vagsample/CMakeLists.txt | 2 +- examples/system/childexec/CMakeLists.txt | 2 +- examples/system/console/CMakeLists.txt | 2 +- examples/system/dynlink/CMakeLists.txt | 2 +- examples/system/timer/CMakeLists.txt | 2 +- examples/system/tty/CMakeLists.txt | 2 +- libpsn00b/CMakeLists.txt | 2 +- libpsn00b/cmake/internal_setup.cmake | 2 +- libpsn00b/cmake/sdk.cmake | 2 +- template/CMakeLists.txt | 2 +- tools/CMakeLists.txt | 9 ++------- tools/mkpsxiso | 2 +- 29 files changed, 30 insertions(+), 35 deletions(-) (limited to 'examples') diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c44c09..0e6eefd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ # workaround is to use ExternalProject_Add() to launch multiple independent # CMake instances, creating what's known as a "superbuild". -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) include(ExternalProject) project( diff --git a/cpack/fakeroot_fix.cmake b/cpack/fakeroot_fix.cmake index e34baa0..1c1430d 100644 --- a/cpack/fakeroot_fix.cmake +++ b/cpack/fakeroot_fix.cmake @@ -7,7 +7,7 @@ # script does is simply finding and deleting all directories that do not match # the installation prefix before CPack generates the package. -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) set(_prefix ${CPACK_TEMPORARY_INSTALL_DIRECTORY}${CPACK_PACKAGING_INSTALL_PREFIX}) diff --git a/cpack/setup.cmake b/cpack/setup.cmake index a483462..0c4f3cb 100644 --- a/cpack/setup.cmake +++ b/cpack/setup.cmake @@ -2,7 +2,7 @@ # rules to bundle the GCC toolchain and CMake in packages. It is included by # the main CMakeLists.txt script. -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) ## Settings diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7cd7e98..87210b9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK examples build script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) project( PSn00bSDK-examples diff --git a/examples/beginner/cppdemo/CMakeLists.txt b/examples/beginner/cppdemo/CMakeLists.txt index 83f0f0a..3b6a53e 100644 --- a/examples/beginner/cppdemo/CMakeLists.txt +++ b/examples/beginner/cppdemo/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/beginner/hello/CMakeLists.txt b/examples/beginner/hello/CMakeLists.txt index 40e30b0..81ed0f7 100644 --- a/examples/beginner/hello/CMakeLists.txt +++ b/examples/beginner/hello/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/cdrom/cdbrowse/CMakeLists.txt b/examples/cdrom/cdbrowse/CMakeLists.txt index 6eb4cbb..d587f5a 100644 --- a/examples/cdrom/cdbrowse/CMakeLists.txt +++ b/examples/cdrom/cdbrowse/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/cdrom/cdxa/CMakeLists.txt b/examples/cdrom/cdxa/CMakeLists.txt index b0c8d90..d95a40d 100644 --- a/examples/cdrom/cdxa/CMakeLists.txt +++ b/examples/cdrom/cdxa/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/demos/n00bdemo/CMakeLists.txt b/examples/demos/n00bdemo/CMakeLists.txt index 0b51beb..02c7b35 100644 --- a/examples/demos/n00bdemo/CMakeLists.txt +++ b/examples/demos/n00bdemo/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/graphics/balls/CMakeLists.txt b/examples/graphics/balls/CMakeLists.txt index b063425..5afb2b1 100644 --- a/examples/graphics/balls/CMakeLists.txt +++ b/examples/graphics/balls/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/graphics/billboard/CMakeLists.txt b/examples/graphics/billboard/CMakeLists.txt index bf73297..1d9df78 100644 --- a/examples/graphics/billboard/CMakeLists.txt +++ b/examples/graphics/billboard/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/graphics/fpscam/CMakeLists.txt b/examples/graphics/fpscam/CMakeLists.txt index 8fa66f2..b2becb9 100644 --- a/examples/graphics/fpscam/CMakeLists.txt +++ b/examples/graphics/fpscam/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/graphics/gte/CMakeLists.txt b/examples/graphics/gte/CMakeLists.txt index 3cdf2ff..5fdf4d1 100644 --- a/examples/graphics/gte/CMakeLists.txt +++ b/examples/graphics/gte/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/graphics/hdtv/CMakeLists.txt b/examples/graphics/hdtv/CMakeLists.txt index 98a0b3f..899f963 100644 --- a/examples/graphics/hdtv/CMakeLists.txt +++ b/examples/graphics/hdtv/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/graphics/render2tex/CMakeLists.txt b/examples/graphics/render2tex/CMakeLists.txt index 42a063b..db30377 100644 --- a/examples/graphics/render2tex/CMakeLists.txt +++ b/examples/graphics/render2tex/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/graphics/rgb24/CMakeLists.txt b/examples/graphics/rgb24/CMakeLists.txt index c66ae69..71e2cfa 100644 --- a/examples/graphics/rgb24/CMakeLists.txt +++ b/examples/graphics/rgb24/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/io/pads/CMakeLists.txt b/examples/io/pads/CMakeLists.txt index 124d62b..62c06a2 100644 --- a/examples/io/pads/CMakeLists.txt +++ b/examples/io/pads/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/sound/vagsample/CMakeLists.txt b/examples/sound/vagsample/CMakeLists.txt index 1f42608..54305ab 100644 --- a/examples/sound/vagsample/CMakeLists.txt +++ b/examples/sound/vagsample/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt index c9983c4..f28a136 100644 --- a/examples/system/childexec/CMakeLists.txt +++ b/examples/system/childexec/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/system/console/CMakeLists.txt b/examples/system/console/CMakeLists.txt index acae08f..024c7a4 100644 --- a/examples/system/console/CMakeLists.txt +++ b/examples/system/console/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/system/dynlink/CMakeLists.txt b/examples/system/dynlink/CMakeLists.txt index 3af5d4b..e7188de 100644 --- a/examples/system/dynlink/CMakeLists.txt +++ b/examples/system/dynlink/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/system/timer/CMakeLists.txt b/examples/system/timer/CMakeLists.txt index 189bf87..6dc5ec3 100644 --- a/examples/system/timer/CMakeLists.txt +++ b/examples/system/timer/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) diff --git a/examples/system/tty/CMakeLists.txt b/examples/system/tty/CMakeLists.txt index 024ccd4..b8b5738 100644 --- a/examples/system/tty/CMakeLists.txt +++ b/examples/system/tty/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) 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..732294c 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 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/template/CMakeLists.txt b/template/CMakeLists.txt index c2d0d9d..c0c05d0 100644 --- a/template/CMakeLists.txt +++ b/template/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) # CMAKE_TOOLCHAIN_FILE must be set to point to cmake/sdk.cmake in the PSn00bSDK # installation directory *before* calling project(). You don't have to hardcode diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 14fa775..af99046 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK tools build script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.20) project( PSn00bSDK-tools @@ -57,12 +57,7 @@ target_link_libraries(lzpack tinyxml2 lzp) # Install the executables and copy the Blender SMX export plugin to the data # directory (for manual installation). -install( - TARGETS elf2x elf2cpe smxlink lzpack - #RUNTIME_DEPENDENCIES - #PRE_EXCLUDE_REGEXES ".*" - #PRE_INCLUDE_REGEXES "tinyxml2" -) +install(TARGETS elf2x elf2cpe smxlink lzpack) install( DIRECTORY plugin DESTINATION ${CMAKE_INSTALL_DATADIR}/psn00bsdk diff --git a/tools/mkpsxiso b/tools/mkpsxiso index 0d65bb7..fe14e95 160000 --- a/tools/mkpsxiso +++ b/tools/mkpsxiso @@ -1 +1 @@ -Subproject commit 0d65bb7ef80a67c1a89a6c43e40521fd57776814 +Subproject commit fe14e95d07a0da5727a8c2fb3ff2aaa892e465cf -- cgit v1.2.3 From b55bc88017aac1bbe9eab21b480093459c0fd0e1 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Wed, 10 Nov 2021 17:11:44 +0100 Subject: Fixed examples directory hierarchy not being preserved --- INSTALL.md | 2 +- cpack/setup.cmake | 4 ++-- examples/CMakeLists.txt | 22 +++++++++++++++++++--- examples/beginner/cppdemo/CMakeLists.txt | 2 +- examples/beginner/hello/CMakeLists.txt | 2 +- examples/cdrom/cdbrowse/CMakeLists.txt | 2 +- examples/cdrom/cdxa/CMakeLists.txt | 2 +- examples/demos/n00bdemo/CMakeLists.txt | 2 +- examples/graphics/balls/CMakeLists.txt | 2 +- examples/graphics/billboard/CMakeLists.txt | 2 +- examples/graphics/fpscam/CMakeLists.txt | 4 ++-- examples/graphics/gte/CMakeLists.txt | 4 ++-- examples/graphics/hdtv/CMakeLists.txt | 2 +- examples/graphics/render2tex/CMakeLists.txt | 2 +- examples/graphics/rgb24/CMakeLists.txt | 2 +- examples/io/pads/CMakeLists.txt | 2 +- examples/sound/vagsample/CMakeLists.txt | 2 +- examples/system/childexec/CMakeLists.txt | 2 +- examples/system/console/CMakeLists.txt | 2 +- examples/system/dynlink/CMakeLists.txt | 2 +- examples/system/timer/CMakeLists.txt | 2 +- examples/system/tty/CMakeLists.txt | 2 +- libpsn00b/cmake/internal_setup.cmake | 4 +--- 23 files changed, 44 insertions(+), 30 deletions(-) (limited to 'examples') diff --git a/INSTALL.md b/INSTALL.md index 8fa7889..d0a2cd7 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -12,7 +12,7 @@ tested. - `git` - `build-essential`, `base-devel` or similar - `ninja-build` - - `cmake` (3.21+ is required, download it from + - `cmake` (3.20+ is required, download it from [here](https://cmake.org/download) if your package manager only provides older versions) diff --git a/cpack/setup.cmake b/cpack/setup.cmake index 0c4f3cb..33f127e 100644 --- a/cpack/setup.cmake +++ b/cpack/setup.cmake @@ -111,11 +111,11 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY PSn00bSDK) ## DEB/RPM variables -set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.28), cmake (>= 3.21)") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.28), cmake (>= 3.20)") set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "ninja-build (>= 1.10)") set(CPACK_DEBIAN_PACKAGE_SUGGESTS "git (>= 2.25)") set(CPACK_DEBIAN_PACKAGE_SECTION devel) -set(CPACK_RPM_PACKAGE_REQUIRES "cmake >= 3.21") +set(CPACK_RPM_PACKAGE_REQUIRES "cmake >= 3.20") set(CPACK_RPM_PACKAGE_SUGGESTS "ninja-build >= 1.10, git >= 2.25") #set(CPACK_RPM_PACKAGE_RELOCATABLE ON) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 87210b9..15212c8 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -10,16 +10,32 @@ project( HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" ) +include(GNUInstallDirs) + +# Find all subdirectories that contain a CMake build script. This includes the +# top-level examples directory and this file as well, however we're going to +# skip it. file( GLOB_RECURSE _examples + RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/CMakeLists.txt ) foreach(_script IN LISTS _examples) - cmake_path(GET _script PARENT_PATH _dir) - if(_dir STREQUAL PROJECT_SOURCE_DIR) + if(_script STREQUAL "CMakeLists.txt") continue() endif() - add_subdirectory(${_dir}) + # CMake provides no way to override the install prefix of a subdirectory, + # as it "imports" its targets into the main project rather than treating it + # as a separate project. However, as the example subdirectories use + # install(... TYPE BIN) to install executables, it is possible to override + # CMAKE_INSTALL_BINDIR temporarily to place them in any directory within + # the install prefix. This is a hack, but it allows us to preserve the + # examples' folder hierarchy in the installation directory (it is already + # preserved by CMake in the build tree!) with minimal effort. + cmake_path(GET _script PARENT_PATH _dir) + cmake_path(GET _dir PARENT_PATH CMAKE_INSTALL_BINDIR) + + add_subdirectory(${PROJECT_SOURCE_DIR}/${_dir}) endforeach() diff --git a/examples/beginner/cppdemo/CMakeLists.txt b/examples/beginner/cppdemo/CMakeLists.txt index 3b6a53e..becf464 100644 --- a/examples/beginner/cppdemo/CMakeLists.txt +++ b/examples/beginner/cppdemo/CMakeLists.txt @@ -19,4 +19,4 @@ file(GLOB _sources *.cpp) psn00bsdk_add_executable(cppdemo STATIC ${_sources}) #psn00bsdk_add_cd_image(cppdemo_iso cppdemo iso.xml DEPENDS cppdemo) -install(FILES ${PROJECT_BINARY_DIR}/cppdemo.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/cppdemo.exe TYPE BIN) diff --git a/examples/beginner/hello/CMakeLists.txt b/examples/beginner/hello/CMakeLists.txt index 81ed0f7..7fb7c22 100644 --- a/examples/beginner/hello/CMakeLists.txt +++ b/examples/beginner/hello/CMakeLists.txt @@ -19,4 +19,4 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(hello STATIC ${_sources}) #psn00bsdk_add_cd_image(hello_iso hello iso.xml DEPENDS hello) -install(FILES ${PROJECT_BINARY_DIR}/hello.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/hello.exe TYPE BIN) diff --git a/examples/cdrom/cdbrowse/CMakeLists.txt b/examples/cdrom/cdbrowse/CMakeLists.txt index d587f5a..e5ec759 100644 --- a/examples/cdrom/cdbrowse/CMakeLists.txt +++ b/examples/cdrom/cdbrowse/CMakeLists.txt @@ -23,5 +23,5 @@ install( FILES ${PROJECT_BINARY_DIR}/cdbrowse.bin ${PROJECT_BINARY_DIR}/cdbrowse.cue - DESTINATION . + TYPE BIN ) diff --git a/examples/cdrom/cdxa/CMakeLists.txt b/examples/cdrom/cdxa/CMakeLists.txt index d95a40d..18dcc69 100644 --- a/examples/cdrom/cdxa/CMakeLists.txt +++ b/examples/cdrom/cdxa/CMakeLists.txt @@ -25,5 +25,5 @@ install( #${PROJECT_BINARY_DIR}/cdxa.bin #${PROJECT_BINARY_DIR}/cdxa.cue ${PROJECT_BINARY_DIR}/cdxa.exe - DESTINATION . + TYPE BIN ) diff --git a/examples/demos/n00bdemo/CMakeLists.txt b/examples/demos/n00bdemo/CMakeLists.txt index 02c7b35..c62c4ef 100644 --- a/examples/demos/n00bdemo/CMakeLists.txt +++ b/examples/demos/n00bdemo/CMakeLists.txt @@ -47,4 +47,4 @@ target_include_directories(n00bdemo PRIVATE ${PROJECT_SOURCE_DIR}) add_custom_target(n00bdemo_data DEPENDS data.lzp) add_dependencies(n00bdemo n00bdemo_data) -install(FILES ${PROJECT_BINARY_DIR}/n00bdemo.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/n00bdemo.exe TYPE BIN) diff --git a/examples/graphics/balls/CMakeLists.txt b/examples/graphics/balls/CMakeLists.txt index 5afb2b1..5886484 100644 --- a/examples/graphics/balls/CMakeLists.txt +++ b/examples/graphics/balls/CMakeLists.txt @@ -19,4 +19,4 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(balls STATIC ${_sources}) #psn00bsdk_add_cd_image(balls_iso balls iso.xml DEPENDS balls) -install(FILES ${PROJECT_BINARY_DIR}/balls.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/balls.exe TYPE BIN) diff --git a/examples/graphics/billboard/CMakeLists.txt b/examples/graphics/billboard/CMakeLists.txt index 1d9df78..8cd31a9 100644 --- a/examples/graphics/billboard/CMakeLists.txt +++ b/examples/graphics/billboard/CMakeLists.txt @@ -25,4 +25,4 @@ psn00bsdk_add_executable( ) #psn00bsdk_add_cd_image(billboard_iso billboard iso.xml DEPENDS billboard) -install(FILES ${PROJECT_BINARY_DIR}/billboard.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/billboard.exe TYPE BIN) diff --git a/examples/graphics/fpscam/CMakeLists.txt b/examples/graphics/fpscam/CMakeLists.txt index b2becb9..791f6c2 100644 --- a/examples/graphics/fpscam/CMakeLists.txt +++ b/examples/graphics/fpscam/CMakeLists.txt @@ -8,7 +8,7 @@ if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) endif() project( - hello + fpscam LANGUAGES C VERSION 1.0.0 DESCRIPTION "PSn00bSDK 3D camera controls example" @@ -19,4 +19,4 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(fpscam STATIC ${_sources}) #psn00bsdk_add_cd_image(fpscam_iso fpscam iso.xml DEPENDS fpscam) -install(FILES ${PROJECT_BINARY_DIR}/fpscam.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/fpscam.exe TYPE BIN) diff --git a/examples/graphics/gte/CMakeLists.txt b/examples/graphics/gte/CMakeLists.txt index 5fdf4d1..85b2942 100644 --- a/examples/graphics/gte/CMakeLists.txt +++ b/examples/graphics/gte/CMakeLists.txt @@ -8,7 +8,7 @@ if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) endif() project( - hello + gte LANGUAGES C VERSION 1.0.0 DESCRIPTION "PSn00bSDK GTE 3D cube example" @@ -19,4 +19,4 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(gte STATIC ${_sources}) #psn00bsdk_add_cd_image(gte_iso gte iso.xml DEPENDS gte) -install(FILES ${PROJECT_BINARY_DIR}/gte.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/gte.exe TYPE BIN) diff --git a/examples/graphics/hdtv/CMakeLists.txt b/examples/graphics/hdtv/CMakeLists.txt index 899f963..f92faeb 100644 --- a/examples/graphics/hdtv/CMakeLists.txt +++ b/examples/graphics/hdtv/CMakeLists.txt @@ -19,4 +19,4 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(hdtv STATIC ${_sources}) #psn00bsdk_add_cd_image(hdtv_iso hdtv iso.xml DEPENDS hdtv) -install(FILES ${PROJECT_BINARY_DIR}/hdtv.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/hdtv.exe TYPE BIN) diff --git a/examples/graphics/render2tex/CMakeLists.txt b/examples/graphics/render2tex/CMakeLists.txt index db30377..360840d 100644 --- a/examples/graphics/render2tex/CMakeLists.txt +++ b/examples/graphics/render2tex/CMakeLists.txt @@ -25,4 +25,4 @@ psn00bsdk_add_executable( ) #psn00bsdk_add_cd_image(render2tex_iso render2tex iso.xml DEPENDS render2tex) -install(FILES ${PROJECT_BINARY_DIR}/render2tex.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/render2tex.exe TYPE BIN) diff --git a/examples/graphics/rgb24/CMakeLists.txt b/examples/graphics/rgb24/CMakeLists.txt index 71e2cfa..bf8a8fa 100644 --- a/examples/graphics/rgb24/CMakeLists.txt +++ b/examples/graphics/rgb24/CMakeLists.txt @@ -25,4 +25,4 @@ psn00bsdk_add_executable( ) #psn00bsdk_add_cd_image(rgb24_iso rgb24 iso.xml DEPENDS rgb24) -install(FILES ${PROJECT_BINARY_DIR}/rgb24.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/rgb24.exe TYPE BIN) diff --git a/examples/io/pads/CMakeLists.txt b/examples/io/pads/CMakeLists.txt index 62c06a2..5bd7f5d 100644 --- a/examples/io/pads/CMakeLists.txt +++ b/examples/io/pads/CMakeLists.txt @@ -19,4 +19,4 @@ file(GLOB _sources *.c *.s) psn00bsdk_add_executable(pads STATIC ${_sources}) #psn00bsdk_add_cd_image(pads_iso pads iso.xml DEPENDS pads) -install(FILES ${PROJECT_BINARY_DIR}/pads.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/pads.exe TYPE BIN) diff --git a/examples/sound/vagsample/CMakeLists.txt b/examples/sound/vagsample/CMakeLists.txt index 54305ab..1a15d9c 100644 --- a/examples/sound/vagsample/CMakeLists.txt +++ b/examples/sound/vagsample/CMakeLists.txt @@ -19,4 +19,4 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(vagsample STATIC ${_sources}) #psn00bsdk_add_cd_image(vagsample_iso vagsample iso.xml DEPENDS vagsample) -install(FILES ${PROJECT_BINARY_DIR}/vagsample.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/vagsample.exe TYPE BIN) diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt index f28a136..88168e0 100644 --- a/examples/system/childexec/CMakeLists.txt +++ b/examples/system/childexec/CMakeLists.txt @@ -38,4 +38,4 @@ target_link_options(child PRIVATE -Ttext=0x80030000) # embedded via child_exe.s). add_dependencies(parent child) -install(FILES ${PROJECT_BINARY_DIR}/parent.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/parent.exe TYPE BIN) diff --git a/examples/system/console/CMakeLists.txt b/examples/system/console/CMakeLists.txt index 024c7a4..6dc6154 100644 --- a/examples/system/console/CMakeLists.txt +++ b/examples/system/console/CMakeLists.txt @@ -19,4 +19,4 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(console STATIC ${_sources}) #psn00bsdk_add_cd_image(console_iso console iso.xml DEPENDS console) -install(FILES ${PROJECT_BINARY_DIR}/console.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/console.exe TYPE BIN) diff --git a/examples/system/dynlink/CMakeLists.txt b/examples/system/dynlink/CMakeLists.txt index e7188de..5834647 100644 --- a/examples/system/dynlink/CMakeLists.txt +++ b/examples/system/dynlink/CMakeLists.txt @@ -28,5 +28,5 @@ install( FILES ${PROJECT_BINARY_DIR}/dynlink.bin ${PROJECT_BINARY_DIR}/dynlink.cue - DESTINATION . + TYPE BIN ) diff --git a/examples/system/timer/CMakeLists.txt b/examples/system/timer/CMakeLists.txt index 6dc5ec3..58daf9b 100644 --- a/examples/system/timer/CMakeLists.txt +++ b/examples/system/timer/CMakeLists.txt @@ -19,4 +19,4 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(timer STATIC ${_sources}) #psn00bsdk_add_cd_image(timer_iso timer iso.xml DEPENDS timer) -install(FILES ${PROJECT_BINARY_DIR}/timer.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/timer.exe TYPE BIN) diff --git a/examples/system/tty/CMakeLists.txt b/examples/system/tty/CMakeLists.txt index b8b5738..4e0ca36 100644 --- a/examples/system/tty/CMakeLists.txt +++ b/examples/system/tty/CMakeLists.txt @@ -19,4 +19,4 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(tty STATIC ${_sources}) #psn00bsdk_add_cd_image(tty_iso tty iso.xml DEPENDS tty) -install(FILES ${PROJECT_BINARY_DIR}/tty.exe DESTINATION .) +install(FILES ${PROJECT_BINARY_DIR}/tty.exe TYPE BIN) diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index 732294c..f485ec2 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -93,9 +93,7 @@ function(psn00bsdk_add_executable name type) 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} -- cgit v1.2.3 From 8b6a76055ca426c494e16042e21f5e19b870b2ac Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 11 Nov 2021 00:37:10 +0100 Subject: Cleaned up pads example, added CMake script for cartrom --- examples/io/pads/main.c | 100 ++++++++++++++++++------------- examples/io/pads/spi.c | 22 +++---- examples/lowlevel/cartrom/CMakeLists.txt | 36 +++++++++++ examples/lowlevel/cartrom/makefile | 14 ----- examples/system/dynlink/display.c | 8 ++- libpsn00b/cmake/internal_setup.cmake | 2 +- libpsn00b/cmake/virtual_targets.cmake | 4 +- 7 files changed, 117 insertions(+), 69 deletions(-) create mode 100644 examples/lowlevel/cartrom/CMakeLists.txt delete mode 100644 examples/lowlevel/cartrom/makefile (limited to 'examples') diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c index bb56a27..ea7219b 100644 --- a/examples/io/pads/main.c +++ b/examples/io/pads/main.c @@ -15,9 +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 doesn't work on pcsx-redux, and hasn't yet been - * tested on real hardware and/or with unofficial controllers. It works on - * DuckStation and no$psx though. + * 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. */ #include @@ -54,6 +57,10 @@ static const char *const PAD_TYPEIDS[] = { #define SCREEN_XRES 320 #define SCREEN_YRES 240 +#define BGCOLOR_R 48 +#define BGCOLOR_G 24 +#define BGCOLOR_B 0 + typedef struct { DISPENV disp; DRAWENV draw; @@ -73,14 +80,14 @@ void init_context(CONTEXT *ctx) { db = &(ctx->db[0]); SetDefDispEnv(&(db->disp), 0, 0, SCREEN_XRES, SCREEN_YRES); SetDefDrawEnv(&(db->draw), SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES); - setRGB0(&(db->draw), 63, 0, 127); + setRGB0(&(db->draw), BGCOLOR_R, BGCOLOR_G, BGCOLOR_B); db->draw.isbg = 1; db->draw.dtd = 1; db = &(ctx->db[1]); SetDefDispEnv(&(db->disp), SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES); SetDefDrawEnv(&(db->draw), 0, 0, SCREEN_XRES, SCREEN_YRES); - setRGB0(&(db->draw), 63, 0, 127); + setRGB0(&(db->draw), BGCOLOR_R, BGCOLOR_G, BGCOLOR_B); db->draw.isbg = 1; db->draw.dtd = 1; @@ -139,13 +146,17 @@ void send_pad_cmd( ); } -// This callback determines whether a pad that identifies as digital is -// actually a DualShock in digital mode by checking how it replied to the -// CONFIG_MODE command. +// 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. void dualshock_init_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { - // Flag the pad as digital-only if it didn't reply. - // FIXME: rx_len should be 8 for digital pads, but sometimes it's only 4 - if (rx_len < 4) { + PADTYPE *pad = (PADTYPE *) buff; + + if ( + (rx_len < 2) || + (pad->raw.prefix != 0x5a) || + (pad->raw.type != PAD_ID_CONFIG_MODE) + ) { printf("no, pad is digital-only (len = %d)\n", rx_len); pad_digital_only[port] = 1; @@ -154,9 +165,13 @@ void dualshock_init_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_le printf("yes, forcing analog mode (len = %d)\n", rx_len); - // Issue further commands to finish configuring the controller. + // Issue further commands to force analog mode on, unlock rumble (not used + // in this example) and enable longer responses containing button pressure + // readings. + // 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_SET_ANALOG, 0x01, 0x02, 0); // 0x03 disables analog button...? + 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); send_pad_cmd(port, PAD_CMD_RESPONSE_CONFIG, 0xff, 0xff, 0); // Ignored by DualShock 1 @@ -179,21 +194,22 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { // 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 // returning digital pad responses. - if ((pad->raw.prefix == 0x5a) && (pad->raw.type == PAD_ID_DIGITAL)) { + if ( + rx_len && + (pad->raw.prefix == 0x5a) && + (pad->raw.type == PAD_ID_DIGITAL) + ) { if (!pad_digital_only[port]) { printf("Detecting if pad %d supports config mode... ", port + 1); - send_pad_cmd( - port, - PAD_CMD_CONFIG_MODE, - 0x01, - 0x00, - &dualshock_init_cb - ); + // 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); } - } else if (pad_digital_only[port]) { - printf("Clearing digital-only flag for pad %d\n", port + 1); + } else { + //printf("Clearing digital-only flag for pad %d\n", port + 1); pad_digital_only[port] = 0; } @@ -213,13 +229,7 @@ int main(int argc, const char* argv[]) { FntPrint(-1, "COUNTER=%d", counter++); for (uint32_t port = 0; port < 2; port++) { - PADTYPE *pad = (PADTYPE *) 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. - //if (!pad->raw.prefix != 0x5a) { + // TODO. if (!pad_buff_len[port]) { FntPrint(-1, "\n\nPORT %d: NO DEVICE FOUND\n", port + 1); if ((counter % 64) < 32) @@ -228,26 +238,36 @@ int main(int argc, const char* argv[]) { continue; } - uint32_t type = pad->raw.type; - uint32_t len = pad->raw.len * 2; - if (type == PAD_ID_MULTITAP) - len = 32; + PADTYPE *pad = (PADTYPE *) pad_buff[port]; + PAD_TYPEID type = pad->raw.type; + + // 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)) { + FntPrint(-1, "\n\nPORT %d: INVALID RESPONSE\n", port + 1); + if ((counter % 64) < 32) + FntPrint(-1, " CHECK CONNECTION..."); + + continue; + }*/ FntPrint( -1, - "\n\nPORT %d: %s\n TYPE=%d LEN=%d", + "\n\nPORT %d: %s (TYPE=%d)\n", port + 1, PAD_TYPEIDS[type], - type, - len + type ); // Print a hexdump of the payload returned by the pad. - for (uint32_t i = 0; i < len; i++) + for (uint32_t i = 0; i < pad_buff_len[port]; i++) FntPrint( -1, - (i % 8) ? " %02x" : "\n %02x", - pad_buff[port][i + 2] + ((i - 2) % 8) ? " %02x" : "\n %02x", + pad_buff[port][i] ); } diff --git a/examples/io/pads/spi.c b/examples/io/pads/spi.c index 4728626..5fc2648 100644 --- a/examples/io/pads/spi.c +++ b/examples/io/pads/spi.c @@ -2,9 +2,9 @@ * PSn00bSDK controller polling example (SPI driver) * (C) 2021 spicyjpeg - MPL licensed * - * This is a fairly complete timer driven high-speed SPI driver, with support - * for sending custom commands (including memory card reads/writes), in about - * 200 lines of code. Feel free to copypaste and adapt it. + * This is a fairly complete timer driven, asynchronous high-speed SPI driver, + * with support for sending custom commands (including memory card access), in + * about 200 lines of code. Feel free to copypaste and adapt it. * * The way this works is by maintaining a queue of requests to send, each with * its own payload and callback. Timer 2 is configured to trigger an IRQ at @@ -42,8 +42,12 @@ #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)) -#define JOY_TXRX *((volatile uint32_t *) 0x1f801040) -#define JOY_STAT *((volatile uint32_t *) 0x1f801044) + +// 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) @@ -142,11 +146,9 @@ static void spi_ack_handler(void) { if (!ctx.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 to ensure we are only going to read valid data from - // now on. - volatile uint32_t dummy; - while (JOY_STAT & 0x0002) - dummy = JOY_TXRX; + // 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) { // If this is not the first byte, put it in the RX buffer. diff --git a/examples/lowlevel/cartrom/CMakeLists.txt b/examples/lowlevel/cartrom/CMakeLists.txt new file mode 100644 index 0000000..3e807a3 --- /dev/null +++ b/examples/lowlevel/cartrom/CMakeLists.txt @@ -0,0 +1,36 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + cartrom + LANGUAGES C ASM + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK expansion port ROM example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c *.s) + +# This example only uses the toolchain (without the rest of the SDK), so the +# executable has to be created manually and converted into raw binary format +# (for testing on emulators or flashing to a cheat cartridge). +add_executable (cartrom ${_sources}) +target_link_libraries(cartrom psn00bsdk_static_exe) +set_target_properties(cartrom PROPERTIES PREFIX "" SUFFIX ".elf") +target_link_options (cartrom PRIVATE -T${PROJECT_SOURCE_DIR}/rom.ld) + +target_include_directories(cartrom PRIVATE ${PROJECT_SOURCE_DIR}) + +add_custom_command( + TARGET cartrom POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary cartrom.elf cartrom.bin + BYPRODUCTS cartrom.bin +) + +install(FILES ${PROJECT_BINARY_DIR}/cartrom.bin TYPE BIN) diff --git a/examples/lowlevel/cartrom/makefile b/examples/lowlevel/cartrom/makefile deleted file mode 100644 index 2434685..0000000 --- a/examples/lowlevel/cartrom/makefile +++ /dev/null @@ -1,14 +0,0 @@ -PREFIX = mipsel-unknown-elf- - -CC = $(PREFIX)gcc -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: rom.o - $(LD) --oformat binary -T rom.ld -o cartrom.rom rom.o - -%.o: %.s - $(AS) -msoft-float --warn $< -o $@ - -clean: - rm -f rom.o cartrom.rom \ No newline at end of file diff --git a/examples/system/dynlink/display.c b/examples/system/dynlink/display.c index d8ad3ed..573f17c 100644 --- a/examples/system/dynlink/display.c +++ b/examples/system/dynlink/display.c @@ -10,6 +10,10 @@ #define SCREEN_XRES 320 #define SCREEN_YRES 240 +#define BGCOLOR_R 48 +#define BGCOLOR_G 24 +#define BGCOLOR_B 0 + /* Display/GPU context utilities */ void init_context(CONTEXT *ctx) { @@ -23,14 +27,14 @@ void init_context(CONTEXT *ctx) { db = &(ctx->db[0]); SetDefDispEnv(&(db->disp), 0, 0, SCREEN_XRES, SCREEN_YRES); SetDefDrawEnv(&(db->draw), SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES); - setRGB0(&(db->draw), 63, 0, 127); + setRGB0(&(db->draw), BGCOLOR_R, BGCOLOR_G, BGCOLOR_B); db->draw.isbg = 1; db->draw.dtd = 1; db = &(ctx->db[1]); SetDefDispEnv(&(db->disp), SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES); SetDefDrawEnv(&(db->draw), 0, 0, SCREEN_XRES, SCREEN_YRES); - setRGB0(&(db->draw), 63, 0, 127); + setRGB0(&(db->draw), BGCOLOR_R, BGCOLOR_G, BGCOLOR_B); db->draw.isbg = 1; db->draw.dtd = 1; diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index f485ec2..b0c4591 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -86,7 +86,7 @@ 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) 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 -- cgit v1.2.3 From 619fa016bbc4ddd8d4a670cf3f8aa63617473b2f Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 18 Nov 2021 17:23:25 +0100 Subject: Deprecated malloc.h, moved int*_t types to stdint.h --- examples/beginner/cppdemo/main.cpp | 2 +- examples/cdrom/cdbrowse/main.c | 1 - examples/cdrom/cdxa/main.c | 1 - examples/demos/n00bdemo/logo.c | 1 - examples/demos/n00bdemo/main.c | 1 - examples/io/pads/main.c | 2 +- examples/io/pads/spi.c | 4 ++-- examples/io/pads/spi.h | 1 + examples/system/dynlink/library/balls.c | 2 +- examples/system/dynlink/library/cube.c | 2 +- examples/system/dynlink/library/dll_common.h | 1 + examples/system/dynlink/main.c | 3 +-- indev/psxmdec/main.c | 2 +- indev/psxpad/main.c | 1 - libpsn00b/include/malloc.h | 14 ++------------ libpsn00b/include/stdint.h | 16 ++++++++++++++++ libpsn00b/include/stdlib.h | 28 +++++++++------------------- libpsn00b/include/sys/types.h | 16 ++++------------ libpsn00b/libc/c++-support.cxx | 3 +-- libpsn00b/libc/string.c | 2 +- libpsn00b/lzp/compress.c | 1 - libpsn00b/psxcd/isofs.c | 2 +- libpsn00b/psxetc/dl.c | 4 ++-- libpsn00b/psxgpu/font.c | 2 +- tools/util/elf2cpe.c | 2 +- 25 files changed, 48 insertions(+), 66 deletions(-) create mode 100644 libpsn00b/include/stdint.h (limited to 'examples') diff --git a/examples/beginner/cppdemo/main.cpp b/examples/beginner/cppdemo/main.cpp index 58bfcda..fd2e3a8 100644 --- a/examples/beginner/cppdemo/main.cpp +++ b/examples/beginner/cppdemo/main.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/examples/cdrom/cdbrowse/main.c b/examples/cdrom/cdbrowse/main.c index ead2df0..9a1dbd0 100644 --- a/examples/cdrom/cdbrowse/main.c +++ b/examples/cdrom/cdbrowse/main.c @@ -67,7 +67,6 @@ #include #include -#include #include "ball16c.h" diff --git a/examples/cdrom/cdxa/main.c b/examples/cdrom/cdxa/main.c index 16f1c82..5f11d8d 100644 --- a/examples/cdrom/cdxa/main.c +++ b/examples/cdrom/cdxa/main.c @@ -129,7 +129,6 @@ #include #include -#include #include "ball16c.h" diff --git a/examples/demos/n00bdemo/logo.c b/examples/demos/n00bdemo/logo.c index d10b5b4..40160e7 100644 --- a/examples/demos/n00bdemo/logo.c +++ b/examples/demos/n00bdemo/logo.c @@ -5,7 +5,6 @@ #include #include #include -#include "malloc.h" #include "smd.h" #include diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c index e9dd336..d2fe317 100644 --- a/examples/demos/n00bdemo/main.c +++ b/examples/demos/n00bdemo/main.c @@ -32,7 +32,6 @@ #include #include -#include "malloc.h" #include "smd.h" #include "data.h" #include "disp.h" diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c index ea7219b..92beb1c 100644 --- a/examples/io/pads/main.c +++ b/examples/io/pads/main.c @@ -23,7 +23,7 @@ * zerofilled responses, slow replies) for maximum compatibility. */ -#include +#include #include #include #include diff --git a/examples/io/pads/spi.c b/examples/io/pads/spi.c index 5fc2648..e01b3f6 100644 --- a/examples/io/pads/spi.c +++ b/examples/io/pads/spi.c @@ -26,9 +26,9 @@ * card APIs) alongside it. */ -#include +#include #include -#include +#include #include #include #include diff --git a/examples/io/pads/spi.h b/examples/io/pads/spi.h index 09223e2..1c473cd 100644 --- a/examples/io/pads/spi.h +++ b/examples/io/pads/spi.h @@ -6,6 +6,7 @@ #ifndef __SPI_H #define __SPI_H +#include #include //#define SPI_BUFF_LEN 34 diff --git a/examples/system/dynlink/library/balls.c b/examples/system/dynlink/library/balls.c index 2a4d9f4..ef6993e 100644 --- a/examples/system/dynlink/library/balls.c +++ b/examples/system/dynlink/library/balls.c @@ -3,7 +3,7 @@ * (C) 2021 spicyjpeg - MPL licensed */ -#include +#include #include #include #include diff --git a/examples/system/dynlink/library/cube.c b/examples/system/dynlink/library/cube.c index 57f3e56..84fe552 100644 --- a/examples/system/dynlink/library/cube.c +++ b/examples/system/dynlink/library/cube.c @@ -3,7 +3,7 @@ * (C) 2021 spicyjpeg - MPL licensed */ -#include +#include #include #include #include diff --git a/examples/system/dynlink/library/dll_common.h b/examples/system/dynlink/library/dll_common.h index 4f9314b..315a993 100644 --- a/examples/system/dynlink/library/dll_common.h +++ b/examples/system/dynlink/library/dll_common.h @@ -6,6 +6,7 @@ #ifndef __DLL_COMMON_H #define __DLL_COMMON_H +#include #include /* Common structures shared by the main executable and DLLs */ diff --git a/examples/system/dynlink/main.c b/examples/system/dynlink/main.c index 33f6f44..6d93e71 100644 --- a/examples/system/dynlink/main.c +++ b/examples/system/dynlink/main.c @@ -36,12 +36,11 @@ * as plugins/mods/patches stored on a memory card. */ -#include +#include #include #include #include #include -#include #include #include #include diff --git a/indev/psxmdec/main.c b/indev/psxmdec/main.c index c9fd678..f4f0f51 100644 --- a/indev/psxmdec/main.c +++ b/indev/psxmdec/main.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/indev/psxpad/main.c b/indev/psxpad/main.c index e8a6181..afd801e 100644 --- a/indev/psxpad/main.c +++ b/indev/psxpad/main.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include 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 " is deprecated, include 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 #endif // _MALLOC_H \ 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 " and u_* types are deprecated, include instead" + +//#include + 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 -#include +#include #include -#include extern "C" 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 #include -#include +#include int tolower(int chr) { 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 #if LZP_USE_MALLOC == TRUE #include -#include #endif #include "lzconfig.h" 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 #include -#include +#include #include #include #include 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 +#include #include -#include +#include #include #include #include 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 #include #include -#include +#include #include #include diff --git a/tools/util/elf2cpe.c b/tools/util/elf2cpe.c index 46b0a37..210f25b 100644 --- a/tools/util/elf2cpe.c +++ b/tools/util/elf2cpe.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include "elf.h" #ifdef WIN32 -- cgit v1.2.3