A Documenting of the Nim CHIP-8 Game This is documentation for the nim 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  ▀█ ▀▀█▄ 6E23 28195  VE ← 035 202-203 0514-0515  ▀▀ ▀▀▄▀ 6D02 27906  VD ← 002 204-205 0516-0517  ▄█ █ 2262 08802  Call 0610 206-207 0518-0519 ▀▀▀▀█▀▄ FC0A 64522  VC ← key 208-209 0520-0521  ▀ ██▄▄ 4C0F 19471  Skip next if VC <> 015 20A-20B 0522-0523  █▄ ▀ 1218 04632  Jump to 0536 20C-20D 0524-0525  ▀▀ ▀ ▀▄ 6A01 27137  VA ← 001 20E-20F 0526-0527 █ ▄ ▀█▀▄ 8EA5 36517  VE ← VE − VA; VF ← borrow 210-211 0528-0529  ▄█ █ 2262 08802  Call 0610 212-213 0530-0531 █ ▄ ▀█ █ 8DA5 36261  VD ← VD − VA; VF ← borrow 214-215 0532-0533  ▀ ▀▀▀ 4E00 19968  Skip next if VE <> 000 216-217 0534-0535 ▄ ▀ █ 1282 04738  Jump to 0642 218-219 0536-0537  ▀▀ ▀ ▄ 6801 26625  V8 ← 001 21A-21B 0538-0539 █▀█ ▀ ▄ E8A1 59553  Skip next if V8 <> key 21C-21D 0540-0541  ▄▀ ▄█ 1226 04646  Jump to 0550 21E-21F 0542-0543  ▀▀▀▀ ▄ 7801 30721  V8 ← V8 + 001 220-221 0544-0545  ▀▀▀▄ 3804 14340  Skip next if V8 = 004 222-223 0546-0547  █▄ █ 121A 04634  Jump to 0538 224-225 0548-0549  █▄ ▀ 1218 04632  Jump to 0536 226-227 0550-0551 █▄▄ ▀ ▀ 85E0 34272  V5 ← VE 228-229 0552-0553 █ █ █ 8585 34181  V5 ← V5 − V8; VF ← borrow 22A-22B 0554-0555  ▀▀▀▀▀█ 3F01 16129  Skip next if VF = 001 22C-22D 0556-0557  █▄ ▀ 1218 04632  Jump to 0536 22E-22F 0558-0559 █ ▀█▀▄ 8E85 36485  VE ← VE − V8; VF ← borrow 230-231 0560-0561  ▄█ █ 2262 08802  Call 0610 232-233 0562-0563  ▀ ▀▀▀ 4E00 19968  Skip next if VE <> 000 234-235 0564-0565 ▄ █ █ 1292 04754  Jump to 0658 236-237 0566-0567  ██▄▀ ▀ 6970 26992  V9 ← 112 238-239 0568-0569 ▀▀▀█▀▄ █ F915 63765  delay ← V9 23A-23B 0570-0571 ▀▀▀▀▀▄▄█ F907 63751  V9 ← delay 23C-23D 0572-0573  ▀▀▀ ▀ 3900 14592  Skip next if V9 = 000 23E-23F 0574-0575  ▄█▄ █ 123A 04666  Jump to 0570 240-241 0576-0577 █▄ █▀ 98D0 39120  Skip next if V8 <> VD 242-243 0578-0579  ▄ █ ▀ 1250 04688  Jump to 0592 244-245 0580-0581 █ ▀▀▀ 8780 34688  V7 ← V8 246-247 0582-0583 █▄ ▄ ▀▀ 86D0 34512  V6 ← VD 248-249 0584-0585 ▀▄▄ █▀█ 8765 34661  V7 ← V7 − V6; VF ← borrow 24A-24B 0586-0587  ▀ ▀▀▀▀ 4F00 20224  Skip next if VF <> 000 24C-24D 0588-0589  ▄ █ ▀ 1250 04688  Jump to 0592 24E-24F 0590-0591  ▀▀▀▀█ ▀ 7D04 32004  VD ← VD + 004 250-251 0592-0593 █ ▀█ █ 8D85 36229  VD ← VD − V8; VF ← borrow 252-253 0594-0595  ▀▀▀▀ ▀ 3D00 15616  Skip next if VD = 000 254-255 0596-0597  ▄ █▄ █ 125A 04698  Jump to 0602 256-257 0598-0599  ▀▀ ▀█ ▀ 6D04 27908  VD ← 004 258-259 0600-0601  ▀▄▄▀ 120C 04620  Jump to 0524 25A-25B 0602-0603 █▄ ▄▀█▀▄ 8ED5 36565  VE ← VE − VD; VF ← borrow 25C-25D 0604-0605  ▄█ █ 2262 08802  Call 0610 25E-25F 0606-0607  ▀▀ ▀█ ▀ 6D04 27908  VD ← 004 260-261 0608-0609  █▄ ▀ 1218 04632  Jump to 0536 262-263 0610-0611 ▀▀▀██ ▀ FA18 64024  sound ← VA 264-265 0612-0613 ▄▄▄ 00E0 00224  Clear the screen 266-267 0614-0615 ▀▄▀▄ ▀▀ A350 41808  I ← 0848 268-269 0616-0617 ▀▀██▀▀█▄ FE33 65075  VE as BCD stored from I 26A-26B 0618-0619  ▀▀▄ ▀▀ 6310 25360  V3 ← 016 26C-26D 0620-0621  ▀▀ ▀ ▀▀ 6B00 27392  VB ← 000 26E-26F 0622-0623 ▀██▀ ▄▀▄ F265 62053  Load V0→V2; I ← I + 03 270-271 0624-0625 ▀▀█▀▄ ▄ F029 61481  I ← digit sprite of V0 272-273 0626-0627 █▀▄█ ▄▀█ D3B5 54197  Draw 08×05 at V3,VB; VF ← XOR 274-275 0628-0629  ▀▀▀ ▄▀█ 7305 29445  V3 ← V3 + 005 276-277 0630-0631 ▀▀█▀▄ █ F129 61737  I ← digit sprite of V1 278-279 0632-0633 █▀▄█ ▄▀█ D3B5 54197  Draw 08×05 at V3,VB; VF ← XOR 27A-27B 0634-0635  ▀▀▀ ▄▀█ 7305 29445  V3 ← V3 + 005 27C-27D 0636-0637 ▀▀█▀▄ ▀▄ F229 61993  I ← digit sprite of V2 27E-27F 0638-0639 █▀▄█ ▄▀█ D3B5 54197  Draw 08×05 at V3,VB; VF ← XOR 280-281 0640-0641 ▄▄▄ ▄▄▄ 00EE 00238  Return 282-283 0642-0643 █ █ █ A2A2 41634  I ← 0674 284-285 0644-0645  ▀▀ 6000 24576  V0 ← 000 286-287 0646-0647  ▀▀▄ ▄ █ 6115 24853  V1 ← 021 288-289 0648-0649 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 28A-28B 0650-0651 █ █ ▄█▄ A2A7 41639  I ← 0679 28C-28D 0652-0653  ▀▀ ▄ 6008 24584  V0 ← 008 28E-28F 0654-0655 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 290-291 0656-0657 ▄ █ ▀ 1290 04752  Jump to 0656 292-293 0658-0659 █ █ ▄▄▀ A2AC 41644  I ← 0684 294-295 0660-0661  ▀▀ 6000 24576  V0 ← 000 296-297 0662-0663  ▀▀▄ ▀ 6110 24848  V1 ← 016 298-299 0664-0665 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 29A-29B 0666-0667 █ █▄ ▀▄ A2B1 41649  I ← 0689 29C-29D 0668-0669  ▀▀ ▄ 6008 24584  V0 ← 008 29E-29F 0670-0671 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 2A0-2A1 0672-0673 ▄ ▄▀ ▀ 12A0 04768  Jump to 0672 2A2-2A3 0674-0675 █ █ ▀█ 8B89 35721 2A4-2A5 0676-0677 █ ▄ █ █ 89A9 35241 2A6-2A7 0678-0679 █▀▄█▀ █▀ DBB2 56242  Draw 08×02 at VB,VB; VF ← XOR 2A8-2A9 0680-0681  █▀▄ █ 322A 12842  Skip next if V2 = 042 2AA-2AB 0682-0683 ▄ █ ██ 26A6 09894  Call 1702 2AC-2AD 0684-0685 █ █▀█ 8E8A 36490 2AE-2AF 0686-0687 █ █ █ 8A8A 35466 2B0-2B1 0688-0689 ███ ███ EEEE 61166 2B2-2B3 0690-0691 █▄▄ █▄ 88EC 35052 2B4-2B5 0692-0693 ▄▄█ █▄▄ 28EE 10478  Call 2286 Follows now is the fully annotated view of the program when it is loaded into the tool: 200-201 0512-0513  ▀█ ▀▀█▄ 6E23 28195  VE ← 035 202-203 0514-0515  ▀▀ ▀▀▄▀ 6D02 27906  VD ← 002 204-205 0516-0517  ▄█ █ 2262 08802  Call count and sound 206-207 0518-0519 ▀▀▀▀█▀▄ FC0A 64522  VC ← key 208-209 0520-0521  ▀ ██▄▄ 4C0F 19471  Skip next if VC <> 015 20A-20B 0522-0523  █▄ ▀ 1218 04632  Jump to ready input 20C-20D 0524-0525  ▀▀ ▀ ▀▄ 6A01 27137  begin VA ← 001 20E-20F 0526-0527 █ ▄ ▀█▀▄ 8EA5 36517  VE ← VE − VA; VF ← borrow 210-211 0528-0529  ▄█ █ 2262 08802  Call count and sound 212-213 0530-0531 █ ▄ ▀█ █ 8DA5 36261  VD ← VD − VA; VF ← borrow 214-215 0532-0533  ▀ ▀▀▀ 4E00 19968  Skip next if VE <> 000 216-217 0534-0535 ▄ ▀ █ 1282 04738  Jump to win 218-219 0536-0537  ▀▀ ▀ ▄ 6801 26625  ready input V8 ← 001 21A-21B 0538-0539 █▀█ ▀ ▄ E8A1 59553  input Skip next if V8 <> key 21C-21D 0540-0541  ▄▀ ▄█ 1226 04646  Jump to validate 21E-21F 0542-0543  ▀▀▀▀ ▄ 7801 30721  V8 ← V8 + 001 220-221 0544-0545  ▀▀▀▄ 3804 14340  Skip next if V8 = 004 222-223 0546-0547  █▄ █ 121A 04634  Jump to input 224-225 0548-0549  █▄ ▀ 1218 04632  Jump to ready input 226-227 0550-0551 █▄▄ ▀ ▀ 85E0 34272  validate V5 ← VE 228-229 0552-0553 █ █ █ 8585 34181  V5 ← V5 − V8; VF ← borrow 22A-22B 0554-0555  ▀▀▀▀▀█ 3F01 16129  Skip next if VF = 001 22C-22D 0556-0557  █▄ ▀ 1218 04632  Jump to ready input 22E-22F 0558-0559 █ ▀█▀▄ 8E85 36485  VE ← VE − V8; VF ← borrow 230-231 0560-0561  ▄█ █ 2262 08802  Call count and sound 232-233 0562-0563  ▀ ▀▀▀ 4E00 19968  Skip next if VE <> 000 234-235 0564-0565 ▄ █ █ 1292 04754  Jump to lose 236-237 0566-0567  ██▄▀ ▀ 6970 26992  V9 ← 112 238-239 0568-0569 ▀▀▀█▀▄ █ F915 63765  delay ← V9 23A-23B 0570-0571 ▀▀▀▀▀▄▄█ F907 63751  delay V9 ← delay 23C-23D 0572-0573  ▀▀▀ ▀ 3900 14592  Skip next if V9 = 000 23E-23F 0574-0575  ▄█▄ █ 123A 04666  Jump to delay 240-241 0576-0577 █▄ █▀ 98D0 39120  Skip next if V8 <> VD 242-243 0578-0579  ▄ █ ▀ 1250 04688  Jump to adjust 244-245 0580-0581 █ ▀▀▀ 8780 34688  V7 ← V8 246-247 0582-0583 █▄ ▄ ▀▀ 86D0 34512  V6 ← VD 248-249 0584-0585 ▀▄▄ █▀█ 8765 34661  V7 ← V7 − V6; VF ← borrow 24A-24B 0586-0587  ▀ ▀▀▀▀ 4F00 20224  Skip next if VF <> 000 24C-24D 0588-0589  ▄ █ ▀ 1250 04688  Jump to adjust 24E-24F 0590-0591  ▀▀▀▀█ ▀ 7D04 32004  VD ← VD + 004 250-251 0592-0593 █ ▀█ █ 8D85 36229  adjust VD ← VD − V8; VF ← borrow 252-253 0594-0595  ▀▀▀▀ ▀ 3D00 15616  Skip next if VD = 000 254-255 0596-0597  ▄ █▄ █ 125A 04698  Jump to correct 256-257 0598-0599  ▀▀ ▀█ ▀ 6D04 27908  VD ← 004 258-259 0600-0601  ▀▄▄▀ 120C 04620  Jump to begin 25A-25B 0602-0603 █▄ ▄▀█▀▄ 8ED5 36565  correct VE ← VE − VD; VF ← borrow 25C-25D 0604-0605  ▄█ █ 2262 08802  Call count and sound 25E-25F 0606-0607  ▀▀ ▀█ ▀ 6D04 27908  VD ← 004 260-261 0608-0609  █▄ ▀ 1218 04632  Jump to ready input 262-263 0610-0611 ▀▀▀██ ▀ FA18 64024 count and sound sound ← VA 264-265 0612-0613 ▄▄▄ 00E0 00224  Clear the screen 266-267 0614-0615 ▀▄▀▄ ▀▀ A350 41808  I ← 0848 268-269 0616-0617 ▀▀██▀▀█▄ FE33 65075  VE as BCD stored from I 26A-26B 0618-0619  ▀▀▄ ▀▀ 6310 25360  V3 ← 016 26C-26D 0620-0621  ▀▀ ▀ ▀▀ 6B00 27392  VB ← 000 26E-26F 0622-0623 ▀██▀ ▄▀▄ F265 62053  Load V0→V2; I ← I + 03 270-271 0624-0625 ▀▀█▀▄ ▄ F029 61481  I ← digit sprite of V0 272-273 0626-0627 █▀▄█ ▄▀█ D3B5 54197  Draw 08×05 at V3,VB; VF ← XOR 274-275 0628-0629  ▀▀▀ ▄▀█ 7305 29445  V3 ← V3 + 005 276-277 0630-0631 ▀▀█▀▄ █ F129 61737  I ← digit sprite of V1 278-279 0632-0633 █▀▄█ ▄▀█ D3B5 54197  Draw 08×05 at V3,VB; VF ← XOR 27A-27B 0634-0635  ▀▀▀ ▄▀█ 7305 29445  V3 ← V3 + 005 27C-27D 0636-0637 ▀▀█▀▄ ▀▄ F229 61993  I ← digit sprite of V2 27E-27F 0638-0639 █▀▄█ ▄▀█ D3B5 54197  Draw 08×05 at V3,VB; VF ← XOR 280-281 0640-0641 ▄▄▄ ▄▄▄ 00EE 00238  Return 282-283 0642-0643 █ █ █ A2A2 41634  win I ← wi 284-285 0644-0645  ▀▀ 6000 24576  V0 ← 000 286-287 0646-0647  ▀▀▄ ▄ █ 6115 24853  V1 ← 021 288-289 0648-0649 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 28A-28B 0650-0651 █ █ ▄█▄ A2A7 41639  I ← n 28C-28D 0652-0653  ▀▀ ▄ 6008 24584  V0 ← 008 28E-28F 0654-0655 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 290-291 0656-0657 ▄ █ ▀ 1290 04752  self Jump to self 292-293 0658-0659 █ █ ▄▄▀ A2AC 41644  lose I ← lo 294-295 0660-0661  ▀▀ 6000 24576  V0 ← 000 296-297 0662-0663  ▀▀▄ ▀ 6110 24848  V1 ← 016 298-299 0664-0665 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 29A-29B 0666-0667 █ █▄ ▀▄ A2B1 41649  I ← se 29C-29D 0668-0669  ▀▀ ▄ 6008 24584  V0 ← 008 29E-29F 0670-0671 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 2A0-2A1 0672-0673 ▄ ▄▀ ▀ 12A0 04768  end Jump to end 2A2 0674 █ █ ██ 8B 139  wi 2A3 0675 █ █ █ 89 137 2A4 0676 █ █ █ 89 137 2A5 0677 █ █ █ █ A9 169 2A6 0678 ██ ██ ██ DB 219 2A7 0679 █ ██ █ B2 178  n 2A8 0680  ██ █ 32 050 2A9 0681  █ █ █ 2A 042 2AA 0682  █ ██ 26 038 2AB 0683 █ █ ██ A6 166 2AC 0684 █ ███ 8E 142  lo 2AD 0685 █ █ █ 8A 138 2AE 0686 █ █ █ 8A 138 2AF 0687 █ █ █ 8A 138 2B0 0688 ███ ███ EE 238 2B1 0689 ███ ███ EE 238  se 2B2 0690 █ █ 88 136 2B3 0691 ███ ██ EC 236 2B4 0692  █ █ 28 040 2B5 0693 ███ ███ EE 238 The register usage is as follows: V0 Load from I and then BCD display; horizontal positioning of win and lose sprites. V1 Load from I and then BCD display; vertical positioning of win and lose sprites. V2 Load from I and then BCD display. V3 Horizontal positioning of BCD sprites. V4 Unused. V5 Store another register's value. V6 Store another register's value. V7 Store another register's value. V8 Store a key and the player decrement. V9 Manipulating the delay register. VA Manipulating the sound register and a decrement. VB Vertical positioning of BCD sprites. VC Store a key. VD Store the machine decrement. VE Store the count. VF Borrow checking. The game begins by setting registers thirteen and fourteen to the machine decrement and count, respectively, before calling the count and sound routine: 200-201 0512-0513  ▀█ ▀▀█▄ 6E23 28195  VE ← 035 202-203 0514-0515  ▀▀ ▀▀▄▀ 6D02 27906  VD ← 002 204-205 0516-0517  ▄█ █ 2262 08802  Call count and sound Register twelve is then used to compare the key being hit with fifteen, in which case the ready input routine is skipped; this is equivalent to deciding whether the player or machine goes first: 206-207 0518-0519 ▀▀▀▀█▀▄ FC0A 64522  VC ← key 208-209 0520-0521  ▀ ██▄▄ 4C0F 19471  Skip next if VC <> 015 20A-20B 0522-0523  █▄ ▀ 1218 04632  Jump to ready input If the key pressed was fifteen, then the prime loop of the program is entered. Here, register ten is set to its only value of one and used to decrement register fourteen before the count and sound routine is entered again: 20C-20D 0524-0525  ▀▀ ▀ ▀▄ 6A01 27137  begin VA ← 001 20E-20F 0526-0527 █ ▄ ▀█▀▄ 8EA5 36517  VE ← VE − VA; VF ← borrow 210-211 0528-0529  ▄█ █ 2262 08802  Call count and sound Register ten is then used to decrement register thirteen and it's here that the win routine is entered if register fourteen is zero, meaning the machine has taken the last values and so lost: 212-213 0530-0531 █ ▄ ▀█ █ 8DA5 36261  VD ← VD − VA; VF ← borrow 214-215 0532-0533  ▀ ▀▀▀ 4E00 19968  Skip next if VE <> 000 216-217 0534-0535 ▄ ▀ █ 1282 04738  Jump to win The input routine checks for keys one through four using register eight and the ready input routine initializes it; when such a key is pressed, the validate routine is entered: 218-219 0536-0537  ▀▀ ▀ ▄ 6801 26625  ready input V8 ← 001 21A-21B 0538-0539 █▀█ ▀ ▄ E8A1 59553  input Skip next if V8 <> key 21C-21D 0540-0541  ▄▀ ▄█ 1226 04646  Jump to validate 21E-21F 0542-0543  ▀▀▀▀ ▄ 7801 30721  V8 ← V8 + 001 220-221 0544-0545  ▀▀▀▄ 3804 14340  Skip next if V8 = 004 222-223 0546-0547  █▄ █ 121A 04634  Jump to input 224-225 0548-0549  █▄ ▀ 1218 04632  Jump to ready input The validate routine initializes register five as a scratch register for register fourteen and subtracts the value of the key. If there is a borrow, meaning there was an attempt to take more than was available, the ready input routine is entered again to get a valid answer. If not, the amount is valid and register fourteen is decremented by this amount and the count and sound routine is entered again. It is noteworthy that a check for not zero would be better than a check for one here. If register fourteen is zero, meaning the player has taken the last values, then the lose routine is entered: 226-227 0550-0551 █▄▄ ▀ ▀ 85E0 34272  validate V5 ← VE 228-229 0552-0553 █ █ █ 8585 34181  V5 ← V5 − V8; VF ← borrow 22A-22B 0554-0555  ▀▀▀▀▀█ 3F01 16129  Skip next if VF = 001 22C-22D 0556-0557  █▄ ▀ 1218 04632  Jump to ready input 22E-22F 0558-0559 █ ▀█▀▄ 8E85 36485  VE ← VE − V8; VF ← borrow 230-231 0560-0561  ▄█ █ 2262 08802  Call count and sound 232-233 0562-0563  ▀ ▀▀▀ 4E00 19968  Skip next if VE <> 000 234-235 0564-0565 ▄ █ █ 1292 04754  Jump to lose A delay of 112/60 of a second is then exhausted: 236-237 0566-0567  ██▄▀ ▀ 6970 26992  V9 ← 112 238-239 0568-0569 ▀▀▀█▀▄ █ F915 63765  delay ← V9 23A-23B 0570-0571 ▀▀▀▀▀▄▄█ F907 63751  delay V9 ← delay 23C-23D 0572-0573  ▀▀▀ ▀ 3900 14592  Skip next if V9 = 000 23E-23F 0574-0575  ▄█▄ █ 123A 04666  Jump to delay If register eight and thirteen are equal, the adjust routine is entered. If not, registers six and seven are used as scratch registers to determine which is greater, with the adjust routine being entered if register eight is not greater than register thirteen, with register thirteen being incremented by four, otherwise: 240-241 0576-0577 █▄ █▀ 98D0 39120  Skip next if V8 <> VD 242-243 0578-0579  ▄ █ ▀ 1250 04688  Jump to adjust 244-245 0580-0581 █ ▀▀▀ 8780 34688  V7 ← V8 246-247 0582-0583 █▄ ▄ ▀▀ 86D0 34512  V6 ← VD 248-249 0584-0585 ▀▄▄ █▀█ 8765 34661  V7 ← V7 − V6; VF ← borrow 24A-24B 0586-0587  ▀ ▀▀▀▀ 4F00 20224  Skip next if VF <> 000 24C-24D 0588-0589  ▄ █ ▀ 1250 04688  Jump to adjust 24E-24F 0590-0591  ▀▀▀▀█ ▀ 7D04 32004  VD ← VD + 004 Register thirteen is decremented by register eight and, if zero, the correct routine is entered. If not, register thirteen is set to four and the prime loop of the game is entered again: 250-251 0592-0593 █ ▀█ █ 8D85 36229  adjust VD ← VD − V8; VF ← borrow 252-253 0594-0595  ▀▀▀▀ ▀ 3D00 15616  Skip next if VD = 000 254-255 0596-0597  ▄ █▄ █ 125A 04698  Jump to correct 256-257 0598-0599  ▀▀ ▀█ ▀ 6D04 27908  VD ← 004 258-259 0600-0601  ▀▄▄▀ 120C 04620  Jump to begin Register fourteen is decremented by register thirteen, the count and sound routine is entered again, and register thirteen is set to four before the ready input routine is entered again: 25A-25B 0602-0603 █▄ ▄▀█▀▄ 8ED5 36565  correct VE ← VE − VD; VF ← borrow 25C-25D 0604-0605  ▄█ █ 2262 08802  Call count and sound 25E-25F 0606-0607  ▀▀ ▀█ ▀ 6D04 27908  VD ← 004 260-261 0608-0609  █▄ ▀ 1218 04632  Jump to ready input The count and sound routine gives a sound of 1/60 of a second before clearing the screen and displaying register fourteen using scratch space pointing to an unimportant location. It is noteworthy that register ten is not set before the first time this routine is called: 262-263 0610-0611 ▀▀▀██ ▀ FA18 64024 count and sound sound ← VA 264-265 0612-0613 ▄▄▄ 00E0 00224  Clear the screen 266-267 0614-0615 ▀▄▀▄ ▀▀ A350 41808  I ← 0848 268-269 0616-0617 ▀▀██▀▀█▄ FE33 65075  VE as BCD stored from I 26A-26B 0618-0619  ▀▀▄ ▀▀ 6310 25360  V3 ← 016 26C-26D 0620-0621  ▀▀ ▀ ▀▀ 6B00 27392  VB ← 000 26E-26F 0622-0623 ▀██▀ ▄▀▄ F265 62053  Load V0→V2; I ← I + 03 270-271 0624-0625 ▀▀█▀▄ ▄ F029 61481  I ← digit sprite of V0 272-273 0626-0627 █▀▄█ ▄▀█ D3B5 54197  Draw 08×05 at V3,VB; VF ← XOR 274-275 0628-0629  ▀▀▀ ▄▀█ 7305 29445  V3 ← V3 + 005 276-277 0630-0631 ▀▀█▀▄ █ F129 61737  I ← digit sprite of V1 278-279 0632-0633 █▀▄█ ▄▀█ D3B5 54197  Draw 08×05 at V3,VB; VF ← XOR 27A-27B 0634-0635  ▀▀▀ ▄▀█ 7305 29445  V3 ← V3 + 005 27C-27D 0636-0637 ▀▀█▀▄ ▀▄ F229 61993  I ← digit sprite of V2 27E-27F 0638-0639 █▀▄█ ▄▀█ D3B5 54197  Draw 08×05 at V3,VB; VF ← XOR 280-281 0640-0641 ▄▄▄ ▄▄▄ 00EE 00238  Return The win routine displays the WI and N sprites before entering an infinite loop; as CHIP-8 lacks an instruction to exit a game, there is simply a jump instruction that jumps to itself to accomplish this: 282-283 0642-0643 █ █ █ A2A2 41634  win I ← wi 284-285 0644-0645  ▀▀ 6000 24576  V0 ← 000 286-287 0646-0647  ▀▀▄ ▄ █ 6115 24853  V1 ← 021 288-289 0648-0649 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 28A-28B 0650-0651 █ █ ▄█▄ A2A7 41639  I ← n 28C-28D 0652-0653  ▀▀ ▄ 6008 24584  V0 ← 008 28E-28F 0654-0655 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 290-291 0656-0657 ▄ █ ▀ 1290 04752  self Jump to self The lose routine is similar to the win routine, but chooses a lower position and displays the LO and SE sprites before entering its ending infinite loop: 292-293 0658-0659 █ █ ▄▄▀ A2AC 41644  lose I ← lo 294-295 0660-0661  ▀▀ 6000 24576  V0 ← 000 296-297 0662-0663  ▀▀▄ ▀ 6110 24848  V1 ← 016 298-299 0664-0665 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 29A-29B 0666-0667 █ █▄ ▀▄ A2B1 41649  I ← se 29C-29D 0668-0669  ▀▀ ▄ 6008 24584  V0 ← 008 29E-29F 0670-0671 ▀▀ █ ▄ ▄ D015 53269  Draw 08×05 at V0,V1; VF ← XOR 2A0-2A1 0672-0673 ▄ ▄▀ ▀ 12A0 04768  end Jump to end The game ends with the WI, N, LO, and SE sprites: 2A2 0674 █ █ ██ 8B 139  wi 2A3 0675 █ █ █ 89 137 2A4 0676 █ █ █ 89 137 2A5 0677 █ █ █ █ A9 169 2A6 0678 ██ ██ ██ DB 219 2A7 0679 █ ██ █ B2 178  n 2A8 0680  ██ █ 32 050 2A9 0681  █ █ █ 2A 042 2AA 0682  █ ██ 26 038 2AB 0683 █ █ ██ A6 166 2AC 0684 █ ███ 8E 142  lo 2AD 0685 █ █ █ 8A 138 2AE 0686 █ █ █ 8A 138 2AF 0687 █ █ █ 8A 138 2B0 0688 ███ ███ EE 238 2B1 0689 ███ ███ EE 238  se 2B2 0690 █ █ 88 136 2B3 0691 ███ ██ EC 236 2B4 0692  █ █ 28 040 2B5 0693 ███ ███ EE 238 It is particularly noteworthy that this game is entirely deterministic. .