home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * sy_handl.c - system handler functions.
- *
- * Purpose: This file contains the low level system functions
- * required for clock,interrupts, and directory.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <dos.h>
- #include <process.h>
- #include "blackstr.h"
- #include "sy_head.h"
- #include "sy_defs.h"
- #include "ut_defs.h"
-
-
- /*****************
- sy_gtime() get current time
- *****************/
- void sy_gtime(void)
- {
- union REGS inregs,outregs;
-
- inregs.h.ah = 0x2c; /* get time command */
- int86(IMSDOS,&inregs,&outregs);
- time_.hr = hour_ = outregs.h.ch;
- time_.mn = minute_ = outregs.h.cl;
- time_.sec = sec_ = outregs.h.dh;
- time_.hsec = hsec_ = outregs.h.dl;
- }
-
- /*****************
- sy_gdate() get current date
- *****************/
- void sy_gdate(void)
- {
- union REGS inregs,outregs;
-
- inregs.h.ah = 0x2a; /* get date command */
- int86(IMSDOS,&inregs,&outregs);
- today_.yr = year_ = (short) outregs.x.cx;
- today_.mo = month_ = (short) outregs.h.dh;
- today_.dy = day_ = (short) outregs.h.dl;
- }
-
- /******************************
- sy_setintf(vector,function) set interrupt vector to c function
- *******************************/
- void sy_setintf(int vector, int (*function)())
- {
- int ptr[2];
-
- ptr[1] = sy_pseg(function);
- ptr[0] = sy_poff(function);
- sy_setintv(vector,(int*)ptr);
- }
-
- /*****************************
- sy_setintv(vector,address) set interrupt vector to address
- ******************************/
- void sy_setintv(int vector, int *address)
- {
- sy_setint_(vector,address[0],address[1]);
- }
-
- /****************************
- sy_getintv(vector,address)
- *******************************/
- void sy_getintv(int vector, int *address)
- {
- sy_getint_(vector,address); /* use assembly program */
- }
-
- /************************
- char *sy_ffdir(path,attr) find directory occurence
- ************************/
- char *sy_ffdir( /* attr = 0 - normal 08 - volume */
- char *path, /* 1 - read only 10 - directory*/
- int attr) /* 2 - hidden file 20 - archive */
- {
- union REGS inregs,outregs;
- struct SREGS segs;
- int carry;
- char *dptr;
-
- segread(&segs);
- dptr = (char*) sy_dta_; /* need for seg macros */
- if(!path)
- return(sy_fdir());
-
- inregs.h.ah = 0x1a;
- inregs.x.dx = sy_doff(dptr);
- segs.ds = sy_dseg(dptr); /* default dta area */
- int86x(IMSDOS,&inregs,&outregs,&segs);
-
- inregs.h.ah = 0x4e; /* version 2 find */
- inregs.x.cx = attr; /* attribute of file to search for*/
- inregs.x.dx = sy_doff(path); /* offset of path name */
- segs.ds = sy_dseg(path); /* segment of path name */
- int86x(IMSDOS,&inregs,&outregs,&segs);
-
- carry = outregs.x.cflag;
- //printf("carry = %u\n", carry);
- return (carry? NULL : &sy_dta_[30]); /* pointer to file found */
- }
-
- /********************
- char *sy_fdir() find subsequent dirctory occurence
- *********************/
- char *sy_fdir(void)
- {
- union REGS inregs,outregs;
- int carry;
-
- inregs.h.ah = 0x4f; /* dos command # */
- int86(IMSDOS,&inregs,&outregs);
-
- carry = outregs.x.cflag;
- return (carry? NULL : &sy_dta_[30]); /* pointer to file name */
- }
-
- /*******************
- sy_getsys() get system parameters
- ********************/
- void sy_getsys(void)
- {
- union REGS inregs,outregs;
-
- inregs.h.ah = 0x30; /* dos version */
- int86(IMSDOS,&inregs,&outregs);
-
- sy_dosver_ = outregs.h.ah; /* minor version */
- sy_dosrel_ = outregs.h.al; /* major release */
- if(!sy_dosrel_) ++sy_dosrel_; /* release 1 */
- int86(0x11,&inregs,&outregs); /* get equip */
-
- sy_prnts_ = (outregs.h.ah & 0xc0)>>6; /* #printers attached */
- if(outregs.h.al&01)
- sy_flpys_=((outregs.h.al & 0xc0)>>6)+1; /* #floppies attached */
- else
- sy_flpys_ = 0;
- sy_vmod_ =(outregs.h.al & 0x30)>>4; /* initial video mode*/
-
- int86(0x12,&inregs,&outregs);
- sy_memk_ = outregs.x.ax; /* 1k blocks of memory */
- }
-
- /**********************
- sy_isdrive(driveno) check for drive number present
- ***********************/
- int sy_isdrive(int driveno) /* number to check 0=A, 1=B, etc */
- {
- union REGS inregs,outregs;
- int flag,cur;
- inregs.h.ah= 0x19; /* get and save current */
- intdos(&inregs,&outregs);
- cur = outregs.h.al;
- inregs.h.ah= 0x0e; /* select disk drive */
- inregs.h.dl = driveno;
- intdos(&inregs,&outregs);
- inregs.h.ah= 0x19; /* and check if it's current */
- intdos(&inregs,&outregs);
- if(outregs.h.al==driveno)
- flag = TRUE;
- else flag = FALSE; /* not there */
- inregs.h.ah= 0x0e; /* restore current drive as default */
- inregs.h.dl = cur;
- intdos(&inregs,&outregs);
- return(flag);
- }
-
- /******************
- sy_indosf(ptr) get dos critical flag address
- ******************/
- int sy_indosf(int *ptr)
- {
- union REGS inregs,outregs;
- struct SREGS segregs;
-
- inregs.h.ah = 0x34; /* get critical command */
- int86(IMSDOS,&inregs,&outregs);
- segread(&segregs);
- *ptr++ = segregs.es; /* segment */
- *ptr = outregs.x.bx; /* offset */
- return 0;
- }
-
- /***************
- sy_beep() sound the beeper
- ***************/
- void sy_beep(void)
- {
- union REGS inregs,outregs;
-
- inregs.h.ah = 0x0e; /* use teletype command */
- inregs.h.al = 07; /* ascii bell */
- int86(ISCREEN,&inregs,&outregs);
- }
-
- /****************
- sy_abort() abort gracefully
- ****************/
- void sy_abort(void)
- {
- extern int sc_attr_;
- extern char rattr_;
- sc_cursor(1); /* cursor on */
- sc_attr_ = rattr_;
- sc_clr(); /* clear old window */
- exit(0);
- }
-
- /****************
- sy_doff(data) return offset of data address
- *****************/
- int sy_doff(void *data)
- {
- if (sizeof(int) == 2)
- return ((sizeof(char *) == 2)? (int)data : FP_OFF(data));
- else
- return ((sizeof(char *) == 4)? (int)data : FP_OFF(data));
- }
-
- /****************
- sy_dseg(data) return segment of data address
- *****************/
- int sy_dseg(void *data)
- {
- struct SREGS segregs;
- union {
- struct {
- unsigned offset;
- short segment;
- } both;
- char *d;
- } fp;
-
- if (sizeof(int) == 2)
- if (sizeof(char *) == 2) {
- segread(&segregs);
- return(segregs.ds);
- }
- else
- return(FP_SEG(data));
- else
- if (sizeof(char *) == 4) {
- segread(&segregs);
- return(segregs.ds);
- }
- else {
- fp.d = data;
- return(fp.both.segment);
- }
- }
-
- /********************
- sy_poff(function) return offset of function address
- *********************/
- int sy_poff(int (*function)())
- {
- if (sizeof(int) == 2)
- return ((sizeof(void (*)()) == 2)? (int)function : FP_OFF(function));
- else
- return ((sizeof(void (*)()) == 4)? (int)function : FP_OFF(function));
- }
-
- /********************
- sy_pseg(function) return segment of function address
- *********************/
- int sy_pseg(int (*function)())
- {
- struct SREGS segregs;
- union {
- struct {
- unsigned offset;
- short segment;
- } both;
- int (*d)();
- } fp;
-
- if (sizeof(int) == 2)
- if (sizeof(void (*)()) == 2) {
- segread(&segregs);
- return(segregs.cs);
- }
- else
- return(FP_SEG(function));
- else
- if (sizeof(char *) == 4) {
- segread(&segregs);
- return(segregs.ds);
- }
- else {
- fp.d = function;
- return(fp.both.segment);
- }
- }
-
-