[HN Gopher] I wrote a Game Boy Advance game in Zig
       ___________________________________________________________________
        
       I wrote a Game Boy Advance game in Zig
        
       Author : tehnub
       Score  : 305 points
       Date   : 2024-12-30 21:51 UTC (1 days ago)
        
 (HTM) web link (jonot.me)
 (TXT) w3m dump (jonot.me)
        
       | aquova wrote:
       | 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.
       | 
       | https://github.com/exelotl/natu
        
         | archargelod wrote:
         | Natu has an amazing commercial game called Goodboy Galaxy [0].
         | In addition to the Game Boy Advance version, they've also
         | ported it to Windows and Linux with Xatu [1] (which is also
         | written in Nim).
         | 
         | 0 - https://goodboygalaxy.com/
         | 
         | 1 - https://git.sr.ht/~exelotl/xatu
        
         | girvo wrote:
         | And interestingly, one of the problems raised in the article
         | __attribute__((target("arm")))         void interrupt_handler()
         | {             ...         }
         | 
         | that fancy __attribute output can be achieved quite nicely
         | using a custom pragma/codegendecl -- we did exactly this for
         | the embedded firmware written in Nim at my previous workplace,
         | to get access to some specific features of the ESP32-S3 (things
         | like RTC_ATTR_NOINIT for example)
        
       | keyle wrote:
       | Interesting post. I wish it went deeper but I guess it's just a
       | post-mortem.
       | 
       | 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.
       | 
       | If you have a good resource please let me know (I prefer C).
       | 
       | Edit: also this library [2].
       | 
       | [1] http://www.loirak.com/gameboy/gbatutor.php
       | 
       | [2] https://www.coranac.com/tonc/text/toc.htm
        
         | discard38484 wrote:
         | Check out https://gbadev.net
        
       | dijit wrote:
       | > I started using Linux five years ago, mainly because I couldn't
       | figure out how to get Python working on Windows
       | 
       | 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.
       | 
       | 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 _fucking
       | batchfiles_ with no docs... come on...
        
         | ashleyn wrote:
         | windows 95 did come with Qbasic for MS-DOS. it wasn't the
         | latest and greatest, but it did contribute to a moderately
         | large online scene of kids making Qbasic games or Windows-like
         | Qbasic GUIs for DOS.
        
           | bigfishrunning wrote:
           | That's where I got started, copying basic code from the back
           | of Boy's Life magazine, before I had a modem. I'm sure I'm
           | not the only one here!
        
             | binary132 wrote:
             | I learned BASIC from those Usborne books on it, muddling my
             | way through with qbasic. The PDFs of them are actually
             | available on their site now!
        
           | kevin_thibedeau wrote:
           | Debug.exe still shipped in Win7 x86.
        
           | paride5745 wrote:
           | I remember in Win98 it being hidden in the Windows folder, if
           | you didn't know where and what to look for, it was pretty
           | much impossible to find.
        
           | spacechild1 wrote:
           | That's how I started programming as a kid! There even were a
           | few sample games.
        
         | ralusek wrote:
         | When I was first getting started with programming in about
         | 2008, I found it to be so unbelievably frustrating. Any
         | tutorial I was following would invariably run into something
         | that didn't work how it was supposed to. I would try to find
         | some work around, and sort of would, but it would lead to other
         | unforeseen issues down the line. I finally came across cygwin,
         | and that sort of made things start to work.
         | 
         | Eventually, though, I just installed a linux partition and
         | literally never looked back. The entire ecosystem of everything
         | I was learning at the time (Python, JS, PHP) was set up for
         | unix. Things have improved over time, and obviously WSL is
         | nice, but it's still a pain.
        
         | eru wrote:
         | Python is actually relatively easy to set up on Windows. (Or at
         | least it was easy to set up on Windows 98 in the early 2000s. I
         | don't know how it's now, or five years ago.)
         | 
         | You just download the official Python installer, and off you
         | go. It even comes with Idle as a reasonably good IDE.
        
           | nicce wrote:
           | If you run python in command-line, it starts Windows Store...
        
             | a1o wrote:
             | The python from Windows Store is not good, it redirects
             | some path writes and will make the debugging experience of
             | tools using python dreadful. Always install from the win32
             | installer from the website.
        
             | heavensteeth wrote:
             | Experiencing this for the first time was really jaw
             | dropping. And I believe by default "python3" has distinct
             | behaviour of _telling you_ to visit the Microsoft Store,
             | but not opening it. Bizarre.
        
           | actuallyalys wrote:
           | It's currently just as easy to use for learning and
           | experimenting on Windows as you describe. I don't use Python
           | on Windows heavily enough to evaluate it for more serious
           | development.
        
           | thrdbndndn wrote:
           | Yeah, upgrading Python from build-in ancient version that
           | came with Linux distro (usually 3.8, or even 2.x) is actually
           | much harder than doing so on Windows.
        
             | prmoustache wrote:
             | you don't have to upgrade, you can have more than one
             | python install at the same time. You only really need to
             | know about how to manage your PATH environment variable.
        
             | eru wrote:
             | I guess it depends on what Linux distribution you are
             | using?
        
             | adastra22 wrote:
             | > upgrading Python from build-in ancient version ...
             | usually 3.8
             | 
             | Now you're making me feel old.
        
             | klibertp wrote:
             | You shouldn't use the OS's Python for your work. That
             | Python is for OS utilities' use. It's meant to be old and
             | stable. Instead, use pyenv, conda, asdf, mise, etc. - it'll
             | allow you to install multiple versions of Python and easily
             | switch between them for your projects. You're gonna need it
             | anyway once you try writing integration tests for multiple
             | versions of Python, like with tox or nox.
        
           | m1keil wrote:
           | I started using python at around 2.6/2.7, and while it was
           | easy to install python on windows, anything that involved non
           | pure python was a nightmare.
           | 
           | Back in these days you had no wheels and I think it was at
           | least a partial reason for why conda was a thing.
        
             | klibertp wrote:
             | Yeah, back then, `pip install` just didn't work for
             | anything written in C. I seem to remember a Windows-
             | specific site with builds of popular extension packages -
             | Cython, lxml, OpenSSL, and the like. It was unofficial, and
             | you couldn't use a package manager to install them, but
             | after manually downloading them, they tended to work.
             | 
             | Wheels, Conda, and WSL, helped - now, all the R&D guys at
             | work use Python on Windows with PyTorch, TensorFlow, and
             | all that without problems. I'm also using (mini)conda (on
             | Linux) instead of virtualenv - it's nice because I don't
             | need to worry about all my venvs breaking after an OS
             | upgrade.
             | 
             | Anyway, compared to those days (I started with 2.4 on
             | Windows, switched to Linux around 2.7), working with Python
             | on Windows is at least feasible.
        
           | rvba wrote:
           | Long time ago I participated in a Python course, where it
           | just wouldnt work for half of the students (like 10 people) -
           | and the lecturer couldnt figure it out.
           | 
           | As far as I remember Python REQUIRED to be installed on C:
           | and in something like C:\Python where it would bring 5000
           | various files.
           | 
           | Even more time ago, I was at a Java class, where my code
           | would work on my computer but just wouldnt work on the
           | computer of the lecturer. I remember the guy spend like 10
           | minutes looking at the (very simple) code and trying to
           | figure out why the code worked on Windows but not on Linux
        
           | devjab wrote:
           | It's still easy to setup, it's all the commands that are
           | different in powershell. So if you're doing a lot of Google
           | programming it's not going to be easy to actually use Python
           | if you're running things from a command line.
           | 
           | That being said Microsoft know windows is terrible for
           | software development which is why it's so easy to use Linux
           | inside Windows with WSL2. Since Docker Desktop for Windows
           | requires WSL2 it's very common for any developer AD account
           | to have it locally as admin.
        
             | 7bit wrote:
             | > That being said Microsoft know windows is terrible for
             | software development which is why it's so easy to use Linux
             | inside Windows with WSL2.
             | 
             | What are you smoking man? Don't impose your beliefs as
             | facts upon Microsoft.
        
               | dijit wrote:
               | I don't think Microsoft is stupid, they know that they
               | have the lions share of developers- they're also aware
               | that they are losing to linux in a big way when it comes
               | to service deployment environments. I even heard Azure
               | itself does not run Hyper-V on Windows anymore (though,
               | who can be sure).
               | 
               | It's a smart play for them to have WSL- it means less
               | friction to target Linux and will keep people writing
               | software on Windows (which increases the likelihood of
               | making software _for_ Windows- especially developer
               | tooling).
               | 
               | I think the parent is wrong that developing software on
               | Windows is hard, my original comment up-thread was
               | largely regarding the fact that in the late-90's and
               | early-00's internet access was not common and getting
               | your hands on a _Microsoft_ Development environment was
               | the furthest thing from easy. Linux, ironically, was
               | easier as it _came_ with all kinds of documentation and
               | interpreters and compilers out of the box.
        
               | pjmlp wrote:
               | It certainly still does run on a Windows flavour,
               | 
               | https://techcommunity.microsoft.com/blog/windowsosplatfor
               | m/a...
               | 
               | However they have been working on something else for
               | specific workloads,
               | 
               | https://opensource.microsoft.com/blog/2024/11/07/introduc
               | ing...
        
               | bmacho wrote:
               | Huh? Then why WSL2 if not because Windows sucks?
               | 
               | (This latter, Windows sucking, is not necessarily meant
               | in isolation but as part of our world: Windows is not
               | supported by many modern tools.)
        
               | moomin wrote:
               | It's possible to accept there are many dev tasks that can
               | only really be achieved on Linux without accepting
               | Windows sucks. The first is pretty much inarguable, the
               | second is emotive and imprecise.
        
               | maccard wrote:
               | Lots of tools are only built to run on Linux and are
               | ported over in ways that just about run to windows. Wsl
               | was an enormous step up from Cygwin in allowing windows
               | developers to use those tools and wsl2 is another huge
               | leap in that direction.
               | 
               | I don't think windows sucks, I think that a lot of people
               | outright refuse to use windows and design their tools to
               | run on Linux only, making choices that are optimal for
               | Linux but not for windows. two examples are processes vs
               | threads and opening/closing lots of files. Ironically the
               | Linux first approach of processes over threads doesn't
               | really scale to the level we want. Postgres is a great
               | example of trying very hard to be multithreaded as it's
               | hit the multiprocess limit, and struggling to do so.
        
             | pjmlp wrote:
             | It isn't easy for folks that see UNIX everywhere, and
             | nowadays a Linux VM makes more sense than the old POSIX
             | subsystem, that is all.
             | 
             | For better or worse, UNIX has won on embedded and server
             | room.
             | 
             | Despite my UNIX experience across all known vendors, I only
             | use WSL for Linux containers.
        
               | iamthepieman wrote:
               | For better or worse, UNIX has won on embedded and server
               | room.
               | 
               | I think this is the HN bubble at work. Maybe you mean
               | something qualitatively or quantitatively different than
               | I do when you say server room but every client I've
               | worked with in my extremely conservative industry in the
               | past ten years has been running on site, coloc, or cloud
               | "server rooms" on windows.
        
           | flohofwoe wrote:
           | On modern Windows there's this weird pre-installed python
           | stub which (IIRC) asks you to install Python from the app
           | store and which can confuse shell script which check if
           | Python is installed.
           | 
           | In terms of IDE support, VSCode with the MS Python extension
           | bundle is a pretty good Python IDE.
        
         | alexjplant wrote:
         | I will also say that starting to use Linux in earnest around
         | the age of 20 was a very humbling experience having been raised
         | on Windows. Back in the 00s being able to deal with Microsoft
         | esoterica by way of registry hacks and MMC snap-in wizardry
         | meant that you were a "smart computer kid" that non-technical
         | folks found impressive. It wasn't until I started using an OS
         | that acted more consistently and predictably that I realized
         | I'd been building a career (and decently-sized ego) out of
         | Microsoft-specific make-work. Being freed up to learn more
         | timeless and universal concepts lined up perfectly with my
         | college coursework centered around writing shells, compilers,
         | etc. and completely changed how I interacted with computers for
         | the better.
         | 
         | Apropos - if I ever win the lottery and don't need a job I'm
         | going to spend some time learning Plan 9. Superficially it
         | seems to be Unix without many of the warts combined with some
         | concepts from NT/VMS that make good sense.
        
           | robertlagrant wrote:
           | > building a career (and decently-sized ego) out of
           | Microsoft-specific make-work
           | 
           | This can be quite a successful career, probably even if you
           | start today.
        
             | skyyler wrote:
             | That's what I'm doing right now because it's easy. I need
             | to look for more challenging work soon.
        
             | kjs3 wrote:
             | My brother built his company (IT services in the
             | manufacturing sector) on the back of Microsoft starting in
             | the mid 90s. He's done extremely well and continues to work
             | on interesting stuff (these days cloud, complex databases,
             | CRM, etc). Employees are by-and-large long term and well
             | compensated. Not FAANG numbers to be sure, but we're in a
             | city with a reasonable CoL.
             | 
             | But he focused on building a long-term sustainable
             | business, not chasing some buzzword-du-jour, VC funded
             | pipedream with a quick exit, and thus no matter his
             | personal success will never have any HN cred.
        
               | robertlagrant wrote:
               | > and thus no matter his personal success will never have
               | any HN cred
               | 
               | These sorts of comments really don't fit with what I've
               | seen here. HN is very encouraging even of personal
               | projects.
        
           | tiberious726 wrote:
           | > if I ever win the lottery and don't need a job I'm going to
           | spend some time learning Plan 9.
           | 
           | I'd recommend adding OpenGenera and IBM's systems I and Z to
           | that list: a whole bunch of us build careers out of
           | unnecessary unix make-work too
        
             | pjmlp wrote:
             | Also Mesa/XDE, Mesa/Cedar, Burroughs, Oberon, AOS, TAO,
             | Solo, MacOS and Lisa OS, Inferno, Amiga, Singularity,
             | Midori.
        
         | purple-leafy wrote:
         | Lol when I first had to use Linux at uni, I tried to set up a
         | hard-drive partition and wiped my windows partition. That was a
         | fun day, I knew nothing!
        
         | BrouteMinou wrote:
         | I started on an Amiga without a compiler, and I've learned my
         | first programming language there.
         | 
         | Then I got my first PC with Windows, and I learned a shit ton
         | on it.
         | 
         | I am sure you had little effort to get your games, didn't you?
         | 
         | If you wanted to code, you would have done the same effort to
         | get what you needed.
         | 
         | Magazines were a thing too...
         | 
         | Cheap excuses, the OS is irrelevant here.
        
           | worthless-trash wrote:
           | Not everyone had finances for magazines, not everyone lives
           | in a densely populated area where you can get access to
           | information, including libraries.
           | 
           | Many HN readers frequently forget they lived in the perfect
           | storm to allow their skills to grow.
        
             | ane wrote:
             | Indeed, as a kid of 10, I remember learning C/C++ thanks to
             | DJGPP, a DOS port of GCC, being free software. I didn't
             | have any money to buy a commercial compiler, though I never
             | asked my parents. I wasn't sure how to frame the question,
             | I guess. Well, regardless, getting your hands on a
             | commercial compiler wasn't that difficult in the late
             | 90s/early 00s. Soon after though small non-commercial indie
             | games kinda died out and everyone was using DirectX using
             | MSVC on Windows, until SDL came out.
        
           | homebrewer wrote:
           | I lived in bumfuck nowhere where there were basically no
           | developers (if you knew how to reinstall Windows you were
           | called "a genius kid"), no computer magazines, and access to
           | the internet was available through dial-up for an hour or two
           | in the middle of the night a couple of times per month
           | because it was:
           | 
           | 1) very slow -- my modem was never able to achieve more than
           | 2.5-3 KB/s, and
           | 
           | 2) pretty expensive given our measly salaries.
           | 
           | I also didn't speak English at all. I first got access to a
           | programming environment at 16, at an age where my Western
           | peers were starting to write operating systems: it was a copy
           | of "pirated" Delphi that came by pure chance. The first
           | couple of years I was making shit that wouldn't impress
           | anybody because there was nothing to learn from besides the
           | standard library, which would probably be achievable by a
           | computer science version of Ramanujan, but not by some random
           | dude like myself.
           | 
           | Please remember about the rest of the world before accusing
           | others of making "cheap excuses". Not every person on this
           | planet lived or lives in the middle of Manhattan; this may
           | very well include GP.
        
         | afavour wrote:
         | In all those years (and in years since) the most-used
         | programming environment was the web browser. But it always gets
         | written off.
         | 
         | I grew up in the MS-DOS era and my exposure to programming was
         | basically batch files too. That and editing CONFIG.SYS.
        
         | SOLAR_FIELDS wrote:
         | Opposite hot take: one of the main reasons I got into
         | programming was because Microsoft Access made it accessible
         | enough that I was confident enough to produce value even
         | knowing nothing about how to think like a software engineer
        
         | TimTheTinker wrote:
         | > only interpreter
         | 
         | Hey now, Windows Script Host (WSH) supported VBA and JScript
         | scripts. WSH was installed by default on systems up through
         | Windows 7, I believe. Scripts run though WSH had access to a
         | wide array of APIs -- a lot was possible. The WSH executable
         | (wscript.exe) was also configured to be the default handler for
         | .js files in Windows Explorer.
         | 
         | Also, HTA apps were an option. Write an HTML file, include a
         | <script> tag with either JS or VBA, and you have access to APIs
         | equivalent to a local HTML file opened on IE5, plus some. This
         | was a popular option at one point for powering CD-ROM autorun
         | menus, among other things.
         | 
         | (The company I worked for used embedded HTA in a massive C++
         | COM app to render some forms where the fields and values had to
         | be dynamic based on data only known at run time. Debugging was
         | horrible until I learned you could inject Firebug Lite into the
         | HTA apps and at least be able to console.log(). It was truly a
         | dark, dusty corner of Windows programming -- of which there
         | were many.)
        
           | badsectoracula wrote:
           | Yeah, WSH and VBA was available since Win98, though the
           | documentation was scarce and _not_ part of Windows itself
           | (compare with QBASIC someone else mentioned where not only it
           | came with documentation but the first thing it tells you when
           | you run it is how to open the documentation).
           | 
           | I did use it for an "Introduction to programming" magazine
           | article back in mid-2000s though, main reason because it was
           | already _there_ and all you had to do was open Notepad and
           | start typing (...and make sure you save with a .vbs and not a
           | .vbs.txt extension...). I even got an email a few years later
           | by someone telling me they got into programming because of it
           | :-P.
        
         | pjmlp wrote:
         | Yet those of us that started to program in the 1980's and older
         | decades, were able to acquire all the required programming
         | tools for Windows.
         | 
         | And we didn't had the Internet to learn from.
         | 
         | Personally I don't get this kind of excuses.
        
           | dijit wrote:
           | computers in the 80s only had a programming environment. You
           | would drop basically directly into an interpreter. So Windows
           | was an evolution for you.
           | 
           | I know this because my mother knew more how to program than I
           | did, and I was the one with the passion for it and she was
           | not.
           | 
           | I also discussed this recently with a 47-year-old programmer.
           | and we came to the same conclusion.
        
             | pjmlp wrote:
             | Which computers thought?
             | 
             | That wasn't true of CP/M, UNIX, VMS, Atari ST, Amiga, and
             | many others.
             | 
             | The reality was not the same as 8 bit home computers, and
             | even on those you were limited by BASIC. Anything else like
             | machine code, required the same learning effort.
             | 
             | If you wanted to program, you either bought the programming
             | tools, or pirated them, most of the time.
             | 
             | Then you would need to buy books, computer magazines, or
             | have the luck of local library with computing section, to
             | actually learn how to use them.
        
               | dijit wrote:
               | my mum had a Commodore 64, and before that a zx-spectrum
               | 
               | The only programming book in my local library was COBOL.
               | 
               | There was no included disk (it was missing) but in
               | hindsight, it would likely not have worked on windows
               | anyway.
               | 
               | Your premise is that I knew what I was looking for, I
               | kinda didn't.
               | 
               | My first proper exposure to programming anything was when
               | college told me there was a thing called visual studio
               | and .NET; its only later when installing linux that I
               | found that many of the systems were written in
               | interpreted languages and could be modified (yum, apt
               | etc).
               | 
               |  _That_ was extremely evolutionary for me.
        
               | pjmlp wrote:
               | My premise is lack of curiosity, or do you think a small
               | town in a country just out of 40 years of dictorship, and
               | colonial wars, was flowing with computing information all
               | over the place?
               | 
               | Just having access to electronics was revolutionary.
               | 
               | How would we even know what to look for, if it wasn't for
               | our curiosity?
        
               | dijit wrote:
               | Are you arguing that your experience was helped by that?
               | 
               | My premise is that Microsoft dominance took a few years
               | off my programming journey- obviously I was curious and
               | motivated because otherwise it would have been impossible
               | to he where I am now without motivation and curiosity.
               | 
               | I'm not entirely sure what your argument against this is
               | other than that you potentially had it worse, which is
               | not my point. Obviously motivation and curiosity are
               | enough _eventually_ , since we're here.
               | 
               | If Linux was the monoculture then it would have happened
               | sooner for me, much sooner.
        
               | pjmlp wrote:
               | My experience was helped by being curious, having the
               | luck to track down people, that provided software and
               | knowledge to learn in an offline world.
               | 
               | UNIX was already around doing those days, and it surely
               | wasn't that easier either, unless one was already at the
               | university with enough budget for their computing
               | infrastructure, or something like a bank, although in
               | many countries most likely the most advanced stuff would
               | be MS-DOS terminals connected via Novel Netware, running
               | Clipper applications.
        
           | kbolino wrote:
           | In my experience, there was a big difference between DOS,
           | where programming tools were relatively easy to find, and
           | Windows, where they weren't. Until widespread Internet
           | access, programming on Windows as a kid required finding the
           | rare adult who had access to the tools.
        
             | giancarlostoro wrote:
             | Downloading VB6 on dial up was torture as a 12 year old.
        
             | pjmlp wrote:
             | Find where?
             | 
             | Not in 1980's Portugal.
        
               | anthk wrote:
               | Maybe he meant debug.com. Not easy in the 90's in Spain
               | neither. And Visual C++ under Win32 from pirated CD's was
               | a nightware to start with.
               | 
               | In the 20000's, an early 3-DVD release (Sarge) was like
               | night and day. Properly documented with all the manuals
               | obtainable either thru Synaptic or the bundled magazine-
               | book.
        
               | hyperman1 wrote:
               | Gwbasic and later qbasic were delivered with MS-DOS
        
               | pjmlp wrote:
               | Yeah, but beyond the learning to program steps, it was
               | about time to acquire programming environments for
               | Quick/Turbo Pascal, NASM/TASM, Turbo/Quick Basic, Clipper
               | DBase,... by whatever means, and the same for the
               | knowledge how to use them, on an offline first world.
               | 
               | And for this, one had to be curious, track down people
               | with knowledge, either from computer magazines ads,
               | hanging around electronic stores, eventually find people
               | with similar interests, to meet them physically.
        
         | eek2121 wrote:
         | I got my start on a computer that booted to a BASIC prompt! :)
        
         | 0xDEFACED wrote:
         | wow, i also started using linux about 5 years ago due to
         | frustrations with getting python to work on windows
         | 
         | sure, the windows installer is easy enough to get set up, but
         | pretty quickly i started noticing a pattern in most
         | documentation/tutorials.
         | 
         | Linux: one-line setup command
         | 
         | Windows: nothing, or a complicated, multi-step process (that
         | rarely works without hiccups)
         | 
         | wasting my time going down rabbit holes debugging my
         | environment was not as fun as actually writing code
        
         | soerxpso wrote:
         | I do have fond memories of batch files, though. I showed my
         | classmates that it only took two lines of batch to make the
         | school library's computers open their disk drives every hour.
        
       | actionfromafar wrote:
       | For the upper right quadrant, something like a Silicon Graphics
       | might fit.
        
         | erik wrote:
         | Upper right quadrant would be an 8-bit (or maybe 16-bit) CPU
         | paired with a 3D graphics capable GPU. SNES + the SuperFX chip
         | is the closest example I can think of. Similarly, there is the
         | Genesis/Mega Drive + SVP chip.
         | 
         | I can't name a fully 8-bit machine with a 3d focused graphics
         | chip. Maybe there are arcade boards?
        
           | coolsunglasses wrote:
           | Mega Drive is probably earliest that was capable of it
           | really, but Namco System 21 and especially Sega Model 1
           | (1990) were designed with 3d/polygons in mind but have
           | relatively old chips in them. Programming for those things
           | could not have been easy.
        
           | wk_end wrote:
           | It's stretching the definition of "3D-focused graphics chip",
           | but an early example might be I, Robot. An 8-bit 6809 CPU
           | drives a custom polygon-pushing graphics processor. It's
           | primitive but must've been mind-blowing in 1984.
           | 
           | https://en.wikipedia.org/wiki/I,_Robot_(video_game)
        
         | lynguist wrote:
         | N64 is actually Silicon Graphics and it's upper left.
        
         | phire wrote:
         | You mean the early systems like the IRIS 2000?
         | 
         | It arguably fits, because it pairs a 68010 with hardware
         | accelerated 3d graphics. As far as I can tell, it's not quite
         | modern 3d graphics. If you paid for the geometry engine, you
         | did get hardware accelerated transform and clipping. And the
         | framebuffer supported hardware acceleration of 2d polygon. But
         | if you wanted texture mapping, that was all done on the CPU.
         | 
         | I don't think we can consider SGI as having "modern" 3d
         | accelerated graphics until they implemented support for
         | hardware accelerated texturing with the Reality Engine in 1992,
         | long after they switched to MIPS.
        
       | oxidant wrote:
       | This was an interesting read, thanks.
       | 
       | One nit on mobile (Firefox and Chrome, Android), your code blocks
       | overflow the background instead of scrolling.
        
         | yapyap wrote:
         | in safari as well
        
         | vanderZwan wrote:
         | Regarding the nit: this seems to be so common these days that
         | I'm wondering if it's a bug in a default CSS theme in a popular
         | static site generator or something
        
         | jonot wrote:
         | should be fixed now
        
       | dropbear3 wrote:
       | > How would you do [packed structs] in C?
       | 
       | Bitfields! This is valid C:                 struct foo {
       | unsigned bg_priority: 2;         unsigned character_base: 2;
       | // ...       };
        
         | purple-leafy wrote:
         | But C/ C-compilers don't guarantee your struct wont have holes
         | (by default), so you may have to do something like
         | __attribute__((packed)) to ensure they are packed structs:
         | struct bitmap_file_header         {           UWord signature;
         | UDWord file_size;           UWord reserved_1;           UWord
         | reserved_2;           UDWord file_offset_to_pixel_array;
         | } __attribute__((packed));
        
           | travisgriggs wrote:
           | There's also a directive (don't have code in front of me)
           | that you can do at file level that will cause all subsequent
           | struct defs to be packed...
           | 
           | #push(pragma(pack(0)) ??
           | 
           | I've done a lot of direct register access in C this way. I do
           | like Zigs ability to just define the different sizes though.
        
           | dropbear3 wrote:
           | This is not true of adjacent bitfields, at least for C99:
           | An implementation may allocate any addressable storage unit
           | large enough to hold a bit-field. If enough space remains, a
           | bit-field that immediately follows another bit-field in a
           | structure shall be packed into adjacent bits of the same
           | unit.
           | 
           | https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
           | 6.7.2.1 SS 10
        
         | MobiusHorizons wrote:
         | in microcontrollers it's very common to see code generated that
         | creates structs for the registers. They will typically output
         | fields that are a full machine word in size (or maybe in some
         | cases as small as a byte), and individual bits will be
         | addressed with bitmasking (ie `my_device.some_reg |=
         | SOME_REG_FLAG_NAME` or `my_device.some_reg &=
         | ~SOME_REG_FLAG_NAME` to clear it). It is sometimes necessary to
         | be thoughtful about batching writes so that certain bits are
         | set before the periferal begins some process. A trivial example
         | would be:                 port_a.data_out |= GPIOA_PIN_1 |
         | GPIOA_PIN_2;
         | 
         | and                 port_a.pin1 = true;       port_a.pin2 =
         | true;
        
           | kevin_thibedeau wrote:
           | This is why manufacturers don't do this for volatile register
           | access. You now have bloated, hazard prone code with multiple
           | read-modify-writes.
        
       | MobiusHorizons wrote:
       | > 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.
       | 
       | 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
        
         | pcwalton wrote:
         | This is controllable by customizing TargetLibraryInfo [1] for
         | your target in LLVM. Note, however, that detecting memcpy is
         | always a valid optimization in C, not just in userspace. The C
         | _language_ standard, not POSIX, requires that a function
         | spelled  "memcpy" be available.
         | 
         | As a side note, the optimization pass that detects and replaces
         | memcpy is called LoopIdiomRecognize [2]. It actually detects
         | quite a bit, not just memcpy.
         | 
         | [1]:
         | https://llvm.org/doxygen/TargetLibraryInfo_8cpp_source.html
         | 
         | [2]: https://llvm.org/doxygen/LoopIdiomRecognize_8cpp.html
        
           | MobiusHorizons wrote:
           | Very Interesting! I guess I would still expect the
           | optimization to use the library implementation of memcpy to
           | be invalid when interacting with memory mapped IO. In this
           | case the issue was the size of writes being issued (byte vs
           | word), but you can easily imagine other issues that would not
           | matter something like memcpy. I would have thought volatile
           | might have signaled this, even if the issue here is not
           | related to values being cached in registers. Does zig have a
           | version of volatile?
        
         | NobodyNada wrote:
         | The "correct" thing to do here is to use volatile writes to
         | tell the compiler that they must not be torn:
         | https://llvm.org/docs/LangRef.html#volatile-memory-accesses
         | 
         | > IR-level volatile loads and stores cannot safely be optimized
         | into llvm.memcpy or llvm.memmove intrinsics even when those
         | intrinsics are flagged volatile. Likewise, the backend should
         | never split or merge target-legal volatile load/store
         | instructions. Similarly, IR-level volatile loads and stores
         | cannot change from integer to floating-point or vice versa.
         | 
         | Even in a baremetal/OS context, the compiler is generally
         | allowed to split, combine, reorder, and eliminate memory access
         | however it likes as long as the end result is consistent. Being
         | able to do that is very important for performance and code
         | size, which _especially_ matters in embedded or OS dev -- for
         | example, inserting memcpy calls can save on code size for
         | things like passing a medium-sized struct to a function. The
         | memory model for any reasonably low-level programming language
         | nowadays requires you to specify whenever you actually need
         | memory access that look _exactly_ like you wrote.
         | 
         | The OP suggests:
         | 
         | > 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.
         | 
         | The downside to this approach is that the compiler doesn't
         | usually know what address range an arbitrary pointer will
         | acccess; it's not resolved until link-time or often runtime. So
         | this would require dynamic checks around _every single memory
         | access_ , which would kill performance. Thus, the solution is
         | to use volatile loads and stores for any memory ranges that
         | need special treatment.
        
         | matheusmoreira wrote:
         | Even GCC emits calls to memcpy. Even for freestanding nostdlib
         | targets. There is no way to turn it off. I had to implement
         | memcpy because of it. Incredibly annoying.
         | 
         | https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
         | 
         | > The compiler may generate calls to memcmp, memset, memcpy and
         | memmove.
        
         | tazjin wrote:
         | > llvm (which zig is based on)
         | 
         | Wasn't Zig moving off LLVM?
        
           | brabel wrote:
           | No, it is adding an alternative to it. LLVM, last I heard,
           | will still always be an option at least.
        
             | cgh wrote:
             | Have you been following
             | https://github.com/ziglang/zig/issues/16270 ?
        
       | klooney wrote:
       | > 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?
       | 
       | Brutal. I don't miss but banging much.
        
         | vanderZwan wrote:
         | I imagine it must be a real (occasionally Freudian) pain in the
         | ass
        
         | kookamamie wrote:
         | You either missed a 't' or an 'i'.
        
           | klooney wrote:
           | Oh good grief
        
         | sitzkrieg wrote:
         | ill take bit banging over retooling to a worse pile of software
         | written by clueless idiots every couple of years (muh clout)
         | 
         | its crazy how nice knowing 100% of whats going on is
        
       | zzo38computer wrote:
       | > 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?
       | 
       | 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.
        
         | yard2010 wrote:
         | How did you find the cause of it?
        
           | bdhcuidbebe wrote:
           | could it be... reading the docs?
        
             | bmacho wrote:
             | Ask IRC/Stackoverflow/Reddit/ChatGPT?
        
       | AndyKelley wrote:
       | > it would be nice if there was some way to specify how memory in
       | certain address ranges need to be addressed.
       | 
       | If making the respective loads and stores volatile doesn't solve
       | this problem please feel free to file a bug against the compiler.
       | 
       | https://ziglang.org/documentation/0.13.0/#volatile
        
         | ant6n wrote:
         | Oh look, small world!
        
           | AndyKelley wrote:
           | Howdy!
        
         | underdeserver wrote:
         | > 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?
         | 
         | Andrew (or any Zig mavens) - What would be the idiomatic way of
         | solving this issue? Can you define your own memcpy with
         | @std.mem.doNotOptimizeAway or something?
        
           | MatthiasPortzel wrote:
           | Andrew's point is that marking the memory as volatile should
           | prevent this optimization. (i.e. the compiler isn't allowed
           | to split a 16-bit volatile write into two 8-but writes.) This
           | is idiomatic because volatile is intended for MMIO.
           | 
           | There's a proposal for a way to disable LLVM generating
           | builtin calls like memcpy. But I'd argue volatile would still
           | be more appropriate in this case.
           | 
           | https://github.com/ziglang/zig/issues/22110
           | 
           | Edit: this comment from later in the thread is also relevant:
           | 
           | https://news.ycombinator.com/item?id=42556624
        
       | __loam wrote:
       | 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.
        
       | mysecretaccount wrote:
       | Why is the DS in the "Non-modern graphics" row? It does not use a
       | tile based renderer.
        
         | msephton wrote:
         | DS has both 2D tile-based renderer and 3D renderer. You can
         | find many examples of games with tiled graphics. I made a tile
         | map viewer for my favourite DS game
         | https://blog.gingerbeardman.com/2021/04/21/level-viewer-for-...
        
       | Dwedit wrote:
       | 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.
        
       | Validark wrote:
       | > 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.
       | 
       | Can you post the code that's impossible to write properly?
        
       | Validark wrote:
       | > 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.
       | 
       | Could you elaborate on this? Does LLVM support this feature? If
       | so, it might not be too hard to get it into Zig.
        
         | NobodyNada wrote:
         | I'm not a compiler dev and I don't know Zig, but I can think of
         | a couple of things that make this tricky:
         | 
         | - The compiler doesn't typically know anything about memory
         | address ranges; that's the linker's business.
         | 
         | - Even if you taught the compiler about memory address ranges,
         | the compiler often won't know what address ranges a pointer
         | could point to at runtime. For instance, suppose you declare a
         | function that takes a pointer as its parameter; and then maybe
         | elsewhere in your code you call it with pointers to various
         | address ranges. What's the compiler supposed to do, check the
         | pointer value at runtime and branch based on its address range?
         | That's certainly not good for performance or code size.
         | 
         | So we clearly need some way to "color" the pointer type itself
         | as belonging to a specific address range -- a function needs to
         | be able to declare what color of memory it wants to operate on,
         | and it should be an error to pass a wrong-colored pointer to a
         | function. Except you can already do this in programming
         | languages today! Create a wrapper type representing a pointer
         | to a specific type of memory (something like 'struct
         | VramPtr(*mut u32)' in Rust), and define read and write
         | functions that issue volatile writes of the correct type (or
         | even inline assembly if you need some specific instruction that
         | volatile doesn't guarantee).
        
       | latexr wrote:
       | > You can try the game out in an emulator <a href="">here</a>.
       | 
       | You left out the most important part of the post.
        
       ___________________________________________________________________
       (page generated 2024-12-31 23:00 UTC)