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-2014 **/ 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 /** ARMScaleImage() Attributes *******************************/ 17 /** These values can be ORed and passed to ARMScaleImage(). **/ 18 /*************************************************************/ 19 #define ARMSI_VFILL 0x01 20 #define ARMSI_HFILL 0x02 21 22 /** SetEffects() Attributes **********************************/ 23 /** These values can be ORed and passed to SetEffects(). **/ 24 /*************************************************************/ 25 #define EFF_NONE 0x0000 /* No special effects */ 26 #define EFF_SCALE 0x0001 /* Scale video to fill screen */ 27 #define EFF_SOFTEN 0x0002 /* Scale + soften video */ 28 #define EFF_TVLINES 0x0004 /* Apply TV scanlines effect */ 29 #define EFF_SAVECPU 0x0008 /* Suspend when inactive */ 30 #define EFF_SYNC 0x0010 /* Wait for sync timer */ 31 #define EFF_PENCUES 0x0020 /* Draw pen input cue lines */ 32 #define EFF_DIALCUES 0x0040 /* Draw dialpad (with PENCUES)*/ 33 #define EFF_VERBOSE 0x0080 /* Report problems via printf */ 34 #define EFF_STRETCH 0x0100 /* Stretch video, fill screen */ 35 #define EFF_SHOWFPS 0x0200 /* Show frames-per-sec count */ 36 #define EFF_LCDLINES 0x0400 /* Apply LCD scanlines effect */ 37 #define EFF_VKBD 0x0800 /* Draw virtual keyboard */ 38 #define EFF_FULLJOY 0x2000 /* Use full screen controls */ 39 #define EFF_TILTJOY 0x4000 /* Use accelerometer controls */ 40 #define EFF_PENJOY 0x8000 /* Use touchpad controls */ 41 #define EFF_VSYNC 0x10000 /* Wait for VBlanks */ 42 #define EFF_DIRECT 0x20000 /* Copy whole VideoImg */ 43 #if defined(ANDROID) 44 #define EFF_FIXFFWD 0x100000 /* Persistent FFWD button */ 45 #define EFF_GLES 0x200000 /* OpenGLES video rendering */ 46 #define EFF_EXTVKBD 0x400000 /* Java virtual keyboard */ 47 #define EFF_LOCKED 0x80000000 /* SetEffects() now disabled */ 48 #elif defined(MAEMO) 49 #define EFF_NOVOLUME 0x100000 /* No volume control on F7/F8 */ 50 #define EFF_FULLSCR 0x200000 /* Force full-screen mode */ 51 #define EFF_WINDOWED 0x400000 /* Force windowed mode */ 52 #define EFF_HAA 0x800000 /* Use HildonAnimationActor */ 53 #define EFF_ALWAYS1 0x80000000 /* 1: InitMaemo() success */ 54 #elif defined(S60) || defined(UIQ) 55 #define EFF_FILL 0x100000 /* Fill display vertically */ 56 #define EFF_LIGHT 0x200000 /* Keep backlight on */ 57 #define EFF_USEHAL 0x400000 /* Use direct image rendering without DSB */ 58 #elif defined(UNIX) 59 #define EFF_VARBPP 0x200000 /* X11 determines Image depth */ 60 #endif 61 62 /** Button Bits **********************************************/ 63 /** Bits returned by GetJoystick() and WaitJoystick(). **/ 64 /*************************************************************/ 65 #define BTN_LEFT 0x0001 66 #define BTN_RIGHT 0x0002 67 #define BTN_UP 0x0004 68 #define BTN_DOWN 0x0008 69 #define BTN_FIREA 0x0010 70 #define BTN_FIREB 0x0020 71 #define BTN_FIREL 0x0040 72 #define BTN_FIRER 0x0080 73 #define BTN_START 0x0100 74 #define BTN_SELECT 0x0200 75 #define BTN_EXIT 0x0400 76 #define BTN_FIREX 0x0800 77 #define BTN_FIREY 0x1000 78 #define BTN_FFWD 0x2000 79 #define BTN_MENU 0x4000 80 #define BTN_ALL 0x7FFF 81 #define BTN_OK (BTN_FIREA|BTN_START) 82 #define BTN_FIRE (BTN_FIREA|BTN_FIREB|BTN_FIREL|BTN_FIRER|BTN_FIREX|BTN_FIREY) 83 #define BTN_ARROWS (BTN_LEFT|BTN_RIGHT|BTN_UP|BTN_DOWN) 84 #define BTN_SHIFT CON_SHIFT 85 #define BTN_CONTROL CON_CONTROL 86 #define BTN_ALT CON_ALT 87 #define BTN_MODES (BTN_SHIFT|BTN_CONTROL|BTN_ALT) 88 89 /** Mouse Bits ***********************************************/ 90 /** Bits returned by GetMouse() and WaitKeyOrMouse(). **/ 91 /*************************************************************/ 92 #define MSE_RIGHT 0x80000000 93 #define MSE_LEFT 0x40000000 94 #define MSE_BUTTONS (MSE_RIGHT|MSE_LEFT) 95 #define MSE_YPOS 0x3FFF0000 96 #define MSE_XPOS 0x0000FFFF 97 98 /** Special Key Codes ****************************************/ 99 /** Modifiers returned by GetKey() and WaitKey(). **/ 100 /*************************************************************/ 101 #define CON_KEYCODE 0x03FFFFFF /* Key code */ 102 #define CON_MODES 0xFC000000 /* Mode bits, as follows: */ 103 #define CON_CLICK 0x04000000 /* Key click (LiteS60 only) */ 104 #define CON_CAPS 0x08000000 /* CapsLock held */ 105 #define CON_SHIFT 0x10000000 /* SHIFT held */ 106 #define CON_CONTROL 0x20000000 /* CONTROL held */ 107 #define CON_ALT 0x40000000 /* ALT held */ 108 #define CON_RELEASE 0x80000000 /* Key released (going up) */ 109 110 #define CON_F1 0xEE 111 #define CON_F2 0xEF 112 #define CON_F3 0xF0 113 #define CON_F4 0xF1 114 #define CON_F5 0xF2 115 #define CON_F6 0xF3 116 #define CON_F7 0xF4 117 #define CON_F8 0xF5 118 #define CON_F9 0xF6 119 #define CON_F10 0xF7 120 #define CON_F11 0xF8 121 #define CON_F12 0xF9 122 #define CON_LEFT 0xFA 123 #define CON_RIGHT 0xFB 124 #define CON_UP 0xFC 125 #define CON_DOWN 0xFD 126 #define CON_OK 0xFE 127 #define CON_EXIT 0xFF 128 129 #define SND_CHANNELS 16 /* Number of sound channels */ 130 #define SND_BITS 8 131 #define SND_BUFSIZE (1<<SND_BITS) 132 133 #define PIXEL(R,G,B) (pixel)(((31*(R)/255)<<11)|((63*(G)/255)<<5)|(31*(B)/255)) 134 #define PIXEL2MONO(P) (522*(((P)&31)+(((P)>>5)&63)+(((P)>>11)&31))>>8) 135 #define RMASK 0xF800 136 #define GMASK 0x07E0 137 #define BMASK 0x001F 138 139 #ifdef __cplusplus 140 extern "C" { 141 #endif 142 143 /** pixel ****************************************************/ 144 /** Pixels may be either 8bit, or 16bit, or 32bit. When no **/ 145 /** BPP* specified, we assume the pixel to have the largest **/ 146 /** size and default to GetColor(). **/ 147 /*************************************************************/ 148 #ifndef PIXEL_TYPE_DEFINED 149 #define PIXEL_TYPE_DEFINED 150 #if defined(BPP32) || defined(BPP24) 151 typedef unsigned int pixel; 152 #elif defined(BPP16) 153 typedef unsigned short pixel; 154 #elif defined(BPP8) 155 typedef unsigned char pixel; 156 #else 157 typedef unsigned int pixel; 158 #define PIXEL(R,G,B) GetColor(R,G,B) 159 #endif 160 #endif 161 162 /** sample ***************************************************/ 163 /** Audio samples may be either 8bit or 16bit. **/ 164 /*************************************************************/ 165 #ifndef SAMPLE_TYPE_DEFINED 166 #define SAMPLE_TYPE_DEFINED 167 #ifdef BPS16 168 typedef signed short sample; 169 #else 170 typedef signed char sample; 171 #endif 172 #endif 173 174 /** Image ****************************************************/ 175 /** This data type encapsulates a bitmap. **/ 176 /*************************************************************/ 177 typedef struct 178 { 179 pixel *Data; /* Buffer containing WxH pixels */ 180 int W,H,L,D; /* Image size, pitch, depth */ 181 char Cropped; /* 1: Cropped, do not free() */ 182 } Image; 183 184 /** Current Video Image **************************************/ 185 /** These parameters are set with SetVideo() and used by **/ 186 /** ShowVideo() to show a WxH fragment from <X,Y> of Img. **/ 187 /*************************************************************/ 188 extern Image *VideoImg; /* Current ShowVideo() image */ 189 extern int VideoX; /* X for ShowVideo() */ 190 extern int VideoY; /* Y for ShowVideo() */ 191 extern int VideoW; /* Width for ShowVideo() */ 192 extern int VideoH; /* Height for ShowVideo() */ 193 194 /** KeyHandler ***********************************************/ 195 /** This function receives key presses and releases. **/ 196 /*************************************************************/ 197 extern void (*KeyHandler)(unsigned int Key); 198 199 /** NewImage() ***********************************************/ 200 /** Create a new image of the given size. Returns pointer **/ 201 /** to the image data on success, 0 on failure. **/ 202 /*************************************************************/ 203 pixel *NewImage(Image *Img,int Width,int Height); 204 205 /** FreeImage() **********************************************/ 206 /** Free previously allocated image. **/ 207 /*************************************************************/ 208 void FreeImage(Image *Img); 209 210 /** CropImage() **********************************************/ 211 /** Create a subimage Dst of the image Src. Returns Dst. **/ 212 /*************************************************************/ 213 Image *CropImage(Image *Dst,const Image *Src,int X,int Y,int W,int H); 214 215 #if defined(WINDOWS) || defined(UNIX) || defined(MAEMO) || defined(MEEGO) 216 Image *GenericCropImage(Image *Dst,const Image *Src,int X,int Y,int W,int H); 217 #endif 218 219 /** ScaleImage() *********************************************/ 220 /** Copy Src into Dst, scaling as needed. **/ 221 /*************************************************************/ 222 void ScaleImage(Image *Dst,const Image *Src,int X,int Y,int W,int H); 223 224 /** ARMScaleImage() ******************************************/ 225 /** Copy Src into Dst using ARM-optimized assembly code. **/ 226 /** Returns 0 if this function is not supported or there is **/ 227 /** an alignment problem. Returns destination height and **/ 228 /** width on success in <Height 31:16><Width 15:0> format. **/ 229 /*************************************************************/ 230 unsigned int ARMScaleImage(Image *Dst,Image *Src,int X,int Y,int W,int H,int Attrs); 231 232 /** TelevizeImage() ******************************************/ 233 /** Create televizion effect on the image. **/ 234 /*************************************************************/ 235 void TelevizeImage(Image *Img,int X,int Y,int W,int H); 236 237 /** LcdizeImage() ********************************************/ 238 /** Create LCD effect on the image. **/ 239 /*************************************************************/ 240 void LcdizeImage(Image *Img,int X,int Y,int W,int H); 241 242 /** RasterizeImage() *****************************************/ 243 /** Create raster effect on the image. **/ 244 /*************************************************************/ 245 void RasterizeImage(Image *Img,int X,int Y,int W,int H); 246 247 /** SoftenImage() ********************************************/ 248 /** Uses softening algorithm to interpolate image Src into **/ 249 /** a bigger image Dst. **/ 250 /*************************************************************/ 251 void SoftenImage(Image *Dst,const Image *Src,int X,int Y,int W,int H); 252 253 /** ClearImage() *********************************************/ 254 /** Clear image with a given color. **/ 255 /*************************************************************/ 256 void ClearImage(Image *Img,pixel Color); 257 258 /** IMGCopy() ************************************************/ 259 /** Copy one image into another. Skips pixels of given **/ 260 /** color unless TColor=-1. **/ 261 /*************************************************************/ 262 void IMGCopy(Image *Dst,int DX,int DY,const Image *Src,int SX,int SY,int W,int H,int TColor); 263 264 /** IMGDrawRect()/IMGFillRect() ******************************/ 265 /** Draw filled/unfilled rectangle in a given image. **/ 266 /*************************************************************/ 267 void IMGDrawRect(Image *Img,int X,int Y,int W,int H,pixel Color); 268 void IMGFillRect(Image *Img,int X,int Y,int W,int H,pixel Color); 269 270 /** IMGPrint() ***********************************************/ 271 /** Print text in a given image. **/ 272 /*************************************************************/ 273 //@@@ NOT YET 274 //void IMGPrint(Image *Img,const char *S,int X,int Y,int FG,int BG); 275 276 /** SetVideo() ***********************************************/ 277 /** Set part of the image as "active" for display. **/ 278 /*************************************************************/ 279 void SetVideo(Image *Img,int X,int Y,int W,int H); 280 281 #if defined(UNIX) || defined(MAEMO) || defined(MEEGO) || defined(ANDROID) 282 void GenericSetVideo(Image *Img,int X,int Y,int W,int H); 283 #endif 284 285 /** ShowVideo() **********************************************/ 286 /** Show "active" image at the actual screen or window. **/ 287 /*************************************************************/ 288 int ShowVideo(void); 289 290 /** GetColor() ***********************************************/ 291 /** Return pixel corresponding to the given <R,G,B> value. **/ 292 /** This only works for non-palletized modes. **/ 293 /*************************************************************/ 294 pixel GetColor(unsigned char R,unsigned char G,unsigned char B); 295 296 /** SetPalette() *********************************************/ 297 /** Set color N to the given <R,G,B> value. This only works **/ 298 /** for palette-based modes. **/ 299 /*************************************************************/ 300 void SetPalette(pixel N,unsigned char R,unsigned char G,unsigned char B); 301 302 /** GetFreeAudio() *******************************************/ 303 /** Get the amount of free samples in the audio buffer. **/ 304 /*************************************************************/ 305 unsigned int GetFreeAudio(void); 306 307 /** WriteAudio() *********************************************/ 308 /** Write up to a given number of samples to audio buffer. **/ 309 /** Returns the number of samples written. **/ 310 /*************************************************************/ 311 unsigned int WriteAudio(sample *Data,unsigned int Length); 312 313 /** PauseAudio() *********************************************/ 314 /** Pause/resume audio playback. Returns current playback **/ 315 /** state. **/ 316 /************************************************* OPTIONAL **/ 317 int PauseAudio(int Switch); 318 319 /** GetJoystick() ********************************************/ 320 /** Get the state of joypad buttons (1="pressed"). Refer to **/ 321 /** the BTN_* #defines for the button mappings. Notice that **/ 322 /** on Windows this function calls ProcessEvents() thus **/ 323 /** automatically handling all Windows messages. **/ 324 /*************************************************************/ 325 unsigned int GetJoystick(void); 326 327 /** WaitJoystick() *******************************************/ 328 /** Wait until one or more of the given buttons have been **/ 329 /** pressed. Returns the bitmask of pressed buttons. Refer **/ 330 /** to BTN_* #defines for the button mappings. **/ 331 /*************************************************************/ 332 unsigned int WaitJoystick(unsigned int Mask); 333 334 /** GetMouse() ***********************************************/ 335 /** Get mouse position and button states in the following **/ 336 /** format: RMB.LMB.Y[29-16].X[15-0] **/ 337 /*************************************************************/ 338 unsigned int GetMouse(void); 339 340 /** GetKey() *************************************************/ 341 /** Get currently pressed key or 0 if none pressed. Returns **/ 342 /** CON_* definitions for arrows and special keys. **/ 343 /*************************************************************/ 344 unsigned int GetKey(void); 345 346 /** WaitKey() ************************************************/ 347 /** Wait for a key to be pressed. Returns CON_* definitions **/ 348 /** for arrows and special keys. **/ 349 /*************************************************************/ 350 unsigned int WaitKey(void); 351 352 /** WaitKeyOrMouse() *****************************************/ 353 /** Wait for a key or a mouse button to be pressed. Returns **/ 354 /** the same result as GetMouse(). If no mouse buttons **/ 355 /** reported to be pressed, call GetKey() to fetch a key. **/ 356 /*************************************************************/ 357 unsigned int WaitKeyOrMouse(void); 358 359 /** SetKeyHandler() ******************************************/ 360 /** Attach keyboard handler that will be called when a key **/ 361 /** is pressed or released. **/ 362 /*************************************************************/ 363 void SetKeyHandler(void (*Handler)(unsigned int Key)); 364 365 /** WaitSyncTimer() ******************************************/ 366 /** Wait for the timer to become ready. Returns number of **/ 367 /** times timer has been triggered after the last call to **/ 368 /** WaitSyncTimer(). **/ 369 /*************************************************************/ 370 int WaitSyncTimer(void); 371 372 /** SyncTimerReady() *****************************************/ 373 /** Return 1 if sync timer ready, 0 otherwise. **/ 374 /*************************************************************/ 375 int SyncTimerReady(void); 376 377 /** SetSyncTimer() *******************************************/ 378 /** Set synchronization timer to a given frequency in Hz. **/ 379 /*************************************************************/ 380 int SetSyncTimer(int Hz); 381 382 /** ProcessEvents() ******************************************/ 383 /** Process UI (X11,GTK,Qt,...) event messages. When Wait=1 **/ 384 /** and there are no messages, wait for some. Returns 1 for **/ 385 /** continued execution, 0 if application has been closed. **/ 386 /*************************************************************/ 387 int ProcessEvents(int Wait); 388 389 /** SetEffects() *********************************************/ 390 /** Set visual effects applied to video in ShowVideo(). **/ 391 /*************************************************************/ 392 void SetEffects(unsigned int NewEffects); 393 394 /** GetFilePath() ********************************************/ 395 /** Extracts pathname from filename and returns a pointer **/ 396 /** to the internal buffer containing just the path name **/ 397 /** ending with "\". **/ 398 /*************************************************************/ 399 const char *GetFilePath(const char *Name); 400 401 /** NewFile() ************************************************/ 402 /** Given pattern NAME.EXT, generates a new filename in the **/ 403 /** NAMEnnnn.EXT (nnnn = 0000..9999) format and returns a **/ 404 /** pointer to the internal buffer containing new filename. **/ 405 /*************************************************************/ 406 const char *NewFile(const char *Pattern); 407 408 /** ChangeDir() **********************************************/ 409 /** This function is a wrapper for chdir(). Unlike chdir(), **/ 410 /** it changes *both* the drive and the directory in MSDOS, **/ 411 /** exactly like the "normal" chdir() should. Returns 0 on **/ 412 /** success, -1 on failure, just like chdir(). **/ 413 /*************************************************************/ 414 int ChangeDir(const char *Name); 415 416 /** MicroSleep() *********************************************/ 417 /** Wait for a given number of microseconds. **/ 418 /*************************************************************/ 419 void MicroSleep(unsigned int uS); 420 421 #ifdef GIFLIB 422 /** LoadGIF() ************************************************/ 423 /** Load screen from .GIF file. Returns the number of used **/ 424 /** colors or 0 if failed. **/ 425 /*************************************************************/ 426 int LoadGIF(const char *File); 427 428 /** SaveGIF() ************************************************/ 429 /** Save screen to .GIF file. Returns the number of written **/ 430 /** scanlines or 0 if failed. **/ 431 /*************************************************************/ 432 int SaveGIF(const char *File); 433 #endif /* GIFLIB */ 434 435 #ifdef LIBPNG 436 /** LoadPNG() ************************************************/ 437 /** Load image from a .PNG file. Returns 1 on success, 0 on **/ 438 /** failure. **/ 439 /*************************************************************/ 440 int LoadPNG(Image *Img,const char *FileName); 441 #endif 442 443 #ifdef __cplusplus 444 } 445 #endif 446 #endif /* EMULIB_H */ 447