You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

161 lines
2.2 KiB

INCLUDE "hardware.inc"
INCLUDE "util.inc"
SECTION "Header", ROM0[$100]
_entry:
di
jp start
rept $150 - _entry
db 0
endr
SECTION "Frame", WRAM0
frame:: db
SECTION "VBlank", ROM0[$40]
handle_vblank:
reti
SECTION "Code", ROM0
start:
ld hl, rLCDC
res 7, [hl]
res 2, [hl]
ld hl, rIE
ld [hl], IEF_VBLANK
call OAM_Init
; call Keys_Init
; call Player_Init
ld hl, intro_Data
call Map_Load
; set palette
ld a, %11100100
ld hl, rOBP0
ld [hl], a
ld hl, rBGP
ld [hl], a
; enable lcd, sprites and interrupts
ld hl, rLCDC
set 7, [hl]
set 1, [hl]
ei
.loop:
ld hl, frame
inc [hl]
call Keys_Update
; Clear pending row state
xor a
ld [PENDING_ROW_PTR], a
ld [PENDING_ROW_PTR + 1], a
; TODO: remove once scrolling is implemented
; scroll map with arrow keys
ld a, [keys]
and PADF_UP
jr z, .down
; don't scroll up if on last tile
ld hl, rSCY
ld a, [hl]
and %111
jr nz, .update_up
ld hl, CURRENT_CAMERA_Y
ld a, [hl]
or a
jr z, .vbl
.update_up:
ld hl, rSCY
dec [hl]
ld a, [hl]
and %111
cp %111
jr nz, .update_up_map
ld a, [CURRENT_CAMERA_Y]
dec a
ld [CURRENT_CAMERA_Y], a
.update_up_map:
call Map_Scroll
jr .vbl
.down:
ld a, [keys]
and PADF_DOWN
jr z, .right
; don't scroll down if on last tile
ld a, [rSCY]
and %111
jr nz, .update_down
ld a, [CURRENT_MAP_HEIGHT]
ld b, a
ld a, [CURRENT_CAMERA_Y]
add 18
cp b
jr z, .vbl
.update_down:
ld hl, rSCY
inc [hl]
ld a, [hl]
and %111
jr nz, .update_down_map
ld a, [CURRENT_CAMERA_Y]
inc a
ld [CURRENT_CAMERA_Y], a
.update_down_map:
call Map_Scroll
jr .vbl
.right:
ld a, [keys]
and PADF_RIGHT
jr z, .left
ld hl, rSCX
inc [hl]
call Map_Scroll
.left:
ld a, [keys]
and PADF_LEFT
jr z, .vbl
ld hl, rSCX
dec [hl]
call Map_Scroll
; call Player_Update
; wait for vblank
.vbl:
halt
call Map_Update
; ~160 cycles
ld a, HIGH(_OAM)
call DMA_Start
jp .loop