Shop OBEX P1 Docs P2 Docs Learn Events
vga_512x384_bitmap_DEMO — Parallax Forums

vga_512x384_bitmap_DEMO

PrincPrinc Posts: 12
edited 2013-11-15 08:32 in Learn with BlocklyProp
Hi,

i would like to ask someone about vga_512x384_bitmap_DEMO.
I don´t understand why the pixels which make the plot are different color from background.
In driver there is probably explenation in the paragraf ColorPtr but i don´t understand to it.

So i would like to know how it works with colors and pixels in the driver.

Thanks a lot for reply

Princ

Comments

  • potatoheadpotatohead Posts: 10,261
    edited 2013-11-13 09:28
    In that driver, there are tiles. Each tile is 32 pixels by 32 pixels, I think. it might be 16. Been a long time since I ran that one.for
    For each tile there is a color palette..

    I'll go and fetch that one and take a quick look.

    Edited to reflect post below.
  • potatoheadpotatohead Posts: 10,261
    edited 2013-11-13 09:43
    From the driver comments: 512x384_Bitmap (the driver)
    '' This object generates a 512x384 pixel bitmap, signaled as 1024x768 VGA.
    '' Each pixel is one bit, so the entire bitmap requires 512 x 384 / 32 longs,
    '' or 6,144 longs (24KB). Color words comprised of two byte fields provide
    '' unique colors for every 32x32 pixel group. These color words require 512/32
    '' * 384/32 words, or 192 words. Pixel memory and color memory are arranged
    '' left-to-right then top-to-bottom.
    
    

    So we know there are 192 words that contain the color bytes for the tiles. And we know they are arranged sequentially growing upward in the HUB memory, first word = upper left, second word = second tile from upper left, continuing through line by line until the last word = lower right tile.

    The color bytes themselves only reference about 64 colors and this is because the Propeller VGA only has a couple of bits per color. Lower numbers = VGA colors.

    From the driver comments:
    PUB start(BasePin, ColorPtr, PixelPtr, SyncPtr) : okay | i, j
    
    '' Start VGA driver - starts a COG
    '' returns false if no COG available
    ''
    ''     BasePin = VGA starting pin (0, 8, 16, 24, etc.)
    ''
    ''    ColorPtr = Pointer to 192 words which define the "0" and "1" colors for
    ''               each 32x32 pixel group. The lower byte of each word contains
    ''               the "0" bit RGB data while the upper byte of each word contains
    ''               the "1" bit RGB data for the associated group. The RGB
    ''               data in each byte is arranged as %RRGGBB00 (4 levels each).
    ''
    ''               color word example: %%0020_3300 = "0" = gold, "1" = blue
    ''
    ''    PixelPtr = Pointer to 6,144 longs containing pixels that make up the 512 x
    ''               384 pixel bitmap. Longs' LSBs appear left on the screen, while
    ''               MSBs appear right. The longs are arranged in sequence from left-
    ''               to-right, then top-to-bottom.
    ''
    ''     SyncPtr = Pointer to long which gets written with non-0 upon each screen
    ''               refresh. May be used to time writes/scrolls, so that chopiness
    ''               can be avoided. You must clear it each time if you want to see
    ''               it re-trigger.
    
      'if driver is already running, stop it
    
    

    The value ColorPtr holds the address of the color words. At that address you will find the first color word which is the upper left tile.

    We can also see the lower numbered byte is the background, or "0" color, and the upper byte has the foreground, or "1" color.

    The format for color bytes is: %RRGGBB00, so I was wrong about it. Higher numbers = VGA colors. Oh well. There are 4 levels for R, G, and B, two bits each.

    From the demo code: 512x384_Bitmap_Demo
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      tiles    = vga#xtiles * vga#ytiles
      tiles32  = tiles * 32
    
    
    OBJ
    
      vga : "vga_512x384_bitmap"
    
    
    VAR
    
      long  sync, pixels[tiles32]
      word  colors[tiles]
    
    

    Here we see the length of the color array defined by:
      tiles    = vga#xtiles * vga#ytiles
      tiles32  = tiles * 32
    
    

    And the color array defined here:
      word  colors[tiles]
    

    So then, to change the first tile to black and white:

    Lower byte = black = %00_00_00_00 R= 00, B= 00, G= 00

    Upper byte = white = %11_11_11_00 R=11, B=11, G=11

    Use the statement
    colors[0] = %11_11_11_00_00_00_00_00
    

    From there, you can simply index into the colors array with "colors[x]" where x is the tile number as defined above. if you see success with the upper left tile, go ahead and set a bunch of them with something like:
    repeat i from 0 to 20
      colors[i] := %11_11_11_00_00_00_00_00
    

    And you are on your way!

    I'm not where I can run this, but I should be really close based on reading this driver. Close enough you can tell me what I got wrong when I read this later on. :)
  • potatoheadpotatohead Posts: 10,261
    edited 2013-11-13 10:13
    The two lower bits in a color are sync bits. Be sure and keep those set to 0, or your display may not sync properly.
  • PrincPrinc Posts: 12
    edited 2013-11-15 06:01
    Thanks a lot for great tutorial.
    I got it but i miss one last thing. In the demo there is a plot how the plot is connected witch colors?.
    I think but i´m not sure if we make the pixel high it is executed like a "foreground" ?
    So for example:


    repeat i from 0 to tiles -1
    colors := %11_11_11_00_00_00_00_00

    pixel[1] = %1

    it will make one pixel white and other pixels black ?
  • PrincPrinc Posts: 12
    edited 2013-11-15 08:27
    I solved it thanks :smile:
  • potatoheadpotatohead Posts: 10,261
    edited 2013-11-15 08:32
    Cool. Glad you got it all working.
Sign In or Register to comment.