PS2 Linux Programming
SPS2 Wrapper Class
Introduction
This tutorial will introduce a simple SPS2 wrapper
class which will encapsulate some of the basic memory management operations
that are required when using SPS2. The functionality of the wrapper class is
minimal at this stage but can easily be extended to facilitate other operations
and functions as they arise.
When using SPS2 it is necessary to allocate
unmovable physical memory which can be used by the DMAC. At this stage in the
tutorial series memory needs to be allocated for primitive data, textures, font
textures and DMA chain sequences. The maximum size of a texture being used is
256 kBytes (256 x 256 x 32 bits) so the allocated memory has been divided up
into blocks of size 256k. The memory map for the allocated memory is given in
the table below.
Block 10 (256k) DMA Chains |
Block 9 (256k) FontTex |
Block 8 (256k) Tex1 |
Block 7 (256k) Tex2 |
Block 6 (256k) Tex3 |
Block 5 (256k) Tex4 |
Block 4 (256k) Prim4 |
Block 3 (256k) Prim3 |
Block 2 (256k) Prim2 |
Block 1 (256k) Prim1 |
Blocks 1 to 4 are used to hold primitive data,
blocks 5 to 8 are used to hold textures, block 9 is used to hold a font texture
and block 10 is used to hold the DMA chains which will be built to send textures
to GS memory.
The structure of block 10 is expanded in the table
below.
(128k) FontDMA |
(4k) Tex1DMA |
(4k) Tex2DMA |
(4k) Tex3DMA |
(4k) Tex4DMA |
(112k) Free |
The most important method of the wrapper class is Initialise(const
int iAllocPages) which takes as a parameter the number of 4k pages of SPS2
memory that are to be allocated. In order to accommodate the memory map which
is presented in the tables above, a total of 10 x 256 kBytes (2.56 MB) of
memory is needed, this being 640 x 4 kB pages. 640 pages is therefore the
minimum amount of memory that can be allocated, but this can be increased to accommodate
additional features when required.
Once this memory has been allocated, pointers to
each of the allocated memory blocks are assigned and these pointers can be
extracted from the class using accessor functions. The SPS2 kernel module
handle and the pointer to the memory structure (sps2Memory_t) are also
contained within the class.
In addition to the above, there are some basic
management wrapper functions to facilitate the operation of some of the common
operations such as beginning and ending a scene (BeginScene(), EndScene()), flushing
the cache (FlushCache()) and waiting for a DMA transfer to end (WaitForDMA()).
The operation of these and the other wrapper functions can be seen from the
code and should be fairly self explanatory.
The wrapper class is contained within the files sps2wrap.cpp
and sps2wrap.h. An illustration of using the wrapper class is given in the
accompanying code example. The example is a rewrite of the tutorial “Using the
DMAC”.
A simple but expandable wrapper class has been introduced
to manage some of the main features and operations which are necessary when
using SPS2 on the PS2. This wrapper class will be used in future tutorials.
Dr Henry S Fortuna
University of Abertay
Dundee