### Disc Sector Data Interleaving Example Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt Provides a sequential example of how video frames and audio data are interleaved across disc sectors during playback. ```text Sector 1: Video frame 1, sector #0 (of 5) Sector 2: Video frame 1, sector #1 (of 5) Sector 3: Video frame 1, sector #2 (of 5) Sector 3: Video frame 1, sector #3 (of 5) Sector 4: Video frame 1, sector #4 (of 5) Sector 5: Video frame 2, sector #0 (of 4) Sector 6: Video frame 2, sector #1 (of 4) Sector 7: Video frame 2, sector #2 (of 4) Sector 8: 4032 samples of audio at 37800 samples/second Sector 9: Video frame 2, sector #3 (of 4) Sector 10: Video frame 3, sector #0 (of 5) ``` -------------------------------- ### Interactive Program Notice Example Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/doc/CDDL-GPL-2-CP.txt This is a sample notice that an interactive program should display upon startup, providing version, copyright, warranty, and licensing information. ```text Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Copyright Disclaimer Example Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/doc/CDDL-GPL-2-CP.txt A sample copyright disclaimer for a proprietary entity to use when releasing a program, indicating their relinquishment of copyright interest. ```text Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice ``` -------------------------------- ### File Table Structure Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Details the File table, which maps file names to their sector start and size within the game data. It contains 126 entries and is located between bytes 401016 and 402024. ```text File table * 4 bytes: File sector start * 4 bytes: File size (minor differences to the ISO9660 file sizes) ``` -------------------------------- ### Site A Alternate File Table Structure Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Describes the Site A alternate file table, which stores sector start and unknown data for Site A XA files. It has 13 entries and is located between bytes 400216 and 400768. ```text SiteA alt. file table * 4 bytes: Site A XA file sector start * 4 bytes: unknown ``` -------------------------------- ### SYSTEM.CNF File Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Details the SYSTEM.CNF file, which likely contains boot parameters for the executable. It is noted to be identical on both discs except for one byte. ```text SYSTEM.CNF ``` -------------------------------- ### Site A Environment Equivalence Table Structure Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Describes the Site A Environment Equivalence table, containing indices for Site A environment images. It has 10 entries and is located starting at byte 408056. ```text Site A Env Equivalence table * 2 bytes; Site A Env image 0 * 2 bytes; Site A Env image 1 * 2 bytes; Site A Env image 2 ``` -------------------------------- ### Calculating Audio Sector Frequency Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt Illustrates how to determine the interval between audio sectors based on audio sample generation, disc read speed, and desired audio sample rate. ```text 4032 samples per sector * 75 sectors per second / 37800 samples per second = 8 sectors between audio sector ``` -------------------------------- ### Lain Compression Reference Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Mentions the Lain compression method used in various BIN files and provides a reference to a Java implementation for further study. ```text Reference implementation in Lain_Pk.java ``` -------------------------------- ### Site B Environment Equivalence Table Structure Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Describes the Site B Environment Equivalence table, containing indices for Site B environment images. It has 10 entries and is located starting at byte 408116. ```text Site B Env Equivalence table * 2 bytes; Site A Env image 0 * 2 bytes; Site A Env image 1 * 2 bytes; Site A Env image 2 ``` -------------------------------- ### BIN.BIN File Contents Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Describes the contents of the BIN.BIN file, which includes compressed/uncompressed TIM images, the katakana table (replaceable with romaji), the animated lof image, and the credits list. ```text BIN.BIN ``` -------------------------------- ### SLPS_016.03 Executable File Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Identifies SLPS_016.03 as the actual executable program for the game. This file is identical on both discs. ```text SLPS_016.03 ``` -------------------------------- ### RGB Value Clamping Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt This pseudocode demonstrates how to clamp the calculated Red, Green, and Blue values to ensure they stay within the valid 0 to 255 range. ```pseudocode If Red > 255 Then Red = 255 Else If Red < 0 Then Red = 0 If Green > 255 Then Green = 255 Else If Green < 0 Then Green = 0 If Blue > 255 Then Blue = 255 Else If Blue < 0 Then Blue = 0 ``` -------------------------------- ### Full Macroblock YCbCr to RGB Conversion with Clamping Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt This pseudocode illustrates the complete process of converting a 16x16 macroblock from YCbCr to RGB, including the application of the conversion equations and clamping. ```pseudocode Define Macroblock_RGB[16, 16] of structure {Red, Green, Blue} For x = 0 to 15 For y = 0 to 15 r = Macroblock_YCbCr[x, y].Y + 1.402 * Macroblock_YCbCr[x, y].Cr g = Macroblock_YCbCr[x, y].Y - 0.3437 * Macroblock_YCbCr[x, y].Cb - 0.7143 * Macroblock_YCbCr[x, y].Cr b = Macroblock_YCbCr[x, y].Y + 1.772 * Macroblock_YCbCr[x, y].Cb Macroblock_RGB[x, y].Red = Max( Min(r, 255), 0) Macroblock_RGB[x, y].Green = Max( Min(g, 255), 0) Macroblock_RGB[x, y].Blue = Max( Min(b, 255), 0) Next Next ``` -------------------------------- ### Extracting Quantization Scale and DC Coefficient Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt Shows how to extract the Quantization Scale and DC Coefficient from the first 16 bits of MDEC data. ```pseudocode Quantization_Scale = (First_16_Bits() >> 10) DC_Coefficient = (First_16_Bits() & 0x3FF) ``` -------------------------------- ### Calculating Sectors Per Frame Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt Demonstrates how to calculate the number of disc sectors required for each video frame based on the game's frame rate and the PlayStation's disc read speed. ```text 75 sectors per second / 15 frames per second = 5 sectors per frame ``` -------------------------------- ### MDEC Macro-Block Decoding Steps Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt Outlines the six steps involved in decoding a macro-block to a 16x16 RGB pixel square using MDEC emulation, similar to MPEG1 I-frame decoding. ```text For each block (Cr, Cb, Y1, Y2, Y3, Y4): 1) Expand the 16-bit MDEC codes into a 64 value list. 2) Wind the list into an 8x8 matrix of values using the normal MPEG1/JPEG zig-zag order. 3) De-quantize the values using the PSX specific quantization table and the macro-block's quantization scale. 4) Perform the complicated inverse discrete cosine transform on the 8x8 matrix. 5) Once that has been done for all 6 blocks, then merge the Cr and Cb values together with the Y1, Y2, Y3, Y4 values. 6) Convert every YCbCr pixel into an RGB pixel. ``` -------------------------------- ### BIN.BIN Table Structure Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Details the structure of the BIN.BIN table, which contains sector offsets and sizes for various compressed and uncompressed images (TIM files). ```text BIN.BIN table * 4 bytes: Sector offset * 4 bytes: size ``` -------------------------------- ### Constructor Validation in Identified Sector Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/jPSXdec-design.md Demonstrates the constructor pattern for validating identified sectors, propagating probability from superclasses to subclasses. Used within the `IIdentifiedSector` implementation. ```java super(cdSector); if (isSuperInvalidElseReset()) return; setProbability(100); ``` -------------------------------- ### SITEB Image Index Table Structure Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Describes the structure of the SITEB image index table, similar to SITEA but with approximately 558 entries. It provides offsets and sizes for images. ```text SITEB image index table * 4 bytes; Offset to the image (in sectors) * 4 bytes; Size of the data ``` -------------------------------- ### Pseudocode for Decoding Version 3 DC Coefficient (Chroma) Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt This pseudocode illustrates the logic for decoding DC Coefficients for Cr or Cb in version 3 frames. It handles variable length codes, differential values, and updates the previous DC coefficient. Initialize Previous_DC_Coefficient to 0 before processing the first block. ```pseudocode /* At the start of the frame, initialize */ Previous_DC_Coefficient = 0 If Peek_Next_Bits() == "11111110" Skip_Bits(8) If Read_Bits(1) = "0" Then DC_Coefficient = Read_UnsignedBits(7) - 255 Else DC_Coefficient = Read_UnsignedBits(7) + 128 End If Else If Peek_Next_Bits() == "1111110" Skip_Bits(7) If Read_Bits(1) = "0" Then DC_Coefficient = Read_UnsignedBits(6) - 127 Else DC_Coefficient = Read_UnsignedBits(6) + 64 End If Else If Peek_Next_Bits() == "111110" Skip_Bits(6) If Read_Bits(1) = "0" Then DC_Coefficient = Read_UnsignedBits(5) - 63 Else DC_Coefficient = Read_UnsignedBits(5) + 32 End If /* ...and so on... */ Else If Peek_Next_Bits() == "01" Skip_Bits(2) If Read_Bits(1) = "0" Then DC_Coefficient = -1 Else DC_Coefficient = 1 End If Else If Peek_Next_Bits() == "00" Skip_Bits(2) DC_Coefficient = 0 End If DC_Coefficient *= 4 /* Shift the precision up to 10-bits */ /* If Cr, use previous Cr. If Cb, use previous Cb */ DC_Coefficient += Previous_DC_Coefficient Previous_DC_Coefficient = DC_Coefficient ``` -------------------------------- ### LAIN_1.INF & LAIN_2.INF File Contents Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Identifies LAIN_1.INF and LAIN_2.INF as small ASCII files containing disc identification text: 'LAIN SITE A DISC' and 'LAIN SITE B DISC'. ```text LAIN_1.INF & LAIN_2.INF ``` -------------------------------- ### SITEA Image Index Table Structure Source: https://github.com/m35/jpsxdec/blob/readme/laintools/LainModding.txt Describes the structure of the SITEA image index table, used for locating images within the game data. It contains offsets and sizes for approximately 790 entries. ```text SITEA image index table * 4 bytes; Offset to the image (in sectors) * 4 bytes; Size of the data ``` -------------------------------- ### PlayStation 1 Dequantization Matrix Calculation Source: https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt This pseudocode outlines the process of dequantizing matrix elements using the PSX quantization table and a quantization scale. It handles the DC coefficient separately from other elements. ```pseudocode Define Dequantized_Matrix[8, 8] For x = 0 to 7 For y = 0 to 7 If x == 0 And y == 0 Then /* The DC coefficient is not multiplied by the quantization scale */ Dequantized_Matrix[x, y] = Coefficient_Matrix[x, y] * PSX_QUANTIZATION_TABLE[x, y] Else Dequantized_Matrix[x, y] = 2 * Coefficient_Matrix[x, y] * Quantization_Scale * PSX_QUANTIZATION_TABLE[x, y] / 16 End If Next Next ```