Formatting changes to jmact

git-svn-id: https://svn.eduke32.com/eduke32@809 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-06-29 10:41:01 +00:00
parent 2fa3153a84
commit 3c51265878
8 changed files with 1322 additions and 1185 deletions

View file

@ -51,11 +51,11 @@ static boolean Anim_Started = false;
// //
//**************************************************************************** //****************************************************************************
static void CheckAnimStarted ( char * funcname ) static void CheckAnimStarted(char * funcname)
{ {
if (!Anim_Started) if (!Anim_Started)
Error("ANIMLIB_%s: Anim has not been initialized\n",funcname); Error("ANIMLIB_%s: Anim has not been initialized\n",funcname);
} }
//**************************************************************************** //****************************************************************************
// //
// findpage () // findpage ()
@ -63,22 +63,22 @@ static void CheckAnimStarted ( char * funcname )
// //
//**************************************************************************** //****************************************************************************
uint16 findpage (uint16 framenumber) uint16 findpage(uint16 framenumber)
{ {
uint16 i; uint16 i;
CheckAnimStarted ( "findpage" ); CheckAnimStarted("findpage");
for(i=0; i<anim->lpheader.nLps; i++) for (i=0; i<anim->lpheader.nLps; i++)
{ {
if if
( (
anim->LpArray[i].baseRecord <= framenumber && anim->LpArray[i].baseRecord <= framenumber &&
anim->LpArray[i].baseRecord + anim->LpArray[i].nRecords > framenumber anim->LpArray[i].baseRecord + anim->LpArray[i].nRecords > framenumber
) )
return(i); return(i);
} }
return(i); return(i);
} }
//**************************************************************************** //****************************************************************************
@ -88,32 +88,32 @@ uint16 findpage (uint16 framenumber)
// //
//**************************************************************************** //****************************************************************************
void loadpage (uint16 pagenumber, uint16 *pagepointer) void loadpage(uint16 pagenumber, uint16 *pagepointer)
{ {
int32 size; int32 size;
byte * buffer; byte * buffer;
CheckAnimStarted ( "loadpage" ); CheckAnimStarted("loadpage");
buffer = anim->buffer; buffer = anim->buffer;
if (anim->curlpnum != pagenumber) if (anim->curlpnum != pagenumber)
{ {
anim->curlpnum = pagenumber; anim->curlpnum = pagenumber;
buffer += 0xb00 + (pagenumber*0x10000); buffer += 0xb00 + (pagenumber*0x10000);
size = sizeof(lp_descriptor); size = sizeof(lp_descriptor);
/* /*
Bmemcpy(&anim->curlp,buffer,size); Bmemcpy(&anim->curlp,buffer,size);
// JBF: why didn't this get read from the LpArray[] table? // JBF: why didn't this get read from the LpArray[] table?
anim->curlp.baseRecord = B_LITTLE16(anim->curlp.baseRecord); anim->curlp.baseRecord = B_LITTLE16(anim->curlp.baseRecord);
anim->curlp.nRecords = B_LITTLE16(anim->curlp.nRecords); anim->curlp.nRecords = B_LITTLE16(anim->curlp.nRecords);
anim->curlp.nBytes = B_LITTLE16(anim->curlp.nBytes); anim->curlp.nBytes = B_LITTLE16(anim->curlp.nBytes);
*/ */
Bmemcpy(&anim->curlp, &anim->LpArray[pagenumber], size); Bmemcpy(&anim->curlp, &anim->LpArray[pagenumber], size);
buffer += size + sizeof(uint16); buffer += size + sizeof(uint16);
Bmemcpy(pagepointer,buffer,anim->curlp.nBytes+(anim->curlp.nRecords*2)); Bmemcpy(pagepointer,buffer,anim->curlp.nBytes+(anim->curlp.nRecords*2));
} }
} }
//**************************************************************************** //****************************************************************************
@ -123,76 +123,80 @@ void loadpage (uint16 pagenumber, uint16 *pagepointer)
// //
//**************************************************************************** //****************************************************************************
void CPlayRunSkipDump (char *srcP, char *dstP) void CPlayRunSkipDump(char *srcP, char *dstP)
{ {
signed char cnt; signed char cnt;
uint16 wordCnt; uint16 wordCnt;
byte pixel; byte pixel;
nextOp: nextOp:
cnt = (signed char) *srcP++; cnt = (signed char) *srcP++;
if (cnt > 0) if (cnt > 0)
goto dump; goto dump;
if (cnt == 0) if (cnt == 0)
goto run; goto run;
cnt -= 0x80; cnt -= 0x80;
if (cnt == 0) if (cnt == 0)
goto longOp; goto longOp;
/* shortSkip */ /* shortSkip */
dstP += cnt; /* adding 7-bit count to 32-bit pointer */ dstP += cnt; /* adding 7-bit count to 32-bit pointer */
goto nextOp; goto nextOp;
dump: dump:
do do
{ {
*dstP++ = *srcP++; *dstP++ = *srcP++;
} while (--cnt); }
goto nextOp; while (--cnt);
goto nextOp;
run: run:
wordCnt = (byte)*srcP++; /* 8-bit unsigned count */ wordCnt = (byte)*srcP++; /* 8-bit unsigned count */
pixel = *srcP++; pixel = *srcP++;
do do
{ {
*dstP++ = pixel; *dstP++ = pixel;
} while (--wordCnt); }
while (--wordCnt);
goto nextOp; goto nextOp;
longOp: longOp:
wordCnt = B_LITTLE16(*((uint16 *)srcP)); wordCnt = B_LITTLE16(*((uint16 *)srcP));
srcP += sizeof(uint16); srcP += sizeof(uint16);
if ((int16)wordCnt <= 0) if ((int16)wordCnt <= 0)
goto notLongSkip; /* Do SIGNED test. */ goto notLongSkip; /* Do SIGNED test. */
/* longSkip. */ /* longSkip. */
dstP += wordCnt; dstP += wordCnt;
goto nextOp; goto nextOp;
notLongSkip: notLongSkip:
if (wordCnt == 0) if (wordCnt == 0)
goto stop; goto stop;
wordCnt -= 0x8000; /* Remove sign bit. */ wordCnt -= 0x8000; /* Remove sign bit. */
if (wordCnt >= 0x4000) if (wordCnt >= 0x4000)
goto longRun; goto longRun;
/* longDump. */ /* longDump. */
do do
{ {
*dstP++ = *srcP++; *dstP++ = *srcP++;
} while (--wordCnt); }
goto nextOp; while (--wordCnt);
goto nextOp;
longRun: longRun:
wordCnt -= 0x4000; /* Clear "longRun" bit. */ wordCnt -= 0x4000; /* Clear "longRun" bit. */
pixel = *srcP++; pixel = *srcP++;
do do
{ {
*dstP++ = pixel; *dstP++ = pixel;
} while (--wordCnt); }
goto nextOp; while (--wordCnt);
goto nextOp;
stop: /* all done */ stop: /* all done */
; ;
} }
@ -203,34 +207,34 @@ stop: /* all done */
// //
//**************************************************************************** //****************************************************************************
void renderframe (uint16 framenumber, uint16 *pagepointer) void renderframe(uint16 framenumber, uint16 *pagepointer)
{ {
uint16 offset=0; uint16 offset=0;
uint16 i; uint16 i;
uint16 destframe; uint16 destframe;
byte *ppointer; byte *ppointer;
CheckAnimStarted ( "renderframe" ); CheckAnimStarted("renderframe");
destframe = framenumber - anim->curlp.baseRecord; destframe = framenumber - anim->curlp.baseRecord;
for(i = 0; i < destframe; i++) for (i = 0; i < destframe; i++)
{ {
offset += B_LITTLE16(pagepointer[i]); offset += B_LITTLE16(pagepointer[i]);
} }
ppointer = (byte *)pagepointer; ppointer = (byte *)pagepointer;
ppointer+=anim->curlp.nRecords*2+offset; ppointer+=anim->curlp.nRecords*2+offset;
if(ppointer[1]) if (ppointer[1])
{ {
ppointer += (4 + B_LITTLE16(((uint16 *)ppointer)[1]) + (B_LITTLE16(((uint16 *)ppointer)[1]) & 1)); ppointer += (4 + B_LITTLE16(((uint16 *)ppointer)[1]) + (B_LITTLE16(((uint16 *)ppointer)[1]) & 1));
} }
else else
{ {
ppointer+=4; ppointer+=4;
} }
CPlayRunSkipDump ((char *)ppointer, (char *)anim->imagebuffer); CPlayRunSkipDump((char *)ppointer, (char *)anim->imagebuffer);
} }
//**************************************************************************** //****************************************************************************
@ -240,12 +244,12 @@ void renderframe (uint16 framenumber, uint16 *pagepointer)
// //
//**************************************************************************** //****************************************************************************
void drawframe (uint16 framenumber) void drawframe(uint16 framenumber)
{ {
CheckAnimStarted ( "drawframe" ); CheckAnimStarted("drawframe");
loadpage(findpage(framenumber), anim->thepage); loadpage(findpage(framenumber), anim->thepage);
renderframe(framenumber, anim->thepage); renderframe(framenumber, anim->thepage);
} }
//**************************************************************************** //****************************************************************************
@ -254,54 +258,55 @@ void drawframe (uint16 framenumber)
// //
//**************************************************************************** //****************************************************************************
void ANIM_LoadAnim (char * buffer) void ANIM_LoadAnim(char * buffer)
{ {
uint16 i; uint16 i;
int32 size; int32 size;
if (!Anim_Started) { if (!Anim_Started)
anim = SafeMalloc(sizeof(anim_t)); {
Anim_Started = true; anim = SafeMalloc(sizeof(anim_t));
} Anim_Started = true;
}
anim->buffer = (unsigned char *)buffer; anim->buffer = (unsigned char *)buffer;
anim->curlpnum = 0xffff; anim->curlpnum = 0xffff;
anim->currentframe = -1; anim->currentframe = -1;
size = sizeof(lpfileheader); size = sizeof(lpfileheader);
Bmemcpy(&anim->lpheader, buffer, size ); Bmemcpy(&anim->lpheader, buffer, size);
anim->lpheader.id = B_LITTLE32(anim->lpheader.id); anim->lpheader.id = B_LITTLE32(anim->lpheader.id);
anim->lpheader.maxLps = B_LITTLE16(anim->lpheader.maxLps); anim->lpheader.maxLps = B_LITTLE16(anim->lpheader.maxLps);
anim->lpheader.nLps = B_LITTLE16(anim->lpheader.nLps); anim->lpheader.nLps = B_LITTLE16(anim->lpheader.nLps);
anim->lpheader.nRecords = B_LITTLE32(anim->lpheader.nRecords); anim->lpheader.nRecords = B_LITTLE32(anim->lpheader.nRecords);
anim->lpheader.maxRecsPerLp = B_LITTLE16(anim->lpheader.maxRecsPerLp); anim->lpheader.maxRecsPerLp = B_LITTLE16(anim->lpheader.maxRecsPerLp);
anim->lpheader.lpfTableOffset = B_LITTLE16(anim->lpheader.lpfTableOffset); anim->lpheader.lpfTableOffset = B_LITTLE16(anim->lpheader.lpfTableOffset);
anim->lpheader.contentType = B_LITTLE32(anim->lpheader.contentType); anim->lpheader.contentType = B_LITTLE32(anim->lpheader.contentType);
anim->lpheader.width = B_LITTLE16(anim->lpheader.width); anim->lpheader.width = B_LITTLE16(anim->lpheader.width);
anim->lpheader.height = B_LITTLE16(anim->lpheader.height); anim->lpheader.height = B_LITTLE16(anim->lpheader.height);
anim->lpheader.nFrames = B_LITTLE32(anim->lpheader.nFrames); anim->lpheader.nFrames = B_LITTLE32(anim->lpheader.nFrames);
anim->lpheader.framesPerSecond = B_LITTLE16(anim->lpheader.framesPerSecond); anim->lpheader.framesPerSecond = B_LITTLE16(anim->lpheader.framesPerSecond);
buffer += size+128; buffer += size+128;
// load the color palette // load the color palette
for (i = 0; i < 768; i += 3) for (i = 0; i < 768; i += 3)
{ {
anim->pal[i+2] = *buffer++; anim->pal[i+2] = *buffer++;
anim->pal[i+1] = *buffer++; anim->pal[i+1] = *buffer++;
anim->pal[i] = *buffer++; anim->pal[i] = *buffer++;
buffer++; buffer++;
} }
// read in large page descriptors // read in large page descriptors
size = sizeof(anim->LpArray); size = sizeof(anim->LpArray);
Bmemcpy(&anim->LpArray,buffer,size); Bmemcpy(&anim->LpArray,buffer,size);
for (i = 0; i < size/sizeof(lp_descriptor); i++) for (i = 0; i < size/sizeof(lp_descriptor); i++)
{ {
anim->LpArray[i].baseRecord = B_LITTLE16(anim->LpArray[i].baseRecord); anim->LpArray[i].baseRecord = B_LITTLE16(anim->LpArray[i].baseRecord);
anim->LpArray[i].nRecords = B_LITTLE16(anim->LpArray[i].nRecords); anim->LpArray[i].nRecords = B_LITTLE16(anim->LpArray[i].nRecords);
anim->LpArray[i].nBytes = B_LITTLE16(anim->LpArray[i].nBytes); anim->LpArray[i].nBytes = B_LITTLE16(anim->LpArray[i].nBytes);
} }
} }
//**************************************************************************** //****************************************************************************
// //
@ -309,14 +314,14 @@ void ANIM_LoadAnim (char * buffer)
// //
//**************************************************************************** //****************************************************************************
void ANIM_FreeAnim ( void ) void ANIM_FreeAnim(void)
{ {
if (Anim_Started) if (Anim_Started)
{ {
SafeFree(anim); SafeFree(anim);
Anim_Started = false; Anim_Started = false;
} }
} }
//**************************************************************************** //****************************************************************************
// //
@ -324,11 +329,11 @@ void ANIM_FreeAnim ( void )
// //
//**************************************************************************** //****************************************************************************
int32 ANIM_NumFrames ( void ) int32 ANIM_NumFrames(void)
{ {
CheckAnimStarted ( "NumFrames" ); CheckAnimStarted("NumFrames");
return anim->lpheader.nRecords; return anim->lpheader.nRecords;
} }
//**************************************************************************** //****************************************************************************
// //
@ -336,24 +341,24 @@ int32 ANIM_NumFrames ( void )
// //
//**************************************************************************** //****************************************************************************
byte * ANIM_DrawFrame (int32 framenumber) byte * ANIM_DrawFrame(int32 framenumber)
{ {
int32 cnt; int32 cnt;
CheckAnimStarted ( "DrawFrame" ); CheckAnimStarted("DrawFrame");
if ((anim->currentframe != -1) && (anim->currentframe<=framenumber)) if ((anim->currentframe != -1) && (anim->currentframe<=framenumber))
{ {
for (cnt = anim->currentframe; cnt < framenumber; cnt++) for (cnt = anim->currentframe; cnt < framenumber; cnt++)
drawframe (cnt); drawframe(cnt);
} }
else else
{ {
for (cnt = 0; cnt < framenumber; cnt++) for (cnt = 0; cnt < framenumber; cnt++)
drawframe (cnt); drawframe(cnt);
} }
anim->currentframe = framenumber; anim->currentframe = framenumber;
return anim->imagebuffer; return anim->imagebuffer;
} }
//**************************************************************************** //****************************************************************************
// //
@ -361,8 +366,8 @@ byte * ANIM_DrawFrame (int32 framenumber)
// //
//**************************************************************************** //****************************************************************************
byte * ANIM_GetPalette ( void ) byte * ANIM_GetPalette(void)
{ {
CheckAnimStarted ( "GetPalette" ); CheckAnimStarted("GetPalette");
return anim->pal; return anim->pal;
} }

