00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Fred Klaus * 00003 * frednet@web.de * 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 * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 #ifndef CPCMU_TYPES_H 00021 #define CPCMU_TYPES_H 00022 00023 #include <stdint.h> 00024 //enum Bits {Bit0=1, Bit1=2, Bit2=4, Bit3=8, Bit4=16, Bit5=32, Bit6=64, Bit7=128}; 00025 00026 00027 #define CPC_SCR_WIDTH 1024 // max width 00028 #define CPC_SCR_HEIGHT 312 // max height 00029 #define CPC_VISIBLE_SCR_WIDTH 384 // visible width : 4+40+4 * 8 00030 #define CPC_VISIBLE_SCR_HEIGHT 272 // visible height: 5+25+4 * 8 @todo original is 272 00031 00032 00033 // ************** 00034 // *** signed *** 00035 // ************** 00036 #ifndef BYTE 00037 typedef int8_t BYTE; 00038 #else 00039 #warning "*** BYTE is already defined and may not match requested size. ***" 00040 #endif 00041 00042 #ifndef WORD 00043 typedef int16_t WORD; 00044 #else 00045 #warning "*** WORD is already defined and may not match requested size. ***" 00046 #endif 00047 00048 #ifndef DWORD 00049 typedef int32_t DWORD; 00050 #else 00051 #warning "*** DWORD is already defined and may not match requested size. ***" 00052 #endif 00053 00054 #ifndef QWORD 00055 typedef int64_t QWORD; 00056 #else 00057 #warning "*** QWORD is already defined and may not match requested size. ***" 00058 #endif 00059 00060 #ifndef INT64 00061 typedef int64_t INT64; 00062 #else 00063 #warning "*** INT64 is already defined and may not match requested size. ***" 00064 #endif 00065 00066 00067 // **************** 00068 // *** unsigned *** 00069 // **************** 00070 #ifndef BYTE 00071 typedef uint8_t UBYTE; 00072 #else 00073 #warning "*** UBYTE is already defined and may not match requested size. ***" 00074 #endif 00075 00076 #ifndef WORD 00077 typedef uint16_t UWORD; 00078 #else 00079 #warning "*** UWORD is already defined and may not match requested size. ***" 00080 #endif 00081 00082 #ifndef DWORD 00083 typedef uint32_t UDWORD; 00084 #else 00085 #warning "*** UDWORD is already defined and may not match requested size. ***" 00086 #endif 00087 00088 #ifndef QWORD 00089 typedef uint64_t UQWORD; 00090 #else 00091 #warning "*** UQWORD is already defined and may not match requested size. ***" 00092 #endif 00093 00094 #ifndef INT64 00095 typedef uint64_t UINT64; 00096 #else 00097 #warning "*** UINT64 is already defined and may not match requested size. ***" 00098 #endif 00099 00100 00101 #ifndef REGPAIR 00102 typedef union 00103 { 00104 #if SDL_BYTEORDER == SDL_LIL_ENDIAN 00105 struct { UBYTE l, h, h2, h3; } b; 00106 struct { UWORD l, h; } w; 00107 #else 00108 struct { UBYTE h3, h2, h, l; } b; 00109 struct { UWORD h, l; } w; 00110 #endif 00111 DWORD d; 00112 } REGPAIR; 00113 #else 00114 #warning "*** REGPAIR is already defined and may not match requested size. ***" 00115 #endif 00116 00117 #ifndef uint 00118 typedef unsigned int uint; 00119 #else 00120 #warning "*** WORD is already defined and may not match requested size. ***" 00121 #endif 00122 00123 00124 //@todo Should this be here ?? 00125 static UBYTE bit_values[8] = 00126 { 00127 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 00128 }; 00129 00130 00131 00132 /* 00133 class WORD 00134 { 00135 public: 00136 WORD() {} 00137 ~WORD() {} 00138 00139 operator short int() {return mValue.Both;} 00140 WORD & operator=(const short int & w) 00141 {mValue.Both=w; return *this;} 00142 WORD & operator--() 00143 {mValue.Both--; return *this;} 00144 00145 BYTE low() {return mValue.Low;} 00146 BYTE high() {return mValue.High;} 00147 00148 void setLow (BYTE w) {mValue.Low = w;} 00149 void setHigh(BYTE w) {mValue.High = w;} 00150 00151 private: 00152 typedef union 00153 { 00154 struct 00155 { 00156 BYTE Low; 00157 BYTE High; 00158 }; 00159 short int Both; 00160 } WORD_t; 00161 00162 WORD_t mValue; 00163 }; 00164 00165 class UWORD 00166 { 00167 public: 00168 UWORD() {} 00169 UWORD(unsigned short int v) {mValue.Both=v;} 00170 ~UWORD() {} 00171 00172 operator unsigned short int() {return mValue.Both;} 00173 operator uint() {return (uint) mValue.Both;} 00174 operator int() {return (int) mValue.Both;} 00175 operator bool() {return (bool) mValue.Both;} 00176 00177 //UWORD operator+ (const UWORD & w) 00178 // {return UWORD(mValue.Both + w.both());} 00179 00180 UWORD operator-(const int & w) 00181 {return UWORD(mValue.Both - (unsigned short int) w);} 00182 00183 UWORD operator+(const int & w) 00184 {return UWORD(mValue.Both + (unsigned short int) w);} 00185 00186 UWORD operator*(const int & w) 00187 {return UWORD(mValue.Both * (unsigned short int) w);} 00188 00189 UWORD* operator&(UWORD & w) 00190 {return w.ptr();} 00191 00192 UWORD & operator=(const unsigned short int & w) 00193 {mValue.Both=w; return *this;} 00194 00195 UWORD & operator-=(const unsigned short int & w) 00196 {mValue.Both-=w; return *this;} 00197 00198 UWORD & operator+=(const unsigned short int & w) 00199 {mValue.Both+=w; return *this;} 00200 00201 bool operator<(const UWORD & v) const 00202 {return (bool) (mValue.Both < v.both());} 00203 bool operator<=(const UWORD & v) const 00204 {return (bool) (mValue.Both <= v.both());} 00205 bool operator>(const UWORD & v) const 00206 {return (bool) (mValue.Both > v.both());} 00207 bool operator>=(const UWORD & v) const 00208 {return (bool) (mValue.Both >= v.both());} 00209 bool operator==(const UWORD & v) const 00210 {return (bool) (mValue.Both == v.both());} 00211 bool operator!=(const UWORD & v) const 00212 {return (bool) (mValue.Both != v.both());} 00213 00214 */ 00215 00216 /* 00217 bool operator<(const unsigned short int & v) const 00218 {return (bool) (mValue.Both < v);} 00219 bool operator<=(const unsigned short int & v) const 00220 {return (bool) (mValue.Both <= v);} 00221 bool operator>(const unsigned short int & v) const 00222 {return (bool) (mValue.Both > v);} 00223 bool operator>=(const unsigned short int & v) const 00224 {return (bool) (mValue.Both >= v);} 00225 bool operator==(const unsigned short int & v) const 00226 {return (bool) (mValue.Both == v);} 00227 bool operator!=(const unsigned short int & v) const 00228 {return (bool) (mValue.Both != v);} 00229 */ 00230 00231 /* 00232 UWORD & operator--() 00233 {--mValue.Both; return *this;} 00234 00235 UWORD operator--(int) 00236 {UWORD tmp(*this);--mValue.Both; return tmp;} 00237 00238 UWORD & operator++() 00239 {++mValue.Both; return *this;} 00240 00241 UWORD operator++(int) 00242 {UWORD tmp(*this);++mValue.Both; return tmp;} 00243 00244 00245 UBYTE low() {return mValue.Low;} 00246 UBYTE high() {return mValue.High;} 00247 00248 const unsigned short int both() const {return mValue.Both;} 00249 00250 void setLow (UBYTE w) {mValue.Low = w;} 00251 void setHigh(UBYTE w) {mValue.High = w;} 00252 00253 UWORD* ptr() {return this;} 00254 00255 private: 00256 typedef union 00257 { 00258 struct 00259 { 00260 UBYTE Low; 00261 UBYTE High; 00262 }; 00263 unsigned short int Both; 00264 } UWORD_t; 00265 00266 UWORD_t mValue; 00267 }; 00268 */ 00269 00270 #endif // CPCMU_TYPES_H 00271