Index

Here is the plain version with ECMA-48 color control functions, the game itself, and the game metadata.

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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×02 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 08×07 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×07 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:

  1. V0 Unused.
  2. V1 Horizontal positioning of text sprites.
  3. V2 Store a key.
  4. V3 Contain a randomly generated number of zero, one, four, or five; vertical positioning of text sprites.
  5. V4 Manipulating the sound register.
  6. V5 Contain the number of iterations of the game.
  7. V6 Horizontal positioning of gun sprite.
  8. V7 Vertical positioning of gun sprite.
  9. V8 Unused.
  10. V9 Unused.
  11. VA Unused.
  12. VB Unused.
  13. VC Unused.
  14. VD Unused.
  15. VE Unused.
  16. 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×05 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 08×07 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