Pocket Plane Group
Friends and Neighbors => Weimer Republic (WeiDU.org) => WeiDU => Topic started by: Sam. on July 15, 2017, 08:24:48 PM
-
How do I read/write nibbles with WeiDU?
-
Try this:
SET nibbleL = (BYTE_AT offset) & 0x0f
SET nibbleH = ((BYTE_AT offset) >> 4) & 0x0f
WRITE_BYTE offset ((THIS & 0xf0) | nibbleL)
WRITE_BYTE offset ((THIS & 0x0f) | (nibbleH << 4))
-
Nibbles ?
It's not like the snacks have fortunes written in them or anything... ok, joking aside, I have never ran in to these in weidu, so care to elaborate ? Not that you need to.
-
Half a byte. Use >>/<<, as Argent says.
-
@Argent77
That is exactly what I needed, thank you!
@The Imp
A nibble is half of a byte (so 4 bits) and stores a value from 0 to 15. The problem is that the smallest value traditionally used to read from / write to a file is a byte, so low level bit manipulations (something I've never been able to wrap my head around) are required to get at the two 4-bit nibbles in the byte. That's where Argent77's code comes in. As far as my need to do this, 4-bit bitmaps (the format used by area search maps) have a 16 color palette, and each pixel is a 4-bit nibble that is a pointer into the palette. So each byte stores two pixels, but in order to change the pixels one must access each nibble.