The other day I was working on my pet project ngdevkit, an open source C development kit for the Neo Geo hardware. I needed to write a simple clear_screen function, and I chose to do it in C for simplicity, in the hope that this would get efficiently compiled into 68000 assembly. That apparently innocuous task led me to some interesting findings regarding gcc, binutils, and how you can hint the compiler to generate efficient 68000 code for small loops to reclaim some of your precious clock cycles. A quick glimpse at the Neo Geo video hardware Back in the days, the Neo Geo MVS and AES hardware have gained a stellar reputation for their outstanding graphics capabilities for the time: complex parallax backgrounds, gigantic sprites on screen, thousands of colors... But conceptually, this hardware is surprisingly simple. The GPU can display sprites, which are essentially moving objects made out of 16×16 graphics tiles. On top of that it can render a fixed layer of 8×8 graphics tiles, which are non-moving objects used for in-game score, health bars and whatnot. The actual graphics content of a tile is stored in ROM and cannot be updated. At run-time, a dedicated Video RAM holds information about the sprites and tiles to render on screen, along with their attributes, such as color palette, position or scale factor. A simple clear screen function For now, let's just consider the fixed tile layer. This layer overlays the entire visible screen space (320×224 pixels) and is divided into 40×32 tiles of 8×8 pixel. The Video RAM uses one 16 bits word to describe each tile in the layer: 12 bits for a 8×8 tile index in the ROM, and 4 bits for a palette to be used by the GPU to render the tile on screen. Data for fix tiles are contiguous in Video RAM, so clearing the entire fixed tile layer is just a matter of looping over the Video RAM and setting the proper tile data to obtain a blank screen. So how would that look in C? Well, unlike regular RAM, The Video RAM is dedicated to the ...
First seen: 2025-10-02 09:47
Last seen: 2025-10-02 15:48