2018-08-13 22:17:36 +00:00
|
|
|
|
2020-09-07 21:09:49 +00:00
|
|
|
; Atari 8-bit sample code
|
2020-07-28 20:06:49 +00:00
|
|
|
; Written by Daniel Boris (danlb_2000@yahoo.com)
|
|
|
|
; Modified by Steven Hugg @8bitworkshop
|
2018-06-20 08:06:18 +00:00
|
|
|
; Assemble with DASM
|
|
|
|
;
|
|
|
|
|
|
|
|
processor 6502
|
|
|
|
|
2020-07-28 20:06:49 +00:00
|
|
|
include "atari.inc"
|
2018-06-20 08:06:18 +00:00
|
|
|
|
|
|
|
;*************** Variable ***********************
|
2020-07-21 19:14:05 +00:00
|
|
|
line equ $20 ;Current DLI line
|
|
|
|
pm0pos equ $21 ;Current pos of P0
|
2018-06-20 08:06:18 +00:00
|
|
|
|
|
|
|
;*************** Start of Code *******************
|
|
|
|
|
2020-07-28 20:06:49 +00:00
|
|
|
org $a000 ;Start of cartridge area
|
2018-06-20 08:06:18 +00:00
|
|
|
Start
|
|
|
|
|
|
|
|
;************* Setup display list *******************
|
|
|
|
|
|
|
|
ldx #$21 ;Number of bytes in list
|
|
|
|
dlloop ;Copy display list to RAM
|
|
|
|
lda dlist,x ;Get byte
|
|
|
|
sta $1000,x ;Copy to RAM
|
|
|
|
dex ;next byte
|
|
|
|
bpl dlloop
|
|
|
|
|
|
|
|
;************* Setup hardware registers *************
|
|
|
|
|
|
|
|
lda #$22 ;Set color PF0
|
2020-07-21 19:14:05 +00:00
|
|
|
sta COLOR0
|
2018-06-20 08:06:18 +00:00
|
|
|
lda #$0F ;Set color PF1
|
2020-07-21 19:14:05 +00:00
|
|
|
sta COLOR1
|
2018-06-20 08:06:18 +00:00
|
|
|
lda #$84 ;Set color PF2
|
2020-07-21 19:14:05 +00:00
|
|
|
sta COLOR2
|
2018-06-20 08:06:18 +00:00
|
|
|
lda #$00 ;Set Display list pointer
|
2020-07-21 19:14:05 +00:00
|
|
|
sta SDLSTL
|
2018-06-20 08:06:18 +00:00
|
|
|
lda #$10
|
2020-07-21 19:14:05 +00:00
|
|
|
sta SDLSTH
|
2018-06-20 08:06:18 +00:00
|
|
|
lda #$f8 ;Set Charcter Set Base
|
2020-07-28 20:06:49 +00:00
|
|
|
sta CHBAS
|
2018-06-20 08:06:18 +00:00
|
|
|
lda #$22 ;Enable DMA
|
2020-07-21 19:14:05 +00:00
|
|
|
sta SDMCTL
|
2020-07-28 20:06:49 +00:00
|
|
|
; load display list interrupt address
|
|
|
|
lda #<dli
|
|
|
|
sta VDSLST
|
|
|
|
lda #>dli
|
|
|
|
sta VDSLST+1
|
|
|
|
; activate display list interrupt and vertical blank interrupt
|
|
|
|
lda #$C0
|
|
|
|
sta NMIEN
|
2018-06-20 08:06:18 +00:00
|
|
|
|
|
|
|
;************ Draw display graphics *******************
|
|
|
|
|
|
|
|
ldy #$02 ;Draw bars on screen
|
|
|
|
lda #$18 ;Screen memory starts at $1800
|
|
|
|
sta $81
|
|
|
|
lda #$00
|
|
|
|
sta $80
|
|
|
|
ldx #$18
|
|
|
|
crloop5
|
|
|
|
lda #$FF ;Bar 4 pixels wide of color 3
|
|
|
|
sta ($80),y ;Store data
|
|
|
|
iny
|
|
|
|
iny ;Skip 4 pixels
|
|
|
|
lda #$55 ;Bar 4 pixels wide of color 1
|
|
|
|
sta ($80),y ;Store data
|
|
|
|
iny
|
|
|
|
iny ;Skip 4 pixels
|
|
|
|
lda #$AA ;Bar 4 pixels wide of color 2
|
|
|
|
sta ($80),y ;Store data
|
|
|
|
tya
|
|
|
|
clc
|
|
|
|
adc #$06 ;Move pointer to next line
|
|
|
|
tay
|
|
|
|
dex ;Next line
|
|
|
|
bne crloop5 ;Branch if not done
|
|
|
|
|
|
|
|
;************* Setup Player/Missile registers ***************
|
|
|
|
|
|
|
|
lda #$3A ;Enable DMA (single line resolution/
|
2020-07-21 19:14:05 +00:00
|
|
|
sta SDMCTL ;normal background)
|
2018-06-20 08:06:18 +00:00
|
|
|
lda #$20 ;Set PM base address ($200)
|
|
|
|
sta PMBASE
|
|
|
|
lda #$03 ;Enable players and missiles
|
|
|
|
sta GRACTL
|
|
|
|
lda #$16 ;Color of player 0
|
2020-07-21 19:14:05 +00:00
|
|
|
sta PCOLR0
|
2018-06-20 08:06:18 +00:00
|
|
|
ldy #$00
|
2020-07-21 19:14:05 +00:00
|
|
|
lda #$02 ;Size of player 0
|
2018-06-20 08:06:18 +00:00
|
|
|
sta SIZEP0
|
|
|
|
lda #$01 ;Give players priority over playfield
|
2020-07-28 20:06:49 +00:00
|
|
|
sta GPRIOR
|
2018-06-20 08:06:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
;************ Copy player data to RAM ********************************
|
|
|
|
|
|
|
|
pmloop1
|
|
|
|
lda pm1,y ;Get data
|
|
|
|
sta $2430,y ;Write it into RAM
|
|
|
|
sta $24C0,y
|
|
|
|
iny
|
|
|
|
cpy #$08 ;Copy 8 bytes
|
|
|
|
bne pmloop1
|
|
|
|
|
|
|
|
;************ Move player ********************************************
|
|
|
|
|
|
|
|
ldx #$20 ;Starting position of player
|
|
|
|
mvloop1
|
|
|
|
jsr waitvb ;Wait for a vertical bank
|
|
|
|
lda #$00 ;Reset line counter
|
|
|
|
sta line
|
|
|
|
stx HPOSP0 ;Set position of player
|
|
|
|
stx pm0pos ;Save position for DLI
|
|
|
|
inx
|
2020-07-21 19:14:05 +00:00
|
|
|
cpx #$C0 ;Check for end of move
|
2018-06-20 08:06:18 +00:00
|
|
|
bne mvloop1 ;If not keep moving right
|
|
|
|
lda #$04 ;Give playfield priority player
|
2020-07-28 20:06:49 +00:00
|
|
|
sta GPRIOR
|
2018-06-20 08:06:18 +00:00
|
|
|
|
|
|
|
mvloop2
|
|
|
|
jsr waitvb ;Wait for a vertical blank
|
|
|
|
lda #$00 ;Reset line counter
|
|
|
|
sta line
|
|
|
|
stx HPOSP0 ;Set position of player
|
|
|
|
stx pm0pos ;Save position for DLI
|
|
|
|
dex
|
2020-07-21 19:14:05 +00:00
|
|
|
cpx #$30 ;Check for end of move
|
2018-06-20 08:06:18 +00:00
|
|
|
bne mvloop2 ;If not keep moving left
|
|
|
|
lda #$01 ;Give player priority over playfield
|
2020-07-28 20:06:49 +00:00
|
|
|
sta GPRIOR
|
2018-06-20 08:06:18 +00:00
|
|
|
jmp mvloop1 ;Continue looping
|
|
|
|
|
|
|
|
;************ Wait for vertical blank ************************
|
|
|
|
|
|
|
|
waitvb
|
2020-07-28 20:06:49 +00:00
|
|
|
lda RTCLOK+2 ;Read timer (this is incremented during VB)
|
2018-06-20 08:06:18 +00:00
|
|
|
waitvb2
|
2020-07-28 20:06:49 +00:00
|
|
|
cmp RTCLOK+2 ;Did it change?
|
2018-06-20 08:06:18 +00:00
|
|
|
beq waitvb2 ;If not keep waiting
|
|
|
|
rts
|
|
|
|
|
|
|
|
;************ Display list interrupt ************************
|
|
|
|
|
|
|
|
dli
|
|
|
|
pha ;Save A
|
|
|
|
inc line ;Increment the line counter
|
|
|
|
lda line ;Past the fifth DLI?
|
|
|
|
cmp #$05
|
|
|
|
bne done ;If not then exit DLI
|
|
|
|
lda pm0pos ;Get player 0 position
|
|
|
|
eor #$FF ;Invert it
|
|
|
|
sta HPOSP0 ;Set player 0 position
|
|
|
|
lda #$0F ;Change player color
|
|
|
|
sta COLPM0 ;
|
|
|
|
; Note: Player color is changed in hardware register not the shadow
|
|
|
|
; register so it takes effect immediatly.
|
|
|
|
done
|
|
|
|
pla ;Restore A
|
|
|
|
rti ;Done
|
|
|
|
|
|
|
|
;************* Display list data ****************************
|
2020-07-21 19:14:05 +00:00
|
|
|
; starts at $1000
|
2018-06-20 08:06:18 +00:00
|
|
|
|
|
|
|
dlist .byte $70,$70,$70 ;24 blank scanlines
|
|
|
|
.byte $48,$00,$18 ;Mode 8 and Load memory scan $1800
|
|
|
|
.byte $88,$88,$88,$88,$88,$88,$88 ;23 more line of mode 8
|
|
|
|
.byte $88,$88,$88,$88,$88,$88,$88,$88,$88,$88,$88,$88,$88
|
|
|
|
.byte $88,$88,$88
|
|
|
|
.byte $41,$00,$10 ;Jump back to start at $1000
|
|
|
|
|
|
|
|
;************* Player shape *********************************
|
|
|
|
|
|
|
|
pm1 .byte %00111100
|
|
|
|
.byte %01000010
|
|
|
|
.byte %10100101
|
|
|
|
.byte %10000001
|
|
|
|
.byte %10100101
|
|
|
|
.byte %10011001
|
|
|
|
.byte %01000010
|
|
|
|
.byte %00111100
|
|
|
|
|
|
|
|
;************** Cart reset vector **************************
|
|
|
|
|
2020-07-28 20:06:49 +00:00
|
|
|
;Cartridge footer
|
|
|
|
org CARTCS
|
|
|
|
.word Start ; cold start address
|
|
|
|
.byte $00 ; 0 == cart exists
|
|
|
|
.byte $04 ; boot cartridge
|
|
|
|
.word Start ; start
|