home *** CD-ROM | disk | FTP | other *** search
- '┌────────────────────────────────────────────────────────────────────────┐
- '│ │
- '│ 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
-
-