From 31fba94b8e8c15c1d127925f01a38efc68933fd1 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Mon, 29 Nov 2021 00:17:28 +0100 Subject: Add io/system573 example, rewrite dev notes, fix CI --- examples/io/system573/CMakeLists.txt | 27 +++ examples/io/system573/iso.xml | 34 ++++ examples/io/system573/main.c | 371 +++++++++++++++++++++++++++++++++++ 3 files changed, 432 insertions(+) create mode 100644 examples/io/system573/CMakeLists.txt create mode 100644 examples/io/system573/iso.xml create mode 100644 examples/io/system573/main.c (limited to 'examples/io') diff --git a/examples/io/system573/CMakeLists.txt b/examples/io/system573/CMakeLists.txt new file mode 100644 index 0000000..34c9153 --- /dev/null +++ b/examples/io/system573/CMakeLists.txt @@ -0,0 +1,27 @@ +# 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( + system573 + LANGUAGES C ASM + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK Konami System 573 example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c *.s) +psn00bsdk_add_executable(system573 STATIC ${_sources}) +psn00bsdk_add_cd_image(system573_iso system573 iso.xml DEPENDS system573) + +install( + FILES + ${PROJECT_BINARY_DIR}/system573.bin + ${PROJECT_BINARY_DIR}/system573.cue + TYPE BIN +) diff --git a/examples/io/system573/iso.xml b/examples/io/system573/iso.xml new file mode 100644 index 0000000..09b4d85 --- /dev/null +++ b/examples/io/system573/iso.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c new file mode 100644 index 0000000..67a98da --- /dev/null +++ b/examples/io/system573/main.c @@ -0,0 +1,371 @@ +/* + * PSn00bSDK Konami System 573 example + * (C) 2021 spicyjpeg - MPL licensed + * + * This is a minimal example demonstrating how to target the Konami System 573 + * using PSn00bSDK. The System 573 is a PS1-based arcade motherboard that + * powered various Konami arcade games throughout the late 1990s, most notably + * Dance Dance Revolution and other Bemani rhythm games. It came in several + * configurations, with slightly different I/O connectors depending on the game + * and two optional add-on modules (known as the "analog I/O" and "digital I/O" + * boards respectively) providing light control outputs and, in the case of the + * digital I/O board, MP3 audio playback. + * + * Unlike other arcade systems based on PS1 hardware, the 573 is mostly + * identical to a regular PS1, with almost all custom extensions mapped into + * the expansion port region at 0x1f000000. The major differences are: + * + * - RAM is 4 MB instead of 2, and VRAM is 2 MB instead of 1. It is recommended + * *not* to use the additional memory to preserve PS1 compatibility. + * + * - The CD drive is replaced by a standard IDE/ATAPI drive (which most of the + * time is going to be an aftermarket DVD drive, as the original drives the + * system shipped with were prone to failure and couldn't read CD-Rs). This + * also means the 573 has no support at all for XA audio playback, as XA is + * not part of the CD-ROM specification implemented by IDE drives. CD audio + * is supported by most IDE drives, but 573 units with the digital I/O board + * installed have the 4-pin audio cable plugged into that instead of the + * drive. The IDE bus is connected to IRQ10 and DMA5 (expansion port) instead + * of IRQ2 and DMA3, which go unused. + * + * - The BIOS seems to have most file I/O APIs removed and exposes no functions + * whatsoever for accessing the IDE drive or the filesystem on the disc. The + * launcher/shell is completely different from Sony's shell and is capable of + * loading an executable from the CD drive, a PCMCIA memory-mapped flash card + * or the internal 16 MB flash memory. + * + * - The SPI controller bus seems to be left unconnected. Inputs are routed to + * a JAMMA PCB edge connector and handled through two custom/relabeled chips, + * which expose the inputs as memory-mapped registers. There is also a JVS + * port (i.e. RS-485 serial bus wired to a USB-A connector, commonly used for + * daisy-chaining peripherals in arcade cabinets) managed by a + * microcontroller. + * + * - There is a "security cartridge" slot, which breaks out the serial port as + * well as several GPIO pins. All security cartridge communication and DRM is + * handled by games rather than by the BIOS, so a security cartridge is *not* + * required to boot homebrew. Each game came with a different cartridge type; + * many of them expose the serial port or provide additional game-specific + * I/O connectors. + * + * Currently the only publicly available documentation for the custom registers + * is the System 573 MAME driver. Also keep in mind that the psxcd library does + * not yet support IDE drives, so the 573's drive can only be accessed by + * writing a custom ATAPI driver and ISO9660 parser (which is out of the scope + * of this example). + * + * https://github.com/mamedev/mame/blob/master/src/mame/drivers/ksys573.cpp + * https://github.com/mamedev/mame/blob/master/src/mame/machine/k573dio.cpp + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Register definitions */ + +#define EXP1_ADDR *((volatile uint32_t *) 0x1f801000) +#define EXP1_CTRL *((volatile uint32_t *) 0x1f801008) + +#define K573_IN0 *((volatile uint16_t *) 0x1f400000) +#define K573_IN1_L *((volatile uint16_t *) 0x1f400004) +#define K573_IN1_H *((volatile uint16_t *) 0x1f400006) +#define K573_IN2 *((volatile uint16_t *) 0x1f400008) +#define K573_IN3_L *((volatile uint16_t *) 0x1f40000c) +#define K573_IN3_H *((volatile uint16_t *) 0x1f40000e) +#define K573_BANK *((volatile uint16_t *) 0x1f500000) +#define K573_WATCHDOG *((volatile uint16_t *) 0x1f5c0000) + +#define K573_IDE_CS0 ((volatile uint16_t *) 0x1f480000) +#define K573_IDE_CS1 ((volatile uint16_t *) 0x1f4c0000) +#define K573_RTC ((volatile uint16_t *) 0x1f620000) +#define K573_IO_BOARD ((volatile uint16_t *) 0x1f640000) + +typedef enum { + ANALOG_IO_LIGHTS0 = 0x20, + ANALOG_IO_LIGHTS1 = 0x22, + ANALOG_IO_LIGHTS2 = 0x24, + ANALOG_IO_LIGHTS3 = 0x26, + + // The digital I/O board has a lot more registers than these, but there + // seems to be no DIGITAL_IO_LIGHTS6 register. WTF + DIGITAL_IO_LIGHTS1 = 0x70, + DIGITAL_IO_LIGHTS0 = 0x71, + DIGITAL_IO_LIGHTS3 = 0x72, + DIGITAL_IO_LIGHTS7 = 0x73, + DIGITAL_IO_LIGHTS4 = 0x7d, + DIGITAL_IO_LIGHTS5 = 0x7e, + DIGITAL_IO_LIGHTS2 = 0x7f +} IO_BOARD_REG; + +// The 573's real-time clock chip is an M48T58, which behaves like a standard +// 8 KB battery-backed SRAM with a bunch of special registers. Official games +// store highscores and settings in RTC RAM. +typedef enum { + RTC_CTRL = 0x1ff8, + RTC_SECONDS = 0x1ff9, + RTC_MINUTES = 0x1ffa, + RTC_HOURS = 0x1ffb, + RTC_DAY_OF_WEEK = 0x1ffc, + RTC_DAY_OF_MONTH = 0x1ffd, + RTC_MONTH = 0x1ffe, + RTC_YEAR = 0x1fff +} RTC_REG; + +#define btoi(x) ((((x) >> 4) & 0xf) * 10 + ((x) & 0xf)) + +/* Display/GPU context utilities */ + +#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; +} 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), 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), BGCOLOR_R, BGCOLOR_G, BGCOLOR_B); + 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); +} + +/* Input polling utilities */ + +typedef struct { + uint8_t p1_joy, p1_btn; + uint8_t p2_joy, p2_btn; + uint8_t coin, dip_sw; +} JAMMA_INPUTS; + +void get_jamma_inputs(JAMMA_INPUTS *output) { + uint16_t in1l = K573_IN1_L; + uint16_t in1h = K573_IN1_H; + uint16_t in2 = K573_IN2; + uint16_t in3l = K573_IN3_L; + uint16_t in3h = K573_IN3_H; + uint8_t p1_btn, p2_btn, coin; + + // Rearrange the bits read from the input register into something that's + // easier to parse and display. Refer to MAME for information on what each + // bit in the IN* registers does. + p1_btn = ((in2 >> 15) & 0x0001); // Bit 0 = start button + p1_btn |= ((in2 >> 8) & 0x0007) << 1; // Bit 1-3 = buttons 1-3 + p1_btn |= ((in3l >> 8) & 0x0003) << 4; // Bit 4-5 = buttons 4-5 + p1_btn |= ((in3l >> 11) & 0x0001) << 6; // Bit 6 = button 6 + p2_btn = ((in2 >> 7) & 0x0001); // Bit 0 = start button + p2_btn |= ((in2 >> 4) & 0x0007) << 1; // Bit 1-3 = buttons 1-3 + p2_btn |= ((in3h >> 8) & 0x0003) << 4; // Bit 4-5 = buttons 4-5 + p2_btn |= ((in3h >> 11) & 0x0001) << 6; // Bit 6 = button 6 + coin = ((in1h >> 8) & 0x0003); // Bit 0-1 = coin switches + coin |= ((in1h >> 12) & 0x0001) << 2; // Bit 2 = service button + coin |= ((in3l >> 10) & 0x0001) << 3; // Bit 3 = test button + coin |= ((in1h >> 10) & 0x0003) << 4; // Bit 4-5 = PCMCIA cards + + output->p1_joy = (in2 >> 8) & 0x000f; + output->p1_btn = p1_btn; + output->p2_joy = in2 & 0x000f; + output->p2_btn = p2_btn; + output->coin = coin; + output->dip_sw = in1l & 0x000f; +} + +/* I/O board (light control) utilities */ + +// This function controls light outputs on analog I/O boards. +void set_lights_analog(uint32_t lights) { + uint32_t bits; + + bits = (lights & 0x01010101) << 7; // Lamp 0 -> bit 7 + bits |= (lights & 0x02020202) << 5; // Lamp 1 -> bit 6 + bits |= (lights & 0x04040404) >> 1; // Lamp 2 -> bit 1 + bits |= (lights & 0x08080808) >> 3; // Lamp 3 -> bit 0 + bits |= (lights & 0x10101010) << 1; // Lamp 4 -> bit 5 + bits |= (lights & 0x20202020) >> 1; // Lamp 5 -> bit 4 + bits |= (lights & 0x40404040) >> 3; // Lamp 6 -> bit 3 + bits |= (lights & 0x80808080) >> 5; // Lamp 7 -> bit 2 + + K573_IO_BOARD[ANALOG_IO_LIGHTS0] = (bits) & 0xff; + K573_IO_BOARD[ANALOG_IO_LIGHTS1] = (bits >> 8) & 0xff; + K573_IO_BOARD[ANALOG_IO_LIGHTS2] = (bits >> 16) & 0xff; + K573_IO_BOARD[ANALOG_IO_LIGHTS3] = (bits >> 24) & 0xff; +} + +// This function controls light outputs on digital I/O boards (i.e. the ones +// that include MP3 playback hardware in addition to the light control). +// TODO: test this on real hardware -- it might not work if lights are handled +// by the board's FPGA, which requires a binary blob... +void set_lights_digital(uint32_t lights) { + uint32_t bits; + + bits = (lights & 0x11111111); // Lamp 0 -> bit 0 + bits |= (lights & 0x22222222) << 1; // Lamp 1 -> bit 2 + bits |= (lights & 0x44444444) << 1; // Lamp 2 -> bit 3 + bits |= (lights & 0x88888888) >> 2; // Lamp 3 -> bit 1 + + K573_IO_BOARD[DIGITAL_IO_LIGHTS0] = ((bits) & 0xf) << 12; + K573_IO_BOARD[DIGITAL_IO_LIGHTS1] = ((bits >> 4) & 0xf) << 12; + K573_IO_BOARD[DIGITAL_IO_LIGHTS2] = ((bits >> 8) & 0xf) << 12; + K573_IO_BOARD[DIGITAL_IO_LIGHTS3] = ((bits >> 12) & 0xf) << 12; + K573_IO_BOARD[DIGITAL_IO_LIGHTS4] = ((bits >> 16) & 0xf) << 12; + K573_IO_BOARD[DIGITAL_IO_LIGHTS5] = ((bits >> 20) & 0xf) << 12; + //K573_IO_BOARD[DIGITAL_IO_LIGHTS6] = ((bits >> 24) & 0xf) << 12; + K573_IO_BOARD[DIGITAL_IO_LIGHTS7] = ((bits >> 28) & 0xf) << 12; +} + +/* Main */ + +static CONTEXT ctx; + +#define SHOW_STATUS(...) { FntPrint(-1, __VA_ARGS__); FntFlush(-1); display(&ctx); } +#define SHOW_ERROR(...) { SHOW_STATUS(__VA_ARGS__); while (1) __asm__("nop"); } + +int main(int argc, const char* argv[]) { + // Reinitialize the heap and relocate the stack to allow the 573's full 4 + // MB of RAM to be used. This isn't strictly required; executables designed + // for 2 MB of RAM will also run fine on the 573 (obviously). + // FIXME: this seems to be broken currently + //__asm__ volatile("li $sp, 0x803fffe0"); + //_mem_init(0x400000, 0x20000); + + EXP1_ADDR = 0x1f000000; + EXP1_CTRL = 0x24173f47; // 573 BIOS uses this value + K573_WATCHDOG = 0; + + init_context(&ctx); + + // Determine whether we are running on a 573 by fetching the version string + // from the BIOS. + const char *const version = (const char *const) GetSystemInfo(0x02); + //if (strncmp(version, "Konami OS", 9)) + //SHOW_ERROR("ERROR: NOT RUNNING ON A SYSTEM 573!\n\n[%s]\n", version); + + uint32_t counter = 0; + uint8_t last_joystick = 0xff; + uint8_t last_buttons = 0xff; + uint32_t current_light = 0; + uint32_t is_digital = 0; + + while (1) { + FntPrint(-1, "COUNTER=%d\n", counter++); + + JAMMA_INPUTS inputs; + get_jamma_inputs(&inputs); + + FntPrint(-1, "\nJAMMA INPUTS:\n"); + FntPrint(-1, " P1 JOYSTICK =%04@\n", inputs.p1_joy); + FntPrint(-1, " P1 BUTTONS =%07@\n", inputs.p1_btn); + FntPrint(-1, " P2 JOYSTICK =%04@\n", inputs.p2_joy); + FntPrint(-1, " P2 BUTTONS =%07@\n", inputs.p2_btn); + FntPrint(-1, " COIN/SERVICE=%04@\n", inputs.coin); + FntPrint(-1, " DIP SWITCHES=%04@\n", inputs.dip_sw); + + FntPrint(-1, "\nCABINET LIGHTS:\n"); + FntPrint(-1, " BOARD=%s I/O\n", is_digital ? "DIGITAL" : "ANALOG"); + FntPrint(-1, " LIGHT=%d\n\n", current_light); + FntPrint(-1, " [START] CHANGE BOARD TYPE\n"); + FntPrint(-1, " [LEFT/RIGHT] SELECT LIGHT TO TEST\n"); + + // Request the current date/time from the RTC and display it. + K573_RTC[RTC_CTRL] |= 0x40; + FntPrint(-1, "\nRTC:\n"); + FntPrint( + -1, + " %02d-%02d-%02d %02d:%02d:%02d\n", + btoi(K573_RTC[RTC_YEAR]), + btoi(K573_RTC[RTC_MONTH]), + btoi(K573_RTC[RTC_DAY_OF_MONTH] & 0x3f), + btoi(K573_RTC[RTC_HOURS]), + btoi(K573_RTC[RTC_MINUTES]), + btoi(K573_RTC[RTC_SECONDS] & 0x7f) + ); + + FntPrint(-1, "\nSYSTEM:\n"); + FntPrint(-1, " KERNEL=%s\n", version); + FntPrint(-1, " PCMCIA=%02@\n", inputs.coin >> 4); + + FntFlush(-1); + display(&ctx); + + // Reset the watchdog. This must be done at least once per frame to + // prevent the 573 from rebooting. + K573_WATCHDOG = 0; + + if (is_digital) + set_lights_digital(1 << current_light); + else + set_lights_analog(1 << current_light); + + // Handle inputs. + if ((last_joystick & 0x01) && !(inputs.p1_joy & 0x01)) // Left + current_light--; + if ((last_joystick & 0x02) && !(inputs.p1_joy & 0x02)) // Right + current_light++; + if ((last_buttons & 0x02) && !(inputs.p1_btn & 0x02)) // Button 1 + current_light--; + if ((last_buttons & 0x04) && !(inputs.p1_btn & 0x04)) // Button 2 + current_light++; + if ((last_buttons & 0x01) && !(inputs.p1_btn & 0x01)) { // Start + is_digital = !is_digital; + if (is_digital) + set_lights_analog(0); + else + set_lights_digital(0); + } + + current_light %= 32; + last_joystick = inputs.p1_joy; + last_buttons = inputs.p1_btn; + } + + return 0; +} -- cgit v1.2.3 From 2e6625481cd006d0a9d68285ce557f195030718e Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 23 Dec 2021 22:09:06 +0100 Subject: Fix CdGetSector size inconsistency, update changelog --- .github/scripts/generate_release_notes.py | 46 ++++++++++--------------------- CHANGELOG.md | 29 +++++++++++++------ examples/cdrom/cdxa/main.c | 2 +- examples/io/system573/main.c | 2 +- libpsn00b/psxcd/cdgetsector.s | 3 +- libpsn00b/psxcd/isofs.c | 2 +- libpsn00b/psxcd/psxcd.c | 8 +++--- 7 files changed, 44 insertions(+), 48 deletions(-) (limited to 'examples/io') diff --git a/.github/scripts/generate_release_notes.py b/.github/scripts/generate_release_notes.py index f3e4870..e3fbc7f 100644 --- a/.github/scripts/generate_release_notes.py +++ b/.github/scripts/generate_release_notes.py @@ -3,7 +3,7 @@ # (C) 2021 spicyjpeg - MPL licensed import sys, re -from time import gmtime, strptime +from time import gmtime, strptime, struct_time from argparse import ArgumentParser, FileType ## Helpers @@ -11,14 +11,13 @@ from argparse import ArgumentParser, FileType VERSION_REGEX = re.compile(r"^(?:refs\/tags\/)?(?:v|ver|version|release)? *(.*)") def parse_date(date): + if isinstance(date, struct_time): + return date + return strptime(date.strip(), "%Y-%m-%d") def normalize_version(version): - match = VERSION_REGEX.match(version.lower()) - if not match: - raise ValueError(f"invalid version string: {version}") - - return match.group(1) + return VERSION_REGEX.match(version.lower()).group(1) ## Changelog parser @@ -50,9 +49,6 @@ def parse_blocks(changelog): # [ _crap, date, version, body, date, version, body, ... ] items = BLOCK_REGEX.split(changelog.strip()) - #if items[0].strip(): - #raise RuntimeError("the changelog doesn't start with a valid block") - # Iterate over all blocks from bottom to top (i.e. oldest first). last_version = FIRST_VERSION @@ -110,51 +106,39 @@ def generate_notes(versions): def get_args(): parser = ArgumentParser( - description = "Generates and outputs release notes from a Markdown changelog file.", - add_help = False + description = "Generates and outputs release notes from a Markdown changelog file." ) - - tools_group = parser.add_argument_group("Tools") - tools_group.add_argument( - "-h", "--help", - action = "help", - help = "Show this help message and exits" - ) - - files_group = parser.add_argument_group("Files") - files_group.add_argument( + parser.add_argument( "changelog", type = FileType("rt"), help = "Markdown changelog file to parse" ) - files_group.add_argument( + parser.add_argument( "-o", "--output", type = FileType("wt"), default = sys.stdout, - help = "Where to output release notes (stdout by default)", + help = "where to output release notes (stdout by default)", metavar = "file" ) - - filter_group = parser.add_argument_group("Filters") - filter_group.add_argument( + parser.add_argument( "-v", "--version", action = "append", type = str, - help = "Ignore all changes not belonging to a version (can be specified multiple times)", + help = "ignore all changes not belonging to a version (can be specified multiple times)", metavar = "name" ) - filter_group.add_argument( + parser.add_argument( "-f", "--from-date", type = parse_date, default = parse_date("2000-01-01"), - help = "Ignore all changes before date", + help = "ignore all changes before date", metavar = "yyyy-mm-dd" ) - filter_group.add_argument( + parser.add_argument( "-t", "--to-date", type = parse_date, default = gmtime(), - help = "Ignore all changes after date", + help = "ignore all changes after date", metavar = "yyyy-mm-dd" ) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9463b83..ea4f4d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ contributing to PSn00bSDK, add a new block at the top following this template: ``` -## --: +## --: [optional new version] : @@ -19,6 +19,17 @@ to ensure the changelog can be parsed correctly. ------------------------------------------------------------------------------- +## 2021-12-23 + +spicyjpeg: + +- psxcd: `CdGetSector()` now expects the sector size to be in 32-bit word units + (rather than bytes) for consistency with the official CD-ROM library. The + library's ISO9660 parser and helper functions have been updated accordingly. + **This is a breaking change**. + +- examples: Added `spustream` audio streaming example. + ## 2021-11-28: 0.18 spicyjpeg: @@ -453,7 +464,7 @@ Lameguy64: - psxgpu: Fixed typos in `setUVWH()` macro. -- Added `_boot()` BIOS function (A(A0h) aka Warmboot, useful for CD based +- Added `_boot()` BIOS function (`A(A0h)` aka Warmboot, useful for CD based serial loaders). ## 2019-08-17: 0.13b @@ -505,9 +516,9 @@ Lameguy64: executable to return to a parent executable, return logic automatically calls `EnterCriticalSection()`. -- libc: Updated build method which takes libgcc from the compiler and adds +- libc: Updated build method which takes `libgcc` from the compiler and adds its own object files into it, eliminating linker problems caused by having - to order libc and libgcc libraries in a specific manner. + to order `libc` and `libgcc` libraries in a specific manner. - psxgpu: Added `RestartCallback()`. @@ -526,7 +537,7 @@ Lameguy64: performance, as the R3000 does not support 64-bit arithmetic natively so its emulated like floats. `int64` still used for processing floats and doubles and old `vsprintf.c` file is still included for those who really - want int64 support for whatever reason. + want `int64` support for whatever reason. - libc: Removed `stdarg.h` which is part of GCC and not license compatible with MPL. The toolchain compiled with libgcc provides `stdarg.h` and other @@ -540,7 +551,7 @@ Lameguy64: - psxgpu: Fixed bug in DMACallback where the internal DMA handler would fail to install due to `GetInterruptCallback()` retrieving the callback value - immediately in the branch delay slot of a jr instruction, which resuls to + immediately in the branch delay slot of a `jr` instruction, which resuls to an inconsistent return value. This also broke `DrawSyncCallback()`. - psxsio: Done fixes on `_sio_control()` from the aformentioned issues with @@ -619,7 +630,7 @@ Lameguy64: ready instead of simply waiting for GPU transfer ready which is the likely cause of subtle GPU related timing issues, it also sets GPU DMA transfer mode to off afterwards. It can also read number of words remaining in DMA - transfer if a0 is non-zero but it likely only returns the correct value on + transfer if `a0` is non-zero but it likely only returns the correct value on VRAM transfers. Exact way how `DrawSync()` returns the count in the official SDK is currently unknown. @@ -645,10 +656,10 @@ Lameguy64: - Added `rgb24` example. - Got custom exit handler set using `SetCustomExitFromException()` (BIOS - function B(19h)) working. Currently used to acknowledge VSync IRQ but + function `B(19h)`) working. Currently used to acknowledge VSync IRQ but actual VSync handling is still done with events and needs to be transferred to the custom exit handler. At least it lets BIOS - controller functions to work now. See doc/dev `notes.txt` for details + controller functions to work now. See `doc/dev notes.txt` for details on how this handler behaves. - Made stack usage in `ResetGraph()` less wasteful. You only need to diff --git a/examples/cdrom/cdxa/main.c b/examples/cdrom/cdxa/main.c index 5f11d8d..284b92f 100644 --- a/examples/cdrom/cdxa/main.c +++ b/examples/cdrom/cdxa/main.c @@ -199,7 +199,7 @@ void xa_callback(int intr, unsigned char *result) if (intr == CdlDataReady) { /* Fetch data sector */ - CdGetSector((u_long*)&xa_sector_buff, 2048); + CdGetSector((u_long*)&xa_sector_buff, 512); /* Quirk: This CdGetSector() implementation must fetch 2048 bytes */ /* or more otherwise the following sectors will be read in an */ diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c index 67a98da..95c3155 100644 --- a/examples/io/system573/main.c +++ b/examples/io/system573/main.c @@ -306,7 +306,7 @@ int main(int argc, const char* argv[]) { FntPrint(-1, " P1 BUTTONS =%07@\n", inputs.p1_btn); FntPrint(-1, " P2 JOYSTICK =%04@\n", inputs.p2_joy); FntPrint(-1, " P2 BUTTONS =%07@\n", inputs.p2_btn); - FntPrint(-1, " COIN/SERVICE=%04@\n", inputs.coin); + FntPrint(-1, " COIN/SERVICE=%04@\n", inputs.coin & 0xf); FntPrint(-1, " DIP SWITCHES=%04@\n", inputs.dip_sw); FntPrint(-1, "\nCABINET LIGHTS:\n"); diff --git a/libpsn00b/psxcd/cdgetsector.s b/libpsn00b/psxcd/cdgetsector.s index 9af3543..dbe95cb 100644 --- a/libpsn00b/psxcd/cdgetsector.s +++ b/libpsn00b/psxcd/cdgetsector.s @@ -18,7 +18,8 @@ CdGetSector: # nop lui $v0, 0x1 - srl $a1, 2 +# srl $a1, 2 # (the official implementation expects $a1/size + # to be in 32-bit words rather than bytes) or $v0, $a1 sw $a0, D3_MADR($a2) # Set DMA base address and transfer length sw $v0, D3_BCR($a2) diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index 29bbb76..d1c1b18 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -795,7 +795,7 @@ static void _scan_callback(int status, unsigned char *result) { if( status == CdlDataReady ) { - CdGetSector((void*)_ses_scanbuff, 2048); + CdGetSector((void*)_ses_scanbuff, 512); if( _ses_scanbuff[0] == 0x1 ) { diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index 74c6c1c..76415f9 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -255,7 +255,7 @@ static void _CdReadReadyCallback(int status, unsigned char *result) CdGetSector((void*)_cd_read_addr, _cd_read_sector_sz); // Increment destination address - _cd_read_addr += _cd_read_sector_sz>>2; + _cd_read_addr += _cd_read_sector_sz; // Subtract sector count _cd_sector_count--; @@ -290,15 +290,15 @@ int CdRead(int sectors, u_long *buf, int mode) // Determine sector based on mode flags if( mode & CdlModeSize0 ) { - _cd_read_sector_sz = 2328; + _cd_read_sector_sz = 2328 / 4; } else if( mode & CdlModeSize1 ) { - _cd_read_sector_sz = 2340; + _cd_read_sector_sz = 2340 / 4; } else { - _cd_read_sector_sz = 2048; + _cd_read_sector_sz = 2048 / 4; } _cd_read_counter = VSync(-1); -- cgit v1.2.3 From d60b046bf362fcc9332f463823e8d02147d516de Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 23 Dec 2021 23:20:12 +0100 Subject: Remove PSN00BSDK_LIBS leftovers, improve CI artifact upload --- .github/workflows/build.yml | 32 +++++++++++++++++++++++------ doc/installation.md | 25 +++++++++++----------- examples/beginner/cppdemo/CMakeLists.txt | 4 ---- examples/beginner/hello/CMakeLists.txt | 4 ---- examples/cdrom/cdbrowse/CMakeLists.txt | 4 ---- examples/cdrom/cdxa/CMakeLists.txt | 4 ---- examples/demos/n00bdemo/CMakeLists.txt | 4 ---- examples/graphics/balls/CMakeLists.txt | 4 ---- examples/graphics/billboard/CMakeLists.txt | 4 ---- examples/graphics/fpscam/CMakeLists.txt | 4 ---- examples/graphics/gte/CMakeLists.txt | 4 ---- examples/graphics/hdtv/CMakeLists.txt | 4 ---- examples/graphics/render2tex/CMakeLists.txt | 4 ---- examples/graphics/rgb24/CMakeLists.txt | 4 ---- examples/io/pads/CMakeLists.txt | 4 ---- examples/io/system573/CMakeLists.txt | 4 ---- examples/lowlevel/cartrom/CMakeLists.txt | 4 ---- examples/sound/spustream/CMakeLists.txt | 4 ---- examples/sound/vagsample/CMakeLists.txt | 4 ---- examples/system/childexec/CMakeLists.txt | 4 ---- examples/system/console/CMakeLists.txt | 4 ---- examples/system/dynlink/CMakeLists.txt | 4 ---- examples/system/timer/CMakeLists.txt | 4 ---- examples/system/tty/CMakeLists.txt | 4 ---- 24 files changed, 38 insertions(+), 107 deletions(-) (limited to 'examples/io') diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c16ac3..3cbefb1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -124,13 +124,20 @@ jobs: cmake --build build cmake --build build -t package + # The GitHub Actions UI doesn't allow downloading individual files from + # an artifact, so it's best to upload each package type as a separate + # artifact. - name: Upload build artifacts uses: actions/upload-artifact@v2 with: name: psn00bsdk-windows - path: | - build/packages/* - !build/packages/_CPack_Packages + path: build/packages/*.zip + + - name: Upload build artifacts (NSIS) + uses: actions/upload-artifact@v2 + with: + name: psn00bsdk-windows-nsis + path: build/packages/*.exe build-sdk-linux: name: Build PSn00bSDK on Linux @@ -169,9 +176,19 @@ jobs: uses: actions/upload-artifact@v2 with: name: psn00bsdk-linux - path: | - build/packages/* - !build/packages/_CPack_Packages + path: build/packages/*.zip + + - name: Upload build artifacts (DEB) + uses: actions/upload-artifact@v2 + with: + name: psn00bsdk-linux-deb + path: build/packages/*.deb + + - name: Upload build artifacts (RPM) + uses: actions/upload-artifact@v2 + with: + name: psn00bsdk-linux-rpm + path: build/packages/*.rpm # This job takes care of creating a new release and upload the build # artifacts if the last commit is associated to a tag. @@ -222,4 +239,7 @@ jobs: files: | *.zip psn00bsdk-windows/* + psn00bsdk-windows-nsis/* psn00bsdk-linux/* + psn00bsdk-linux-deb/* + psn00bsdk-linux-rpm/* diff --git a/doc/installation.md b/doc/installation.md index 576eb7a..ca3aab4 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -96,9 +96,9 @@ and installed properly. - `/lib/libpsn00b` - `/share/psn00bsdk` -7. Set the `PSN00BSDK_LIBS` environment variable to point to the `lib/libpsn00b` - subfolder inside the install directory. You might also want to add the `bin` - folder to `PATH` if it's not listed already. +7. You may optionally set the `PSN00BSDK_LIBS` environment variable to point to + the `lib/libpsn00b` subfolder inside the install directory. You might also + want to add the `bin` folder to `PATH` if it's not listed already. Although not strictly required, you'll probably want to install a PS1 emulator with debugging capabilities such as [no$psx](https://problemkaputt.de/psx.htm) @@ -132,24 +132,23 @@ far from being feature-complete. 1. Copy the contents of `/share/psn00bsdk/template` (or the `template` folder within the repo) to your new project's root directory. -2. Configure and build the template by running: +2. If you haven't set the `PSN00BSDK_LIBS` environment variable previously or + if you want to use a different PSn00bSDK installation for the project, edit + `CMakePresets.json` to set the path you installed the SDK to. See the + [setup guide](cmake_reference.md#setup) for details. + +3. Configure and build the template by running: ```bash - cmake -S . -B ./build + cmake --preset default . cmake --build ./build ``` If you did everything correctly there should be a `template.bin` CD image in the `build` folder. Test it in an emulator to ensure it works. -Note that, even though the template relies on the `PSN00BSDK_LIBS` environment -variable to locate the SDK by default, you can also specify the path directly -on the CMake command line by adding -`-DCMAKE_TOOLCHAIN_FILE=/lib/libpsn00b/cmake/sdk.cmake` to the -CMake command line. - The toolchain script defines a few CMake macros to create PS1 executables, DLLs -and CD images. See the [reference](doc/cmake_reference.md) for details. +and CD images. See the [reference](cmake_reference.md) for details. ----------------------------------------- -_Last updated on 2021-11-19 by spicyjpeg_ +_Last updated on 2021-12-23 by spicyjpeg_ diff --git a/examples/beginner/cppdemo/CMakeLists.txt b/examples/beginner/cppdemo/CMakeLists.txt index becf464..c43d4a1 100644 --- a/examples/beginner/cppdemo/CMakeLists.txt +++ b/examples/beginner/cppdemo/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( cppdemo LANGUAGES CXX diff --git a/examples/beginner/hello/CMakeLists.txt b/examples/beginner/hello/CMakeLists.txt index 7fb7c22..d8297c5 100644 --- a/examples/beginner/hello/CMakeLists.txt +++ b/examples/beginner/hello/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( hello LANGUAGES C diff --git a/examples/cdrom/cdbrowse/CMakeLists.txt b/examples/cdrom/cdbrowse/CMakeLists.txt index e5ec759..e36407d 100644 --- a/examples/cdrom/cdbrowse/CMakeLists.txt +++ b/examples/cdrom/cdbrowse/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( cdbrowse LANGUAGES C diff --git a/examples/cdrom/cdxa/CMakeLists.txt b/examples/cdrom/cdxa/CMakeLists.txt index 18dcc69..7b90f59 100644 --- a/examples/cdrom/cdxa/CMakeLists.txt +++ b/examples/cdrom/cdxa/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( cdxa LANGUAGES C diff --git a/examples/demos/n00bdemo/CMakeLists.txt b/examples/demos/n00bdemo/CMakeLists.txt index c62c4ef..1c211b3 100644 --- a/examples/demos/n00bdemo/CMakeLists.txt +++ b/examples/demos/n00bdemo/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( n00bdemo LANGUAGES C ASM diff --git a/examples/graphics/balls/CMakeLists.txt b/examples/graphics/balls/CMakeLists.txt index 5886484..f5297c3 100644 --- a/examples/graphics/balls/CMakeLists.txt +++ b/examples/graphics/balls/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( balls LANGUAGES C diff --git a/examples/graphics/billboard/CMakeLists.txt b/examples/graphics/billboard/CMakeLists.txt index 8cd31a9..1b417d2 100644 --- a/examples/graphics/billboard/CMakeLists.txt +++ b/examples/graphics/billboard/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( billboard LANGUAGES C ASM diff --git a/examples/graphics/fpscam/CMakeLists.txt b/examples/graphics/fpscam/CMakeLists.txt index 791f6c2..cb0c086 100644 --- a/examples/graphics/fpscam/CMakeLists.txt +++ b/examples/graphics/fpscam/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( fpscam LANGUAGES C diff --git a/examples/graphics/gte/CMakeLists.txt b/examples/graphics/gte/CMakeLists.txt index 85b2942..f95c5ff 100644 --- a/examples/graphics/gte/CMakeLists.txt +++ b/examples/graphics/gte/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( gte LANGUAGES C diff --git a/examples/graphics/hdtv/CMakeLists.txt b/examples/graphics/hdtv/CMakeLists.txt index f92faeb..804b096 100644 --- a/examples/graphics/hdtv/CMakeLists.txt +++ b/examples/graphics/hdtv/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( hdtv LANGUAGES C diff --git a/examples/graphics/render2tex/CMakeLists.txt b/examples/graphics/render2tex/CMakeLists.txt index 360840d..70e489e 100644 --- a/examples/graphics/render2tex/CMakeLists.txt +++ b/examples/graphics/render2tex/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( render2tex LANGUAGES C ASM diff --git a/examples/graphics/rgb24/CMakeLists.txt b/examples/graphics/rgb24/CMakeLists.txt index bf8a8fa..449981a 100644 --- a/examples/graphics/rgb24/CMakeLists.txt +++ b/examples/graphics/rgb24/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( rgb24 LANGUAGES C ASM diff --git a/examples/io/pads/CMakeLists.txt b/examples/io/pads/CMakeLists.txt index 5bd7f5d..cf5f817 100644 --- a/examples/io/pads/CMakeLists.txt +++ b/examples/io/pads/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( pads LANGUAGES C ASM diff --git a/examples/io/system573/CMakeLists.txt b/examples/io/system573/CMakeLists.txt index 34c9153..1c74347 100644 --- a/examples/io/system573/CMakeLists.txt +++ b/examples/io/system573/CMakeLists.txt @@ -3,10 +3,6 @@ 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( system573 LANGUAGES C ASM diff --git a/examples/lowlevel/cartrom/CMakeLists.txt b/examples/lowlevel/cartrom/CMakeLists.txt index 3e807a3..107cc3d 100644 --- a/examples/lowlevel/cartrom/CMakeLists.txt +++ b/examples/lowlevel/cartrom/CMakeLists.txt @@ -3,10 +3,6 @@ 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 diff --git a/examples/sound/spustream/CMakeLists.txt b/examples/sound/spustream/CMakeLists.txt index 91243cf..9e84fa3 100644 --- a/examples/sound/spustream/CMakeLists.txt +++ b/examples/sound/spustream/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( spustream LANGUAGES C diff --git a/examples/sound/vagsample/CMakeLists.txt b/examples/sound/vagsample/CMakeLists.txt index 1a15d9c..f37be97 100644 --- a/examples/sound/vagsample/CMakeLists.txt +++ b/examples/sound/vagsample/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( vagsample LANGUAGES C diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt index 88168e0..ca0c110 100644 --- a/examples/system/childexec/CMakeLists.txt +++ b/examples/system/childexec/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( childexec LANGUAGES C ASM diff --git a/examples/system/console/CMakeLists.txt b/examples/system/console/CMakeLists.txt index 6dc6154..d58f212 100644 --- a/examples/system/console/CMakeLists.txt +++ b/examples/system/console/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( console LANGUAGES C diff --git a/examples/system/dynlink/CMakeLists.txt b/examples/system/dynlink/CMakeLists.txt index 5834647..aae3bb3 100644 --- a/examples/system/dynlink/CMakeLists.txt +++ b/examples/system/dynlink/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( dynlink LANGUAGES C diff --git a/examples/system/timer/CMakeLists.txt b/examples/system/timer/CMakeLists.txt index 58daf9b..328e07e 100644 --- a/examples/system/timer/CMakeLists.txt +++ b/examples/system/timer/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( timer LANGUAGES C diff --git a/examples/system/tty/CMakeLists.txt b/examples/system/tty/CMakeLists.txt index 4e0ca36..0664502 100644 --- a/examples/system/tty/CMakeLists.txt +++ b/examples/system/tty/CMakeLists.txt @@ -3,10 +3,6 @@ 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) -endif() - project( tty LANGUAGES C -- cgit v1.2.3 From de38196a978548b61c4b45115d24ef743b9eef90 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Mon, 17 Jan 2022 15:57:04 +0100 Subject: Minor psxgpu/psxpad header changes --- examples/io/pads/main.c | 37 ++-- libpsn00b/include/psxgpu.h | 2 +- libpsn00b/include/psxpad.h | 328 ++++++++++++++++++--------------- libpsn00b/psxetc/_dl_resolve_wrapper.s | 6 +- libpsn00b/psxgpu/gettimimage.c | 2 +- 5 files changed, 203 insertions(+), 172 deletions(-) (limited to 'examples/io') diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c index 92beb1c..cc4ef56 100644 --- a/examples/io/pads/main.c +++ b/examples/io/pads/main.c @@ -118,16 +118,16 @@ static volatile uint8_t pad_buff[2][34]; static volatile size_t pad_buff_len[2]; static volatile uint32_t pad_digital_only[2] = { 0, 0 }; -// Just a wrapper around spi_new_request(). This does not send the command +// Just a wrapper around SPI_CreateRequest(). This does not send the command // immediately but adds it to the driver's request queue. void send_pad_cmd( - uint32_t port, - PAD_COMMAND cmd, - uint8_t arg1, - uint8_t arg2, - SPICALLBACK callback + uint32_t port, + PadCommand cmd, + uint8_t arg1, + uint8_t arg2, + SPI_Callback callback ) { - SPIREQUEST *req = spi_new_request(); + SPI_request *req = SPI_CreateRequest(); req->len = 9; req->port = port; @@ -150,12 +150,12 @@ void send_pad_cmd( // actually a DualShock in digital mode by checking if it started identifying // as CONFIG_MODE after receiving a configuration command. void dualshock_init_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { - PADTYPE *pad = (PADTYPE *) buff; + PadResponse *pad = (PadResponse *) buff; if ( (rx_len < 2) || - (pad->raw.prefix != 0x5a) || - (pad->raw.type != PAD_ID_CONFIG_MODE) + (pad->prefix != 0x5a) || + (pad->type != PAD_ID_CONFIG_MODE) ) { printf("no, pad is digital-only (len = %d)\n", rx_len); @@ -187,7 +187,7 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { if (rx_len) memcpy((void *) pad_buff[port], (void *) buff, rx_len); - PADTYPE *pad = (PADTYPE *) buff; + PadResponse *pad = (PadResponse *) buff; // If this pad identifies as a digital pad and hasn't been flagged as a // digital-only pad already, attempt to put it into analog mode by entering @@ -196,8 +196,8 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { // returning digital pad responses. if ( rx_len && - (pad->raw.prefix == 0x5a) && - (pad->raw.type == PAD_ID_DIGITAL) + (pad->prefix == 0x5a) && + (pad->type == PAD_ID_DIGITAL) ) { if (!pad_digital_only[port]) { printf("Detecting if pad %d supports config mode... ", port + 1); @@ -221,7 +221,7 @@ static CONTEXT ctx; int main(int argc, const char* argv[]) { init_context(&ctx); - spi_init(&poll_cb); + SPI_Init(&poll_cb); uint32_t counter = 0; @@ -238,15 +238,14 @@ int main(int argc, const char* argv[]) { continue; } - PADTYPE *pad = (PADTYPE *) pad_buff[port]; - PAD_TYPEID type = pad->raw.type; + PadResponse *pad = (PadResponse *) pad_buff[port]; // According to nocash docs, there is a hardware bug in DualShock // controllers that causes the prefix byte (normally 0x5a) to turn // into 0x00 if the analog button is pressed after configuration // commands have been used. Thus making sure the prefix is 0x5a // isn't enough to reliably detect pads. - /*if ((pad->raw.prefix != 0x5a) && (type != PAD_ID_ANALOG)) { + /*if ((pad->prefix != 0x5a) && (pad->type != PAD_ID_ANALOG)) { FntPrint(-1, "\n\nPORT %d: INVALID RESPONSE\n", port + 1); if ((counter % 64) < 32) FntPrint(-1, " CHECK CONNECTION..."); @@ -258,8 +257,8 @@ int main(int argc, const char* argv[]) { -1, "\n\nPORT %d: %s (TYPE=%d)\n", port + 1, - PAD_TYPEIDS[type], - type + PAD_TYPEIDS[pad->type], + pad->type ); // Print a hexdump of the payload returned by the pad. diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h index f50b841..f061219 100644 --- a/libpsn00b/include/psxgpu.h +++ b/libpsn00b/include/psxgpu.h @@ -609,7 +609,7 @@ void AddPrim(u_long* ot, void* pri); // Function definitions (C) -int GetTimInfo(u_long *tim, TIM_IMAGE *timimg); /* ORIGINAL */ +int GetTimInfo(const u_long *tim, TIM_IMAGE *timimg); /* ORIGINAL */ DISPENV *SetDefDispEnv(DISPENV *disp, int x, int y, int w, int h); DRAWENV *SetDefDrawEnv(DRAWENV *draw, int x, int y, int w, int h); diff --git a/libpsn00b/include/psxpad.h b/libpsn00b/include/psxpad.h index d152896..9638ec1 100644 --- a/libpsn00b/include/psxpad.h +++ b/libpsn00b/include/psxpad.h @@ -14,43 +14,48 @@ #ifndef _PSXPAD_H #define _PSXPAD_H -// Pad button definitions for digital pad, joystick, dual analog, -// Dualshock and Jogcon -#define PAD_SELECT 1 -#define PAD_L3 2 -#define PAD_R3 4 -#define PAD_START 8 -#define PAD_UP 16 -#define PAD_RIGHT 32 -#define PAD_DOWN 64 -#define PAD_LEFT 128 -#define PAD_L2 256 -#define PAD_R2 512 -#define PAD_L1 1024 -#define PAD_R1 2048 -#define PAD_TRIANGLE 4096 -#define PAD_CIRCLE 8192 -#define PAD_CROSS 16384 -#define PAD_SQUARE 32768 - -// Mouse button definitions -#define MOUSE_RIGHT 1024 -#define MOUSE_LEFT 2048 - -// neGcon button definitions -#define NCON_START 8 -#define NCON_UP 16 -#define NCON_RIGHT 32 -#define NCON_DOWN 64 -#define NCON_LEFT 128 -#define NCON_R 256 -#define NCON_B 512 -#define NCON_A 1024 - -// Guncon button definitions -#define GCON_A 8 -#define GCON_TRIGGER 8192 -#define GCON_B 16384 +#include + +/* Controller type and button definitions */ + +typedef enum { + // Standard pads, analog joystick, Jogcon + PAD_SELECT = 1 << 0, + PAD_L3 = 1 << 1, + PAD_R3 = 1 << 2, + PAD_START = 1 << 3, + PAD_UP = 1 << 4, + PAD_RIGHT = 1 << 5, + PAD_DOWN = 1 << 6, + PAD_LEFT = 1 << 7, + PAD_L2 = 1 << 8, + PAD_R2 = 1 << 9, + PAD_L1 = 1 << 10, + PAD_R1 = 1 << 11, + PAD_TRIANGLE = 1 << 12, + PAD_CIRCLE = 1 << 13, + PAD_CROSS = 1 << 14, + PAD_SQUARE = 1 << 15, + + // Mouse + MOUSE_LEFT = 1 << 10, + MOUSE_RIGHT = 1 << 11, + + // neGcon + NCON_START = 1 << 3, + NCON_UP = 1 << 4, + NCON_RIGHT = 1 << 5, + NCON_DOWN = 1 << 6, + NCON_LEFT = 1 << 7, + NCON_R = 1 << 8, + NCON_B = 1 << 9, + NCON_A = 1 << 10, + + // Guncon + GCON_A = 1 << 3, + GCON_TRIGGER = 1 << 13, + GCON_B = 1 << 14 +} PadButton; typedef enum { PAD_ID_MOUSE = 0x1, // Sony PS1 mouse @@ -64,9 +69,10 @@ typedef enum { PAD_ID_JOGCON = 0xe, // Namco Jogcon PAD_ID_CONFIG_MODE = 0xf, // Dual Analog/DualShock in config mode (if len == 0x3) PAD_ID_NONE = 0xf // No pad connected (if len == 0xf) -} PAD_TYPEID; +} PadTypeID; + +/* Pad and memory card commands */ -// Controller command definitions typedef enum { PAD_CMD_INIT_PRESSURE = '@', // Initialize DS2 button pressure sensors (in config mode) PAD_CMD_READ = 'B', // Read pad state and set rumble @@ -74,131 +80,155 @@ typedef enum { PAD_CMD_SET_ANALOG = 'D', // Set analog mode/LED state (in config mode) PAD_CMD_GET_ANALOG = 'E', // Get analog mode/LED state (in config mode) PAD_CMD_REQUEST_CONFIG = 'M', // Configure request/unlock vibration (in config mode) - PAD_CMD_RESPONSE_CONFIG = 'O' // Configure response/unlock DS2 pressure (in config mode) -} PAD_COMMAND; + PAD_CMD_RESPONSE_CONFIG = 'O', // Configure response/unlock DS2 pressure (in config mode) -// Memory card command/response definitions -typedef enum { - MCD_CMD_READ = 'R', // Read sector - MCD_CMD_IDENTIFY = 'S', // Retrieve ID and card size information - MCD_CMD_WRITE = 'W' // Write sector -} MCD_COMMAND; + MCD_CMD_READ_SECTOR = 'R', // Read 128-byte sector + MCD_CMD_IDENTIFY = 'S', // Retrieve ID and card size information (Sony cards only) + MCD_CMD_WRITE_SECTOR = 'W' // Erase and write 128-byte sector +} PadCommand; typedef enum { MCD_STAT_OK = 'G', MCD_STAT_BAD_CHECKSUM = 'N', MCD_STAT_BAD_SECTOR = 0xff -} MCD_STATUS; - -#define MCD_CMD_READ_LEN 139 -#define MCD_CMD_IDENTIFY_LEN 9 -#define MCD_CMD_WRITE_LEN 137 - -// Memory card status flags -#define MCD_FLAG_WRITE_ERROR 4 // Last write command failed -#define MCD_FLAG_NOT_WRITTEN 8 // No writes have been issued yet -#define MCD_FLAG_UNKNOWN 16 // Might be set on third-party cards - -// Struct for data returned by controllers -typedef struct _PADTYPE { - union { // Header: - struct __attribute__((packed)) { // When parsing data returned by BIOS: - unsigned char stat; // Status - unsigned char len:4; // Payload length / 2, 0 for multitap - unsigned char type:4; // Device type (PAD_TYPEID) +} MemCardStatus; + +typedef enum { + MCD_FLAG_WRITE_ERROR = 1 << 2, // Last write command failed + MCD_FLAG_NOT_WRITTEN = 1 << 3, // No writes have been issued yet + MCD_FLAG_UNKNOWN = 1 << 4 // Might be set on third-party cards +} MemCardStatusFlag; + +#define MEMCARD_CMD_READ_LEN 139 +#define MEMCARD_CMD_IDENTIFY_LEN 9 +#define MEMCARD_CMD_WRITE_LEN 137 + +/* Controller response as returned by BIOS driver */ + +typedef struct __attribute__((packed)) _PADTYPE { + uint8_t stat; // Status + uint8_t len:4; // Payload length / 2, 0 for multitap + uint8_t type:4; // Device type (PadTypeID) + + uint16_t btn; // Button states + union { + struct { // Analog controller: + uint8_t rs_x,rs_y; // - Right stick coordinates + uint8_t ls_x,ls_y; // - Left stick coordinates + uint8_t press[12]; // - Button pressure (DualShock 2 only) }; - struct __attribute__((packed)) { // When parsing raw controller response: - unsigned char len:4; // Payload length / 2, 0 for multitap - unsigned char type:4; // Device type (PAD_TYPEID) - unsigned char prefix; // Must be 0x5a - } raw; - }; - struct { // Payload: - unsigned short btn; // Button states - union { - struct { // Analog controller: - unsigned char rs_x,rs_y; // Right stick coordinates - unsigned char ls_x,ls_y; // Left stick coordinates - unsigned char press[12]; // Button pressure (DualShock 2 only) - }; - struct { // Mouse: - char x_mov; // X movement of mouse - char y_mov; // Y movement of mouse - }; - struct { // neGcon: - unsigned char twist; // Controller twist - unsigned char btn_i; // I button value - unsigned char btn_ii; // II button value - unsigned char trg_l; // L trigger value - }; - struct { // Jogcon: - unsigned short jog_rot; // Jog rotation - }; - struct { // Guncon: - unsigned short gun_x; // Gun X position in dotclocks - unsigned short gun_y; // Gun Y position in scanlines - }; + struct { // Mouse: + int8_t x_mov; // - X movement of mouse + int8_t y_mov; // - Y movement of mouse + }; + struct { // neGcon: + uint8_t twist; // - Controller twist + uint8_t btn_i; // - I button value + uint8_t btn_ii; // - II button value + uint8_t trg_l; // - L trigger value + }; + struct { // Jogcon: + uint16_t jog_rot; // - Jog rotation + }; + struct { // Guncon: + uint16_t gun_x; // - Gun X position in dotclocks + uint16_t gun_y; // - Gun Y position in scanlines }; }; } PADTYPE; -typedef struct _MCDRESPONSE { - unsigned char flags; // Status flags - unsigned char type1; // Must be 0x5a - unsigned char type2; // Must be 0x5d +//typedef struct _PADTYPE MOUSETYPE; +//typedef struct _PADTYPE NCONTYPE; +//typedef struct _PADTYPE JCONTYPE; +//typedef struct _PADTYPE GCONTYPE; + +/* Raw responses */ + +typedef struct __attribute__((packed)) _PadResponse { + uint8_t len:4; // Payload length / 2, 0 for multitap + uint8_t type:4; // Device type (PadTypeID) + uint8_t prefix; // Must be 0x5a + + uint16_t btn; // Button states + union { + struct { // Analog controller: + uint8_t rs_x,rs_y; // - Right stick coordinates + uint8_t ls_x,ls_y; // - Left stick coordinates + uint8_t press[12]; // - Button pressure (DualShock 2 only) + }; + struct { // Mouse: + int8_t x_mov; // - X movement of mouse + int8_t y_mov; // - Y movement of mouse + }; + struct { // neGcon: + uint8_t twist; // - Controller twist + uint8_t btn_i; // - I button value + uint8_t btn_ii; // - II button value + uint8_t trg_l; // - L trigger value + }; + struct { // Jogcon: + uint16_t jog_rot; // - Jog rotation + }; + struct { // Guncon: + uint16_t gun_x; // - Gun X position in dotclocks + uint16_t gun_y; // - Gun Y position in scanlines + }; + }; +} PadResponse; + +typedef struct __attribute__((packed)) _MemCardResponse { + uint8_t flags; // Status flags (MemCardStatusFlag) + uint8_t type1; // Must be 0x5a + uint8_t type2; // Must be 0x5d + union { - struct { // MCD_CMD_READ response: - unsigned char dummy[2]; - unsigned char ack1; // Must be 0x5c - unsigned char ack2; // Must be 0x5d - unsigned char lba_h; - unsigned char lba_l; - unsigned char data[128]; - unsigned char checksum; // = lba_h ^ lba_l ^ data - unsigned char stat; // Status (MCD_STATUS) + struct { // CMD_READ response: + uint8_t dummy[2]; + uint8_t ack1; // Must be 0x5c + uint8_t ack2; // Must be 0x5d + uint8_t lba_h; + uint8_t lba_l; + uint8_t data[128]; + uint8_t checksum; // = lba_h ^ lba_l ^ data + uint8_t stat; // Status (MemCardStatus) } read; - struct { // MCD_CMD_IDENTIFY response: - unsigned char ack1; // Must be 0x5c - unsigned char ack2; // Must be 0x5d - unsigned char size_h; // Card capacity bits 8-15 (0x04 = 128KB) - unsigned char size_l; // Card capacity bits 0-7 (0x00 = 128KB) - unsigned char blksize_h; // Sector size bits 8-15 (must be 0x00) - unsigned char blksize_l; // Sector size bits 0-7 (must be 0x80) + struct { // CMD_IDENTIFY response: + uint8_t ack1; // Must be 0x5c + uint8_t ack2; // Must be 0x5d + uint8_t size_h; // Card capacity bits 8-15 (0x04 = 128KB) + uint8_t size_l; // Card capacity bits 0-7 (0x00 = 128KB) + uint8_t blksize_h; // Sector size bits 8-15 (must be 0x00) + uint8_t blksize_l; // Sector size bits 0-7 (must be 0x80) } identify; - struct { // MCD_CMD_WRITE response: - unsigned char dummy[131]; - unsigned char ack1; // Must be 0x5c - unsigned char ack2; // Must be 0x5d - unsigned char stat; // Status (MCD_STATUS) + struct { // CMD_WRITE response: + uint8_t dummy[131]; + uint8_t ack1; // Must be 0x5c + uint8_t ack2; // Must be 0x5d + uint8_t stat; // Status (MemCardStatus) } write; }; -} MCDRESPONSE; - -//typedef PADTYPE MOUSETYPE; -//typedef PADTYPE NCONTYPE; -//typedef PADTYPE JCONTYPE; -//typedef PADTYPE GCONTYPE; - -// Structs for raw controller request -typedef struct _PADREQUEST { - unsigned char addr; // Must be 0x01 (or 02/03/04 for multitap pads) - unsigned char cmd; // Command (PAD_COMMAND) - unsigned char tap_mode; // 0x01 to enable multitap response - unsigned char motor_r; // Right motor control (on/off) - unsigned char motor_l; // Left motor control (PWM) - unsigned char dummy[4]; -} PADREQUEST; - -// Structs for raw memory card request -typedef struct _MCDREQUEST { - unsigned char addr; // Must be 0x81 (or 02/03/04 for multitap cards) - unsigned char cmd; // Command (MCD_COMMAND) - unsigned char dummy[2]; - unsigned char lba_h; // Sector address bits 8-15 (dummy for CMD_IDENTIFY) - unsigned char lba_l; // Sector address bits 0-7 (dummy for CMD_IDENTIFY) - unsigned char data[128]; // Sector payload (dummy for CMD_READ/CMD_IDENTIFY) - unsigned char checksum; // = lba_h ^ lba_l ^ data (CMD_WRITE only) - unsigned char dummy2[3]; -} MCDREQUEST; +} MemCardResponse; + +/* Raw requests */ + +typedef struct __attribute__((packed)) _PadRequest { + uint8_t addr; // Must be 0x01 (or 02/03/04 for multitap pads) + uint8_t cmd; // Command (PadCommand) + uint8_t tap_mode; // 0x01 to enable multitap response + uint8_t motor_r; // Right motor control (on/off) + uint8_t motor_l; // Left motor control (PWM) + uint8_t dummy[4]; +} PadRequest; + +typedef struct __attribute__((packed)) _MemCardRequest { + uint8_t addr; // Must be 0x81 (or 02/03/04 for multitap cards) + uint8_t cmd; // Command (MemCardCommand) + uint8_t dummy[2]; + uint8_t lba_h; // Sector address bits 8-15 (dummy for CMD_IDENTIFY) + uint8_t lba_l; // Sector address bits 0-7 (dummy for CMD_IDENTIFY) + uint8_t data[128]; // Sector payload (dummy for CMD_READ/CMD_IDENTIFY) + uint8_t checksum; // = lba_h ^ lba_l ^ data (CMD_WRITE only) + uint8_t dummy2[3]; +} MemCardRequest; #endif \ No newline at end of file diff --git a/libpsn00b/psxetc/_dl_resolve_wrapper.s b/libpsn00b/psxetc/_dl_resolve_wrapper.s index 7f1132b..01ebf3a 100644 --- a/libpsn00b/psxetc/_dl_resolve_wrapper.s +++ b/libpsn00b/psxetc/_dl_resolve_wrapper.s @@ -48,7 +48,9 @@ _dl_resolve_wrapper: jr $t0 nop -.global _dl_credits -.type _dl_credits, @object +.section .data + +.global _dl_credits +.type _dl_credits, @object _dl_credits: .asciiz "psxetc runtime dynamic linker by spicyjpeg\n" diff --git a/libpsn00b/psxgpu/gettimimage.c b/libpsn00b/psxgpu/gettimimage.c index d9cf1bf..5598e07 100644 --- a/libpsn00b/psxgpu/gettimimage.c +++ b/libpsn00b/psxgpu/gettimimage.c @@ -1,7 +1,7 @@ #include #include -int GetTimInfo(u_long *tim, TIM_IMAGE *timimg) { +int GetTimInfo(const u_long *tim, TIM_IMAGE *timimg) { u_long *rtim; -- cgit v1.2.3