;
;
BUILD_CHESS equ 1
BUILD_LOGO equ 2
BUILD = BUILD_LOGO
;
include "hw.inc"
xoffs_center equ 4
yoffs_center equ 12
frame equ $ff80
bnstate equ $ff81
bnxor equ $ff82
pause equ $ff83
BN_A equ $01
BN_B equ $02
BN_SELECT equ $04
BN_START equ $08
BN_RIGHT equ $10
BN_LEFT equ $20
BN_UP equ $40
BN_DOWN equ $80
section "hdr", ROM0[$100]
nop
jp main
rept $150 - $104
db 0
endr
section "text", ROM0
main:
call init
xor a, a
ldh [frame], a
ldh [bnstate], a
ldh [bnxor], a
ldh [pause], a
.mainloop:
ldh a, [REG_LY]
cp a, 144
jr c, .wait_hsync
;
;
call read_input
;
ldh a, [bnxor]
and a, BN_A
jr z, .skip_akey ;
ldh a, [bnstate]
and a, BN_A
jr z, .skip_akey ;
ldh a, [REG_BGP]
cpl
ldh [REG_BGP], a
.skip_akey:
;
ldh a, [bnxor]
and a, BN_START
jr z, .skip_startkey ;
ldh a, [bnstate]
and a, BN_START
jr z, .skip_startkey ;
ldh a, [pause]
cpl
ldh [pause], a
.skip_startkey:
;
ldh a, [pause]
bit 0, a
jr nz, .skip_frameinc
ldh a, [frame]
inc a
ldh [frame], a
.skip_frameinc:
.wait_newframe:
ldh a, [REG_LY]
cp a, 0
jr nz, .wait_newframe
;
.wait_hsync:
ldh a, [REG_STAT]
and a, STAT_MODE_MASK
jr nz, .wait_hsync
ldh a, [frame]
ld d, a
xor a, a
ld b, a
ldh a, [REG_LY]
add a, d ;
ld c, a
ld hl, sintab
add hl, bc ;
ld a, [hl]
;
ld e, a ;
sla d
ld a, [REG_LY]
sla a
add a, d
ld c, a
srl d
ld hl, sintab
add hl, bc
ld a, [hl]
sra a
add a, e ;
add a, yoffs_center
ldh [REG_SCY], a
;
ld a, d
sla a
ld d, a
ldh a, [REG_LY]
add a, 32
add a, d ;
ld c, a
ld hl, sintab
add hl, bc
ld a, [hl]
sra a
add a, xoffs_center
ldh [REG_SCX], a
;
.wait_endhsync:
ldh a, [REG_STAT]
and a, STAT_MODE_MASK
jr z, .wait_endhsync
jp .mainloop
di
.end: halt
nop
jp .end
init:
call wait_vsync
xor a, a
ldh [REG_LCDC], a
;
ld a, $1b
ldh [REG_BGP], a
;
ld hl, $8000
ld de, tiles
ld bc, tiles_end - tiles
.copytiles:
ld a, [de]
ld [hl+], a
inc de
dec bc
ld a, b
or c
jp nz, .copytiles
IF BUILD == BUILD_LOGO
;
ld hl, $9800
ld de, tilemap
ld b, 21
.copymap:
ld c, 21
.copymaprow:
ld a, [de]
inc de
ld [hl+], a
dec c
jr nz, .copymaprow
push bc
ld bc, 11
add hl, bc
pop bc
dec b
jr nz, .copymap
ELSE
;
ld hl, $9800
ld b, 32
.fillscr:
ld c, 32
.fillrow:
ld a, b
add a, c
and a, 1
ld [hl+], a
dec c
jr nz, .fillrow
dec b
jr nz, .fillscr
ENDC
;
ld a, yoffs_center
ldh [REG_SCY], a
ld a, xoffs_center
ldh [REG_SCX], a
;
ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON
ldh [REG_LCDC], a
ret
wait_vsync:
ldh a, [REG_LY]
cp a, 144
jr c, wait_vsync
ret
read_input:
;
ld a, P1_DPAD
ld [REG_P1], a
ld a, [REG_P1]
ld a, [REG_P1]
cpl
and a, $0f
swap a
ld b, a
;
ld a, P1_BUTTONS
ld [REG_P1], a
ld a, [REG_P1]
ld a, [REG_P1]
ld a, [REG_P1]
ld a, [REG_P1]
ld a, [REG_P1]
ld a, [REG_P1]
cpl
and a, $0f
or a, b
ld b, a
;
ld a, P1_DPAD | P1_BUTTONS
ldh [REG_P1], a
;
ldh a, [bnstate]
xor a, b
ldh [bnxor], a
ld a, b
ldh [bnstate], a
ret
section "data", ROM0, align[8]
sintab:
include "sin.inc"
IF BUILD == BUILD_LOGO
tiles:
incbin "logo.tiles"
tiles_end:
tilemap:
incbin "logo.tilemap"
tilemap_end:
ELSE
;
tiles:
db $ff,$00
db $81,$00
db $81,$00
db $81,$00
db $81,$00
db $81,$00
db $81,$00
db $ff,$00
db $00,$ff
db $7e,$ff
db $7e,$ff
db $7e,$ff
db $7e,$ff
db $7e,$ff
db $7e,$ff
db $00,$ff
tiles_end:
ENDC