Re:I Like and Use Global Variables
by pjc50 on Monday February 10, 2025 @04:56AM
(#42998689)
Emulators are often emulating "hardware globals", things like machine registers or GPU state where in the thing being emulated there really is only one instance.
[ Parent
| on HN ]
Unless it's an arcade machine like Bombjack which has two Z80s and three AY sound chips ;)
It's still possible to wrap all that as nested state in a single global, and it works just fine:
https://github.com/floooh/chips-test/blob/613dbfe907104f4110...
That's a single mutable global with all application state, but inside that global are nested structs and the code working on those structs takes essentially a 'this' pointer. This approach works well since it enforces a strictly hierarchical code and data structure with a single root-struct (and also a single root-source-file) at the top.