Shop OBEX P1 Docs P2 Docs Learn Events
Help with arrays of bytes, Graphics.spin and pointers please. — Parallax Forums

Help with arrays of bytes, Graphics.spin and pointers please.

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:
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

  • Doh! I'm using the same pointer twice.

    Dunce's cap on.
  • ElectrodudeElectrodude Posts: 1,657
    edited 2016-05-12 15:57
    Most, if not all, methods in graphics.spin, including gr.text, return as soon as the graphics cog reads the operation but before it actually finishes the operation. Your bytefill and bytemove are overwriting the scratchpad before the graphics cog ever gets around to reading it for the first gr.text.

    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:
    PUB wait
    
    '' Wait for previous command to finish
    
        setcommand(_loop, 0)                                  'make sure last command finished
    

    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.
  • Brilliant.

    Thanks for the information. That will help keep things simpler than I thought I was going to have to make them. Phew!
Sign In or Register to comment.