Skip to content

Commit

Permalink
consistency and optimization improvement (#87)
Browse files Browse the repository at this point in the history
* Update GalacticArmada.asm - optimizations and consistency

* Update gameplay-background.asm

* Update gameplay-background.asm

* Update gameplay-state.asm

* Update hud.asm

* Update hud.asm

* Update interrupts.asm

* Update player.asm

* Update enemies.asm

* Update bullets.asm

* Update enemy-player-collision.asm

* Update enemy-bullet-collision.asm

* Update entry-point.md

* Update story-state.asm

* Update story-state.asm

* Update title-screen-state.asm

* Update vblank-utils.asm

* Update background-utils.asm

* Update collision-utils.asm

* Update input-utils.asm

* Update math.asm

* Update memory-utils.asm

* Update metasprites.asm

* Update sprites-utils.asm

* Update text-utils.asm
  • Loading branch information
win-ini committed Apr 17, 2024
1 parent 34b165c commit db9eb64
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 285 deletions.
33 changes: 15 additions & 18 deletions galactic-armada/src/main/GalacticArmada.asm
Expand Up @@ -19,10 +19,9 @@ EntryPoint:
; ANCHOR: entry-point-end
; Shut down audio circuitry
ld a, 0
xor a
ld [rNR52], a

ld a, 0
; We don't actually need another xor a here, because the value of A doesn't change between these two instructions
ld [wGameState], a

; Wait for the vertical blank phase before initiating the library
Expand All @@ -34,7 +33,7 @@ EntryPoint:
call InitSprObjLibWrapper

; Turn the LCD off
ld a, 0
xor a
ld [rLCDC], a

; Load our common text font into VRAM
Expand All @@ -47,7 +46,6 @@ EntryPoint:
; During the first (blank) frame, initialize display registers
ld a, %11100100
ld [rBGP], a
ld a, %11100100
ld [rOBP0], a

; ANCHOR_END: entry-point-end
Expand All @@ -58,18 +56,17 @@ NextGameState::
; Do not turn the LCD off outside of VBlank
call WaitForOneVBlank

call ClearBackground;
call ClearBackground


; Turn the LCD off
ld a, 0
xor a
ld [rLCDC], a

ld a, 0
ld [rSCX],a
ld [rSCY],a
ld [rWX],a
ld [rWY],a
ld [rSCX], a
ld [rSCY], a
ld [rWX], a
ld [rWY], a
; disable interrupts
call DisableInterrupts
Expand All @@ -78,21 +75,21 @@ NextGameState::

; Initiate the next state
ld a, [wGameState]
cp a, 2 ; 2 = Gameplay
cp 2 ; 2 = Gameplay
call z, InitGameplayState
ld a, [wGameState]
cp a, 1 ; 1 = Story
cp 1 ; 1 = Story
call z, InitStoryState
ld a, [wGameState]
cp a, 0 ; 0 = Menu
and a ; 0 = Menu
call z, InitTitleScreenState

; Update the next state
ld a, [wGameState]
cp a, 2 ; 2 = Gameplay
cp 2 ; 2 = Gameplay
jp z, UpdateGameplayState
cp a, 1 ; 1 = Story
cp 1 ; 1 = Story
jp z, UpdateStoryState
jp UpdateTitleScreenState

; ANCHOR_END: next-game-state
; ANCHOR_END: next-game-state
27 changes: 12 additions & 15 deletions galactic-armada/src/main/states/gameplay/gameplay-background.asm
Expand Up @@ -28,11 +28,9 @@ InitializeBackground::
ld bc, starFieldMapEnd - starFieldMap
call CopyDEintoMemoryAtHL_With52Offset

ld a, 0
ld [mBackgroundScroll+0],a
ld a, 0
ld [mBackgroundScroll+1],a

xor a
ld [mBackgroundScroll], a
ld [mBackgroundScroll+1], a
ret
; ANCHOR_END: gameplay-background-initialize

Expand All @@ -42,13 +40,13 @@ UpdateBackground::

; Increase our scaled integer by 5
; Get our true (non-scaled) value, and save it for later usage in bc
ld a , [mBackgroundScroll+0]
add a , 5
ld b,a
ld [mBackgroundScroll+0], a
ld a , [mBackgroundScroll+1]
adc a , 0
ld c,a
ld a, [mBackgroundScroll]
add a, 5
ld b, a
ld [mBackgroundScroll], a
ld a, [mBackgroundScroll+1]
adc 0
ld c, a
ld [mBackgroundScroll+1], a
; ANCHOR_END: gameplay-background-update-start

Expand All @@ -65,8 +63,7 @@ UpdateBackground::
rr b

; Use the de-scaled low byte as the backgrounds position
ld a,b
ld a, b
ld [rSCY], a

ret
; ANCHOR_END: gameplay-background-update-end
; ANCHOR_END: gameplay-background-update-end
14 changes: 7 additions & 7 deletions galactic-armada/src/main/states/gameplay/gameplay-state.asm
Expand Up @@ -17,10 +17,10 @@ wLivesText:: db "lives", 255
InitGameplayState::

ld a, 3
ld [wLives+0], a
ld [wLives], a

ld a, 0
ld [wScore+0], a
xor a
ld [wScore], a
ld [wScore+1], a
ld [wScore+2], a
ld [wScore+3], a
Expand All @@ -44,7 +44,7 @@ InitGameplayState::
call DrawTextTilesLoop

; Call Our function that draws text onto background/window tiles
ld de, $9c0D
ld de, $9c0d
ld hl, wLivesText
call DrawTextTilesLoop
Expand All @@ -64,7 +64,7 @@ InitGameplayState::
ld a, LCDCF_ON | LCDCF_BGON|LCDCF_OBJON | LCDCF_OBJ16 | LCDCF_WINON | LCDCF_WIN9C00|LCDCF_BG9800
ld [rLCDC], a

ret;
ret
; ANCHOR_END: init-gameplay-state
; ANCHOR: update-gameplay-state-start
Expand Down Expand Up @@ -102,7 +102,7 @@ UpdateGameplayState::

; ANCHOR: update-gameplay-end-update
ld a, [wLives]
cp a, 250
cp 250
jp nc, EndGameplay

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand All @@ -127,4 +127,4 @@ EndGameplay:
ld a, 0
ld [wGameState],a
jp NextGameState
; ANCHOR_END: update-gameplay-end-update
; ANCHOR_END: update-gameplay-end-update
19 changes: 8 additions & 11 deletions galactic-armada/src/main/states/gameplay/hud.asm
Expand Up @@ -18,19 +18,18 @@ IncreaseScore_Loop:
ld [hl], a

; Stop if it hasn't gone past 0
cp a, 9
cp 9
ret c

; If it HAS gone past 9
IncreaseScore_Next:

; Increase a counter so we can not go out of our scores bounds
inc c
ld a, c
inc a
ld c, a

; Check if we've gone our o our scores bounds
cp a, 6
; Check if we've gone over our scores bounds
cp 6
ret z

; Reset the current digit to zero
Expand All @@ -50,7 +49,7 @@ DrawLives::
ld de, $9C13 ; The window tilemap starts at $9C00

ld a, [hl]
add a, 10 ; our numeric tiles start at tile 10, so add to 10 to each bytes value
add 10 ; our numeric tiles start at tile 10, so add 10 to each bytes value
ld [de], a

ret
Expand All @@ -68,13 +67,11 @@ DrawScore::
DrawScore_Loop:

ld a, [hli]
add a, 10 ; our numeric tiles start at tile 10, so add to 10 to each bytes value
add 10 ; our numeric tiles start at tile 10, so add to 10 to each bytes value
ld [de], a

; Decrease how many numbers we have drawn
ld a, c
dec a
ld c, a
dec c
; Stop when we've drawn all the numbers
ret z
Expand All @@ -83,4 +80,4 @@ DrawScore_Loop:
inc de

jp DrawScore_Loop
; ANCHOR_END: hud-draw-score
; ANCHOR_END: hud-draw-score
12 changes: 6 additions & 6 deletions galactic-armada/src/main/states/gameplay/interrupts.asm
Expand Up @@ -5,7 +5,7 @@ INCLUDE "src/main/utils/hardware.inc"
SECTION "Interrupts", ROM0

DisableInterrupts::
ld a, 0
xor a
ldh [rSTAT], a
di
ret
Expand All @@ -14,7 +14,7 @@ InitStatInterrupts::

ld a, IEF_STAT
ldh [rIE], a
xor a, a ; This is equivalent to `ld a, 0`!
xor a
ldh [rIF], a
ei

Expand All @@ -24,7 +24,7 @@ InitStatInterrupts::

; We'll start with the first scanline
; The first stat interrupt will call the next time rLY = 0
ld a, 0
xor a
ldh [rLYC], a

ret
Expand All @@ -39,13 +39,13 @@ StatInterrupt:

; Check if we are on the first scanline
ldh a, [rLYC]
cp 0
and a
jp z, LYCEqualsZero

LYCEquals8:

; Don't call the next stat interrupt until scanline 8
ld a, 0
xor a
ldh [rLYC], a

; Turn the LCD on including sprites. But no window
Expand All @@ -70,4 +70,4 @@ EndStatInterrupts:
pop af

reti;
; ANCHOR_END: interrupts-section
; ANCHOR_END: interrupts-section

0 comments on commit db9eb64

Please sign in to comment.