home *** CD-ROM | disk | FTP | other *** search
- {.L-} { Suppress listing by LISTT }
- {*
- * --------------------------------------------------------------------
- * C O N S O L E I N T E R F A C E U N I T
- * --------------------------------------------------------------------
- *
- * In this 'unit' a number of methods are gathered for interfacing to
- * the console device.
- *
- * I N T E R F A C E S E C T I O N
- *}
-
- const
- Beep = ^G ; { Bell signal }
- Cr = ^M ; { Carriage return }
-
- type
- HexString = string[4] ; { Hexadecimal encoded integer }
-
- {
- function GetMaxX : Integer ;
- function GetMaxY : Integer ;
- function Hex( Value : Integer ; DigitCount : Integer ) : HexString ;
- procedure IllegalCommand ;
- procedure InitConsoleUnit ;
- procedure ReadCommand( var Code : Char ) ;
- function WhereX : Integer ;
- function WhereY : Integer ;
- }
-
- {*
- * I M P L E M E N T A T I O N S E C T I O N
- *}
-
- (* -------------------------
- function GetMaxX : Integer ;
- {*
- * Return the number of characters on one line, that is the maximum value of
- * the X coordinate.
- *}
- begin
- GetMaxX:= 80 ;
- end ; { of GetMaxX }
-
- function GetMaxY : Integer ;
- {*
- * Return the number of user lines on the screen, that is the maximum value
- * of the Y coordinate.
- *}
- begin
- GetMaxY:= 24 ;
- end ; { of GetMaxY }
- -------------------------- *)
-
- function Hex( Value : Integer ; DigitCount : Integer ) : HexString ;
- {*
- * Return the rightmost DigitCount nibbles of the variable Value in the
- * hexadecimal notation in a string.
- *}
- var
- Result : HexString ; { Area to build converted string }
- const
- HexDigit : array[0..15] of char = '0123456789ABCDEF' ;
- begin
- Result:= '' ; { Preset result string }
- while DigitCount>0 do
- begin
- Result:= HexDigit[ Value and $000F ] + Result ;
- Value := Value shr 4 ;
- DigitCount:= Pred( DigitCount ) ;
- end ;
- Hex:= Result ;
- end ; { of Hex }
-
- procedure IllegalCommand ;
- {*
- * Remove the command character left by ReadCommand and give an audible
- * alarmsignal.
- *}
- begin
- Write( ^H' '^H^G ) ;
- end ; { of IllegalCommand }
-
- procedure ReadCommand( var Code : Char ) ;
- {*
- * The procedure ReadCommand reads a single character, the command character,
- * and returns it in upper case in the variable Code. Only letters are
- * accepted as commands.
- *}
- var
- NextChar : Char ; { Next character entered by user }
- Done : Boolean ; { Loop termination condition }
- begin
- Write( Cr, 'Enter command - ' ) ;
- ClrEol ;
- repeat
- Read ( Kbd, NextChar ) ;
- NextChar:= UpCase( NextChar ) ;
- Done := NextChar in ['A'..'Z'] ;
- if not Done then
- Write( Beep ) ;
- until Done ;
- Write( NextChar ) ;
- Code:= NextChar ;
- end ; { of ReadCommand }
-
- (* -----------------------
- function WhereX : Integer ;
- {*
- * Return the X coordinate, the column number, of the cursor on the screen.
- *}
- begin
- WhereX:= ? ;
- end ; { of WhereX }
-
- function WhereY : Integer ;
- {*
- * Return the Y coordinate, the row number, of the cursor on the screen.
- *}
- begin
- WhereY:= ? ;
- end ; { of WhereY }
- ------------------------ *)
-
- procedure InitConsoleUnit ;
- begin
- { Nothing to do }
- end ; { of InitConsoleUnit }
- {.L+}