Screen Memory: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 23: Line 23:
{{Cl|FOR...NEXT|FOR}} j = 1 {{Cl|TO}} 15
{{Cl|FOR...NEXT|FOR}} j = 1 {{Cl|TO}} 15
  {{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} {{Cl|LEN}}(s)
  {{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} {{Cl|LEN}}(s)
   {{Cl|POKE}} (j * 80 + (i - 1)) * 2, {{Cl|ASC}}({{Cl|MID$}}(s$, i, 1))        'text characters
   {{Cl|POKE}} (j * 80 + (i - 1)) * 2, {{Cl|ASC (function)|ASC}}({{Cl|MID$ (function)|MID$}}(s$, i, 1))        'text characters
   {{Cl|POKE}} (j * 80 + (i - 1)) * 2 + 1, {{Cl|&H}}80 {{Cl|OR (boolean)|OR}} j 'blinking color
   {{Cl|POKE}} (j * 80 + (i - 1)) * 2 + 1, {{Cl|&H}}80 {{Cl|OR (boolean)|OR}} j 'blinking color
  {{Cl|NEXT}}
  {{Cl|NEXT}}
Line 52: Line 52:
{{Cl|END}}
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}
{{small|Code by Ted Weissgerber}}
{{Small|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.
:''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.
{{WhiteStart}}                                '''4000 byte Video Memory Segment'''
{{FixedStart}}                                '''4000 byte Video Memory Segment'''


Text block #:  1                  321    322    323    324    325    326    327
Text block #:  1                  321    322    323    324    325    326    327
Line 64: Line 64:


                         Offset% = (160 * (Row% - 1)) + (2 * (Column% - 1))
                         Offset% = (160 * (Row% - 1)) + (2 * (Column% - 1))
{{WhiteEnd}}
{{FixedEnd}}


<center>'''Graphic Screen Segment &HA000'''</center>
<center>'''Graphic Screen Segment &HA000'''</center>
Line 73: Line 73:




''See also:''
{{PageSeeAlso}}
 
* [[PEEK]], [[POKE]]
* [[PEEK]], [[POKE]]
* [[DEF SEG = 0]]
* [[DEF SEG = 0]]
* [[SCREEN]]
* [[SCREEN]]
* [[SCREEN (function)]]
* [[SCREEN (function)]]
* [[_NEWIMAGE]] {{text|(screen pages)}}
* [[_NEWIMAGE]]
* [[_LOADIMAGE]] {{text|(image files)}}
* [[_LOADIMAGE]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 00:46, 26 February 2023

SCREEN Memory Segments


Screen 0 Text Segment &HB800
  • The text video memory segment is located at hexadecimal memory address B800 or 47104 decimal.
  • The normal SCREEN 0 WIDTH is 25 rows by 80 columns wide capable of up to 2000 text characters.
  • Each text block memory offset consists of a text character byte followed by a color byte.
  • Each unsigned byte can hold values from 0 to 255 only. PEEK can read and POKE can write positive values to those bytes.
  • Text ASCII code values range from 0 to 127 with the extended codes ranging from 128 to 255.
  • Color values from 0 to 127 are the normal 16 text colors with background color attributes ranging from 0 to 7.
  • Color values from 128 to 255 are the high intensity blinking color values with background color attributes ranging from 0 to 7.


Example 1: 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


Example 2: 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
  • The graphic video memory segment is located at hexadecimal memory address A000 or 40960 decimal.
  • Legacy graphic screen modes include 1, 2, 7, 8, 9, 10, 11, 12 and 13 with varying pixel widths, heights and color attributes.
  • QB64 _NEWIMAGE or _LOADIMAGE screen modes can use the legacy modes above, 256 color or 32 bit color modes.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage