diff --git a/src/main.s b/src/main.s index d6f8b9e..fc57d94 100644 --- a/src/main.s +++ b/src/main.s @@ -13,13 +13,40 @@ endr SECTION "Code", ROM0 start: + ld hl, rLCDC + res 7, [hl] + res 2, [hl] + + ; set tilemap to tile index 1 + ld hl, _SCRN0 + ld a, 1 + ld c, 32 +.loop0: + ld b, 32 +.loop1 + ld [hli], a + dec b + jr nz, .loop1 + dec c + jr nz, .loop0 + + ; clear 2nd sprite + ld hl, _VRAM + 16 + ld a, 0 + ld c, 16 + call memset + call PlayerInit - ; enable lcd and interrupts + ; enable lcd, sprites and interrupts ld hl, rLCDC set 7, [hl] + set 1, [hl] ei + ld hl, rOBP0 + ld [hl], %11100100 + .vbl: ld a, [$ff41] and 3 diff --git a/src/player.s b/src/player.s index 37f8236..bb21619 100644 --- a/src/player.s +++ b/src/player.s @@ -6,8 +6,9 @@ playerWorldX: dw playerWorldY: dw ; Sprite data -playerScreenX: db +playerSprite: playerScreenY: db +playerScreenX: db playerTileIndex: db playerFlags: db @@ -21,19 +22,22 @@ PlayerInit:: ld hl, playerScreenX ld [hl], a - ld bc, _VRAM8800 + ld bc, _VRAM8000 ld hl, spriteData ld d, 16 call memcpy - ld hl, playerScreenX + ld hl, playerSprite + ld a, 144-8 + ld [hli], a ld a, 8 ld [hli], a - ld a, 144-8*3 + xor a + ld [hli], a ld [hli], a ld bc, _OAMRAM - ld hl, playerScreenX + ld hl, playerSprite ld d, 4 call memcpy diff --git a/src/util.s b/src/util.s index b2e3945..18aed71 100644 --- a/src/util.s +++ b/src/util.s @@ -11,3 +11,13 @@ memcpy:: dec d jr nz, memcpy ret + +; Fills a memory region with a value +; @param hl Pointer to the destination region +; @param a Byte to fill with +; @param c Number of bytes to fill. Must be >0 +memset:: + ld [hli], a + dec c + jr nz, memset + ret