home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / dmenu1.zip / DM10SRC.ZIP / SETUP.C < prev   
Text File  |  1991-10-15  |  8KB  |  333 lines

  1. /***************************************************************************/
  2. void Break_Off(void)
  3.  
  4. {
  5.     _asm push    ds
  6.     _asm push    cs
  7.     _asm pop    ds
  8.     _asm mov    dx, offset DUMMY_IRET
  9.     _asm mov    ah,25h  ; DOS Function 25 - set interrupt vector
  10.     _asm mov    al,23h  ; Select interrupt 23H
  11.     _asm int    21h
  12.     _asm pop    ds
  13.     return;
  14.  
  15.     DUMMY_IRET:
  16.     _asm mov ah,02;       
  17.     _asm sub bh,bh;
  18.     _asm sub dx,dx;
  19.     _asm int 10h;
  20.     _asm iret
  21. }
  22.  
  23. /****************************************************************************/
  24. void Monochrome_Defaults()
  25.  
  26. {
  27.     color_monitor   = NO;
  28.     default_palette = 8;
  29.     header_palette  = 9;
  30.     error_palette   = 9;
  31.     message_palette = 9;
  32.     backdrop_color  = 7;
  33.     footer_color    = 15;
  34. }
  35.  
  36. /***************************************************************************/
  37. void Get_Video_Info()
  38.  
  39. {
  40.     color_monitor   = YES;
  41.     default_palette = 0;
  42.     header_palette  = 1;
  43.     error_palette   = 2;
  44.     message_palette = 3;
  45.     backdrop_color  = 19;
  46.     footer_color    = 31;
  47.  
  48.       _asm mov ax, 1a00h
  49.      _asm int 10h
  50.     _asm cmp ah,1ah
  51.     _asm jne not_vga_or_mcga_or_ps
  52.         _asm and ah,01h
  53.         _asm je find_video_start
  54.             Monochrome_Defaults();
  55.             goto find_video_start;
  56.  
  57.     not_vga_or_mcga_or_ps:
  58.     _asm mov ah, 12h
  59.     _asm mov bl, 10h
  60.     _asm int 10h
  61.     _asm cmp bl,10h
  62.     _asm jne find_video_start
  63.         _asm cmp bh,01h
  64.         _asm jne find_video_start
  65.             Monochrome_Defaults();
  66.  
  67. find_video_start:
  68.     video_start = (int far * ) 0xb8000000;
  69.     _asm mov ax,0F00h;
  70.     _asm int 10h;
  71.     _asm cmp al,07h;
  72.     _asm jne find_video_dimensions
  73.         video_start = (int far * ) 0xb0000000;
  74.         Monochrome_Defaults();
  75.  
  76. find_video_dimensions:
  77.     max_screen_y = *((char far *) 0x00400084L);
  78.     max_screen_x = *((char far *) 0x0040004AL);
  79.     if (max_screen_y == 0){
  80.         max_screen_x = 80;
  81.         max_screen_y = 24;
  82.     }
  83. }
  84.  
  85. /***************************************************************************/
  86. void Display_Title_Screen()
  87.  
  88. {
  89.     Fill_Screen(' ',7);
  90.     if (first_run){
  91.         Put_Cursor(0,7);
  92.         puts("\t\t\tWelcome to DougMenu.   (c) Copyright 1991\n\n");
  93.         puts("This program is freeware product, and is to be distributed at no charge.\n\n");
  94.         puts("\t\tSee the file 'TERMS' for the terms of usage.");
  95.     }
  96. }
  97.  
  98. /***************************************************************************/
  99. void Set_Up_Enviroment()
  100.  
  101. /* this routine changes the enviroment var's as needed and gets the path
  102.   of the temporary batch file from there */
  103.  
  104. {
  105.     char temp_bat_ext[] = ".BAT";
  106.  
  107.     long int psp_segment;
  108.     long int env_segment;
  109.  
  110.     int far *ptr;
  111.     char far *cptr;
  112.  
  113.     byte i;
  114.  
  115.     _asm mov ax,6200h
  116.     _asm int 21h
  117.     _asm mov psp_segment,bx;
  118.  
  119.         /* go to the oldest enviroment space */
  120.  
  121.     while (ptr !=(ptr = (int far *) ((psp_segment << 16) + 0x16)));
  122.     psp_segment = *ptr;
  123.     ptr = (int far *) ((psp_segment << 16) + 0x2c);
  124.     env_segment = *ptr;
  125.     cptr = (char far *) (env_segment <<16);
  126.  
  127.         /* find proper entry */
  128.  
  129.     while ( *cptr != 0 || *(cptr+1) != 'T' || *(cptr+2) != '='){
  130.         if ( *cptr == 0 && *(cptr+1) ==0)
  131.             Critical_Error(ENVIROMENT,"Missing 'T' enviroment variable");
  132.         cptr++;
  133.     }
  134.     cptr +=3;
  135.  
  136.     temp_bat = cptr;
  137.  
  138.     while (*cptr != '\0')
  139.         cptr++;
  140.     cptr--;
  141.     if (*cptr != 'T') first_run = YES;
  142.     
  143.     cptr-=3;
  144.  
  145.     if ( *cptr != '.')
  146.         Critical_Error(ENVIROMENT,"Improper enviroment variable");
  147.  
  148.             /* fill in name at the end of the path */
  149.     for (i=3;i>0;i--)
  150.         *(cptr+i) = temp_bat_ext[i];
  151. }
  152.  
  153.  
  154. /***************************************************************************/
  155. void Set_Up_Mouse()
  156.  
  157. {
  158.     int max_x,max_y;    
  159.  
  160.     max_x = (max_screen_x -1 ) * 8;
  161.     max_y = max_screen_y * 8;
  162.  
  163.     _asm sub ax,ax           /* intitalize mouse */
  164.     _asm int 33h
  165.  
  166.     _asm mov dx,max_x    /* Pixels horizontally */
  167.     _asm mov ax,7        /* mouse driver function 7 -- set max x range */
  168.     _asm sub cx,cx       /* Minimum range */
  169.     _asm int 33h
  170.  
  171.     _asm mov dx,max_y    /* Pixels veritcally */
  172.     _asm mov ax,8        /* mouse driver function 8 -- set max y range */
  173.     _asm sub cx,cx       /* Minimum range */
  174.     _asm int 33h
  175.  
  176.     _asm mov ax,4        /* set current mouse position  0,0 */
  177.     _asm sub bx,bx            
  178.     _asm sub cx,cx            
  179.     _asm sub dx,dx
  180.     _asm int 33h
  181.  
  182.     Hide_Mouse();
  183. }
  184.  
  185. /***************************************************************************/
  186. void Draw_Backdrop(void)
  187.  
  188. {
  189.     FILE *Backdrop;
  190.     register char ch;
  191.  
  192.     Fill_Screen(backdrop_char,backdrop_color);
  193.  
  194.     if (backdrop_file[0] != '\0'){
  195.         if ( ( Backdrop = fopen(backdrop_file, "r" ) ) != NULL ){
  196.             ch = getc(Backdrop);
  197.             while ( ch != EOF)
  198.                 putchar( ch = getc(Backdrop) );
  199.               fclose(Backdrop);
  200.         }
  201.     }
  202. }
  203.  
  204. /***************************************************************************/
  205. void Draw_Header()
  206.  
  207. {
  208.     char title[] = "   DougMenu v1.0";
  209.     byte x;
  210.     byte back   = palette[header_palette][ BACK ] << 4;
  211.     byte text   = palette[header_palette][ TEXT ] | back;
  212.     byte border = palette[header_palette][ HIGHLIGHT ] | back;
  213.  
  214.         /* draw top */
  215.     x=0;
  216.     Draw(x, 0, '┌', border);
  217.     for (x++; x < (byte)(max_screen_x-1); x++)
  218.         Draw(x, 0, '─', border);
  219.     Draw(x, 0,'┐', border);
  220.  
  221.         /* draw filling */
  222.     x=0;
  223.     Draw(x++, 1, '│', border);
  224.     while (title[x] != '\0')
  225.         Draw(x++,1,title[x],text);
  226.     while (x< (byte)(max_screen_x-1) )    
  227.         Draw(x++, 1, ' ', text);
  228.     Draw(x, 1, '│', border);
  229.  
  230.         /* draw bottom */
  231.     x = 0;
  232.     Draw(x, 2, '└', border);
  233.     for(x++; x < (byte)(max_screen_x-1); x++)
  234.         Draw(x, 2, '─', border);
  235.     Draw(x, 2, '┘', border);
  236.  
  237.     Update_Time();
  238. }
  239.  
  240. /***************************************************************************/
  241. void Draw_Footer()
  242.  
  243. {
  244.     register byte x,i,ch;
  245.  
  246.     x=0;
  247.     for ( i=1; i < 11 ; i++){
  248.         if (function_key[i] != NULL){
  249.             Draw (x++,max_screen_y,' ',footer_color);    
  250.             Draw (x++,max_screen_y,'F',footer_color);    
  251.             if ( i == 10 ){
  252.                 Draw (x++,max_screen_y,'1',footer_color);    
  253.                 Draw (x++,max_screen_y,'0',footer_color);    
  254.             }
  255.             else
  256.                 Draw (x++,max_screen_y,(byte)(i+48),footer_color);    
  257.             Draw (x++,max_screen_y,'=',footer_color);    
  258.             Draw (x++,max_screen_y,' ',footer_color);    
  259.             ch =0;
  260.             while ( function_key[i]->title[ch] != '\0' )
  261.                 Draw (x++,max_screen_y,function_key[i]->title[ch++],footer_color);
  262.             function_key[i]->title_length = x;
  263.             Draw (x++,max_screen_y,' ',footer_color);
  264.         }
  265.     }
  266.     if (x > 0){
  267.         while (x < max_screen_x)
  268.             Draw (x++,max_screen_y,' ',footer_color);
  269.     }
  270. }
  271.  
  272. /***************************************************************************/
  273. void Set_Up_Screen()
  274.  
  275. {
  276.     char     temp_line[MAX_LINE];
  277.     register byte ch;
  278.     FILE     *Old_Bat;
  279.     char     old_bat[MAX_FILE_NAME];
  280.  
  281.     temp_line[0] = '\n';
  282.  
  283.     if (!first_run){
  284.             /* read enviroment variable */
  285.         for (ch=0; *(temp_bat+ch) != '\0';ch++)
  286.             old_bat[ch] = *(temp_bat+ch);
  287.         old_bat[ch]='\0';
  288.  
  289.         if ( ( Old_Bat = fopen(old_bat, "r" ) ) != NULL ){
  290.             while ( ch = getc(Old_Bat) != ':' && ch != EOF);
  291.                 if (ch != EOF)
  292.                     fscanf(Old_Bat,"%s\n",temp_line);
  293.               fclose(Old_Bat);   
  294.         }
  295.     }
  296.     remove(old_bat);
  297.  
  298.     Draw_Backdrop();
  299.     Draw_Header();
  300.     Draw_Footer();
  301.  
  302.     if (shadow){
  303.         shad_buf = (byte *) malloc ( max_screen_x + max_screen_y );
  304.     }
  305.  
  306.     win_index = 255;         /* we are now at the -1st menu */
  307.  
  308.     if (!Windowfy_Menu(first_menu))
  309.         Critical_Error(DISPLAY,NULL);
  310.  
  311.     if (temp_line[0] != '\n') for(;;){
  312.  
  313.         Win[win_index].item = current_item = Number_To_Item( (byte) (temp_line[(win_index*2)] - 64) );
  314.         Display_Menu(current_item);
  315.  
  316.         ch = temp_line[(win_index*2)+1];
  317.         if ( ch == DO_ITEM+64)
  318.             Win[win_index].event = DO_ITEM;
  319.         else if ( ch >= FUNCTION_KEY+64){
  320.             Win[win_index].event = ch - 64;
  321.             current_item = function_key[ch-FUNCTION_KEY-64];
  322.         }
  323.         else break;
  324.  
  325.         if( current_item->first_line->text_line[0] != '%' ||
  326.             !Windowfy_Menu( Find_Menu( current_item->first_line->text_line ) ) )
  327.             break;
  328.     }
  329.  
  330.     Display_Menu(NULL);
  331.      Select(current_item);
  332. }
  333.