📄 support.c
字号:
{
byte = (BYTE)(KBuffer[j*2] & cDisplayMask[(j<8)?j:(15-j)]);
disp_byte(x, y + j, byte);
byte = (BYTE)(KBuffer[j*2+1] & cDisplayMask[(j<8)?j:(15-j)]);
disp_byte(x + 8, y + j, byte);
}
x += 16;
i += 2;
}
else
{
lOffset = bQM * 16L;
memcpy(KBuffer, pAFont + lOffset, 16);
for(j=0; j<15; j++)
{
byte = (BYTE)(KBuffer[j] & cDisplayMask[(j<8)?j:(15-j)]);
disp_byte(x, y + j + 1, byte);
}
x += 8;
i += 1;
if(bWM == '\0' || bWM == '\t' || bWM == '\n')
break;
if(bWM & 0x80)
continue;
lOffset = bWM * 16L;
memcpy(KBuffer, pAFont + lOffset, 16);
for(j=0; j<15; j++)
{
byte = (BYTE)(KBuffer[j] & cDisplayMask[(j<8)?j:(15-j)]);
disp_byte(x, y + j + 1, byte);
}
x += 8;
i += 1;
}
}while(TRUE);
}
/*
* Function: cc_printf( LPSTR lpCStr, int x, int y )
* This Function display formatted Chinese word.
* Parameters:
* x,y: the coordination of display point.
* Return: None.
*/
void GUIAPI cc_printf( LPCSTR lpCStr, short x, short y )
{
int i;
int iNewx, iNewy;
i = 0;
iNewx = x;
iNewy = y;
if(*lpCStr != '\0' && *lpCStr != '\t' && *lpCStr != '\n')
cc_wt16(lpCStr, iNewx, iNewy);
while(*(lpCStr+i) != '\0')
{
if(*(lpCStr+i) == '\t')
{
iNewx = x + ((iNewx - x)/32 + 1)*32;
cc_wt16(lpCStr+i+1, iNewx, iNewy);
}
else if(*(lpCStr+i) == '\n')
{
iNewx = x;
iNewy = iNewy + 16;
cc_wt16(lpCStr+i+1, x, iNewy);
}
else
{
iNewx += 8;
}
i++;
}
}
/*
* Function: int GetOutWidth( LPSTR lpCStr )
* This function calculates the lpCStr's width that will be outputed by
* function cc_printf.
* Parameters:
* lpCStr: pointer to Chinese Words.
* Return:
* int: the width that want to get.
*/
int GUIAPI GetOutWidth( LPCSTR lpCStr )
{
int iWidth = 0;
int i = 0;
if(lpCStr == NULL)
return 0;
while(*(lpCStr+i) != '\0' && *(lpCStr+i) != '\n')
{
if(*(lpCStr+i) == '\t')
{
iWidth = (iWidth/32 + 1)*32;
}
else
iWidth += 8;
i++;
}
return iWidth;
}
/*
* Function: static void DisplayIcon( LPSTR pImage, short x, short y ).
* This function display a icon.
* Parameters:
* ANDImage, XORImage;
* x,y.
* Return:
* None
*/
void GUIAPI DisplayIcon(LPSTR lpImage, short x, short y )
{
if(!lpImage)return;
def_GDC_reg();
_putimage(x, y, lpImage, _GAND);
_putimage(x, y, lpImage+664, _GXOR);
}
/*
* Function: void __interrupt __far Clock( void ).
* this function is the new vector of INT 0x1c;
* Parameters:
* None.
* Return:
* None.
*/
void __interrupt __far Clock( void )
{
CaretInfo.uCountForChange++;
(*oldClock)();
if(!CaretInfo.fDisplay)
return;
CaretInfo.count++;
CaretInfo.uCount++;
if(CaretInfo.uCount > MAXCOUNTE)
{
CaretInfo.uCount = 0;
}
}
/*
* Function: void __far CriticalErrorHandler( unsigned ax, unsigned di, unsigned __far* header)
* this function is the new vector of INT 0x1c;
* Parameters:
* None.
* Return:
* None.
*/
void __far CriticalErrorHandler( unsigned ax, unsigned di, unsigned __far* header)
{
DWORD lStyle = MB_ABORTRETRYIGNORE;
char szInfo[256];
if((ax >> 8) & 128)
szInfo[0] = '\0';
else
sprintf(szInfo, "Drive %c: ", 'A' + ax & 0xff);
switch(di)
{
case 0:
strcat(szInfo, "Attempt to write a write-protected disk.");
lStyle = MB_RETRYCANCEL;
break;
case 1:
strcat(szInfo, "Unkown unit.");
lStyle = MB_RETRYCANCEL;
break;
case 2:
strcat(szInfo, "Drive not ready.");
lStyle = MB_RETRYCANCEL;
break;
case 3:
strcat(szInfo, "Unkown command.");
break;
case 4:
strcat(szInfo, "Cyclic-redundancy-check error in data.");
break;
case 5:
strcat(szInfo, "Bad drive-request structure length.");
break;
case 6:
strcat(szInfo, "Seek error.");
break;
case 7:
strcat(szInfo, "Unkown media type.");
break;
case 8:
strcat(szInfo, "Sector not found.");
break;
case 9:
strcat(szInfo, "Printer out of paper.");
break;
case 10:
strcat(szInfo, "Write fault.");
break;
case 11:
strcat(szInfo, "Read fault.");
break;
case 12:
strcat(szInfo, "General failure.");
break;
}
switch(SysMessageBox(NULL, szInfo, "System Error", lStyle))
{
case IDCANCEL:
_hardresume(_HARDERR_FAIL);
break;
case IDABORT:
_hardresume(_HARDERR_ABORT);
break;
case IDRETRY:
_hardresume(_HARDERR_RETRY);
break;
case IDIGNORE:
_hardresume(_HARDERR_IGNORE);
break;
}
}
/* GetKey - Gets a key from the keyboard. This routine distinguishes
* between ASCII keys and function or control keys with different shift
* states. It also accepts a flag to return immediately if no key is
* available.
*
* Params: fWait - Code to indicate how to handle keyboard buffer:
* NO_WAIT Return 0 if no key in buffer, else return key
* WAIT Return first key if available, else wait for key
* CLEAR_WAIT Throw away any key in buffer and wait for new key
*
* Return: One of the following:
*
* Keytype High Byte Low Byte
* ------- --------- --------
* No key available (only with NO_WAIT) 0 0
* Only Shift key was pressed x 0
* ASCII value 0 ASCII code
* Unshifted function or keypad 1 scan code
* Shifted function or keypad 2 scan code
* CTRL function or keypad 3 scan code
* ALT function or keypad 4 scan code
*
* Note: getkey cannot return codes for keys not recognized by BIOS
* int 16, such as the CTRL-UP or the 5 key on the numeric keypad.
*/
unsigned GUIAPI GetKey( int fWait )
{
unsigned uKey, uShift;
/* If CLEAR_WAIT, drain the keyboard buffer. */
if( (fWait == CLEAR_WAIT) || (fWait == CLEAR) )
while( _bios_keybrd( fNewKb ? _NKEYBRD_READY : _KEYBRD_READY ) )
_bios_keybrd( fNewKb ? _NKEYBRD_READ : _KEYBRD_READ );
if( fWait == CLEAR )
return 0;
/* If NO_WAIT, return 0 if there is no key ready. */
if( !fWait && !_bios_keybrd( fNewKb ? _NKEYBRD_READY : _KEYBRD_READY ) )
return 0;
/* Get key code. */
uKey = _bios_keybrd( fNewKb ? _NKEYBRD_READ : _KEYBRD_READ );
/* If low byte is not zero, it's an ASCII key. Check scan code to see
* if it's on the numeric keypad. If not, clear high byte and return.
*/
if( uKey & 0x00ff )
if( (uKey & 0x00ff) != 0xE0 )
return( uKey & 0x00ff );
/* For function keys and numeric keypad, put scan code in low byte
* and shift state codes in high byte.
*/
uKey >>= 8;
uShift = _bios_keybrd( _KEYBRD_SHIFTSTATUS ) & 0x000f;
switch( uShift )
{
case 0:
return( 0x0100 | uKey ); /* None (1) */
case 1:
case 2:
case 3:
return( 0x0200 | uKey ); /* Shift (2) */
case 4:
return( 0x0300 | uKey ); /* Control (3) */
case 8:
return( 0x0400 | uKey ); /* Alt (4) */
}
}
/* Function: void GUIAPI Beep(int frequency, int duration)
* This function beep with a specified frequency
* and duration time
* Parameters:
* frequency: the number of freanqency;
* duration : the micseconds number of duration time.
* Return:
* None.
*/
void GUIAPI Beep( int frequency, int duration )
{
int control;
/* If frequency is 0, Beep doesn't try to make a sound. It
* just sleeps for the duration.
*/
if( frequency )
{
/* 75 is about the shortest reliable duration of a sound. */
if( duration < 75 )
duration = 75;
/* Prepare timer by sending 10111100 to port 43. */
_outp( 0x43, 0xb6 );
/* Divide input frequency by timer ticks per second and
* write (byte by byte) to timer.
*/
frequency = (unsigned)(1193180L / frequency);
_outp( 0x42, (char)frequency );
_outp( 0x42, (char)(frequency >> 8) );
/* Save speaker control byte. */
control = inp( 0x61 );
/* Turn on the speaker (with bits 0 and 1). */
_outp( 0x61, control | 0x3 );
}
Sleep( (clock_t)duration );
/* Turn speaker back on if necessary. */
if( frequency )
_outp( 0x61, control );
}
/*
* Function: void GUIAPI Sleep( clock_t wait );
* This function pauses for a specified number of microseconds.
* Parameters:
* wait: the number of microseconds.
* Return:
* None.
*/
void GUIAPI Sleep( clock_t wait )
{
clock_t goal;
goal = wait + clock();
while( goal > clock() )
;
}
/*
* Function: void GUIAPI set_color( short color );
* This function set color value.
* Parameters:
* color: the color value.
* Return:
* None.
*/
void GUIAPI set_color(short color)
{
_asm
{
mov dx, 3ceh
mov ax, 0005h
out dx, al
inc dx
xchg ah, al
out dx, al
dec dx
mov al, 0
out dx, al
inc dx
mov ax, color
out dx, al
dec dx
mov ax, 0f01h
out dx, al
inc dx
xchg ah, al
out dx, al
dec dx
}
}
/*
* Function: void GUIAPI def_GDC_reg( void );
* This function set color value.
* Parameters:
* color: the color value.
* Return:
* None.
*/
void GUIAPI def_GDC_reg( void )
{
_asm
{
mov dx, 3ceh
mov ax, 0
out dx, al
inc dx
out dx, al
dec dx
mov al, 0001
out dx, al
inc dx
xchg ah, al
out dx, al
dec dx
mov ax, 0ff08h
out dx, al
inc dx
xchg ah, al
out dx, al
dec dx
}
}
/*
* Function: void GUIAPI disp_byte( short x, short y, BYTE by );
* This function display a line.
* Parameters:
* x, y: coordinate of point;
* by : the byte that include the infomation of display line.
* Return:
* None.
*/
void GUIAPI disp_byte(short x, short y, BYTE by)
{
if( ((rcClipRgn.left/8)*8 > x) ||
((rcClipRgn.right/8)*8 < x) ||
( rcClipRgn.top > y) ||
( rcClipRgn.bottom < y) )
return;
_asm
{
push ds
mov ax, y
mov bx, x
mov dx, 80
mul dx
mov cl, 3
shr bx, cl
push bx
push ax
shl bx, cl
mov ax, x
sub ax, bx
mov cl, al
pop ax
pop bx
add bx, ax
mov ax, 0a000h
mov ds, ax
mov dx, 3ceh
mov al, 08h
out dx, al
inc dx
mov ah, by
mov al, 0
shr ax, cl
xchg ah, al
out dx, al
or [bx], al
cmp cl,0
je equ
xchg ah, al
out dx, al
inc bx
or [bx], al
equ: pop ds
}
}
void GUIAPI set_cliprgn(short lx, short ty, short rx, short by)
{
rcClipRgn.left = lx;
rcClipRgn.top = ty;
rcClipRgn.right = rx;
rcClipRgn.bottom = by;
_setcliprgn(lx, ty, rx, by);
}
void GUIAPI move_image(short srcx, short srcy, short srcw, short srch, short destx, short desty)
{
_asm
{
push ds
push es
mov dx, 3ceh
mov ax, 0105h
out dx, al
xchg ah, al
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -