Shop OBEX P1 Docs P2 Docs Learn Events
Need some code help and or suggestions with buffer indexing — Parallax Forums

Need some code help and or suggestions with buffer indexing

Don MDon M Posts: 1,652
edited 2013-05-03 05:05 in Propeller 1
I have a 27 byte main buffer but I'm only concerned about the last 16 bytes (from byte 26 to byte 11 in that order). Let's say that bytes 26 through 11 contains the following:

Byte 26 >>>>>>>>>>>>>>>>>>>>>>> Byte 11
00 00 00 00 00 00 00 00 00 00 FF 14 0A 05 02 01

Now I have another buffer that has 2 bytes. We'll call it the mask buffer. It is a mask for which of the 16 bytes from the main buffer will be displayed.

Let's say I only want to display bytes 11, 13, 14 & 15 of the main buffer so the mask buffer would be:

Hex: $1D

Binary:
bit15 >>>>>>>> bit 0
0000 0000 0001 1101

How do I make this work?

Comments

  • kwinnkwinn Posts: 8,697
    edited 2013-05-02 10:29
    Set a pointer to byte 26 of the main buffer
    Repeat the following 16 times
    Test the MSbit of the mask
    If the bit is 1 display the byte pointed to
    shift the mask left 1
    decrement the byte pointer
  • kwinnkwinn Posts: 8,697
    edited 2013-05-02 10:29
    Set a pointer to byte 26 of the main buffer
    Repeat the following 16 times
    Test the MSbit of the mask
    If the bit is 1 display the byte pointed to
    shift the mask left 1
    decrement the byte pointer
  • Don MDon M Posts: 1,652
    edited 2013-05-02 11:23
    Ok so I'm trying to figure out bit decoding...

    I was trying to do this just to display which bits are set in the buffer but I get an error trying to compile. It doesn't like the |<.

    What am I doing wrong here?
    repeat bit from 0 to 15
                div := mask |< bit  
                term.dec(div)
                term.tx(13)
    
  • Don MDon M Posts: 1,652
    edited 2013-05-02 11:34
    Ok I got this to work...
    idx := 26
    repeat bit from 15 to 0
      div := (mask >> bit) & 1
      if div == 1 
        term.dec(byte[@main][idx])
        term.tx(32)
      idx--    
    term.tx(13)
    

    Still wondering why Prop tool didn't like the |< expression....
  • kwinnkwinn Posts: 8,697
    edited 2013-05-02 11:50
    Only difference I can see is the brackets in the "div :=" statement.
  • kuronekokuroneko Posts: 3,623
    edited 2013-05-02 16:21
    Don M wrote: »
    Still wondering why Prop tool didn't like the |< expression....
    The expression itself is invalid. |< only takes the (right parameter) so you basically wrote a := b c. Did you mean div := mask & |< bit?
  • Don MDon M Posts: 1,652
    edited 2013-05-02 18:13
    kuroneko wrote: »
    The expression itself is invalid. |< only takes the (right parameter) so you basically wrote a := b c. Did you mean div := mask & |< bit?

    Ok with that here is what I tried:

    "mask" has the value of $1D (0000 0000 0001 1101)
    repeat bit from 15 to 0
      div := mask &|< bit
      term.dec(div)
      term.tx(32)
    
    

    For the response I get: 0 0 0 0 0 0 0 0 0 0 0 16 8 4 0 1

    I thought I would have gotten: 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1

    How do I change it to get that type of response?
  • kuronekokuroneko Posts: 3,623
    edited 2013-05-02 18:34
    Don M wrote: »
    I thought I would have gotten: 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1

    How do I change it to get that type of response?
    Like you did in your second attempt i.e. div := (mask >> bit) & 1. Or you could put mask into outb and use div := outb[bit].
  • Don MDon M Posts: 1,652
    edited 2013-05-03 05:05
    kuroneko wrote: »
    Like you did in your second attempt i.e. div := (mask >> bit) & 1. Or you could put mask into outb and use div := outb[bit].

    Thanks again for your help. Much appreciated.
Sign In or Register to comment.