-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlowingPalette.asm
215 lines (154 loc) · 5.6 KB
/
GlowingPalette.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
; ==============================================================================
pushpc
; Hook for glowing palettes here
org $01CC08 ; Replace hole(3) and hole(4) tag DO NOT USE hole(4) use hole(3)
LDA.l $7EC1A1 : DEC : STA.l $7EC1A1 : BPL .wait
LDA #$06 : STA.l $7EC1A1
LDA.l $7EC1A0 : BNE .DoPalMax
JSL GlowingPaletteMax
RTS
.DoPalMax
JSL GlowingPaletteMin
.wait
RTS
pullpc
; ==============================================================================
GlowingPaletteMax:
{
; for each colors in palette
REP #$30
LDX #$0008 ; Numbers of colors in the palette
LDY #$0004 ; C0 / 2
; Load the current color check if value match the target we're trying to reach either PalMin or PalMax
.LoopAllColors
LDA.l $7EC5E8, X : BEQ .colorAlreadyAtGoalDEY ; Color is $0000 no need to change
CMP.l PalMax, X : BEQ .colorAlreadyAtGoalDEY
STA.b $00
AND.w #$001F : STA.b $02
LDA.b $00 : AND.w #$03E0 : STA $04
LDA.b $00 : AND.w #$7C00 : STA $06
LDA.l PalMax, X : STA $08
AND.w #$001F : CMP $02 : BEQ .RedIsSame ; Is RED the same as goal?
BCC .GoalRedIsLowerThanCurrent
; Red is lower than goal here so INC here
INC $02
BRA .RedIsSame
.GoalRedIsLowerThanCurrent
; Red is higher than goal here so DEC here
DEC $02
.RedIsSame
LDA.b $08
AND.w #$03E0 : CMP $04 : BEQ .GreenIsSame
BCC .GoalGreenIsLowerThanCurrent
; Green is lower than goal here so INC here
LDA.b $04 : CLC : ADC.w #$0020 : STA $04
BRA .GreenIsSame
.GoalGreenIsLowerThanCurrent
; Green is higher than goal here so DEC here
LDA.b $04 : SEC : SBC.w #$0020 : STA $04
.GreenIsSame
LDA.b $08 : AND.w #$7C00 : CMP $06 : BEQ .BlueIsSame
BCC .GoalBlueIsLowerThanCurrent
; Blue is lower than goal here so INC here
LDA.b $06 : CLC : ADC.w #$0400 : STA $06
BRA .BlueIsSame
.GoalBlueIsLowerThanCurrent
; Blue is higher than goal here so DEC here
LDA.b $06 : SEC : SBC.w #$0400 : STA $06
.BlueIsSame
BRA .endcolors
.colorAlreadyAtGoal
DEX : DEX
BPL .LoopAllColors
INC.b $15
SEP #$30
RTL
.colorAlreadyAtGoalDEY
DEY : CPY #$0001 : BCC .reverseColor
BRA .colorAlreadyAtGoal
.reverseColor
SEP #$30
LDA.l $7EC1A0 : EOR.b #$01 : STA.l $7EC1A0
RTL
; $00 = Current color (faster to load from DP)
; $02 = R
; $04 = G
; $06 = B
; $08 = goal color
.endcolors
LDA.w #$0000 : ORA.b $02 : ORA.b $04 : ORA.b $06
STA.l $7EC5E8, X
BRA .colorAlreadyAtGoal
}
GlowingPaletteMin:
{
; for each colors in palette
REP #$30
LDX #$0008 ; Numbers of colors in the palette
LDY #$0004 ; C0 / 2
; Load the current color check if value match the target we're trying to reach either PalMin or PalMax
.LoopAllColors
LDA.l $7EC5E8, X : BEQ .colorAlreadyAtGoalDEY ; Color is $0000 no need to change
CMP.l PalMin, X : BEQ .colorAlreadyAtGoalDEY
STA.b $00
AND.w #$001F : STA.b $02
LDA.b $00 : AND.w #$03E0 : STA $04
LDA.b $00 : AND.w #$7C00 : STA $06
LDA.l PalMin, X : STA $08
AND.w #$001F : CMP $02 : BEQ .RedIsSame ; Is RED the same as goal?
BCC .GoalRedIsLowerThanCurrent
; Red is lower than goal here so INC here
INC $02
BRA .RedIsSame
.GoalRedIsLowerThanCurrent
; Red is higher than goal here so DEC here
DEC $02
.RedIsSame
LDA.b $08 : AND.w #$03E0 : CMP $04 : BEQ .GreenIsSame
BCC .GoalGreenIsLowerThanCurrent
; Green is lower than goal here so INC here
LDA.b $04 : CLC : ADC.w #$0020 : STA $04
BRA .GreenIsSame
.GoalGreenIsLowerThanCurrent
; Green is higher than goal here so DEC here
LDA.b $04 : SEC : SBC.w #$0020 : STA $04
.GreenIsSame
LDA.b $08
AND.w #$7C00 : CMP $06 : BEQ .BlueIsSame
BCC .GoalBlueIsLowerThanCurrent
; Blue is lower than goal here so INC here
LDA.b $06 : CLC : ADC.w #$0400 : STA $06
BRA .BlueIsSame
.GoalBlueIsLowerThanCurrent
; Blue is higher than goal here so DEC here
LDA.b $06 : SEC : SBC.w #$0400 : STA $06
.BlueIsSame
BRA .endcolors
.colorAlreadyAtGoal
DEX : DEX
BPL .LoopAllColors
INC.b $15
SEP #$30
RTL
.colorAlreadyAtGoalDEY
DEY : CPY #$0001 : BCC .reverseColor
BRA .colorAlreadyAtGoal
.reverseColor
SEP #$30
LDA.l $7EC1A0 : EOR.b #$01 : STA.l $7EC1A0
RTL
; $00 = Current color (faster to load from DP)
; $02 = R
; $04 = G
; $06 = B
; $08 = goal color
.endcolors
LDA.w #$0000 : ORA.b $02 : ORA.b $04 : ORA.b $06
STA.l $7EC5E8, X
BRA .colorAlreadyAtGoal
}
PalMin:
dw $0060, $0900, $0980, $0E27
PalMax:
dw $0100, $2220, $26E0, $0663
; ==============================================================================