nes/main.s

170 lines
2.3 KiB
ArmAsm

.segment "HEADER"
.byte $4E, $45, $53, $1A ;Nes header identifier
.byte 2 ;2x 16KB PRG code
.byte 1 ; 1x 8KB CHR Data
.byte $01, $00 ; mapper 0, vertical mirroring
.segment "VECTORS"
.addr nmi ; nmi interrupt
.addr reset ; reset interrupt
.addr 0 ; external interrupt
.segment "STARTUP"
.segment "ZEROPAGE"
InNum: .res 1
BCD: .res 2
TMP: .res 1
NUM: .res 1
.segment "CHARS"
.incbin "./CHR-ROM.bin"
.segment "CODE"
bg_pallets:
.byte $0F, $30, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
double_dabble:
lda #0
sta BCD
sta BCD+1
ldx #8
dabble:
; check first digit
lda BCD
and #$F
jsr check
sta TMP
lda #$F0
and BCD
ora TMP
sta BCD
; check second digit
lda BCD
and #$F0
lsr
lsr
lsr
lsr
jsr check
asl
asl
asl
asl
sta TMP
lda #$F
and BCD
ora TMP
sta BCD
; check third digit
lda BCD+1
and #$F
jsr check
sta TMP
lda #$F0
and BCD+1
ora TMP
sta BCD+1
; Shift
clc
rol InNum
rol BCD
rol BCD+1
dex
bne dabble
rts
check:
cmp #5
bcc skip
clc
adc #3
skip:
rts
reset:
sei
cld
ldx #$40
stx $4017
ldx #$ff
txs
inx
stx $2000
stx $2001
stx $4010
vblankwait1:
bit $2002
bpl vblankwait1
clear_memory:
lda #$00
sta $0000, x
sta $0100, x
sta $0200, x
sta $0300, x
sta $0400, x
sta $0500, x
sta $0600, x
sta $0700, x
inx
bne clear_memory
ldx #0
vblankwait2:
bit $2002
bpl vblankwait2
main:
lda $2002
lda #$3F
sta $2006
lda #$00
sta $2006
loop:
lda bg_pallets, x
sta $2007
inx
cpx #2
bne loop
lda #54
sta $00
lda #%10000000
sta $2000
lda #%00001010
sta $2001
forever:
jmp forever
nmi:
inc NUM
lda NUM
sta InNum
jsr double_dabble
lda $2002
lda #$20
sta $2006
lda #$20
sta $2006
lda BCD+1
and #$F
cmp #0
bne :+
lda #10
: sta $2007
lda BCD
and #$F0
lsr
lsr
lsr
lsr
cmp #0
bne :+
lda #10
: sta $2007
lda BCD
and #$F
cmp #0
bne :+
lda #10
: sta $2007
lda #0
sta $2005
sta $2005
rti