QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

SCREEN Memory Segments

Screen 0 Text Segment &HB800

Example(s)

Printing text with blinking colors in SCREEN 0 only.


DIM s AS STRING
DIM i AS LONG
DIM j AS LONG
CLS
s = "Hello, World!"
DEF SEG = &HB800
FOR j = 1 TO 15
 FOR i = 1 TO LEN(s)
  POKE (j * 80 + (i - 1)) * 2, ASC(MID$(s$, i, 1))        'text characters
  POKE (j * 80 + (i - 1)) * 2 + 1, &H80 OR j 'blinking color
 NEXT
NEXT
DEF SEG 'restore to default segment
END 

Displaying and coloring the 256 ASCII characters using POKE in SCREEN 0.


SCREEN 12 'set full screen in QBasic only for flashing colors
SCREEN 0
OUT &H3C8, 0: OUT &H3C9, 0: OUT &H3C9, 0: OUT &H3C9, 20

_FONT _LOADFONT("C:\Windows\Fonts\Cour.ttf", 20, "MONOSPACE") 'select monospace font. QB64 only!

DEF SEG = &HB800                        'SCREEN 0 text ONLY!
FOR code = 0 TO 255
  POKE 640 + code * 4, code             'poke the even text offsets with space between
NEXT
COLOR 11: LOCATE 20, 27: PRINT "Press a key to add color!"
K$ = INPUT$(1)
FOR colr = 0 TO 255
  POKE 641 + colr * 4, colr             'poke the ODD color offsets(second byte)
NEXT
DEF SEG                                 'reset to default segment
END 

Code by Ted Weissgerber

Explanation: To POKE text characters to the screen in SCREEN 0, DEF SEG sets the memory segment to &HB800. Text values are poked at the even segment offsets starting 640 bytes(4 rows * 80 columns wide * 2 bytes) from the upper left corner 0 offset of the screen memory segment. To space the text it skips an even offset by multiplying by 4 instead of 2. The odd offsets can be written to to set the color. Using the same 4 byte offsets, the text and background are colored using values up to 128. Values over 128 cause the text to flash and the background colors 0 to 7 are repeated. The background color is incremented every 16 values.


                                **4000 byte Video Memory Segment**

Text block #:   1                  321     322     323     324     325     326     327             
Text position:  1, 1                5, 1    5, 2    5, 3    5, 4    5, 5    5, 6    5, 7
Byte offset:    0, 1               640     642     644     646     648     650     652
**Segment: (CHR$(0), COLOR 0),.......(0, 0), (0, 0), (1, 1), (0, 0), (2, 2), (0, 0), (3, 3),...**

            Row% = Offset% \ 160 + 1          Column% = (Offset% MOD 160) \ 2 + 1

                         Offset% = (160 * (Row% - 1)) + (2 * (Column% - 1))

Graphic Screen Segment &HA000

See Also