-
Notifications
You must be signed in to change notification settings - Fork 28
/
shield.asm
167 lines (148 loc) · 4.36 KB
/
shield.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
; Troy's HBC-56 - 6502 - Invaders - Shields
;
; Copyright (c) 2021 Troy Schrapel
;
; This code is licensed under the MIT license
;
; https://github.com/visrealm/hbc-56
;
;
COLOR_SHIELD = TMS_WHITE << 4 | TMS_BLACK
shieldLayout:
!byte 8,9,10,0,0,0,14,15,16,0,0,0,0,20,21,22,0,0,0,26,27,28
!fill 10, 0
!byte 11,12,13,0,0,0,17,18,19,0,0,0,0,23,24,25,0,0,0,29,30,31
SHIELD_BYTES = * - shieldLayout
; -----------------------------------------------------------------------------
; Setup the shields
; -----------------------------------------------------------------------------
setupShield:
+tmsSetAddrPattTable 8
+tmsSendData SHIELD, 8 * 6 ; Shield1 8 - 13
+tmsSendData SHIELD, 8 * 6 ; Shield2 14 - 18
+tmsSendData SHIELD, 8 * 6 ; Shield3 20 - 25
+tmsSendData SHIELD, 8 * 6 ; Shield4 26 - 31
+tmsSetPosWrite 5, 17
+tmsSendData shieldLayout, SHIELD_BYTES
rts
; -----------------------------------------------------------------------------
; testShieldBombed: Shield bombed by alien
; -----------------------------------------------------------------------------
; Inputs:
; A: Shield pattern index
; HIT_TILE_X / HIT_TILE_Y shield tile location
; HIT_TILE_PIX_X / HIT_TILE_PIX_Y pixel offset (hit location in tile)
; Outputs:
; Carry: Set if hit, clear if no hit
; -----------------------------------------------------------------------------
testShieldBombed:
ldy HIT_TILE_PIX_Y
jsr tmsSetPatternRead
; load the pattern row that was hit
+tmsGet
jsr patternHitTest
beq .noBomb
jsr clearShieldBombedPixels
; kill the bomb
ldy #BULLET_Y_LOADED
sty INVADER_BOMB1_Y
sec
rts
.noBomb
clc
rts
; -----------------------------------------------------------------------------
; testShieldPlayerBullet: Test shield hit by player bullet
; -----------------------------------------------------------------------------
; Inputs:
; A: Shield pattern index
; HIT_TILE_X / HIT_TILE_Y shield tile location
; HIT_TILE_PIX_X / HIT_TILE_PIX_Y pixel offset (hit location in tile)
; Outputs:
; Carry: Set if hit, clear if no hit
; -----------------------------------------------------------------------------
testShieldPlayerBullet:
ldy HIT_TILE_PIX_Y
jsr tmsSetPatternRead
; load the pattern row that was hit
+tmsGet
jsr patternHitTest
beq .noHit
jsr clearShieldPlayerBulletPixels
; kill the bullet
ldy #0
sty BULLET_Y
sec
rts
.noHit
clc
rts
; -----------------------------------------------------------------------------
; clearShieldPlayerBulletPixels: Clear pixels in the following shape: X = HIT_TILE_PIX
; -----------------------------------------------------------------------------
;
; O
; OO
; OX
; O
;
clearShieldPlayerBulletPixels:
jsr tileClearPixel ; X
jsr incTileHitY
jsr tileClearPixel
jsr decTileHitX
jsr decTileHitY
jsr tileClearPixel
jsr decTileHitY
jsr incTileHitX
jsr tileClearPixel
jsr incTileHitX
jsr tileClearPixel
jsr decTileHitY
jsr decTileHitX
jsr tileClearPixel
rts
; -----------------------------------------------------------------------------
; clearShieldBombedPixels: Clear pixels in the following shape: X = HIT_TILE_PIX
; -----------------------------------------------------------------------------
;
; OOO
; OXO
; OOO
; OOO
; OO
;
clearShieldBombedPixels:
jsr tileClearPixel
jsr decTileHitY
jsr tileClearPixel
jsr incTileHitX
jsr tileClearPixel
jsr incTileHitX
jsr tileClearPixel
jsr incTileHitY
jsr decTileHitX
jsr tileClearPixel
jsr decTileHitX
jsr decTileHitX
jsr tileClearPixel
jsr incTileHitY
jsr incTileHitX
jsr tileClearPixel
jsr incTileHitX
jsr tileClearPixel
jsr incTileHitX
jsr tileClearPixel
jsr incTileHitY
jsr decTileHitX
jsr tileClearPixel
jsr decTileHitX
jsr tileClearPixel
jsr decTileHitX
jsr tileClearPixel
jsr incTileHitY
jsr incTileHitX
jsr tileClearPixel
jsr incTileHitX
jsr tileClearPixel
rts