Shop OBEX P1 Docs P2 Docs Learn Events
Trouble using Graphics.Spin — Parallax Forums

Trouble using Graphics.Spin

Keith YoungKeith Young Posts: 569
edited 2011-01-26 22:50 in Propeller 1
I am trying to use Graphics.Spin in my own program. I can run the demos fine, but when I try to copy their method of running Graphics I just can't seem to get it right. One issue I am having which may be the problem is I run out of space in the prop when I use _stack = ($3000 + $3000 + 100) >> 2

so I've been using _stack= ($2000 + $2000 + 100) >> 2

Other than that, I've copied the constants, variables, initialization, and tvparams.

Any big reason why this won't work? I can get Tv_Text to work but I need graphics in addition to text.
CON
  _clkmode  = xtal1 + pll16x
  _xinfreq  = 5_000_000
  _stack = ($2000 + $2000 + 100) >> 2   'accomodate display memory and stack 
  ADC_dpin  = 1
  ADC_cpin  = 2
  ADC_spin  = 0
  rudderc   = 0
  aileronc  = 1
  elevatorc = 2
  throttlec = 3                
  XB_RX     = 8
  XB_TX     = 9
  XB_Mode   = 0
  XB_Baud   = 9600
  TV_Start  = 16
 
  x_tiles = 16
  y_tiles = 12
  paramcount = 14       
  bitmap_base = $2000
  display_base = $5000
  lines = 5
  thickness = 2
 
 
 
OBJ
  XB    : "XBee_Object_2"             
  AD    : "MCP3208_fast_ADC"
  'TT    : "TV_Keith"          
  GR    : "Graphicsb"
  'GK    : "Graphics_Keith"
  TV    : "TV"
  NU    : "Numbers"
 
VAR
 
  long cog, Shared
  word rudder, aileron, elevator, throttle, DataIn, commy, clownt   
  long stack[256]
 
 
  long  tv_status     '0/1/2 = off/visible/invisible           read-only
  long  tv_enable     '0/? = off/on                            write-only
  long  tv_pins       '%ppmmm = pins                           write-only
  long  tv_mode       '%ccinp = chroma,interlace,ntsc/pal,swap write-only
  long  tv_screen     'pointer to screen (words)               write-only
  long  tv_colors     'pointer to colors (longs)               write-only               
  long  tv_hc         'horizontal cells                        write-only
  long  tv_vc         'vertical cells                          write-only
  long  tv_hx         'horizontal cell expansion               write-only
  long  tv_vx         'vertical cell expansion                 write-only
  long  tv_ho         'horizontal offset                       write-only
  long  tv_vo         'vertical offset                         write-only
  long  tv_broadcast  'broadcast frequency (Hz)                write-only
  long  tv_auralcog   'aural fm cog                            write-only
  word  screen[x_tiles * y_tiles]
  long  colors[64]
 
 
PUB Start | i, dx, dy, clk_scale,d,e,f,fdeg,Offset,Bar,dx1,dy1,dx2,dy2,cordlength,size
 
  XB.Start( XB_RX, XB_TX, XB_Mode, XB_Baud)   
  AD.Start(ADC_dpin, ADC_cpin, ADC_spin, 0)
  cognew(@entry, @Shared)
  cognew(Check, @stack[0])                                    
  'TT.Start(TV_Start)
 
  longmove(@tv_status, @tvparams, paramcount)
  tv_screen := @screen
  tv_colors := @colors
  tv.start(@tv_status)
  'init colors
  repeat i from 0 to 63
    colors[i] := $9D_07_1C_02
  'init tile screen
  repeat dx from 0 to tv_hc - 1
    repeat dy from 0 to tv_vc - 1
      screen[dy * tv_hc + dx] := display_base >> 6 + dy + dx * tv_vc + ((dy & $3F) << 10)
  'start and setup graphics
  gr.start
  gr.setup(16, 12, 128, 96, bitmap_base)      
  cognew(GUI, @stack[128])
 
  repeat                                 
    XB.Str(String("!"))
    XB.Dec(Shared)
    XB.Str(String(","))
    XB.Dec(rudder)
    XB.Str(String(","))
    XB.Dec(aileron)
    XB.Str(String(","))
    XB.Dec(elevator)
    XB.Str(String(","))
    XB.Dec(throttle)   
    XB.CR
    waitcnt(clkfreq / 50 + cnt)                             
 
