TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

I wrote a Game Boy Advance game in Zig

334 pointsby tehnub4 months ago

17 comments

AndyKelley4 months ago
&gt; 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&#x27;t solve this problem please feel free to file a bug against the compiler.<p><a href="https:&#x2F;&#x2F;ziglang.org&#x2F;documentation&#x2F;0.13.0&#x2F;#volatile" rel="nofollow">https:&#x2F;&#x2F;ziglang.org&#x2F;documentation&#x2F;0.13.0&#x2F;#volatile</a>
评论 #42558198 未加载
评论 #42557909 未加载
dijit4 months ago
&gt; 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…
评论 #42555584 未加载
评论 #42555504 未加载
评论 #42555318 未加载
评论 #42558621 未加载
评论 #42558537 未加载
评论 #42559058 未加载
评论 #42555332 未加载
评论 #42557100 未加载
评论 #42556098 未加载
评论 #42555902 未加载
评论 #42562287 未加载
评论 #42558824 未加载
评论 #42555718 未加载
评论 #42562484 未加载
评论 #42570727 未加载
zzo38computer4 months ago
&gt; 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.
评论 #42556731 未加载
aquova4 months ago
This is really interesting. As an aside, someone has created a GBA toolchain for the Nim language as well. It&#x27;s really cool seeing these projects for a variety of languages.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;exelotl&#x2F;natu">https:&#x2F;&#x2F;github.com&#x2F;exelotl&#x2F;natu</a>
评论 #42556540 未加载
评论 #42555791 未加载
MobiusHorizons4 months ago
&gt; 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 &#x2F; kernel style programs like this is. I would have expected the equivalent of -nostdlib to handle this automatically. I wonder if the author&#x27;s build could be tweaked to tell llvm (which zig is based on) not to perform this or other &quot;default to stdlib implementation&quot; style optimizations
评论 #42556152 未加载
评论 #42556624 未加载
评论 #42556850 未加载
评论 #42558630 未加载
dropbear34 months ago
&gt; 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; &#x2F;&#x2F; ... };</code></pre>
评论 #42555704 未加载
评论 #42555948 未加载
klooney4 months ago
&gt; 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&#x27;t miss but banging much.
评论 #42557518 未加载
评论 #42557517 未加载
评论 #42559989 未加载
评论 #42556260 未加载
oxidant4 months ago
This was an interesting read, thanks.<p>One nit on mobile (Firefox and Chrome, Android), your code blocks overflow the background instead of scrolling.
评论 #42557523 未加载
评论 #42559707 未加载
评论 #42555314 未加载
latexr4 months ago
&gt; You can try the game out in an emulator &lt;a href=&quot;&quot;&gt;here&lt;&#x2F;a&gt;.<p>You left out the most important part of the post.
评论 #42563540 未加载
keyle4 months ago
Interesting post. I wish it went deeper but I guess it&#x27;s just a post-mortem.<p>Related, I found this old post that goes into the basics of GBA coding [1]. It doesn&#x27;t look nearly as bad as I expected. That said I&#x27;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:&#x2F;&#x2F;www.loirak.com&#x2F;gameboy&#x2F;gbatutor.php" rel="nofollow">http:&#x2F;&#x2F;www.loirak.com&#x2F;gameboy&#x2F;gbatutor.php</a><p>[2] <a href="https:&#x2F;&#x2F;www.coranac.com&#x2F;tonc&#x2F;text&#x2F;toc.htm" rel="nofollow">https:&#x2F;&#x2F;www.coranac.com&#x2F;tonc&#x2F;text&#x2F;toc.htm</a>
评论 #42557195 未加载
Validark4 months ago
&gt; 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&#x27;s impossible to write properly?
Validark4 months ago
&gt; 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.
评论 #42561159 未加载
anta404 months ago
How to build this? I&#x27;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
Dwedit4 months ago
While the GBA does have decompression routines in its BIOS, APLIB does a far better job with compression. I made a fast APLIB depacker for GBA.
mysecretaccount4 months ago
Why is the DS in the &quot;Non-modern graphics&quot; row? It does not use a tile based renderer.
评论 #42557170 未加载
actionfromafar4 months ago
For the upper right quadrant, something like a Silicon Graphics might fit.
评论 #42557820 未加载
评论 #42555912 未加载
评论 #42557620 未加载
__loam4 months ago
Extremely excited to read through this. I&#x27;m fascinated by Zig and the GBA. It&#x27;s really cool to see people still developing software on such an old machine.