forked from KatDevsGames/z3randomizer
-
Notifications
You must be signed in to change notification settings - Fork 6
/
RandSprite.asm
171 lines (143 loc) · 3.27 KB
/
RandSprite.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
;================================================================================
macro ChangeSpriteOnEvent(event)
PHA : PHY : PHX
LDA DisableRandomSpriteOnEvent : BNE .endChangeSpriteOnEvent
PHP : REP #$30
LDA RandomSpriteOnEvent : AND <event> : BEQ .no_change
PLP
JSR change_sprite
BRA .endChangeSpriteOnEvent ;Burn the 3 cycles for previous branch not taken
.no_change
NOP ;Burn the 2 cycles for previous branch already taken.
PLP
JSR dont_change_sprite
.endChangeSpriteOnEvent
PLX : PLY : PLA
endmacro
OnInitFileSelectRandSprite:
{
LDA DisableRandomSpriteOnEvent : BNE .continue
LDA #$E0 : STA $BC ; Set default sprite.
%ChangeSpriteOnEvent(RandomSpriteOnEvent)
.continue
JSL OnInitFileSelect
RTL
}
Palette_ArmorAndGlovesRandSprite:
{
;DEDF9
LDA DisableRandomSpriteOnEvent : BEQ .continue
LDA.b #$10 : STA $BC ; Load Original Sprite Location
REP #$21
LDA $7EF35B
JSL $1BEDFF;Read Original Palette Code
RTL
.part_two
SEP #$30
LDA DisableRandomSpriteOnEvent : BEQ .continue
REP #$30
LDA $7EF354
JSL $1BEE21;Read Original Palette Code
RTL
.continue
PHX : PHY : PHA
; Load armor palette
PHB : PHK : PLB
REP #$20
; Check what Link's armor value is.
LDA $7EF35B : AND.w #$00FF : TAX
; (DEC06, X)
LDA $1BEC06, X : AND.w #$00FF : ASL A : ADC.w #$F000 : STA $00
;replace D308 by 7000 and search
REP #$10
LDA.w #$01E2 ; Target SP-7 (sprite palette 6)
LDX.w #$000E ; Palette has 15 colors
TXY : TAX
;LDA $7EC178 : AND #$00FF : STA $02
LDA.b $BC : AND #$00FF : STA $02
.loop
LDA [$00] : STA $7EC300, X : STA $7EC500, X
INC $00 : INC $00
INX #2
DEY : BPL .loop
SEP #$30
PLB
INC $15
PLA : PLY : PLX
RTL
}
change_sprite:
{
JSL GetRandomInt : AND #$1F : !ADD #$E0 : STA $BC
STA $7EC178
JSL Palette_ArmorAndGlovesRandSprite
STZ $0710
RTS
}
dont_change_sprite:
{
JSL GetRandomInt : AND #$1F : !ADD #$E0 : LDA $BC
STA $7EC178
JSL Palette_ArmorAndGlovesRandSprite
STZ $0710
RTS
}
change_sprite_damage:
{
%ChangeSpriteOnEvent(#$0001)
LDA $0E20, X : CMP.b #$61 ; Restored Code Bank06.asm(5967) ; LDA $0E20, X : CMP.b #$61 : BNE .not_beamos_laser
RTL
}
change_sprite_enter:
{
%ChangeSpriteOnEvent(#$0002)
LDA.b #$01 : STA $1B
RTL
}
change_sprite_exit:
{
%ChangeSpriteOnEvent(#$0004)
STZ $1B : STZ $0458
RTL
}
change_sprite_slash:
{
%ChangeSpriteOnEvent(#$0008)
JSL $0DBB67
RTL
}
change_sprite_item:
{
%ChangeSpriteOnEvent(#$0010)
JSL AddReceivedItemExpandedGetItem
RTL
}
change_sprite_bonk:
{
%ChangeSpriteOnEvent(#$0020)
JSL StatBonkCounter
RTL
}
EndOfRandSprite:
macro copysprite()
!spritescopied #= 0
!spritesoffset #= $E08000
while !spritescopied < 32
org !spritesoffset
!copycount #= 0
while !copycount+3 < $7000
dd read4(pctosnes($80000+!copycount))
!copycount #= !copycount+4
endif
!copycount #= 0
while !copycount+3 < $78
dd read4(pctosnes($DD308+!copycount))
!copycount #= !copycount+4
endif
dd read4(pctosnes($DEDF5))
!spritescopied #= !spritescopied+1
!spritesoffset #= !spritesoffset+$10000
endif
endmacro
%copysprite()
org EndOfRandSprite