[52] Non-Maskable Post
- Conlan Walker

- Oct 6, 2022
- 2 min read
I don't think many would be surprised if told that making a general-purpose NES game engine is difficult, painful, and time consuming.
This week, I got some distance in one area, before realizing that something is completely broken in another.

First, though, I started the week by compartmentalizing some of the source code into relevant sections.
So, problem 1: scrolling gives unpredictable lag spikes.
To solve this problem, I need to isolate the components which are involved.
Technically, scrolling is defined in 3 places:
C function binding and usage
Assembly routine
Section in vblank interrupt routine

At the highest level, the C binding of ppuScroll is supposed to be used this way, shown left.
I say "binding" because the function isn't actually made in C.
This is what ppuScroll actually does, in its assembly implementation.
All this does is changes three values in RAM, with one acting as a flag that announces that the real scroll values be updated at some point.

Finally, this part of the vblank routine actually writes the desired scroll values to the PPU.

This makes for an exciting system with at least 3 points on failure.
The C code that uses ppuScroll could be broken, or ppuScroll itself could be broken, or even the code inside the vblank routine could be broken.
Better still, there's the possibility that all 3 should work as intended, with the source of the problem being some unrelated code somewhere else.
I'm more or less adept at debugging in C-like languages, but I am less so in the context of assembly. Especially when that assembly is supposed to interface with C.
Problem 2: Changes to background tiles fail inexplicably sometimes.
Working:

Not working (there should be a "!" there instead of a space):

I think I fixed some of the problem by unsetting the flag that determines changes to the background before writing to the appropriate buffer, hopefully ensuring that garbage data doesn't get written to VRAM.

It seemed to work for some time, but that might have just been through some microscopic timing change, because as soon as I messed up the feng shui of other parts of the program, it started breaking again.
Other than some music practice I don't have tangible proof of, this is about where I'm at now.
I wanted some great breakthrough to mark one year (52 weeks) of these posts, but I guess you can't always get what you want.
That's it for this week.

![[158] Most Important Brick in the Least Important Wall](https://static.wixstatic.com/media/df100d_f70be6ae4318455fbbc605cd1069c6ee~mv2.jpg/v1/fill/w_980,h_410,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/df100d_f70be6ae4318455fbbc605cd1069c6ee~mv2.jpg)
![[157] Mail Order Sacrifice](https://static.wixstatic.com/media/df100d_e284fa6c51b04524bab9d3cf9f1f6441~mv2.png/v1/fill/w_980,h_382,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/df100d_e284fa6c51b04524bab9d3cf9f1f6441~mv2.png)
![[156] Moat of Babble](https://static.wixstatic.com/media/df100d_091e451794b14aecb494a16c15c966c3~mv2.png/v1/fill/w_980,h_705,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/df100d_091e451794b14aecb494a16c15c966c3~mv2.png)
Comments