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.
 
 
 
 

212 lines
2.9 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 map state
xor a
ld [PENDING_ROW_PTR], a
ld [PENDING_ROW_PTR + 1], a
ld [PENDING_COL_PTR], a
ld [PENDING_COL_PTR + 1], a
call scroll_update
; wait for vblank
halt
call Map_Update
; ~160 cycles
ld a, HIGH(_OAM)
call DMA_Start
jp .loop
; TODO: remove once scrolling is implemented
scroll_update:
; 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
ret z
.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
ret
.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
ret z
.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
ret
.right:
ld a, [keys]
and PADF_RIGHT
jr z, .left
; don't scroll right if on last tile
ld hl, rSCX
ld a, [hl]
and %111
jr nz, .update_right
ld a, [CURRENT_MAP_WIDTH]
ld b, a
ld a, [CURRENT_CAMERA_X]
add SCRN_X_B
cp b
ret z
.update_right:
ld hl, rSCX
inc [hl]
ld a, [hl]
and %111
jr nz, .update_right_map
ld a, [CURRENT_CAMERA_X]
inc a
ld [CURRENT_CAMERA_X], a
.update_right_map:
call Map_Scroll
ret
.left:
ld a, [keys]
and PADF_LEFT
ret z
; don't scroll left if on last tile
ld hl, rSCX
ld a, [hl]
and %111
jr nz, .update_left
ld hl, CURRENT_CAMERA_X
ld a, [hl]
or a
ret z
.update_left:
ld hl, rSCX
dec [hl]
ld a, [hl]
and %111
cp %111
jr nz, .update_left_map
ld a, [CURRENT_CAMERA_X]
dec a
ld [CURRENT_CAMERA_X], a
.update_left_map:
call Map_Scroll
ret