pm.c
来自「适合KS8695X」· C语言 代码 · 共 2,244 行 · 第 1/5 页
C
2,244 行
return 0;
}
char * PMAPI PM_getCurrentPath(
char *path,
int maxLen)
{
return getcwd(path,maxLen);
}
char PMAPI PM_getBootDrive(void)
{ return 'C'; }
const char * PMAPI PM_getVBEAFPath(void)
{ return "c:\\"; }
const char * PMAPI PM_getNucleusPath(void)
{
static char path[256];
char *env;
if ((env = getenv("NUCLEUS_PATH")) != NULL)
return env;
if ((env = getenv("WINBOOTDIR")) != NULL) {
/* Running in a Windows 9x DOS box or DOS mode */
strcpy(path,env);
strcat(path,"\\system\\nucleus");
return path;
}
if ((env = getenv("SystemRoot")) != NULL) {
/* Running in an NT/2K DOS box */
strcpy(path,env);
strcat(path,"\\system32\\nucleus");
return path;
}
return "c:\\nucleus";
}
const char * PMAPI PM_getNucleusConfigPath(void)
{
static char path[256];
strcpy(path,PM_getNucleusPath());
PM_backslash(path);
strcat(path,"config");
return path;
}
const char * PMAPI PM_getUniqueID(void)
{ return "DOS"; }
const char * PMAPI PM_getMachineName(void)
{ return "DOS"; }
int PMAPI PM_kbhit(void)
{
return kbhit();
}
int PMAPI PM_getch(void)
{
return getch();
}
PM_HWND PMAPI PM_openConsole(PM_HWND hwndUser,int device,int xRes,int yRes,int bpp,ibool fullScreen)
{
/* Not used for DOS */
(void)hwndUser;
(void)device;
(void)xRes;
(void)yRes;
(void)bpp;
(void)fullScreen;
return 0;
}
int PMAPI PM_getConsoleStateSize(void)
{
return sizeof(DOS_stateBuf);
}
void PMAPI PM_saveConsoleState(void *stateBuf,PM_HWND hwndConsole)
{
RMREGS regs;
DOS_stateBuf *sb = stateBuf;
/* Save the old video mode state */
regs.h.ah = 0x0F;
PM_int86(0x10,®s,®s);
sb->oldMode = regs.h.al & 0x7F;
sb->old50Lines = false;
if (sb->oldMode == 0x3) {
regs.x.ax = 0x1130;
regs.x.bx = 0;
regs.x.dx = 0;
PM_int86(0x10,®s,®s);
sb->old50Lines = (regs.h.dl == 42 || regs.h.dl == 49);
}
(void)hwndConsole;
}
void PMAPI PM_setSuspendAppCallback(int (_ASMAPIP saveState)(int flags))
{
/* Not used for DOS */
(void)saveState;
}
void PMAPI PM_restoreConsoleState(const void *stateBuf,PM_HWND hwndConsole)
{
RMREGS regs;
const DOS_stateBuf *sb = stateBuf;
/* Retore 50 line mode if set */
if (sb->old50Lines) {
regs.x.ax = 0x1112;
regs.x.bx = 0;
PM_int86(0x10,®s,®s);
}
(void)hwndConsole;
}
void PMAPI PM_closeConsole(PM_HWND hwndConsole)
{
/* Not used for DOS */
(void)hwndConsole;
}
void PMAPI PM_setOSCursorLocation(int x,int y)
{
uchar *_biosPtr = PM_getBIOSPointer();
PM_setByte(_biosPtr+0x50,x);
PM_setByte(_biosPtr+0x51,y);
}
void PMAPI PM_setOSScreenWidth(int width,int height)
{
uchar *_biosPtr = PM_getBIOSPointer();
PM_setWord(_biosPtr+0x4A,width);
PM_setWord(_biosPtr+0x4C,width*2);
PM_setByte(_biosPtr+0x84,height-1);
if (height > 25) {
PM_setWord(_biosPtr+0x60,0x0607);
PM_setByte(_biosPtr+0x85,0x08);
}
else {
PM_setWord(_biosPtr+0x60,0x0D0E);
PM_setByte(_biosPtr+0x85,0x016);
}
}
void * PMAPI PM_mallocShared(long size)
{
return PM_malloc(size);
}
void PMAPI PM_freeShared(void *ptr)
{
PM_free(ptr);
}
#define GetRMVect(intno,isr) *(isr) = ((ulong*)rmZeroPtr)[intno]
#define SetRMVect(intno,isr) ((ulong*)rmZeroPtr)[intno] = (isr)
ibool PMAPI PM_doBIOSPOST(
ushort axVal,
ulong BIOSPhysAddr,
void *mappedBIOS,
ulong BIOSLen)
{
static int firstTime = true;
static uchar *rmZeroPtr;
long Current10,Current6D,Current42;
RMREGS regs;
RMSREGS sregs;
/* Create a zero memory mapping for us to use */
if (firstTime) {
rmZeroPtr = PM_mapPhysicalAddr(0,0x7FFF,true);
firstTime = false;
}
/* Remap the secondary BIOS to 0xC0000 physical */
if (BIOSPhysAddr != 0xC0000L || BIOSLen > 32768) {
/* DOS cannot virtually remap the BIOS, so we can only work if all
* the secondary controllers are identical, and we then use the
* BIOS on the first controller for all the remaining controllers.
*
* For OS'es that do virtual memory, and remapping of 0xC0000
* physical (perhaps a copy on write mapping) should be all that
* is needed.
*/
return false;
}
/* Save current handlers of int 10h and 6Dh */
GetRMVect(0x10,&Current10);
GetRMVect(0x6D,&Current6D);
/* POST the secondary BIOS */
GetRMVect(0x42,&Current42);
SetRMVect(0x10,Current42); /* Restore int 10h to STD-BIOS */
regs.x.ax = axVal;
PM_callRealMode(0xC000,0x0003,®s,&sregs);
/* Restore current handlers */
SetRMVect(0x10,Current10);
SetRMVect(0x6D,Current6D);
/* Second the primary BIOS mappin 1:1 for 0xC0000 physical */
if (BIOSPhysAddr != 0xC0000L) {
/* DOS does not support this */
(void)mappedBIOS;
}
return true;
}
void PMAPI PM_sleep(ulong milliseconds)
{
ulong microseconds = milliseconds * 1000L;
LZTimerObject tm;
LZTimerOnExt(&tm);
while (LZTimerLapExt(&tm) < microseconds)
;
LZTimerOffExt(&tm);
}
int PMAPI PM_getCOMPort(int port)
{
switch (port) {
case 0: return 0x3F8;
case 1: return 0x2F8;
}
return 0;
}
int PMAPI PM_getLPTPort(int port)
{
switch (port) {
case 0: return 0x3BC;
case 1: return 0x378;
case 2: return 0x278;
}
return 0;
}
PM_MODULE PMAPI PM_loadLibrary(
const char *szDLLName)
{
(void)szDLLName;
return NULL;
}
void * PMAPI PM_getProcAddress(
PM_MODULE hModule,
const char *szProcName)
{
(void)hModule;
(void)szProcName;
return NULL;
}
void PMAPI PM_freeLibrary(
PM_MODULE hModule)
{
(void)hModule;
}
int PMAPI PM_setIOPL(
int level)
{
return level;
}
/****************************************************************************
REMARKS:
Internal function to convert the find data to the generic interface.
****************************************************************************/
static void convertFindData(
PM_findData *findData,
struct find_t *blk)
{
ulong dwSize = findData->dwSize;
memset(findData,0,findData->dwSize);
findData->dwSize = dwSize;
if (blk->attrib & _A_RDONLY)
findData->attrib |= PM_FILE_READONLY;
if (blk->attrib & _A_SUBDIR)
findData->attrib |= PM_FILE_DIRECTORY;
if (blk->attrib & _A_ARCH)
findData->attrib |= PM_FILE_ARCHIVE;
if (blk->attrib & _A_HIDDEN)
findData->attrib |= PM_FILE_HIDDEN;
if (blk->attrib & _A_SYSTEM)
findData->attrib |= PM_FILE_SYSTEM;
findData->sizeLo = blk->size;
strncpy(findData->name,blk->name,PM_MAX_PATH);
findData->name[PM_MAX_PATH-1] = 0;
}
#define FIND_MASK (_A_RDONLY | _A_ARCH | _A_SUBDIR | _A_HIDDEN | _A_SYSTEM)
/****************************************************************************
REMARKS:
Function to find the first file matching a search criteria in a directory.
****************************************************************************/
void * PMAPI PM_findFirstFile(
const char *filename,
PM_findData *findData)
{
struct find_t *blk;
if ((blk = PM_malloc(sizeof(*blk))) == NULL)
return PM_FILE_INVALID;
if (_dos_findfirst((char*)filename,FIND_MASK,blk) == 0) {
convertFindData(findData,blk);
return blk;
}
return PM_FILE_INVALID;
}
/****************************************************************************
REMARKS:
Function to find the next file matching a search criteria in a directory.
****************************************************************************/
ibool PMAPI PM_findNextFile(
void *handle,
PM_findData *findData)
{
struct find_t *blk = handle;
if (_dos_findnext(blk) == 0) {
convertFindData(findData,blk);
return true;
}
return false;
}
/****************************************************************************
REMARKS:
Function to close the find process
****************************************************************************/
void PMAPI PM_findClose(
void *handle)
{
PM_free(handle);
}
/****************************************************************************
REMARKS:
Function to determine if a drive is a valid drive or not. Under Unix this
function will return false for anything except a value of 3 (considered
the root drive, and equivalent to C: for non-Unix systems). The drive
numbering is:
1 - Drive A:
2 - Drive B:
3 - Drive C:
etc
****************************************************************************/
ibool PMAPI PM_driveValid(
char drive)
{
RMREGS regs;
regs.h.dl = (uchar)(drive - 'A' + 1);
regs.h.ah = 0x36; /* Get disk information service */
PM_int86(0x21,®s,®s);
return regs.x.ax != 0xFFFF; /* AX = 0xFFFF if disk is invalid */
}
/****************************************************************************
REMARKS:
Function to get the current working directory for the specififed drive.
Under Unix this will always return the current working directory regardless
of what the value of 'drive' is.
****************************************************************************/
void PMAPI PM_getdcwd(
int drive,
char *dir,
int len)
{
uint oldDrive,maxDrives;
_dos_getdrive(&oldDrive);
_dos_setdrive(drive,&maxDrives);
getcwd(dir,len);
_dos_setdrive(oldDrive,&maxDrives);
}
/****************************************************************************
REMARKS:
Function to change the file attributes for a specific file.
****************************************************************************/
void PMAPI PM_setFileAttr(
const char *filename,
uint attrib)
{
#if defined(TNT) && defined(_MSC_VER)
DWORD attr = 0;
if (attrib & PM_FILE_READONLY)
attr |= FILE_ATTRIBUTE_READONLY;
if (attrib & PM_FILE_ARCHIVE)
attr |= FILE_ATTRIBUTE_ARCHIVE;
if (attrib & PM_FILE_HIDDEN)
attr |= FILE_ATTRIBUTE_HIDDEN;
if (attrib & PM_FILE_SYSTEM)
attr |= FILE_ATTRIBUTE_SYSTEM;
SetFileAttributes((LPSTR)filename, attr);
#else
uint attr = 0;
if (attrib & PM_FILE_READONLY)
attr |= _A_RDONLY;
if (attrib & PM_FILE_ARCHIVE)
attr |= _A_ARCH;
if (attrib & PM_FILE_HIDDEN)
attr |= _A_HIDDEN;
if (attrib & PM_FILE_SYSTEM)
attr |= _A_SYSTEM;
_dos_setfileattr(filename,attr);
#endif
}
/****************************************************************************
REMARKS:
Function to create a directory.
****************************************************************************/
ibool PMAPI PM_mkdir(
const char *filename)
{
#ifdef __GNUC__
return mkdir(filename,S_IRUSR) == 0;
#else
return mkdir(filename) == 0;
#endif
}
/****************************************************************************
REMARKS:
Function to remove a directory.
****************************************************************************/
ibool PMAPI PM_rmdir(
const char *filename)
{
return rmdir(filename) == 0;
}
/*-------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?