-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsonic.asm
More file actions
7342 lines (6261 loc) · 211 KB
/
Copy pathsonic.asm
File metadata and controls
7342 lines (6261 loc) · 211 KB
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
; =========================================================================
; | Sonic tMY NUTS ITCH isassembly for Sega Mega Drive |
; =========================================================================
;
; Disassembly created by xx_THEULTIMATEGAMER_xx235
; thanks to Bill Gates(the owner of fucking Microslop hes really bad), Clownancy(the) and Esrael Sonic Edtior Neato!
; ---------------------------------------------------------------------------
; NOTE:
; Set your editor's tab width to 8 characters wide for viewing this file or else you will be touched.
; ===========================================================================
; ASSEMBLY OPTIONS:
DickingAround = 0
; | If 0, loads SEGA screen first (for public release)
; | If 1, load Debug Menu first
EggblockOrigin = 0
; | If 0, play ads at 5 minute intervals or when grabbing the ad random monitor powerup
; | If 1, no ads play at all unless opened from debug menu
;!@ GD: Change runtime physics for DemoRecording
DemoRecord = 0
; | If 0, regular gameplay physics
; | If 1, disable Sonic CD terminal velocity/speed caps for Sonic
CheatsOn = 0
; | If 0, build it with no cheats active
; | If 1, build it with all cheats active
MSUEnabled = 0
M2Engage = 0 ;!@ GD: If set, then apply compatibility bugfixes and changes to make builds
;work properly on stock Sega Genesis 1/2 Mini emulator (M2Engage)
FixBugs = 1
; | If 1, enables various bugfixes across the game and sound driver
; | See also FixMusicAndSFXDataBugs
AllOptimizations = 1
; | If 1, enables all optimizations
SkipChecksumCheck = 0|AllOptimizations
; | If 1, disables the slow bootup checksum calculation
ZeroOffsetOptimization = 0|AllOptimizations
; | If 1, makes a handful of zero-offset instructions smaller
PaddingOptimization = 0|AllOptimizations
; | If 1, removes about 3 KB of various superfluous padding
EnableSRAM = 0
; | If 1, enable SRAM support
BackupSRAM = 0
; | 0 = no saving (read-only SRAM); 1 = allow saving
AddressSRAM = 3
; | 0 = odd+even; 2 = even only; 3 = odd only
; | (odd only is the most common)
ZoneCount: equ $0F ; Used for the zonewarning macro
; ===========================================================================
cpu 68000
message "Pass \{MOMPASS}"
include "MacroSetup.asm"
include "Macros.asm"
include "Constants.asm"
include "Variables.asm"
include "Debugger.asm"
SonicMappingsVer = 1
SonicDplcVer = 1
include "_maps/_MapMacros.asm"
; ===========================================================================
; start of ROM
!org 0
StartOfRom:
if * <> 0
fatal "StartOfRom was $\{*} but it should be 0"
endif
Vectors:
dc.l v_systemstack ; Initial stack pointer value
dc.l EntryPoint ; Start of program
dc.l BusError ; Bus error
dc.l AddressError ; Address error (4)
dc.l IllegalInstr ; Illegal instruction
dc.l ZeroDivide ; Division by zero
dc.l ChkInstr ; CHK exception
dc.l TrapvInstr ; TRAPV exception (8)
dc.l PrivilegeViol ; Privilege violation
dc.l Trace ; TRACE exception
dc.l Line1010Emu ; Line-A emulator
dc.l Line1111Emu ; Line-F emulator (12)
dc.l ErrorExcept ; Unused (reserved)
dc.l ErrorExcept ; Unused (reserved)
dc.l ErrorExcept ; Unused (reserved)
dc.l ErrorExcept ; Unused (reserved) (16)
dc.l ErrorExcept ; Unused (reserved)
dc.l ErrorExcept ; Unused (reserved)
dc.l ErrorExcept ; Unused (reserved)
dc.l ErrorExcept ; Unused (reserved) (20)
dc.l ErrorExcept ; Unused (reserved)
dc.l ErrorExcept ; Unused (reserved)
dc.l ErrorExcept ; Unused (reserved)
dc.l ErrorExcept ; Unused (reserved) (24)
dc.l ErrorExcept ; Spurious exception
dc.l ErrorTrap ; IRQ level 1
dc.l COP_SBlast ; IRQ level 2 (Copera soundblaster FM)
dc.l PCO_ADPCM ; IRQ level 3 (28)
dc.l v_hintcode ; IRQ level 4 (horizontal retrace interrupt)
dc.l v_hintcode ; IRQ level 5 (horizontal retrace interrupt/Pico). !@ GenesisDoes: This allows for Model 2 Sega Pico compatibility
dc.l v_vintcode ; IRQ level 6 (vertical retrace interrupt)
dc.l ErrorTrap ; IRQ level 7 (32)
dc.l ErrorTrap ; TRAP #00 exception
dc.l ErrorTrap ; TRAP #01 exception
dc.l ErrorTrap ; TRAP #02 exception
dc.l ErrorTrap ; TRAP #03 exception (36)
dc.l ErrorTrap ; TRAP #04 exception
dc.l ErrorTrap ; TRAP #05 exception
dc.l ErrorTrap ; TRAP #06 exception
dc.l ErrorTrap ; TRAP #07 exception (40)
dc.l ErrorTrap ; TRAP #08 exception
dc.l ErrorTrap ; TRAP #09 exception
dc.l ErrorTrap ; TRAP #10 exception
dc.l ErrorTrap ; TRAP #11 exception (44)
dc.l ErrorTrap ; TRAP #12 exception
dc.l ErrorTrap ; TRAP #13 exception
dc.l ErrorTrap ; TRAP #14 exception
dc.l ErrorTrap ; TRAP #15 exception (48)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
dc.l ErrorTrap ; Unused (reserved)
;!@ GD: Add S1Pico code to change header depending on platform being run on
dc.b hdr_Genesis ; Hardware system ID (Console name)
dc.b "SONICGM41 26.05" ; Copyright holder and release date (generally year)
dc.b "I WILL BANISH YOU TO THAT TOWN IN JOHTO " ; Domestic name
dc.b "GITHUB MADNESS IV: RETURN OF THE FEVERDREAM " ; International name
dc.b "GM 00042069-25" ; Serial/version number (Rev non-0)
Checksum:
dc.w 0
dc.b "J " ; I/O support
dc.l StartOfRom ; Start address of ROM
RomEndLoc: dc.l EndOfRom-1 ; End address of ROM
dc.l $FF0000 ; Start address of RAM
dc.l $FFFFFF ; End address of RAM
if EnableSRAM=1
dc.b "RA", $A0+(BackupSRAM<<6)+(AddressSRAM<<3), $20 ; SRAM support
dc.l $200001
dc.l $2003FF
else
dc.l $20202020
dc.l $20202020 ; SRAM start ($200001)
dc.l $20202020 ; SRAM end ($20xxxx)
endif
dc.b "HEY JIMMY, GIMME A ROM HEADER AREA FOR NOTHIN'. " ; Notes (unused, anything can be put in this space, but it has to be 52 bytes.)
dc.b "JUE " ; Region (Country code)
EndOfHeader:
binclude "misc/rom manual.txt"
even
; ===========================================================================
; Crash/Freeze the 68000. Unlike Sonic 2, Sonic 1 uses the 68000 for playing music, so it stops too
ErrorTrap:
nop
nop
bra.s ErrorTrap
; ===========================================================================
; these labels must never changed location or else the game switching won't work
EntryPoint:
disable_ints
; add.l crack.w, predominantly_projectfm_neighborhoods.w ; r/HemorrhoidHumpingHumor
tst.l (port_1_control_hi).l ; test port A & B control registers
bne.s PortA_Ok
tst.w (expansion_control_hi).l ; test port C control register
PortA_Ok: bne.s SkipSetup ; skip the VDP and Z80 setup code if this is a soft-reset
lea SetupValues(pc),a5 ; load setup values array address
movem.w (a5)+,d5-d7
movem.l (a5)+,a0-a4
move.b -$10FF(a1),d0 ; get hardware version (from $A10001)
andi.b #$F,d0
beq.s SkipSecurity ; If the console has no TMSS, skip the security stuff.
move.l #tmss_str,$2F00(a1) ; move \ to TMSS register ($A14000)
SkipSecurity:
move.w (a4),d0 ; clear write-pending flag in VDP to prevent issues if the 68k has been reset in the middle of writing a command long word to the VDP.
moveq #0,d0 ; clear d0
movea.l d0,a6 ; clear a6
move.l a6,usp ; set usp to $0
moveq #$17,d1
VDPInitLoop:
move.b (a5)+,d5 ; add $8000 to value
move.w d5,(a4) ; move value to VDP register
add.w d7,d5 ; next register
dbf d1,VDPInitLoop
move.l (a5)+,(a4)
move.w d0,(a3) ; clear the VRAM
move.w d7,(a1) ; stop the Z80
move.w d7,(a2) ; reset the Z80
WaitForZ80:
btst d0,(a1) ; has the Z80 stopped?
bne.s WaitForZ80 ; if not, branch
moveq #$25,d2
Z80InitLoop:
move.b (a5)+,(a0)+
dbf d2,Z80InitLoop
move.w d0,(a2)
move.w d0,(a1) ; start the Z80
move.w d7,(a2) ; reset the Z80
ClrRAMLoop:
move.l d0,-(a6) ; clear 4 bytes of RAM
dbf d6,ClrRAMLoop ; repeat until the entire RAM is clear
move.l (a5)+,(a4) ; set VDP display mode and increment mode
move.l (a5)+,(a4) ; set VDP to CRAM write
moveq #$1F,d3 ; set repeat times
ClrCRAMLoop:
move.l d0,(a3) ; clear 2 palettes
dbf d3,ClrCRAMLoop ; repeat until the entire CRAM is clear
move.l (a5)+,(a4) ; set VDP to VSRAM write
moveq #$13,d4
ClrVSRAMLoop:
move.l d0,(a3) ; clear 4 bytes of VSRAM.
dbf d4,ClrVSRAMLoop ; repeat until the entire VSRAM is clear
moveq #3,d5
PSGInitLoop:
move.b (a5)+,$11(a3) ; reset the PSG
dbf d5,PSGInitLoop ; repeat for other channels
move.w d0,(a2)
movem.l (a6),d0-a6 ; clear all registers
SkipSetup:
bra.s GameProgram ; begin game
; ===========================================================================
SetupValues: dc.w $8000 ; VDP register start number
dc.w $3FFF ; size of RAM/4
dc.w $100 ; VDP register diff
dc.l z80_ram ; start of Z80 RAM
dc.l z80_bus_request ; Z80 bus request
dc.l z80_reset ; Z80 reset
dc.l vdp_data_port ; VDP data
dc.l vdp_control_port ; VDP control
dc.b 4 ; VDP $80 - 8-colour mode
dc.b $14 ; VDP $81 - Megadrive mode, DMA enable
dc.b ($C000>>10) ; VDP $82 - foreground nametable address
dc.b ($F000>>10) ; VDP $83 - window nametable address
dc.b ($E000>>13) ; VDP $84 - background nametable address
dc.b ($D800>>9) ; VDP $85 - sprite table address
dc.b 0 ; VDP $86 - unused
dc.b 0 ; VDP $87 - background colour
dc.b 0 ; VDP $88 - unused
dc.b 0 ; VDP $89 - unused
dc.b 255 ; VDP $8A - HBlank register
dc.b 0 ; VDP $8B - full screen scroll
dc.b $81 ; VDP $8C - 40 cell display
dc.b ($DC00>>10) ; VDP $8D - hscroll table address
dc.b 0 ; VDP $8E - unused
dc.b 1 ; VDP $8F - VDP increment
dc.b 1 ; VDP $90 - 64 cell hscroll size
dc.b 0 ; VDP $91 - window h position
dc.b 0 ; VDP $92 - window v position
dc.w $FFFF ; VDP $93/94 - DMA length
dc.w 0 ; VDP $95/96 - DMA source
dc.b $80 ; VDP $97 - DMA fill VRAM
dc.l $40000080 ; VRAM address 0
Z80_SetupValues:
; Z80 instructions (not the sound driver; that gets loaded later)
save
CPU Z80 ; start assembling Z80 code
phase 0 ; pretend we're at address 0
xor a ; clear a to 0
ld bc,((z80_ram_end-z80_ram)-zStartupCodeEndLoc)-1 ; prepare to loop this many times
ld de,zStartupCodeEndLoc+1 ; initial destination address
ld hl,zStartupCodeEndLoc ; initial source address
ld sp,hl ; set the address the stack starts at
ld (hl),a ; set first byte of the stack to 0
ldir ; loop to fill the stack (entire remaining available Z80 RAM) with 0
pop ix ; clear ix
pop iy ; clear iy
ld i,a ; clear i
ld r,a ; clear r
pop de ; clear de
pop hl ; clear hl
pop af ; clear af
ex af,af' ; swap af with af'
exx ; swap bc/de/hl with their shadow registers too
pop bc ; clear bc
pop de ; clear de
pop hl ; clear hl
pop af ; clear af
ld sp,hl ; clear sp
di ; clear iff1 (for interrupt handler)
im 1 ; interrupt handling mode = 1
ld (hl),0E9h ; replace the first instruction with a jump to itself
jp (hl) ; jump to the first instruction (to stay there forever)
zStartupCodeEndLoc:
dephase ; stop pretending
restore
padding off ; unfortunately our flags got reset so we have to set them again...
dc.w $8104 ; VDP display mode
dc.w $8F02 ; VDP increment
dc.l $C0000000 ; CRAM write mode
dc.l $40000010 ; VSRAM address 0
dc.b $9F, $BF, $DF, $FF ; values for PSG channel volumes
; ===========================================================================
GameProgram:
if MSUEnabled
btst #5, (console_version)
bne.s .NoMCD
jsr (Init_MSU_Driver).l
move.b #1, (MegaCDMode).w
.NoMCD
else
move.b #0, (MegaCDMode).w
endif
tst.w (vdp_control_port).l
btst #6,(expansion_control).l
beq.s CheckSumCheck
cmpi.l #tmss_init,(v_init).w ; ye bruv has the checksum started innit?
beq.w GameInit ; if yes, fucking branch. HARD
CheckSumCheck:
if SkipChecksumCheck=0
movea.l #EndOfHeader,a0 ; start checking bytes after the header ($200)
movea.l #RomEndLoc,a1 ; stop at end of ROM
move.l (a1),d0
moveq #0,d1
.loop:
add.w (a0)+,d1
cmp.l a0,d0
bhs.s .loop
movea.l #Checksum,a1 ; read the CHECKSUM (cheese helper epic crate keep some user money)
cmp.w (a1),d1 ; compare checksum in header to ROM "random only memory" RAM "read access memory????!90238902"
bne.w CheckSumError ; if they don't match, branch
endif
;man im going nuts
CheckSumOk:
clearRAM v_crossresetram,v_ram_end
move.b (console_version).l,d0
andi.b #$C0,d0
move.b d0,(v_megadrive).w ; get region setting
move.l #'init',(v_init).w ; set flag so checksum won't run again
GameInit:
clearRAM v_ram_start_def,v_crossresetram
bra.w Get_CurGame ; This is where we branch to the different game
Init_GHM4:
;!@ GD: Only init DMA queue in normal build
if M2Engage=0
bsr.w InitDMAQueue
endif
bsr.w VDPSetupGame
bsr.w JoypadInit
jsr (Init_SoundDriver).l
if CheatsOn=1
move.w #$101,(f_levselcheat).w
move.w #$101,(f_debugcheat).w
endif
if DickingAround=1
move.b #id_DebugMenu,(v_gamemode).w ; set Game Mode to deubg menu Screen
else
move.b #id_Sega,(v_gamemode).w ; set Game Mode to Sega Screen
endif
MainGameLoop:
; ;!@GD: Fix VDP registers if mode changed
; temporarily removed this. it causes extreme visual tearing when in certain gamemodes because
; it's resetting registers during active scan
; add it to ClearScreen maybe, that's called on most gamemode inits
; moveq #0,d0
; moveq #1,d1
; jsr (Pow_vdp_fixRegs).l
move.b (v_gamemode).w,d0 ; load Game Mode
andi.w #$7C,d0 ; limit Game Mode value to $1C max (change to a maximum of 7C to add more game modes)
chk #GameModeArray_End-GameModeArray-4,d0 ; bounds check
move.l GameModeArray(pc,d0.w),a0
jsr (a0) ; jump to apt location in ROM
bra.s MainGameLoop ; loop indefinitely
; ---------------------------------------------------------------------------
; macro to define gamemodes and their ID
GAMEMODE macro addr, id
id = *
dc.l addr
endm
; ---------------------------------------------------------------------------
; Game Mode table
; ---------------------------------------------------------------------------
GameModeArray:
phase 0
GAMEMODE GM_Sega, id_Sega ; Sega Screen
GAMEMODE GM_Title, id_Title ; Title Screen
GAMEMODE GM_Level, id_Demo ; Demo Mode
GAMEMODE GM_Level, id_Level ; Normal Level
GAMEMODE GM_Special, id_Special ; Special Stage
GAMEMODE GM_Continue, id_Continue ; Continue Screen
GAMEMODE GM_Ending, id_Ending ; End of game sequence
GAMEMODE GM_ThanatosCredits, id_Thanatos ; Credits - Thanatos ver.
GAMEMODE TryAgainEnd, id_TryAgainEnd ; TRY AGAIN/END screen
GAMEMODE GM_ColdBrew, id_ColdBrew ; Cold Brew
GAMEMODE GM_FoxyBoo, id_FoxyBoo ; Jumpscare Test Mode
GAMEMODE GM_Options, id_Options ; Options select
GAMEMODE GM_Fetus, id_Fetus ; Difficulty Select
GAMEMODE GM_Damn, id_Damn ; DAMN!!!!!!!!!!!!!!!!!!!!!!!
GAMEMODE GM_Advert, id_Advert ; In-Game Advertisements
GAMEMODE GM_Cutscene, id_Cutscene ; Intro/Outro Cutscenes
GAMEMODE GM_SonicTheScreensaver, id_Screensaver ; GMZ - DVD Screensaver
GAMEMODE GM_ClintonScreens, id_ClintonScr ; Clinton fail/win
GAMEMODE GM_BSOD, id_BSOD ; !@ GD: Windows zone BSOD (on death)
GAMEMODE GM_Sans, id_SansDied ; he died.
GAMEMODE GM_DebugMenu, id_DebugMenu ; Debug Menu
dephase
GameModeArray_End:
; ===========================================================================
if SkipChecksumCheck=0
CheckSumError:
bsr.w VDPSetupGame
move.l #$C0000000,(vdp_control_port).l ; set VDP to CRAM write
moveq #($80)/2-1,d7
.fillred:
move.w #cRed,(vdp_data_port).l ; fill palette with red
dbf d7,.fillred ; repeat until CRAM is filled
.endlessloop:
bra.s .endlessloop
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Subroutine to get the current game and then jump to it
; ---------------------------------------------------------------------------
Get_CurGame:
moveq #0,d3
move.b (v_curgame).w,d3 ; Get the current game
cmp.b (v_lastgame).w,d3 ; Are we still on the same game?
beq.s .samegame ; If yes, don't clear cross-reset RAM
clearRAM v_crossresetram,v_gamechangeram ; We don't want to clear the last $18 bytes of RAM space
moveq #0,d0
move.w #$100,d7
lea Z80_SetupValues(pc),a5 ; load setup values array address
lea (z80_ram).l,a0
move.w d7,(z80_bus_request).l ; stop the Z80
move.w d7,(z80_reset).l ; reset the Z80
.WaitForZ80:
btst d0,(z80_bus_request).l ; has the Z80 stopped?
bne.s .WaitForZ80 ; if not, branch
moveq #$25,d2
.Z80InitLoop:
move.b (a5)+,(a0)+
dbf d2,.Z80InitLoop
move.w d0,(z80_reset).l
move.w d0,(z80_bus_request).l ; start the Z80
move.w d7,(z80_reset).l ; reset the Z80
.samegame:
move.w #opcode_jmpabslong,(v_vintcode.jmp).w ; Let's set these up first
move.w #opcode_jmpabslong,(v_hintcode.jmp).w
add.w d3,d3
moveq #0,d0
move.w .GameIndex(pc,d3.w),d0
jmp .GameIndex(pc,d0.w)
; ===========================================================================
.GameIndex:
dc.w .GHM4-.GameIndex ; 0
dc.w .TooLimited-.GameIndex ; 2
; ===========================================================================
.GHM4:
move.l #VBlank,(v_vintcode.addr).w ; Setup Vint for GHM4
move.w #opcode_rte,(v_hintcode.jmp).w ; Setup Hint for GHM4
move.b (v_curgame).w,(v_lastgame).w
jmp (Init_GHM4).l ; Boot up GHM4
; ===========================================================================
.TooLimited:
move.l #V_Int_2LS,(v_vintcode.addr).w ; Setup Vint for Too LimitedSonic
move.l #H_Int_2LS,(v_hintcode.addr).w ; Setup Hint for Too LimitedSonic
move.b (v_curgame).w,(v_lastgame).w
jmp (Init_TooLimited).l ; Boot up Too LimitedSonic
; ===========================================================================
Art_Text: binclude "artunc/menutext.bin" ; text used in level select and debug mode
Art_Text_End: even
;!@ Variant with (C) replaced with [at] symbol
Art_TextAT: binclude "artunc/menutextAT.bin" ; text used in level select and debug mode
Art_TextAT_End: even
; ===========================================================================
; ---------------------------------------------------------------------------
; Write VScroll buffer to VSRAM
; ---------------------------------------------------------------------------
VDPDATA = vdp_data_port ; i hate you
VDPCTRL = vdp_control_port
VScrollWrt:
lea VDPDATA,a4
move.w #$8B00+%0111,4(a4)
lea vscroll_buffer,a3
move.l #$40000010,(vdp_control_port).l
; meh
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
move.l (a3)+,(a4)
rts
; ===========================================================================
; ---------------------------------------------------------------------------
; Vertical interrupt
; ---------------------------------------------------------------------------
; loc_B10:
VBlank:
movem.l d0-a6,-(sp)
tst.b (v_vbla_routine).w
beq.w VBla_00
tst.b vscroll_mode
beq.s .normal
pea .dovbla(pc)
bra.w VScrollWrt
.normal:
move.w #$8B00+%0011,vdp_control_port
move.w (vdp_control_port).l,d0
move.l #$40000010,(vdp_control_port).l
move.l (v_scrposy_vdp).w,(vdp_data_port).l ; send screen y-axis pos. to VSRAM
.dovbla:
move.b (v_vbla_routine).w,d0
move.b #0,(v_vbla_routine).w
move.w #1,(f_hbla_pal).w
andi.w #$3E,d0
move.w VBla_Index(pc,d0.w),d0
jsr VBla_Index(pc,d0.w)
move.w (v_jpadhold1+2).w,d7
or.w d7,(v_jpadhold1).w
VBla_Music:
enable_ints
;!@ GD: f_hangSMPS flag. If set, then stop update music (hang sound driver)
tst.b (f_hangSMPS).w
bne.s .skip
jsr (UpdateMusic).l
.skip:
jsr (RandomNumber).l
addq.l #1,(v_vbla_count).w
movem.l (sp)+,d0-a6
rte
; ===========================================================================
VBla_Index: dc.w VBla_00-VBla_Index ; (lag frame)
dc.w VBla_02-VBla_Index ; Sega Screen
dc.w VBla_04-VBla_Index ; Title Screen, Credits
dc.w VBla_06-VBla_Index ; (unused)
dc.w VBla_08-VBla_Index ; Levels
dc.w VBla_0A-VBla_Index ; Special Stage
dc.w VBla_0C-VBla_Index ; Title Cards
dc.w VBla_0E-VBla_Index ; (unused)
dc.w VBla_10-VBla_Index ; Paused
dc.w VBla_12-VBla_Index ; Palette Fade
dc.w VBla_14-VBla_Index ; Sega Screen PCM
dc.w VBla_16-VBla_Index ; Continue Screen
dc.w VBla_18-VBla_Index ; Ending Sequence
dc.w VBla_1A-VBla_Index ; kys
dc.w VBla_1C-VBla_Index ; gfy
dc.w VBla_1E-VBla_Index ; fake credits
; ===========================================================================
VBla_1C:
jmp VBLANK_CUTSCENE
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 00 - Lag frame (VBlank occured before call to WaitForVBla)
; ---------------------------------------------------------------------------
; loc_B88:
VBla_00:
tst.b (v_waterflag).w
beq.w VBla_Music
move.w #1,(f_hbla_pal).w ; set HBlank flag
tst.b (f_wtr_state).w ; is water above top of screen?
bne.s .waterabove ; if yes, branch
writeCRAM v_palette,0
bra.s .waterbelow
.waterabove:
writeCRAM v_palette_water,0
.waterbelow:
move.w (v_hbla_hreg).w,(a5)
bra.w VBla_Music
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 02 - Sega Screen
; ---------------------------------------------------------------------------
; loc_C32:
VBla_02:
bsr.w VBla_StandardTransfers
; fall-through
; ---------------------------------------------------------------------------
; VBlank 14 - Sega Screen while the PCM sample is playing
; ---------------------------------------------------------------------------
VBla_14:
tst.w (v_generictimer).w
beq.w .end
subq.w #1,(v_generictimer).w
.end:
rts
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 04 - Title Screen, Level Select, Credits, "Try Again" screen
; ---------------------------------------------------------------------------
VBla_04:
bsr.w VBla_StandardTransfers
jsr LoadTilesAsYouMove_BGOnly
tst.b (v_flashtimer).w
beq.s .noflash
subq.b #1, (v_flashtimer).w
lea (vdp_data_port).l, a6
move.l #$C0000000, ($C00004).l ; CRAM write mode
move.w #$E,d0
move.w #$1F,d1
.fillpalette:
move.w d0, (a6)
dbf d1, .fillpalette
move.w #0, (a6)
move.w #$1E, d1
.fillpalette2:
move.w d0, (a6)
dbf d1, .fillpalette2
.noflash:
bsr.w ProcessDPLC_9Tiles
tst.w (v_generictimer).w
beq.w .end
subq.w #1,(v_generictimer).w
.end:
rts
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 06 - Unused
; ---------------------------------------------------------------------------
; loc_C5E:
VBla_06:
;!@ M2Engage compat; only run DMAQueue in regular build
if M2Engage=0
jsr ProcessDMAQueue(pc)
endif
bsr.w VBla_StandardTransfers
bra.w ProcessDPLC_9Tiles
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 10 - While game is paused
; ---------------------------------------------------------------------------
; loc_C64:
VBla_10:
cmpi.b #id_Special,(v_gamemode).w ; is game on special stage?
beq.w VBla_02 ; if yes, branch
; fall-through...
; ---------------------------------------------------------------------------
; VBlank 08 - Levels
; ---------------------------------------------------------------------------
; loc_C6E:
VBla_08:
bsr.w ReadJoypads
writeVRAM v_hscrolltablebuffer,vram_hscroll
writeVRAM v_spritetablebuffer,vram_sprites
move.w (v_hbla_hreg).w,(a5)
tst.b (f_wtr_state).w
bne.s .waterabove
writeCRAM v_palette,0
bra.s .waterbelow
.waterabove:
writeCRAM v_palette_water,0
.waterbelow:
;!@ GD: M2Engage compat
;If regular build, then use DMA queue; else regular S1 DPLCs
if M2Engage=0
jsr ProcessDMAQueue(pc)
else
jsr LoadDynPLC_Std(pc)
endif
.nochg:
tst.w (v_generictimer).w ; is there time left in the generic timer left?
beq.w .end ; if not, branch
subq.w #1,(v_generictimer).w ; subtract 1 from time left
.end:
movem.l (v_screenposx).w,d0-d7
movem.l d0-d7,(v_screenposx_dup).w
movem.l (v_fg_scroll_flags).w,d0-d1
movem.l d0-d1,(v_fg_scroll_flags_dup).w
; The following code handles an awkward visual glitch for the LZ water surface.
; If the surface is near the top of the screen (within 96 pixels), the VDP would not have
; enough time to do all the transfers in VBla_UpdateScreen before the palette needs to get
; changed for the water. Without this special check, the water surface would violently flicker
; whenever it's near the top of the screen. It's a rather dirty workaround, but it works.
tst.b (v_waterflag).w
beq.s VBla_UpdateScreen
cmpi.b #96,(v_hbla_line).w ; is LZ water surface within 96 pixels of the top of the screen?
bhs.s VBla_UpdateScreen ; if not, do screen updates now
move.b #1,(f_doupdatesinhblank).w ; otherwise, we don't have enough time to do them now before HBlank hits, defer updates to then
rts
; ===========================================================================
; ---------------------------------------------------------------------------
; Subroutine to update various screen elements during interrupts.
; Also deducts the generic timer that controls the length of a Demo.
; ---------------------------------------------------------------------------
; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
; Demo_Time:
VBla_UpdateScreen:
jsr (LoadTilesAsYouMove).l ; update level tiles while screen is moving
jsr (AnimateLevelGfx).l ; updated animated tiles
jsr (HUD_Update).l ; update HUD data
bra.w ProcessDPLC_3Tiles ; run a bit of PLC decompression
; End of function VBla_UpdateScreen
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 0A - Special Stages
; ---------------------------------------------------------------------------
VBla_0A:
bsr.w ReadJoypads
writeVRAM v_spritetablebuffer,vram_sprites
writeVRAM v_hscrolltablebuffer,vram_hscroll
writeCRAM v_palette,0
;!@ GD: M2Engage compat
;If regular build, then use DMA queue; else regular S1 DPLCs
if M2Engage=0
jsr ProcessDMAQueue(pc)
else
jsr LoadDynPLC_Std(pc)
endif
tst.w (v_generictimer).w ; is there time left on the demo?
beq.w .end ; if not, return
subq.w #1,(v_generictimer).w ; subtract 1 from time left in demo
.end:
rts
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 0C & 18 - While title cards are displayed (Levels and SS Results)
; ---------------------------------------------------------------------------
VBla_0C:
VBla_18:
bsr.w ReadJoypads
writeVRAM v_hscrolltablebuffer,vram_hscroll
writeVRAM v_spritetablebuffer,vram_sprites
move.w (v_hbla_hreg).w,(a5)
tst.b (f_wtr_state).w
bne.s .waterabove
writeCRAM v_palette,0
bra.s .waterbelow
.waterabove:
writeCRAM v_palette_water,0
.waterbelow:
;!@ GD: M2Engage compat
;If regular build, then use DMA queue; else regular S1 DPLCs
if M2Engage=0
jsr ProcessDMAQueue(pc)
else
jsr LoadDynPLC_Std(pc)
endif
movem.l (v_screenposx).w,d0-d7
movem.l d0-d7,(v_screenposx_dup).w
movem.l (v_fg_scroll_flags).w,d0-d1
movem.l d0-d1,(v_fg_scroll_flags_dup).w
jsr (LoadTilesAsYouMove).l
jsr (AnimateLevelGfx).l
jsr (HUD_Update).l
bra.w ProcessDPLC_9Tiles
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 0E - Unused
; ---------------------------------------------------------------------------
VBla_0E:
bsr.w VBla_StandardTransfers
addq.b #1,(v_vbla_0e_counter).w ; Unused besides this one write...
move.b #$E,(v_vbla_routine).w
rts
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 12 - During palette fades
; ---------------------------------------------------------------------------
VBla_12:
bsr.w VBla_StandardTransfers
move.w (v_hbla_hreg).w,(a5)
bra.w ProcessDPLC_9Tiles
; ===========================================================================
; ---------------------------------------------------------------------------
; VBlank 16 - Continue Screen and Special Stage finish loop
; ---------------------------------------------------------------------------
VBla_16:
bsr.w ReadJoypads
writeVRAM v_spritetablebuffer,vram_sprites
writeVRAM v_hscrolltablebuffer,vram_hscroll
writeCRAM v_palette,0
;!@ GD: M2Engage compat
;If regular build, then use DMA queue; else regular S1 DPLCs
if M2Engage=0
jsr ProcessDMAQueue(pc)
else
jsr LoadDynPLC_Std(pc)
endif
tst.w (v_generictimer).w
beq.w .end
subq.w #1,(v_generictimer).w
.end:
rts
; ===========================================================================
; ---------------------------------------------------------------------------
; Subroutine to perform standard VRAM transfers (palette, sprites, H-scroll)
; ---------------------------------------------------------------------------
; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
; sub_106E:
VBla_StandardTransfers:
bsr.w ReadJoypads
writeVRAM v_spritetablebuffer,vram_sprites
writeVRAM v_hscrolltablebuffer,vram_hscroll
tst.b (f_wtr_state).w ; is the screen completely underwater?
bne.s .underwater ; if yes, branch
writeCRAM v_palette,0 ; write full regular palette buffer to CRAM
rts
.underwater:
writeCRAM v_palette_water,0 ; write full water palette buffer to CRAM
rts
; End of function VBla_StandardTransfers
; ===========================================================================
; ---------------------------------------------------------------------------
; FUCKING EXIT THE LEVEL PROPERLY FROM CLINTON FUCKER I GUESS
; ---------------------------------------------------------------------------
VBla_1A:
stopZ80
waitZ80
;!@ GD: M2Engage compat
;If regular build, then use DMA queue; else regular S1 DPLCs
if M2Engage=0
jsr ProcessDMAQueue(pc)
else
jsr LoadDynPLC_Std(pc)
endif
bsr.w VBla_StandardTransfers
startZ80
tst.w (v_generictimer).w
beq.w .end
subq.w #1,(v_generictimer).w
.end:
bra.w ProcessDPLC_9Tiles
; ===========================================================================
; ---------------------------------------------------------------------------
; the fake credits it just calls SMPS too much
; ---------------------------------------------------------------------------
VBla_1E:
bsr.w VBla_StandardTransfers
jsr (UpdateMusic).l ; this is gonna be fucked
jsr (UpdateMusic).l
jsr (UpdateMusic).l
rts
;!@ GenesisDoes: Dummy int/func for Copera Soundblaster FM
; ===========================================================================
; ---------------------------------------------------------------------------
; Yamaha Copera Soundblaster FM. Dummy stub
; ---------------------------------------------------------------------------
COP_SBlast:
rte
; ---------------------------------------------------------------------------
;!@ GenesisDoes: Dummy int/func for Pico ADPCM
; ===========================================================================
; ---------------------------------------------------------------------------
; Sega Pico ADPCM interrupt. Dummy stub
; ---------------------------------------------------------------------------
PCO_ADPCM:
rte
; ---------------------------------------------------------------------------
; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
; ===========================================================================
; ---------------------------------------------------------------------------
; Horizontal interrupt (exclusively used for the LZ water palette effect)
; ---------------------------------------------------------------------------
; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
HBlank:
disable_ints
tst.w (f_hbla_pal).w ; is palette set to change?
beq.s .nochg ; if not, branch
move.w #0,(f_hbla_pal).w ; clear palette change flag
movem.l a0-a1,-(sp)
lea (vdp_data_port).l,a1
lea (v_palette_water).w,a0 ; get water palette from RAM
move.l #$C0000000,4(a1) ; set VDP to CRAM write
rept (4*$10)/2 ; overwrite full palette (4 rows, 2 colors per move)