SLEEP 'so we can see the original text
_MEMPUT m
, m.OFFSET
, 4 AS _UNSIGNED _BYTE 'first, to change the character at 1,1 (Top Left of screen; it should be "H") SLEEP 'so we can see the change, as we changed the "H" to CHR$(4) --- ""
_MEMPUT m
, m.OFFSET
+ 3 * 2 + 1, 4 AS _UNSIGNED _BYTE 'now let's try to change the "3rd" character's color to RED (color value 4) 'If you notice, we actually changed the FOURTH characcter's color to red (the second "l" in "Hello World".
'This makes sense once you realize that memory is mapped starting at 0,0; whereas LOCATE starts at 1,1 in SCREEN 0.
'To work with any particular point for SCREEN 0 memory, we need to remember:
'1) Screen Information is stored in 2 bytes -- First Byte is the character.
' Second Byte is the color code.
'2) To convert the screen coordinates to memory coordinates, use the simple formula:
' CharacterMemoryPosition = ((Column -1) * _WIDTH + Row -1)) * 2
' ColorMemoryPosition = ((Column -1) * _WIDTH + Row -1)) * 2 + 1
'3) Next tip is to always remember to add the value to m.Offset which is QB64's way to track where the screen information starts in memory
'So to make Row 2, Column 1 become a "W", we'd do the following:
CharacterMemoryPosition
= ((2 - 1) * _WIDTH + 1 - 1) * 2SLEEP 'so we can wait and see the W appear where we want it _MEMPUT m
, m.OFFSET
+ CharacterMemoryPosition
, "W" 'And to change that W to being blue, we'd do the following:
ColorMemoryPosition
= ((2 - 1) * _WIDTH + 1 - 1) * 2 + 1SLEEP 'to see the change one step at a time