home *** CD-ROM | disk | FTP | other *** search
-
- This information is included for interest. It works, but the code in
- "close.c" is more universal.
-
- ---------------------------------------------------------------------
-
- Here is some alternative code for the
- void increase_handles(void)
- function:
-
-
- ----------------- code for small-data models ------------------------
-
- /* We use assembler here to get access to the byte swap instruction
- and to make the access to DOS functions cleaner.
- It also saves some bytes and a few microseconds...
- */
-
- /* WARNING: This code will prevent the subsequent use of far-data
- memory allocation, e.g. by farmalloc() etc.
- */
-
- asm {
- mov ah, 0x30 /* Get the DOS version. */
- int 0x21
- xchg al, ah /* Swap the byte order */
- /* to allow easy comparison. */
- cmp ax, 0x0303
- jb done /* Exit if the DOS version is not
- at least 3.3 */
-
- mov ax, 0x6700 /* Increase the size of the handle table */
- mov bx, MAX_FD /* to this value. */
- int 0x21
- jnc done /* Exit if no errors */
- }
-
- {
- /* Whoops! we should never get here! */
- printf("DOS error %d for service 0x67\n", _AX);
- exit(1);
- }
-
- done: ;
-
-
-
-
- ------------------ Code for large-data models ------------------
-
- /* Unfortunately, the Turbo C large data models handle memory
- allocation differently and the memory fragmentation caused
- by the DOS service 0x67 call above will cause malloc() etc
- to fail!
- So, for the large data models, we take care of the nitty-
- gritty details ourselves...
- */
-
-
- #if MAX_FD <= 20
- #error "MAX_FD must be > 20"
- #endif
-
- #if !defined(__COMPACT__) && !defined(__LARGE__) && !defined(__HUGE__)
- #error "This code will cause crashes with small-data models"
- #endif
-
- char *newblock;
-
- /* Get space for the file_table from the Turbo C allocation scheme. */
- if ( (newblock = malloc(MAX_FD+15)) == NULL )
- abort();
-
- /* Start on a paragraph */
- newblock = MK_FP(FP_SEG(newblock)+1, FP_OFF(newblock) & 0xfff0);
-
- memcpy(newblock, MK_FP(_psp, 0x18), 20); /* Copy the existing table. */
- memset(newblock+20, 0xff, MAX_FD-20); /* Make the extra entries invalid. */
- *((long far *)MK_FP(_psp, 0x34)) = (long)newblock; /* Point to the table. */
- *((int far *)MK_FP(_psp, 0x32)) = MAX_FD; /* Set its size. */
-
-
- ------------------------------------------------------------------------------
-
-
-
- -------------
- 16th feb 1992
-
- W. Metzenthen
- apm233m@vaxc.cc.monash.edu.au
-