📄 i_ibm.c
字号:
lasttic = ticcount;
if(tics > 20)
{
tics = 20;
}
for(i = 0; i < tics; i++)
{
*dest = 0xff;
dest += 2;
}
for(i = tics; i < 20; i++)
{
*dest = 0x00;
dest += 2;
}
}
//memset(pcscreen, 255, SCREENHEIGHT*SCREENWIDTH);
if(UpdateState == I_NOUPDATE)
{
return;
}
if(UpdateState&I_FULLSCRN)
{
memcpy(pcscreen, screen, SCREENWIDTH*SCREENHEIGHT);
UpdateState = I_NOUPDATE; // clear out all draw types
}
if(UpdateState&I_FULLVIEW)
{
if(UpdateState&I_MESSAGES && screenblocks > 7)
{
for(i = 0; i <
(viewwindowy+viewheight)*SCREENWIDTH; i += SCREENWIDTH)
{
memcpy(pcscreen+i, screen+i, SCREENWIDTH);
}
UpdateState &= ~(I_FULLVIEW|I_MESSAGES);
}
else
{
for(i = viewwindowy*SCREENWIDTH+viewwindowx; i <
(viewwindowy+viewheight)*SCREENWIDTH; i += SCREENWIDTH)
{
memcpy(pcscreen+i, screen+i, viewwidth);
}
UpdateState &= ~I_FULLVIEW;
}
}
if(UpdateState&I_STATBAR)
{
memcpy(pcscreen+SCREENWIDTH*(SCREENHEIGHT-SBARHEIGHT),
screen+SCREENWIDTH*(SCREENHEIGHT-SBARHEIGHT),
SCREENWIDTH*SBARHEIGHT);
UpdateState &= ~I_STATBAR;
}
if(UpdateState&I_MESSAGES)
{
memcpy(pcscreen, screen, SCREENWIDTH*28);
UpdateState &= ~I_MESSAGES;
}
// memcpy(pcscreen, screen, SCREENHEIGHT*SCREENWIDTH);
}
//--------------------------------------------------------------------------
//
// PROC I_InitGraphics
//
//--------------------------------------------------------------------------
void I_InitGraphics(void)
{
if(novideo)
{
return;
}
//grmode = true;
regs.w.ax = 0x13;
int386(0x10, (const union REGS *)®s, ®s);
pcscreen = destscreen = (byte *)0xa0000;
I_SetPalette(W_CacheLumpName("PLAYPAL", PU_CACHE));
}
//--------------------------------------------------------------------------
//
// PROC I_ShutdownGraphics
//
//--------------------------------------------------------------------------
void I_ShutdownGraphics(void)
{
byte mode;
// don't reset mode if it didn't get set
mode = *(byte *)0x449;
if(mode == 0x12 || mode == 0x13)
{
regs.w.ax = 3;
int386(0x10, ®s, ®s); // back to text mode
}
}
//--------------------------------------------------------------------------
//
// PROC I_ReadScreen
//
// Reads the screen currently displayed into a linear buffer.
//
//--------------------------------------------------------------------------
/*
void I_ReadScreen(byte *scr)
{
memcpy(scr, screen, SCREENWIDTH*SCREENHEIGHT);
}
*/
//===========================================================================
/*
===================
=
= I_StartTic
=
// called by D_DoomLoop
// called before processing each tic in a frame
// can call D_PostEvent
// asyncronous interrupt functions should maintain private ques that are
// read by the syncronous functions to be converted into events
===================
*/
/*
OLD STARTTIC STUFF
void I_StartTic (void)
{
int k;
event_t ev;
I_ReadMouse ();
//
// keyboard events
//
while (kbdtail < kbdhead)
{
k = keyboardque[kbdtail&(KBDQUESIZE-1)];
// if (k==14)
// I_Error ("exited");
kbdtail++;
// extended keyboard shift key bullshit
if ( (k&0x7f)==KEY_RSHIFT )
{
if ( keyboardque[(kbdtail-2)&(KBDQUESIZE-1)]==0xe0 )
continue;
k &= 0x80;
k |= KEY_RSHIFT;
}
if (k==0xe0)
continue; // special / pause keys
if (keyboardque[(kbdtail-2)&(KBDQUESIZE-1)] == 0xe1)
continue; // pause key bullshit
if (k==0xc5 && keyboardque[(kbdtail-2)&(KBDQUESIZE-1)] == 0x9d)
{
ev.type = ev_keydown;
ev.data1 = KEY_PAUSE;
D_PostEvent (&ev);
continue;
}
if (k&0x80)
ev.type = ev_keyup;
else
ev.type = ev_keydown;
k &= 0x7f;
ev.data1 = k;
//ev.data1 = scantokey[k];
D_PostEvent (&ev);
}
}
*/
#define SC_UPARROW 0x48
#define SC_DOWNARROW 0x50
#define SC_LEFTARROW 0x4b
#define SC_RIGHTARROW 0x4d
void I_StartTic (void)
{
int k;
event_t ev;
I_ReadMouse ();
//
// keyboard events
//
while (kbdtail < kbdhead)
{
k = keyboardque[kbdtail&(KBDQUESIZE-1)];
kbdtail++;
// extended keyboard shift key bullshit
if ( (k&0x7f)==SC_LSHIFT || (k&0x7f)==SC_RSHIFT )
{
if ( keyboardque[(kbdtail-2)&(KBDQUESIZE-1)]==0xe0 )
continue;
k &= 0x80;
k |= SC_RSHIFT;
}
if (k==0xe0)
continue; // special / pause keys
if (keyboardque[(kbdtail-2)&(KBDQUESIZE-1)] == 0xe1)
continue; // pause key bullshit
if (k==0xc5 && keyboardque[(kbdtail-2)&(KBDQUESIZE-1)] == 0x9d)
{
ev.type = ev_keydown;
ev.data1 = KEY_PAUSE;
H2_PostEvent (&ev);
continue;
}
if (k&0x80)
ev.type = ev_keyup;
else
ev.type = ev_keydown;
k &= 0x7f;
switch (k)
{
case SC_UPARROW:
ev.data1 = KEY_UPARROW;
break;
case SC_DOWNARROW:
ev.data1 = KEY_DOWNARROW;
break;
case SC_LEFTARROW:
ev.data1 = KEY_LEFTARROW;
break;
case SC_RIGHTARROW:
ev.data1 = KEY_RIGHTARROW;
break;
default:
ev.data1 = scantokey[k];
break;
}
H2_PostEvent (&ev);
}
}
/*
void I_ReadKeys (void)
{
int k;
while (1)
{
while (kbdtail < kbdhead)
{
k = keyboardque[kbdtail&(KBDQUESIZE-1)];
kbdtail++;
printf ("0x%x\n",k);
if (k == 1)
I_Quit ();
}
}
}
*/
/*
===============
=
= I_StartFrame
=
===============
*/
void I_StartFrame (void)
{
I_JoystickEvents ();
if(useexterndriver)
{
DPMIInt(i_Vector);
}
}
/*
============================================================================
TIMER INTERRUPT
============================================================================
*/
/*
void I_ColorBlack (int r, int g, int b)
{
_outbyte (PEL_WRITE_ADR,0);
_outbyte(PEL_DATA,r);
_outbyte(PEL_DATA,g);
_outbyte(PEL_DATA,b);
}
*/
/*
================
=
= I_TimerISR
=
================
*/
int I_TimerISR (void)
{
ticcount++;
return 0;
}
/*
============================================================================
KEYBOARD
============================================================================
*/
void (__interrupt __far *oldkeyboardisr) () = NULL;
int lastpress;
/*
================
=
= I_KeyboardISR
=
================
*/
void __interrupt I_KeyboardISR (void)
{
// Get the scan code
keyboardque[kbdhead&(KBDQUESIZE-1)] = lastpress = _inbyte(0x60);
kbdhead++;
// acknowledge the interrupt
_outbyte(0x20,0x20);
}
/*
===============
=
= I_StartupKeyboard
=
===============
*/
void I_StartupKeyboard (void)
{
#ifndef NOKBD
oldkeyboardisr = _dos_getvect(KEYBOARDINT);
_dos_setvect (0x8000 | KEYBOARDINT, I_KeyboardISR);
#endif
//I_ReadKeys ();
}
void I_ShutdownKeyboard (void)
{
if (oldkeyboardisr)
_dos_setvect (KEYBOARDINT, oldkeyboardisr);
*(short *)0x41c = *(short *)0x41a; // clear bios key buffer
}
/*
============================================================================
MOUSE
============================================================================
*/
int I_ResetMouse (void)
{
regs.w.ax = 0; // reset
int386 (0x33, ®s, ®s);
return regs.w.ax;
}
/*
================
=
= StartupMouse
=
================
*/
void I_StartupCyberMan(void);
void I_StartupMouse (void)
{
//
// General mouse detection
//
mousepresent = 0;
if ( M_CheckParm ("-nomouse") || !usemouse )
return;
if (I_ResetMouse () != 0xffff)
{
ST_Message("Mouse: not present\n");
return;
}
ST_Message("Mouse: detected\n");
mousepresent = 1;
I_StartupCyberMan();
}
/*
================
=
= ShutdownMouse
=
================
*/
void I_ShutdownMouse (void)
{
if (!mousepresent)
return;
I_ResetMouse ();
}
/*
================
=
= I_ReadMouse
=
================
*/
void I_ReadMouse (void)
{
event_t ev;
//
// mouse events
//
if (!mousepresent)
return;
ev.type = ev_mouse;
memset (&dpmiregs,0,sizeof(dpmiregs));
dpmiregs.eax = 3; // read buttons / position
DPMIInt (0x33);
ev.data1 = dpmiregs.ebx;
dpmiregs.eax = 11; // read counters
DPMIInt (0x33);
ev.data2 = (short)dpmiregs.ecx;
ev.data3 = -(short)dpmiregs.edx;
H2_PostEvent (&ev);
}
/*
============================================================================
JOYSTICK
============================================================================
*/
int joyxl, joyxh, joyyl, joyyh;
boolean WaitJoyButton (void)
{
int oldbuttons, buttons;
oldbuttons = 0;
do
{
I_WaitVBL (1);
buttons = ((inp(0x201) >> 4)&1)^1;
if (buttons != oldbuttons)
{
oldbuttons = buttons;
continue;
}
if ( (lastpress& 0x7f) == 1 )
{
joystickpresent = false;
return false;
}
} while ( !buttons);
do
{
I_WaitVBL (1);
buttons = ((inp(0x201) >> 4)&1)^1;
if (buttons != oldbuttons)
{
oldbuttons = buttons;
continue;
}
if ( (lastpress& 0x7f) == 1 )
{
joystickpresent = false;
return false;
}
} while ( buttons);
return true;
}
/*
===============
=
= I_StartupJoystick
=
===============
*/
int basejoyx, basejoyy;
void I_StartupJoystick (void)
{
int centerx, centery;
joystickpresent = 0;
if ( M_CheckParm ("-nojoy") || !usejoystick )
return;
if (!I_ReadJoystick ())
{
joystickpresent = false;
ST_Message("joystick not found\n ");
return;
}
ST_Message("joystick found\n");
joystickpresent = true;
ST_RealMessage("CENTER the joystick and press button 1:");
if (!WaitJoyButton ())
return;
I_ReadJoystick ();
centerx = joystickx;
centery = joysticky;
ST_RealMessage("\nPush the joystick to the UPPER LEFT corner and press button 1:");
if (!WaitJoyButton ())
return;
I_ReadJoystick ();
joyxl = (centerx + joystickx)/2;
joyyl = (centerx + joysticky)/2;
ST_RealMessage("\nPush the joystick to the LOWER RIGHT corner and press button 1:");
if (!WaitJoyButton ())
return;
I_ReadJoystick ();
joyxh = (centerx + joystickx)/2;
joyyh = (centery + joysticky)/2;
ST_RealMessage("\n");
}
/*
===============
=
= I_JoystickEvents
=
===============
*/
void I_JoystickEvents (void)
{
event_t ev;
//
// joystick events
//
if (!joystickpresent)
return;
I_ReadJoystick ();
ev.type = ev_joystick;
ev.data1 = ((inp(0x201) >> 4)&15)^15;
if (joystickx < joyxl)
ev.data2 = -1;
else if (joystickx > joyxh)
ev.data2 = 1;
else
ev.data2 = 0;
if (joysticky < joyyl)
ev.data3 = -1;
else if (joysticky > joyyh)
ev.data3 = 1;
else
ev.data3 = 0;
H2_PostEvent (&ev);
}
/*
============================================================================
DPMI STUFF
============================================================================
*/
#define REALSTACKSIZE 1024
dpmiregs_t dpmiregs;
unsigned realstackseg;
void I_DivException (void);
int I_SetDivException (void);
/*
void DPMIFarCall (void)
{
segread (&segregs);
regs.w.ax = 0x301;
regs.w.bx = 0;
regs.w.cx = 0;
regs.x.edi = (unsigned)&dpmiregs;
segregs.es = segregs.ds;
int386x( DPMI_INT, ®s, ®s, &segregs );
}
*/
void DPMIInt (int i)
{
dpmiregs.ss = realstackseg;
dpmiregs.sp = REALSTACKSIZE-4;
segread (&segregs);
regs.w.ax = 0x300;
regs.w.bx = i;
regs.w.cx = 0;
regs.x.edi = (unsigned)&dpmiregs;
segregs.es = segregs.ds;
int386x( DPMI_INT, ®s, ®s, &segregs );
}
/*
==============
=
= I_StartupDPMI
=
==============
*/
void I_StartupDPMI (void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -