?? io.c
字號:
/*
io.c
expanded input/output functions
*/
// standard libs..
#include <stdtypes.h>
#include <string.h>
#include <ctype.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
// custom libs...
#include <clib1.h>
extern CHAR errstring[];
/*
************************************************************************
************************************************************************
** **
** logical <--> physical address conversion routines **
** **
************************************************************************
************************************************************************
*/
UINT32 physaddr( void *voidaddr )
{
UINT32 ulong;
ulong = (UINT32)FP_SEG(voidaddr) << 4;
ulong += (UINT32)FP_OFF(voidaddr);
return ulong;
}
void *voidaddr( UINT32 physaddr )
{
if( physaddr > 0x000FFFFFlu )
{
fprintf( stderr, "Function voidaddr() called with address > 1mb.\n " );
exit(1);
}
return MK_FP( (UINT16)((physaddr & 0x000FFFF0lu) >> 4), (UINT16)(physaddr & 0x0000000Flu) );
}
/*
************************************************************************
************************************************************************
** **
** endian swapping routines **
** **
************************************************************************
************************************************************************
*/
UINT32 swaplong ( UINT32 ulong )
/* swap byte order of 32-bit dword */
{
UINT8 swapped[4];
swapped[0] = (UINT8)(ulong >> 24);
swapped[1] = (UINT8)(ulong >> 16);
swapped[2] = (UINT8)(ulong >> 8);
swapped[3] = (UINT8)ulong;
return( *(UINT32 *)swapped );
}
UINT16 swapword ( UINT16 uword )
/* swap byte order of 16-bit word */
{
UINT8 swapped[2];
swapped[0] = (UINT8)(uword >> 8);
swapped[1] = (UINT8)uword;
return( *(UINT16 *)swapped );
}
/****************************************************************************/
/* */
/* INSB */
/* */
/* Purpose: Inputs a string of BYTEs from a hardware port */
/* */
/* Inputs: */
/* */
/* word port */
/* hardware port to read from */
/* */
/* void *buf */
/* Buffer to read data into */
/* */
/* int count */
/* Number of BYTEs to read */
/* */
/* Outputs: */
/* */
/* None */
/* */
/****************************************************************************/
void insb(UINT16 port, void *buf, int count)
{
_ES = FP_SEG(buf); /* Segment of buf */
_DI = FP_OFF(buf); /* Offset of buf */
_CX = count; /* Number to read */
_DX = port; /* Port */
asm REP INSB;
}
/****************************************************************************/
/* */
/* INSW */
/* */
/* Purpose: Inputs a string of WORDs from a hardware port */
/* */
/* Inputs: */
/* */
/* word port */
/* hardware port to read from */
/* */
/* void *buf */
/* Buffer to read data into */
/* */
/* int count */
/* Number of WORDs to read */
/* */
/* Outputs: */
/* */
/* None */
/* */
/****************************************************************************/
void insw(UINT16 port, void *buf, int count)
{
_ES = FP_SEG(buf); /* Segment of buf */
_DI = FP_OFF(buf); /* Offset of buf */
_CX = count; /* Number to read */
_DX = port; /* Port */
asm REP INSW;
}
/****************************************************************************/
/* */
/* INSL */
/* */
/* Purpose: Inputs a string of 32-bit words from a hardware port */
/* */
/* Inputs: */
/* */
/* word port */
/* hardware port to read from */
/* */
/* void *buf */
/* Buffer to read data into */
/* */
/* int count */
/* Number of DWORDs to read */
/* */
/* Outputs: */
/* */
/* None */
/* */
/****************************************************************************/
void insl(UINT16 port, void *buf, int count)
{
_ES = FP_SEG(buf); /* Segment of buf */
_DI = FP_OFF(buf); /* Offset of buf */
_CX = count; /* Number to read */
_DX = port; /* Port */
__emit__(0xf3, 0x66, 0x6D); /* asm REP INSD */
}
/****************************************************************************/
/* */
/* OUTSB */
/* */
/* Purpose: Outputs a string of BYTEs to a hardware port */
/* */
/* Inputs: */
/* */
/* word port */
/* hardware port to write to */
/* */
/* void *buf */
/* Buffer to write data from */
/* */
/* int count */
/* Number of BYTEs to write */
/* */
/* Outputs: */
/* */
/* None */
/* */
/****************************************************************************/
void outsb(UINT16 port, void *buf, int count)
{
_SI = FP_SEG(buf); /* Offset of buf */
_CX = count; /* Number to read */
_DX = port; /* Port */
asm REP OUTSB;
}
/****************************************************************************/
/* */
/* OUTSW */
/* */
/* Purpose: Outputs a string of WORDs to a hardware port */
/* */
/* Inputs: */
/* */
/* word port */
/* hardware port to write to */
/* */
/* void *buf */
/* Buffer to write data from */
/* */
/* int count */
/* Number of WORDs to write */
/* */
/* Outputs: */
/* */
/* None */
/* */
/****************************************************************************/
void outsw(UINT16 port, void *buf, int count)
{
_SI = FP_SEG(buf); /* Offset of buf */
_CX = count; /* Number to read */
_DX = port; /* Port */
asm REP OUTSW;
}
/****************************************************************************/
/* */
/* OUTSL */
/* */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -