How Long Can You Fall?
Fahrfall isn't about running though a maze while eating dots, nor is it about jumping barrels or shooting aliens. It is all about staying on the screen for as long as possible. So, the basic scoring mechanism will be based on game time. Future versions will likely have bonus items to grab or maybe other score modifiers based on how you play the game. But for now the score will really be a glorified clock.
The frame loop is timed based on the vertical sync signal from the video output. Hooking this sixty Hertz timer seems like a natural place to start. But, bumping the score on every frame leads to scores that advance too quickly to read -- fast enough to roll the score in about five hours.
Maybe it is unrealistic to think that anyone would play Fahrfall for five hours...but I can dream! :-) Plus, I don't want the score to roll prematurely when I later add bonus items and whatnot. So, I introduced a countdown timer that gets reset every time the score is advanced. Now I have the count increasing four times per second. If someone plays Fahrfall for seventy-five straight hours then they deserve to see the score roll over!!
Count It Up
The obvious vessel for the score in memory would be a multi-byte binary integer -- something like an "unsigned long" in the C programming language. Updating an integer like that is relatively simple, even in an 8-bit processor's assembly language. Unfortunately, such a representation is not directly compatible with the CoCo's display. Repeatedly converting from a multi-byte binary integer to a display-compatible format seems like a waste of CPU cycles.
The VDG uses hexadecimal values 0x30 through 0x39 to represent the normal digits '0' through '9' respectively. If the score is kept in a compatible format, then the score can simply be dumped to the display whenever it is needed. This is easily accomplished by implementing a cascaded decade counter based on the value in the lower nibble of each byte. This technique uses only a few more cycles than incrementing a multi-byte binary integer and it avoids the need to do any further conversion for displaying the score.
Every arcade game needs a high-score display! People like having that objective to reach, even if such an achievement is always ephemeral. So, after the current score is incremented, Fahrfall compares it to the recorded high-score. The comparison starts with the most-signifcant byte and proceeds until it finds two uequal values. If the current score is higher, it is copied to the high-score position. There is only one trick here -- the high-score is displayed using digits that use a color set that is the inverse of the current score's color set!
The VDG is using hexadecimal values 0x70 through 0x79 for the high-score digits. So, the score comparison needs to convert each byte value before comparing the score digits. Also, if a new high-score is achieved then the current score digits need to be converted before moving them to the high-score area. This is a simple detail, but without this the two score displays would look exactly alike.
So, Fahrfall now has one more feature implemented. It is starting to look like a real game! Hopefully I will be able to nail-down a few more basic features in time for the end of the RetroChallenge Winter Warmup. I might even have time for a few extras by then as well -- stay tuned!