Shop OBEX P1 Docs P2 Docs Learn Events
4 colors with GRAPHICS.spin? — Parallax Forums

4 colors with GRAPHICS.spin?

RinksCustomsRinksCustoms Posts: 531
edited 2007-07-22 05:42 in Propeller 1
I figured out how to produce S-video -(definetly a cleaner image), but i cannot figure out how to get more than 4 colors from graphics.spin. I've "gutted" the graphics demo to make a program, but it seems to be creating more of a problem than it's solving. I'm guessing a block of code has to be changed in the init area and also in the DAT section as well to get more than 4 colors, just don't know what to change.roll.gif
PUB init 
'init colors
  repeat i from 0 to 63
    colors[noparse][[/noparse]i] := $00001010 * (i+4) & $F + $2B060C02
 
 
 <blah, blah, setup/main code, blah, blah>
 
 
DAT
' Color codes
colors  long    %%0000000000000000
        long    %%1111111111111111
        long    %%2222222222222222
        long    %%3333333333333333

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
E3 = Thought

http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! The average PC while browsing the internet typically uses less than 30% of it's potential, why not donate a portion of the rest for cancer resaerch?

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-07-19 21:15
    There is a most instructive explanation in Andre LaMothe's recommendable book on pp 239 /240. BTW I think 90% of all questions in this forum are answered in Andre's book.

    So that you do not have to buy it smile.gif
    Color data consists of
    4 bits Chroma
    1 bit Chroma enable ("Modulation")
    3 Bits Luma

    Not all values are permitted (Luma should stick between 2 and 6 e.g.)
    The 16 Chroma values are coded along the NTCS/PAL colour wheel, e.g. 0: blue , 5: red e.t.c.


    Edit: Chroma Enable ist set to zero to generate clear gray values (e.g. luma 2: black, luma 6: white, where Chroma is ignored)

    Post Edited (deSilva) : 7/19/2007 9:25:24 PM GMT
  • RinksCustomsRinksCustoms Posts: 531
    edited 2007-07-20 00:11
    Sounds like the HYDRA book is a good investment.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! The average PC while browsing the internet typically uses less than 30% of it's potential, why not donate a portion of the rest for cancer resaerch?
  • potatoheadpotatohead Posts: 10,260
    edited 2007-07-20 02:50
    It is, no question.

    The Parallax TV driver only does 4 colors per tile. You can set these, for more than 4 colors, by changing the screen array values. There is a sample chapter here that covers that:

    http://www.parallax.com/dl/docs/prod/prop/Hydra-Ch16Sample-v1.0.pdf

    So, you are closer. Lots of colors on screen, but only 4 within one tile in particular.

    From there, you essentially need different TV driver code. With that will come changes to graphics.spin to handle the different color addressing.

    We've not seen 8, 16 or 32 color drivers written yet, but they are totally doable. I've got one that does high-color, but it consumes a lot of ram. One byte per pixel. It's decent at lower resolutions (160x96). It permits any standard propeller color at any pixel position. It can be found here, and is based on CardboardGuru's EASYNTSC driver demo example.

    http://forums.parallax.com/forums/attach.aspx?a=14813

    Read through the code header and define your horizontal resolution, vertical resolution (one scan line or two high for 96 or 192 pixels), define a screen memory area and call the driver. It does no color lookup, so it's not a bad idea to fill the screen memory area with black pixels, or whatever color you want as background first. The simple program included does this.

    Before doing too much with that driver, take a hard look at the sample chapter. 4 colors per tile is not too big of a limitation and really saves on the RAM. Depending on what you want to put onto the screen, it might work very nicely.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
  • RinksCustomsRinksCustoms Posts: 531
    edited 2007-07-20 04:20
    ah! i forgot about the chapter 16 hydra teaser. I was refering to the 4 color pallet that is only available when you call gr.color(c) or gr.colorwidth(c,w). It will only let you choose black, white, rainbow, red, or blue. My querry regaurds some cut/paste of code from graphics pallet to graphics.spin to make accessing - what was it 64 colors? - that much easier than writing a driver. I don't quite posses the knowledge yet to write my own driver.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! The average PC while browsing the internet typically uses less than 30% of it's potential, why not donate a portion of the rest for cancer resaerch?
  • potatoheadpotatohead Posts: 10,260
    edited 2007-07-20 05:03
    Actually it lets you choose from colors 0 to 3. This is important as those numbers don't directly equate to on-screen colors. (and that's the rub. Get past that, and it's largely cake from there.)

    What these colors actually end up being on screen, depends on the contents of the colors array. The key is in the rainbow color. That's really color 3, I think. (well, it's one of the 4 in any case!) Same color index, but different results on screen. All 4 colors work the same way.

    In the case of the graphics demo, this definition has been applied vertically to demonstrate more colors on screen. In a nutshell, the screen is broken up into 16 x 16 pixel tiles. Each tile gets it's four colors from the colors array.

    Parse through the portion of the graphics demo program that sets up the tiles, using that sample chapter. Or, If you want to, isolate one tile in particular and put your own color values into it. (simply choose one of the colors array elements and change it only) Redefine color 0 to change the background and verify you have the right tile. From there, you can learn how things are setup. Once you have control of that one tile, then it's no biggie to set the rest of them up the way you want.

    I think the first colors array element has the sync colors in it. Leave that one, or the first coupla of them alone. On the Propeller, some colors are actually sync signal colors! This is unlike pretty much any other graphics engine. So, a $00 for a color is not black, but blacker than black, which is actually a signal to the TV. This is what deSilva was hinting at. $02 = black.

    This is tricky, but worth it. In the end, you can make any tile display any of the standard colors, and have it display any chunk of propeller RAM. For the graphics demo, the tiles have been lined up to form a nice bitmap. They start addressing from upper left, filling horizontally, ending up at lower right. You probably want to leave the addressing alone, and setup some color constants in your program to make things easier.

    Writing your own driver is tough! I was having one heck of a time until CardboardGuru wrote his nice and simple example. Still tough, but I get more hits than strikes now.

    There is a table with color values here on this page: http://propeller.wikispaces.com/Colors

      'init colors
      repeat i from $00 to $0F
        case i
          5..10 : c := $01000000 * (i - 5) + $02020507
          other  : c := $07020504
        colors[i] := c
      repeat i from $10 to $1F
        colors[i] := $10100000 * (i & $F) + $0B0A0507
      repeat i from $20 to $2F
        colors[i] := $10100000 * (i & $F) + $0D0C0507
      repeat i from $30 to $3F
        colors[i] := $10100000 * (i & $F) + $080E0507
    
        colors[noparse][[/noparse]40] := $07_05_03_cd
    [/i][/i][/i][/i]
    



    In the colors[noparse][[/noparse]40] line, the definitions are:

    color0 = background = some purpleish color = $cd (May vary in color, depending)
    color1 = dark grey = 03
    color2 = med grey = 05
    color3 = white = 07

    Add that one line, and you should see the tile, near the middle of the screen look different from the others. I used the palette program because it would run in gear and I wanted to double check. Same approach should work for graphics_demo.spin too. Anything that uses the Parallax TV driver.


    Did your s-video circuit change from your last posting? If so, mind sharing it?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Post Edited (potatohead) : 7/20/2007 7:09:22 AM GMT
  • RinksCustomsRinksCustoms Posts: 531
    edited 2007-07-20 18:33
    The s-video out uses the identical resistors as the baseband setup, but the "aural cog" resistor is used for the chrominance signal, schematic and documentation explainging how to set pin group mode for s-video are inside this version of graphics demo, enjoy. turn.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! The average PC while browsing the internet typically uses less than 30% of it's potential, why not donate a portion of the rest for cancer resaerch?

    Post Edited (RinksCustoms) : 7/22/2007 5:49:31 AM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-07-21 04:08
    RinksCustoms said...
    Attachment:
    "...you may have to experiment with the settings. They don't make alot of sense to me, it seems that the broadcast bit and the baseband bit is reversed.
    You shouldn't say that. The settings you gave for tv_mode and tv_pins are absolutely correct amd there are no other settings (except you want to change the pin group, use PAL, need interlacing,..). All settings are correctly documented e.g. at the end of TV.SPIN and work accordingly.

    Post Edited (deSilva) : 7/21/2007 4:19:54 AM GMT
  • RinksCustomsRinksCustoms Posts: 531
    edited 2007-07-22 05:42
    good to hear that someone else got it working too. I will omit that part then, and i guess i'll have to go and re-study the driver and it's settings for the chroma, broadcast, and baseband.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! The average PC while browsing the internet typically uses less than 30% of it's potential, why not donate a portion of the rest for cancer resaerch?
Sign In or Register to comment.