home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR21 / DOUGM.ZIP / DM168SRC.ZIP / MISC.C < prev    next >
Text File  |  1992-08-17  |  11KB  |  467 lines

  1. void Break_Off(void)
  2.  
  3. {
  4.     freopen("NUL:","w",stdout);
  5.         /* capture stdout to stop ^c from apearing */
  6.  
  7.     _asm push    ds
  8.     _asm push    cs
  9.     _asm pop    ds
  10.     _asm mov    dx, offset Int_23h_Handler
  11.     _asm mov    ah,25h  ; DOS Function 25 - set interrupt vector
  12.     _asm mov    al,23h  ; change interrupt 23H
  13.     _asm int    21h
  14.     _asm pop    ds
  15.     return;
  16.  
  17.     Int_23h_Handler:
  18.     _asm iret
  19.  
  20.     /* dos will reset this interrupt after any executable terminates
  21.         so this does not have to be reset by this program */   
  22. }
  23.  
  24. /**************************************************************************/
  25. long int Disk_Space_Check( drive )
  26.  
  27. byte drive;
  28.  
  29. {
  30.     int hold_seg,hold_off;
  31.     int a=0,b=0,c=0;
  32.  
  33.     _asm push    ds
  34.     _asm mov    ah,35h  ; DOS Function 35 - get interrupt vector
  35.     _asm mov    al,24h  ; Read interrupt 24H
  36.     _asm int    21h
  37.     _asm mov    hold_off,ds
  38.     _asm mov    hold_seg,dx
  39.  
  40.     _asm pop    ds
  41.     _asm mov    dx, offset Int_24h_Handler
  42.     _asm push    ds
  43.     _asm push    cs
  44.     _asm pop    ds
  45.     _asm mov    ah,25h  ; DOS Function 25 - set interrupt vector
  46.     _asm mov    al,24h  ; Change interrupt 24H
  47.     _asm int    21h
  48.     _asm pop    ds
  49.  
  50.         /* find disk space */
  51.     _asm   mov  ah,36h
  52.     _asm   mov  dl,drive
  53.     _asm   int  21h
  54.     _asm   mov  a,ax
  55.     _asm   mov  b,bx
  56.     _asm   mov  c,cx
  57.  
  58.         /* restore critical interrupt */ 
  59.     _asm push    ds
  60.     _asm mov    dx, hold_seg
  61.     _asm mov    ds, hold_off
  62.     _asm mov    ah,25h  ; DOS Function 25 - set interrupt vector
  63.     _asm mov    al,24h  ; Change interrupt 24H
  64.     _asm int    21h
  65.     _asm pop    ds
  66.  
  67.         /* check for success */
  68.     if ( a == -1 )
  69.         return( -1 );
  70.     return( (long)a*b*c );
  71.  
  72.     Int_24h_Handler:
  73.     _asm mov al,3
  74.     _asm iret
  75. }
  76.  
  77. /***************************************************************************/
  78. void Error_Box(line1,line2)
  79.  
  80. char line1[],line2[];
  81.  
  82. {
  83.     char title[] = "Error - Error - Error - Error";
  84.     char foot[] = "Press any key to continue.";
  85.     char blank[] = " ";
  86.     char *lines[7];    
  87.  
  88.     lines[0] = title;
  89.     lines[1] = blank;
  90.     lines[2] = line1;
  91.     lines[3] = line2;
  92.     lines[4] = blank;
  93.     lines[5] = foot;
  94.     lines[6] = NULL;
  95.  
  96.     Display_Text_Box(lines,CENTER,CENTER,error_palette);
  97.     Pause_Until_Serious_Action();
  98.     Remove_Window();
  99. }
  100.  
  101. /***************************************************************************/
  102. void Critical_Error(error)
  103.  
  104. error_type error;
  105.  
  106. {
  107.     Clean_Up();
  108.     if (current_file != NULL){
  109.         fprintf(stderr,"file- %s\n",current_file);
  110.         if (line_count)
  111.             fprintf(stderr,"line- %u\n",line_count);
  112.     }
  113.     switch(error){
  114.         case SYNTAX:
  115.             fputs("Syntax Error.",stderr);
  116.             break;
  117.         case VALUE:
  118.             fputs("Illegal or Missing Value.",stderr);
  119.             break;
  120.         case POSITION:
  121.             fputs("Unexpected menu structure.",stderr);
  122.             break;
  123.         case MEMORY:
  124.             fputs("Memory allocation error.",stderr);
  125.             break;
  126.         case FILE_OPEN:
  127.             fputs("Unable to open file.",stderr);
  128.             break;
  129.         case DISPLAY:
  130.             fputs("Unable to display menu script.",stderr);
  131.             break;
  132.         case ENVIROMENT:
  133.             fputs("Improper 't' enviroment variable",stderr);
  134.             break;
  135.     }
  136.     fputc('\n',stderr);
  137.     exit(LEAVE_MENU);
  138. }
  139.  
  140. /**************************************************************************/
  141. boolean Get_DM_Var( place, temp, space )
  142.  
  143. char *place, *temp;
  144. byte space;
  145.  
  146. {
  147.     byte i = 0;
  148.     
  149.     for (i=0;i<var_number;i++){
  150.         if (Compare(place,vars[i].name)){
  151.             strncpy(temp,vars[i].value,space);
  152.             return(YES);
  153.         }
  154.     }
  155.     return(NO);
  156. }
  157.  
  158. /**************************************************************************/
  159. void Transcribe_String(old,new)
  160.  
  161. char *old,*new;
  162.  
  163. {
  164.     byte space = MAX_LINE;
  165.  
  166.     *new = '\0';
  167.  
  168.     for (;;){
  169.             /* check for variables */
  170.         while (*old == '%'){
  171.             if ( !Get_DM_Var(old,new,space)){
  172.                 Find_Env_Var(old,new,space);
  173.                 if (*new == VAR_NOT_FOUND){
  174.                     break;    /* leave the while loop if it's not a variable */
  175.                 }
  176.             }
  177.  
  178.       /* move past variable */
  179.             while (*new != '\0'){
  180.                 space--;
  181.                 new++;
  182.             }
  183.  
  184.             old++;
  185.             while (*old != '%'){
  186.                 old++;
  187.             }
  188.             old++;
  189.  
  190.             if (!space)  /* stop if no room left in allocated space */
  191.                 return;
  192.         }
  193.  
  194.         if (*old == '\0' || !(--space) ){
  195.             *new = '\0';
  196.             return;
  197.         }
  198.         *new = *old;
  199.         new++;
  200.         old++;
  201.     }
  202. }
  203.  
  204. /***************************************************************************/
  205. boolean Fcompare( string1,string2 )
  206.  
  207. char *string1, far *string2;
  208.  
  209. {
  210.         /* skip first '%' */
  211.     string1++;
  212.  
  213.     while (*string2 != '='){
  214.         if( (*string1++ | 32) != (*string2++ | 32) )
  215.             return(NO);
  216.     }
  217.         /* does it have a closing '%' ? */
  218.     if (*string1 == '%')
  219.         return(YES);
  220.     return(NO);
  221. }
  222.  
  223. /***************************************************************************/
  224. void Find_Env_Var( var, string, space )
  225.  
  226. char *var, *string;
  227. byte space;
  228.  
  229. {
  230.     char far *cptr = env_start;
  231.  
  232.     while (!Fcompare(var,cptr)){
  233.         while (*cptr != '\0')
  234.             cptr++;
  235.         if (*(++cptr) == '\0'){
  236.             *string = VAR_NOT_FOUND;
  237.             return;
  238.         }
  239.     }
  240.     while (*cptr++ != '=');
  241.     
  242.     while (*cptr != '\0'){
  243.         *string++ = *cptr++;
  244.         if (--space == 0)
  245.             break;
  246.     }
  247.     *string  = '\0';
  248.     return;
  249. }
  250.  
  251. /****************************************************************************/
  252. void Monochrome_Defaults()
  253.  
  254. {
  255.     color_monitor    = NO;
  256.     default_palette  = 8;
  257.     header_palette   = 9;
  258.     error_palette    = 9;
  259.     message_palette  = 9;
  260.     backdrop_color   = 7;
  261.     footer_color     = 15;
  262.     footer_highlight = 4;
  263. }
  264.  
  265. /***************************************************************************/
  266. void Get_Video_Info( parameter )
  267.  
  268. char *parameter;
  269.  
  270. {
  271.     // color defaults
  272.     color_monitor    = YES;
  273.     video_start = (int far * ) 0xb8000000;
  274.     default_palette  = 0;
  275.     header_palette   = 1;
  276.     error_palette    = 2;
  277.     message_palette  = 3;
  278.     backdrop_color   = 19;
  279.     footer_color     = 31;
  280.     footer_highlight = 113;
  281.  
  282.     // put the screen to the 0 video page of whatever mode we are in.
  283.     _asm mov ax, 0500h
  284.     _asm int 10h
  285.  
  286.     // now let's find out what video mode we are in.
  287.     _asm mov ax, 0F00h
  288.     _asm int 10h
  289.     _asm mov video_mode,al;
  290.     if (video_mode >= 7){
  291.         // monochrome defaults
  292.         video_start = (int far * ) 0xb0000000;
  293.         color_monitor    = NO;
  294.         default_palette  = 8;
  295.         header_palette   = 9;
  296.         error_palette    = 9;
  297.         message_palette  = 9;
  298.         backdrop_color   = 7;
  299.         footer_color     = 15;
  300.         footer_highlight = 4;
  301.     }
  302.  
  303.     // now determine the screen size
  304.     max_screen_y = *((char far *) 0x00400084L);
  305.     max_screen_x = *((char far *) 0x0040004AL);
  306.     if (max_screen_y == 0){
  307.         max_screen_x = 80;
  308.         max_screen_y = 24;
  309.     }
  310.  
  311.     // now record the cursor shape
  312.     _asm mov ah,03   
  313.     _asm mov bh,00    ;look in page 0
  314.     _asm int 10h
  315.     _asm mov cursor_top,ch
  316.     _asm mov cursor_bottom,cl
  317. }
  318.  
  319. /***************************************************************************/
  320. void Set_Up_Enviroment()
  321.  
  322. /* this routine changes the enviroment var's as needed and gets the path
  323.   of the temporary batch file from there */
  324.  
  325. {
  326.     long int psp_segment;
  327.     long int env_segment;
  328.  
  329.     int far *ptr;
  330.     char far *cptr;
  331.  
  332.     _asm mov ax,6200h
  333.     _asm int 21h
  334.     _asm mov psp_segment,bx;
  335.  
  336.         /* go to the oldest enviroment space */
  337.  
  338.     while (ptr !=(ptr = (int far *) ((psp_segment << 16) + 0x16)));
  339.     psp_segment = *ptr;
  340.     ptr = (int far *) ((psp_segment << 16) + 0x2c);
  341.     env_segment = *ptr;
  342.     cptr = env_start = (char far *) (env_segment <<16);
  343.  
  344.     while (!Fcompare( "%t%", cptr )){
  345.         while (*cptr != '\0')
  346.             cptr++;
  347.         if (*(++cptr) == '\0'){
  348.             Critical_Error(ENVIROMENT);
  349.         }
  350.     }
  351.  
  352.     while (*cptr != '\0')
  353.         cptr++;
  354.     cptr--;
  355.  
  356.     if (*(cptr-3) != '.')
  357.         Critical_Error(ENVIROMENT);
  358.     if (*cptr == 'T') 
  359.         first_run = NO;
  360.  
  361.     else{
  362.         first_run = YES;
  363.         *cptr-- = 'T';
  364.         *cptr-- = 'A';
  365.         *cptr = 'B';
  366.    }
  367. }
  368.  
  369. /***************************************************************************/
  370. void Set_Up_Mouse()
  371.  
  372. {
  373.     int max_x,max_y;    
  374.  
  375.     max_x = (max_screen_x -1 ) * 8;
  376.     max_y = max_screen_y * 8;
  377.  
  378.     _asm sub ax,ax           /* intitalize mouse */
  379.     _asm int 33h
  380.  
  381.     _asm mov dx,max_x    /* Pixels horizontally */
  382.     _asm mov ax,7        /* mouse driver function 7 -- set max x range */
  383.     _asm sub cx,cx       /* Minimum range */
  384.     _asm int 33h
  385.  
  386.     _asm mov dx,max_y    /* Pixels veritcally */
  387.     _asm mov ax,8        /* mouse driver function 8 -- set max y range */
  388.     _asm sub cx,cx       /* Minimum range */
  389.     _asm int 33h
  390.  
  391.     _asm mov ax,4        /* set current mouse position  0,0 */
  392.     _asm sub bx,bx            
  393.     _asm sub cx,cx            
  394.     _asm sub dx,dx
  395.     _asm int 33h
  396.  
  397.     Hide_Mouse();
  398. }
  399.  
  400. /***************************************************************************/
  401. void Set_Up_Screen()
  402.  
  403. {
  404.     char    ch;
  405.     char     old_bat[MAX_FILE_NAME];
  406.     FILE   *Old_Bat;
  407.  
  408.     Hide_Cursor();
  409.     Draw_Backdrop();
  410.     Draw_Header();
  411.     Draw_Footer();
  412.     Draw_Back_Boxes();
  413.  
  414.     win_index = 255;         /* we are now at the -1st menu */
  415.  
  416.                              /* this sets win[].item */
  417.     if (!Windowfy_Menu(first_menu))
  418.         Critical_Error(DISPLAY);
  419.  
  420.     if ( !first_run ){
  421.         Find_Env_Var("%t%",old_bat,MAX_LINE);
  422.         if ( ( Old_Bat = fopen(old_bat, "r" ) ) != NULL ){
  423.             if ( do_return ){
  424.                     /* advance to the pertinent information */
  425.                 while ( ch = fgetc(Old_Bat) != ':' )
  426.                     if ( ch == '\n' || ch == EOF)
  427.                         break;
  428.                 for (;;){
  429.                        // get item number
  430.                     ch = (char) (fgetc(Old_Bat) - 64);
  431.                     current_item = Number_To_Item( (byte)ch );
  432.                     if (current_item->first_line == NULL)
  433.                         break;
  434.                     Win[win_index].item = current_item;
  435.                     Display_Menu(current_item);
  436.  
  437.                        // do it if possible
  438.                     ch = (char) (fgetc(Old_Bat) - 64);
  439.                        // now 42, that's a magic number */
  440.                     if ( (byte)ch > SPECIAL+30 )
  441.                         break;
  442.                     Win[win_index].event = (byte)ch;
  443.                     if ( ch != DO_ITEM)
  444.                         current_item = special_item[ch-SPECIAL];
  445.                     if ( current_item == NULL )
  446.                         break;
  447.                     if ( !Windowfy_Menu( Find_Menu( current_item->first_line ) ) )
  448.                         break;
  449.                 }
  450.             }
  451.             fclose(Old_Bat);   
  452.             remove(old_bat);
  453.         }
  454.     }
  455.  
  456.         /* start doing shadows now */
  457.         /* allocate the shadow buffer if necessary */
  458.     if (shadow = draw_shadow){
  459.         shad_buf = (byte *) malloc ( max_screen_x + max_screen_y );
  460.     }
  461.  
  462.         /*make sure that the current item is proper */
  463.     current_item = Win[win_index].item;
  464.     Display_Menu(NULL);
  465.      Select(current_item);
  466. }
  467.