mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-12-21 06:29:48 +00:00
193 lines
6.2 KiB
Plaintext
193 lines
6.2 KiB
Plaintext
|
|
; Atari 8-bit sample code
|
|
; Written by Daniel Boris (danlb_2000@yahoo.com)
|
|
; Modified by Steven Hugg @8bitworkshop
|
|
; Assemble with DASM
|
|
;
|
|
|
|
processor 6502
|
|
|
|
include "atari.inc"
|
|
|
|
;*************** Variable ***********************
|
|
line equ $20 ;Current DLI line
|
|
pm0pos equ $21 ;Current pos of P0
|
|
|
|
;*************** Start of Code *******************
|
|
|
|
org $a000 ;Start of cartridge area
|
|
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
|
|
sta COLOR0
|
|
lda #$0F ;Set color PF1
|
|
sta COLOR1
|
|
lda #$84 ;Set color PF2
|
|
sta COLOR2
|
|
lda #$00 ;Set Display list pointer
|
|
sta SDLSTL
|
|
lda #$10
|
|
sta SDLSTH
|
|
lda #$f8 ;Set Charcter Set Base
|
|
sta CHBAS
|
|
lda #$22 ;Enable DMA
|
|
sta SDMCTL
|
|
; 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
|
|
|
|
;************ 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/
|
|
sta SDMCTL ;normal background)
|
|
lda #$20 ;Set PM base address ($200)
|
|
sta PMBASE
|
|
lda #$03 ;Enable players and missiles
|
|
sta GRACTL
|
|
lda #$16 ;Color of player 0
|
|
sta PCOLR0
|
|
ldy #$00
|
|
lda #$02 ;Size of player 0
|
|
sta SIZEP0
|
|
lda #$01 ;Give players priority over playfield
|
|
sta GPRIOR
|
|
|
|
|
|
;************ 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
|
|
cpx #$C0 ;Check for end of move
|
|
bne mvloop1 ;If not keep moving right
|
|
lda #$04 ;Give playfield priority player
|
|
sta GPRIOR
|
|
|
|
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
|
|
cpx #$30 ;Check for end of move
|
|
bne mvloop2 ;If not keep moving left
|
|
lda #$01 ;Give player priority over playfield
|
|
sta GPRIOR
|
|
jmp mvloop1 ;Continue looping
|
|
|
|
;************ Wait for vertical blank ************************
|
|
|
|
waitvb
|
|
lda RTCLOK+2 ;Read timer (this is incremented during VB)
|
|
waitvb2
|
|
cmp RTCLOK+2 ;Did it change?
|
|
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 ****************************
|
|
; starts at $1000
|
|
|
|
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 **************************
|
|
|
|
;Cartridge footer
|
|
org CARTCS
|
|
.word Start ; cold start address
|
|
.byte $00 ; 0 == cart exists
|
|
.byte $04 ; boot cartridge
|
|
.word Start ; start
|