home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / EDITOR / TDE120.ZIP / HWIND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-05  |  12.9 KB  |  448 lines

  1. /*******************  start of original comments  ********************/
  2. /*
  3.  * Written by Douglas Thomson (1989/1990)
  4.  *
  5.  * This source code is released into the public domain.
  6.  */
  7.  
  8. /*
  9.  * Name:    hardware independent screen IO module
  10.  * Purpose: This file contains the code to interface the rest of the
  11.  *           editor to the display and input hardware.
  12.  * File:    hwind.c
  13.  * Author:  Douglas Thomson
  14.  * System:  this file is intended to be system-independent
  15.  * Date:    October 2, 1989
  16.  * Notes:   This is the only module that is allowed to call the hardware
  17.  *           dependent display IO library.
  18.  *          Typically, functions here check whether any action is
  19.  *           necessary (for example, the cursor may already happen to be
  20.  *           in the required position), call hardware dependent functions
  21.  *           to achieve the required effect, and finally update status
  22.  *           information about the current state of the terminal display.
  23.  *          The idea behind this approach is to keep the hardware
  24.  *           dependent code as small and simple as possible, thus making
  25.  *           porting the code easier.
  26.  */
  27. /*********************  end of original comments   ********************/
  28.  
  29.  
  30. /*
  31.  * Some routines were added to display current editor modes in the lite bar
  32.  * at the bottom of the screen. Other routines were rewritten in assembly.
  33.  * I feel the need for speed.
  34.  *
  35.  * New editor name:  tde, the Thomson-Davis Editor.
  36.  * Author:           Frank Davis
  37.  * Date:             June 5, 1991
  38.  *
  39.  * This modification of Douglas Thomson's code is released into the
  40.  * public domain, Frank Davis.  You may distribute it freely.
  41.  */
  42.  
  43. #include <bios.h>
  44.  
  45. #include "tdestr.h"
  46. #include "common.h"
  47. #include "tdefunc.h"
  48.  
  49. /*
  50.  * Name:    xygoto
  51.  * Purpose: To move the cursor to the required column and line.
  52.  * Date:    September 28, 1991
  53.  * Passed:  col:    desired column (0 up to max)
  54.  *          line:   desired line (0 up to max)
  55.  */
  56. void xygoto( int col, int line )
  57. {
  58. union REGS inregs, outregs;
  59.  
  60.    inregs.h.ah = 2;
  61.    inregs.h.bh = 0;
  62.    inregs.h.dh = line;
  63.    inregs.h.dl = col;
  64.    int86( 0x10, &inregs, &outregs );
  65. }
  66.  
  67. /*
  68.  * Name:    save_screen_line
  69.  * Purpose: To save the characters and attributes of a line on screen.
  70.  * Date:    June 5, 1991
  71.  * Notes:   No need to redraw entire screen to show a prompt.  Just save
  72.  *          the contents of the line on screen where prompt is to be displayed
  73.  */
  74. void save_screen_line( int col, int line, char *screen_buffer )
  75. {
  76. char far *p;
  77.  
  78.    p = g_display.display_address + line * 160 + col * 2;
  79.    _fmemcpy( screen_buffer, p, 160 );
  80. }
  81.  
  82. /*
  83.  * Name:    restore_screen_line
  84.  * Purpose: To restore the characters and attributes of a line on screen.
  85.  * Date:    June 5, 1991
  86.  * Notes:   No need to redraw entire screen to show a prompt.  Just save
  87.  *          the contents of the line on screen where prompt is to be displayed
  88.  */
  89. void restore_screen_line( int col, int line, char *screen_buffer )
  90. {
  91. char far *p;
  92.  
  93.    p = g_display.display_address + line * 160 + col * 2;
  94.    _fmemcpy( p, screen_buffer, 160 );
  95. }
  96.  
  97. /*
  98.  * Name:    cls
  99.  * Purpose: clear screen
  100.  * Date:    June 5, 1991
  101.  * Notes:   Call the video BIOS routine to clear the screen.
  102.  */
  103. void cls( void )
  104. {
  105. int line;
  106.  
  107.    line = g_display.nlines+1;
  108.    _asm {
  109.         xor     ch, ch                  ; starting row in ch = 0
  110.         xor     cl, cl                  ; starting column in cl = 0
  111.         mov     ax, WORD PTR line       ; get ending row
  112.         mov     dh, al                  ; put it in dh
  113.         mov     dl, 79                  ; ending column in dl = 79
  114.         mov     bh, 7                   ; attribute in bh  = 7 (normal)
  115.         mov     al, 0                   ; get number of lines
  116.         mov     ah, 6                   ; get function number
  117.         push    bp                      ; some dos versions wipe out bp
  118.         int     0x10
  119.         pop     bp
  120.    }
  121. }
  122.  
  123. /*
  124.  * Name:    initialize
  125.  * Purpose: To initialize all the screen status info that is not hardware
  126.  *           dependent, and call the hardware initialization routine to
  127.  *           pick up the hardware dependent stuff.
  128.  * Date:    June 5, 1991
  129.  * Returns: [g_status and g_display]: all set up ready to go
  130.  * Notes:   It is assumed that g_status and g_display are all \0's to begin
  131.  *           with (the default if they use static storage). If this may
  132.  *           not be the case, then clear them explicitly here.
  133.  */
  134. void initialize( void )
  135. {
  136.    /*
  137.     * we do not know where the cursor is yet
  138.     */
  139.    g_display.col = -1;
  140.    g_display.line = -1;
  141.  
  142.    /*
  143.     * do the hardware initialization first, since this allocates the main
  144.     *  text buffer and sets up other info needed here later.
  145.     */
  146.    hw_initialize( );
  147.  
  148.    bm.search_defined = ERROR;
  149.    bm.search_case = IGNORE;
  150.    /*
  151.     * the main text buffer must be preceded by a ^Z, so that backward
  152.     *  searches can see the start of the text buffer
  153.     */
  154.    *g_status.start_mem++ = CONTROL_Z;
  155.  
  156.    /*
  157.     * most of the system's text pointers are safer set to the start
  158.     *  of the text buffer - some of these may not be strictly
  159.     *  necessary.
  160.     */
  161.    g_status.temp_end = g_status.start_mem;
  162.    g_status.end_mem = g_status.start_mem;
  163.  
  164.    /*
  165.     * set the default modes - may want to read this from a file later
  166.     */
  167.    g_status.marked = FALSE;
  168.    g_status.marked_file = NULL;
  169.  
  170.    g_status.current_window = NULL;
  171.    g_status.current_file = NULL;
  172.    g_status.window_list = NULL;
  173.    g_status.file_list = NULL;
  174.    g_status.window_count = 0;
  175.    g_status.file_count = 0;
  176.    g_status.undo_head  = -1;
  177.    g_status.next_file_number = 1;
  178.  
  179.    /*
  180.     * set the number of lines from one page that should still be visible
  181.     *  on the next page after page up or page down.
  182.     */
  183.    g_status.overlap = 1;
  184.  
  185.    /*
  186.     * clear the screen and show the author's names
  187.     */
  188.    cls( );
  189.    show_credits( );
  190. }
  191.  
  192.  
  193. /*
  194.  * Name:    show_modes
  195.  * Purpose: show current editor modes in lite bar at bottom of screen
  196.  * Date:    June 5, 1991
  197.  */
  198. void show_modes( void )
  199. {
  200. char status_line[MAX_COLS+2];
  201. register int color;
  202.  
  203.    color = g_display.mode_color;
  204.    memset( status_line, ' ', MAX_COLS );
  205.    status_line[MAX_COLS] = '\0';
  206.    s_output( status_line, g_display.mode_line, 0, color );
  207.    s_output( "F =    W = ", g_display.mode_line, 1, color );
  208.    s_output( "memory = ", g_display.mode_line, 16, color );
  209.    show_window_count( g_status.window_count );
  210.    show_file_count( g_status.file_count );
  211.    show_avail_mem( );
  212.    show_indent_mode( );
  213.    show_insert_mode( );
  214.    show_search_case( );
  215.    show_sdelete_mode( );
  216. }
  217.  
  218.  
  219. /*
  220.  * Name:    show_file_count
  221.  * Purpose: show number of open files in lite bar at bottom of screen
  222.  * Date:    June 5, 1991
  223.  */
  224. void show_file_count( int fc )
  225. {
  226. char status_line[MAX_COLS+2];
  227. int mode_line, mode_color;
  228.  
  229.    mode_line = g_display.mode_line;
  230.    mode_color = g_display.mode_color;
  231.    s_output( "  ", mode_line, 5, mode_color );
  232.    s_output( itoa( fc, status_line, 10 ), mode_line, 5, mode_color );
  233. }
  234.  
  235.  
  236. /*
  237.  * Name:    show_window_count
  238.  * Purpose: show total number of windows in lite bar at bottom of screen
  239.  * Date:    September 13, 1991
  240.  */
  241. void show_window_count( int wc )
  242. {
  243. char status_line[MAX_COLS+2];
  244. int mode_line, mode_color;
  245.  
  246.    mode_line = g_display.mode_line;
  247.    mode_color = g_display.mode_color;
  248.    s_output( "  ", mode_line, 12, mode_color );
  249.    s_output( itoa( wc, status_line, 10 ), mode_line, 12, mode_color );
  250. }
  251.  
  252.  
  253. /*
  254.  * Name:    show_avail_mem
  255.  * Purpose: show available free memory in lite bar at bottom of screen
  256.  * Date:    June 5, 1991
  257.  */
  258. void show_avail_mem( void )
  259. {
  260. char memory[MAX_COLS+2];
  261. int mode_line, mode_color;
  262. unsigned long avail;
  263.  
  264.    avail = ptoul( g_status.max_mem ) - ptoul( g_status.end_mem );
  265.    ultoa( avail, memory, 10 );
  266.    mode_line = g_display.mode_line;
  267.    mode_color = g_display.mode_color;
  268.    s_output( "        ", mode_line, 25, mode_color );
  269.    s_output( memory, mode_line, 25, mode_color );
  270. }
  271.  
  272.  
  273. /*
  274.  * Name:    show_indent_mode
  275.  * Purpose: show indent mode in lite bar at bottom of screen
  276.  * Date:    June 5, 1991
  277.  */
  278. void show_indent_mode( void )
  279. {
  280. register char *p;
  281. char *indent = "Indent";
  282. char *blank  = "      ";
  283.  
  284.    if (mode.indent)
  285.       p = indent;
  286.    else
  287.       p = blank;
  288.    s_output( p, g_display.mode_line, 35, g_display.mode_color );
  289. }
  290.  
  291.  
  292. /*
  293.  * Name:    show_insert_mode
  294.  * Purpose: show insert mode in lite bar at bottom of screen
  295.  * Date:    June 5, 1991
  296.  */
  297. void show_insert_mode( void )
  298. {
  299. int c;
  300.  
  301.    c = (mode.insert == TRUE) ? 'i' : 'o';
  302.    c_output( c, 78, g_display.mode_line, g_display.mode_color );
  303. }
  304.  
  305.  
  306. /*
  307.  * Name:    show_search_case
  308.  * Purpose: indicate whether to ignore or match case on search strings
  309.  * Date:    June 5, 1991
  310.  */
  311. void show_search_case( void )
  312. {
  313. char *p;
  314. char *ignore = "Ignore";
  315. char *match  = "Match ";
  316.  
  317.    if (bm.search_case == IGNORE)
  318.       p = ignore;
  319.    else
  320.       p = match;
  321.    s_output( p, g_display.mode_line, 45, g_display.mode_color );
  322. }
  323.  
  324.  
  325. /*
  326.  * Name:    show_sdelete_mode
  327.  * Purpose: indicate whether to stream delete with the delete key
  328.  * Date:    June 5, 1991
  329.  */
  330. void show_sdelete_mode( void )
  331. {
  332. char *p;
  333. char *sdel = "Sdel";
  334. char *ndel = "    ";
  335.  
  336.    if (mode.sdel == TRUE)
  337.       p = sdel;
  338.    else
  339.       p = ndel;
  340.    s_output( p, g_display.mode_line, 55, g_display.mode_color );
  341. }
  342.  
  343.  
  344. /*
  345.  * Name:    window_scroll_up
  346.  * Purpose: To scroll all the lines between top and bottom up one line.
  347.  * Date:    June 5, 1991
  348.  * Passed:  top:    top line to be scrolled
  349.  *          bottom: bottom line to be scrolled
  350.  * Notes:   Call the video BIOS routine to scroll window up.
  351.  */
  352. void window_scroll_up( int top, int bottom )
  353. {
  354. int attr;
  355.  
  356.    attr = g_display.text_color;
  357.    _asm {
  358.         mov     bx, WORD PTR attr
  359.         mov     bh, bl                  ; put attribute in bh
  360.         mov     ax, WORD PTR top        ; get starting row
  361.         mov     ch, al                  ; put it in ch
  362.         xor     cl, cl                  ; starting column in cl = 0
  363.         mov     ax, WORD PTR bottom     ; get ending row
  364.         mov     dh, al                  ; put it in dh
  365.         mov     dl, 79                  ; ending column in dl = 79
  366.         mov     al, 1                   ; get number of lines
  367.         mov     ah, 6                   ; get function number
  368.         push    bp
  369.         int     0x10
  370.         pop     bp
  371.    }
  372. }
  373.  
  374. /*
  375.  * Name:    window_scroll_down
  376.  * Purpose: To scroll all the lines between top and bottom down one line.
  377.  * Date:    June 5, 1991
  378.  * Passed:  top:    top line to be scrolled
  379.  *          bottom: bottom line to be scrolled
  380.  * Notes:   Call the video BIOS routine to scroll window down.
  381.  */
  382. void window_scroll_down( int top, int bottom )
  383. {
  384. int attr;
  385.  
  386.    attr = g_display.text_color;
  387.    _asm {
  388.         mov     bx, WORD PTR attr
  389.         mov     bh, bl                  ; put attribute in bh
  390.         mov     ax, WORD PTR top        ; get starting row
  391.         mov     ch, al                  ; put it in ch
  392.         xor     cl, cl                  ; put starting column in cl - 0
  393.         mov     ax, WORD PTR bottom     ; get ending row
  394.         mov     dh, al                  ; put it in dh
  395.         mov     dl, 79                  ; put ending column in dl
  396.         mov     ah, 7                   ; get function number
  397.         mov     al, 1                   ; get number of lines
  398.         push    bp
  399.         int     0x10
  400.         pop     bp
  401.    }
  402. }
  403.  
  404. /*
  405.  * Name:    window_scroll_up_eof
  406.  * Purpose: To scroll all the lines between top and bottom up one line with
  407.  *          the bottom lines having the 0x07 attribute.
  408.  * Date:    June 5, 1991
  409.  * Passed:  top:    top line to be scrolled
  410.  *          bottom: bottom line to be scrolled
  411.  * Notes:   Call the video BIOS routine to scroll window up.
  412.  */
  413. void window_scroll_up_eof( int top, int bottom )
  414. {
  415.  
  416.    _asm {
  417.         mov     bh, 7                   ; put attribute in bh
  418.         mov     ax, WORD PTR top        ; get starting row
  419.         mov     ch, al                  ; put it in ch
  420.         xor     cl, cl                  ; starting column in cl = 0
  421.         mov     ax, WORD PTR bottom     ; get ending row
  422.         mov     dh, al                  ; put it in dh
  423.         mov     dl, 79                  ; ending column in dl = 79
  424.         mov     al, 1                   ; get number of lines
  425.         mov     ah, 6                   ; get function number
  426.         push    bp
  427.         int     0x10
  428.         pop     bp
  429.    }
  430. }
  431.  
  432.  
  433. /*
  434.  * Name:    combine_strings
  435.  * Purpose: stick 3 strings together
  436.  * Date:    June 5, 1991
  437.  * Passed:  buff:    buffer to hold concatenation of 3 strings
  438.  *          s1:  pointer to string 1
  439.  *          s2:  pointer to string 2
  440.  *          s3:  pointer to string 3
  441.  */
  442. void combine_strings( char *buff, char *s1, char *s2, char *s3 )
  443. {
  444.    strcpy( buff, s1 );
  445.    strcat( buff, s2 );
  446.    strcat( buff, s3 );
  447. }
  448.