Browse Source

Draw player to screen

master
Forest Belton 3 years ago
parent
commit
623661b52d
3 changed files with 47 additions and 6 deletions
  1. +28
    -1
      src/main.s
  2. +9
    -5
      src/player.s
  3. +10
    -0
      src/util.s

+ 28
- 1
src/main.s View File

@ -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

+ 9
- 5
src/player.s View File

@ -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

+ 10
- 0
src/util.s View File

@ -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

Loading…
Cancel
Save