feat: add Memset, clear memory at init

main
Louis Pearson 2024-04-19 19:00:23 -06:00
parent 2ab08f6447
commit 8471b51a4a
1 changed files with 84 additions and 58 deletions

142
main.asm
View File

@ -27,13 +27,13 @@ WaitVBlank:
call InitSprObjLib
; Reset hardware OAM
xor a, a
ld a, 0
ld b, 160
ld hl, _OAMRAM
.resetOAM
ld [hli], a
dec b
jr nz, .resetOAM
jp nz, .resetOAM
; Copy cat sprite
ld de, GfxCat
@ -42,47 +42,15 @@ WaitVBlank:
call Memcopy
; Reset positions
ld hl, wMetaspritePosition.x
ld a, $10
ld d, 0
ld hl, wMetaspriteBegin
ld bc, wMetaspriteEnd - wMetaspriteBegin
call Memset
; Clear player data
ld a, $F0
ld [wMetaspritePosition.x], a
ld a, $0
ld [wMetaspritePosition.x + 1], a
ld hl, wMetaspritePosition.y
ld a, $10
ld [wMetaspritePosition.y], a
ld a, $01
ld [wMetaspritePosition.y + 1], a
ld hl, wMetaspritePosition.z
ld a, $00
ld [wMetaspritePosition.z], a
ld a, $0
ld [wMetaspritePosition.z + 1], a
; Reset velocity
ld hl, wMetaspriteVelocity.x
ld a, $0
ld [wMetaspriteVelocity.x], a
ld a, $0
ld [wMetaspriteVelocity.x + 1], a
ld hl, wMetaspriteVelocity.y
ld a, $0
ld [wMetaspriteVelocity.y], a
ld a, $0
ld [wMetaspriteVelocity.y + 1], a
ld hl, wMetaspriteVelocity.z
ld a, $0
ld [wMetaspriteVelocity.z], a
ld a, $0
ld [wMetaspriteVelocity.z + 1], a
ld hl, wMetaspriteVelocity.boost
ld a, $0
ld [wMetaspriteVelocity.boost], a
ld [wMetaspriteVelocity.boosting], a
; Copy the tile data
ld de, Tiles
@ -90,12 +58,17 @@ WaitVBlank:
ld bc, TilesEnd - Tiles
call Memcopy
; Copy the tilemap
ld de, Tilemap
; Clear the tilemap
ld hl, $9800
ld bc, TilemapEnd - Tilemap
call Memcopy
ld bc, (32 * 20)
ld d, 0
call Memset
; Clear shadown OAM
ld hl, wShadowOAM
ld bc, 160
ld d, 0
call Memset
; Turn the LCD on
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON | LCDCF_OBJ8
@ -363,7 +336,7 @@ UpdateJoypadState::
ld [wJoypadState], a
ret
SECTION "MemCopy Routine", ROM0
SECTION "Memcopy Routine", ROM0
Memcopy::
dec bc
inc b
@ -378,6 +351,23 @@ Memcopy::
jr nz, .loop
ret
; @param hl - Location
; @param bc - Length
; @param d - Value
SECTION "Memset Routine", ROM0
Memset::
dec bc
inc b
inc c
.loop:
ld a, d
ld [hli], a
dec c
jr nz, .loop
dec b
jr nz, .loop
ret
SECTION "VBlank Interrupt", ROM0[$0040]
VBlankInterrupt:
; Store registers to prevent clobbering
@ -391,17 +381,6 @@ SECTION "VBlank Handler", ROM0
VBlankHandler:
ldh a, [hFrameCounter]
/*
bit 5, a
ld a, %11100100
jr z, .skipCpl
cpl ; Invert a
.skipCpl:
ldh [rBGP], a
*/
ld a, HIGH(wShadowOAM)
call hOAMDMA
@ -416,7 +395,6 @@ SECTION "Frame Counter", HRAM
hFrameCounter:
db
SECTION "Tile data", ROM0
Tiles:
@ -429,6 +407,52 @@ Tilemap:
INCBIN "tileset.tilemap"
TilemapEnd:
SECTION "Level data", ROM0
db $03 ; width
db $03 ; height
; Each byte stores whether it is solid or not
; Z = 1
db $01
db $01
db $01
db $01
db $01
db $01
db $01
db $01
db $00
; Z = 2
db $01
db $01
db $01
db $01
db $01
db $01
db $00
db $00
db $00
; Z = 3
db $01
db $00
db $00
db $00
db $00
db $00
db $00
db $00
db $00
SECTION "Graphics", ROM0
GfxCat:
INCBIN "sprites.2bpp"
@ -444,6 +468,7 @@ ShadowMetasprite:
db 128
SECTION "Position Vars", WRAM0
wMetaspriteBegin:
; Q12.4 fixed-point X posiition
wMetaspritePosition::
.x:
@ -465,6 +490,7 @@ wMetaspriteVelocity::
db
.boosting:
db
wMetaspriteEnd:
SECTION "Joypad Vars", WRAM0
wJoypadState: