Documenting the P2 varint format (read by RFVAR / RFVARS instructions)
Conga
Posts: 51
It's not urgent, but I think it's worth doing.
'varint' = Varying-length Integer, or Variable-length Integer.
This is my current understanding of the format implemented by Chip (may be wrong).
Unsigned varint (RFVAR):
0xxx xxxx -> 0xxx xxxx (byte value less than 128)
1xxx xxxx 0yyy yyyy -> 00xx xxxx xyyy yyyy ? or 00yy yyyy yxxx xxxx
1xxx xxxx 1yyy yyyy 0zzz zzzz
1xxx xxxx 1yyy yyyy 1zzz zzzz vvvv vvvv
Signed varint (RFVARS):
0sxx xxxx -> ssxx xxxx
Where is the sign bit in the following?
1xxx xxxx 0yyy yyyy
1xxx xxxx 1yyy yyyy 0zzz zzzz
1xxx xxxx 1yyy yyyy 1zzz zzzz vvvv vvvv
'varint' = Varying-length Integer, or Variable-length Integer.
This is my current understanding of the format implemented by Chip (may be wrong).
Unsigned varint (RFVAR):
0xxx xxxx -> 0xxx xxxx (byte value less than 128)
1xxx xxxx 0yyy yyyy -> 00xx xxxx xyyy yyyy ? or 00yy yyyy yxxx xxxx
1xxx xxxx 1yyy yyyy 0zzz zzzz
1xxx xxxx 1yyy yyyy 1zzz zzzz vvvv vvvv
Signed varint (RFVARS):
0sxx xxxx -> ssxx xxxx
Where is the sign bit in the following?
1xxx xxxx 0yyy yyyy
1xxx xxxx 1yyy yyyy 0zzz zzzz
1xxx xxxx 1yyy yyyy 1zzz zzzz vvvv vvvv
Comments
In the case of RFVARS, the value is sign-extended to 32 bits from the MSB of the data.
For both RFVAR and RFVARS, C = MSB of the data and Z = data is zero.
These instructions take two clocks.
I was just thinking that this might be useful as a simple way of compressing data, maybe something like RLE...
I guess using a couple bytes in the first byte to say how many bytes in the packet is OK.
But, would be faster if was transferred to C and Z flags...
But, the decoder wouldn't know, right?
Maybe 4-byte data would be a 24-bit color value and 1-byte data would be a count of how many pixels to paint with that color. Similar to RLE encoding...
or even better a WVLONG instruction as well that works similar to WMLONG except only bytes below the highest zero byte are written. This way the values are no longer "compose once" type.
Ducks for cover.....
when seeing this (and I did not follow all the discussion ...)
I wonder if there is a inverse WFVAR, which takes a long and write it so it can be read with RFVAR(S)?
Doing this manually is long.
Or will this be done by the assembler / compiler only and not used in runtime?
This would be nice for some data compression/uncompression ...
EDIT: OZ - you were faster ;-) ... but obviously the idea is in the 'air'