-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalien.asm
292 lines (278 loc) · 5.36 KB
/
alien.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
;Player/Missile graphics exanple
;
;by Karl E. Wiegers
;
;.encoding "screencodeatari"
OPEN = $03
ICCOM = $0342
ICBAL = $0344
ICBLL = $0348
ICAX1 = $034A
ICAX2 = $034B
CIOV = $E456
;
;PMG-related equates
;
PCOLR0 = $02C0
SDMCTL = $022F
HPOSP0 = $D000
SIZEP0 = $D008
GRACTL = $D01D
PMBASE = $D407
;
;some variables I need to use
;
SHAPE = $CB
PLYRSTRT = $CD
YPOSP0 = $0630
XPOSP0 = $0634
NBYTES = $0638
TOP = $0639
BOTTOM = $063A
DIRECT = $063D
;
;PMG area of 2K begins at $3000;
;player images are stored in
;unused part of PMG area
;
PMG = $3000
;
;*******************************
; MAIN PROGRAM STARTS HERE
;*******************************
;
;*= $5000 ; for ATASM
.org $5000 ;for MADS
START
CLD ;binary mode
JSR OPENSCREEN ;open screen
LDX #0
TXA
INIT1
STA PMG+$0300,X ;zero out
STA PMG+$0400,X ;player and
STA PMG+$0500,X ;missile
STA PMG+$0600,X ;parts of
STA PMG+$0700,X ;PMG area
INX
BNE INIT1
LDA #>PMG ;store address
STA PMBASE ;of PMG area
LDA #0
LDX #3
INIT2
STA SIZEP0,X ;zero sizes,
STA HPOSP0,X ;horizontal
STA XPOSP0,X ;positions
DEX ;for all
BNE INIT2 ;players
;
;load alien shape into player
;
LDA #<ALIEN ;store address
STA SHAPE ;of shape in
LDA #>ALIEN ;page 8 bytes
STA SHAPE+1
CLC
LDA #$04 ;store address
ADC #>PMG ;where player
STA PLYRSTRT+1 ;is to be
LDA #180 ;stored into
STA PLYRSTRT ;page 0 bytes
STA YPOSP0 ;and variable
JSR COPYPLAYER ;store image
;
;load car shape into player 1
;the same way as the alien
;
LDA #<CAR
STA SHAPE
LDA #>CAR
STA SHAPE+1
CLC
LDA #$05
ADC #>PMG
STA PLYRSTRT+1
LDA #122
STA PLYRSTRT
STA YPOSP0+1
JSR COPYPLAYER
;
;set up PMG environment
;
LDA #30 ;top of alien
STA TOP ;movement area.
LDA #200 ;bottom of alien
STA BOTTOM ;movement area.
LDA #28 ;alien is yellow
STA PCOLR0
LDA #86 ;car is purple
STA PCOLR0+1
LDA #62 ;single-line PMG
STA SDMCTL ;resolution
LDA #1 ;car is double
STA SIZEP0+1 ;wide
LDA #3 ;enable PMG
STA GRACTL
LDA #120 ;alien starts in
STA HPOSP0 ;middle of scree
STA XPOSP0
LDA #1 ;initial direc-
STA DIRECT ;tion is up
;
;commence player movement:
;alien moves only vertically,
;car moves only horizontally
ACTION
LDX #15 ;do nothing
JSR DELAY ;for a bit
INC XPOSP0+1 ;move car 1
LDA XPOSP0+1 ;position to
STA HPOSP0+1 ;the right
CLC
LDA #$04 ;store initial
ADC #>PMG ;RAM position
STA PLYRSTRT+1 ;of alien in
LDA YPOSP0 ;page bytes
STA PLYRSTRT
;
;logic to figure out if alien is
;be moved up or down
;
LDA DIRECT ;current dir
BNE CHKTOP ;up, check top
CHKBOT
LDA YPOSP0 ;is he at the
CMP BOTTOM ;bottom?
BEQ UP ;yes. move up
BNE DOWN ;no. move down
CHKTOP
LDA YPOSP0 ;is he at the
CMP TOP ;top?
BNE UP ;no, move up
DOWN
JSR MOVEDOWN ;move him down
LDA #0 ;current direc-
STA DIRECT ;tion is down
CLC ;keep going
BCC ACTION
UP
JSR MOVEUP ;move him up
LDA #1 ;current direc-
STA DIRECT ;tion is up
CLC ;keep going
BCC ACTION
;********************************
; END OF MAIN PROGRAM
;********************************
;
;
;********************************
;SUBROUTINES START HERE
;********************************
;
;open screen in Graphics 3
;
OPENSCREEN
LDX #$60
LDA #OPEN
STA ICCOM,X
LDA #<SCREEN
STA ICBAL,X
LDA #>SCREEN
STA ICBAL+1,X
LDA #12
STA ICAX1,X
LDA #3
STA ICAX2,X
JSR CIOV
RTS
;
;copy player from data region
;to desired PMG location
;
COPYPLAYER
LDY #0 ;get no. of
LDA (SHAPE),Y ;bytes of
STA NBYTES ;player data
INC NBYTES ;to be moved
LDY #1
PLOOP
LDA (SHAPE),Y ;copy to PMG
STA (PLYRSTRT),Y ;area
INY ;data area
CPY NBYTES ;all bytes yet?
BNE PLOOP ;no, keep going
RTS ;yes, stop
;
;do-nothing delay subroutine
;number in X-register deternines
;length of delay
;
DELAY
LDY #0
DELAY2
DEY
BNE DELAY2
DEX
BNE DELAY
RTS
;sub. to Move alien shape down
;one line (up one byte in RAM)
MOVEDOWN
LDY ALIEN ;get # bytes
LOOPDOWN
LDA (PLYRSTRT),Y ; get a byte
INY ;store one
STA (PLYRSTRT),Y ;byte higher
DEY ;point to
DEY ;lower byte
BPL LOOPDOWN ;go until
INC YPOSP0 ;new Y position
RTS
;sub. to Move alien shape up
;one line (down one byte in RAM)
MOVEUP
LDA ALIEN ;# bytes to move
STA NBYTES ;is 1 more than
INC NBYTES ;# player bytes
LDY #1
LOOPUP
LDA (PLYRSTRT),Y ;get a byte
DEY ;store 1
STA (PLYRSTRT),Y ;byte lower
INY ;point to
INY ;next one
CPY NBYTES ;done all?
BNE LOOPUP ;no, go on
DEC YPOSP0 ;new Y position
RTS
;
;data values needed
;
SCREEN .text 'S'
;
;data for player shapes are
;stored in unused portion of
;PMG area
;
;*= PMG ; for atasm
.org PMG ;for MADS
;
;normal alien
;
ALIEN
.BYTE 14,60,24,126,189,189
.BYTE 189,189,60,50,36
.BYTE 36,36,102,0
;
;car shape
;
CAR
.BYTE 15,126,195,219,219
.BYTE 91,219,219,219,219
.BYTE 91,219,219,195,126,0
; *= $02E0 ; for atasm
;.org $2e0 ;for MADS
.segment "Launcher"
.WORD START