home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / editors / tde150.arj / CRITERR.C < prev    next >
C/C++ Source or Header  |  1992-04-01  |  8KB  |  218 lines

  1. /*
  2.  * Instead of the Abort, Retry, Ignore thing, let's try to handle critical
  3.  * errors within tde.  Give the user some indication of the critical error
  4.  * and then find out what the user wants to do.
  5.  *
  6.  * This is a very simple critical error handler.  It's not much better than
  7.  * Abort, Retry, Ignore, but at least the program will probably not terminate
  8.  * with unsaved work.
  9.  *
  10.  * IMPORTANT:  This is a replacement for the standard DOS critical error
  11.  * handler.  Since DOS is not re-entrant, do not call any functions that,
  12.  * directly or indirectly, call DOS functions.  We are in some DOS function
  13.  * when a critical error occurs.  Using BIOS and direct hardware I/O
  14.  * functions, however, is allowed.
  15.  *
  16.  * New editor name:  tde, the Thomson-Davis Editor.
  17.  * Author:           Frank Davis
  18.  * Date:             June 5, 1991, version 1.0
  19.  * Date:             July 29, 1991, version 1.1
  20.  * Date:             October 5, 1991, version 1.2
  21.  * Date:             January 20, 1992, version 1.3
  22.  * Date:             February 17, 1992, version 1.4
  23.  * Date:             April 1, 1992, version 1.5
  24.  *
  25.  * This code is released into the public domain, Frank Davis.
  26.  *    You may distribute it freely.
  27.  */
  28.  
  29. #include "tdestr.h"
  30. #include "common.h"
  31. #include "tdefunc.h"
  32. #include "criterr.h"
  33.  
  34. /*
  35.  * Save the area of the screen that will display the Critical
  36.  * Error info.  CEH_WIDTH and CEH_HEIGHT are the dimensions of critical
  37.  * error screen in criterr.h.   CEH_OFFSET is the offset into the screen
  38.  * refresh buffer.  Let the compiler calculate the offset, 'cause the offset
  39.  * don't change anyway.
  40.  */
  41. #define CEH_ROW         5
  42. #define CEH_COL         6
  43. #define CEH_WIDTH       69
  44. #define CEH_HEIGHT      15
  45. #define CEH_OFFSET      ((CEH_ROW * 160) + (CEH_COL * 2))
  46.  
  47.  
  48. /*
  49.  * buffer for ceh info screen.  make this an int array because we
  50.  * need to save character and attribute.
  51.  */
  52. int ceh_buffer[CEH_HEIGHT][CEH_WIDTH];
  53.  
  54.  
  55. /*
  56.  * Name:    crit_err_handler
  57.  * Purpose: Show user something is wrong and get a response
  58.  * Date:    April 1, 1992
  59.  */
  60. int  far crit_err_handler( void )
  61. {
  62. int rc;
  63. int c;
  64.  
  65.    save_area( (void far *)ceh_buffer );
  66.    show_error_screen( CEH_ROW, CEH_COL );
  67.    xygoto( 60, 17 );
  68.    c = getkey( );
  69.    while (c != 'Q' && c != 'q' && c != 'R' && c != 'r')
  70.       c = getkey( );
  71.    switch ( c ) {
  72.       case 'Q':
  73.       case 'q':
  74.          rc = FAIL;
  75.          break;
  76.       case 'R':
  77.       case 'r':
  78.          rc = RETRY;
  79.          break;
  80.    }
  81.    restore_area( (void far *)ceh_buffer );
  82.    return( rc );
  83. }
  84.  
  85.  
  86. /*
  87.  * Name:    show_error_screen
  88.  * Purpose: Display error screen in window
  89.  * Date:    April 1, 1992
  90.  * Passed:  row: line to display ceh screen
  91.  *          col: column to begin display ceh screen
  92.  */
  93. void show_error_screen( int row, int col )
  94. {
  95. char **p;
  96.  
  97.    for (p=criterr_screen; *p != NULL; p++, row++)
  98.       s_output( *p, row, col, g_display.help_color );
  99.    s_output( error_code[ceh.code],    8, 23, g_display.help_color );
  100.    s_output( operation[ceh.rw],       9, 23, g_display.help_color );
  101.    if (ceh.dattr == 0)
  102.       c_output( ceh.drive + 'a',     23, 10, g_display.help_color );
  103.    else
  104.       s_output( "N/A",               10, 23, g_display.help_color );
  105.    s_output( ext_err[ceh.extended],  11, 23, g_display.help_color );
  106.    s_output( error_class[ceh.class], 12, 23, g_display.help_color );
  107.    s_output( locus[ceh.locus],       13, 23, g_display.help_color );
  108.    s_output( device_type[ceh.dattr], 14, 23, g_display.help_color );
  109.    if (ceh.dattr == 0)
  110.       s_output( "N/A",               15, 23, g_display.help_color );
  111.    else
  112.       s_output( ceh.dname,           15, 23, g_display.help_color );
  113. }
  114.  
  115.  
  116. /*
  117.  * Name:    save_area
  118.  * Purpose: save a region of the screen
  119.  * Date:    April 1, 1992
  120.  * Passed:  dest: pointer to buffer for contents of screen under ceh
  121.  * Notes:   use an assembly routine to save the area.  we could have used
  122.  *          a C library function instead of assembly, but the "rep movsw"
  123.  *          instruction is really easy to use.  this function does not check
  124.  *          for snow.  the source is the screen and the destination is the
  125.  *          buffer.
  126.  */
  127. void save_area( void far *dest )
  128. {
  129. void far *source;
  130.  
  131.    /*
  132.     * put the address of the display adapter in a local stack variable.
  133.     */
  134.    source = (void far *)g_display.display_address;
  135.    _asm {
  136.         push    ds                      ; save ds and any register vars
  137.         push    si
  138.         push    di
  139.  
  140.         mov     dx, CEH_HEIGHT          ; save height in dx (num of rows)
  141.  
  142.         mov     di, WORD PTR dest       ; load OFFSET of destination
  143.         mov     ax, WORD PTR dest+2     ; load SEGMENT of destination
  144.         mov     es, ax                  ; es:di == destination
  145.         mov     si, WORD PTR source     ; load OFFSET of source
  146.         mov     ax, WORD PTR source+2   ; load SEGMENT of source
  147.         mov     ds, ax                  ; ds:si == source
  148.         add     si, CEH_OFFSET          ; add offset into display screen
  149.         ALIGN   2
  150. top:
  151.         cmp     dx, 0           ; any more rows left?
  152.         jbe     getout          ; if not, we're done
  153.  
  154.         mov     cx, CEH_WIDTH   ; load count register
  155.         mov     bx, si          ; save videomem location
  156.         rep     movsw           ; copy from screen area to buffer
  157.         mov     si, bx          ; get back videomem location
  158.         add     si, 160         ; make videomem point to next line
  159.         dec     dx              ; ready for another row
  160.         jmp     SHORT top
  161. getout:
  162.         pop     di
  163.         pop     si
  164.         pop     ds
  165.    }
  166. }
  167.  
  168.  
  169. /*
  170.  * Name:    restore_area
  171.  * Purpose: restore a region of the screen
  172.  * Date:    April 1, 1992
  173.  * Passed:  source: pointer to buffer for contents of screen under ceh
  174.  * Notes:   use an assembly routine to restore the area.  this function
  175.  *          does not check for snow.  the source is the buffer and
  176.  *          the destination is the screen.
  177.  */
  178. void restore_area( void far *source )
  179. {
  180. void far *dest;
  181.  
  182.    /*
  183.     * put the address of the display adapter in a local stack variable.
  184.     */
  185.    dest = (void far *)g_display.display_address;
  186.    _asm {
  187.         push    ds                      ; save ds and any register vars
  188.         push    si
  189.         push    di
  190.  
  191.         mov     dx, CEH_HEIGHT          ; save height in dx (num of rows)
  192.  
  193.         mov     di, WORD PTR dest       ; load OFFSET of destination
  194.         mov     ax, WORD PTR dest+2     ; load SEGMENT of destination
  195.         mov     es, ax                  ; es:di == destination
  196.         add     di, CEH_OFFSET          ; add offset into display screen
  197.         mov     si, WORD PTR source     ; load OFFSET of source
  198.         mov     ax, WORD PTR source+2   ; load SEGMENT of source
  199.         mov     ds, ax                  ; ds:si == source
  200.         ALIGN   2
  201. top:
  202.         cmp     dx, 0           ; any more rows left?
  203.         jbe     getout          ; if not, we're done
  204.  
  205.         mov     cx, CEH_WIDTH   ; load count register, number of words
  206.         mov     bx, di          ; save videomem location
  207.         rep     movsw           ; copy from buffer to screen area
  208.         mov     di, bx          ; get back videomem location
  209.         add     di, 160         ; make videomem point to next line
  210.         dec     dx              ; ready for another row
  211.         jmp     SHORT top
  212. getout:
  213.         pop     di
  214.         pop     si
  215.         pop     ds
  216.    }
  217. }
  218.