1 /** EMULib Emulation Library *********************************/ 2 /** **/ 3 /** EMULib.h **/ 4 /** **/ 5 /** This file contains platform-independent definitions and **/ 6 /** declarations for the emulation library. **/ 7 /** **/ 8 /** Copyright (C) Marat Fayzullin 1996-2009 **/ 9 /** You are not allowed to distribute this software **/ 10 /** commercially. Please, notify me, if you make any **/ 11 /** changes to this file. **/ 12 /*************************************************************/ 13 #ifndef EMULIB_H 14 #define EMULIB_H 15 16 #ifdef WINDOWS 17 #include "LibWin.h" 18 #endif 19 #ifdef MSDOS 20 #include "LibMSDOS.h" 21 #endif 22 #ifdef UNIX 23 #include "LibUnix.h" 24 #endif 25 #ifdef MAEMO 26 #include "LibMaemo.h" 27 #endif 28 #ifdef NXC2600 29 #include "LibNXC2600.h" 30 #endif 31 #ifdef STMP3700 32 #include "LibSTMP3700.h" 33 #endif 34 #if defined(S60) || defined(UIQ) 35 #include "LibSym.h" 36 #include "LibSym.rh" 37 #endif 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /** ARMScaleImage() Attributes *******************************/ 44 /** These values can be ORed and passed to ARMScaleImage(). **/ 45 /*************************************************************/ 46 #define ARMSI_VFILL 0x01 47 #define ARMSI_HFILL 0x02 48 49 /** Button Bits **********************************************/ 50 /** Bits returned by GetJoystick() and WaitJoystick(). **/ 51 /*************************************************************/ 52 #define BTN_LEFT 0x0001 53 #define BTN_RIGHT 0x0002 54 #define BTN_UP 0x0004 55 #define BTN_DOWN 0x0008 56 #define BTN_FIREA 0x0010 57 #define BTN_FIREB 0x0020 58 #define BTN_FIREL 0x0040 59 #define BTN_FIRER 0x0080 60 #define BTN_START 0x0100 61 #define BTN_SELECT 0x0200 62 #define BTN_EXIT 0x0400 63 #define BTN_FIREX 0x0800 64 #define BTN_FIREY 0x1000 65 #define BTN_ALL 0x1FFF 66 #define BTN_OK (BTN_FIREA|BTN_START) 67 #define BTN_FIRE (BTN_FIREA|BTN_FIREB|BTN_FIREL|BTN_FIRER|BTN_FIREX|BTN_FIREY) 68 #define BTN_SHIFT CON_SHIFT 69 #define BTN_CONTROL CON_CONTROL 70 #define BTN_ALT CON_ALT 71 #define BTN_MODES (BTN_SHIFT|BTN_CONTROL|BTN_ALT) 72 73 /** Special Key Codes ****************************************/ 74 /** Modifiers returned by GetKey() and WaitKey(). **/ 75 /*************************************************************/ 76 #define CON_KEYCODE 0x00FFFFFF /* Key code */ 77 #define CON_MODES 0xFF000000 /* Mode bits, as follows: */ 78 #define CON_CLICK 0x04000000 /* Key click (LiteS60 only) */ 79 #define CON_CAPS 0x08000000 /* CapsLock held */ 80 #define CON_SHIFT 0x10000000 /* SHIFT held */ 81 #define CON_CONTROL 0x20000000 /* CONTROL held */ 82 #define CON_ALT 0x40000000 /* ALT held */ 83 #define CON_RELEASE 0x80000000 /* Key released (going up) */ 84 85 #define CON_F1 0xEE 86 #define CON_F2 0xEF 87 #define CON_F3 0xF0 88 #define CON_F4 0xF1 89 #define CON_F5 0xF2 90 #define CON_F6 0xF3 91 #define CON_F7 0xF4 92 #define CON_F8 0xF5 93 #define CON_F9 0xF6 94 #define CON_F10 0xF7 95 #define CON_F11 0xF8 96 #define CON_F12 0xF9 97 #define CON_LEFT 0xFA 98 #define CON_RIGHT 0xFB 99 #define CON_UP 0xFC 100 #define CON_DOWN 0xFD 101 #define CON_OK 0xFE 102 #define CON_EXIT 0xFF 103 104 /** pixel ****************************************************/ 105 /** Pixels may be either 8bit, or 16bit, or 32bit. When no **/ 106 /** BPP* specified, we assume the pixel to have the largest **/ 107 /** size and default to GetColor(). **/ 108 /*************************************************************/ 109 #ifndef PIXEL_TYPE_DEFINED 110 #define PIXEL_TYPE_DEFINED 111 #if defined(BPP32) || defined(BPP24) 112 typedef unsigned int pixel; 113 #elif defined(BPP16) 114 typedef unsigned short pixel; 115 #elif defined(BPP8) 116 typedef unsigned char pixel; 117 #else 118 typedef unsigned int pixel; 119 #define PIXEL(R,G,B) GetColor(R,G,B) 120 #endif 121 #endif 122 123 /** sample ***************************************************/ 124 /** Audio samples may be either 8bit or 16bit. **/ 125 /*************************************************************/ 126 #ifndef SAMPLE_TYPE_DEFINED 127 #define SAMPLE_TYPE_DEFINED 128 #ifdef BPS16 129 typedef signed short sample; 130 #else 131 typedef signed char sample; 132 #endif 133 #endif 134 135 /** Image ****************************************************/ 136 /** This data type encapsulates a bitmap. **/ 137 /*************************************************************/ 138 typedef struct 139 { 140 pixel *Data; /* Buffer containing WxH pixels */ 141 int W,H,L,D; /* Image size, pitch, depth */ 142 char Cropped; /* 1: Cropped, do not free() */ 143 #ifdef WINDOWS 144 HDC hDC; /* Handle to device context */ 145 HBITMAP hBMap; /* Handle to bitmap */ 146 #endif 147 #ifdef MAEMO 148 GdkImage *GImg; /* Pointer to GdkImage object */ 149 #endif 150 #ifdef UNIX 151 XImage *XImg; /* Pointer to XImage structure */ 152 int Attrs; /* USE_SHM and other attributes */ 153 #ifdef MITSHM 154 XShmSegmentInfo SHMInfo; /* Shared memory information */ 155 #endif 156 #endif 157 } Image; 158 159 /** Current Video Image **************************************/ 160 /** These parameters are set with SetVideo() and used by **/ 161 /** ShowVideo() to show a WxH fragment from <X,Y> of Img. **/ 162 /*************************************************************/ 163 extern Image *VideoImg; /* Current ShowVideo() image */ 164 extern int VideoX; /* X for ShowVideo() */ 165 extern int VideoY; /* Y for ShowVideo() */ 166 extern int VideoW; /* Width for ShowVideo() */ 167 extern int VideoH; /* Height for ShowVideo() */ 168 169 /** KeyHandler ***********************************************/ 170 /** This function receives key presses and releases. **/ 171 /*************************************************************/ 172 extern void (*KeyHandler)(unsigned int Key); 173 174 /** MouseHandler *********************************************/ 175 /** This function receives mouse clicks and unclicks. **/ 176 /*************************************************************/ 177 extern void (*MouseHandler)(int X,int Y,int State); 178 179 /** NewImage() ***********************************************/ 180 /** Create a new image of the given size. Returns pointer **/ 181 /** to the image data on success, 0 on failure. **/ 182 /*************************************************************/ 183 pixel *NewImage(Image *Img,int Width,int Height); 184 185 /** FreeImage() **********************************************/ 186 /** Free previously allocated image. **/ 187 /*************************************************************/ 188 void FreeImage(Image *Img); 189 190 /** CropImage() **********************************************/ 191 /** Create a subimage Dst of the image Src. Returns Dst. **/ 192 /*************************************************************/ 193 Image *CropImage(Image *Dst,const Image *Src,int X,int Y,int W,int H); 194 195 #if defined(WINDOWS) || defined(UNIX) || defined(MAEMO) 196 Image *GenericCropImage(Image *Dst,const Image *Src,int X,int Y,int W,int H); 197 #endif 198 199 /** ScaleImage() *********************************************/ 200 /** Copy Src into Dst, scaling as needed. **/ 201 /*************************************************************/ 202 void ScaleImage(Image *Dst,const Image *Src,int X,int Y,int W,int H); 203 204 /** ARMScaleImage() ******************************************/ 205 /** Copy Src into Dst using ARM-optimized assembly code. **/ 206 /** Returns 0 if this function is not supported or there is **/ 207 /** an alignment problem. Returns destination height and **/ 208 /** width on success in <Height 31:16><Width 15:0> format. **/ 209 /*************************************************************/ 210 int ARMScaleImage(Image *Dst,Image *Src,int X,int Y,int W,int H,int Attrs); 211 212 /** TelevizeImage() ******************************************/ 213 /** Create televizion effect on the image. **/ 214 /*************************************************************/ 215 void TelevizeImage(Image *Img,int X,int Y,int W,int H); 216 217 /** SoftenImage() ********************************************/ 218 /** Uses softening algorithm to interpolate image Src into **/ 219 /** a bigger image Dst. **/ 220 /*************************************************************/ 221 void SoftenImage(Image *Dst,const Image *Src,int X,int Y,int W,int H); 222 223 /** ClearImage() *********************************************/ 224 /** Clear image with a given color. **/ 225 /*************************************************************/ 226 void ClearImage(Image *Img,pixel Color); 227 228 /** IMGCopy() ************************************************/ 229 /** Copy one image into another. Skips pixels of given **/ 230 /** color unless TColor=-1. **/ 231 /*************************************************************/ 232 void IMGCopy(Image *Dst,int DX,int DY,const Image *Src,int SX,int SY,int W,int H,int TColor); 233 234 /** IMGDrawRect()/IMGFillRect() ******************************/ 235 /** Draw filled/unfilled rectangle in a given image. **/ 236 /*************************************************************/ 237 void IMGDrawRect(Image *Img,int X,int Y,int W,int H,pixel Color); 238 void IMGFillRect(Image *Img,int X,int Y,int W,int H,pixel Color); 239 240 /** IMGPrint() ***********************************************/ 241 /** Print text in a given image. **/ 242 /*************************************************************/ 243 //@@@ NOT YET 244 //void IMGPrint(Image *Img,const char *S,int X,int Y,int FG,int BG); 245 246 /** SetVideo() ***********************************************/ 247 /** Set part of the image as "active" for display. **/ 248 /*************************************************************/ 249 void SetVideo(Image *Img,int X,int Y,int W,int H); 250 251 #if defined(MAEMO) 252 void GenericSetVideo(Image *Img,int X,int Y,int W,int H); 253 #endif 254 255 /** ShowVideo() **********************************************/ 256 /** Show "active" image at the actual screen or window. **/ 257 /*************************************************************/ 258 int ShowVideo(void); 259 260 /** GetColor() ***********************************************/ 261 /** Return pixel corresponding to the given <R,G,B> value. **/ 262 /** This only works for non-palletized modes. **/ 263 /*************************************************************/ 264 pixel GetColor(unsigned char R,unsigned char G,unsigned char B); 265 266 /** SetPalette() *********************************************/ 267 /** Set color N to the given <R,G,B> value. This only works **/ 268 /** for palette-based modes. **/ 269 /*************************************************************/ 270 void SetPalette(pixel N,unsigned char R,unsigned char G,unsigned char B); 271 272 /** GetFreeAudio() *******************************************/ 273 /** Get the amount of free samples in the audio buffer. **/ 274 /*************************************************************/ 275 unsigned int GetFreeAudio(void); 276 277 /** WriteAudio() *********************************************/ 278 /** Write up to a given number of samples to audio buffer. **/ 279 /** Returns the number of samples written. **/ 280 /*************************************************************/ 281 unsigned int WriteAudio(sample *Data,unsigned int Length); 282 283 /** PauseAudio() *********************************************/ 284 /** Pause/resume audio playback. Returns current playback **/ 285 /** state. **/ 286 /************************************************* OPTIONAL **/ 287 int PauseAudio(int Switch); 288 289 /** GetJoystick() ********************************************/ 290 /** Get the state of joypad buttons (1="pressed"). Refer to **/ 291 /** the BTN_* #defines for the button mappings. Notice that **/ 292 /** on Windows this function calls WinProcessMsgs() thus **/ 293 /** automatically handling all Windows messages. **/ 294 /*************************************************************/ 295 unsigned int GetJoystick(void); 296 297 /** WaitJoystick() *******************************************/ 298 /** Wait until one or more of the given buttons have been **/ 299 /** pressed. Returns the bitmask of pressed buttons. Refer **/ 300 /** to BTN_* #defines for the button mappings. **/ 301 /*************************************************************/ 302 unsigned int WaitJoystick(unsigned int Mask); 303 304 /** GetMouse() ***********************************************/ 305 /** Get mouse position and button states in the following **/ 306 /** format: RMB.LMB.Y[29-16].X[15-0] **/ 307 /*************************************************************/ 308 unsigned int GetMouse(void); 309 310 /** GetKey() *************************************************/ 311 /** Get currently pressed key or 0 if none pressed. Returns **/ 312 /** CON_* definitions for arrows and special keys. **/ 313 /*************************************************************/ 314 unsigned int GetKey(void); 315 316 /** WaitKey() ************************************************/ 317 /** Wait for a key to be pressed. Returns CON_* definitions **/ 318 /** for arrows and special keys. **/ 319 /*************************************************************/ 320 unsigned int WaitKey(void); 321 322 /** WaitKeyOrMouse() *****************************************/ 323 /** Wait for a key or a mouse button to be pressed. Returns **/ 324 /** the same result as GetMouse(). If no mouse buttons **/ 325 /** reported to be pressed, call GetKey() to fetch a key. **/ 326 /*************************************************************/ 327 unsigned int WaitKeyOrMouse(void); 328 329 /** SetKeyHandler() ******************************************/ 330 /** Attach keyboard handler that will be called when a key **/ 331 /** is pressed or released. **/ 332 /*************************************************************/ 333 void SetKeyHandler(void (*Handler)(unsigned int Key)); 334 335 /** WaitSyncTimer() ******************************************/ 336 /** Wait for the timer to become ready. **/ 337 /*************************************************************/ 338 void WaitSyncTimer(void); 339 340 /** SyncTimerReady() *****************************************/ 341 /** Return 1 if sync timer ready, 0 otherwise. **/ 342 /*************************************************************/ 343 int SyncTimerReady(void); 344 345 /** SetSyncTimer() *******************************************/ 346 /** Set synchronization timer to a given frequency in Hz. **/ 347 /*************************************************************/ 348 int SetSyncTimer(int Hz); 349 350 /** GetFilePath() ********************************************/ 351 /** Extracts pathname from filename and returns a pointer **/ 352 /** to the internal buffer containing just the path name **/ 353 /** ending with "\". **/ 354 /*************************************************************/ 355 const char *GetFilePath(const char *Name); 356 357 /** NewFile() ************************************************/ 358 /** Given pattern NAME.EXT, generates a new filename in the **/ 359 /** NAMEnnnn.EXT (nnnn = 0000..9999) format and returns a **/ 360 /** pointer to the internal buffer containing new filename. **/ 361 /*************************************************************/ 362 const char *NewFile(const char *Pattern); 363 364 /** ChangeDir() **********************************************/ 365 /** This function is a wrapper for chdir(). Unlike chdir(), **/ 366 /** it changes *both* the drive and the directory in MSDOS, **/ 367 /** exactly like the "normal" chdir() should. Returns 0 on **/ 368 /** success, -1 on failure, just like chdir(). **/ 369 /*************************************************************/ 370 int ChangeDir(const char *Name); 371 372 #ifdef GIFLIB 373 /** LoadGIF() ************************************************/ 374 /** Load screen from .GIF file. Returns the number of used **/ 375 /** colors or 0 if failed. **/ 376 /*************************************************************/ 377 int LoadGIF(const char *File); 378 379 /** SaveGIF() ************************************************/ 380 /** Save screen to .GIF file. Returns the number of written **/ 381 /** scanlines or 0 if failed. **/ 382 /*************************************************************/ 383 int SaveGIF(const char *File); 384 #endif /* GIFLIB */ 385 386 #ifdef __cplusplus 387 } 388 #endif 389 #endif /* EMULIB_H */ 390