I need to create a lookup table that will map an incoming single-byte index and provide a two-byte value that will be used in an outgoing message.
Can two-byte values be stored in lookup tables?
I need to split the two-byte value into two bytes after retrieval because a checksum operation needs to be performed on them.
Here is a pseudocode example.
Let's say my lookup table is L and it is setup like this
ASS L0 = llmm ASS L1 = nnpp ASS L2 = qqrr
where llmm is a two-byte number that will eventually be split into ll mm
# incoming message will be something like F0 F1 F1 zz vv F7 # where M0-M2 are a header # M3 (zz) is the index used for the lookup and vv is a value passed out
if M0 == F0 F1 F1
#construct a new message to send in this form # where 32 32 45 is a header byte newMessage = F0 32 32 45 LM3a LM3b M4 checksum F7 #where checksum is a roland style checksum performed on the non-header bytes
# and where LM3a is the first byte of the the value stored in LM3 and LM3b is the second byte.
Thanks for the prompt response. For a number of reasons it would be good to keep both bytes together in the same table -- not least of which is to make it straightforward to create and edit the codes that make up the table. But also because there will be several lookup tables. If each gets split between two separate arrays, I will run out of arrays to use.
Are there byte operations one could perform that would split a two-byte value into individual bytes? The docs mention a few byte operators for MAT but doesn't mention what operations they map to. I am assuming these are the same as in C.
I am rusty on bitwise operations. So, maybe there is something obvious that I am overlooking.
MATH OPERATIONS ON LOOKUP TABLE INDICES? A related question. Is there a way if you have an index into a lookup table -- lets say in M2 -- to perform a math operation to add an offset to that index or do a multiply.
For example, let's say my M3 has a value of 0x14 and I am using L0 to store two sets of data for each index. Is there a way, with M3 to retrieve a value from L at M3+1 or L at M3*2. For example, if the array notation were L[index, I want to be able to access L[M3+1] or L[M*2]
We can indeed store two bytes in each slot and pull them out as follows:
IF LOAD # A0B0 A1B1 ASS L0 = 1234 5678 END
# extract byte a and b of slot n (n is in I0) # from 'L', into I1 and I2 MAT I1 = LI0 / 100 # byte A (shift 8 bits right) MAT I2 = LI0 & 0F # byte B (mask top 8 bits)
If I0 contained '1', then I1 would resolve to 56 and I2 would resolve to 78 in the above table
> For example, let's say my M3 has a value of 0x14 and I am using L0 to store two sets of data for each index. Is there a way, with M3 to retrieve a value from L at M3+1 or L at M3*2. For example, if the array notation were L[index, I want to be able to access L[M3+1] or L[M*2]
Yes, you just setup the correct index in a temporary variable and then use that:
# get L[M3 + 1] into I1 MAT I0 = M3 + 1 ASS I1 = LI0
# get L[M3*2] into I2 MAT I0 = M3 * 2 ASS I2 = LI0
If you're using the AU some of this stuff could be in subroutines. (new SB extensions for MidiFire currently work in progress)
BTW, if you're looking to calculate Roland checksums, this post has the code for that (if you haven't found it already)