int GetCodePage (void) { #if (DOSX & DJGPP) /* _osmajor/_osminor not set in crt0.o */ _get_dos_version (0); #endif if ((_osmajor << 8) + _osminor >= 0x303) { #if (DOSX & DJGPP) __dpmi_regs reg; reg.d.eax = 0x6601; __dpmi_int (0x21, ®); if (reg.x.flags & 1) return (0); return (reg.x.bx); #elif (DOSX & PHARLAP) SWI_REGS reg; reg.eax = 0x6601; _dx_real_int (0x21, ®); if (reg.flags & 1) return (0); return (WORD)reg.ebx; #elif (DOSX & (DOS4GW|WDOSX)) struct DPMI_regs reg; reg.r_ax = 0x6601; if (!dpmi_real_interrupt (0x21, ®)) return (0); return (WORD)reg.r_bx; #elif (DOSX & POWERPAK) UNFINISHED(); #elif (DOSX == 0) /* real-mode */ union REGS reg; reg.x.ax = 0x6601; int86 (0x21, ®, ®); if (reg.x.cflag) return (0); return (reg.x.bx); #else #error Unsupported target #endif } return (0); }
static qboolean Sys_DetectWinNT (void) /* FS: Wisdom from Gisle Vanem */ { if(_get_dos_version(1) == 0x0532) return true; return false; }
/* Compute table of pointers to look for directory entry of a file. */ static int init_dirent_table (void) { short get_sda_func; unsigned short dirent_offset; unsigned short true_dos_version; unsigned short dos_major, dos_minor; __dpmi_regs regs; if (dirent_count == -1) /* we already tried and found we can't */ return 0; /* Compute INT 21h function number and offset of directory entry from start of SDA. These depend on the DOS version. We need exact knowledge about DOS internals, so we need the TRUE DOS version (not the simulated one by SETVER), if that's available. */ true_dos_version = _get_dos_version(1); dos_major = true_dos_version >> 8; dos_minor = true_dos_version & 0xff; if ((dos_major == 3) && (dos_minor >= 10)) { get_sda_func = 0x5d06; dirent_offset = 0x1a7; } else if (dos_major == 4) { /* According to ``Undocumented DOS, 2nd edition'', I could have used 5d06 here, as for DOS 5 and above, but I like to be defensive. In fact, the above book itself uses 5d0b, contrary to its own recommendation. */ get_sda_func = 0x5d0b; dirent_offset = 0x1b3; } else if (dos_major >= 5) { get_sda_func = 0x5d06; dirent_offset = 0x1b3; } else { _djstat_fail_bits |= _STFAIL_OSVER; dirent_count = -1; return 0; } _djstat_fail_bits &= ~_STFAIL_OSVER; /* version is OK */ /* Get the pointer to SDA by calling undocumented function 5dh of INT 21. */ regs.x.ax = get_sda_func; __dpmi_int(0x21, ®s); if (regs.x.flags & 1) { _djstat_fail_bits |= _STFAIL_SDA; dirent_count = -1; /* if the call failed, never try this later */ return 0; } _djstat_fail_bits &= ~_STFAIL_SDA; /* Get SDA succeeded */ /* DOS 4.x might have several SDA's, which means we might have more than one place to look into. (It is typical of DOS 4 to complicate things.) Compute all the possible addresses where we will have to look. */ if (dos_major == 4) { /* The pointer returned by INT 21h, AX=5D0b points to a header which holds a number of SDA's and then an array of that number of records each one of which includes address of an SDA (DWORD) and its length and type (encoded in a WORD). While walking this list of SDA's, we add to each pointer the offset of directory entry and stash the resulting address in our table for later use. */ int sda_list_walker = MK_FOFF(regs.x.ds, regs.x.si); int i; int *tbl; dirent_count = _farpeekw(_dos_ds, sda_list_walker); /* number of SDA's */ /* Allocate storage for table. */ tbl = dirent_table = (int *)malloc(dirent_count*sizeof(int)); if (!dirent_table) { /* If malloc() failed, maybe later it will succeed, so don't store -1 in dirent_count. */ dirent_count = 0; _djstat_fail_bits |= _STFAIL_DCOUNT; return 0; } memset(dirent_table, 0, dirent_count*sizeof(int)); _djstat_fail_bits &= ~_STFAIL_DCOUNT; /* dirent_count seems OK */ /* Walk the array of pointers, computing addresses of directory entries and stashing them in our table. */ _farsetsel(_dos_ds); for (i = dirent_count, sda_list_walker += 2; i--; sda_list_walker += 6) { int sda_start = _farnspeekl(sda_list_walker); unsigned short sda_len = _farnspeekw(sda_list_walker + 4) & 0x7fff; /* Let's be defensive here: if this SDA is too short to have place for directory entry, we won't use it. */ if (sda_len > dirent_offset) *tbl++ = sda_start + dirent_offset; else dirent_count--; } } /* DOS 3.1 and 5.0 or later. We have only one SDA pointed to by whatever INT 21h, AH=5d returns. */ else { dirent_count = 1; dirent_place = MK_FOFF(regs.x.ds, regs.x.si) + dirent_offset; dirent_table = &dirent_place; } return 1; }
/* detect_os: * Operating system autodetection routine. */ static void detect_os() { static int done = 0; __dpmi_regs r; char buf[16]; char *p; int i; if (done) return; done = 1; /* check for Windows 3.1 or 95 */ r.x.ax = 0x1600; __dpmi_int(0x2F, &r); if ((r.h.al != 0) && (r.h.al != 1) && (r.h.al != 0x80) && (r.h.al != 0xFF)) { dz_i_love_bill = TRUE; return; } /* check for Windows NT */ p = getenv("OS"); if (((p) && (stricmp(p, "Windows_NT") == 0)) || (_get_dos_version(1) == 0x0532)) { dz_i_love_bill = TRUE; return; } /* check for OS/2 */ r.x.ax = 0x4010; __dpmi_int(0x2F, &r); if (r.x.ax != 0x4010) { dz_i_love_bill = TRUE; return; } /* check for Linux DOSEMU */ _farsetsel(_dos_ds); for (i=0; i<8; i++) buf[i] = _farnspeekb(0xFFFF5+i); buf[8] = 0; if (!strcmp(buf, "02/25/93")) { r.x.ax = 0; __dpmi_int(0xE6, &r); if (r.x.ax == 0xAA55) { dz_i_love_bill = TRUE; /* (evil chortle) */ return; } } /* check if running under OpenDOS */ r.x.ax = 0x4452; __dpmi_int(0x21, &r); if ((r.x.ax >= 0x1072) && !(r.x.flags & 1)) { /* now check for OpenDOS EMM386.EXE */ r.x.ax = 0x12FF; r.x.bx = 0x0106; __dpmi_int(0x2F, &r); if ((r.x.ax == 0) && (r.x.bx == 0xEDC0)) { dz_i_love_bill = TRUE; } return; } /* check for that stupid win95 "stealth mode" setting */ r.x.ax = 0x8102; r.x.bx = 0; r.x.dx = 0; __dpmi_int(0x4B, &r); if ((r.x.bx == 3) && !(r.x.flags & 1)) { dz_i_love_bill = TRUE; return; } }
int GetCountryCode (void) { #if (DOSX & DJGPP) /* _osmajor/_osminor not set in crt0.o */ _get_dos_version (0); #endif if (_osmajor >= 3) { #if (DOSX & DJGPP) __dpmi_regs reg; reg.d.edx = 0; reg.x.ds = __tb / 16; reg.d.eax = 0x3800; __dpmi_int (0x21, ®); if (reg.x.flags & 1) return (0); dosmemget (__tb, sizeof(_country_info), &_country_info); return (reg.x.bx); #elif (DOSX & PHARLAP) SWI_REGS reg; if (_watt_dosTbSize < sizeof(_country_info)) return (0); reg.edx = RP_OFF (_watt_dosTbr); reg.ds = RP_SEG (_watt_dosTbr); reg.eax = 0x3800; _dx_real_int (0x21, ®); if (reg.flags & 1) return (0); ReadRealMem (&_country_info, _watt_dosTbr, sizeof(_country_info)); return (reg.ebx); #elif (DOSX & (DOS4GW|WDOSX)) union REGS reg; struct SREGS sreg; if (_watt_dosTbSize < sizeof(_country_info)) return (0); reg.x.edx = 0; sreg.ds = _watt_dosTbSeg; reg.x.eax = 0x3800; int386x (0x21, ®, ®, &sreg); if (reg.x.cflag) return (0); memcpy (&_country_info, SEG_OFS_TO_LIN(_watt_dosTbSeg,0), sizeof(_country_info)); return (reg.w.bx); #elif (DOSX & POWERPAK) UNFINISED(); #elif (DOSX == 0) /* real-mode */ union REGS reg; struct SREGS sreg; reg.x.dx = FP_OFF (_country_info); sreg.ds = FP_SEG (_country_info); reg.x.ax = 0x3800; int86x (0x21, ®, ®, &sreg); if (reg.x.cflag) return (0); return (reg.x.bx); #else #error Unsupported target #endif } return (0); }