-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvaders.asm
224 lines (194 loc) · 9.07 KB
/
invaders.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
216
217
218
219
220
221
222
223
224
// *******************************************************************************************************************************************************************
// *******************************************************************************************************************************************************************
//
// Microvision Space Invaders
//
// Written by Paul Robson January 2014
//
// Revisions: 1.0 Completed 22-Jan-2014
//
// *******************************************************************************************************************************************************************
// *******************************************************************************************************************************************************************
include idata.asm // Define Memory Usage
include system.asm // Microvision Standard Routines
ldx 3 // Set Lives to one.
tcy Lives_3
tcmiy 1
lcall OSClearDisplaySpace // Clear Display to 0000
tcy 1
lbr PlayOver // Go a rendering - fakes 'lost life'
// *******************************************************************************************************************************************************************
//
// Start a new game
//
// *******************************************************************************************************************************************************************
RestartGame
ldx 3 // Set Invader Speed (basic game speed control) to 10 and Lives to 3.
tcy InvaderSpeed_3
tcmiy 10
tcmiy 3
lcall OSClearDisplaySpace // Clear score
// *******************************************************************************************************************************************************************
//
// Go to the next level
//
// *******************************************************************************************************************************************************************
NextLevel
ldx 3 // Bump Invader Speed
tcy InvaderSpeed_3
dman // If you somehow beat level 0 which is insane you will get to very slow 15.
tam
// *******************************************************************************************************************************************************************
//
// Reset the same level (after invaders have landed)
//
// *******************************************************************************************************************************************************************
ResetLevel
comc
ldx 4 // Reset the invader rows
lcall ResetInvaderRow
ldx 5
lcall ResetInvaderRow
ldx 6
lcall ResetInvaderRow
ldx 7
lcall ResetInvaderRow
cla
lcall SetInvaderVerticalPosition // Position invaders at the top
comc
// *******************************************************************************************************************************************************************
//
// Life has been lost - invaders stay as they are but base and bullets are reset
//
// *******************************************************************************************************************************************************************
LostLife
comc
lcall ResetPlayerAndBullets // Reset the bullets and the player.
comc
tcy InvaderDirection_3 // Reset Invader Initial Direction so they go left
ldx 3
tcmiy 0
// *******************************************************************************************************************************************************************
//
// Main Game Loop (most of which is in imain.asm)
//
// *******************************************************************************************************************************************************************
MainLoop
lcall OSSwitchPolarity // Switch display polarity, keeps Microvision LCD happy.
comc
lbr RenderAllAndMove // Render everything using the code in Chapter 1, which comes back immediately below.
EndRenderAndMove // Here : Y = 0 (ok), 1 (life lost), 2 (landed), 3 (complete)
ynec 0 // If Y is zero, then the game has stopped.
br PlayOver
br MainLoop
// *******************************************************************************************************************************************************************
//
// Game ended for some reason: Y = 1 (life lost), Y = 2 (invaders landed), Y = 3 (level complete)
//
// *******************************************************************************************************************************************************************
PlayOver
tya // Put code in Y (as above, can also be 4 - starting)
ldx 2 // Save code in Game Status in Bank 2
tcy GameStatus_2
tam
a13aac // S will be set if the status value was 3 or more
br NoLivesLost
ldx 3 // Point XY to the lives value
tcy Lives_3
dman // decrement and write back.
tam
NoLivesLost
lbr RenderScoreAndLives
// *******************************************************************************************************************************************************************
//
// Render the score/lives display
//
// *******************************************************************************************************************************************************************
page
RenderScoreAndLives
lcall OSSwitchPolarity // Polarity Switch on this.
tcy 2 // Render score at offset 2.
lbr OSUpdateAllAndRenderTextDisplay
OSExternalRenderTextExit
tcy 14
ldx 0
lcall OSWriteBitsY // Write Column 14 out.
cla
a7aac // value to output = 1110 to LCD controller
tdo // Put on output lines.
ldx 3 // Read lives into A
tcy Lives_3
tma
lcall OutputATimes // Output A times.
cla
tdo
ldx 3 // Read Lives
tcy Lives_3
tma
cpaiz // Calculate 4 - Lives
a4aac
lcall OutputATimes // Output spaces.
lcall OSUpdateDisplay
comc // Update keyboard variables.
lcall ScanKeyboard
comc
ldx 3 // Check for both left + middle pressed.
tcy HWKeyMiddleCol
cla // check 8 in both middle and left values
a8aac
mnea
br RenderScoreAndLives
tcy HWKeyLeftCol
mnea
br RenderScoreAndLives
lbr DecideAction // Both 8, the decide what to do next.
OutputATimes
dan // Dec A
br OATContinue // If gone -ve then over
retn
OATContinue
tcy HWNotDataClock
rstr
setr
br OutputATimes
// *******************************************************************************************************************************************************************
//
// End of Score/Lives Display - decide what to do next.
//
// *******************************************************************************************************************************************************************
page
DecideAction
ldx 3 // Read lives.
tcy Lives_3
tma
cpaiz // Sets S if Lives = 0
br DA_Restart // If so, Restart game.
ldx 2 // Read the game status.
tcy GameStatus_2
tma
a13aac // if >= 3 then
br DA_NextLevel // do the next level
iac
br DA_ResetLevel // if = 2 then redo the current level.
lbr LostLife // otherwise =1, lost life but continue.
DA_Restart
lbr RestartGame
DA_NextLevel
lbr NextLevel
DA_ResetLevel
lbr ResetLevel
// *******************************************************************************************************************************************************************
//
// Fix up as OSIncrement cannot jump back to chapter 1
//
// *******************************************************************************************************************************************************************
OSExternalIncrementExit // Fix up. OSIncrementOne is called in the bullet move code (if an invader is hit)
comc // It comes here (in Chapter 0) and is dispatched to the end of the bullet move
lbr BulletMoveExit // code in Chapter 1.
// *******************************************************************************************************************************************************************
//
// Subroutine and main games code
//
// *******************************************************************************************************************************************************************
include iroutines.asm // Space Invader Subroutines
include imain.asm // Main Loop Code.