'ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'³                                                                        ³
'³                          X C O L O R S . B A S                         ³
'³                                                                        ³
'³                   Supplementary Source Code for the                    ³
'³       The QBSCR Screen Routines for QuickBASIC 4.0+ Programmers        ³
'³                              Version 2.0                               ³
'³                                                                        ³
'³                   (C) Copyright 1992 by Tony Martin                    ³
'³                                                                        ³
'ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
'³                                                                        ³
'³  This source code is copyright 1992 by Tony Martin.  You may change    ³
'³  it to suit your programming needs, but you may not distribute any     ³
'³  modified copies of the library itself.  I retain all rights to the    ³
'³  source code and all library modules included with the QBSCR package,  ³
'³  as well as to the example programs.  You may not remove this notice   ³
'³  from any copies of the library itself you distribute.                 ³
'³                                                                        ³
'³  You are granted the right to use this source code for your own pro-   ³
'³  grams, without royalty payments or credits to me (though, if you      ³
'³  feel so inclined to give me credit, feel free to do so).  You MUST    ³
'³  register this software if you release a shareware or commercial       ³
'³  program that uses it.  You may use these routines in any type of      ³
'³  software you create, as long as it is not a programming toolbox or    ³
'³  package of routines OF ANY KIND.                                      ³
'³                                                                        ³
'³  This package is shareware.  If you find it useful or use it in any    ³
'³  software you release, you are requested to send a registration fee of ³
'³  $25.00 (U.S. funds only) to:                                          ³
'³                                                                        ³
'³                            Tony Martin                                 ³
'³                       1611 Harvest Green Ct.                           ³
'³                          Reston, VA 22094                              ³
'³                                                                        ³
'³  All registered users receive an 'official' disk set containing the    ³
'³  latest verison of the QBSCR routines.  For more information, see      ³
'³  the QBSCR documentation.                                              ³
'³                                                                        ³
'ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
'³                                                                        ³
'³  For information on using these routines and incorporating them into   ³
'³  your own programs, see the accompanying documentation.                ³
'³                                                                        ³
'ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
' Include QB.BI to get access to the RegType type and the Interrupt sub.
' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
REM $INCLUDE: 'qb.bi'

' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
' The three simple declare statements for this library...
' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
DECLARE FUNCTION EgaPresent% ()
DECLARE FUNCTION rgbRGB% (red%, green%, blue%)
DECLARE FUNCTION VgaPresent% ()
DECLARE SUB BlinkOff ()
DECLARE SUB BlinkOn ()
DECLARE SUB LoadVgaTextFont (fontfile$)
DECLARE SUB LoadEgaTextFont (fontfile$)

' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
' Required constants.
' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
CONST FALSE = 0, TRUE = NOT FALSE

COMMON SHARED mouseExists%, mouseState%

SUB BlinkOff

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' This routine disables blinking characters and instead allows high-
	' intensity background colors.  To obtain a high-intensity background,
	' you must set your backgound color normally (to a value from 0 to 7),
	' and then add 16 to the foreground color, just as if you were making
	' a blinking foreground.  Example:
	'
	'   To set a Dark Blue foreground onto a high-intensity White background,
	'   the following steps would be performed:
	'
	'     1. Call BlinkOff once.
	'     2. Set your background color to White (7).
	'     3. Set your foreground color to Dark Blue (1) plus 16 for the
	'        bright background.
	'     4. Issue a color statement with these values.
	'     5. Display any text you desire in these colors.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ


	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' We may need to make a BIOS call to set blink off (if EGA or VGA is
	' present), so DIMension an object of RegType, that represents the
	' CPU's registers, for use with the Interrupt routine.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
 
	DIM reg AS RegType


	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Check to see if an EGA or VGA is present.  If so, call BIOS function
	' 1003h with register BX set to 0 (Blink OFF).  If EGA/VGA is NOT present
	' (CGA is there), then send hex value 09h to port 3D8h, to turn off the
	' blink attribute.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
 
	IF EgaPresent% THEN
		reg.ax = &H1003
		reg.bx = 0
		INTERRUPT &H10, reg, reg
	ELSE
		OUT &H3D8, 9
	END IF

END SUB

