Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - LechU

Pages: [1]
1
QB64 Discussion / Re: Question about text attributes in SCREEN 0
« on: March 04, 2019, 02:53:09 pm »
Sounds to me as if you're looking for the _MEM commands:

Code: QB64: [Select]
  1.  
  2. PRINT "Hello World"
  3. SLEEP 'so we can see the original text
  4.  
  5. m = _MEMIMAGE(0)
  6.  
  7. _MEMPUT m, m.OFFSET, 4 AS _UNSIGNED _BYTE 'first, to change the character at 1,1 (Top Left of screen; it should be "H")
  8. SLEEP 'so we can see the change, as we changed the "H" to CHR$(4) --- ""
  9.  
  10. _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)
  11. 'If you notice, we actually changed the FOURTH characcter's color to red (the second "l" in "Hello World".
  12. 'This makes sense once you realize that memory is mapped starting at 0,0; whereas LOCATE starts at 1,1 in SCREEN 0.
  13. 'To work with any particular point for SCREEN 0 memory, we need to remember:
  14.  
  15. '1) Screen Information is stored in 2 bytes -- First Byte is the character.
  16. '                                              Second Byte is the color code.
  17.  
  18. '2) To convert the screen coordinates to memory coordinates, use the simple formula:
  19. '                                              CharacterMemoryPosition = ((Column -1) * _WIDTH + Row -1)) * 2
  20. '                                              ColorMemoryPosition =     ((Column -1) * _WIDTH + Row -1)) * 2 + 1
  21.  
  22. '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
  23.  
  24.  
  25. 'So to make Row 2, Column 1 become a "W", we'd do the following:
  26. CharacterMemoryPosition = ((2 - 1) * _WIDTH + 1 - 1) * 2
  27. SLEEP 'so we can wait and see the W appear where we want it
  28. _MEMPUT m, m.OFFSET + CharacterMemoryPosition, "W"
  29. 'And to change that W to being blue, we'd do the following:
  30. ColorMemoryPosition = ((2 - 1) * _WIDTH + 1 - 1) * 2 + 1
  31. SLEEP 'to see the change one step at a time
  32. _MEMPUT m, m.OFFSET + ColorMemoryPosition, 1 AS _UNSIGNED _BYTE
  33.  
  34.  

VERY BIG THANKS.
This is exactly what I'm looking for.
THANKS AGAIN.


But. Are You raelly sure that:

        CharacterMemoryPosition = ((Column - 1) * _WIDTH + Row - 1) * 2
        ColorMemoryPosition =     ((Column - 1) * _WIDTH + Row - 1) * 2 + 1


not:

        CharacterMemoryPosition = (Column - 1 + _WIDTH * (Row - 1)) * 2
        ColorMemoryPosition =     (Column - 1 * _WIDTH * (Row - 1)) * 2 + 1


Row and Column swapped?


2
QB64 Discussion / Question about text attributes in SCREEN 0
« on: March 04, 2019, 07:07:10 am »
Two simple(?) questions:

1. Is it possible to print something on the screen (SCREEN 0) WITHOUT altering old attribytes at cursor position?
2. Is it possible to change attributes of text already displayed at screen (SCREEN 0)?



Pages: [1]