Original Source for 1.13 Mod High Resolution version from 12/06/05

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@21 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
lalien
2006-04-19 11:32:51 +00:00
commit e54aeb96aa
790 changed files with 741287 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
//**************************************************************************
//
// Filename : bitmap.h
//
// Purpose : bitmap format
//
// Modification history :
//
// 20nov96:HJH - Creation
//
//**************************************************************************
#ifndef _bitmap_h
#define _bitmap_h
//**************************************************************************
//
// Includes
//
//**************************************************************************
#include "types.h"
//**************************************************************************
//
// Defines
//
//**************************************************************************
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
typedef struct sgpBmHeadertag
{
UINT32 uiNumBytes; // number of bytes of the bitmap, including the
// memory for all variables in this structure plus
// all the memory in bitmap
UINT32 uiWidth; // width of bitmap in pixels
UINT32 uiHeight; // height of bitmap in pixels
UINT8 uiBitDepth; // 8, 16, 24, or 32
UINT8 uiNumPalEntries; // if uiBitDepth is 8, non-zero, else 0
} SGPBmHeader;
typedef struct sgpBitmaptag
{
SGPBmHeader header;
UINT8 uiData[1]; // if uiNumPalEntries != 0
// uiNumPalEntries*3 (rgb) bytes for palette
// if uiBitDepth == 8
// uiWidth * uiHeight bytes
// else if uiBitDepth == 16
// uiWidth * uiHeight * 2 bytes
// else if uiBitDepth == 24
// uiWidth * uiHeight * 3 bytes
// else if uiBitDepth == 32
// uiWidth * uiHeight * 4 bytes
} SGPBitmap;
#endif
@@ -0,0 +1,193 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "types.h"
#include "Button System.h"
#include "Button Sound Control.h"
#include "Sound Control.h"
#include "jascreens.h"
#endif
void SpecifyButtonSoundScheme( INT32 iButtonID, INT8 bSoundScheme )
{
ButtonList[ iButtonID ]->ubSoundSchemeID = (UINT8)bSoundScheme;
if( bSoundScheme == BUTTON_SOUND_SCHEME_GENERIC )
{
#ifdef JA2
switch( guiCurrentScreen )
{
case MAINMENU_SCREEN:
case OPTIONS_SCREEN:
case LOADSAVE_SCREEN:
case SAVE_LOAD_SCREEN:
case INIT_SCREEN:
ButtonList[ iButtonID ]->ubSoundSchemeID = BUTTON_SOUND_SCHEME_BIGSWITCH3;
break;
case LAPTOP_SCREEN:
ButtonList[ iButtonID ]->ubSoundSchemeID = BUTTON_SOUND_SCHEME_COMPUTERBEEP2;
break;
case AUTORESOLVE_SCREEN:
case MAP_SCREEN:
case GAME_SCREEN:
case SHOPKEEPER_SCREEN:
ButtonList[ iButtonID ]->ubSoundSchemeID = BUTTON_SOUND_SCHEME_SMALLSWITCH2;
break;
case GAME_INIT_OPTIONS_SCREEN:
ButtonList[ iButtonID ]->ubSoundSchemeID = BUTTON_SOUND_SCHEME_VERYSMALLSWITCH2;
break;
//Anything not handled gets NO sound.
//SHOPKEEPER_SCREEN,
//GAME_SCREEN,
//MSG_BOX_SCREEN,
//ERROR_SCREEN,
//ANIEDIT_SCREEN,
//PALEDIT_SCREEN,
//DEBUG_SCREEN,
//SEX_SCREEN,
}
#endif
if( bSoundScheme == BUTTON_SOUND_SCHEME_GENERIC )
bSoundScheme = BUTTON_SOUND_SCHEME_NONE;
}
}
void PlayButtonSound( INT32 iButtonID, INT32 iSoundType )
{
if ( ButtonList[ iButtonID ] == NULL )
{
return;
}
switch( ButtonList[ iButtonID ]->ubSoundSchemeID )
{
case BUTTON_SOUND_SCHEME_NONE:
case BUTTON_SOUND_SCHEME_GENERIC:
break;
#ifdef JA2
case BUTTON_SOUND_SCHEME_VERYSMALLSWITCH1:
switch( iSoundType )
{
case BUTTON_SOUND_CLICKED_ON:
PlayJA2Sample( VSM_SWITCH1_IN, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_CLICKED_OFF:
PlayJA2Sample( VSM_SWITCH1_OUT, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_DISABLED_CLICK:
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
break;
}
break;
case BUTTON_SOUND_SCHEME_VERYSMALLSWITCH2:
switch( iSoundType )
{
case BUTTON_SOUND_CLICKED_ON:
PlayJA2Sample( VSM_SWITCH2_IN, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_CLICKED_OFF:
PlayJA2Sample( VSM_SWITCH2_OUT, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_DISABLED_CLICK:
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
break;
}
break;
case BUTTON_SOUND_SCHEME_SMALLSWITCH1:
switch( iSoundType )
{
case BUTTON_SOUND_CLICKED_ON:
PlayJA2Sample( SM_SWITCH1_IN, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_CLICKED_OFF:
PlayJA2Sample( SM_SWITCH1_OUT, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_DISABLED_CLICK:
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
break;
}
break;
case BUTTON_SOUND_SCHEME_SMALLSWITCH2:
switch( iSoundType )
{
case BUTTON_SOUND_CLICKED_ON:
PlayJA2Sample( SM_SWITCH2_IN, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_CLICKED_OFF:
PlayJA2Sample( SM_SWITCH2_OUT, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_DISABLED_CLICK:
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
break;
}
break;
case BUTTON_SOUND_SCHEME_SMALLSWITCH3:
switch( iSoundType )
{
case BUTTON_SOUND_CLICKED_ON:
PlayJA2Sample( SM_SWITCH3_IN, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_CLICKED_OFF:
PlayJA2Sample( SM_SWITCH3_OUT, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_DISABLED_CLICK:
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
break;
}
break;
case BUTTON_SOUND_SCHEME_BIGSWITCH3:
switch( iSoundType )
{
case BUTTON_SOUND_CLICKED_ON:
PlayJA2Sample( BIG_SWITCH3_IN, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_CLICKED_OFF:
PlayJA2Sample( BIG_SWITCH3_OUT, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_DISABLED_CLICK:
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
break;
}
break;
case BUTTON_SOUND_SCHEME_COMPUTERBEEP2:
switch( iSoundType )
{
case BUTTON_SOUND_CLICKED_ON:
PlayJA2Sample( COMPUTER_BEEP2_IN, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_CLICKED_OFF:
PlayJA2Sample( COMPUTER_BEEP2_OUT, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_DISABLED_CLICK:
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
break;
}
break;
case BUTTON_SOUND_SCHEME_COMPUTERSWITCH1:
switch( iSoundType )
{
case BUTTON_SOUND_CLICKED_ON:
PlayJA2Sample( COMPUTER_SWITCH1_IN, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_CLICKED_OFF:
PlayJA2Sample( COMPUTER_SWITCH1_OUT, RATE_11025, 15, 1, MIDDLEPAN );
break;
case BUTTON_SOUND_DISABLED_CLICK:
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
break;
}
break;
#endif
}
}
@@ -0,0 +1,20 @@
#ifndef __BUTTON_SOUND_CONTROL_H
#define __BUTTON_SOUND_CONTROL_H
//These are gener
enum
{
BUTTON_SOUND_SCHEME_NONE,
BUTTON_SOUND_SCHEME_GENERIC,
BUTTON_SOUND_SCHEME_VERYSMALLSWITCH1,
BUTTON_SOUND_SCHEME_VERYSMALLSWITCH2,
BUTTON_SOUND_SCHEME_SMALLSWITCH1,
BUTTON_SOUND_SCHEME_SMALLSWITCH2,
BUTTON_SOUND_SCHEME_SMALLSWITCH3,
BUTTON_SOUND_SCHEME_BIGSWITCH3,
BUTTON_SOUND_SCHEME_COMPUTERBEEP2,
BUTTON_SOUND_SCHEME_COMPUTERSWITCH1,
};
#endif
File diff suppressed because it is too large Load Diff
+369
View File
@@ -0,0 +1,369 @@
//*****************************************************************************************************
// Button System.h
//
// by Kris Morness (originally created by Bret Rowden)
//*****************************************************************************************************
#ifndef __BUTTON_SYSTEM_H
#define __BUTTON_SYSTEM_H
#include "vobject.h"
#include "mousesystem.h"
#include "soundman.h"
#include "Button Sound Control.h"
// Moved here from Button System.c by DB 99/01/07
// Names of the default generic button image files.
#ifdef JA2
#define DEFAULT_GENERIC_BUTTON_OFF "GENBUTN.STI"
#define DEFAULT_GENERIC_BUTTON_ON "GENBUTN2.STI"
#define DEFAULT_GENERIC_BUTTON_OFF_HI "GENBUTN3.STI"
#define DEFAULT_GENERIC_BUTTON_ON_HI "GENBUTN4.STI"
#else
#define DEFAULT_GENERIC_BUTTON_OFF "Data\\Message Box\\GENBUTN.STI"
#define DEFAULT_GENERIC_BUTTON_ON "Data\\Message Box\\GENBUTN2.STI"
#define DEFAULT_GENERIC_BUTTON_OFF_HI "Data\\Message Box\\GENBUTN3.STI"
#define DEFAULT_GENERIC_BUTTON_ON_HI "Data\\Message Box\\GENBUTN4.STI"
#endif
#define BUTTON_TEXT_LEFT -1
#define BUTTON_TEXT_CENTER 0
#define BUTTON_TEXT_RIGHT 1
#define TEXT_LJUSTIFIED BUTTON_TEXT_LEFT
#define TEXT_CJUSTIFIED BUTTON_TEXT_CENTER
#define TEXT_RJUSTIFIED BUTTON_TEXT_RIGHT
// Some GUI_BUTTON system defines
#define BUTTON_USE_DEFAULT -1
#define BUTTON_NO_FILENAME NULL
#define BUTTON_NO_CALLBACK NULL
#define BUTTON_NO_IMAGE -1
#define BUTTON_NO_SLOT -1
#define BUTTON_INIT 1
#define BUTTON_WAS_CLICKED 2
//effects how the button is rendered.
#define BUTTON_TYPES ( BUTTON_QUICK | BUTTON_GENERIC | BUTTON_HOT_SPOT | BUTTON_CHECKBOX )
//effects how the button is processed
#define BUTTON_TYPE_MASK (BUTTON_NO_TOGGLE| BUTTON_ALLOW_DISABLED_CALLBACK | BUTTON_CHECKBOX | BUTTON_IGNORE_CLICKS )
//button flags
#define BUTTON_TOGGLE 0x00000000
#define BUTTON_QUICK 0x00000000
#define BUTTON_ENABLED 0x00000001
#define BUTTON_CLICKED_ON 0x00000002
#define BUTTON_NO_TOGGLE 0x00000004
#define BUTTON_CLICK_CALLBACK 0x00000008
#define BUTTON_MOVE_CALLBACK 0x00000010
#define BUTTON_GENERIC 0x00000020
#define BUTTON_HOT_SPOT 0x00000040
#define BUTTON_SELFDELETE_IMAGE 0x00000080
#define BUTTON_DELETION_PENDING 0x00000100
#define BUTTON_ALLOW_DISABLED_CALLBACK 0x00000200
#define BUTTON_DIRTY 0x00000400
#define BUTTON_SAVEBACKGROUND 0x00000800
#define BUTTON_CHECKBOX 0x00001000
#define BUTTON_NEWTOGGLE 0x00002000
#define BUTTON_FORCE_UNDIRTY 0x00004000 // no matter what happens this buttons does NOT get marked dirty
#define BUTTON_IGNORE_CLICKS 0x00008000 // Ignore any clicks on this button
#define BUTTON_DISABLED_CALLBACK 0x80000000
#define BUTTON_SOUND_NONE 0x00
#define BUTTON_SOUND_CLICKED_ON 0x01
#define BUTTON_SOUND_CLICKED_OFF 0x02
#define BUTTON_SOUND_MOVED_ONTO 0x04
#define BUTTON_SOUND_MOVED_OFF_OF 0x08
#define BUTTON_SOUND_DISABLED_CLICK 0x10
#define BUTTON_SOUND_DISABLED_MOVED_ONTO 0x20
#define BUTTON_SOUND_DISABLED_MOVED_OFF_OF 0x40
#define BUTTON_SOUND_ALREADY_PLAYED 0X80
#define BUTTON_SOUND_ALL_EVENTS 0xff
// Internal use!
#define GUI_SND_CLK_ON BUTTON_SOUND_CLICKED_ON
#define GUI_SND_CLK_OFF BUTTON_SOUND_CLICKED_OFF
#define GUI_SND_MOV_ON BUTTON_SOUND_MOVED_ONTO
#define GUI_SND_MOV_OFF BUTTON_SOUND_MOVED_OFF_OF
#define GUI_SND_DCLK BUTTON_SOUND_DISABLED_CLICK
#define GUI_SND_DMOV BUTTON_SOUND_DISABLED_MOVED_ONTO
extern UINT32 ButtonDestBuffer;
// GUI_BUTTON callback function type
typedef void (*GUI_CALLBACK)(struct _GUI_BUTTON *,INT32);
// GUI_BUTTON structure definitions.
typedef struct _GUI_BUTTON {
INT32 IDNum; // ID Number, contains it's own button number
UINT32 ImageNum; // Image number to use (see DOCs for details)
MOUSE_REGION Area; // Mouse System's mouse region to use for this button
GUI_CALLBACK ClickCallback; // Button Callback when button is clicked
GUI_CALLBACK MoveCallback; // Button Callback when mouse moved on this region
INT16 Cursor; // Cursor to use for this button
UINT32 uiFlags; // Button state flags etc.( 32-bit )
UINT32 uiOldFlags; // Old flags from previous render loop
INT16 XLoc; // Coordinates where button is on the screen
INT16 YLoc;
INT32 UserData[4]; // Place holder for user data etc.
INT16 Group; // Group this button belongs to (see DOCs)
INT8 bDefaultStatus;
//Button disabled style
INT8 bDisabledStyle;
//For buttons with text
UINT16 *string; //the string
UINT16 usFont; //font for text
BOOLEAN fMultiColor; //font is a multi-color font
INT16 sForeColor; //text colors if there is text
INT16 sShadowColor;
INT16 sForeColorDown; //text colors when button is down (optional)
INT16 sShadowColorDown;
INT16 sForeColorHilited; //text colors when button is down (optional)
INT16 sShadowColorHilited;
INT8 bJustification; // BUTTON_TEXT_LEFT, BUTTON_TEXT_CENTER, BUTTON_TEXT_RIGHT
INT8 bTextXOffset;
INT8 bTextYOffset;
INT8 bTextXSubOffSet;
INT8 bTextYSubOffSet;
BOOLEAN fShiftText;
INT16 sWrappedWidth;
//For buttons with icons (don't confuse this with quickbuttons which have up to 5 states )
INT32 iIconID;
INT16 usIconIndex;
INT8 bIconXOffset; //-1 means horizontally centered
INT8 bIconYOffset; //-1 means vertically centered
BOOLEAN fShiftImage; //if true, icon is shifted +1,+1 when button state is down.
UINT8 ubToggleButtonOldState; // Varibles for new toggle buttons that work
UINT8 ubToggleButtonActivated;
INT32 BackRect; // Handle to a Background Rectangle
UINT8 ubSoundSchemeID;
} GUI_BUTTON;
#define MAX_BUTTONS 400
extern GUI_BUTTON *ButtonList[MAX_BUTTONS]; // Button System's Main Button List
#define GetButtonPtr(x) (((x>=0) && (x<MAX_BUTTONS))? ButtonList[x] : NULL)
// Struct definition for the QuickButton pictures.
typedef struct {
HVOBJECT vobj; // The Image itself
INT32 Grayed; // Index to use for a "Grayed-out" button
INT32 OffNormal; // Index to use when button is OFF
INT32 OffHilite; // Index to use when button is OFF w/ hilite on it
INT32 OnNormal; // Index to use when button is ON
INT32 OnHilite; // Index to use when button is ON w/ hilite on it
UINT32 MaxWidth; // Width of largest image in use
UINT32 MaxHeight; // Height of largest image in use
UINT32 fFlags; // Special image flags
} BUTTON_PICS;
#define MAX_BUTTON_PICS 256
extern BUTTON_PICS ButtonPictures[MAX_BUTTON_PICS];
// Function protos for button system
BOOLEAN InitializeButtonImageManager(INT32 DefaultBuffer, INT32 DefaultPitch, INT32 DefaultBPP);
void ShutdownButtonImageManager(void);
BOOLEAN InitButtonSystem(void);
void ShutdownButtonSystem(void);
INT16 FindFreeIconSlot(void);
INT32 FindFreeButtonSlot(void);
INT16 FindFreeGenericSlot(void);
INT16 FindFreeIconSlot(void);
INT32 GetNextButtonNumber(void);
// Now used by Wizardry -- DB
void SetButtonFastHelpText(INT32 iButton, UINT16 * Text);
#ifdef _JA2_RENDER_DIRTY
void SetBtnHelpEndCallback( INT32 iButton, MOUSE_HELPTEXT_DONE_CALLBACK CallbackFxn );
//void DisplayFastHelp(GUI_BUTTON *b);
void RenderButtonsFastHelp(void);
#define RenderButtonsFastHelp() RenderFastHelp()
BOOLEAN SetButtonSavedRect( INT32 iButton );
void FreeButtonSavedRect( INT32 iButton );
#endif
template <typename string1>
INT16 LoadGenericButtonIcon(string1 filename);
BOOLEAN UnloadGenericButtonIcon(INT16 GenImg);
template <typename type1>
INT32 LoadButtonImage(type1 filename, INT32 Grayed, INT32 OffNormal, INT32 OffHilite, INT32 OnNormal, INT32 OnHilite);
INT32 UseLoadedButtonImage(INT32 LoadedImg, INT32 Grayed, INT32 OffNormal, INT32 OffHilite, INT32 OnNormal, INT32 OnHilite);
INT32 UseVObjAsButtonImage(HVOBJECT hVObject, INT32 Grayed, INT32 OffNormal, INT32 OffHilite, INT32 OnNormal, INT32 OnHilite);
void UnloadButtonImage(INT32 Index);
INT16 LoadGenericButtonImages(UINT8 *GrayName,UINT8 *OffNormName,UINT8 *OffHiliteName,UINT8 *OnNormName,UINT8 *OnHiliteName,UINT8 *BkGrndName,INT16 Index,INT16 OffsetX, INT16 OffsetY);
BOOLEAN UnloadGenericButtonImage(INT16 GenImg);
BOOLEAN SetButtonDestBuffer(UINT32 DestBuffer);
BOOLEAN EnableButton(INT32 iButtonID);
BOOLEAN DisableButton(INT32 iButtonID);
void RemoveButton(INT32 iButtonID );
void HideButton( INT32 iButtonID );
void ShowButton( INT32 iButton );
void RenderButtons(void);
BOOLEAN DrawButton(INT32 iButtonID);
void DrawButtonFromPtr(GUI_BUTTON *b);
//Base button types
void DrawGenericButton(GUI_BUTTON *b);
void DrawQuickButton(GUI_BUTTON *b);
void DrawCheckBoxButton( GUI_BUTTON *b );
//Additional layers on buttons that can exist in any combination on generic or quick buttons
//To do so, use the new specify functions below.
void DrawIconOnButton(GUI_BUTTON *b);
void DrawTextOnButton(GUI_BUTTON *b);
extern BOOLEAN gfRenderHilights;
#define EnableHilightsAndHelpText() gfRenderHilights = TRUE;
#define DisableHilightsAndHelpText() gfRenderHilights = FALSE;
//Providing you have allocated your own image, this is a somewhat simplified function.
INT32 QuickCreateButton(UINT32 Image, INT16 xloc, INT16 yloc, INT32 Type,INT16 Priority,GUI_CALLBACK MoveCallback,GUI_CALLBACK ClickCallback);
//A hybrid of QuickCreateButton. Takes a lot less parameters, but makes more assumptions. It self manages the
//loading, and deleting of the image. The size of the image determines the size of the button. It also uses
//the default move callback which emulates Win95. Finally, it sets the priority to normal. The function you
//choose also determines the type of button (toggle, notoggle, or newtoggle)
template <typename string3>
INT32 CreateEasyNoToggleButton ( INT32 x, INT32 y, string3 filename, GUI_CALLBACK ClickCallback );
template <typename string3>
INT32 CreateEasyToggleButton ( INT32 x, INT32 y, string3 filename, GUI_CALLBACK ClickCallback );
template <typename string3>
INT32 CreateEasyNewToggleButton( INT32 x, INT32 y, string3 filename, GUI_CALLBACK ClickCallback );
//Same as above, but accepts specify toggle type
template <typename string3>
INT32 CreateEasyButton( INT32 x, INT32 y, string3 filename, INT32 Type, GUI_CALLBACK ClickCallback);
//Same as above, but accepts priority specification.
template <typename string3>
INT32 CreateSimpleButton( INT32 x, INT32 y, string3 filename, INT32 Type, INT16 Priority, GUI_CALLBACK ClickCallback );
template <typename string3>
INT32 CreateCheckBoxButton( INT16 x, INT16 y, string3 filename, INT16 Priority, GUI_CALLBACK ClickCallback );
INT32 CreateIconButton(INT16 Icon,INT16 IconIndex,INT16 GenImg,INT16 xloc,INT16 yloc,INT16 w,INT16 h,INT32 Type,INT16 Priority,GUI_CALLBACK MoveCallback,GUI_CALLBACK ClickCallback);
INT32 CreateHotSpot(INT16 xloc, INT16 yloc, INT16 Width, INT16 Height,INT16 Priority,GUI_CALLBACK MoveCallback,GUI_CALLBACK ClickCallback);
INT32 CreateTextButton(UINT16 *string, UINT32 uiFont, INT16 sForeColor, INT16 sShadowColor, INT16 GenImg, INT16 xloc, INT16 yloc, INT16 w, INT16 h, INT32 Type, INT16 Priority,GUI_CALLBACK MoveCallback, GUI_CALLBACK ClickCallback);
template <typename string2>
INT32 CreateIconAndTextButton( INT32 Image, string2 string, UINT32 uiFont,
INT16 sForeColor, INT16 sShadowColor,
INT16 sForeColorDown, INT16 sShadowColorDown,
INT8 bJustification,
INT16 xloc, INT16 yloc, INT32 Type, INT16 Priority,
GUI_CALLBACK MoveCallback,GUI_CALLBACK ClickCallback);
//New functions
void SpecifyButtonText( INT32 iButtonID, UINT16 * string );
void SpecifyButtonFont( INT32 iButtonID, UINT32 uiFont );
void SpecifyButtonMultiColorFont(INT32 iButtonID, BOOLEAN fMultiColor);
void SpecifyButtonUpTextColors( INT32 iButtonID, INT16 sForeColor, INT16 sShadowColor );
void SpecifyButtonDownTextColors( INT32 iButtonID, INT16 sForeColorDown, INT16 sShadowColorDown );
void SpecifyButtonHilitedTextColors( INT32 iButtonID, INT16 sForeColorHilited, INT16 sShadowColorHilited );
void SpecifyButtonTextJustification( INT32 iButtonID, INT8 bJustification );
void SpecifyGeneralButtonTextAttributes( INT32 iButtonID, UINT16 *string, INT32 uiFont,
INT16 sForeColor, INT16 sShadowColor );
void SpecifyFullButtonTextAttributes( INT32 iButtonID, UINT16 *string, INT32 uiFont,
INT16 sForeColor, INT16 sShadowColor,
INT16 sForeColorDown, INT16 sShadowColorDown, INT8 bJustification );
void SpecifyGeneralButtonTextAttributes( INT32 iButtonID, UINT16 *string, INT32 uiFont,
INT16 sForeColor, INT16 sShadowColor );
void SpecifyButtonTextOffsets( INT32 iButtonID, INT8 bTextXOffset, INT8 bTextYOffset, BOOLEAN fShiftText );
void SpecifyButtonTextSubOffsets( INT32 iButtonID, INT8 bTextXOffset, INT8 bTextYOffset, BOOLEAN fShiftText );
void SpecifyButtonTextWrappedWidth(INT32 iButtonID, INT16 sWrappedWidth);
void SpecifyButtonSoundScheme( INT32 iButtonID, INT8 bSoundScheme );
void PlayButtonSound( INT32 iButtonID, INT32 iSoundType );
void AllowDisabledButtonFastHelp( INT32 iButtonID, BOOLEAN fAllow );
enum{
DEFAULT_STATUS_NONE,
DEFAULT_STATUS_DARKBORDER, //shades the borders 2 pixels deep
DEFAULT_STATUS_DOTTEDINTERIOR, //draws the familiar dotted line in the interior portion of the button.
DEFAULT_STATUS_WINDOWS95, //both DARKBORDER and DOTTEDINTERIOR
};
void GiveButtonDefaultStatus( INT32 iButtonID, INT32 iDefaultStatus );
void RemoveButtonDefaultStatus( INT32 iButtonID );
enum //for use with SpecifyDisabledButtonStyle
{
DISABLED_STYLE_NONE, //for dummy buttons, panels, etc. Always displays normal state.
DISABLED_STYLE_DEFAULT, //if button has text then shade, else hatch
DISABLED_STYLE_HATCHED, //always hatches the disabled button
DISABLED_STYLE_SHADED //always shades the disabled button 25% darker
};
void SpecifyDisabledButtonStyle( INT32 iButtonID, INT8 bStyle );
void RemoveTextFromButton( INT32 iButtonID );
void RemoveIconFromButton( INT32 iButtonID );
//Note: Text is always on top
//If fShiftImage is true, then the image will shift down one pixel and right one pixel
//just like the text does.
BOOLEAN SpecifyButtonIcon( INT32 iButtonID, INT32 iVideoObjectID, UINT16 usVideoObjectIndex,
INT8 bXOffset, INT8 bYOffset, BOOLEAN fShiftImage );
void SetButtonPosition(INT32 iButtonID,INT16 x, INT16 y);
void ResizeButton(INT32 iButtonID,INT16 w, INT16 h);
void QuickButtonCallbackMMove(MOUSE_REGION *reg,INT32 reason);
void QuickButtonCallbackMButn(MOUSE_REGION *reg,INT32 reason);
BOOLEAN SetButtonCursor(INT32 iBtnId, UINT16 crsr);
void MSYS_SetBtnUserData(INT32 iButtonNum,INT32 index,INT32 userdata);
INT32 MSYS_GetBtnUserData(GUI_BUTTON *b,INT32 index);
void MarkAButtonDirty( INT32 iButtonNum ); // will mark only selected button dirty
void MarkButtonsDirty(void);// Function to mark buttons dirty ( all will redraw at next RenderButtons )
void PausedMarkButtonsDirty( void ); // mark buttons dirty for button render the frame after the next
void UnMarkButtonDirty( INT32 iButtonIndex ); // unmark button
void UnmarkButtonsDirty( void ); // unmark ALL the buttoms on the screen dirty
void ForceButtonUnDirty( INT32 iButtonIndex ); // forces button undirty no matter the reason, only lasts one frame
// DB 98-05-05
BOOLEAN GetButtonArea(INT32 iButtonID, SGPRect *pRect);
// DB 99-01-13
INT32 GetButtonWidth(INT32 iButtonID);
INT32 GetButtonHeight(INT32 iButtonID);
// DB 99-08-27
INT32 GetButtonX(INT32 iButtonID);
INT32 GetButtonY(INT32 iButtonID);
void BtnGenericMouseMoveButtonCallback(GUI_BUTTON *btn,INT32 reason);
#define DEFAULT_MOVE_CALLBACK BtnGenericMouseMoveButtonCallback
void DrawCheckBoxButtonOn( INT32 iButtonID );
void DrawCheckBoxButtonOff( INT32 iButtonID );
extern UINT16 GetWidthOfButtonPic( UINT16 usButtonPicID, INT32 iSlot );
#endif
+165
View File
@@ -0,0 +1,165 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "MemMan.h"
#include "debug.h"
#include "zlib.h"
#endif
// mem allocation functions for ZLIB's purposes
voidpf ZAlloc( voidpf opaque, uInt items, uInt size )
{
return( MemAlloc( items * size ) );
}
void ZFree( voidpf opaque, voidpf address )
{
MemFree( address );
}
PTR DecompressInit( BYTE * pCompressedData, UINT32 uiDataSize )
{
z_stream * pZStream;
int iZRetCode;
// allocate memory for the z_stream struct
pZStream = MemAlloc( sizeof( z_stream ) );
if( pZStream == NULL )
{ // out of memory!
return( NULL );
}
// initial defines
pZStream->zalloc = ZAlloc;
pZStream->zfree = ZFree;
pZStream->opaque = NULL;
// call the ZLIB init routine
iZRetCode = inflateInit( pZStream );
if( iZRetCode != Z_OK )
{ // ZLIB init error!
MemFree( pZStream );
return( NULL );
}
// set up our parameters
pZStream->next_in = pCompressedData;
pZStream->avail_in = uiDataSize;
return( (PTR) pZStream );
}
UINT32 Decompress( PTR pDecompPtr, BYTE * pBuffer, UINT32 uiBufferLen )
{
int iZRetCode;
z_stream * pZStream = (z_stream *) pDecompPtr;
// these assertions is in here to ensure that we get passed a proper z_stream pointer
Assert( pZStream != NULL );
Assert( pZStream->zalloc == ZAlloc );
if (pZStream->avail_in == 0)
{ // There is nothing left to decompress!
return( 0 );
}
// set up the z_stream with our parameters
pZStream->next_out = pBuffer;
pZStream->avail_out = uiBufferLen;
// decompress!
iZRetCode = inflate( pZStream, Z_PARTIAL_FLUSH );
Assert( iZRetCode == Z_OK || iZRetCode == Z_STREAM_END );
return( uiBufferLen - pZStream->avail_out );
}
void DecompressFini( PTR pDecompPtr )
{
z_stream * pZStream = (z_stream *) pDecompPtr;
// these assertions is in here to ensure that we get passed a proper z_stream pointer
Assert( pZStream != NULL );
Assert( pZStream->zalloc == ZAlloc );
inflateEnd( pZStream );
MemFree( pZStream );
}
UINT32 CompressedBufferSize( UINT32 uiDataSize )
{ // Function that calculates the worst-case buffer size needed to
// hold uiDataSize bytes compressed
return( uiDataSize + uiDataSize / 10 + 13 );
}
PTR CompressInit( BYTE * pUncompressedData, UINT32 uiDataSize )
{
z_stream * pZStream;
int iZRetCode;
// allocate memory for the z_stream struct
pZStream = MemAlloc( sizeof( z_stream ) );
if( pZStream == NULL )
{ // out of memory!
return( NULL );
}
// initial defines
pZStream->zalloc = ZAlloc;
pZStream->zfree = ZFree;
pZStream->opaque = NULL;
// call the ZLIB init routine
iZRetCode = deflateInit( pZStream, Z_BEST_COMPRESSION );
if( iZRetCode != Z_OK )
{ // ZLIB init error!
MemFree( pZStream );
return( NULL );
}
// set up our parameters
pZStream->next_in = pUncompressedData;
pZStream->avail_in = uiDataSize;
return( (PTR) pZStream );
}
UINT32 Compress( PTR pCompPtr, BYTE * pBuffer, UINT32 uiBufferLen )
{
int iZRetCode;
z_stream * pZStream = (z_stream *) pCompPtr;
// these assertions is in here to ensure that we get passed a proper z_stream pointer
Assert( pZStream != NULL );
Assert( pZStream->zalloc == ZAlloc );
if (pZStream->avail_in == 0)
{ // There is nothing left to compress!
return( 0 );
}
// set up the z_stream with our parameters
pZStream->next_out = pBuffer;
pZStream->avail_out = uiBufferLen;
// decompress!
iZRetCode = deflate( pZStream, Z_FINISH );
Assert( iZRetCode == Z_STREAM_END );
return( uiBufferLen - pZStream->avail_out );
}
void CompressFini( PTR pCompPtr )
{
z_stream * pZStream = (z_stream *) pCompPtr;
// these assertions is in here to ensure that we get passed a proper z_stream pointer
Assert( pZStream != NULL );
Assert( pZStream->zalloc == ZAlloc );
deflateEnd( pZStream );
MemFree( pZStream );
}
+52
View File
@@ -0,0 +1,52 @@
#if !defined( COMPRESSION_H )
#define COMPRESSION_H
#include "types.h"
// Notes on how to use these functions without getting your hands dirty:
// To decompress:
//
// 1) call DecompressInit() with a pointer to your compressed data, and the
// size of that compressed data. DecompressInit() returns a "decompression
// pointer" that you should pass to Decompress() and DecompressFini()
//
// 2) call Decompress() with the decompression pointer, a pointer to a
// buffer for decompressed data, and the length of that buffer. If the
// buffer is not large enough to hold all of the decompressed data,
// Decompress() will fill it completely, and you can call Decompress() again
// to continue your decompression. You are responsible for knowing the
// size your data will be after decompression. (The STI/STCI file format
// records your original data size for you...) Decompress() returns the
// number of bytes of output.
//
// 3) call DecompressFini() with the decompression pointer when you're done
PTR DecompressInit( BYTE * pCompressedData, UINT32 uiDataSize );
UINT32 Decompress( PTR pDecompPtr, BYTE * pBuffer, UINT32 uiBufferLen );
void DecompressFini( PTR pDecompPtr );
// To compress:
//
// 1) call CompressInit() with a pointer to your uncompressed data, and the
// size of that uncompressed data. CompressInit() returns a "compression
// pointer" that you should pass to Compress() and CompressFini()
//
// 2) call Compress() with the compression pointer, a pointer to a
// buffer for compressed data, and the length of that buffer. If the
// buffer is not large enough to hold all of the compressed data,
// Compress() will fill it completely, and you can call Compress() again
// with a new or emptied buffer to continue your compression later. You
// can call CompressedBufferSize() to determine the largest buffer size you
// should need for a certain number of bytes. Ccompress() returns the number
// of bytes of output.
//
// 3) call CompressFini() with the compression pointer when you're done
UINT32 CompressedBufferSize( UINT32 uiDataSize );
PTR CompressInit( BYTE * pUncompressedData, UINT32 uiDataSize );
UINT32 Compress( PTR pCompPtr, BYTE * pBuffer, UINT32 uiBufferLen );
void CompressFini( PTR pCompPtr );
#endif
File diff suppressed because it is too large Load Diff
+132
View File
@@ -0,0 +1,132 @@
//***********************************************
//
// Filename : Container.h
//
// Purpose : prototypes for the container file
//
// Modification History : 25 Nov 96 Creation
//
//***********************************************
#ifndef _CONTAINER_H
#define _CONTAINER_H
//***********************************************
//
// Includes
//
//
//***********************************************
#include "types.h"
//***********************************************
//
// Defines and typedefs
//
//***********************************************
#define ORDLIST_ERROR -1
#define ORDLIST_EQUAL 0
#define ORDLIST_LEFT_LESS 1
#define ORDLIST_RIGHT_LESS 2
typedef void * HCONTAINER;
typedef HCONTAINER HSTACK;
typedef HCONTAINER HQUEUE;
typedef HCONTAINER HLIST;
typedef HCONTAINER HORDLIST;
//***********************************************
//
// Function Prototypes
//
//***********************************************
#ifdef __cplusplus
extern "C" {
#endif
// call these functions to initialize and shutdown the debug messages for
// containers
extern void InitializeContainers(void);
extern void ShutdownContainers(void);
// Stack Functions
// CreateStack(estimated number of items in stack, size of each item
// Push(handle to container returned from CreateStack, data to be passed in (must be void *)
// : returns handle to new stack
// Pop(handle to container returned from CreateStack, data to be passed in (must be void *)
// : returns BOOLEAN
// DeleteStack deletes the stack container
// StackSize returns size of stack
extern HSTACK CreateStack(UINT32 num_of_elem , UINT32 siz_of_each);
extern HSTACK Push(HSTACK hStack, void *data);
extern BOOLEAN Pop(HSTACK hStack, void *data);
extern UINT32 StackSize(HSTACK hStack);
extern BOOLEAN DeleteStack(HSTACK hStack);
extern BOOLEAN PeekStack(HSTACK hStack, void *data);
// Queue Functions
// CreateQueue(estimated number of items in queue, size of each item
// AddtoQueue(handle to container returned from CreateQueue, data to be passed in (must be void *))
// : returns handle to queue
// RemfromQueue(handle to container returned from CreateQueue, variable where data is stored (must be void *))
// : returns BOOLEAN
// PeekQueue(handle to the queue, variable where peeked data is stored). Item is not deleted.
// : returns BOOLEAN
// QueueSize(handle to the queue) returns the queue size
// DeleteQueue(handle to container) Delete the queue container
// : returns BOOLEAN
extern HQUEUE CreateQueue(UINT32 num_of_elem, UINT32 siz_of_each);
extern HQUEUE AddtoQueue(HQUEUE hQueue, void *data);
extern BOOLEAN RemfromQueue(HQUEUE hQueue,void *data);
extern BOOLEAN PeekQueue(HQUEUE hQueue, void *data);
extern UINT32 QueueSize(HQUEUE hQueue);
extern BOOLEAN DeleteQueue(HQUEUE hQueue);
// List Functions
// CreateList(estimated number of items in queue, size of each item
// AddtoList(handle to container returned from CreateQueue, data to be passed in (must be void *)
// position where data is to be added (0...sizeof(list))
// : returns handle to new list
// RemfromList(handle to container returned from CreateList, variable where data is stored (must be void *)
// position where data is to be deleted (0...sizeof(list)-1)
// PeekList(handle to the list, variable where peeked data is stored). Item is not deleted.
// position where data is to be peeked (0...sizeof(list)-1)
// ListSize(handle to the list) returns the list size
// DeleteList(handle to the list) Delete the list container
extern HLIST CreateList(UINT32 num_of_elem, UINT32 siz_of_each);
extern HLIST AddtoList(HLIST hList, void *data, UINT32 position);
extern BOOLEAN RemfromList(HLIST hList,void *data, UINT32 position);
extern BOOLEAN PeekList(HLIST hList, void *data, UINT32 position);
extern UINT32 ListSize(HLIST hList);
extern BOOLEAN DeleteList(HLIST hList);
extern BOOLEAN SwapListNode(HLIST hList, void *pdata, UINT32 uiPos);
extern BOOLEAN StoreListNode(HLIST hList, void *pdata, UINT32 uiPos);
// Ordered List Functions
// CreateOrdList(estimated number of items in ordered list, size of each item,
// pointer to a compare function that returns info on whether the data in the ordered stack
// is < or > the new data to be added into the ordered list.
// AddtoOrdList(handle to container returned from CreateOrdList, data to be passed in (must be void *)
// RemfromOrdList(handle to container returned from CreateList, variable where data is stored (must be void *)
// position where data is to be deleted (0...sizeof(list)-1)
// PeekOrdList(handle to the list, variable where peeked data is stored). Item is not deleted.
// position where data is to be peeked (0...sizeof(list)-1)
// OrdListSize(handle to the list) returns the ordered list size
// DeleteOrdList(handle to the list) Delete the ordered list container
extern HLIST CreateOrdList(UINT32 num_of_elem, UINT32 siz_of_each, INT8 (*compare)(void *,void *, UINT32));
extern HLIST AddtoOrdList(HLIST hList, void *data);
extern BOOLEAN RemfromOrdList(HLIST hList,void *data, UINT32 position);
extern BOOLEAN PeekOrdList(HLIST hList, void *data, UINT32 position);
extern UINT32 OrdListSize(HLIST hList);
extern BOOLEAN DeleteOrdList(HLIST hList);
#ifdef __cplusplus
}
#endif
#endif
+653
View File
@@ -0,0 +1,653 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "Cursor Control.h"
#if defined( JA2 ) || defined( UTIL )
#include "video.h"
#else
#include "video2.h"
#endif
#include "wcheck.h"
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Cursor Database
//
///////////////////////////////////////////////////////////////////////////////////////////////////
BOOLEAN gfCursorDatabaseInit = FALSE;
CursorFileData *gpCursorFileDatabase;
CursorData *gpCursorDatabase;
INT16 gsGlobalCursorYOffset = 0;
INT16 gsCurMouseOffsetX = 0;
INT16 gsCurMouseOffsetY = 0;
UINT16 gsCurMouseHeight = 0;
UINT16 gsCurMouseWidth = 0;
UINT16 gusNumDataFiles = 0;
UINT32 guiExternVo;
UINT16 gusExternVoSubIndex;
UINT32 guiExtern2Vo;
UINT16 gusExtern2VoSubIndex;
UINT32 guiOldSetCursor = 0;
UINT32 guiDelayTimer = 0;
MOUSEBLT_HOOK gMouseBltOverride = NULL;
BOOLEAN BltToMouseCursorFromVObject( HVOBJECT hVObject, UINT16 usVideoObjectSubIndex, UINT16 usXPos, UINT16 usYPos )
{
BOOLEAN ReturnValue;
ReturnValue = BltVideoObject(MOUSE_BUFFER, hVObject, usVideoObjectSubIndex, usXPos, usYPos, VO_BLT_SRCTRANSPARENCY, NULL);
return ReturnValue;
}
BOOLEAN BltToMouseCursorFromVObjectWithOutline( HVOBJECT hVObject, UINT16 usVideoObjectSubIndex, UINT16 usXPos, UINT16 usYPos )
{
BOOLEAN ReturnValue;
ETRLEObject *pTrav;
INT16 sXPos, sYPos;
// Adjust for offsets
pTrav = &(hVObject->pETRLEObject[ usVideoObjectSubIndex ] );
sXPos = 0;
sYPos = 0;
// Remove offsets...
sXPos -= pTrav->sOffsetX;
sYPos -= pTrav->sOffsetY;
// Center!
sXPos += ( ( gsCurMouseWidth - pTrav->usWidth ) / 2 );
sYPos += ( ( gsCurMouseHeight - pTrav->usHeight ) / 2 );
ReturnValue = BltVideoObjectOutline(MOUSE_BUFFER, hVObject, usVideoObjectSubIndex, sXPos, sYPos, Get16BPPColor( FROMRGB( 0, 255, 0 ) ), TRUE );
return ReturnValue;
}
// THESE TWO PARAMETERS MUST POINT TO STATIC OR GLOBAL DATA, NOT AUTOMATIC VARIABLES
void InitCursorDatabase( CursorFileData *pCursorFileData, CursorData *pCursorData, UINT16 suNumDataFiles )
{
// Set global values!
gpCursorFileDatabase = pCursorFileData;
gpCursorDatabase = pCursorData;
gusNumDataFiles = suNumDataFiles;
gfCursorDatabaseInit = TRUE;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Cursor Handlers
//
///////////////////////////////////////////////////////////////////////////////////////////////////
BOOLEAN LoadCursorData(UINT32 uiCursorIndex)
{
// Load cursor data will load all data required for the cursor specified by this index
CursorData *pCurData;
CursorImage *pCurImage;
UINT32 cnt;
INT16 sMaxHeight = -1;
INT16 sMaxWidth = -1;
ETRLEObject *pTrav;
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
{
pCurImage = &( pCurData->Composites[ cnt ] );
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].fLoaded == FALSE )
{
//
// The file containing the video object hasn't been loaded yet. Let's load it now
//
VOBJECT_DESC VideoObjectDescription;
// FIRST LOAD AS AN HIMAGE SO WE CAN GET AUX DATA!
HIMAGE hImage;
AuxObjectData *pAuxData;
// ATE: First check if we are using an extern vo cursor...
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags & USE_EXTERN_VO_CURSOR )
{
// Let's check if we have NOT NULL here...
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject == NULL )
{
// Something wrong here...
}
}
else
{
hImage = CreateImage( (CHAR8 *)gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFilename, IMAGE_ALLDATA );
if (hImage == NULL)
{
return( FALSE );
}
VideoObjectDescription.fCreateFlags = VOBJECT_CREATE_FROMHIMAGE;
VideoObjectDescription.hImage = hImage;
if ( !AddVideoObject( &VideoObjectDescription, &( gpCursorFileDatabase[ pCurImage->uiFileIndex ].uiIndex) ) )
{
return( FALSE );
}
// Check for animated tile
if (hImage->uiAppDataSize > 0 )
{
// Valid auxiliary data, so get # od frames from data
pAuxData = ( AuxObjectData* ) hImage->pAppData;
if ( pAuxData->fFlags & AUX_ANIMATED_TILE )
{
gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags |= ANIMATED_CURSOR;
gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubNumberOfFrames = pAuxData->ubNumberOfFrames;
}
}
// the hImage is no longer needed
DestroyImage( hImage );
// Save hVObject....
GetVideoObject( &(gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject), gpCursorFileDatabase[ pCurImage->uiFileIndex ].uiIndex );
}
gpCursorFileDatabase[ pCurImage->uiFileIndex ].fLoaded = TRUE;
}
// Get ETRLE Data for this video object
pTrav = &(gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject->pETRLEObject[ pCurImage->uiSubIndex ] );
if( !pTrav )
{
return FALSE;
}
if ( pTrav->usHeight > sMaxHeight )
{
sMaxHeight = pTrav->usHeight;
}
if ( pTrav->usWidth > sMaxWidth )
{
sMaxWidth = pTrav->usWidth;
}
}
pCurData->usHeight = sMaxHeight;
pCurData->usWidth = sMaxWidth;
if ( pCurData->sOffsetX == CENTER_CURSOR )
{
pCurData->sOffsetX = ( pCurData->usWidth / 2 );
}
if ( pCurData->sOffsetX == RIGHT_CURSOR )
{
pCurData->sOffsetX = pCurData->usWidth;
}
if ( pCurData->sOffsetX == LEFT_CURSOR )
{
pCurData->sOffsetX = 0;
}
if ( pCurData->sOffsetY == CENTER_CURSOR )
{
pCurData->sOffsetY = ( pCurData->usHeight / 2 );
}
if ( pCurData->sOffsetY == BOTTOM_CURSOR )
{
pCurData->sOffsetY = pCurData->usHeight;
}
if ( pCurData->sOffsetY == TOP_CURSOR )
{
pCurData->sOffsetY = 0;
}
gsCurMouseOffsetX = pCurData->sOffsetX;
gsCurMouseOffsetY = pCurData->sOffsetY;
gsCurMouseHeight = pCurData->usHeight;
gsCurMouseWidth = pCurData->usWidth;
// Adjust relative offsets
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
{
pCurImage = &( pCurData->Composites[ cnt ] );
// Get ETRLE Data for this video object
pTrav = &(gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject->pETRLEObject[ pCurImage->uiSubIndex ] );
if( !pTrav )
{
return FALSE;
}
if ( pCurImage->usPosX == CENTER_SUBCURSOR )
{
pCurImage->usPosX = pCurData->sOffsetX - ( pTrav->usWidth / 2 );
}
if ( pCurImage->usPosY == CENTER_SUBCURSOR )
{
pCurImage->usPosY = pCurData->sOffsetY - ( pTrav->usHeight / 2 );
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void UnLoadCursorData(UINT32 uiCursorIndex)
{
// This function will unload add data used for this cursor
//
// Ok, first we make sure that the video object file is indeed loaded. Once this is verified, we will
// move on to the deletion
//
CursorData *pCurData;
CursorImage *pCurImage;
UINT32 cnt;
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
{
pCurImage = &( pCurData->Composites[ cnt ] );
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].fLoaded )
{
if ( !( gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags & USE_EXTERN_VO_CURSOR ) )
{
DeleteVideoObjectFromIndex( gpCursorFileDatabase[ pCurImage->uiFileIndex ].uiIndex);
gpCursorFileDatabase[ pCurImage->uiFileIndex ].uiIndex = 0;
}
gpCursorFileDatabase[ pCurImage->uiFileIndex ].fLoaded = FALSE;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void CursorDatabaseClear(void)
{
UINT32 uiIndex;
for (uiIndex = 0; uiIndex < gusNumDataFiles; uiIndex++)
{
if (gpCursorFileDatabase[uiIndex].fLoaded == TRUE)
{
if ( !( gpCursorFileDatabase[ uiIndex ].ubFlags & USE_EXTERN_VO_CURSOR ) )
{
DeleteVideoObjectFromIndex( gpCursorFileDatabase[uiIndex].uiIndex);
gpCursorFileDatabase[uiIndex].uiIndex = 0;
}
gpCursorFileDatabase[uiIndex].fLoaded = FALSE;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
BOOLEAN SetCurrentCursorFromDatabase( UINT32 uiCursorIndex )
{
#ifdef JA2
BOOLEAN ReturnValue = TRUE;
UINT16 usSubIndex;
CursorData *pCurData;
CursorImage *pCurImage;
UINT32 cnt;
INT16 sCenterValX, sCenterValY;
HVOBJECT hVObject;
ETRLEObject *pTrav;
UINT16 usEffHeight, usEffWidth;
if ( gfCursorDatabaseInit )
{
// Enter mouse buffer mutex
//EnterMutex(MOUSE_BUFFER_MUTEX, __LINE__, __FILE__);
// If the current cursor is the first index, disable cursors
if ( uiCursorIndex == VIDEO_NO_CURSOR )
{
EraseMouseCursor( );
SetMouseCursorProperties( 0, 0, 5, 5 );
DirtyCursor( );
//EnableCursor( FALSE );
}
else
{
// CHECK FOR EXTERN CURSOR
if ( uiCursorIndex == EXTERN_CURSOR || uiCursorIndex == EXTERN2_CURSOR )
{
INT16 sSubX, sSubY;
HVOBJECT hVObjectTemp;
ETRLEObject *pTravTemp;
// Erase old cursor
EraseMouseCursor( );
if ( uiCursorIndex == EXTERN2_CURSOR )
{
// Get ETRLE values
GetVideoObject( &hVObject, guiExtern2Vo );
pTrav = &(hVObject->pETRLEObject[ gusExtern2VoSubIndex ] );
}
else
{
// Get ETRLE values
GetVideoObject( &hVObject, guiExternVo );
pTrav = &(hVObject->pETRLEObject[ gusExternVoSubIndex ] );
}
// Determine center
sCenterValX = 0;
sCenterValY = 0;
// Effective height
usEffHeight = pTrav->usHeight + pTrav->sOffsetY;
usEffWidth = pTrav->usWidth + pTrav->sOffsetX;
// ATE: Check for extern 2nd...
if ( uiCursorIndex == EXTERN2_CURSOR )
{
BltVideoObjectOutlineFromIndex( MOUSE_BUFFER, guiExtern2Vo, gusExtern2VoSubIndex, 0, 0, 0, FALSE );
// Get ETRLE values
GetVideoObject( &hVObjectTemp, guiExternVo );
pTravTemp = &(hVObjectTemp->pETRLEObject[ gusExternVoSubIndex ] );
sSubX = ( pTrav->usWidth - pTravTemp->usWidth - pTravTemp->sOffsetX ) / 2;
sSubY = ( pTrav->usHeight - pTravTemp->usHeight - pTravTemp->sOffsetY ) / 2;
BltVideoObjectOutlineFromIndex( MOUSE_BUFFER, guiExternVo, gusExternVoSubIndex, sSubX, sSubY, 0, FALSE );
}
else
{
BltVideoObjectOutlineFromIndex( MOUSE_BUFFER, guiExternVo, gusExternVoSubIndex, 0, 0, 0, FALSE );
}
// Hook into hook function
if ( gMouseBltOverride != NULL )
{
gMouseBltOverride( );
}
#ifdef JA2
SetMouseCursorProperties( (INT16)(usEffWidth/2), (INT16)(usEffHeight/2), (UINT16)(usEffHeight), (UINT16)(usEffWidth ) );
#else
SetMouseCursorProperties( sCenterValY, (INT16)( sCenterValY + gsGlobalCursorYOffset ), MAX_CURSOR_HEIGHT, MAX_CURSOR_WIDTH );
#endif
DirtyCursor( );
}
else
{
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
// First check if we are a differnet curosr...
if ( uiCursorIndex != guiOldSetCursor )
{
// OK, check if we are a delay cursor...
if ( pCurData->bFlags & DELAY_START_CURSOR )
{
guiDelayTimer = GetTickCount( );
}
}
guiOldSetCursor = uiCursorIndex;
// Olny update if delay timer has elapsed...
if ( pCurData->bFlags & DELAY_START_CURSOR )
{
if ( ( GetTickCount( ) - guiDelayTimer ) < 1000 )
{
EraseMouseCursor( );
SetMouseCursorProperties( 0, 0, 5, 5 );
DirtyCursor( );
return( TRUE );
}
}
//
// Call LoadCursorData to make sure that the video object is loaded
//
LoadCursorData(uiCursorIndex);
// Erase old cursor
EraseMouseCursor( );
// NOW ACCOMODATE COMPOSITE CURSORS
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
{
// Check if we are a flashing cursor!
if ( pCurData->bFlags & CURSOR_TO_FLASH )
{
if ( cnt <= 1 )
{
if ( pCurData->bFlashIndex != cnt )
{
continue;
}
}
}
// Check if we are a sub cursor!
// IN this case, do all frames but
// skip the 1st or second!
if ( pCurData->bFlags & CURSOR_TO_SUB_CONDITIONALLY )
{
if ( pCurData->bFlags & CURSOR_TO_FLASH )
{
if ( cnt <= 1 )
{
if ( pCurData->bFlashIndex != cnt )
{
continue;
}
}
}
else if ( pCurData->bFlags & CURSOR_TO_FLASH2 )
{
if ( cnt <= 2 && cnt > 0 )
{
if ( pCurData->bFlashIndex != cnt )
{
continue;
}
}
}
else
{
if ( cnt <= 1 )
{
if ( pCurData->bFlashIndex != cnt )
{
continue;
}
}
}
}
pCurImage = &( pCurData->Composites[ cnt ] );
// Adjust sub-index if cursor is animated
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex].ubFlags & ANIMATED_CURSOR )
{
usSubIndex = (UINT16)pCurImage->uiCurrentFrame;
}
else
{
usSubIndex = pCurImage->uiSubIndex;
}
if ( pCurImage->usPosX != HIDE_SUBCURSOR && pCurImage->usPosY != HIDE_SUBCURSOR )
{
// Blit cursor at position in mouse buffer
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex].ubFlags & USE_OUTLINE_BLITTER )
{
ReturnValue = BltToMouseCursorFromVObjectWithOutline( gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject , usSubIndex, pCurImage->usPosX, pCurImage->usPosY );
}
else
{
ReturnValue = BltToMouseCursorFromVObject( gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject , usSubIndex, pCurImage->usPosX, pCurImage->usPosY );
}
if ( !ReturnValue )
{
return( FALSE );
}
}
//if ( pCurData->bFlags & CURSOR_TO_FLASH )
//{
// break;
//}
}
// Hook into hook function
if ( gMouseBltOverride != NULL )
{
gMouseBltOverride( );
}
sCenterValX = pCurData->sOffsetX;
sCenterValY = pCurData->sOffsetY;
#ifdef JA2
SetMouseCursorProperties( sCenterValX, (INT16)( sCenterValY + gsGlobalCursorYOffset ), pCurData->usHeight, pCurData->usWidth );
#else
SetMouseCursorProperties( sCenterValY, (INT16)( sCenterValY + gsGlobalCursorYOffset ), MAX_CURSOR_HEIGHT, MAX_CURSOR_WIDTH );
#endif
DirtyCursor( );
}
}
}
else
{
if ( uiCursorIndex == VIDEO_NO_CURSOR )
{
EraseMouseCursor( );
SetMouseCursorProperties( 0, 0, 5, 5 );
DirtyCursor( );
//EnableCursor( FALSE );
}
else
{
SetCurrentCursor( (UINT16)uiCursorIndex, 0, 0 );
ReturnValue = TRUE;
}
}
return ( ReturnValue );
#else
return(0);
#endif
}
void SetMouseBltHook( MOUSEBLT_HOOK pMouseBltOverride )
{
gMouseBltOverride = pMouseBltOverride;
}
// Sets an external video object as cursor file data....
void SetExternVOData( UINT32 uiCursorIndex, HVOBJECT hVObject, UINT16 usSubIndex )
{
CursorData *pCurData;
CursorImage *pCurImage;
UINT32 cnt;
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
{
pCurImage = &( pCurData->Composites[ cnt ] );
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags & USE_EXTERN_VO_CURSOR )
{
// OK, set Video Object here....
// If loaded, unload...
UnLoadCursorData( uiCursorIndex );
// Set extern vo
gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject = hVObject;
pCurImage->uiSubIndex = usSubIndex;
// Reload....
LoadCursorData( uiCursorIndex );
}
}
}
void RemoveExternVOData( UINT32 uiCursorIndex )
{
CursorData *pCurData;
CursorImage *pCurImage;
UINT32 cnt;
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
{
pCurImage = &( pCurData->Composites[ cnt ] );
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags & USE_EXTERN_VO_CURSOR )
{
gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject = NULL;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
+119
View File
@@ -0,0 +1,119 @@
#ifndef __CURSOR_DATABASE_
#define __CURSOR_DATABASE_
#include "Types.h"
#include "FileMan.h"
#include "VObject.h"
#include "VSurface.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined( JA2 ) || defined( UTIL )
#include "Video.h"
#else
#include "video2.h"
#endif
extern UINT32 GetCursorHandle(UINT32 uiCursorIndex);
extern void UnloadCursorData(UINT32 uiCursorIndex);
extern BOOLEAN LoadCursorData(UINT32 uiCursorIndex);
extern void CursorDatabaseClear(void);
extern UINT16 GetCursorSubIndex(UINT32 uiCursorIndex);
extern BOOLEAN SetCurrentCursorFromDatabase( UINT32 uiCursorIndex );
#define ANIMATED_CURSOR 0x02
#define USE_EXTERN_VO_CURSOR 0x04
#define USE_OUTLINE_BLITTER 0x08
#define EXTERN_CURSOR 0xFFF0
#define EXTERN2_CURSOR 0xFFE0
#define MAX_COMPOSITES 5
#define CENTER_SUBCURSOR 31000
#define HIDE_SUBCURSOR 32000
#define CENTER_CURSOR 32000
#define RIGHT_CURSOR 32001
#define LEFT_CURSOR 32002
#define TOP_CURSOR 32003
#define BOTTOM_CURSOR 32004
#define CURSOR_TO_FLASH 0x01
#define CURSOR_TO_FLASH2 0x02
#define CURSOR_TO_SUB_CONDITIONALLY 0x04
#define DELAY_START_CURSOR 0x08
#define CURSOR_TO_PLAY_SOUND 0x10
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Cursor Database
//
///////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct
{
UINT8 ubFilename[MAX_FILENAME_LEN];
BOOLEAN fLoaded;
UINT32 uiIndex;
UINT8 ubFlags;
UINT8 ubNumberOfFrames;
HVOBJECT hVObject;
} CursorFileData;
typedef struct
{
UINT32 uiFileIndex;
UINT16 uiSubIndex;
UINT32 uiCurrentFrame;
INT16 usPosX;
INT16 usPosY;
} CursorImage;
typedef struct
{
CursorImage Composites[ MAX_COMPOSITES ];
UINT16 usNumComposites;
INT16 sOffsetX;
INT16 sOffsetY;
UINT16 usHeight;
UINT16 usWidth;
UINT8 bFlags;
UINT8 bFlashIndex;
} CursorData;
extern INT16 gsGlobalCursorYOffset;
// Globals for cursor database offset values
extern INT16 gsCurMouseOffsetX;
extern INT16 gsCurMouseOffsetY;
extern UINT16 gsCurMouseHeight;
extern UINT16 gsCurMouseWidth;
extern UINT32 guiExternVo;
extern UINT16 gusExternVoSubIndex;
extern UINT32 guiExtern2Vo;
extern UINT16 gusExtern2VoSubIndex;
extern BOOLEAN gfExternUse2nd;
typedef void (*MOUSEBLT_HOOK)( void );
void InitCursorDatabase( CursorFileData *pCursorFileData, CursorData *pCursorData, UINT16 suNumDataFiles );
void SetMouseBltHook( MOUSEBLT_HOOK pMouseBltOverride );
void SetExternVOData( UINT32 uiCursorIndex, HVOBJECT hVObject, UINT16 usSubIndex );
void RemoveExternVOData( UINT32 uiCursorIndex );
#ifdef __cplusplus
}
#endif
#endif
+172
View File
@@ -0,0 +1,172 @@
//**************************************************************************
//
// Filename : debug.h
//
// Purpose : prototypes for the debug manager
//
// Modification history :
//
// xxxxx96:LH - Creation
// xxnov96:HJH - made it work
//
//**************************************************************************
#ifndef __DEBUG_MANAGER_
#define __DEBUG_MANAGER_
#include <crtdbg.h>
#include "types.h"
#include "TopicOps.h"
#include "TopicIDs.h"
/*
#ifdef __cplusplus
extern "C" {
#endif
*/
#define INVALID_TOPIC 0xffff
#define MAX_TOPICS_ALLOTED 1024
extern BOOLEAN gfRecordToFile;
extern BOOLEAN gfRecordToDebugger;
extern UINT32 guiProfileStart, guiExecutions, guiProfileTime;
extern INT32 giProfileCount;
#define PROFILE(x) guiProfileStart=GetTickCount(); \
guiExecutions=x; \
for(giProfileCount=0; giProfileCount < x; giProfileCount++)
#define PROFILE_REPORT() guiProfileTime=(GetTickCount()-guiProfileStart); \
_RPT3(_CRT_WARN, "*** PROFILE REPORT: %d executions took %dms, average of %.2fms per iteration.\n", guiExecutions, guiProfileTime, (FLOAT)guiProfileTime/guiExecutions);
extern void _Null(void);
extern UINT8 *String(const char *String, ...);
#if defined ( _DEBUG ) || defined ( FORCE_ASSERTS_ON )
// If DEBUG_ is defined, we need to initialize all the debug macros. Otherwise all the
// debug macros will be substituted by blank lines at compile time
//*******************************************************************************************
// Debug Mode
//*******************************************************************************************
//Modified the Assertion code. As of the writing of this code, there are no other functions that
//make use of _FailMessage. With that assumption made, we can then make two functions, the first Assert, taking
//one argument, and passing a NULL string. The second one, AssertMsg(), accepts a string as the second parameter.
//This string that has vanished for Assert is now built inside of fail message. This is the case for both Asserts, but the second one
//also is added. Ex:
//Assert( pointer );
//Assert( pointer, "This pointer is null and you tried to access it in function A ");
//It'll make debugging a little simpler. In anal cases, you could build the string first, then assert
//with it.
template <typename type1, typename type2>
extern void _FailMessage(type1 pString, UINT32 uiLineNum, type2 pSourceFile );
#define Assert(a) (a) ? _Null() : _FailMessage( NULL, __LINE__, __FILE__ )
#define AssertMsg(a,b) (a) ? _Null() : _FailMessage( b, __LINE__, __FILE__ )
extern UINT8 gubAssertString[128];
#else
#define Assert(a) ((void *)0)
#define AssertMsg(a,b) ((void *)0)
//*******************************************************************************************
#endif
// Moved these out of the defines - debug mgr always initialized
#define InitializeDebugManager() DbgInitialize()
#define ShutdownDebugManager() DbgShutdown()
extern BOOLEAN DbgInitialize(void);
extern void DbgShutdown(void);
#ifdef SGP_DEBUG
// If DEBUG_ is defined, we need to initialize all the debug macros. Otherwise all the
// debug macros will be substituted by blank lines at compile time
//*******************************************************************************************
// Debug Mode
//*******************************************************************************************
extern BOOLEAN gfDebugTopics[MAX_TOPICS_ALLOTED];
// These are the debug macros (the ones the use will use). The user should never call
// the actual debug functions directly
// Force a breakpoint in the debugger
#define DebugBreakpoint() __asm { int 3 }
#define DbgMessage(a, b, c) DbgMessageReal( (UINT16)(a), (UINT8)(TOPIC_MESSAGE), (UINT8)(b), (CHAR8 *)(c) )
#define FastDebugMsg(a) _DebugMessage( (UINT8 *)(a), (UINT32)(__LINE__), (UINT8 *)(__FILE__) )
#define UnRegisterDebugTopic(a, b) DbgTopicRegistration( (UINT8)TOPIC_UNREGISTER, (UINT16 *)(&(a)), (CHAR8 *)(b) )
#define ClearAllDebugTopics( ) DbgClearAllTopics( )
#define ErrorMsg(a) _DebugMessage( (UINT8 *)(a), (UINT32)(__LINE__), (UINT8 *)(__FILE__))
// Enable the debug topic we want
#if defined( JA2 ) || defined( UTIL )
#define RegisterJA2DebugTopic(a, b) DbgTopicRegistration( TOPIC_REGISTER, &(a), (b) )
#define RegisterDebugTopic(a, b) ((void *)0)
#define DebugMsg(a, b, c) DbgMessageReal( (a), TOPIC_MESSAGE, (b), (c) )
#else
#define RegisterJA2DebugTopic(a, b) ((void *)0)
#define RegisterDebugTopic(a, b) DbgTopicRegistration( (UINT8)TOPIC_REGISTER, (UINT16 *)(&(a)), (CHAR8 *)(b) )
#define DebugMsg(a) _DebugMessage((UINT8 *)(a), (UINT32)(__LINE__), (UINT8 *)(__FILE__))
#endif
// public interface to debug methods:
template <typename type4>
extern void DbgMessageReal(UINT16 uiTopicId, UINT8 uiCommand, UINT8 uiDebugLevel, type4 strMessage);
extern BOOLEAN DbgSetDebugLevel(UINT16 TopicId, UINT8 uiDebugLevel);
extern void DbgFailedAssertion( BOOLEAN fExpression, char *szFile, int nLine );
//extern void _FailMessage(UINT8 *pString, UINT32 uiLineNum, UINT8 *pSourceFile );
extern void DbgTopicRegistration( UINT8 ubCmd, UINT16 *usTopicID, CHAR8 *zMessage );
extern void DbgClearAllTopics( void );
extern void _DebugMessage(UINT8 *pSourceFile, UINT32 uiLineNum, UINT8 *pString);
//*******************************************************************************************
#else
//*******************************************************************************************
// Release Mode
//*******************************************************************************************
#define DebugBreakpoint() ((void *)0)
#define RegisterDebugTopic(a, b) ((void *)0)
#define UnRegisterDebugTopic(a, b) ((void *)0)
#define ClearAllDebugTopics( ) ((void *)0)
#define FastDebugMsg(a) ((void *)0)
#define ErrorMsg(a) ((void *)0)
#define DbgTopicRegistration(a, b, c); ((void *)0)
#define DbgMessage(a, b, c) ((void *)0)
#if defined( JA2 ) || defined( UTIL )
#define RegisterJA2DebugTopic(a, b) ((void *)0)
#define DebugMsg(a, b, c) ((void *)0)
#else
#define DebugMsg(a) ((void *)0)
#endif
//*******************************************************************************************
#endif
/*
#ifdef __cplusplus
}
#endif
*/
#endif
+638
View File
@@ -0,0 +1,638 @@
// JA2
//**************************************************************************
//
// Filename : debug.c
//
// Purpose : debug manager implementation
//
// Modification history :
//
// xxxxx96:LH - Creation
// xxnov96:HJH - made it work
//
//**************************************************************************
// Because we're in a library, define SGP_DEBUG here - the client may not always
// use the code to write text, because the header switches on the define
#define SGP_DEBUG
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "types.h"
#include <windows.h>
#include <ddeml.h>
#include <stdio.h>
#include "debug.h"
#include "WCheck.h"
#include "TopicIDs.h"
#include "TopicOps.h"
#include "WizShare.h"
//Kris addition
#ifdef JA2
#include "screenids.h"
#include "Sys Globals.h"
#include "jascreens.h"
#include "gameloop.h"
#include "input.h"
#endif
// CJC added
#ifndef _NO_DEBUG_TXT
#include "fileman.h"
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
BOOLEAN gfRecordToFile = FALSE;
BOOLEAN gfRecordToDebugger = TRUE;
// moved from header file: 24mar98:HJH
UINT32 guiProfileStart, guiExecutions, guiProfileTime;
INT32 giProfileCount;
// Had to move these outside the ifdef SGP_DEBUG below, because
// they are required for the String() function, which is NOT a
// debug-mode only function, it's used in release-mode as well! -- DB
UINT8 gubAssertString[128];
#define MAX_MSG_LENGTH2 512
UINT8 gbTmpDebugString[8][MAX_MSG_LENGTH2];
UINT8 gubStringIndex = 0;
#ifdef SGP_DEBUG
//**************************************************************************
//
// Defines
//
//**************************************************************************
#define BUFSIZE 100
#define TIMER_TIMEOUT 1000
//**************************************************************************
//
// Variables
//
//**************************************************************************
UINT16 TOPIC_MEMORY_MANAGER = INVALID_TOPIC;
UINT16 TOPIC_FILE_MANAGER = INVALID_TOPIC;
UINT16 TOPIC_DATABASE_MANAGER = INVALID_TOPIC;
UINT16 TOPIC_GAME = INVALID_TOPIC;
UINT16 TOPIC_SGP = INVALID_TOPIC;
UINT16 TOPIC_VIDEO = INVALID_TOPIC;
UINT16 TOPIC_INPUT = INVALID_TOPIC;
UINT16 TOPIC_STACK_CONTAINERS = INVALID_TOPIC;
UINT16 TOPIC_LIST_CONTAINERS = INVALID_TOPIC;
UINT16 TOPIC_QUEUE_CONTAINERS = INVALID_TOPIC;
UINT16 TOPIC_PRILIST_CONTAINERS = INVALID_TOPIC;
UINT16 TOPIC_HIMAGE = INVALID_TOPIC;
UINT16 TOPIC_ORDLIST_CONTAINERS = INVALID_TOPIC;
UINT16 TOPIC_3DENGINE = INVALID_TOPIC;
UINT16 TOPIC_VIDEOOBJECT = INVALID_TOPIC;
UINT16 TOPIC_FONT_HANDLER = INVALID_TOPIC;
UINT16 TOPIC_VIDEOSURFACE = INVALID_TOPIC;
UINT16 TOPIC_MOUSE_SYSTEM = INVALID_TOPIC;
UINT16 TOPIC_BUTTON_HANDLER = INVALID_TOPIC;
UINT16 TOPIC_MUTEX = INVALID_TOPIC;
UINT16 TOPIC_JA2 = 3;
UINT16 TOPIC_BLIT_QUEUE = INVALID_TOPIC;
UINT16 TOPIC_JA2OPPLIST = 2;
UINT16 TOPIC_JA2AI = 1;
UINT32 guiTimerID = 0;
UINT8 guiDebugLevels[NUM_TOPIC_IDS]; // don't change this, Luis!!!!
BOOLEAN gfDebugTopics[MAX_TOPICS_ALLOTED];
UINT16 *gpDbgTopicPtrs[MAX_TOPICS_ALLOTED];
// remove debug .txt file
void RemoveDebugText( void );
STRING512 gpcDebugLogFileName;
#ifdef __cplusplus
}
#endif
//**************************************************************************
//
// Functions
//
//**************************************************************************
//**************************************************************************
//
// DbgGetLogFileName
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// xxjun98:CJC -> creation
//
//**************************************************************************
BOOLEAN DbgGetLogFileName( STRING512 pcName )
{
// use the provided buffer to get the directory name, then tack on
// "\debug.txt"
#ifndef _NO_DEBUG_TXT
if ( ! GetExecutableDirectory( pcName ) )
{
return( FALSE );
}
if ( strlen( pcName ) > (512 - strlen( "\\debug.txt" ) - 1 ) )
{
// no room!
return( FALSE );
}
strcat( pcName, "\\debug.txt" );
#endif
return( TRUE );
}
//**************************************************************************
//
// DbgInitialize
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// xxnov96:HJH -> creation
//
//**************************************************************************
BOOLEAN DbgInitialize(void)
{
INT32 iX;
for( iX = 0; iX < MAX_TOPICS_ALLOTED; iX++ )
{
gpDbgTopicPtrs[iX] = NULL;
}
DbgClearAllTopics();
gfRecordToFile = TRUE;
gfRecordToDebugger = TRUE;
gubAssertString[0] = '\0';
#ifndef _NO_DEBUG_TXT
if (! DbgGetLogFileName( gpcDebugLogFileName ) )
{
return( FALSE );
}
// clear debug text file out
RemoveDebugText( );
#endif
return(TRUE);
}
//**************************************************************************
//
// DbgShutdown
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// xxnov96:HJH -> creation
//
//**************************************************************************
void DbgShutdown(void)
{
DbgMessageReal( (UINT16)(-1), CLIENT_SHUTDOWN, 0, "SGP Going Down" );
}
//**************************************************************************
//
// DbgTopicRegistration
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// June 97: BR -> creation
//
//**************************************************************************
void DbgTopicRegistration( UINT8 ubCmd, UINT16 *usTopicID, CHAR8 *zMessage )
{
UINT16 usIndex,usUse;
BOOLEAN fFound;
if ( usTopicID == NULL )
return;
if( ubCmd == TOPIC_REGISTER )
{
usUse = INVALID_TOPIC;
fFound = FALSE;
for( usIndex = 0; usIndex < MAX_TOPICS_ALLOTED && !fFound; usIndex++)
{
if ( !gfDebugTopics[usIndex] )
{
fFound = TRUE;
usUse = usIndex;
}
}
gfDebugTopics[ usUse ] = TRUE;
*usTopicID = usUse;
gpDbgTopicPtrs[usUse] = usTopicID;
DbgMessageReal(usUse, TOPIC_MESSAGE, DBG_LEVEL_0, zMessage );
}
else if( ubCmd == TOPIC_UNREGISTER )
{
if ( *usTopicID >= MAX_TOPICS_ALLOTED )
return;
DbgMessageReal( *usTopicID, TOPIC_MESSAGE, DBG_LEVEL_0, zMessage );
gfDebugTopics[ *usTopicID ] = FALSE;
if (gpDbgTopicPtrs[ *usTopicID ] != NULL )
{
gpDbgTopicPtrs[ *usTopicID ] = NULL;
}
*usTopicID = INVALID_TOPIC;
}
}
// *************************************************************************
// Clear the debug txt file out to prevent it from getting huge
//
//
// *************************************************************************
void RemoveDebugText( void )
{
DeleteFile( gpcDebugLogFileName );
}
//**************************************************************************
//
// DbgClearAllTopics
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// June 97: BR -> creation
//
//**************************************************************************
void DbgClearAllTopics( void )
{
UINT16 usIndex;
for( usIndex = 0; usIndex < MAX_TOPICS_ALLOTED; usIndex++)
{
gfDebugTopics[ usIndex ] = FALSE;
if ( gpDbgTopicPtrs[ usIndex ] != NULL )
{
*gpDbgTopicPtrs[usIndex] = INVALID_TOPIC;
gpDbgTopicPtrs[usIndex] = NULL;
}
}
}
//**************************************************************************
//
// DbgMessageReal
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// xxnov96:HJH -> creation
//
//**************************************************************************
template void DbgMessageReal<unsigned char *>(UINT16, UINT8, UINT8, unsigned char *);
template <typename type4>
void DbgMessageReal(UINT16 uiTopicId, UINT8 uiCommand, UINT8 uiDebugLevel, type4 strMessage)
{
#ifndef _NO_DEBUG_TXT
FILE *OutFile;
#endif
// Check for a registered topic ID
if ( uiTopicId < MAX_TOPICS_ALLOTED )//&& gfDebugTopics[uiTopicId] )
{
OutputDebugString ( (LPCSTR) strMessage );
OutputDebugString ( "\n" );
//add _NO_DEBUG_TXT to your SGP preprocessor definitions to avoid this f**king huge file from
//slowly growing behind the scenes!!!!
#ifndef _NO_DEBUG_TXT
if ((OutFile = fopen(gpcDebugLogFileName, "a+t")) != NULL)
{
fprintf(OutFile, "%s\n", strMessage);
fclose(OutFile);
}
#endif
}
}
//**************************************************************************
//
// DbgSetDebugLevel
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// 11nov96:HJH -> creation
//
//**************************************************************************
BOOLEAN DbgSetDebugLevel(UINT16 uiTopicId, UINT8 uiDebugLevel)
{
return(TRUE);
}
//**************************************************************************
//
// DbgFailedAssertion
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// xxnov96:HJH -> creation
//
//**************************************************************************
void DbgFailedAssertion( BOOLEAN fExpression, char *szFile, int nLine )
{
#ifndef _NO_DEBUG_TXT
FILE *OutFile;
if ( fExpression == FALSE )
{
if ((OutFile = fopen(gpcDebugLogFileName, "a+t")) != NULL)
{
fprintf(OutFile, "Assertion Failed at:\n line %i\n %s\n", nLine, szFile);
fclose(OutFile);
}
}
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void _DebugRecordToFile(BOOLEAN gfState)
{
gfRecordToFile = gfState;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void _DebugRecordToDebugger(BOOLEAN gfState)
{
gfRecordToDebugger = gfState;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Wiz8 compatible debug messaging
void _DebugMessage(UINT8 *pString, UINT32 uiLineNum, UINT8 *pSourceFile)
{
UINT8 ubOutputString[512];
#ifndef _NO_DEBUG_TXT
FILE *DebugFile;
#endif
//
// Build the output string
//
sprintf( (char *) ubOutputString, "{ %ld } %s [Line %d in %s]\n", GetTickCount(), pString, uiLineNum, pSourceFile );
//
// Output to debugger
//
if (gfRecordToDebugger)
{
OutputDebugString( (LPCSTR) ubOutputString );
}
//
// Record to file if required
//
#ifndef _NO_DEBUG_TXT
if (gfRecordToFile)
{
if ((DebugFile = fopen( gpcDebugLogFileName, "a+t" )) != NULL)
{
fputs( (const char *)ubOutputString, DebugFile );
fclose( DebugFile );
}
}
#endif
}
//////////////////////////////////////////////////////////////////////
// This func is used by Assert()
void _Null(void)
{
}
extern HVOBJECT FontObjs[25];
#ifdef JA2 //JAGGED ALLIANCE 2 VERSION ONLY
template void _FailMessage<char *, char const *>(char *, unsigned int, char const *);
template void _FailMessage<char const *, char const *>(char const *, unsigned int, char const *);
template void _FailMessage<int, char const *>(int, unsigned int, char const *);
template void _FailMessage<int, char *>(int, unsigned int, char *);
template void _FailMessage<char *, char *>(char *, unsigned int, char *);
template void _FailMessage<char *, char *>(unsigned char *, unsigned int, char *);
template void _FailMessage<unsigned char *, char const *>(unsigned char *, unsigned int, char const *);
template <typename type1, typename type2>
void _FailMessage( type1 pString, UINT32 uiLineNum, type2 pSourceFile )
{
MSG Message;
UINT8 ubOutputString[512];
#ifndef _NO_DEBUG_TXT
FILE *DebugFile;
#endif
BOOLEAN fDone = FALSE;
//Build the output strings
sprintf( (char *)ubOutputString, "{ %ld } Assertion Failure [Line %d in %s]\n", GetTickCount(), uiLineNum, pSourceFile );
if( pString )
sprintf( (char *)gubAssertString, (const char *)pString );
else
sprintf( (char *)gubAssertString, "" );
//Output to debugger
if (gfRecordToDebugger)
OutputDebugString( (LPCSTR)ubOutputString );
//Record to file if required
#ifndef _NO_DEBUG_TXT
if (gfRecordToFile)
{
if ((DebugFile = fopen( gpcDebugLogFileName, "a+t" )) != NULL)
{
fputs( (const char *)ubOutputString, DebugFile );
fclose( DebugFile );
}
}
#if 0
if( !FontObjs[0] )
{ //Font manager hasn't yet been initialized so use the windows error system
sprintf( gubErrorText, "Assertion Failure -- Line %d in %s", uiLineNum, pSourceFile );
MessageBox( NULL, gubErrorText, "Jagged Alliance 2", MB_OK );
gfProgramIsRunning = FALSE;
return;
}
#endif
//Kris:
//NASTY HACK, THE GAME IS GOING TO DIE ANYWAY, SO WHO CARES WHAT WE DO.
//This will actually bring up a screen that prints out the assert message
//until the user hits esc or alt-x.
sprintf( (char *)gubErrorText, "Assertion Failure -- Line %d in %s", uiLineNum, pSourceFile );
SetPendingNewScreen( ERROR_SCREEN );
SetCurrentScreen( ERROR_SCREEN );
while (gfProgramIsRunning)
{
if (PeekMessage(&Message, NULL, 0, 0, PM_NOREMOVE))
{ // We have a message on the WIN95 queue, let's get it
if (!GetMessage(&Message, NULL, 0, 0))
{ // It's quitting time
continue;
}
// Ok, now that we have the message, let's handle it
TranslateMessage(&Message);
DispatchMessage(&Message);
}
else
{ // Windows hasn't processed any messages, therefore we handle the rest
GameLoop();
gfSGPInputReceived = FALSE;
}
}
#endif
exit(0);
}
#else //NOT JAGGED ALLIANCE 2
void _FailMessage(UINT8 *pString, UINT32 uiLineNum, UINT8 *pSourceFile)
{
UINT8 ubOutputString[512];
BOOLEAN fDone = FALSE;
#ifndef _NO_DEBUG_TXT
FILE *DebugFile;
#endif
// Build the output string
sprintf( ubOutputString, "{ %ld } Assertion Failure: %s [Line %d in %s]\n", GetTickCount(), pString, uiLineNum, pSourceFile );
if( pString )
sprintf( gubAssertString, pString );
// Output to debugger
if (gfRecordToDebugger)
{
OutputDebugString( ubOutputString );
if( pString )
{ //tag on the assert message
OutputDebugString( gubAssertString );
}
}
// Record to file if required
#ifndef _NO_DEBUG_TXT
if (gfRecordToFile)
{
if ((DebugFile = fopen( gpcDebugLogFileName, "a+t" )) != NULL)
{
fputs( ubOutputString, DebugFile );
if( pString )
{ //tag on the assert message
fputs( gubAssertString, DebugFile );
}
fclose( DebugFile );
}
}
#endif
exit( 0 );
}
#endif
#endif
// This is NOT a _DEBUG only function! It is also needed in
// release mode builds. -- DB
UINT8 *String(const char *String, ...)
{
va_list ArgPtr;
UINT8 usIndex;
// Record string index. This index is used since we live in a multitasking environment.
// It is still not bulletproof, but it's better than a single string
usIndex = gubStringIndex++;
if (gubStringIndex == 8)
{ // reset string pointer
gubStringIndex = 0;
}
va_start(ArgPtr, String);
vsprintf((char *) gbTmpDebugString[usIndex], String, ArgPtr);
va_end(ArgPtr);
return gbTmpDebugString[usIndex];
}
File diff suppressed because it is too large Load Diff
+87
View File
@@ -0,0 +1,87 @@
//**************************************************************************
//
// Filename : DbMan.h
//
// Purpose : prototypes for the database manager
//
// Modification history :
//
// 08oct96:HJH - Creation
//
//**************************************************************************
#ifndef _DBMAN_H
#define _DBMAN_H
//**************************************************************************
//
// Includes
//
//**************************************************************************
#include "types.h"
//**************************************************************************
//
// Defines
//
//**************************************************************************
#ifndef FILE_ACCESS_READ
#define FILE_ACCESS_READ 0x01
#endif
#ifndef FILE_ACCESS_WRITE
#define FILE_ACCESS_WRITE 0x02
#endif
#define FILE_SEEK_FROM_START 0x01 // keep in sync with fileman.h
#define FILE_SEEK_FROM_END 0x02 // keep in sync with fileman.h
#define FILE_SEEK_FROM_CURRENT 0x04 // keep in sync with fileman.h
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
typedef UINT8 BYTE;
typedef UINT32 HDBFILE;
typedef UINT16 HFILEINDEX;
typedef UINT16 HDBINDEX;
//**************************************************************************
//
// Function Prototypes
//
//**************************************************************************
#ifdef __cplusplus
extern "C" {
#endif
extern BOOLEAN InitializeDatabaseManager( STR strIndexFilename );
extern void ShutdownDatabaseManager( void );
extern void DbDebug( BOOLEAN f );
extern BOOLEAN DbExists( STR filename );
extern HDBINDEX DbOpen( STR filename );
extern void DbClose( HDBINDEX );
extern HDBFILE DbFileOpen( STR filename );
extern void DbFileClose( HDBFILE );
extern BOOLEAN DbFileRead( HDBFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead );
extern BOOLEAN DbFileLoad( STR filename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead );
extern BOOLEAN DbFileSeek( HDBFILE hFile, UINT32 uiDistance, UINT8 uiHow );
extern UINT32 DbFileGetPos( HDBFILE hFile );
extern UINT32 DbFileGetSize( HDBFILE );
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,541 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "DirectX Common.h"
#include "DirectDraw Calls.h"
#include <ddraw.h>
#include "debug.h"
#include "video_private.h"
#endif
// DirectDrawSurface2 Calls
void
DDCreateSurface ( LPDIRECTDRAW2 pExistingDirectDraw,
DDSURFACEDESC *pNewSurfaceDesc,
LPDIRECTDRAWSURFACE *ppNewSurface1,
LPDIRECTDRAWSURFACE2 *ppNewSurface2 )
{
Assert ( pExistingDirectDraw != NULL );
Assert ( pNewSurfaceDesc != NULL );
Assert ( ppNewSurface1 != NULL );
Assert ( ppNewSurface2 != NULL );
// create the directdraw surface
ATTEMPT ( IDirectDraw2_CreateSurface ( pExistingDirectDraw,
pNewSurfaceDesc, ppNewSurface1, NULL ) );
//get the direct draw surface 2 interface
ATTEMPT ( IDirectDrawSurface_QueryInterface ( *ppNewSurface1, /*&*/IID_IDirectDrawSurface2, (LPVOID*) ppNewSurface2 ) ); // (jonathanl)
}
// DirectDrawSurface2 Calls
void
DDCreateSurfaceInMemory ( LPDIRECTDRAW2 pExistingDirectDraw,
DDSURFACEDESC *pNewSurfaceDesc,
BOOLEAN fVideoMemory, LPDIRECTDRAWSURFACE *ppNewSurface1,
LPDIRECTDRAWSURFACE2 *ppNewSurface2 )
{
DDSURFACEDESC DDSurfaceDesc;
BOOLEAN fDestination;
Assert ( pExistingDirectDraw != NULL );
Assert ( pNewSurfaceDesc != NULL );
Assert ( ppNewSurface1 != NULL );
Assert ( ppNewSurface2 != NULL );
// copy to a local so we don't change the input parameter
memcpy ( &DDSurfaceDesc, pNewSurfaceDesc, sizeof ( DDSURFACEDESC ) );
// must have caps set since we are adding to the ddsCaps element
DDSurfaceDesc.dwFlags |= DDSD_CAPS;
// If this is a hardware D3D driver, the Z-Buffer MUST end up in video
// memory. Otherwise, it MUST end up in system memory.
if ( fVideoMemory )
DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
else
DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
// create the surface
DDCreateSurface ( pExistingDirectDraw, &DDSurfaceDesc, ppNewSurface1, ppNewSurface2 );
// get surface information
DDGetSurfaceDescription ( *ppNewSurface2, &DDSurfaceDesc );
// was the surface created in video memory?
fDestination = ( DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY ) ?
TRUE : FALSE;
// did we create the surface in the right memory area?
if ( fDestination != fVideoMemory )
{
// nope we couldn't do it right so release the newly created surface
// and pass back a NULL pointer to the user
DDReleaseSurface ( ppNewSurface1, ppNewSurface2 );
}
}
// Lock, unlock calls
void DDLockSurface ( LPDIRECTDRAWSURFACE2 pSurface, LPRECT pDestRect, LPDDSURFACEDESC pSurfaceDesc, UINT32 uiFlags, HANDLE hEvent )
{
HRESULT ReturnCode;
Assert( pSurface != NULL );
Assert( pSurfaceDesc != NULL );
ZEROMEM ( *pSurfaceDesc );
pSurfaceDesc->dwSize = sizeof(DDSURFACEDESC);
do
{
ReturnCode = IDirectDrawSurface2_Lock( pSurface, pDestRect, pSurfaceDesc, uiFlags, hEvent);
} while( ReturnCode == DDERR_WASSTILLDRAWING );
ATTEMPT( ReturnCode );
}
void DDUnlockSurface( LPDIRECTDRAWSURFACE2 pSurface, PTR pSurfaceData )
{
Assert( pSurface != NULL );
ATTEMPT( IDirectDrawSurface2_Unlock( pSurface, pSurfaceData ) );
}
void DDGetSurfaceDescription ( LPDIRECTDRAWSURFACE2 pSurface, DDSURFACEDESC *pSurfaceDesc )
{
Assert ( pSurface != NULL );
Assert ( pSurfaceDesc != NULL );
ZEROMEM ( *pSurfaceDesc );
pSurfaceDesc->dwSize = sizeof ( DDSURFACEDESC );
ATTEMPT ( IDirectDrawSurface2_GetSurfaceDesc ( pSurface, pSurfaceDesc ) );
}
void DDGetSurfaceCaps ( LPDIRECTDRAWSURFACE2 pSurface, DDSCAPS *pSurfaceCaps )
{
Assert( pSurface != NULL );
Assert( pSurfaceCaps != NULL );
ATTEMPT( IDirectDrawSurface2_GetCaps( pSurface, pSurfaceCaps ) );
}
void DDCreateRasterSurface ( LPDIRECTDRAW2 pDirectDraw, INT32 iWidth, INT32 iHeight,
BOOLEAN fVideoMemory,
LPDIRECTDRAWSURFACE *ppRasterSurface1,
LPDIRECTDRAWSURFACE2 *ppRasterSurface2 )
{
DDSURFACEDESC DDSurfaceDesc;
// validate used portions of the structure
Assert ( pDirectDraw != NULL );
Assert ( iWidth != 0 );
Assert ( iHeight != 0 );
Assert ( ppRasterSurface1 != NULL );
Assert ( ppRasterSurface2 != NULL );
// create the raster surface
ZEROMEM ( DDSurfaceDesc );
DDSurfaceDesc.dwSize = sizeof ( DDSurfaceDesc );
DDSurfaceDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
DDSurfaceDesc.dwWidth = iWidth;
DDSurfaceDesc.dwHeight = iHeight;
DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN;
DDCreateSurfaceInMemory ( pDirectDraw, &DDSurfaceDesc, fVideoMemory, ppRasterSurface1, ppRasterSurface2 );
}
void DDCreateZBufferSurface ( LPDIRECTDRAW2 pDirectDraw, INT32 iWidth, INT32 iHeight,
BOOLEAN fVideoMemory,
LPDIRECTDRAWSURFACE *ppZBufferSurface1,
LPDIRECTDRAWSURFACE2 *ppZBufferSurface2 )
{
DDSURFACEDESC DDSurfaceDesc;
// validate used portions of the structure
Assert ( pDirectDraw != NULL );
Assert ( iWidth != 0 );
Assert ( iHeight != 0 );
Assert ( ppZBufferSurface1 != NULL );
Assert ( ppZBufferSurface2 != NULL );
// create the z buffer
ZEROMEM ( DDSurfaceDesc );
DDSurfaceDesc.dwSize = sizeof ( DDSurfaceDesc );
DDSurfaceDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_ZBUFFERBITDEPTH;
DDSurfaceDesc.dwWidth = iWidth;
DDSurfaceDesc.dwHeight = iHeight;
DDSurfaceDesc.dwZBufferBitDepth = 16;
DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
DDCreateSurfaceInMemory ( pDirectDraw, &DDSurfaceDesc, fVideoMemory, ppZBufferSurface1, ppZBufferSurface2 );
}
void
DDAddAttachedSurface ( LPDIRECTDRAWSURFACE2 pParentSurface,
LPDIRECTDRAWSURFACE2 pAddChildSurface )
{
Assert ( pParentSurface != NULL );
Assert ( pAddChildSurface != NULL );
// attach the child to the parent surface
ATTEMPT ( IDirectDrawSurface2_AddAttachedSurface ( pParentSurface,
pAddChildSurface ) );
}
void
DDDeleteAttachedSurface ( LPDIRECTDRAWSURFACE2 pParentSurface,
LPDIRECTDRAWSURFACE2 pDeleteChildSurface )
{
Assert ( pParentSurface != NULL );
Assert ( pDeleteChildSurface != NULL );
// seperate the z buffer surface from the raster surface
ATTEMPT ( IDirectDrawSurface2_DeleteAttachedSurface ( pParentSurface,
0, pDeleteChildSurface ) );
}
void
DDReleaseSurface ( LPDIRECTDRAWSURFACE *ppOldSurface1, LPDIRECTDRAWSURFACE2 *ppOldSurface2 )
{
Assert ( ppOldSurface1 != NULL );
Assert ( ppOldSurface2 != NULL );
Assert ( *ppOldSurface1 != NULL );
Assert ( *ppOldSurface2 != NULL );
ATTEMPT ( IDirectDrawSurface2_Release ( *ppOldSurface2 ) );
ATTEMPT ( IDirectDrawSurface_Release ( *ppOldSurface1 ) );
*ppOldSurface1 = NULL;
*ppOldSurface2 = NULL;
}
void DDRestoreSurface( LPDIRECTDRAWSURFACE2 pSurface )
{
Assert( pSurface != NULL );
ATTEMPT( IDirectDrawSurface2_Restore( pSurface ) );
}
void DDBltFastSurface( LPDIRECTDRAWSURFACE2 pDestSurface, UINT32 uiX, UINT32 uiY, LPDIRECTDRAWSURFACE2 pSrcSurface,
LPRECT pSrcRect, UINT32 uiTrans)
{
HRESULT ReturnCode;
Assert( pDestSurface != NULL );
Assert( pSrcSurface != NULL );
do
{
ReturnCode = IDirectDrawSurface2_SGPBltFast( pDestSurface, uiX, uiY, pSrcSurface, pSrcRect, uiTrans );
} while( ReturnCode == DDERR_WASSTILLDRAWING );
}
void DDBltSurface( LPDIRECTDRAWSURFACE2 pDestSurface, LPRECT pDestRect, LPDIRECTDRAWSURFACE2 pSrcSurface,
LPRECT pSrcRect, UINT32 uiFlags, LPDDBLTFX pDDBltFx )
{
HRESULT ReturnCode;
Assert( pDestSurface != NULL );
do
{
ReturnCode = IDirectDrawSurface2_SGPBlt( pDestSurface, pDestRect, pSrcSurface, pSrcRect, uiFlags, pDDBltFx );
} while( ReturnCode == DDERR_WASSTILLDRAWING );
ATTEMPT( ReturnCode );
}
void DDCreatePalette( LPDIRECTDRAW2 pDirectDraw, UINT32 uiFlags, LPPALETTEENTRY pColorTable, LPDIRECTDRAWPALETTE FAR *ppDDPalette,
IUnknown FAR * pUnkOuter)
{
Assert( pDirectDraw != NULL );
ATTEMPT( IDirectDraw2_CreatePalette( pDirectDraw, uiFlags, pColorTable, ppDDPalette, pUnkOuter ) );
}
void DDSetSurfacePalette( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWPALETTE pDDPalette )
{
Assert( pDDPalette != NULL );
Assert( pSurface != NULL );
ATTEMPT( IDirectDrawSurface2_SetPalette( pSurface, pDDPalette ) );
}
void DDGetSurfacePalette( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWPALETTE *ppDDPalette )
{
Assert( ppDDPalette != NULL );
Assert( pSurface != NULL );
ATTEMPT( IDirectDrawSurface2_GetPalette( pSurface, ppDDPalette ) );
}
void DDSetPaletteEntries( LPDIRECTDRAWPALETTE pPalette, UINT32 uiFlags, UINT32 uiStartingEntry,
UINT32 uiCount, LPPALETTEENTRY pEntries )
{
Assert( pPalette != NULL );
Assert( pEntries != NULL );
ATTEMPT( IDirectDrawPalette_SetEntries( pPalette, uiFlags, uiStartingEntry, uiCount, pEntries ) );
}
void DDGetPaletteEntries( LPDIRECTDRAWPALETTE pPalette, UINT32 uiFlags, UINT32 uiBase,
UINT32 uiNumEntries, LPPALETTEENTRY pEntries )
{
Assert( pPalette != NULL );
Assert( pEntries != NULL );
ATTEMPT( IDirectDrawPalette_GetEntries( pPalette, uiFlags, uiBase, uiNumEntries, pEntries ) );
}
void DDReleasePalette( LPDIRECTDRAWPALETTE pPalette )
{
Assert( pPalette != NULL );
ATTEMPT( IDirectDrawPalette_Release( pPalette ) );
}
void DDGetDC( LPDIRECTDRAWSURFACE2 pSurface, HDC *phDC )
{
Assert( pSurface != NULL );
Assert( phDC != NULL );
ATTEMPT( IDirectDrawSurface2_GetDC( pSurface, phDC ) );
}
void DDReleaseDC( LPDIRECTDRAWSURFACE2 pSurface, HDC hDC )
{
Assert( pSurface != NULL );
ATTEMPT( IDirectDrawSurface2_ReleaseDC( pSurface, hDC ) );
}
void DDSetSurfaceColorKey( LPDIRECTDRAWSURFACE2 pSurface, UINT32 uiFlags, LPDDCOLORKEY pDDColorKey )
{
Assert( pSurface != NULL );
Assert( pDDColorKey != NULL );
ATTEMPT( IDirectDrawSurface2_SetColorKey( pSurface, uiFlags, pDDColorKey ) );
}
void DDGetDDInterface( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAW *ppDirectDraw )
{
Assert( pSurface != NULL );
Assert( ppDirectDraw != NULL );
ATTEMPT( IDirectDrawSurface2_GetDDInterface( pSurface, (LPVOID *)ppDirectDraw ) );
}
// Clipper FUnctions
void DDCreateClipper( LPDIRECTDRAW2 pDirectDraw, UINT32 fFlags, LPDIRECTDRAWCLIPPER *pDDClipper )
{
Assert( pDirectDraw != NULL );
Assert( pDDClipper != NULL );
ATTEMPT( IDirectDraw2_CreateClipper( pDirectDraw, 0, pDDClipper, NULL ) );
}
void DDSetClipper( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWCLIPPER pDDClipper )
{
Assert( pSurface != NULL );
Assert( pDDClipper != NULL );
ATTEMPT( IDirectDrawSurface2_SetClipper( pSurface, pDDClipper ) );
}
void DDReleaseClipper( LPDIRECTDRAWCLIPPER pDDClipper )
{
Assert( pDDClipper != NULL );
ATTEMPT( IDirectDrawClipper_Release( pDDClipper ) );
}
void DDSetClipperList( LPDIRECTDRAWCLIPPER pDDClipper, LPRGNDATA pClipList, UINT32 uiFlags)
{
Assert( pDDClipper != NULL );
Assert( pClipList != NULL );
ATTEMPT( IDirectDrawClipper_SetClipList( pDDClipper, pClipList, uiFlags ) );
}
HRESULT BltFastDDSurfaceUsingSoftware( LPDIRECTDRAWSURFACE2 pDestSurface, INT32 uiX, INT32 uiY, LPDIRECTDRAWSURFACE2 pSrcSurface, LPRECT pSrcRect, UINT32 uiTrans )
{
DDSURFACEDESC SurfaceDescription;
UINT32 uiDestPitchBYTES, uiSrcPitchBYTES;
UINT8 *pDestBuf, *pSrcBuf;
HRESULT ReturnCode;
DDCOLORKEY ColorKey;
UINT16 us16BPPColorKey;
// Lock surfaces
DDLockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL, &SurfaceDescription, 0, NULL);
uiDestPitchBYTES = SurfaceDescription.lPitch;
pDestBuf = (UINT8 *) SurfaceDescription.lpSurface;
// Lock surfaces
DDLockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL, &SurfaceDescription, 0, NULL);
uiSrcPitchBYTES = SurfaceDescription.lPitch;
pSrcBuf = (UINT8 *) SurfaceDescription.lpSurface;
if ( uiTrans == DDBLTFAST_NOCOLORKEY )
{
Blt16BPPTo16BPP( (UINT16 *)pDestBuf, uiDestPitchBYTES,
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
uiX , uiY,
pSrcRect->left , pSrcRect->top,
( pSrcRect->right - pSrcRect->left ),
( pSrcRect->bottom - pSrcRect->top ) );
}
else if ( uiTrans == DDBLTFAST_SRCCOLORKEY )
{
// Get 16 bpp color key.....
ReturnCode = IDirectDrawSurface2_GetColorKey( pSrcSurface, DDCKEY_SRCBLT, &ColorKey);
if (ReturnCode == DD_OK)
{
us16BPPColorKey = (UINT16)ColorKey.dwColorSpaceLowValue;
Blt16BPPTo16BPPTrans( (UINT16 *)pDestBuf, uiDestPitchBYTES,
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
uiX , uiY,
pSrcRect->left , pSrcRect->top,
( pSrcRect->right - pSrcRect->left ),
( pSrcRect->bottom - pSrcRect->top ), us16BPPColorKey );
}
}
else
{
// Not supported.....
}
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL );
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL );
return( DD_OK );
}
HRESULT BltDDSurfaceUsingSoftware( LPDIRECTDRAWSURFACE2 pDestSurface, LPRECT pDestRect, LPDIRECTDRAWSURFACE2 pSrcSurface, LPRECT pSrcRect, UINT32 uiFlags, LPDDBLTFX pDDBltFx )
{
DDSURFACEDESC SurfaceDescription;
UINT32 uiDestPitchBYTES, uiSrcPitchBYTES;
UINT8 *pDestBuf, *pSrcBuf;
HRESULT ReturnCode;
DDCOLORKEY ColorKey;
UINT16 us16BPPColorKey;
// Lock surfaces
DDLockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL, &SurfaceDescription, 0, NULL);
uiDestPitchBYTES = SurfaceDescription.lPitch;
pDestBuf = (UINT8 *) SurfaceDescription.lpSurface;
if ( pSrcSurface != NULL )
{
// Lock surfaces
DDLockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL, &SurfaceDescription, 0, NULL);
uiSrcPitchBYTES = SurfaceDescription.lPitch;
pSrcBuf = (UINT8 *) SurfaceDescription.lpSurface;
}
if ( pSrcRect != NULL &&
( ( pSrcRect->right - pSrcRect->left ) != ( pDestRect->right - pDestRect->left ) ||
( pSrcRect->bottom - pSrcRect->top ) != ( pDestRect->bottom - pDestRect->top ) ) )
{
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL );
if ( pSrcSurface != NULL )
{
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL );
}
// Fall back to DD
IDirectDrawSurface2_Blt( pDestSurface, pDestRect, pSrcSurface, pSrcRect, uiFlags, pDDBltFx );
return( DD_OK );
}
else if ( uiFlags == DDBLT_WAIT )
{
// Lock surfaces
DDLockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL, &SurfaceDescription, 0, NULL);
uiSrcPitchBYTES = SurfaceDescription.lPitch;
pSrcBuf = (UINT8 *) SurfaceDescription.lpSurface;
Blt16BPPTo16BPP( (UINT16 *)pDestBuf, uiDestPitchBYTES,
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
pDestRect->left , pDestRect->top,
pSrcRect->left , pSrcRect->top,
( pSrcRect->right - pSrcRect->left ),
( pSrcRect->bottom - pSrcRect->top ) );
}
else if ( uiFlags & DDBLT_KEYSRC )
{
// Get 16 bpp color key.....
ReturnCode = IDirectDrawSurface2_GetColorKey( pSrcSurface, DDCKEY_SRCBLT, &ColorKey);
if (ReturnCode == DD_OK)
{
us16BPPColorKey = (UINT16)ColorKey.dwColorSpaceLowValue;
Blt16BPPTo16BPPTrans( (UINT16 *)pDestBuf, uiDestPitchBYTES,
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
pDestRect->left , pDestRect->top,
pSrcRect->left , pSrcRect->top,
( pSrcRect->right - pSrcRect->left ),
( pSrcRect->bottom - pSrcRect->top ), us16BPPColorKey );
}
}
else if ( uiFlags & DDBLT_COLORFILL )
{
// do color fill here...
FillRect16BPP( (UINT16 *)pDestBuf, uiDestPitchBYTES, pDestRect->left, pDestRect->top, pDestRect->right, pDestRect->bottom, (UINT16)pDDBltFx->dwFillColor );
}
else
{
// Not supported.....
}
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL );
if ( pSrcSurface != NULL )
{
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL );
}
return( DD_OK );
}
@@ -0,0 +1,97 @@
#ifndef __DirectDraw_Calls_H__
#define __DirectDraw_Calls_H__
#include "DirectX Common.h"
#include <ddraw.h>
// Direct Draw Functions
#ifdef __cplusplus
extern "C" {
#endif
// Surface Functions
void DDCreateSurface ( LPDIRECTDRAW2 pExistingDirectDraw,
DDSURFACEDESC *pNewSurfaceDesc, LPDIRECTDRAWSURFACE *ppNewSurface1, LPDIRECTDRAWSURFACE2 *ppNewSurface2 );
void DDCreateSurfaceInMemory ( LPDIRECTDRAW2 pExistingDirectDraw,
DDSURFACEDESC *pNewSurfaceDesc,
BOOLEAN fVideoMemory, LPDIRECTDRAWSURFACE *ppNewSurface1,
LPDIRECTDRAWSURFACE2 *ppNewSurface2 );
void DDCreateZBufferSurface ( LPDIRECTDRAW2 pDirectDraw, INT32 iWidth, INT32 iHeight,
BOOLEAN fVideoMemory, LPDIRECTDRAWSURFACE *ppZBufferSurface1,
LPDIRECTDRAWSURFACE2 *ppZBufferSurface2 );
void DDCreateRasterSurface ( LPDIRECTDRAW2 pDirectDraw, INT32 iWidth, INT32 iHeight,
BOOLEAN fVideoMemory, LPDIRECTDRAWSURFACE *ppRasterSurface1,
LPDIRECTDRAWSURFACE2 *ppRasterSurface2 );
void DDGetSurfaceDescription ( LPDIRECTDRAWSURFACE2 pSurface, DDSURFACEDESC *pSurfaceDesc );
void DDGetSurfaceCaps ( LPDIRECTDRAWSURFACE2 pSurface, DDSCAPS *pSurfaceCaps );
void DDAddAttachedSurface ( LPDIRECTDRAWSURFACE2 pParentSurface,
LPDIRECTDRAWSURFACE2 pAddChildSurface );
void DDDeleteAttachedSurface ( LPDIRECTDRAWSURFACE2 pParentSurface,
LPDIRECTDRAWSURFACE2 pDeleteChildSurface );
void DDReleaseSurface ( LPDIRECTDRAWSURFACE *ppOldSurface1, LPDIRECTDRAWSURFACE2 *ppOldSurface2 );
void DDGetDDInterface( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAW *ppDirectDraw );
void DDLockSurface( LPDIRECTDRAWSURFACE2 pSurface, LPRECT pDestRect, LPDDSURFACEDESC pSurfaceDesc,
UINT32 uiFlags, HANDLE hEvent);
void DDUnlockSurface( LPDIRECTDRAWSURFACE2 pSurface, PTR pSurfaceData );
void DDRestoreSurface( LPDIRECTDRAWSURFACE2 pSurface );
void DDBltFastSurface( LPDIRECTDRAWSURFACE2 pDestSurface, UINT32 uiX, UINT32 uiY, LPDIRECTDRAWSURFACE2 pSrcSurface,
LPRECT pSrcRect, UINT32 uiTrans);
void DDBltSurface( LPDIRECTDRAWSURFACE2 pDestSurface, LPRECT pDestRect, LPDIRECTDRAWSURFACE2 pSrcSurface,
LPRECT pSrcRect, UINT32 uiFlags, LPDDBLTFX pDDBltFx );
void DDSetSurfacePalette( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWPALETTE pDDPalette );
void DDGetSurfacePalette( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWPALETTE *ppDDPalette );
void DDGetDC( LPDIRECTDRAWSURFACE2 pSurface, HDC *phDC );
void DDReleaseDC( LPDIRECTDRAWSURFACE2 pSurface, HDC hDC );
void DDSetSurfaceColorKey( LPDIRECTDRAWSURFACE2 pSurface, UINT32 uiFlags, LPDDCOLORKEY pDDColorKey );
// Palette Functions
void DDCreatePalette( LPDIRECTDRAW2 pDirectDraw, UINT32 uiFlags, LPPALETTEENTRY pColorTable, LPDIRECTDRAWPALETTE FAR *ppDDPalette,
IUnknown FAR * pUnkOuter);
void DDSetPaletteEntries( LPDIRECTDRAWPALETTE pPalette, UINT32 uiFlags, UINT32 uiStartingEntry,
UINT32 uiCount, LPPALETTEENTRY pEntries );
void DDReleasePalette( LPDIRECTDRAWPALETTE pPalette );
void DDGetPaletteEntries( LPDIRECTDRAWPALETTE pPalette, UINT32 uiFlags, UINT32 uiBase,
UINT32 uiNumEntries, LPPALETTEENTRY pEntries );
// Clipper functions
void DDCreateClipper( LPDIRECTDRAW2 pDirectDraw, UINT32 fFlags, LPDIRECTDRAWCLIPPER *pDDClipper );
void DDSetClipper( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWCLIPPER pDDClipper );
void DDReleaseClipper( LPDIRECTDRAWCLIPPER pDDClipper );
void DDSetClipperList( LPDIRECTDRAWCLIPPER pDDClipper, LPRGNDATA pClipList, UINT32 uiFlags);
HRESULT BltFastDDSurfaceUsingSoftware( LPDIRECTDRAWSURFACE2 pDestSurface, INT32 uiX, INT32 uiY, LPDIRECTDRAWSURFACE2 pSrcSurface, LPRECT pSrcRect, UINT32 uiTrans );
HRESULT BltDDSurfaceUsingSoftware( LPDIRECTDRAWSURFACE2 pDestSurface, LPRECT pDestRect, LPDIRECTDRAWSURFACE2 pSrcSurface, LPRECT pSrcRect, UINT32 uiFlags, LPDDBLTFX pDDBltFx );
#define IDirectDrawSurface2_SGPBltFast(p,a,b,c,d,e) ( ( gfDontUseDDBlits == TRUE ) ? BltFastDDSurfaceUsingSoftware( p, a, b, c, d, e ) : ( IDirectDrawSurface2_BltFast(p,a,b,c,d,e) ) )
#define IDirectDrawSurface2_SGPBlt(p,a,b,c,d,e) ( ( gfDontUseDDBlits == TRUE ) ? BltDDSurfaceUsingSoftware( p, a, b, c, d, e ) : ( IDirectDrawSurface2_Blt(p,a,b,c,d,e) ) )
#ifdef __cplusplus
}
#endif
#endif // __DirectDraw_Calls_H__
+244
View File
@@ -0,0 +1,244 @@
#include "types.h"
#include <objbase.h>
#include <initguid.h>
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "types.h"
#include <ddraw.h>
#include "DirectX Common.h"
#include <windows.h>
#include "debug.h"
#endif
void DirectXZeroMem ( void* pMemory, int nSize )
{
memset ( pMemory, 0, nSize );
}
void DirectXAttempt ( INT32 iErrorCode, INT32 nLine, char *szFilename )
{
#ifdef _DEBUG
if ( iErrorCode != DD_OK )
{
FastDebugMsg("DIRECTX COMMON: DirectX Error\n" );
FastDebugMsg(DirectXErrorDescription(iErrorCode));
}
#endif
}
char* DirectXErrorDescription ( INT32 iDXReturn )
{
switch( iDXReturn )
{
case DD_OK
: return "No error.\0";
case DDERR_ALREADYINITIALIZED
: return "The object has already been initialized.";
case DDERR_BLTFASTCANTCLIP
: return "A DirectDrawClipper object is attached to a source surface that has passed into a call to the IDirectDrawSurface2::BltFast method.";
case DDERR_CANNOTATTACHSURFACE
: return "A surface cannot be attached to another requested surface.";
case DDERR_CANNOTDETACHSURFACE
: return "A surface cannot be detached from another requested surface.";
case DDERR_CANTCREATEDC
: return "Windows cannot create any more device contexts (DCs).";
case DDERR_CANTDUPLICATE
: return "Primary and 3D surfaces, or surfaces that are implicitly created, cannot be duplicated.";
case DDERR_CANTLOCKSURFACE
: return "Access to this surface is refused because an attempt was made to lock the primary surface without DCI support.";
case DDERR_CANTPAGELOCK
: return "An attempt to page lock a surface failed. Page lock will not work on a display-memory surface or an emulated primary surface.";
case DDERR_CANTPAGEUNLOCK
: return "An attempt to page unlock a surface failed. Page unlock will not work on a display-memory surface or an emulated primary surface.";
case DDERR_CLIPPERISUSINGHWND
: return "An attempt was made to set a clip list for a DirectDrawClipper object that is already monitoring a window handle.";
case DDERR_COLORKEYNOTSET
: return "No source color key is specified for this operation.";
case DDERR_CURRENTLYNOTAVAIL
: return "No support is currently available.";
case DDERR_DCALREADYCREATED
: return "A device context (DC) has already been returned for this surface. Only one DC can be retrieved for each surface.";
case DDERR_DIRECTDRAWALREADYCREATED
: return "A DirectDraw object representing this driver has already been created for this process.";
case DDERR_EXCEPTION
: return "An exception was encountered while performing the requested operation.";
case DDERR_EXCLUSIVEMODEALREADYSET
: return "An attempt was made to set the cooperative level when it was already set to exclusive.";
case DDERR_GENERIC
: return "There is an undefined error condition.";
case DDERR_HEIGHTALIGN
: return "The height of the provided rectangle is not a multiple of the required alignment.";
case DDERR_HWNDALREADYSET
: return "The DirectDraw cooperative level window handle has already been set. It cannot be reset while the process has surfaces or palettes created.";
case DDERR_HWNDSUBCLASSED
: return "DirectDraw is prevented from restoring state because the DirectDraw cooperative level window handle has been subclassed.";
case DDERR_IMPLICITLYCREATED
: return "The surface cannot be restored because it is an implicitly created surface.";
case DDERR_INCOMPATIBLEPRIMARY
: return "The primary surface creation request does not match with the existing primary surface.";
case DDERR_INVALIDCAPS
: return "One or more of the capability bits passed to the callback function are incorrect.";
case DDERR_INVALIDCLIPLIST
: return "DirectDraw does not support the provided clip list.";
case DDERR_INVALIDDIRECTDRAWGUID
: return "The globally unique identifier (GUID) passed to the DirectDrawCreate function is not a valid DirectDraw driver identifier.";
case DDERR_INVALIDMODE
: return "DirectDraw does not support the requested mode.";
case DDERR_INVALIDOBJECT
: return "DirectDraw received a pointer that was an invalid DirectDraw object.";
case DDERR_INVALIDPARAMS
: return "One or more of the parameters passed to the method are incorrect.";
case DDERR_INVALIDPIXELFORMAT
: return "The pixel format was invalid as specified.";
case DDERR_INVALIDPOSITION
: return "The position of the overlay on the destination is no longer legal.";
case DDERR_INVALIDRECT
: return "The provided rectangle was invalid.";
case DDERR_INVALIDSURFACETYPE
: return "The requested operation could not be performed because the surface was of the wrong type.";
case DDERR_LOCKEDSURFACES
: return "One or more surfaces are locked, causing the failure of the requested operation.";
case DDERR_NO3D
: return "No 3D hardware or emulation is present.";
case DDERR_NOALPHAHW
: return "No alpha acceleration hardware is present or available, causing the failure of the requested operation.";
case DDERR_NOBLTHW
: return "No blitter hardware is present.";
case DDERR_NOCLIPLIST
: return "No clip list is available.";
case DDERR_NOCLIPPERATTACHED
: return "No DirectDrawClipper object is attached to the surface object.";
case DDERR_NOCOLORCONVHW
: return "The operation cannot be carried out because no color-conversion hardware is present or available.";
case DDERR_NOCOLORKEY
: return "The surface does not currently have a color key.";
case DDERR_NOCOLORKEYHW
: return "The operation cannot be carried out because there is no hardware support for the destination color key.";
case DDERR_NOCOOPERATIVELEVELSET
: return "A create function is called without the IDirectDraw2::SetCooperativeLevel method being called.";
case DDERR_NODC
: return "No DC has ever been created for this surface.";
case DDERR_NODDROPSHW
: return "No DirectDraw raster operation (ROP) hardware is available.";
case DDERR_NODIRECTDRAWHW
: return "Hardware-only DirectDraw object creation is not possible; the driver does not support any hardware.";
case DDERR_NODIRECTDRAWSUPPORT
: return "DirectDraw support is not possible with the current display driver.";
case DDERR_NOEMULATION
: return "Software emulation is not available.";
case DDERR_NOEXCLUSIVEMODE
: return "The operation requires the application to have exclusive mode, but the application does not have exclusive mode.";
case DDERR_NOFLIPHW
: return "Flipping visible surfaces is not supported.";
case DDERR_NOGDI
: return "No GDI is present.";
case DDERR_NOHWND
: return "Clipper notification requires a window handle, or no window handle has been previously set as the cooperative level window handle.";
case DDERR_NOMIPMAPHW
: return "The operation cannot be carried out because no mipmap texture mapping hardware is present or available.";
case DDERR_NOMIRRORHW
: return "The operation cannot be carried out because no mirroring hardware is present or available.";
case DDERR_NOOVERLAYDEST
: return "The IDirectDrawSurface2::GetOverlayPosition method is called on an overlay that the IDirectDrawSurface2::UpdateOverlay method has not been called on to establish a destination.";
case DDERR_NOOVERLAYHW
: return "The operation cannot be carried out because no overlay hardware is present or available.";
case DDERR_NOPALETTEATTACHED
: return "No palette object is attached to this surface.";
case DDERR_NOPALETTEHW
: return "There is no hardware support for 16- or 256-color palettes.";
case DDERR_NORASTEROPHW
: return "The operation cannot be carried out because no appropriate raster operation hardware is present or available.";
case DDERR_NOROTATIONHW
: return "The operation cannot be carried out because no rotation hardware is present or available.";
case DDERR_NOSTRETCHHW
: return "The operation cannot be carried out because there is no hardware support for stretching.";
case DDERR_NOT4BITCOLOR
: return "The DirectDrawSurface object is not using a 4-bit color palette and the requested operation requires a 4-bit color palette.";
case DDERR_NOT4BITCOLORINDEX
: return "The DirectDrawSurface object is not using a 4-bit color index palette and the requested operation requires a 4-bit color index palette.";
case DDERR_NOT8BITCOLOR
: return "The DirectDrawSurface object is not using an 8-bit color palette and the requested operation requires an 8-bit color palette.";
case DDERR_NOTAOVERLAYSURFACE
: return "An overlay component is called for a non-overlay surface.";
case DDERR_NOTEXTUREHW
: return "The operation cannot be carried out because no texture-mapping hardware is present or available.";
case DDERR_NOTFLIPPABLE
: return "An attempt has been made to flip a surface that cannot be flipped.";
case DDERR_NOTFOUND
: return "The requested item was not found.";
case DDERR_NOTINITIALIZED
: return "An attempt was made to call an interface method of a DirectDraw object created by CoCreateInstance before the object was initialized.";
case DDERR_NOTLOCKED
: return "An attempt is made to unlock a surface that was not locked.";
case DDERR_NOTPAGELOCKED
: return "An attempt is made to page unlock a surface with no outstanding page locks.";
case DDERR_NOTPALETTIZED
: return "The surface being used is not a palette-based surface.";
case DDERR_NOVSYNCHW
: return "The operation cannot be carried out because there is no hardware support for vertical blank synchronized operations.";
case DDERR_NOZBUFFERHW
: return "The operation to create a z-buffer in display memory or to perform a blit using a z-buffer cannot be carried out because there is no hardware support for z-buffers.";
case DDERR_NOZOVERLAYHW
: return "The overlay surfaces cannot be z-layered based on the z-order because the hardware does not support z-ordering of overlays.";
case DDERR_OUTOFCAPS
: return "The hardware needed for the requested operation has already been allocated.";
case DDERR_OUTOFMEMORY
: return "DirectDraw does not have enough memory to perform the operation.";
case DDERR_OUTOFVIDEOMEMORY
: return "DirectDraw does not have enough display memory to perform the operation.";
case DDERR_OVERLAYCANTCLIP
: return "The hardware does not support clipped overlays.";
case DDERR_OVERLAYCOLORKEYONLYONEACTIVE
: return "An attempt was made to have more than one color key active on an overlay.";
case DDERR_OVERLAYNOTVISIBLE
: return "The IDirectDrawSurface2::GetOverlayPosition method is called on a hidden overlay.";
case DDERR_PALETTEBUSY
: return "Access to this palette is refused because the palette is locked by another thread.";
case DDERR_PRIMARYSURFACEALREADYEXISTS
: return "This process has already created a primary surface.";
case DDERR_REGIONTOOSMALL
: return "The region passed to the IDirectDrawClipper::GetClipList method is too small.";
case DDERR_SURFACEALREADYATTACHED
: return "An attempt was made to attach a surface to another surface to which it is already attached.";
case DDERR_SURFACEALREADYDEPENDENT
: return "An attempt was made to make a surface a dependency of another surface to which it is already dependent.";
case DDERR_SURFACEBUSY
: return "Access to the surface is refused because the surface is locked by another thread.";
case DDERR_SURFACEISOBSCURED
: return "Access to the surface is refused because the surface is obscured.";
case DDERR_SURFACELOST
: return "Access to the surface is refused because the surface memory is gone. The DirectDrawSurface object representing this surface should have the IDirectDrawSurface2::Restore method called on it.";
case DDERR_SURFACENOTATTACHED
: return "The requested surface is not attached.";
case DDERR_TOOBIGHEIGHT
: return "The height requested by DirectDraw is too large.";
case DDERR_TOOBIGSIZE
: return "The size requested by DirectDraw is too large. However, the individual height and width are OK.";
case DDERR_TOOBIGWIDTH
: return "The width requested by DirectDraw is too large.";
case DDERR_UNSUPPORTED
: return "The operation is not supported.";
case DDERR_UNSUPPORTEDFORMAT
: return "The FourCC format requested is not supported by DirectDraw.";
case DDERR_UNSUPPORTEDMASK
: return "The bitmask in the pixel format requested is not supported by DirectDraw.";
case DDERR_UNSUPPORTEDMODE
: return "The display is currently in an unsupported mode.";
case DDERR_VERTICALBLANKINPROGRESS
: return "A vertical blank is in progress.";
case DDERR_WASSTILLDRAWING
: return "The previous blit operation that is transferring information to or from this surface is incomplete.";
case DDERR_WRONGMODE
: return "This surface cannot be restored because it was created in a different mode.";
case DDERR_XALIGN
: return "The provided rectangle was not horizontally aligned on a required boundary.";
default
: return "Unrecognized error value.\0";
}
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef __DirectX_Common_H__
#define __DirectX_Common_H__
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
// local functions
char* DirectXErrorDescription ( INT32 iDXReturn );
void DirectXAttempt ( INT32 iErrorCode, INT32 nLine, char *szFilename );
void DirectXAssert ( BOOLEAN fValue, INT32 nLine, char *szFilename );
void DirectXZeroMem ( void* pMemory, int nSize );
#undef ATTEMPT
#define ATTEMPT(x) DirectXAttempt ((x),__LINE__,__FILE__)
#undef ZEROMEM
#define ZEROMEM(x) DirectXZeroMem ( (void*)&(x), sizeof(x) )
#undef DEBUGMSG
#define DEBUGMSG(x) OutputDebugString(x)
#ifdef __cplusplus
}
#endif
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,558 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "Types.h"
#include <stdlib.h>
#include <malloc.h>
#include <stdio.h>
#endif
#include "ExceptionHandling.h"
#ifdef JA2
#include "GameVersion.h"
#endif
//If we are to use exception handling
#ifdef ENABLE_EXCEPTION_HANDLING
const int NumCodeBytes = 16; // Number of code bytes to record.
const int MaxStackDump = 2048; // Maximum number of DWORDS in stack dumps.
const int StackColumns = 8; // Number of columns in stack dump.
#define ONEK 1024
#define SIXTYFOURK (64*ONEK)
#define ONEM (ONEK*ONEK)
#define ONEG (ONEK*ONEK*ONEK)
//ppp
void ErrorLog(HWFILE LogFile, char* Format, ...);
STR GetExceptionString( DWORD uiExceptionCode );
void DisplayRegisters( HWFILE hFile, CONTEXT *pContext );
BOOLEAN GetAndDisplayModuleAndSystemInfo( HWFILE hFile, CONTEXT *pContext );
BOOLEAN DisplayStack( HWFILE hFile, CONTEXT *pContext );
void RecordModuleList(HWFILE hFile );
void PrintTime(char *output, FILETIME TimeToPrint);
static void ShowModuleInfo(HWFILE hFile, HINSTANCE ModuleHandle);
INT32 RecordExceptionInfo( EXCEPTION_POINTERS *pExceptInfo )
{
EXCEPTION_RECORD Record;
CONTEXT Context;
CHAR8 zFileName[512];
CHAR8 zDate[512];
CHAR8 zTime[512];
HWFILE hFile;
CHAR8 zString[2048];
SYSTEMTIME SysTime;
CHAR8 zNewLine[] = "\r\n";
//create local copies of the exception info
memcpy( &Record, pExceptInfo->ExceptionRecord , sizeof( EXCEPTION_RECORD ) );
memcpy( &Context, pExceptInfo->ContextRecord, sizeof( CONTEXT ) );
//
// Open a file to output the current state of the game
//
// Get the current time
GetLocalTime( &SysTime );
//create a date string
sprintf( zDate, "%02d_%02d_%d", SysTime.wDay, SysTime.wMonth, SysTime.wYear );
//create a time string
sprintf( zTime, "%02d_%02d", SysTime.wHour, SysTime.wMinute );
//create the crash file
sprintf( zFileName, "Crash Report_%s___%s.txt", zDate, zTime );
// create the save game file
hFile = FileOpen( zFileName, FILE_ACCESS_WRITE | FILE_OPEN_ALWAYS, FALSE );
if( !hFile )
{
FileClose( hFile );
return( 0 );
}
//
// Display the version number
//
#ifdef JA2
//Dispay Ja's version number
ErrorLog( hFile, "%S: %s. %S",zVersionLabel, czVersionNumber, zTrackingNumber );
//Insert a new line
ErrorLog( hFile, zNewLine );
//Insert a new line
ErrorLog( hFile, zNewLine );
#endif
//
// Write out the current state of the system
//
GetAndDisplayModuleAndSystemInfo( hFile, &Context );
//Insert a new line
ErrorLog( hFile, zNewLine );
//Display the address of where the exception occured
sprintf( zString, "Exception occured at address: 0x%08x\r\n", Record.ExceptionAddress );
ErrorLog( hFile, zString );
//if the exception was an access violation, display the offending address
if( Record.ExceptionCode == EXCEPTION_ACCESS_VIOLATION && Record.NumberParameters != 0 )
{
if( Record.ExceptionInformation[0] != 0 )
{
//Display the address of where the access violation occured
sprintf( zString, "\tWrite Access Violation at: 0x%08x\r\n", Record.ExceptionInformation[1] );
}
else
{
//Display the address of where the access violation occured
sprintf( zString, "\tWrite Access Violation at: 0x%08x\r\n", Record.ExceptionInformation[1] );
}
ErrorLog( hFile, zString );
}
//Insert a new line
ErrorLog( hFile, zNewLine );
//Display the exception that caused this
sprintf( zString, "Exact Error Message \r\n \"%s\"\r\n", GetExceptionString( Record.ExceptionCode ) );
ErrorLog( hFile, zString );
//Insert a new line
ErrorLog( hFile, zNewLine );
//Dispay if the code 'could' continue
if( Record.ExceptionFlags != 0 )
sprintf( zString, "%s\r\n", "The game 'can NOT' continue" );
else
sprintf( zString, "%s\r\n", "The game 'CAN' continue" );
ErrorLog( hFile, zString );
//Insert a new line
ErrorLog( hFile, zNewLine );
ErrorLog( hFile, zNewLine );
//
// Display the current context information
//
DisplayRegisters( hFile, &Context );
ErrorLog( hFile, zNewLine );
ErrorLog( hFile, zNewLine );
//display the stack ( call stack + local variables )
DisplayStack( hFile, &Context);
//Display some spaces
ErrorLog( hFile, zNewLine );
ErrorLog( hFile, zNewLine );
//Display all modules currently loaded
RecordModuleList(hFile );
//eee
FileClose( hFile );
return( EXCEPTION_EXECUTE_HANDLER );
}
void ErrorLog( HWFILE hFile, char* Format, ...)
{
char buffer[2000]; // wvsprintf never prints more than one K.
UINT32 uiNumBytesWritten=0;
UINT32 uiStringWidth;
va_list arglist;
va_start( arglist, Format);
wvsprintf(buffer, Format, arglist);
va_end( arglist);
//WriteFile(LogFile, buffer, lstrlen(buffer), &NumBytes, 0);
uiStringWidth = lstrlen(buffer);
//write out the string
FileWrite( hFile, buffer, uiStringWidth, &uiNumBytesWritten );
if( uiNumBytesWritten != uiStringWidth )
{
FileClose( hFile );
return;
}
}
STR GetExceptionString( DWORD uiExceptionCode )
{
switch( uiExceptionCode )
{
case EXCEPTION_ACCESS_VIOLATION:
return( "The thread tried to read from or write to a virtual address for which it does not have the appropriate access.");
break;
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
return( "The thread tried to access an array element that is out of bounds and the underlying hardware supports bounds checking.");
case EXCEPTION_BREAKPOINT:
return( "A breakpoint was encountered.");
case EXCEPTION_DATATYPE_MISALIGNMENT:
return( "The thread tried to read or write data that is misaligned on hardware that does not provide alignment. For example, 16-bit values must be aligned on 2-byte boundaries; 32-bit values on 4-byte boundaries, and so on.");
case EXCEPTION_FLT_DENORMAL_OPERAND:
return( "One of the operands in a floating-point operation is denormal. A denormal value is one that is too small to represent as a standard floating-point value.");
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
return( "The thread tried to divide a floating-point value by a floating-point divisor of zero.");
case EXCEPTION_FLT_INEXACT_RESULT:
return( "The result of a floating-point operation cannot be represented exactly as a decimal fraction.");
case EXCEPTION_FLT_INVALID_OPERATION:
return( "This exception represents any floating-point exception not included in this list.");
case EXCEPTION_FLT_OVERFLOW:
return( "The exponent of a floating-point operation is greater than the magnitude allowed by the corresponding type.");
case EXCEPTION_FLT_STACK_CHECK:
return( "The stack overflowed or underflowed as the result of a floating-point operation.");
case EXCEPTION_FLT_UNDERFLOW:
return( "The exponent of a floating-point operation is less than the magnitude allowed by the corresponding type.");
case EXCEPTION_ILLEGAL_INSTRUCTION:
return( "The thread tried to execute an invalid instruction.");
case EXCEPTION_IN_PAGE_ERROR:
return( "The thread tried to access a page that was not present, and the system was unable to load the page. For example, this exception might occur if a network connection is lost while running a program over the network.");
case EXCEPTION_INT_DIVIDE_BY_ZERO:
return( "The thread tried to divide an integer value by an integer divisor of zero.");
case EXCEPTION_INT_OVERFLOW:
return( "The result of an integer operation caused a carry out of the most significant bit of the result.");
case EXCEPTION_INVALID_DISPOSITION:
return( "An exception handler returned an invalid disposition to the exception dispatcher. Programmers using a high-level language such as C should never encounter this exception.");
case EXCEPTION_NONCONTINUABLE_EXCEPTION:
return( "The thread tried to continue execution after a noncontinuable exception occurred.");
case EXCEPTION_PRIV_INSTRUCTION:
return( "The thread tried to execute an instruction whose operation is not allowed in the current machine mode.");
case EXCEPTION_SINGLE_STEP:
return( "A trace trap or other single-instruction mechanism signaled that one instruction has been executed.");
case EXCEPTION_STACK_OVERFLOW:
return( "The thread used up its stack.");
default:
return("Exception not in case ");
break;
}
}
void DisplayRegisters( HWFILE hFile, CONTEXT *pContext )
{
ErrorLog( hFile, "Registers:\r\n");
ErrorLog( hFile, "\tEAX=%08x CS=%04x EIP=%08x EFLGS=%08x\r\n",
pContext->Eax, pContext->SegCs, pContext->Eip, pContext->EFlags);
ErrorLog( hFile, "\tEBX=%08x SS=%04x ESP=%08x EBP=%08x\r\n",
pContext->Ebx, pContext->SegSs, pContext->Esp, pContext->Ebp);
ErrorLog( hFile, "\tECX=%08x DS=%04x ESI=%08x FS=%04x\r\n",
pContext->Ecx, pContext->SegDs, pContext->Esi, pContext->SegFs);
ErrorLog( hFile, "\tEDX=%08x ES=%04x EDI=%08x GS=%04x\r\n",
pContext->Edx, pContext->SegEs, pContext->Edi, pContext->SegGs);
// ErrorLog( hFile, "Bytes at CS:EIP:\r\n");
}
BOOLEAN GetAndDisplayModuleAndSystemInfo( HWFILE hFile, CONTEXT *pContext )
{
char zFileName[2048];
char zString[2048];
SYSTEM_INFO SystemInfo;
MEMORYSTATUS MemInfo;
// MEMORY_BASIC_INFORMATION MemBasicInfo;
size_t PageSize;
size_t pageNum = 0;
FILETIME LastWriteTime;
if( GetModuleFileName(0, zFileName, sizeof(zFileName) ) == 0)
{
return( FALSE );
}
MemInfo.dwLength = sizeof(MemInfo);
GlobalMemoryStatus(&MemInfo);
//Display the filename
ErrorLog( hFile, "File:\r\n\t%s\r\n", zFileName);
//Get the time the file was created
if (GetFileTime(GetRealFileHandleFromFileManFileHandle( hFile ), 0, 0, &LastWriteTime))
{
PrintTime( zString, LastWriteTime);
ErrorLog( hFile, "\tFile created on: %s\r\n", zString );
}
//Get cpu type and number
GetSystemInfo(&SystemInfo);
ErrorLog( hFile, "\t%d type %d processor.\r\n", SystemInfo.dwNumberOfProcessors, SystemInfo.dwProcessorType );
//Get free ram
ErrorLog( hFile, "\tTotal Physical Memory: %d Megs.\r\n", MemInfo.dwTotalPhys/(1024*1024) );
PageSize = SystemInfo.dwPageSize;
pageNum = 0;
/*
//Get current instruction pointer
if( VirtualQuery((void *)(pageNum * PageSize), &MemBasicInfo, sizeof(MemBasicInfo) ) )
{
if (MemBasicInfo.RegionSize > 0)
{
ErrorLog( hFile, "\r\n\r\nJagged is loaded into memory at: 0x%08d.\r\n", MemBasicInfo.AllocationBase );
}
}
*/
ErrorLog( hFile, "Segment( CS:EIP ):\t%04x:%08x.\r\n", pContext->SegCs, pContext->Eip );
return( TRUE );
}
//
// This code for this function is based ( stolen ) from Bruce Dawson's article in Game Developer Magazine Jan 99
//
BOOLEAN DisplayStack( HWFILE hFile, CONTEXT *pContext )
{
int Count = 0;
char buffer[1000] = "";
const int safetyzone = 50;
char* nearend = buffer + sizeof(buffer) - safetyzone;
char* output = buffer;
// Time to print part or all of the stack to the error log. This allows
// us to figure out the call stack, parameters, local variables, etc.
ErrorLog( hFile, "Stack dump:\r\n" );
__try
{
// Esp contains the bottom of the stack, or at least the bottom of
// the currently used area.
DWORD* pStack = (DWORD *)pContext->Esp;
DWORD* pStackTop;
__asm
{
// Load the top (highest address) of the stack from the
// thread information block. It will be found there in
// Win9x and Windows NT.
mov eax, fs:[4]
mov pStackTop, eax
}
if (pStackTop > pStack + MaxStackDump)
pStackTop = pStack + MaxStackDump;
// Too many calls to WriteFile can take a long time, causing
// confusing delays when programs crash. Therefore I implemented
// simple buffering for the stack dumping code instead of calling
// hprintf directly.
while (pStack + 1 <= pStackTop)
{
char *Suffix = " ";
if ((Count % StackColumns) == 0)
output += wsprintf(output, "%08x: ", pStack);
if ((++Count % StackColumns) == 0 || pStack + 2 > pStackTop)
Suffix = "\r\n";
output += wsprintf(output, "%08x%s", *pStack, Suffix);
pStack++;
// Check for when the buffer is almost full, and flush it to disk.
if (output > nearend)
{
ErrorLog( hFile, "%s", buffer);
buffer[0] = 0;
output = buffer;
}
}
// Print out any final characters from the cache.
ErrorLog( hFile, "%s", buffer);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
ErrorLog( hFile, "Exception encountered during stack dump.\r\n");
}
return( TRUE );
}
//
// This code for this function is ( stolen :) from Bruce Dawson's article in Game Developer Magazine Jan 99
//
// Print the specified FILETIME to output in a human readable format,
// without using the C run time.
void PrintTime(char *output, FILETIME TimeToPrint)
{
WORD Date, Time;
if (FileTimeToLocalFileTime(&TimeToPrint, &TimeToPrint) &&
FileTimeToDosDateTime(&TimeToPrint, &Date, &Time))
{
// What a silly way to print out the file date/time. Oh well,
// it works, and I'm not aware of a cleaner way to do it.
wsprintf(output, "%02d/%02d/%d %02d:%02d:%02d",
(Date / 32) & 15, Date & 31, (Date / 512) + 1980,
(Time / 2048), (Time / 32) & 63, (Time & 31) * 2);
}
else
output[0] = 0;
}
//
// This code for this function is ( stolen :) from Bruce Dawson's article in Game Developer Magazine Jan 99
//
// Scan memory looking for code modules (DLLs or EXEs). VirtualQuery is used
// to find all the blocks of address space that were reserved or committed,
// and ShowModuleInfo will display module information if they are code
// modules.
void RecordModuleList(HWFILE hFile )
{
ErrorLog( hFile, "\r\n"
"Module list: names, addresses, sizes, time stamps "
"and file times:\r\n");
SYSTEM_INFO SystemInfo;
GetSystemInfo(&SystemInfo);
const size_t PageSize = SystemInfo.dwPageSize;
// Set NumPages to the number of pages in the 4GByte address space,
// while being careful to avoid overflowing ints.
const size_t NumPages = 4 * size_t(ONEG / PageSize);
size_t pageNum = 0;
void *LastAllocationBase = 0;
while (pageNum < NumPages)
{
MEMORY_BASIC_INFORMATION MemInfo;
if (VirtualQuery((void *)(pageNum * PageSize), &MemInfo,
sizeof(MemInfo)))
{
if (MemInfo.RegionSize > 0)
{
// Adjust the page number to skip over this block of memory.
pageNum += MemInfo.RegionSize / PageSize;
if (MemInfo.State == MEM_COMMIT && MemInfo.AllocationBase >
LastAllocationBase)
{
// Look for new blocks of committed memory, and try
// recording their module names - this will fail
// gracefully if they aren't code modules.
LastAllocationBase = MemInfo.AllocationBase;
ShowModuleInfo(hFile, (HINSTANCE)LastAllocationBase);
}
}
else
pageNum += SIXTYFOURK / PageSize;
}
else
pageNum += SIXTYFOURK / PageSize;
// If VirtualQuery fails we advance by 64K because that is the
// granularity of address space doled out by VirtualAlloc().
}
}
//
// This code for this function is ( stolen :) from Bruce Dawson's article in Game Developer Magazine Jan 99
//
static void ShowModuleInfo(HWFILE hFile, HINSTANCE ModuleHandle)
{
char ModName[MAX_PATH];
__try
{
if (GetModuleFileName(ModuleHandle, ModName, sizeof(ModName)) > 0)
{
// If GetModuleFileName returns greater than zero then this must
// be a valid code module address. Therefore we can try to walk
// our way through its structures to find the link time stamp.
IMAGE_DOS_HEADER *DosHeader = (IMAGE_DOS_HEADER*)ModuleHandle;
if (IMAGE_DOS_SIGNATURE != DosHeader->e_magic)
return;
IMAGE_NT_HEADERS *NTHeader = (IMAGE_NT_HEADERS*)((char *)DosHeader
+ DosHeader->e_lfanew);
if (IMAGE_NT_SIGNATURE != NTHeader->Signature)
return;
// Open the code module file so that we can get its file date
// and size.
HANDLE ModuleFile = CreateFile(ModName, GENERIC_READ,
FILE_SHARE_READ, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
char TimeBuffer[100] = "";
DWORD FileSize = 0;
if (ModuleFile != INVALID_HANDLE_VALUE)
{
FileSize = GetFileSize(ModuleFile, 0);
FILETIME LastWriteTime;
if (GetFileTime(ModuleFile, 0, 0, &LastWriteTime))
{
wsprintf(TimeBuffer, " - file date is ");
PrintTime(TimeBuffer + lstrlen(TimeBuffer), LastWriteTime);
}
CloseHandle(ModuleFile);
}
ErrorLog( hFile, "%-35s, loaded at 0x%08x - %7d bytes - %08x%s\r\n",
ModName, ModuleHandle, FileSize,
NTHeader->FileHeader.TimeDateStamp, TimeBuffer);
}
}
// Handle any exceptions by continuing from this point.
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
#endif
@@ -0,0 +1,31 @@
#ifndef _EXCEPTION_HANDLING__H_
#define _EXCEPTION_HANDLING__H_
//uncomment this line if you want Exceptions to be handled
#ifdef JA2
#ifndef _DEBUG
#define ENABLE_EXCEPTION_HANDLING
#endif
#else
//Wizardry
//#define ENABLE_EXCEPTION_HANDLING
#endif
#ifdef __cplusplus
extern "C" {
#endif
INT32 RecordExceptionInfo( EXCEPTION_POINTERS *pExceptInfo );
#ifdef __cplusplus
}
#endif
#endif
+97
View File
@@ -0,0 +1,97 @@
//
// Snap: Implementation of the TFileCat class
//
#include "FileCat.h"
#include "readdir.h"
// Remove a slash or backslash (if any) from the end of a string
void ChompSlash(std::string& s)
{
if ( s.empty() ) return;
if ( *s.rbegin() == '\\' || *s.rbegin() == '/' ) {
s.erase( s.length() - 1 );
}
}
// Build a new file catalogue by recursively traversing the root directory
void TFileCat::NewCat(std::string root)
{
fRootDir = root;
ChompSlash(fRootDir);
fFileCat.clear();
TraverseDir(fRootDir);
}
// Look for a given file in the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
bool TFileCat::FindFile(std::string path, bool pathIncludesRoot) const
{
if (pathIncludesRoot) return fFileCat.find(path) != fFileCat.end();
else return fFileCat.find(fRootDir + '\\' + path) != fFileCat.end();
}
// Delete a given file from the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
size_t TFileCat::RemoveFile(std::string path, bool pathIncludesRoot)
{
if (pathIncludesRoot) return fFileCat.erase(path);
else return fFileCat.erase(fRootDir + '\\' + path);
}
// Delete all files from a given directory in the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
size_t TFileCat::RemoveDir(std::string dir, bool pathIncludesRoot)
{
if ( !pathIncludesRoot ) dir = fRootDir + '\\' + dir;
ChompSlash(dir);
std::string dirlower = dir + '\\';
std::string dirupper = dir + char('\\'+1);
TCatalogue::iterator upper = fFileCat.upper_bound(dirupper);
TCatalogue::iterator lower;
int deleted = 0;
while ( ( lower = fFileCat.lower_bound(dirlower) ) != upper) {
fFileCat.erase(lower);
deleted++;
}
return deleted;
}
// Recursively traverse a directory, adding regular files to the catalogue
void TFileCat::TraverseDir(std::string dir, int depth)
{
using std::string;
if (!dir.empty()) dir += '\\';
TReadDir readDir((dir + "*").c_str());
char const* fileName;
unsigned attrib;
while ( readDir.NextFile(fileName, attrib) ) {
if (string(".") == fileName || string("..") == fileName) continue;
string fullPath = dir + fileName;
if (attrib & FILE_ATTRIBUTE_DIRECTORY) {
if (depth < 0) TraverseDir(fullPath);
else if (depth > 0) TraverseDir(fullPath, depth-1);
}
else {
fFileCat.insert(fullPath);
}
}
}
+48
View File
@@ -0,0 +1,48 @@
//
// Snap: Declaration of the TFileCat class
//
// This class catalogues files in a directory and all its subdirectories
//
#ifndef FILECAT_H
#define FILECAT_H
#include "stringicmp.h"
#include <string>
#include <set>
class TFileCat {
public:
TFileCat(std::string root) { NewCat(root); }
TFileCat() {}
// Build a new file catalogue by recursively traversing the root directory
void NewCat(std::string root);
std::string GetRootDir() const { return fRootDir; }
// Look for a given file in the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
bool FindFile(std::string path, bool pathIncludesRoot = false) const;
// Delete a given file from the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
size_t RemoveFile(std::string path, bool pathIncludesRoot = false);
// Delete all files from a given directory in the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
size_t RemoveDir(std::string dir, bool pathIncludesRoot = false);
private:
typedef std::set<std::string, TStringiLess> TCatalogue;
std::string fRootDir;
TCatalogue fFileCat;
// Recursively traverse a directory, adding regular files to the catalogue
void TraverseDir(std::string dir, int depth = -1);
};
#endif // FILECAT_H
File diff suppressed because it is too large Load Diff
+199
View File
@@ -0,0 +1,199 @@
//**************************************************************************
//
// Filename : FileMan.h
//
// Purpose : prototypes for the file manager
//
// Modification history :
//
// 24sep96:HJH - Creation
//
//**************************************************************************
#ifndef _FILEMAN_H
#define _FILEMAN_H
//**************************************************************************
//
// Includes
//
//**************************************************************************
#include "types.h"
#include "Windows.h"
#include "FileCat.h"
//**************************************************************************
//
// Defines
//
//**************************************************************************
#define MAX_FILENAME_LEN 48
#define FILE_ACCESS_READ 0x01
#define FILE_ACCESS_WRITE 0x02
#define FILE_ACCESS_READWRITE 0x03
#define FILE_CREATE_NEW 0x0010 // create new file. fail if exists
#define FILE_CREATE_ALWAYS 0x0020 // create new file. overwrite existing
#define FILE_OPEN_EXISTING 0x0040 // open a file. fail if doesn't exist
#define FILE_OPEN_ALWAYS 0x0080 // open a file, create if doesn't exist
#define FILE_TRUNCATE_EXISTING 0x0100 // open a file, truncate to size 0. fail if no exist
#define FILE_SEEK_FROM_START 0x01 // keep in sync with dbman.h
#define FILE_SEEK_FROM_END 0x02 // keep in sync with dbman.h
#define FILE_SEEK_FROM_CURRENT 0x04 // keep in sync with dbman.h
// GetFile file attributes
#define FILE_IS_READONLY 1
#define FILE_IS_DIRECTORY 2
#define FILE_IS_HIDDEN 4
#define FILE_IS_NORMAL 8
#define FILE_IS_ARCHIVE 16
#define FILE_IS_SYSTEM 32
#define FILE_IS_TEMPORARY 64
#define FILE_IS_COMPRESSED 128
#define FILE_IS_OFFLINE 256
//File Attributes settings
#define FILE_ATTRIBUTES_ARCHIVE FILE_ATTRIBUTE_ARCHIVE
#define FILE_ATTRIBUTES_HIDDEN FILE_ATTRIBUTE_HIDDEN
#define FILE_ATTRIBUTES_NORMAL FILE_ATTRIBUTE_NORMAL
#define FILE_ATTRIBUTES_OFFLINE FILE_ATTRIBUTE_OFFLINE
#define FILE_ATTRIBUTES_READONLY FILE_ATTRIBUTE_READONLY
#define FILE_ATTRIBUTES_SYSTEM FILE_ATTRIBUTE_SYSTEM
#define FILE_ATTRIBUTES_TEMPORARY FILE_ATTRIBUTE_TEMPORARY
#define FILE_ATTRIBUTES_DIRECTORY FILE_ATTRIBUTE_DIRECTORY
// Snap, Kaiden: This define duplicates a standard MFC define
// Added to resolve some intractable issue with MSVC6
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
typedef FILETIME SGP_FILETIME;
//**************************************************************************
//
// Globals
//
//**************************************************************************
// Snap: At program launch we build two directory catalogues:
// one for the default Data directory, the other for the custom Data directory.
extern TFileCat gDefaultDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp)
extern TFileCat gCustomDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp)
//**************************************************************************
//
// Function Prototypes
//
//**************************************************************************
/*
#ifdef __cplusplus
extern "C" {
#endif
*/
extern BOOLEAN InitializeFileManager( STR strIndexFilename );
extern void ShutdownFileManager( void );
extern void FileDebug( BOOLEAN f );
BOOLEAN FileExists( STR strFilename );
extern BOOLEAN FileExistsNoDB( STR strFilename );
extern BOOLEAN FileDelete( STR strFilename );
extern HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose );
extern void FileClose( HWFILE );
extern BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead );
extern BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBytesWritten );
extern BOOLEAN FileLoad( STR filename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead );
extern BOOLEAN _cdecl FilePrintf( HWFILE hFile, char * strFormatted, ... );
extern BOOLEAN FileSeek( HWFILE, UINT32 uiDistance, UINT8 uiHow );
extern INT32 FileGetPos( HWFILE );
extern UINT32 FileGetSize( HWFILE );
extern UINT32 FileSize(STR strFilename);
BOOLEAN SetFileManCurrentDirectory( STR pcDirectory );
BOOLEAN GetFileManCurrentDirectory( STRING512 pcDirectory );
BOOLEAN GetExecutableDirectory( STRING512 pcDirectory );
BOOLEAN DirectoryExists( STRING512 pcDirectory );
BOOLEAN MakeFileManDirectory( STRING512 pcDirectory );
// WARNING: THESE DELETE ALL FILES IN THE DIRECTORY ( and all subdirectories if fRecursive is TRUE!! )
BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive);
BOOLEAN EraseDirectory( STRING512 pcDirectory);
typedef struct _GETFILESTRUCT_TAG {
INT32 iFindHandle;
CHAR8 zFileName[ 260 ]; // changed from UINT16, Alex Meduna, Mar-20'98
UINT32 uiFileSize;
UINT32 uiFileAttribs;
} GETFILESTRUCT;
BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct );
BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct );
void GetFileClose( GETFILESTRUCT *pGFStruct );
BOOLEAN FileCopy(STR strSrcFile, STR strDstFile, BOOLEAN fFailIfExists);
BOOLEAN FileMove(STR strOldName, STR strNewName);
//Added by Kris Morness
BOOLEAN FileSetAttributes( STR filename, UINT32 uiNewAttribs );
UINT32 FileGetAttributes( STR filename );
BOOLEAN FileClearAttributes( STR strFilename );
//returns true if at end of file, else false
BOOLEAN FileCheckEndOfFile( HWFILE hFile );
BOOLEAN GetFileManFileTime( HWFILE hFile, SGP_FILETIME *pCreationTime, SGP_FILETIME *pLastAccessedTime, SGP_FILETIME *pLastWriteTime );
// CompareSGPFileTimes() returns...
// -1 if the First file time is less than second file time. ( first file is older )
// 0 First file time is equal to second file time.
// +1 First file time is greater than second file time ( first file is newer ).
INT32 CompareSGPFileTimes( SGP_FILETIME *pFirstFileTime, SGP_FILETIME *pSecondFileTime );
// One call comparison of file times, allowing for a certain leeway in cases where
// files times may be slightly different due to SourceSafe of copying
BOOLEAN FileIsOlderThanFile(CHAR8 *pcFileName1, CHAR8 *pcFileName2, UINT32 ulNumSeconds);
// Pass in the Fileman file handle of an OPEN file and it will return..
// if its a Real File, the return will be the handle of the REAL file
// if its a LIBRARY file, the return will be the handle of the LIBRARY
HANDLE GetRealFileHandleFromFileManFileHandle( HWFILE hFile );
BOOLEAN AddSubdirectoryToPath(CHAR8 *pDirectory);
//Gets the amount of free space on the hard drive that the main executeablt is runnning from
UINT32 GetFreeSpaceOnHardDriveWhereGameIsRunningFrom( );
//Gets the free hard drive space from the drive letter passed in. It has to be the root dir. ( eg. c:\ )
UINT32 GetFreeSpaceOnHardDrive( STR pzDriveLetter );
/*
#ifdef __cplusplus
}
#endif
*/
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+194
View File
@@ -0,0 +1,194 @@
#ifndef __FONT_H_
#define __FONT_H_
#include "Types.h"
#include "himage.h"
#include "vobject.h"
#define DEFAULT_SHADOW 2
#define MILITARY_SHADOW 67
#define NO_SHADOW 0
#ifdef JA2
// these are bogus! No palette is set yet!
// font foreground color symbols
#define FONT_FCOLOR_WHITE 208
#define FONT_FCOLOR_RED 162
#define FONT_FCOLOR_NICERED 164
#define FONT_FCOLOR_BLUE 203
#define FONT_FCOLOR_GREEN 184
#define FONT_FCOLOR_YELLOW 144
#define FONT_FCOLOR_BROWN 184
#define FONT_FCOLOR_ORANGE 76
#define FONT_FCOLOR_PURPLE 160
// font background color symbols
#define FONT_BCOLOR_WHITE 208
#define FONT_BCOLOR_RED 162
#define FONT_BCOLOR_BLUE 203
#define FONT_BCOLOR_GREEN 184
#define FONT_BCOLOR_YELLOW 144
#define FONT_BCOLOR_BROWN 80
#define FONT_BCOLOR_ORANGE 76
#define FONT_BCOLOR_PURPLE 160
#else
// font foreground color symbols
#define FONT_FCOLOR_WHITE 0x0000
#define FONT_FCOLOR_RED 0x0000
#define FONT_FCOLOR_BLUE 0x0000
#define FONT_FCOLOR_GREEN 0x0000
#define FONT_FCOLOR_YELLOW 0x0000
#define FONT_FCOLOR_BROWN 0x0000
#define FONT_FCOLOR_ORANGE 0x0000
#define FONT_FCOLOR_PURPLE 0x0000
// font background color symbols
#define FONT_BCOLOR_WHITE 0x0000
#define FONT_BCOLOR_RED 0x0000
#define FONT_BCOLOR_BLUE 0x0000
#define FONT_BCOLOR_GREEN 0x0000
#define FONT_BCOLOR_YELLOW 0x0000
#define FONT_BCOLOR_BROWN 0x0000
#define FONT_BCOLOR_ORANGE 0x0000
#define FONT_BCOLOR_PURPLE 0x0000
// font glyphs for spell targeting types
#define FONT_GLYPH_TARGET_POINT 0xFFF0
#define FONT_GLYPH_TARGET_CONE 0xFFF1
#define FONT_GLYPH_TARGET_SINGLE 0xFFF2
#define FONT_GLYPH_TARGET_GROUP 0xFFF3
#define FONT_GLYPH_TARGET_NONE 0xFFF4
#endif
// typedefs
typedef struct
{
UINT16 usNumberOfSymbols;
UINT16 *DynamicArrayOf16BitValues;
} FontTranslationTable;
/*
#ifdef __cplusplus
extern "C" {
#endif
*/
extern INT32 FontDefault;
extern UINT32 FontDestBuffer;
extern UINT32 FontDestPitch;
extern UINT32 FontDestBPP;
extern SGPRect FontDestRegion;
extern BOOLEAN FontDestWrap;
#define SetFontDestObject(x) (SetFontDestBuffer(x, \
FontDestRegion.left, \
FontDestRegion.top, \
FontDestRegion.right, \
FontDestRegion.bottom,\
FontDestWrap))
#define SetFontDestClip(x1, y1, x2, y2) (SetFontDestBuffer(FontDestBuffer, \
x1, y1, \
x2, y2, \
FontDestWrap))
#define SetFontDestWrap(x) (SetFontDestBuffer(FontDestBuffer, \
FontDestRegion.left, \
FontDestRegion.top, \
FontDestRegion.right, \
FontDestRegion.bottom,\
x))
// functions
void SetFontColors(UINT16 usColors);
void SetFontForeground(UINT8 ubForeground);
void SetFontBackground(UINT8 ubBackground);
void SetFontShadow(UINT8 ubBackground);
//Kris: added these
void SetRGBFontForeground( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue );
void SetRGBFontBackground( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue );
void SetRGBFontShadow( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue );
BOOLEAN ResetFontObjectPalette(INT32 iFont);
UINT16 *SetFontObjectPalette8BPP(INT32 iFont, SGPPaletteEntry *pPal8);
UINT16 *SetFontObjectPalette16BPP(INT32 iFont, UINT16 *pPal16);
UINT16 *GetFontObjectPalette16BPP(INT32 iFont);
void DestroyEnglishTransTable( void );
extern HVOBJECT GetFontObject(INT32 iFont);
extern UINT32 gprintf(INT32 x, INT32 y, UINT16 *pFontString, ...);
extern UINT32 gprintfDirty(INT32 x, INT32 y, UINT16 *pFontString, ...);
template <typename type3>
extern UINT32 mprintf(INT32 x, INT32 y, type3 pFontString, ...);
extern UINT32 gprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, UINT16 *pFontString, ...);
template <typename string6>
extern UINT32 mprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, string6 pFontString, ...);
// Function for displaying coded test. Since it's slower to do this, it's separate from the normal fuctions
#define FONT_CODE_BEGINCOLOR 180
#define FONT_CODE_RESETCOLOR 181
template <typename string6>
UINT32 mprintf_buffer_coded( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, string6 pFontString, ...);
UINT32 mprintf_coded( INT32 x, INT32 y, UINT16 *pFontString, ...);
extern BOOLEAN SetFontDestBuffer(UINT32 DestBuffer, INT32 x1, INT32 y1, INT32 x2, INT32 y2, BOOLEAN wrap);
extern BOOLEAN SetFont(INT32 iFontIndex);
template <typename string1>
extern INT32 LoadFontFile(string1 pFileName);
extern UINT16 GetFontHeight(INT32 FontNum);
extern BOOLEAN InitializeFontManager(UINT16 usDefaultPixDepth, FontTranslationTable *pTransTable);
extern void ShutdownFontManager(void);
extern void UnloadFont(UINT32 FontIndex);
extern FontTranslationTable *CreateEnglishTransTable( );
extern INT16 GetIndex(UINT16 siChar);
extern UINT32 GetWidth(HVOBJECT hSrcVObject, INT16 ssIndex);
extern INT16 StringPixLengthArgFastHelp( INT32 usUseFont, INT32 usBoldFont, UINT32 uiCharCount, UINT16 *pFontString );
extern INT16 StringPixLengthArg(INT32 usUseFont, UINT32 uiCharCount, UINT16 *pFontString, ...);
template <typename type1>
extern INT16 StringPixLength(type1 string,INT32 UseFont);
extern INT16 StringNPixLength(UINT16 *string, UINT32 uiMaxCount, INT32 UseFont);
extern void SaveFontSettings(void);
extern void RestoreFontSettings(void);
template <typename type8>
void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, type8 pFontString, ... );
template <typename type8>
void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, type8 pFontString, ... );
template <typename string5, typename string7, typename string8>
void FindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, string5 pStr, INT32 iFontIndex, string7 psNewX, string8 psNewY );
template <typename string5, typename string7, typename string8>
void FindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, string5 pStr, INT32 iFontIndex, string7 psNewX, string8 psNewY );
//extern FontBase *LoadFontFile(UINT8 *pFileName);
//extern UINT8 *GetFontPalette(UINT8 *pFileName);
//extern UINT16 GetMaxFontWidth(FontBase *pBase);
//extern void UnloadFont(FontBase *pBase);
//extern BOOLEAN SetFontPalette(FontBase *pFont, UINT16 siDepthPix, SGPPaletteEntry *pNewPalette);
// make sure the pFontString is terminated by 0
//extern BOOLEAN PrintFontString(UINT16 *pFontString, UINT8 *pDestBuffer, UINT16 siDestWidth, UINT16 siDestPixelDepth, UINT16 siDestPitch, UINT16 siDestHeight, UINT16 siX, UINT16 siY, UINT16 siTotalWidth, UINT16 siTotalHeight, BOOLEAN MultiLine, FontBase *pFontBase);
//extern BOOLEAN SetFont16BitData(FontBase *pFontBase, UINT16 *pData16);
/*
#ifdef __cplusplus
}
#endif
*/
#endif
+64
View File
@@ -0,0 +1,64 @@
//**************************************************************************
//
// Filename : Install.c
//
// Purpose : install routines
//
// Modification history :
//
// 02dec96:HJH - Creation
//
//**************************************************************************
//**************************************************************************
//
// Includes
//
//**************************************************************************
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "types.h"
#include <windows.h>
#include <tchar.h>
#include <assert.h>
#include "Install.h"
#include "RegInst.h"
#endif
//**************************************************************************
//
// Defines
//
//**************************************************************************
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
//**************************************************************************
//
// Functions
//
//**************************************************************************
BOOLEAN InstallApplication( STR strAppname, STR strPath )
{
HKEY hKey;
BOOL fRet = TRUE;
hKey = GetAppRegistryKey();
RegCloseKey( hKey );
//hKeySection = GetSectionKey("Startup");
//RegCloseKey( hKeySection );
fRet = fRet && WriteProfileChar( "Startup", "InstPath", strPath );
return(fRet);
}
+52
View File
@@ -0,0 +1,52 @@
//**************************************************************************
//
// Filename : Install.h
//
// Purpose : prototypes for the install routines
//
// Modification history :
//
// 02dec96:HJH - Creation
//
//**************************************************************************
#ifndef _Install_h
#define _Install_h
//**************************************************************************
//
// Includes
//
//**************************************************************************
#include "types.h"
//**************************************************************************
//
// Defines
//
//**************************************************************************
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
//**************************************************************************
//
// Function Prototypes
//
//**************************************************************************
#ifdef __cplusplus
extern "C" {
#endif
extern BOOLEAN InstallApplication( STR strAppname, STR strPath );
#ifdef __cplusplus
}
#endif
#endif
+98
View File
@@ -0,0 +1,98 @@
#ifndef __JA2_SGP_ALL_H
#define __JA2_SGP_ALL_H
#pragma message("GENERATED PCH FOR JA2 SGP PROJECT.")
//#ifndef INITGUID
// #define INITGUID
//#endif
#include "WordWrap.h"
#include "video.h"
#include "Button Sound Control.h"
#include "Sound Control.h"
#ifdef _JA2_RENDER_DIRTY
#include "Font Control.h"
#include "Render Dirty.h"
#include "utilities.h"
#endif
#include "input.h"
#include "memman.h"
#include "english.h"
#include "vobject.h"
#include "vobject_blitters.h"
#include "soundman.h"
#include "Button System.h"
#include "line.h"
#include <stdarg.h>
#include "debug.h"
#ifndef NO_ZLIB_COMPRESSION
#include "zlib.h"
#include "Compression.h"
#endif
#include "types.h"
#include <stdlib.h>
#include <malloc.h>
#include <stdio.h>
#include "Container.h"
#if _MSC_VER < 1300 //(iostream.h was removed from VC.NET2003)
#include <iostream.h>
#endif
#include "Cursor Control.h"
#include "wcheck.h"
#include "FileMan.h"
#include "DbMan.h"
#include <windows.h>
#include <ddeml.h>
#include "TopicIDs.h"
#include "TopicOps.h"
#include "WizShare.h"
#include "screenids.h"
#include "Sys Globals.h"
#include "jascreens.h"
#include "gameloop.h"
#include "DirectX Common.h"
#include "DirectDraw Calls.h"
#include "video_private.h"
#include <direct.h>
#include "RegInst.h"
#include "LibraryDataBase.h"
#include "io.h"
#include <wchar.h>
#include "sgp.h"
#include "pcx.h"
#include "Font.h"
#include "himage.h"
#include <math.h>
#include <string.h>
#include "impTGA.h"
#include "STCI.h"
#include <memory.h>
#include "local.h"
#include <tchar.h>
#include <assert.h>
#include "Install.h"
#include "GameSettings.h"
#ifdef _DEBUG
#include <crtdbg.h>
#endif
#include "mousesystem.h"
#include "Mutex Manager.h"
#include "Random.h"
#include <windowsx.h>
#include "vobject_private.h"
#include "shading.h"
#include "mss.h"
#include "imgfmt.h"
#include "timer.h"
#include "renderworld.h"
#include "Isometric utils.h"
#include "fade screen.h"
#include "timer control.h"
#include "vsurface.h"
#include "vsurface_private.h"
#include "Timer Control.h"
#endif
+52
View File
@@ -0,0 +1,52 @@
LibraryInitHeader gGameLibaries[ ] =
{
//Library Name Can be Init at start
// on cd
{ "Data.slf", FALSE, TRUE },
{ "Ambient.slf", FALSE, TRUE },
{ "Anims.slf", FALSE, TRUE },
{ "BattleSnds.slf", FALSE, TRUE },
{ "BigItems.slf", FALSE, TRUE },
{ "BinaryData.slf", FALSE, TRUE },
{ "Cursors.slf", FALSE, TRUE },
{ "Faces.slf", FALSE, TRUE },
{ "Fonts.slf", FALSE, TRUE },
{ "Interface.slf", FALSE, TRUE },
{ "Laptop.slf", FALSE, TRUE },
{ "Maps.slf", TRUE, TRUE },
{ "MercEdt.slf", FALSE, TRUE },
{ "Music.slf", TRUE, TRUE },
{ "Npc_Speech.slf", TRUE, TRUE },
{ "NpcData.slf", FALSE, TRUE },
{ "RadarMaps.slf", FALSE, TRUE },
{ "Sounds.slf", FALSE, TRUE },
{ "Speech.slf", TRUE, TRUE },
// { "TileCache.slf", FALSE, TRUE },
{ "TileSets.slf", TRUE, TRUE },
{ "LoadScreens.slf", TRUE, TRUE },
{ "Intro.slf", TRUE, TRUE },
#ifdef GERMAN
{ "German.slf", FALSE, TRUE },
#endif
#ifdef POLISH
{ "Polish.slf", FALSE, TRUE },
#endif
#ifdef DUTCH
{ "Dutch.slf", FALSE, TRUE },
#endif
#ifdef ITALIAN
{ "Italian.slf", FALSE, TRUE },
#endif
#ifdef RUSSIAN
{ "Russian.slf", FALSE, TRUE },
#endif
};
+56
View File
@@ -0,0 +1,56 @@
#ifndef _JA2_LIBS_H_
#define _JA2_LIBS_H_
//enums used for accessing the libraries
enum
{
LIBRARY_DATA,
LIBRARY_AMBIENT,
LIBRARY_ANIMS,
LIBRARY_BATTLESNDS,
LIBRARY_BIGITEMS,
LIBRARY_BINARY_DATA,
LIBRARY_CURSORS,
LIBRARY_FACES,
LIBRARY_FONTS,
LIBRARY_INTERFACE,
LIBRARY_LAPTOP,
LIBRARY_MAPS,
LIBRARY_MERCEDT,
LIBRARY_MUSIC,
LIBRARY_NPC_SPEECH,
LIBRARY_NPC_DATA,
LIBRARY_RADAR_MAPS,
LIBRARY_SOUNDS,
LIBRARY_SPEECH,
// LIBRARY_TILE_CACHE,
LIBRARY_TILESETS,
LIBRARY_LOADSCREENS,
LIBRARY_INTRO,
#ifdef GERMAN
LIBRARY_GERMAN_DATA,
#endif
#ifdef DUTCH
LIBRARY_DUTCH_DATA,
#endif
#ifdef POLISH
LIBRARY_POLISH_DATA,
#endif
#ifdef ITALIAN
LIBRARY_ITALIAN_DATA,
#endif
#ifdef RUSSIAN
LIBRARY_RUSSIAN_DATA,
#endif
NUMBER_OF_LIBRARIES
};
#endif
File diff suppressed because it is too large Load Diff
+215
View File
@@ -0,0 +1,215 @@
#ifndef _LIBRARY_DATABASE_H
#define _LIBRARY_DATABASE_H
#include "Types.h"
#include "windows.h"
#include "FileMan.h"
#define FILENAME_SIZE 256
//#define FILENAME_SIZE 40 + PATH_SIZE
#define PATH_SIZE 80
#define NUM_FILES_TO_ADD_AT_A_TIME 20
#define INITIAL_NUM_HANDLES 20
#define REAL_FILE_LIBRARY_ID 1022
#define DB_BITS_FOR_LIBRARY 10
#define DB_BITS_FOR_FILE_ID 22
#define DB_EXTRACT_LIBRARY( exp ) ( exp >> DB_BITS_FOR_FILE_ID )
#define DB_EXTRACT_FILE_ID( exp ) ( exp & 0x3FFFFF )
#define DB_ADD_LIBRARY_ID( exp ) ( exp << DB_BITS_FOR_FILE_ID )
#define DB_ADD_FILE_ID( exp ) ( exp & 0xC00000 )
typedef UINT32 HWFILE;
typedef struct
{
CHAR8 sLibraryName[ FILENAME_SIZE ]; // The name of the library file on the disk
BOOLEAN fOnCDrom; // A flag specifying if its a cdrom library ( not implemented yet )
BOOLEAN fInitOnStart; // Flag specifying if the library is to Initialized at the begining of the game
} LibraryInitHeader;
#ifdef JA2
#include "Ja2 Libs.h"
#elif UTIL
#define NUMBER_OF_LIBRARIES 0
typedef FILETIME SGP_FILETIME;
#else //wizardry
#include "WizLibs.h"
#endif
extern LibraryInitHeader gGameLibaries[];
extern CHAR8 gzCdDirectory[ SGPFILENAME_LEN ];
#define REAL_LIBRARY_FILE "RealFiles.slf"
typedef struct
{
UINT32 uiFileID; // id of the file ( they start at 1 )
HANDLE hRealFileHandle; // if the file is a Real File, this its handle
} RealFileOpenStruct;
typedef struct
{
STR pFileName;
UINT32 uiFileLength;
UINT32 uiFileOffset;
} FileHeaderStruct;
typedef struct
{
UINT32 uiFileID; // id of the file ( they start at 1 )
UINT32 uiFilePosInFile; // current position in the file
UINT32 uiActualPositionInLibrary; // Current File pointer position in actuall library
FileHeaderStruct *pFileHeader;
} FileOpenStruct;
typedef struct
{
STR sLibraryPath;
HANDLE hLibraryHandle;
UINT16 usNumberOfEntries;
BOOLEAN fLibraryOpen;
// BOOLEAN fAnotherFileAlreadyOpenedLibrary; //this variable is set when a file is opened from the library and reset when the file is close. No 2 files can have access to the library at 1 time.
UINT32 uiIdOfOtherFileAlreadyOpenedLibrary; //this variable is set when a file is opened from the library and reset when the file is close. No 2 files can have access to the library at 1 time.
INT32 iNumFilesOpen;
INT32 iSizeOfOpenFileArray;
FileHeaderStruct *pFileHeader;
FileOpenStruct *pOpenFiles;
//
// Temp: Total memory used for each library ( all memory allocated
//
#ifdef JA2TESTVERSION
UINT32 uiTotalMemoryAllocatedForLibrary;
#endif
} LibraryHeaderStruct;
typedef struct
{
INT32 iNumFilesOpen;
INT32 iSizeOfOpenFileArray;
RealFileOpenStruct *pRealFilesOpen;
} RealFileHeaderStruct;
typedef struct
{
STR sManagerName;
LibraryHeaderStruct *pLibraries;
UINT16 usNumberOfLibraries;
BOOLEAN fInitialized;
RealFileHeaderStruct RealFiles;
} DatabaseManagerHeaderStruct;
//typedef UINT32 HLIBFILE;
//*************************************************************************
//
// NOTE! The following structs are also used by the datalib98 utility
//
//*************************************************************************
#define FILE_OK 0
#define FILE_DELETED 0xff
#define FILE_OLD 1
#define FILE_DOESNT_EXIST 0xfe
typedef struct
{
CHAR8 sLibName[ FILENAME_SIZE ];
CHAR8 sPathToLibrary[ FILENAME_SIZE ];
INT32 iEntries;
INT32 iUsed;
UINT16 iSort;
UINT16 iVersion;
BOOLEAN fContainsSubDirectories;
INT32 iReserved;
} LIBHEADER;
typedef struct
{
CHAR8 sFileName[ FILENAME_SIZE ];
UINT32 uiOffset;
UINT32 uiLength;
UINT8 ubState;
UINT8 ubReserved;
FILETIME sFileTime;
UINT16 usReserved2;
} DIRENTRY;
#ifdef __cplusplus
extern "C" {
#endif
//The FileDatabaseHeader
extern DatabaseManagerHeaderStruct gFileDataBase;
//Function Prototypes
BOOLEAN CheckForLibraryExistence( STR pLibraryName );
BOOLEAN InitializeLibrary( STR pLibraryName, LibraryHeaderStruct *pLibheader, BOOLEAN fCanBeOnCDrom );
BOOLEAN InitializeFileDatabase( );
BOOLEAN ReopenCDLibraries(void);
BOOLEAN ShutDownFileDatabase( );
BOOLEAN CheckIfFileExistInLibrary( STR pFileName );
INT16 GetLibraryIDFromFileName( STR pFileName );
HWFILE OpenFileFromLibrary( STR pName );
HWFILE CreateRealFileHandle( HANDLE hFile );
BOOLEAN CloseLibraryFile( INT16 sLibraryID, UINT32 uiFileID );
BOOLEAN GetLibraryAndFileIDFromLibraryFileHandle( HWFILE hlibFile, INT16 *pLibraryID, UINT32 *pFileNum );
BOOLEAN LoadDataFromLibrary( INT16 sLibraryID, UINT32 uiFileIndex, PTR pData, UINT32 uiBytesToRead, UINT32 *pBytesRead );
BOOLEAN LibraryFileSeek( INT16 sLibraryID, UINT32 uiFileNum, UINT32 uiDistance, UINT8 uiHowToSeek );
//used to open and close libraries during the game
BOOLEAN CloseLibrary( INT16 sLibraryID );
BOOLEAN OpenLibrary( INT16 sLibraryID );
BOOLEAN IsLibraryOpened( INT16 sLibraryID );
BOOLEAN GetLibraryFileTime( INT16 sLibraryID, UINT32 uiFileNum, SGP_FILETIME *pLastWriteTime );
#ifdef __cplusplus
}
#endif
#endif
+753
View File
@@ -0,0 +1,753 @@
//**************************************************************************
//
// Filename : MemMan.cpp
//
// Purpose : function definitions for the memory manager
//
// Modification history :
//
// 11sep96:HJH - Creation
// 29may97:ARM - Fix & improve MemDebugCounter handling, logging of
// MemAlloc/MemFree, and reporting of any errors
//
//**************************************************************************
//**************************************************************************
//
// Includes
//
//**************************************************************************
//#ifdef JA2_PRECOMPILED_HEADERS
// #include "JA2 SGP ALL.H"
//#elif defined( WIZ8_PRECOMPILED_HEADERS )
// #include "WIZ8 SGP ALL.H"
//#else
#include "types.h"
#include <windows.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include "MemMan.h"
#include "Debug.h"
#include <stdio.h>
#ifdef _DEBUG
#include <crtdbg.h>
#endif
//#endif
#ifdef _DEBUG
//#define DEBUG_MEM_LEAKS // turns on tracking of every MemAlloc and MemFree!
#endif
//**************************************************************************
//
// Variables
//
//**************************************************************************
#ifdef JA2
#include "mousesystem.h"
#include "MessageBoxScreen.h"
STR16 gzJA2ScreenNames[] =
{
L"EDIT_SCREEN",
L"SAVING_SCREEN",
L"LOADING_SCREEN",
L"ERROR_SCREEN",
L"INIT_SCREEN",
L"GAME_SCREEN",
L"ANIEDIT_SCREEN",
L"PALEDIT_SCREEN",
L"DEBUG_SCREEN",
L"MAP_SCREEN",
L"LAPTOP_SCREEN",
L"LOADSAVE_SCREEN",
L"MAPUTILITY_SCREEN",
L"FADE_SCREEN",
L"MSG_BOX_SCREEN",
L"MAINMENU_SCREEN",
L"AUTORESOLVE_SCREEN",
L"SAVE_LOAD_SCREEN",
L"OPTIONS_SCREEN",
L"SHOPKEEPER_SCREEN",
L"SEX_SCREEN",
L"GAME_INIT_OPTIONS_SCREEN",
L"DEMO_EXIT_SCREEN",
L"INTRO_SCREEN",
L"CREDIT_SCREEN",
#ifdef JA2BETAVERSION
L"AIVIEWER_SCREEN",
L"QUEST_DEBUG_SCREEN",
#endif
};
#endif
#ifdef EXTREME_MEMORY_DEBUGGING
typedef struct MEMORY_NODE
{
PTR pBlock;
struct MEMORY_NODE *next, *prev;
UINT8 *pCode;
UINT32 uiSize;
}MEMORY_NODE;
MEMORY_NODE *gpMemoryHead = NULL;
MEMORY_NODE *gpMemoryTail = NULL;
UINT32 guiMemoryNodes = 0;
UINT32 guiTotalMemoryNodes = 0;
#endif
static BOOLEAN gfMemDebug = TRUE;
// debug variable for total memory currently allocated
UINT32 guiMemTotal = 0;
UINT32 guiMemAlloced = 0;
UINT32 guiMemFreed = 0;
UINT32 MemDebugCounter = 0;
BOOLEAN fMemManagerInit = FALSE;
//**************************************************************************
//
// Function Prototypes
//
//**************************************************************************
void DebugPrint( void );
//**************************************************************************
//
// Functions
//
//**************************************************************************
//**************************************************************************
//
// MemInit
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// 12sep96:HJH -> modified for use by Wizardry
//
//**************************************************************************
BOOLEAN InitializeMemoryManager( void )
{
// Register the memory manager with the debugger
RegisterDebugTopic(TOPIC_MEMORY_MANAGER, "Memory Manager");
MemDebugCounter = 0;
guiMemTotal = 0;
guiMemAlloced = 0;
guiMemFreed = 0;
fMemManagerInit = TRUE;
#ifdef EXTREME_MEMORY_DEBUGGING
gpMemoryHead = NULL;
gpMemoryTail = NULL;
guiMemoryNodes = 0;
guiTotalMemoryNodes = 0;
#endif
return(TRUE);
}
//**************************************************************************
//
// MemDebug
//
// To set whether or not we should print debug info.
//
// Parameter List :
// Return Value :
// Modification history :
//
// 12sep96:HJH -> modified for use by Wizardry
//
//**************************************************************************
void MemDebug( BOOLEAN f )
{
gfMemDebug = f;
}
//**************************************************************************
//
// MemShutdown
//
// Shuts down the memory manager.
//
// Parameter List :
// Return Value :
// Modification history :
//
// 12sep96:HJH -> modified for use by Wizardry
//
//**************************************************************************
void ShutdownMemoryManager( void )
{
if ( MemDebugCounter != 0 )
{
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" "));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" "));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" >>>>> MEMORY LEAK DETECTED!!! <<<<< "));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d memory blocks still allocated", MemDebugCounter ));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d bytes memory total STILL allocated", guiMemTotal ));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d bytes memory total was allocated", guiMemAlloced));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d bytes memory total was freed", guiMemFreed));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" "));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" "));
#ifndef EXTREME_MEMORY_DEBUGGING
#ifdef JA2BETAVERSION
{
FILE *fp;
fp = fopen( "MemLeakInfo.txt", "a" );
if( fp )
{
fprintf( fp, "\n\n" );
fprintf( fp, ">>>>> MEMORY LEAK DETECTED!!! <<<<<\n" );
fprintf( fp, " %d bytes memory total was allocated\n", guiMemAlloced );
fprintf( fp, "- %d bytes memory total was freed\n", guiMemFreed );
fprintf( fp, "_______________________________________________\n" );
fprintf( fp, "%d bytes memory total STILL allocated\n", guiMemTotal );
fprintf( fp, "%d memory blocks still allocated\n", MemDebugCounter );
fprintf( fp, "guiScreenExitedFrom = %S\n", gzJA2ScreenNames[ gMsgBox.uiExitScreen ] );
fprintf( fp, "\n\n" );
}
fclose( fp );
}
#endif
#endif
}
UnRegisterDebugTopic( TOPIC_MEMORY_MANAGER, "Memory Manager Un-initialized" );
fMemManagerInit = FALSE;
}
#ifdef _DEBUG
PTR MemAllocReal( UINT32 uiSize, const char *pcFile, INT32 iLine )
{
PTR ptr;
if( !uiSize )
{
return NULL;
}
if ( !fMemManagerInit )
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAlloc: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) );
ptr = _malloc_dbg( uiSize, _NORMAL_BLOCK, pcFile, iLine );
if (ptr != NULL)
{
guiMemTotal += uiSize;
guiMemAlloced += uiSize;
MemDebugCounter++;
}
else
{
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAlloc failed: %d bytes (line %d file %s)", uiSize, iLine, pcFile) );
}
#ifdef DEBUG_MEM_LEAKS
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemAlloc %p: %d bytes (line %d file %s)", ptr, uiSize, iLine, pcFile) );
#endif
return( ptr );
}
void MemFreeReal( PTR ptr, const char *pcFile, INT32 iLine )
{
UINT32 uiSize;
if ( !fMemManagerInit )
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFree: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) );
if (ptr != NULL)
{
uiSize = _msize(ptr);
guiMemTotal -= uiSize;
guiMemFreed += uiSize;
_free_dbg( ptr, _NORMAL_BLOCK );
#ifdef DEBUG_MEM_LEAKS
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemFree %p: %d bytes (line %d file %s)", ptr, uiSize, iLine, pcFile) );
#endif
}
else
{
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFree ERROR: NULL ptr received (line %d file %s)", iLine, pcFile) );
}
// count even a NULL ptr as a MemFree, not because it's really a memory leak, but because it is still an error of some
// sort (nobody should ever be freeing NULL pointers), and this will help in tracking it down if the above DbgMessage
// is not noticed.
MemDebugCounter--;
}
PTR MemReallocReal( PTR ptr, UINT32 uiSize, const char *pcFile, INT32 iLine )
{
PTR ptrNew;
UINT32 uiOldSize;
if ( !fMemManagerInit )
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemRealloc: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) );
if(ptr != NULL)
{
uiOldSize = _msize(ptr);
guiMemTotal -= uiOldSize;
guiMemFreed += uiOldSize;
MemDebugCounter--;
}
// Note that the ptr changes to ptrNew...
ptrNew = _realloc_dbg( ptr, uiSize, _NORMAL_BLOCK, pcFile, iLine );
if (ptrNew == NULL)
{
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemReAlloc failed: ptr %d, %d -> %d bytes (line %d file %s)", ptr, uiOldSize, uiSize, iLine, pcFile) );
if ( uiSize != 0 )
{
// ptr is left untouched, so undo the math above
guiMemTotal += uiOldSize;
guiMemFreed -= uiOldSize;
MemDebugCounter++;
}
}
else
{
#ifdef DEBUG_MEM_LEAKS
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemRealloc %p: Resizing %d bytes to %d bytes (line %d file %s) - New ptr %p", ptr, uiOldSize, uiSize, iLine, pcFile, ptrNew ) );
#endif
guiMemTotal += uiSize;
guiMemAlloced += uiSize;
MemDebugCounter++;
}
return( ptrNew );
}
#endif
PTR MemAllocLocked( UINT32 uiSize )
{
PTR ptr;
if ( !fMemManagerInit )
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAllocLocked: Warning -- Memory manager not initialized!!! ") );
ptr = VirtualAlloc( NULL, uiSize, MEM_COMMIT, PAGE_READWRITE );
if ( ptr )
{
VirtualLock( ptr, uiSize );
guiMemTotal += uiSize;
guiMemAlloced += uiSize;
MemDebugCounter++;
}
else
{
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAllocLocked failed: %d bytes", uiSize) );
}
#ifdef DEBUG_MEM_LEAKS
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemAllocLocked %p: %d bytes", ptr, uiSize) );
#endif
return( ptr );
}
void MemFreeLocked( PTR ptr, UINT32 uiSize )
{
if ( !fMemManagerInit )
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFreeLocked: Warning -- Memory manager not initialized!!! ") );
if (ptr != NULL)
{
VirtualUnlock( ptr, uiSize );
VirtualFree( ptr, uiSize, MEM_RELEASE );
guiMemTotal -= uiSize;
guiMemFreed += uiSize;
}
else
{
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFreeLocked ERROR: NULL ptr received, size %d", uiSize) );
}
// count even a NULL ptr as a MemFree, not because it's really a memory leak, but because it is still an error of some
// sort (nobody should ever be freeing NULL pointers), and this will help in tracking it down if the above DbgMessage
// is not noticed.
MemDebugCounter--;
#ifdef DEBUG_MEM_LEAKS
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemFreeLocked %p", ptr) );
#endif
}
//**************************************************************************
//
// MemGetFree
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// ??sep96:HJH -> modified for use by Wizardry
//
//**************************************************************************
UINT32 MemGetFree( void )
{
MEMORYSTATUS ms;
ms.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus( &ms );
return( ms.dwAvailPhys );
}
//**************************************************************************
//
// MemGetTotalSystem
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// May98:HJH -> Carter
//
//**************************************************************************
UINT32 MemGetTotalSystem( void )
{
MEMORYSTATUS ms;
ms.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus( &ms );
return( ms.dwTotalPhys );
}
//**************************************************************************
//
// MemCheckPool
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// 23sep96:HJH -> modified for use by Wizardry
//
//**************************************************************************
BOOLEAN MemCheckPool( void )
{
BOOLEAN fRet = TRUE;
#ifdef _DEBUG
fRet = _CrtCheckMemory();
Assert( fRet );
#endif
return(fRet);
}
#ifdef EXTREME_MEMORY_DEBUGGING
PTR MemAllocXDebug( UINT32 size, const char *szCodeString, INT32 iLineNum, void *pSpecial )
{
PTR ptr;
UINT16 usLength;
UINT8 str[70];
UINT8 *pStr;
if( !size )
{
return NULL;
}
if( !pSpecial )
{
ptr = malloc( size );
}
else
{
ptr = pSpecial;
}
if( ptr )
{
// Set into video object list
if( gpMemoryHead )
{ //Add node after tail
gpMemoryTail->next = (MEMORY_NODE*)malloc( sizeof( MEMORY_NODE ) );
Assert( gpMemoryTail->next ); //out of memory?
gpMemoryTail->next->prev = gpMemoryTail;
gpMemoryTail->next->next = NULL;
gpMemoryTail = gpMemoryTail->next;
}
else
{ //new list
gpMemoryHead = (MEMORY_NODE*)malloc( sizeof( MEMORY_NODE ) );
Assert( gpMemoryHead ); //out of memory?
gpMemoryHead->prev = gpMemoryHead->next = NULL;
gpMemoryTail = gpMemoryHead;
}
//record the code location of the calling creating function.
pStr = strrchr( szCodeString, '\\' );
pStr++;
sprintf( str, "%s -- line(%d)", pStr, iLineNum );
usLength = strlen( str ) + 1;
gpMemoryTail->pCode = (UINT8*)malloc( usLength );
memset( gpMemoryTail->pCode, 0, usLength );
strcpy( gpMemoryTail->pCode, str );
//record the size
gpMemoryTail->uiSize = size;
//Set the hVObject into the node.
gpMemoryTail->pBlock = ptr;
guiMemoryNodes++;
guiTotalMemoryNodes++;
}
return( ptr );
}
void MemFreeXDebug( PTR ptr, const char *szCodeString, INT32 iLineNum, void *pSpecial )
{
MEMORY_NODE *curr;
if( ptr )
{
curr = gpMemoryHead;
while( curr )
{
if( curr->pBlock == ptr )
{ //Found the node, so detach it and delete it.
if( !pSpecial )
{
free( ptr );
}
if( curr == gpMemoryHead )
{ //Advance the head, because we are going to remove the head node.
gpMemoryHead = gpMemoryHead->next;
}
if( curr == gpMemoryTail )
{ //Back up the tail, because we are going to remove the tail node.
gpMemoryTail = gpMemoryTail->prev;
}
//Detach the node from the vobject list
if( curr->next )
{ //Make the prev node point to the next
curr->next->prev = curr->prev;
}
if( curr->prev )
{ //Make the next node point to the prev
curr->prev->next = curr->next;
}
//The node is now detached. Now deallocate it.
free( curr );
curr = NULL;
guiMemoryNodes--;
return;
}
curr = curr->next;
}
}
}
PTR MemReallocXDebug( PTR ptr, UINT32 size, const char *szCodeString, INT32 iLineNum, void *pSpecial )
{
MEMORY_NODE *curr;
PTR ptrNew;
UINT16 usLength;
UINT8 str[70];
UINT8 *pStr;
if( !ptr && size )
{
return MemAllocXDebug( size, szCodeString, iLineNum, pSpecial );
}
curr = gpMemoryHead;
while( curr )
{
if( curr->pBlock == ptr )
{
// Note that the ptr changes to ptrNew...
if( !pSpecial )
{
ptrNew = realloc( ptr, size );
}
else
{
ptrNew = pSpecial;
}
if( ptrNew )
{
curr->pBlock = ptrNew;
curr->uiSize = size;
free( curr->pCode );
//record the code location of the calling creating function.
pStr = strrchr( szCodeString, '\\' );
pStr++;
sprintf( str, "%s -- line(%d)", pStr, iLineNum );
usLength = strlen( str ) + 1;
curr->pCode = (UINT8*)malloc( usLength );
memset( curr->pCode, 0, usLength );
strcpy( curr->pCode, str );
}
else
{
ptr = ptr;
}
return ptrNew;
}
curr = curr->next;
}
return 0;
}
typedef struct DUMPFILENAME
{
UINT8 str[70];
}DUMPFILENAME;
void DumpMemoryInfoIntoFile( UINT8 *filename, BOOLEAN fAppend )
{
MEMORY_NODE *curr;
FILE *fp;
DUMPFILENAME *pCode;
UINT32 *puiCounter, *puiSize;
UINT8 tempCode[ 70 ];
UINT32 i, uiUniqueID, uiTotalKbWasted = 0, uiBytesRemainder = 0;
BOOLEAN fFound;
if( fAppend )
{
fp = fopen( filename, "a" );
}
else
{
fp = fopen( filename, "w" );
}
Assert( fp );
if( !guiMemoryNodes )
{
fprintf( fp, "NO MEMORY LEAKS DETECTED! CONGRATULATIONS!\n" );
fclose( fp );
return;
}
//Allocate enough strings and counters for each node.
pCode = (DUMPFILENAME*)malloc( sizeof( DUMPFILENAME ) * guiMemoryNodes );
memset( pCode, 0, sizeof( DUMPFILENAME ) * guiMemoryNodes );
puiSize = (UINT32*)malloc( 4 * guiMemoryNodes );
memset( puiSize, 0, 4 * guiMemoryNodes );
puiCounter = (UINT32*)malloc( 4 * guiMemoryNodes );
memset( puiCounter, 0, 4 * guiMemoryNodes );
//Loop through the list and record every unique filename and count them
uiUniqueID = 0;
curr = gpMemoryHead;
while( curr )
{
strcpy( tempCode, curr->pCode );
fFound = FALSE;
for( i = 0; i < uiUniqueID; i++ )
{
if( !_stricmp( tempCode, pCode[i].str ) )
{ //same string
fFound = TRUE;
(puiCounter[ i ])++;
(puiSize[ i ]) += curr->uiSize;
break;
}
}
if( !fFound )
{
strcpy( pCode[i].str, tempCode );
(puiSize[ i ]) += curr->uiSize;
(puiCounter[ i ])++;
uiUniqueID++;
}
curr = curr->next;
}
//Now dump the info.
fprintf( fp, "--------------------------------------------------------------------------------\n" );
fprintf( fp, "%d unique memory allocation locations exist in %d memory nodes\n", uiUniqueID, guiMemoryNodes );
fprintf( fp, "--------------------------------------------------------------------------------\n" );
for( i = 0; i < uiUniqueID; i++ )
{
fprintf( fp, "%d occurrences of %s (total size %d bytes)\n", puiCounter[i], pCode[i].str, puiSize[i] );
uiBytesRemainder += puiSize[i];
if( uiBytesRemainder >= 1024 )
{
uiTotalKbWasted += uiBytesRemainder/1024;
uiBytesRemainder %= 1024;
}
}
fprintf( fp, "--------------------------------------------------------------------------------\n" );
fprintf( fp, "%dKB of memory total wasn't cleaned up!\n", uiTotalKbWasted );
fprintf( fp, "--------------------------------------------------------------------------------\n" );
fclose( fp );
//Free all memory associated with this operation.
free( pCode );
free( puiCounter );
free( puiSize );
}
BOOLEAN _AddAndRecordMemAlloc( UINT32 size, UINT32 uiLineNum, UINT8 *pSourceFile )
{
return 0;
}
#endif
+106
View File
@@ -0,0 +1,106 @@
//**************************************************************************
//
// Filename : MemMan.h
//
// Purpose : prototypes for the memory manager
//
// Modification history :
//
// 11sep96:HJH - Creation
//
//**************************************************************************
#ifndef _MEMMAN_H
#define _MEMMAN_H
//**************************************************************************
//
// Includes
//
//**************************************************************************
#include "types.h"
//**************************************************************************
//
// Defines
//
//**************************************************************************
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
//**************************************************************************
//
// Function Prototypes
//
//**************************************************************************
#ifdef __cplusplus
extern "C" {
#endif
extern UINT32 MemDebugCounter;
extern UINT32 guiMemTotal;
extern UINT32 guiMemAlloced;
extern UINT32 guiMemFreed;
extern BOOLEAN InitializeMemoryManager( void );
extern void MemDebug( BOOLEAN f );
extern void ShutdownMemoryManager( void );
// Creates and adds a video object to list
#ifdef EXTREME_MEMORY_DEBUGGING
//This is the most effective way to debug memory leaks. Each memory leak will be recorded in a linked
//list containing a string referring to the location in code the memory was allocated in addition to
//the number of occurrences. The shutdown code will report all unhandled memory with exact location allocated.
void DumpMemoryInfoIntoFile( UINT8 *filename, BOOLEAN fAppend );
BOOLEAN _AddAndRecordMemAlloc( UINT32 size, UINT32 uiLineNum, UINT8 *pSourceFile );
#define MemAlloc( size ) MemAllocXDebug( (size), __FILE__, __LINE__, NULL )
#define MemFree( ptr ) MemFreeXDebug( (ptr), __FILE__, __LINE__, NULL )
#define MemRealloc( ptr, size ) MemReallocXDebug( (ptr), (size), __FILE__, __LINE__, NULL )
extern PTR MemAllocXDebug( UINT32 size, const char *szCodeString, INT32 iLineNum, void *pSpecial );
extern void MemFreeXDebug( PTR ptr, const char *szCodeString, INT32 iLineNum, void *pSpecial );
extern PTR MemReallocXDebug( PTR ptr, UINT32 size, const char *szCodeString, INT32 iLineNum, void *pSpecial );
#else
#ifdef _DEBUG
//This is another debug feature. Not as sophistocated, but definately not the pig the extreme system is.
//This system reports all memory allocations/deallocations in the debug output.
#define MemAlloc( size ) MemAllocReal( (size), __FILE__, __LINE__ )
#define MemFree( ptr ) MemFreeReal( (ptr), __FILE__, __LINE__ )
#define MemRealloc( ptr, size ) MemReallocReal( (ptr), (size), __FILE__, __LINE__ )
extern PTR MemAllocReal( UINT32 size, const char *, INT32 );
extern void MemFreeReal( PTR ptr, const char *, INT32 );
extern PTR MemReallocReal( PTR ptr, UINT32 size, const char *, INT32 );
#else
//Release build verison
#include <malloc.h>
#define MemAlloc( size ) malloc( (size) )
#define MemFree( ptr ) free( (ptr) )
#define MemRealloc( ptr, size ) realloc( (ptr), (size) )
#endif
#endif
extern PTR MemAllocLocked( UINT32 size );
extern void MemFreeLocked( PTR, UINT32 size );
// get total free on the system at this moment
extern UINT32 MemGetFree( void );
// get the total on the system
extern UINT32 MemGetTotalSystem( void );
extern BOOLEAN MemCheckPool( void );
#ifdef __cplusplus
}
#endif
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+223
View File
@@ -0,0 +1,223 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "Mutex Manager.h"
#include "debug.h"
#endif
//#define __MUTEX_TYPE
#ifdef __MUTEX_TYPE
//
// Use defines to allocate slots in the mutex manager. Put these defines in LOCAL.H
//
HANDLE MutexTable[MAX_MUTEX_HANDLES];
BOOLEAN InitializeMutexManager(void)
{
UINT32 uiIndex;
//
// Register the Mutex Manager debug topic
//
RegisterDebugTopic(TOPIC_MUTEX, "Mutex Manager");
DbgMessage(TOPIC_MUTEX, DBG_LEVEL_0, "Initializing the Mutex Manager");
//
// Initialize the table of mutex handles to NULL
//
for (uiIndex = 0; uiIndex < MAX_MUTEX_HANDLES; uiIndex++)
{
MutexTable[uiIndex] = NULL;
}
return TRUE;
}
void ShutdownMutexManager(void)
{
UINT32 uiIndex;
DbgMessage(TOPIC_MUTEX, DBG_LEVEL_0, "Shutting down the Mutex Manager");
//
// Make sure all mutex handles are closed
//
for (uiIndex = 0; uiIndex < MAX_MUTEX_HANDLES; uiIndex++)
{
if (MutexTable[uiIndex] != NULL)
{
CloseHandle(MutexTable[uiIndex]);
MutexTable[uiIndex] = NULL;
}
}
UnRegisterDebugTopic(TOPIC_MUTEX, "Mutex Manager");
}
BOOLEAN InitializeMutex(UINT32 uiMutexIndex, UINT8 *ubMutexName)
{
MutexTable[uiMutexIndex] = CreateMutex(NULL, FALSE, ubMutexName);
if (MutexTable[uiMutexIndex] == NULL)
{
//
// Mutex creation has failed.
//
DbgMessage(TOPIC_MUTEX, DBG_LEVEL_0, "ERROR : Mutex initialization has failed.");
return FALSE;
}
return TRUE;
}
BOOLEAN DeleteMutex(UINT32 uiMutexIndex)
{
if (MutexTable[uiMutexIndex] == NULL)
{
//
// Hum ?? We just tried to initialize a mutex entry which doesn't have a reserved slot
//
DbgMessage(TOPIC_MUTEX, DBG_LEVEL_0, "ERROR : Mutex cannot be deleted since it does not exit");
return FALSE;
}
if (CloseHandle(MutexTable[uiMutexIndex]) == FALSE)
{
//
// Hum, the mutex deletion has failed
//
DbgMessage(TOPIC_MUTEX, DBG_LEVEL_0, "ERROR : Mutex cannot be deleted since it does not exit");
return FALSE;
}
MutexTable[uiMutexIndex] = NULL;
return TRUE;
}
BOOLEAN EnterMutex(UINT32 uiMutexIndex, INT32 nLine, char *szFilename)
{
switch (WaitForSingleObject(MutexTable[uiMutexIndex], INFINITE))
{
case WAIT_OBJECT_0
: return TRUE;
case WAIT_TIMEOUT
: DbgMessage(TOPIC_MUTEX, DBG_LEVEL_0, "ERROR : Possible infinite loop detected due to enter mutex timeout");
return FALSE;
case WAIT_ABANDONED
: DbgMessage(TOPIC_MUTEX, DBG_LEVEL_0, "ERROR : Abandoned mutex has been found");
return FALSE;
}
}
BOOLEAN EnterMutexWithTimeout(UINT32 uiMutexIndex, UINT32 uiTimeout, INT32 nLine, char *szFilename)
{
switch (WaitForSingleObject(MutexTable[uiMutexIndex], uiTimeout))
{
case WAIT_OBJECT_0
: return TRUE;
case WAIT_TIMEOUT
: return FALSE;
case WAIT_ABANDONED
: return FALSE;
}
return TRUE;
}
BOOLEAN LeaveMutex(UINT32 uiMutexIndex, INT32 nLine, char *szFilename)
{
if (ReleaseMutex(MutexTable[uiMutexIndex]) == FALSE)
{
DbgMessage(TOPIC_MUTEX, DBG_LEVEL_0, "ERROR : Failed to leave mutex");
return FALSE;
}
return TRUE;
}
#else
//
// Use defines to allocate slots in the mutex manager. Put these defines in LOCAL.H
//
CRITICAL_SECTION MutexTable[MAX_MUTEX_HANDLES];
BOOLEAN InitializeMutexManager(void)
{
UINT32 uiIndex;
//
// Make sure all mutex handles are opened
//
for (uiIndex = 0; uiIndex < MAX_MUTEX_HANDLES; uiIndex++)
{
InitializeCriticalSection(&MutexTable[uiIndex]);
}
RegisterDebugTopic(TOPIC_MUTEX, "Mutex Manager");
return TRUE;
}
void ShutdownMutexManager(void)
{
UINT32 uiIndex;
DbgMessage(TOPIC_MUTEX, DBG_LEVEL_0, "Shutting down the Mutex Manager");
//
// Make sure all mutex handles are closed
//
for (uiIndex = 0; uiIndex < MAX_MUTEX_HANDLES; uiIndex++)
{
DeleteCriticalSection(&MutexTable[uiIndex]);
}
UnRegisterDebugTopic(TOPIC_MUTEX, "Mutex Manager");
}
BOOLEAN InitializeMutex(UINT32 uiMutexIndex, UINT8 *ubMutexName)
{
//InitializeCriticalSection(&MutexTable[uiMutexIndex]);
return TRUE;
}
BOOLEAN DeleteMutex(UINT32 uiMutexIndex)
{
//DeleteCriticalSection(&MutexTable[uiMutexIndex]);
return TRUE;
}
BOOLEAN EnterMutex(UINT32 uiMutexIndex, INT32 nLine, char *szFilename)
{
EnterCriticalSection(&MutexTable[uiMutexIndex]);
return TRUE;
}
BOOLEAN EnterMutexWithTimeout(UINT32 uiMutexIndex, UINT32 uiTimeout, INT32 nLine, char *szFilename)
{
EnterCriticalSection(&MutexTable[uiMutexIndex]);
return TRUE;
}
BOOLEAN LeaveMutex(UINT32 uiMutexIndex, INT32 nLine, char *szFilename)
{
LeaveCriticalSection(&MutexTable[uiMutexIndex]);
return TRUE;
}
#endif
+20
View File
@@ -0,0 +1,20 @@
#ifndef __MUTEX_
#define __MUTEX_
#include <process.h>
#include "Types.h"
#include "Local.h"
extern BOOLEAN InitializeMutexManager(void);
extern void ShutdownMutexManager(void);
extern BOOLEAN InitializeMutex(UINT32 uiMutexIndex, UINT8 *ubMutexName);
extern BOOLEAN DeleteMutex(UINT32 uiMutexIndex);
extern BOOLEAN EnterMutex(UINT32 uiMutexIndex, INT32 nLine, char *szFilename);
extern BOOLEAN EnterMutexWithTimeout(UINT32 uiMutexIndex, UINT32 uiTimeout, INT32 nLine, char *szFilename);
extern BOOLEAN LeaveMutex(UINT32 uiMutexIndex, INT32 nLine, char *szFilename);
//
// Use defines to allocate slots in the mutex manager. Put these defines in LOCAL.H
//
#endif
+382
View File
@@ -0,0 +1,382 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include <stdio.h>
#include <stdarg.h>
#include "pcx.h"
#include "memman.h"
#include "fileman.h"
#endif
// Local typedefs
#define PCX_NORMAL 1
#define PCX_RLE 2
#define PCX_256COLOR 4
#define PCX_TRANSPARENT 8
#define PCX_CLIPPED 16
#define PCX_REALIZEPALETTE 32
#define PCX_X_CLIPPING 64
#define PCX_Y_CLIPPING 128
#define PCX_NOTLOADED 256
#define PCX_ERROROPENING 1
#define PCX_INVALIDFORMAT 2
#define PCX_INVALIDLEN 4
#define PCX_OUTOFMEMORY 8
BOOLEAN SetPcxPalette( PcxObject *pCurrentPcxObject, HIMAGE hImage );
BOOLEAN BlitPcxToBuffer( PcxObject *pCurrentPcxObject, UINT8 *pBuffer, UINT16 usBufferWidth, UINT16 usBufferHeight, UINT16 usX, UINT16 usY, BOOLEAN fTransp);
PcxObject *LoadPcx(UINT8 *pFilename);
BOOLEAN LoadPCXFileToImage( HIMAGE hImage, UINT16 fContents )
{
PcxObject *pPcxObject;
// First Load a PCX Image
pPcxObject = LoadPcx( (UINT8 *)hImage->ImageFile );
if ( pPcxObject == NULL )
{
return( FALSE );
}
// Set some header information
hImage->usWidth = pPcxObject->usWidth;
hImage->usHeight = pPcxObject->usHeight;
hImage->ubBitDepth = 8;
hImage->fFlags = hImage->fFlags | fContents;
// Read and allocate bitmap block if requested
if ( fContents & IMAGE_BITMAPDATA )
{
// Allocate memory for buffer
hImage->p8BPPData = (UINT8 *) MemAlloc( hImage->usWidth * hImage->usHeight );
if ( !BlitPcxToBuffer( pPcxObject, hImage->p8BPPData, hImage->usWidth, hImage->usHeight, 0, 0, FALSE ) )
{
MemFree( hImage->p8BPPData );
return( FALSE );
}
}
if ( fContents & IMAGE_PALETTE )
{
SetPcxPalette( pPcxObject, hImage );
// Create 16 BPP palette if flags and BPP justify
hImage->pui16BPPPalette = Create16BPPPalette( hImage->pPalette );
}
// Free and remove pcx object
MemFree( pPcxObject->pPcxBuffer );
MemFree( pPcxObject );
return( TRUE );
}
PcxObject *LoadPcx(UINT8 *pFilename)
{
PcxHeader Header;
PcxObject *pCurrentPcxObject;
HWFILE hFileHandle;
UINT32 uiFileSize;
UINT8 *pPcxBuffer;
// Open and read in the file
if ((hFileHandle = FileOpen((STR)pFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE)) == 0)
{ // damn we failed to open the file
return NULL;
}
uiFileSize = FileGetSize(hFileHandle);
if (uiFileSize == 0)
{ // we failed to size up the file
return NULL;
}
// Create enw pCX object
pCurrentPcxObject = (PcxObject *) MemAlloc( sizeof( PcxObject ) );
if ( pCurrentPcxObject == NULL )
{
return( NULL );
}
pCurrentPcxObject->pPcxBuffer = (UINT8 *) MemAlloc( uiFileSize - (sizeof(PcxHeader) + 768) );
if ( pCurrentPcxObject->pPcxBuffer == NULL )
{
return( NULL );
}
// Ok we now have a file handle, so let's read in the data
FileRead(hFileHandle, &Header, sizeof(PcxHeader), NULL);
if ((Header.ubManufacturer != 10)||(Header.ubEncoding != 1))
{ // We have an invalid pcx format
// Delete the object
MemFree( pCurrentPcxObject->pPcxBuffer );
MemFree( pCurrentPcxObject );
return( NULL );
}
if (Header.ubBitsPerPixel == 8)
{
pCurrentPcxObject->usPcxFlags = PCX_256COLOR;
} else
{
pCurrentPcxObject->usPcxFlags = 0;
}
pCurrentPcxObject->usWidth = 1 + (Header.usRight - Header.usLeft);
pCurrentPcxObject->usHeight = 1 + (Header.usBottom - Header.usTop);
pCurrentPcxObject->uiBufferSize = uiFileSize - 768 - sizeof(PcxHeader);
// We are ready to read in the pcx buffer data. Therefore we must lock the buffer
pPcxBuffer = pCurrentPcxObject->pPcxBuffer;
FileRead(hFileHandle, pPcxBuffer, pCurrentPcxObject->uiBufferSize, NULL);
// Read in the palette
FileRead(hFileHandle, &(pCurrentPcxObject->ubPalette[0]), 768, NULL);
// Close file
FileClose( hFileHandle );
return pCurrentPcxObject;
}
BOOLEAN BlitPcxToBuffer( PcxObject *pCurrentPcxObject, UINT8 *pBuffer, UINT16 usBufferWidth, UINT16 usBufferHeight, UINT16 usX, UINT16 usY, BOOLEAN fTransp)
{
UINT8 *pPcxBuffer;
UINT8 ubRepCount;
UINT16 usMaxX, usMaxY;
UINT32 uiImageSize;
UINT8 ubCurrentByte = 0;
UINT8 ubMode;
UINT16 usCurrentX, usCurrentY;
UINT32 uiOffset, uiIndex;
UINT32 uiNextLineOffset, uiStartOffset, uiCurrentOffset;
pPcxBuffer = pCurrentPcxObject->pPcxBuffer;
if (((pCurrentPcxObject->usWidth + usX) == usBufferWidth)&&((pCurrentPcxObject->usHeight + usY)== usBufferHeight))
{ // Pre-compute PCX blitting aspects.
uiImageSize = usBufferWidth * usBufferHeight;
ubMode = PCX_NORMAL;
uiOffset = 0;
ubRepCount = 0;
// Blit Pcx object. Two main cases, one for transparency (0's are skipped and for without transparency.
if (fTransp == TRUE)
{
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{
ubMode = PCX_NORMAL;
}
}
if (ubCurrentByte != 0)
{
*(pBuffer + uiIndex) = ubCurrentByte;
}
}
}
else
{
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{ ubMode = PCX_NORMAL;
}
}
*(pBuffer + uiIndex) = ubCurrentByte;
}
}
} else
{ // Pre-compute PCX blitting aspects.
if ((pCurrentPcxObject->usWidth + usX) >= usBufferWidth)
{
pCurrentPcxObject->usPcxFlags |= PCX_X_CLIPPING;
usMaxX = usBufferWidth - 1;
}
else
{
usMaxX = pCurrentPcxObject->usWidth + usX;
}
if ((pCurrentPcxObject->usHeight + usY) >= usBufferHeight)
{
pCurrentPcxObject->usPcxFlags |= PCX_Y_CLIPPING;
uiImageSize = pCurrentPcxObject->usWidth * (usBufferHeight - usY);
usMaxY = usBufferHeight - 1;
}
else
{ uiImageSize = pCurrentPcxObject->usWidth * pCurrentPcxObject->usHeight;
usMaxY = pCurrentPcxObject->usHeight + usY;
}
ubMode = PCX_NORMAL;
uiOffset = 0;
ubRepCount = 0;
usCurrentX = usX;
usCurrentY = usY;
// Blit Pcx object. Two main cases, one for transparency (0's are skipped and for without transparency.
if (fTransp == TRUE)
{
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{ ubMode = PCX_NORMAL;
}
}
if (ubCurrentByte != 0)
{ *(pBuffer + (usCurrentY*usBufferWidth) + usCurrentX) = ubCurrentByte;
}
usCurrentX++;
if (usCurrentX > usMaxX)
{
usCurrentX = usX;
usCurrentY++;
}
}
} else
{
uiStartOffset = (usCurrentY*usBufferWidth) + usCurrentX;
uiNextLineOffset = uiStartOffset + usBufferWidth;
uiCurrentOffset = uiStartOffset;
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{
ubMode = PCX_NORMAL;
}
}
if (usCurrentX < usMaxX)
{ // We are within the visible bounds so we write the byte to buffer
*(pBuffer + uiCurrentOffset) = ubCurrentByte;
uiCurrentOffset++;
usCurrentX++;
}
else
{ if ((uiCurrentOffset + 1)< uiNextLineOffset)
{ // Increment the uiCurrentOffset
uiCurrentOffset++;
}
else
{ // Go to next line
usCurrentX = usX;
usCurrentY++;
if (usCurrentY > usMaxY)
{
break;
}
uiStartOffset = (usCurrentY*usBufferWidth) + usCurrentX;
uiNextLineOffset = uiStartOffset + usBufferWidth;
uiCurrentOffset = uiStartOffset;
}
}
}
}
}
return( TRUE );
}
BOOLEAN SetPcxPalette( PcxObject *pCurrentPcxObject, HIMAGE hImage )
{
UINT16 Index;
UINT8 *pubPalette;
pubPalette = &(pCurrentPcxObject->ubPalette[0]);
// Allocate memory for palette
hImage->pPalette = (SGPPaletteEntry *) MemAlloc( sizeof( SGPPaletteEntry ) * 256 );
if ( hImage->pPalette == NULL )
{
return( FALSE );
}
// Initialize the proper palette entries
for (Index = 0; Index < 256; Index++)
{
hImage->pPalette[ Index ].peRed = *(pubPalette+(Index*3));
hImage->pPalette[ Index ].peGreen = *(pubPalette+(Index*3)+1);
hImage->pPalette[ Index ].peBlue = *(pubPalette+(Index*3)+2);
hImage->pPalette[ Index ].peFlags = 0;
}
return TRUE;
}
+638
View File
@@ -0,0 +1,638 @@
#ifndef __RAD__
#define __RAD__
#define RADCOPYRIGHT "Copyright (C) 1994-98 RAD Game Tools, Inc."
#ifndef __RADRES__
// __RADDOS__ means DOS code (16 or 32 bit)
// __RAD16__ means 16 bit code (Win16)
// __RAD32__ means 32 bit code (DOS, Win386, Win32s, Mac)
// __RADWIN__ means Windows code (Win16, Win386, Win32s)
// __RADWINEXT__ means Windows 386 extender (Win386)
// __RADNT__ means Win32s code
// __RADMAC__ means Macintosh
// __RAD68K__ means 68K Macintosh
// __RADPPC__ means PowerMac
#if (defined(__MWERKS__) && !defined(__INTEL__)) || defined(THINK_C) || defined(powerc) || defined(macintosh) || defined(__powerc)
#define __RADMAC__
#if defined(powerc) || defined(__powerc)
#define __RADPPC__
#else
#define __RAD68K__
#endif
#define __RAD32__
#else
#ifdef __DOS__
#define __RADDOS__
#endif
#ifdef __386__
#define __RAD32__
#endif
#ifdef _Windows //For Borland
#ifdef __WIN32__
#define WIN32
#else
#define __WINDOWS__
#endif
#endif
#ifdef _WINDOWS //For MS
#ifndef _WIN32
#define __WINDOWS__
#endif
#endif
#ifdef _WIN32
#define __RADWIN__
#define __RADNT__
#define __RAD32__
#else
#ifdef __NT__
#define __RADWIN__
#define __RADNT__
#define __RAD32__
#else
#ifdef __WINDOWS_386__
#define __RADWIN__
#define __RADWINEXT__
#define __RAD32__
#else
#ifdef __WINDOWS__
#define __RADWIN__
#define __RAD16__
#else
#ifdef WIN32
#define __RADWIN__
#define __RADNT__
#define __RAD32__
#endif
#endif
#endif
#endif
#endif
#endif
#if (!defined(__RADDOS__) && !defined(__RADWIN__) && !defined(__RADMAC__))
#error RAD.H did not detect your platform. Define __DOS__, __WINDOWS__, WIN32, macintosh, or powerc.
#endif
#ifdef __RADMAC__
// this define is for CodeWarrior 11's stupid new libs (even though
// we don't use longlong's).
#define __MSL_LONGLONG_SUPPORT__
#define RADLINK
#define RADEXPLINK
#ifdef __CFM68K__
#ifdef __RADINDLL__
#define RADEXPFUNC RADDEFFUNC __declspec(export)
#else
#define RADEXPFUNC RADDEFFUNC __declspec(import)
#endif
#else
#define RADEXPFUNC RADDEFFUNC
#endif
#define RADASMLINK
#else
#ifdef __RADNT__
#ifndef _WIN32
#define _WIN32
#endif
#ifndef WIN32
#define WIN32
#endif
#endif
#ifdef __RADWIN__
#ifdef __RAD32__
#ifdef __RADNT__
#define RADLINK __stdcall
#define RADEXPLINK __stdcall
#ifdef __RADINEXE__
#define RADEXPFUNC RADDEFFUNC
#else
#ifndef __RADINDLL__
#define RADEXPFUNC RADDEFFUNC __declspec(dllimport)
#ifdef __BORLANDC__
#if __BORLANDC__<=0x460
#undef RADEXPFUNC
#define RADEXPFUNC RADDEFFUNC
#endif
#endif
#else
#define RADEXPFUNC RADDEFFUNC __declspec(dllexport)
#endif
#endif
#else
#define RADLINK __pascal
#define RADEXPLINK __far __pascal
#define RADEXPFUNC RADDEFFUNC
#endif
#else
#define RADLINK __pascal
#define RADEXPLINK __far __pascal __export
#define RADEXPFUNC RADDEFFUNC
#endif
#else
#define RADLINK __pascal
#define RADEXPLINK __pascal
#define RADEXPFUNC RADDEFFUNC
#endif
#define RADASMLINK __cdecl
#endif
#ifdef __RADWIN__
#ifndef _WINDOWS
#define _WINDOWS
#endif
#endif
#ifdef __cplusplus
#define RADDEFFUNC extern "C"
#define RADDEFSTART extern "C" {
#define RADDEFEND }
#else
#define RADDEFFUNC
#define RADDEFSTART
#define RADDEFEND
#endif
RADDEFSTART
#define s8 signed char
#define u8 unsigned char
#define u32 unsigned long
#define s32 signed long
#define u64 unsigned __int64
#define s64 signed __int64
#ifdef __RAD32__
#define PTR4
#define u16 unsigned short
#define s16 signed short
#ifdef __RADMAC__
#include <string.h>
#include <memory.h>
#include <OSUtils.h>
#define radstrlen strlen
#define radmemset memset
#define radmemcmp memcmp
#define radmemcpy(dest,source,size) BlockMoveData((Ptr)(source),(Ptr)(dest),size)
#define radmemcpydb(dest,source,size) BlockMoveData((Ptr)(source),(Ptr)(dest),size)
#define radstrcat strcat
#define radstrcpy strcpy
static u32 inline radsqr(s32 a) { return(a*a); }
#ifdef __RAD68K__
#pragma parameter __D0 mult64anddiv(__D0,__D1,__D2)
u32 mult64anddiv(u32 m1,u32 m2,u32 d) ={0x4C01,0x0C01,0x4C42,0x0C01};
// muls.l d1,d1:d0 divs.l d2,d1:d0
#pragma parameter radconv32a(__A0,__D0)
void radconv32a(void* p,u32 n) ={0x4A80,0x600C,0x2210,0xE059,0x4841,0xE059,0x20C1,0x5380,0x6EF2};
// tst.l d0 bra.s @loope @loop: move.l (a0),d1 ror.w #8,d1 swap d1 ror.w #8,d1 move.l d1,(a0)+ sub.l #1,d0 bgt.s @loop @loope:
#else
u32 mult64anddiv(u32 m1,u32 m2,u32 d);
void radconv32a(void* p,u32 n);
#endif
#else
#ifdef __WATCOMC__
u32 radsqr(s32 a);
#pragma aux radsqr = "mul eax" parm [eax] modify [EDX eax];
u32 mult64anddiv(u32 m1,u32 m2,u32 d);
#pragma aux mult64anddiv = "mul ecx" "div ebx" parm [eax] [ecx] [ebx] modify [EDX eax];
s32 radabs(s32 ab);
#pragma aux radabs = "test eax,eax" "jge skip" "neg eax" "skip:" parm [eax];
#define radabs32 radabs
u32 DOSOut(const char* str);
#pragma aux DOSOut = "cld" "mov ecx,0xffffffff" "xor eax,eax" "mov edx,edi" "repne scasb" "not ecx" "dec ecx" "mov ebx,1" "mov ah,0x40" "int 0x21" parm [EDI] modify [EAX EBX ECX EDX EDI] value [ecx];
void DOSOutNum(const char* str,u32 len);
#pragma aux DOSOutNum = "mov ah,0x40" "mov ebx,1" "int 0x21" parm [edx] [ecx] modify [eax ebx];
u32 ErrOut(const char* str);
#pragma aux ErrOut = "cld" "mov ecx,0xffffffff" "xor eax,eax" "mov edx,edi" "repne scasb" "not ecx" "dec ecx" "xor ebx,ebx" "mov ah,0x40" "int 0x21" parm [EDI] modify [EAX EBX ECX EDX EDI] value [ecx];
void ErrOutNum(const char* str,u32 len);
#pragma aux ErrOutNum = "mov ah,0x40" "xor ebx,ebx" "int 0x21" parm [edx] [ecx] modify [eax ebx];
void radmemset16(void* dest,u16 value,u32 size);
#pragma aux radmemset16 = "cld" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,1" "rep stosd" "mov cl,bl" "and cl,1" "rep stosw" parm [EDI] [EAX] [ECX] modify [EAX EDX EBX ECX EDI];
void radmemset(void* dest,u8 value,u32 size);
#pragma aux radmemset = "cld" "mov ah,al" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,2" "and bl,3" "rep stosd" "mov cl,bl" "rep stosb" parm [EDI] [AL] [ECX] modify [EAX EDX EBX ECX EDI];
void radmemset32(void* dest,u32 value,u32 size);
#pragma aux radmemset32 = "cld" "rep stosd" parm [EDI] [EAX] [ECX] modify [EAX EDX EBX ECX EDI];
void radmemcpy(void* dest,const void* source,u32 size);
#pragma aux radmemcpy = "cld" "mov bl,cl" "shr ecx,2" "rep movsd" "mov cl,bl" "and cl,3" "rep movsb" parm [EDI] [ESI] [ECX] modify [EBX ECX EDI ESI];
void __far *radfmemcpy(void __far* dest,const void __far* source,u32 size);
#pragma aux radfmemcpy = "cld" "push es" "push ds" "mov es,cx" "mov ds,dx" "mov ecx,eax" "shr ecx,2" "rep movsd" "mov cl,al" "and cl,3" "rep movsb" "pop ds" "pop es" parm [CX EDI] [DX ESI] [EAX] modify [ECX EDI ESI] value [CX EDI];
void radmemcpydb(void* dest,const void* source,u32 size); //Destination bigger
#pragma aux radmemcpydb = "std" "mov bl,cl" "lea esi,[esi+ecx-4]" "lea edi,[edi+ecx-4]" "shr ecx,2" "rep movsd" "and bl,3" "jz dne" "add esi,3" "add edi,3" "mov cl,bl" "rep movsb" "dne:" "cld" parm [EDI] [ESI] [ECX] modify [EBX ECX EDI ESI];
char* radstrcpy(void* dest,const void* source);
#pragma aux radstrcpy = "cld" "mov edx,edi" "lp:" "mov al,[esi]" "inc esi" "mov [edi],al" "inc edi" "cmp al,0" "jne lp" parm [EDI] [ESI] modify [EAX EDX EDI ESI] value [EDX];
char __far* radfstrcpy(void __far* dest,const void __far* source);
#pragma aux radfstrcpy = "cld" "push es" "push ds" "mov es,cx" "mov ds,dx" "mov edx,edi" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "pop ds" "pop es" parm [CX EDI] [DX ESI] modify [EAX EDX EDI ESI] value [CX EDX];
char* radstpcpy(void* dest,const void* source);
#pragma aux radstpcpy = "cld" "lp:" "mov al,[esi]" "inc esi" "mov [edi],al" "inc edi" "cmp al,0" "jne lp" "dec edi" parm [EDI] [ESI] modify [EAX EDI ESI] value [EDI];
char* radstpcpyrs(void* dest,const void* source);
#pragma aux radstpcpyrs = "cld" "lp:" "mov al,[esi]" "inc esi" "mov [edi],al" "inc edi" "cmp al,0" "jne lp" "dec esi" parm [EDI] [ESI] modify [EAX EDI ESI] value [ESI];
u32 radstrlen(const void* dest);
#pragma aux radstrlen = "cld" "mov ecx,0xffffffff" "xor eax,eax" "repne scasb" "not ecx" "dec ecx" parm [EDI] modify [EAX ECX EDI] value [ECX];
char* radstrcat(void* dest,const void* source);
#pragma aux radstrcat = "cld" "mov ecx,0xffffffff" "mov edx,edi" "xor eax,eax" "repne scasb" "dec edi" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" \
parm [EDI] [ESI] modify [EAX ECX EDI ESI] value [EDX];
char* radstrchr(const void* dest,char chr);
#pragma aux radstrchr = "cld" "lp:" "lodsb" "cmp al,dl" "je fnd" "cmp al,0" "jnz lp" "mov esi,1" "fnd:" "dec esi" parm [ESI] [DL] modify [EAX ESI] value [esi];
s8 radmemcmp(const void* s1,const void* s2,u32 len);
#pragma aux radmemcmp = "cld" "rep cmpsb" "setne al" "jbe end" "neg al" "end:" parm [EDI] [ESI] [ECX] modify [ECX EDI ESI];
s8 radstrcmp(const void* s1,const void* s2);
#pragma aux radstrcmp = "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,ah" "jne set" "cmp al,0" "je set" "inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" \
parm [EDI] [ESI] modify [EAX EDI ESI];
s8 radstricmp(const void* s1,const void* s2);
#pragma aux radstricmp = "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" "cmp ah,'a'" "jb c2" "cmp ah,'z'" "ja c2" "sub ah,32" "c2:" "cmp al,ah" "jne set" "cmp al,0" "je set" \
"inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" \
parm [EDI] [ESI] modify [EAX EDI ESI];
s8 radstrnicmp(const void* s1,const void* s2,u32 len);
#pragma aux radstrnicmp = "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" "cmp ah,'a'" "jb c2" "cmp ah,'z'" "ja c2" "sub ah,32" "c2:" "cmp al,ah" "jne set" "cmp al,0" "je set" \
"dec ecx" "jz set" "inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" \
parm [EDI] [ESI] [ECX] modify [EAX ECX EDI ESI];
char* radstrupr(void* s1);
#pragma aux radstrupr = "mov ecx,edi" "lp:" "mov al,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub [edi],32" "c1:" "inc edi" "cmp al,0" "jne lp" parm [EDI] modify [EAX EDI] value [ecx];
char* radstrlwr(void* s1);
#pragma aux radstrlwr = "mov ecx,edi" "lp:" "mov al,[edi]" "cmp al,'A'" "jb c1" "cmp al,'Z'" "ja c1" "add [edi],32" "c1:" "inc edi" "cmp al,0" "jne lp" parm [EDI] modify [EAX EDI] value [ecx];
u32 radstru32(const void* dest);
#pragma aux radstru32 = "cld" "xor ecx,ecx" "xor ebx,ebx" "xor edi,edi" "lodsb" "cmp al,45" "jne skip2" "mov edi,1" "jmp skip" "lp:" "mov eax,10" "mul ecx" "lea ecx,[eax+ebx]" \
"skip:" "lodsb" "skip2:" "cmp al,0x39" "ja dne" "cmp al,0x30" "jb dne" "mov bl,al" "sub bl,0x30" "jmp lp" "dne:" "test edi,1" "jz pos" "neg ecx" "pos:" \
parm [ESI] modify [EAX EBX EDX EDI ESI] value [ecx];
u16 GetDS();
#pragma aux GetDS = "mov ax,ds" value [ax];
#ifdef __RADWINEXT__
#define _16To32(ptr16) ((void*)(((GetSelectorBase((u16)(((u32)(ptr16))>>16))+((u16)(u32)(ptr16)))-GetSelectorBase(GetDS()))))
#endif
#ifndef __RADWIN__
#define int86 int386
#define int86x int386x
#endif
#define u32regs x
#define u16regs w
#else
#define radstrcpy strcpy
#define radstrcat strcat
#define radmemcpy memcpy
#define radmemcpydb memmove
#define radmemcmp memcmp
#define radmemset memset
#define radstrlen strlen
#define radstrchr strchr
#define radtoupper toupper
#define radstru32(s) ((u32)atol(s))
#define radstricmp _stricmp
#define radstrcmp strcmp
#define radstrupr _strupr
#define radstrlwr _strlwr
#define BreakPoint() _asm {int 3}
#ifdef _MSC_VER
#pragma warning( disable : 4035)
typedef char* RADPCHAR;
u32 __inline radsqr(u32 m) {
_asm {
mov eax,[m]
mul eax
}
}
u32 __inline mult64anddiv(u32 m1,u32 m2, u32 d) {
_asm {
mov eax,[m1]
mov ecx,[m2]
mul ecx
mov ecx,[d]
div ecx
}
}
s32 __inline radabs(s32 ab) {
_asm {
mov eax,[ab]
test eax,eax
jge skip
neg eax
skip:
}
}
u8 __inline radinp(u16 p) {
_asm {
mov dx,[p]
in al,dx
}
}
void __inline radoutp(u16 p,u8 v) {
_asm {
mov dx,[p]
mov al,[v]
out dx,al
}
}
RADPCHAR __inline radstpcpy(char* p1, char* p2) {
_asm {
mov edx,[p1]
mov ecx,[p2]
cld
lp:
mov al,[ecx]
inc ecx
mov [edx],al
inc edx
cmp al,0
jne lp
dec edx
mov eax,edx
}
}
RADPCHAR __inline radstpcpyrs(char* p1, char* p2) {
_asm {
mov edx,[p1]
mov ecx,[p2]
cld
lp:
mov al,[ecx]
inc ecx
mov [edx],al
inc edx
cmp al,0
jne lp
dec ecx
mov eax,ecx
}
}
void __inline radmemset16(void* dest,u16 value,u32 sizeb) {
_asm {
mov edi,[dest]
mov ax,[value]
mov ecx,[sizeb]
shl eax,16
cld
mov ax,[value]
mov bl,cl
shr ecx,1
rep stosd
mov cl,bl
and cl,1
rep stosw
}
}
void __inline radmemset32(void* dest,u32 value,u32 sizeb) {
_asm {
mov edi,[dest]
mov eax,[value]
mov ecx,[sizeb]
cld
rep stosd
}
}
u32 __inline __stdcall RADsqrt(u32 sq) {
_asm {
fild dword ptr [sq]
fsqrt
fistp word ptr [sq]
movzx eax,word ptr [sq]
}
}
void __inline RADCycleTimerStartAddr(u32* addr)
{
_asm {
mov ecx,[addr]
__asm __emit 0fh __asm __emit 031h
mov [ecx],eax
}
}
u32 __inline RADCycleTimerDeltaAddr(u32* addr)
{
_asm {
__asm __emit 0fh __asm __emit 031h
mov ecx,[addr]
sub eax,[ecx]
}
}
#define RADCycleTimerStart(var) RADCycleTimerStartAddr(&var)
#define RADCycleTimerDelta(var) RADCycleTimerDeltaAddr(&var)
#pragma warning( default : 4035)
#endif
#endif
#endif
#else
#define PTR4 __far
#define u16 unsigned int
#define s16 signed int
#ifdef __WATCOMC__
u32 radsqr(s32 a);
#pragma aux radsqr = "shl edx,16" "mov dx,ax" "mov eax,edx" "xor edx,edx" "mul eax" "shld edx,eax,16" parm [dx ax] modify [DX ax] value [dx ax];
s16 radabs(s16 ab);
#pragma aux radabs = "test ax,ax" "jge skip" "neg ax" "skip:" parm [ax] value [ax];
s32 radabs32(s32 ab);
#pragma aux radabs32 = "test dx,dx" "jge skip" "neg dx" "neg ax" "sbb dx,0" "skip:" parm [dx ax] value [dx ax];
u32 DOSOut(const char far* dest);
#pragma aux DOSOut = "cld" "and edi,0xffff" "mov dx,di" "mov ecx,0xffffffff" "xor eax,eax" 0x67 "repne scasb" "not ecx" "dec ecx" "mov bx,1" "push ds" "push es" "pop ds" "mov ah,0x40" "int 0x21" "pop ds" "movzx eax,cx" "shr ecx,16" \
parm [ES DI] modify [AX BX CX DX DI ES] value [CX AX];
void DOSOutNum(const char far* str,u16 len);
#pragma aux DOSOutNum = "push ds" "mov ds,cx" "mov cx,bx" "mov ah,0x40" "mov bx,1" "int 0x21" "pop ds" parm [cx dx] [bx] modify [ax bx cx];
u32 ErrOut(const char far* dest);
#pragma aux ErrOut = "cld" "and edi,0xffff" "mov dx,di" "mov ecx,0xffffffff" "xor eax,eax" 0x67 "repne scasb" "not ecx" "dec ecx" "xor bx,bx" "push ds" "push es" "pop ds" "mov ah,0x40" "int 0x21" "pop ds" "movzx eax,cx" "shr ecx,16" \
parm [ES DI] modify [AX BX CX DX DI ES] value [CX AX];
void ErrOutNum(const char far* str,u16 len);
#pragma aux ErrOutNum = "push ds" "mov ds,cx" "mov cx,bx" "mov ah,0x40" "xor bx,bx" "int 0x21" "pop ds" parm [cx dx] [bx] modify [ax bx cx];
void radmemset(void far *dest,u8 value,u32 size);
#pragma aux radmemset = "cld" "and edi,0ffffh" "shl ecx,16" "mov cx,bx" "mov ah,al" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,2" 0x67 "rep stosd" "mov cl,bl" "and cl,3" "rep stosb" parm [ES DI] [AL] [CX BX];
void radmemset16(void far* dest,u16 value,u32 size);
#pragma aux radmemset16 = "cld" "and edi,0ffffh" "shl ecx,16" "mov cx,bx" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,1" "rep stosd" "mov cl,bl" "and cl,1" "rep stosw" parm [ES DI] [AX] [CX BX];
void radmemcpy(void far* dest,const void far* source,u32 size);
#pragma aux radmemcpy = "cld" "push ds" "mov ds,dx" "and esi,0ffffh" "and edi,0ffffh" "shl ecx,16" "mov cx,bx" "shr ecx,2" 0x67 "rep movsd" "mov cl,bl" "and cl,3" "rep movsb" "pop ds" parm [ES DI] [DX SI] [CX BX] modify [CX SI DI ES];
s8 radmemcmp(const void far* s1,const void far* s2,u32 len);
#pragma aux radmemcmp = "cld" "push ds" "mov ds,dx" "shl ecx,16" "mov cx,bx" "rep cmpsb" "setne al" "jbe end" "neg al" "end:" "pop ds" parm [ES DI] [DX SI] [CX BX] modify [CX SI DI ES];
char far* radstrcpy(void far* dest,const void far* source);
#pragma aux radstrcpy = "cld" "push ds" "mov ds,dx" "and esi,0xffff" "and edi,0xffff" "mov dx,di" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "pop ds" parm [ES DI] [DX SI] modify [AX DX DI SI ES] value [es dx];
char far* radstpcpy(void far* dest,const void far* source);
#pragma aux radstpcpy = "cld" "push ds" "mov ds,dx" "and esi,0xffff" "and edi,0xffff" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "dec di" "pop ds" parm [ES DI] [DX SI] modify [DI SI ES] value [es di];
u32 radstrlen(const void far* dest);
#pragma aux radstrlen = "cld" "and edi,0xffff" "mov ecx,0xffffffff" "xor eax,eax" 0x67 "repne scasb" "not ecx" "dec ecx" "movzx eax,cx" "shr ecx,16" parm [ES DI] modify [AX CX DI ES] value [CX AX];
char far* radstrcat(void far* dest,const void far* source);
#pragma aux radstrcat = "cld" "and edi,0xffff" "mov ecx,0xffffffff" "and esi,0xffff" "push ds" "mov ds,dx" "mov dx,di" "xor eax,eax" 0x67 "repne scasb" "dec edi" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "pop ds" \
parm [ES DI] [DX SI] modify [AX CX DI SI ES] value [es dx];
char far* radstrchr(const void far* dest,char chr);
#pragma aux radstrchr = "cld" "lp:" 0x26 "lodsb" "cmp al,dl" "je fnd" "cmp al,0" "jnz lp" "xor ax,ax" "mov es,ax" "mov si,1" "fnd:" "dec si" parm [ES SI] [DL] modify [AX SI ES] value [es si];
s8 radstricmp(const void far* s1,const void far* s2);
#pragma aux radstricmp = "and edi,0xffff" "push ds" "mov ds,dx" "and esi,0xffff" "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" \
"cmp ah,'a'" "jb c2" "cmp ah,'z'" "ja c2" "sub ah,32" "c2:" "cmp al,ah" "jne set" "cmp al,0" "je set" \
"inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" "pop ds" \
parm [ES DI] [DX SI] modify [AX DI SI];
u32 radstru32(const void far* dest);
#pragma aux radstru32 = "cld" "xor ecx,ecx" "xor ebx,ebx" "xor edi,edi" 0x26 "lodsb" "cmp al,45" "jne skip2" "mov edi,1" "jmp skip" "lp:" "mov eax,10" "mul ecx" "lea ecx,[eax+ebx]" \
"skip:" 0x26 "lodsb" "skip2:" "cmp al,0x39" "ja dne" "cmp al,0x30" "jb dne" "mov bl,al" "sub bl,0x30" "jmp lp" "dne:" "test edi,1" "jz pos" "neg ecx" "pos:" \
"movzx eax,cx" "shr ecx,16" parm [ES SI] modify [AX BX DX DI SI] value [cx ax];
u32 mult64anddiv(u32 m1,u32 m2,u32 d);
#pragma aux mult64anddiv = "shl ecx,16" "mov cx,ax" "shrd eax,edx,16" "mov ax,si" "mul ecx" "shl edi,16" "mov di,bx" "div edi" "shld edx,eax,16" "and edx,0xffff" "and eax,0xffff" parm [cx ax] [dx si] [di bx] \
modify [ax bx cx dx si di] value [dx ax];
#endif
#endif
RADDEFEND
#define u32neg1 ((u32)(s32)-1)
#define RAD_align(var) var; u8 junk##var[4-(sizeof(var)&3)];
#define RAD_align_after(var) u8 junk##var[4-(sizeof(var)&3)]={0};
#define RAD_align_init(var,val) var=val; u8 junk##var[4-(sizeof(var)&3)]={0};
#define RAD_align_array(var,num) var[num]; u8 junk##var[4-(sizeof(var)&3)];
#define RAD_align_string(var,str) char var[]=str; u8 junk##var[4-(sizeof(var)&3)]={0};
RADEXPFUNC void PTR4* RADEXPLINK radmalloc(u32 numbytes);
RADEXPFUNC void RADEXPLINK radfree(void PTR4* ptr);
#ifdef __WATCOMC__
char bkbhit();
#pragma aux bkbhit = "mov ah,1" "int 0x16" "lahf" "shr eax,14" "and eax,1" "xor al,1" ;
char bgetch();
#pragma aux bgetch = "xor ah,ah" "int 0x16" "test al,0xff" "jnz done" "mov al,ah" "or al,0x80" "done:" modify [AX];
void BreakPoint();
#pragma aux BreakPoint = "int 3";
u8 radinp(u16 p);
#pragma aux radinp = "in al,dx" parm [DX];
u8 radtoupper(u8 p);
#pragma aux radtoupper = "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" parm [al] value [al];
void radoutp(u16 p,u8 v);
#pragma aux radoutp = "out dx,al" parm [DX] [AL];
#endif
// for multi-processor machines
#ifdef __RADNT__
#define LockedIncrement(var) _asm { lock inc [var] }
#define LockedDecrement(var) _asm { lock dec [var] }
#else
#define LockedIncrement(var) _asm { inc [var] }
#define LockedDecrement(var) _asm { dec [var] }
#endif
#endif
#endif
+109
View File
@@ -0,0 +1,109 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "Random.h"
#endif
#ifdef PRERANDOM_GENERATOR
UINT32 guiPreRandomIndex = 0;
UINT32 guiPreRandomNums[ MAX_PREGENERATED_NUMS ];
#ifdef JA2BETAVERSION
UINT32 guiRandoms = 0;
UINT32 guiPreRandoms = 0;
BOOLEAN gfCountRandoms = FALSE;
#endif
#endif
void InitializeRandom()
{
// Seed the random-number generator with current time so that
// the numbers will be different every time we run.
srand( (unsigned) time(NULL) );
#ifdef PRERANDOM_GENERATOR
//Pregenerate all of the random numbers.
for( guiPreRandomIndex = 0; guiPreRandomIndex < MAX_PREGENERATED_NUMS; guiPreRandomIndex++ )
{
guiPreRandomNums[ guiPreRandomIndex ] = rand();
}
guiPreRandomIndex = 0;
#endif
}
// Returns a pseudo-random integer between 0 and uiRange
UINT32 Random(UINT32 uiRange)
{
// Always return 0, if no range given (it's not an error)
#ifdef JA2BETAVERSION
if( gfCountRandoms )
{
guiRandoms++;
}
#endif
if (uiRange == 0)
return(0);
return rand() * uiRange / RAND_MAX % uiRange;
}
BOOLEAN Chance( UINT32 uiChance )
{
return (BOOLEAN)(Random( 100 ) < uiChance);
}
#ifdef PRERANDOM_GENERATOR
UINT32 PreRandom( UINT32 uiRange )
{
UINT32 uiNum;
#ifdef JA2BETAVERSION
if( gfCountRandoms )
{
guiPreRandoms++;
}
#endif
if( !uiRange )
return 0;
//Extract the current pregenerated number
uiNum = guiPreRandomNums[ guiPreRandomIndex ] * uiRange / RAND_MAX % uiRange;
//Replace the current pregenerated number with a new one.
//This was removed in the name of optimization. Uncomment if you hate recycling.
//guiPreRandomNums[ guiPreRandomIndex ] = rand();
//Go to the next index.
guiPreRandomIndex++;
if( guiPreRandomIndex >= (UINT32)MAX_PREGENERATED_NUMS )
guiPreRandomIndex = 0;
return uiNum;
}
BOOLEAN PreChance( UINT32 uiChance )
{
return (BOOLEAN)(PreRandom( 100 ) < uiChance);
}
#ifdef JA2BETAVERSION
void CountRandomCalls( BOOLEAN fStart )
{
gfCountRandoms = fStart;
if( fStart )
{
guiRandoms = 0;
guiPreRandoms = 0;
}
}
void GetRandomCalls( UINT32 *puiRandoms, UINT32 *puiPreRandoms )
{
*puiRandoms = guiRandoms;
*puiPreRandoms = guiPreRandoms;
}
#endif
#endif
+386
View File
@@ -0,0 +1,386 @@
//**************************************************************************
//
// Filename : RegInst.c
//
// Purpose : registry routines
//
// Modification history :
//
// 02dec96:HJH - Creation
//
//**************************************************************************
//**************************************************************************
//
// Includes
//
//**************************************************************************
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "types.h"
#include "RegInst.h"
#include "WCheck.h"
#endif
//**************************************************************************
//
// Defines
//
//**************************************************************************
#define REG_KEY_SIZE 50
//**************************************************************************
//
// Variables
//
//**************************************************************************
// INI strings are not localized
static const TCHAR szSoftware[] = _T("Software");
static CHAR gszRegistryKey[REG_KEY_SIZE];
static CHAR gszAppName[REG_KEY_SIZE];
static CHAR gszProfileName[REG_KEY_SIZE];
//**************************************************************************
//
// Functions
//
//**************************************************************************
BOOLEAN InitializeRegistryKeys(STR lpszAppName, STR lpszRegistryKey)
{
CHECKF(lpszAppName != NULL);
CHECKF(lpszRegistryKey != NULL);
//CHECKF(gpszRegistryKey == NULL);
//CHECKF(gpszAppName == NULL);
//CHECKF(gpszProfileName == NULL);
// Note: this will leak the original gpszProfileName, but it
// will be freed when the application exits. No assumptions
// can be made on how gpszProfileName was allocated.
strcpy( gszAppName, lpszAppName);
strcpy( gszRegistryKey, lpszRegistryKey );
strcpy( gszProfileName, gszAppName);
return(TRUE);
}
// returns key for HKEY_CURRENT_USER\"Software"\RegistryKey\ProfileName
// creating it if it doesn't exist
// responsibility of the caller to call RegCloseKey() on the returned HKEY
HKEY GetAppRegistryKey()
{
HKEY hAppKey = NULL;
HKEY hSoftKey = NULL;
HKEY hCompanyKey = NULL;
assert(gszRegistryKey[0] != '\0');
//assert(gpszProfileName != NULL);
if (RegOpenKeyEx(HKEY_CURRENT_USER, szSoftware, 0, KEY_WRITE|KEY_READ,
&hSoftKey) == ERROR_SUCCESS)
{
DWORD dw;
if (RegCreateKeyEx(hSoftKey, gszRegistryKey, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&hCompanyKey, &dw) == ERROR_SUCCESS)
{
RegCreateKeyEx(hCompanyKey, gszProfileName, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&hAppKey, &dw);
}
}
if (hSoftKey != NULL)
RegCloseKey(hSoftKey);
if (hCompanyKey != NULL)
RegCloseKey(hCompanyKey);
return hAppKey;
}
// returns key for:
// HKEY_CURRENT_USER\"Software"\RegistryKey\AppName\lpszSection
// creating it if it doesn't exist.
// responsibility of the caller to call RegCloseKey() on the returned HKEY
HKEY GetSectionKey(STR lpszSection)
{
HKEY hSectionKey = NULL;
HKEY hAppKey = GetAppRegistryKey();
DWORD dw;
assert(lpszSection != NULL);
if (hAppKey == NULL)
return NULL;
RegCreateKeyEx(hAppKey, lpszSection, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&hSectionKey, &dw);
RegCloseKey(hAppKey);
return hSectionKey;
}
UINT GetProfileInteger(STR lpszSection, STR lpszEntry, int nDefault)
{
DWORD dwValue;
DWORD dwType;
DWORD dwCount = sizeof(DWORD);
LONG lResult;
assert(lpszSection != NULL);
assert(lpszEntry != NULL);
if (gszRegistryKey[0] != '\0') // use registry
{
HKEY hSecKey = GetSectionKey(lpszSection);
if (hSecKey == NULL)
return nDefault;
lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
(LPBYTE)&dwValue, &dwCount);
RegCloseKey(hSecKey);
if (lResult == ERROR_SUCCESS)
{
assert(dwType == REG_DWORD);
assert(dwCount == sizeof(dwValue));
return (UINT)dwValue;
}
return nDefault;
}
else
{
assert(gszProfileName[0] != '\0');
return GetPrivateProfileInt(lpszSection, lpszEntry, nDefault,
gszProfileName);
}
}
BOOLEAN GetProfileChar(STR lpszSection, STR lpszEntry, STR lpszDefault, STR lpszValue)
{
DWORD dwType, dwCount;
LONG lResult;
BOOLEAN fRet = TRUE;
CHAR strValue[200];
assert(lpszSection != NULL);
assert(lpszEntry != NULL);
assert(lpszDefault != NULL);
if (gszRegistryKey[0] != '\0')
{
HKEY hSecKey = GetSectionKey(lpszSection);
if (hSecKey == NULL)
{
strcpy( lpszValue, lpszDefault );
return(TRUE);
}
lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
NULL, &dwCount);
if (lResult == ERROR_SUCCESS)
{
assert(dwType == REG_SZ);
lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
(LPBYTE)strValue, &dwCount);
}
RegCloseKey(hSecKey);
if (lResult == ERROR_SUCCESS)
{
assert(dwType == REG_SZ);
strcpy( lpszValue, strValue );
return(TRUE);
}
strcpy( lpszValue, lpszDefault );
return(TRUE);
}
// else
// {
// assert(gpszProfileName != NULL);
//
// if (lpszDefault == NULL)
// lpszDefault = &afxChNil; // don't pass in NULL
// TCHAR szT[4096];
// DWORD dw = ::GetPrivateProfileString(lpszSection, lpszEntry,
// lpszDefault, szT, _countof(szT), gpszProfileName);
// assert(dw < 4095);
// return szT;
// }
return( fRet );
}
BOOL GetProfileBinary(STR lpszSection, STR lpszEntry,
BYTE** ppData, UINT* pBytes)
{
// DWORD dwType, dwCount;
// LONG lResult;
//
// assert(lpszSection != NULL);
// assert(lpszEntry != NULL);
// assert(ppData != NULL);
// assert(pBytes != NULL);
// *ppData = NULL;
// *pBytes = 0;
//
// if (gpszRegistryKey != NULL)
// {
// LPBYTE lpByte = NULL;
// HKEY hSecKey = GetSectionKey(lpszSection);
// if (hSecKey == NULL)
// return FALSE;
//
// lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
// NULL, &dwCount);
// *pBytes = dwCount;
// if (lResult == ERROR_SUCCESS)
// {
// assert(dwType == REG_BINARY);
// *ppData = new BYTE[*pBytes];
// lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
// *ppData, &dwCount);
// }
// RegCloseKey(hSecKey);
// if (lResult == ERROR_SUCCESS)
// {
// assert(dwType == REG_BINARY);
// return TRUE;
// }
// else
// {
// delete [] *ppData;
// *ppData = NULL;
// }
// return FALSE;
// }
// else
// {
// //assert(gpszProfileName != NULL);
// //
// //CString str = GetProfileString(lpszSection, lpszEntry, NULL);
// //if (str.IsEmpty())
// // return FALSE;
// //assert(str.GetLength()%2 == 0);
// //int nLen = str.GetLength();
// //*pBytes = nLen/2;
// //*ppData = new BYTE[*pBytes];
// //for (int i=0;i<nLen;i+=2)
// //{
// // (*ppData)[i/2] = (BYTE)
// // (((str[i+1] - _T('A')) << 4) + (str[i] - _T('A')));
// //}
// return TRUE;
// }
return TRUE;
}
BOOL WriteProfileInt(STR lpszSection, STR lpszEntry, int nValue)
{
// LONG lResult;
// TCHAR szT[16];
//
// assert(lpszSection != NULL);
// assert(lpszEntry != NULL);
//
// if (gpszRegistryKey != NULL)
// {
// HKEY hSecKey = GetSectionKey(lpszSection);
// if (hSecKey == NULL)
// return FALSE;
// lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_DWORD,
// (LPBYTE)&nValue, sizeof(nValue));
// RegCloseKey(hSecKey);
// return lResult == ERROR_SUCCESS;
// }
// else
// {
// assert(gpszProfileName != NULL);
//
// wsprintf(szT, _T("%d"), nValue);
// return ::WritePrivateProfileString(lpszSection, lpszEntry, szT,
// gpszProfileName);
// }
return TRUE;
}
BOOL WriteProfileChar(STR lpszSection, STR lpszEntry, STR lpszValue)
{
assert(lpszSection != NULL);
if (gszRegistryKey[0] != '\0')
{
LONG lResult;
if (lpszEntry == NULL) //delete whole section
{
HKEY hAppKey = GetAppRegistryKey();
if (hAppKey == NULL)
return FALSE;
lResult = RegDeleteKey(hAppKey, lpszSection);
RegCloseKey(hAppKey);
}
else if (lpszValue == NULL)
{
HKEY hSecKey = GetSectionKey(lpszSection);
if (hSecKey == NULL)
return FALSE;
// necessary to cast away const below
lResult = RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);
RegCloseKey(hSecKey);
}
else
{
HKEY hSecKey = GetSectionKey(lpszSection);
if (hSecKey == NULL)
return FALSE;
lResult = RegSetValueEx(hSecKey, lpszEntry, 0, REG_SZ,
(LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));
RegCloseKey(hSecKey);
}
return lResult == ERROR_SUCCESS;
}
// else
// {
// assert(gpszProfileName != NULL);
// assert(lstrlen(gpszProfileName) < 4095); // can't read in bigger
// return ::WritePrivateProfileString(lpszSection, lpszEntry, lpszValue,
// gpszProfileName);
// }
return TRUE;
}
BOOL WriteProfileBinary(STR lpszSection, STR lpszEntry, LPBYTE pData, UINT nBytes)
{
// assert(lpszSection != NULL);
//
// if (gpszRegistryKey != NULL)
// {
// LONG lResult;
// HKEY hSecKey = GetSectionKey(lpszSection);
// if (hSecKey == NULL)
// return FALSE;
// lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_BINARY,
// pData, nBytes);
// RegCloseKey(hSecKey);
// return lResult == ERROR_SUCCESS;
// }
//
// // convert to string and write out
// LPTSTR lpsz = new TCHAR[nBytes*2+1];
// for (UINT i = 0; i < nBytes; i++)
// {
// lpsz[i*2] = (TCHAR)((pData[i] & 0x0F) + _T('A')); //low nibble
// lpsz[i*2+1] = (TCHAR)(((pData[i] >> 4) & 0x0F) + _T('A')); //high nibble
// }
// lpsz[i*2] = 0;
//
// assert(gpszProfileName != NULL);
//
// BOOL bResult = WriteProfileString(lpszSection, lpszEntry, lpsz);
// delete[] lpsz;
// return bResult;
return TRUE;
}
+75
View File
@@ -0,0 +1,75 @@
//**************************************************************************
//
// Filename : RegInst.h
//
// Purpose : prototypes for the registry stuff
//
// Modification history :
//
// 02dec96:HJH - Creation
//
//**************************************************************************
#ifndef _RegInst_h
#define _RegInst_h
//**************************************************************************
//
// Includes
//
//**************************************************************************
#include <windows.h>
#include <tchar.h>
#include <assert.h>
#include "types.h"
//**************************************************************************
//
// Defines
//
//**************************************************************************
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
//**************************************************************************
//
// Function Prototypes
//
//**************************************************************************
#ifdef __cplusplus
extern "C" {
#endif
// call once per execution of application:
extern BOOLEAN InitializeRegistryKeys(STR strAppName, STR strRegistryKey);
// returns key for HKEY_CURRENT_USER\"Software"\RegistryKey\ProfileName
// creating it if it doesn't exist
// responsibility of the caller to call RegCloseKey() on the returned HKEY
extern HKEY GetAppRegistryKey();
// returns key for:
// HKEY_CURRENT_USER\"Software"\RegistryKey\AppName\lpszSection
// creating it if it doesn't exist.
// responsibility of the caller to call RegCloseKey() on the returned HKEY
extern HKEY GetSectionKey(STR lpszSection);
extern UINT GetProfileInteger(STR lpszSection, STR lpszEntry, int nDefault);
extern BOOLEAN GetProfileChar(STR lpszSection, STR lpszEntry, STR lpszDefault, STR lpszValue);
extern BOOL GetProfileBinary(STR lpszSection, STR lpszEntry, BYTE** ppData, UINT* pBytes);
extern BOOL WriteProfileInt(STR lpszSection, STR lpszEntry, int nValue);
extern BOOL WriteProfileChar(STR lpszSection, STR lpszEntry, STR lpszValue);
extern BOOL WriteProfileBinary(STR lpszSection, STR lpszEntry, LPBYTE pData, UINT nBytes);
#ifdef __cplusplus
}
#endif
#endif
+434
View File
@@ -0,0 +1,434 @@
#ifndef SMACKH
#define SMACKH
#define SMACKVERSION "3.2f"
#ifndef __RADRES__
#include "rad.h"
RADDEFSTART
typedef struct SmackTag {
u32 Version; // SMK2 only right now
u32 Width; // Width (1 based, 640 for example)
u32 Height; // Height (1 based, 480 for example)
u32 Frames; // Number of frames (1 based, 100 = 100 frames)
u32 MSPerFrame; // Frame Rate
u32 SmackerType; // bit 0 set=ring frame
u32 LargestInTrack[7]; // Largest single size for each track
u32 tablesize; // Size of the init tables
u32 codesize; // Compression info
u32 absize; // ditto
u32 detailsize; // ditto
u32 typesize; // ditto
u32 TrackType[7]; // high byte=0x80-Comp,0x40-PCM data,0x20-16 bit,0x10-stereo
u32 extra; // extra value (should be zero)
u32 NewPalette; // set to one if the palette changed
u8 Palette[772]; // palette data
u32 PalType; // type of palette
u32 FrameNum; // Frame Number to be displayed
u32 FrameSize; // The current frame's size in bytes
u32 SndSize; // The current frame sound tracks' size in bytes
s32 LastRectx; // Rect set in from SmackToBufferRect (X coord)
s32 LastRecty; // Rect set in from SmackToBufferRect (Y coord)
s32 LastRectw; // Rect set in from SmackToBufferRect (Width)
s32 LastRecth; // Rect set in from SmackToBufferRect (Height)
u32 OpenFlags; // flags used on open
u32 LeftOfs; // Left Offset used in SmackTo
u32 TopOfs; // Top Offset used in SmackTo
u32 LargestFrameSize; // Largest frame size
u32 Highest1SecRate; // Highest 1 sec data rate
u32 Highest1SecFrame; // Highest 1 sec data rate starting frame
u32 ReadError; // Set to non-zero if a read error has ocurred
u32 addr32; // translated address for 16 bit interface
} Smack;
#define SmackHeaderSize(smk) ((((u8*)&((smk)->extra))-((u8*)(smk)))+4)
typedef struct SmackSumTag {
u32 TotalTime; // total time
u32 MS100PerFrame; // MS*100 per frame (100000/MS100PerFrame=Frames/Sec)
u32 TotalOpenTime; // Time to open and prepare for decompression
u32 TotalFrames; // Total Frames displayed
u32 SkippedFrames; // Total number of skipped frames
u32 SoundSkips; // Total number of sound skips
u32 TotalBlitTime; // Total time spent blitting
u32 TotalReadTime; // Total time spent reading
u32 TotalDecompTime; // Total time spent decompressing
u32 TotalBackReadTime; // Total time spent reading in background
u32 TotalReadSpeed; // Total io speed (bytes/second)
u32 SlowestFrameTime; // Slowest single frame time
u32 Slowest2FrameTime; // Second slowest single frame time
u32 SlowestFrameNum; // Slowest single frame number
u32 Slowest2FrameNum; // Second slowest single frame number
u32 AverageFrameSize; // Average size of the frame
u32 HighestMemAmount; // Highest amount of memory allocated
u32 TotalExtraMemory; // Total extra memory allocated
u32 HighestExtraUsed; // Highest extra memory actually used
} SmackSum;
//=======================================================================
#define SMACKNEEDPAN 0x00020L // Will be setting the pan
#define SMACKNEEDVOLUME 0x00040L // Will be setting the volume
#define SMACKFRAMERATE 0x00080L // Override fr (call SmackFrameRate first)
#define SMACKLOADEXTRA 0x00100L // Load the extra buffer during SmackOpen
#define SMACKPRELOADALL 0x00200L // Preload the entire animation
#define SMACKNOSKIP 0x00400L // Don't skip frames if falling behind
#define SMACKSIMULATE 0x00800L // Simulate the speed (call SmackSim first)
#define SMACKFILEHANDLE 0x01000L // Use when passing in a file handle
#define SMACKTRACK1 0x02000L // Play audio track 1
#define SMACKTRACK2 0x04000L // Play audio track 2
#define SMACKTRACK3 0x08000L // Play audio track 3
#define SMACKTRACK4 0x10000L // Play audio track 4
#define SMACKTRACK5 0x20000L // Play audio track 5
#define SMACKTRACK6 0x40000L // Play audio track 6
#define SMACKTRACK7 0x80000L // Play audio track 7
#define SMACKTRACKS (SMACKTRACK1|SMACKTRACK2|SMACKTRACK3|SMACKTRACK4|SMACKTRACK5|SMACKTRACK6|SMACKTRACK7)
#define SMACKBUFFERREVERSED 0x00000001
#define SMACKBUFFER555 0x80000000
#define SMACKBUFFER565 0xc0000000
#define SMACKBUFFER16 (SMACKBUFFER555|SMACKBUFFER565)
#define SMACKYINTERLACE 0x100000L // Force interleaving Y scaling
#define SMACKYDOUBLE 0x200000L // Force doubling Y scaling
#define SMACKYNONE (SMACKYINTERLACE|SMACKYDOUBLE) // Force normal Y scaling
#define SMACKFILEISSMK 0x2000000L // Internal flag for 16 to 32 bit thunking
#define SMACKAUTOEXTRA 0xffffffffL // NOT A FLAG! - Use as extrabuf param
//=======================================================================
#define SMACKSURFACEFAST 0
#define SMACKSURFACESLOW 1
#define SMACKSURFACEDIRECT 2
RADEXPFUNC Smack PTR4* RADEXPLINK SmackOpen(const char PTR4* name,u32 flags,u32 extrabuf);
#ifdef __RADMAC__
#include <files.h>
RADEXPFUNC Smack PTR4* RADEXPLINK SmackMacOpen(FSSpec* fsp,u32 flags,u32 extrabuf);
#endif
RADEXPFUNC u32 RADEXPLINK SmackDoFrame(Smack PTR4* smk);
RADEXPFUNC void RADEXPLINK SmackNextFrame(Smack PTR4* smk);
RADEXPFUNC u32 RADEXPLINK SmackWait(Smack PTR4* smk);
RADEXPFUNC void RADEXPLINK SmackClose(Smack PTR4* smk);
RADEXPFUNC void RADEXPLINK SmackVolumePan(Smack PTR4* smk, u32 trackflag,u32 volume,u32 pan);
RADEXPFUNC void RADEXPLINK SmackSummary(Smack PTR4* smk,SmackSum PTR4* sum);
RADEXPFUNC u32 RADEXPLINK SmackSoundInTrack(Smack PTR4* smk,u32 trackflags);
RADEXPFUNC u32 RADEXPLINK SmackSoundOnOff(Smack PTR4* smk,u32 on);
#ifndef __RADMAC__
RADEXPFUNC void RADEXPLINK SmackToScreen(Smack PTR4* smk,u32 left,u32 top,u32 BytePS,const u16 PTR4* WinTbl,void* SetBank,u32 Flags);
#endif
RADEXPFUNC void RADEXPLINK SmackToBuffer(Smack PTR4* smk,u32 left,u32 top,u32 Pitch,u32 destheight,const void PTR4* buf,u32 Flags);
RADEXPFUNC u32 RADEXPLINK SmackToBufferRect(Smack PTR4* smk, u32 SmackSurface);
RADEXPFUNC void RADEXPLINK SmackGoto(Smack PTR4* smk,u32 frame);
RADEXPFUNC void RADEXPLINK SmackColorRemapWithTrans(Smack PTR4* smk,const void PTR4* remappal,u32 numcolors,u32 paltype,u32 transindex);
#define SmackColorRemap(smk,remappal,numcolors,paltype) SmackColorRemapWithTrans(smk,remappal,numcolors,paltype,1000)
RADEXPFUNC void RADEXPLINK SmackColorTrans(Smack PTR4* smk,const void PTR4* trans);
RADEXPFUNC void RADEXPLINK SmackFrameRate(u32 forcerate);
RADEXPFUNC void RADEXPLINK SmackSimulate(u32 sim);
RADEXPFUNC u32 RADEXPLINK SmackGetTrackData(Smack PTR4* smk,void PTR4* dest,u32 trackflag);
RADEXPFUNC void RADEXPLINK SmackSoundCheck(void);
//======================================================================
// the functions for the new SmackBlit API
typedef struct _SMACKBLIT PTR4* HSMACKBLIT;
typedef struct _SMACKBLIT {
u32 Flags;
u8 PTR4* Palette;
u32 PalType;
u16 PTR4* SmoothTable;
u16 PTR4* Conv8to16Table;
u32 whichmode;
u32 palindex;
u32 t16index;
u32 smoothindex;
u32 smoothtype;
u32 firstpalette;
} SMACKBLIT;
#define SMACKBLIT1X 1
#define SMACKBLIT2X 2
#define SMACKBLIT2XSMOOTHING 4
#define SMACKBLIT2XINTERLACE 8
RADEXPFUNC HSMACKBLIT RADEXPLINK SmackBlitOpen(u32 flags);
RADEXPFUNC void RADEXPLINK SmackBlitSetPalette(HSMACKBLIT sblit, void PTR4* Palette,u32 PalType);
RADEXPFUNC u32 RADEXPLINK SmackBlitSetFlags(HSMACKBLIT sblit,u32 flags);
RADEXPFUNC void RADEXPLINK SmackBlit(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, void PTR4* src, u32 srcpitch, u32 srcx, u32 srcy, u32 srcw, u32 srch);
RADEXPFUNC void RADEXPLINK SmackBlitClear(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, u32 destw, u32 desth, s32 color);
RADEXPFUNC void RADEXPLINK SmackBlitClose(HSMACKBLIT sblit);
RADEXPFUNC void RADEXPLINK SmackBlitTrans(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, void PTR4* src, u32 srcpitch, u32 srcx, u32 srcy, u32 srcw, u32 srch, u32 trans);
RADEXPFUNC void RADEXPLINK SmackBlitMask(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, void PTR4* src, u32 srcpitch, u32 srcx, u32 srcy, u32 srcw, u32 srch, u32 trans,void PTR4* mask);
RADEXPFUNC void RADEXPLINK SmackBlitMerge(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, void PTR4* src, u32 srcpitch, u32 srcx, u32 srcy, u32 srcw, u32 srch, u32 trans,void PTR4* back);
RADEXPFUNC char PTR4* RADEXPLINK SmackBlitString(HSMACKBLIT sblit,char PTR4* dest);
#ifndef __RADMAC__
RADEXPFUNC u32 RADEXPLINK SmackUseMMX(u32 flag); //0=off, 1=on, 2=query current
#endif
//======================================================================
#ifdef __RADDOS__
#define SMACKSOUNDNONE -1
extern void* SmackTimerSetupAddr;
extern void* SmackTimerReadAddr;
extern void* SmackTimerDoneAddr;
typedef void RADEXPLINK (*SmackTimerSetupType)(void);
typedef u32 RADEXPLINK (*SmackTimerReadType)(void);
typedef void RADEXPLINK (*SmackTimerDoneType)(void);
#define SmackTimerSetup() ((SmackTimerSetupType)(SmackTimerSetupAddr))()
#define SmackTimerRead() ((SmackTimerReadType)(SmackTimerReadAddr))()
#define SmackTimerDone() ((SmackTimerDoneType)(SmackTimerDoneAddr))()
RADEXPFUNC u8 RADEXPLINK SmackSoundUseMSS(void* DigDriver);
#ifndef AIL_startup
#ifdef __SW_3R
extern s32 cdecl AIL_startup_reg(void);
#define AIL_startup AIL_startup_reg
#else
extern s32 cdecl AIL_startup_stack(void);
#define AIL_startup AIL_startup_stack
#endif
#endif
#define SmackSoundMSSLiteInit() SmackSoundMSSLiteInitWithStart(&AIL_startup);
RADEXPFUNC void RADEXPLINK SmackSoundMSSLiteInitWithStart(void* start);
RADEXPFUNC void RADEXPLINK SmackSoundMSSLiteDone(void);
RADEXPFUNC u8 RADEXPLINK SmackSoundUseSOS3r(u32 SOSDriver,u32 MaxTimerSpeed);
RADEXPFUNC u8 RADEXPLINK SmackSoundUseSOS3s(u32 SOSDriver,u32 MaxTimerSpeed);
RADEXPFUNC u8 RADEXPLINK SmackSoundUseSOS4r(u32 SOSDriver,u32 MaxTimerSpeed);
RADEXPFUNC u8 RADEXPLINK SmackSoundUseSOS4s(u32 SOSDriver,u32 MaxTimerSpeed);
#ifdef __SW_3R
#define SmackSoundUseSOS3 SmackSoundUseSOS3r
#define SmackSoundUseSOS4 SmackSoundUseSOS4r
#else
#define SmackSoundUseSOS3 SmackSoundUseSOS3s
#define SmackSoundUseSOS4 SmackSoundUseSOS4s
#endif
#else
#define SMACKRESRESET 0
#define SMACKRES640X400 1
#define SMACKRES640X480 2
#define SMACKRES800X600 3
#define SMACKRES1024X768 4
RADEXPFUNC u32 RADEXPLINK SmackSetSystemRes(u32 mode); // use SMACKRES* values
#define SMACKNOCUSTOMBLIT 128
#define SMACKSMOOTHBLIT 256
#define SMACKINTERLACEBLIT 512
#ifdef __RADMAC__
#include <windows.h>
#include <palettes.h>
#include <qdoffscreen.h>
#define SmackTimerSetup()
#define SmackTimerDone()
RADEXPFUNC u32 RADEXPLINK SmackTimerRead(void);
RADEXPFUNC s32 RADEXPLINK SmackGDSurfaceType( GDHandle gd );
#define SMACKAUTOBLIT 0
#define SMACKDIRECTBLIT 1
#define SMACKGWORLDBLIT 2
typedef struct SmackBufTag {
u32 Reversed;
u32 SurfaceType; // SMACKSURFACExxxxxx
u32 BlitType; // SMACKxxxxxBLIT
u32 Width;
u32 Height;
u32 Pitch;
u32 Zoomed;
u32 ZWidth;
u32 ZHeight;
u32 DispColors; // colors on screen
u32 MaxPalColors;
u32 PalColorsInUse;
u32 StartPalColor;
u32 EndPalColor;
void* Buffer;
void* Palette;
u32 PalType;
u32 SoftwareCursor;
WindowPtr wp;
GWorldPtr gwp;
CTabHandle cth;
PaletteHandle palh;
GDHandle gd;
u32 gdSurfaceType;
HSMACKBLIT sblit;
void * ScreenAddr;
u32 ScreenPitch;
s32 manyblits;
s32 PTR4* blitrects;
s32 PTR4* rectsptr;
s32 maxrects;
s32 numrects;
} SmackBuf;
#else
#ifdef __RADWIN__
#define INCLUDE_MMSYSTEM_H
#include "windows.h"
#include "windowsx.h"
#ifdef __RADNT__ // to combat WIN32_LEAN_AND_MEAN
#include "mmsystem.h"
RADEXPFUNC s32 RADEXPLINK SmackDDSurfaceType(void* lpDDS);
#endif
#define SMACKAUTOBLIT 0
#define SMACKFULL320X240BLIT 1
#define SMACKFULL320X200BLIT 2
#define SMACKFULL320X200DIRECTBLIT 3
#define SMACKSTANDARDBLIT 4
#define SMACKWINGBLIT 5
#define SMACKDIBSECTIONBLIT 5
#define WM_SMACKACTIVATE WM_USER+0x5678
typedef struct SmackBufTag {
u32 Reversed; // 1 if the buffer is upside down
u32 SurfaceType; // SMACKSURFACExxxx defines
u32 BlitType; // SMACKxxxxBLIT defines
u32 FullScreen; // 1 if full-screen
u32 Width;
u32 Height;
u32 Pitch;
u32 Zoomed;
u32 ZWidth;
u32 ZHeight;
u32 DispColors; // colors on the screen
u32 MaxPalColors; // total possible colors in palette (usually 256)
u32 PalColorsInUse; // Used colors in palette (usually 236)
u32 StartPalColor; // first usable color index (usually 10)
u32 EndPalColor; // last usable color index (usually 246)
RGBQUAD Palette[256];
u32 PalType;
u32 forceredraw; // force a complete redraw on next blit (for >8bit)
u32 didapalette; // force an invalidate on the next palette change
void PTR4* Buffer;
void PTR4* DIBRestore;
u32 OurBitmap;
u32 OrigBitmap;
u32 OurPalette;
u32 WinGDC;
u32 FullFocused;
u32 ParentHwnd;
u32 OldParWndProc;
u32 OldDispWndProc;
u32 DispHwnd;
u32 WinGBufHandle;
void PTR4* lpDD;
void PTR4* lpDDSP;
u32 DDSurfaceType;
HSMACKBLIT DDblit;
s32 ddSoftwarecur;
s32 didaddblit;
s32 lastwasdd;
RECT ddscreen;
s32 manyblits;
s32 PTR4* blitrects;
s32 PTR4* rectsptr;
s32 maxrects;
s32 numrects;
HDC lastdc;
} SmackBuf;
RADEXPFUNC void RADEXPLINK SmackGet(Smack PTR4* smk,void PTR4* dest);
RADEXPFUNC void RADEXPLINK SmackBufferGet( SmackBuf PTR4* sbuf, void PTR4* dest);
RADEXPFUNC u8 RADEXPLINK SmackSoundUseMSS(void PTR4* dd);
RADEXPFUNC u8 RADEXPLINK SmackSoundUseDirectSound(void PTR4* dd); // NULL=Create
RADEXPFUNC void RADEXPLINK SmackSoundSetDirectSoundHWND(HWND hw);
RADEXPFUNC u8 RADEXPLINK SmackSoundUseDW(u32 openfreq, u32 openbits, u32 openchans);
#define SmackTimerSetup()
#define SmackTimerDone()
#define SmackTimerRead timeGetTime
#endif
#endif
#ifdef __RADMAC__
RADEXPFUNC SmackBuf PTR4* RADEXPLINK SmackBufferOpen( WindowPtr wp, u32 BlitType, u32 width, u32 height, u32 ZoomW, u32 ZoomH );
RADEXPFUNC u32 RADEXPLINK SmackBufferBlit( SmackBuf PTR4* sbuf, s32 hwndx, s32 hwndy, s32 subx, s32 suby, s32 subw, s32 subh );
RADEXPFUNC void RADEXPLINK SmackBufferFromScreen( SmackBuf PTR4* destbuf, s32 x, s32 y);
RADEXPFUNC s32 RADEXPLINK SmackIsSoftwareCursor(GDHandle gd);
RADEXPFUNC s32 RADEXPLINK SmackCheckCursor(WindowPtr wp,s32 x,s32 y,s32 w,s32 h);
RADEXPFUNC void RADEXPLINK SmackRestoreCursor(s32 checkcount);
#else
RADEXPFUNC SmackBuf PTR4* RADEXPLINK SmackBufferOpen( HWND wnd, u32 BlitType, u32 width, u32 height, u32 ZoomW, u32 ZoomH );
RADEXPFUNC u32 RADEXPLINK SmackBufferBlit( SmackBuf PTR4* sbuf, HDC dc, s32 hwndx, s32 hwndy, s32 subx, s32 suby, s32 subw, s32 subh );
RADEXPFUNC void RADEXPLINK SmackBufferFromScreen( SmackBuf PTR4* destbuf, HWND hw, s32 x, s32 y);
RADEXPFUNC s32 RADEXPLINK SmackIsSoftwareCursor(void* lpDDSP,HCURSOR cur);
RADEXPFUNC s32 RADEXPLINK SmackCheckCursor(HWND wnd,s32 x,s32 y,s32 w,s32 h);
RADEXPFUNC void RADEXPLINK SmackRestoreCursor(s32 checkcount);
#endif
RADEXPFUNC void RADEXPLINK SmackBufferStartMultipleBlits( SmackBuf PTR4* sbuf );
RADEXPFUNC void RADEXPLINK SmackBufferEndMultipleBlits( SmackBuf PTR4* sbuf );
RADEXPFUNC char PTR4* RADEXPLINK SmackBufferString(SmackBuf PTR4* sb,char PTR4* dest);
RADEXPFUNC void RADEXPLINK SmackBufferNewPalette( SmackBuf PTR4* sbuf, const void PTR4* pal, u32 paltype );
RADEXPFUNC u32 RADEXPLINK SmackBufferSetPalette( SmackBuf PTR4* sbuf );
RADEXPFUNC void RADEXPLINK SmackBufferClose( SmackBuf PTR4* sbuf );
RADEXPFUNC void RADEXPLINK SmackBufferClear( SmackBuf PTR4* destbuf, u32 color);
RADEXPFUNC void RADEXPLINK SmackBufferToBuffer( SmackBuf PTR4* destbuf, s32 destx, s32 desty, const SmackBuf PTR4* sourcebuf,s32 sourcex,s32 sourcey,s32 sourcew,s32 sourceh);
RADEXPFUNC void RADEXPLINK SmackBufferToBufferTrans( SmackBuf PTR4* destbuf, s32 destx, s32 desty, const SmackBuf PTR4* sourcebuf,s32 sourcex,s32 sourcey,s32 sourcew,s32 sourceh,u32 TransColor);
RADEXPFUNC void RADEXPLINK SmackBufferToBufferMask( SmackBuf PTR4* destbuf, s32 destx, s32 desty, const SmackBuf PTR4* sourcebuf,s32 sourcex,s32 sourcey,s32 sourcew,s32 sourceh,u32 TransColor,const SmackBuf PTR4* maskbuf);
RADEXPFUNC void RADEXPLINK SmackBufferToBufferMerge( SmackBuf PTR4* destbuf, s32 destx, s32 desty, const SmackBuf PTR4* sourcebuf,s32 sourcex,s32 sourcey,s32 sourcew,s32 sourceh,u32 TransColor,const SmackBuf PTR4* mergebuf);
RADEXPFUNC void RADEXPLINK SmackBufferCopyPalette( SmackBuf PTR4* destbuf, SmackBuf PTR4* sourcebuf, u32 remap);
RADEXPFUNC u32 RADEXPLINK SmackBufferFocused( SmackBuf PTR4* sbuf);
#endif
RADDEFEND
#endif
#endif
+405
View File
@@ -0,0 +1,405 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include <string.h>
#include "MemMan.h"
#include "FileMan.h"
#include "imgfmt.h"
#include "himage.h"
#include "Types.h"
#include "Debug.h"
#include "WCheck.h"
#endif
BOOLEAN STCILoadRGB( HIMAGE hImage, UINT16 fContents, HWFILE hFile, STCIHeader * pHeader );
BOOLEAN STCILoadIndexed( HIMAGE hImage, UINT16 fContents, HWFILE hFile, STCIHeader * pHeader );
BOOLEAN STCISetPalette( PTR pSTCIPalette, HIMAGE hImage );
BOOLEAN LoadSTCIFileToImage( HIMAGE hImage, UINT16 fContents )
{
HWFILE hFile;
STCIHeader Header;
UINT32 uiBytesRead;
image_type TempImage;
// Check that hImage is valid, and that the file in question exists
Assert( hImage != NULL );
TempImage = *hImage;
CHECKF( FileExists( TempImage.ImageFile ) );
// Open the file and read the header
hFile = FileOpen( TempImage.ImageFile, FILE_ACCESS_READ, FALSE );
CHECKF( hFile );
if (!FileRead( hFile, &Header, STCI_HEADER_SIZE, &uiBytesRead ) || uiBytesRead != STCI_HEADER_SIZE || memcmp( Header.cID, STCI_ID_STRING, STCI_ID_LEN ) != 0 )
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem reading STCI header." );
FileClose( hFile );
return( FALSE );
}
// Determine from the header the data stored in the file. and run the appropriate loader
if (Header.fFlags & STCI_RGB)
{
if( !STCILoadRGB( &TempImage, fContents, hFile, &Header ) )
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem loading RGB image." );
FileClose( hFile );
return( FALSE );
}
}
else if (Header.fFlags & STCI_INDEXED)
{
if( !STCILoadIndexed( &TempImage, fContents, hFile, &Header ) )
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem loading palettized image." );
FileClose( hFile );
return( FALSE );
}
}
else
{ // unsupported type of data, or the right flags weren't set!
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Unknown data organization in STCI file." );
FileClose( hFile );
return( FALSE );
}
// Requested data loaded successfully.
FileClose( hFile );
// Set some more flags in the temporary image structure, copy it so that hImage points
// to it, and return.
if (Header.fFlags & STCI_ZLIB_COMPRESSED)
{
TempImage.fFlags |= IMAGE_COMPRESSED;
}
TempImage.usWidth = Header.usWidth;
TempImage.usHeight = Header.usHeight;
TempImage.ubBitDepth = Header.ubDepth;
*hImage = TempImage;
return( TRUE );
}
BOOLEAN STCILoadRGB( HIMAGE hImage, UINT16 fContents, HWFILE hFile, STCIHeader * pHeader )
{
UINT32 uiBytesRead;
if (fContents & IMAGE_PALETTE && !(fContents & IMAGE_ALLIMAGEDATA))
{ // RGB doesn't have a palette!
return( FALSE );
}
if (fContents & IMAGE_BITMAPDATA)
{
// Allocate memory for the image data and read it in
hImage->pImageData = MemAlloc( pHeader->uiStoredSize );
if (hImage->pImageData == NULL)
{
return( FALSE );
}
else if (!FileRead( hFile, hImage->pImageData, pHeader->uiStoredSize, &uiBytesRead ) || uiBytesRead != pHeader->uiStoredSize)
{
MemFree( hImage->pImageData );
return( FALSE );
}
hImage->fFlags |= IMAGE_BITMAPDATA;
if( pHeader->ubDepth == 16)
{
// ASSUMPTION: file data is 565 R,G,B
if (gusRedMask != (UINT16) pHeader->RGB.uiRedMask || gusGreenMask != (UINT16) pHeader->RGB.uiGreenMask || gusBlueMask != (UINT16) pHeader->RGB.uiBlueMask )
{
// colour distribution of the file is different from hardware! We have to change it!
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Converting to current RGB distribution!" );
// Convert the image to the current hardware's specifications
if (gusRedMask > gusGreenMask && gusGreenMask > gusBlueMask)
{
// hardware wants RGB!
if (gusRedMask == 0x7C00 && gusGreenMask == 0x03E0 && gusBlueMask == 0x001F)
{ // hardware is 555
ConvertRGBDistribution565To555( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
return( TRUE );
}
else if (gusRedMask == 0xFC00 && gusGreenMask == 0x03E0 && gusBlueMask == 0x001F)
{
ConvertRGBDistribution565To655( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
return( TRUE );
}
else if (gusRedMask == 0xF800 && gusGreenMask == 0x07C0 && gusBlueMask == 0x003F)
{
ConvertRGBDistribution565To556( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
return( TRUE );
}
else
{
// take the long route
ConvertRGBDistribution565ToAny( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
return( TRUE );
}
}
else
{
// hardware distribution is not R-G-B so we have to take the long route!
ConvertRGBDistribution565ToAny( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
return( TRUE );
}
}
}
}
#ifdef JA2
return( TRUE );
#else
// Anything else is an ERROR! --DB
return(FALSE);
#endif
}
BOOLEAN STCILoadIndexed( HIMAGE hImage, UINT16 fContents, HWFILE hFile, STCIHeader * pHeader )
{
UINT32 uiFileSectionSize;
UINT32 uiBytesRead;
PTR pSTCIPalette;
if (fContents & IMAGE_PALETTE)
{ // Allocate memory for reading in the palette
if (pHeader->Indexed.uiNumberOfColours != 256)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Palettized image has bad palette size." );
return( FALSE );
}
uiFileSectionSize = pHeader->Indexed.uiNumberOfColours * STCI_PALETTE_ELEMENT_SIZE;
pSTCIPalette = MemAlloc( uiFileSectionSize );
if (pSTCIPalette == NULL)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Out of memory!" );
FileClose( hFile );
return( FALSE );
}
// ATE: Memset: Jan 16/99
memset( pSTCIPalette, 0, uiFileSectionSize );
// Read in the palette
if (!FileRead( hFile, pSTCIPalette, uiFileSectionSize, &uiBytesRead ) || uiBytesRead != uiFileSectionSize)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem loading palette!" );
FileClose( hFile );
MemFree( pSTCIPalette );
return( FALSE );
}
else if (!STCISetPalette( pSTCIPalette, hImage ))
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem setting hImage-format palette!" );
FileClose( hFile );
MemFree( pSTCIPalette );
return( FALSE );
}
hImage->fFlags |= IMAGE_PALETTE;
// Free the temporary buffer
MemFree( pSTCIPalette );
}
else if (fContents & (IMAGE_BITMAPDATA | IMAGE_APPDATA))
{ // seek past the palette
uiFileSectionSize = pHeader->Indexed.uiNumberOfColours * STCI_PALETTE_ELEMENT_SIZE;
if (FileSeek( hFile, uiFileSectionSize, FILE_SEEK_FROM_CURRENT) == FALSE)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem seeking past palette!" );
FileClose( hFile );
return( FALSE );
}
}
if (fContents & IMAGE_BITMAPDATA)
{
if (pHeader->fFlags & STCI_ETRLE_COMPRESSED)
{
// load data for the subimage (object) structures
Assert( sizeof( ETRLEObject ) == STCI_SUBIMAGE_SIZE );
hImage->usNumberOfObjects = pHeader->Indexed.usNumberOfSubImages;
uiFileSectionSize = hImage->usNumberOfObjects * STCI_SUBIMAGE_SIZE;
hImage->pETRLEObject = (ETRLEObject *) MemAlloc( uiFileSectionSize );
if (hImage->pETRLEObject == NULL)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Out of memory!" );
FileClose( hFile );
if (fContents & IMAGE_PALETTE)
{
MemFree( hImage->pPalette );
}
return( FALSE );
}
if (!FileRead( hFile, hImage->pETRLEObject, uiFileSectionSize, &uiBytesRead ) || uiBytesRead != uiFileSectionSize)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Error loading subimage structures!" );
FileClose( hFile );
if (fContents & IMAGE_PALETTE)
{
MemFree( hImage->pPalette );
}
MemFree( hImage->pETRLEObject );
return( FALSE );
}
hImage->uiSizePixData = pHeader->uiStoredSize;
hImage->fFlags |= IMAGE_TRLECOMPRESSED;
}
// allocate memory for and read in the image data
hImage->pImageData = MemAlloc( pHeader->uiStoredSize );
if (hImage->pImageData == NULL)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Out of memory!" );
FileClose( hFile );
if (fContents & IMAGE_PALETTE)
{
MemFree( hImage->pPalette );
}
if (hImage->usNumberOfObjects > 0)
{
MemFree( hImage->pETRLEObject );
}
return( FALSE );
}
else if (!FileRead( hFile, hImage->pImageData, pHeader->uiStoredSize, &uiBytesRead ) || uiBytesRead != pHeader->uiStoredSize)
{ // Problem reading in the image data!
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Error loading image data!" );
FileClose( hFile );
MemFree( hImage->pImageData );
if (fContents & IMAGE_PALETTE)
{
MemFree( hImage->pPalette );
}
if (hImage->usNumberOfObjects > 0)
{
MemFree( hImage->pETRLEObject );
}
return( FALSE );
}
hImage->fFlags |= IMAGE_BITMAPDATA;
}
else if (fContents & IMAGE_APPDATA) // then there's a point in seeking ahead
{
if (FileSeek( hFile, pHeader->uiStoredSize, FILE_SEEK_FROM_CURRENT) == FALSE)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem seeking past image data!" );
FileClose( hFile );
return( FALSE );
}
}
if (fContents & IMAGE_APPDATA && pHeader->uiAppDataSize > 0)
{
// load application-specific data
hImage->pAppData = (UINT8 *) MemAlloc( pHeader->uiAppDataSize );
if (hImage->pAppData == NULL)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Out of memory!" );
FileClose( hFile );
MemFree( hImage->pAppData );
if (fContents & IMAGE_PALETTE)
{
MemFree( hImage->pPalette );
}
if (fContents & IMAGE_BITMAPDATA)
{
MemFree( hImage->pImageData );
}
if (hImage->usNumberOfObjects > 0)
{
MemFree( hImage->pETRLEObject );
}
return( FALSE );
}
if (!FileRead( hFile, hImage->pAppData, pHeader->uiAppDataSize, &uiBytesRead ) || uiBytesRead != pHeader->uiAppDataSize)
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Error loading application-specific data!" );
FileClose( hFile );
MemFree( hImage->pAppData );
if (fContents & IMAGE_PALETTE)
{
MemFree( hImage->pPalette );
}
if (fContents & IMAGE_BITMAPDATA)
{
MemFree( hImage->pImageData );
}
if (hImage->usNumberOfObjects > 0)
{
MemFree( hImage->pETRLEObject );
}
return( FALSE );
}
hImage->uiAppDataSize = pHeader->uiAppDataSize;;
hImage->fFlags |= IMAGE_APPDATA;
}
else
{
hImage->pAppData = NULL;
hImage->uiAppDataSize = 0;
}
return( TRUE );
}
BOOLEAN STCISetPalette( PTR pSTCIPalette, HIMAGE hImage )
{
UINT16 usIndex;
STCIPaletteElement * pubPalette;
pubPalette = (STCIPaletteElement *) pSTCIPalette;
// Allocate memory for palette
hImage->pPalette = (SGPPaletteEntry *) MemAlloc( sizeof( SGPPaletteEntry ) * 256 );
memset( hImage->pPalette, 0, ( sizeof( SGPPaletteEntry ) * 256 ) );
if ( hImage->pPalette == NULL )
{
return( FALSE );
}
// Initialize the proper palette entries
for (usIndex = 0; usIndex < 256; usIndex++)
{
hImage->pPalette[ usIndex ].peRed = pubPalette->ubRed;
hImage->pPalette[ usIndex ].peGreen = pubPalette->ubGreen;
hImage->pPalette[ usIndex ].peBlue = pubPalette->ubBlue;
hImage->pPalette[ usIndex ].peFlags = 0;
pubPalette ++;
}
return TRUE;
}
BOOLEAN IsSTCIETRLEFile( CHAR8 * ImageFile )
{
HWFILE hFile;
STCIHeader Header;
UINT32 uiBytesRead;
CHECKF( FileExists( ImageFile ) );
// Open the file and read the header
hFile = FileOpen( ImageFile, FILE_ACCESS_READ, FALSE );
CHECKF( hFile );
if (!FileRead( hFile, &Header, STCI_HEADER_SIZE, &uiBytesRead ) || uiBytesRead != STCI_HEADER_SIZE || memcmp( Header.cID, STCI_ID_STRING, STCI_ID_LEN ) != 0 )
{
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem reading STCI header." );
FileClose( hFile );
return( FALSE );
}
FileClose( hFile );
if (Header.fFlags & STCI_ETRLE_COMPRESSED)
{
return( TRUE );
}
else
{
return( FALSE );
}
}
+5
View File
@@ -0,0 +1,5 @@
#include "types.h"
BOOLEAN LoadSTCIFileToImage( HIMAGE hImage, UINT16 fContents );
BOOLEAN IsSTCIETRLEFile( CHAR8 * ImageFile );
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,650 @@
# Microsoft Developer Studio Project File - Name="Standard Gaming Platform" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=Standard Gaming Platform - Win32 Debug Demo
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Standard Gaming Platform.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Standard Gaming Platform.mak" CFG="Standard Gaming Platform - Win32 Debug Demo"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Standard Gaming Platform - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "Standard Gaming Platform - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE "Standard Gaming Platform - Win32 Release with Debug Info" (based on "Win32 (x86) Static Library")
!MESSAGE "Standard Gaming Platform - Win32 Bounds Checker" (based on "Win32 (x86) Static Library")
!MESSAGE "Standard Gaming Platform - Win32 Debug Demo" (based on "Win32 (x86) Static Library")
!MESSAGE "Standard Gaming Platform - Win32 Release Demo" (based on "Win32 (x86) Static Library")
!MESSAGE "Standard Gaming Platform - Win32 Demo Release with Debug Info" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/Jagged Alliance 2/Development/Programming/Jagged Alliance 2/Build", AVAAAAAA"
# PROP Scc_LocalPath "..\ja2\build"
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Standard Gaming Platform - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir "."
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Target_Dir "."
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\\" /I "..\TileEngine" /I "..\Tactical" /I "..\Utils" /I "..\strategic" /I ".\\" /D "NO_ZLIB" /D "JA2_PRECOMPILED_HEADERS" /D "NO_ZLIB_COMPRESSION" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "JA2" /D "XML_STATIC" /D "CINTERFACE" /FR /YX"JA2 SGP ALL.H" /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir "."
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Target_Dir "."
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\Build" /I "..\TileEngine" /I "..\Tactical" /I "..\Utils" /I "..\strategic" /I "..\\" /I ".\\" /D "JA2_PRECOMPILED_HEADERS" /D "NO_ZLIB_COMPRESSION" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "JA2" /D "_VTUNE_PROFILING" /D "XML_STATIC" /D "CINTERFACE" /FR /YX"JA2 SGP ALL.H" /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Release with Debug Info"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release with Debug Info"
# PROP BASE Intermediate_Dir "Release with Debug Info"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release with Debug Info"
# PROP Intermediate_Dir "Release with Debug Info"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "\ja2\build" /I "\ja2\build\TileEngine" /I "\ja2\build\Tactical" /I "\ja2\build\Utils" /I "\ja2\build\strategic" /D "NDEBUG" /D "JA2" /D "WIN32" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /Zi /O2 /I "..\\" /I "..\TileEngine" /I "..\Tactical" /I "..\Utils" /I "..\strategic" /I ".\\" /D "NDEBUG" /D "RELEASE_WITH_DEBUG_INFO" /D "NO_ZLIB" /D "WIN32" /D "_WINDOWS" /D "JA2" /D "JA2_PRECOMPILED_HEADERS" /D "NO_ZLIB_COMPRESSION" /D "_VTUNE_PROFILING" /D "XML_STATIC" /D "CINTERFACE" /YX"JA2 SGP ALL.H" /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Bounds Checker"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Standar0"
# PROP BASE Intermediate_Dir "Standar0"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Standar0"
# PROP Intermediate_Dir "Standar0"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /GX /Z7 /Od /I "\ja2\build" /I "\ja2\build\TileEngine" /I "\ja2\build\Tactical" /I "\ja2\build\Utils" /I "\ja2\build\strategic" /D "_DEBUG" /D "JA2" /D "WIN32" /D "_WINDOWS" /FR /YX /FD /c
# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "\ja2\build" /I "\ja2\build\TileEngine" /I "\ja2\build\Tactical" /I "\ja2\build\Utils" /I "\ja2\build\strategic" /D "_DEBUG" /D "BOUNDS_CHECKER" /D "NO_ZLIB" /D "WIN32" /D "_WINDOWS" /D "JA2" /D "JA2_PRECOMPILED_HEADERS" /D "NO_ZLIB_COMPRESSION" /D "_VTUNE_PROFILING" /FR /YX"JA2 SGP ALL.H" /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Debug Demo"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Standard"
# PROP BASE Intermediate_Dir "Standard"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Standard"
# PROP Intermediate_Dir "Standard"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /GX /Z7 /Od /I "\ja2\build" /I "\ja2\build\TileEngine" /I "\ja2\build\Tactical" /I "\ja2\build\Utils" /I "\ja2\build\strategic" /D "_DEBUG" /D "JA2" /D "WIN32" /D "_WINDOWS" /FR /YX /FD /c
# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "\ja2\build" /I "\ja2\build\TileEngine" /I "\ja2\build\Tactical" /I "\ja2\build\Utils" /I "\ja2\build\strategic" /D "_DEBUG" /D "JA2DEMO" /D "NO_ZLIB" /D "WIN32" /D "_WINDOWS" /D "JA2" /D "JA2_PRECOMPILED_HEADERS" /D "NO_ZLIB_COMPRESSION" /FR /YX"JA2 SGP ALL.H" /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Release Demo"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Standar1"
# PROP BASE Intermediate_Dir "Standar1"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Standar1"
# PROP Intermediate_Dir "Standar1"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W4 /GX /Zi /O2 /I "\ja2\build" /I "\ja2\build\TileEngine" /I "\ja2\build\Tactical" /I "\ja2\build\Utils" /I "\ja2\build\strategic" /D "NDEBUG" /D "JA2" /D "WIN32" /D "_WINDOWS" /D "RELEASE_WITH_DEBUG_INFO" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /Zi /O2 /I "\ja2\build" /I "\ja2\build\TileEngine" /I "\ja2\build\Tactical" /I "\ja2\build\Utils" /I "\ja2\build\strategic" /D "RELEASE_WITH_DEBUG_INFO" /D "NDEBUG" /D "JA2DEMO" /D "NO_ZLIB" /D "WIN32" /D "_WINDOWS" /D "JA2" /D "JA2_PRECOMPILED_HEADERS" /D "NO_ZLIB_COMPRESSION" /YX"JA2 SGP ALL.H" /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Demo Release with Debug Info"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Standar2"
# PROP BASE Intermediate_Dir "Standar2"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Standar2"
# PROP Intermediate_Dir "Standar2"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W4 /GX /Zi /O2 /I "\ja2\build" /I "\ja2\build\TileEngine" /I "\ja2\build\Tactical" /I "\ja2\build\Utils" /I "\ja2\build\strategic" /D "NDEBUG" /D "JA2" /D "WIN32" /D "_WINDOWS" /D "RELEASE_WITH_DEBUG_INFO" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /Zi /O2 /I "..\\" /I "..\TileEngine" /I "..\Tactical" /I "..\Utils" /I "..\strategic" /I ".\\" /D "RELEASE_WITH_DEBUG_INFO" /D "NDEBUG" /D "JA2DEMO" /D "NO_ZLIB" /D "WIN32" /D "_WINDOWS" /D "JA2" /D "JA2_PRECOMPILED_HEADERS" /D "NO_ZLIB_COMPRESSION" /D "XML_STATIC" /D "CINTERFACE" /YX"JA2 SGP ALL.H" /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "Standard Gaming Platform - Win32 Release"
# Name "Standard Gaming Platform - Win32 Debug"
# Name "Standard Gaming Platform - Win32 Release with Debug Info"
# Name "Standard Gaming Platform - Win32 Bounds Checker"
# Name "Standard Gaming Platform - Win32 Debug Demo"
# Name "Standard Gaming Platform - Win32 Release Demo"
# Name "Standard Gaming Platform - Win32 Demo Release with Debug Info"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90"
# Begin Source File
SOURCE=".\Button Sound Control.cpp"
# End Source File
# Begin Source File
SOURCE=".\Button System.cpp"
# End Source File
# Begin Source File
SOURCE=".\Container.cpp"
# End Source File
# Begin Source File
SOURCE=".\Cursor Control.cpp"
# End Source File
# Begin Source File
SOURCE=".\DbMan.cpp"
# End Source File
# Begin Source File
SOURCE=".\DEBUG.cpp"
!IF "$(CFG)" == "Standard Gaming Platform - Win32 Release"
# ADD CPP /D "_DEBUG"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Debug"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Release with Debug Info"
# ADD BASE CPP /D "_DEBUG"
# ADD CPP /D "_DEBUG"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Bounds Checker"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Debug Demo"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Release Demo"
# ADD BASE CPP /D "_DEBUG"
# ADD CPP /D "_DEBUG"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Demo Release with Debug Info"
# ADD BASE CPP /D "_DEBUG"
# ADD CPP /D "_DEBUG"
!ENDIF
# End Source File
# Begin Source File
SOURCE=".\DirectDraw Calls.cpp"
# End Source File
# Begin Source File
SOURCE=".\DirectX Common.cpp"
# End Source File
# Begin Source File
SOURCE=".\English.cpp"
# End Source File
# Begin Source File
SOURCE=.\ExceptionHandling.cpp
# End Source File
# Begin Source File
SOURCE=.\FileCat.cpp
# End Source File
# Begin Source File
SOURCE=".\FileMan.cpp"
# End Source File
# Begin Source File
SOURCE=".\Font.cpp"
# End Source File
# Begin Source File
SOURCE=".\himage.cpp"
# End Source File
# Begin Source File
SOURCE=".\impTGA.cpp"
# End Source File
# Begin Source File
SOURCE=".\input.cpp"
# End Source File
# Begin Source File
SOURCE=".\Install.cpp"
# End Source File
# Begin Source File
SOURCE=".\LibraryDataBase.cpp"
# End Source File
# Begin Source File
SOURCE=".\line.cpp"
# End Source File
# Begin Source File
SOURCE=".\MemMan.cpp"
!IF "$(CFG)" == "Standard Gaming Platform - Win32 Release"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Debug"
# ADD CPP /D "_MEMMAN_DEBUG"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Release with Debug Info"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Bounds Checker"
# ADD BASE CPP /D "_MEMMAN_DEBUG"
# ADD CPP /D "_MEMMAN_DEBUG"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Debug Demo"
# ADD BASE CPP /D "_MEMMAN_DEBUG"
# ADD CPP /D "_MEMMAN_DEBUG"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Release Demo"
!ELSEIF "$(CFG)" == "Standard Gaming Platform - Win32 Demo Release with Debug Info"
!ENDIF
# End Source File
# Begin Source File
SOURCE=".\mousesystem.cpp"
# End Source File
# Begin Source File
SOURCE=".\Mutex Manager.cpp"
# End Source File
# Begin Source File
SOURCE=".\PCX.cpp"
# End Source File
# Begin Source File
SOURCE=".\Random.cpp"
# End Source File
# Begin Source File
SOURCE=.\readdir.cpp
# End Source File
# Begin Source File
SOURCE=".\RegInst.cpp"
# End Source File
# Begin Source File
SOURCE=".\sgp.cpp"
# End Source File
# Begin Source File
SOURCE=".\shading.cpp"
# End Source File
# Begin Source File
SOURCE=".\soundman.cpp"
# End Source File
# Begin Source File
SOURCE=".\STCI.cpp"
# End Source File
# Begin Source File
SOURCE=.\stringicmp.cpp
# End Source File
# Begin Source File
SOURCE=".\timer.cpp"
# End Source File
# Begin Source File
SOURCE=".\video.cpp"
# End Source File
# Begin Source File
SOURCE=".\vobject.cpp"
# End Source File
# Begin Source File
SOURCE=".\vobject_blitters.cpp"
# End Source File
# Begin Source File
SOURCE=".\vsurface.cpp"
# End Source File
# Begin Source File
SOURCE=.\WinFont.cpp
# End Source File
# Begin Source File
SOURCE=".\ddraw.lib"
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
# Begin Source File
SOURCE=".\Button System.h"
# End Source File
# Begin Source File
SOURCE=".\container.h"
# End Source File
# Begin Source File
SOURCE=".\Cursor Control.h"
# End Source File
# Begin Source File
SOURCE=".\DbMan.h"
# End Source File
# Begin Source File
SOURCE=".\Debug.h"
# End Source File
# Begin Source File
SOURCE=".\DirectDraw Calls.h"
# End Source File
# Begin Source File
SOURCE=".\DirectX Common.h"
# End Source File
# Begin Source File
SOURCE=".\english.h"
# End Source File
# Begin Source File
SOURCE=.\ExceptionHandling.h
# End Source File
# Begin Source File
SOURCE=.\FileCat.h
# End Source File
# Begin Source File
SOURCE=".\FileMan.h"
# End Source File
# Begin Source File
SOURCE="..\Utils\Font Control.h"
# End Source File
# Begin Source File
SOURCE=".\font.h"
# End Source File
# Begin Source File
SOURCE=".\gameloop.h"
# End Source File
# Begin Source File
SOURCE=".\himage.h"
# End Source File
# Begin Source File
SOURCE=".\imgfmt.h"
# End Source File
# Begin Source File
SOURCE=".\impTGA.h"
# End Source File
# Begin Source File
SOURCE=".\Input.h"
# End Source File
# Begin Source File
SOURCE=".\Install.h"
# End Source File
# Begin Source File
SOURCE=".\JA2 SGP ALL.H"
# End Source File
# Begin Source File
SOURCE=..\jascreens.h
# End Source File
# Begin Source File
SOURCE=".\LibraryDataBase.h"
# End Source File
# Begin Source File
SOURCE=".\line.h"
# End Source File
# Begin Source File
SOURCE=..\local.h
# End Source File
# Begin Source File
SOURCE=".\MemMan.h"
# End Source File
# Begin Source File
SOURCE=".\mousesystem.h"
# End Source File
# Begin Source File
SOURCE=".\mousesystem_macros.h"
# End Source File
# Begin Source File
SOURCE=".\Mutex Manager.h"
# End Source File
# Begin Source File
SOURCE=".\pcx.h"
# End Source File
# Begin Source File
SOURCE=".\random.h"
# End Source File
# Begin Source File
SOURCE=.\readdir.h
# End Source File
# Begin Source File
SOURCE=".\RegInst.h"
# End Source File
# Begin Source File
SOURCE="..\TileEngine\render dirty.h"
# End Source File
# Begin Source File
SOURCE=..\screenids.h
# End Source File
# Begin Source File
SOURCE=..\SCREENS.H
# End Source File
# Begin Source File
SOURCE=".\sgp.h"
# End Source File
# Begin Source File
SOURCE=".\shading.h"
# End Source File
# Begin Source File
SOURCE=".\soundman.h"
# End Source File
# Begin Source File
SOURCE=".\STCI.h"
# End Source File
# Begin Source File
SOURCE=.\stringicmp.h
# End Source File
# Begin Source File
SOURCE=".\timer.h"
# End Source File
# Begin Source File
SOURCE=".\TopicIDs.h"
# End Source File
# Begin Source File
SOURCE=".\TopicOps.h"
# End Source File
# Begin Source File
SOURCE=".\trle.h"
# End Source File
# Begin Source File
SOURCE=.\Types.h
# End Source File
# Begin Source File
SOURCE=".\Video.h"
# End Source File
# Begin Source File
SOURCE=".\video_private.h"
# End Source File
# Begin Source File
SOURCE=".\vobject.h"
# End Source File
# Begin Source File
SOURCE=".\vobject_blitters.h"
# End Source File
# Begin Source File
SOURCE=".\vobject_private.h"
# End Source File
# Begin Source File
SOURCE=".\vsurface.h"
# End Source File
# Begin Source File
SOURCE=".\vsurface_private.h"
# End Source File
# Begin Source File
SOURCE=".\WCheck.h"
# End Source File
# Begin Source File
SOURCE=".\Winbart97.h"
# End Source File
# Begin Source File
SOURCE=.\WinFont.h
# End Source File
# Begin Source File
SOURCE=".\WizShare.h"
# End Source File
# Begin Source File
SOURCE=".\ZCONF.H"
# End Source File
# End Group
# End Target
# End Project
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+66
View File
@@ -0,0 +1,66 @@
#ifndef _TOPICIDS_H
#define _TOPICIDS_H
// YOU MUST KEEP THIS VARIABLE UP TO DATE !!!!
#define NUM_TOPIC_IDS 23
/* #define TOPIC_MEMORY_MANAGER 0
#define TOPIC_FILE_MANAGER 1
#define TOPIC_DATABASE_MANAGER 2
#define TOPIC_GAME 3
#define TOPIC_SGP 4
#define TOPIC_VIDEO 5
#define TOPIC_INPUT 6
#define TOPIC_STACK_CONTAINERS 7
#define TOPIC_LIST_CONTAINERS 8
#define TOPIC_QUEUE_CONTAINERS 9
#define TOPIC_PRILIST_CONTAINERS 10
#define TOPIC_HIMAGE 11
#define TOPIC_ORDLIST_CONTAINERS 12
#define TOPIC_3DENGINE 13
#define TOPIC_VIDEOOBJECT 14
#define TOPIC_FONT_HANDLER 15
#define TOPIC_VIDEOSURFACE 16
#define TOPIC_MOUSE_SYSTEM 17
#define TOPIC_BUTTON_HANDLER 18
#define TOPIC_MUTEX 19
#define TOPIC_JA2 20
#define TOPIC_BLIT_QUEUE 21
#define TOPIC_JA2OPPLIST 22
*/
#ifdef __cplusplus
extern "C" {
#endif
extern UINT16 TOPIC_MEMORY_MANAGER;
extern UINT16 TOPIC_FILE_MANAGER;
extern UINT16 TOPIC_DATABASE_MANAGER;
extern UINT16 TOPIC_GAME;
extern UINT16 TOPIC_SGP;
extern UINT16 TOPIC_VIDEO;
extern UINT16 TOPIC_INPUT;
extern UINT16 TOPIC_STACK_CONTAINERS;
extern UINT16 TOPIC_LIST_CONTAINERS;
extern UINT16 TOPIC_QUEUE_CONTAINERS;
extern UINT16 TOPIC_PRILIST_CONTAINERS;
extern UINT16 TOPIC_HIMAGE;
extern UINT16 TOPIC_ORDLIST_CONTAINERS;
extern UINT16 TOPIC_3DENGINE;
extern UINT16 TOPIC_VIDEOOBJECT;
extern UINT16 TOPIC_FONT_HANDLER;
extern UINT16 TOPIC_VIDEOSURFACE;
extern UINT16 TOPIC_MOUSE_SYSTEM;
extern UINT16 TOPIC_BUTTON_HANDLER;
extern UINT16 TOPIC_MUTEX;
extern UINT16 TOPIC_JA2;
extern UINT16 TOPIC_BLIT_QUEUE;
extern UINT16 TOPIC_JA2OPPLIST;
extern UINT16 TOPIC_JA2AI;
#ifdef __cplusplus
}
#endif
#endif // NUM_TOPICS_IDS
+25
View File
@@ -0,0 +1,25 @@
#ifndef _TopicOps_h
#define _TopicOps_h
// debug levels
#define DBG_LEVEL_0 0 // for registering and unregistering topics only
#define DBG_LEVEL_1 1 // for basic stuff
#define DBG_LEVEL_2 2 // for ordinary, I usually want to see them, messages
#define DBG_LEVEL_3 3 // nitty gritty detail
// from client
#define TOPIC_REGISTER 0
#define TOPIC_UNREGISTER 1
#define TOPIC_MESSAGE 2
#define CLIENT_REGISTER 3
#define CLIENT_SHUTDOWN 4
// from server
#define SYSTEM_SHUTDOWN 0
#define MODULE_RESET 1
#define SET_DEBUG_LEVEL 2
#endif
+134
View File
@@ -0,0 +1,134 @@
#ifndef __TYPES_
#define __TYPES_
#ifndef _SIRTECH_TYPES_
#define _SIRTECH_TYPES_
#ifdef JA2
#ifdef RELEASE_WITH_DEBUG_INFO
//For JA2 Release with debug info build, disable these warnigs messages
#pragma warning( disable : 4201 4214 4057 4100 4514 4115 4711 4244 )
#endif
#endif
// build defines header....
#include "builddefines.h"
#include <wchar.h> // for wide-character strings
// *** SIR-TECH TYPE DEFINITIONS ***
// These two types are defined by VC6 and were causing redefinition
// problems, but JA2 is compiled with VC5
// HEY WIZARDRY DUDES, JA2 ISN'T THE ONLY PROGRAM WE COMPILE! :-)
#if defined( JA2 ) || defined( UTILS )
typedef unsigned int UINT32;
typedef signed int INT32;
#else
typedef unsigned int UINT32;
typedef int INT32;
#endif
// integers
typedef unsigned char UINT8;
typedef signed char INT8;
typedef unsigned short UINT16;
typedef signed short INT16;
// floats
typedef float FLOAT;
typedef double DOUBLE;
// strings
typedef char CHAR8;
typedef wchar_t CHAR16;
typedef char * STR;
typedef char * STR8;
typedef wchar_t * STR16;
// flags (individual bits used)
typedef unsigned char FLAGS8;
typedef unsigned short FLAGS16;
typedef unsigned long FLAGS32;
// other
typedef unsigned char BOOLEAN;
typedef void * PTR;
typedef unsigned short HNDL;
typedef UINT8 BYTE;
typedef CHAR8 STRING512[512];
typedef UINT32 HWFILE;
#define SGPFILENAME_LEN 100
typedef CHAR8 SGPFILENAME[SGPFILENAME_LEN];
// *** SIR-TECH TYPE DEFINITIONS ***
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define BAD_INDEX -1
#define NULL_HANDLE 65535
#define PI 3.1415926
#define ST_EPSILON 0.00001 // define a sir-tech epsilon value
#ifndef NULL
#define NULL 0
#endif
typedef struct
{
INT32 iLeft;
INT32 iTop;
INT32 iRight;
INT32 iBottom;
} SGPRect;
typedef struct
{
INT32 iX;
INT32 iY;
} SGPPoint;
typedef struct
{
INT32 Min;
INT32 Max;
} SGPRange;
typedef FLOAT VECTOR2[2]; // 2d vector (2x1 matrix)
typedef FLOAT VECTOR3[3]; // 3d vector (3x1 matrix)
typedef FLOAT VECTOR4[4]; // 4d vector (4x1 matrix)
typedef INT32 IVECTOR2[2]; // 2d vector (2x1 matrix)
typedef INT32 IVECTOR3[3]; // 3d vector (3x1 matrix)
typedef INT32 IVECTOR4[4]; // 4d vector (4x1 matrix)
typedef VECTOR3 MATRIX3[3]; // 3x3 matrix
typedef VECTOR4 MATRIX4[4]; // 4x4 matrix
typedef VECTOR3 ANGLE; // angle return array
typedef VECTOR4 COLOR; // rgba color array
#endif
+14
View File
@@ -0,0 +1,14 @@
#ifndef __WCHECK_
#define __WCHECK_
#define CHECKF(exp) if (!(exp)) { return(FALSE); }
#define CHECKV(exp) if (!(exp)) { return; }
#define CHECKN(exp) if (!(exp)) { return(NULL); }
#define CHECKBI(exp) if (!(exp)) { return(-1); }
#define CHECKASSERTF(exp) if (!(exp)) { ASSERT(0); return(FALSE); }
#define CHECKASSERTV(exp) if (!(exp)) { ASSERT(0); return; }
#define CHECKASSERTN(exp) if (!(exp)) { ASSERT(0); return(NULL); }
#define CHECKASSERTBI(exp) if (!(exp)) { ASSERT(0); return(-1); }
#endif
+358
View File
@@ -0,0 +1,358 @@
//#define UNICODE
#include "types.h"
#include <stdio.h>
#include <stdarg.h>
#include <malloc.h>
#include <windows.h>
#include <windowsx.h>
#include <stdarg.h>
#include <wchar.h>
#include <string.h>
#include "sgp.h"
#include "memman.h"
#include "fileman.h"
#include "Font.h"
#include "Debug.h"
#include "vsurface.h"
#include "vsurface_private.h"
#include "DirectX Common.h"
#include <ddraw.h>
#include "winfont.h"
#include "font.h"
INT32 FindFreeWinFont( void );
BOOLEAN gfEnumSucceed = FALSE;
#define MAX_WIN_FONTS 10
// Private struct not to be exported
// to other modules
typedef struct
{
HFONT hFont;
COLORVAL ForeColor;
COLORVAL BackColor;
} HWINFONT;
LOGFONT gLogFont;
HWINFONT WinFonts[ MAX_WIN_FONTS ];
void Convert16BitStringTo8BitChineseBig5String( UINT8 *dst, UINT16 *src )
{
INT32 i, j;
char *ptr;
i = j = 0;
ptr = (char*)src;
while( ptr[j] || ptr[j + 1] )
{
if( ptr[j] )
{
dst[i] = ptr[j];
dst[ i + 1 ] = '\0';
i++;
}
j++;
}
}
void InitWinFonts( )
{
memset( WinFonts, 0, sizeof( WinFonts ) );
}
void ShutdownWinFonts( )
{
}
INT32 FindFreeWinFont( void )
{
INT32 iCount;
for( iCount = 0; iCount < MAX_WIN_FONTS; iCount++ )
{
if( WinFonts[ iCount ].hFont == NULL )
{
return( iCount );
}
}
return( -1 );
}
HWINFONT *GetWinFont( INT32 iFont )
{
if ( iFont == -1 )
{
return( NULL );
}
if ( WinFonts[ iFont ].hFont == NULL )
{
return( NULL );
}
else
{
return( &( WinFonts[ iFont ] ) );
}
}
UINT16 gzFontName[32];
INT32 CreateWinFont( INT32 iHeight, INT32 iWidth, INT32 iEscapement,
INT32 iWeight, BOOLEAN fItalic, BOOLEAN fUnderline, BOOLEAN fStrikeOut, STR16 szFontName, INT32 iCharSet )
{
INT32 iFont;
HFONT hFont;
UINT8 szCharFontName[32]; //32 characters including null terminator (matches max font name length)
// Find free slot
iFont = FindFreeWinFont( );
if ( iFont == -1 )
{
return( iFont );
}
//SET UP FONT WE WANT TO LOAD HERE
wcscpy( gzFontName, szFontName );
//ATTEMPT TO LOAD THE FONT NOW
sprintf( (char *) szCharFontName, "%S", szFontName );
if( DoesWinFontExistOnSystem( szFontName, iCharSet ) )
{
gLogFont.lfHeight = iHeight;
gLogFont.lfWidth = 0;
hFont = CreateFontIndirect( &gLogFont );
}
else
{
FatalError( "Cannot load subtitle Windows Font: %S.", szFontName );
return( -1 );
}
if ( hFont == NULL )
{
return( -1 );
}
// Set font....
WinFonts[ iFont ].hFont = hFont;
return( iFont );
}
void DeleteWinFont( INT32 iFont )
{
HWINFONT *pWinFont;
pWinFont = GetWinFont( iFont );
if ( pWinFont != NULL )
{
DeleteObject( pWinFont->hFont );
}
}
void SetWinFontForeColor( INT32 iFont, COLORVAL *pColor )
{
HWINFONT *pWinFont;
pWinFont = GetWinFont( iFont );
if ( pWinFont != NULL )
{
pWinFont->ForeColor = ( *pColor );
}
}
void SetWinFontBackColor( INT32 iFont, COLORVAL *pColor )
{
HWINFONT *pWinFont;
pWinFont = GetWinFont( iFont );
if ( pWinFont != NULL )
{
pWinFont->BackColor = ( *pColor );
}
}
void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, UINT16 *pFontString, ...)
{
va_list argptr;
wchar_t string2[512];
char string[512];
HVSURFACE hVSurface;
LPDIRECTDRAWSURFACE2 pDDSurface;
HDC hdc;
RECT rc;
HWINFONT *pWinFont;
int len;
SIZE RectSize;
pWinFont = GetWinFont( iFont );
if ( pWinFont == NULL )
{
return;
}
va_start(argptr, pFontString); // Set up variable argument pointer
len = vswprintf(string2, pFontString, argptr); // process gprintf string (get output str)
va_end(argptr);
#ifdef TAIWANESE
Convert16BitStringTo8BitChineseBig5String( string, string2 );
#else
sprintf( string, "%S", string2 );
#endif
// Get surface...
GetVideoSurface( &hVSurface, uiDestBuf );
pDDSurface = GetVideoSurfaceDDSurface( hVSurface );
IDirectDrawSurface2_GetDC( pDDSurface, &hdc );
SelectObject(hdc, pWinFont->hFont );
SetTextColor( hdc, pWinFont->ForeColor );
SetBkColor(hdc, pWinFont->BackColor );
SetBkMode(hdc, TRANSPARENT);
GetTextExtentPoint32( hdc, string, len, &RectSize );
SetRect(&rc, x, y, x + RectSize.cx, y + RectSize.cy );
ExtTextOut( hdc, x, y, ETO_OPAQUE, &rc, string, len, NULL );
IDirectDrawSurface2_ReleaseDC( pDDSurface, hdc );
}
INT16 WinFontStringPixLength( UINT16 *string2, INT32 iFont )
{
HWINFONT *pWinFont;
HDC hdc;
SIZE RectSize;
char string[512];
pWinFont = GetWinFont( iFont );
if ( pWinFont == NULL )
{
return( 0 );
}
#ifdef TAIWANESE
Convert16BitStringTo8BitChineseBig5String( string, string2 );
#else
sprintf( string, "%S", string2 );
#endif
hdc = GetDC(NULL);
SelectObject(hdc, pWinFont->hFont );
GetTextExtentPoint32( hdc, string, strlen(string), &RectSize );
ReleaseDC(NULL, hdc);
return( (INT16)RectSize.cx );
}
INT16 GetWinFontHeight( UINT16 *string2, INT32 iFont )
{
HWINFONT *pWinFont;
HDC hdc;
SIZE RectSize;
char string[512];
pWinFont = GetWinFont( iFont );
if ( pWinFont == NULL )
{
return( 0 );
}
#ifdef TAIWANESE
Convert16BitStringTo8BitChineseBig5String( string, string2 );
#else
sprintf( string, "%S", string2 );
#endif
hdc = GetDC(NULL);
SelectObject(hdc, pWinFont->hFont );
GetTextExtentPoint32( hdc, string, strlen(string), &RectSize );
ReleaseDC(NULL, hdc);
return( (INT16)RectSize.cy );
}
UINT32 WinFont_mprintf( INT32 iFont, INT32 x, INT32 y, UINT16 *pFontString, ...)
{
va_list argptr;
wchar_t string[512];
va_start(argptr, pFontString); // Set up variable argument pointer
vswprintf(string, pFontString, argptr); // process gprintf string (get output str)
va_end(argptr);
PrintWinFont( FontDestBuffer, iFont, x, y, string );
return( 1 );
}
int CALLBACK EnumFontFamProc( CONST LOGFONT *lplf, CONST TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData )
{
gfEnumSucceed = TRUE;
return( TRUE );
}
int CALLBACK EnumFontFamExProc( ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam )
{
UINT8 szFontName[32];
sprintf( (char *)szFontName, "%S", gzFontName );
if( !strcmp( (const char *) szFontName, (const char *)lpelfe->elfFullName ) )
{
gfEnumSucceed = TRUE;
memcpy( &gLogFont, &(lpelfe->elfLogFont), sizeof( LOGFONT ) );
}
return TRUE;
}
BOOLEAN DoesWinFontExistOnSystem( STR16 pTypeFaceName, INT32 iCharSet )
{
HDC hdc;
char string[512];
LOGFONT LogFont;
hdc = GetDC(NULL);
gfEnumSucceed = FALSE;
// Copy into 8-bit!
sprintf( string, "%S", pTypeFaceName );
memset( &LogFont, 0, sizeof( LOGFONT ) );
LogFont.lfCharSet = iCharSet;
lstrcpy( (LPSTR)&LogFont.lfFaceName, string );
EnumFontFamiliesEx( hdc, &LogFont, (FONTENUMPROCA) EnumFontFamExProc, 0, 0 );
ReleaseDC(NULL, hdc);
return( gfEnumSucceed );
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef __WINFONT_
#define __WINFONT_
void InitWinFonts( );
void ShutdownWinFonts( );
INT32 CreateWinFont( INT32 iHeight, INT32 iWidth, INT32 iEscapement,
INT32 iWeight, BOOLEAN fItalic, BOOLEAN fUnderline, BOOLEAN fStrikeOut, STR16 szFontName, INT32 iCharSet );
void DeleteWinFont( INT32 iFont );
void SetWinFontBackColor( INT32 iFont, COLORVAL *pColor );
void SetWinFontForeColor( INT32 iFont, COLORVAL *pColor );
void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, UINT16 *pFontString, ...);
INT16 WinFontStringPixLength( UINT16 *string, INT32 iFont );
INT16 GetWinFontHeight( UINT16 *string, INT32 iFont );
UINT32 WinFont_mprintf( INT32 iFont, INT32 x, INT32 y, UINT16 *pFontString, ...);
BOOLEAN DoesWinFontExistOnSystem( STR16 pTypeFaceName, INT32 iCharSet );
#endif
+54
View File
@@ -0,0 +1,54 @@
//**************************************************************************
//
// Filename : WizShare.h
//
// Purpose :
//
// Modification history :
//
// 25nov96:HJH - creation
//
//**************************************************************************
#ifndef _WizShare_h
#define _WizShare_h
//**************************************************************************
//
// Includes
//
//**************************************************************************
#include "types.h"
//**************************************************************************
//
// Defines
//
//**************************************************************************
#define MAX_MSG_LENGTH 128
#define NUM_MESSAGES 100
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
#pragma pack(push, 1)
typedef struct WizSharedtag
{
BOOLEAN fMessage;
INT32 iMessageIndex; // index to 1st message
INT32 iNumMessages; // # messages
INT32 iLastIndex;
CHAR cMessages[NUM_MESSAGES][MAX_MSG_LENGTH];
} WizShared;
#pragma pack(pop)
#endif
+184
View File
@@ -0,0 +1,184 @@
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-1996 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* $Id: ZCONF.H,v 1.2 2004/03/16 02:00:39 digicrab Exp $ */
#ifndef _ZCONF_H
#define _ZCONF_H
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_
# define inflate z_inflate
# define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset
# define deflateParams z_deflateParams
# define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync
# define inflateReset z_inflateReset
# define compress z_compress
# define uncompress z_uncompress
# define adler32 z_adler32
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define Byte z_Byte
# define uInt z_uInt
# define uLong z_uLong
# define Bytef z_Bytef
# define charf z_charf
# define intf z_intf
# define uIntf z_uIntf
# define uLongf z_uLongf
# define voidpf z_voidpf
# define voidp z_voidp
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
# ifndef __32BIT__
# define __32BIT__
# endif
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#if defined(MSDOS) && !defined(__32BIT__)
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
# define STDC
#endif
#if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC)
# define STDC
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
1 << (windowBits+2) + 1 << (memLevel+9)
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR __far
# else
# define FAR far
# endif
#endif
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
# ifndef __32BIT__
# define SMALL_MEDIUM
# define FAR __far
# endif
#endif
#ifndef FAR
# define FAR
#endif
typedef unsigned char Byte; /* 8 bits */
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#if defined(__BORLANDC__) && defined(SMALL_MEDIUM)
/* Borland C/C++ ignores FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
/* Compile with -DZLIB_DLL for Windows DLL support */
#if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL)
# include <windows.h>
# define EXPORT WINAPI
#else
# define EXPORT
#endif
#endif /* _ZCONF_H */
+780
View File
@@ -0,0 +1,780 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.0.4, Jul 24th, 1996.
Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
gzip@prep.ai.mit.edu madler@alumni.caltech.edu
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/
#ifndef _ZLIB_H
#define _ZLIB_H
#ifdef __cplusplus
extern "C" {
#endif
#include "zconf.h"
#define ZLIB_VERSION "1.0.4"
/*
The 'zlib' compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data. This version of the library supports only one compression method
(deflation) but other algorithms may be added later and will have the same
stream interface.
For compression the application must provide the output buffer and
may optionally provide the input buffer for optimization. For decompression,
the application must provide the input buffer and may optionally provide
the output buffer for optimization.
Compression can be done in a single step if the buffers are large
enough (for example if an input file is mmap'ed), or can be done by
repeated calls of the compression function. In the latter case, the
application must provide more input and/or consume the output
(providing more output space) before each call.
The library does not install any signal handler. It is recommended to
add at least a handler for SIGSEGV when decompressing; the library checks
the consistency of the input data whenever possible but may go nuts
for some forms of corrupted input.
*/
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state;
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
int data_type; /* best guess about the data type: ascii or binary */
uLong adler; /* adler32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} z_stream;
typedef z_stream FAR *z_streamp;
/*
The application must update next_in and avail_in when avail_in has
dropped to zero. It must update next_out and avail_out when avail_out
has dropped to zero. The application must initialize zalloc, zfree and
opaque before calling the init function. All other fields are set by the
compression library and must not be updated by the application.
The opaque value provided by the application will be passed as the first
parameter for calls of zalloc and zfree. This can be useful for custom
memory management. The compression library attaches no meaning to the
opaque value.
zalloc must return Z_NULL if there is not enough memory for the object.
On 16-bit systems, the functions zalloc and zfree must be able to allocate
exactly 65536 bytes, but will not be required to allocate more than this
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
pointers returned by zalloc for objects of exactly 65536 bytes *must*
have their offset normalized to zero. The default allocation function
provided by this library ensures this (see zutil.c). To reduce memory
requirements and avoid any allocation of 64K objects, at the expense of
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
The fields total_in and total_out can be used for statistics or
progress reports. After compression, total_in holds the total size of
the uncompressed data and may be saved for use in the decompressor
(particularly if the decompressor wants to decompress everything in
a single step).
*/
/* constants */
#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH 2
#define Z_FULL_FLUSH 3
#define Z_FINISH 4
/* Allowed flush values; see deflate() below for details */
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6)
/* Return codes for the compression/decompression functions. Negative
* values are errors, positive values are used for special but normal events.
*/
#define Z_NO_COMPRESSION 0
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
/* compression levels */
#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */
#define Z_BINARY 0
#define Z_ASCII 1
#define Z_UNKNOWN 2
/* Possible values of the data_type field */
#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define zlib_version zlibVersion()
/* for compatibility with versions < 1.0.2 */
/* basic functions */
extern const char * EXPORT zlibVersion OF((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is
not compatible with the zlib.h header file used by the application.
This check is automatically made by deflateInit and inflateInit.
*/
/*
extern int EXPORT deflateInit OF((z_streamp strm, int level));
Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller.
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
use default allocation functions.
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at
all (the input data is simply copied a block at a time).
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
compression (currently equivalent to level 6).
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
with the version assumed by the caller (ZLIB_VERSION).
msg is set to null if there is no error message. deflateInit does not
perform any compression: this will be done by deflate().
*/
extern int EXPORT deflate OF((z_streamp strm, int flush));
/*
Performs one or both of the following actions:
- Compress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in and avail_in are updated and
processing will resume at this point for the next call of deflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. This action is forced if the parameter flush is non zero.
Forcing flush frequently degrades the compression ratio, so this parameter
should be set only when necessary (in interactive applications).
Some output may be provided even if flush is not set.
Before the call of deflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating avail_in or avail_out accordingly; avail_out
should never be zero before the call. The application can consume the
compressed output when it wants, for example when the output buffer is full
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
and with zero avail_out, it must be called again after making room in the
output buffer because there might be more output pending.
If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
block is terminated and flushed to the output buffer so that the
decompressor can get all input data available so far. For method 9, a future
variant on method 8, the current block will be flushed but not terminated.
Z_SYNC_FLUSH has the same effect as partial flush except that the compressed
output is byte aligned (the compressor can clear its internal bit buffer)
and the current block is always terminated; this can be useful if the
compressor has to be restarted from scratch after an interruption (in which
case the internal state of the compressor may be lost).
If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
special marker is output and the compression dictionary is discarded; this
is useful to allow the decompressor to synchronize if one compressed block
has been damaged (see inflateSync below). Flushing degrades compression and
so should be used only when necessary. Using Z_FULL_FLUSH too often can
seriously degrade the compression. If deflate returns with avail_out == 0,
this function must be called again with the same value of the flush
parameter and more output space (updated avail_out), until the flush is
complete (deflate returns with non-zero avail_out).
If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there
was enough output space; if deflate returns with Z_OK, this function must be
called again with Z_FINISH and more output space (updated avail_out) but no
more input data, until it returns with Z_STREAM_END or an error. After
deflate has returned Z_STREAM_END, the only possible operations on the
stream are deflateReset or deflateEnd.
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least
0.1% larger than avail_in plus 12 bytes. If deflate does not return
Z_STREAM_END, then it must be called again as described above.
deflate() may update data_type if it can make a good guess about
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
binary. This field is only for information purposes and does not affect
the compression algorithm in any manner.
deflate() returns Z_OK if some progress has been made (more input
processed or more output produced), Z_STREAM_END if all input has been
consumed and all output has been produced (only when flush is set to
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
*/
extern int EXPORT deflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
prematurely (some input or output was discarded). In the error case,
msg may be set but then points to a static string (which must not be
deallocated).
*/
/*
extern int EXPORT inflateInit OF((z_streamp strm));
Initializes the internal stream state for decompression. The fields
zalloc, zfree and opaque must be initialized before by the caller. If
zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
allocation functions.
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
with the version assumed by the caller. msg is set to null if there is no
error message. inflateInit does not perform any decompression: this will be
done by inflate().
*/
extern int EXPORT inflate OF((z_streamp strm, int flush));
/*
Performs one or both of the following actions:
- Decompress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in is updated and processing
will resume at this point for the next call of inflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. inflate() provides as much output as possible, until there
is no more input data or no more space in the output buffer (see below
about the flush parameter).
Before the call of inflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating the next_* and avail_* values accordingly.
The application can consume the uncompressed output when it wants, for
example when the output buffer is full (avail_out == 0), or after each
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
must be called again after making room in the output buffer because there
might be more output pending.
If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much
output as possible to the output buffer. The flushing behavior of inflate is
not specified for values of the flush parameter other than Z_PARTIAL_FLUSH
and Z_FINISH, but the current implementation actually flushes as much output
as possible anyway.
inflate() should normally be called until it returns Z_STREAM_END or an
error. However if all decompression is to be performed in a single step
(a single call of inflate), the parameter flush should be set to
Z_FINISH. In this case all pending input is processed and all pending
output is flushed; avail_out must be large enough to hold all the
uncompressed data. (The size of the uncompressed data may have been saved
by the compressor for this purpose.) The next operation on this stream must
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
is never required, but can be used to inform inflate that a faster routine
may be used for the single inflate() call.
inflate() returns Z_OK if some progress has been made (more input
processed or more output produced), Z_STREAM_END if the end of the
compressed data has been reached and all uncompressed output has been
produced, Z_NEED_DICT if a preset dictionary is needed at this point (see
inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted,
Z_STREAM_ERROR if the stream structure was inconsistent (for example if
next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
Z_BUF_ERROR if no progress is possible or if there was not enough room in
the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the
application may then call inflateSync to look for a good compression block.
In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the
dictionary chosen by the compressor.
*/
extern int EXPORT inflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
was inconsistent. In the error case, msg may be set but then points to a
static string (which must not be deallocated).
*/
/* Advanced functions */
/*
The following functions are needed only in some special applications.
*/
/*
extern int EXPORT deflateInit2 OF((z_streamp strm,
int level,
int method,
int windowBits,
int memLevel,
int strategy));
This is another version of deflateInit with more compression options. The
fields next_in, zalloc, zfree and opaque must be initialized before by
the caller.
The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library. (Method 9 will allow a 64K history buffer and
partial block flushes.)
The windowBits parameter is the base two logarithm of the window size
(the size of the history buffer). It should be in the range 8..15 for this
version of the library (the value 16 will be allowed for method 9). Larger
values of this parameter result in better compression at the expense of
memory usage. The default value is 15 if deflateInit is used instead.
The memLevel parameter specifies how much memory should be allocated
for the internal compression state. memLevel=1 uses minimum memory but
is slow and reduces compression ratio; memLevel=9 uses maximum memory
for optimal speed. The default value is 8. See zconf.h for total memory
usage as a function of windowBits and memLevel.
The strategy parameter is used to tune the compression algorithm. Use the
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
string match). Filtered data consists mostly of small values with a
somewhat random distribution. In this case, the compression algorithm is
tuned to compress them better. The effect of Z_FILTERED is to force more
Huffman coding and less string matching; it is somewhat intermediate
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
the compression ratio but not the correctness of the compressed output even
if it is not set appropriately.
If next_in is not null, the library will use this buffer to hold also
some history information; the buffer must either hold the entire input
data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
is null, the library will allocate its own history buffer (and leave next_in
null). next_out need not be provided here but must be provided by the
application for the next call of deflate().
If the history buffer is provided by the application, next_in must
must never be changed by the application since the compressor maintains
information inside this buffer from call to call; the application
must provide more input only by increasing avail_in. next_in is always
reset by the library in this case.
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
an invalid method). msg is set to null if there is no error message.
deflateInit2 does not perform any compression: this will be done by
deflate().
*/
extern int EXPORT deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the compression dictionary (history buffer) from the given
byte sequence without producing any compressed output. This function must
be called immediately after deflateInit or deflateInit2, before any call
of deflate. The compressor and decompressor must use exactly the same
dictionary (see inflateSetDictionary).
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
used strings preferably put towards the end of the dictionary. Using a
dictionary is most useful when the data to be compressed is short and
can be predicted with good accuracy; the data can then be compressed better
than with the default empty dictionary. In this version of the library,
only the last 32K bytes of the dictionary are used.
Upon return of this function, strm->adler is set to the Adler32 value
of the dictionary; the decompressor may later use this value to determine
which dictionary has been used by the compressor. (The Adler32 value
applies to the whole dictionary even if only a subset of the dictionary is
actually used by the compressor.)
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state
is inconsistent (for example if deflate has already been called for this
stream). deflateSetDictionary does not perform any compression: this will
be done by deflate().
*/
extern int EXPORT deflateCopy OF((z_streamp dest,
z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream. If
the source stream is using an application-supplied history buffer, a new
buffer is allocated for the destination stream. The compressed output
buffer is always application-supplied. It's the responsibility of the
application to provide the correct values of next_out and avail_out for the
next call of deflate.
This function can be useful when several compression strategies will be
tried, for example when there are several ways of pre-processing the input
data with a filter. The streams that will be discarded should then be freed
by calling deflateEnd. Note that deflateCopy duplicates the internal
compression state which can be quite large, so this strategy is slow and
can consume lots of memory.
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being NULL). msg is left unchanged in both source and
destination.
*/
extern int EXPORT deflateReset OF((z_streamp strm));
/*
This function is equivalent to deflateEnd followed by deflateInit,
but does not free and reallocate all the internal compression state.
The stream will keep the same compression level and any other attributes
that may have been set by deflateInit2.
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
/*
Dynamically update the compression level and compression strategy.
This can be used to switch between compression and straight copy of
the input data, or to switch to a different kind of input data requiring
a different strategy. If the compression level is changed, the input
available so far is compressed with the old level (and may be flushed);
the new level will take effect only at the next call of deflate().
Before the call of deflateParams, the stream state must be set as for
a call of deflate(), since the currently available input may have to
be compressed and flushed. In particular, strm->avail_out must be non-zero.
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
if strm->avail_out was zero.
*/
/*
extern int EXPORT inflateInit2 OF((z_streamp strm,
int windowBits));
This is another version of inflateInit with more compression options. The
fields next_out, zalloc, zfree and opaque must be initialized before by
the caller.
The windowBits parameter is the base two logarithm of the maximum window
size (the size of the history buffer). It should be in the range 8..15 for
this version of the library (the value 16 will be allowed soon). The
default value is 15 if inflateInit is used instead. If a compressed stream
with a larger window size is given as input, inflate() will return with
the error code Z_DATA_ERROR instead of trying to allocate a larger window.
If next_out is not null, the library will use this buffer for the history
buffer; the buffer must either be large enough to hold the entire output
data, or have at least 1<<windowBits bytes. If next_out is null, the
library will allocate its own buffer (and leave next_out null). next_in
need not be provided here but must be provided by the application for the
next call of inflate().
If the history buffer is provided by the application, next_out must
never be changed by the application since the decompressor maintains
history information inside this buffer from call to call; the application
can only reset next_out to the beginning of the history buffer when
avail_out is zero and all output has been consumed.
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
windowBits < 8). msg is set to null if there is no error message.
inflateInit2 does not perform any decompression: this will be done by
inflate().
*/
extern int EXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the decompression dictionary (history buffer) from the given
uncompressed byte sequence. This function must be called immediately after
a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen
by the compressor can be determined from the Adler32 value returned by this
call of inflate. The compressor and decompressor must use exactly the same
dictionary (see deflateSetDictionary).
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
expected one (incorrect Adler32 value). inflateSetDictionary does not
perform any decompression: this will be done by subsequent calls of
inflate().
*/
extern int EXPORT inflateSync OF((z_streamp strm));
/*
Skips invalid compressed data until the special marker (see deflate()
above) can be found, or until all available input is skipped. No output
is provided.
inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
if no more input was provided, Z_DATA_ERROR if no marker has been found,
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
case, the application may save the current current value of total_in which
indicates where valid compressed data was found. In the error case, the
application may repeatedly call inflateSync, providing more input each time,
until success or end of the input data.
*/
extern int EXPORT inflateReset OF((z_streamp strm));
/*
This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate all the internal decompression state.
The stream will keep attributes that may have been set by inflateInit2.
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
/* utility functions */
/*
The following utility functions are implemented on top of the
basic stream-oriented functions. To simplify the interface, some
default options are assumed (compression level, window size,
standard memory allocation functions). The source code of these
utility functions can easily be modified if you need special options.
*/
extern int EXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be at least 0.1% larger than
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
compressed buffer.
This function can be used to compress a whole file at once if the
input file is mmap'ed.
compress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer.
*/
extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
typedef voidp gzFile;
extern gzFile EXPORT gzopen OF((const char *path, const char *mode));
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb") but can also include a compression level
("wb9"). gzopen can be used to read a file which is not in gzip format;
in this case gzread will directly read from the file without decompression.
gzopen returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR).
*/
extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
/*
gzdopen() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or
fileno (in the file has been previously opened with fopen).
The mode parameter is as in gzopen.
The next call of gzclose on the returned gzFile will also close the
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
gzdopen returns NULL if there was insufficient memory to allocate
the (de)compression state.
*/
extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file.
If the input file was not in gzip format, gzread copies the given number
of bytes into the buffer.
gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */
extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len));
/*
Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes actually written
(0 in case of error).
*/
extern int EXPORT gzflush OF((gzFile file, int flush));
/*
Flushes all pending output into the compressed file. The parameter
flush is as in the deflate() function. The return value is the zlib
error number (see function gzerror below). gzflush returns Z_OK if
the flush parameter is Z_FINISH and all output could be flushed.
gzflush should be called only when strictly necessary because it can
degrade compression.
*/
extern int EXPORT gzclose OF((gzFile file));
/*
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression state. The return value is the zlib
error number (see function gzerror below).
*/
extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
/*
Returns the error message for the last error which occurred on the
given compressed file. errnum is set to zlib error number. If an
error occurred in the file system and not in the compression library,
errnum is set to Z_ERRNO and the application may consult errno
to get the exact error code.
*/
/* checksum functions */
/*
These functions are not related to compression but are exported
anyway because they might be useful in applications using the
compression library.
*/
extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
/*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is NULL, this function returns
the required initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example:
uLong adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
*/
extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running crc with the bytes buf[0..len-1] and return the updated
crc. If buf is NULL, this function returns the required initial value
for the crc. Pre- and post-conditioning (one's complement) is performed
within this function so it shouldn't be done by the application.
Usage example:
uLong crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
*/
/* various hacks, don't look :) */
/* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream:
*/
extern int EXPORT deflateInit_ OF((z_streamp strm, int level,
const char *version, int stream_size));
extern int EXPORT inflateInit_ OF((z_streamp strm,
const char *version, int stream_size));
extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
int windowBits, int memLevel, int strategy,
const char *version, int stream_size));
extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
const char *version, int stream_size));
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */
#ifdef __cplusplus
}
#endif
#endif /* _ZLIB_H */
File diff suppressed because it is too large Load Diff
Binary file not shown.
+366
View File
@@ -0,0 +1,366 @@
/*==========================================================================;
*
* Copyright (C) 1995,1996 Microsoft Corporation. All Rights Reserved.
*
* File: dsound.h
* Content: DirectSound include file
*
***************************************************************************/
#ifndef __DSOUND_INCLUDED__
#define __DSOUND_INCLUDED__
#ifdef _WIN32
#define COM_NO_WINDOWS_H
#include <objbase.h>
#endif
#define _FACDS 0x878
#define MAKE_DSHRESULT( code ) MAKE_HRESULT( 1, _FACDS, code )
#ifdef __cplusplus
extern "C" {
#endif
// Direct Sound Component GUID {47D4D946-62E8-11cf-93BC-444553540000}
DEFINE_GUID(CLSID_DirectSound,
0x47d4d946, 0x62e8, 0x11cf, 0x93, 0xbc, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0);
// DirectSound 279afa83-4981-11ce-a521-0020af0be560
DEFINE_GUID(IID_IDirectSound,0x279AFA83,0x4981,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60);
// DirectSoundBuffer 279afa85-4981-11ce-a521-0020af0be560
DEFINE_GUID(IID_IDirectSoundBuffer,0x279AFA85,0x4981,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60);
//==========================================================================;
//
// Structures...
//
//==========================================================================;
#ifdef __cplusplus
/* 'struct' not 'class' per the way DECLARE_INTERFACE_ is defined */
struct IDirectSound;
struct IDirectSoundBuffer;
#endif
typedef struct IDirectSound *LPDIRECTSOUND;
typedef struct IDirectSoundBuffer *LPDIRECTSOUNDBUFFER;
typedef struct IDirectSoundBuffer **LPLPDIRECTSOUNDBUFFER;
typedef struct _DSCAPS
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwMinSecondarySampleRate;
DWORD dwMaxSecondarySampleRate;
DWORD dwPrimaryBuffers;
DWORD dwMaxHwMixingAllBuffers;
DWORD dwMaxHwMixingStaticBuffers;
DWORD dwMaxHwMixingStreamingBuffers;
DWORD dwFreeHwMixingAllBuffers;
DWORD dwFreeHwMixingStaticBuffers;
DWORD dwFreeHwMixingStreamingBuffers;
DWORD dwMaxHw3DAllBuffers;
DWORD dwMaxHw3DStaticBuffers;
DWORD dwMaxHw3DStreamingBuffers;
DWORD dwFreeHw3DAllBuffers;
DWORD dwFreeHw3DStaticBuffers;
DWORD dwFreeHw3DStreamingBuffers;
DWORD dwTotalHwMemBytes;
DWORD dwFreeHwMemBytes;
DWORD dwMaxContigFreeHwMemBytes;
DWORD dwUnlockTransferRateHwBuffers;
DWORD dwPlayCpuOverheadSwBuffers;
DWORD dwReserved1;
DWORD dwReserved2;
} DSCAPS, *LPDSCAPS;
typedef struct _DSBCAPS
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwBufferBytes;
DWORD dwUnlockTransferRate;
DWORD dwPlayCpuOverhead;
} DSBCAPS, *LPDSBCAPS;
typedef struct _DSBUFFERDESC
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwBufferBytes;
DWORD dwReserved;
LPWAVEFORMATEX lpwfxFormat;
} DSBUFFERDESC, *LPDSBUFFERDESC;
typedef LPVOID* LPLPVOID;
typedef BOOL (FAR PASCAL * LPDSENUMCALLBACKW)(GUID FAR *, LPWSTR, LPWSTR, LPVOID);
typedef BOOL (FAR PASCAL * LPDSENUMCALLBACKA)(GUID FAR *, LPSTR, LPSTR, LPVOID);
extern HRESULT WINAPI DirectSoundCreate(GUID FAR * lpGUID, LPDIRECTSOUND * ppDS, IUnknown FAR *pUnkOuter );
extern HRESULT WINAPI DirectSoundEnumerateW(LPDSENUMCALLBACKW lpCallback, LPVOID lpContext );
extern HRESULT WINAPI DirectSoundEnumerateA(LPDSENUMCALLBACKA lpCallback, LPVOID lpContext );
#ifdef UNICODE
#define LPDSENUMCALLBACK LPDSENUMCALLBACKW
#define DirectSoundEnumerate DirectSoundEnumerateW
#else
#define LPDSENUMCALLBACK LPDSENUMCALLBACKA
#define DirectSoundEnumerate DirectSoundEnumerateA
#endif
//
// IDirectSound
//
#undef INTERFACE
#define INTERFACE IDirectSound
#ifdef _WIN32
DECLARE_INTERFACE_( IDirectSound, IUnknown )
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
STDMETHOD_(ULONG,Release) (THIS) PURE;
/*** IDirectSound methods ***/
STDMETHOD( CreateSoundBuffer)(THIS_ LPDSBUFFERDESC, LPLPDIRECTSOUNDBUFFER, IUnknown FAR *) PURE;
STDMETHOD( GetCaps)(THIS_ LPDSCAPS ) PURE;
STDMETHOD( DuplicateSoundBuffer)(THIS_ LPDIRECTSOUNDBUFFER, LPLPDIRECTSOUNDBUFFER ) PURE;
STDMETHOD( SetCooperativeLevel)(THIS_ HWND, DWORD ) PURE;
STDMETHOD( Compact)(THIS ) PURE;
STDMETHOD( GetSpeakerConfig)(THIS_ LPDWORD ) PURE;
STDMETHOD( SetSpeakerConfig)(THIS_ DWORD ) PURE;
STDMETHOD( Initialize)(THIS_ GUID FAR * ) PURE;
};
#if !defined(__cplusplus) || defined(CINTERFACE)
#define IDirectSound_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IDirectSound_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IDirectSound_Release(p) (p)->lpVtbl->Release(p)
#define IDirectSound_CreateSoundBuffer(p,a,b,c) (p)->lpVtbl->CreateSoundBuffer(p,a,b,c)
#define IDirectSound_GetCaps(p,a) (p)->lpVtbl->GetCaps(p,a)
#define IDirectSound_DuplicateSoundBuffer(p,a,b) (p)->lpVtbl->DuplicateSoundBuffer(p,a,b)
#define IDirectSound_SetCooperativeLevel(p,a,b) (p)->lpVtbl->SetCooperativeLevel(p,a,b)
#define IDirectSound_Compact(p) (p)->lpVtbl->Compact(p)
#define IDirectSound_GetSpeakerConfig(p,a) (p)->lpVtbl->GetSpeakerConfig(p,a)
#define IDirectSound_SetSpeakerConfig(p,b) (p)->lpVtbl->SetSpeakerConfig(p,b)
#define IDirectSound_Initialize(p,a) (p)->lpVtbl->Initialize(p,a)
#endif
#endif
//
// IDirectSoundBuffer
//
#undef INTERFACE
#define INTERFACE IDirectSoundBuffer
#ifdef _WIN32
DECLARE_INTERFACE_( IDirectSoundBuffer, IUnknown )
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
STDMETHOD_(ULONG,Release) (THIS) PURE;
/*** IDirectSoundBuffer methods ***/
STDMETHOD( GetCaps)(THIS_ LPDSBCAPS ) PURE;
STDMETHOD(GetCurrentPosition)(THIS_ LPDWORD,LPDWORD ) PURE;
STDMETHOD( GetFormat)(THIS_ LPWAVEFORMATEX, DWORD, LPDWORD ) PURE;
STDMETHOD( GetVolume)(THIS_ LPLONG ) PURE;
STDMETHOD( GetPan)(THIS_ LPLONG ) PURE;
STDMETHOD( GetFrequency)(THIS_ LPDWORD ) PURE;
STDMETHOD( GetStatus)(THIS_ LPDWORD ) PURE;
STDMETHOD( Initialize)(THIS_ LPDIRECTSOUND, LPDSBUFFERDESC ) PURE;
STDMETHOD( Lock)(THIS_ DWORD,DWORD,LPVOID,LPDWORD,LPVOID,LPDWORD,DWORD ) PURE;
STDMETHOD( Play)(THIS_ DWORD,DWORD,DWORD ) PURE;
STDMETHOD(SetCurrentPosition)(THIS_ DWORD ) PURE;
STDMETHOD( SetFormat)(THIS_ LPWAVEFORMATEX ) PURE;
STDMETHOD( SetVolume)(THIS_ LONG ) PURE;
STDMETHOD( SetPan)(THIS_ LONG ) PURE;
STDMETHOD( SetFrequency)(THIS_ DWORD ) PURE;
STDMETHOD( Stop)(THIS ) PURE;
STDMETHOD( Unlock)(THIS_ LPVOID,DWORD,LPVOID,DWORD ) PURE;
STDMETHOD( Restore)(THIS ) PURE;
};
#if !defined(__cplusplus) || defined(CINTERFACE)
#define IDirectSoundBuffer_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IDirectSoundBuffer_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IDirectSoundBuffer_Release(p) (p)->lpVtbl->Release(p)
#define IDirectSoundBuffer_GetCaps(p,a) (p)->lpVtbl->GetCaps(p,a)
#define IDirectSoundBuffer_GetCurrentPosition(p,a,b) (p)->lpVtbl->GetCurrentPosition(p,a,b)
#define IDirectSoundBuffer_GetFormat(p,a,b,c) (p)->lpVtbl->GetFormat(p,a,b,c)
#define IDirectSoundBuffer_GetVolume(p,a) (p)->lpVtbl->GetVolume(p,a)
#define IDirectSoundBuffer_GetPan(p,a) (p)->lpVtbl->GetPan(p,a)
#define IDirectSoundBuffer_GetFrequency(p,a) (p)->lpVtbl->GetFrequency(p,a)
#define IDirectSoundBuffer_GetStatus(p,a) (p)->lpVtbl->GetStatus(p,a)
#define IDirectSoundBuffer_Initialize(p,a,b) (p)->lpVtbl->Initialize(p,a,b)
#define IDirectSoundBuffer_Lock(p,a,b,c,d,e,f,g) (p)->lpVtbl->Lock(p,a,b,c,d,e,f,g)
#define IDirectSoundBuffer_Play(p,a,b,c) (p)->lpVtbl->Play(p,a,b,c)
#define IDirectSoundBuffer_SetCurrentPosition(p,a) (p)->lpVtbl->SetCurrentPosition(p,a)
#define IDirectSoundBuffer_SetFormat(p,a) (p)->lpVtbl->SetFormat(p,a)
#define IDirectSoundBuffer_SetVolume(p,a) (p)->lpVtbl->SetVolume(p,a)
#define IDirectSoundBuffer_SetPan(p,a) (p)->lpVtbl->SetPan(p,a)
#define IDirectSoundBuffer_SetFrequency(p,a) (p)->lpVtbl->SetFrequency(p,a)
#define IDirectSoundBuffer_Stop(p) (p)->lpVtbl->Stop(p)
#define IDirectSoundBuffer_Unlock(p,a,b,c,d) (p)->lpVtbl->Unlock(p,a,b,c,d)
#define IDirectSoundBuffer_Restore(p) (p)->lpVtbl->Restore(p)
#endif
#endif
/*
* Return Codes
*/
#define DS_OK 0
/*
* The call failed because resources (such as a priority level)
* were already being used by another caller.
*/
#define DSERR_ALLOCATED MAKE_DSHRESULT( 10 )
/*
* The control (vol,pan,etc.) requested by the caller is not available.
*/
#define DSERR_CONTROLUNAVAIL MAKE_DSHRESULT( 30 )
/*
* An invalid parameter was passed to the returning function
*/
#define DSERR_INVALIDPARAM E_INVALIDARG
/*
* This call is not valid for the current state of this object
*/
#define DSERR_INVALIDCALL MAKE_DSHRESULT( 50 )
/*
* An undetermined error occured inside the DSound subsystem
*/
#define DSERR_GENERIC E_FAIL
/*
* The caller does not have the priority level required for the function to
* succeed.
*/
#define DSERR_PRIOLEVELNEEDED MAKE_DSHRESULT( 70 )
/*
* The DSound subsystem couldn't allocate sufficient memory to complete the
* caller's request.
*/
#define DSERR_OUTOFMEMORY E_OUTOFMEMORY
/*
* The specified WAVE format is not supported
*/
#define DSERR_BADFORMAT MAKE_DSHRESULT( 100 )
/*
* The function called is not supported at this time
*/
#define DSERR_UNSUPPORTED E_NOTIMPL
/*
* No sound driver is available for use
*/
#define DSERR_NODRIVER MAKE_DSHRESULT( 120 )
/*
* This object is already initialized
*/
#define DSERR_ALREADYINITIALIZED MAKE_DSHRESULT( 130 )
/*
* This object does not support aggregation
*/
#define DSERR_NOAGGREGATION CLASS_E_NOAGGREGATION
/*
* The buffer memory has been lost, and must be Restored.
*/
#define DSERR_BUFFERLOST MAKE_DSHRESULT( 150 )
/*
* Another app has a higher priority level, preventing this call from
* succeeding.
*/
#define DSERR_OTHERAPPHASPRIO MAKE_DSHRESULT( 160 )
/*
* The Initialize() member on the Direct Sound Object has not been
* called or called successfully before calls to other members.
*/
#define DSERR_UNINITIALIZED MAKE_DSHRESULT( 170 )
//==========================================================================;
//
// Flags...
//
//==========================================================================;
#define DSCAPS_PRIMARYMONO 0x00000001
#define DSCAPS_PRIMARYSTEREO 0x00000002
#define DSCAPS_PRIMARY8BIT 0x00000004
#define DSCAPS_PRIMARY16BIT 0x00000008
#define DSCAPS_CONTINUOUSRATE 0x00000010
#define DSCAPS_EMULDRIVER 0x00000020
#define DSCAPS_CERTIFIED 0x00000040
#define DSCAPS_SECONDARYMONO 0x00000100
#define DSCAPS_SECONDARYSTEREO 0x00000200
#define DSCAPS_SECONDARY8BIT 0x00000400
#define DSCAPS_SECONDARY16BIT 0x00000800
#define DSBPLAY_LOOPING 0x00000001
#define DSBSTATUS_PLAYING 0x00000001
#define DSBSTATUS_BUFFERLOST 0x00000002
#define DSBSTATUS_LOOPING 0x00000004
#define DSBLOCK_FROMWRITECURSOR 0x00000001
#define DSSCL_NORMAL 1
#define DSSCL_PRIORITY 2
#define DSSCL_EXCLUSIVE 3
#define DSSCL_WRITEPRIMARY 4
#define DSBCAPS_PRIMARYBUFFER 0x00000001
#define DSBCAPS_STATIC 0x00000002
#define DSBCAPS_LOCHARDWARE 0x00000004
#define DSBCAPS_LOCSOFTWARE 0x00000008
#define DSBCAPS_CTRLFREQUENCY 0x00000020
#define DSBCAPS_CTRLPAN 0x00000040
#define DSBCAPS_CTRLVOLUME 0x00000080
#define DSBCAPS_CTRLDEFAULT 0x000000E0 // Pan + volume + frequency.
#define DSBCAPS_CTRLALL 0x000000E0 // All control capabilities
#define DSBCAPS_STICKYFOCUS 0x00004000
#define DSBCAPS_GETCURRENTPOSITION2 0x00010000 // More accurate play cursor under emulation
#define DSSPEAKER_HEADPHONE 1
#define DSSPEAKER_MONO 2
#define DSSPEAKER_QUAD 3
#define DSSPEAKER_STEREO 4
#define DSSPEAKER_SURROUND 5
#ifdef __cplusplus
};
#endif
#endif /* __DSOUND_INCLUDED__ */
+133
View File
@@ -0,0 +1,133 @@
#ifndef __ENGLISH_
#define __ENGLISH_
#include "types.h"
#define SHIFT 16
#define CTRL 17
#define ALT 18
#define F1 124
#define F2 125
#define F3 126
#define F4 127
#define F5 128
#define F6 129
#define F7 130
#define F8 131
#define F9 132
#define F10 133
#define F11 134
#define F12 135
#define SHIFT_F1 368
#define SHIFT_F2 369
#define SHIFT_F3 370
#define SHIFT_F4 371
#define SHIFT_F5 372
#define SHIFT_F6 373
#define SHIFT_F7 374
#define SHIFT_F8 375
#define SHIFT_F9 376
#define SHIFT_F10 377
#define SHIFT_F11 378
#define SHIFT_F12 379
#define ALT_F1 624
#define ALT_F2 625
#define ALT_F3 626
#define ALT_F4 627
#define ALT_F5 628
#define ALT_F6 629
#define ALT_F7 630
#define ALT_F8 631
#define ALT_F9 632
#define ALT_F10 633
#define ALT_F11 634
#define ALT_F12 635
#define CTRL_F1 880
#define CTRL_F2 881
#define CTRL_F3 882
#define CTRL_F4 883
#define CTRL_F5 884
#define CTRL_F6 885
#define CTRL_F7 886
#define CTRL_F8 887
#define CTRL_F9 888
#define CTRL_F10 889
#define CTRL_F11 890
#define CTRL_F12 891
#define ESC 27
#define TAB 9
#define CAPS 20
#define SCRL_LOCK 145 //*** this may be incorrect! DB
#define SNAPSHOT 44
#define PAUSE 19
#define NUM_LOCK 144
#define BACKSPACE 8
#define INSERT 245
#define DEL 246
#ifndef JA2
// Stupid definition causes problems with headers that use the keyword END -- DB
#define KEY_END 247
#else
#define END 247
#endif
#define DNARROW 248
#define PGDN 249
#define LEFTARROW 250
#define RIGHTARROW 251
#define HOME 252
#define UPARROW 253
#define PGUP 254
#define SHIFT_TAB 265
#define SHIFT_INSERT 501
#define SHIFT_DELETE 502
#define SHIFT_END 503
#define SHIFT_DNARROW 504
#define SHIFT_PGDN 505
#define SHIFT_LEFTARROW 506
#define SHIFT_RIGHTARROW 507
#define SHIFT_HOME 508
#define SHIFT_UPARROW 509
#define SHIFT_PGUP 510
#define ALT_TAB 521
#define ALT_INSERT 757
#define ALT_DELETE 758
#define ALT_END 759
#define ALT_DNARROW 760
#define ALT_PGDN 761
#define ALT_LEFTARROW 762
#define ALT_RIGHTARROW 763
#define ALT_HOME 764
#define ALT_UPARROW 765
#define ALT_PGUP 766
#define CTRL_TAB 777
#define CTRL_INSERT 1013
#define CTRL_DELETE 1014
#define CTRL_END 1015
#define CTRL_DNARROW 1016
#define CTRL_PGDN 1017
#define CTRL_LEFTARROW 1018
#define CTRL_RIGHTARROW 1019
#define CTRL_HOME 1020
#define CTRL_UPARROW 1021
#define CTRL_PGUP 1022
#define CURSOR 1023
#define ENTER 13
#define SPACE 32
#endif
File diff suppressed because it is too large Load Diff
+224
View File
@@ -0,0 +1,224 @@
//**************************************************************************
//
// Filename : flic.h
//
// Purpose : to define some flic stuff
//
// Modification history :
//
//**************************************************************************
#ifndef __FLIC_H
#define __FLIC_H
//**************************************************************************
//
// Includes
//
//**************************************************************************
#include "sgp.h"
#include <stdio.h>
//**************************************************************************
//
// Defines
//
//**************************************************************************
#define ErrFlicLibAccess -1
#define ErrFlicAccess -2
#define ErrFlicSeek -3
#define ErrFlicRead -4
#define ErrFlicBad -5
#define ErrFlicBadFrame -6
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
struct _Flic;
typedef signed char Char; /* Signed 8 bits. */
typedef unsigned char Uchar; /* Unsigned 8 bits. */
typedef short Short; /* Signed 16 bits please. */
typedef unsigned short Ushort; /* Unsigned 16 bits please. */
typedef long Long; /* Signed 32 bits. */
typedef unsigned long Ulong; /* Unsigned 32 bits. */
typedef int Boolean; /* TRUE or FALSE value. */
typedef int ErrCode; /* ErrXXX or Success. */
typedef int FileHandle; /* OS file handle. */
typedef Uchar Pixel; /* Pixel type. */
typedef ErrCode FlicOpenFunc(struct _Flic *flic, const char *filename);
typedef ErrCode FlicCheckFrameFunc(struct _Flic *);
typedef ErrCode FlicSeekFunc(struct _Flic *, long offset);
typedef struct
{
Uchar r,g,b;
} Colour; /* One color map entry r,g,b 0-255. */
typedef struct
{
Pixel pixels[2];
} Pixels2; /* For word-oriented run length encoding */
/* Flic Header */
typedef struct
{
Long size; /* Size of flic including this header. */
Ushort type; /* Either FLI_TYPE or FLC_TYPE below. */
Ushort frames; /* Number of frames in flic. */
Ushort width; /* Flic width in pixels. */
Ushort height; /* Flic height in pixels. */
Ushort depth; /* Bits per pixel. (Always 8 now.) */
Ushort flags; /* FLI_FINISHED | FLI_LOOPED ideally. */
Long speed; /* Delay between frames. */
Short reserved1; /* Set to zero. */
Short created1;
Short created2;
//Ulong created; /* Date of flic creation. (FLC only.) */
Short creator1;
Short creator2;
//Ulong creator; /* Serial # of flic creator. (FLC only.) */
Short updated1;
Short updated2;
//Ulong updated; /* Date of flic update. (FLC only.) */
Short updater1;
Short updater2;
//Ulong updater; /* Serial # of flic updater. (FLC only.) */
Ushort aspect_dx; /* Width of square rectangle. (FLC only.) */
Ushort aspect_dy; /* Height of square rectangle. (FLC only.) */
Char reserved2[38]; /* Set to zero. */
Long oframe1; /* Offset to frame 1. (FLC only.) */
Long oframe2; /* Offset to frame 2. (FLC only.) */
Char reserved3[40]; /* Set to zero. */
} FlicHead;
typedef struct
{
Pixel *pixels; /* Set to AOOO:0000 for hardware. */
int width, height; /* Dimensions of screen. (320x200) */
char change_palette; /*True means that the flic changes the palette */
} FlicScreen; /* Device specific screen type. */
typedef struct
{
Ulong max_loop_count,
loop_count;
Ushort max_frame_index,
frame_index;
} FlicFrameStatus;
typedef struct
{
// lmlib_t *names;
long offset,
length;
}FlicLib;
typedef struct _Flic
{
FlicHead head; /* Flic file header. */
FILE *file; /* File handle. */
const char *name; /* Name from flic_open. Helps error reporting. */
int xoff,yoff; /* Offset to display flic at. */
FlicFrameStatus status;
FlicScreen screen;
FlicLib lib;
FlicOpenFunc *open;
FlicCheckFrameFunc *check_frame;
FlicSeekFunc *seek;
} Flic;
/* Values for FlicHead.type */
#define FLI_TYPE 0xAF11u /* 320x200 .FLI type ID */
#define FLC_TYPE 0xAF12u /* Variable rez .FLC type ID */
/* Values for FlicHead.flags */
#define FLI_FINISHED 0x0001
#define FLI_LOOPED 0x0002
/* Optional Prefix Header */
typedef struct
{
Long size; /* Size of prefix including header. */
Ushort type; /* Always PREFIX_TYPE. */
Short chunks; /* Number of subchunks in prefix. */
Char reserved[8];/* Always 0. */
} PrefixHead;
/* Value for PrefixHead.type */
#define PREFIX_TYPE 0xF100u
/* Frame Header */
typedef struct
{
Long size; /* Size of frame including header. */
Ushort type; /* Always FRAME_TYPE */
Short chunks; /* Number of chunks in frame. */
Char reserved[8];/* Always 0. */
} FrameHead;
/* Value for FrameHead.type */
#define FRAME_TYPE 0xF1FAu
/* Chunk Header */
typedef struct
{
Long size; /* Size of chunk including header. */
Ushort type; /* Value from ChunkTypes below. */
} ChunkHead;
typedef enum
{
COLOR_256 = 4, /* 256 level color pallette info. (FLC only.) */
DELTA_FLC = 7, /* Word-oriented delta compression. (FLC only.) */
COLOR_64 = 11, /* 64 level color pallette info. */
DELTA_FLI = 12, /* Byte-oriented delta compression. */
BLACK_FRAME = 13, /* whole frame is color 0 */
BYTE_RUN = 15, /* Byte run-length compression. */
LITERAL = 16, /* Uncompressed pixels. */
PSTAMP = 18, /* "Postage stamp" chunk. (FLC only.) */
} ChunkTypes;
//**************************************************************************
//
// Function prototypes.
//
//**************************************************************************
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void FlicInit(Flic *flic, unsigned screen_width, unsigned screen_height, char change_palette, char *Buffer);
ErrCode FlicOpen(Flic *flic, const char *filename);
void FlicSetOrigin(Flic *flic, unsigned x, unsigned y);
ErrCode FlicPlay(Flic *flic, Ulong max_loop);
void FlicClose(Flic *flic);
void FlicSeekFirst(Flic *flic);
int FlicAdvance(Flic *flic, BOOL fDecode);
int FlicAdvanceNoDecode(Flic *flic);
int FlicStart(char *filename, int width, int height, char *buffer, Flic *flic, char usepal);
void FlicStop(Flic *flic);
ErrCode FlicGetStats(char *filename, int width, int height, Flic *flic, int *piBufferSize, int *piColourPalSize);
ErrCode FlicGetColourPalette(CHAR *filename, int width, int height, CHAR **ppBuffer, INT *piNumColours);
CHAR *FlicSeekChunk(Flic *flic, INT iFrame, ChunkTypes eType, INT *piChunkSize);
INT FlicFindByteRunBeforeFrame(Flic *flic, INT iFrame);
ErrCode FlicFillBitmapData( Flic *flic, INT iPrevFrame, INT iFrame, HBITMAP hBitmap );
ErrCode FlicFillFrameData( Flic *flic, INT iPrevFrame, INT iFrame, CHAR *, INT * );
void FlicClearBitmap( HBITMAP hBitmap, INT iColourIndex );
#ifdef __cplusplus
}
#endif /* __cplusplus */
extern char FlicPal[768];
#endif
File diff suppressed because it is too large Load Diff
+215
View File
@@ -0,0 +1,215 @@
#ifndef __IMAGE_H
#define __IMAGE_H
#include "MemMan.h"
#include "imgfmt.h"
// The HIMAGE module provides a common interface for managing image data. This module
// includes:
// - A set of data structures representing image data. Data can be 8 or 16 bpp and/or
// compressed
// - A set of file loaders which load specific file formats into the internal data format
// - A set of blitters which blt the data to memory
// - A comprehensive automatic blitter which blits the appropriate type based on the
// image header.
// Defines for type of file readers
#define PCX_FILE_READER 0x1
#define TGA_FILE_READER 0x2
#define STCI_FILE_READER 0x4
#define TRLE_FILE_READER 0x8
#define UNKNOWN_FILE_READER 0x200
// Defines for buffer bit depth
#define BUFFER_8BPP 0x1
#define BUFFER_16BPP 0x2
// Defines for image charactoristics
#define IMAGE_COMPRESSED 0x0001
#define IMAGE_TRLECOMPRESSED 0x0002
#define IMAGE_PALETTE 0x0004
#define IMAGE_BITMAPDATA 0x0008
#define IMAGE_APPDATA 0x0010
#define IMAGE_ALLIMAGEDATA 0x000C
#define IMAGE_ALLDATA 0x001C
// Palette structure, mimics that of Win32
typedef struct tagSGPPaletteEntry
{
UINT8 peRed;
UINT8 peGreen;
UINT8 peBlue;
UINT8 peFlags;
} SGPPaletteEntry;
#define AUX_FULL_TILE 0x01
#define AUX_ANIMATED_TILE 0x02
#define AUX_DYNAMIC_TILE 0x04
#define AUX_INTERACTIVE_TILE 0x08
#define AUX_IGNORES_HEIGHT 0x10
#define AUX_USES_LAND_Z 0x20
typedef struct
{
UINT8 ubWallOrientation;
UINT8 ubNumberOfTiles;
UINT16 usTileLocIndex;
UINT8 ubUnused1[3];
UINT8 ubCurrentFrame;
UINT8 ubNumberOfFrames;
UINT8 fFlags;
UINT8 ubUnused[6];
} AuxObjectData;
typedef struct
{
INT8 bTileOffsetX;
INT8 bTileOffsetY;
} RelTileLoc; // relative tile location
// TRLE subimage structure, mirroring that of ST(C)I
typedef struct tagETRLEObject
{
UINT32 uiDataOffset;
UINT32 uiDataLength;
INT16 sOffsetX;
INT16 sOffsetY;
UINT16 usHeight;
UINT16 usWidth;
} ETRLEObject;
typedef struct tagETRLEData
{
PTR pPixData;
UINT32 uiSizePixData;
ETRLEObject * pETRLEObject;
UINT16 usNumberOfObjects;
} ETRLEData;
// Image header structure
typedef struct
{
UINT16 usWidth;
UINT16 usHeight;
UINT8 ubBitDepth;
UINT16 fFlags;
SGPFILENAME ImageFile;
UINT32 iFileLoader;
SGPPaletteEntry *pPalette;
UINT16 *pui16BPPPalette;
UINT8 * pAppData;
UINT32 uiAppDataSize;
// This union is used to describe each data type and is flexible to include the
// data strucutre of the compresssed format, once developed.
union
{
struct
{
PTR pImageData;
};
struct
{
PTR pCompressedImageData;
};
struct
{
UINT8 *p8BPPData;
};
struct
{
UINT16 *p16BPPData;
};
struct
{
UINT8 * pPixData8;
UINT32 uiSizePixData;
ETRLEObject * pETRLEObject;
UINT16 usNumberOfObjects;
};
};
} image_type, *HIMAGE;
#define SGPGetRValue(rgb) ((BYTE) (rgb))
#define SGPGetBValue(rgb) ((BYTE) ((rgb) >> 16))
#define SGPGetGValue(rgb) ((BYTE) (((UINT16) (rgb)) >> 8))
// *****************************************************************************
//
// Function prototypes
//
// *****************************************************************************
#ifdef __cplusplus
extern "C" {
#endif
// This function will return NULL if it fails, and call SetLastError() to set
// error information
HIMAGE CreateImage( SGPFILENAME ImageFile, UINT16 fContents );
// This function destroys the HIMAGE structure as well as its contents
BOOLEAN DestroyImage( HIMAGE hImage );
// This function releases data allocated to various parts of the image based
// on the contents flags passed as a parameter. If a contents flag is given
// and the image does not contain that data, no error is raised
BOOLEAN ReleaseImageData( HIMAGE hImage, UINT16 fContents );
// This function will attept to Load data from an existing image object's filename
// In this way, dynamic loading of image data can be done
BOOLEAN LoadImageData( HIMAGE hImage, UINT16 fContents );
// This function will run the appropriate copy function based on the type of HIMAGE object
BOOLEAN CopyImageToBuffer( HIMAGE hImage, UINT32 fBufferType, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
// The following blitters are used by the function above as well as clients
#ifndef NO_ZLIB_COMPRESSION
BOOLEAN Copy8BPPCompressedImageTo8BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
BOOLEAN Copy8BPPCompressedImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
BOOLEAN Copy16BPPCompressedImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
// This function will extract a compressed image into a non-compressed buffer
BOOLEAN Extract8BPPCompressedImageToBuffer( HIMAGE hImage, BYTE *pDestBuf );
BOOLEAN Extract16BPPCompressedImageToBuffer( HIMAGE hImage, BYTE *pDestBuf );
#endif
BOOLEAN Copy8BPPImageTo8BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
BOOLEAN Copy8BPPImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
BOOLEAN Copy16BPPImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
// This function will create a buffer in memory of ETRLE data, excluding palette
BOOLEAN GetETRLEImageData( HIMAGE hImage, ETRLEData *pBuffer );
// UTILITY FUNCTIONS
// Used to create a 16BPP Palette from an 8 bit palette, found in himage.c
UINT16 *Create16BPPPaletteShaded( SGPPaletteEntry *pPalette, UINT32 rscale, UINT32 gscale, UINT32 bscale, BOOLEAN mono);
UINT16 *Create16BPPPalette( SGPPaletteEntry *pPalette );
UINT16 Get16BPPColor( UINT32 RGBValue );
UINT32 GetRGBColor( UINT16 Value16BPP );
SGPPaletteEntry *ConvertRGBToPaletteEntry(UINT8 sbStart, UINT8 sbEnd, UINT8 *pOldPalette);
extern UINT16 gusAlphaMask;
extern UINT16 gusRedMask;
extern UINT16 gusGreenMask;
extern UINT16 gusBlueMask;
extern INT16 gusRedShift;
extern INT16 gusBlueShift;
extern INT16 gusGreenShift;
// used to convert 565 RGB data into different bit-formats
void ConvertRGBDistribution565To555( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
void ConvertRGBDistribution565To655( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
void ConvertRGBDistribution565To556( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
void ConvertRGBDistribution565ToAny( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
#ifdef __cplusplus
}
#endif
#endif
+92
View File
@@ -0,0 +1,92 @@
#if !defined( STCI_H )
#define STCI_H
// Sir-Tech's Crazy Image (STCI) file format specifications. Each file is composed of:
// 1 ImageFileHeader, uncompressed
// * Palette (STCI_INDEXED, size = uiNumberOfColours * PALETTE_ELEMENT_SIZE), uncompressed
// * SubRectInfo's (usNumberOfRects > 0, size = usNumberOfSubRects * sizeof(SubRectInfo) ), uncompressed
// * Bytes of image data, possibly compressed
#include "Types.h"
#define STCI_ID_STRING "STCI"
#define STCI_ID_LEN 4
#define STCI_ETRLE_COMPRESSED 0x0020
#define STCI_ZLIB_COMPRESSED 0x0010
#define STCI_INDEXED 0x0008
#define STCI_RGB 0x0004
#define STCI_ALPHA 0x0002
#define STCI_TRANSPARENT 0x0001
// ETRLE defines
#define COMPRESS_TRANSPARENT 0x80
#define COMPRESS_NON_TRANSPARENT 0x00
#define COMPRESS_RUN_LIMIT 0x7F
// NB if you're going to change the header definition:
// - make sure that everything in this header is nicely aligned
// - don't exceed the 64-byte maximum
typedef struct
{
UINT8 cID[STCI_ID_LEN];
UINT32 uiOriginalSize;
UINT32 uiStoredSize; // equal to uiOriginalSize if data uncompressed
UINT32 uiTransparentValue;
UINT32 fFlags;
UINT16 usHeight;
UINT16 usWidth;
union
{
struct
{
UINT32 uiRedMask;
UINT32 uiGreenMask;
UINT32 uiBlueMask;
UINT32 uiAlphaMask;
UINT8 ubRedDepth;
UINT8 ubGreenDepth;
UINT8 ubBlueDepth;
UINT8 ubAlphaDepth;
} RGB;
struct
{ // For indexed files, the palette will contain 3 separate bytes for red, green, and blue
UINT32 uiNumberOfColours;
UINT16 usNumberOfSubImages;
UINT8 ubRedDepth;
UINT8 ubGreenDepth;
UINT8 ubBlueDepth;
UINT8 cIndexedUnused[11];
} Indexed;
};
UINT8 ubDepth; // size in bits of one pixel as stored in the file
UINT32 uiAppDataSize;
UINT8 cUnused[15];
} STCIHeader;
#define STCI_HEADER_SIZE 64
typedef struct
{
UINT32 uiDataOffset;
UINT32 uiDataLength;
INT16 sOffsetX;
INT16 sOffsetY;
UINT16 usHeight;
UINT16 usWidth;
} STCISubImage;
#define STCI_SUBIMAGE_SIZE 16
typedef struct
{
UINT8 ubRed;
UINT8 ubGreen;
UINT8 ubBlue;
} STCIPaletteElement;
#define STCI_PALETTE_ELEMENT_SIZE 3
#define STCI_8BIT_PALETTE_SIZE 768
#endif
+463
View File
@@ -0,0 +1,463 @@
//**************************************************************************
//
// Filename : impTGA.c
//
// Purpose : .tga file importer
//
// Modification history :
//
// 20nov96:HJH - Creation
//
//**************************************************************************
//**************************************************************************
//
// Includes
//
//**************************************************************************
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "types.h"
#include "Fileman.h"
#include "memman.h"
#include "WCheck.h"
#include "himage.h"
#include "string.h"
#include "debug.h"
#if defined( JA2 ) || defined( UTIL )
#include "video.h"
#else
#include "video2.h"
#endif
#endif
//**************************************************************************
//
// Defines
//
//**************************************************************************
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
//**************************************************************************
//
// Function Prototypes
//
//**************************************************************************
BOOLEAN ReadUncompColMapImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents );
BOOLEAN ReadUncompRGBImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents );
BOOLEAN ReadRLEColMapImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents );
BOOLEAN ReadRLERGBImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents );
//BOOLEAN ConvertTGAToSystemBPPFormat( HIMAGE hImage );
//**************************************************************************
//
// Function Definitions
//
//**************************************************************************
BOOLEAN LoadTGAFileToImage( HIMAGE hImage, UINT16 fContents )
{
HWFILE hFile;
UINT8 uiImgID, uiColMap, uiType;
UINT32 uiBytesRead;
BOOLEAN fReturnVal = FALSE;
Assert( hImage != NULL );
CHECKF( FileExists( hImage->ImageFile ) );
hFile = FileOpen( hImage->ImageFile, FILE_ACCESS_READ, FALSE );
CHECKF( hFile );
if ( !FileRead( hFile, &uiImgID, sizeof(UINT8), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiColMap, sizeof(UINT8), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiType, sizeof(UINT8), &uiBytesRead ) )
goto end;
switch( uiType )
{
case 1:
fReturnVal = ReadUncompColMapImage( hImage, hFile, uiImgID, uiColMap, fContents );
break;
case 2:
fReturnVal = ReadUncompRGBImage( hImage, hFile, uiImgID, uiColMap, fContents );
break;
case 9:
fReturnVal = ReadRLEColMapImage( hImage, hFile, uiImgID, uiColMap, fContents );
break;
case 10:
fReturnVal = ReadRLERGBImage( hImage, hFile, uiImgID, uiColMap, fContents );
break;
default:
break;
}
// Set remaining values
end:
FileClose( hFile );
return( fReturnVal );
}
//**************************************************************************
//
// ReadUncompColMapImage
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// 20nov96:HJH -> creation
//
//**************************************************************************
BOOLEAN ReadUncompColMapImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents )
{
return( FALSE );
}
//**************************************************************************
//
// ReadUncompRGBImage
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// 20nov96:HJH -> creation
//
//**************************************************************************
BOOLEAN ReadUncompRGBImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents )
{
UINT8 *pBMData;
UINT8 *pBMPtr;
UINT16 uiColMapOrigin;
UINT16 uiColMapLength;
UINT8 uiColMapEntrySize;
UINT32 uiBytesRead;
UINT16 uiXOrg;
UINT16 uiYOrg;
UINT16 uiWidth;
UINT16 uiHeight;
UINT8 uiImagePixelSize;
UINT8 uiImageDescriptor;
UINT32 iNumValues;
UINT16 cnt;
UINT32 i;
UINT8 r;
UINT8 g;
UINT8 b;
if ( !FileRead( hFile, &uiColMapOrigin, sizeof(UINT16), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiColMapLength, sizeof(UINT16), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiColMapEntrySize, sizeof(UINT8), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiXOrg, sizeof(UINT16), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiYOrg, sizeof(UINT16), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiWidth, sizeof(UINT16), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiHeight, sizeof(UINT16), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiImagePixelSize, sizeof(UINT8), &uiBytesRead ) )
goto end;
if ( !FileRead( hFile, &uiImageDescriptor, sizeof(UINT8), &uiBytesRead ) )
goto end;
// skip the id
FileSeek( hFile, uiImgID, FILE_SEEK_FROM_CURRENT );
// skip the colour map
if ( uiColMap != 0 )
{
FileSeek( hFile, uiColMapLength * (uiImagePixelSize / 8), FILE_SEEK_FROM_CURRENT );
}
// Set some HIMAGE data values
hImage->usWidth = uiWidth;
hImage->usHeight = uiHeight;
hImage->ubBitDepth = uiImagePixelSize;
// Allocate memory based on bpp, height, width
// Only do if contents flag is appropriate
if ( fContents & IMAGE_BITMAPDATA )
{
if ( uiImagePixelSize == 16 )
{
iNumValues = uiWidth * uiHeight;
hImage->p16BPPData = (UINT16 *) MemAlloc( iNumValues * (uiImagePixelSize / 8) );
if ( hImage->p16BPPData == NULL )
goto end;
// Get data pointer
pBMData = hImage->p8BPPData;
// Start at end
pBMData += uiWidth * ( uiHeight - 1 ) * (uiImagePixelSize / 8);
// Data is stored top-bottom - reverse for SGP HIMAGE format
for ( cnt = 0; cnt < uiHeight-1; cnt++ )
{
if ( !FileRead( hFile, pBMData, uiWidth*2, &uiBytesRead ) )
goto freeEnd;
pBMData -= uiWidth * 2;
}
// Do first row
if ( !FileRead( hFile, pBMData, uiWidth*2, &uiBytesRead ) )
goto freeEnd;
// Convert TGA 5,5,5 16 BPP data into current system 16 BPP Data
//ConvertTGAToSystemBPPFormat( hImage );
hImage->fFlags |= IMAGE_BITMAPDATA;
}
if ( uiImagePixelSize == 24 )
{
hImage->p8BPPData = (UINT8 *) MemAlloc( uiWidth * uiHeight * (uiImagePixelSize / 8) );
if ( hImage->p8BPPData == NULL )
goto end;
// Get data pointer
pBMData = (UINT8*)hImage->p8BPPData;
// Start at end
pBMPtr = pBMData + uiWidth * ( uiHeight - 1 ) * 3;
iNumValues = uiWidth * uiHeight;
for ( cnt = 0; cnt < uiHeight; cnt++ )
{
for ( i=0 ; i < uiWidth; i++ )
{
if ( !FileRead( hFile, &b, sizeof(UINT8), &uiBytesRead ) )
goto freeEnd;
if ( !FileRead( hFile, &g, sizeof(UINT8), &uiBytesRead ) )
goto freeEnd;
if ( !FileRead( hFile, &r, sizeof(UINT8), &uiBytesRead ) )
goto freeEnd;
pBMPtr[ i*3 ] = r;
pBMPtr[ i*3+1 ] = g;
pBMPtr[ i*3+2 ] = b;
}
pBMPtr -= uiWidth * 3;
}
hImage->fFlags |= IMAGE_BITMAPDATA;
}
#if 0
// 32 bit not yet allowed in SGP
else if ( uiImagePixelSize == 32 )
{
iNumValues = uiWidth * uiHeight;
for ( i=0 ; i<iNumValues; i++ )
{
if ( !FileRead( hFile, &b, sizeof(UINT8), &uiBytesRead ) )
goto freeEnd;
if ( !FileRead( hFile, &g, sizeof(UINT8), &uiBytesRead ) )
goto freeEnd;
if ( !FileRead( hFile, &r, sizeof(UINT8), &uiBytesRead ) )
goto freeEnd;
if ( !FileRead( hFile, &a, sizeof(UINT8), &uiBytesRead ) )
goto freeEnd;
pBMData[ i*3 ] = r;
pBMData[ i*3+1 ] = g;
pBMData[ i*3+2 ] = b;
}
}
#endif
}
return( TRUE );
end:
return( FALSE );
freeEnd:
MemFree( pBMData );
return( FALSE );
}
//**************************************************************************
//
// ReadRLEColMapImage
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// 20nov96:HJH -> creation
//
//**************************************************************************
BOOLEAN ReadRLEColMapImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents )
{
return( FALSE );
}
//**************************************************************************
//
// ReadRLERGBImage
//
//
//
// Parameter List :
// Return Value :
// Modification history :
//
// 20nov96:HJH -> creation
//
//**************************************************************************
BOOLEAN ReadRLERGBImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents )
{
return( FALSE );
}
/*
BOOLEAN ConvertTGAToSystemBPPFormat( HIMAGE hImage )
{
UINT16 usX, usY;
UINT16 Old16BPPValue;
UINT16 *pData;
UINT16 usR, usG, usB;
float scale_val;
UINT32 uiRBitMask;
UINT32 uiGBitMask;
UINT32 uiBBitMask;
UINT8 ubRNewShift;
UINT8 ubGNewShift;
UINT8 ubBNewShift;
UINT8 ubScaleR;
UINT8 ubScaleB;
UINT8 ubScaleG;
// Basic algorithm for coonverting to different rgb distributions
// Get current Pixel Format from DirectDraw
CHECKF( GetPrimaryRGBDistributionMasks( &uiRBitMask, &uiGBitMask, &uiBBitMask ) );
// Only convert if different
if ( uiRBitMask == 0x7c00 && uiGBitMask == 0x3e0 && uiBBitMask == 0x1f )
{
return( TRUE );
}
// Default values
ubScaleR = 0;
ubScaleG = 0;
ubScaleB = 0;
ubRNewShift = 10;
ubGNewShift = 5;
ubBNewShift = 0;
// Determine values
switch( uiBBitMask )
{
case 0x3f: // 0000000000111111 pixel mask for blue
// 5-5-6
ubRNewShift = 11;
ubGNewShift = 6;
ubScaleB = 1;
break;
case 0x1f: // 0000000000011111 pixel mask for blue
switch( uiGBitMask )
{
case 0x7e0: // 0000011111100000 pixel mask for green
// 5-6-5
ubRNewShift = 11;
ubScaleG = 1;
break;
case 0x3e0: // 0000001111100000 pixel mask for green
switch( uiRBitMask )
{
case 0xfc00: // 1111110000000000 pixel mask for red
// 6-5-5
ubScaleR = 1;
break;
}
break;
}
break;
}
pData = hImage->pui16BPPPalette;
usX = 0;
do
{
usY = 0;
do
{
// Get Old 5,5,5 value
Old16BPPValue = hImage->p16BPPData[ usX * hImage->usWidth + usY ];
// Get component r,g,b values AT 5 5 5
usR = ( Old16BPPValue & 0x7c00 ) >> 10;
usG = ( Old16BPPValue & 0x3e0 ) >> 5;
usB = Old16BPPValue & 0x1f;
// Scale accordingly
usR = usR << ubScaleR;
usG = usG << ubScaleG;
usB = usB << ubScaleB;
hImage->p16BPPData[ usX * hImage->usWidth + usY ] = ((UINT16) ( ( usR << ubRNewShift | usG << ubGNewShift ) | usB ) );
usY++;
} while( usY < hImage->usWidth );
usX++;
} while( usX < hImage->usHeight );
return( TRUE );
}
*/
+54
View File
@@ -0,0 +1,54 @@
//**************************************************************************
//
// Filename : impTGA.h
//
// Purpose : .tga file importer function prototypes
//
// Modification history :
//
// 20nov96:HJH - Creation
//
//**************************************************************************
#ifndef _impTGA_h
#define _impTGA_h
//**************************************************************************
//
// Includes
//
//**************************************************************************
#include "types.h"
#include "himage.h"
//**************************************************************************
//
// Defines
//
//**************************************************************************
//**************************************************************************
//
// Typedefs
//
//**************************************************************************
//**************************************************************************
//
// Function Prototypes
//
//**************************************************************************
#ifdef __cplusplus
extern "C" {
#endif
BOOLEAN LoadTGAFileToImage( HIMAGE hImage, UINT16 fContents );
#ifdef __cplusplus
}
#endif
#endif
File diff suppressed because it is too large Load Diff
+140
View File
@@ -0,0 +1,140 @@
#ifndef __INPUT_
#define __INPUT_
#include "types.h"
#define SCAN_CODE_MASK 0xff0000
#define EXT_CODE_MASK 0x01000000
#define TRANSITION_MASK 0x80000000
#define KEY_DOWN 0x0001
#define KEY_UP 0x0002
#define KEY_REPEAT 0x0004
#define LEFT_BUTTON_DOWN 0x0008
#define LEFT_BUTTON_UP 0x0010
#define LEFT_BUTTON_DBL_CLK 0x0020
#define LEFT_BUTTON_REPEAT 0x0040
#define RIGHT_BUTTON_DOWN 0x0080
#define RIGHT_BUTTON_UP 0x0100
#define RIGHT_BUTTON_REPEAT 0x0200
#define MOUSE_POS 0x0400
#define MOUSE_WHEEL 0x0800
#define SHIFT_DOWN 0x01
#define CTRL_DOWN 0x02
#define ALT_DOWN 0x04
#define MAX_STRING_INPUT 64
#define DBL_CLK_TIME 300 // Increased by Alex, Jun-10-97, 200 felt too short
#define BUTTON_REPEAT_TIMEOUT 250
#define BUTTON_REPEAT_TIME 50
typedef struct
{
UINT32 uiTimeStamp;
UINT16 usKeyState;
UINT16 usEvent;
UINT32 usParam;
UINT32 uiParam;
} InputAtom;
//Mouse pos extracting macros from InputAtom
#define GETYPOS(a) HIWORD(((a)->uiParam))
#define GETXPOS(a) LOWORD(((a)->uiParam))
typedef struct StringInput
{
UINT16 *pString;
UINT16 *pOriginalString;
UINT16 *pFilter;
UINT16 usMaxStringLength;
UINT16 usCurrentStringLength;
UINT16 usStringOffset;
UINT16 usLastCharacter;
BOOLEAN fInsertMode;
BOOLEAN fFocus;
struct StringInput *pPreviousString;
struct StringInput *pNextString;
} StringInput;
#ifdef __cplusplus
extern "C" {
#endif
extern BOOLEAN InitializeInputManager(void);
extern void ShutdownInputManager(void);
extern BOOLEAN DequeueEvent(InputAtom *Event);
extern void QueueEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam);
extern void KeyDown(UINT32 usParam, UINT32 uiParam);
extern void KeyUp(UINT32 usParam, UINT32 uiParam);
extern void EnableDoubleClk(void);
extern void DisableDoubleClk(void);
extern void GetMousePos(SGPPoint *Point);
extern StringInput *InitStringInput(UINT16 *pInputString, UINT16 usLength, UINT16 *pFilter);
extern void LinkPreviousString(StringInput *pCurrentString, StringInput *pPreviousString);
extern void LinkNextString(StringInput *pCurrentString, StringInput *pNextString);
extern UINT16 GetStringLastInput(void);
extern BOOLEAN StringInputHasFocus(void);
extern BOOLEAN SetStringFocus(StringInput *pStringDescriptor);
extern UINT16 GetCursorPositionInString(StringInput *pStringDescriptor);
extern UINT16 GetStringInputState(void);
extern BOOLEAN StringHasFocus(StringInput *pStringDescriptor);
extern UINT16 *GetString(StringInput *pStringDescriptor);
extern void EndStringInput(StringInput *pStringDescriptor);
extern BOOLEAN DequeueSpecificEvent(InputAtom *Event, UINT32 uiMaskFlags );
extern void RestrictMouseToXYXY(UINT16 usX1, UINT16 usY1, UINT16 usX2, UINT16 usY2);
extern void RestrictMouseCursor(SGPRect *pRectangle);
extern void FreeMouseCursor(void);
extern BOOLEAN IsCursorRestricted( void );
extern void GetRestrictedClipCursor( SGPRect *pRectangle );
extern void RestoreCursorClipRect( void );
void SimulateMouseMovement( UINT32 uiNewXPos, UINT32 uiNewYPos );
BOOLEAN InputEventInside(InputAtom *Event, UINT32 uiX1, UINT32 uiY1, UINT32 uiX2, UINT32 uiY2);
INT16 GetMouseWheelDeltaValue( UINT32 wParam );
extern void DequeueAllKeyBoardEvents();
extern BOOLEAN gfKeyState[256]; // TRUE = Pressed, FALSE = Not Pressed
extern UINT16 gusMouseXPos; // X position of the mouse on screen
extern UINT16 gusMouseYPos; // y position of the mouse on screen
extern BOOLEAN gfLeftButtonState; // TRUE = Pressed, FALSE = Not Pressed
extern BOOLEAN gfRightButtonState; // TRUE = Pressed, FALSE = Not Pressed
extern BOOLEAN gfSGPInputReceived;
#define _KeyDown(a) gfKeyState[(a)]
#define _LeftButtonDown gfLeftButtonState
#define _RightButtonDown gfRightButtonState
#define _MouseXPos gusMouseXPos
#define _MouseYPos gusMouseYPos
// NOTE: this may not be the absolute most-latest current mouse co-ordinates, use GetCursorPos for that
#define _gusMouseInside(x1,y1,x2,y2) ((gusMouseXPos >= x1) && (gusMouseXPos <= x2) && (gusMouseYPos >= y1) && (gusMouseYPos <= y2))
#define _EvType(a) ((InputAtom *)(a))->usEvent
#define _EvTimeStamp(a) ((InputAtom *)(a))->uiTimeStamp
#define _EvKey(a) ((InputAtom *)(a))->usParam
#define _EvMouseX(a) (UINT16)(((InputAtom *)(a))->uiParam & 0x0000ffff)
#define _EvMouseY(a) (UINT16)((((InputAtom *)(a))->uiParam & 0xffff0000) >> 16)
#define _EvShiftDown(a) (((InputAtom *)(a))->usKeyState & SHIFT_DOWN)
#define _EvCtrlDown(a) (((InputAtom *)(a))->usKeyState & CTRL_DOWN)
#define _EvAltDown(a) (((InputAtom *)(a))->usKeyState & ALT_DOWN)
#ifdef __cplusplus
}
#endif
#endif
+690
View File
@@ -0,0 +1,690 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "line.h"
#endif
//**************************************************************************
//
// Example Usage
//
//**************************************************************************
// SEND THE PITCH IN BYTES
// SetClippingRegionAndImageWidth( uiPitch, 15, 15, 30, 30 );
//
// LineDraw( TRUE, 10, 10, 200, 200, colour, pImageData);
// OR
// RectangleDraw( TRUE, 10, 10, 200, 200, colour, pImageData);
//**************************************************************************
//
// Line Drawing Functions
//
//**************************************************************************
int giImageWidth=0;
int giClipXMin=0;
int giClipXMax=0;
int giClipYMin=0;
int giClipYMax=0;
void DrawHorizontalRun(char **ScreenPtr, int XAdvance, int RunLength,
int Color, int ScreenWidth);
void DrawVerticalRun(char **ScreenPtr, int XAdvance, int RunLength,
int Color, int ScreenWidth);
void DrawHorizontalRun8(char **ScreenPtr, int XAdvance,
int RunLength, int Color, int ScreenWidth);
void DrawVerticalRun8(char **ScreenPtr, int XAdvance,
int RunLength, int Color, int ScreenWidth);
void SetClippingRegionAndImageWidth(
int iImageWidth,
int iClipStartX,
int iClipStartY,
int iClipWidth,
int iClipHeight
)
{
giImageWidth = iImageWidth;
giClipXMin = iClipStartX;
giClipXMax = iClipStartX + iClipWidth-1;
giClipYMin = iClipStartY;
giClipYMax = iClipStartY + iClipHeight-1;
}
BOOL Clipt( FLOAT denom, FLOAT num, FLOAT *tE, FLOAT *tL )
{
FLOAT t;
BOOL accept;
accept = TRUE;
if ( denom > 0.0f )
{
t = num/denom;
if ( t > *tL )
accept = FALSE;
else if ( t > *tE )
*tE = t;
}
else if ( denom < 0.0f )
{
t = num/denom;
if ( t < *tE )
accept = FALSE;
else if ( t < *tL )
*tL = t;
}
else if ( num > 0 )
accept = FALSE;
return(accept);
}
BOOL ClipPoint( int x, int y )
{
return( x <= giClipXMax && x >= giClipXMin &&
y <= giClipYMax && y >= giClipYMin );
}
BOOL Clip2D( int *ix0, int *iy0, int *ix1, int *iy1 )
{
BOOL visible;
FLOAT te, tl;
FLOAT dx, dy;
FLOAT x0, y0, x1, y1;
x0 = (FLOAT)*ix0;
x1 = (FLOAT)*ix1;
y0 = (FLOAT)*iy0;
y1 = (FLOAT)*iy1;
dx = x1-x0;
dy = y1-y0;
visible = FALSE;
if ( dx == 0.0 && dy == 0.0 && ClipPoint(*ix0,*iy0) )
visible = TRUE;
else
{
te = 0.0f;
tl = 1.0f;
if ( Clipt( dx, (FLOAT)giClipXMin-x0, &te, &tl ) )
{
if ( Clipt(-dx, x0-(FLOAT)giClipXMax, &te, &tl ) )
{
if ( Clipt(dy, (FLOAT)giClipYMin-y0, &te, &tl ) )
{
if ( Clipt(-dy, y0-(FLOAT)giClipYMax, &te, &tl ) )
{
visible = TRUE;
if ( tl < 1.0f )
{
x1 = x0 + tl*dx;
y1 = y0 + tl*dy;
}
if ( te > 0 )
{
x0 = x0 + te*dx;
y0 = y0 + te*dy;
}
}
}
}
}
}
*ix0 = (int)x0;
*ix1 = (int)x1;
*iy0 = (int)y0;
*iy1 = (int)y1;
return( visible );
}
// (jonathanl) to save me having to cast all the previous code
void LineDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr)
{
LineDraw( fClip, XStart, YStart, XEnd, YEnd, Color, (char *)ScreenPtr);
}
/* Draws a line between the specified endpoints in color Color. */
void LineDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, char *ScreenPtr)
{
int Temp, AdjUp, AdjDown, ErrorTerm, XAdvance, XDelta, YDelta;
int WholeStep, InitialPixelCount, FinalPixelCount, i, RunLength;
int ScreenWidth=giImageWidth/2;
char col2 = Color>>8;
char col1 = Color & 0x00FF;
if ( fClip )
{
if ( !Clip2D( &XStart, &YStart, &XEnd, &YEnd ) )
return;
}
/* We'll always draw top to bottom, to reduce the number of cases we have to
handle, and to make lines between the same endpoints draw the same pixels */
if (YStart > YEnd) {
Temp = YStart;
YStart = YEnd;
YEnd = Temp;
Temp = XStart;
XStart = XEnd;
XEnd = Temp;
}
// point to the bitmap address first pixel to draw
ScreenPtr = ScreenPtr + YStart*giImageWidth + XStart*2;
/* Figure out whether we're going left or right, and how far we're
going horizontally */
if ((XDelta = XEnd - XStart) < 0)
{
XAdvance = -1;
XDelta = -XDelta;
}
else
{
XAdvance = 1;
}
/* Figure out how far we're going vertically */
YDelta = YEnd - YStart;
/* Special-case horizontal, vertical, and diagonal lines, for speed
and to avoid nasty boundary conditions and division by 0 */
if (XDelta == 0)
{
/* Vertical line */
for (i=0; i<=YDelta; i++)
{
ScreenPtr[0] = col1;
ScreenPtr[1] = col2;
ScreenPtr += giImageWidth;
}
return;
}
if (YDelta == 0)
{
/* Horizontal line */
for (i=0; i<=XDelta; i++)
{
ScreenPtr[0] = col1;
ScreenPtr[1] = col2;
ScreenPtr += XAdvance*2;
}
return;
}
if (XDelta == YDelta)
{
/* Diagonal line */
for (i=0; i<=XDelta; i++)
{
ScreenPtr[0] = col1;
ScreenPtr[1] = col2;
ScreenPtr += (XAdvance*2) + giImageWidth;
}
return;
}
/* Determine whether the line is X or Y major, and handle accordingly */
if (XDelta >= YDelta)
{
/* X major line */
/* Minimum # of pixels in a run in this line */
WholeStep = XDelta / YDelta;
/* Error term adjust each time Y steps by 1; used to tell when one
extra pixel should be drawn as part of a run, to account for
fractional steps along the X axis per 1-pixel steps along Y */
AdjUp = (XDelta % YDelta) * 2;
/* Error term adjust when the error term turns over, used to factor
out the X step made at that time */
AdjDown = YDelta * 2;
/* Initial error term; reflects an initial step of 0.5 along the Y
axis */
ErrorTerm = (XDelta % YDelta) - (YDelta * 2);
/* The initial and last runs are partial, because Y advances only 0.5
for these runs, rather than 1. Divide one full run, plus the
initial pixel, between the initial and last runs */
InitialPixelCount = (WholeStep / 2) + 1;
FinalPixelCount = InitialPixelCount;
/* If the basic run length is even and there's no fractional
advance, we have one pixel that could go to either the initial
or last partial run, which we'll arbitrarily allocate to the
last run */
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
{
InitialPixelCount--;
}
/* If there're an odd number of pixels per run, we have 1 pixel that can't
be allocated to either the initial or last partial run, so we'll add 0.5
to error term so this pixel will be handled by the normal full-run loop */
if ((WholeStep & 0x01) != 0)
{
ErrorTerm += YDelta;
}
/* Draw the first, partial run of pixels */
DrawHorizontalRun(&ScreenPtr, XAdvance, InitialPixelCount, Color, ScreenWidth);
/* Draw all full runs */
for (i=0; i<(YDelta-1); i++)
{
RunLength = WholeStep; /* run is at least this long */
/* Advance the error term and add an extra pixel if the error
term so indicates */
if ((ErrorTerm += AdjUp) > 0)
{
RunLength++;
ErrorTerm -= AdjDown; /* reset the error term */
}
/* Draw this scan line's run */
DrawHorizontalRun(&ScreenPtr, XAdvance, RunLength, Color, ScreenWidth);
}
/* Draw the final run of pixels */
DrawHorizontalRun(&ScreenPtr, XAdvance, FinalPixelCount, Color, ScreenWidth);
return;
}
else
{
/* Y major line */
/* Minimum # of pixels in a run in this line */
WholeStep = YDelta / XDelta;
/* Error term adjust each time X steps by 1; used to tell when 1 extra
pixel should be drawn as part of a run, to account for
fractional steps along the Y axis per 1-pixel steps along X */
AdjUp = (YDelta % XDelta) * 2;
/* Error term adjust when the error term turns over, used to factor
out the Y step made at that time */
AdjDown = XDelta * 2;
/* Initial error term; reflects initial step of 0.5 along the X axis */
ErrorTerm = (YDelta % XDelta) - (XDelta * 2);
/* The initial and last runs are partial, because X advances only 0.5
for these runs, rather than 1. Divide one full run, plus the
initial pixel, between the initial and last runs */
InitialPixelCount = (WholeStep / 2) + 1;
FinalPixelCount = InitialPixelCount;
/* If the basic run length is even and there's no fractional advance, we
have 1 pixel that could go to either the initial or last partial run,
which we'll arbitrarily allocate to the last run */
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
{
InitialPixelCount--;
}
/* If there are an odd number of pixels per run, we have one pixel
that can't be allocated to either the initial or last partial
run, so we'll add 0.5 to the error term so this pixel will be
handled by the normal full-run loop */
if ((WholeStep & 0x01) != 0)
{
ErrorTerm += XDelta;
}
/* Draw the first, partial run of pixels */
DrawVerticalRun(&ScreenPtr, XAdvance, InitialPixelCount, Color, ScreenWidth);
/* Draw all full runs */
for (i=0; i<(XDelta-1); i++)
{
RunLength = WholeStep; /* run is at least this long */
/* Advance the error term and add an extra pixel if the error
term so indicates */
if ((ErrorTerm += AdjUp) > 0)
{
RunLength++;
ErrorTerm -= AdjDown; /* reset the error term */
}
/* Draw this scan line's run */
DrawVerticalRun(&ScreenPtr, XAdvance, RunLength, Color, ScreenWidth);
}
/* Draw the final run of pixels */
DrawVerticalRun(&ScreenPtr, XAdvance, FinalPixelCount, Color, ScreenWidth);
return;
}
}
//Draws a pixel in the specified color
void PixelDraw( BOOLEAN fClip, INT32 xp, INT32 yp, INT16 sColor, INT8 *pScreen )
{
INT8 col2 = sColor >> 8;
INT8 col1 = sColor & 0x00ff;
if ( fClip )
{
if ( !ClipPoint( xp, yp ) )
return;
}
// point to the bitmap address first pixel to draw
pScreen += yp * giImageWidth + xp * 2;
pScreen[ 0 ] = col1;
pScreen[ 1 ] = col2;
}
/* Draws a horizontal run of pixels, then advances the bitmap pointer to
the first pixel of the next run. */
void DrawHorizontalRun(char **ScreenPtr, int XAdvance,
int RunLength, int Color, int ScreenWidth)
{
int i;
char *WorkingScreenPtr = *ScreenPtr;
char col2 = Color>>8;
char col1 = Color & 0x00FF;
for (i=0; i<RunLength; i++)
{
WorkingScreenPtr[0] = col1;
WorkingScreenPtr[1] = col2;
WorkingScreenPtr += XAdvance*2;
}
/* Advance to the next scan line */
WorkingScreenPtr += giImageWidth;
*ScreenPtr = WorkingScreenPtr;
}
/* Draws a vertical run of pixels, then advances the bitmap pointer to
the first pixel of the next run. */
void DrawVerticalRun(char **ScreenPtr, int XAdvance,
int RunLength, int Color, int ScreenWidth)
{
int i;
char *WorkingScreenPtr = *ScreenPtr;
char col2 = Color>>8;
char col1 = Color & 0x00FF;
for (i=0; i<RunLength; i++)
{
WorkingScreenPtr[0] = col1;
WorkingScreenPtr[1] = col2;
WorkingScreenPtr += giImageWidth;
}
/* Advance to the next column */
WorkingScreenPtr += XAdvance*2;
*ScreenPtr = WorkingScreenPtr;
}
/* Draws a rectangle between the specified endpoints in color Color. */
template void RectangleDraw<unsigned char *>(BOOL, int, int, int, int, short, unsigned char *);
template <typename string7>
void RectangleDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, string7 ScreenPtr)
{
LineDraw( fClip, XStart, YStart, XEnd, YStart, Color, ScreenPtr);
LineDraw( fClip, XStart, YEnd, XEnd, YEnd, Color, ScreenPtr);
LineDraw( fClip, XStart, YStart, XStart, YEnd, Color, ScreenPtr);
LineDraw( fClip, XEnd, YStart, XEnd, YEnd, Color, ScreenPtr);
}
/***********************************************************************************
* 8-Bit Versions
*
*
*
* Added by Derek Beland
***********************************************************************************/
/* Draws a rectangle between the specified endpoints in color Color. */
template void RectangleDraw8<unsigned char *>(BOOL, int, int ,int ,int, short, unsigned char *);
template <typename string7>
void RectangleDraw8( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, string7 ScreenPtr)
{
LineDraw8( fClip, XStart, YStart, XEnd, YStart, Color, (char *)ScreenPtr);
LineDraw8( fClip, XStart, YEnd, XEnd, YEnd, Color, (char *)ScreenPtr);
LineDraw8( fClip, XStart, YStart, XStart, YEnd, Color, (char *)ScreenPtr);
LineDraw8( fClip, XEnd, YStart, XEnd, YEnd, Color, (char *)ScreenPtr);
}
/* Draws a line between the specified endpoints in color Color. */
void LineDraw8( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, char *ScreenPtr)
{
int Temp, AdjUp, AdjDown, ErrorTerm, XAdvance, XDelta, YDelta;
int WholeStep, InitialPixelCount, FinalPixelCount, i, RunLength;
int ScreenWidth = giImageWidth;
char col2 = Color>>8;
char col1 = Color & 0x00FF;
if ( fClip )
{
if ( !Clip2D( &XStart, &YStart, &XEnd, &YEnd ) )
return;
}
/* We'll always draw top to bottom, to reduce the number of cases we have to
handle, and to make lines between the same endpoints draw the same pixels */
if (YStart > YEnd) {
Temp = YStart;
YStart = YEnd;
YEnd = Temp;
Temp = XStart;
XStart = XEnd;
XEnd = Temp;
}
// point to the bitmap address first pixel to draw
ScreenPtr = ScreenPtr + YStart*giImageWidth + XStart;
/* Figure out whether we're going left or right, and how far we're
going horizontally */
if ((XDelta = XEnd - XStart) < 0)
{
XAdvance = -1;
XDelta = -XDelta;
}
else
{
XAdvance = 1;
}
/* Figure out how far we're going vertically */
YDelta = YEnd - YStart;
/* Special-case horizontal, vertical, and diagonal lines, for speed
and to avoid nasty boundary conditions and division by 0 */
if (XDelta == 0)
{
/* Vertical line */
for (i=0; i<=YDelta; i++)
{
*ScreenPtr = col1;
ScreenPtr += giImageWidth;
}
return;
}
if (YDelta == 0)
{
/* Horizontal line */
for (i=0; i<=XDelta; i++)
{
*ScreenPtr = col1;
ScreenPtr += XAdvance;
}
return;
}
if (XDelta == YDelta)
{
/* Diagonal line */
for (i=0; i<=XDelta; i++)
{
*ScreenPtr = col1;
ScreenPtr += (XAdvance + giImageWidth);
}
return;
}
/* Determine whether the line is X or Y major, and handle accordingly */
if (XDelta >= YDelta)
{
/* X major line */
/* Minimum # of pixels in a run in this line */
WholeStep = XDelta / YDelta;
/* Error term adjust each time Y steps by 1; used to tell when one
extra pixel should be drawn as part of a run, to account for
fractional steps along the X axis per 1-pixel steps along Y */
AdjUp = (XDelta % YDelta) * 2;
/* Error term adjust when the error term turns over, used to factor
out the X step made at that time */
AdjDown = YDelta * 2;
/* Initial error term; reflects an initial step of 0.5 along the Y
axis */
ErrorTerm = (XDelta % YDelta) - (YDelta * 2);
/* The initial and last runs are partial, because Y advances only 0.5
for these runs, rather than 1. Divide one full run, plus the
initial pixel, between the initial and last runs */
InitialPixelCount = (WholeStep / 2) + 1;
FinalPixelCount = InitialPixelCount;
/* If the basic run length is even and there's no fractional
advance, we have one pixel that could go to either the initial
or last partial run, which we'll arbitrarily allocate to the
last run */
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
{
InitialPixelCount--;
}
/* If there're an odd number of pixels per run, we have 1 pixel that can't
be allocated to either the initial or last partial run, so we'll add 0.5
to error term so this pixel will be handled by the normal full-run loop */
if ((WholeStep & 0x01) != 0)
{
ErrorTerm += YDelta;
}
/* Draw the first, partial run of pixels */
DrawHorizontalRun8(&ScreenPtr, XAdvance, InitialPixelCount, Color, ScreenWidth);
/* Draw all full runs */
for (i=0; i<(YDelta-1); i++)
{
RunLength = WholeStep; /* run is at least this long */
/* Advance the error term and add an extra pixel if the error
term so indicates */
if ((ErrorTerm += AdjUp) > 0)
{
RunLength++;
ErrorTerm -= AdjDown; /* reset the error term */
}
/* Draw this scan line's run */
DrawHorizontalRun8(&ScreenPtr, XAdvance, RunLength, Color, ScreenWidth);
}
/* Draw the final run of pixels */
DrawHorizontalRun8(&ScreenPtr, XAdvance, FinalPixelCount, Color, ScreenWidth);
return;
}
else
{
/* Y major line */
/* Minimum # of pixels in a run in this line */
WholeStep = YDelta / XDelta;
/* Error term adjust each time X steps by 1; used to tell when 1 extra
pixel should be drawn as part of a run, to account for
fractional steps along the Y axis per 1-pixel steps along X */
AdjUp = (YDelta % XDelta) * 2;
/* Error term adjust when the error term turns over, used to factor
out the Y step made at that time */
AdjDown = XDelta * 2;
/* Initial error term; reflects initial step of 0.5 along the X axis */
ErrorTerm = (YDelta % XDelta) - (XDelta * 2);
/* The initial and last runs are partial, because X advances only 0.5
for these runs, rather than 1. Divide one full run, plus the
initial pixel, between the initial and last runs */
InitialPixelCount = (WholeStep / 2) + 1;
FinalPixelCount = InitialPixelCount;
/* If the basic run length is even and there's no fractional advance, we
have 1 pixel that could go to either the initial or last partial run,
which we'll arbitrarily allocate to the last run */
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
{
InitialPixelCount--;
}
/* If there are an odd number of pixels per run, we have one pixel
that can't be allocated to either the initial or last partial
run, so we'll add 0.5 to the error term so this pixel will be
handled by the normal full-run loop */
if ((WholeStep & 0x01) != 0)
{
ErrorTerm += XDelta;
}
/* Draw the first, partial run of pixels */
DrawVerticalRun8(&ScreenPtr, XAdvance, InitialPixelCount, Color, ScreenWidth);
/* Draw all full runs */
for (i=0; i<(XDelta-1); i++)
{
RunLength = WholeStep; /* run is at least this long */
/* Advance the error term and add an extra pixel if the error
term so indicates */
if ((ErrorTerm += AdjUp) > 0)
{
RunLength++;
ErrorTerm -= AdjDown; /* reset the error term */
}
/* Draw this scan line's run */
DrawVerticalRun8(&ScreenPtr, XAdvance, RunLength, Color, ScreenWidth);
}
/* Draw the final run of pixels */
DrawVerticalRun8(&ScreenPtr, XAdvance, FinalPixelCount, Color, ScreenWidth);
return;
}
}
/* Draws a horizontal run of pixels, then advances the bitmap pointer to
the first pixel of the next run. */
void DrawHorizontalRun8(char **ScreenPtr, int XAdvance,
int RunLength, int Color, int ScreenWidth)
{
int i;
char *WorkingScreenPtr = *ScreenPtr;
char col2 = Color>>8;
char col1 = Color & 0x00FF;
for (i=0; i<RunLength; i++)
{
*WorkingScreenPtr = col1;
WorkingScreenPtr += XAdvance;
}
/* Advance to the next scan line */
WorkingScreenPtr += giImageWidth;
*ScreenPtr = WorkingScreenPtr;
}
/* Draws a vertical run of pixels, then advances the bitmap pointer to
the first pixel of the next run. */
void DrawVerticalRun8(char **ScreenPtr, int XAdvance,
int RunLength, int Color, int ScreenWidth)
{
int i;
char *WorkingScreenPtr = *ScreenPtr;
char col2 = Color>>8;
char col1 = Color & 0x00FF;
for (i=0; i<RunLength; i++)
{
*WorkingScreenPtr = col1;
WorkingScreenPtr += giImageWidth;
}
/* Advance to the next column */
WorkingScreenPtr += XAdvance;
*ScreenPtr = WorkingScreenPtr;
}
+80
View File
@@ -0,0 +1,80 @@
// *****************************************************************************
//
// Filename : line.h
//
// Purpose :
//
// Modification history :
//
// *****************************************************************************
#ifndef ___LINE___H
#define ___LINE___H
// *****************************************************************************
//
// Includes
//
// *****************************************************************************
#include "sgp.h"
#include "types.h"
//**************************************************************************
//
// Example Usage
//
//**************************************************************************
// // don't send pitch, send width in pixels
// SetClippingRegionAndImageWidth( uiPitch, 15, 15, 30, 30 );
//
// LineDraw( TRUE, 10, 10, 200, 200, colour, pImageData);
// OR
// RectangleDraw( TRUE, 10, 10, 200, 200, colour, pImageData);
// *****************************************************************************
//
// Prototypes
//
// *****************************************************************************
/*
#ifdef __cplusplus
extern "C" {
#endif
*/
// *****************************************************************************
void SetClippingRegionAndImageWidth(
int iImageWidth,
int iClipStartX, int iClipStartY,
int iClipWidth, int iClipHeight );
// NOTE:
// Don't send fClip==TRUE to LineDraw if you don't have to. So if you know
// that your line will be within the region you want it to be in, set
// fClip == FALSE.
void PixelDraw( BOOLEAN fClip, INT32 xp, INT32 yp, INT16 sColor, INT8 *pScreen );
void LineDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, char *ScreenPtr);
void LineDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr);
void LineDraw8( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, char *ScreenPtr);
template <typename string7>
void RectangleDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, string7 ScreenPtr);
template <typename string7>
void RectangleDraw8( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, string7 ScreenPtr);
// *****************************************************************************
/*
#ifdef __cplusplus
}
#endif
*/
#endif
// EOF *************************************************************************
File diff suppressed because it is too large Load Diff
+232
View File
@@ -0,0 +1,232 @@
// *****************************************************************************
//
// Filename : MouseSystem.h
//
// Purpose : Defines and typedefs for the "mousesystem" mouse region handler
//
// Modification history :
//
// 30jan97:Bret -> Creation
//
// *****************************************************************************
// *****************************************************************************
//
// Includes
//
// *****************************************************************************
#include "mousesystem_macros.h"
#ifndef _MOUSE_SYSTEM_H_
#define _MOUSE_SYSTEM_H_
// *****************************************************************************
//
// Typedefs
//
// *****************************************************************************
#ifdef JA2
#define _JA2_RENDER_DIRTY // Undef this if not using the JA2 Dirty Rectangle System.
#endif
typedef void (*MOUSE_CALLBACK)(struct _MOUSE_REGION *,INT32); // Define MOUSE_CALLBACK type as pointer to void
typedef void (*MOUSE_HELPTEXT_DONE_CALLBACK)( ); // the help is done callback
typedef struct _MOUSE_REGION {
UINT16 IDNumber; // Region's ID number, set by mouse system
INT8 PriorityLevel; // Region's Priority, set by system and/or caller
UINT32 uiFlags; // Region's state flags
INT16 RegionTopLeftX; // Screen area affected by this region (absolute coordinates)
INT16 RegionTopLeftY;
INT16 RegionBottomRightX;
INT16 RegionBottomRightY;
INT16 MouseXPos; // Mouse's Coordinates in absolute screen coordinates
INT16 MouseYPos;
INT16 RelativeXPos; // Mouse's Coordinates relative to the Top-Left corner of the region
INT16 RelativeYPos;
UINT16 ButtonState; // Current state of the mouse buttons
UINT16 Cursor; // Cursor to use when mouse in this region (see flags)
MOUSE_CALLBACK MovementCallback; // Pointer to callback function if movement occured in this region
MOUSE_CALLBACK ButtonCallback; // Pointer to callback function if button action occured in this region
INT32 UserData[4]; // User Data, can be set to anything!
//Fast help vars.
INT16 FastHelpTimer; // Countdown timer for FastHelp text
UINT16 *FastHelpText; // Text string for the FastHelp (describes buttons if left there a while)
INT32 FastHelpRect;
MOUSE_HELPTEXT_DONE_CALLBACK HelpDoneCallback;
struct _MOUSE_REGION *next; // List maintenance, do NOT touch these entries
struct _MOUSE_REGION *prev;
} MOUSE_REGION;
// *****************************************************************************
//
// Defines
//
// *****************************************************************************
// Mouse Region Flags
#define MSYS_NO_FLAGS 0x00000000
#define MSYS_MOUSE_IN_AREA 0x00000001
#define MSYS_SET_CURSOR 0x00000002
#define MSYS_MOVE_CALLBACK 0x00000004
#define MSYS_BUTTON_CALLBACK 0x00000008
#define MSYS_REGION_EXISTS 0x00000010
#define MSYS_SYSTEM_INIT 0x00000020
#define MSYS_REGION_ENABLED 0x00000040
#define MSYS_FASTHELP 0x00000080
#define MSYS_GOT_BACKGROUND 0x00000100
#define MSYS_HAS_BACKRECT 0x00000200
#define MSYS_FASTHELP_RESET 0x00000400
#define MSYS_ALLOW_DISABLED_FASTHELP 0x00000800
// Mouse region IDs
#define MSYS_ID_BASE 1
#define MSYS_ID_MAX 0xfffffff // ( INT32 max )
#define MSYS_ID_SYSTEM 0
// Mouse region priorities
#define MSYS_PRIORITY_LOWEST 0
#define MSYS_PRIORITY_LOW 15
#define MSYS_PRIORITY_BASE 31
#define MSYS_PRIORITY_NORMAL 31
#define MSYS_PRIORITY_HIGH 63
#define MSYS_PRIORITY_HIGHEST 127
#define MSYS_PRIORITY_SYSTEM -1
#define MSYS_PRIORITY_AUTO -1
// Mouse system defines used during updates
#define MSYS_NO_ACTION 0
#define MSYS_DO_MOVE 1
#define MSYS_DO_LBUTTON_DWN 2
#define MSYS_DO_LBUTTON_UP 4
#define MSYS_DO_RBUTTON_DWN 8
#define MSYS_DO_RBUTTON_UP 16
#define MSYS_DO_LBUTTON_REPEAT 32
#define MSYS_DO_RBUTTON_REPEAT 64
#define MSYS_DO_BUTTONS (MSYS_DO_LBUTTON_DWN|MSYS_DO_LBUTTON_UP|MSYS_DO_RBUTTON_DWN|MSYS_DO_RBUTTON_UP|MSYS_DO_RBUTTON_REPEAT|MSYS_DO_LBUTTON_REPEAT)
// Mouse system button masks
#define MSYS_LEFT_BUTTON 1
#define MSYS_RIGHT_BUTTON 2
// Mouse system special values
#define MSYS_NO_CALLBACK NULL
#define MSYS_NO_CURSOR 65534
// Mouse system callback reasons
#define MSYS_CALLBACK_REASON_NONE 0
#define MSYS_CALLBACK_REASON_INIT 1
#define MSYS_CALLBACK_REASON_MOVE 2
#define MSYS_CALLBACK_REASON_LBUTTON_DWN 4
#define MSYS_CALLBACK_REASON_LBUTTON_UP 8
#define MSYS_CALLBACK_REASON_RBUTTON_DWN 16
#define MSYS_CALLBACK_REASON_RBUTTON_UP 32
#define MSYS_CALLBACK_REASON_BUTTONS (MSYS_CALLBACK_REASON_LBUTTON_DWN|MSYS_CALLBACK_REASON_LBUTTON_UP| \
MSYS_CALLBACK_REASON_RBUTTON_DWN|MSYS_CALLBACK_REASON_RBUTTON_UP)
#define MSYS_CALLBACK_REASON_LOST_MOUSE 64
#define MSYS_CALLBACK_REASON_GAIN_MOUSE 128
#define MSYS_CALLBACK_REASON_LBUTTON_REPEAT 256
#define MSYS_CALLBACK_REASON_RBUTTON_REPEAT 512
//Kris: Nov 31, 1999
//Added support for double clicks. The DOUBLECLICK event is passed combined with
//the LBUTTON_DWN event if two LBUTTON_DWN events are detected on the same button/region
//within the delay defined by MSYS_DOUBLECLICK_DELAY (in milliseconds). If your button/region
//supports double clicks and single clicks, make sure the DOUBLECLICK event is checked first (rejecting
//the LBUTTON_DWN event if detected)
#define MSYS_CALLBACK_REASON_LBUTTON_DOUBLECLICK 1024
// Mouse grabbing return codes
#define MSYS_GRABBED_OK 0
#define MSYS_ALREADY_GRABBED 1
#define MSYS_REGION_NOT_IN_LIST 2
// *****************************************************************************
//
// Prototypes
//
// *****************************************************************************
/*
#ifdef __cplusplus
extern "C" {
#endif
*/
// *****************************************************************************
// Note:
// The prototype for MSYS_SGP_Mouse_Handler_Hook() is defined in mousesystem_macros.h
// Internal Functions
INT32 MSYS_GetNewID(void);
void MSYS_TrashRegList(void);
void MSYS_AddRegionToList(MOUSE_REGION *region);
INT32 MSYS_RegionInList(MOUSE_REGION *region);
void MSYS_DeleteRegionFromList(MOUSE_REGION *region);
void MSYS_UpdateMouseRegion(void);
void MSYS_SetCurrentCursor(UINT16 Cursor);
// External
INT32 MSYS_Init(void);
void MSYS_Shutdown(void);
void MSYS_DefineRegion(MOUSE_REGION *region,UINT16 tlx,UINT16 tly,UINT16 brx,UINT16 bry,INT8 priority,
UINT16 crsr,MOUSE_CALLBACK movecallback,MOUSE_CALLBACK buttoncallback);
void MSYS_ChangeRegionCursor(MOUSE_REGION *region,UINT16 crsr);
INT32 MSYS_AddRegion(MOUSE_REGION *region);
void MSYS_RemoveRegion(MOUSE_REGION *region);
void MSYS_EnableRegion(MOUSE_REGION *region);
void MSYS_DisableRegion(MOUSE_REGION *region);
void MSYS_ChangeRegionPriority(MOUSE_REGION *region,INT8 priority);
void MSYS_SetRegionUserData(MOUSE_REGION *region,INT32 index,INT32 userdata);
INT32 MSYS_GetRegionUserData(MOUSE_REGION *region,INT32 index);
INT32 MSYS_GrabMouse(MOUSE_REGION *region);
void MSYS_ReleaseMouse(MOUSE_REGION *region);
void MSYS_MoveMouseRegionBy( MOUSE_REGION *region, INT16 sDeltaX, INT16 sDeltaY);
void MSYS_MoveMouseRegionTo( MOUSE_REGION *region, INT16 sX, INT16 sY);
void MSYS_AllowDisabledRegionFastHelp( MOUSE_REGION *region, BOOLEAN fAllow );
// This function will force a re-evaluation of mous regions
// Usually used to force change of mouse cursor if panels switch, etc
void RefreshMouseRegions( );
template <typename type2>
void SetRegionFastHelpText( MOUSE_REGION *region, type2 szText );
void SetRegionHelpEndCallback( MOUSE_REGION *region, MOUSE_HELPTEXT_DONE_CALLBACK CallbackFxn );
// Now also used by Wizardry -- DB
void DisplayFastHelp( MOUSE_REGION *region );
void RenderFastHelp();
void SetFastHelpDelay( INT16 sFastHelpDelay );
void EnableMouseFastHelp( void );
void DisableMouseFastHelp( void );
void ResetClickedMode(void);
#ifdef _JA2_RENDER_DIRTY
BOOLEAN SetRegionSavedRect( MOUSE_REGION *region);
void FreeRegionSavedRect( MOUSE_REGION *region );
#endif
// *****************************************************************************
/*
#ifdef __cplusplus
}
#endif
*/
#endif
// EOF *************************************************************************
@@ -0,0 +1,40 @@
//=================================================================================================
// MouseSystem_Macros.h
//
// Macro definitions for the "mousesystem" mouse region handler.
//
// This file is included by "mousesystem.h" or can be included by itself.
//
// Written by Bret Rowdon. Jan 30 '97
//=================================================================================================
#ifndef _MOUSE_SYSTEM_MACROS_H_
#define _MOUSE_SYSTEM_MACROS_H_
// Special macro hook for the mouse handler. Allows a call to a secondary mouse handler.
// Define the label _MOUSE_SYSTEM_HOOK_ to activate. Undef it to deactivate.
//
// The actual function prototype is shown below
#define _MOUSE_SYSTEM_HOOK_
#ifdef _MOUSE_SYSTEM_HOOK_
#define MouseSystemHook(t,x,y,l,r) MSYS_SGP_Mouse_Handler_Hook(t,x,y,l,r)
#else
#define MouseSystemHook(t,x,y,l,r)
#endif
#ifdef __cplusplus
extern "C" {
#endif
// Special prototype for mouse handler hook
extern void MSYS_SGP_Mouse_Handler_Hook(UINT16 Type, UINT16 Xcoord, UINT16 Ycoord, BOOLEAN LeftButton, BOOLEAN RightButton);
#ifdef __cplusplus
}
#endif
#endif
+40
View File
@@ -0,0 +1,40 @@
#ifndef __PCX_
#define __PCX_
#include "types.h"
#include "himage.h"
typedef struct
{
UINT8 ubManufacturer;
UINT8 ubVersion;
UINT8 ubEncoding;
UINT8 ubBitsPerPixel;
UINT16 usLeft, usTop;
UINT16 usRight, usBottom;
UINT16 usHorRez, usVerRez;
UINT8 ubEgaPalette[48];
UINT8 ubReserved;
UINT8 ubColorPlanes;
UINT16 usBytesPerLine;
UINT16 usPaletteType;
UINT8 ubFiller[58];
} PcxHeader;
typedef struct
{
UINT8 *pPcxBuffer;
UINT8 ubPalette[768];
UINT16 usWidth, usHeight;
UINT32 uiBufferSize;
UINT16 usPcxFlags;
} PcxObject;
BOOLEAN LoadPCXFileToImage( HIMAGE hImage, UINT16 fContents );
PcxObject *LoadPcx(UINT8 *pFilename);
BOOLEAN BlitPcxToBuffer( PcxObject *pCurrentPcxObject, UINT8 *pBuffer, UINT16 usBufferWidth, UINT16 usBufferHeight, UINT16 usX, UINT16 usY, BOOLEAN fTransp);
#endif
+42
View File
@@ -0,0 +1,42 @@
#ifndef __RANDOM_
#define __RANDOM_
#include "Types.h"
#include "Debug.h"
#include <stdlib.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
extern void InitializeRandom(void);
extern UINT32 Random( UINT32 uiRange );
//Chance( 74 ) returns TRUE 74% of the time. If uiChance >= 100, then it will always return TRUE.
extern BOOLEAN Chance( UINT32 uiChance );
//Wizardry can use it too, but I'm saving them a K in the meantime...
//If Wizardry wants it, then removing the #ifdef JA2 will make it work.
#ifdef JA2
#define PRERANDOM_GENERATOR
#endif
#ifdef PRERANDOM_GENERATOR
//Returns a pregenerated random number.
//Used to deter Ian's tactic of shoot, miss, restore saved game :)
extern UINT32 PreRandom( UINT32 uiRange );
extern BOOLEAN PreChance( UINT32 uiChance );
//IMPORTANT: Changing this define will invalidate the JA2 save. If this
// is necessary, please ifdef your own value.
#define MAX_PREGENERATED_NUMS 256
extern UINT32 guiPreRandomIndex;
extern UINT32 guiPreRandomNums[ MAX_PREGENERATED_NUMS ];
#endif
#ifdef __cplusplus
}
#endif
#endif
+22
View File
@@ -0,0 +1,22 @@
//
// Snap: Implementation of the TReadDir class
// This class reads the contents of a directory file-by-file
//
#include "readdir.h"
TReadDir::TReadDir(char const* searchPattern)
{
fSearchHandle = FindFirstFile(searchPattern, &fFileInfo);
fFirstRequest = true;
}
bool TReadDir::NextFile(char const* &fileName, unsigned &attrib)
{
if (fSearchHandle == INVALID_HANDLE_VALUE) return false;
if (fFirstRequest) fFirstRequest = false;
else if ( !FindNextFile(fSearchHandle, &fFileInfo) ) return false;
fileName = fFileInfo.cFileName;
attrib = fFileInfo.dwFileAttributes;
return true;
}
+27
View File
@@ -0,0 +1,27 @@
//
// Snap: Declaration of the TReadDir class
// This class reads the contents of a directory file-by-file
//
#ifndef READDIR_H
#define READDIR_H
#include <windows.h>
class TReadDir {
public:
TReadDir(char const* searchPattern);
~TReadDir() { FindClose(fSearchHandle); }
bool NextFile(char const* &fileName, unsigned &attrib);
private:
HANDLE fSearchHandle;
WIN32_FIND_DATA fFileInfo;
bool fFirstRequest;
};
#endif // #ifndef READDIR_H
File diff suppressed because it is too large Load Diff
+58
View File
@@ -0,0 +1,58 @@
#ifndef __SGP_
#define __SGP_
#include "local.h"
#include "types.h"
#include "timer.h"
#include "debug.h"
#if defined( JA2 ) || defined( UTIL )
#include "video.h"
#else
#include "video2.h"
#endif
#ifndef JA2
#include "input.h"
#include "memman.h"
#include "fileman.h"
#include "dbman.h"
#include "soundman.h"
#include "pcx.h"
#include "line.h"
#include "gameloop.h"
#include "font.h"
#include "english.h"
#include "Mutex Manager.h"
#include "vobject.h"
#include "Random.h"
#include "shading.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern BOOLEAN gfProgramIsRunning; // Turn this to FALSE to exit program
extern UINT32 giStartMem;
extern CHAR8 gzCommandLine[100]; // Command line given
extern UINT8 gbPixelDepth; // GLOBAL RUN-TIME SETTINGS
extern BOOLEAN gfDontUseDDBlits; // GLOBAL FOR USE OF DD BLITTING
#if !defined(JA2) && !defined(UTILS)
extern BOOLEAN gfLoadAtStartup;
extern CHAR8 *gzStringDataOverride;
extern BOOLEAN gfUsingBoundsChecker;
extern BOOLEAN gfCapturingVideo;
#endif
// function prototypes
void SGPExit(void);
void ShutdownWithErrorBox(CHAR8 *pcMessage);
#ifdef __cplusplus
}
#endif
#endif
+318
View File
@@ -0,0 +1,318 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "DirectDraw Calls.h"
#include <stdio.h>
#include "debug.h"
#if defined( JA2 ) || defined( UTIL )
#include "video.h"
#else
#include "video2.h"
#endif
#include "himage.h"
#include "vobject.h"
#include "vobject_private.h"
#include "video_private.h"
#include "wcheck.h"
#include "vobject_blitters.h"
#include "shading.h"
#endif
BOOLEAN ShadesCalculateTables(SGPPaletteEntry *p8BPPPalette);
BOOLEAN ShadesCalculatePalette(SGPPaletteEntry *pSrcPalette, SGPPaletteEntry *pDestPalette, UINT16 usRed, UINT16 usGreen, UINT16 usBlue, BOOLEAN fMono);
void FindIndecies(SGPPaletteEntry *pSrcPalette, SGPPaletteEntry *pMapPalette, UINT8 *pTable);
void FindMaskIndecies(UINT8 *, UINT8 *, UINT8 *);
SGPPaletteEntry Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES+3][256];
UINT8 ubColorTables[HVOBJECT_SHADE_TABLES+3][256];
UINT16 IntensityTable[65536];
UINT16 ShadeTable[65536];
UINT16 White16BPPPalette[ 256 ];
FLOAT guiShadePercent = (FLOAT)0.48;
FLOAT guiBrightPercent = (FLOAT)1.1;
BOOLEAN ShadesCalculateTables(SGPPaletteEntry *p8BPPPalette)
{
UINT32 uiCount;
// Green palette
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[0], 0, 255, 0, TRUE);
// Blue palette
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES], 0, 0, 255, TRUE);
// Yellow palette
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES+1], 255, 255, 0, TRUE);
// Red palette
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES+2], 255, 0, 0, TRUE);
// these are the brightening tables, 115%-150% brighter than original
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[1], 293, 293, 293, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[2], 281, 281, 281, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[3], 268, 268, 268, FALSE);
// palette 4 is the non-modified palette.
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[4], 255, 255, 255, FALSE);
// the rest are darkening tables, right down to all-black.
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[5], 195, 195, 195, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[6], 165, 165, 165, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[7], 135, 135, 135, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[8], 105, 105, 105, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[9], 75, 75, 75, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[10], 45, 45, 45, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[11], 36, 36, 36, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[12], 27, 27, 27, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[13], 18, 18, 18, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[14], 9, 9, 9, FALSE);
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[15], 0, 0, 0, FALSE);
// Remap the shade colors to the original palette
for(uiCount=0; uiCount < (HVOBJECT_SHADE_TABLES+3); uiCount++)
{
FindIndecies(Shaded8BPPPalettes[uiCount], p8BPPPalette, ubColorTables[uiCount]);
ubColorTables[uiCount][0]=0;
}
return(TRUE);
}
BOOLEAN ShadesCalculatePalette(SGPPaletteEntry *pSrcPalette, SGPPaletteEntry *pDestPalette, UINT16 usRed, UINT16 usGreen, UINT16 usBlue, BOOLEAN fMono)
{
UINT32 cnt, lumin;
UINT32 rmod, gmod, bmod;
Assert( pSrcPalette != NULL );
Assert( pDestPalette != NULL );
for ( cnt = 0; cnt < 256; cnt++ )
{
if(fMono)
{
lumin=(pSrcPalette[ cnt ].peRed*299/1000)+ (pSrcPalette[ cnt ].peGreen*587/1000)+(pSrcPalette[ cnt ].peBlue*114/1000);
rmod=usRed*lumin/255;
gmod=usGreen*lumin/255;
bmod=usBlue*lumin/255;
}
else
{
rmod = (usRed*pSrcPalette[ cnt ].peRed/255);
gmod = (usGreen*pSrcPalette[ cnt ].peGreen/255);
bmod = (usBlue*pSrcPalette[ cnt ].peBlue/255);
}
pDestPalette[ cnt ].peRed = (UINT8)__min(rmod, 255);
pDestPalette[ cnt ].peGreen = (UINT8)__min(gmod, 255);
pDestPalette[ cnt ].peBlue = (UINT8)__min(bmod, 255);
}
return(TRUE);
}
void FindIndecies(SGPPaletteEntry *pSrcPalette, SGPPaletteEntry *pMapPalette, UINT8 *pTable)
{
UINT16 usCurIndex, usCurDelta, usCurCount;
UINT32 *pSavedPtr;
__asm {
// Assumes:
// ESI = Pointer to source palette (shaded values)
// EDI = Pointer to original palette (palette we'll end up using!)
// EBX = Pointer to array of indecies
mov esi, pSrcPalette
mov edi, pMapPalette
mov ebx, pTable
mov BYTE PTR [ebx],0 ; Index 0 is always 0, for trans col
inc ebx
add esi,4 ; Goto next color entry
add edi,4
mov pSavedPtr, edi ; Save pointer to original pal
mov usCurCount, 255 ; We'll check cols 1-255
DoNextIndex:
mov edi, pSavedPtr ; Restore saved ptr
mov usCurIndex, 256 ; Set found index & delta to some
mov usCurDelta, 0ffffh ; val so we get at least 1 col.
mov ecx,255 ; Check cols 1-255 of orig pal
push ebx
xor bx,bx
NextColor:
xor ah,ah ; Calc delta between shaded color
mov al,[edi] ; and a color in the orig palette.
mov bl,[esi] ; Formula:
sub ax,bx ; Delta = abs(red-origred) +
or ax,ax ; abs(green-origgreen) +
jns NC1
neg ax
NC1:mov dx,ax ; abs(blue-origblue)
xor ah,ah
mov al,[edi+1]
mov bl,[esi+1]
sub ax,bx
or ax,ax ; abs(green-origgreen) +
jns NC2
neg ax
NC2:add dx,ax
xor ah,ah
mov al,[edi+2]
mov bl,[esi+2]
sub ax,bx
or ax,ax ; abs(green-origgreen) +
jns NC3
neg ax
NC3:add dx,ax
cmp dx,usCurDelta ; If delta < old delta
jae NotThisCol ; Save this delta and it's
mov ax,256 ; palette index
mov [usCurDelta],dx
sub ax,cx
mov [usCurIndex],ax
NotThisCol:
add edi,4 ; Try next color in orginal pal
dec cx
jnz NextColor
pop ebx
mov ax,usCurIndex ; By now, usCurIndex holds pal index
mov [ebx],al ; of closest color in orig pal
inc ebx ; so save it, then repeat above
add esi,4 ; for the other cols in shade pal
dec usCurCount
jnz DoNextIndex
}
}
/**********************************************************************************************
BuildShadeTable
Builds a 16-bit color shading table. This function should be called only after the current
video adapter's pixel format is known (IE: GetRgbDistribution() has been called, and the
globals for masks and shifts have been initialized by that function), and before any
blitting is done.
Using the table is a straight lookup. The pixel to be shaded down is used as the index into
the table and the entry at that point will be a pixel that is 25% darker.
**********************************************************************************************/
void BuildShadeTable(void)
{
UINT16 red, green, blue;
UINT16 index;
for(red=0; red < 256; red+=4)
for(green=0; green < 256; green+=4)
for(blue=0; blue < 256; blue+=4)
{
index=Get16BPPColor(FROMRGB(red, green, blue));
ShadeTable[index]=Get16BPPColor(FROMRGB(red*guiShadePercent, green*guiShadePercent, blue*guiShadePercent));
}
memset( White16BPPPalette, 65535, sizeof( White16BPPPalette ) );
}
/**********************************************************************************************
BuildIntensityTable
Builds a 16-bit color shading table. This function should be called only after the current
video adapter's pixel format is known (IE: GetRgbDistribution() has been called, and the
globals for masks and shifts have been initialized by that function), and before any
blitting is done.
**********************************************************************************************/
void BuildIntensityTable(void)
{
UINT16 red, green, blue;
UINT16 index;
FLOAT dShadedPercent = (FLOAT)0.80;
#if 0
UINT32 lumin;
UINT32 rmod, gmod, bmod;
for(red=0; red < 256; red+=4)
for(green=0; green < 256; green+=4)
for(blue=0; blue < 256; blue+=4)
{
index=Get16BPPColor(FROMRGB(red, green, blue));
lumin=( red*299/1000)+ ( green*587/1000 ) + ( blue*114/1000 );
//lumin = __min(lumin, 255);
rmod=(255*lumin)/256;
gmod=(100*lumin)/256;
bmod=(100*lumin)/256;
//rmod = __m( 255, rmod );
IntensityTable[index]=Get16BPPColor( FROMRGB( rmod, gmod , bmod ) );
}
#endif
for(red=0; red < 256; red+=4)
for(green=0; green < 256; green+=4)
for(blue=0; blue < 256; blue+=4)
{
index=Get16BPPColor(FROMRGB(red, green, blue));
IntensityTable[index]=Get16BPPColor(FROMRGB(red*dShadedPercent, green*dShadedPercent, blue*dShadedPercent));
}
}
void SetShadeTablePercent( FLOAT uiShadePercent )
{
guiShadePercent = uiShadePercent;
BuildShadeTable( );
}
#ifdef JA2 // Jul. 23 '97 - ALEX - because Wizardry isn't using it & no longer has a version of Set8BPPPalette() available
void Init8BitTables(void)
{
SGPPaletteEntry Pal[256];
UINT32 uiCount;
// calculate a grey-scale table for the default palette
for(uiCount=0; uiCount < 256; uiCount++)
{
Pal[uiCount].peRed=(UINT8)(uiCount%128)+128;
Pal[uiCount].peGreen=(UINT8)(uiCount%128)+128;
Pal[uiCount].peBlue=(UINT8)(uiCount%128)+128;
}
Pal[0].peRed=0;
Pal[0].peGreen=0;
Pal[0].peBlue=0;
Set8BPPPalette(Shaded8BPPPalettes[4]);
}
BOOLEAN Set8BitModePalette(SGPPaletteEntry *pPal)
{
ShadesCalculateTables(pPal);
Set8BPPPalette(pPal);
return(TRUE);
}
#endif
+39
View File
@@ -0,0 +1,39 @@
#ifndef _SHADING_H_
#define _SHADING_H_
#include "himage.h" // For SGPPaletteEntry
#include "vobject.h" // For HVOBJECT_SHADE_TABLES
#include "vsurface.h" // For
#ifdef __cplusplus
extern "C" {
#endif
BOOLEAN ShadesCalculateTables(SGPPaletteEntry *p8BPPPalette);
void BuildShadeTable(void);
void BuildIntensityTable(void);
void SetShadeTablePercent( FLOAT uiShadePercent );
#ifdef JA2 // Jul. 23 '97 - ALEX - because Wizardry isn't using it & no longer has a version of Set8BPPPalette() available
void Init8BitTables(void);
BOOLEAN Set8BitModePalette(SGPPaletteEntry *pPal);
#endif
extern SGPPaletteEntry Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES+3][256];
extern UINT8 ubColorTables[HVOBJECT_SHADE_TABLES+3][256];
extern UINT16 IntensityTable[65536];
extern UINT16 ShadeTable[65536];
extern UINT16 White16BPPPalette[ 256 ];
extern FLOAT guiShadePercent;
extern FLOAT guiBrightPercent;
#ifdef __cplusplus
}
#endif
#define DEFAULT_SHADE_LEVEL 4
#endif
File diff suppressed because it is too large Load Diff
+264
View File
@@ -0,0 +1,264 @@
#ifndef __SOUNDMAN_
#define __SOUNDMAN_
#include "types.h"
#include "mss.h"
/*
#ifdef __cplusplus
extern "C" {
#endif
*/
// Sample status flags
#define SAMPLE_ALLOCATED 0x00000001
#define SAMPLE_LOCKED 0x00000002
#define SAMPLE_RANDOM 0x00000004
#define SAMPLE_RANDOM_MANUAL 0x00000008
#define SAMPLE_3D 0x00000010
// Sound error values (they're all the same)
#define NO_SAMPLE 0xffffffff
#define SOUND_ERROR 0xffffffff
// Maximum allowable priority value
#define PRIORITY_MAX 0xfffffffe
#define PRIORITY_RANDOM PRIORITY_MAX-1
// Structure definition for 3D sound positional information used by
// various other structs and functions
typedef struct {
FLOAT flX, flY, flZ;
FLOAT flVelX, flVelY, flVelZ;
FLOAT flFaceX, flFaceY, flFaceZ;
FLOAT flUpX, flUpY, flUpZ;
FLOAT flFalloffMin, flFalloffMax;
UINT32 uiVolume;
} SOUND3DPOS;
// Struct definition for sample slots in the cache
// Holds the regular sample data, as well as the
// data for the random samples
typedef struct {
CHAR8 pName[128]; // Path to sample data
UINT32 uiSize; // Size of sample data
UINT32 uiSoundSize; // Playable sound size
UINT32 uiFlags; // Status flags
UINT32 uiSpeed; // Playback frequency
BOOLEAN fStereo; // Stereo/Mono
UINT8 ubBits; // 8/16 bits
PTR pData; // pointer to sample data memory
PTR pSoundStart; // pointer to start of sound data
UINT32 uiCacheHits;
UINT32 uiTimeNext; // Random sound data
UINT32 uiTimeMin, uiTimeMax;
UINT32 uiSpeedMin, uiSpeedMax;
UINT32 uiVolMin, uiVolMax;
UINT32 uiPanMin, uiPanMax;
UINT32 uiPriority;
UINT32 uiInstances;
UINT32 uiMaxInstances;
UINT32 uiAilWaveFormat; // AIL wave sample type
UINT32 uiADPCMBlockSize; // Block size for compressed files
} SAMPLETAG;
// Structure definition for slots in the sound output
// These are used for both the cached and double-buffered
// streams
typedef struct {
SAMPLETAG *pSample;
UINT32 uiSample;
HSAMPLE hMSS;
HSTREAM hMSSStream;
H3DSAMPLE hM3D;
UINT32 uiFlags;
UINT32 uiSoundID;
UINT32 uiPriority;
void (*pCallback)(UINT8*, UINT32, UINT32, UINT32, void *);
void *pData;
void (*EOSCallback)(void *);
void *pCallbackData;
UINT32 uiTimeStamp;
BOOLEAN fLooping;
HWFILE hFile;
BOOLEAN fMusic;
BOOLEAN fStopAtZero;
UINT32 uiFadeVolume;
UINT32 uiFadeRate;
UINT32 uiFadeTime;
} SOUNDTAG;
// Structure definition for sound parameters being passed down to
// the sample playing function
typedef struct {
UINT32 uiSpeed;
UINT32 uiPitchBend; // Random pitch bend range +/-
UINT32 uiVolume;
UINT32 uiPan;
UINT32 uiLoop;
UINT32 uiPriority;
void (*EOSCallback)(void *);
void *pCallbackData;
} SOUNDPARMS;
// Structure definition for 3D sound parameters being passed down to
// the sample playing function
typedef struct {
UINT32 uiSpeed;
UINT32 uiPitchBend; // Random pitch bend range +/-
UINT32 uiVolume; // volume at distance zero
UINT32 uiLoop;
UINT32 uiPriority;
void (*EOSCallback)(void *);
void *pCallbackData;
SOUND3DPOS Pos; // NOT optional, MUST be set
} SOUND3DPARMS;
// Structure definition for parameters to the random sample playing
// function
typedef struct {
UINT32 uiTimeMin, uiTimeMax;
UINT32 uiSpeedMin, uiSpeedMax;
UINT32 uiVolMin, uiVolMax;
UINT32 uiPanMin, uiPanMax;
UINT32 uiPriority;
UINT32 uiMaxInstances;
} RANDOMPARMS;
// Structure definition for parameters to the random 3D sample playing
// function
typedef struct {
UINT32 uiTimeMin, uiTimeMax;
UINT32 uiSpeedMin, uiSpeedMax;
UINT32 uiVolMin, uiVolMax;
UINT32 uiPriority;
UINT32 uiMaxInstances;
SOUND3DPOS Pos; // NOT optional, MUST be set
} RANDOM3DPARMS;
enum e_EAXRoomTypes
{
EAXROOMTYPE_NONE=0,
EAXROOMTYPE_SMALL_CAVE,
EAXROOMTYPE_MEDIUM_CAVE,
EAXROOMTYPE_LARGE_CAVE,
EAXROOMTYPE_SMALL_ROOM,
EAXROOMTYPE_MEDIUM_ROOM,
EAXROOMTYPE_LARGE_ROOM,
EAXROOMTYPE_OUTDOORS_FLAT,
EAXROOMTYPE_OUTDOORS_CANYON,
EAXROOMTYPE_UNDERWATER,
EAXROOMTYPE_NUM_TYPES
};
// Global startup/shutdown functions
extern BOOLEAN InitializeSoundManager(void);
extern void ShutdownSoundManager(void);
// Configuration functions
extern BOOLEAN SoundSetMemoryLimit(UINT32 uiLimit);
extern BOOLEAN SoundSetCacheThreshhold(UINT32 uiThreshold);
extern HDIGDRIVER SoundGetDriverHandle(void);
// Master volume control functions
extern BOOLEAN SoundSetDigitalVolume(UINT32 uiVolume);
extern UINT32 SoundGetDigitalVolume(UINT32 uiVolume);
extern void SoundSetDefaultVolume(UINT32 uiVolume);
extern UINT32 SoundGetDefaultVolume(void);
// Cache control functions
UINT32 SoundLoadSample(STR pFilename);
extern UINT32 SoundFreeSample(STR pFilename);
extern UINT32 SoundLockSample(STR pFilename);
extern UINT32 SoundUnlockSample(STR pFilename);
extern BOOLEAN SoundEmptyCache(void);
extern BOOLEAN SoundSampleIsInUse(UINT32 uiSample);
// Play/service sample functions
extern UINT32 SoundPlay(STR pFilename, SOUNDPARMS *pParms);
extern UINT32 SoundPlayStreamedFile( STR pFilename, SOUNDPARMS *pParms );
extern UINT32 SoundPlayRandom(STR pFilename, RANDOMPARMS *pParms);
extern BOOLEAN SoundRandomShouldPlay(UINT32 uiSample);
extern UINT32 SoundStartRandom(UINT32 uiSample);
extern UINT32 SoundStreamCallback(STR pFilename, SOUNDPARMS *pParms, void (*pCallback)(UINT8 *, UINT32, UINT32, UINT32, void *), void *);
extern BOOLEAN SoundServiceStreams(void);
extern BOOLEAN SoundServiceRandom(void);
extern void SoundSampleSetVolumeRange(UINT32 uiSample, UINT32 uiVolMin, UINT32 uiVolMax);
extern void SoundSampleSetPanRange(UINT32 uiSample, UINT32 uiPanMin, UINT32 uiPanMax);
// Sound instance manipulation functions
extern void SoundSetMusic(UINT32 uiSound);
extern BOOLEAN SoundStopMusic(void);
extern BOOLEAN SoundStopAll(void);
extern BOOLEAN SoundStopAllRandom(void);
extern BOOLEAN SoundStop(UINT32 uiSoundID);
extern BOOLEAN SoundIsPlaying(UINT32 uiSoundID);
extern BOOLEAN SoundFileIsPlaying(CHAR8 *pFilename);
extern BOOLEAN SoundSetFadeVolume(UINT32 uiSoundID, UINT32 uiVolume, UINT32 uiRate, BOOLEAN fStopAtZero);
extern BOOLEAN SoundSetVolume(UINT32 uiSoundID, UINT32 uiVolume);
extern BOOLEAN SoundSetPan(UINT32 uiSoundID, UINT32 uiPan);
extern BOOLEAN SoundSetFrequency(UINT32 uiSoundID, UINT32 uiFreq);
extern BOOLEAN SoundSetLoop(UINT32 uiSoundID, UINT32 uiLoop);
extern UINT32 SoundGetVolume(UINT32 uiSoundID);
extern UINT32 SoundGetPan(UINT32 uiSoundID);
extern UINT32 SoundGetFrequency(UINT32 uiSoundID);
extern UINT32 SoundGetLoop(UINT32 uiSoundID);
extern UINT32 SoundGetPosition(UINT32 uiSoundID);
extern BOOLEAN SoundGetMilliSecondPosition(UINT32 uiSoundID, UINT32 *puiTotalMilliseconds, UINT32 *puiCurrentMilliseconds);
// Sound instance group functions
extern BOOLEAN SoundStopGroup(UINT32 uiPriority);
extern BOOLEAN SoundFreeGroup(UINT32 uiPriority);
extern void SoundSetSampleFlags( UINT32 uiSample, UINT32 uiFlags );
extern void SoundRemoveSampleFlags( UINT32 uiSample, UINT32 uiFlags );
extern void SoundEnableSound(BOOLEAN fEnable);
// New 3D sound priovider
extern void Sound3DSetProvider(CHAR8 *pProviderName);
extern BOOLEAN Sound3DInitProvider(CHAR8 *pProviderName);
extern void Sound3DShutdownProvider(void);
// 3D sound control
extern void Sound3DSetPosition(UINT32 uiSample, FLOAT flX, FLOAT flY, FLOAT flZ);
extern void Sound3DSetVelocity(UINT32 uiSample, FLOAT flX, FLOAT flY, FLOAT flZ);
extern void Sound3DSetListener(FLOAT flX, FLOAT flY, FLOAT flZ);
extern void Sound3DSetFacing(FLOAT flXFace, FLOAT flYFace, FLOAT flZFace, FLOAT flXUp, FLOAT flYUp, FLOAT flZUp);
extern void Sound3DSetDirection(UINT32 uiSample, FLOAT flXFace, FLOAT flYFace, FLOAT flZFace, FLOAT flXUp, FLOAT flYUp, FLOAT flZUp);
extern void Sound3DSetFalloff(UINT32 uiSample, FLOAT flMax, FLOAT flMin);
extern void Sound3DSetEnvironment(INT32 iEnvironment);
extern UINT32 Sound3DPlay(STR pFilename, SOUND3DPARMS *pParms);
extern UINT32 Sound3DStartSample(UINT32 uiSample, UINT32 uiChannel, SOUND3DPARMS *pParms);
extern void Sound3DStopAll(void);
extern UINT32 Sound3DPlayRandom(STR pFilename, RANDOM3DPARMS *pParms);
extern UINT32 Sound3DStartRandom(UINT32 uiSample, SOUND3DPOS *Pos);
extern void Sound3DSetRoomType(UINT32 uiRoomType);
// Status query functions
extern UINT32 Sound3DChannelsInUse(void);
extern UINT32 SoundStreamsInUse(void);
extern UINT32 Sound2DChannelsInUse(void);
extern UINT32 SoundTotalChannelsInUse(void);
/*
#ifdef __cplusplus
}
#endif
*/
#endif
+27
View File
@@ -0,0 +1,27 @@
//
// Snap: Implementation of case-insensitive string comparison classes
//
#include "stringicmp.h"
//#include <cctype>
#include <ctype.h>
bool TStringiLess::operator() (std::string const& s1, std::string const& s2) const
{
// An MSVC compliance issue...
//using std::toupper;
std::string::const_iterator p1 = s1.begin();
std::string::const_iterator p2 = s2.begin();
while (p1 != s1.end() && p2 != s2.end() && toupper(*p1) == toupper(*p2)) {
++p1;
++p2;
}
if (p1 == s1.end()) return p2 != s2.end();
if (p2 == s2.end()) return false;
return toupper(*p1) < toupper(*p2);
}
+16
View File
@@ -0,0 +1,16 @@
//
// Snap: Declaration of case-insensitive string comparison classes
//
#pragma warning(disable:4786)
#ifndef STRINGICMP_H
#define STRINGICMP_H
#include <string>
// Function-object that compares strings (s1 < s2) ignoring case
class TStringiLess {
public:
bool operator() (std::string const& s1, std::string const& s2) const;
};
#endif // STRINGICMP_H
+73
View File
@@ -0,0 +1,73 @@
#ifdef JA2_PRECOMPILED_HEADERS
#include "JA2 SGP ALL.H"
#elif defined( WIZ8_PRECOMPILED_HEADERS )
#include "WIZ8 SGP ALL.H"
#else
#include "types.h"
#include <windows.h>
#if defined( JA2 ) || defined( UTIL )
#include "video.h"
#else
#include "video2.h"
#endif
#include "timer.h"
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
UINT32 guiStartupTime;
UINT32 guiCurrentTime;
void CALLBACK Clock( HWND hWindow, UINT uMessage, UINT idEvent, DWORD dwTime )
{
guiCurrentTime = GetTickCount();
if (guiCurrentTime < guiStartupTime)
{ // Adjust guiCurrentTime because of loopback on the timer value
guiCurrentTime = guiCurrentTime + (0xffffffff - guiStartupTime);
}
else
{ // Adjust guiCurrentTime because of loopback on the timer value
guiCurrentTime = guiCurrentTime - guiStartupTime;
}
}
BOOLEAN InitializeClockManager(void)
{
// Register the start time (use WIN95 API call)
guiCurrentTime = guiStartupTime = GetTickCount();
SetTimer(ghWindow, MAIN_TIMER_ID, 10, (TIMERPROC)Clock);
return TRUE;
}
void ShutdownClockManager(void)
{
// Make sure we kill the timer
KillTimer(ghWindow, MAIN_TIMER_ID);
}
TIMER GetClock(void)
{
return guiCurrentTime;
}
TIMER SetCountdownClock(UINT32 uiTimeToElapse)
{
return (guiCurrentTime + uiTimeToElapse);
}
UINT32 ClockIsTicking(TIMER uiTimer)
{
if (uiTimer > guiCurrentTime)
{ // Well timer still hasn't elapsed
return (uiTimer - guiCurrentTime);
}
// Time's up
return 0;
}
+30
View File
@@ -0,0 +1,30 @@
#ifndef __TIMER_
#define __TIMER_
#include "types.h"
typedef UINT32 TIMER;
#define MAIN_TIMER_ID 1
#define MILLISECONDS(a) (a)
#define SECONDS(a) ((a) / 1000)
#define MINUTES(a) (SECOND((a)) / 60)
#define HOURS(a) (MINUTES((a)) / 60)
#define DAYS(a) (HOURS((a)) / 24)
#ifdef __cplusplus
extern "C" {
#endif
BOOLEAN InitializeClockManager(void);
void ShutdownClockManager(void);
TIMER GetClock(void);
TIMER SetCountdownClock(UINT32 TimeToElapse);
UINT32 ClockIsTicking(TIMER uiTimer);
#ifdef __cplusplus
}
#endif
#endif
+31
View File
@@ -0,0 +1,31 @@
#ifndef __TRLE_H
#define __TRLE_H
typedef struct
{
UINT32 uiOffset;
UINT32 uiWidth;
UINT32 uiOffLen;
INT16 sOffsetX;
INT16 sOffsetY;
} TRLEObject;
typedef struct
{
UINT32 uiHeightEach;
UINT32 uiTotalElements;
TRLEObject *pTRLEObject;
PTR pPixData;
UINT32 uiSizePixDataElem;
} TRLEData;
BOOLEAN GetTRLEObjectData( UINT32 uiTotalElements, TRLEObject *pTRLEObject, INT16 ssIndex, UINT32 *pWidth, UINT32 *pOffset, UINT32 *pOffLen, UINT16 *pOffsetX, UINT16 *pOffsetY );
BOOLEAN SetTRLEObjectOffset( UINT32 uiTotalElements, TRLEObject *pTRLEObject, INT16 ssIndex, INT16 sOffsetX, INT16 sOffsetY );
#endif
File diff suppressed because it is too large Load Diff
+99
View File
@@ -0,0 +1,99 @@
#ifndef __VIDEO_
#define __VIDEO_
#include <windows.h>
#include <ddraw.h>
#include <process.h>
#include "Local.h"
#include "Debug.h"
#include "Types.h"
#include "DirectDraw Calls.h"
#include "VSurface.h"
#include "Mutex Manager.h"
#define BUFFER_READY 0x00
#define BUFFER_BUSY 0x01
#define BUFFER_DIRTY 0x02
#define BUFFER_DISABLED 0x03
#define MAX_CURSOR_WIDTH 64
#define MAX_CURSOR_HEIGHT 64
#define VIDEO_NO_CURSOR 0xFFFF
extern HWND ghWindow;
extern UINT32 guiMouseBufferState; // BUFFER_READY, BUFFER_DIRTY, BUFFER_DISABLED
/*
#ifdef __cplusplus
extern "C" {
#endif
*/
extern BOOLEAN InitializeVideoManager(HINSTANCE hInstance, UINT16 usCommandShow, void *WindowProc);
extern void ShutdownVideoManager(void);
extern void SuspendVideoManager(void);
extern BOOLEAN RestoreVideoManager(void);
extern void GetCurrentVideoSettings(UINT16 *usWidth, UINT16 *usHeight, UINT8 *ubBitDepth);
extern BOOLEAN CanBlitToFrameBuffer(void);
extern BOOLEAN CanBlitToMouseBuffer(void);
extern void InvalidateRegion(INT32 iLeft, INT32 iTop, INT32 iRight, INT32 iBottom);
extern void InvalidateRegions(SGPRect *pArrayOfRegions, UINT32 uiRegionCount);
extern void InvalidateScreen(void);
extern void InvalidateFrameBuffer(void);
extern void SetFrameBufferRefreshOverride(PTR pFrameBufferRefreshOverride);
extern LPDIRECTDRAW2 GetDirectDraw2Object(void);
extern LPDIRECTDRAWSURFACE2 GetPrimarySurfaceObject(void);
extern LPDIRECTDRAWSURFACE2 GetBackBufferObject(void);
extern LPDIRECTDRAWSURFACE2 GetFrameBufferObject(void);
extern LPDIRECTDRAWSURFACE2 GetMouseBufferObject(void);
extern PTR LockPrimarySurface(UINT32 *uiPitch);
extern void UnlockPrimarySurface(void);
extern PTR LockBackBuffer(UINT32 *uiPitch);
extern void UnlockBackBuffer(void);
extern PTR LockFrameBuffer(UINT32 *uiPitch);
extern void UnlockFrameBuffer(void);
extern PTR LockMouseBuffer(UINT32 *uiPitch);
extern void UnlockMouseBuffer(void);
extern BOOLEAN GetRGBDistribution(void);
extern BOOLEAN GetPrimaryRGBDistributionMasks(UINT32 *RedBitMask, UINT32 *GreenBitMask, UINT32 *BblueBitMask);
extern BOOLEAN SetMouseCursorFromObject(UINT32 uiVideoObjectHandle, UINT16 usVideoObjectSubIndex, UINT16 usOffsetX, UINT16 usOffsetY );
extern BOOLEAN HideMouseCursor(void);
extern BOOLEAN LoadCursorFile(PTR pFilename);
extern BOOLEAN SetCurrentCursor(UINT16 usVideoObjectSubIndex, UINT16 usOffsetX, UINT16 usOffsetY );
extern void StartFrameBufferRender(void);
extern void EndFrameBufferRender(void);
extern void PrintScreen(void);
extern BOOLEAN EraseMouseCursor( );
extern BOOLEAN SetMouseCursorProperties( INT16 sOffsetX, INT16 sOffsetY, UINT16 usCursorHeight, UINT16 usCursorWidth );
extern BOOLEAN BltToMouseCursor(UINT32 uiVideoObjectHandle, UINT16 usVideoObjectSubIndex, UINT16 usXPos, UINT16 usYPos );
void DirtyCursor( );
void EnableCursor( BOOLEAN fEnable );
BOOLEAN Set8BPPPalette(SGPPaletteEntry *pPalette);
// 8-bit palette globals
void VideoCaptureToggle( void );
void InvalidateRegionEx(INT32 iLeft, INT32 iTop, INT32 iRight, INT32 iBottom, UINT32 uiFlags );
void RefreshScreen(void *DummyVariable);
template <typename string1>
void FatalError( string1 pError, ...);
extern SGPPaletteEntry gSgpPalette[256];
extern LPDIRECTDRAWPALETTE gpDirectDrawPalette;
/*
#ifdef __cplusplus
}
#endif
*/
#endif
+21
View File
@@ -0,0 +1,21 @@
#ifndef __VIDEO_PRIVATE_
#define __VIDEO_PRIVATE_
// ***********************************************************************
//
// PRIVATE, INTERNAL Header used by other SGP Internal modules
//
// Allows direct access to underlying Direct Draw Implementation
//
// ***********************************************************************
LPDIRECTDRAW2 GetDirectDraw2Object( );
LPDIRECTDRAWSURFACE2 GetPrimarySurfaceInterface( );
LPDIRECTDRAWSURFACE2 GetBackbufferInterface( );
BOOLEAN SetDirectDraw2Object( LPDIRECTDRAW2 pDirectDraw );
BOOLEAN SetPrimarySurfaceInterface( LPDIRECTDRAWSURFACE2 pSurface );
BOOLEAN SetBackbufferInterface( LPDIRECTDRAWSURFACE2 pSurface );
#endif
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More