C:/DevKitPro/!MDuel/source/macros.h

Go to the documentation of this file.
00001 /*
00002  * Marshmallow Duel DS v2
00003  * Copyright © 2007 Sam Pospischil http://pospi.spadgos.com
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  */
00019 
00020 // started off as some simple macros, has sortof turned into my definitions file now.
00021 
00022 //#ifndef __MDDEBUG             //debug mode - attempt log output (slow!)
00023 //#define __MDDEBUG
00024 //#endif
00025 
00026 #ifndef __WITHSOUND             //enable or disable sound easily
00027 #define __WITHSOUND
00028         //#ifndef __WITHMENUTRACK       //<-- i took this out cos it roughly doubled the rom size
00029         //#define __WITHMENUTRACK
00030         //#endif
00031 #endif
00032 
00033 #ifndef __WITHSAVING    //enable or disable SRAM support
00034 #define __WITHSAVING
00035 #endif
00036 
00038 #define OFFX -50
00040 #define OFFY -256
00041 
00042 #ifdef __MDDEBUG
00044         #define LOGPOS 1
00046         #define ERRORPOS 4
00048         #define ERRTEXT "ERR"
00049 #endif
00050 
00051 #ifndef _MDUELMACROS_
00052 #define _MDUELMACROS_
00053 
00054 #include <PA9.h>
00055 #include <string>
00056 using namespace std;
00057 
00058 #ifdef __MDDEBUG
00059         #include <fstream>
00060         #include <fat.h>
00061         #define LOGFILE "mduelLog.txt"
00062 #endif
00063 
00071 namespace macros
00072 {
00073                 #ifdef __MDDEBUG
00074 
00084                 inline string debugMessage(string className, string outText, u8 yPos = LOGPOS)
00085                 {
00086                         string ret = className+string(": ")+outText+string(" \n");
00087                         
00088                         if (yPos == LOGPOS)
00089                         {
00090                                 FILE* logFile = fopen(LOGFILE, "a+");
00091                                 if (logFile)    //this probably only works for supported flashcarts, so just draw onscreen if failed.
00092                                         fprintf(logFile, ret.c_str());
00093                                 else
00094                                         PA_OutputText(0, 0, 0, const_cast<char *>(ret.c_str()));
00095                                 fclose(logFile);
00096                         } else {
00097                                 PA_OutputText(0, 0, yPos, const_cast<char *>(ret.c_str()));
00098                                 //pause for critical errors to be read
00099                                 if (className == ERRTEXT && yPos == ERRORPOS)
00100                                         PA_WaitFor(Stylus.Newpress);
00101                         } 
00102                                 
00103                         return ret;
00104                 }
00105                 #endif
00106                 
00114                 inline string getPlayerName(u8 playerNum, string playerNames, bool leftPadding = true)
00115                 {
00116                         playerNum -= 1; //1 indexed players
00117                         string ret;
00118                         for (u8 i=playerNum*8; i < (playerNum+1)*8; ++i)
00119                                 ret += playerNames[i];
00120                         
00121                         if (leftPadding)
00122                         {
00123                                 if (playerNum >= 4)     //need left padding
00124                                 {
00125                                         while (ret.at(ret.length()-1) == ' ')
00126                                         {
00127                                                 for (s8 i=ret.length()-2; i>=0; i--)
00128                                                         ret.at(i+1) = ret.at(i);
00129                                                 ret.at(0) = ' ';
00130                                         }
00131                                 }
00132                         }
00133                         return ret;
00134                 }
00135 };
00136 
00137 #endif

Generated on Tue Mar 13 23:27:52 2007 for MDuel DS by  doxygen 1.5.1-p1