Skip to content

Gradual VRAM loading

Pre-release
Pre-release
Compare
Choose a tag to compare
@qguv qguv released this 27 May 23:07
· 98 commits to master since this release

Play this version directly in your browser

This version introduces gradual loading of levels that are wider than the Gameboy's VRAM! In the previous version, the level was limited to what would fit in VRAM, which meant you could walk over the edge of the world as it wrapped around. With this version, you can now walk to the end of the level, even though the level is larger then what would fit in memory. The level will continue to load as the Gameboy's display wraps around the edge of its available VRAM.

In the gif below, the left side shows the Gameboy screen, and the right side shows what's actually loaded in the Gameboy VRAM. The moving window on the right represents what the screen is currently displaying. Tiles are loaded from the map into VRAM just before the screen moves to show them.

1590620220_recording

In this release I also got a better handle on how subroutine calling works using unconditional calls (call lbl) and returns (ret), conditional calls (call cc,lbl) and returns (ret cc), and tail-call optimizations using conditional (jp lbl) and unconditional (jp cc,lbl) absolute jumps.

I had some trouble with rgbasm because I was using relative jumps with labels (jr lbl) as a micro-optimization for absolute jumps with labels (jp lbl). If more code is added between the jump and the label being jumped to, such that the label is over one register width (0xff) away from the jump, rgbasm crashes with a syntax error and a less-than-helpful explanation text. Maybe I should submit a patch…

In any case, all relative jumps are replaced with absolute jumps for stability as new code is being written. Maybe I can add an optimization step in the build pipeline that replaces these with relative jumps when possible, repeatedly reassembling to check whether it works. I've found some other easy machine optimizations on the way as well—maybe I should just write an optimizer for rgbds…

It's nice to be writing Gameboy assembly again! I think I'll work on the player character next.

Bonus: I wrote an archlinux package for bgb so that it behaves more like a native binary.