'===========================================================================
' Subject: PLOT TEXT STRING TRANSPARENTLY     Date: 12-14-96 (00:00)       
'  Author: Tika Carr                          Code: QB, PDS                
'  Origin: FidoNet QUIK_BAS Echo            Packet: EGAVGA.ABC
'===========================================================================
'plots.BAS by Tika Carr 12/14/96
'Donated to the Public Domain
'No waranties or gaurantees are expressed or implied.

'PLOT a text String (plots) to the graphics screen transparently.
'Syntax: plots("Text string", x, y, color)
'NOTE: The x and y are text locations, not graphics pixel locations.

DEFINT A-Z
DECLARE SUB plots (s$, x%, y%, c%)
'$INCLUDE: 'qb.bi'

SCREEN 12                                '640 x 480/16 color VGA mode
LINE (0, 0)-(640, 480), 3, BF            'clear screen
plots "Hello World", 10, 10, 14          'plot string to gfx screen
p$ = INPUT$(1)                           'wait for keypress before ending
SCREEN 0, 0, 0, 0: CLS                   'back to text mode and end

SUB plots (s$, x, y, c)

'Information obtained from Ralph Brown's Interrupt List:
'INT 10h
' ah = 09h
' al = character to write
' bh = page number (for 256 color modes, the background color instead)
' bl = text mode attribute, or graphics mode color of text
'      if the mode is not a 256 color mode, and bit 7 is set, then
'      the character is XOR'd to the screen.
' cx = number of times to write the character (usually 1ce)

DIM inregs AS RegType, outregs AS RegType
ah$ = "09"                               'Set up interrupt to write chr
inregs.cx = 1                            'Write each character only once
bh$ = HEX$(0)                            'Graphics Page number (usually 0)
bl$ = HEX$(c - 1 + &H80)                 'Color + bit 7 set for transparency
bx$ = bh$ + bl$                          'Set up bx register
inregs.bx = VAL("&H" + bx$)
FOR i = 1 TO LEN(s$)
  LOCATE y, x
  al$ = HEX$(ASC(MID$(s$, i, 1)))        'load in the next chr to write
  ax$ = ah$ + al$                        'set up ax register
  inregs.ax = VAL("&H" + ax$)
  INTERRUPT &H10, inregs, outregs        'call the interrupt
  x = x + 1                              'advance cursor one position
NEXT
END SUB
