-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch.asm
105 lines (91 loc) · 2.46 KB
/
patch.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
; Constants: ---------------------------------------------------------------------------------
MD_PLUS_OVERLAY_PORT: equ $0003F7FA
MD_PLUS_CMD_PORT: equ $0003F7FE
REGISTER_BACKUP: equ $FFFFFF80
; Overrides: ---------------------------------------------------------------------------------
org $2608
jmp PLAY_DETOUR
nop
nop
RETURN_FROM_PLAY_DETOUR
org $261A
jmp STOP_DETOUR
nop
nop
RETURN_FROM_STOP_DETOUR
org $1E4944
jmp PAUSE_DETOUR
nop
nop
RETURN_FROM_PAUSE_DETOUR
org $1E499C
jmp RESUME_DETOUR
nop
nop
RETURN_FROM_RESUME_DETOUR
; Detours: ------------------------------------------------------------------------------------
org $1FD200
PAUSE_DETOUR
movem D1,(REGISTER_BACKUP)
move.w #$1300,D1
jsr WRITE_MD_PLUS_FUNCTION
movem (REGISTER_BACKUP),D1
st $FFFFBFD6 ; Original game code
jsr $0001CB632
jmp RETURN_FROM_PAUSE_DETOUR
RESUME_DETOUR
movem D1,(REGISTER_BACKUP)
move.w #$1400,D1
jsr WRITE_MD_PLUS_FUNCTION
movem (REGISTER_BACKUP),D1
sf $FFFFBFD6 ; Original game code
jsr $0001CB632
jmp RETURN_FROM_RESUME_DETOUR
STOP_DETOUR
cmpi.l #$FFFFFFFF,D0
bne DONT_STOP_MUSIC
movem D1,(REGISTER_BACKUP)
move.w #$1300,D1
bsr WRITE_MD_PLUS_FUNCTION
movem (REGISTER_BACKUP),D1
DONT_STOP_MUSIC
movem.l D0/A0,-(A7) ; Original game code
jsr $0001CB622
jmp RETURN_FROM_STOP_DETOUR
PLAY_DETOUR
cmpi.b #$22,D0
bhi NOT_MUSIC ; Branch if higher than $22
movem D1-D2,(REGISTER_BACKUP)
move.w #$1200,D1
move.b D0,D1
addi.b #$1,D1
move.b #$0,D2
cmpi.b #$D,D0 ; Beginning from #$D, there is a set of 3 empty track ids
bcs DO_NOT_DECREMENT_FURTHER
addi.b #$3,D2
cmpi.b #$13,D0
bcs DO_NOT_DECREMENT_FURTHER ; On #$13, there is one empty track id
addi.b #$1,D2
cmpi.b #$15,D0
bcs DO_NOT_DECREMENT_FURTHER ; On #$15, there is one empty track id
addi.b #$1,D2
cmpi.b #$19,D0
bcs DO_NOT_DECREMENT_FURTHER ; On #$19, there is one empty track id
addi.b #$1,D2
cmpi #$1D,D0
bcs DO_NOT_DECREMENT_FURTHER ; Beginning from #$1D, there is a set of 3 empty track ids
addi.b #$3,D2
DO_NOT_DECREMENT_FURTHER
sub.b D2,D1 ; Subtract D2 from D1 to get rid of holes in the track index sequence
bsr WRITE_MD_PLUS_FUNCTION
movem (REGISTER_BACKUP),D1-D2
rts
NOT_MUSIC
movem.l D0/A0/A6,-(A7) ; Original game code
jsr $0001CB60C
jmp RETURN_FROM_PLAY_DETOUR
WRITE_MD_PLUS_FUNCTION:
move.w #$CD54,(MD_PLUS_OVERLAY_PORT) ; Open interface
move.w D1,(MD_PLUS_CMD_PORT) ; Send command to interface
move.w #$0000,(MD_PLUS_OVERLAY_PORT) ; Close interface
rts