feat: add Memset, clear memory at init
parent
2ab08f6447
commit
8471b51a4a
142
main.asm
142
main.asm
|
@ -27,13 +27,13 @@ WaitVBlank:
|
||||||
call InitSprObjLib
|
call InitSprObjLib
|
||||||
|
|
||||||
; Reset hardware OAM
|
; Reset hardware OAM
|
||||||
xor a, a
|
ld a, 0
|
||||||
ld b, 160
|
ld b, 160
|
||||||
ld hl, _OAMRAM
|
ld hl, _OAMRAM
|
||||||
.resetOAM
|
.resetOAM
|
||||||
ld [hli], a
|
ld [hli], a
|
||||||
dec b
|
dec b
|
||||||
jr nz, .resetOAM
|
jp nz, .resetOAM
|
||||||
|
|
||||||
; Copy cat sprite
|
; Copy cat sprite
|
||||||
ld de, GfxCat
|
ld de, GfxCat
|
||||||
|
@ -42,47 +42,15 @@ WaitVBlank:
|
||||||
call Memcopy
|
call Memcopy
|
||||||
|
|
||||||
; Reset positions
|
; Reset positions
|
||||||
ld hl, wMetaspritePosition.x
|
ld d, 0
|
||||||
ld a, $10
|
ld hl, wMetaspriteBegin
|
||||||
|
ld bc, wMetaspriteEnd - wMetaspriteBegin
|
||||||
|
call Memset
|
||||||
|
|
||||||
|
; Clear player data
|
||||||
|
ld a, $F0
|
||||||
ld [wMetaspritePosition.x], a
|
ld [wMetaspritePosition.x], a
|
||||||
ld a, $0
|
|
||||||
ld [wMetaspritePosition.x + 1], a
|
|
||||||
|
|
||||||
ld hl, wMetaspritePosition.y
|
|
||||||
ld a, $10
|
|
||||||
ld [wMetaspritePosition.y], a
|
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
|
; Copy the tile data
|
||||||
ld de, Tiles
|
ld de, Tiles
|
||||||
|
@ -90,12 +58,17 @@ WaitVBlank:
|
||||||
ld bc, TilesEnd - Tiles
|
ld bc, TilesEnd - Tiles
|
||||||
call Memcopy
|
call Memcopy
|
||||||
|
|
||||||
; Copy the tilemap
|
; Clear the tilemap
|
||||||
ld de, Tilemap
|
|
||||||
ld hl, $9800
|
ld hl, $9800
|
||||||
ld bc, TilemapEnd - Tilemap
|
ld bc, (32 * 20)
|
||||||
call Memcopy
|
ld d, 0
|
||||||
|
call Memset
|
||||||
|
|
||||||
|
; Clear shadown OAM
|
||||||
|
ld hl, wShadowOAM
|
||||||
|
ld bc, 160
|
||||||
|
ld d, 0
|
||||||
|
call Memset
|
||||||
|
|
||||||
; Turn the LCD on
|
; Turn the LCD on
|
||||||
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON | LCDCF_OBJ8
|
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON | LCDCF_OBJ8
|
||||||
|
@ -363,7 +336,7 @@ UpdateJoypadState::
|
||||||
ld [wJoypadState], a
|
ld [wJoypadState], a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
SECTION "MemCopy Routine", ROM0
|
SECTION "Memcopy Routine", ROM0
|
||||||
Memcopy::
|
Memcopy::
|
||||||
dec bc
|
dec bc
|
||||||
inc b
|
inc b
|
||||||
|
@ -378,6 +351,23 @@ Memcopy::
|
||||||
jr nz, .loop
|
jr nz, .loop
|
||||||
ret
|
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]
|
SECTION "VBlank Interrupt", ROM0[$0040]
|
||||||
VBlankInterrupt:
|
VBlankInterrupt:
|
||||||
; Store registers to prevent clobbering
|
; Store registers to prevent clobbering
|
||||||
|
@ -391,17 +381,6 @@ SECTION "VBlank Handler", ROM0
|
||||||
VBlankHandler:
|
VBlankHandler:
|
||||||
ldh a, [hFrameCounter]
|
ldh a, [hFrameCounter]
|
||||||
|
|
||||||
/*
|
|
||||||
bit 5, a
|
|
||||||
|
|
||||||
ld a, %11100100
|
|
||||||
|
|
||||||
jr z, .skipCpl
|
|
||||||
cpl ; Invert a
|
|
||||||
.skipCpl:
|
|
||||||
ldh [rBGP], a
|
|
||||||
*/
|
|
||||||
|
|
||||||
ld a, HIGH(wShadowOAM)
|
ld a, HIGH(wShadowOAM)
|
||||||
call hOAMDMA
|
call hOAMDMA
|
||||||
|
|
||||||
|
@ -416,7 +395,6 @@ SECTION "Frame Counter", HRAM
|
||||||
hFrameCounter:
|
hFrameCounter:
|
||||||
db
|
db
|
||||||
|
|
||||||
|
|
||||||
SECTION "Tile data", ROM0
|
SECTION "Tile data", ROM0
|
||||||
|
|
||||||
Tiles:
|
Tiles:
|
||||||
|
@ -429,6 +407,52 @@ Tilemap:
|
||||||
INCBIN "tileset.tilemap"
|
INCBIN "tileset.tilemap"
|
||||||
TilemapEnd:
|
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
|
SECTION "Graphics", ROM0
|
||||||
GfxCat:
|
GfxCat:
|
||||||
INCBIN "sprites.2bpp"
|
INCBIN "sprites.2bpp"
|
||||||
|
@ -444,6 +468,7 @@ ShadowMetasprite:
|
||||||
db 128
|
db 128
|
||||||
|
|
||||||
SECTION "Position Vars", WRAM0
|
SECTION "Position Vars", WRAM0
|
||||||
|
wMetaspriteBegin:
|
||||||
; Q12.4 fixed-point X posiition
|
; Q12.4 fixed-point X posiition
|
||||||
wMetaspritePosition::
|
wMetaspritePosition::
|
||||||
.x:
|
.x:
|
||||||
|
@ -465,6 +490,7 @@ wMetaspriteVelocity::
|
||||||
db
|
db
|
||||||
.boosting:
|
.boosting:
|
||||||
db
|
db
|
||||||
|
wMetaspriteEnd:
|
||||||
|
|
||||||
SECTION "Joypad Vars", WRAM0
|
SECTION "Joypad Vars", WRAM0
|
||||||
wJoypadState:
|
wJoypadState:
|
||||||
|
|
Loading…
Reference in New Issue