Gligli is absolutely right. I've figured it out now, sorry for posting first and thinking later.
Took me some time, my 8-bit coding times are long past, and they like to do things the hard way in the Matrix firmware code. So this may serve as a cautionary tale.
The buggy part of the routine deals with the low byte of a NRPN message (remember, in MIDI, there can be 16,384 NRPN controllers, so you need 2 bytes).
The routine expects the MIDI command byte in register A, and the value in register B. What is does is this:
- Read a variable where the NRPN controller value is stored into A - they seem to have expected up to 255.
- Take the MSB of this variable (by ANDing A with #$80).
- Remember, the NRPN_L value you just received now resides in register B.
- Now, add the MSB bit to the NRPN_L byte in a rather original way: Push B to the stack, then OR A with the byte indexed by the stack pointer, and post-increment. (Mnemonic: "ORA ,S+")
Unfortunately, the NRPN value in memory always seems to have its MSB set, so the routine always returns a NRPN parameter number greater than 127. Which is meaningless.
So yes, disabling the MSB setting should fix it. Kudos to Gligli.