Pocket Plane Group

Friends and Neighbors => Weimer Republic (WeiDU.org) => WeiDU => Topic started by: Sam. on July 15, 2017, 08:24:48 PM

Title: read/write nibbles
Post by: Sam. on July 15, 2017, 08:24:48 PM
How do I read/write nibbles with WeiDU?
Title: Re: read/write nibbles
Post by: Argent77 on July 16, 2017, 04:42:45 AM
Try this:
Code: [Select]
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))
Title: Re: read/write nibbles
Post by: The Imp on July 16, 2017, 05:35:57 AM
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.
Title: Re: read/write nibbles
Post by: GeN1e on July 17, 2017, 07:21:02 PM
Half a byte.  Use >>/<<, as Argent says.
Title: Re: read/write nibbles
Post by: Sam. on July 19, 2017, 02:08:34 PM
@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.