top of page
Search

[52] Non-Maskable Post

  • Writer: Conlan Walker
    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.

ree

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

ree

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.

ree

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

ree

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:

ree

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

ree

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.

ree

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.

 
 
 

Comments


bottom of page