Shop OBEX P1 Docs P2 Docs Learn Events
Some newbie problems with propeller, please help! — Parallax Forums

Some newbie problems with propeller, please help!

morfellumorfellu Posts: 5
edited 2007-12-18 19:57 in Propeller 1
Hey guys,

Im new to this forum and im here to find some help. Im doing a college work, its just a simple sudoku developed with the propeller.

In my main program I use the graphics, TV, mouse and keyboard objects. The problem is I think I dont have enough memory in the chip because:

If I try to run the program loading only the graphics,tv and keyboard objects, it works, but when i try to run all the 4 objects I got a black screen and nothing happens. If i load tv, graphics and mouse instead keyboard It also works ok. The problem is loading the 4 objects at once.

u think its a memory problem? Should I use any cogs?

thanks in advance and sorry my newbinessss [noparse]:([/noparse]

Comments

  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2007-12-18 11:24
    In your top level program (the one calling the drivers for the graphics, tv, keyboard, mouse) hit 'F8' in the editor so see what memory is being used. This should help give you an idea of what is available.

    I doubt you are using up the memory because there are some intense demos in the Hydra forum. Check that you are intiailizing each driver properly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter
    tdswieter.com
    One little spark of imagination is all it takes for an idea to explode
  • morfellumorfellu Posts: 5
    edited 2007-12-18 11:34
    thank you for replying so fast,

    when I hit F8 I see I have 6008 longs of free memory, so its not a memory problem?

    About initializing the drivers ..., i think im doing well because I can use them separately, but not together. I mean if I only use the keyboard i can play the sudoku with keyboard, and when I load the mouse I can also play ok. So the drivers initialize correctly, at least they do it separately.

    What can I do? I read in some other forum, that I can have free memory when I hit F8, but then In execution time you can run out of memory, could it be?
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-12-18 12:24
    can you attach your code?
  • morfellumorfellu Posts: 5
    edited 2007-12-18 12:45
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      '_free = ($3000 + $3000) >> 2          'accomodate bitmap buffers
      '_stack = $100                         'insure sufficient stack
    
      x_tiles = 16
      y_tiles = 12
    
      paramcount = 14      
      bitmap_base = $2000
      display_base = $5000
    
      CL_Black      = $02
      CL_Grey1      = $03
      CL_Grey2      = $04
      CL_Grey3      = $05
      CL_Grey4      = $06
      CL_White      = $07
      CL_Blue       = $0A
      CL_DarkBlue   = $3A
      CL_Green      = $F8
      CL_DarkGreen  = $4A
      CL_Red        = $48
      CL_Brown      = $28
      CL_Yellow     = $9E
      CL_Purple     = $88
      CL_DarkPurple = $EA
     
    VAR
    
      long  stack[noparse][[/noparse]20]
      long  mousex, mousey
      long  cog
      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[noparse][[/noparse]x_tiles * y_tiles]
      long  colors[noparse][[/noparse]64]
      long  anchura
      long  altura
    
    
    
    OBJ
    
      tv    : "tv"
      gr    : "graphics"
      mouse : "mouse"
      kb : "keyboard"
     
    PUB start | x, y, i, c, k
    
      'start tv
      longmove(@tv_status, @tvparams, paramcount)
      tv_screen := @screen
      tv_colors := @colors
      tv.start(@tv_status)
      
      SetColorPalette(0,CL_Green,CL_Red,CL_White,CL_Black)
    
      {
      'init colors
      repeat i from $00 to $3F
          'colors[i] := $00001010 * (i+4) & $F + $2B060C02
          c := $8B053C02
         'c := $07020505
        colors[i] := c   }
     
      'init tile screen
      repeat x from 0 to tv_hc - 1
        repeat y from 0 to tv_vc - 1
          case y
            0, 2 : i := $30 + x
            3..4 : i := $20 + x
            5..6 : i := $10 + x
            8    : i := x 
            other:  i := 0
          screen[noparse][[/noparse]x + y * tv_hc] := i << 10 + display_base >> 6 + x * tv_vc + y
    
      motor
         
    PRI motor
         
      'start and setup graphics
      gr.start
      gr.setup(16, 12, 0, 0, bitmap_base)
      
    
      'start mouse
      mouse.start(24, 25)
      mousex := 188
      mousey := 100                  
      'kb.start(26, 27)
      
      repeat
      
        'clear bitmap
        gr.clear
        gr.width(29)
        gr.color(3)  
          
        'calls
        dibujarTablero    'draw sudoku
        teclado           'keyboard
        raton             'mouse
    
          
        gr.color(3) 
        gr.copy(display_base)
    
    PRI raton | x, y
    
        anchura := 160 - 14                          
        altura := 188 - 44 
        gr.width(0)
        mousex := mousex + mouse.delta_x #> 0 <# 251
        mousey := mousey + mouse.delta_y #> 4 <# 191
        gr.pix(mousex, mousey, 0, @puntero)
    
        'select box with mouse
        if mouse.button(0)
          repeat y from 0 to 8
           repeat x from 1 to 9
              if (mousey < (altura/9)*(9-y)+39) and (mousey > (altura/9)*(9-1-y)+39) and (mousex > (anchura/9)*(x-1)+14) and (mousex < (anchura/9)*x+14)
                casillaX:=x
                casillaY:=y
                gr.color(1)
                gr.plot(casillaX << 4 + 7, 180 - casillaY << 4)
                               
    PRI teclado |num, x, y, error, c
    
          num:= kb.GetKey
          
          if ((num >$30 )&(num<$3A))' and (arrayJugador[noparse][[/noparse](casillaX-1)+(casillaY)*9] == "0")  'valida num
             case num
              $31 : num := "1"
              $32 : num := "2"
              $33 : num := "3"
              $34 : num := "4"
              $35 : num := "5"
              $36 : num := "6"
              $37 : num := "7"
              $38 : num := "8"
              $39 : num := "9"
             error:=0
             'Validation to draw or not the number 
            if(arraySudoku[noparse][[/noparse](casillaX-1)+(casillaY)*9] == "0")'si no es negrita
              repeat x from 3 to 11  'comprobar fila
                if(arrayJugador[noparse][[/noparse](x-1)+(casillaY)*9] == num)'and((x-1)+(casillaY)*9 <> (casillaX-1)+(casillaY)*9)'si el numero metido existe en la fila o y no es el mismo
                  error:=1
              if (error == 0)
               repeat y from 1 to 9
                 if(arrayJugador[noparse][[/noparse](casillaX-1)+(y)*9] == num)'and((casillaX-1)+(y)*9 <> (casillaX-1)+(casillaY)*9)'si el numero metido existe en la columna o y no es el mismo
                   error:=1
              if (error == 0)'comprobar bloque
               case casillaY
                 1..3 : case casillaX
                          3..5 : c:=0
                          6..8 : c:=3
                          9..11: c:=6
                 4..6 : case casillaX
                          3..5 : c:=27
                          6..8 : c:=30
                          9..11: c:=33
                 7..9 : case casillaX
                          3..5 : c:=54
                          6..8 : c:=57
                          9..11: c:=60
               repeat y from 0 to 2
                 repeat x from 0 to 2
                    if (arrayJugador[noparse][[/noparse]c+x+(9*y)] == num)
                      error := 1
    
                      
              if(error == 0)'introducir numero valido en arrayJugador
                arrayJugador[noparse][[/noparse](casillaX-1)+(casillaY)*9]:=num
               'else
                 'mensaje de error 
                                      
               
          elseif (num > $BF)&(num < $C4)   'movements with cursors
           case num
            $C0 : if(casillaX > 1)
                     casillaX:=casillaX-1
            $C1 : if(casillaX <9)
                     casillaX:=casillaX+1
            $C2 : if(casillaY > 0)
                     casillaY:=casillaY-1
            $C3 : if(casillaY < 8)
                     casillaY:=casillaY+1
          elseif (num == $C8 and (arraySudoku[noparse][[/noparse](casillaX-1)+(casillaY)*9] == "0"))   'erase number
             arrayJugador[noparse][[/noparse](casillaX-1)+(casillaY)*9] := "0"   
             
    PRI dibujarTablero | x, y
    
         repeat y from 0 to 8
          repeat x from 1 to 9
            
            gr.color(3)
             gr.plot(x << 4 + 7, 180 - y << 4)
            if ((casillaX==x) and (casillaY==y))
              gr.color(2)
              gr.plot(x << 4 + 7, 180 - y << 4)
    
    
           
        linea(160,188,160,44)
        linea(160,188,16,188)
    
        linea(14,188,14,46)
        linea(14,44,160,44)
    
        linea(63,188,63,46)
        linea(111,188,111,44)
    
        linea(159,139,15,139)
        linea(159,91,15,91)
    
        gr.colorwidth(3,14)
       ' gr.box(190,44,50,16)
        gr.colorwidth(2,0)
        gr.textmode(1,1,6,5)
        gr.text(215,52,string("ESIDOKU"))
    
    PRI numero(xn,yn, numer)
          gr.colorwidth(2, 0)
          gr.textmode(1, 1, 7, %0101)
          gr.text(xn, yn, @numer)
    
    
    PRI linea(pl1,pl2,lx,ly)
        gr.colorwidth(2,1)
        gr.plot(pl1,pl2)
        gr.line(lx,ly)
    
    
    {PRI hex(value) : chr
    
      return lookupz(value : "0".."9", "A".."F")      }
    
    Pub SetColorPalette(ColorIndex,Color1,Color2,Color3,Color4)
      colors[noparse][[/noparse]ColorIndex] := (Color1) + (Color2 << 8) +  (Color3 << 16) + (Color4 << 24)
      
    DAT
    
    tvparams                long    0               'status
                            long    1               'enable
                            long    %001_0101       'pins
                            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    60_000_000      'broadcast
                            long    0               'auralcog
    
    puntero                 word                            
                            byte    1,8,0,0
                            word    %%10000000
                            word    %%22000000
                            word    %%11100000
                            word    %%22220000
                            word    %%11111000
                            word    %%22222200 
                            word    %%11000110
                            word    %%20000022
    
    {colorstring             byte    "COLOR "                        
    hexstring               byte    "00",0      }
    
    casillaX byte 1
    casillaY byte 0  
    arraySudoku byte   "098600400000798650000000089430010060760000503902005700600829005010000302000400800"   'fixed numbers
    arrayCompleto byte "198652437324798651576143289435217968761984523982365714643829175819576342257431896"   'Complete sudoku
    arrayJugador  byte "098600400000798650000000089430010060760000503902005700600829005010000302000400800"   'Suooku to play[/i][/i]
    




    This is a preliminary version, so the sudoku game function is not yet properlly implemented, but at least I should be able to move around the cells with my mouse or keyboard!

    please help!
  • hippyhippy Posts: 1,981
    edited 2007-12-18 13:04
    morfellu said...
      '_free = ($3000 + $3000) >> 2          'accomodate bitmap buffers
      '_stack = $100                         'insure sufficient stack
    
       bitmap_base = $2000
      display_base = $5000
    
    

    Seems you are using bitmap memory but have commented out the _free which protects
    from using too much memory. What happens with _free and _stack not commented out ?
    morfellu said...
      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[noparse][[/noparse]x_tiles * y_tiles]
      long  colors[noparse][[/noparse]64]
    
    

    I don't know what parameters are required in this list but you cannot just comment them out on a whim.
  • RaymanRayman Posts: 14,162
    edited 2007-12-18 13:45
    Graphics is a resource hog.· There's not much room left over for code if you use it.· You could disable the double buffering at recovers some room for your code.· You have to be careful with Graphics because the memory space for the screen buffer isn't formally allocated.

    I have some info on Graphics here:

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

    Also, another student is doing the exact same thing· (maybe one of your classmates?).· Look here:

    http://forums.parallax.com/showthread.php?p=693838
  • morfellumorfellu Posts: 5
    edited 2007-12-18 16:42
    Hi Rayman, thank you for your help, I have a new problem....

    I have changed the bitmap_base = $5000 value, and now i can compile and execute my program with keyboard and mouse at once, but the new problem is that the screen is flickering all the time, it seems like the processor is not fast enough to do the repeat cycle and I can see the flickering? u know what I mean ? what can i do ?

    thanks in advance
  • potatoheadpotatohead Posts: 10,260
    edited 2007-12-18 16:51
    You are redrawing the entire screen every code loop cycle. That's where the flicker is coming from. Without the double buffer, this must be managed some how.

    Some options:

    1. draw only changes. Adapt your main loop to display the screen, then only draw those things that are different. For a game like this, that's a few numeric characters, which will both localize the flicker and diminish it. (probably the easiest approach)

    2. decouple the drawing from the main program loop. Draw whatever you want, but do it when the television / monitor beam is not scanning the screen. The result will be a slower display, but one that has a whole lot less flicker. (somewhat harder)

    3. Consider using other graphics means and methods. A tile based driver is more work, but will consume a lot less memory. I posted an 8x8 NTSC driver here that's another alternative. It's been enhanced by Hippy too, for color and PAL display. Break your game elements into discrete tiles, build them up, then display them on the screen. This can be double buffered, which then gets rid of your flicker and memory problems. (hardest, but yields the greatest overall improvement!)

    eg: the numbers displayed then consume a coupla bytes of screen memory, instead of all the bytes required to display them as full-on bitmap graphics. Draw speed is faster too, in that your program really only needs to manipulate a small number of memory elements to rebuild the display as a whole. Finally, everything is stored maybe once or twice, instead of many times.

    BTW: You can do tiles with the reference Parallax drivers. Each tile of screen memory can be pointed to any other place in memory, not just to form a bitmapped screen. One could point the graphics routines to an area of memory, not being displayed, draw all the unique graphics elements, then point each screen memory tile to that region of memory, as needed, to form the dynamic game display. That's somewhat complex, but totally doable with that driver set.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Post Edited (potatohead) : 12/18/2007 4:56:48 PM GMT
  • morfellumorfellu Posts: 5
    edited 2007-12-18 19:57
    potatohead I tried using double buffering, but It flickers the same.

    Could you explain me the point 2. of your comment? I really dont understand it. Thank you
Sign In or Register to comment.