1 #ifndef PLATFORM_INCLUDED 2 #define PLATFORM_INCLUDED 3 4 #include "fixer.h" 5 6 #include "shape.h" // struct imageheader 7 8 /* 9 10 Platform Specific Header Include 11 12 */ 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 /* Types */ 19 20 typedef struct LONGLONGCH { 21 22 unsigned int lo32; 23 int hi32; 24 25 } LONGLONGCH; 26 27 /* 28 29 Sine and Cosine 30 31 */ 32 33 #define GetSin(a) sine[a] 34 #define GetCos(a) cosine[a] 35 36 /* 37 Available processor types 38 */ 39 40 typedef enum { 41 42 PType_OffBottomOfScale, 43 PType_486, 44 PType_Pentium, 45 PType_P6, 46 PType_PentiumMMX, 47 PType_Klamath, 48 PType_OffTopOfScale 49 50 } PROCESSORTYPES; 51 52 /* 53 Video mode decsription (to be filled 54 in by DirectDraw callback). 55 */ 56 57 typedef struct videomodeinfo { 58 59 int Width; /* in pixels */ 60 int Height; /* in pixels */ 61 int ColourDepth; /* in bits per pixel */ 62 63 } VIDEOMODEINFO; 64 65 /* 66 Maximum number of display modes 67 that could be detected on unknown 68 hardware. 69 */ 70 71 #define MaxAvailableVideoModes 100 72 73 /* 74 #defines, structures etc for 75 textprint system 76 */ 77 78 #define MaxMsgChars 100 79 #define MaxMessages 20 80 81 /* Font description */ 82 83 #define CharWidth 8 /* In PIXELS, not bytes */ 84 #define CharHeight 10 /* In PIXELS, not bytes */ 85 #define CharVertSep (CharHeight + 0) /* In PIXELS, not bytes */ 86 87 #define FontStart 33 // random squiggle in standard ASCII 88 #define FontEnd 127 // different random squiggle in standard ASCII 89 90 #define FontInvisValue 0x00 // value to be colour keyed out of font blit 91 92 typedef struct printqueueitem { 93 94 char text[MaxMsgChars]; 95 int text_length; 96 int x; 97 int y; 98 99 } PRINTQUEUEITEM; 100 101 102 103 /* KJL 12:30:05 9/9/97 - new keyboard, mouse etc. enum */ 104 enum KEY_ID 105 { 106 KEY_ESCAPE, 107 108 KEY_0, 109 KEY_1, 110 KEY_2, 111 KEY_3, 112 KEY_4, 113 KEY_5, 114 KEY_6, 115 KEY_7, 116 KEY_8, 117 KEY_9, 118 119 KEY_A, 120 KEY_B, 121 KEY_C, 122 KEY_D, 123 KEY_E, 124 KEY_F, 125 KEY_G, 126 KEY_H, 127 KEY_I, 128 KEY_J, 129 KEY_K, 130 KEY_L, 131 KEY_M, 132 KEY_N, 133 KEY_O, 134 KEY_P, 135 KEY_Q, 136 KEY_R, 137 KEY_S, 138 KEY_T, 139 KEY_U, 140 KEY_V, 141 KEY_W, 142 KEY_X, 143 KEY_Y, 144 KEY_Z, 145 146 KEY_LEFT, 147 KEY_RIGHT, 148 KEY_UP, 149 KEY_DOWN, 150 KEY_CR, 151 KEY_TAB, 152 KEY_INS, 153 KEY_DEL, 154 KEY_END, 155 KEY_HOME, 156 KEY_PAGEUP, 157 KEY_PAGEDOWN, 158 KEY_BACKSPACE, 159 KEY_COMMA, 160 KEY_FSTOP, 161 KEY_SPACE, 162 163 KEY_LEFTSHIFT, 164 KEY_RIGHTSHIFT, 165 KEY_LEFTALT, 166 KEY_RIGHTALT, 167 KEY_LEFTCTRL, 168 KEY_RIGHTCTRL, 169 170 KEY_CAPS, 171 KEY_NUMLOCK, 172 KEY_SCROLLOK, 173 174 KEY_NUMPAD0, 175 KEY_NUMPAD1, 176 KEY_NUMPAD2, 177 KEY_NUMPAD3, 178 KEY_NUMPAD4, 179 KEY_NUMPAD5, 180 KEY_NUMPAD6, 181 KEY_NUMPAD7, 182 KEY_NUMPAD8, 183 KEY_NUMPAD9, 184 KEY_NUMPADSUB, 185 KEY_NUMPADADD, 186 KEY_NUMPADDEL, 187 KEY_NUMPADENTER, 188 KEY_NUMPADDIVIDE, 189 KEY_NUMPADMULTIPLY, 190 191 KEY_LBRACKET, 192 KEY_RBRACKET, 193 KEY_SEMICOLON, 194 KEY_APOSTROPHE, 195 KEY_GRAVE, 196 KEY_BACKSLASH, 197 KEY_SLASH, 198 KEY_CAPITAL, 199 KEY_MINUS, 200 KEY_EQUALS, 201 KEY_LWIN, 202 KEY_RWIN, 203 KEY_APPS, 204 205 206 KEY_F1, 207 KEY_F2, 208 KEY_F3, 209 KEY_F4, 210 KEY_F5, 211 KEY_F6, 212 KEY_F7, 213 KEY_F8, 214 KEY_F9, 215 KEY_F10, 216 KEY_F11, 217 KEY_F12, 218 219 KEY_JOYSTICK_BUTTON_1, 220 KEY_JOYSTICK_BUTTON_2, 221 KEY_JOYSTICK_BUTTON_3, 222 KEY_JOYSTICK_BUTTON_4, 223 KEY_JOYSTICK_BUTTON_5, 224 KEY_JOYSTICK_BUTTON_6, 225 KEY_JOYSTICK_BUTTON_7, 226 KEY_JOYSTICK_BUTTON_8, 227 KEY_JOYSTICK_BUTTON_9, 228 KEY_JOYSTICK_BUTTON_10, 229 KEY_JOYSTICK_BUTTON_11, 230 KEY_JOYSTICK_BUTTON_12, 231 KEY_JOYSTICK_BUTTON_13, 232 KEY_JOYSTICK_BUTTON_14, 233 KEY_JOYSTICK_BUTTON_15, 234 KEY_JOYSTICK_BUTTON_16, 235 236 KEY_LMOUSE, 237 KEY_MMOUSE, 238 KEY_RMOUSE, 239 240 KEY_MOUSEBUTTON4, 241 KEY_MOUSEWHEELUP, 242 KEY_MOUSEWHEELDOWN, 243 244 // Dutch 245 KEY_ORDINAL, 246 KEY_LESSTHAN, 247 KEY_PLUS, 248 249 // French 250 KEY_RIGHTBRACKET, 251 KEY_ASTERISK, 252 KEY_DOLLAR, 253 KEY_U_GRAVE, 254 KEY_EXCLAMATION, 255 KEY_COLON, 256 257 // German 258 KEY_BETA, 259 KEY_A_UMLAUT, 260 KEY_O_UMLAUT, 261 KEY_U_UMLAUT, 262 KEY_HASH, 263 264 // Spanish 265 KEY_UPSIDEDOWNEXCLAMATION, 266 KEY_C_CEDILLA, 267 KEY_N_TILDE, 268 269 // accents & diacritics 270 KEY_DIACRITIC_GRAVE, 271 KEY_DIACRITIC_ACUTE, 272 KEY_DIACRITIC_CARET, 273 KEY_DIACRITIC_UMLAUT, 274 275 276 KEY_VOID=255, // used to indicate a blank spot in the key config 277 MAX_NUMBER_OF_INPUT_KEYS, 278 279 }; 280 /* 281 Mouse handler modes (velocity mode is for 282 interfacing to input functions that need 283 to read the mouse velocity, e.g. WeRequest 284 functions, while poistion mode is for menus 285 and similar problems). 286 287 The initial mode is defined as a compiled in 288 global in game.c 289 */ 290 291 typedef enum { 292 293 MouseVelocityMode, 294 MousePositionMode 295 296 } MOUSEMODES; 297 298 299 /* Defines for the purpose of familiarity of name only */ 300 301 #define LeftButton 0x0001 302 #define RightButton 0x0002 303 #define MiddleButton 0x0004 304 305 306 307 308 /* 309 Video Modes 310 */ 311 312 typedef enum { 313 314 VideoMode_DX_320x200x8, 315 VideoMode_DX_320x200x8T, 316 VideoMode_DX_320x200x15, 317 VideoMode_DX_320x240x8, 318 319 VideoMode_DX_640x480x8, 320 VideoMode_DX_640x480x8T, 321 VideoMode_DX_640x480x15, 322 VideoMode_DX_640x480x24, 323 324 VideoMode_DX_800x600x8, 325 VideoMode_DX_800x600x8T, 326 VideoMode_DX_800x600x15, 327 VideoMode_DX_800x600x24, 328 329 VideoMode_DX_1024x768x8, 330 VideoMode_DX_1024x768x8T, 331 VideoMode_DX_1024x768x15, 332 VideoMode_DX_1024x768x24, 333 334 VideoMode_DX_1280x1024x8, 335 VideoMode_DX_1280x1024x8T, 336 VideoMode_DX_1280x1024x15, 337 VideoMode_DX_1280x1024x24, 338 339 VideoMode_DX_1600x1200x8, 340 VideoMode_DX_1600x1200x8T, 341 VideoMode_DX_1600x1200x15, 342 VideoMode_DX_1600x1200x24, 343 344 MaxVideoModes 345 346 } VIDEOMODES; 347 348 349 #define MaxScreenWidth 1600 /* Don't get this wrong! */ 350 351 352 /* 353 354 Video Mode Types 355 356 */ 357 358 typedef enum { 359 360 VideoModeType_8, 361 VideoModeType_15, 362 VideoModeType_24, 363 VideoModeType_8T 364 365 } VIDEOMODETYPES; 366 367 368 /* 369 Windows modes 370 */ 371 372 typedef enum { 373 374 WindowModeFullScreen, 375 WindowModeSubWindow 376 377 } WINDOWMODES; 378 379 typedef struct WinScaleXY { 380 381 float x; 382 float y; 383 384 } WINSCALEXY; 385 386 387 /* 388 Dubious hack for dubious 389 aspects of DirectDraw initialisation 390 */ 391 392 typedef enum { 393 394 /* Default */ 395 NoRestartRequired, 396 /* 397 Characteristic of driver which 398 will not support changing to a different 399 bit depth without rebooting 400 */ 401 RestartDisplayModeNotAvailable, 402 /* 403 Characteristic of ModeX emulation leading 404 to no video memory being available because 405 of the need to cooperate with a large existing 406 GDI surface which cannot be reduced without a 407 reboot 408 */ 409 RestartOutOfVidMemForPrimary 410 411 } VIDEORESTARTMODES; 412 413 414 /* 415 Direct3D driver modes 416 */ 417 418 typedef enum { 419 420 D3DSoftwareRGBDriver, 421 D3DSoftwareRampDriver, 422 D3DHardwareRGBDriver 423 424 } D3DMODES; 425 426 /* 427 Software scan draw request modes 428 */ 429 430 typedef enum { 431 432 RequestScanDrawDirectDraw, 433 RequestScanDrawSoftwareRGB, 434 RequestScanDrawRamp, 435 RequestScanDrawDefault 436 437 } SOFTWARESCANDRAWREQUESTMODES; 438 439 /* 440 Rasterisation request modes 441 */ 442 443 typedef enum { 444 445 RequestSoftwareRasterisation, 446 RequestDefaultRasterisation 447 448 } RASTERREQUESTMODES; 449 450 451 /* 452 Actual scan draw mode 453 */ 454 455 typedef enum { 456 457 ScanDrawDirectDraw, 458 ScanDrawD3DRamp, 459 ScanDrawD3DSoftwareRGB, 460 ScanDrawD3DHardwareRGB 461 462 } SCANDRAWMODES; 463 464 465 /* 466 Z buffering request modes 467 */ 468 469 typedef enum { 470 471 RequestZBufferNever, 472 RequestZBufferAlways, 473 RequestZBufferDefault 474 475 } ZBUFFERREQUESTMODES; 476 477 /* 478 Z buffering modes 479 */ 480 481 typedef enum { 482 483 ZBufferOn, 484 ZBufferWriteOnly, 485 ZBufferOff 486 487 } ZBUFFERMODES; 488 489 /* 490 Request modes for DirectX 491 memory usage 492 */ 493 494 typedef enum { 495 496 RequestSystemMemoryAlways, 497 RequestDefaultMemoryAllocation 498 499 } DXMEMORYREQUESTMODES; 500 501 502 /* 503 DirectX memory usage modes 504 */ 505 506 typedef enum { 507 508 SystemMemoryPreferred, 509 VideoMemoryPreferred 510 511 } DXMEMORYMODES; 512 513 /* 514 Types of texture files that can be 515 requested from the main D3D texture 516 loader. 517 */ 518 519 typedef enum { 520 521 TextureTypePGM, 522 TextureTypePPM 523 524 } TEXTUREFILETYPE; 525 526 /* 527 Windows initialisation modes. 528 See InitialiseWindowsSystem 529 in the default win_proj.cpp 530 for a full description. 531 */ 532 533 typedef enum { 534 535 WinInitFull, 536 WinInitChange 537 538 } WININITMODES; 539 540 541 /* 542 Function prototypes 543 */ 544 545 /* 546 Windows functionality. Note current 547 DirectInput functions are also here since 548 they are really part of the Win32 multimedia 549 library. 550 */ 551 552 long GetWindowsTickCount(void); 553 void CheckForWindowsMessages(void); 554 BOOL ExitWindowsSystem(void); 555 BOOL InitialiseWindowsSystem(HANDLE hInstance, int nCmdShow, int WinInitMode); 556 //void KeyboardHandlerKeyDown(WPARAM wParam); 557 //void KeyboardHandlerKeyUp(WPARAM wParam); 558 //void MouseVelocityHandler(UINT message, LPARAM lParam); 559 //void MousePositionHandler(UINT message, LPARAM lParam); 560 int ReadJoystick(void); 561 int CheckForJoystick(void); 562 BOOL SpawnRasterThread(); 563 BOOL WaitForRasterThread(); 564 565 566 /* DirectDraw */ 567 void finiObjects(void); 568 void GenerateDirectDrawSurface(void); 569 void LockSurfaceAndGetBufferPointer(void); 570 void UnlockSurface(void); 571 void finiObjects(void); 572 void ColourFillBackBuffer(int FillColour); 573 void ColourFillBackBufferQuad(int FillColour, int LeftX, 574 int TopY, int RightX, int BotY); 575 void FlipBuffers(void); 576 void BlitToBackBuffer(void* lpBackground, RECT* destRectPtr, RECT* srcRectPtr); 577 void BlitToBackBufferWithoutTearing(void* lpBackground, RECT* destRectPtr, RECT* srcRectPtr); 578 void BlitWin95Char(int x, int y, unsigned char toprint); 579 void ReleaseDDSurface(void* DDSurface); 580 BOOL InitialiseDirectDrawObject(void); 581 BOOL ChangeDirectDrawObject(void); 582 BOOL CheckForVideoModes(int TestVideoMode); 583 void finiObjectsExceptDD(void); 584 BOOL TestMemoryAccess(void); 585 int ChangePalette (unsigned char* NewPalette); 586 int GetAvailableVideoMemory(void); 587 //void HandleVideoModeRestarts(HINSTANCE hInstance, int nCmdShow); 588 void* MakeBackdropSurface(void); 589 void ReleaseBackdropSurface(void); 590 void LockBackdropSurface(void); 591 void UnlockBackdropSurface(void); 592 void ComposeBackdropBackBuffer(void); 593 int GetSingleColourForPrimary(int Colour); 594 595 /* Direct 3D Immediate Mode Rasterisation Module */ 596 BOOL InitialiseDirect3DImmediateMode(void); 597 BOOL LockExecuteBuffer(void); 598 BOOL UnlockExecuteBufferAndPrepareForUse(void); 599 BOOL BeginD3DScene(void); 600 BOOL EndD3DScene(void); 601 BOOL ExecuteBuffer(void); 602 BOOL RenderD3DScene(void); 603 void ReleaseDirect3D(void); 604 void WritePolygonToExecuteBuffer(int* itemptr); 605 void WriteGouraudPolygonToExecuteBuffer(int* itemptr); 606 void Write2dTexturedPolygonToExecuteBuffer(int* itemptr); 607 void WriteGouraud2dTexturedPolygonToExecuteBuffer(int* itemptr); 608 void Write3dTexturedPolygonToExecuteBuffer(int* itemptr); 609 void WriteGouraud3dTexturedPolygonToExecuteBuffer(int* itemptr); 610 void WriteBackdrop2dTexturedPolygonToExecuteBuffer(int* itemptr); 611 void WriteBackdrop3dTexturedPolygonToExecuteBuffer(int* itemptr); 612 void WriteEndCodeToExecuteBuffer(void); 613 void ReleaseD3DTexture(void* D3DTexture); 614 void ReleaseDirect3DNotDD(void); 615 void ReleaseDirect3DNotDDOrImages(void); 616 BOOL SetExecuteBufferDefaults(void); 617 void SelectD3DDriverAndDrawMode(void); 618 #if SUPPORT_MMX 619 void SelectMMXOptions(void); 620 #endif 621 BOOL TestInitD3DObject(void); 622 623 #if SupportZBuffering 624 BOOL CreateD3DZBuffer(void); 625 void FlushD3DZBuffer(void); 626 void WriteZBPolygonToExecuteBuffer(int* itemptr); 627 void WriteZBGouraudPolygonToExecuteBuffer(int* itemptr); 628 void WriteZB2dTexturedPolygonToExecuteBuffer(int* itemptr); 629 void WriteZBGouraud2dTexturedPolygonToExecuteBuffer(int* itemptr); 630 void WriteZB3dTexturedPolygonToExecuteBuffer(int* itemptr); 631 void WriteZBGouraud3dTexturedPolygonToExecuteBuffer(int* itemptr); 632 #endif 633 634 /* KJL 11:28:31 9/9/97 - Direct Input prototypes */ 635 BOOL InitialiseDirectInput(void); 636 void ReleaseDirectInput(void); 637 BOOL InitialiseDirectKeyboard(); 638 void DirectReadKeyboard(void); 639 void ReleaseDirectKeyboard(void); 640 BOOL InitialiseDirectMouse(); 641 void DirectReadMouse(void); 642 void ReleaseDirectMouse(void); 643 644 /* 645 Internal 646 */ 647 //#ifdef AVP_DEBUG_VERSION 648 int textprint(const char* t, ...); 649 //#else 650 //#define textprint(ignore) 651 //#endif 652 653 654 void ConvertToDDPalette(unsigned char* src, unsigned char* dst, int length, int flags); 655 int textprintXY(int x, int y, const char* t, ...); 656 void LoadSystemFonts(char* fname); 657 void DisplayWin95String(int x, int y, unsigned char *buffer); 658 void WriteStringToTextBuffer(int x, int y, unsigned char *buffer); 659 void FlushTextprintBuffer(void); 660 void InitPrintQueue(void); 661 void InitJoysticks(void); 662 void ReadJoysticks(void); 663 //int ChangeDisplayModes(HINSTANCE hInst, int nCmd, 664 // int NewVideoMode, int NewWindowMode, 665 // int NewZBufferMode, int NewRasterisationMode, 666 // int NewSoftwareScanDrawMode, int NewDXMemoryMode); 667 int DeallocateAllImages(void); 668 int MinimizeAllImages(void); 669 int RestoreAllImages(void); 670 void ConvertDDToInternalPalette(unsigned char* src, unsigned char* dst, int length); 671 PROCESSORTYPES ReadProcessorType(void); 672 673 //extern DDCAPS direct_draw_caps; 674 675 /* 676 677 Jake's image functions 678 679 */ 680 681 void * CopyD3DTexture(struct imageheader *iheader); 682 683 #ifdef MaxImageGroups 684 685 #if (MaxImageGroups > 1) 686 687 void SetCurrentImageGroup(unsigned int group); 688 int DeallocateCurrentImages(void); 689 690 #endif /* MaxImageGroups > 1 */ 691 692 #endif /* defined(MaxImageGroups) */ 693 694 695 /* 696 Project callbacks 697 */ 698 699 void ExitGame(void); 700 701 void ProjectSpecificBufferFlipPostProcessing(); 702 703 void ProjectSpecificItemListPostProcessing(); 704 705 #if optimiseflip 706 void ProcessProjectWhileWaitingToBeFlippable(); 707 #endif 708 709 #ifdef __cplusplus 710 }; 711 #endif 712 713 714 #endif 715