217 lines
3.3 KiB
NASM
217 lines
3.3 KiB
NASM
.p816
|
|
.smart
|
|
|
|
.include "macros.inc"
|
|
.include "registers.inc"
|
|
.include "keys.inc"
|
|
|
|
.include "header.asm"
|
|
|
|
.segment "ZEROPAGE"
|
|
|
|
nmi_count: .res 2
|
|
|
|
.segment "BSS"
|
|
|
|
oam_lo_buffer: .res 512
|
|
oam_hi_buffer: .res 32
|
|
oam_buffer_end:
|
|
|
|
.segment "CODE"
|
|
|
|
VRAM_CHARS = $0000
|
|
VRAM_BG1 = $1000
|
|
|
|
start:
|
|
.include "init.asm"
|
|
|
|
; Set up the color palette
|
|
stz CGADD
|
|
|
|
; Color 0 - black
|
|
lda #$00
|
|
sta CGDATA
|
|
lda #$00
|
|
sta CGDATA
|
|
|
|
; Color 1 - red
|
|
lda #$1f
|
|
sta CGDATA
|
|
lda #$00
|
|
sta CGDATA
|
|
|
|
; Color 2 - green
|
|
lda #$e0
|
|
sta CGDATA
|
|
lda #$03
|
|
sta CGDATA
|
|
|
|
; Color 3 - blue
|
|
lda #$00
|
|
sta CGDATA
|
|
lda #$7c
|
|
sta CGDATA
|
|
|
|
; Set up sprite palette
|
|
lda #128 ;sprite palettes begin at cgdata index 128
|
|
sta CGADD
|
|
stz CGDATA
|
|
stz CGDATA
|
|
|
|
lda #$1f
|
|
sta CGDATA
|
|
stz CGDATA
|
|
|
|
; Graphics mode 0, 8x8 tiles
|
|
stz BGMODE
|
|
|
|
; Set BG1 and tile map and character data
|
|
lda #>VRAM_BG1
|
|
sta BG1SC
|
|
lda #VRAM_CHARS
|
|
sta BG12NBA
|
|
|
|
; Load character data into VRAM
|
|
lda #$80
|
|
sta VMAIN
|
|
ldx #VRAM_CHARS
|
|
stx VMADDL
|
|
|
|
; Set DMA source flags
|
|
lda #%00000001
|
|
sta DMAP0
|
|
|
|
; DMA destination VMDATAL register
|
|
lda #<VMDATAL
|
|
sta BBAD0
|
|
|
|
; Set starting address to charset
|
|
ldx #.loword(charset)
|
|
stx A1T0L
|
|
lda #^charset
|
|
sta A1B0
|
|
|
|
; Write to charset_end bytes
|
|
ldx #(charset_end - charset)
|
|
stx DAS0L
|
|
|
|
; actually kick off the DMA
|
|
lda #1
|
|
sta MDMAEN
|
|
|
|
|
|
|
|
; @charset_loop:
|
|
; lda charset,x
|
|
; sta VMDATAL
|
|
; inx
|
|
; lda charset,x
|
|
; sta VMDATAH
|
|
; inx
|
|
; cpx #(charset_end - charset)
|
|
; bne @charset_loop
|
|
|
|
; Manually clear screen
|
|
ldx #(VRAM_BG1)
|
|
@loop:
|
|
stx VMADDL
|
|
lda #$00
|
|
sta VMDATAL
|
|
stz VMDATAH
|
|
inx
|
|
cpx #(VRAM_BG1 + 32 * 29)
|
|
bne @loop
|
|
|
|
; write tile to position (1, 1)
|
|
TILE_X = 1
|
|
TILE_Y = 1
|
|
ldx #(VRAM_BG1 + (TILE_Y * 32) + TILE_X)
|
|
stx VMADDL
|
|
lda #$01 ; tile number
|
|
sta VMDATAL
|
|
stz VMDATAH
|
|
|
|
; Show bg1 + sprites
|
|
lda #%00010001
|
|
sta TM
|
|
|
|
lda #$0f
|
|
sta INIDISP
|
|
|
|
lda #$0
|
|
sta OBSEL
|
|
|
|
ldx #0
|
|
@zero_oam:
|
|
stz oam_lo_buffer, x
|
|
inx
|
|
cpx #(oam_buffer_end - oam_lo_buffer)
|
|
bne @zero_oam
|
|
|
|
lda #%10000001
|
|
sta NMITIMEN
|
|
|
|
mainloop:
|
|
|
|
lda nmi_count
|
|
nmi_check:
|
|
wai
|
|
cmp nmi_count
|
|
beq nmi_check
|
|
|
|
; set sprite 0 X position
|
|
ldx #$42
|
|
stx oam_lo_buffer
|
|
|
|
; set sprite 0 Y position
|
|
ldx #$69
|
|
stx oam_lo_buffer + 1
|
|
; Set sprite 0 to priority 3 and tile 0x01
|
|
ldx #((%00110000 << 8) | $0001)
|
|
stx oam_lo_buffer + 2
|
|
|
|
; Set sprite 0 to be large (16x16)
|
|
lda #%00000010
|
|
sta oam_hi_buffer
|
|
|
|
; Copy OAM data via DMA
|
|
stz OAMADDL
|
|
lda #$0
|
|
sta DMAP1
|
|
lda #<OAMDATA
|
|
sta BBAD1
|
|
ldx #.loword(oam_lo_buffer)
|
|
stx A1B1
|
|
ldx #(oam_buffer_end - oam_lo_buffer)
|
|
stx DAS1L
|
|
lda #%00000010
|
|
sta MDMAEN
|
|
|
|
|
|
|
|
lda JOY1L
|
|
bit #JOYL_L
|
|
beq down_not_pressed
|
|
; write tile 2 to position (4, 8)
|
|
TILE_X2= 4
|
|
TILE_Y2= 8
|
|
ldx #(VRAM_BG1 + (TILE_Y2* 32) + TILE_X2)
|
|
stx VMADDL
|
|
lda #$02
|
|
sta VMDATAL
|
|
stz VMDATAH
|
|
down_not_pressed:
|
|
|
|
bra mainloop
|
|
|
|
busywait:
|
|
bra busywait
|
|
|
|
nmi:
|
|
bit RDNMI
|
|
inc nmi_count
|
|
_rti:
|
|
rti
|
|
|
|
.include "charset.asm"
|