Author Topic: read/write nibbles  (Read 221 times)

Offline Sam.

  • The moose man
  • Planewalker
  • *****
  • Posts: 67
  • Gender: Male
    • Classic Adventures Homepage
read/write nibbles
« on: July 15, 2017, 08:24:48 PM »
How do I read/write nibbles with WeiDU?
"Ok, I've just about had my FILL of riddle asking, quest assigning, insult throwing, pun hurling, hostage taking, iron mongering, smart-arsed fools, freaks, and felons that continually test my will, mettle, strength, intelligence, and most of all, patience! If you've got a straight answer ANYWHERE in that bent little head of yours, I want to hear it pretty damn quick or I'm going to take a large blunt object roughly the size of Elminster AND his hat, and stuff it lengthwise into a crevice of your being so seldom seen that even the denizens of the nine hells themselves wouldn't touch it with a twenty-foot rusty halberd! Have I MADE myself perfectly CLEAR?!"
-- <CHARNAME> to Portalbendarwinden

Offline Argent77

  • Planewalker
  • *****
  • Posts: 146
Re: read/write nibbles
« Reply #1 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))

Offline The Imp

  • Planewalker
  • *****
  • Posts: 217
  • Gender: Male
Re: read/write nibbles
« Reply #2 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.

Offline GeN1e

  • Planewalker
  • *****
  • Posts: 267
  • Gender: Male
Re: read/write nibbles
« Reply #3 on: July 17, 2017, 07:21:02 PM »
Half a byte.  Use >>/<<, as Argent says.

Offline Sam.

  • The moose man
  • Planewalker
  • *****
  • Posts: 67
  • Gender: Male
    • Classic Adventures Homepage
Re: read/write nibbles
« Reply #4 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.
"Ok, I've just about had my FILL of riddle asking, quest assigning, insult throwing, pun hurling, hostage taking, iron mongering, smart-arsed fools, freaks, and felons that continually test my will, mettle, strength, intelligence, and most of all, patience! If you've got a straight answer ANYWHERE in that bent little head of yours, I want to hear it pretty damn quick or I'm going to take a large blunt object roughly the size of Elminster AND his hat, and stuff it lengthwise into a crevice of your being so seldom seen that even the denizens of the nine hells themselves wouldn't touch it with a twenty-foot rusty halberd! Have I MADE myself perfectly CLEAR?!"
-- <CHARNAME> to Portalbendarwinden

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: