# unit b_crt

### OS independent screen and keyboard routines.

author: bocianu bocianu@gmail.com

Set of useful constants, registers and methods to cope with text input and output without ATARI OS.
This library is a part of 'blibs' - set of custom Mad-Pascal libraries.
https://gitlab.com/bocianu/blibs

## Constants:

name: | value: | description:
--- | --- | ---
CHAR_RETURN | #$9b | Chars returned for special keys in ASCII code
CHAR_ESCAPE | #$1b |
CHAR_BACKSPACE | #$7e |
CHAR_TAB | #$7f |
CHAR_INVERSE | #$81 |
CHAR_CAPS | #$82 |
ICHAR_RETURN | #219 | Chars returned for special keys in Antic code
ICHAR_ESCAPE | #91 |
ICHAR_BACKSPACE | #126 |
ICHAR_TAB | #127 |
ICHAR_INVERSE | #193 |
ICHAR_CAPS | #194 |

## Register Variables:

name: | address: | type: | description:
--- | --- | --- | ---
kbcode | $d209 | byte | code of last pressed key
consol | $d01f | byte | console keys status

## Global Variables:

name: | type: | description:
--- | --- | ---
CRT_vram | word | contains address of video memory
CRT_size | word | contains size of video memory
CRT_screenWidth | byte | contains width of screen in bytes
CRT_screenHeight | byte | contains height of screen in bytes
CRT_cursor | word | contains cursor position in memory

## Interface:

