'===========================================================================
' Subject: PRINT TEXT TO VIDEO MEMORY         Date: 06-24-98 (08:30)       
'  Author: Ka-Lok Fung                        Code: QB, QBasic, PDS        
'  Origin: kalok@vcn.bc.ca                  Packet: MEMORY.ABC
'===========================================================================
'DPrint - Print Text to video memory directly
'by Jason Downey [FG/98] 98-6-23

'Notes: 1) this is designed to work in 25x80 Text Mode
'       2) currently only one colour may be used for the entire
'          phrase        
'       3) the colour may be changed by using the COLOR statement, followed
'          by a CLS statement

'How To Read From And Write To The Text Screen Directly?
'Characters are stored in the video memory using two bytes per character. The
'first is the ASCII code of the character and the second the colour, using the
'formula value = foreground + 16 x background + 128 x blinking, where foreground
'is the foreground colour ranging 0-15, background is the background colour
'ranging 0-7 and blinking is either 0 or 1. To read or write characters directly
'from the screen, you can use PEEK and POKE like this:
'DEF SEG = &HB800
'POKE 160, 65'Put an A in the top left corner
'POKE 161, 3
'x = PEEK(157) 'Get ASCII value for character in top right corner
'Source: Egbert Zijlema.

DEFINT A-Z
DECLARE SUB DPrint (TextToPrint$, x%, y%, Position%)

SCREEN 0: COLOR 15: CLS
FOR LetterPos = 1 TO 34
    DPrint "Another Quality [FG/98] Production", 50, 13, LetterPos
NEXT LetterPos

END

SUB DPrint (TextToPrint$, x%, y%, Position%)
'****************************************************************
'    TextToPrint$ - Text to Write directory to video memory
'    x%, y%       - Co-ordinates for the text to be placed on
'    Position%    - The number of the next letter to print
'****************************************************************

DEF SEG = &HB800
num% = x% + (Position% * 2) - 2 + (y% * 160) - 160
IF (num% / 2) <> INT(num% / 2) THEN num% = num% + 1
POKE num%, ASC(MID$(TextToPrint$, Position%))
DEF SEG = 0

END SUB
