/* and fraction (in nanoseconds). */ void gp_get_realtime(long *pdt) { union REGS osdate, ostime; long idate; static const int mstart[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; osdate.h.ah = 0x2a; /* get date */ intdos(&osdate, &osdate); #define da_year rshort.cx #define da_mon h.dh #define da_day h.dl ostime.h.ah = 0x2c; /* get time */ intdos(&ostime, &ostime); #define ti_hour h.ch #define ti_min h.cl #define ti_sec h.dh #define ti_hund h.dl idate = (long)osdate.da_year * 365 + ( /* intervening leap days */ ((osdate.da_year + 1979) / 4 - 1979 / 4) + (1979 / 100 - (osdate.da_year + 1979) / 100) + ((osdate.da_year + 1979) / 400 - 1979 / 400) + mstart[osdate.da_mon - 1] + /* month is 1-origin */ osdate.da_day - 1); /* day of month is 1-origin */ idate += (2 < osdate.da_mon && (osdate.da_year % 4 == 0 && ((osdate.da_year + 1980) % 100 != 0 || (osdate.da_year + 1980) % 400 == 0))); pdt[0] = ((idate * 24 + ostime.ti_hour) * 60 + ostime.ti_min) * 60 + ostime.ti_sec; pdt[1] = ostime.ti_hund * 10000000; }
/* and time (in milliseconds since midnight). */ void gp_get_clock(long *pdt) { union REGS osdate, ostime; long idate; static int mstart[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; osdate.h.ah = 0x2a; /* get date */ intdos(&osdate, &osdate); #define da_year rshort.cx #define da_mon h.dh #define da_day h.dl ostime.h.ah = 0x2c; /* get time */ intdos(&ostime, &ostime); #define ti_hour h.ch #define ti_min h.cl #define ti_sec h.dh #define ti_hund h.dl idate = (long)osdate.da_year * 365 + (osdate.da_year / 4 + 1 + /* account for leap years */ mstart[osdate.da_mon - 1] + /* month is 1-origin */ osdate.da_day - 1); /* day of month is 1-origin */ if ( osdate.da_mon <= 2 && osdate.da_year % 4 == 0 ) /* Jan. or Feb. of leap year */ idate--; pdt[0] = idate; pdt[1] = (ostime.ti_hour * 60 + ostime.ti_min) * 60000L + (ostime.ti_sec * 100 + ostime.ti_hund) * 10L; }
ttcooked() { ttflush(); if (dosversion > 1) { inregs.h.ah = 0x33; /* Reset BREAK check status. */ inregs.h.al = 0x01; inregs.h.dl = breakstat; intdos(&inregs, &outregs); if (outregs.h.al == 0xff) { ewprintf("ttclose can't set break check status"); return(FALSE); } inregs.h.ah = 0x44; /* Reset IOCTRL status. */ inregs.h.al = 0x01; inregs.x.bx = 0x00; /* 0 = stdin. */ inregs.x.dx = stdinstat & 7; intdos(&inregs, &outregs); if (outregs.x.cflag != 0x00) { ewprintf("ttclose can't set IOCTRL status"); return(FALSE); } } #ifdef IBMPC /* 90.02.23 by S.Yoshida */ cancelkey(); resetcursor(); /* 91.01.05 Reset cursor by S.Yoshida */ #endif /* IBMPC */ #ifdef PC9801 /* 90.03.06 by K.Takano */ cancelkey(); if (use_metakey) resetezkey(); #endif /* PC9801 */ return(TRUE); }
void pause(register int ptime) { #ifdef WINCIT Sleep(ptime * 10); #else union REGS in, out; register int i, j = 0; in.h.ah = 0x2C; intdos(&in, &out); i = out.h.dl; while (j < ptime) { in.h.ah = 0x2C; intdos(&in, &out); if (out.h.dl < (uchar) i) { j += (100 + out.h.dl) - i; } else { j += out.h.dl - i; } i = out.h.dl; CitIsIdle(); } #endif }
int valid_drive(char *s) { char buf1[128],buf2[128]; struct SREGS sregs; union REGS regs; if (s[1] != ':') return(0); *TempDrive = *s; /* Make sure this is a valid drive. */ con_fcb[fcbDRIVE] = *TempDrive-'A'+1; regs.x.ax = 0x0f00; regs.x.dx = (unsigned)con_fcb; /* needs NEAR POINTER */ intdos(®s, ®s); if (regs.h.al) { myprintf("Not a valid drive\r\n",0); /* printf("Not a valid drive\n") */ exit(1); } /* end if. */ regs.x.ax = 0x1000; regs.x.dx = (unsigned)con_fcb; /* needs NEAR POINTER */ intdos(®s, ®s); /* Now close the file. */ /* Make sure user is not trying to label a network drive. */ regs.h.ah = IOCTL; regs.h.al = REMOTE; regs.h.bl = (char)(*TempDrive-'A'+1); intdos(®s, ®s); if (regs.x.dx & 0x1000) { myprintf("You cannot label a network drive\r\n",0); /* printf("You cannot label a network drive\n"); */ exit(5); } /* end if. */ /* Make sure the user is not trying to label a drive which has */ /* been ASSIGNed, JOINed, or SUBSTed. */ strcpy(buf1, TempDrive); strcat(buf1, "\\"); segread(&sregs); regs.x.si = (unsigned)buf1; /* needs NEAR POINTER */ regs.x.di = (unsigned)buf2; /* needs NEAR POINTER */ regs.x.ax = 0x6000; intdosx(®s, ®s, &sregs); if (*buf1 != *buf2) { myprintf("You cannot label a drive which has\r\n",0); myprintf("been ASSIGNed, JOINed, or SUBSTed.\r\n",0); exit(5); } /* end if. */ return(1); } /* end valid_drive. */
int ext_getch(void) { int key; #ifdef __OS2__ extern KBDKEYINFO ki; /* defined in ISSHIFT.C */ KBDINFO kb_state; kb_state = setkbmode(); /* Change keyboard to binary mode */ KbdCharIn(&ki, IO_WAIT, 0); /* Get the key */ restkbmode(kb_state); /* restore previous keyboard mode */ key = (ki.chScan << 8) + ki.chChar; /* format it into an int */ #else /* assume DOS */ union REGS regs; #if USING_DOS regs.h.ah = 7; intdos(®s, ®s); key = regs.h.al; if (0 == key) { regs.h.ah = 7; intdos(®s, ®s); key = (regs.h.al << 8); } #else regs.h.ah = 0x10; int86(0x16, ®s, ®s); key = regs.x.ax; #endif switch (LoByte(key)) { case 0: key = HiByte(key) + 256; break; case 0xe0: key = HiByte(key) + 512; break; default: if (0xe0 == HiByte(key)) key = LoByte(key) + 512; else { if (ispunct(LoByte(key)) && HiByte(key) > 0x36) key = LoByte(key) + 512; else key = LoByte(key); } } #endif return key; }
void mygets(char *buff, unsigned int length) { char *sptr; int i; union REGS regs; if (input_redir==-1) { regs.h.ah = 0x44; regs.h.al = 0x0; regs.x.bx = 0x0; intdos(®s, ®s); if (regs.x.dx & 0x80) input_redir = 0; else input_redir = 1; } /* end if. */ if (input_redir) { regs.h.ah = 0xb; /* check if input waiting */ intdos(®s,®s); if (regs.h.al==0) /* no input waiting */ { /* puts(""); */ /* WHY ??? */ exit(10); } /* end if. */ } /* end if. */ getsbuf[0] = (char) length; getsbuf[2] = 0; regs.x.dx = (unsigned) getsbuf; regs.h.ah = 0xa; intdos(®s,®s); myprintf("\r",0); /* puts("\r"); */ sptr = &getsbuf[2]; if (*sptr==0x1a) { /* puts(""); */ /* WHY ??? */ exit(10); } /* end if. */ for (i=0;i<getsbuf[1];i++) { *buff = *sptr; buff++; sptr++; } /* end for. */ *buff='\0'; } /* end mygets. */
void TERMWINDOWMEMBER netpause(register int ptime) { #ifdef WINCIT Sleep(ptime * 10); // After waiting, display any input we got form the comm port while (CommPort->IsInputReady()) { const int ch = CommPort->Input(); if (debug) { outCon((char) ch); } } #else union REGS in, out; register int i, j=0; in.h.ah = 0x2C; intdos(&in, &out); i = out.h.dl; while (j < ptime) { in.h.ah=0x2C; intdos(&in, &out); if (out.h.dl < (uchar)i) { j += (100 + out.h.dl) - i; } else { j += out.h.dl - i; } i = out.h.dl; if (CommPort->IsInputReady()) { const int ch = CommPort->Input(); if (debug) { outCon(ch); } } CitIsIdle(); } #endif }
void TERMWINDOWMEMBER twirlypause(register int ptime) { #ifdef WINCIT if (KeyboardBuffer.IsEmpty() && !CommPort->IsInputReady()) { HANDLE ToWaitFor[2]; int WaitingFor = 0; // keyboard is worth looking at if we are focused if (TermWindowCollection.InFocus(this)) { ToWaitFor[WaitingFor++] = hConsoleInput; } // comm port is worth looking at if we could create the event if (CommPort->InputWaiting) { ToWaitFor[WaitingFor++] = CommPort->InputWaiting; } if (WaitingFor) { WaitForMultipleObjects(WaitingFor, ToWaitFor, FALSE, ptime * 10); } } #else union REGS in, out; register int i, j=0; in.h.ah = 0x2C; intdos(&in, &out); i = out.h.dl; while (j < ptime && !KBReady() && !(CommPort->IsInputReady() && CommPort->HaveConnection() && modStat && (OC.whichIO == MODEM))) { in.h.ah = 0x2C; intdos(&in, &out); if (out.h.dl < (uchar) i) { j += (100 + out.h.dl) - i; } else { j += out.h.dl - i; } i = out.h.dl; CitIsIdle(); } #endif }
/* but all MS-DOS configurations need it. */ void gp_set_printer_binary(int prnfno) { union REGS regs; regs.h.ah = 0x44; /* ioctl */ regs.h.al = 0; /* get device info */ regs.rshort.bx = prnfno; intdos(®s, ®s); regs.h.dl |= 0x20; /* binary (no ^Z intervention) */ regs.h.dh = 0; regs.h.ah = 0x44; /* ioctl */ regs.h.al = 1; /* set device info */ intdos(®s, ®s); }
void disp_label() { unsigned char serialbuf[26]; union REGS regs; struct SREGS sregs; /* First set the dta to be fcb so information returned is put there. */ regs.x.ax = 0x1a00; regs.x.dx = (unsigned)fcb; /* needs NEAR POINTER */ intdos(®s, ®s); /* Now try to find the volume label. */ fcb[fcbDRIVE] = *Drive-'A'+1; regs.x.ax = 0x1100; regs.x.dx = (unsigned)fcb; /* needs NEAR POINTER */ intdos(®s, ®s); if (regs.h.al) { myprintf("Volume in drive ",0); myprintf(Drive,1); myprintf(" has no label\r\n",0); } /* end if. */ else { NoLabel = 0; fcb[ENDNAME] = '\0'; myprintf("Volume in drive ",0); myprintf(Drive,1); myprintf(" is ",0); myprintf(&fcb[NAME],0); myprintf("\r\n",0); } /* end else. */ /* Now print out the volume serial number, if it exists. */ segread(&sregs); regs.x.ax = 0x6900; regs.h.bl = *Drive-'A'+1; regs.x.dx = (unsigned)serialbuf; /* needs NEAR POINTER */ intdosx(®s, ®s, &sregs); if (!regs.x.cflag) { myprintf("Volume serial number is ",0); hexprint(serialbuf[5]); hexprint(serialbuf[4]); myprintf("-",0); hexprint(serialbuf[3]); hexprint(serialbuf[2]); myprintf("\r\n",0); } /* end if. */ } /* end disp_label. */
dsk_err_t int25_open(DSK_DRIVER *self, const char *filename) { INT25_DSK_DRIVER *int25self; char vname[20]; int driveno; dsk_err_t err; union REGS rg; /* Sanity check: Is this meant for our driver? */ if (self->dr_class != &dc_dosint25) return DSK_ERR_BADPTR; int25self = (INT25_DSK_DRIVER *)self; /* Not a drive? Not interested. */ if (strlen(filename) != 2 || filename[1] != ':') return DSK_ERR_NOTME; int25self->int25_unit = -1; vname[0] = (char)toupper(filename[0]); driveno = vname[0] - 'A'; /* 0=A: 1=B: */ int25self->int25_unit = driveno; /* Get DOS version */ rg.h.ah = 0x30; intdos(&rg, &rg); int25self->int25_dosver = rg.h.al * 256 + rg.h.ah; int25self->int25_oem = rg.h.bh; err = int25_getgeom(self, &int25self->int25_geom); /* If we can't get the geometry (eg a network drive) bail out */ if (err == DSK_ERR_NOTIMPL) err = DSK_ERR_NOTME; if (!err) { /* If DOS 7.10 or greater try to acquire a lock on the drive. * This does not appear to make the slightest difference; * perhaps if I got as far as writing, it would. */ if (int25self->int25_dosver >= 0x70A && int25self->int25_oem != 0) { rg.x.ax = 0x440D; rg.x.bx = 1 + int25self->int25_unit; rg.x.cx = 0x084A; rg.x.dx = 0; intdos(&rg, &rg); if (rg.x.cflag) return DSK_ERR_ACCESS; int25self->int25_lock = 1; } } return err; }
static int abspath( char *filename, char *fullpath ) { int i; char *fn, *fp; union REGS r; fn = filename; fp = fullpath; if( fn[0] && fn[1] == ':' ) { *fp = fn[0], fn += 2; } else { r.h.ah = 0x19; /* get current drive */ intdos( &r, &r ); *fp = (char)( r.h.al + 'A' ); } r.h.dl = (unsigned char)( toupper( *fp ) - 'A' + 1 ); *++fp = ':'; ++fp; if( *fn != '\\' ) { /* filename not abs, so get current directory */ *fp++ = '\\'; r.h.ah = 0x47; r.x.si = (unsigned short)fp; intdos( &r, &r ); if( r.x.cflag ) return( 0 ); if( i = strlen( fp ) ) { fp += i; *fp++ = '\\'; } } /* fullpath to fp is current dir for drive, fn is relative path */ while( *fp++ = *fn ) { if( *fn++ == '.' ) { if( *fn == '\\' ) { ++fn; /* .\ is nop */ --fp; } else if( *fn == '.' && *++fn == '\\' ) { fp -= 3; /* back past last \ */ while( *--fp != '\\' ) { if( fp <= fullpath ) { return( 0 ); } } } } } return( 1 ); }
main() { union REGS in, out; int i; /* Novell's shell TSRs allow up to 32 drive 'letters' to be created */ char drives[]={' ','a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t','u', 'v','w','x','y','z','[','\\',']','^','_','`'}; in.x.ax=0x4409; /* IOCTL function - Check if block device remote */ for(i = 1; i < 32; i++) { in.h.bl=(unsigned char)i; /* 1==a:, 2==b:, etc. */ intdos(&in,&out); if(!out.x.cflag) /* carry flag set on error */ { /* bit 15 == subst, bit 12 == 'remote'*/ printf("drive %c: is %s\n", drives[i],out.x.dx & 1<<15 ? "subst" : out.x.dx & 1<<12 ? "network" : "local"); } } return(0); }
/* forces re-creation of DPB when drive is next accessed */ void Force_Drive_Recheck() { regs.h.ah = 0x0d; /* reset disk system of DOS, flush buffers */ intdos(®s, ®s); regs.h.ah = 0x32; /* force re-reading of boot sector (not useful for FAT1x?) */ regs.h.dl = param.drive_number + 1; intdosx(®s, ®s, &sregs); /* DS:BX is DPB pointer on return - ignored! */ segread(&sregs); /* restore defaults */ if (param.fat_type == FAT32) { /* structure is DW size 0x18, DW 0, DD function (2 "force media change"), * plus 0x10 unused bytes */ union REGS r; struct SREGS s; char some_struc[0x20]; memset(some_struc,0, 0x20); some_struc[0] = 0x18; some_struc[4] = 2; r.x.ax = 0x7304; /* get/set FAT32 flag stuff */ s.es = FP_SEG(&some_struc[0]); r.x.di = FP_OFF(&some_struc[0]); r.h.dl = param.drive_number+1; /* A: is 1 etc. */ r.x.cx = 0x18; /* structure size */ intdosx(&r, &r, &s); segread(&sregs); /* restore defaults */ } /* FAT32 */ }
emmtest() { /* Tests for the presence of expnaded memory by attempting to open the file EMMXXXX0. */ union REGS regs; struct SREGS sregs; int error; long handle; /* Attempt to open the file device EMMXXXX0 */ regs.x.ax = 0x3d00; regs.x.dx = (int)"EMMXXXX0"; sregs.ds = 0; //???? intdosx(®s,®s,&sregs); handle = regs.x.ax; error = regs.x.cflag; if (!error) { regs.h.ah = 0x3e; regs.x.bx = handle; intdos(®s,®s); } return error; }
/* Procedure: trm_close Purpose: close the terminal Parameters: none Return value: error code, or zero if OK Calls: setvect intdos (CLOSE_FILE) Globals: old_kbhand_p, dcb_trm, regs Errors: ERR_TRM_CL_NOTOPN terminal not open ERR_TRM_CL_CLFAIL close failed */ trm_close(void) { int err; /* if not open, return error code */ if (dcb_trm.eflag_p == NULL) return(ERR_TRM_CL_NOTOPN); /* clear the open flag */ dcb_trm.open = FALSE; /* restore MS-DOS interrupt vector */ if (old_kbhand_p!=NULL) { setvect(KBD_INTNUM, old_kbhand_p); } old_kbhand_p = NULL; /* close CON */ regs.h.ah = (byte) CLOSE_FILE; regs.x.bx = (word) con_handle; err = intdos(®s, ®s); err = err; if (regs.x.cflag!=0) return(ERR_TRM_CL_CLFAIL); return(OK); }
void dos_close(int file) { union REGS r; r.h.ah = 0x3e; r.x.bx = file; intdos(&r,&r); }
static int ibmgetc(void){ /* Copied from ibm.c file in memacs */ #if DOS regs.h.ah = 7; intdos(®s,®s); return (int)regs.h.al; #else #if G32 union REGS regs; regs.h.ah = 7; intdos(®s,®s); return (int)regs.h.al; #else return (*emacs_term.t_getchar)(); #endif #endif }
WORD ProgramLoad(char *ProgName, char *Parameters) { char *LoadFile = ProgName; char *CmdLine = Parameters; union REGS r; struct SREGS s; WORD FreeMemorySize; WORD Stack_Seg = 0, Stack_Ptr = 0; struct Parameter_AL00 par_blk; par_blk.EnvSeg = 0; par_blk.CmdLineOffset = FP_OFF(CmdLine); par_blk.CmdLineSeg = FP_SEG(CmdLine); par_blk.FCB1 = par_blk.FCB2 = (DWORD)-1; r.h.ah = 0x48; r.x.bx = 0xFFFF; intdos(&r, &r); if (r.x.bx < MINPARA) { return 8; } Stack_Seg = _SS; Stack_Ptr = _SP; r.x.ax = 0x4B00; /* Load & Execute */ r.x.dx = FP_OFF(LoadFile); r.x.bx = FP_OFF(&par_blk); s.es = s.ds = FP_SEG(LoadFile); intdosx(&r, &r, &s); if (r.x.flags & 1) { return r.x.ax; } disable(); _SS = Stack_Seg; _SP = Stack_Ptr; enable(); return 0; }
int check_quotes() { union REGS regs; static unsigned char far *psp; /* Get the segment address of PSP. */ regs.x.ax = 0x6200; intdos(®s, ®s); /* Get address of original command line. */ #ifdef __TURBOC__ psp = MK_FP(regs.x.bx, 0x81); #else FP_OFF(psp) = 0x81; FP_SEG(psp) = regs.x.bx; #endif /* Check for double quotes. */ for (;*psp != '\r';psp++) { if (*psp==DBQ) return(1); } /* end for. */ return(0); } /* end check_quotes. */
static int RunningUnderDesqview(void) { static int result = 2; union REGS inregs, outregs; if (result != 2) /* First call? */ return result; /* No --> Return saved result */ inregs.x.ax = 0x2B01; /* Dos Set Date function */ inregs.x.cx = 0x4445; /* CX DX = 'DESQ' */ inregs.x.dx = 0x5351; intdos(&inregs, &outregs); if (outregs.h.al == 0xff) { result = 0; } else { printmsg(4, "RunningUnderDesqview: Running under DesqView (AX=0x%x)", (int) outregs.x.ax); result = 1; } return result; } /* RunningUnderDesqview */
int srchnext(fileinfo *pInfo) { /* Search next matching file */ union REGS inreg; union REGS outreg; DEBUG_ENTER(("srchnext(0x%p);\n", pInfo)); /* Make sure the DTA is assigned before calling DOS functions 4E and 4F */ put_dta((char *)pInfo); inreg.h.ah = 0x4f; do { intdos(&inreg, &outreg); if (CF & outreg.x.cflag) { DEBUG_LEAVE(("return %d; // DOS error code\n", outreg.x.ax)); return(outreg.x.ax); } } while ((!strncmp(previousFI.fiFileName, pInfo->fiFileName, sizeof(previousFI))) && REPORT_WORKAROUND(("// Skipped one duplicate entry\n"))); previousFI = *pInfo; /* Save it for the workaround for the VMWare player bug */ DEBUG_LEAVE(("return 0; // Success\n")); return 0; }
/* ** test file exists and return attributes */ meInt meFileGetAttributes(meUByte *fname) { #ifdef __DJGPP2__ return _chmod(fname,0,0) ; #else union REGS reg ; /* cpu register for use of DOS calls */ meUByte fn[meBUF_SIZE_MAX] ; meInt len ; reg.x.ax = 0x4300 ; len = strlen(fname) ; if(fname[len-1] == DIR_CHAR) { strcpy(fn,fname) ; fn[len] = '.' ; fn[len+1] = '\0' ; reg.x.dx = ((unsigned long) fn) ; } else reg.x.dx = ((unsigned long) fname) ; intdos(®, ®); if(reg.x.cflag) return -1 ; return reg.x.ax ; #endif }
void main() { long A,B,C,D; union REGS r; r.h.ah = 0x36; r.h.dl = 2; /* Unidad B: */ if (intdos (&r, &r) == -1) { printf ("Unidad mal especificada\n"); getch(); exit(1); } if (r.x.cflag != 0) { /* Ocurrio un error */ printf ("%s\n",strerror (_doserrno)); getch(); exit (1); } C = r.x.cx; A = r.x.ax; B = r.x.bx; D = r.x.dx; printf ("%-30s %ld\n","Bytes por Cluster",C * A); printf ("%-30s %ld\n","Numero total de bytes libres",C * A *B); printf ("%-30s %ld\n","Espacio total de almacenamiento",C * A * D); printf ("%-30s %lf\n","Porcentaje de espacio libre",B*100/(double)D); getch(); }
/*---------------------------------------------------------------------*/ static int getverify(void) { union REGS regs; regs.x.ax = 0x5400; intdos(®s, ®s); return regs.h.dl; }
/*---------------------------------------------------------------------*/ static void setverify(int value) { union REGS regs; regs.x.ax = 0x2E; regs.h.dl = value; intdos(®s, ®s); }
void terminate( int return_code ) { union REGS inregs, outregs; inregs.h.ah = 0x4C; inregs.h.al = ( unsigned char ) return_code; intdos( &inregs, &outregs ); }
void setBreak(int OnOff) /* Off = 0, On = 1 */ { union REGS regs; regs.x.ax = 0x3301; regs.h.dl = OnOff; intdos(®s, ®s); }
int isBreakOn(void) { union REGS regs; regs.x.ax = 0x3300; intdos(®s, ®s); return (int)regs.h.dl; }