> it would be nice if there was some way to specify how memory in certain address ranges need to be addressed.<p>If making the respective loads and stores volatile doesn't solve this problem please feel free to file a bug against the compiler.<p><a href="https://ziglang.org/documentation/0.13.0/#volatile" rel="nofollow">https://ziglang.org/documentation/0.13.0/#volatile</a>
> I started using Linux five years ago, mainly because I couldn’t figure out how to get Python working on Windows<p>Windows being by far the most dominant operating system from 97-2015 definitely exacerbated a dearth in knowledge among the young. In the early days internet access was not ubiquitous and shipping an operating system without even a primitive programming environment definitely lead to missed years of programming for me.<p>I learned a lot about windows, lots of UIs and how the system was constructed somewhat, but no visual studio, no functioning compiler in base and the only interpreter being <i>fucking batchfiles</i> with no docs… come on…
> Did you know that you can’t write to video memory on the Game Boy Advance in units of 8 bits, and if you do, it’ll still work but all your graphics will be messed up with no obvious way to figure it out unless you read one specific paragraph of the documentation?<p>I did. At one time I did write a program that wrote to video memory in units of 8 bits, but the emulator I was using did not prevent that, so my program worked on the emulator but not on the real hardware, and I could not figure it out until I found out that was the problem and I managed to fix my program so that it would work.
This is really interesting. As an aside, someone has created a GBA toolchain for the Nim language as well. It's really cool seeing these projects for a variety of languages.<p><a href="https://github.com/exelotl/natu">https://github.com/exelotl/natu</a>
> Sometimes, the compiler would get too smart for its own good, and recognize that a function that I wrote just copies memory. It would helpfully replace the function body with memcpy to save space.<p>I would generally expect this optimization to only be done for programs executing in userspace, not os / kernel style programs like this is. I would have expected the equivalent of -nostdlib to handle this automatically. I wonder if the author's build could be tweaked to tell llvm (which zig is based on) not to perform this or other "default to stdlib implementation" style optimizations
> How would you do [packed structs] in C?<p>Bitfields! This is valid C:<p><pre><code> struct foo {
unsigned bg_priority: 2;
unsigned character_base: 2;
// ...
};</code></pre>
> Did you know that you can’t write to video memory on the Game Boy Advance in units of 8 bits, and if you do, it’ll still work but all your graphics will be messed up with no obvious way to figure it out unless you read one specific paragraph of the documentation? Hey did you know that when you compile a binary optimized for size, memory copies will be by units of 8 bits, but not if you use debug mode?<p>Brutal. I don't miss but banging much.
This was an interesting read, thanks.<p>One nit on mobile (Firefox and Chrome, Android), your code blocks overflow the background instead of scrolling.
Interesting post. I wish it went deeper but I guess it's just a post-mortem.<p>Related, I found this old post that goes into the basics of GBA coding [1]. It doesn't look nearly as bad as I expected. That said I'm sure performance might be the issue once you start having a few things going.<p>If you have a good resource please let me know (I prefer C).<p>Edit: also this library [2].<p>[1] <a href="http://www.loirak.com/gameboy/gbatutor.php" rel="nofollow">http://www.loirak.com/gameboy/gbatutor.php</a><p>[2] <a href="https://www.coranac.com/tonc/text/toc.htm" rel="nofollow">https://www.coranac.com/tonc/text/toc.htm</a>
> Unfortunately, it only has support for one output. Some of the BIOS functions on the GBA that you might use inline assembly for output multiple values in different registers, which is problematic for Zig. This is currently being worked on so it might be improved in the future.<p>Can you post the code that's impossible to write properly?
> As it would turn out, the Game Boy Advance has quite a bit of “weird memory” that you have to work around in weird ways. I know that this is a long shot, but it would be nice if there was some way to specify how memory in certain address ranges need to be addressed.<p>Could you elaborate on this? Does LLVM support this feature? If so, it might not be too hard to get it into Zig.
How to build this? I'm on M2 Mac with 2 Zigs installed:<p>0.13.0 and 0.14.0-dev.2589+0df1f3df2<p>Both gave the same error:<p>run gbaimg (tiles.zig) transitive failure
│ │ └─ zig build-exe gbaimg Debug native 1 errors
Extremely excited to read through this. I'm fascinated by Zig and the GBA. It's really cool to see people still developing software on such an old machine.