PSVRender v1.50
This
document assumes you have a decent
working
knowledge of programming in a .NET language (and uses C# notation).
It also assumes you have moderate experience in ROM hacking.
PSVRender contains helper
classes related to ROM hacking. Any
members or methods not covered here are for internal use.
Much of
this code was obtained and modified from publicly available source code
and algorithms (that I have
long since forgotten).
CompressionDataVar Class
The CompressionDataVar class implements
compression/decompression routines from Chrono Trigger and Final
Fantasy VI.
- Members
- nCompressedSize
(uint) - Reports the compressed data's size.
- nDecompressedSize
(uint) - When decompressing, reports the decompressed data's size.
When compressing, this value must be set to the size of the
data to be compressed.
- nDecRoutine
(CompressionRoutines) - Specifies the compression routine to use.
See CompressionRoutines Enum.
- SrcBuffer
(byte[]) - Source (or input) data's buffer.
- nSrcOff
(uint) - Source data's starting offset (default: 0).
- WorkingBuffer
(byte[]) - Working (or output) data's buffer.
- nWorkOff
(uint) - Work data's starting offset (default: 0).
- Methods
- void
DecompressData() - Decompress data in SrcBuffer
to WorkingBuffer using routine nDecRoutine.
- void
CompressData() - Compress data in SrcBuffer to
WorkingBuffer using routine nDecRoutine.
CompressionRoutines Enum
CompressionRoutines contains the values
for the different compression routines used by CompressionDataVar.
- eChronoTrigger
- Chrono Trigger's primary compression routine
- eChronoTriggerRunLength
- Chrono Trigger's run-length compression. This is only used
for a portion of the location maps.
- eFinalFantasyVI
- Final Fantasy VI's primary compression routine
GetSnesPaletteVar Class
The GetSnesPaletteVar class will make
palettes from SNES byte data.
- Members
- nNumPalettes
(byte) - The number of palettes that should be read from the data
(default: 1).
- nPaletteColors
(ushort) - The number of colors in the original palette (default: 16).
IOW, this is the number of colors stored in the original byte
data.
- nPaletteShift
(ushort) - The number of colors that should be skipped when converting
the original palette (default: 0). Usually, nPaletteShift +
nPaletteColors = nPaletteSize.
- nPaletteSize
(ushort) - The number of colors in the converted palette (default: 16).
- nSnesPalette
(byte[]) - The original palette byte data from the ROM.
- nSnesStartIndex
(uint) - The original palette's starting byte offset (default: 0).
- WorkingPalette
(Color[]) - The converted palette data, in standard 32 bit color.
- nWorkStartIndex
(uint) - The converted palette's starting color index (default: 0).
- Methods
- void
GetSnesPalette() - Once all the members are set, calling
this function will convert the original byte data to 32 bit ARGB color.
PixelRenderMode Enum
PixelRenderMode's values determine how
PutSubtileVar's WorkingImage should be mixed with its SubImage.
- eAdditive
- SubImage's pixels should be added to WorkingImage's.
- eOverwrite - SubImage's
pixels should be overwritten by WorkingImage's.
- eSubtractive - SubImage's pixels should be subtracted from WorkingImage's.
PSV Class
Provides a static function to get a grey
color palette. Useful for image information that doesn't have
an associated palette.
- Methods
- void
GetGreyPalette(ref Color[] WorkingPalette, ushort nColors)
- Gets a grey palette to WorkingPalette, with nColors shades of grey.
PutSubtileVar Class
The PutSubtileVar class is designed to
draw subtiles in a number of formats.
- Members
- dx
(int) - Subtile's x coordinate in the image.
- dy
(int) - Subtile's y coordinate in the image.
- nBitPlanes
(BitPlanes) - Subtile's
format (default: eTetraPlane). There are a number of documents publicly
available that describe tile formats, so it will not be discussed here.
- nDecodingStart
(uint) - The starting offset of the subtile's original byte data in
WorkingBuffer.
- bDimmed
(byte) - True (1)
if this subtile should be drawn at half color intensity (default: false
(0)). This was originally used to draw the scrolling mask on
the
Location maps, but has since been replaced by a set of transparent
rectangles drawn on top of the image.
- nFlip
(byte) - Subtile
flipping options. Set bit 01 to flip horizontally.
Set bit 02 to flip
vertically. The FlipDir enum can also be used to set these
values.
- bHalfColorRender
(bool) - True
if the subtile's pixels should be down-mixed with half the color
of
nSubImage's pixels for the same area (default: false). This
is how the
SNES achieves its transparency effects.
- nPaletteShift
(byte) - Subtile's starting palette index (default: 0). Useful
when drawing maps, which use several palettes.
- PRMode
(PixelRenderMode) - Determines how the subtile's pixels should mix with
nSubImage's pixels. See PixelRenderMode Enum.
- SubImage
(Bitmap) - Not currently used, because GDIplus' implementation of
pixel-to-pixel copying is far too slow.
- nSubImage
(byte*) - Subimage pixel data used to achieve transparency effects.
See also bHalfColorRender and PRMode.
- bSwapRB (bool)
- True if this subtile's red and blue channels should be swapped (default:
false). Only applies to RGB formats.
- WorkingBuffer
(byte[]) - The original byte data containing the subtile's pixel
information.
- WorkingImage
(Bitmap) - The output image.
- nWorkingImage
(byte*) - The output image's raw data, underlying WorkingImage's Bitmap.
- WorkingPalette
(Color[]) - Palette to use when drawing the subtile.
- Methods
- void PutSubtile() - After setting the member variables, calling this function will draw a subtile.
- void ProcessSpriteData() -
After setting the member variables, calling this function will draw a
series of contiguous subtiles until the full dimensions of the image
are reached. This is used by Temporal Flux to draw the tile swatches.
Maps or sprites will typically not be able to make use of this
function.
- void ClearArea(ushort nTop, ushort nBottom, ushort nLeft, ushort nRight) - Sets the passed in rectangle pixel coordinates to black with 100% transparency.
- ushort
GetShort(byte[] nSrc, uint nOffset) - Returns a ushort
from the data nSrc at offset nOffset. (All variants of this function
work the same.)
- string
HexStr(int nVal, int nPad) - Returns a hex string of the
value nVal padded to nPad digits. (All variants of this function work
the same.)
- string
HexStr(ushort nVal) - Returns a hex string of the value
nVal, padded to four digits.
- string
HexStr(byte nVal) - Returns a hex string of the value
nVal, padded to two digits.
- void
SetInt24(byte[] nDest, uint nOffset, uint nVal) - Set an
unsigned 24 bit integer in th data nDest at offset nOffset to value
nVal.
- void
SetShort(byte[] nDest, uint nOffset, ushort nVal) - Set a
ushort in the data nDest at offset nOffset to value nVal.
(All variants of this function work the same.)
SNES Class
The SNES class contains a number
of static helper methods. This class is inherited by
GlobalShared in the TFPA.
- Methods
- uint
GetFileOffset(uint nSnesAddr) - Get the file offset
directly from the passed in value. (Careful which type you pass in.)
- uint
GetInt24(byte[] nSrc, uint nOffset) - Get an unsigned 24
bit integer from the data nSrc at offset nOffset.
- uint
GetSnesAddr(uint nFileOffset) - Get the SNES address
equivalent of a file offset.
- ushort
GetShort(byte[] nSrc, uint nOffset) - Returns a ushort
from the data nSrc at offset nOffset. (All variants of this function
work the same.)
- string
HexStr(int nVal, int nPad) - Returns a hex string of the
value nVal padded to nPad digits. (All variants of this function work
the same.)
- string
HexStr(ushort nVal) - Returns a hex string of the value
nVal, padded to four digits.
- string
HexStr(byte nVal) - Returns a hex string of the value
nVal, padded to two digits.
- void
SetInt24(byte[] nDest, uint nOffset, uint nVal) - Set an
unsigned 24 bit integer in th data nDest at offset nOffset to value
nVal.
- void
SetShort(byte[] nDest, uint nOffset, ushort nVal) - Set a
ushort in the data nDest at offset nOffset to value nVal.
(All variants of this function work the same.)
Waveform Class
The Waveform class can decode SNES BRR samples and write them out as standard waveform files.
- Methods
- void DecodeBRR(byte[] nRawData, uint nOffset) - Decode SNES BRR data from nRawData starting at offset nOffset.
- void SetDataSize(uint nSize) - Set the size of the waveform's data. Not necessary when decoding standard BRR files.
- void SetSampleRate(uint nSampleRate) - Set the waveform's sample rate in Hz (default: 8000).
- void WriteOutWaveform(string sFilename) - Write the waveform to file sFilename.