sps2wrap.h

00001 /*
00002 * "PS2" Application Framework
00003 *
00004 * University of Abertay Dundee
00005 * May be used for educational purposed only
00006 *
00007 * Author - Dr Henry S Fortuna
00008 *
00009 * $Revision: 1.2 $
00010 * $Date: 2007/08/19 12:45:12 $
00011 *
00012 */
00013 
00014 #ifndef __SPS2WRAP_H__
00015 #define __SPS2WRAP_H__
00016 
00017 #include <sps2lib.h>
00018 #include <sps2util.h>
00019 #include <sps2tags.h>
00020 #include "singleton.h"
00021 
00022 #define IMAGE_RGBA      (0)
00023 #define IMAGE_RGB       (1)
00024 
00025 // This define allows us to treat SPS2Manager as a global
00026 // instance of the CSPS2Manager class, that's all you need
00027 // to know to use it!
00028 #define SPS2Manager CSPS2Manager::GetSingleton()
00029 
00030 class CDMAMem;
00031 
00032 class CSPS2Manager : public CSingleton<CSPS2Manager>
00033 {
00034         public:
00035                 CSPS2Manager();
00036                 ~CSPS2Manager();
00037 
00038                 // Call this function at the start of your program.
00039                 // It allocates as many pages of SPS2 memory as you
00040                 // want. 512 pages, i.e. 20MB is about the most you
00041                 // can safely allocate.
00042                 void Initialise(const int iAllocPages);
00043 
00044                 // Call this once, after Initialise to set the colour
00045                 // that the screen should be cleared to (note, you have
00046                 // to call this, even if you don't care what colour the
00047                 // screen is cleared to)
00048                 void InitScreenClear(int R, int G, int B);
00049 
00050                 // Call these before, and after, you do any rendering.
00051                 void BeginScene();
00052                 void EndScene();
00053 
00054                 // This function will put iQuadWords amount of SPS2 memory
00055                 // into the Memory structure. (Note, 256 QWords is the maximum
00056                 // amount that a CDMAMem structure can hold)
00057                 void Allocate(CDMAMem & Memory, int iQuadWords);
00058 
00059                 // Calls sps2FlushCache
00060                 void FlushCache();
00061 
00062                 int GetScreenWidth()
00063                 { return sps2UScreenGetWidth(); }
00064 
00065                 int GetScreenHeight()
00066                 { return sps2UScreenGetHeight(); }
00067                 
00068                 // This function takes a screen shot and saves it to a TGA file
00069                 void ScreenShot(const int ImageType = 1);
00070                 
00071         private:
00072                 int m_iSPS2Desc;
00073 
00074                 // The memory that is allocated by Initialise( )
00075                 sps2Memory_t * m_pMemCached, 
00076                                          * m_pMemUncached;
00077                 
00078                 // Keep an array with the memory remaining in each page
00079                 int * m_iaFreeMemInPage;
00080                 // How many pages worth of memory did we allocate?
00081                 int m_iNumPages;
00082                 
00083                 // Screen Shot variables
00084                 int m_SS_Number;
00085                 
00086                 // Screen shot functions
00087                 // Check if a file exists - used to get a free filename for the screen shot
00088                 int FileExists(const char * const FileName);
00089                 // Download part of the frame buffer to main memory
00090                 void DownloadVram(CDMAMem & DMAChainMem, CDMAMem & SShotMem, int addr, int bufw, int x, int y, int w, int h);
00091 
00092 };
00093 
00094 // Call this once you have finished drawing.
00095 inline void CSPS2Manager::EndScene()
00096 {
00097         while(*EE_D1_CHCR & 256);
00098         sps2UScreenSwap();
00099 }
00100 
00101 // Flushes all data through SPS2 to make sure it is written to memory before
00102 // it is fired off to the DMAC.
00103 inline void CSPS2Manager::FlushCache()
00104 {
00105         sps2FlushCache(m_iSPS2Desc);
00106 }
00107 
00108 // A simple structure to look after a memory page (4096k, 256 quadwords)
00109 class CDMAMem
00110 {
00111         public:
00112                 // Construtor (no parameters)
00113                 CDMAMem()
00114                 :m_iAmount(0), m_pCached(NULL), 
00115                  m_pUncached(NULL), m_iPhysAddr(0)
00116                         {};
00117                 ~CDMAMem(){};
00118 
00119                 // Constructor, specifying how many quad words to
00120                 // use (must be less than or equal to 256).
00121                 CDMAMem(int iQWC)
00122                 :m_iAmount(0), m_pCached(NULL), 
00123                  m_pUncached(NULL), m_iPhysAddr(0)
00124                 {
00125                         assert(256 >= iQWC);
00126                         SPS2Manager.Allocate(*this, iQWC);
00127                 }
00128 
00129                 // Set all of the member variables.
00130                 void Set(int Amount, void * pCached, void * pUncached, int PhysAddr)
00131                 {
00132                         m_iAmount = Amount;
00133                         m_pCached = pCached;
00134                         m_pUncached = pUncached;
00135                         m_iPhysAddr = PhysAddr;
00136                 }
00137 
00138                 // Get the cached pointer to this memory block.
00139                 void * GetCached()
00140                 { return m_pCached; }
00141 
00142                 // Get the uncached pointer to this memory block.
00143                 void * GetUncached()
00144                 { return m_pUncached; }
00145 
00146                 // Get the physical address of this memory block.
00147                 int GetPhysicalAddr()
00148                 { return m_iPhysAddr; }
00149                 
00150                 // Get the size of this memory block.
00151                 int GetSize()
00152                 { return m_iAmount; }
00153                 
00154         protected:
00155                 int m_iAmount;          // Number of quadwords in this block.
00156                 void * m_pCached,       // Cached pointer to the start of this block.
00157                      * m_pUncached;     // Uncached pointer to the start of this block.
00158                 int m_iPhysAddr;        // Physical address of this start of this block.
00159 };
00160 
00161 #endif

Generated on Sun May 18 21:45:09 2008 for PS2X by  doxygen 1.5.4