Pub Check
  dira[26]~~
  outa[26]~   
  repeat
    !outa[26]           
    rudder   := AD.In(rudderc)
    aileron  := AD.In(aileronc)
    elevator := AD.In(elevatorc)
    throttle := AD.In(throttlec)
    if shared & butt1 == butt1 'One way to check a certain button
      outa[ 3]~~
PUB GUI  | shareds, rudders, ailerons, elevators, throttles
 
 
  dira[27]~~
  outa[27]~
  dira[26]~~
  outa[26]~
  !outa[27]
 
  GR.Textmode(1,1,6,5)
  GR.Colorwidth(2,0)
  repeat
    GR.Clear              
    GR.Text(-90,50,"D")        
    {{TT.Str(String("    ",$A,3,$B,1,"Button  :"))
    TT.Dec(shared)
    TT.Str(String("    ",$A,3,$B,2,"Rudder  :"))
    TT.Dec(rudder)
    TT.Str(String("    ",$A,3,$B,3,"Aileron :"))
    TT.Dec(aileron)
    TT.Str(String("    ",$A,3,$B,4,"Elevator:"))
    TT.Dec(elevator)
    TT.Str(String("    ",$A,3,$B,5,"Throttle:"))
    TT.Dec(throttle)
    'TT.Str(String("    ",$A,3,$B,6,"Phail   :"))
    'TT.Dec(phail)
    'TT.Str(String("    ",$A,3,$B,8,"Debug   :"))
    'TT.Str(error)}}                           
 
DAT         
          ' ORG      0
 
tvparams                long    0               'status
                        long    1               'enable
                        long    %010_0000       'pins   New Demo Board
'                        long    %011_0000       'pins   Old Demo Board
 
                        long    %0000           'mode
                        long    0               'screen
                        long    0               'colors
                        long    x_tiles         'hc
                        long    y_tiles         'vc
                        long    10              'hx
                        long    1               'vx
                        long    0               'ho
                        long    0               'vo
                        long    0               'broadcast
                        long    0               'auralcog

Comments

  • potatoheadpotatohead Posts: 10,261
    edited 2011-01-26 20:58
    The demo program takes up a lot of RAM, because the display is double buffered. You can choose to cut down the graphics resolution, partial buffer the display, single buffer the display, unless you want to shrink other parts of your program. The demo eats up 24K!

    I have a single buffer version of that demo here, for the smallest RAM use case. http://forums.parallax.com/entry.php?86-Ripple-Draw Basically 12K or so.

    There is also a partial buffer version, that uses a small off-screen buffer. This is 15K or so.

    The trade off is having to manage what you draw, how you draw it, and when you draw it. The two examples are commented, and setup for demo board. Give them a look and see whether or not those techniques could render your display in considerably less HUB RAM.

    They also have color and tile comments, and a method or two to make color and tile selection easy.

    The key to this, is drawing the parts of the screen that change, and repeating that as needed to update the screen, once per strip defined.

    The video on the single buffer shows it's actually a little bit too much data. There is some flicker. Should be done with less objects in motion / changing.

    The partial can do a lot more things before breaking down.

    Both techniques trade some screen tearing and update rates for the buffer size.
  • Keith YoungKeith Young Posts: 569
    edited 2011-01-26 22:11
    This cut down the space drastically but to keep both those stack values at $3000 I think I need a second prop still lol. I gutted Graphics and I am still over by 774 longs. Plus I haven't started adding my GUI yet. Hopefully PropII has a bit more RAM...

    If I could just draw lines and maybe circles in TV_Text I think I'd be ok with 1 Prop. Just seems strange, what I'm doing isn't very complicated.
  • potatoheadpotatohead Posts: 10,261
    edited 2011-01-26 22:21
    You really only need this:

    _stack = ($3100 + 100) >> 2 'accommodate display memory and stack

    Sorry. I did not cut the stack down. Run the spin program I linked to, and edit the stack to the smaller size. That will free almost 3000. Then look at the draw methods.

    Complexity isn't the issue. Pixels take a lot of space. Two pages, as demonstrated in the graphics_demo.spin, consume 24K of the 32. Getting rid of one of those, or most of one of those will make a significant difference, leaving you to manage your graphics drawing.
  • Keith YoungKeith Young Posts: 569
    edited 2011-01-26 22:50
    It was giving me a green/yellow screen and I was having trouble getting stuff to display but after copying practically your whole 03_single into my program it's showing the demo. Looks like I'll be able to cut out the actual Prop Demo stuff and get this working!

    I really appreciate your help

    BTW ($3100 + 100) worked
Sign In or Register to comment.