name: | description:
--- | ---
CRT_Init | #### procedure CRT_Init(vram_address: word; width, height: byte); overload; Initializes CRT library with video ram located at specified memory address, using custom values for screen width and height. ##### parameters: vram_address - memory address of video ram width - width of the screen (chars) height - height of the screen (rows)
CRT_Init | #### procedure CRT_Init(vram_address: word); overload; Initializes CRT library with video ram located at specified memory address, Screen size is defined as default values (40 x 24). ##### parameters: vram_address - memory address of video ram
CRT_Init | #### procedure CRT_Init; overload; Initializes CRT library with video ram pointed by savmsc register, Screen size is defined as default values (40 x 24). ##### parameters: vram_address - memory address of video ram
CRT_Clear | #### procedure CRT_Clear; overload; Clears screen.
CRT_Clear | #### procedure CRT_Clear(filler: byte); overload; Clears screen using specified byte as filling value.
CRT_ClearRow | #### procedure CRT_ClearRow(row: byte); overload; Clears specified row of a screen. ##### parameters: row - number of row to clear
CRT_ClearRow | #### procedure CRT_ClearRow; overload; Clears current row of a screen.
CRT_GotoXY | #### procedure CRT_GotoXY(x, y: byte); Moves cursor to specified position on screen. x=0, y=0 is upper left corner. ##### parameters: x - cursor's horizontal position y - cursor's vertical position
CRT_WhereY | #### function CRT_WhereY: byte; Returns current vertical position of cursor (row). ##### returns: (byte) - current row
CRT_WhereY | #### function CRT_WhereY: byte; Returns current horizontal position of cursor (column). ##### returns: (byte) - current column
CRT_GetXY | #### function CRT_GetXY(x, y: byte): byte; Returns byte located at specified position on screen. x=0, y=0 is upper left corner. ##### parameters: x - cursor's horizontal position y - cursor's vertical position ##### returns: (byte) - value at specified position
CRT_Write | #### procedure CRT_Write(s: string); overload; Outputs string at current cursor position. This function outputs text in Antic coding, not ATASCII. Add 'tilda' after finishing quote of your string to use Antic coding. Example: Write('Hello Atari'~); You may also use Atascii2Antic function, to convert strings. ##### parameters: s - string of text in Antic code
CRT_Write | #### procedure CRT_Write(num: integer); overload; Outputs integer value at current cursor position. ##### parameters: num - value to write.
CRT_Write | #### procedure CRT_Write(num: real); overload; Outputs real value at current cursor position. ##### parameters: num - value to write.
CRT_WriteXY | #### procedure CRT_WriteXY(x,y: byte; s: string); Outputs string at desired position of the screen. x=0, y=0 is upper left corner. ##### parameters: x - cursor's horizontal position y - cursor's vertical position s - string to output (in Antic code)
CRT_WriteCentered | #### procedure CRT_WriteCentered(row: byte; s:string); overload; Outputs centered string at specified row of the screen. ##### parameters: row - row number s - string to output (in Antic code)
CRT_WriteCentered | #### procedure CRT_WriteCentered(s:string); overload; Outputs centered string in current row of cursor. ##### parameters: s - string to output (in Antic code)
CRT_Put | #### procedure CRT_Put(b: byte); overload; Outputs single byte at current position of the cursor. ##### parameters: b - byte to be writen
CRT_Put | #### procedure CRT_Put(x, y, b: byte); overload; Outputs single byte at desired position of the screen. x=0, y=0 is upper left corner. ##### parameters: x - cursor's horizontal position y - cursor's vertical position b - byte to be writen
CRT_KeyPressed | #### function CRT_KeyPressed: boolean; Returns true if any key on keyboard is pressed down. ##### returns: (boolean) true if any key is down
CRT_ReadKey | #### function CRT_ReadKey: byte; Waits for key to be pressed and returns it's keyboard code. ##### returns: keyboard code of pressed key.
CRT_ReadChar | #### function CRT_ReadChar: byte; Waits for key to be pressed and returns it's value in ATASCII code. ##### returns: ATASCII code of pressed key.
CRT_ReadCharI | #### function CRT_ReadCharI: byte; Waits for key to be pressed and returns it's value in ANTIC code. ##### returns: ANTIC code of pressed key.
CRT_ReadStringI | #### function CRT_ReadStringI(limit: byte): string; overload; Reads string from keyboard, finished with return key, and returns it's value in ANTIC code. You can provide maximum number of chars to be entered. ##### returns: entered string in ANTIC code
CRT_ReadStringI | #### function CRT_ReadStringI: string; overload; Reads string from keyboard, finished with return key, and returns it's value in ANTIC code. Maximum length is 255 chars ##### returns: entered string in ANTIC code
CRT_ReadString | #### function CRT_ReadString(limit: byte): string; overload; Reads string from keyboard, finished with return key, and returns it's value in ATASCII code. You can provide maximum number of chars to be entered. ##### returns: entered string in ATASCII code
CRT_ReadString | #### function CRT_ReadString: string; overload; Reads string from keyboard, finished with return key, and returns it's value in ATASCII code. Maximum length is 255 chars ##### returns: entered string in ATASCII code
CRT_ReadInt | #### function CRT_ReadInt: integer; Reads integer value from keyboard, finished with return key, ##### returns: (integer) entered integer value
CRT_ReadFloat | #### function CRT_ReadFloat: real; Reads floating point value from keyboard, finished with return key, Dot symbol '.' is used to separate fractional part. ##### returns: (real) entered floating point value
CRT_NewLine | #### procedure CRT_NewLine; overload; Moves cursor to next line of screen.
CRT_NewLine | #### procedure CRT_NewLine(offset: byte); overload; Moves cursor to next line of screen and sets left margin (text offset). ##### parameters: offset - new value for left margin
CRT_NewLines | #### procedure CRT_NewLines(count: byte); Moves cursor down by specifien number of lines. ##### parameters: number of lines
CRT_Invert | #### procedure CRT_Invert(x, y, width: byte); Inverts part of the screen. x=0, y=0 is upper left corner. ##### parameters: x - starting cursor's horizontal position y - starting cursor's vertical position b - number of characters to be inverted
CRT_InvertRow | #### procedure CRT_InvertRow(row: byte); Inverts selected row of the screen. ##### parameters: row - row number to invert
CRT_StartPressed | #### function CRT_StartPressed: boolean; Returns true if START key is pressed down. ##### returns: (boolean) true if START key is down
CRT_SelectPressed | #### function CRT_SelectPressed: boolean; Returns true if SELECT key is pressed down. ##### returns: (boolean) true if SELECT key is down
CRT_OptionPressed | #### function CRT_OptionPressed: boolean; Returns true if OPTION key is pressed down. ##### returns: (boolean) true if OPTION key is down
CRT_HelpPressed | #### function CRT_HelpPressed:boolean; Returns true if HELP key is pressed down. ##### returns: (boolean) true if HELP key is down
Atascii2Antic | #### function Atascii2Antic(c: byte): byte;overload; Converts single byte from ATASCII to ANTIC coding. ##### parameters: c - byte to convert
Antic2Atascii | #### function Antic2Atascii(c: byte): byte; overload; Converts single byte from ANTIC to ATASCII coding. ##### parameters: c - byte to convert
Atascii2Antic | #### function Atascii2Antic(s: string): string; overload; Converts text string from ATASCII to ANTIC coding. ##### parameters: s - string to convert
Antic2Atascii | #### function Antic2Atascii(s: string): string; overload; Converts text string from ANTIC to ATASCII coding. ##### parameters: s - string to convert