View Full Version : boundaries (byte/long) [again?]
02-04-2007, 01:35 PM
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[ (X-1 ) / 16 ] to get the value (H is a local *long* variable).
It's OK for X 1-16; it picks up HouseCode
But for X 17-32, it gets HouseCode; for X 33-48, it gets HouseCode
It almost seems like it's jumping by Longs instead of bytes.
Seems like i'm missing some fundamental concept here (?)
02-04-2007, 01:43 PM
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.
02-04-2007, 01:53 PM
Here is the code presenting difficulties:
pri ProcessCmd | B, H, UF
case Param ' the command
1,3 : ' OFF or ON
if Param => 1 and Param =< 256 'units 1-256 only
H := HouseCode[ (Param-1 ) / 16 ] ' Param is the "X" in my original post. It prints out OK
UF := UnitCode[ ( 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==1 ' no problem with this block
B |= (Off<<18)
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.str(string("unit number out of range",13))
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
02-04-2007, 02:27 PM
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.
02-05-2007, 02:00 AM
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.