Put Graphics bitmap in VAR section - ran into trouble.
Howdy all -
I am using the Graphics object and it seems to work well as long as I set up the bitmap pointer to an unused area of memory.· However, I would like to keep better tabs on how much memory I have, so I decided to define the bitmap in the VAR section like so:
· long· display_base[noparse][[/noparse]x_tiles * y_tiles * 16]
Then, when initalize the screen, I use code similar to the Graphics Demo, except instead of "display_base" I'm using "@display_base".
Also, when I start the graphics object, I do it like this:
· gr.start
· gr.setup(x_tiles, y_tiles, 0, 0, (@display_base))
Now, everything that I draw on the screen seems to be misaligned down in the Y direction, and I get garbage in the upper LH corner.· When I change it back to the way it is in the Graphics Demo, everything works normally.
Am I missing something important?
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
I am using the Graphics object and it seems to work well as long as I set up the bitmap pointer to an unused area of memory.· However, I would like to keep better tabs on how much memory I have, so I decided to define the bitmap in the VAR section like so:
· long· display_base[noparse][[/noparse]x_tiles * y_tiles * 16]
Then, when initalize the screen, I use code similar to the Graphics Demo, except instead of "display_base" I'm using "@display_base".
Also, when I start the graphics object, I do it like this:
· gr.start
· gr.setup(x_tiles, y_tiles, 0, 0, (@display_base))
Now, everything that I draw on the screen seems to be misaligned down in the Y direction, and I get garbage in the upper LH corner.· When I change it back to the way it is in the Graphics Demo, everything works normally.
Am I missing something important?
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Comments
Try the @@ operator thus:
gr.setup(x_tiles, y_tiles, 0, 0, (@@display_base))
I've a color lookup table in one of my programs that does this consistently.
More on run time address -vs- compile time address in Prop Manual p. 279
Edit: What I don't always know is when and why this occurs. In my programs, I don't generally have trouble referencing the display buffer with @. It is the first VAR defined, and run time seems to match compile time addressing. The CLUT is defined in DAT statements and does appear to have different run time -vs- compile time addressing.
Edit: My display buffer does not suffer from this particular alignment issue either. It just starts on a long, and is linear addressed, no tiles.
It's not come up again, so I've not dug any deeper.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
Post Edited (potatohead) : 8/23/2007 12:36:08 AM GMT
No this a complete misunderstand!
Yes, it is an alignment problem, but must be fixed differently.
display_base MUST be aligned to 16 longs (i.e. its address must be a multiple of 64)
There are two or three possibilities for this...
Simplest:
Let's have at it! I need to know why one cannot just use @@ for that condition.
Apologies to Ken, if this is a sidetrack.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
My post above then is bad practice. And it's not gonna work.
On that padding then, the order of things must also be considered. Do that first, then define all the other stuff, such that the padding is doing a known thing; otherwise the starting address could be any long and could then run afoul of the boundary / page problem right?
That makes the assumption the variable address allocation starts on a boundary that fits in the first place. Does it always do this?
If not, then wouldn't a more robust solution be to allocate the amount necessary for the display buffer, plus at least 16 extra longs? From there, the address can be obtained, the boundary compatible one computed, then passed to the TV driver.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
Post Edited (potatohead) : 8/23/2007 12:42:23 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
He's spot on right.
Just do it first, unless I'm missing some other key SPIN thing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Your (second) ideas are generally correct. It is a matter of whether to pad "in front" or "behind". Both works. The trick is, when you need - say - N cells you have to allocate N+15.
It depends now on what you choose as a "starting" point. Using the address of Nplus15 you have to compute
(@Nplus15+15)<<6>>6 which is absolutely fine
My solution it second class, insofar it needs two names and the construction is in danger to be misunderstood. In fact a "good" compiler would even issue a warning ("Array PADDING not used!") I just saved the "+15"
But I think I said :"There are two or three solutions..."
Just wanted to make sure I grokked it.
...and that only applies to the Reference Parallax driver. Others, who may use different addressing schemes, may not have that limitation, or others!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
It is an ugly left over from using the ROM font. This is fine aligned to 32 k (so we can consider ourselves happy they took not THAT alignement
As the colourtables were constructed to consist of 16 bit words, they decided to use 64 colors, and leave 10 bits for the address...
Graphics adopted this concept...
But these are just software constraints, the video logic takes any long...
And·- found two great tutorials. So first of all my deepest appreciation and respect·to deSilva for machine language tutorial (just started, and it's a great read) and to Potatohead for the 'beginner's' staff (this one is not that·useful for me personally now, but I wish I had it in my starting·days long time ago). It's unbeleivable amount of work and service to all of us. If I would be in IRS, I·definetely let you write it as a tax deductible donation for the·total taxes amount for the whole year·
Ok, now to the current problems. I·am also confused with all this alignment problem resolutions. I have a text tv program with custom 4-color font·(I did it in order to simplify black border implementation). Screen is 32 (or 30) x 13, font is currently just alphabet, numbers and space.
Anyway, it displays ok when line 1 contains certain amount of characters·(in my case 26). If I add a character to the first line or put any characters to other lines, it·displays characters, which consist of two repeated vertically lower parts of a font characters.
So its like this:
As far as I understand, the font in this case should be aligned to 128 bytes boundary. Is it right ?
Will highly appreciate all and any advices.
Gennady
I do not see how you use user_fontbase, but
is not consistent. After you move your font up the memory you have to use its new address.
It is better style to make this explicit, i.e. define a variable
BTW: It's not only Paul's advice but also mine - I remember I posted it an hour earlier, but my reputation was not existent at that time
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
I am well aware what the driver expects!
But I did not spot that Gennady was alligning to 128 rather than 64. 128 is not strictly necessary, but it will do no harm, IF you compute your user_fontbase correctly.
I flopped with >>6<<6 it has to be >>7<<7 for this case!
So the simplest fix for Gennady would be to set
But I think it would be cleaner to follow aditionally my original proposal.
it's fixed.
Thanks a lot (and I do need to go into details of it one time :-( )
Gennady