A Documenting of the Russian Roulette CHIP-8 Game This is documentation for the Russian roulette game provided in the sixth edition of VIPER magazine. Firstly, follows is a view of the program when it is first loaded into the tool: 200-201 0512-0513 ßß ÜßÜß 650A 25866 V5  010 202-203 0514-0515 Ü ß Ü ß 2288 08840 Call 0648 204-205 0516-0517 ßßßßÜ Û F20A 61962 V2  key 206-207 0518-0519 ßß ÜßÛ C305 49925 V3  ??? AND 005 208-209 0520-0521 ß Üßß 4304 17156 Skip next if V3 <> 004 20A-20B 0522-0523 ÜÛ Û 1232 04658 Jump to 0562 20C-20D 0524-0525 ßÜßÜÜ Û A25A 41562 I  0602 20E-20F 0526-0527 ßßÜ ß 6110 24848 V1  016 210-211 0528-0529 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 212-213 0530-0531 ßÜßÜÜÜÛÜ A25F 41567 I  0607 214-215 0532-0533 ßßÜÜ ß 6118 24856 V1  024 216-217 0534-0535 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 218-219 0536-0537 ßÜÛ Üß A264 41572 I  0612 21A-21B 0538-0539 ßÛ ß 6120 24864 V1  032 21C-21D 0540-0541 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 21E-21F 0542-0543 ßÛÜ ß 6430 25648 V4  048 220-221 0544-0545 ßßßÛ Û Ü F415 62485 delay  V4 222-223 0546-0547 ßßßß ÛÜÜ F407 62471 V4  delay 224-225 0548-0549 ßß ß 3400 13312 Skip next if V4 = 000 226-227 0550-0551 Üß Û 1222 04642 Jump to 0546 228-229 0552-0553 ÜÜÜ 00E0 00224 Clear the screen 22A-22B 0554-0555 ÜÛÛÛÜÛÜÛ 75FF 30207 V5  V5 + 255 22C-22D 0556-0557 ß ß ß 4500 17664 Skip next if V5 <> 000 22E-22F 0558-0559 Ü ß ÜÛ 1246 04678 Jump to 0582 230-231 0560-0561 ß Û 1202 04610 Jump to 0514 232-233 0562-0563 ßÜÛ Ü ßÜ A269 41577 I  0617 234-235 0564-0565 ßßÜ ß 6110 24848 V1  016 236-237 0566-0567 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 238-239 0568-0569 ßÜÛ ÜÜÛ A26E 41582 I  0622 23A-23B 0570-0571 ßßÜÜ ß 6118 24856 V1  024 23C-23D 0572-0573 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 23E-23F 0574-0575 ßÜÛÜ ÛÜ A273 41587 I  0627 240-241 0576-0577 ßÛ ß 6120 24864 V1  032 242-243 0578-0579 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 244-245 0580-0581 Ü ß Üß 1244 04676 Jump to 0580 246-247 0582-0583 ßÜÛÜÜ ß A278 41592 I  0632 248-249 0584-0585 ßßÜ ß 6110 24848 V1  016 24A-24B 0586-0587 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 24C-24D 0588-0589 ßÜÛÜÜÜßÜ A27D 41597 I  0637 24E-24F 0590-0591 ßßÜÜ ß 6118 24856 V1  024 250-251 0592-0593 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 252-253 0594-0595 Û ß Û A282 41602 I  0642 254-255 0596-0597 ßÛ ß 6120 24864 V1  032 256-257 0598-0599 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 258-259 0600-0601 Ü ÛÜ ß 1258 04696 Jump to 0600 25A-25B 0602-0603 Ûßß Û E888 59528 25C-25D 0604-0605 Û Û 8888 34952 25E-25F 0606-0607 ÛÛÛ ÛÛÛ EEEE 61166 260-261 0608-0609 Û Û 4848 18504 Skip next if V8 <> 072 262-263 0610-0611 ÜÛÜ ÛÜÜ 48EE 18670 Skip next if V8 <> 238 264-265 0612-0613 ÛÜß Û Û AACA 43722 I  2762 266-267 0614-0615 ÛÛ ß ß CAC0 51904 VA  ??? AND 192 268-269 0616-0617 ÛÜÛÜßÜÛÜ AAF7 43767 I  2807 26A-26B 0618-0619 ÛÜÛ ÛÜÛ 5577 21879 26C-26D 0620-0621 ÜÛÜÛ Û Û 55F5 22005 26E-26F 0622-0623 ÛÛ Û Û 6565 25957 V5  101 270-271 0624-0625 Û ßÜÛ Û 554D 21837 272-273 0626-0627 ÜÛ ÜßÛ Û 4DD5 19925 Skip next if VD <> 213 274-275 0628-0629 Û Û Û 1515 05397 Jump to 1301 276-277 0630-0631 ÜÛ Ü Ü Ü 40D5 16597 Skip next if V0 <> 213 278-279 0632-0633 Û Û ßÛ 8B89 35721 27A-27B 0634-0635 Û Ü Û Û 89A9 35241 27C-27D 0636-0637 ÛßÜÛß Ûß DBB2 56242 Draw 08x02 at VB,VB; VF  XOR 27E-27F 0638-0639 ÛßÜ Û 322A 12842 Skip next if V2 = 042 280-281 0640-0641 Ü Û ßÛ 26A2 09890 Call 1698 282-283 0642-0643 Û Û Û Û AAAA 43690 I  2730 284-285 0644-0645 ß ß ß ß AA00 43520 I  2560 286-287 0646-0647 ß Û ß ß AA20 43552 I  2592 288-289 0648-0649 Û ßÜ Û A292 41618 I  0658 28A-28B 0650-0651 ßßÜÜßß 6618 26136 V6  024 28C-28D 0652-0653 ßßÜ ßßß 6710 26384 V7  016 28E-28F 0654-0655 ßÛÜÛ ÛÛÜ D677 54903 Draw 08x07 at V6,V7; VF  XOR 290-291 0656-0657 ÜÜÜ ÜÜÜ 00EE 00238 Return 292-293 0658-0659 Ü Û Ü 082A 02090 Jump to COSMAC VIP 2090 294-295 0660-0661 ÛÛßßßÛÛ 7F63 32611 VF  VF + 099 296-297 0662-0663 ÛÛ ß ÛÛ 6B63 27491 VB  099 298-299 0664-0665 ÛÛÛÛÛÛÛ 7F7F 32639 VF  VF + 127 29A-29B 0666-0667 ÛÛÜÜÜÛÛ 637F 25471 V3  127 Follows now is the fully annotated view of the program when it is loaded into the tool: 200-201 0512-0513 ßß ÜßÜß 650A 25866 V5  010 202-203 0514-0515 Ü ß Ü ß 2288 08840 begin Call draw gun 204-205 0516-0517 ßßßßÜ Û F20A 61962 V2  key 206-207 0518-0519 ßß ÜßÛ C305 49925 V3  ??? AND 005 208-209 0520-0521 ß Üßß 4304 17156 Skip next if V3 <> 004 20A-20B 0522-0523 ÜÛ Û 1232 04658 Jump to lose 20C-20D 0524-0525 ßÜßÜÜ Û A25A 41562 I  cl 20E-20F 0526-0527 ßßÜ ß 6110 24848 V1  016 210-211 0528-0529 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 212-213 0530-0531 ßÜßÜÜÜÛÜ A25F 41567 I  ic 214-215 0532-0533 ßßÜÜ ß 6118 24856 V1  024 216-217 0534-0535 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 218-219 0536-0537 ßÜÛ Üß A264 41572 I  k!! 21A-21B 0538-0539 ßÛ ß 6120 24864 V1  032 21C-21D 0540-0541 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 21E-21F 0542-0543 ßÛÜ ß 6430 25648 V4  048 220-221 0544-0545 ßßßÛ Û Ü F415 62485 delay  V4 222-223 0546-0547 ßßßß ÛÜÜ F407 62471 delay V4  delay 224-225 0548-0549 ßß ß 3400 13312 Skip next if V4 = 000 226-227 0550-0551 Üß Û 1222 04642 Jump to delay 228-229 0552-0553 ÜÜÜ 00E0 00224 Clear the screen 22A-22B 0554-0555 ÜÛÛÛÜÛÜÛ 75FF 30207 V5  V5 + 255 22C-22D 0556-0557 ß ß ß 4500 17664 Skip next if V5 <> 000 22E-22F 0558-0559 Ü ß ÜÛ 1246 04678 Jump to win 230-231 0560-0561 ß Û 1202 04610 Jump to begin 232-233 0562-0563 ßÜÛ Ü ßÜ A269 41577 lose I  ba 234-235 0564-0565 ßßÜ ß 6110 24848 V1  016 236-237 0566-0567 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 238-239 0568-0569 ßÜÛ ÜÜÛ A26E 41582 I  n 23A-23B 0570-0571 ßßÜÜ ß 6118 24856 V1  024 23C-23D 0572-0573 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 23E-23F 0574-0575 ßÜÛÜ ÛÜ A273 41587 I  g!! 240-241 0576-0577 ßÛ ß 6120 24864 V1  032 242-243 0578-0579 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 244-245 0580-0581 Ü ß Üß 1244 04676 self Jump to self 246-247 0582-0583 ßÜÛÜÜ ß A278 41592 win I  w 248-249 0584-0585 ßßÜ ß 6110 24848 V1  016 24A-24B 0586-0587 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 24C-24D 0588-0589 ßÜÛÜÜÜßÜ A27D 41597 I  in 24E-24F 0590-0591 ßßÜÜ ß 6118 24856 V1  024 250-251 0592-0593 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 252-253 0594-0595 Û ß Û A282 41602 I  !!!! 254-255 0596-0597 ßÛ ß 6120 24864 V1  032 256-257 0598-0599 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 258-259 0600-0601 Ü ÛÜ ß 1258 04696 end Jump to end 25A 0602 ÛÛÛ Û E8 232 cl 25B 0603 Û Û 88 136 25C 0604 Û Û 88 136 25D 0605 Û Û 88 136 25E 0606 ÛÛÛ ÛÛÛ EE 238 25F 0607 ÛÛÛ ÛÛÛ EE 238 ic 260 0608 Û Û 48 072 261 0609 Û Û 48 072 262 0610 Û Û 48 072 263 0611 ÛÛÛ ÛÛÛ EE 238 264 0612 Û Û Û Û AA 170 k!! 265 0613 ÛÛ Û Û CA 202 266 0614 ÛÛ Û Û CA 202 267 0615 ÛÛ C0 192 268 0616 Û Û Û Û AA 170 269 0617 ÛÛÛÛ ÛÛÛ F7 247 ba 26A 0618 Û Û Û Û 55 085 26B 0619 ÛÛÛ ÛÛÛ 77 119 26C 0620 Û Û Û Û 55 085 26D 0621 ÛÛÛÛ Û Û F5 245 26E 0622 ÛÛ Û Û 65 101 n 26F 0623 ÛÛ Û Û 65 101 270 0624 Û Û Û Û 55 085 271 0625 Û ÛÛ Û 4D 077 272 0626 Û ÛÛ Û 4D 077 273 0627 ÛÛ Û Û Û D5 213 g!! 274 0628 Û Û Û 15 021 275 0629 Û Û Û 15 021 276 0630 Û 40 064 277 0631 ÛÛ Û Û Û D5 213 278 0632 Û Û ÛÛ 8B 139 w 279 0633 Û Û Û 89 137 27A 0634 Û Û Û 89 137 27B 0635 Û Û Û Û A9 169 27C 0636 ÛÛ ÛÛ ÛÛ DB 219 27D 0637 Û ÛÛ Û B2 178 in 27E 0638 ÛÛ Û 32 050 27F 0639 Û Û Û 2A 042 280 0640 Û ÛÛ 26 038 281 0641 Û Û Û A2 162 282 0642 Û Û Û Û AA 170 !!!! 283 0643 Û Û Û Û AA 170 284 0644 Û Û Û Û AA 170 285 0645 00 000 286 0646 Û Û Û Û AA 170 287 0647 Û 20 032 288-289 0648-0649 Û ßÜ Û A292 41618 draw gun I  gun 28A-28B 0650-0651 ßßÜÜßß 6618 26136 V6  024 28C-28D 0652-0653 ßßÜ ßßß 6710 26384 V7  016 28E-28F 0654-0655 ßÛÜÛ ÛÛÜ D677 54903 Draw 08x07 at V6,V7; VF  XOR 290-291 0656-0657 ÜÜÜ ÜÜÜ 00EE 00238 Return 292 0658 Û 08 008 gun 293 0659 Û Û Û 2A 042 294 0660 ÛÛÛÛÛÛÛ 7F 127 295 0661 ÛÛ ÛÛ 63 099 296 0662 ÛÛ Û ÛÛ 6B 107 297 0663 ÛÛ ÛÛ 63 099 298 0664 ÛÛÛÛÛÛÛ 7F 127 299 0665 ÛÛÛÛÛÛÛ 7F 127 29A 0666 ÛÛ ÛÛ 63 099 29B 0667 ÛÛÛÛÛÛÛ 7F 127 The register usage is as follows: V0 Unused. V1 Horizontal positioning of text sprites. V2 Store a key. V3 Contain a randomly generated number of zero, one, four, or five; vertical positioning of text sprites. V4 Manipulating the sound register. V5 Contain the number of iterations of the game. V6 Horizontal positioning of gun sprite. V7 Vertical positioning of gun sprite. V8 Unused. V9 Unused. VA Unused. VB Unused. VC Unused. VD Unused. VE Unused. VF Unused. The program begins by initializing register 5 and then entering the prime loop of the program, which I name ``begin'' by convention, which starts with calling the draw gun routine: 200-201 0512-0513 ßß ÜßÜß 650A 25866 V5  010 202-203 0514-0515 Ü ß Ü ß 2288 08840 begin Call draw gun The prime loop, sans the draw gun routine, is responsible for the entire game. Once the routine returns, the program waits for input to simulate pulling the trigger and then generates the 1/4 chance of losing, jumping to the lose routine in that case: 204-205 0516-0517 ßßßßÜ Û F20A 61962 V2  key 206-207 0518-0519 ßß ÜßÛ C305 49925 V3  ??? AND 005 208-209 0520-0521 ß Üßß 4304 17156 Skip next if V3 <> 004 20A-20B 0522-0523 ÜÛ Û 1232 04658 Jump to lose Otherwise, the game displays ``CLICK!!'' drawn using three sprites: 20C-20D 0524-0525 ßÜßÜÜ Û A25A 41562 I  cl 20E-20F 0526-0527 ßßÜ ß 6110 24848 V1  016 210-211 0528-0529 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 212-213 0530-0531 ßÜßÜÜÜÛÜ A25F 41567 I  ic 214-215 0532-0533 ßßÜÜ ß 6118 24856 V1  024 216-217 0534-0535 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 218-219 0536-0537 ßÜÛ Üß A264 41572 I  k!! 21A-21B 0538-0539 ßÛ ß 6120 24864 V1  032 21C-21D 0540-0541 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR The game then enters a delay of 48/60 of a second using a simple subloop: 21E-21F 0542-0543 ßÛÜ ß 6430 25648 V4  048 220-221 0544-0545 ßßßÛ Û Ü F415 62485 delay  V4 222-223 0546-0547 ßßßß ÛÜÜ F407 62471 delay V4  delay 224-225 0548-0549 ßß ß 3400 13312 Skip next if V4 = 000 226-227 0550-0551 Üß Û 1222 04642 Jump to delay The game then clears the screen to ease screen management and decrements the game counter by adding two's complement negative one to the iteration counter. It then checks if the game has iterated the appropriate number of times and jumps to the win routine if so; if not, it finishes the loop: 228-229 0552-0553 ÜÜÜ 00E0 00224 Clear the screen 22A-22B 0554-0555 ÜÛÛÛÜÛÜÛ 75FF 30207 V5  V5 + 255 22C-22D 0556-0557 ß ß ß 4500 17664 Skip next if V5 <> 000 22E-22F 0558-0559 Ü ß ÜÛ 1246 04678 Jump to win 230-231 0560-0561 ß Û 1202 04610 Jump to begin The lose routine displays ``BANG!!'' drawn using three sprites and then ends the game. It is interesting to note that, as CHIP-8 lacks an instruction to exit the game, the game simply enters an infinite loop upon finishing: 232-233 0562-0563 ßÜÛ Ü ßÜ A269 41577 lose I  ba 234-235 0564-0565 ßßÜ ß 6110 24848 V1  016 236-237 0566-0567 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 238-239 0568-0569 ßÜÛ ÜÜÛ A26E 41582 I  n 23A-23B 0570-0571 ßßÜÜ ß 6118 24856 V1  024 23C-23D 0572-0573 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 23E-23F 0574-0575 ßÜÛÜ ÛÜ A273 41587 I  g!! 240-241 0576-0577 ßÛ ß 6120 24864 V1  032 242-243 0578-0579 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 244-245 0580-0581 Ü ß Üß 1244 04676 self Jump to self The win routine is identical in structure to the lose routine, but displays ``WIN!!!!'' instead and then ends the game: 246-247 0582-0583 ßÜÛÜÜ ß A278 41592 win I  w 248-249 0584-0585 ßßÜ ß 6110 24848 V1  016 24A-24B 0586-0587 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 24C-24D 0588-0589 ßÜÛÜÜÜßÜ A27D 41597 I  in 24E-24F 0590-0591 ßßÜÜ ß 6118 24856 V1  024 250-251 0592-0593 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 252-253 0594-0595 Û ß Û A282 41602 I  !!!! 254-255 0596-0597 ßÛ ß 6120 24864 V1  032 256-257 0598-0599 ßßÜÛ Ü Û D135 53557 Draw 08x05 at V1,V3; VF  XOR 258-259 0600-0601 Ü ÛÜ ß 1258 04696 end Jump to end Following the prime loop are the CL, IC, K!, BA, N, G!!, W, IN, and !!!! sprites and an insignificant byte; it's reasonable to assume this byte is padding so that the following code is aligned to an even address; there's no reason seen for its particular value, however: 25A 0602 ÛÛÛ Û E8 232 cl 25B 0603 Û Û 88 136 25C 0604 Û Û 88 136 25D 0605 Û Û 88 136 25E 0606 ÛÛÛ ÛÛÛ EE 238 25F 0607 ÛÛÛ ÛÛÛ EE 238 ic 260 0608 Û Û 48 072 261 0609 Û Û 48 072 262 0610 Û Û 48 072 263 0611 ÛÛÛ ÛÛÛ EE 238 264 0612 Û Û Û Û AA 170 k!! 265 0613 ÛÛ Û Û CA 202 266 0614 ÛÛ Û Û CA 202 267 0615 ÛÛ C0 192 268 0616 Û Û Û Û AA 170 269 0617 ÛÛÛÛ ÛÛÛ F7 247 ba 26A 0618 Û Û Û Û 55 085 26B 0619 ÛÛÛ ÛÛÛ 77 119 26C 0620 Û Û Û Û 55 085 26D 0621 ÛÛÛÛ Û Û F5 245 26E 0622 ÛÛ Û Û 65 101 n 26F 0623 ÛÛ Û Û 65 101 270 0624 Û Û Û Û 55 085 271 0625 Û ÛÛ Û 4D 077 272 0626 Û ÛÛ Û 4D 077 273 0627 ÛÛ Û Û Û D5 213 g!! 274 0628 Û Û Û 15 021 275 0629 Û Û Û 15 021 276 0630 Û 40 064 277 0631 ÛÛ Û Û Û D5 213 278 0632 Û Û ÛÛ 8B 139 w 279 0633 Û Û Û 89 137 27A 0634 Û Û Û 89 137 27B 0635 Û Û Û Û A9 169 27C 0636 ÛÛ ÛÛ ÛÛ DB 219 27D 0637 Û ÛÛ Û B2 178 in 27E 0638 ÛÛ Û 32 050 27F 0639 Û Û Û 2A 042 280 0640 Û ÛÛ 26 038 281 0641 Û Û Û A2 162 282 0642 Û Û Û Û AA 170 !!!! 283 0643 Û Û Û Û AA 170 284 0644 Û Û Û Û AA 170 285 0645 00 000 286 0646 Û Û Û Û AA 170 287 0647 Û 20 032 Lastly, there is the draw gun routine, which merely displays the gun sprite and then returns. As it is only called from one location, it would be simple to move this routine and then eliminate the call instruction, the return instruction, and the padding byte immediately following this routine: 288-289 0648-0649 Û ßÜ Û A292 41618 draw gun I  gun 28A-28B 0650-0651 ßßÜÜßß 6618 26136 V6  024 28C-28D 0652-0653 ßßÜ ßßß 6710 26384 V7  016 28E-28F 0654-0655 ßÛÜÛ ÛÛÜ D677 54903 Draw 08x07 at V6,V7; VF  XOR 290-291 0656-0657 ÜÜÜ ÜÜÜ 00EE 00238 Return 292 0658 Û 08 008 gun 293 0659 Û Û Û 2A 042 294 0660 ÛÛÛÛÛÛÛ 7F 127 295 0661 ÛÛ ÛÛ 63 099 296 0662 ÛÛ Û ÛÛ 6B 107 297 0663 ÛÛ ÛÛ 63 099 298 0664 ÛÛÛÛÛÛÛ 7F 127 299 0665 ÛÛÛÛÛÛÛ 7F 127 29A 0666 ÛÛ ÛÛ 63 099 29B 0667 ÛÛÛÛÛÛÛ 7F 127 .