View file

@ -50,7 +50,7 @@ static boolean CONTROL_MouseButtonClickedState[MAXMOUSEBUTTONS], CONTROL_JoyButt
static boolean CONTROL_MouseButtonClicked[MAXMOUSEBUTTONS], CONTROL_JoyButtonClicked[MAXJOYBUTTONS]; static boolean CONTROL_MouseButtonClicked[MAXMOUSEBUTTONS], CONTROL_JoyButtonClicked[MAXJOYBUTTONS];
static byte CONTROL_MouseButtonClickedCount[MAXMOUSEBUTTONS], CONTROL_JoyButtonClickedCount[MAXJOYBUTTONS]; static byte CONTROL_MouseButtonClickedCount[MAXMOUSEBUTTONS], CONTROL_JoyButtonClickedCount[MAXJOYBUTTONS];
static boolean CONTROL_UserInputCleared[3]; static boolean CONTROL_UserInputCleared[3];
static int32 (*GetTime)(void); static int32(*GetTime)(void);
static boolean CONTROL_Started = false; static boolean CONTROL_Started = false;
static int32 ticrate; static int32 ticrate;
static int32 CONTROL_DoubleClickSpeed; static int32 CONTROL_DoubleClickSpeed;
@ -92,7 +92,7 @@ boolean CONTROL_StartMouse(void)
return MOUSE_Init(); return MOUSE_Init();
} }
void CONTROL_GetJoyAbs( void ) void CONTROL_GetJoyAbs(void)
{ {
} }
@ -100,7 +100,7 @@ void CONTROL_FilterJoyDelta(void)
{ {
} }
void CONTROL_GetJoyDelta( void ) void CONTROL_GetJoyDelta(void)
{ {
int32 i; int32 i;
@ -139,12 +139,18 @@ void CONTROL_SetFlag(int32 which, boolean active)
{ {
if (CONTROL_CheckRange(which)) return; if (CONTROL_CheckRange(which)) return;
if (CONTROL_Flags[which].toggle == INSTANT_ONOFF) { if (CONTROL_Flags[which].toggle == INSTANT_ONOFF)
{
CONTROL_Flags[which].active = active; CONTROL_Flags[which].active = active;
} else { }
if (active) { else
{
if (active)
{
CONTROL_Flags[which].buttonheld = false; CONTROL_Flags[which].buttonheld = false;
} else if (CONTROL_Flags[which].buttonheld == false) { }
else if (CONTROL_Flags[which].buttonheld == false)
{
CONTROL_Flags[which].buttonheld = true; CONTROL_Flags[which].buttonheld = true;
CONTROL_Flags[which].active = (CONTROL_Flags[which].active ? false : true); CONTROL_Flags[which].active = (CONTROL_Flags[which].active ? false : true);
} }
@ -181,7 +187,7 @@ void CONTROL_ClearKeyboardFunction(int32 which)
KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] = 0; KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] = 0;
} }
void CONTROL_DefineFlag( int32 which, boolean toggle ) void CONTROL_DefineFlag(int32 which, boolean toggle)
{ {
if (CONTROL_CheckRange(which)) return; if (CONTROL_CheckRange(which)) return;
@ -192,14 +198,14 @@ void CONTROL_DefineFlag( int32 which, boolean toggle )
CONTROL_Flags[which].cleared = 0; CONTROL_Flags[which].cleared = 0;
} }
boolean CONTROL_FlagActive( int32 which ) boolean CONTROL_FlagActive(int32 which)
{ {
if (CONTROL_CheckRange(which)) return false; if (CONTROL_CheckRange(which)) return false;
return CONTROL_Flags[which].used; return CONTROL_Flags[which].used;
} }
void CONTROL_MapKey( int32 which, kb_scancode key1, kb_scancode key2 ) void CONTROL_MapKey(int32 which, kb_scancode key1, kb_scancode key2)
{ {
if (CONTROL_CheckRange(which)) return; if (CONTROL_CheckRange(which)) return;
@ -211,7 +217,8 @@ void CONTROL_PrintKeyMap(void)
{ {
int32 i; int32 i;
for (i=0;i<CONTROL_NUM_FLAGS;i++) { for (i=0;i<CONTROL_NUM_FLAGS;i++)
{
initprintf("function %2ld key1=%3x key2=%3x\n", initprintf("function %2ld key1=%3x key2=%3x\n",
i, CONTROL_KeyMapping[i].key1, CONTROL_KeyMapping[i].key2); i, CONTROL_KeyMapping[i].key1, CONTROL_KeyMapping[i].key2);
} }
@ -230,29 +237,33 @@ void CONTROL_PrintAxes(void)
int32 i; int32 i;
initprintf("nummouseaxes=%d\n", CONTROL_NumMouseAxes); initprintf("nummouseaxes=%d\n", CONTROL_NumMouseAxes);
for (i=0;i<CONTROL_NumMouseAxes;i++) { for (i=0;i<CONTROL_NumMouseAxes;i++)
{
initprintf("axis=%d analog=%d digital1=%d digital2=%d\n", initprintf("axis=%d analog=%d digital1=%d digital2=%d\n",
i, CONTROL_MouseAxesMap[i].analogmap, i, CONTROL_MouseAxesMap[i].analogmap,
CONTROL_MouseAxesMap[i].minmap, CONTROL_MouseAxesMap[i].maxmap); CONTROL_MouseAxesMap[i].minmap, CONTROL_MouseAxesMap[i].maxmap);
} }
initprintf("numjoyaxes=%d\n", CONTROL_NumJoyAxes); initprintf("numjoyaxes=%d\n", CONTROL_NumJoyAxes);
for (i=0;i<CONTROL_NumJoyAxes;i++) { for (i=0;i<CONTROL_NumJoyAxes;i++)
{
initprintf("axis=%d analog=%d digital1=%d digital2=%d\n", initprintf("axis=%d analog=%d digital1=%d digital2=%d\n",
i, CONTROL_JoyAxesMap[i].analogmap, i, CONTROL_JoyAxesMap[i].analogmap,
CONTROL_JoyAxesMap[i].minmap, CONTROL_JoyAxesMap[i].maxmap); CONTROL_JoyAxesMap[i].minmap, CONTROL_JoyAxesMap[i].maxmap);
} }
} }
void CONTROL_MapButton( int32 whichfunction, int32 whichbutton, boolean doubleclicked, controldevice device ) void CONTROL_MapButton(int32 whichfunction, int32 whichbutton, boolean doubleclicked, controldevice device)
{ {
controlbuttontype *set; controlbuttontype *set;
if (CONTROL_CheckRange(whichfunction)) whichfunction = BUTTONUNDEFINED; if (CONTROL_CheckRange(whichfunction)) whichfunction = BUTTONUNDEFINED;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
if ((uint32)whichbutton >= (uint32)MAXMOUSEBUTTONS) { if ((uint32)whichbutton >= (uint32)MAXMOUSEBUTTONS)
{
//Error("CONTROL_MapButton: button %d out of valid range for %d mouse buttons.", //Error("CONTROL_MapButton: button %d out of valid range for %d mouse buttons.",
// whichbutton, CONTROL_NumMouseButtons); // whichbutton, CONTROL_NumMouseButtons);
return; return;
@ -261,7 +272,8 @@ void CONTROL_MapButton( int32 whichfunction, int32 whichbutton, boolean doublecl
break; break;
case controldevice_joystick: case controldevice_joystick:
if ((uint32)whichbutton >= (uint32)MAXJOYBUTTONS) { if ((uint32)whichbutton >= (uint32)MAXJOYBUTTONS)
{
//Error("CONTROL_MapButton: button %d out of valid range for %d joystick buttons.", //Error("CONTROL_MapButton: button %d out of valid range for %d joystick buttons.",
// whichbutton, CONTROL_NumJoyButtons); // whichbutton, CONTROL_NumJoyButtons);
return; return;
@ -280,19 +292,22 @@ void CONTROL_MapButton( int32 whichfunction, int32 whichbutton, boolean doublecl
set[whichbutton].singleclicked = whichfunction; set[whichbutton].singleclicked = whichfunction;
} }
void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice device ) void CONTROL_MapAnalogAxis(int32 whichaxis, int32 whichanalog, controldevice device)
{ {
controlaxismaptype *set; controlaxismaptype *set;
if ((uint32)whichanalog >= (uint32)analog_maxtype) { if ((uint32)whichanalog >= (uint32)analog_maxtype)
{
//Error("CONTROL_MapAnalogAxis: analog function %d out of valid range for %d analog functions.", //Error("CONTROL_MapAnalogAxis: analog function %d out of valid range for %d analog functions.",
// whichanalog, analog_maxtype); // whichanalog, analog_maxtype);
return; return;
} }
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES) { if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES)
{
//Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d mouse axes.", //Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d mouse axes.",
// whichaxis, MAXMOUSEAXES); // whichaxis, MAXMOUSEAXES);
return; return;
@ -302,7 +317,8 @@ void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice de
break; break;
case controldevice_joystick: case controldevice_joystick:
if ((uint32)whichaxis >= (uint32)MAXJOYAXES) { if ((uint32)whichaxis >= (uint32)MAXJOYAXES)
{
//Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d joystick axes.", //Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d joystick axes.",
// whichaxis, MAXJOYAXES); // whichaxis, MAXJOYAXES);
return; return;
@ -319,13 +335,15 @@ void CONTROL_MapAnalogAxis( int32 whichaxis, int32 whichanalog, controldevice de
set[whichaxis].analogmap = whichanalog; set[whichaxis].analogmap = whichanalog;
} }
void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice device ) void CONTROL_SetAnalogAxisScale(int32 whichaxis, int32 axisscale, controldevice device)
{ {
int32 *set; int32 *set;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES) { if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES)
{
//Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d mouse axes.", //Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d mouse axes.",
// whichaxis, MAXMOUSEAXES); // whichaxis, MAXMOUSEAXES);
return; return;
@ -335,7 +353,8 @@ void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice
break; break;
case controldevice_joystick: case controldevice_joystick:
if ((uint32)whichaxis >= (uint32)MAXJOYAXES) { if ((uint32)whichaxis >= (uint32)MAXJOYAXES)
{
//Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d joystick axes.", //Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d joystick axes.",
// whichaxis, MAXJOYAXES); // whichaxis, MAXJOYAXES);
return; return;
@ -352,15 +371,17 @@ void CONTROL_SetAnalogAxisScale( int32 whichaxis, int32 axisscale, controldevice
set[whichaxis] = axisscale; set[whichaxis] = axisscale;
} }
void CONTROL_MapDigitalAxis( int32 whichaxis, int32 whichfunction, int32 direction, controldevice device ) void CONTROL_MapDigitalAxis(int32 whichaxis, int32 whichfunction, int32 direction, controldevice device)
{ {
controlaxismaptype *set; controlaxismaptype *set;
if (CONTROL_CheckRange(whichfunction)) whichfunction = AXISUNDEFINED; if (CONTROL_CheckRange(whichfunction)) whichfunction = AXISUNDEFINED;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES) { if ((uint32)whichaxis >= (uint32)MAXMOUSEAXES)
{
//Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d mouse axes.", //Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d mouse axes.",
// whichaxis, MAXMOUSEAXES); // whichaxis, MAXMOUSEAXES);
return; return;
@ -370,7 +391,8 @@ void CONTROL_MapDigitalAxis( int32 whichaxis, int32 whichfunction, int32 directi
break; break;
case controldevice_joystick: case controldevice_joystick:
if ((uint32)whichaxis >= (uint32)MAXJOYAXES) { if ((uint32)whichaxis >= (uint32)MAXJOYAXES)
{
//Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d joystick axes.", //Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d joystick axes.",
// whichaxis, MAXJOYAXES); // whichaxis, MAXJOYAXES);
return; return;
@ -384,7 +406,8 @@ void CONTROL_MapDigitalAxis( int32 whichaxis, int32 whichfunction, int32 directi
return; return;
} }
switch (direction) { // JBF: this is all very much a guess. The ASM puzzles me. switch (direction) // JBF: this is all very much a guess. The ASM puzzles me.
{
case axis_up: case axis_up:
case axis_left: case axis_left:
set[whichaxis].minmap = whichfunction; set[whichaxis].minmap = whichfunction;
@ -406,7 +429,7 @@ void CONTROL_ClearFlags(void)
CONTROL_Flags[i].used = false; CONTROL_Flags[i].used = false;
} }
void CONTROL_ClearAssignments( void ) void CONTROL_ClearAssignments(void)
{ {
int32 i; int32 i;
@ -433,33 +456,42 @@ static void DoGetDeviceButtons(
boolean *ButtonClickedState, boolean *ButtonClickedState,
boolean *ButtonClicked, boolean *ButtonClicked,
byte *ButtonClickedCount byte *ButtonClickedCount
) { )
{
int32 i, bs; int32 i, bs;
for (i=0;i<NumButtons;i++) { for (i=0;i<NumButtons;i++)
{
bs = (buttons >> i) & 1; bs = (buttons >> i) & 1;
DeviceButtonState[i] = bs; DeviceButtonState[i] = bs;
ButtonClickedState[i] = false; ButtonClickedState[i] = false;
if (bs) { if (bs)
if (ButtonClicked[i] == false) { {
if (ButtonClicked[i] == false)
{
ButtonClicked[i] = true; ButtonClicked[i] = true;
if (ButtonClickedCount[i] == 0 || tm > ButtonClickedTime[i]) { if (ButtonClickedCount[i] == 0 || tm > ButtonClickedTime[i])
{
ButtonClickedTime[i] = tm + CONTROL_DoubleClickSpeed; ButtonClickedTime[i] = tm + CONTROL_DoubleClickSpeed;
ButtonClickedCount[i] = 1; ButtonClickedCount[i] = 1;
} }
else if (tm < ButtonClickedTime[i]) { else if (tm < ButtonClickedTime[i])
{
ButtonClickedState[i] = true; ButtonClickedState[i] = true;
ButtonClickedTime[i] = 0; ButtonClickedTime[i] = 0;
ButtonClickedCount[i] = 2; ButtonClickedCount[i] = 2;
} }
} }
else if (ButtonClickedCount[i] == 2) { else if (ButtonClickedCount[i] == 2)
{
ButtonClickedState[i] = true; ButtonClickedState[i] = true;
} }
} else { }
else
{
if (ButtonClickedCount[i] == 2) if (ButtonClickedCount[i] == 2)
ButtonClickedCount[i] = 0; ButtonClickedCount[i] = 0;
@ -474,7 +506,8 @@ void CONTROL_GetDeviceButtons(void)
t = GetTime(); t = GetTime();
if (CONTROL_MouseEnabled) { if (CONTROL_MouseEnabled)
{
DoGetDeviceButtons( DoGetDeviceButtons(
MOUSE_GetButtons(), t, MOUSE_GetButtons(), t,
CONTROL_NumMouseButtons, CONTROL_NumMouseButtons,
@ -486,9 +519,11 @@ void CONTROL_GetDeviceButtons(void)
); );
} }
if (CONTROL_JoystickEnabled) { if (CONTROL_JoystickEnabled)
{
int32 buttons = joyb; int32 buttons = joyb;
if (joynumhats > 0 && joyhat[0] != -1) { if (joynumhats > 0 && joyhat[0] != -1)
{
static int32 hatstate[] = { 1, 1|2, 2, 2|4, 4, 4|8, 8, 8|1 }; static int32 hatstate[] = { 1, 1|2, 2, 2|4, 4, 4|8, 8, 8|1 };
int val; int val;
@ -513,7 +548,8 @@ void CONTROL_DigitizeAxis(int32 axis, controldevice device)
{ {
controlaxistype *set, *lastset; controlaxistype *set, *lastset;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
set = CONTROL_MouseAxes; set = CONTROL_MouseAxes;
lastset = CONTROL_LastMouseAxes; lastset = CONTROL_LastMouseAxes;
@ -527,20 +563,31 @@ void CONTROL_DigitizeAxis(int32 axis, controldevice device)
default: return; default: return;
} }
if (set[axis].analog > 0) { if (set[axis].analog > 0)
if (set[axis].analog > THRESHOLD) { // if very much in one direction, {
if (set[axis].analog > THRESHOLD) // if very much in one direction,
{
set[axis].digital = 1; // set affirmative set[axis].digital = 1; // set affirmative
} else { }
if (set[axis].analog > MINTHRESHOLD) { // if hanging in limbo, else
{
if (set[axis].analog > MINTHRESHOLD) // if hanging in limbo,
{
if (lastset[axis].digital == 1) // set if in same direction as last time if (lastset[axis].digital == 1) // set if in same direction as last time
set[axis].digital = 1; set[axis].digital = 1;
} }
} }
} else { }
if (set[axis].analog < -THRESHOLD) { else
{
if (set[axis].analog < -THRESHOLD)
{
set[axis].digital = -1; set[axis].digital = -1;
} else { }
if (set[axis].analog < -MINTHRESHOLD) { else
{
if (set[axis].analog < -MINTHRESHOLD)
{
if (lastset[axis].digital == -1) if (lastset[axis].digital == -1)
set[axis].digital = -1; set[axis].digital = -1;
} }
@ -553,7 +600,8 @@ void CONTROL_ScaleAxis(int32 axis, controldevice device)
controlaxistype *set; controlaxistype *set;
int32 *scale; int32 *scale;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
set = CONTROL_MouseAxes; set = CONTROL_MouseAxes;
scale = CONTROL_MouseAxesScale; scale = CONTROL_MouseAxesScale;
@ -575,7 +623,8 @@ void CONTROL_ApplyAxis(int32 axis, ControlInfo *info, controldevice device)
controlaxistype *set; controlaxistype *set;
controlaxismaptype *map; controlaxismaptype *map;
switch (device) { switch (device)
{
case controldevice_mouse: case controldevice_mouse:
set = CONTROL_MouseAxes; set = CONTROL_MouseAxes;
map = CONTROL_MouseAxesMap; map = CONTROL_MouseAxesMap;
@ -589,7 +638,8 @@ void CONTROL_ApplyAxis(int32 axis, ControlInfo *info, controldevice device)
default: return; default: return;
} }
switch (map[axis].analogmap) { switch (map[axis].analogmap)
{
case analog_turning: info->dyaw += set[axis].analog; break; case analog_turning: info->dyaw += set[axis].analog; break;
case analog_strafing: info->dx += set[axis].analog; break; case analog_strafing: info->dx += set[axis].analog; break;
case analog_lookingupanddown: info->dpitch += set[axis].analog; break; case analog_lookingupanddown: info->dpitch += set[axis].analog; break;
@ -611,24 +661,28 @@ void CONTROL_PollDevices(ControlInfo *info)
memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes)); memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes));
memset(info, 0, sizeof(ControlInfo)); memset(info, 0, sizeof(ControlInfo));
if (CONTROL_MouseEnabled) { if (CONTROL_MouseEnabled)
{
CONTROL_GetMouseDelta(); CONTROL_GetMouseDelta();
for (i=0; i<MAXMOUSEAXES; i++) { for (i=0; i<MAXMOUSEAXES; i++)
{
CONTROL_DigitizeAxis(i, controldevice_mouse); CONTROL_DigitizeAxis(i, controldevice_mouse);
CONTROL_ScaleAxis(i, controldevice_mouse); CONTROL_ScaleAxis(i, controldevice_mouse);
LIMITCONTROL(&CONTROL_MouseAxes[i].analog); LIMITCONTROL(&CONTROL_MouseAxes[i].analog);
CONTROL_ApplyAxis(i, info, controldevice_mouse); CONTROL_ApplyAxis(i, info, controldevice_mouse);
} }
} }
if (CONTROL_JoystickEnabled) { if (CONTROL_JoystickEnabled)
{
CONTROL_GetJoyDelta(); CONTROL_GetJoyDelta();
// Why? // Why?
//CONTROL_Axes[0].analog /= 2; //CONTROL_Axes[0].analog /= 2;
//CONTROL_Axes[2].analog /= 2; //CONTROL_Axes[2].analog /= 2;
for (i=0; i<MAXJOYAXES; i++) { for (i=0; i<MAXJOYAXES; i++)
{
CONTROL_DigitizeAxis(i, controldevice_joystick); CONTROL_DigitizeAxis(i, controldevice_joystick);
CONTROL_ScaleAxis(i, controldevice_joystick); CONTROL_ScaleAxis(i, controldevice_joystick);
LIMITCONTROL(&CONTROL_JoyAxes[i].analog); LIMITCONTROL(&CONTROL_JoyAxes[i].analog);
@ -643,7 +697,8 @@ void CONTROL_AxisFunctionState(int32 *p1)
{ {
int32 i, j; int32 i, j;
for (i=0; i<CONTROL_NumMouseAxes; i++) { for (i=0; i<CONTROL_NumMouseAxes; i++)
{
if (!CONTROL_MouseAxes[i].digital) continue; if (!CONTROL_MouseAxes[i].digital) continue;
if (CONTROL_MouseAxes[i].digital < 0) if (CONTROL_MouseAxes[i].digital < 0)
@ -655,7 +710,8 @@ void CONTROL_AxisFunctionState(int32 *p1)
p1[j] = 1; p1[j] = 1;
} }
for (i=0; i<CONTROL_NumJoyAxes; i++) { for (i=0; i<CONTROL_NumJoyAxes; i++)
{
if (!CONTROL_JoyAxes[i].digital) continue; if (!CONTROL_JoyAxes[i].digital) continue;
if (CONTROL_JoyAxes[i].digital < 0) if (CONTROL_JoyAxes[i].digital < 0)
@ -668,11 +724,12 @@ void CONTROL_AxisFunctionState(int32 *p1)
} }
} }
void CONTROL_ButtonFunctionState( int32 *p1 ) void CONTROL_ButtonFunctionState(int32 *p1)
{ {
int32 i, j; int32 i, j;
for (i=0; i<CONTROL_NumMouseButtons; i++) { for (i=0; i<CONTROL_NumMouseButtons; i++)
{
j = CONTROL_MouseButtonMapping[i].doubleclicked; j = CONTROL_MouseButtonMapping[i].doubleclicked;
if (j != KEYUNDEFINED) if (j != KEYUNDEFINED)
p1[j] |= CONTROL_MouseButtonClickedState[i]; p1[j] |= CONTROL_MouseButtonClickedState[i];
@ -682,7 +739,8 @@ void CONTROL_ButtonFunctionState( int32 *p1 )
p1[j] |= CONTROL_MouseButtonState[i]; p1[j] |= CONTROL_MouseButtonState[i];
} }
for (i=0; i<CONTROL_NumJoyButtons; i++) { for (i=0; i<CONTROL_NumJoyButtons; i++)
{
j = CONTROL_JoyButtonMapping[i].doubleclicked; j = CONTROL_JoyButtonMapping[i].doubleclicked;
if (j != KEYUNDEFINED) if (j != KEYUNDEFINED)
p1[j] |= CONTROL_JoyButtonClickedState[i]; p1[j] |= CONTROL_JoyButtonClickedState[i];
@ -779,10 +837,10 @@ void CONTROL_ClearUserInput( UserInput *info )
if (info->button1) CONTROL_UserInputCleared[2] = true; if (info->button1) CONTROL_UserInputCleared[2] = true;
} }
*/ */
void CONTROL_ClearButton( int32 whichbutton ) void CONTROL_ClearButton(int32 whichbutton)
{ {
if (CONTROL_CheckRange( whichbutton )) return; if (CONTROL_CheckRange(whichbutton)) return;
BUTTONCLEAR( whichbutton ); BUTTONCLEAR(whichbutton);
CONTROL_Flags[whichbutton].cleared = true; CONTROL_Flags[whichbutton].cleared = true;
} }
@ -807,11 +865,11 @@ void CONTROL_ProcessBinds(void)
} }
void CONTROL_GetInput( ControlInfo *info ) void CONTROL_GetInput(ControlInfo *info)
{ {
int32 i, periphs[CONTROL_NUM_FLAGS]; int32 i, periphs[CONTROL_NUM_FLAGS];
CONTROL_PollDevices( info ); CONTROL_PollDevices(info);
memset(periphs, 0, sizeof(periphs)); memset(periphs, 0, sizeof(periphs));
CONTROL_ButtonFunctionState(periphs); CONTROL_ButtonFunctionState(periphs);
@ -823,7 +881,8 @@ void CONTROL_GetInput( ControlInfo *info )
CONTROL_ProcessBinds(); CONTROL_ProcessBinds();
for (i=0; i<CONTROL_NUM_FLAGS; i++) { for (i=0; i<CONTROL_NUM_FLAGS; i++)
{
CONTROL_SetFlag(i, CONTROL_KeyboardFunctionPressed(i) | periphs[i] | extinput[i]); CONTROL_SetFlag(i, CONTROL_KeyboardFunctionPressed(i) | periphs[i] | extinput[i]);
if (CONTROL_Flags[i].cleared == false) BUTTONSET(i, CONTROL_Flags[i].active); if (CONTROL_Flags[i].cleared == false) BUTTONSET(i, CONTROL_Flags[i].active);
@ -832,15 +891,15 @@ void CONTROL_GetInput( ControlInfo *info )
memset(extinput, 0, sizeof(extinput)); memset(extinput, 0, sizeof(extinput));
} }
void CONTROL_WaitRelease( void ) void CONTROL_WaitRelease(void)
{ {
} }
void CONTROL_Ack( void ) void CONTROL_Ack(void)
{ {
} }
boolean CONTROL_Startup(controltype which, int32 ( *TimeFunction )( void ), int32 ticspersecond) boolean CONTROL_Startup(controltype which, int32(*TimeFunction)(void), int32 ticspersecond)
{ {
int32 i; int32 i;

View file

@ -58,75 +58,80 @@ static char *FileNames[MaxFiles];
int32 SafeOpen(const char *filename, int32 mode, int32 sharemode) int32 SafeOpen(const char *filename, int32 mode, int32 sharemode)
{ {
int32 h; int32 h;
h = openfrompath(filename, mode, sharemode); h = openfrompath(filename, mode, sharemode);
if (h < 0) Error("Error opening %s: %s", filename, strerror(errno)); if (h < 0) Error("Error opening %s: %s", filename, strerror(errno));
if (h < MaxFiles) { if (h < MaxFiles)
if (FileNames[h]) SafeFree(FileNames[h]); {
FileNames[h] = (char*)SafeMalloc(strlen(filename)+1); if (FileNames[h]) SafeFree(FileNames[h]);
if (FileNames[h]) strcpy(FileNames[h], filename); FileNames[h] = (char*)SafeMalloc(strlen(filename)+1);
} if (FileNames[h]) strcpy(FileNames[h], filename);
}
return h; return h;
} }
int32 SafeOpenRead(const char *filename, int32 filetype) int32 SafeOpenRead(const char *filename, int32 filetype)
{ {
switch (filetype) { switch (filetype)
case filetype_binary: {
return SafeOpen(filename, O_RDONLY|O_BINARY, S_IREAD); case filetype_binary:
case filetype_text: return SafeOpen(filename, O_RDONLY|O_BINARY, S_IREAD);
return SafeOpen(filename, O_RDONLY|O_TEXT, S_IREAD); case filetype_text:
default: return SafeOpen(filename, O_RDONLY|O_TEXT, S_IREAD);
Error("SafeOpenRead: Illegal filetype specified"); default:
return -1; Error("SafeOpenRead: Illegal filetype specified");
} return -1;
}
} }
void SafeClose ( int32 handle ) void SafeClose(int32 handle)
{ {
if (handle < 0) return; if (handle < 0) return;
if (close(handle) < 0) { if (close(handle) < 0)
if (handle < MaxFiles) {
Error("Unable to close file %s", FileNames[handle]); if (handle < MaxFiles)
else Error("Unable to close file %s", FileNames[handle]);
Error("Unable to close file"); else
} Error("Unable to close file");
}
if (handle < MaxFiles && FileNames[handle]) { if (handle < MaxFiles && FileNames[handle])
SafeFree(FileNames[handle]); {
FileNames[handle] = NULL; SafeFree(FileNames[handle]);
} FileNames[handle] = NULL;
}
} }
boolean SafeFileExists(const char *filename) boolean SafeFileExists(const char *filename)
{ {
if (!access(filename, F_OK)) return true; if (!access(filename, F_OK)) return true;
return false; return false;
} }
int32 SafeFileLength ( int32 handle ) int32 SafeFileLength(int32 handle)
{ {
if (handle < 0) return -1; if (handle < 0) return -1;
return Bfilelength(handle); return Bfilelength(handle);
} }
void SafeRead(int32 handle, void *buffer, int32 count) void SafeRead(int32 handle, void *buffer, int32 count)
{ {
int32 b; int32 b;
b = read(handle, buffer, count); b = read(handle, buffer, count);
if (b != count) { if (b != count)
close(handle); {
if (handle < MaxFiles) close(handle);
Error("File read failure %s reading %d bytes from file %s.", if (handle < MaxFiles)
strerror(errno), count, FileNames[handle]); Error("File read failure %s reading %d bytes from file %s.",
else strerror(errno), count, FileNames[handle]);
Error("File read failure %s reading %d bytes.", else
strerror(errno), count); Error("File read failure %s reading %d bytes.",
} strerror(errno), count);
}
} }

View file

@ -43,111 +43,113 @@ kb_scancode KB_LastScan;
static boolean numpad = 0; static boolean numpad = 0;
// translation table for taking key names to scancodes and back again // translation table for taking key names to scancodes and back again
static struct { static struct
char *key; {
kb_scancode sc; char *key;
} sctokeylut[] = { kb_scancode sc;
{ "Escape", 0x1 }, } sctokeylut[] =
{ "1", 0x2 }, {
{ "2", 0x3 }, { "Escape", 0x1 },
{ "3", 0x4 }, { "1", 0x2 },
{ "4", 0x5 }, { "2", 0x3 },
{ "5", 0x6 }, { "3", 0x4 },
{ "6", 0x7 }, { "4", 0x5 },
{ "7", 0x8 }, { "5", 0x6 },
{ "8", 0x9 }, { "6", 0x7 },
{ "9", 0xa }, { "7", 0x8 },
{ "0", 0xb }, { "8", 0x9 },
{ "-", 0xc }, { "9", 0xa },
{ "=", 0xd }, { "0", 0xb },
{ "BakSpc", 0xe }, { "-", 0xc },
{ "Tab", 0xf }, { "=", 0xd },
{ "Q", 0x10 }, { "BakSpc", 0xe },
{ "W", 0x11 }, { "Tab", 0xf },
{ "E", 0x12 }, { "Q", 0x10 },
{ "R", 0x13 }, { "W", 0x11 },
{ "T", 0x14 }, { "E", 0x12 },
{ "Y", 0x15 }, { "R", 0x13 },
{ "U", 0x16 }, { "T", 0x14 },
{ "I", 0x17 }, { "Y", 0x15 },
{ "O", 0x18 }, { "U", 0x16 },
{ "P", 0x19 }, { "I", 0x17 },
{ "[", 0x1a }, { "O", 0x18 },
{ "]", 0x1b }, { "P", 0x19 },
{ "Enter", 0x1c }, { "[", 0x1a },
{ "LCtrl", 0x1d }, { "]", 0x1b },
{ "A", 0x1e }, { "Enter", 0x1c },
{ "S", 0x1f }, { "LCtrl", 0x1d },
{ "D", 0x20 }, { "A", 0x1e },
{ "F", 0x21 }, { "S", 0x1f },
{ "G", 0x22 }, { "D", 0x20 },
{ "H", 0x23 }, { "F", 0x21 },
{ "J", 0x24 }, { "G", 0x22 },
{ "K", 0x25 }, { "H", 0x23 },
{ "L", 0x26 }, { "J", 0x24 },
{ ";", 0x27 }, { "K", 0x25 },
{ "'", 0x28 }, { "L", 0x26 },
{ "`", 0x29 }, { ";", 0x27 },
{ "LShift", 0x2a }, { "'", 0x28 },
{ "\\", 0x2b }, { "`", 0x29 },
{ "Z", 0x2c }, { "LShift", 0x2a },
{ "X", 0x2d }, { "\\", 0x2b },
{ "C", 0x2e }, { "Z", 0x2c },
{ "V", 0x2f }, { "X", 0x2d },
{ "B", 0x30 }, { "C", 0x2e },
{ "N", 0x31 }, { "V", 0x2f },
{ "M", 0x32 }, { "B", 0x30 },
{ ",", 0x33 }, { "N", 0x31 },
{ ".", 0x34 }, { "M", 0x32 },
{ "/", 0x35 }, { ",", 0x33 },
{ "RShift", 0x36 }, { ".", 0x34 },
{ "Kpad*", 0x37 }, { "/", 0x35 },
{ "LAlt", 0x38 }, { "RShift", 0x36 },
{ "Space", 0x39 }, { "Kpad*", 0x37 },
{ "CapLck", 0x3a }, { "LAlt", 0x38 },
{ "F1", 0x3b }, { "Space", 0x39 },
{ "F2", 0x3c }, { "CapLck", 0x3a },
{ "F3", 0x3d }, { "F1", 0x3b },
{ "F4", 0x3e }, { "F2", 0x3c },
{ "F5", 0x3f }, { "F3", 0x3d },
{ "F6", 0x40 }, { "F4", 0x3e },
{ "F7", 0x41 }, { "F5", 0x3f },
{ "F8", 0x42 }, { "F6", 0x40 },
{ "F9", 0x43 }, { "F7", 0x41 },
{ "F10", 0x44 }, { "F8", 0x42 },
{ "NumLck", 0x45 }, { "F9", 0x43 },
{ "ScrLck", 0x46 }, { "F10", 0x44 },
{ "Kpad7", 0x47 }, { "NumLck", 0x45 },
{ "Kpad8", 0x48 }, { "ScrLck", 0x46 },
{ "Kpad9", 0x49 }, { "Kpad7", 0x47 },
{ "Kpad-", 0x4a }, { "Kpad8", 0x48 },
{ "Kpad4", 0x4b }, { "Kpad9", 0x49 },
{ "Kpad5", 0x4c }, { "Kpad-", 0x4a },
{ "Kpad6", 0x4d }, { "Kpad4", 0x4b },
{ "Kpad+", 0x4e }, { "Kpad5", 0x4c },
{ "Kpad1", 0x4f }, { "Kpad6", 0x4d },
{ "Kpad2", 0x50 }, { "Kpad+", 0x4e },
{ "Kpad3", 0x51 }, { "Kpad1", 0x4f },
{ "Kpad0", 0x52 }, { "Kpad2", 0x50 },
{ "Kpad.", 0x53 }, { "Kpad3", 0x51 },
{ "F11", 0x57 }, { "Kpad0", 0x52 },
{ "F12", 0x58 }, { "Kpad.", 0x53 },
{ "KpdEnt", 0x9c }, { "F11", 0x57 },
{ "RCtrl", 0x9d }, { "F12", 0x58 },
{ "Kpad/", 0xb5 }, { "KpdEnt", 0x9c },
{ "RAlt", 0xb8 }, { "RCtrl", 0x9d },
{ "PrtScn", 0xb7 }, { "Kpad/", 0xb5 },
{ "Pause", 0xc5 }, { "RAlt", 0xb8 },
{ "Home", 0xc7 }, { "PrtScn", 0xb7 },
{ "Up", 0xc8 }, { "Pause", 0xc5 },
{ "PgUp", 0xc9 }, { "Home", 0xc7 },
{ "Left", 0xcb }, { "Up", 0xc8 },
{ "Right", 0xcd }, { "PgUp", 0xc9 },
{ "End", 0xcf }, { "Left", 0xcb },
{ "Down", 0xd0 }, { "Right", 0xcd },
{ "PgDn", 0xd1 }, { "End", 0xcf },
{ "Insert", 0xd2 }, { "Down", 0xd0 },
{ "Delete", 0xd3 }, { "PgDn", 0xd1 },
{ "Insert", 0xd2 },
{ "Delete", 0xd3 },
}; };
// translation table for turning scancode into ascii characters // translation table for turning scancode into ascii characters
@ -194,91 +196,91 @@ static char sctoasc[2][256] = {
}; };
*/ */
boolean KB_KeyWaiting( void ) boolean KB_KeyWaiting(void)
{ {
return bkbhit(); return bkbhit();
// return (keyfifoplc != keyfifoend); // return (keyfifoplc != keyfifoend);
} }
char KB_Getch( void ) char KB_Getch(void)
{ {
/* /*
unsigned char ch; unsigned char ch;
char shifted; char shifted;
if (keyfifoplc == keyfifoend) return 0; if (keyfifoplc == keyfifoend) return 0;
ch = keyfifo[keyfifoplc]; ch = keyfifo[keyfifoplc];
keyfifoplc = ((keyfifoplc+2)&(KEYFIFOSIZ-1)); keyfifoplc = ((keyfifoplc+2)&(KEYFIFOSIZ-1));
shifted = ((keystatus[0x2a]!=0)||(keystatus[0x36]!=0)); shifted = ((keystatus[0x2a]!=0)||(keystatus[0x36]!=0));
if (ch >= 0x47 && ch <= 0x52) shifted = numpad; if (ch >= 0x47 && ch <= 0x52) shifted = numpad;
return sctoasc[shifted][ch]; return sctoasc[shifted][ch];
*/ */
return (char)bgetchar(); return (char)bgetchar();
} }
void KB_FlushKeyboardQueue( void ) void KB_FlushKeyboardQueue(void)
{ {
//keyfifoplc = keyfifoend = 0; //keyfifoplc = keyfifoend = 0;
bflushchars(); bflushchars();
} }
void KB_ClearKeysDown( void ) void KB_ClearKeysDown(void)
{ {
KB_LastScan = 0; KB_LastScan = 0;
memset(keystatus, 0, sizeof(keystatus)); memset(keystatus, 0, sizeof(keystatus));
//keyfifoplc = keyfifoend = 0; //keyfifoplc = keyfifoend = 0;
//bflushchars(); //bflushchars();
} }
char *KB_ScanCodeToString( kb_scancode scancode ) char *KB_ScanCodeToString(kb_scancode scancode)
{ {
unsigned s; unsigned s;
for (s=0; s < (sizeof(sctokeylut)/sizeof(sctokeylut[0])); s++) for (s=0; s < (sizeof(sctokeylut)/sizeof(sctokeylut[0])); s++)
if (sctokeylut[s].sc == scancode) return sctokeylut[s].key; if (sctokeylut[s].sc == scancode) return sctokeylut[s].key;
return ""; return "";
} }
kb_scancode KB_StringToScanCode( char * string ) kb_scancode KB_StringToScanCode(char * string)
{ {
unsigned s; unsigned s;
for (s=0; s < (sizeof(sctokeylut)/sizeof(sctokeylut[0])); s++) for (s=0; s < (sizeof(sctokeylut)/sizeof(sctokeylut[0])); s++)
if (!Bstrcasecmp(sctokeylut[s].key, string)) return sctokeylut[s].sc; if (!Bstrcasecmp(sctokeylut[s].key, string)) return sctokeylut[s].sc;
return 0; return 0;
} }
void KB_TurnKeypadOn( void ) void KB_TurnKeypadOn(void)
{ {
numpad = 1; numpad = 1;
} }
void KB_TurnKeypadOff( void ) void KB_TurnKeypadOff(void)
{ {
numpad = 0; numpad = 0;
} }
boolean KB_KeypadActive( void ) boolean KB_KeypadActive(void)
{ {
return numpad; return numpad;
} }
static void KB_KeyEvent( int scancode, int keypressed ) static void KB_KeyEvent(int scancode, int keypressed)
{ {
if (keypressed) KB_LastScan = scancode; if (keypressed) KB_LastScan = scancode;
} }
void KB_Startup( void ) void KB_Startup(void)
{ {
numpad = 0; numpad = 0;
setkeypresscallback(KB_KeyEvent); setkeypresscallback(KB_KeyEvent);
} }
void KB_Shutdown( void ) void KB_Shutdown(void)
{ {
setkeypresscallback((void(*)(int,int))NULL); setkeypresscallback((void(*)(int,int))NULL);
} }

View file

@ -37,14 +37,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Ken's reverse-engineering job // Ken's reverse-engineering job
int32 FindDistance2D(int32 x, int32 y) int32 FindDistance2D(int32 x, int32 y)
{ {
int32 i; int32 i;
x = labs(x); x = labs(x);
y = labs(y); y = labs(y);
if (!x) return(y); if (!x) return(y);
if (!y) return(x); if (!y) return(x);
if (y < x) { i = x; x = y; y = i; } //swap x, y if (y < x) { i = x; x = y; y = i; } //swap x, y
x += (x>>1); x += (x>>1);
return ((x>>6)+(x>>2)+y-(y>>5)-(y>>7)); //handle 1 octant return ((x>>6)+(x>>2)+y-(y>>5)-(y>>7)); //handle 1 octant
} }
// My abomination // My abomination
@ -59,7 +59,7 @@ int32 FindDistance2D(int32 dx, int32 dy)
int32 FindDistance3D(int32 dx, int32 dy, int32 dz) int32 FindDistance3D(int32 dx, int32 dy, int32 dz)
{ {
// return (int32)floor(sqrt((double)(sqr(dx)+sqr(dy)+sqr(dz)))); // return (int32)floor(sqrt((double)(sqr(dx)+sqr(dy)+sqr(dz))));
return ksqrt(square(dx)+square(dy)+square(dz)); return ksqrt(square(dx)+square(dy)+square(dz));
} }
#else #else
@ -77,36 +77,36 @@ int32 FindDistance3D(int32 dx, int32 dy, int32 dz)
int32 FindDistance2D(int32 x, int32 y) int32 FindDistance2D(int32 x, int32 y)
{ {
int32 t; int32 t;
x= abs(x); /* absolute values */ x= abs(x); /* absolute values */
y= abs(y); y= abs(y);
if (x<y) if (x<y)
SWAP(x,y); SWAP(x,y);
t = y + (y>>1); t = y + (y>>1);
return (x - (x>>5) - (x>>7) + (t>>2) + (t>>6)); return (x - (x>>5) - (x>>7) + (t>>2) + (t>>6));
} }
int32 FindDistance3D(int32 x, int32 y, int32 z) int32 FindDistance3D(int32 x, int32 y, int32 z)
{ {
int32 t; int32 t;
x= abs(x); /* absolute values */ x= abs(x); /* absolute values */
y= abs(y); y= abs(y);
z= abs(z); z= abs(z);
if (x<y) if (x<y)
SWAP(x,y); SWAP(x,y);
if (x<z) if (x<z)
SWAP(x,z); SWAP(x,z);
t = y + z; t = y + z;
return (x - (x>>4) + (t>>2) + (t>>3)); return (x - (x>>4) + (t>>2) + (t>>3));
} }
#endif #endif

View file

@ -38,46 +38,46 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "baselayer.h" #include "baselayer.h"
boolean MOUSE_Init( void ) boolean MOUSE_Init(void)
{ {
initmouse(); initmouse();
return ((inputdevices & 2) == 2); return ((inputdevices & 2) == 2);
} }
void MOUSE_Shutdown( void ) void MOUSE_Shutdown(void)
{ {
uninitmouse(); uninitmouse();
} }
void MOUSE_ShowCursor( void ) void MOUSE_ShowCursor(void)
{ {
} }
void MOUSE_HideCursor( void ) void MOUSE_HideCursor(void)
{ {
} }
int32 MOUSE_GetButtons( void ) int32 MOUSE_GetButtons(void)
{ {
int32 buttons; int32 buttons;
readmousebstatus(&buttons); readmousebstatus(&buttons);
return buttons; return buttons;
} }
int32 MOUSE_ClearButton( int32 b ) int32 MOUSE_ClearButton(int32 b)
{ {
return (mouseb &= ~b); return (mouseb &= ~b);
} }
void MOUSE_GetDelta( int32*x, int32*y ) void MOUSE_GetDelta(int32*x, int32*y)
{ {
readmousexy(x,y); readmousexy(x,y);
} }

File diff suppressed because it is too large Load diff

View file

@ -42,112 +42,114 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void (*ShutDown)(void) = NULL; // this is defined by whoever links us static void (*ShutDown)(void) = NULL; // this is defined by whoever links us
void RegisterShutdownFunction( void (* sh) (void) ) void RegisterShutdownFunction(void (* sh)(void))
{ {
ShutDown = sh; ShutDown = sh;
} }
#ifndef RENDERTYPEWIN #ifndef RENDERTYPEWIN
void Error(char *error, ...) void Error(char *error, ...)
{ {
va_list va; va_list va;
if (ShutDown) ShutDown(); if (ShutDown) ShutDown();
if (error) { if (error)
va_start(va, error); {
vprintf(error, va); va_start(va, error);
va_end(va); vprintf(error, va);
printf("\n\n"); va_end(va);
} printf("\n\n");
}
exit((error != NULL)); exit((error != NULL));
} }
#endif #endif
char CheckParm(char *check) char CheckParm(char *check)
{ {
int c; int c;
for (c=1;c<_buildargc;c++) { for (c=1;c<_buildargc;c++)
if (_buildargv[c][0] == '/' || _buildargv[c][0] == '-') {
if (!Bstrcasecmp(&_buildargv[c][1], check)) return c; if (_buildargv[c][0] == '/' || _buildargv[c][0] == '-')
} if (!Bstrcasecmp(&_buildargv[c][1], check)) return c;
}
return 0; return 0;
} }
void *SafeMalloc (int32 size) void *SafeMalloc(int32 size)
{ {
void *p; void *p;
p = malloc(size); p = malloc(size);
if (!p) Error("SafeMalloc failure for %d bytes",size); if (!p) Error("SafeMalloc failure for %d bytes",size);
return p; return p;
} }
void SafeFree (void * ptr) void SafeFree(void * ptr)
{ {
if (!ptr) Error("Tried to deallocate NULL pointer."); if (!ptr) Error("Tried to deallocate NULL pointer.");
free(ptr); free(ptr);
} }
void SafeRealloc (void ** ptr, int32 newsize) void SafeRealloc(void ** ptr, int32 newsize)
{ {
void *p; void *p;
p = realloc(*ptr, newsize); p = realloc(*ptr, newsize);
if (!p) Error("SafeRealloc failure for %d bytes",newsize); if (!p) Error("SafeRealloc failure for %d bytes",newsize);
*ptr = p; *ptr = p;
} }
int32 ParseHex (char *hex) int32 ParseHex(char *hex)
{ {
return strtol(hex, NULL, 16); return strtol(hex, NULL, 16);
} }
int32 ParseNum (char *str) int32 ParseNum(char *str)
{ {
return strtol(str, NULL, 10); return strtol(str, NULL, 10);
} }
int16 MotoShort (int16 l) int16 MotoShort(int16 l)
{ {
#if B_LITTLE_ENDIAN != 0 #if B_LITTLE_ENDIAN != 0
return l; return l;
#else #else
return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8); return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8);
#endif #endif
} }
int16 IntelShort (int16 l) int16 IntelShort(int16 l)
{ {
#if B_BIG_ENDIAN != 0 #if B_BIG_ENDIAN != 0
return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8); return ((l & 0x00ff) << 8) | ((l & 0xff00) >> 8);
#else #else
return l; return l;
#endif #endif
} }
int32 MotoLong (int32 l) int32 MotoLong(int32 l)
{ {
#if B_LITTLE_ENDIAN != 0 #if B_LITTLE_ENDIAN != 0
return l; return l;
#else #else
int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8); int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8);
return ((t & 0x0000ffffl) << 16) | ((t & 0xffff0000l) >> 16); return ((t & 0x0000ffffl) << 16) | ((t & 0xffff0000l) >> 16);
#endif #endif
} }
int32 IntelLong (int32 l) int32 IntelLong(int32 l)
{ {
#if B_BIG_ENDIAN != 0 #if B_BIG_ENDIAN != 0
int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8); int32 t = ((l & 0x00ff00ffl) << 8) | ((l & 0xff00ff00l) >> 8);
return ((t & 0x0000ffffl) << 16) | ((t & 0xffff0000l) >> 16); return ((t & 0x0000ffffl) << 16) | ((t & 0xffff0000l) >> 16);
#else #else
return l; return l;
#endif #endif
} }