1 /****************************************************************************
3 * SciTech OS Portability Manager Library
5 * ========================================================================
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
25 * Environment: RTTarget-32
27 * Description: Implementation for the OS Portability Manager Library, which
28 * contains functions to implement OS specific services in a
29 * generic, cross platform API. Porting the OS Portability
30 * Manager library is the first step to porting any SciTech
31 * products to a new platform.
33 ****************************************************************************/
36 #include "drvlib/os/os.h"
40 #define WIN32_LEAN_AND_MEAN
48 /*--------------------------- Global variables ----------------------------*/
50 static void (PMAPIP fatalErrorCleanup)(void) = NULL;
52 /*----------------------------- Implementation ----------------------------*/
56 /****************************************************************************
58 Initialise the PM library.
59 ****************************************************************************/
60 void PMAPI PM_init(void)
62 // TODO: dO any special init code in here.
66 /****************************************************************************
68 Return the operating system type identifier.
69 ****************************************************************************/
70 long PMAPI PM_getOSType(void)
75 /****************************************************************************
77 Return the runtime type identifier.
78 ****************************************************************************/
79 int PMAPI PM_getModeType(void)
84 /****************************************************************************
86 Add a file directory separator to the end of the filename.
87 ****************************************************************************/
88 void PMAPI PM_backslash(
92 if (s[pos-1] != '\\') {
98 /****************************************************************************
100 Add a user defined PM_fatalError cleanup function.
101 ****************************************************************************/
102 void PMAPI PM_setFatalErrorCleanup(
103 void (PMAPIP cleanup)(void))
105 fatalErrorCleanup = cleanup;
108 /****************************************************************************
110 Report a fatal error condition and halt the program.
111 ****************************************************************************/
112 void PMAPI PM_fatalError(
115 if (fatalErrorCleanup)
117 // TODO: Display a fatal error message and exit!
118 // MessageBox(NULL,msg,"Fatal Error!", MB_ICONEXCLAMATION);
122 /****************************************************************************
124 Allocate the real mode VESA transfer buffer for communicating with the BIOS.
125 ****************************************************************************/
126 void * PMAPI PM_getVESABuf(
131 /* No BIOS access for the RTTarget */
135 /****************************************************************************
137 Check if a key has been pressed.
138 ****************************************************************************/
139 int PMAPI PM_kbhit(void)
141 // TODO: Need to check if a key is waiting on the keyboard queue
145 /****************************************************************************
147 Wait for and return the next keypress.
148 ****************************************************************************/
149 int PMAPI PM_getch(void)
151 // TODO: Need to obtain the next keypress, and block until one is hit
155 /****************************************************************************
157 Set the location of the OS console cursor.
158 ****************************************************************************/
159 void PM_setOSCursorLocation(
163 /* Nothing to do for RTTarget-32 */
166 /****************************************************************************
168 Set the width of the OS console.
169 ****************************************************************************/
170 void PM_setOSScreenWidth(
174 /* Nothing to do for RTTarget-32 */
177 /****************************************************************************
179 Set the real time clock handler (used for software stereo modes).
180 ****************************************************************************/
181 ibool PMAPI PM_setRealTimeClockHandler(
185 /* Not supported for RTTarget-32 */
189 /****************************************************************************
191 Set the real time clock frequency (for stereo modes).
192 ****************************************************************************/
193 void PMAPI PM_setRealTimeClockFrequency(
196 /* Not supported under RTTarget-32 */
199 /****************************************************************************
201 Restore the original real time clock handler.
202 ****************************************************************************/
203 void PMAPI PM_restoreRealTimeClockHandler(void)
205 /* Not supported under RTTarget-32 */
208 /****************************************************************************
210 Return the current operating system path or working directory.
211 ****************************************************************************/
212 char * PMAPI PM_getCurrentPath(
216 return getcwd(path,maxLen);
219 /****************************************************************************
221 Return the drive letter for the boot drive.
222 ****************************************************************************/
223 char PMAPI PM_getBootDrive(void)
228 /****************************************************************************
230 Return the path to the VBE/AF driver files.
231 ****************************************************************************/
232 const char * PMAPI PM_getVBEAFPath(void)
237 /****************************************************************************
239 Return the path to the Nucleus driver files.
240 ****************************************************************************/
241 const char * PMAPI PM_getNucleusPath(void)
243 // TODO: Point this at the path when the Nucleus drivers will be found
244 return "c:\\nucleus";
247 /****************************************************************************
249 Return the path to the Nucleus configuration files.
250 ****************************************************************************/
251 const char * PMAPI PM_getNucleusConfigPath(void)
253 static char path[256];
254 strcpy(path,PM_getNucleusPath());
256 strcat(path,"config");
260 /****************************************************************************
262 Return a unique identifier for the machine if possible.
263 ****************************************************************************/
264 const char * PMAPI PM_getUniqueID(void)
266 return PM_getMachineName();
269 /****************************************************************************
271 Get the name of the machine on the network.
272 ****************************************************************************/
273 const char * PMAPI PM_getMachineName(void)
275 /* Not necessary for RTTarget-32 */
279 /****************************************************************************
281 Return a pointer to the real mode BIOS data area.
282 ****************************************************************************/
283 void * PMAPI PM_getBIOSPointer(void)
285 /* Not used for RTTarget-32 */
289 /****************************************************************************
291 Return a pointer to 0xA0000 physical VGA graphics framebuffer.
292 ****************************************************************************/
293 void * PMAPI PM_getA0000Pointer(void)
295 static void *bankPtr;
297 bankPtr = PM_mapPhysicalAddr(0xA0000,0xFFFF,true);
301 /****************************************************************************
303 Map a physical address to a linear address in the callers process.
304 ****************************************************************************/
305 void * PMAPI PM_mapPhysicalAddr(
310 // TODO: Map a physical memory address to a linear address
314 /****************************************************************************
316 Free a physical address mapping allocated by PM_mapPhysicalAddr.
317 ****************************************************************************/
318 void PMAPI PM_freePhysicalAddr(
322 // TODO: Free the physical address mapping
325 ulong PMAPI PM_getPhysicalAddr(void *p)
327 // TODO: This function should find the physical address of a linear
332 void PMAPI PM_sleep(ulong milliseconds)
337 int PMAPI PM_getCOMPort(int port)
339 // TODO: Re-code this to determine real values using the Plug and Play
340 // manager for the OS.
342 case 0: return 0x3F8;
343 case 1: return 0x2F8;
348 int PMAPI PM_getLPTPort(int port)
350 // TODO: Re-code this to determine real values using the Plug and Play
351 // manager for the OS.
353 case 0: return 0x3BC;
354 case 1: return 0x378;
355 case 2: return 0x278;
360 /****************************************************************************
362 Allocate a block of (unnamed) shared memory.
363 ****************************************************************************/
364 void * PMAPI PM_mallocShared(
367 return PM_malloc(size);
370 /****************************************************************************
372 Free a block of shared memory.
373 ****************************************************************************/
374 void PMAPI PM_freeShared(
380 /****************************************************************************
382 Map a linear memory address to the calling process address space. The
383 address will have been allocated in another process using the
384 PM_mapPhysicalAddr function.
385 ****************************************************************************/
386 void * PMAPI PM_mapToProcess(
393 /****************************************************************************
395 Map a real mode pointer to a protected mode pointer.
396 ****************************************************************************/
397 void * PMAPI PM_mapRealPointer(
401 /* Not used for RTTarget-32 */
405 /****************************************************************************
407 Allocate a block of real mode memory
408 ****************************************************************************/
409 void * PMAPI PM_allocRealSeg(
414 /* Not used for RTTarget-32 */
418 /****************************************************************************
420 Free a block of real mode memory.
421 ****************************************************************************/
422 void PMAPI PM_freeRealSeg(
425 /* Not used for RTTarget-32 */
428 /****************************************************************************
430 Issue a real mode interrupt (parameters in DPMI compatible structure)
431 ****************************************************************************/
432 void PMAPI DPMI_int86(
436 /* Not used for RTTarget-32 */
439 /****************************************************************************
441 Issue a real mode interrupt.
442 ****************************************************************************/
448 /* Not used for RTTarget-32 */
452 /****************************************************************************
454 Issue a real mode interrupt.
455 ****************************************************************************/
462 /* Not used for RTTarget-32 */
466 /****************************************************************************
468 Call a real mode far function.
469 ****************************************************************************/
470 void PMAPI PM_callRealMode(
476 /* Not used for RTTarget-32 */
479 /****************************************************************************
481 Return the amount of available memory.
482 ****************************************************************************/
483 void PMAPI PM_availableMemory(
487 // TODO: Figure out how to determine the available memory. Not entirely
488 // critical so returning 0 is OK.
489 *physical = *total = 0;
492 /****************************************************************************
494 Allocate a block of locked, physical memory for DMA operations.
495 ****************************************************************************/
496 void * PMAPI PM_allocLockedMem(
502 // TODO: Allocate a block of locked, phsyically contigous memory for DMA
506 /****************************************************************************
508 Free a block of locked physical memory.
509 ****************************************************************************/
510 void PMAPI PM_freeLockedMem(
516 // TODO: Free a locked memory buffer
519 /****************************************************************************
521 Call the VBE/Core software interrupt to change display banks.
522 ****************************************************************************/
523 void PMAPI PM_setBankA(
526 /* Not used for RTTarget-32 */
529 /****************************************************************************
531 Call the VBE/Core software interrupt to change display banks.
532 ****************************************************************************/
533 void PMAPI PM_setBankAB(
536 /* Not used for RTTarget-32 */
539 /****************************************************************************
541 Call the VBE/Core software interrupt to change display start address.
542 ****************************************************************************/
543 void PMAPI PM_setCRTStart(
548 /* Not used for RTTarget-32 */
551 /****************************************************************************
553 Execute the POST on the secondary BIOS for a controller.
554 ****************************************************************************/
555 ibool PMAPI PM_doBIOSPOST(
560 /* Not used for RTTarget-32 */
564 PM_MODULE PMAPI PM_loadLibrary(
565 const char *szDLLName)
567 // TODO: Implement this to load shared libraries!
572 void * PMAPI PM_getProcAddress(
574 const char *szProcName)
576 // TODO: Implement this!
582 void PMAPI PM_freeLibrary(
585 // TODO: Implement this!
589 /****************************************************************************
591 Function to find the first file matching a search criteria in a directory.
592 ****************************************************************************/
593 ulong PMAPI PM_findFirstFile(
594 const char *filename,
595 PM_findData *findData)
597 // TODO: This function should start a directory enumeration search
598 // given the filename (with wildcards). The data should be
599 // converted and returned in the findData standard form.
602 return PM_FILE_INVALID;
605 /****************************************************************************
607 Function to find the next file matching a search criteria in a directory.
608 ****************************************************************************/
609 ibool PMAPI PM_findNextFile(
611 PM_findData *findData)
613 // TODO: This function should find the next file in directory enumeration
614 // search given the search criteria defined in the call to
615 // PM_findFirstFile. The data should be converted and returned
616 // in the findData standard form.
622 /****************************************************************************
624 Function to close the find process
625 ****************************************************************************/
626 void PMAPI PM_findClose(
629 // TODO: This function should close the find process. This may do
630 // nothing for some OS'es.
634 /****************************************************************************
636 Function to determine if a drive is a valid drive or not. Under Unix this
637 function will return false for anything except a value of 3 (considered
638 the root drive, and equivalent to C: for non-Unix systems). The drive
646 ****************************************************************************/
647 ibool PMAPI PM_driveValid(
655 /****************************************************************************
657 Function to get the current working directory for the specififed drive.
658 Under Unix this will always return the current working directory regardless
659 of what the value of 'drive' is.
660 ****************************************************************************/
661 void PMAPI PM_getdcwd(
670 /****************************************************************************
672 Function to change the file attributes for a specific file.
673 ****************************************************************************/
674 void PMAPI PM_setFileAttr(
675 const char *filename,
678 // TODO: Set the file attributes for a file
683 /****************************************************************************
685 Function to create a directory.
686 ****************************************************************************/
687 ibool PMAPI PM_mkdir(
688 const char *filename)
690 return mkdir(filename) == 0;
693 /****************************************************************************
695 Function to remove a directory.
696 ****************************************************************************/
697 ibool PMAPI PM_rmdir(
698 const char *filename)
700 return rmdir(filename) == 0;