-
Notifications
You must be signed in to change notification settings - Fork 6
/
dkong.asm
11276 lines (8810 loc) · 530 KB
/
dkong.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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Originally disassembled with dZ80 v1.31
;
; Memory map:
; $0000-3fff ROM
; $6000-6fff RAM
; $6900-6A7f sprites
; $7000-73ff unknown; probably not used
; $7400-77ff Video RAM
; top left corner: $77A0
; bottom left corner: $77BF
; top right corner: $7440
; bottom right corner: $745F
;
; Note that the monitor is rotated 90 degrees, so $77A1 is the tile under
; $77A0, not the tile to the right of it.
; I/O ports
IN0 equ $7c00 ; player 1 joystick and jump button
IN1 equ $7c80 ; player 2 joystick and jump button
IN2 equ $7d00 ; coins; start buttons
DSW1 equ $7d80 ; DIP switches
; IN0 and IN1:
; bit 7 : ?
; bit 6 : reset
; bit 5 : ?
; bit 4 : JUMP
; bit 3 : DOWN
; bit 2 : UP
; bit 1 : LEFT
; bit 0 : RIGHT
;
; (IN0 is read on player 1's turn; IN1 is read on player 2's turn)
; IN2:
; bit 7: COIN
; bit 6: ? Radarscope does some wizardry with this bit
; bit 5 : ?
; bit 4 : ?
; bit 3 : START 2
; bit 2 : START 1
; bit 1 : ?
; bit 0 : ? if this is 1, the code jumps to $4000, outside the rom space
; DSW1:
; bit 7 : COCKTAIL or UPRIGHT cabinet (1 = UPRIGHT)
; bit 6 : \ 000 = 1 coin 1 play 001 = 2 coins 1 play 010 = 1 coin 2 plays
; bit 5 : | 011 = 3 coins 1 play 100 = 1 coin 3 plays 101 = 4 coins 1 play
; bit 4 : / 110 = 1 coin 4 plays 111 = 5 coins 1 play
; bit 3 : \bonus at
; bit 2 : / 00 = 7000 01 = 10000 10 = 15000 11 = 20000
; bit 1 : \ 00 = 3 lives 01 = 4 lives
; bit 0 : / 10 = 5 lives 11 = 6 lives
; 7800-780F P8257 Control registers
; @TODO@ -- define constants for this
REG_MUSIC equ $7c00
; Values written to REG_MUSIC
; @TODO@ -- update code to use these
MUS_NONE equ $00
MUS_INTRO equ $01 ; Music when DK climbs ladder
MUS_HOWHIGH equ $02 ; How high can you get?
MUS_OUTATIME equ $03 ; Running out of time
MUS_HAMMER equ $04 ; Hammer music
MUS_ENDING1 equ $05 ; Music after beating even-numbered rivet levels
MUS_HAMMERHIT equ $06 ; Hammer hit
MUS_FANFARE equ $07 ; Music for completing a non-rivet stage
MUS_25M equ $08 ; Music for barrel stage
MUS_50M equ $09 ; Music for pie factory
MUS_75M equ $0a ; Music for elevator stage (or lack thereof)
MUS_100M equ $0b ; Music for rivet stage
MUS_ENDING2 equ $0c ; Music after beating odd-numbered rivet levels
MUS_RM_RIVET equ $0d ; Used when rivet removed
MUS_DK_FALLS equ $0e ; Music when DK is about to fall in rivet stage
MUS_DK_ROAR equ $0f ; Zerbert. Zerbert. Zerbert.
; Sound effects get their own registers
REG_SFX equ $7d00 ; The first of 8 sound registers, but only the first 6 are used
; These are added to REG_SFX to produce the register to write to
; These are also used by RAM (@TODO@ -- what variable?) to queue sounds
SFX_WALK equ 0
SFX_JUMP equ 1
SFX_BOOM equ 2 ; DK pounds ground; barrel hits Mario
SFX_SPRING equ 3 ; (writes to i8035's P1)
SFX_FALL equ 4 ; (writes to i8035's P2)
SFX_POINTS equ 5 ; Got points, grabbed the hammer, etc.
REG_SFX_DEATH equ $7d80 ; plays when Mario dies (triggers i8035's interrupt)
; Some other hardware registers
REG_FLIPSCREEN equ $7d82
REG_SPRITE equ $7d83 ; cleared at program start and never used
REG_VBLANK_ENABLE equ $7d84
REG_DMA equ $7d85 ; @TODO@ -- what does this do, exactly?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Background palette selectors
;
; These registers each store 1 bit. Only the least-significant bit
; matters when writing. The two values together determine the palette
; for the whole screen. Note that the colors can change from row to row
; in each palette. For example, in the high score screen palette, the
; first row of tiles shows red text; the second and third rows have
; white text; the fourth row has blue text; etc. You can see this in
; MAME by looking at the 0's on the screen while the game is booting up.
;
; Palettes:
; A | B
; -----
; 0 | 0 high score screen
; 0 | 1 barrel and elevator stages
; 1 | 0 pie factory stage
; 1 | 1 rivet stage
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
REG_PALETTE_A equ $7d86
REG_PALETTE_B equ $7d87
; Machine accepts no more than 90 credits (this is a BCD value)
MAX_CREDITS equ $90
RAM equ $6000
SPRITE_RAM equ $7000
VIDEO_RAM equ $7400
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Notes on variables (READ THIS)
;
; Donkey Kong's code is a little nutty and often depends on variables
; being stored in a certain way. For instance, if there's a variable at
; RAM+$a, it may do "DEC HL" to get at the variable at RAM+9, even
; if these variables are loosely related at best. If you're making a
; hack, we strongly suggest you keep the addresses of existing variables
; intact!
;
; For the same reason, it's hard to be 100% sure that every variable has
; been documented. It's easy to miss a variable if it's never directly
; referenced by address.
;
; Finally, be aware that, intentionally or not, some variables may have
; been used for more than one purpose.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Number of credits in BCD. Can't go over MAX_CREDITS.
NumCredits equ RAM+1
; Counts number of coins inserted until next credit is reached
; E.g., if the machine is set to 4 coins/credit, this starts at 0 and counts up to 4 with each coin.
; When it's 4, it'll be reset to 0 and a credit will be added.
CoinCounter equ RAM+2
; Usually 1. When a coin is inserted, it changes to 0 momentarily.
; (In MAME, this value will be 0 while the coin key is held down.)
CoinSwitch equ RAM+3
; 1 when in attract mode, 2 when credits in waiting for start, 3 when playing game
GameMode1 equ RAM+5
; 1 when no credits have been inserted, 0 if any credits exist or a game is being played
NoCredits equ RAM+7
; General-purpose timer. 16-bit. The code uses the MSB rather than the LSB for 8-bit timers.
WaitTimer equ RAM+8
WaitTimerLSB equ WaitTimer
WaitTimerMSB equ WaitTimer+1
; Attract mode: $1
; Intro: $7
; How High Can You Get?: $a
; Right before play: $b
; During play: $c
; Dead: $d
; Game over: $10
; Rivets cleared: $16
; @TODO@ -- list is not complete. Range is [0..$17], and most, possibly all, values seem to be used
GameMode2 equ RAM+$a
; Both of these are 0 if it's player 1's turn, and 1 if it's player 2's turn.
; @TODO@ -- try to find why these are two variables and give them better names.
PlayerTurnA equ RAM+$d
PlayerTurnB equ RAM+$e
; 0 if 1-player game, 1 if 2-player game
TwoPlayerGame equ RAM+$f
; The same as RawInput below, except when jump is pressed, bit 7 is set momentarily
InputState equ RAM+$10
; Right sets bit 0, left sets bit 1, up sets bit 2, down sets bit 3, jump sets bit 4
RawInput equ RAM+$11
; constantly changing ... timer of some sort? (@TODO@ -- better name?)
RngTimer1 equ RAM+$18
; RngTimer2 - constantly changing timer - very fast (@TODO@ -- better name?)
RngTimer2 equ RAM+$19
; Constantly counts down from FF to 00 and then FF to 00 again and again, once per frame
FrameCounter equ RAM+$1a
; Initial number of lives (set with dip switches)
StartingLives equ RAM+$20
; score needed for bonus life in thousands
ExtraLifeThreshold equ RAM+$21
CoinsPerCredit equ RAM+$22
; Coins needed for a two-player game (always CoinsPerCredit*2)
CoinsPer2Credits equ RAM+$23
; Seems to be used for the same purpose as CoinsPerCredit (@TODO@ -- why is this a distinct variable?)
CoinsPerCredit2 equ RAM+$24
CreditsPerCoin equ RAM+$25
; 0 = cocktail, 1 = upright cabinet
UprightCab equ RAM+$26
; Timer counting delay before cursor can move. Keeps the cursor from moving too fast.
; (@XXX@ -- verify this is this variable's function!!)
HSCursorDelay equ RAM+$30
; Toggles between 0 and 1 as the player's high score in the table blinks
HSBlinkToggle equ RAM+$31
; Toggles HSBlinkToggle in table whenever it's zero
HSBlinkTimer equ RAM+$32
; Time left to register name in seconds
HSRegiTime equ RAM+$33
; Decrements HSRegiTime when zero
HSTimer equ RAM+$34
; Which character the cursor is highlighting when entering high score
HSCursorPos equ RAM+$35
; Address of screen RAM for current initial being entered (16-bit variable)
HSInitialPos equ RAM+$36
; Something to do with high score entry.
; Changing this value to FF in the debugger on high score screen causes the
; game to prompt for another name after entering the first.
Unk6038 equ RAM+$38
; Number of lives remaining for player 1
P1NumLives equ RAM+$40
; #6041-6047 = ???
Unk6041 equ RAM+$41
; Number of lives for player 2
P2NumLives equ RAM+$48
; #6049-604f probably serve the same purpose as 6041-6047, but for player 2
Unk6049 equ RAM+$49
NumObstaclesJumped equ RAM+$60
; #6080 - #608F are used for sounds - they are a buffer to set up a sound to be played on the hardware
; #6080 = 1 or 3 when mario is walking, makes the walking sound
; #6081 counts down 3, 2, 1, 0 when mario jumps
; #6082 = boom sound
; #6083 counts down 3,2,1,0 when the springs bounce on the elevator level
; #6084 used for falling sounds
; #6085 = 1 when the bonus sound is played
; #6086 =
; #6089 = used to determine which music is played: (not all used during play?)
; #608A is used for same?
; #60B0 and #60B1 are some sort of counter. counts from #C0 192 (decimal) to #FE (256) by twos, then again and again. Related to #60C0 - #60FF ?
; #60B2, #60B3, #60B4 - player 1 score
; #60B5, #60B6, #60B7 - player 2 score
; #60B8 = ???
; #60C0 - #60FF - loaded with #FF, used for a timer, in conjunction with #60B0 ?
; #6100 - #61A5 - high score table
; #61C6, #61C7 = ???
; #6200 is 1 when mario is alive, 0 when dead
; #6202 varies from 0, 2, 4, 1 when mario is walking left or right
; #6203 = Mario's X position
; #6204 = varies between 80 and 0 when mario jumping left or right
; #6205 = Mario's Y position
; #6206 = left 4 bits vary when mario jumping
; #6207 = a movement indicator. when moving right, 128 bit is set. (bit 7) move left, 128 bit is cleared
; #6207 continuted. walking, bits 0 and 1 flip around. jump sets bits 1,2,3 on. when climbing a ladder,
; #6207 cont. bit 7 flips on and off, and bits 0,1,2 flip around
; #6208 = ?
; #620C = mario's jump height?
; #620F is movement indicator. when still it is on 0, 1, or 2. when moving it moves between 2,1,0,2,1,0... when on a ladder it goes to counts down from 4. when it reaches zero, it animates mario climbing.
; #620E is set whenever mario jumps, it holds marios Y value when he jumped.
; #6210 = FF when jumping to the left and afterwards until another jump, 0 otherwise
; #6211 = 0 when jumping straight up, #80 when jumping left or right
; #6212 =
; #6214 = is counted from 0 while mario is jumping.
; #6215 is 1 when mario is on ladder, 0 otherwise
; #6216 is 1 while mario is jumping, 0 otherwise
; #6217 is 1 when hammer is active, 0 otherwise
; #6218 = 0, turns to 1 while mario is grabbing the hammer until he lands
; #6219 = 0, turns to 1 when mario is moving on a moving or broken ladder, [but this is never checked ???]
; #621B,C = the top and bottom locations of a ladder mario is on or near
; #621E = counts down from 4 when mario is landing from a jump. 0 otherwise
; #621F = 1 when mario is at apex or on way down after jump, 0 otherwise.
; #6220 = set to 1 when mario falls too far, 0 otherwise
; #6221
; #6222 = toggles between 0 and 1 when mario on ladder. otherwise 0
; #6224 = toggles between 0 and 1 when mario on ladder. used for sounds while on ladder
; #6225 = 1 when a bonus sound is to be played, 0 otherwise
; #6227 is screen #: 1-girders, 2-pie, 3-elevator, 4-rivets
; #6228 is the number of lives remaining for current player
; #6229 is the level #
; #622C = game start flag. 1 when game begins, 0 after mario has died ?
; #622D = 0, changed to 1 when player is awarded extra life
; #6280 to #6287 = left side retractable ladder on conveyors?
; #6288, 6289, 628A = ???
; #6290 = counts down how many rivets are left from 8
; #62A0 = top conveyor direction reverse counter
; #62A1 = master direction for top conveyor, 01 = right, FF = left
; #62A2 = middle conveyor direction reverse counter
; #62A3 = master direction for middle conveyor, 01 = outwards, FF = inwards
; #62A5 = bottom conveyor direction reverse counter
; #62A6 = master direction for bottom conveyor, 01 = right, FF = left
; #62A7 = counts down from #34 to zero on elevators
; #62A8
; #62AA
; #62AC -
; #62AF = some sort of timer connected with the barrels counts down from 18 to 00 , then kong moves position for next barrel grab See #638F
; continued also used for counter during game intro, used for kong animation
; #62B1 - Bonus timer
; #62B2 controls the timer for blue barrels
; #62B3 = controls the timers for all levels except girders. Is #78 (120), #64 (100), #50,(80) or #3C (60) depending on level.
; level 1 rivets 5000 bonus lasts 99 seconds (say 100) = 100 bonus every 2 seconds
; level 2 rivets 6000 bonus lasts 99 seconds = 100 bonus every 5/3 (1.66666...) seconds
; level 3 rivets 7000 bonus lasts 92 seconds = 100 bonus every 4/3 (1.3333...) seconds
; level 4 rivets 8000 bonus lasts 80 seconds = 100 bonus every 1 seconds
; level 1 barrels 4700 bonus lasts 94 seconds = 100 bonus every 2 seconds
; level 2 barrels 5700 bonus lasts 105 seconds = 100 bonus every 1.842 seconds ???
; level 3 barrels 6700 bonus lasts 93 seconds = 100 bonus every 1.388 seconds
; level 4 barrels 7700 bonus lasts 130 seconds = 100 bonus every 5/3 seconds 1.666 ?
;
; #62B4 a timer used on conveyors ?
; #62B8 = a timer used on conveyors and girders ?
; #62B9 - used for fire release on conveyors and girders ? 0 when no fires onscreen, 1 when fires are onscreen, 3 when a fire is to be released
; #6300 - ladder sprites / locations ???
; #6340 - usually 0, changes when mario picks up bonus item. jumps over item turns to 1 quickly, then 2 until bonus disappears
; #6341 - timer counts down when mario picks up bonus item or jumps an item for showing bonus on screen
; #6342
; #6343 - changes to 14 when umbrella picked up, 0C for hat, 10 for purse
; #6345 - usually 0. changes to 1, then 2 when items are hit with the hammer
; #6348 - #00, turns to #01 when the oil can is on fire on girders
; #6350 - 0, turns to 1 when an item has been hit with hammer, back to 0 after score sprite appears in its place
; #6351 through #6354 used for temp storage for items hit with hammer
; #6380 - Internal difficulty. Dictates speed of fires, wild barrel behavior, barrel steerability and other things. Ranges from 1 to 5.
; #6381 = timer that controls when #6380 changes ?
; #6382 = 00 and turns to 80 when a blue barrel is about to be deployed.
; First blue barrel has this at 81 and then 02. changes to 1 for crazy barrel
; Bit 7 is set when barrel is blue
; Bit 0 is set when barrel is crazy
; bit 1 is set for the second barrel of the round which can't be crazy
; #6383 = timer used in conjunction with the tasks
; #6384 = timer ?
; #6385 = varies from 0 to 7 while the intro screen runs, when kong climbs the dual ladders and scary music is played
; #6386 - is zero until time runs out. then it turns to 2, then when it turns to 3 mario dies
; #6387 - is zero until time runs out. then it counts down from FF to 00, when it hits 00 mario dies and #6386 is set to 3
; #6388 = usually zero, counts from 1 to 5 when the level is complete
; #6389 - ????
; #638C is the onscreen timer
; #638D = counts from 5 to 0 while kong is bouncing during intro
; #638E = counts from #1E to A while kong is climbing ladders at beginning of game
; #638F = Counts down 3,2,1,0 as a barrel is being deployed. See #62AF
; #6390 - counts from 0 to 7F periodically
; #6391 - is 0, then changed to 1 when timer in #6390 is counting up
; #6392 = barrel deployment indicator. 0 normally, 1 when a barrel is being deployed
; #6393 - Barrel deployment indicator. This gets set to 1 as soon as the barrel deployment process begins, and gets set back to 0 as soon as
; kong releases the barrel being deployed.
; #6396 = bouncer release flag. 0 normally, 3 when bouncer is to be deployed
; #6398 = 1 when riding an elevator ?
; #639B = pie deployment counter
; #639D = normally 0. 1 while mario dying, 2 when dead
; #639A = indicator for the fires/deployment
; #63A0 = usually 0, flips to 1 quickly when a firefox is deployed
; #63A1 = number of firefoxes active
; #63A2 = used as a temporary counter
; #63A3 = top conveyor direction for this frame, flips between 00 (stationary) and either 1 (right) or FF (left) depending on kongs direction
; #63A4 = middle left conveyor direction for this frame
; #63A5 = middle right conveyor direction for this frame
; #63A6 = bottom conveyor direction for this frame
; #63B3 - ???
; #63B5 - ???
; #63B7 - ???
; #63B8 is zero but turns to 1 when the timer expires but before mario dies
; #63B9 - is 1 during girders, changes to 0A when item is hit with hammer.
; on rivets it is 07. conveyors turns to 6 when pie hit, 5 when fire hit. changes to 0A when mario dies
; #63C0 - ???
; #63C8,9 - Used during fireball movement processing to store the address of the fireball data array for the current fireball being processed
; #63CC - ???
; #6400 to #649F - Fireball data tables. There are 5 fireball slots, each with 32 bytes for storing data associated with that fireball. The first
; fireball's slot is #6400 to #641F, the second fireball's slot is #6420 to #643F, etc. The following is a description of the data
; stored at each offset into a fireball's slot:
; +00 - Fireball status. 0 = inactive (this fireball slot is free), 1 = active
; +01,02 - Empty
; +03 - Fireball actual X-position. This seems to be the same as +0E.
; +04 - Empty
; +05 - Fireball actual Y-position. This Y-position has been adjusted for the bobbing up and down that a each fireball is constantly doing. Note that
; this bobbing up and down is mainly for visual effect and has no impact on any fireball movement logic (this uses +0F instead, which does not
; account for the bobbing up and down), however hitboxes are still determined by this actual Y-position and not the effective Y-position
; +06 - Empty
; +07 - Fireball graphic data
; +08 - Fireball color. 0 = blue (Mario has hammer), 1 = normal
; +09 - (Width of fireball hitbox - 1)/2
; +0A - (Height of fireball hitbox - 1)/2
; +0B,0C - Empty
; +0D - Fireball direction of movement. It can take on the following values:
; 0 = left, but it can also mean "frozen" in the case of a freezer that is currently in freezer mode
; 1 = right
; 2 = "special" left, this is different from 0 since here the fireball behaves identically to a right-moving fireball, only moving left instead
; of right. This means that ladders are permitted to be taken, speed is deterministic and not slowed, and freezers aren't frozen when
; the direction is 2, unlike a direction of 0. The direction gets set to 2 only immediately after a fireball hits the right edge of a
; girder, and it will stay at 2 until a "decision point" for reversing direction at which point the direction will become either 0 or 1.
; 4 = descending ladder
; 8 = ascending ladder
; +0E - Fireball effective X-position. This seems to be the same as +03.
; +0F - Fireball effective Y-position. This Y-position does not account for the fireball bobbing up and down and is treated as the true Y-position for
; the purposes of all fireball movement.
; +10 to +12 - Empty
; +13 - This counter is used as an index into a table that determines how to adjust the fireball's Y-position to make it bob up and down.
; +14 - Ladder climb timer. This timer counts down from 2 as a fireball climbs a ladder. A fireball is only allowed to climb a pixel when this reaches
; 0, at which point it gets reset back to 2. This has the effect of causing fireballs to climb ladders at 1/3 of the speed at which they descend
; ladders.
; +15 - Fireball animation change timer. This timer counts down from 2, and when it reaches 0 the fireball changes it's graphics.
; +16 - Fireball direction reverse counter. When this counter reaches 0 a fireball reverses direction with 50% probability. Such a decision is referred
; to as a "decision point".
; +17 - Empty
; +18 - Fireball spawning flag. This is set to 1 to indicate that the fireball is in the process of spawning. Often fireballs follow a special
; trajectory, such as when jumping out of an oil can, while this is set.
; +19 - Fireball freezer mode flag. Setting this to 2 indicates that freezer mode has been enguaged, at which point a fireball can potentially start
; freezing. Only fireballs in the 2nd and 4th fireball slots can enter freezer mode.
; +1A,1B - During fireball spawning, when jumping out of an oil can, this is used to store the current index into the Y-position table that dictactes
; the arc that the fireball follows as it comes out of the oil can.
; +1C - Fireball freeze timer. Freezers use this as a timer until a frozen fireball should unfreeze.
; +1D - Fireball freeze flag. If this gets set during freezer mode, then as long as Mario is not above the fireball it will immediately set the freeze
; timer (+1C) for 256 frames and says frozen until the timer reaches 0, this can only happen when a fireball reaches the top of a ladder, all
; other instances of a fireball freezing are caused by the direction being set to 0 during freezer mode and have nothing to do with the freeze
; timer.
; +1E - Empty
; +1F - When a fireball is climbing up or down a ladder, this stores the Y-position of the other end of the ladder (the end the fireball is headed
; towards).
; #64A7 -
; #6500 - #65AF = the ten bouncer values, 6510, 6520, etc. are starting values
; +3 is the X pos, +5 is the Y pos
; #65A0 - #65?? = values for the 6 pies
; #6600 - 665F = the 6 elevator values. 6610, 6620, 6630, 6640 ,6650 are starting values
; + 3 is the X position, + 5 is the Y position
; #6680 -
; #6687 -
; #6688
; hammer code for top hammer of girders, lower hammer on rivets, upper left hammer on conveyors
; #6689 - changes from 5 to 6 when hammer active
; #668A - changes from 6 to 3 when hammer active
; #668E - changes from 0 to 10 when hammer active
; #668F - changes from 0 to F0 when hammer active
; #66A0 - ???
; #6700 range - barrel info +20, +40, +60, +80, +A0, +C0, +E0 for the barrels
; 00 = barrel not in use. #02 = barrel being deployed. #01 = barrel rolling
; #6701 - crazy barrel indicator. 00 for normal, #01 for crazy barrel
; #6702 - motion indicator. 02 = rolling right, 08 = rolling down, 04 = rolling left, bit 1 set when rolling down ladder
; #6703 - barrel X
; #6705 - barrel Y
; #6707 - right 2 bits are 01 when rolling, 10 when being deployed. bit 7 toggles as it rolls
; #6708
; #670E = edge indicator. counts from 0 to 3 while barrel is going over edge
; #670F = counts from 4 to 1 then over again when barrel is moving
; #6710 = 0 when deployed. changed to #FF when at left edge and after landing after falling off right edge of girder.
changed to 1 when after landing after falling off left edge of girder and starting to roll right
changed to 0 while falling off right edge of girder
; #6711 = 60 when barrel is rolling around the right edge, A0 when rolling around left edge
;
; #6714 =
; #6715 =
; #6717 = position of next ladder it is going down or the ladder it just passed.
; ladders are : 70, 6A, 93, 8D, 8B, B3, B0, AC, D1, CD, F3, EE
; #6719 = grabs the Y value of the barrel when its crazy, and has hit a girder
; #6900 - #6907 = 2 sprites used for the girl
; #6908 - (#6908 + #28) = animation states for kong and maybe other things
; #6909 - kong's right leg
; #6913 -
; #6919 - kong's mouth
; #691D - kong's right arm
; #692D - girl under kong's arms during game intro
; #692F - girl under kong's arms ???
; #6944 - #694C = 2 sprites for moving ladders on conveyors
; #694C = mario sprite X value
; #694D = mario sprite value.
; #694E = mario sprite color ?
; #694F = mario sprite Y value
00 = mario facing left
01, 02 = mario running left
03 = mario on ladder with left hand up
04 = mario on ladder with butt showing
05 = mario on ladder with butt showing
06 = mario standing above ladder with back to screen
07 = blank???
08 = mario with hammer up, facing left
09 = mario with hammer down, facing left
0A = mario with hammer up, facing left
0B = mario with hammer down, facing left
0C = mario with hammer up, facing left
0D = mario with hammer down, facing left
0E = mario jumping left
0F = mario landing left
10 = top of girl
11 = bottom of girl
12 = bottom of girl (2nd pose)
13 = bottom of girl (fat)
14 = legs of girl when being carried
15 = rolling barrel
16, 17 = barrel going down ladder or crazy
18 = barrel next to kong (vertical)
19 = blue barrel (skull)
1A, 1B = barrel going down ladder or crazy
1C, 1D = blank ?
1E = hammer
1F = smashing down hammer
20, 21, 22 = crazy kong face
23 = kong face, frowning
24 = kong face, growling
25 = kong chest
26 = kong left leg
27 = kong right leg
28 = kong right arm
29 = kong left arm
2A = kong right shoulder
2B = part of kong ?
2C = kong right foot
2D = kong left arm grabbing barrel
2E = kong bottom center
2F = kong top right shoulder
30 = kong face facing left
31 = kong right arm
32 = kong shoulder
33 = kong shoulder
34 = kong left arm
35 = kong right arm
36 = kong left foot climbing ladder
37 = kong right foot climbing ladder
38 = blank ?
39 = lines for smashed item
3A = solid block ?
3B = bouncer (1)
3C = bouncer (2 squished)
3D = fireball (1)
3E = fireball (2)
3F = blank ?
40 = fire on top of oil can
41 = fire on top of oil can (2)
42 = fire on top of oil can (3)
43 = fire on top of oil can (4)
44 = flat girder (used for elevator?)
45 = elevator receptacle
46 = ladder
47, 48 = blank ?
49 = oil can
4A = blank?
4B = pie
4C = pie spilling over
4D = firefox
4E = firefox (2)
4F = blanK?
50 = edge of conveyor pulley
51 = edge of conveyor pulley (2)
52 = edge of conveyor pulley (3)
53 - 5F = blank ?
60 = circle for item being hit with hammer
61 = small circle for item being hit with hammer
62 = smaller circle for item being hit with hammer
63 = burst for item being hit with hammer
64 - 71 = blank
72 = square for hiscore select
73 = hat
74 = purse
75 = umbrella
76 = heart
77 = broken heart
78 = dying, mario upside down
79 = dying, mario head to right
7A = mario dead
7B = 100
7C = 200
7D = 300
7E = 500
7F = 800
all values from 80-FF are mirror images of items 0 -7F
80 = starting value, mario facing right
81, 82 = mario running to right
83 = mario on ladder with right hand up
84 = mario on ladder with butt showing
85 = mario on ladder with butt showing (2)
86 =
88 = mario with hammer up, facing right
89 = mario with hammer down, facing right
8A = mario with hammer up, facing right
8B = mario with hammer down, facing right
8C = mario with hammer up, facing right
8D = mario with hammer down, facing right
8E = mario jumping right
8F = mario landing right
FA = mario dead with circle (halo?)
F8 = dying, right side up
F9 = dying, head on left
3rd sprite is the color
0 = red
1 = white
2 = blue
3,4,5,6 = cyan
7 = white
8 = orange
9, A = pink
B = light brown
C = blue
D = orange
E = blue
F = black
10 =
; #6980 - X position of a barrel and bouncers (all sprites??) , #6981 = sprite type? , 2= sprite color?, #6983 = Y position
; Add 4 to each barrel/sprite in question up to #6A08
; #69B8 start for pie sprites
; #6A0C - #6A0C + 12 - positions of the bonus extra items, umbrella, purse, etc.
; #6A1C - #6A1F = hammer sprite
; #6A20 - #6A23 heart sprite
; #6A24 - #6A27 sprite used for kong's aching head lines
; #6A29 - sprite for oilcan fire
; #7400-77ff - video ram
; #7700 = 1 up area Letter P
; #7701 = score 10's value
; #7702 = under the score 10's value
; #7708 = area where Kong is on girders
; #7721 = score 100's value
; #7741 = score 1000's value
; #7761 = score 10,000 value
; #7781 = score 100,000 value
; #7641 is the start of high score 100,000 place
; #7521 - the start of player 2 score (100,000's place)
; characters data
00 - 09 = 0 - 9
10 = empty
11 - 2A = A to Z
12 = B
13 = C
14 = D
15 = E
16 = F
17 = G
18 = H
19 = I
1A = J
1B = K
1C = L
1D = M
1E = N
1F = O
20 = P
21 = Q
22 = R
23 = S
24 = T
25 = U
26 = V
27 = W
28 = X
29 = Y
2A = Z
2B = .
2C = -
2D = high -
2E = :
2F = high -
30 = <
31 = >
32 = I
33 = II
34 = = (equals sign)
35 = -
36 , 37 = !! (two exlamations)
38 , 39= !
3A = '
3B, 3C = "
3D = " (skinny quote marks)
3E = L shape (right, bottom)
3F = L shape, (right, top)
40 = L shape
41 = L shape, (left, top)
42 = .
43 = ,
44 - 48 = some graphic (RUB END) ?
49, 4A = copyrigh logo
4B, 4C = some logo?
4D, - 4F = solid blocks of various colors
50 = 67 = kong graphics (retarded brother?)
6C - 6F = a graphic
70-79 = 0 - 9 (larger, used in score and tiemr)
80 - 89 = 0-9
8A = M
8B = m
8F-8C = some graphic
9F= Left half of trademark symbol
9E = right half of TM sybmol
B1 = Red square with Yellow lines top and bottom
B0 = Girder with hole in center used in rivets screen
B6 = white line on top
B7 = wierd icon?
B8 = red line on bottom
C0 - C7 = girder with ladder on bottom going up
D0 - D7 = ladder graphic with girder under going up and out
DD = HE (help graphic)
DE = EL
DF = P!
E1 - E7 = grider graphic going up and out
EC - E8 = blank ?
EF = P!
EE = EL (part of help graphic)
ED = HE (help graphic)
F6 - F0 = girder graphic in several vertical phases coming up from bottom
F7 = bottom yellow line
FA - F8 = blank ?
FB = ? (actually a question mark)
FC = right red edge
FD = left red edge
FE = X graphic
FF = Extra Mario Icon
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; game start power-on
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LD A,#00 ; A := 0
LD (REG_VBLANK_ENABLED),A ; disable interrupts
JP Init ; skip ahead
;
; RST #8
; if there are credits or the game is being played it returns immediately. if not, it returns to higher subroutine
;
0008 3A0760 LD A,(NoCredits) ; load A with 1 when no credits have been inserted, 0 if any credits exist or game is being played
000B 0F RRCA ; any credits in the game ?
000C D0 RET NC ; yes, return
000D 33 INC SP
000E 33 INC SP
000F C9 RET ; else return to higher subroutine
;
; RST #10
; if mario is alive, it returns. if mario is dead, it returns to the higher subroutine.
;
0010 3A0062 LD A,(#6200) ; 1 when mario is alive, 0 when dead
0013 0F RRCA ; is mario alive?
0014 D8 RET C ; yes, return
0015 33 INC SP ; no, increase SP by 2 and return
0016 33 INC SP
0017 C9 RET ; effectively returns twice
;
; RST #18
;
0018 210960 LD HL,WaitTimerMSB ; load timer that counts down
001B 35 DEC (HL) ; Count it down...
001C C8 RET Z ; Return if zero
001D 33 INC SP ; otherwise Increase SP twice
001E 33 INC SP
001F C9 RET ; and return - effectively returns to higher subroutine
;
; RST #20
;
0020 210860 LD HL,WaitTimerLSB ; load HL with timer
0023 35 DEC (HL) ; count it down
0024 28F2 JR Z,#0018 ; If zero skip up and count down the other timer
0026 E1 POP HL ; else move stack pointer up and return to higher subroutine
0027 C9 RET ; return
;
; RST #28
; jumps program to (2*A + Next program address)
; used in conjuction with a jump table after the call
;
0028 87 ADD A,A ; A := A * 2
0029 E1 POP HL ; load HL with address of jump table
002A 5F LD E,A ; load E with A
002B 1600 LD D,#00 ; D := 0
002D C33200 JP #0032 ; skip ahead
;
; RST #30
;
0030 1812 JR #0044 ; this core sub is actually at #0044
;
; continuation of RST #28 from #002D above
;
0032 19 ADD HL,DE ; HL is now 2A more than it was
0033 5E LD E,(HL) ; load E with low byte from the table
0034 23 INC HL ; next table entry
0035 56 LD D,(HL) ; load D with high byte from table
0036 EB EX DE,HL ; DE <> HL
0037 E9 JP (HL) ; jump to the address in HL