-
Notifications
You must be signed in to change notification settings - Fork 0
/
on_off_p-switch.asm
158 lines (117 loc) · 3.04 KB
/
on_off_p-switch.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
; ; ; ; ; ; ; ; ; ; ; ;
;
; (INCOMPLETE)
;
; Sets ON when hit, OFF when hit if EXTRA BIT is set
;
; Insert as a sprite
; Must be assembled with xkas (romi's SpriteTool, not mikeyk's)
;
; ; ; ; ; ; ; ; ; ; ; ;
!GET_DRAW_INFO = $168008 ; Point to GET_DRAW_INFO patch + 8 (hex)
!GFXTILE = $C2 ; Top left 8x8 of 16x16 tile
!GFXTILEb = $88 ; Tile when Extra Bit is set
!YXPPCCCT = #%00011000 ; YXPPCCCT of sprite, 0 is clear, 1 is set
;YXPPCCCT
;Set Y to Y-flip
;Set X to X-flip
;PP is layer priority
;00 - Lowest
;01 - Low
;10 - High
;11 - Highest
;CCC is palette
;000 = Palette 8
;001 = Palette 9
;010 = Palette A
;011 = Palette B
;100 = Palette C
;101 = Palette D
;110 = Palette E
;111 = Palette F
;Set T to use 2nd GFX Page (SP3/SP4)
!YXPPCCCTb = #%00010110 ; YXPPCCCT when Extra Bit is set
;YXPPCCCT
print "INIT ",pc
RTL
print "MAIN ",pc
PHB ; \
PHK ; | Change data bank to current
PLB ; |
JSL SpriteRoutine ; |
PLB ; | Restore
RTL ; /
; ; ; ; ; ; ; ; ;
;
; SpriteRoutine
;
; ; ; ; ; ; ; ; ;
SpriteRoutine:
JSL GraphicsRoutine
JSL $01A7DC ; \ Check if
BCC NoContact ; / touching sprite
LDA $0E
CMP #$F8
BCC Go_on
; Code run when hit from below
BRA SidesBottom
Go_on:
; Code run when hit from sides or above
CMP #$E6
BPL SidesBottom
; Code run when hit from above
LDA #$0B ; \ Play
STA $1DF9 ; / sound
LDA $7FAB10,x ; \
AND #$04 ; | Check if Extra Bit is set
BNE ExtraBit ; /
STZ $14AF ; Set ON
BRA Continue
ExtraBit:
INC $14AF ; Set OFF
Continue:
; TODO: Destroy P-switch
BRA Return
SidesBottom:
; Code run when hit from sides or below
; TODO: Make carryable
JSL $01B44F ; Act solid
NoContact:
Return:
RTL
; ; ; ; ; ; ; ; ;
;
; GraphicsRoutine
;
; ; ; ; ; ; ; ; ;
GraphicsRoutine:
JSL !GET_DRAW_INFO
; The X position of the sprite is now in $00.
; The Y position of the sprite is now in $01.
; The index to the OAM is now in Y
; The X position of the sprite OAM is at $0300.
; The Y position of the sprite OAM is at $0301.
LDA $00 ; \ Store X Position to X Position of Sprite OAM
STA $0300,y ; / Indexed by Y, so it's only for this sprite
LDA $01 ; \ Store Y Position to Y Position of Sprite OAM
STA $0301,y ; / Indexed by Y
LDA $7FAB10,x ; \
AND #$04 ; | Check if Extra Bit is set
BNE ExtraBitSet ; /
LDA #!GFXTILE ; \ Store GFX tile to OAM
STA $0302,y ; / Indexed by Y
LDA.b !YXPPCCCT ; \
ORA $64 ; | Set YXPPCCCT
STA $0303,y ; /
BRA Go
ExtraBitSet:
LDA #!GFXTILEb ; \ Store GFX tile to OAM
STA $0302,y ; / Indexed by Y
LDA.b !YXPPCCCTb ; \
ORA $64 ; | Set YXPPCCCT for when Extra Bit is set
STA $0303,y ; /
Go:
LDY #$02 ; 02 because it's 16x16.
LDA #$00 ; Tiles written - 1 (1-1=0)
JSL $01B7B3 ; Run OAM Routine to write tiles
RTL