Shop OBEX P1 Docs P2 Docs Learn Events
boundaries (byte/long) [again?] — Parallax Forums

boundaries (byte/long) [again?]

Don PomplunDon Pomplun Posts: 116
edited 2007-02-04 18:00 in Propeller 1
I have a table, HouseCode, of 16 Byte values in the DAT area.
A given number, X, from 1-256 is supposed to correlate to one of these table values.
i.e. if X is between 1-16, the first table value is matched; 17-32 gives the 2nd value, etc.

I use H := HouseCode[noparse][[/noparse] (X-1 ) / 16 ] to get the value (H is a local *long* variable).
It's OK for X 1-16; it picks up HouseCode[noparse][[/noparse]0]
But for X 17-32, it gets HouseCode; for X 33-48, it gets HouseCode[noparse][[/noparse]8]

It almost seems like it's jumping by Longs instead of bytes.

Seems like i'm missing some fundamental concept here (?)

-- Don

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-04 05:43
    This doesn't make sense. What you describe should work. Please either cut and paste or attach the relevant code, not an excerpt. There may be something in how you wrote the actual code that would explain this behavior.
  • Don PomplunDon Pomplun Posts: 116
    edited 2007-02-04 05:53
    Here is the code presenting difficulties:

    pri ProcessCmd | B, H, UF
    case Param[noparse][[/noparse]0] ' the command
    1,3 : ' OFF or ON
    if Param => 1 and Param =< 256 'units 1-256 only
    H := HouseCode[noparse][[/noparse] (Param-1 ) / 16 ] ' Param is the "X" in my original post. It prints out OK
    UF := UnitCode[noparse][[/noparse] ( Param-1 ) // 16 ] ' Interestingly this calculation works OK
    B~ ' B=0
    B |= (H<<28) ' This gets botched up
    B |= (UF<<23) ' this seems to come out oK
    if Param[noparse][[/noparse]0]==1 ' no problem with this block
    B |= (Off<<18)
    else
    B |= (On<<18)
    text.str(string(" cmd OK B=" ))
    text.dec(H) ' diagnostically I'm just looking at H and finding it is wrong if Param is > 16
    ' text.bin(B,32)
    text.out(CR)
    else
    text.str(string("unit number out of range",13))

    DAT
    HouseCode
    byte %0110 'A
    byte %1110 'B
    byte %0010 'C
    byte %1010 'D
    byte %0001 'E
    byte %1001 'F
    byte %0101 'G
    byte %1101 'H
    byte %0111 'I
    byte %1111 'J
    byte %0011 'K
    byte %1011 'L
    byte %0000 'M
    byte %1000 'N
    byte %0100 'O
    byte %1100 'P
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-04 06:27
    Because you have HouseCode on a line by itself, the compiler has no way to know what size the data items are and assumes that it's a long. If you use "HouseCode byte", the compiler will know it refers to byte values even though there's no value given on the same line.
  • Don PomplunDon Pomplun Posts: 116
    edited 2007-02-04 18:00
    Thanx. Adding 'byte" after HouseCode did the trick.
    What still is strange is that following after the HouseCode table is one called UnitCode, where I make the same mistake, but it works OK.
    -- Don
Sign In or Register to comment.