Author Topic: Blinking colors code on text screen  (Read 3350 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Blinking colors code on text screen
« on: November 15, 2019, 11:04:25 am »
Hi.
 Why MEM return different colors values in text screen 0 (not the same, which are used with COLOR) for blinking colors?

Expected output is 1, 220, 2, 220, 3, 220.......15, 220, 16, 220, 17, 220, 18, 220 to 31, 220. But program output is different. Why? It is again something with BIT operations? Or is it a resolution (fixed colors are 0 to 15, blinking from half, 128 to 143?)

Color 7 for empty places in text mode is correct, because in mode 0 just foreground can be set and Color 7 is _DEFAULTCOLOR for Screen 0.

Code: QB64: [Select]
  1. img = _NEWIMAGE(60, 30, 0)
  2. _DEST img
  3. FOR o = 0 TO 25
  4.     COLOR o
  5.     PRINT CHR$(220);
  6. FOR o = 27 TO 31
  7.     COLOR o
  8.     PRINT CHR$(220);
  9. SCREEN img
  10. PRINT "   Text screen contains color values 0 to 31. Press key..."
  11.  
  12. m = _MEMIMAGE(img) 'text screen: Character code (_UNSIGNED _BYTE), Character Color (_UNSIGNED _BYTE)
  13.  
  14. FOR Code = 0 TO 60 * 30
  15.     C = _MEMGET(m, m.OFFSET + Code, _UNSIGNED _BYTE)
  16.     PRINT LTRIM$(STR$(C)); ", ";
  17.     SLEEP
  18.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Blinking colors code on text screen
« Reply #1 on: November 15, 2019, 11:30:35 am »
SCREEN 0 has 2 bytes of information for each character on the screen.  One is the ASCII value of the character, the other is the color.

Color is an ASCII value from 0-255..
Foreground color is the first 4 bits, background is the next 3 bits, blinking is the last bit.

00000000 — black on black
10000000 — blinking black on black
01110000 — black on white
11110000 — blinking black on white

*Note:  This is all from memory and order might be reversed, but from what I remember, the principle is there...

I did a tutorial on all this before.  Let me see if I can dig it up once again.  There’s a few simple formulas you can use to get your values, if I can remember them.

Blink = COLOR \ 128
Foreground = Color MOD 16
Background = (Color - 128 * Blink) \ 16

^Those are my guess at the formula, but without testing them with code, I won’t swear they’re 100% correct...  I just took my pills for the day a while ago at breakfast, and I can tell my brain is all fogged up from them.  Give me a few hours for them to settle, and I’ll either hunt down my old tutorial or else work the values out again for you in a demo.  ;)

EDIT:

Note 2: If blinking is off, that last bit is used for extended colors, so you can have 16 foreground, 16 background colors.

Note 3:  To make the value, the color is Blink + 16 * Background + Foreground.
« Last Edit: November 15, 2019, 11:36:45 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Blinking colors code on text screen
« Reply #2 on: November 15, 2019, 11:42:00 am »
Yeah, you're right! I don't know why, but somehow I caught mistakes in setting the background color, which led me to misjudgment. Really. Information on both colors must be set in one byte. Yes. Please wait for the release of the program, I have to figure it out myself once. Thank you! :)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Blinking colors code on text screen
« Reply #3 on: November 15, 2019, 03:23:55 pm »
Testing it, I was right earlier (which is actually surprising as I get soooo many things backwards, or slightly jumbled up, for a few hours after I take my stinking pills).  Here's the briefest of code to show you how the colors are encoded in SCREEN 0:

Code: QB64: [Select]
  1. m = _MEMIMAGE(0)
  2.  
  3. COLOR 15 + 16, 3
  4. PRINT "A"
  5. _MEMGET m, m.OFFSET + 1, b
  6. COLOR 15, 0
  7.  
  8. PRINT "foreground", b MOD 16
  9. PRINT "background", b \ 16 MOD 8
  10. PRINT "blink", b \ 128
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Blinking colors code on text screen
« Reply #4 on: November 15, 2019, 06:27:24 pm »
Just a side note: you can disable blinking to enable high intensity bg colors in SCREEN 0 with _BLINK http://www.qb64.org/wiki/BLINK
« Last Edit: November 15, 2019, 06:41:23 pm by FellippeHeitor »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Blinking colors code on text screen
« Reply #5 on: November 16, 2019, 04:01:49 am »
Thank you, Fellippe.