A Documenting of my Falling CHIP-8 Game This is a documenting of my Falling game I've written. This program was written for the Octo Jam VI event; as with those other programs of mine, only the fully annotated view will be shown here and so follows is a view of the program when it is first loaded into the tool: [32m200-201 [31m0512-0513 [34m▀ █ ▄█ A226 41510 [39m I ← from [32m202-203 [31m0514-0515 [34m▀██▀ █ ▄ F465 62565 [39m Load V0→V4; I ← I + 05 [32m204-205 [31m0516-0517 [34m▀▀▄▄ ▄█▄ C237 49719 [39m V2 ← ??? AND 055 [32m206-207 [31m0518-0519 [34m▀▀ ▄▄██ C30F 49935 [39m V3 ← ??? AND 015 [32m208-209 [31m0520-0521 [34m▀▀█▀▄ ▀█ F329 62249 [39m I ← digit sprite of V3 [32m20A-20B [31m0522-0523 [34m▀█ ▀ ▄▀▄ D245 53829 [33m prime[39m Draw 08×05 at V2,V4; VF ← XOR [32m20C-20D [31m0524-0525 [34m▀▀▀█ ▄ █ F115 61717 [39m delay ← V1 [32m20E-20F [31m0526-0527 [34m█▀█ ▀█ E3A1 58273 [33m delay[39m Skip next if V3 <> key [32m210-211 [31m0528-0529 [34m ▄▀ █ 1222 04642 [39m Jump to hit [32m212-213 [31m0530-0531 [34m▀▀▀▀▀███ FF07 65287 [39m VF ← delay [32m214-215 [31m0532-0533 [34m ▀▀▀▀▀▀ 3F00 16128 [39m Skip next if VF = 000 [32m216-217 [31m0534-0535 [34m ▀▄▄█ 120E 04622 [39m Jump to delay [32m218-219 [31m0536-0537 [34m▀▄ ▀ 9040 36928 [39m Skip next if V0 <> V4 [32m21A-21B [31m0538-0539 [34m █▄ █ 121A 04634 [33m self[39m Jump to self [32m21C-21D [31m0540-0541 [34m▀█ ▀ ▄▀▄ D245 53829 [39m Draw 08×05 at V2,V4; VF ← XOR [32m21E-21F [31m0542-0543 [34m ▀▀▀ ▀ ▄ 7401 29697 [39m V4 ← V4 + 001 [32m220-221 [31m0544-0545 [34m ▀▄ █ 120A 04618 [39m Jump to prime [32m222-223 [31m0546-0547 [34m▄▄▄ 00E0 00224 [33m hit[39m Clear the screen [32m224-225 [31m0548-0549 [34m ▀ ▀ 1200 04608 [39m Jump to 0512 [32m226 [31m0550 [34m ██ ██ 1B 027 [33m from [32m227 [31m0551 [34m █ 04 004[39m The register usage is as follows: V0 Hold the bottom boundary vertical coordinate. V1 Hold the delay. V2 Hold the sprite horizontal coordinate. V3 Hold a key code. V4 Hold the sprite vertical coordinate. V5 Unused. V6 Unused. V7 Unused. V8 Unused. V9 Unused. VA Unused. VB Unused. VC Unused. VD Unused. VE Unused. VF Manipulating the delay register. As I'm the author of this program, I will discuss the history of it to a point, as opposed to a more bare examination. This program was written to adhere to the strictest CHIP-8 timing requirements of seven or ten instructions per second and to be the smallest it could be. I struggled to write games which were compelling and had these qualities. Even a tennis game I'd planned would reasonably need more instructions per second, and was planned to be much more complex through self-modification, but I recalled playing this manner of game fifteen or so years ago on what is now vintage hardware and I wondered how it would distill to the environment. I'm pleased to write this game captures the basic essence of CHIP-8, I think, and I was able to write this across the span of just half an hour or so. The registers were chosen for the following reasons: V0 Ease of access. V1 Ease of access. V2 Ease of access. V3 Ease of access. V4 Ease of access. V5 Unused. V6 Unused. V7 Unused. V8 Unused. V9 Unused. VA Unused. VB Unused. VC Unused. VD Unused. VE Unused. VF Unimportance. The program begins by initializing the first five registers to their respective values and zero; the registers two and three don't strictly need initializing, but register four does. Registers two and three are set to random horizontal coordinates and key codes respectively, and I is set once more to its only other value: [32m200-201 [31m0512-0513 [34m▀ █ ▄█ A226 41510 [39m I ← from [32m202-203 [31m0514-0515 [34m▀██▀ █ ▄ F465 62565 [39m Load V0→V4; I ← I + 05 [32m204-205 [31m0516-0517 [34m▀▀▄▄ ▄█▄ C237 49719 [39m V2 ← ??? AND 055 [32m206-207 [31m0518-0519 [34m▀▀ ▄▄██ C30F 49935 [39m V3 ← ??? AND 015 [32m208-209 [31m0520-0521 [34m▀▀█▀▄ ▀█ F329 62249 [39m I ← digit sprite of V3 The sprite is drawn at its current position starting from the top and then the delay is set: [32m20A-20B [31m0522-0523 [34m▀█ ▀ ▄▀▄ D245 53829 [33m prime[39m Draw 08×05 at V2,V4; VF ← XOR [32m20C-20D [31m0524-0525 [34m▀▀▀█ ▄ █ F115 61717 [39m delay ← V1 The delay loop checks for input as it exhausts and enters the hit routine if the correct key is hit, falling through after the delay is exhausted, if not. If the four instructions comprising the delay code were removed, this game would be exactly thirty-two octets large: [32m20E-20F [31m0526-0527 [34m█▀█ ▀█ E3A1 58273 [33m delay[39m Skip next if V3 <> key [32m210-211 [31m0528-0529 [34m ▄▀ █ 1222 04642 [39m Jump to hit [32m212-213 [31m0530-0531 [34m▀▀▀▀▀███ FF07 65287 [39m VF ← delay [32m214-215 [31m0532-0533 [34m ▀▀▀▀▀▀ 3F00 16128 [39m Skip next if VF = 000 [32m216-217 [31m0534-0535 [34m ▀▄▄█ 120E 04622 [39m Jump to delay If the key sprite has hit the bottom of the screen, the game ends: [32m218-219 [31m0536-0537 [34m▀▄ ▀ 9040 36928 [39m Skip next if V0 <> V4 [32m21A-21B [31m0538-0539 [34m █▄ █ 121A 04634 [33m self[39m Jump to self Otherwise, the sprite is erased and its vertical coordinate is incremented to lower it closer to the bottom for the next iteration: [32m21C-21D [31m0540-0541 [34m▀█ ▀ ▄▀▄ D245 53829 [39m Draw 08×05 at V2,V4; VF ← XOR [32m21E-21F [31m0542-0543 [34m ▀▀▀ ▀ ▄ 7401 29697 [39m V4 ← V4 + 001 [32m220-221 [31m0544-0545 [34m ▀▄ █ 120A 04618 [39m Jump to prime If the correct key has been hit, the screen is cleared and the game restarts: [32m222-223 [31m0546-0547 [34m▄▄▄ 00E0 00224 [33m hit[39m Clear the screen [32m224-225 [31m0548-0549 [34m ▀ ▀ 1200 04608 [39m Jump to 0512 The game ends with two constants for the bottom vertical coordinate and delay: [32m226 [31m0550 [34m ██ ██ 1B 027 [33m from [32m227 [31m0551 [34m █ 04 004[39m It's obvious this program could be reduced in size by one octet by using a 441B instruction in place of 9040 and using register zero instead for manipulating the delay register. This has been done due to wanting to use an even number of octets for the program, although I may later return and optimize this program for that last octet and also rearrange registers to use the minimal loading instruction at a later date. It should be known I found I could reduce the size of this program by two octets, merely by removing the two explicit data octets and using instructions as the replacement. By adjusting register usage a tad, I can easily load registers from location 0531 or 0545 and so have access to both a low delay value and a zero, which are all I truly need. However, I won't revise this program to include these changes, as they're obvious and higher delay values make this game less fun; this can be adjusted by increasing the drop rate and bottom vertical coordinate, but then a smooth animation is lost. Also, it ceases to be worthwhile to modify the delay in any way; these disadvantages don't weigh well with a two octet cost. In any case, it's possible and I feel silly for not realizing these optimizations as I was originally writing the program; reviewing my interest of this manner of programming is what reminded me I'd yet to attempt such a thing with this program.