Debian Codegraph @

test/atari7800/spritesample.asm

raw
1 ; Atari 7800 sprite sample
2 ;
3 ; Written by Daniel Boris ([email protected])
4 ; original at http://atarihq.com/danb/files/7800sprt.s
5 ;
6 ; Adapted to use 7800.h, optional a78 header added, and new
7 ; comments added by Mike Saarna.
8 ;
9 ; NOTE: assembling this source will create a simple BIN file. To
10 ; add an a78 header that most emulators will expect, assemble
11 ; with -DA78HEADER, or uncomment the line below...
12 ;
13 ;A780HEADER = 1
14 ;
15 ; ...and be sure to use the A78 extension for your bin.
16 ;
17 ; The binary won't be cryptographically signed, meaning it won't pass
18 ; the 7800 bios boot checks. This probably won't stop the bin from
19 ; running on most emulators. This may stop it from running on some
20 ; flash carts. It will certainly stop it running from EPROM based carts
21 ; To cryptographically sign binaries, you can use the tools found in
22 ; the 7800AsmDevKit - http://7800.8bitdev.org/index.php/7800AsmDevKit
23
24 processor 6502
25
26 include "7800.h"
27
28 SEG.U data
29
30
31 ;******* Variables ********************************
32
33 org $40
34
35 xpos ds.b 1 ;X Position of sprite
36 ypos ds.b 1 ;Y Position of sprite
37 temp ds.b 1
38 dlpnt ds.w 1
39 dlend ds.b 12 ;Index of end of each DL
40
41
42
43
44 ;**********************************************************
45
46 SEG ROM
47
48 ifconst A78HEADER
49 HEADER ORG ROMTOP-128
50 DC.B 1 ; 0 Header version - 1 byte
51 DC.B "ATARI7800" ; 1..16 "ATARI7800 " - 16 bytes
52 DS 7,32
53 DC.B "Dan Boris, sprite sample"; 17..48 Cart title - 32 bytes
54 DS HEADER+49-.,0
55 DC.B $00,$00,256->ROMTOP,$00; 49..52 data length - 4 bytes
56 DC.B $00,$00 ; 53..54 cart type - 2 bytes
57 ; bit 0 - pokey at $4000
58 ; bit 1 - supergame bank switched
59 ; bit 2 - supergame ram at $4000
60 ; bit 3 - rom at $4000
61 ; bit 4 - bank 6 at $4000
62 ; bit 5 - supergame banked ram
63 ; bit 6 - pokey at $450
64 ; bit 7 - mirror ram at $4000
65 ; bit 8-15 - Special
66 ; 0 = Normal cart
67 DC.B 1 ; 55 controller 1 type - 1 byte
68 DC.B 1 ; 56 controller 2 type - 1 byte
69 ; 0 = None
70 ; 1 = Joystick
71 ; 2 = Light Gun
72 DC.B 0 ; 57 0 = NTSC 1 = PAL
73 DC.B 0 ; 58 Save data peripheral - 1 byte (version 2)
74 ; 0 = None / unknown (default)
75 ; 1 = High Score Cart (HSC)
76 ; 2 = SaveKey
77 ORG HEADER+63
78 DC.B 0 ; 63 Expansion module
79 ; 0 = No expansion module (default on all currently released games)
80 ; 1 = Expansion module required
81 ORG HEADER+100 ; 100..127 "ACTUAL CART DATA STARTS HERE" - 28 bytes
82 DC.B "ACTUAL CART DATA STARTS HERE"
83 endif
84
85 ROMTOP ORG $8000 ;Start of code
86
87 START
88 sei ;Disable interrupts
89 cld ;Clear decimal mode
90
91
92 ;******** Atari recommended startup procedure
93
94 lda #$07
95 sta INPTCTRL ;Lock into 7800 mode
96 lda #$7F
97 sta CTRL ;Disable DMA
98 lda #$00
99 sta OFFSET
100 sta INPTCTRL
101 ldx #$FF ;Reset stack pointer
102 txs
103
104 ;************** Clear zero page and hardware ******
105
106 ldx #$40
107 lda #$00
108 crloop1
109 sta $00,x ;Clear zero page
110 sta $100,x ;Clear page 1
111 inx
112 bne crloop1
113
114 ;************* Clear RAM **************************
115
116 ldy #$00 ;Clear Ram
117 lda #$18 ;Start at $1800
118 sta $81
119 lda #$00
120 sta $80
121 crloop3
122 lda #$00
123 sta ($80),y ;Store data
124 iny ;Next byte
125 bne crloop3 ;Branch if not done page
126 inc $81 ;Next page
127 lda $81
128 cmp #$20 ;End at $1FFF
129 bne crloop3 ;Branch if not
130
131 ldy #$00 ;Clear Ram
132 lda #$22 ;Start at $2200
133 sta $81
134 lda #$00
135 sta $80
136 crloop4
137 lda #$00
138 sta ($80),y ;Store data
139 iny ;Next byte
140 bne crloop4 ;Branch if not done page
141 inc $81 ;Next page
142 lda $81
143 cmp #$27 ;End at $27FF
144 bne crloop4 ;Branch if not
145
146 ldx #$00
147 lda #$00
148 crloop5 ;Clear 2100-213F
149 sta $2100,x
150 inx
151 cpx #$40
152 bne crloop5
153
154 ;************* Build DLL *******************
155
156 ; 20 blank lines
157
158 ldx #$00
159 lda #$4F ;16 lines
160 sta $1800,x
161 inx
162 lda #$21 ;$2100 = blank DL
163 sta $1800,x
164 inx
165 lda #$00
166 sta $1800,x
167 inx
168 lda #$44 ;4 lines
169 sta $1800,x
170 inx
171 lda #$21
172 sta $1800,x
173 inx
174 lda #$00
175 sta $1800,x
176 inx
177
178 ; 192 mode lines divided into 12 regions
179
180 ldy #$00
181 DLLloop2
182 lda #$4F ;16 lines
183 sta $1800,x
184 inx
185 lda DLPOINTH,y
186 sta $1800,x
187 inx
188 lda DLPOINTL,y
189 sta $1800,x
190 inx
191 iny
192 cpy #$0D ;12 DLL entries
193 bne DLLloop2
194
195
196 ; 26 blank lines
197
198 lda #$4F ;16 lines
199 sta $1800,x
200 inx
201 lda #$21 ;$2100 = blank DL
202 sta $1800,x
203 inx
204 lda #$00
205 sta $1800,x
206 inx
207 lda #$4A ;10 lines
208 sta $1800,x
209 inx
210 lda #$21
211 sta $1800,x
212 inx
213 lda #$00
214 sta $1800,x
215
216
217 ;***************** Setup Maria Registers ****************
218
219 lda #$18 ;DLL at $1800
220 sta DPPH
221 lda #$00
222 sta DPPL
223 lda #$18 ;Setup Palette 0
224 sta P0C1
225 lda #$38
226 sta P0C2
227 lda #$58
228 sta P0C3
229 lda #$43 ;Enable DMA
230 sta CTRL
231 lda #$00 ;Setup ports to read mode
232 sta CTLSWA
233 sta CTLSWB
234
235 lda #$40 ;Set initial X position of sprite
236 sta xpos
237
238 mainloop
239 lda MSTAT ;Wait for VBLANK
240 and #$80
241 beq mainloop
242
243 lda SWCHA ;Read stick
244 and #$80 ;Pushed Right?
245 bne skip1
246 ldx xpos ;Move sprite to right
247 inx
248 stx xpos
249 skip1
250 lda SWCHA ;Read stick
251 and #$40 ;Pushed Left?
252 bne skip2
253 ldx xpos ;Move sprite to left
254 dex
255 stx xpos
256 skip2
257 lda SWCHA ;Read stick
258 and #$20 ;Pushed Down?
259 bne skip3
260 ldx ypos ;Move sprite down
261 cpx #176
262 beq skip3 ;Don't move if we are at the bottom
263 inx
264 stx ypos
265 skip3
266 lda SWCHA ;Read stick
267 and #$10 ;Pushed Up?
268 bne skip4
269 ldx ypos ;Move sprite up
270 beq skip4 ;Don't move if we are at the top
271 dex
272 stx ypos
273 skip4
274
275 ;********************** reset DL ends ******************
276
277 ldx #$0C
278 lda #$00
279 dlclearloop
280 dex
281 sta dlend,x
282 bne dlclearloop
283
284
285 ;******************** build DL entries *********************
286
287 lda ypos ;Get Y position
288 and #$F0
289 lsr ;Divide by 16
290 lsr
291 lsr
292 lsr
293 tax
294 lda DLPOINTL,x ;Get pointer to DL that this sprite starts in
295 sta dlpnt
296 lda DLPOINTH,x
297 sta dlpnt+1
298
299 ;Create DL entry for upper part of sprite
300
301 ldy dlend,x ;Get the index to the end of this DL
302 lda #$00
303 sta (dlpnt),y ;Low byte of data address
304 iny
305 lda #$40 ;Mode 320x1
306 sta (dlpnt),y
307 iny
308 lda ypos
309 and #$0F
310 ora #$a0
311 sta (dlpnt),y
312 iny
313 lda #$1F ;Palette 0, 1 byte wide
314 sta (dlpnt),y
315 iny
316 lda xpos ;Horizontal position
317 sta (dlpnt),y
318 sty dlend,x
319
320 lda ypos
321 and #$0F ;See if sprite is entirely within this region
322 beq doneDL ;branch if it is
323
324 ;Create DL entry for lower part of sprite
325
326 inx ;Next region
327 lda DLPOINTL,x ;Get pointer to next DL
328 sta dlpnt
329 lda DLPOINTH,x
330 sta dlpnt+1
331 ldy dlend,x ;Get the index to the end of this DL
332 lda #$00
333 sta (dlpnt),y
334 iny
335 lda #$40 ;Mode 320x1
336 sta (dlpnt),y
337 iny
338 lda ypos
339 and #$0F
340 eor #$0F
341 sta temp
342 lda #$a0
343 clc
344 sbc temp
345 sta (dlpnt),y
346 iny
347 lda #$1F ;Palette 0, 1 byte wide
348 sta (dlpnt),y
349 iny
350 lda xpos ;Horizontal position
351 sta (dlpnt),y
352 sty dlend,x
353 doneDL
354
355 ;************** add DL end entry on each DL *****************************
356
357 ldx #$0C
358 dlendloop
359 dex
360 lda DLPOINTL,x
361 sta dlpnt
362 lda DLPOINTH,x
363 sta dlpnt+1
364 ldy dlend,x
365 iny
366 lda #$00
367 sta (dlpnt),y
368 txa
369 bne dlendloop
370
371 vbloop
372 lda MSTAT ;Wait for VBLANK to end
373 and #$80
374 bne vbloop
375
376 jmp mainloop ;Loop
377
378 redraw
379
380
381 NMI
382 RTI
383
384 IRQ
385 RTI
386
387
388 ;Pointers to the DLs
389
390 DLPOINTH
391 .byte $22,$22,$22,$22,$23,$23,$23,$23,$24,$24,$24,$24
392 DLPOINTL
393 .byte $00,$40,$80,$C0,$00,$40,$80,$C0,$00,$40,$80,$C0
394
395
396
397
398 ;************** Graphic Data *****************************
399 org $a000
400 .byte %00111100
401 org $a100
402 .byte %00111100
403 org $a200
404 .byte %01000010
405 org $a300
406 .byte %01000010
407 org $a400
408 .byte %10011001
409 org $a500
410 .byte %10011001
411 org $a600
412 .byte %10100101
413 org $a700
414 .byte %10100101
415 org $a800
416 .byte %10000001
417 org $a900
418 .byte %10000001
419 org $aA00
420 .byte %10100101
421 org $aB00
422 .byte %10100101
423 org $aC00
424 .byte %01000010
425 org $aD00
426 .byte %01000010
427 org $aE00
428 .byte %00111100
429 org $aF00
430 .byte %00111100
431
432
433 ;************** Cart reset vector **************************
434
435 org $fff8
436 .byte $FF ;Region verification
437 .byte $87 ;ROM start $4000
438 .word #NMI
439 .word #START
440 .word #IRQ