-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathET_atari_2600_source_code.asm
6577 lines (6180 loc) · 209 KB
/
ET_atari_2600_source_code.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
LIST OFF
; *** E . T. T H E E X T R A - T E R R E S T R I A L ***
; Copyright 1982 Atari, Inc.
; Designer: Howard Scott Warshaw
; Artist: Jerome Domurat
; Analyzed, labeled and commented
; by Dennis Debro
; Last Update: July 18, 2006
;
; *** 116 BYTES OF RAM USED 12 BYTES FREE
;
; NTSC ROM usage stats
; -------------------------------------------
; *** 25 BYTES OF ROM FREE IN BANK0
; *** 24 BYTES OF ROM FREE IN BANK1
; ===========================================
; *** 49 TOTAL BYTES FREE
;
; PAL ROM usage stats
; -------------------------------------------
; *** 23 BYTES OF ROM FREE IN BANK0
; *** 24 BYTES OF ROM FREE IN BANK1
; ===========================================
; *** 47 TOTAL BYTES FREE
; This is Howard Scott Warshaw's third game with Atari. It was conceived and
; developed in roughly 5 weeks! The licensing deal didn't complete until the
; end of July (in an interview Howard says July 25). Atari wanted this game
; for the Christmas season which meant Howard had to finish this game by
; September 1st!
;
; - Pits are arranged in the order of...
; 1) ID_FOUR_DIAMOND_PITS
; 2) ID_EIGHT_PITS
; 3) ID_ARROW_PITS
; 4) ID_WIDE_DIAMOND_PITS
; - Objects are never placed in the overlapping pits for ID_EIGHT_PITS
; - Playfield is a 2LK while sprites are a 1LK
; - PAL conversion adjusts E.T. movement and colors
; - It seems RAM location $8B is not used
processor 6502
;
; NOTE: You must compile this with vcs.h version 105 or greater.
;
TIA_BASE_READ_ADDRESS = $30 ; set the read address base so this runs on
; the real VCS and compiles to the exact
; ROM image
include macro.h
include vcs.h
LIST ON
;============================================================================
; A S S E M B L E R - S W I T C H E S
;============================================================================
NTSC = 0
PAL = 1
COMPILE_VERSION = NTSC ; change this to compile for different
; regions
;============================================================================
; T I A - M U S I C C O N S T A N T S
;============================================================================
SOUND_CHANNEL_SAW = 1 ; sounds similar to a saw waveform
SOUND_CHANNEL_ENGINE = 3 ; many games use this for an engine sound
SOUND_CHANNEL_SQUARE = 4 ; a high pitched square waveform
SOUND_CHANNEL_BASS = 6 ; fat bass sound
SOUND_CHANNEL_PITFALL = 7 ; log sound in pitfall, low and buzzy
SOUND_CHANNEL_NOISE = 8 ; white noise
SOUND_CHANNEL_LEAD = 12 ; lower pitch square wave sound
SOUND_CHANNEL_BUZZ = 15 ; atonal buzz, good for percussion
LEAD_F4_SHARP = 13
LEAD_E4 = 15
LEAD_D4_SHARP = 16
LEAD_D4 = 17
LEAD_C4_SHARP = 18
LEAD_H3 = 20
LEAD_A3 = 23
LEAD_G3_SHARP = 24
LEAD_F3_SHARP = 27
LEAD_E3_2 = 31
;============================================================================
; T I A - C O N S T A N T S
;============================================================================
HMOVE_L7 = $70
HMOVE_L6 = $60
HMOVE_L5 = $50
HMOVE_L4 = $40
HMOVE_L3 = $30
HMOVE_L2 = $20
HMOVE_L1 = $10
HMOVE_0 = $00
HMOVE_R1 = $F0
HMOVE_R2 = $E0
HMOVE_R3 = $D0
HMOVE_R4 = $C0
HMOVE_R5 = $B0
HMOVE_R6 = $A0
HMOVE_R7 = $90
HMOVE_R8 = $80
; values for ENAMx and ENABL
DISABLE_BM = %00
ENABLE_BM = %10
; values for RESMPx
LOCK_MISSILE = %10
UNLOCK_MISSILE = %00
; values for REFPx:
NO_REFLECT = %0000
REFLECT = %1000
; values for NUSIZx:
ONE_COPY = %000
TWO_COPIES = %001
TWO_MED_COPIES = %010
THREE_COPIES = %011
TWO_WIDE_COPIES = %100
DOUBLE_SIZE = %101
THREE_MED_COPIES = %110
QUAD_SIZE = %111
MSBL_SIZE1 = %000000
MSBL_SIZE2 = %010000
MSBL_SIZE4 = %100000
MSBL_SIZE8 = %110000
; values for CTRLPF:
PF_PRIORITY = %100
PF_SCORE = %10
PF_REFLECT = %01
PF_NO_REFLECT = %00
; values for SWCHB
P1_DIFF_MASK = %10000000
P0_DIFF_MASK = %01000000
BW_MASK = %00001000
SELECT_MASK = %00000010
RESET_MASK = %00000001
VERTICAL_DELAY = 1
; SWCHA joystick bits:
MOVE_RIGHT = %01111111
MOVE_LEFT = %10111111
MOVE_DOWN = %11011111
MOVE_UP = %11101111
P0_NO_MOVE = %11110000
P1_NO_MOVE = %00001111
NO_MOVE = P0_NO_MOVE | P1_NO_MOVE
; values for VBLANK:
DUMP_PORTS = %10000000
ENABLE_LATCHES = %01000000
DISABLE_TIA = %00000010
ENABLE_TIA = %00000000
;values for VSYNC:
START_VERT_SYNC = %10
STOP_VERT_SYNC = %00
;============================================================================
; U S E R - C O N S T A N T S
;============================================================================
BANK0TOP = $1000
BANK1TOP = $2000
BANK0_REORG = $B000
BANK1_REORG = $F000
BANK0STROBE = $FFF8
BANK1STROBE = $FFF9
NTSC_OVERSCAN_TIME = 45
NTSC_VBLANK_TIME = 47
PAL_VBLANK_TIME = 78
PAL_OVERSCAN_TIME = 72
IF COMPILE_VERSION = NTSC
VBLANK_TIME = NTSC_VBLANK_TIME
OVERSCAN_TIME = NTSC_OVERSCAN_TIME
; NTSC color constants
BLACK = $00
WHITE = $0E
LT_RED = $20
RED = $30
ORANGE = $40
ORANGE_2 = ORANGE
RED_2 = ORANGE
DK_PINK = $50
DK_BLUE = $70
BLUE = $80
LT_BLUE = $90
GREEN = $C0
GREEN_2 = GREEN
DK_GREEN = $D0
DK_GREEN_2 = DK_GREEN
LT_BROWN = $E0
LT_BROWN_2 = LT_BROWN
BROWN = $F0
NTSC_BROWN = BROWN
START_LANDING_TIMER = 63 ; staring value for landing timer
FRAME_DELAY_ONE_HALF = $81 ; move 1 out of 2 frames
FRAME_DELAY_ONE_THIRD = $5D ; move 1 out of 3 frames
FRAME_DELAY_ONE_FORTH = $3F ; move 1 out of 4 frames
FRAME_DELAY_ONE_FIFTH = $3B ; move 1 out of 5 frames
ELSE
VBLANK_TIME = PAL_VBLANK_TIME
OVERSCAN_TIME = PAL_OVERSCAN_TIME
; PAL color constants
BLACK = $00
WHITE = $0E
LT_RED = $20
LT_BROWN_2 = LT_RED
BROWN = LT_RED
GREEN_2 = $30
RED = $40
RED_2 = RED + 2
ORANGE = RED
LT_BROWN = $50
DK_GREEN = LT_BROWN
ORANGE_2 = $62
DK_BLUE = $70
DK_PINK = $80
LT_BLUE = $90
BLUE = $D0
DK_GREEN_2 = BLUE
GREEN = $E0
NTSC_BROWN = $F0
START_LANDING_TIMER = 57 ; staring value for landing timer
FRAME_DELAY_ONE_HALF = $9A ; move 1 out of 2 frames
FRAME_DELAY_ONE_THIRD = $6F ; move 1 out of 3 frames
FRAME_DELAY_ONE_FORTH = $4B ; move 1 out of 4 frames
FRAME_DELAY_ONE_FIFTH = $46 ; move 1 out of 5 frames
ENDIF
LDA_ABS = $AD ; instruction to LDA $XXXX
JMP_ABS = $4C ; instruction for JMP $XXXX
XMIN = 0
XMAX = 119
ET_YMIN = 0
ET_YMAX = 58
OBJECT_IN_PIT_Y = 50
OBJECT_IN_PIT_X = 41
PIT_XMIN = 32
PIT_XMAX = 88
FBI_AGENT_VERT_MAX = 48
ELLIOTT_VERT_MAX = 52
SCIENTIST_VERT_MAX = 48
FBI_AGENT_VERT_TARGET = 15
ELLIOTT_VERT_TARGET = 47
SCIENTIST_VERT_TARGET = 15
FBI_AGENT_HORIZ_TARGET = 28
ELLIOTT_HORIZ_TARGET = 60
SCIENTIST_HORIZ_TARGET = 94
H_ET_GRAPH = 40 ; height of E.T. face for title screen
H_FONT = 8
H_FBIAGENT = 28
H_ELLIOTT = 22
H_SCIENTIST = 28
H_PHONE_PIECES = 10
H_FLOWER = 14
H_MOTHERSHIP = 32
H_YAR = 16
H_INDY = 20
MAX_GAME_SELECTION = 3
MAX_ENERGY = $99 ; maximum energy value (BCD)
MAX_HOLD_CANDY = 9 << 4
INIT_NUM_TRIES = 3 ; initial number of tries to get E.T. home
NUM_PHONE_PIECES = 3
; screen id values
ID_FOUR_DIAMOND_PITS = 0
ID_EIGHT_PITS = 1
ID_ARROW_PITS = 2
ID_WIDE_DIAMOND_PITS = 3
ID_FOREST = 4
ID_WASHINGTON_DC = 5
ID_PIT = 6
ID_ET_HOME = 7
ID_TITLE_SCREEN = 8
; pit id values
ID_PIT_OUT_OF_RANGE = -1
ID_TOP_DIAMOND_PIT = 0
ID_LEFT_DIAMOND_PIT = 1
ID_RIGHT_DIAMOND_PIT = 2
ID_LOWER_DIAMOND_PIT = 3
ID_TOP_EIGHT_PITS = 4
ID_LEFT_EIGHT_PITS = 5
ID_RIGHT_EIGHT_PIT = 6
ID_BOTTOM_EIGHT_PIT = 7
ID_TOP_LEFT_ARROW_PIT = 8
ID_TOP_RIGHT_ARROW_PIT = 9
ID_LOWER_LEFT_ARROW_PIT = 10
ID_LOWER_RIGHT_ARROW_PIT = 11
ID_UPPER_LEFT_WIDE_PIT = 12
ID_UPPER_RIGHT_WIDE_PIT = 13
ID_LOWER_LEFT_WIDE_PIT = 14
ID_LOWER_RIGHT_WIDE_PIT = 15
; object ids
ID_FBIAGENT = 0
ID_ELLIOTT = 1
ID_SCIENTIST = 2
ID_H_PHONE_PIECE = 3
ID_S_PHONE_PIECE = 4
ID_W_PHONE_PIECE = 5
ID_FLOWER = 6
ID_MOTHERSHIP = 7
ID_YAR_0 = 8
ID_YAR_1 = 9
ID_INDY = 10
; power zone indicator ids
ID_BLANK_ZONE = 0
ID_WARP_LEFT_ZONE = 1
ID_WARP_RIGHT_ZONE = 2
ID_WARP_UP_ZONE = 3
ID_WARP_DOWN_ZONE = 4
ID_FIND_PHONE_ZONE = 5
ID_EAT_CANDY_ZONE = 6
ID_RETURN_HOME_ZONE = 7
ID_CALL_ELLIOTT_ZONE = 8
ID_CALL_SHIP_ZONE = 9
ID_LANDING_ZONE = 10
ID_PIT_ZONE = 11
ID_FLOWER_ZONE = 12
; candy status values
FOUR_DIAMOND_PITS_CANDY = %0001
EIGHT_PITS_CANDY = %0010
ARROW_PITS_CANDY = %0100
WIDE_DIAMOND_PITS_CANDY = %1000
SHOW_HSW_INITIALS_VALUE = $69 ; BCD value :-)
; player state values
ET_DEAD = %10000000
ELLIOTT_REVIVE_ET = %01000000
; E.T. home Elliott movement values
MOVE_ELLIOTT_RIGHT = %10000000
; collected candy scoring values
COLLECT_CANDY_SCORE_INC = %01000000
CLOSED_EATING_CANDY_ICON = %00000001
; E.T. motion values
ET_RUNNING = %10000000
ET_CARRIED_BY_SCIENTIST = %01000000
ET_MOTION_MASK = %00001111
; human attribute values
RETURN_HOME = %10000000
MOTION_MASK = %00001111
; fireResetStatus values
FIRE_BUTTON_HELD = %10000000
RESET_SWITCH_HELD = %01000000
; starting screen id values
SET_STARTING_SCREEN = %10000000
STARTING_SCREEN_ID = %00001111
; phone piece attribute values
ET_HAS_PHONE_PIECE = %10000000
PHONE_PIECE_SCREEN_LOC = %01000000
FBI_HAS_PHONE_PIECE = %00100000
ELLIOTT_HAS_PHONE_PIECE = %00010000
PHONE_PIECE_PIT_NUMBER = %00001111
; neck extension values
NECK_EXTENDED = %10000000
NECK_DECENDING = %01000000
; flower state values
FLOWER_REVIVED = %10000000
FLOWER_REVIVE_ANIMATION = %00110000
FLOWER_PIT_NUMBER = %00001111
; E.T. pit status values
FALLING_IN_PIT = %10000000
LEVITATING = %01000000
IN_PIT_BOTTOM = %00100000
; mothership status values
MOTHERSHIP_PRESENT = %10000000
ET_GOING_HOME = %01000000
MOTHERSHIP_LEAVING = %00000001
; Easter Egg sprite values
SHOW_YAR_SPRITE = %10000000
SHOW_INDY_SPRITE = %11000000
; sound data channel 0 values
PLAY_SOUND_CHANNEL0 = %10000000
; Easter Egg status values
DONE_EASTER_EGG_CHECK = %10000000
DONE_EASTER_EGG_STEPS = %00000111
;============================================================================
; Z P - V A R I A B L E S
;============================================================================
currentScreenId = $80
frameCount = $81
secondTimer = $82 ; updates ~every second
temp = $83
;--------------------------------------
tempNumberFonts = temp
;--------------------------------------
powerZoneIndex = temp
;--------------------------------------
loopCount = temp
;--------------------------------------
tempJoystickValues = temp
;--------------------------------------
humanETHorizDistRange = temp
;--------------------------------------
pointsTensValue = temp
;--------------------------------------
pointsHundredsValue = temp
;--------------------------------------
energyIncTensValue = temp
;--------------------------------------
energyIncHundredsValue = temp
;--------------------------------------
humanDirectionIndex = temp
;--------------------------------------
newHumanDirection = temp
;--------------------------------------
totalCandyCollected = temp
;--------------------------------------
tempPitNumber = temp
tempCharHolder = $84
nextETGraphicData = $86
;--------------------------------------
energyDecTensValue = nextETGraphicData
;--------------------------------------
energyDecHundredsValue = energyDecTensValue
nextObjectGraphicData = $87
nextObjectColorData = $88
;--------------------------------------
displayKernelBankSwitch = loopCount
bankSwitchStrobe = displayKernelBankSwitch+1
bankSwitchABSJmp = bankSwitchStrobe+2
bankSwitchRoutinePtr = bankSwitchABSJmp+1
fireResetStatus = $89 ; hold when fire button and RESET held
soundDataChannel0 = $8A
unknown = $8B
currentSpriteHeight = $8C
etHeight = $8D
powerZoneColor = $8E
timerColor = $8F
telephoneColor = $90
etMotionValues = $91
etFractionalDelay = $92
humanFractionalDelay = $93
etNeckExtensionValues = $94
currentObjectHorizPos = $95
etHorizPos = $96
etHeartHorizPos = $97
phonePieceMapHorizPos = $98
candyHorizPos = $99
humanTargetHorizPos = $9A
currentObjectVertPos = $9B
etVertPos = $9C
etHeartVertPos = $9D
phonePieceMapVertPos = $9E
candyVertPos = $9F
humanTargetVertPos = $A0
currentObjectId = $A1
humanAttributes = $A2 ; $A2 - $A4
;--------------------------------------
fbiAttributes = humanAttributes
elliottAttributes = fbiAttributes+1
scientistAttributes = elliottAttributes+1
objectScreenId = $A5 ; $A5 - $A7
;--------------------------------------
fbiScreenId = objectScreenId
elliottScreenId = fbiScreenId+1
scientistScreenId = elliottScreenId+1
objectHorizPos = $A8 ; $A8 - $B1
;--------------------------------------
fbiAgentHorizPos = objectHorizPos
elliottHorizPos = fbiAgentHorizPos+1
scientistHorizPos = elliottHorizPos+1
objectVertPos = $AB ; $AB - $AD
;--------------------------------------
fbiAgentVertPos = objectVertPos
elliottVertPos = fbiAgentVertPos+1
scientistVertPos = elliottVertPos+1
objectGraphicPointers = $AE ; $AE - $B1
;--------------------------------------
objectGraphicPtrs_0 = objectGraphicPointers
objectGraphicPtrs_1 = objectGraphicPtrs_0+2
objectColorPointers = $B2 ; $B2 - $B5
;--------------------------------------
objectColorPtrs_0 = objectColorPointers
objectColorPtrs_1 = objectColorPtrs_0+2
etGraphicsPointers = $B6 ; $B6 - $B9
;--------------------------------------
etGraphicPointers0 = etGraphicsPointers; $B6 - $B7
etGraphicPointers1 = etGraphicPointers0+2; $B8 - $B9
playfieldGraphicPtrs = $BA ; $BA - $BD
;--------------------------------------
pf1GraphicPtrs = playfieldGraphicPtrs
pf2GraphicPtrs = pf1GraphicPtrs+2
graphicPointers = $BE ; $BE - $C9
phonePieceAttributes = $CA ; $CA - $CC
;--------------------------------------
h_phonePieceAttribute = phonePieceAttributes
s_phonePieceAttribute = h_phonePieceAttribute+1
w_phonePieceAttribute = s_phonePieceAttribute+1
powerZonePointer = $CD ; $CD - $CE
powerZoneIndicatorId = $CF
shipLandingTimer = $D0
candyStatus = $D1
heldCandyPieces = $D2
etEnergy = $D3 ; $D3 - $D4
etHMOVEValue = $D5
holdETHorizPos = $D6
holdETVertPos = $D7
holdETScreenId = $D8
etPitStatus = $D9
currentPitNumber = $DA
callHomeScreenId = $DB
extraCandyPieces = $DC
collectedCandyPieces = $DD
collectedCandyScoring = $DE
playerScore = $DF ; $DF - $E1
startingScreenId = $E2
playerState = $E3
gameState = $E4
numberOfTries = $E5
flowerState = $E6
powerZoneLSBValues = $E7 ; $E7 - $E9
;--------------------------------------
powerZoneLSBValue_01 = powerZoneLSBValues
powerZoneLSBValue_02 = powerZoneLSBValue_01+1
powerZoneLSBValue_03 = powerZoneLSBValue_02+1
gameSelection = $EA
mothershipStatus = $EB
etAnimationIndex = $EC
etHomeElliottMovement = $ED
themeMusicNoteDelay = $EE
themeMusicFreqIndex = $EF
easterEggStatus = $F0
programmerInitialFlag = $F1
easterEggSpriteFlag = $F2
artistInitialFlag = $F3
;============================================================================
; R O M - C O D E (BANK 0)
;============================================================================
SEG Bank0
.org BANK0TOP
.rorg BANK0_REORG
lda BANK0STROBE
jmp Start
HorizPositionObjects
ldx #<RESBL - RESP0
.moveObjectLoop
sta WSYNC ; wait for next scan line
lda currentObjectHorizPos,x ; get object's horizontal position
tay
lda HMOVETable,y ; get fine motion/coarse position value
sta HMP0,x ; set object's fine motion value
and #$0F ; mask off fine motion value
tay ; move coarse move value to y
.coarseMoveObject
dey
bpl .coarseMoveObject
sta RESP0,x ; set object's coarse position
dex
bpl .moveObjectLoop
sta WSYNC ; wait for next scan line
sta HMOVE
pla ; pull E.T. horizontal position from stack
sta etHorizPos
tax
lda HMOVETable,x
sta etHMOVEValue ; set E.T. horizontal move value
jmp JumpToDisplayKernel
SetScreenIdFromStartingScreen
lda startingScreenId ; get starting screen id
bpl .skipScreenIdSet ; branch if screen id already set
and #<(~SET_STARTING_SCREEN)
sta currentScreenId ; set screen id from starting screen id
jsr SetCurrentScreenData
lsr startingScreenId ; shift right to show value already set
.skipScreenIdSet
bit mothershipStatus ; check mothership status
bmi .jmpToVerticalSync ; branch if Mothership is present
lda currentScreenId ; get the current screen id
cmp #ID_TITLE_SCREEN
bne .checkForETHome ; branch if not on the title screen
.jmpToVerticalSync
jmp VerticalSync
.checkForETHome
lda currentScreenId ; get the current screen id
cmp #ID_ET_HOME
bne .checkForElliottToReviveET ; branch if not on home (game done) screen
jmp VerticalSync
.checkForElliottToReviveET
bit playerState ; check the player state
bpl .checkETNeckExtension ; branch if E.T. is not dead
bvc .checkETNeckExtension ; branch if Elliott not reviving E.T.
lda currentObjectId ; get the current object id
bpl .checkETNeckExtension ; branch if current object still on screen
ldx #ID_ELLIOTT
stx currentObjectId ; set current object id to Elliott
jsr SetCurrentObjectData
lda #<(MOVE_UP >> 4)
sta elliottAttributes ; set Elliott attributes to move up
lda currentScreenId ; get the current screen id
sta elliottScreenId ; place Elliott on the current screen
lda #5
sta elliottHorizPos
sta elliottVertPos
.checkETNeckExtension
bit etNeckExtensionValues ; check neck extension value
bpl CheckETPlayerCollisions ; branch if E.T. neck not extended
.jmpToCheckForETOnPitScreen
jmp CheckIfETOnPitScreen
CheckETPlayerCollisions
bit CXPPMM ; check player to player collisions
bpl .jmpToCheckForETOnPitScreen ; branch if E.T. not collided with object
ldx currentObjectId ; get the current object id
bpl .checkCollisionObjectNotInWell; branch if object not in a well
jmp .checkCollisionObjectInWell
.checkCollisionObjectNotInWell
lda humanAttributes,x ; get the human attribute value
bmi .jmpToCheckForETOnPitScreen ; branch if returning home
txa ; move current object id to accumulator
bne .checkForScientistCollision ; branch if not FBI Agent
ldx #NUM_PHONE_PIECES - 1
.checkToTakePhoneOrCandy
lda phonePieceAttributes,x ; get phone piece attribute value
bmi .fbiTakePhonePieceFromET ; branch if E.T. took phone piece
dex
bpl .checkToTakePhoneOrCandy
lda #$0A
sta heldCandyPieces ; clear carried candy from E.T.
bne .setForFBITakingObjectSound ; unconditional branch
.fbiTakePhonePieceFromET
lda frameCount ; get the current frame count
and #PHONE_PIECE_PIT_NUMBER
ora #FBI_HAS_PHONE_PIECE
sta phonePieceAttributes,x ; set new location for phone piece
.setForFBITakingObjectSound
lda #PLAY_SOUND_CHANNEL0 | $1C
sta soundDataChannel0
jmp .setHumanToReturnHome
.checkForScientistCollision
cpx #ID_SCIENTIST
bne .etCollidedWithElliott ; branch if not collided with Scientist
lda etMotionValues ; get E.T. motion values
ora #ET_CARRIED_BY_SCIENTIST ; set E.T. motion value to show E.T.
sta etMotionValues ; carried by Scientist
rol fbiAttributes ; set FBI Agent to return home
sec
ror fbiAttributes
rol elliottAttributes ; set Elliott to return home
sec
ror elliottAttributes
bne .setHumanToReturnHome ; unconditional branch
.etCollidedWithElliott
lda #PLAY_SOUND_CHANNEL0 | $0C
sta soundDataChannel0
bit playerState ; check the player state
bpl .checkItemExchange ; branch if E.T. is not dead
ldy numberOfTries ; get number of tries
bpl .reviveET ; revive E.T. for another try
rol gameState ; rotate game state left
sec ; set carry and rotate value right to set
ror gameState ; game loss state (i.e. D7 = 1)
jsr SetCurrentScreenToETHome
jmp VerticalSync
.reviveET
dec numberOfTries ; reduce number of tries
ldx #$15
ldy #$00
jsr IncrementETEnergy ; give E.T. 1500 units of energy
sty currentSpriteHeight
sty playerState ; reset player state
dey ; y = -1
sty currentObjectId
sty elliottScreenId
sty elliottAttributes
bne .setHumanToReturnHome ; unconditional branch
.checkItemExchange
ldx #0
lda #ELLIOTT_HAS_PHONE_PIECE
bit h_phonePieceAttribute
bne .giveElliottPhonePieceToET ; branch if Elliott has H phone piece
inx
bit s_phonePieceAttribute
bne .giveElliottPhonePieceToET ; branch if Elliott has S phone piece
inx
bit w_phonePieceAttribute
beq .giveCandyPiecesToElliott ; branch if Elliott has no phone pieces
.giveElliottPhonePieceToET
lda #ET_HAS_PHONE_PIECE
sta phonePieceAttributes,x
bne .setHumanToReturnHome ; unconditional branch
.giveCandyPiecesToElliott
lda heldCandyPieces ; get number of candy pieces held by E.T.
lsr ; shift upper nybbles to lower nybbles
lsr
lsr
lsr
beq .setHumanToReturnHome ; branch if no candy pieces collected
clc
adc collectedCandyPieces ; increment collected candy pieces
sta collectedCandyPieces
lda heldCandyPieces ; get number of candy pieces held by E.T.
cmp #MAX_HOLD_CANDY ; see if E.T. is holding maximum candy
bcc .clearNumberHeldCandyPieces ; clear held candy count if not
ldx #NUM_PHONE_PIECES - 1
lda #$F0
bit w_phonePieceAttribute
beq .givePhonePieceToElliott
dex
bit s_phonePieceAttribute
beq .givePhonePieceToElliott
dex
bit h_phonePieceAttribute
bne .clearNumberHeldCandyPieces
.givePhonePieceToElliott
lda #ELLIOTT_HAS_PHONE_PIECE
sta phonePieceAttributes,x
.clearNumberHeldCandyPieces
lda heldCandyPieces ; get number of candy pieces held by E.T.
and #$0F ; mask to clear number of candy held
sta heldCandyPieces
.setHumanToReturnHome
ldx currentObjectId ; get the current object id
rol humanAttributes,x ; shift human attribute left
sec ; set carry and shift value right to set
ror humanAttributes,x ; RETURN_HOME flag (i.e. D7 = 1)
bmi CheckIfETOnPitScreen ; unconditional branch
.checkCollisionObjectInWell
cpx #$80 | ID_FLOWER
bcs CheckIfETOnPitScreen ; branch if E.T. didn't pick up phone piece
lda #PLAY_SOUND_CHANNEL0 | $0D
sta soundDataChannel0
txa ; move current object id to accumulator
and #$0F ; mask pit value to keep object id
sec
sbc #3 ; subtract value by 3
tax
cmp #3
bcs CheckIfETOnPitScreen ; branch if E.T. didn't pick up phone piece
lda #ET_HAS_PHONE_PIECE
sta phonePieceAttributes,x
asl ; a = 0
sta currentSpriteHeight
CheckIfETOnPitScreen
lda currentScreenId ; get the current screen id
cmp #ID_FOREST
bcc CheckETPitCollisions ; branch if E.T. on a pit screen
.jmpToDetermineHumanDirection
jmp DetermineHumanDirection
CheckETPitCollisions
bit etMotionValues ; check E.T. motion values
bvs .jmpToDetermineHumanDirection; branch if E.T. carried by Scientist
bit CXP1FB ; check E.T. and playfield collision
bmi PlaceETInPit ; branch if E.T. collided with pit
lda #0
sta etPitStatus ; clear E.T. pit status flags
beq .jmpToDetermineHumanDirection; unconditional branch
PlaceETInPit
bit etNeckExtensionValues ; check neck extension value
bmi .jmpToDetermineHumanDirection; branch if E.T. neck extended
lda etVertPos ; get E.T.'s vertical position
sta holdETVertPos ; save for when E.T. emerges from pit
lda etHorizPos ; get E.T.'s horizontal position
sta holdETHorizPos ; save for when E.T. emerges from pit
ldy #0
ldx currentScreenId ; get the current screen id
stx holdETScreenId ; save for when E.T. emerges from pit
beq SetPitNumberForDiamondPits ; branch if FOUR_DIAMOND_PITS
dex
beq SetPitNumberForEightPits ; branch if EIGHT_PITS
dex
beq SetPitNumberForArrowPits ; branch if ARROW_PITS
ldx #ID_UPPER_LEFT_WIDE_PIT
bne CalculateCurrentPitNumber ; unconditional branch -- WIDE_DIAMOND_PITS
SetPitNumberForArrowPits
ldx #ID_TOP_LEFT_ARROW_PIT
CalculateCurrentPitNumber
stx tempPitNumber
cmp #59 ; compare E.T.'s horizontal position
bcc .compareETVerticalPosition
iny ; y = 1
.compareETVerticalPosition
lda etVertPos ; get E.T.'s vertical position
cmp #33
bcc .combineTempPitNumber
iny
iny
.combineTempPitNumber
tya
ora tempPitNumber
bne .setCurrentPitNumber ; unconditional branch
SetPitNumberForDiamondPits
cmp #41 ; compare E.T.'s horizontal position
bcs .etNotInPitOne
lda #ID_LEFT_DIAMOND_PIT ; show that E.T. is in pit number 1
bne .setCurrentPitNumber ; unconditional branch
.etNotInPitOne
cmp #81 ; compare E.T.'s horizontal position
bcc .etNotInPitTwo
lda #ID_RIGHT_DIAMOND_PIT ; show that E.T. is in pit number 2
bne .setCurrentPitNumber ; unconditional branch
.etNotInPitTwo
lda etVertPos ; get E.T.'s vertical position
cmp #29
lda #ID_TOP_DIAMOND_PIT
bcc .setCurrentPitNumber ; set E.T. to pit number 0
lda #ID_LOWER_DIAMOND_PIT ; show that E.T. is in pit number 3
bne .setCurrentPitNumber ; unconditional branch
SetPitNumberForEightPits
ldx etVertPos ; get E.T.'s vertical position
cpx #19
bcc .checkForOutOfRangePit
cpx #40
bcc .checkHorizPosForPitNumber
ldy #3
.checkForOutOfRangePit
cmp #32 ; compare E.T.'s horizontal position
bcc .setToOutOfRangePitNumber
cmp #96 ; compare E.T.'s horizontal position
bcs .setToOutOfRangePitNumber
.combineIndexForPitNumber
tya
ora #ID_TOP_EIGHT_PITS
bne .setCurrentPitNumber ; unconditional branch
.setToOutOfRangePitNumber
lda #<ID_PIT_OUT_OF_RANGE
bne .setCurrentPitNumber ; unconditional branch
.checkHorizPosForPitNumber
iny ; y = 1
cmp #64 ; compare E.T. horizontal position
bcc .combineIndexForPitNumber
iny ; y = 2
bne .combineIndexForPitNumber ; unconditional branch
.setCurrentPitNumber
sta currentPitNumber
lda #ID_PIT
sta currentScreenId ; set the current screen id
jsr SetCurrentScreenData
DetermineHumanDirection
lda frameCount ; get the current frame count
and #3 ; make value 0 <= a <= 3
cmp #ID_SCIENTIST + 1
beq CheckForETCollectingCandy ; branch if out of human id range
tax ; move object id to x
lda objectScreenId,x ; get the object's screen id
bpl .multiplyScreenIdBy8 ; branch if human is active
lda humanAttributes,x ; get human attribute value
bmi CheckForETCollectingCandy ; branch if returning home
lda #ID_WASHINGTON_DC
jsr CheckForHumanOnScreen
bcs CheckForETCollectingCandy ; branch if human on WASHINGTON_DC screen
sta objectScreenId,x ; set object screen id to WASHINGTON_DC
lda HumanTargetVertPosTable,x
sta objectVertPos,x
lda HumanTargetHorizPosTable,x
sta objectHorizPos,x
lda #<(MOVE_LEFT >> 4)
sta humanAttributes,x ; set human to move left
lda #ID_WASHINGTON_DC
cmp currentScreenId
bne CheckForETCollectingCandy
stx currentObjectId
jsr SetCurrentObjectData
jmp CheckForETCollectingCandy
.multiplyScreenIdBy8
asl
asl
asl
sta humanDirectionIndex
lda humanAttributes,x ; get human attribute value
bpl .checkToChangeHumanDirection ; branch if not returning home
lda #5
clc
bcc .setNewHumanDirection ; unconditional branch
.checkToChangeHumanDirection
lda currentScreenId ; get the current screen id
cmp #ID_PIT ; if on PIT or HOME or TITLE SCREEN then
bcs CheckForETCollectingCandy ; don't change human direction
.setNewHumanDirection
adc humanDirectionIndex
tay
lda HumanDirectionTable,y
bmi CheckForETCollectingCandy
sta newHumanDirection
lda humanAttributes,x ; get human attribute value
and #$F0 ; clear current human direction
ora newHumanDirection ; or in new direction value
sta humanAttributes,x ; set new direction value
CheckForETCollectingCandy
bit CXP1FB ; check E.T. collision with PF and BALL
bvc .skipCandyCollection ; branch if E.T. did not collect candy
ldx currentScreenId ; get the current screen id
cpx #ID_FOREST
bcs .skipCandyCollection ; branch if E.T. not on a pit screen
lda heldCandyPieces ; get number of candy pieces held by E.T.
cmp #MAX_HOLD_CANDY
bcs .skipCandyCollection ; branch if E.T. holding maximum candy
adc #1 * 16 ; increment held candy pieces by 1
sta heldCandyPieces
lda #PLAY_SOUND_CHANNEL0 | $1C
sta soundDataChannel0
lda #127 ; set candy piece vertical position to be
sta candyVertPos ; out of visual range
lda CandyStatusMaskTable,x
and candyStatus
sta candyStatus
.skipCandyCollection
lda secondTimer
and #$0F
bne CheckForETNeckExtension
lda frameCount ; get the current frame count
and #$3F
cmp #23
bne CheckForETNeckExtension
lda candyStatus ; get candy status flag value
and #$0F
tax
lda extraCandyPieces ; get extra candy pieces value
sec
sbc ExtraCandyReductionTable,x