home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / SY_HANDL.C < prev   
Encoding:
C/C++ Source or Header  |  1991-01-30  |  8.1 KB  |  303 lines

  1. /*********************
  2.  *
  3.  *  sy_handl.c - system handler functions.
  4.  *
  5.  *  Purpose: This file contains the low level system functions
  6.  *           required for clock,interrupts, and directory.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985,1989 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include <dos.h>
  14. #include <process.h>
  15. #include "blackstr.h"
  16. #include "sy_head.h"
  17. #include "sy_defs.h"
  18. #include "ut_defs.h"
  19.  
  20.  
  21. /*****************
  22.    sy_gtime()        get current time
  23. *****************/
  24. void sy_gtime(void)
  25. {
  26.     union REGS inregs,outregs;
  27.  
  28.     inregs.h.ah = 0x2c;             /* get time command */
  29.     int86(IMSDOS,&inregs,&outregs);
  30.     time_.hr = hour_   = outregs.h.ch;
  31.     time_.mn = minute_ = outregs.h.cl;
  32.     time_.sec  = sec_  = outregs.h.dh;
  33.     time_.hsec = hsec_ = outregs.h.dl;
  34. }
  35.  
  36. /*****************
  37.   sy_gdate()        get current date
  38. *****************/
  39. void sy_gdate(void)
  40. {
  41.     union REGS inregs,outregs;
  42.  
  43.     inregs.h.ah = 0x2a;             /* get date command */
  44.     int86(IMSDOS,&inregs,&outregs);
  45.     today_.yr = year_  = (short) outregs.x.cx;
  46.     today_.mo = month_ = (short) outregs.h.dh;
  47.     today_.dy = day_   = (short) outregs.h.dl;
  48. }
  49.  
  50. /******************************
  51.   sy_setintf(vector,function)        set interrupt vector to c function
  52. *******************************/
  53. void sy_setintf(int vector, int (*function)())
  54. {
  55.     int ptr[2];
  56.  
  57.     ptr[1] = sy_pseg(function);
  58.     ptr[0] = sy_poff(function);
  59.     sy_setintv(vector,(int*)ptr);
  60. }
  61.  
  62. /*****************************
  63.    sy_setintv(vector,address)        set interrupt vector to address
  64. ******************************/
  65. void sy_setintv(int vector, int *address)
  66. {
  67.     sy_setint_(vector,address[0],address[1]);
  68. }
  69.  
  70. /****************************
  71.    sy_getintv(vector,address)
  72. *******************************/
  73. void sy_getintv(int vector, int *address)
  74. {
  75.     sy_getint_(vector,address);             /* use assembly program */
  76. }
  77.  
  78. /************************
  79. char *sy_ffdir(path,attr)        find directory occurence
  80. ************************/
  81. char *sy_ffdir(           /* attr = 0 - normal       08 - volume */
  82.     char *path,       /*        1 - read only    10 - directory*/
  83.     int attr)         /*        2 - hidden file  20 - archive */
  84. {
  85.     union REGS inregs,outregs;
  86.     struct SREGS segs;
  87.     int carry;
  88.     char *dptr;
  89.  
  90.     segread(&segs);
  91.     dptr = (char*) sy_dta_;                         /* need for seg macros */
  92.     if(!path)
  93.     return(sy_fdir());
  94.  
  95.     inregs.h.ah = 0x1a;
  96.     inregs.x.dx = sy_doff(dptr);
  97.     segs.ds = sy_dseg(dptr);                    /* default dta area */
  98.     int86x(IMSDOS,&inregs,&outregs,&segs);
  99.  
  100.     inregs.h.ah = 0x4e;                         /* version 2 find */
  101.     inregs.x.cx = attr;                         /* attribute of file to search for*/
  102.     inregs.x.dx = sy_doff(path);                /* offset of path name */
  103.     segs.ds = sy_dseg(path);                    /* segment of path name */
  104.     int86x(IMSDOS,&inregs,&outregs,&segs);
  105.  
  106.     carry = outregs.x.cflag;
  107.     //printf("carry = %u\n", carry);
  108.     return (carry? NULL : &sy_dta_[30]);        /* pointer to file found */
  109. }
  110.  
  111. /********************
  112.  char *sy_fdir()        find subsequent dirctory occurence
  113. *********************/
  114. char *sy_fdir(void)
  115. {
  116.     union REGS inregs,outregs;
  117.     int carry;
  118.  
  119.     inregs.h.ah = 0x4f;                     /* dos command # */
  120.     int86(IMSDOS,&inregs,&outregs);
  121.  
  122.     carry = outregs.x.cflag;
  123.     return (carry? NULL : &sy_dta_[30]);    /* pointer to file name */
  124. }
  125.         
  126. /*******************
  127.    sy_getsys()          get system parameters
  128. ********************/
  129. void sy_getsys(void)
  130. {
  131.     union REGS inregs,outregs;
  132.  
  133.     inregs.h.ah = 0x30;                                                                     /* dos version */
  134.     int86(IMSDOS,&inregs,&outregs);
  135.  
  136.     sy_dosver_ = outregs.h.ah;                                                      /* minor version */
  137.     sy_dosrel_ = outregs.h.al;                                                      /* major release */
  138.     if(!sy_dosrel_) ++sy_dosrel_;                                                                           /* release 1 */
  139.     int86(0x11,&inregs,&outregs);               /* get equip */
  140.  
  141.     sy_prnts_ = (outregs.h.ah & 0xc0)>>6;       /* #printers attached */
  142.     if(outregs.h.al&01)
  143.     sy_flpys_=((outregs.h.al & 0xc0)>>6)+1; /* #floppies attached */
  144.     else
  145.     sy_flpys_ = 0;
  146.     sy_vmod_ =(outregs.h.al & 0x30)>>4;         /* initial video mode*/
  147.  
  148.     int86(0x12,&inregs,&outregs);
  149.     sy_memk_ = outregs.x.ax;                                                        /* 1k blocks of memory */
  150. }
  151.  
  152. /**********************
  153.    sy_isdrive(driveno)        check for drive number  present
  154. ***********************/
  155. int sy_isdrive(int driveno)                       /* number to check 0=A, 1=B, etc */
  156. {
  157. union REGS inregs,outregs;
  158. int flag,cur;
  159.         inregs.h.ah= 0x19;            /* get and save current */
  160.         intdos(&inregs,&outregs);
  161.         cur = outregs.h.al;
  162.         inregs.h.ah= 0x0e;            /* select disk drive  */
  163.         inregs.h.dl = driveno;
  164.         intdos(&inregs,&outregs);
  165.         inregs.h.ah= 0x19;            /* and check if it's current */
  166.           intdos(&inregs,&outregs);
  167.         if(outregs.h.al==driveno)
  168.                 flag = TRUE;
  169.         else    flag = FALSE;         /* not there */
  170.         inregs.h.ah= 0x0e;            /* restore current drive as default */
  171.         inregs.h.dl = cur;
  172.         intdos(&inregs,&outregs);
  173.     return(flag);
  174. }
  175.  
  176. /******************
  177.    sy_indosf(ptr)            get dos critical flag address
  178. ******************/
  179. int sy_indosf(int *ptr)
  180. {
  181.     union REGS inregs,outregs;
  182.     struct SREGS segregs;
  183.  
  184.     inregs.h.ah = 0x34;             /* get critical command */
  185.     int86(IMSDOS,&inregs,&outregs);
  186.     segread(&segregs);
  187.     *ptr++ = segregs.es;            /* segment */
  188.     *ptr = outregs.x.bx;            /* offset */
  189.     return 0;
  190. }
  191.  
  192. /***************
  193.    sy_beep()        sound the beeper
  194. ***************/
  195. void sy_beep(void)
  196. {
  197.     union REGS inregs,outregs;
  198.  
  199.     inregs.h.ah = 0x0e;             /* use teletype command */
  200.     inregs.h.al = 07;               /* ascii bell */
  201.     int86(ISCREEN,&inregs,&outregs);
  202. }
  203.  
  204. /****************
  205.    sy_abort()        abort gracefully
  206. ****************/
  207. void sy_abort(void)
  208. {
  209. extern int sc_attr_;
  210. extern char rattr_;
  211.     sc_cursor(1);        /* cursor on */
  212.     sc_attr_ = rattr_;
  213.     sc_clr();        /* clear old window */
  214.     exit(0);
  215. }
  216.  
  217. /****************
  218.     sy_doff(data)           return offset of data address
  219. *****************/
  220. int sy_doff(void *data)
  221. {
  222.     if (sizeof(int) == 2)
  223.     return ((sizeof(char *) == 2)? (int)data : FP_OFF(data));
  224.     else
  225.     return ((sizeof(char *) == 4)? (int)data : FP_OFF(data));
  226. }
  227.  
  228. /****************
  229.     sy_dseg(data)           return segment of data address
  230. *****************/
  231. int sy_dseg(void *data)
  232. {
  233.     struct SREGS segregs;
  234.     union {
  235.     struct {
  236.         unsigned offset;
  237.         short segment;
  238.     } both;
  239.     char *d;
  240.     } fp;
  241.  
  242.     if (sizeof(int) == 2)
  243.     if (sizeof(char *) == 2) {
  244.         segread(&segregs);
  245.         return(segregs.ds);
  246.     }
  247.     else
  248.         return(FP_SEG(data));
  249.     else
  250.     if (sizeof(char *) == 4) {
  251.         segread(&segregs);
  252.         return(segregs.ds);
  253.     }
  254.     else {
  255.         fp.d = data;
  256.         return(fp.both.segment);
  257.     }
  258. }
  259.  
  260. /********************
  261.    sy_poff(function)               return offset of function address
  262. *********************/
  263. int sy_poff(int (*function)())
  264. {
  265.     if (sizeof(int) == 2)
  266.     return ((sizeof(void (*)()) == 2)? (int)function : FP_OFF(function));
  267.     else
  268.     return ((sizeof(void (*)()) == 4)? (int)function : FP_OFF(function));
  269. }
  270.  
  271. /********************
  272.    sy_pseg(function)               return segment of function address
  273. *********************/
  274. int sy_pseg(int (*function)())
  275. {
  276.     struct SREGS segregs;
  277.     union {
  278.     struct {
  279.         unsigned offset;
  280.         short segment;
  281.     } both;
  282.     int (*d)();
  283.     } fp;
  284.  
  285.     if (sizeof(int) == 2)
  286.     if (sizeof(void (*)()) == 2) {
  287.         segread(&segregs);
  288.         return(segregs.cs);
  289.     }
  290.     else
  291.         return(FP_SEG(function));
  292.     else
  293.     if (sizeof(char *) == 4) {
  294.         segread(&segregs);
  295.         return(segregs.ds);
  296.     }
  297.     else {
  298.         fp.d = function;
  299.         return(fp.both.segment);
  300.     }
  301. }
  302.     
  303.