PDA

View Full Version : Need some help with a VGA driver



Oldbitcollector (Jeff)
01-01-2009, 01:36 PM
I've been working with the vga_1280x1024_tile_driver_with_cursor driver
in an effort to create a VGA text driver which is mostly compatible with AiGeneric.


I've been able to accomplish most of what I'm shooting for with two exceptions.

1) I can't figure out how to control the background color. Ideally it should be black.

2) I can't figure out how to add additional text colors.



I suspect I'm misunderstanding the way this driver handles color.
Could someone throw me a few clues? --Code attached.

OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?

Check out: Protoboard Introduction (http://jeffledger.googlepages.com/Protoboard_Introduction.pdf) , Propeller Cookbook 1.4 (http://ucontroller.com/Propeller%20Protoboard%20Designs%20for%20the%20Beg inner.pdf) & Software Index (http://forums.parallax.com/showthread.php?p=770318)
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us (http://propeller.warrantyvoid.us)
Got an SD card connected? - PropDOS (http://www.orrtech.net/propdos/)

Post Edited (Oldbitcollector) : 1/1/2009 7:04:26 PM GMT

johnfl68
01-01-2009, 02:16 PM
First - look at this page:

http://www.rayslogic.com/propeller/Programming/Colors.htm

As I recall the first color of the of the set of 16 longs (8 colors in sets of 2) is the the main background (I think). Then the next 4 single longs are text colors.

If I didn't get that quite right, at least this should help get you a bit closer until someone else chimes in. As I recall it never really did quite what I expected, and I had to play around a bit to get things to work as expected.

John

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Whistler: I want peace on earth and goodwill toward men.
Bernard Abbott: We are the United States Government! We don't do that sort of thing.
Sneakers (1992)

potatohead
01-01-2009, 02:22 PM
This is Parallax style color. It's kind of like the C64, where there is a color memory. Look at the array referenced by:

'' color_ptr = Pointer to 64 longs which will define the 64 color palettes. The RGB data
'' in each long is arranged as %%RGBx_RGBx_RGBx_RGBx with the sub-bytes 3..0
'' providing the color data for pixel values %11..%00, respectively:
''
'' %%3330_0110_0020_3300: %11=white, %10=dark cyan, %01=blue, %00=gold

(That's from the VGA driver code)

Each element of that array will contain the colors for each of the character cells. I think the first element will do the border. I don't have a VGA, so you will have to tinker with this a bit.


Edit: These are the palettes you will choose from in the next array. Any colors you want to appear on screen, must appear here.



BTW: The other major array is the tiles array. It's defined and referenced in a fashion similar to the color array. Each element there points that tile to a specific address. In the case of this driver, it's the Propeller ROM.

If you want to redefine a character, you can point that tile to a character that exists in HUB memory, and you can have as many of those as you want to. Just build it up, 16 longs tall, and point a tile to it. You then will see it on the screen.

On this driver, there is no one background color. EACH tile has four addressable colors, and the long associated with the tile holds them.

Finally, Chip encoded TWO characters per tile address. One is defined with color 01, and the other one with color 10 binary. Have to be careful with that, or you will see a mess! one color is left unused, for a mouse pointer or something that could be done with redefined characters. (outside the scope of your question!)

If you want to set the background to a specific color, you would then loop through the colors array, setting the byte to the background color value you want. Same for any specific character color, or to change characters by color.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
Chat in real time with other Propellerheads on IRC #propeller @ freenode.net (http://propeller.wikispaces.com/Join+us+on+IRC%21/)
Safety Tip: Life is as good as YOU think it is!

Post Edited (potatohead) : 1/1/2009 7:50:02 AM GMT

potatohead
01-01-2009, 02:24 PM
One other thing that's really different from AiGeneric, for example, is that there really isn't a screen RAM with characters in it. That's the tiles array, and what happens is a character number is multiplied by 16, then added to the beginning of the ROM character set, and that address is stored in the tiles array so the driver can just pick it up and read the pixel data from the ROM directly.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
Chat in real time with other Propellerheads on IRC #propeller @ freenode.net (http://propeller.wikispaces.com/Join+us+on+IRC%21/)
Safety Tip: Life is as good as YOU think it is!

potatohead
01-01-2009, 02:34 PM
Arrgh!!! Forgot a step!

You need to look in your HYDRA book, or in the sample chapters posted online also!

'' array_ptr = Pointer to 5,120 long-aligned words, organized as 80 across by 64 down,
'' which will serve as the tile array. Each word specifies a tile bitmap and
'' a color palette for its tile area. The bottom 10 bits of each word hold
'' the base address of a 16-long tile bitmap, while the top 6 bits select a
'' color palette for the bitmap. For example, $B2E5 would specify the tile
'' bitmap spanning $B940..$B97F ($2E5<<6) and color palette $2C ($B2E5>>10).

This is also from the VGA driver code you linked here.

Ok, so this is essentially the "screen" memory. The colors array holds the possible colors to be used with the tiles. Whatever you put into there is what you can use on the screen in combinations.

The bottom 10 bits hold the address, which is shifted left to form a 16 bit ROM address by the driver. This saves RAM in the screen memory. The upper 6 bits then are an index into the colors array, to select sets of colors for that particular tile. That's the link I forgot above.


Edit: These 6 bits index the colors array discussed above. For each character then, you use one of the defined palettes. It is possible to define these while the driver is running too, so you are not locked in at driver start. The driver reads them from the HUB while it's drawing the screen.

You've got 64 pallette entries. At least one of them is sync and overscan. You'll have to look or plug in some test values to find out!

Say that's 60 left.

You can then come up with 60 color combos for the driver! Remember colors 01 and 10 binary do reference different characters, so you have to double up your background color combos. I mean pixels 01 and 10 binary. Those are pixels 1 and 2 out of the four possible. This all works in 2 bits per pixel color, if that was not clear.

If you want it to be black, then you would have black + one entry each for the 16 text colors you want and each of those 16 assigned to pixel color %01, then do it again for pixel %10. There are 512 characters possible with this scheme, including the schematic symbols. So, that's a total of 32 entries for a black background, plus the 16 colors for both sets of chars!

Whew!

I think that's it now...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
Chat in real time with other Propellerheads on IRC #propeller @ freenode.net (http://propeller.wikispaces.com/Join+us+on+IRC%21/)
Safety Tip: Life is as good as YOU think it is!

Post Edited (potatohead) : 1/1/2009 7:51:18 AM GMT

mynet43
01-01-2009, 10:53 PM
Happy New Year!

We had a thread going a few days ago about the VGA_1024 driver.

I added some routines to it that seem like they might work for some of what you're trying to do now.

I'm considering posting this to the OBX.

Here are the new calls added to VGA_1024_test3.spin:




' Change screen background and foreground (text) color in real time
vga.color($2840) ' where the upper byte is the background color (RRGGBB00) and the lower byte is the foreground RGB color.

' Change screen foreground (text) color in real time
vga.screentextcolor(TextColor) ' uses last byte for text color (RRGGBB00)

' Change screen background and foreground (text) color for one row in real time
vga.rowcolor(ColorVal, row) ' ColorVal is the same as described above, a word with two RGB values. Row = {0,1,...63}

' Change foreground (text) color for one row in real time
vga.rowtextcolor(TextColor, row) ' row = {0,1,...,63}




Let me know what you think.

Jim

Oldbitcollector (Jeff)
01-01-2009, 11:02 PM
@John:
Thanks! Now those tools on Ray's site are starting to make sense!

@Doug:
That's a lot of information to digest.. I'll spend some time with it!
Thank You!!

@Jim:
Yes, you've noticed that I've jumped drivers in an attempt to get some
features that I couldn't achieve with the first one, namely the ability to
change text colors on a single row, instead of being limited to one.

Next to the Propeller itself, the forum is one of the best products that
Parallax has! Perhaps I will finally wrap my head around some of
these video concepts I've been grappling with. Might have a couple
more questions, but it looks like I've got some homework to do first.

Thanks guys!

OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?

Check out: Protoboard Introduction (http://jeffledger.googlepages.com/Protoboard_Introduction.pdf) , Propeller Cookbook 1.4 (http://ucontroller.com/Propeller%20Protoboard%20Designs%20for%20the%20Beg inner.pdf) & Software Index (http://forums.parallax.com/showthread.php?p=770318)
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us (http://propeller.warrantyvoid.us)
Got an SD card connected? - PropDOS (http://www.orrtech.net/propdos/)

potatohead
01-02-2009, 01:07 AM
Jeff, I re-read that crap this morning.

It takes two values being changed to get to a color on screen. I'm probably digging a hole, but here is how things go, so you can follow through the code and get your changes done. Nothing needs to be changed at the PASM level.

The driver reads the array for the screen. That's the second one I referenced above. In that word, there are 16 bits. It takes the lower 10, shifts them right 6 bits to realize the character address. I have it wrong above. You put the ROM address directly into the screen array, not some simple character number. In the SPIN program, it's pretty easy to just take the value that represents the character and multiply and add the base ROM address to get the actual address needed for the driver. So that's half of it. Now we've got pixels to put on screen, but what color are they?

The upper 6 bits of that word are shifted left 2 bits to form a long index address. This is added to the base address of the colors array of 64 longs. That gets fetched too. Now, we've got the other half of the data needed for a waitvid.

A waitvid needs two longs, one for all the pixels, the other for all the colors. (Well, that's true for how it's done in this driver anyway)

All of that forms one tile, 16 pixels x 32 pixels, for a character on the graphics screen. Each char definition is then 128 bytes.

So then, put the colors you plan on using into colors array, and put the index of that array element containing your colors into the upper screen memory bits as just a value, like you would in spin, and your colors will appear in that character cell / tile.

I did a poor job of detailing the interleaved characters also.

Basically, this driver runs at 2 bits per pixel. So that's binary 00, 01, 10, 11. If it helps to think of it this way, colors 0, 1, 2, 3, for a total of 4 possible colors. Color 0 is the background. Color 1 is one character, color 2 is another different one, and color 3 is shared by both! (I got that wrong above too)

So that's the last piece of the puzzle. If you want to assign a character a given color, you then make an entry in the colors array that has that combination, then put the index value to it in the screen array (and that's the second one I referenced) upper 6 bits, and that particular character will display, in that cell, with your color! The other character color should be set the same as the background. Color 3 will be set to the same value as you set to either color 2 or 1, depending on the character you want to see.

If you want to redefine a character, like AiGeneric does, you will have to create another array, maybe called characters. That one is organized as 16 longs per character times the number of alternative characters you plan to allow for. You can have as many as you want, limited by the system RAM. Each cell or tile on the screen is a little mini 16x16 graphics screen then. Either it points to ROM, or RAM, your call for each one. When a custom character needs to appear on screen, you simply put the address of it into the screen array and it will appear at that location of the screen.

Custom characters can use all three foreground colors, BTW! There is no one color per visible text character restriction, because there is no interleaved character data. Because of the interleave, text characters are two colors only. Custom ones are 4 color.

There is one restriction on RAM character addresses. They must be aligned on even 64 byte boundaries because of how the screen array addressing is done. The lower 6 bits are always zero.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
Chat in real time with other Propellerheads on IRC #propeller @ freenode.net (http://propeller.wikispaces.com/Join+us+on+IRC%21/)
Safety Tip: Life is as good as YOU think it is!

Post Edited (potatohead) : 1/1/2009 6:41:58 PM GMT

Oldbitcollector (Jeff)
01-02-2009, 02:04 AM
Doug,

It'll take me a while to swallow the math, but I'm starting to get a good handle
on the driver itself. Ray's information is also worth it's weight in gold.

I updated the top thread with a corrected {however unfinished} version which
I hope will help someone else.

OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?

Check out: Protoboard Introduction (http://jeffledger.googlepages.com/Protoboard_Introduction.pdf) , Propeller Cookbook 1.4 (http://ucontroller.com/Propeller%20Protoboard%20Designs%20for%20the%20Beg inner.pdf) & Software Index (http://forums.parallax.com/showthread.php?p=770318)
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us (http://propeller.warrantyvoid.us)
Got an SD card connected? - PropDOS (http://www.orrtech.net/propdos/)