Index  Comments

Here is the program itself and the program metadata.

Both of falling.chip8 and falling.mmc are available under the CC0 Public Domain Dedication.

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:

200-201 0512-0513 ▀ █  ▄█  A226 41510                 I ← from
202-203 0514-0515 ▀██▀ █ ▄ F465 62565                 Load V0→V4; I ← I + 05
204-205 0516-0517 ▀▀▄▄ ▄█▄ C237 49719                 V2 ← ??? AND 055
206-207 0518-0519 ▀▀  ▄▄██ C30F 49935                 V3 ← ??? AND 015
208-209 0520-0521 ▀▀█▀▄ ▀█ F329 62249                 I ← digit sprite of V3
20A-20B 0522-0523 ▀█ ▀ ▄▀▄ D245 53829           prime Draw 08×05 at V2,V4; VF ← XOR
20C-20D 0524-0525 ▀▀▀█ ▄ █ F115 61717                 delay ← V1
20E-20F 0526-0527 █▀█   ▀█ E3A1 58273           delay Skip next if V3 <> key
210-211 0528-0529   ▄▀  █  1222 04642                 Jump to hit
212-213 0530-0531 ▀▀▀▀▀███ FF07 65287                 VF ← delay
214-215 0532-0533   ▀▀▀▀▀▀ 3F00 16128                 Skip next if VF = 000
216-217 0534-0535    ▀▄▄█  120E 04622                 Jump to delay
218-219 0536-0537 ▀▄ ▀     9040 36928                 Skip next if V0 <> V4
21A-21B 0538-0539    █▄ █  121A 04634            self Jump to self
21C-21D 0540-0541 ▀█ ▀ ▄▀▄ D245 53829                 Draw 08×05 at V2,V4; VF ← XOR
21E-21F 0542-0543  ▀▀▀ ▀ ▄ 7401 29697                 V4 ← V4 + 001
220-221 0544-0545    ▀▄ █  120A 04618                 Jump to prime
222-223 0546-0547 ▄▄▄      00E0 00224             hit Clear the screen
224-225 0548-0549    ▀  ▀  1200 04608                 Jump to 0512
226     0550         ██ ██   1B   027            from
227     0551           █     04   004

The register usage is as follows:

  1. V0 Hold the bottom boundary vertical coordinate.
  2. V1 Hold the delay.
  3. V2 Hold the sprite horizontal coordinate.
  4. V3 Hold a key code.
  5. V4 Hold the sprite vertical coordinate.
  6. V5 Unused.
  7. V6 Unused.
  8. V7 Unused.
  9. V8 Unused.
  10. V9 Unused.
  11. VA Unused.
  12. VB Unused.
  13. VC Unused.
  14. VD Unused.
  15. VE Unused.
  16. 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:

  1. V0 Ease of access.
  2. V1 Ease of access.
  3. V2 Ease of access.
  4. V3 Ease of access.
  5. V4 Ease of access.
  6. V5 Unused.
  7. V6 Unused.
  8. V7 Unused.
  9. V8 Unused.
  10. V9 Unused.
  11. VA Unused.
  12. VB Unused.
  13. VC Unused.
  14. VD Unused.
  15. VE Unused.
  16. 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:

200-201 0512-0513 ▀ █  ▄█  A226 41510                 I ← from
202-203 0514-0515 ▀██▀ █ ▄ F465 62565                 Load V0→V4; I ← I + 05
204-205 0516-0517 ▀▀▄▄ ▄█▄ C237 49719                 V2 ← ??? AND 055
206-207 0518-0519 ▀▀  ▄▄██ C30F 49935                 V3 ← ??? AND 015
208-209 0520-0521 ▀▀█▀▄ ▀█ F329 62249                 I ← digit sprite of V3

The sprite is drawn at its current position starting from the top and then the delay is set:

20A-20B 0522-0523 ▀█ ▀ ▄▀▄ D245 53829           prime Draw 08×05 at V2,V4; VF ← XOR
20C-20D 0524-0525 ▀▀▀█ ▄ █ F115 61717                 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:

20E-20F 0526-0527 █▀█   ▀█ E3A1 58273           delay Skip next if V3 <> key
210-211 0528-0529   ▄▀  █  1222 04642                 Jump to hit
212-213 0530-0531 ▀▀▀▀▀███ FF07 65287                 VF ← delay
214-215 0532-0533   ▀▀▀▀▀▀ 3F00 16128                 Skip next if VF = 000
216-217 0534-0535    ▀▄▄█  120E 04622                 Jump to delay

If the key sprite has hit the bottom of the screen, the game ends:

218-219 0536-0537 ▀▄ ▀     9040 36928                 Skip next if V0 <> V4
21A-21B 0538-0539    █▄ █  121A 04634            self 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:

21C-21D 0540-0541 ▀█ ▀ ▄▀▄ D245 53829                 Draw 08×05 at V2,V4; VF ← XOR
21E-21F 0542-0543  ▀▀▀ ▀ ▄ 7401 29697                 V4 ← V4 + 001
220-221 0544-0545    ▀▄ █  120A 04618                 Jump to prime

If the correct key has been hit, the screen is cleared and the game restarts:

222-223 0546-0547 ▄▄▄      00E0 00224             hit Clear the screen
224-225 0548-0549    ▀  ▀  1200 04608                 Jump to 0512

The game ends with two constants for the bottom vertical coordinate and delay:

226     0550         ██ ██   1B   027            from
227     0551           █     04   004

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.