Shop OBEX P1 Docs P2 Docs Learn Events
Programming Question. — Parallax Forums

Programming Question.

reppigreppig Posts: 35
edited 2009-11-05 19:43 in Propeller 1
While I am here another question.

Previously I was trying to create a checkboard pattern the computer monitor with dark and light tiles.
I which I was able to do by accident. Because it did not work as I thought.

I have added the debug to here, the working code is below.

The debug screen shows:
J start
1
-2
1
-2 and so on

If I start with j := 0 see code . I get columns not a checkerboard
and the debug shows:
J start
0
-1
0
-1 and so on

What is going on??? Why in the first example does j go from 1 to -2
when doing a !j and I get the checkerboard. And
Why does j do what I expect in the second example but I don't get the
checkerboard pattern, I get columns?? - especially since when I use j, I
am just checking if it is equal to 1??



CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  '512x384
  tiles = gr#tiles

OBJ
  gr    : "vga graphics ASM"
  debug  : "FullDuplexSerial"

PUB MainLoop|i,j
   gr.start
   gr.pointcolor(1)
   debug.start(31, 30, 0, 57600)  
   waitcnt(clkfreq * 5 + cnt)

   j := 1                        '<---------- SEE HERE IS THE PROBLEM 
(if I change to 0 ----------------
   debug.str(string("J start"))
   debug.Tx(13)
   debug.dec(j)
  
   repeat i from 0 to tiles - 1                          '16 columns x 
12 rows = 192
      if(i//16 == 0)
         !j                     '<------------ HERE I USE IT 
--------------------------
         debug.Tx(13)
         debug.dec(j)

      if(j == 1)            '<------------ HERE I USE IT 
--------------------------
         if(i//2 == 0)
            gr.color(i,$00FF)                              'wht on blk
         else
            gr.color(i,$FF00)                              'blk on wht    
      else
         if(i//2 == 0)
            gr.color(i,$FF00)                              'blk on wht  
         else
            gr.color(i,$00FF)                              'wht on blk
   repeat


Post Edited (reppig) : 11/5/2009 3:26:03 PM GMT

Comments

  • SamMishalSamMishal Posts: 468
    edited 2009-11-05 19:08
    The problem is that you are using the Bit-Invert operator (!) on j
    when you bit invert 0 you get $FFFFFFFF which is -1
    now in your if statement you are checking if j == 1 which j will never be 1 when you start with j:=0 and then keep inverting
    it will alternate between 0 and -1 and thus your if statements will always execute the ELSE section

    When you set it to j:=1 and then inverting 1 gives you $FFFFFFFE which is -2 and the if statement will work correctly
    since j will alternatively be 1 and not 1.

    If you want to start with 0 then -1 etc just change the if statement from j == 1 to j==0··· or····· ·j==-1
    But you are complicating the code too much ....I do not think you need the j at all....just do this....
    (I do not have the "VGA graphics ASM" object so I could not try out your code)
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      '512x384
      tiles = gr#tiles
    
    OBJ
      gr    : "vga graphics ASM"
      debug  : "FullDuplexSerial"
    
    PUB MainLoop|i,j
       gr.start
       gr.pointcolor(1)
       debug.start(31, 30, 0, 57600)  
       waitcnt(clkfreq * 5 + cnt)
    
       repeat i from 0 to tiles - 1  '16 columns x 12 rows = 192
             if(i//2 == 0)
                gr.color(i,$00FF)                              'wht on blk
             else
                gr.color(i,$FF00)                              'blk on wht    
       repeat
    
    

    This will cause the tiles to alternate white and black even from row to row since the 1st tile in each row will be the opposite of the
    the tile above it in the previous row since you have an even number of columns.

    Sam
  • reppigreppig Posts: 35
    edited 2009-11-05 19:43
    Thank you for your help. Now I have got it.
Sign In or Register to comment.