Thank you @xarvh!
Yeah, binary data was and still is one of my pain points.
At first, I had opaque
Word16 types that used an
Int to store the data. Both the
Word16 module had all the basic operations like and, or, xor, add or sub as I obviously could not use the functions from Basics and Bitwise with my new custom types. Relativly close to the end, I removed all of that due to it’s clunkyness (as the codebase is heavy on bitwise and arithmetical operations) and performance, as any access to
WordN types required unwrapping. I had some hope when 0.19 came out that --optimize would help with that case, but as the types where opaque, it didn’t, and they had to go away.
So, as for now, all binary data values are just
Ints. I really dislike that as I could mix up 8 and 16 bit values and the situation gets even worse when you’re dealing with stuff like signed bytes where the binary encoding (two’s complement) is relevant for arithmetic.
I plan to at least to reintroduce a custom type for those cases again and unwrap them everywhere I need access to the value inside. This way, I can use
--optimize should remove the wrapping from the compiled source.
Another problem is pixel data for the screen. As I have to draw the screen line-by-line, emulating the way a real Game Boy would do it (as many games depend on render timings to produce effects), I need to store each pixel separatly and draw them to a
<canvas> later. First, I just serialized the
List of pixels into json to hand them to a port, but that took way to long. Right now, I encode batches of 16 pixels into a single integer (which fit perfectly into a 32bit int as the color depth of the game boy is two bits) send those to JS and unpack them again, before pushing them into the canvas.
Summarized, it’s unwieldy and clunky. But Elm wasn’t supposed for tasks like this and I knew what I was getting into. Maybe sometime in the future we will have a way to encode raw binary data in Elm and much of the issues will go away.
BTW, while I was in the earlier stages of development I listend to the Elm Town episode where you talked about Herzog Drei. In the end, you said (paraphrased): “be ambitious, do something that is big, massive and complicated. It’s totally worth it and Elm can do it.”. I smiled when I heard that as it somehow validated my insane project I was working on. Thanks for that!