SUB BlinkOn

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' This routine enables blinking characters and turns off high-
	' intensity background colors.   Call this when you want to restore the
	' blinking attribute, such as right before your program ends.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ


	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' We may need to make a BIOS call to set blink on (if EGA or VGA is
	' present), so DIMension an object of RegType, that represents the
	' CPU's registers, for use with the Interrupt routine.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
 
	DIM reg AS RegType

 
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Check to see if an EGA or VGA is present.  If so, call BIOS function
	' 1003h with register BX set to 1 (Blink ON).  If EGA/VGA is NOT present
	' (CGA is there), then send value 41 to port 3D8h, to turn on the
	' blink attribute.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	IF EgaPresent% THEN
		reg.ax = &H1003
		reg.bx = 1
		INTERRUPT &H10, reg, reg
	ELSE
		OUT &H3D8, 41
	END IF

END SUB

FUNCTION EgaPresent%

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' This routine checks for the presence of an EGA or VGA graphics card.
	' If one is found, the function returns TRUE (non-zero).  If one is not
	' found, then the function returns FALSE (zero).  This function is only
	' used internally and does not need to be called directly by the
	' programmer.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
 
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' We will need to make a BIOS call to check for the EGA/VGA.  Therefore,
	' we must DIMension an object of RegType, that represents the
	' CPU's registers, for use with the Interrupt routine.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	DIM ireg AS RegType
	
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Set the AH register (the high byte of AX) to hex 12h, and the BL
	' register (the low byte of BX) to hex 10h.  Then make the call to
	' Interrupt 10h.  This Interrupt is actually a call to the Alternate
	' Select routine, which, in this case, is returning to us some information
	' about the EGA card (if we were interested, such info as color or mono
	' mode, amount of video memory, and the EGA switch settings).  If an EGA
	' or VGA is present, the BX register will return some info and will have
	' a different value than the one we put in it (10h).  If there is no
	' EGA or VGA present, then BX will contain the same value we put in it
	' before the call to the Interrupt (10h).
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	ireg.ax = &H12 * 256
	ireg.bx = &H10

	INTERRUPT &H10, ireg, ireg

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' If BX has 10h in it, there is no EGA/VGA present.  If it has some other
	' value, then an EGA or VGA is present.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF ireg.bx = &H10 THEN
		EgaPresent% = FALSE
	ELSE
		EgaPresent% = TRUE
	END IF

END FUNCTION

SUB LoadEgaTextFont (fontfile$)

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' This SUB loads the data from a premade VGA font file and informs the
	' VGA card that it should load it.  It first checks to see if there is a
	' VGA card present.  If not, thius SUB exist without loading the font.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Define some of the data required here.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	DIM regx AS RegTypeX
	DIM charData AS STRING * 3584

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' If the fontfile name is "", then reset the font to normal EGA 8x14.
	' The EGA BIOS service is &H11 (in AH), font-related services.  The sub-
	' service, &H01 (in AL), is Load ROM 8x14 character set.  When done,
	' get outta here.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF fontfile$ = "" THEN
		regx.ax = &H1101             ' Load ROM 8x14 character set.
		INTERRUPTX &H10, regx, regx
		EXIT SUB
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Open font file and load font data.  Note that it is assumed that the
	' font file exists.  If it does not, then your screen will be blank,
	' since this function loaded all zeros.  Call this function with a font
	' file name of "" to restore screen font if this happens.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	fontfile$ = LTRIM$(RTRIM$(fontfile$))
	OPEN fontfile$ FOR RANDOM AS #99 LEN = 3584   ' 3584 bytes in font file.
	GET #99, 1, charData
	CLOSE #99
	fontData$ = LEFT$(charData, 3584)    ' Make sure only 3854 bytes.

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Set up register values for call to VGA BIOS.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	regx.bp = SADD(fontData$)       ' Offset of font data address.
	regx.es = VARSEG(fontData$)     ' Segment of font data address.
	regx.ax = &H1100                ' Service &H11, sub-service &H00.
	regx.bx = &HE00                 ' 14 bytes/char, Load into block 0.
	regx.cx = 256                   ' Load all 256 characters.
	regx.dx = 0                     ' Start at offset 0 (into font data).

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Load that font!
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	INTERRUPTX &H10, regx, regx

END SUB

