home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 337_01 / l_main.c < prev    next >
C/C++ Source or Header  |  1991-01-14  |  6KB  |  249 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   L_MAIN.C   ***************************/
  4.  
  5. #include "mydef.h"
  6. #include <dos.h>
  7. #include <string.h>
  8.  
  9. /* define our external variables */
  10. /* window definitions */
  11.  
  12. struct screen_structure scr;
  13. struct window_structure w[MAX_WINDOW+1];
  14. struct help_structure hlp;
  15.  
  16. int main(int argc,char *argv[])
  17. {
  18. extern struct screen_structure scr;
  19. extern struct window_structure w[];
  20. extern struct help_structure hlp;
  21.  
  22.   int i;
  23.   unsigned int seg,off;
  24.   long l;
  25.   char string[10];
  26.   int return_code;
  27.  
  28. set_screen_attr();      /* set screen attributes */
  29. test_dv();              /* check for DesqView */
  30.  
  31. /* extract segment and offset of screen buffer */
  32. seg=FP_SEG(scr.buffer); off=FP_OFF(scr.buffer);
  33.  
  34. /* check command line values for override values */
  35.  if(argc>1)
  36.  for(i=1;i<=argc;i++){
  37.  
  38.    copy(argv[i],string,2,4); /* copy any values. i.e. r=30 */
  39.                              /* note: copy() is found in l_copy.c */
  40.    /* check for segment override */
  41.    if ( toupper(argv[i][0])=='S') if(atoi(string)) seg=atoi(string);
  42.  
  43.    /* check for offset override */
  44.    if ( toupper(argv[i][0])=='O') if(atoi(string)) off=atoi(string);
  45.  
  46.    /* check for row override */
  47.    if ( toupper(argv[i][0])=='R')
  48.     if(atoi(string)) scr.rows=atoi(string);
  49.  
  50.    /* chec for column override */
  51.    if ( toupper(argv[i][0])=='C')
  52.     if(atoi(string)) scr.columns=atoi(string);
  53.  
  54.    /* check for black & white override */
  55.    if ( toupper(argv[i][0])=='B') set_mode(BW_80);
  56.  
  57.    /* check for snow override (turn off snow avoidance)  */
  58.    if ( toupper(argv[i][0])=='N') scr.snow=FALSE;
  59.  }
  60.  
  61. scr.buffer=MAKE_FP(seg,off);
  62.  
  63. init_window();          /* initialize window structure */
  64. update_margins();
  65.                         /* initialize help structure */
  66. hlp.filename[0]='\0';   /* empty string (no current help file) */
  67.  
  68. /* set text which appears in window frame */
  69. strcpy(hlp.message,"Esc: to exit ");  
  70. hlp.page=0;                   /* page zero */
  71. hlp.x=1;                      /* upper left column of help window */
  72. hlp.y=1;                      /* upper left row of help window */
  73. hlp.interior_attr=scr.normal; /* set window interior to normal */
  74. hlp.frame_attr=scr.normal;    /* set window frame to normal */
  75.  
  76. return_code=start();
  77. return(return_code);
  78. }
  79.  
  80.  
  81. static void init_window(void)
  82. {
  83. extern struct screen_structure scr;
  84. extern struct window_structure w[];
  85. int i;
  86.  
  87. /* initialize initial window (desk top) */
  88.   w[0].frame=FALSE;
  89.   wherexy(&w[0].x,&w[0].y); /* save current cursor location*/
  90.   what_cursor(&w[0].start,&w[0].end);
  91.   w[0].left=1;w[0].right=scr.columns;
  92.   w[0].top=1;w[0].bottom=scr.rows;
  93.   w[0].attribute=scr.normal;  /* assume default normal attribute */
  94.  
  95.  /* initialize window pointer array */
  96.  
  97.  for(i=0;i<=MAX_WINDOW;i++){
  98.   scr.list[i]=i;
  99.  }
  100. }
  101.  
  102.  
  103. /*****************************************************************
  104.  
  105.  Usage: static void set_screen_attr(void);
  106.  
  107.  Ascertains what type of graphics card is in use, sets external
  108.  text attributes and screen buffer address according.
  109.  
  110. *****************************************************************/
  111.  
  112. static void set_screen_attr(void)
  113. {
  114. extern struct  screen_structure scr;
  115. extern struct window_structure w[];
  116.  
  117.  what_mode(&scr.mode,&scr.page);  /*set current textmode and page */
  118.  
  119.  if(scr.mode==MONOCHROME) scr.mode = MONOCHROME;
  120.  
  121.  if(scr.mode==BW_40){      /* if 40 column BW set to 80 column */
  122.   set_mode(BW_80);
  123.   scr.mode =BW_80;
  124.  }
  125.  
  126.  if(scr.mode==COLOR_40){   /* if 40 column color, set to 80 column */
  127.        set_mode(COLOR_80);
  128.        scr.mode=COLOR_80;
  129.  }
  130.  
  131. /* set character attributes */
  132.  
  133.   if (scr.mode==BW_80){             /* set attributes for BW */
  134.     scr.normal=  set_color(WHITE,BLACK);
  135.     scr.inverse= set_color(BLACK,WHITE);
  136.    }
  137.  
  138.   if (scr.mode==COLOR_80){           /* set attributes for COLOR */
  139.     scr.normal=  set_color(WHITE,BLACK);
  140.     scr.inverse= set_color(BLACK,WHITE);
  141.    }
  142.  
  143.    if (scr.mode==MONOCHROME){    /* set attributes for MONOCHROME */
  144.     scr.normal = NORMAL;
  145.     scr.inverse = INVERSE;
  146.    }
  147.  
  148.     scr.current = scr.normal;   /* set screen attribute to normal */
  149.  
  150.  /* set screen buffer address */
  151.  if(scr.mode==MONOCHROME)
  152.     scr.buffer= (char far *)0xb0000000;    /* monochrome address */
  153.    else
  154.      scr.buffer=(char far *)0xb8000000;    /* color address */
  155.  
  156.   scr.rows=25;scr.columns=80;  /* assume standard values for now */
  157.   scr.update=TRUE;
  158.   scr.bold_caps=FALSE;
  159.   scr.ptr=0;scr.active=0;
  160.  
  161.   /* set snow flag if not ega and not monochrome */
  162.   scr.snow=  (!test_ega() && (scr.mode!=MONOCHROME));
  163.  
  164.   /* set screen margins */
  165.   scr.top=1;
  166.   scr.bottom=scr.rows;
  167.   scr.left=1;
  168.   scr.right=scr.columns;
  169.  
  170. }
  171.  
  172.  
  173. #if defined TURBOC
  174.  
  175. static void test_dv(void)
  176. {
  177. extern struct  screen_structure scr;
  178. int seg,off;
  179.  
  180.    struct REGPACK regs;
  181.  
  182.    seg = FP_SEG(scr.buffer);
  183.    off = FP_OFF(scr.buffer);
  184.  
  185.    regs.r_ax=0xfe00;
  186.  
  187.    regs.r_es= seg;
  188.    regs.r_di= off;
  189.  
  190.    intr(0x10, ®s);
  191.  
  192.  if(regs.r_es != seg || regs.r_di != off)
  193.  scr.buffer=MAKE_FP(regs.r_es,regs.r_di);
  194. }
  195. #endif
  196.  
  197.  
  198. #if defined QUICKC
  199.  
  200. static void test_dv(void)
  201. {
  202. extern struct  screen_structure scr;
  203. int seg,off;
  204.  
  205. union REGS inregs,outregs;
  206. struct SREGS segregs;
  207.  
  208.   seg = FP_SEG(scr.buffer);
  209.   off = FP_OFF(scr.buffer);
  210.  
  211.    inregs.h.ah=0xfe;
  212.    segregs.es= seg;
  213.    inregs.x.di= off;
  214.  
  215.    int86x(0x10, &inregs,&outregs,&segregs);
  216.  
  217.  if(segregs.es != seg || inregs.x.di != off)
  218.   scr.buffer=MAKE_FP(segregs.es,inregs.x.di);
  219.  
  220. }
  221. #endif
  222.  
  223.  
  224. int test_ega(void)
  225. {
  226.  union REGS reg;
  227.  
  228.  reg.h.ah = 0X12;         /* call an ega function */
  229.  reg.h.bl = 0X10;
  230.  reg.x.cx = 0Xffff;       /* stuff the register */
  231.  
  232.  int86(0X10, ®, ®);
  233.   if (reg.x.cx==0xffff) return (0); /* if it isn't changed, no ega */
  234.     else
  235.      return(1); /* contents changed, there is a ega */
  236. }
  237.  
  238.  
  239. void update_margins(void)
  240. {
  241. extern struct  screen_structure scr;
  242. extern struct window_structure w[];
  243.  
  244.  scr.top= w[scr.active].top;
  245.  scr.bottom= w[scr.active].bottom;
  246.  scr.left= w[scr.active].left;
  247.  scr.right= w[scr.active].right;
  248. }
  249.