2BPP data structure #577
Replies: 3 comments 1 reply
-
I think I've found the issue, for some reason, the way that the wasm-sdk (or maybe C toolchains in general) pack these bitfields is similar to a switch in endianness. This printed test seems to show that
As you can see from the output, the number matches the one with a sort of backwards sorted set of two bit chunks :/ Oh well, maybe I can redo this as a macro to build these in reverse somehow. Or just actually use the image builder tools :P |
Beta Was this translation helpful? Give feedback.
-
It turns out the bit packing was weirder than I expected, in that each nib was in reverse order per each byte. For future readers, this isn't anything specific to wasm4, but I think rather platform and/or toolchain dependent. Here's the solution I landed on, which requires reordering the nibs after creating the struct, but otherwise draws as you would expect:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the info @computermouth, I actually didn't know C had sized bitfield syntax! It might be interesting to compare how this works vs other languages with this feature, eg: zig. |
Beta Was this translation helpful? Give feedback.
-
Howdy folks, new to wasm, new to wasm4, super cool to be playing with it in a fantasy console, wasm4 is awesome so far!
Anyway, similar to this question #422, I was trying to build a data structure that's as easily drawable in code as the 1BPP binary images. I landed on this using bitfields in C.
I feel like it should work, and it draws something pretty close to what I expect, but not quite. At first I thought that C alignment and packing might be the issue, but the structs are exactly 2 bytes, where each should be a valid 8 pixel line.
Any suggestions?
Beta Was this translation helpful? Give feedback.
All reactions