1 /* ********************************************
  2    *                                          *
  3    * Copyright, (C) Honeywell Bull Inc., 1988 *
  4    *                                          *
  5    ******************************************** */
  6 
  7 /* HISTORY COMMENTS:
  8   1) change(88-06-13,Lee), approve(88-05-16,MCR7897), audit(88-09-19,Flegel),
  9      install(88-10-12,MR12.2-1160):
 10      Created.
 11   2) change(88-07-25,Lee), approve(88-05-16,MCR7897), audit(88-09-19,Flegel),
 12      install(88-10-12,MR12.2-1160):
 13      Documentation additions only. Added header comments to all routines.
 14   3) change(88-08-09,Lee), approve(88-05-16,MCR7897), audit(88-09-19,Flegel),
 15      install(88-10-12,MR12.2-1160):
 16      Fix references to include files; "wstdefs.h" was split into
 17      "wstdefs.h" and "wsttype.h" to avoid declaration clash; also,
 18      various constants defined to descriptive names.
 19   4) change(89-01-18,Lee), approve(89-01-02,MCR8043), audit(89-03-14,Flegel),
 20      install(89-04-24,MR12.3-1033):
 21      Separated input and output parameters to int86() to avoid confusion
 22      when parameters are used.
 23                                                    END HISTORY COMMENTS */
 24 
 25 #include <dos.h>
 26 #include "wstdefs.h"
 27 #include "wstglob.h"
 28 
 29 /*^L
 30 **********************************************************************
 31 
 32   Routine:            GETKEY
 33 
 34   Function:
 35       This routine will fetch a keyboard key press. A flag is
 36   specified to determine whether the routine should wait blocked if
 37   no key was hit or whether to return -1.
 38 
 39   Parameters:
 40      (input)          block_flag - if this value is TRUE, the routine
 41                           will wait in a blocked state for input; if
 42                           false, the routine will return immediately
 43                           with an error code if there is not keyboard
 44                           key hit
 45 
 46   Returns:            -1 if 'block_flag' is FALSE and no keyboard key
 47                           was pressed
 48                       the ASCII character entered from the keyboard,
 49                           if otherwise successful
 50 
 51 **********************************************************************/
 52 
 53 getkey(block_flag)
 54 int block_flag;
 55 {
 56     union REGS reg, outreg;
 57     int cpu_flags;
 58     int code;
 59 
 60     /* break key hit buffered? */
 61     if (break_flag) {
 62         break_flag = FALSE;
 63         return(BREAK_KEY);
 64     }
 65 
 66     /* if not block, just do a quick check to see if a hit was hit */
 67     if (!block_flag) {
 68         reg.h.ah = BIOS_KB_STATUS;
 69         cpu_flags = int86(BIOS_KB,&reg,&outreg);
 70         if (cpu_flags & Z_FLAG_MASK)
 71             return(-1);
 72     }
 73 
 74     /* fetch a key, waiting if necessary */
 75     reg.h.ah = BIOS_KB_READ;
 76     int86(BIOS_KB,&reg,&outreg);
 77 
 78     /* break key hit after waiting blocked? */
 79     if (break_flag) {
 80         break_flag = FALSE;
 81         return(BREAK_KEY);
 82     }
 83 
 84     /* if not an extended ASCII code, just return the ASCII code */
 85     if (outreg.h.al)
 86         return((int)outreg.h.al);
 87 
 88     /* encode to get a unique extended ASCII value */
 89     code = ASCII_EXTEND_CODE + outreg.h.ah;
 90     return(code);
 91 }
 92 
 93 
 94 
 95 /*^L
 96 **********************************************************************
 97 
 98   Routine:            SET_CURSOR
 99 
100   Function:
101       This routine moves the physical cursor (the cursor on the
102   screen) to a specified screen coordinate.
103 
104   Parameters:
105      (input)          row - specifies which row (with 0 being the top
106                           of the screen) to move to
107      (input)          col - specifies which column (with 0 being the
108                           left of the screen) to move to
109 
110   Returns:            NONE
111 
112   Note 1 - This routine is called by routines other than edit mode
113       keyboard routines.
114 **********************************************************************/
115 
116 set_cursor(row,col)
117 int row;
118 int col;
119 {
120     union REGS reg, outreg;
121 
122     reg.h.ah = VIDEO_CURSOR_MOVE_FUNC;   /* VIDEO cursor set */
123     reg.h.dh = row;
124     reg.h.dl = col;
125     reg.h.bh = get_active_page();
126     int86(BIOS_VIDEO,&reg,&outreg);
127 }
128 
129 
130 
131 /*^L
132 **********************************************************************
133 
134   Routine:            SCROLL_DISPLAY
135 
136   Function:
137       This routine scrolls a particular region on the screen one line
138   up, filling the bottom line of the region with a blank line.
139 
140   Parameters:         NONE
141 
142   Returns:            NONE
143 
144 **********************************************************************/
145 
146 scroll_display()
147 {
148     union REGS reg,outreg;
149 
150     reg.h.ah = VIDEO_SCROLL_UP_FUNC;    /* scroll up function */
151     reg.h.al = DEFAULT_LINES_TO_SCROLL; /* number of lines to scroll up */
152     reg.h.ch = CURSOR_HOME_ROW;   /* upper left row coordinate to scroll */
153     reg.h.cl = CURSOR_HOME_COL;   /* upper left col coordinate to scroll */
154     reg.h.dh = MAX_SCREEN_LINE;   /* lower right row coordinate to scroll */
155     reg.h.dl = MAX_SCREEN_COL;    /* lower right row coordinate to scroll */
156     reg.h.bh = wst_fg_screen.attr;      /* attribute of blank scroll line */
157     int86(BIOS_VIDEO,&reg,&outreg);
158 }
159 
160 
161 
162 /*^L
163 **********************************************************************
164 
165   Routine:            DELAY
166 
167   Function:
168       This function delays for several milliseconds in a tight loop.
169   The DOS time function is called to get the current time in hundredth
170   of seconds. The resolution of the clock is typically 18.2 ticks
171   per second so this routine delays for between 1 and 2 ticks.
172   A limit is placed on the number of iterations in the event that
173   the clock does not support hundredth of seconds.
174 
175   Parameters:         NONE
176 
177   Returns:            NONE
178 
179 **********************************************************************/
180 
181 delay ()
182 {
183     int current_hundredth;
184     union REGS reg;
185     int ticks;
186     int iterations;
187 
188     ticks = 0;
189     current_hundredth = -1;
190 
191     /* limit iterations to 500 */
192     for (iterations = 0; iterations < 500; iterations++) {
193 
194         /* get system time */
195         reg.h.ah = SYSTEM_TIME;
196         intdos (&reg, &reg);
197 
198         /* clock changed? */
199         if (current_hundredth != reg.h.dl) {
200             current_hundredth = reg.h.dl;
201 
202             /* tally and check for timeout */
203             ticks++;
204             if (ticks >= 2) break;
205         }
206     }
207 }