PSn00bSDK Documentation

repository·master·Indexed 22 days ago

https://github.com/lameguy64/psn00bsdk

A comprehensive open-source homebrew development kit for the original Sony PlayStation. It provides a C/C++ toolchain and hardware abstraction libraries (libpsn00b) for GPU support, GTE math/geometry, CD-ROM operations, MDEC hardware-accelerated decompression, and BIOS-based interrupt dispatch. Includes a CMake-based build system and a wide array of example programs covering graphics, audio, and system I/O.

Tokens
16.9K
Snippets
39
Records
83
Agent score
78%

What's inside PSn00bSDK

  1. Overview of libpsn00b/libc

    master

    The libc library is a limited C standard library implementation designed for use with PSn00bSDK. It focuses on the most commonly used C functions, specifically string and memory manipulation.

    Key features include:

    • Initialization: Includes assembler-based start code that handles basic system initialization, such as clearing the bss section, setting the gp register, and initializing the heap for malloc.
    • Memory Management: Provides a custom dynamic memory allocation implementation using a first-fit logic. This implementation avoids the PlayStation BIOS memory allocation functions to prevent reported memory leakage issues.
  2. Overview of the PSX Misc library (psxetc)

    master

    The psxetc library is a component of the PSn00bSDK that provides an open-source implementation of the ETC library for the PlayStation (PSX). It primarily serves two purposes:

    1. Interrupt and DMA Callback Dispatchers: Provides the infrastructure used by other libraries to handle interrupts and Direct Memory Access (DMA) callbacks.
    2. Dynamic Library Loading: Provides DL_* and dl* functions (similar to the standard dlopen() API) to allow for dynamic loading of libraries, a feature not present in the official Sony SDK.

    The library is licensed under the Mozilla Public License.

  3. Overview of the PSn00bSDK MDEC library

    master

    The PSn00bSDK MDEC library is a reimplementation of the official SDK's data compression library. It is designed to handle MDEC data processing and the decompression of Huffman-encoded bitstreams (such as .BS files or frames within .STR files) into data suitable for the MDEC.

    Key Features:

    • MDEC API: Provides data input/output functionality similar to the official SDK.
    • Decompression API: Provides two distinct methods for decompressing bitstreams into data for the MDEC.
    • Supported Bitstream Versions: Versions 1, 2, and 3 are supported. (Note: Version 0 and .IKI bitstreams are not supported).

    Note: This library does not include FMV playback logic; playback must be implemented by combining these APIs with custom code to stream data from the CD drive.

  4. Overview of PSn00bSDK

    master

    PSn00bSDK is an open-source homebrew software development kit for the original Sony PlayStation. It provides a C/C++ compiler toolchain and a set of libraries (libpsn00b) that abstract raw hardware into usable APIs for game and app development.

    Key capabilities include:

    • Graphics: Full GPU support (lines, polygons, sprites) and DMA transfers via a software-driven command queue. Supports NTSC and PAL.
    • Math/Geometry: Extensive GTE (Geometry Transformation Engine) support using fixed-point integer math via C/assembly macros and vector/matrix helpers.
    • Interrupts: BIOS-based interrupt dispatch for custom IRQ and DMA callbacks.
    • I/O: Serial I/O with buffering/console drivers, CD-ROM support (asynchronous reading, CD-DA, XA-ADPCM, ISO9660), and MDEC hardware-accelerated decompression.
    • Input: Basic controller support via BIOS or manual polling.
    • Advanced: Experimental runtime dynamic linking with function/variable introspection via build-time map files.
  5. Overview of the PSX GPU library

    master

    The PSX GPU library is an open-source C implementation of the PlayStation (PSX) GPU library, part of the PSn00bSDK. It is designed to closely resemble Sony's original syntax to facilitate porting homebrew code from the official SDK to PSn00bSDK.

    Key features include:

    • DMA Transfers: Supports DMA transfers for drawing OTs (Ordering Tables).
    • Internal OT Queue: Includes an internal queue so DrawOTag() can be called even while another OT is currently being drawn.
    • VRAM Management: Supports transferring image data to and from VRAM via DMA.
  6. Overview of the PSX GTE library

    master

    The PSX GTE library is an open-source implementation of the Geometry Transformation Engine (GTE) library, part of the PSn00bSDK. It is written primarily in MIPS assembly to leverage the GTE for complex matrix multiplication operations.

    The library is designed with syntax that closely resembles Sony's official SDK to facilitate easier porting of homebrew software. Unlike official GTE libraries that rely on inline GTE macros requiring external tools like DMPSX, this implementation uses the corresponding cop2 opcodes directly, simplifying the build process.

  7. Overview of the PSX SPU Library

    master

    The PSX SPU Library is an open-source C implementation of the PlayStation SPU (Sound Processing Unit) library, part of the PSn00bSDK. It provides low-level access to SPU functionality, specifically focusing on:

    • SPU initialization.
    • Reading and writing SPU RAM via DMA (Direct Memory Access).
    • Basic sample playback.

    Note that the library does not implement the full official API. Instead, it focuses on efficient operations. For tasks involving the official API that are essentially wrappers around register access, you should use the macros defined in hwregs_c.h directly.

  8. Understand the purpose of the indev directory

    master

    The indev directory contains work-in-progress (WIP) SDK components, such as prototype libraries and tools.

    Warning: These files are in the prototype stage and are not intended to be compiled during a typical SDK installation. They are maintained in the repository as a redundancy for the retiring Lameguy64 SVN repository.

  9. Summary of PSn00bSDK example programs

    master

    The PSn00bSDK includes a variety of example programs covering different hardware capabilities and software domains. Use these as templates or reference implementations for your own projects.

    Graphics Examples

    • graphics/balls: Draws colored balls bouncing around the screen (EXE).
    • graphics/billboard: Demonstrates 2D sprites in 3D space (EXE).
    • graphics/fpscam: First-person perspective camera with look-at (EXE).
    • graphics/gte: Rotating cube using GTE macros (EXE).
    • graphics/hdtv: Anamorphic widescreen at 704x480 (EXE).
    • graphics/render2tex: Procedural texture effects via off-screen drawing (EXE).
    • graphics/rgb24: Uncompressed 640x480 24-bit RGB image display (EXE).
    • graphics/tilesasm: Tile-map drawing using assembly language (EXE).
    • mdec/mdecimage: Displays raw MDEC format images (EXE).

    Audio & Video Examples

    • cdrom/cdxa: CD-XA ADPCM audio player (CD). Requires manual file provision and CD image building.
    • mdec/strvideo: Plays .STR video files using MDEC (CD). Requires manual file provision and CD image building.
    • sound/cdstream: Streams interleaved .VAG files from CD-ROM (CD).
    • sound/spustream: Streams interleaved .VAG files from main RAM (EXE).
    • sound/vagsample: Loads and plays .VAG sound files using the SPU (EXE).

    System & I/O Examples

    • beginner/hello: Simple "hello world" project template (EXE).
    • beginner/hellocpp: C++ version of the hello world template (EXE).
    • io/pads: Low-level controller reading (EXE). Note: May not automatically enable analog mode on DualShock controllers on real hardware.
    • system/childexec: Loading a child program and returning to parent (EXE).
    • system/console: TTY-based text console that interrupts gameplay (EXE).
    • system/dynlink: Demonstrates dynamically linked libraries (CD).
    • system/timer: Uses hardware timers with interrupts (EXE).
    • system/tty: TTY as a remote text console interface (EXE).

    Other Examples

    • cdrom/cdbrowse: File browser using libpsxcd directory functions (CD).
    • demos/n00bdemo: Premiere demonstration program (EXE). Note: May flicker on real hardware when using masking/stencil buffering.
    • io/system573: Konami System 573 arcade board example (CD).
    • lowlevel/cartrom: ROM firmware for cheat devices using GNU GAS (ROM). Note: Outdated; does not use SDK libraries; for reference only.
  10. Enable shared library support for 'Generic' system names

    master
    If you set CMAKE_SYSTEM_NAME to Generic (common for bare-metal targets), CMake assumes the platform does not support dynamic linking. To enable shared library support, you must set the TARGET_SUPPORTS_SHARED_LIBS global property after the project() command has been called.
  11. Choose a bitstream decompression implementation

    master

    The library provides two different implementations for decompressing Huffman-encoded bitstreams. Choose based on your performance and memory requirements:

    Uses a small (< 1 KB) lookup table and leverages the GTE (written in assembly). This is the modern implementation.

    • Functions: DecDCTvlcStart(), DecDCTvlcContinue()
    • Optimization: You can optionally call DecDCTvlcCopyTableV2() or DecDCTvlcCopyTableV3() to move the table to the scratchpad region to increase decompression speed.
    • Compatibility: Use DecDCTvlc() as a wrapper for Sony SDK compatibility.
    • Supported Versions: 1, 2, and 3.

    2. Main RAM Implementation (Legacy)

    Uses a large (34 KB) lookup table in main RAM (written in C).

    • Functions: DecDCTvlcStart2(), DecDCTvlcContinue2()
    • Setup: You must manually decompress the table ahead of time using DecDCTvlcBuild(). The table can be deallocated once it is no longer needed.
    • Compatibility: Use DecDCTvlc2() as a wrapper for Sony SDK compatibility.
    • Limitations: Does NOT support version 3 bitstreams.