-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepton2-commented.asm
11167 lines (9517 loc) · 349 KB
/
repton2-commented.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Disassembly and annotation of Repton by Superior Software
;
; Originally written by Timothy Tyler (c) Copyright 1985
;
; Disassembly labels and comments by Andy Barnes (c) Copyright 2021
;
; Twitter @ajgbarnes
org &0A00
; Notes on the game
; =================
;
; Memory Relocation
; -----------------
; - Relocation code is sourced from REPTON1 which puts the code in $0700
; - REPTON1 then runs REPTON2 with an execution address of $0700
; - Hence when REPTON2 loads, the relocation routine is called at $0700
; - REPTON2 loads at $1D00 and is moved down $1300 bytes
; - It is moved from $1D00-$72FF to $0A00-$5FFF
;
; Code obfuscation
; ----------------
; - Code is EOR'd with $FF on disc/tape
; - When the relocation routine runs, it reverses this by EORing with $FF
;
; Code
; ----
; - Main game entry point is at fn_game_start ($2640)
; - Main game entry point is called by the memory relocation code above once complete
; - Escape is disabled and break clears memory (*FX 200,3) in REPTON1
; - Many zero page locations are overloaded (used for multiple things)
; not an issue, just have to be aware when debugging / stopping the code
; - Variables are either in zero page or $09xx
; - There are many spare bytes (probably enough for another level) and small
; fragments of unused code - assume the author wanted to maintain the
; memory locations hence NOP'd bits of redundant code. Can also be
; seen when bits of a function are placed in anther "inbetween" subroutine
; instead of in the main fn and then call the final subroutine direct
; (oh to have modern tools back in the day)
;
; Bugs?
; -----
; - Sound channel never set correctly for monster crush sound
; works by luck only - see fn_kill_monster
; - After Repton dies, and the explosions have animated there is a
; half second wait and it then tries to play a sound but the first two parameters
; aren't set properly so no sound ever comes out i.e.
; SOUND &E0, 31, 4,2 - see fn_kill_repton This could have been a late development
; change to stop the sound?
; - Music will not play if Sound is off - music only plays if both sound and music are on
; (why not independent?)
; - $151B should be STY not LDY - doesn't seem to break anything
; - Monster information slots start at $0980 (OK) but the piece of code
; that resets the monster cache starts at $0970 and clears up to $09EF
; - None of the above affects the great game experience thankfully
;
; Game Sounds
; -----------
; - Single envelope used defined at envelope_1
; ENVELOPE 1,2,0,0,0,1,2,3,100,1,255,254,126,126
; - Monster crush sound (SOUND &60,1,1,1 or SOUND &92,1,1,1)
; - Diamond sound (SOUND &13,1,200,1)
; - Rock/egg dropping (SOUND &10,Amplitude,4,2)
; Amplitude calculated as Amplitude = ((rock or egg y) / 4) - 15
; - Repton crunch sound (SOUND &10,-15,6,2)
; - Almost out of time sound (SOUND $10, -15, 10, 1)
;
; Score
; -----
; - Stored as binary coded decimal
; - A diamond is 50 points
; - A piece of Earth is 1 point
; - Repton is always placed on a piece of earth at the start to
; automatically get 1 point - this is used along with remaining
; lives / time to see if a game has started when e.g. displaying
; the start screen
;
; New Game Intro Music
; --------------------
; - Plays a sequence of 52 notes (see repton-music-intro-notes.asm)
; - Code and storage could play up to 64 but code stops at 52nd
; - Code that restricts the notes is at $2217
; - Music is across Channels 1, 2, 3
; - Main melody is in Channel 1
; - Occassional double stops / chords when Channel 2 and/or 3 have notes
;
; In Game Music
; -------------
; - Plays an (devilishly infuriating but) well put together sequence of 256 notes per channel
; - Music is documented in repton-main-music.asm
; - Music is across Channels 1, 2, 3
; - Channels 1 and 2 always play the same note
; - Source code could have been reduced by 256 bytes if Channel 2
; was coded to only play Channel 1 notes instead of reading its
; own identical notes
; - Music continuously loops
; - Music controlled by VSYNC event (event happens every 20ms or 50 times a second)
; - VSYNC event triggers call to EVNT/EVENTV
; - EVNTV/EVENTV calls handler fn_enable_timer_2
; - fn_enable_timer_2 sets one shot countdown timer to 2,512 microseconds
; - IRQ2V is set to point at fn_event_handler_IRQ2V
; - When Timer 2 fires, it calls the routine above pointed at by IRQ2V
; - Routine only plays next music notes in sequence every 8th time around the loop
; it does this by ANDing with $07 and checking for zero
; - It then clears the interrupt and disables Timer 2
; - Standalone music that can be compiled separately can be found in repton-music.asm
;
; Screen
; ------
; - Set up in REPTON1 before REPTON2 is loaded
; - Game runs in 4 colour MODE 5
; - Characters per line are set to 32 ($20) to reduce visible screen memory
; - and to simplify some of the maths
; - Visible screen memory is therefore $6000 - $7FFF (normally starts at $5800)
; - No offscreen buffering
; - During game, only the edges are updated as the new column scrolls into view
; - Only 32 different types of objects
;
; Colours
; -------
; - Defaults colours are Black, Red, Yellow, Green
; - Level colours are set to Black, <level specific>, Yellow, Green
; - <Level specific> colour is based on the zero based level number th ecolour
; in a lookup table at data_screen_physical_colour_lookup
;
; Repton
; ------
; - Always starts a new level in the same position
; - When moving up/down or left/right the animation state is held in
; var_repton_animation_state ($0905) including the explosion sequence at death
; - var_repton_idle_counter ($0906) is used to track game loops since last key press
; - If no key has been detected for 127 times around the main game loop
; then the repton animation will change to the standing animation sequence
;
; Dissolve Screen
; ---------------
; - Routine that handles this is fn_dissolve_screen
; - VSYNC is disabled at the start of the routine
; - Uses a random number generator routine (see fn_generate_random_number for details)
; - To find a memory location for a random byte, it generates an address
; - MSB of the address is the (generated random number AND $F0) OR $E0 which
; always gives a $F0xx or $E0xx MSB
; - Uses memory from $E000 to $F0FF for random byte values
; - The random byte values are ANDed with what is on the screen
; and written back to the screen
; - Iterates 14 times over the entire screen $6000-$7FFF which seems good enough
; to dissolve most pixel
; - Dissolve iterations are controlled by zp_dissolve_screen_iterations
; - Value can be tweaked at $0D6B
;
; Interrupts
; ----------
; - Start of VSYNC is used in game to set User VIA one shot Timer 2 timer
; - VSYNC triggers 50 times a second / every 20 ms
; - VSYNC is processed by redirecting EVNTV / EVENTV to fn_enable_timer_2
; - User VIA Timer 2 is used to trigger next in-game music
; - IRQV2 is used for when User VIA Timer 2 fires - used to play the in-game music
;
; Timers
; ------
; - User VIA Timer 2 is used for in-game music as above in Interrupts
; - Vertical sync is used as a wait/pause timer in multiples of 20ms
; - Code will loop waiting n times for vertical sync to reach the desired time limit
;
; Monsters
; --------
; - State is held in 6 bytes blocks from $0980
; - First empty (inactive) monster slot is used when a monster spawns
; - Maps have a maximum of 3 monsters
; - Code could have up to 20 (enough memory available) from $0980 to $09F7
; - Random number is generated and lowest bit used to determine if
; it should move up/down or left/right
; - Monsters "jitter" too
;
; Random Number Generation
; ------------------------
; - User VIA Registers Timer 1 High Order Counter and Low Order Counter
; - Documented in fn_generate_random_number
;
; Maps
; ----
; - Mini-maps are only shown for screens A - H, code stops it showing (mean!) for I-L
;
; - An object is an egg, or repton, rock, diamond, rounded corner, earth, wall segment etc
; - Each object has an id e.g. $1D for a rock or $1E for a diamond
; - An object is made up of 4x4 tiles
; - Each object is therefore 16 tiles
;
; - Objects are mapped to component tiles in repton-map-objects-to-tile-defs.asm
; - The same tile can be used in multiple objects
; - Maps can show 32x32 objects
; - Maps are therefore 128x128 tiles
;
; - (xpos, ypos) refers to a 128x128 tile co-ordinate
; - (x,y) refers to a 32x32 object co-ordinate
;
; - Off map areas (xpos or ypos > 127) default to the object defined at $1B4B
;
; - Visible region of the map is 8x8 objects
; - Visible region of the map can therefore show 32x32 tiles
; - Visible region shows half an object at each edge, so 6 full objects are shown
; and 2 half objects horiztontally and vertically
;
; - Maps are stored as bit stream across bytes with every 5 bits identifying
; an object id - they are not byte aligned however
; - The map is compressed in that 5 bits ar used to represent
; each object so objects can have a value of $00 to $1F. Spare
; bits are used for the next object so
;
; Looking at Screen A, which starts at &4200 the first
; 5 bytes contain 8 object defintions (from &4200 to &4204)
; with the rest following after (&4200++)
;
; <-------------------Memory----------------------------
; Address: &4205 &4204 &4203 &4202 &4201 &4200
; -------- -------- -------- -------- -------- --------
; Byte: &38 &B5 &AD &6B &5A &D6
; Binary: 00111000 10110101 10101101 01101011 01011010 11010110
; --><---> <---><-- -><--->< ---><--- ><---><- --><--->
; Object: 9 8 7 6 5 4 3 2 1
; Obj value: &18 &16 &16 &16 &16 &16 &16 &16 &16
; Obj type: Earth BrickBrick Brick BrickBrick Brick BrickBrick
;
; - Current level map is decompressed and stored in $0400 to $07FF
; for faster game time access
;
; File offsets
; ------------
; Offset in the REPTON2 file can be calculated with
;
; File offset = memory address - $0A00
;
; Summary Memory Map
; ------------------
; From To Bytes Type Description
;
; 0400 07FF 1024 Data Decompressed current level
; 0A00 0CFF 768 Music In-game music notes
; 0D00 223F 5440 Code Code, data, lookup tables, text strings
; 2240 22FF 192 Music New game intro music
; 2300 26FF 1024 Code Code, data, lookup tables, text strings
; 2700 29FF 768 Graphics Repton has been finished
; 2A00 2AFF 256 Code Code, data, lookup tables, text strings
; 2B00 2BE2 224 Data High scores and high score names
; 2BE3 2D57 175 Code Code, data, lookup tables, text strings
; 2D58 2DF3 156 Data Screen passwords
; 2DF4 2EFF 268 Code Code, data, lookup tables, text strings
; 2F00 2FBF 191 Graphics Start screen Repton logo
; 2FC0 3FFF 4160 Graphics Sprites that animate e.g. Repton, egg, monster, explosion
; 4000 41FF 512 Data Static sprite (object) to tile mapping
; 4200 57FF 1536 Data All maps in a bit stream
; Zero Page Memory Usage
; ----------------------
; From To Bytes Type Description
;
; 0000 0013 20 Data Zero page variables
; 0014 003E 43 Not used
; 003F 003F 1 Data Zero page variables
; 0040 005F 32 Not used
; 0060 0067 8 Data Zero page variables
; 0068 0069 2 Not used
; 006A 006B 2 Data Zero page variables
; 006C 006F 4 Not used
; 0070 007A 11 Data Zero page variables
; 007B 007B 1 Not used
; 007C 0082 7 Data Zero page variables
; 0083 008B 8 Not used
; 008C 008F 4 Data Zero page variables
; 0090 00FB 108 Not used
; 00FC 00FC 1 Data Interrupt Accumulator Storage
; 00FD 00FF 3 Not used
;
; Transient Data Memory Map
; -------------------------
; From To Bytes Type Description
;
; 0206 0207 2 Vector IRQV2
; 0220 0221 2 Vector EVNTV/EVENTV
;
; 034E 034E 1 OS Workspace MSB of HIMEM - set in REPTON1
; 0352 0352 1 OS Workspace Bytes per screen row (LSB) - set in REPTON1
; 0353 0353 1 OS Workspace Bytes per screen row (MSB) - set in REPTON1
; 0354 0354 1 OS Workspace Size of screen memory in pages - set in REPTON1
; 0355 0355 1 OS Workspace Current Screen Mode - set in REPTON1
; 0356 0356 1 OS Workspace Size of screen memory - set in REPTON1
;
; 0400 07FF 1024 Data Decompressed current level map
;
; 0900 0900 1 Data Screen / level number
; 0901 0901 1 Data Lives left
; 0902 0902 1 Data Random number
; 0903 0903 1 Data Repton vertical direction indicator
; 0904 0904 1 Data Repton horizontal direction indicator
; 0905 0905 1 Data Repton animation sprite
; 0906 0906 1 Data Repton idle counter
; 0907 0907 1 Data Main loop counter
; 0908 0908 1 Data Number of diamonds remaining
; 0909 090B 3 Data BCD score digits
; 090C 090D 2 Data Time reamining
; 090E 0910 3 Data Player High Score
; 0911 0911 1 Data Sound on/off status
; 0912 0912 1 Data Music on/off status
; 0913 0913 1 Data If both sound and music are off flag
; 0914 0914 1 Data Which level the player started on
;
; 0920 0920 1 Data Used as an index to loop through the high scores AND lowest high score LSB
; 0921 0922 1 Data Bubble sort iteration AND lowest high score middle byte value
; 0922 0922 1 Data Lowest high score MSB
; 0923 0923 1 Data Lowest high score index
;
; 0980 0980 1 Data Monster 1 - x co-ordinate
; 0981 0981 1 Data Monster 1 - y co-ordinate
; 0982 0982 1 Data Monster 1 - x co-ordinate "jitter" value
; 0983 0983 1 Data Monster 1 - y co-ordinate "jitter" value
; 0984 0984 1 Data Monster 1 - counter for delay on egg crack and delay on monster moving initally
; 0985 0985 1 Data Monster 1 - is this monster slot being used?
;
; 0986 0986 1 Data Monster 2 - x co-ordinate
; 0987 0987 1 Data Monster 2 - y co-ordinate
; 0988 0988 1 Data Monster 2 - x co-ordinate "jitter" value
; 0989 0989 1 Data Monster 2 - y co-ordinate "jitter" value
; 098A 098A 1 Data Monster 2 - counter for delay on egg crack and delay on monster moving initally
; 098B 098B 1 Data Monster 2 - is this monster slot being used?
;
; 098C 098C 1 Data Monster 3 - x co-ordinate
; 098D 098D 1 Data Monster 3 - y co-ordinate
; 098E 098E 1 Data Monster 3 - x co-ordinate "jitter" value
; 098F 098F 1 Data Monster 3 - y co-ordinate "jitter" value
; 0990 0990 1 Data Monster 3 - counter for delay on egg crack and delay on monster moving initally
; 0991 0991 1 Data Monster 3 - is this monster slot being used?
;
; 09FC 09FC 1 Data Indicates if the restart key is pressed
;
; 09FE 09FE 1 Data Main in-game music note sequence number
;
; 09FF 09FF 1 Data How fast the music plays (nth time the interrupt fires)
;
;
; Relocated Memory Map
; ------------------
; From To Bytes Type Description
;
; 0A00 0AFF 256 Music Main game music - channel 1
; 0B00 0BFF 256 Music Main game music - channel 2
; 0C00 0CFF 256 Music Main game music - channel 3
; 0D00 0D00 1 Unused Spare byte
; 0D01 0D3A 58 Code fn_event_handler_IRQ2V
; 0D3B 0D53 25 Code fn_set_sound_block_and_play_sound
; 0D54 0D55 2 Unused Spare bytes
; 0D56 0D69 20 Code fn_draw_repton
; 0D6A 0D6E 5 Code fn_disable_vsync_event
; 0D6F 0D75 7 Code fn_disable_vsync_event_only
; 0D76 0D7E 9 Code fn_reset_palette_music_and_vsync
; 0D7F 0D8F 17 Code fn_play_game_sound
; 0D90 0DA9 25 Code fn_enable_timer_2
; 0DAA 0DB1 8 Code fn_disable_timer_2
; 0DB2 0DB3 2 Unused Spare bytes
; 0DB4 0DBF 12 Code fn_play_sound_and_calc_screen_address
; 0DC0 0DCE 16 Code text_out_of_time
; 0DCF 0DCF 1 Unused Spare bytes
; 0DD0 0DF5 38 Code fn_check_out_of_time
; 0DF6 0DFF 10 Unused Spare bytes
; 0E00 0E01 2 Unused Spare bytes
; 0E02 0E21 32 Lookup table data_repton_pose_lookup_table_lsb/msb
; 0E22 0E29 8 Lookup table repton_moving_left_sprite_lookup
; 0E2A 0E31 8 Lookup table repton_moving_right_sprite_lookup
; 0E32 0E35 4 Lookup table repton_standing_idle_looking
; 0E36 0E3D 8 Lookup table data_map_object_required_bit_mask
; 0E3E 0E45 8 Lookup table data_partial_sprite_offset_lookup_lsb/msb
; 0E46 0E53 14 Data envelope_1
; 0E54 0E5F 12 Lookup table data_screen_physical_colour_lookup
; 0E60 0E9F 64 Lookup table data_screen_character_lookup_table
; 0EA0 0EAF 16 Lookup table ....
; 0EB0 0EBE 15 Lookup table ....
; 0EBF 0EDE 32 Data data_mini_map_characters
; 0EDF 0EE2 4 Data data_screen_colour_masks
; 0EE3 0EF8 22 Text text_by_superior_software
; 0EF9 0F01 9 Text text_score
; 0F02 0F0C 11 Text text_hi_score
; 0F0D 0F13 7 Text text_time
; 0F14 0F1B 8 Text text_lives
; 0F1C 0F26 11 Text text_diamonds
; 0F27 0F3E 24 Text text_screen
; 0F3F 0F53 21 Text text_sound
; 0F54 0F74 33 Text text_press_escape
; 0F75 0F95 33 Text text_press_return
; 0F96 0FB3 30 Text text_press_space
; 0FB4 0FC6 19 Code fn_wait_for_vertical_sync
; 0FC7 1031 107 Code fn_check_if_high_score...
; 1032 1032 1 Unused Spare byte
; 1033 103B 9 Code ...fn_check_if_high_score
; 103C 1043 8 Unused Spare bytes
; 1044 1059 22 Code fn_generate_random_number
; 105A 1084 43 Code fn_play_music_sound
; 1085 108E 10 Code fn_read_key
; 108F 10B0 34 Code fn_define_logical_colour
; 10B1 10C2 18 Code fn_calc_screen_address_from_x_y
; 10C3 10DB 25 Code fn_check_sound_keys
; 10DC 10F3 24 Code fn_check_escape_key
; 10F4 1139 70 Code fn_check_for_map_key_press...
; 113A 113D 4 Unused Spare bytes
; 103E 114A 13 Code ...fn_check_for_map_key_press
; 114B 1190 70 Code fn_write_3_byte_display_value_to_screen
; 1191 11A5 22 Code fn_print_digit_to_screen
; 11A6 11BE 25 Code fn_write_string_to_screen
; 11BE 1215 88 Code fn_print_character_to_screen
; 1216 121D 1 Code fn_print_character_and_increment_xpos...
; 1217 1217 1 Unused Spare byte
; 1218 121D 6 Code ...fn_print_character_and_increment_xpos
; 121E 1252 53 Code fn_check_if_score_update_or_key
; 1253 12A9 87 Code fn_update_score_and_check_if_a_safe
; 12AA 12F5 76 Code fn_change_safes_to_diamonds
; 12F6 1309 20 Code fn_check_if_rock_egg_falling_and_move_it...
; 130A 130B 2 Unused Spare bytes
; 130C 1329 29 Code ...fn_check_if_rock_egg_falling_and_move_it
; 132A 13A9 128 Code fn_drop_rock_or_egg
; 13AA 13D1 40 Code fn_check_if_egg_or_rock_can_roll
; 13D2 1436 101 Code fn_roll_rock_left_and_down
; 1437 1497 97 Code fn_roll_rock_right_and_down
; 1498 1498 1 Unused Spare byte
; 1499 14D2 58 Code fn_check_monster_collision
; 14D3 1526 83 Code fn_check_if_monster_dead
; 1527 1557 50 Code fn_kill_monster
; 1558 1587 48 Code fn_crack_egg
; 1588 15B0 41 Code fn_update_all_monsters
; 15B1 15F0 64 Code fn_move_monster
; 15F1 168D 156 Code fn_check_monster_movement
; 168E 16AD 32 Code fn_draw_or_blank_monster
; 16AE 16C7 26 Code fn_draw_cracked_egg
; 16C8 16E1 26 Code fn_draw_monster_standing
; 16E2 16EA 8 Code fn_wait_120ms
; 16EB 1707 29 Code fn_decrement_remaining_time
; 1708 178D 134 Code fn_kill_repton
; 178E 1798 11 Code fn_wait_600ms_then_initialise_game
; 1799 17A7 15 Code fn_write_r_to_restart
; 17A8 17AE 7 Code fn_set_press_escape_lsb
; 17AF 17B4 6 Code fn_update_high_score_reset_music
; 17B5 18E4 304 Code fn_display_repton_start_screen
; 18E5 195C 119 Code fn_write_plenty_to_screen
; 195D 1976 26 Code fn_add_to_score
; 1977 19B9 43 Code fn_remove_repton
; 19BA 19C9 16 Code fn_lookup_repton_sprite_and_display
; 19CA 1A1B 82 Code fn_display_sprite
; 1A1C 1AE8 205 Code fn_draw_or_blank_object
; 1AE9 1B21 57 Code fn_blank_screen_object
; 1B22 1B4D 43 Code fn_update_6845_screen_start_address
; 1B4E 1BBC 111 Code fn_lookup_screen_tile_for_xpos_ypos
; 1BBD 1BED 48 Code fn_lookup_screen_object_for_x_y
; 1BEE 1BFA 13 Code fn_lookup_map_character_and_display
; 1BFB 1C39 63 Code fn_display_tile
; 1C3A 1C6A 48 Code fn_write_tile_to_screen
; 1C6B 1CA0 54 Code fn_move_repton_down
; 1CA1 1CD5 53 Code fn_move_repton_up
; 1CD6 1D90 187 Code fn_move_repton_left
; 1D91 1E4B 187 Code fn_move_repton_right
; 1E4C 1E74 41 Code fn_get_nth_bit_from_memory
; 1E75 1EAD 57 Code fn_get_next_map_object
; 1EAE 1EBE 17 Code fn_get_next_map_object_bit
; 1EBF 1F08 74 Code fn_reset_game
; 1F09 1F81 121 Code fn_check_repton_movement
; 1F82 1FCE 77 Code fn_dissolve_screen
; 1FCF 1FEC 30 Code fn_initialise_game
; 1FED 1FEF 3 Code fn_initialise_game_after_restart
; 1FF0 2004 21 Code fn_initialise_game_after_restart_no_high_score
; 2005 2007 3 Code fn_do_game_reset
; 2008 2026 30 Code fn_reset_and_show_start_screen
; 2027 2157 304 Code fn_return_pressed_from_game
; 2158 2185 46 Code fn_check_r_d_w_keys
; 2186 218F 19 Code fn_set_sound_and_music_status
; 2190 219E 15 Code fn_clear_screen_show_high_score_table
; 219F 21CA 43 Code fn_show_high_score_repton_logo
; 21CB 21CF 5 Unused Spare bytes
; 21D0 221B 76 Code fn_play_intro_music
; 221C 2230 21 Code fn_draw_rock_right_and_check_repton
; 2231 2236 6 Code fn_write_string_and_set_escape_lsb
; 2237 223F 9 Unused Spare Bytes
; 2240 22FF 192 Music Game intro music
; 2300 2325 38 Code fn_sort_and_display_scores...
; 2326 2340 27 Unused Spare bytes
; 2341 244E 270 Code ...fn_sort_and_display_scores
; 244F 244F 1 Unused Spare byte
; 2450 245D 14 Text text_screen_complete_press_space
; 245E 24B2 85 Text text_screen_complete_well_done
; 24B3 24C2 16 Code fn_reset_music_and_draw_repton
; 24C3 24D9 23 Text text_copyright
; 24DA 24FF 38 Code fn_display_high_score_name_entry_field
; 2500 2509 10 Code fn_reset_palette_to_default_game_colours
; 250A 2517 14 Code fn_set_palette_to_default_with_screen_lookup_colour
; 2518 251F 8 Code fn_default_palette_with_cyan
; 2520 2525 6 Code fn_disable_vsync_event_and_change_palette
; 2526 255B 54 Code fn_check_if_password_match
; 255C 2566 11 Code fn_reset_start_and_started_on_screen
; 2567 2590 42 Code fn_check_if_nearly_out_of_time
; 2591 2597 7 Code fn_add_one_to_lives_left_for_display
; 2598 25A2 11 Code fn_disable_vsync_create_map_colours
; 25A3 25C6 36 Code fn_display_repton_logo_for_high_score_entry
; 25C7 25CF 9 Code fn_wait_for_vsync_and_set_sheila_address_to_12
; 25D0 25F8 41 Code fn_display_p_or_r_option
; 25F9 2624 44 Code fn_check_p_r_d_w_keys
; 2625 262B 7 Code fn_check_intro_music
; 262C 2634 9 Code fn_calc_drop_volume_and_play_sound
; 2635 263F 11 Unused Spare bytes
; 2640 264C 13 Code fn_game_start
; 264D 2652 19 Code fn_set_high_score_mlsb_and_start_screen
; 2653 266A 24 Code fn_check_if_intro_music_should_play
; 266B 2676 12 Code fn_set_start_screen_and_reset_game
; 2677 269A 36 Code fn_show_high_score_table
; 269B 269F 5 Unused Spare bytes
; 26A0 26A6 7 Code fn_set_start_and_started_on_screen
; 26A7 26B3 13 Code fn_restart_game
; 26B4 26FF 76 Unused Spare bytes
; 2700 29FF 768 Graphics Repton has been finished
; 2A00 2A28 41 Code fn_replace_lowest_high_score_with_current
; 2A29 2A3E 22 Code fn_cache_lower_high_score
; 2A3F 2A4D 15 Code fn_call_osword_and_reset_score
; 2A4E 2AAA 93 Code fn_display_completed_screen
; 2AAB 2AB6 12 Code fn_oswrch_and_reset_screen_start_addr
; 2AB7 2AC1 11 Code fn_flush_all_buffers_cache_xpos_and_ypos
; 2AC2 2AF2 49 Code fn_check_and_update_high_score
; 2AF3 2AFE 12 Code fn_compare_user_password_character
; 2AFF 2AFF 1 Unused Spare bytes
; 2B00 2B17 24 Data data_high_score
; 2B18 2BD7 192 Data data_high_score_names
; 2BD8 2BE2 8 Data data_sorted_score_offsets
; 2BE3 2BFF 29 Unused Spare bytes
; 2C00 2C0A 11 Code fn_loop_wait_for_space_bar_on_screen
; 2C0B 2C14 10 Unused Spare bytes
; 2C15 2C97 130 Code fn_display_password_screen
; 2C98 2C9A 3 Unused Spare bytes
; 2C9B 2CB6 27 Text text_press_space_bar_to_play
; 2CB6 2CD2 28 Text text_p_to_enter_password
; 2CD3 2CEF 29 Text text_r_to_restart
; 2CF0 2CFF 16 Text text_enter_password
; 2D00 2D21 34 Text text_congrats_enter_name
; 2D22 2D2D 14 Text text_last_score
; 2D2E 2D3F 16 Unused Spare bytes
; 2D40 2D47 8 Text text_screen_matched
; 2D48 2D56 15 Code fn_call_oswrch_and_reset_high_score
; 2D57 2D57 1 Unused Spare byte
; 2D58 2D63 12 Text text_password_screen_a
; 2D64 2D6F 12 Text text_password_screen_b
; 2D70 2D7B 12 Text text_password_screen_c
; 2D7C 2D87 12 Text text_password_screen_d
; 2D88 2D93 12 Text text_password_screen_e
; 2D94 2D9F 12 Text text_password_screen_f
; 2DA0 2DAB 12 Text text_password_screen_g
; 2DAC 2DB7 12 Text text_password_screen_h
; 2DB8 2DC3 12 Text text_password_screen_i
; 2DC4 2DCF 12 Text text_password_screen_j
; 2DD0 2DDB 12 Text text_password_screen_k
; 2DDC 2DE7 12 Text text_password_screen_l
; 2DE8 2DF3 12 Data data_password_lsb_lookup_table
; 2DF4 2DF9 6 Code fn_write_password_to_screen
; 2DFA 2DFF 6 Unused Spare bytes
; 2E00 2E63 100 Code fn_get_player_password_or_name
; 2E64 2E72 15 Code fn_set_rest_of_password_to_crs
; 2E73 2E93 33 Code fn_write_sound_music_password_to_screen
; 2E94 2EA7 20 Text text_music
; 2EA8 2EB2 11 Text text_password
; 2EB3 2EDF 45 Code fn_write_music_status_and_pwd_to_screen
; 2EE0 2EE3 4 Text text_on
; 2EE3 2EE7 4 Text text_off
; 2EE8 2EFF 24 Data data_player_entered_password_or_name
; 2F00 2FBF 191 Graphics Start screen repton logo
; 2FC0 3FFF 4160 Graphics Sprites that animate e.g. Repton, egg, monster, explosion
; 4000 41FF 512 Data Static sprite (object) to tile mapping
; 4200 57FF 1536 Data All maps in a bit stream
;
; Interesting Pokes
; -----------------
; - Change the value below to put another object as the off map icon
; ?&1B4C = $15
; - Allow mini-maps on all screens
; ?&10FF = $FF
; - Speed up the in-game music
; ?&0D13 = $01
; - Slow down the in-game music
; ?&0D13 = $10
; - Change the value below to change the dissolve screen iterations
; ?&0D6B=$0E
; - Change the lives left in-game
; ?&0901=$03
; - Change default lives
; ?&1FF6=$03
; - Change default time to complete a level to 9999
; note the values have to be in BCD so no hex characters allowed
; ?&2016=&99 ?&201B=&99
; - Stop the time decrementing
; ?&16F1=&00
; - Stop the monster moving (alternates between egg and monster)
; ?&1599=&EA
; ?&159A=&EA
; Read character (from keyboard) to A
OSRDCH = $FFE0
; Write character (to screen) from A - OSWRCH uses VDU values
OSWRCH = $FFEE
; Perfrom miscellaneous OS operation using control block to pass parameters
OSWORD = $FFF1
; Perfrom miscellaneous OS operation using registers to pass parameters
OSBYTE = $FFF4
; Address of the memory mapped hardware
; for the 6845 CRTC video controller
SHEILA_6845_ADDRESS=$FE00
SHEILA_6845_DATA=$FE01
; Sheila System Via Interrupt Enable Register
SHEILA_SYSTEM_VIA_R14_IER=$FE4E
; Sheila System Via Interrupt Flag Register
SHEILA_SYSTEM_VIA_R14_IFR=$FE4D
; Sheila User Via Timer 2 Control low-order counter
SHEILA_USER_VIA_R5_T1C_L = $FE64
; Sheila User Via Timer 2 Control high-order counter
SHEILA_USER_VIA_R5_T1C_H = $FE65
; Sheila User Via Timer 2 Control low-order latch
SHEILA_USER_VIA_R8_T2C_L = $FE68
; Sheila User Via Timer 2 Control High-order latch
SHEILA_USER_VIA_R9_T2C_H = $FE69
; Sheila User VIA Interrupt Enable Register
SHEILA_USER_VIA_R14_IER = $FE6E
; OS Workspace - used to restore the accumulator value
; after the interrupt from Timer 2
OS_ZP_INTERRUPT_A_STORAGE=$00FC
; OSWRCH value for the new logical to physical colour mapping
; Top four bits are the logical colour, bottom four are the physical
zp_logical_physical_colour=$0000
; Used to temporarily cache the map x co-ordinate
; when getting the mini-map character to display
zp_map_x_cache=$0000
; ---------------------------------------------
; These two are paired for reading sprite tiles
; and writing to the screen in fn_display_tile
; and fn_write_tile_to_screen
; Screen memory location where to write the current map tile
zp_screen_write_address_lsb = $0000
zp_screen_write_address_msb = $0001
; Where to read the current tile from before writing to the
; screen
zp_tile_read_address_lsb = $0002
zp_tile_read_address_msb = $0003
; ---------------------------------------------
; These two are paired for reading the sprite tiles
; and writing to the screen in fn_display_sprite
; Repton sprite tiles read address (for when he
; needs to be written to the screen) and used
; to index the tiles that will be written to the screen
; for other objects
zp_sprite_tiles_read_address_lsb=$0000
zp_sprite_tiles_read_address_msb=$0001
; Screen memory location where to write the current
; map tile
zp_target_screen_address_lsb=$0002
zp_target_screen_address_msb=$0003
; ---------------------------------------------
; Used to hold the screen start address DIV 8
; that is passed to the 6845 CRTC Video controller
; to scroll the screen
zp_screen_start_address_lsb_div8=$0000
zp_screen_start_address_msb_div8=$0001
; ---------------------------------------------
; Which sound channel to use for the sound
; Used with A (amplitude), X (pitch), Y (duration)
; when calling fn_play_sound - all this values
; get copied into the appropriate LSBs of
; the zp_sound_block... before OSWORD
; is called
zp_required_sound_channel=$0000
; Sound channel to use - MSB is always zero
zp_sound_block_channel_lsb=$0001
zp_sound_block_channel_msb=$0002
; Sound amplitude to use - MSB is always zero
zp_sound_block_amplitude_lsb=$0003
zp_sound_block_amplitude_msb=$0004
; Sound pitch to use - MSB is always zero
zp_sound_block_pitch_lsb=$0005
zp_sound_block_pitch_msb=$0006
; Sound duration to use - MSB is always zero
zp_sound_block_duration_lsb=$0007
zp_sound_block_duration_msb=$0008
; ---------------------------------------------
; Used to calculate the number of tiles to be
; drawn when showing a sprite on the edge
; of a screen (jittery monsters aren't
; just 2)
zp_temp_x_calc=$0002
zp_temp_y_calc=$0003
; Number of sprite tiles to copy to the screen
zp_sprite_tiles_to_copy_or_blank = $0004
; Default counters for looping around and blanking or displaying
; an object on the screen e.g. Repton or a rock. These are not
; decremented. Objects are made up of 4x4 tiles
; See fn_draw_or_blank_object
zp_object_width_default_counter=$0004
zp_object_height_default_counter=$0005
; Temporarily cache the xpos and ypos in
; fn_lookup_screen_tile_for_xpos_ypos
zp_tile_xpos_cache=$0006
zp_tile_ypos_cache=$0007
; Temporarily cache the x and y in
; fn_lookup_screen_tile_for_x_y
zp_tile_x_cache=$0006
zp_tile_y_cache=$0007
; Working counters for looping around and blanking or displaying
; an object on the screen e.g. Repton or a rock. These ARE
; decremented. Objects are made up of 4x4 tiles
; See fn_draw_or_blank_object
zp_object_width_working_counter=$0006
zp_object_height_working_counter=$0007
; General bytes for manipulating xpos/ypos values
; in fn_lookup_screen_tile_for_xpos_ypos
zp_general_xpos_lookup_calcs=$0008
zp_general_ypos_lookup_calcs=$0009
; Used to reference the memory location of the
; the string to write to the screen
zp_string_read_address_lsb = $000A
zp_string_read_address_msb = $000B
; Used to store the memory location of the current
; processed position of the map or sprite details
; of an object
zp_map_or_object_address_lsb = $000A
zp_map_or_object_address_msb = $000B
; When changing all safes to diamonds, remember the
; map position where repton picked up the key
; by caching it here
zp_map_or_object_address_lsb_cache = $000C
zp_map_or_object_address_msb_cache = $000D
; Used to track which of the 32x32 visible tiles
; on the screen is being drawn in fn_return_pressed_from_game
zp_game_screen_column_to_draw = $000E
zp_game_screen_row_to_draw = $000F
; Whether a trailing zero should be drawn after a number
; is converted into digits
zp_print_zero_or_not_flag =$000F
; Used to hold the BCD values that need conversion
; into individual digits that can be printed to the
; screen - e.g. score, high score, remaining time etc
zp_display_value_msb = $0010
zp_display_value_mlsb = $0011
zp_display_value_lsb = $0012
; When the screen scrolls, where to write anew tile
zp_new_tile_xpos=$0010
zp_new_tile_ypos=$0011
; Cache ofthe screen's top left (xpos,ypos)
; this is where the top left of the screen is on the map
zp_visible_screen_top_left_xpos_cache = $0012
zp_visible_screen_top_left_ypos_cache = $0013
; Current password character ANDed with $5F
; for case insensitive comparison
zp_masked_password_character=$003F
; ---------------------------------------------
; Sound block for the in-game music
;
; Sound channel to use - MSB is always zero
zp_music_block_channel_lsb=$0060
zp_music_block_channel_msb=$0061
; Sound amplitude to use - MSB is always zero
zp_music_block_amplitude_lsb=$0062
zp_music_block_amplitude_msb=$0063
; Sound pitch to use - MSB is always zero
zp_music_block_pitch_lsb=$0064
zp_music_block_pitch_msb=$0065
; Sound duration to use - MSB is always zero
zp_music_block_duration_lsb=$0066
zp_music_block_duration_msb=$0067
; ---------------------------------------------
; Length of the user entered password
zp_password_character_count = $006A
; Cache for the value of the current password character
; that's being processed
zp_password_current_character_cache = $006B
; Current visible screen write address for when
; writing the dissolve effect to the screen
zp_dissolve_screen_write_address_lsb=$0070
zp_dissolve_screen_write_address_msb=$0071
; Used to lookup the level passwords - holds the
; memory location of the current password
zp_screen_password_lookup_lsb=$0070
zp_screen_password_lookup_msb=$0071
; Required map bit in the bitstream of the
; compressed map - used to decode the map bitstream
zp_required_map_bit_lsb=$0070
zp_required_map_bit_msb=$0071
; Used to remember an object id
zp_cached_object_id=$0070
; Used to look for a 32x32 co-ordinate
; for a rock or egg's position that needs
; to drop - starts in the bottom right corner
; one row up
zp_map_x_for_rock_drop=$0070
zp_map_y_for_rock_drop=$0071
; Currently processed monster's position on the map
zp_monster_x=$0070
zp_monster_y=$0071
; Original position of the rock or egg
; so it can be blanked on the map ($00) when the rock
; or egg is moved
zp_map_object_update_lsb=$0071
zp_map_object_update_msb=$0072
; Number of iterations to apply the dissolve effect to the
; screen
zp_dissolve_screen_iterations=$0072
; Used to loop through the level passwords and match
; against the user entered password
zp_screen_password_lookup_index=$0072
; Used to hold the current map memory address position
; when scanning from bottom right (one row up) to find
; rocks or eggs that should drop
zp_object_index_lsb=$0072
zp_object_index_msb=$0073
; Holds the (xpos,ypos) on the 128x128 tile map
; when looping through to find a safe to
; change into a diamond
zp_map_xpos_for_safe_change=$0072
zp_map_ypos_for_safe_change=$0073
; Holds the (xpos,ypos) on the visible screen to check
; around Repton to see if he collided with a monster
zp_repton_xpos=$0072
zp_repton_ypos=$0073
; Used as the address of the source byte to use to dissolve
; the current visible screen byte (always in the range
; from $0E00 to $F0FF)
zp_random_byte_source_lsb=$0073
zp_random_byte_source_msb=$0074
; Just used to cache the values of zp_object_index_lsb/msb
; in fn_get_next_map_object
zp_object_index_lsb_cache=$0074
zp_object_index_msb_cache=$0075
; Used to chache a map object id in various places
zp_cached_object_id_for_rock_drop=$0074
; Loop over the safe and change its tiles into
; diamonds
zp_object_x_parts_for_safe_change=$0074
zp_object_y_parts_for_safe_change=$0075
; Used to collect and hold the bits from the compressed
; map before writing into map memory ($0400-$07FF)
zp_object_id=$0076
; Used to lookup the object on the map at that (x,y)
; position before drawing on the mini-map
zp_map_x = $0076
zp_map_y = $0077
; Used to cache the position to check for an object
; to the left of Repton
zp_left_object_index_lsb=$0076
zp_left_object_index_msb=$0077
; Used to loop through the encoded map looking for the
; nth object (starting at zero)
zp_nth_object_index_lsb=$0077
zp_nth_object_index_msb=$0078
; Holds the (x,y) on the 32x32 object map
; when looping through to find a safe to
; change into a diamond
zp_map_x_for_safe_change=$0077
zp_map_y_for_safe_change=$0078
; Caches an object id on the map when dropping a
; rock right or left
zp_cached_object_id_for_rock_drop_r_or_l=$0078
; Memory location of where to write decoded
; map objects
zp_decoded_map_counter_lsb=$0079
zp_decoded_map_counter_msb=$007A
; Cache of the top left corner of the screen (xpos,ypos)
zp_visible_screen_top_left_xpos_cache2=$007C
zp_visible_screen_top_left_ypos_cache2=$007D
; Current character to write to the screen in
; fn_write_string_to_screen
zp_string_to_display_current_byte = $007E
; Used to get all the bytes of the Repton logo
; on the start screen and the high score screen
zp_screen_write_total_byte_counter = $007F
; Used to loop over the intro music at the start of a new game
zp_sound_note_index=$007F
; Currently processed monster slot (nth active monster)
zp_monster_number=$007F
; Position on the screen to write the text on
; start, password and high score screens
zp_password_cursor_xpos = $0080
zp_password_cursor_ypos = $0081
; Colour mask used to blank out colours on non in-game
; screens e.g. start, password, high score. Can be set
; to:
; $FF (show all colours)
; $F0 (show top logical colours 2 and 3)
; $0F (show bottom logical colours 1 and 2)
zp_screen_colour_mask= $0082
; Visible screen start (xpos,ypos)
zp_visible_screen_top_left_xpos=$008C
zp_visible_screen_top_left_ypos=$008D
; Memory location that is the start of the visible screen
; Used to scroll the screen by DIV 8 and passing to the 6845
zp_screen_start_address_lsb = $008E
zp_screen_start_address_msb = $008F
; Interrupt-request vector 2 (IRQ2V)
IRQ2V_LSB = $0206
IRQ2V_MSB = $0207
EVENTV_LSB = $0220
EVENTV_MSB = $0221
; Player's current level / screen number
var_screen_number = $0900
; Number of player lives left (defaults to 4 i.e. $03)
var_lives_left = $0901
; When a random number is generated by fn_generate_random_number, it is stored here
var_random_value = $0902
; Indicates if there is any vertical movement
; $01 - Repton is moving up
; $00 - Repton not moving up or down
; $FF - Repton is moving down
var_repton_vertical_direction=$0903
; Indicates if there is any horizontal movement
; $01 - Repton is moving right
; $00 - Repton not moving right or left
; $FF - Repton is moving left
var_repton_horizontal_direction=$0904
; Which Repton sprite to draw on screen - table at $0E00 shows poses
var_repton_animation_state=$0905
; Number of times around the game loop a movement key has not been pressed