The Matrix StackĪnother concept that's worth understanding is the 'matrix stack'. For a more detailed picture of the relationship between the CPU and the RCP, see this diagram. The gfxTaskSwitch() function in graphic.c shows one implementation of this. We need to allocate separate instances of this shared data for each frame, and switch which instance we're using when starting a new frame, like a circular buffer.
#Mac os n64 emulator code
To do this, we will need to allocate some structures to hold the displaylists and other data that will be shared between the code which runs on the main CPU (our program) and the code which runs on the RCP (called 'microcode', provided in binary form as part of the SDK).
Rendering on the N64 is a cooperative act between the main CPU, which runs the game logic and produces the list of things to draw, and the RCP, which performs the drawing of one frame while the main CPU moves on to running the logic and producing the display list for the next frame.
#Mac os n64 emulator update
In updateGame00() we first read the controller input, then update these values as appropriate, each frame. In initStage00(), we initialized some state: the squaresRotationDirection boolean, and the squaresRotations array. Reading controller input and updating the game world This then calls initStage00() to initialize the level, and then registers the stage00 callback so that updateGame00(), and makeDL00() can be called on each frame.įrom there it's up to you to fill in the logic for these functions with your game-specific code. When a game using NuSystem boots, it runs the mainproc() function in main.c.
In NuSystem these functions are typically called initStage00(), updateGame00(), and makeDL00() respectively, where 00 is the stage/level number of the game. NuSystem removes the need to think about threads and initializing the hardware, and just lets you provide the typical setup(), update(), and draw() callbacks that form the core of many simple game engines. The N64 comes with an OS (really, a library that you link into your game binary and boot on the bare metal), which provides features like threads and I/O, but still requires a fair bit of boilerplate to get a game engine set up. The N64 SDK comes with a small framework for quickly starting a new game, called NuSystem. RetroReversing has a pretty good tutorial for installing and using the SDK under Wine, which will allow you to compile the code in this repo. the modern open source toolchain, which centers on the libdragon library and tools.