Help with arrays of bytes, Graphics.spin and pointers please.
Hugh
Posts: 362
in Propeller 1
Hi,
Please would someone be kind enough to explain where I might be going wrong with some code?
- I am displaying text on a TV using "Graphics.spin" from the Propeller library to do so.
- Two global arrays of bytes, 'scratchpad' and 'dataGPS' have been declared in a VAR block, each having length of 80 bytes.
- 'dataGPS' is filled with data that I know is correct and is not being changed by anything else.
- I wish to display as text subsections of 'dataGPS'.
The relevant code is:
What results is the same text being displayed twice rather than two different sections of 'dataGPS'.
Any suggestions would be gratefully received.
Thanks
Hugh
Please would someone be kind enough to explain where I might be going wrong with some code?
- I am displaying text on a TV using "Graphics.spin" from the Propeller library to do so.
- Two global arrays of bytes, 'scratchpad' and 'dataGPS' have been declared in a VAR block, each having length of 80 bytes.
- 'dataGPS' is filled with data that I know is correct and is not being changed by anything else.
- I wish to display as text subsections of 'dataGPS'.
The relevant code is:
bytefill(@scratchpad, 0, 80) ' Empty the "scratchpad" array of bytes bytemove(@scratchpad, @dataGPS +6, 6) ' Copy six characters from "dataGPS" to "scratchpad", starting at item 6 gr.text(-100, 0, @scratchpad) ' Display the contents of "scratchpad" using the .text method of 'Graphics.spin' bytefill(@scratchpad, 0, 80) ' Empty the "scratchpad" array of bytes bytemove(@scratchpad, @dataGPS + 12, 6) ' Copy six characters from "dataGPS" to "scratchpad", starting at item 12 gr.text(-100, 65, @scratchpad) ' Display the contents of "scratchpad" using the .text method of 'Graphics.spin' gr.copy(display_base) 'Display results on TV
What results is the same text being displayed twice rather than two different sections of 'dataGPS'.
Any suggestions would be gratefully received.
Thanks
Hugh
Comments
Dunce's cap on.
You can still use the same pointer twice if you stick a graphics.spin call in between your first call to gr.text and the bytefill and bytemove after this. If you don't have anything to draw in between the first gr.text and the following bytefill and bytemove, you could do gr.color(currentcolor) as a dummy operation. The inserted call won't return until after the first gr.text completes and the next command is read, at which point you can safely reuse the scratchpad buffer.
You could also add this method to graphics.spin, which doesn't actually do anything but waits for the previous operation to finish:
Note that methods like gr.setup, gr.clear, and gr.copy that need the graphics cog to be idle before they can do their stuff do the same thing as this wait method.
Thanks for the information. That will help keep things simpler than I thought I was going to have to make them. Phew!