SUB LoadVgaTextFont (fontfile$)

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' This SUB loads the data from a premade VGA font file and informs the
	' VGA card that it should load it.  It first checks to see if there is a
	' VGA card present.  If not, thius SUB exist without loading the font.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Define some of the data required here.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	DIM regx AS RegTypeX
	DIM charData AS STRING * 4096

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' If the fontfile name is "", then reset the font to normal VGA 8x16.
	' The VGA BIOS service is &H11 (in AH), font-related services.  The sub-
	' service, &H04 (in AL), is Load ROM 8x16 character set.  When done,
	' get outta here.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF fontfile$ = "" THEN
		regx.ax = &H1104
		INTERRUPTX &H10, regx, regx
		EXIT SUB
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Open font file and load font data.  Note that it is assumed that the
	' font file exists.  If it does not, then your screen will be blank,
	' since this function loaded all zeros.  Call this function with a font
	' file name of "" to restore screen font if this happens.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	fontfile$ = LTRIM$(RTRIM$(fontfile$))
	OPEN fontfile$ FOR RANDOM AS #99 LEN = 4096   ' 4096 bytes in font file.
	GET #99, 1, charData
	CLOSE #99
	fontData$ = LEFT$(charData, 4096)     ' Make sure only 4096 bytes!

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Set up register values for call to VGA BIOS.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	regx.bp = SADD(fontData$)       ' Offset of font data address.
	regx.es = VARSEG(fontData$)     ' Segment of font data address.
	regx.ax = &H1100                ' Service &H11, sub-service &H00.
	regx.bx = &H1000                ' 4096 bytes in character data.
	regx.cx = 256                   ' Load all 256 characters.
	regx.dx = 0                     ' Start at offset 0 (into font data).

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Load that font!
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	INTERRUPTX &H10, regx, regx

END SUB

FUNCTION rgbRGB% (red%, green%, blue%)

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' This function calculates an attribute color value for extended EGA/VGA
	' colors in text mode.  Pass in red, green and blue values from 0 to 3
	' each to form up to 64 (0-63) possible colors.
	'
	' Red, green, and blue colors mix to form the following colors:
	'
	'             CYAN    = BLUE + GREEN
	'             MAGENTA = BLUE + RED
	'             YELLOW  = RED + GREEN
	'             WHITE   = RED + GREEN + BLUE
	'
	' For example, to get bright yellow, a call to rgbRGB would look like
	' this (in combination with the palette statement):
	'
	'             PALETTE 1, rgbRGB%( 3, 3, 0 )
	'
	' Play around with this function -- you can mix all kinds of combinations
	' to get some really nifty colors.
	'
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Ensure that each parameter passed in is in the range of 0-3.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	red% = red% AND 3
	green% = green% AND 3
	blue% = blue% AND 3

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Calculate an EGA/VGA rgbRGB color value for the passed-in values.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	clr% = 0

	clr% = clr% + ((red% AND 1) * 32)          ' Add lo red if red = 1 or 3
	IF (red% AND 2) THEN clr% = clr% + 4       ' Add hi red if red = 2 or 3

	clr% = clr% + ((green% AND 1) * 16)        ' Add lo green if green = 1 or 3
	IF (green% AND 2) THEN clr% = clr% + 2     ' Add hi green if green = 2 or 3

	clr% = clr% + ((blue% AND 1) * 8)          ' Add lo blue if blue = 1 or 3
	IF (blue% AND 2) THEN clr% = clr% + 1      ' Add hi blue if blue = 2 or 3

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' That's it!  Return our color value, ready for use in a QB PALETTE
	' statement.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	rgbRGB% = clr%

END FUNCTION

FUNCTION VgaPresent%

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' This function determines whether or not a VGA card is present in the
	' system.  If it is, this function returns TRUE (non-zero).  If there is
	' not a VGA card present, this function returns FALSE (zero).
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Set up data to be used.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	DIM iregx AS RegTypeX
	DIM oregx AS RegTypeX
 
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Set up register variables for interruptx call.  Service &H1A00 calls
	' the VGA Read or Write Display Combination Code BIOS routine. It will
	' return value &H1A in register AL (AX), if a VGA is there. Any other
	' value means the function call failed, hence, no VGA.  NOTE: We need
	' both INPUT (iregx) and OUTPUT (oregx) register variables here, since
	' they overlap.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	iregx.ax = &H1A00
	INTERRUPTX &H10, iregx, oregx

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Return value based on INTERRUPTX BIOS call return value.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF (oregx.ax AND &HFF) = &H1A THEN
		VgaPresent% = TRUE
	ELSE
		VgaPresent% = FALSE
	END IF

END FUNCTION

