Skip to content

Commit db9eb64

Browse files
consistency and optimization improvement (#87)
* 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
1 parent 34b165c commit db9eb64

22 files changed

+263
-285
lines changed

galactic-armada/src/main/GalacticArmada.asm

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ EntryPoint:
1919
2020
; ANCHOR: entry-point-end
2121
; Shut down audio circuitry
22-
ld a, 0
22+
xor a
2323
ld [rNR52], a
24-
25-
ld a, 0
24+
; We don't actually need another xor a here, because the value of A doesn't change between these two instructions
2625
ld [wGameState], a
2726

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

3635
; Turn the LCD off
37-
ld a, 0
36+
xor a
3837
ld [rLCDC], a
3938

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

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

61-
call ClearBackground;
59+
call ClearBackground
6260

6361

6462
; Turn the LCD off
65-
ld a, 0
63+
xor a
6664
ld [rLCDC], a
6765

68-
ld a, 0
69-
ld [rSCX],a
70-
ld [rSCY],a
71-
ld [rWX],a
72-
ld [rWY],a
66+
ld [rSCX], a
67+
ld [rSCY], a
68+
ld [rWX], a
69+
ld [rWY], a
7370
; disable interrupts
7471
call DisableInterrupts
7572
@@ -78,21 +75,21 @@ NextGameState::
7875

7976
; Initiate the next state
8077
ld a, [wGameState]
81-
cp a, 2 ; 2 = Gameplay
78+
cp 2 ; 2 = Gameplay
8279
call z, InitGameplayState
8380
ld a, [wGameState]
84-
cp a, 1 ; 1 = Story
81+
cp 1 ; 1 = Story
8582
call z, InitStoryState
8683
ld a, [wGameState]
87-
cp a, 0 ; 0 = Menu
84+
and a ; 0 = Menu
8885
call z, InitTitleScreenState
8986

9087
; Update the next state
9188
ld a, [wGameState]
92-
cp a, 2 ; 2 = Gameplay
89+
cp 2 ; 2 = Gameplay
9390
jp z, UpdateGameplayState
94-
cp a, 1 ; 1 = Story
91+
cp 1 ; 1 = Story
9592
jp z, UpdateStoryState
9693
jp UpdateTitleScreenState
9794

98-
; ANCHOR_END: next-game-state
95+
; ANCHOR_END: next-game-state

galactic-armada/src/main/states/gameplay/gameplay-background.asm

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ InitializeBackground::
2828
ld bc, starFieldMapEnd - starFieldMap
2929
call CopyDEintoMemoryAtHL_With52Offset
3030

31-
ld a, 0
32-
ld [mBackgroundScroll+0],a
33-
ld a, 0
34-
ld [mBackgroundScroll+1],a
35-
31+
xor a
32+
ld [mBackgroundScroll], a
33+
ld [mBackgroundScroll+1], a
3634
ret
3735
; ANCHOR_END: gameplay-background-initialize
3836

@@ -42,13 +40,13 @@ UpdateBackground::
4240

4341
; Increase our scaled integer by 5
4442
; Get our true (non-scaled) value, and save it for later usage in bc
45-
ld a , [mBackgroundScroll+0]
46-
add a , 5
47-
ld b,a
48-
ld [mBackgroundScroll+0], a
49-
ld a , [mBackgroundScroll+1]
50-
adc a , 0
51-
ld c,a
43+
ld a, [mBackgroundScroll]
44+
add a, 5
45+
ld b, a
46+
ld [mBackgroundScroll], a
47+
ld a, [mBackgroundScroll+1]
48+
adc 0
49+
ld c, a
5250
ld [mBackgroundScroll+1], a
5351
; ANCHOR_END: gameplay-background-update-start
5452

@@ -65,8 +63,7 @@ UpdateBackground::
6563
rr b
6664

6765
; Use the de-scaled low byte as the backgrounds position
68-
ld a,b
66+
ld a, b
6967
ld [rSCY], a
70-
7168
ret
72-
; ANCHOR_END: gameplay-background-update-end
69+
; ANCHOR_END: gameplay-background-update-end

galactic-armada/src/main/states/gameplay/gameplay-state.asm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ wLivesText:: db "lives", 255
1717
InitGameplayState::
1818

1919
ld a, 3
20-
ld [wLives+0], a
20+
ld [wLives], a
2121

22-
ld a, 0
23-
ld [wScore+0], a
22+
xor a
23+
ld [wScore], a
2424
ld [wScore+1], a
2525
ld [wScore+2], a
2626
ld [wScore+3], a
@@ -44,7 +44,7 @@ InitGameplayState::
4444
call DrawTextTilesLoop
4545

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

67-
ret;
67+
ret
6868
; ANCHOR_END: init-gameplay-state
6969
7070
; ANCHOR: update-gameplay-state-start
@@ -102,7 +102,7 @@ UpdateGameplayState::
102102

103103
; ANCHOR: update-gameplay-end-update
104104
ld a, [wLives]
105-
cp a, 250
105+
cp 250
106106
jp nc, EndGameplay
107107

108108
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -127,4 +127,4 @@ EndGameplay:
127127
ld a, 0
128128
ld [wGameState],a
129129
jp NextGameState
130-
; ANCHOR_END: update-gameplay-end-update
130+
; ANCHOR_END: update-gameplay-end-update

galactic-armada/src/main/states/gameplay/hud.asm

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@ IncreaseScore_Loop:
1818
ld [hl], a
1919

2020
; Stop if it hasn't gone past 0
21-
cp a, 9
21+
cp 9
2222
ret c
2323

2424
; If it HAS gone past 9
2525
IncreaseScore_Next:
2626

2727
; Increase a counter so we can not go out of our scores bounds
28+
inc c
2829
ld a, c
29-
inc a
30-
ld c, a
3130

32-
; Check if we've gone our o our scores bounds
33-
cp a, 6
31+
; Check if we've gone over our scores bounds
32+
cp 6
3433
ret z
3534

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

5251
ld a, [hl]
53-
add a, 10 ; our numeric tiles start at tile 10, so add to 10 to each bytes value
52+
add 10 ; our numeric tiles start at tile 10, so add 10 to each bytes value
5453
ld [de], a
5554

5655
ret
@@ -68,13 +67,11 @@ DrawScore::
6867
DrawScore_Loop:
6968

7069
ld a, [hli]
71-
add a, 10 ; our numeric tiles start at tile 10, so add to 10 to each bytes value
70+
add 10 ; our numeric tiles start at tile 10, so add to 10 to each bytes value
7271
ld [de], a
7372

7473
; Decrease how many numbers we have drawn
75-
ld a, c
76-
dec a
77-
ld c, a
74+
dec c
7875
7976
; Stop when we've drawn all the numbers
8077
ret z
@@ -83,4 +80,4 @@ DrawScore_Loop:
8380
inc de
8481

8582
jp DrawScore_Loop
86-
; ANCHOR_END: hud-draw-score
83+
; ANCHOR_END: hud-draw-score

galactic-armada/src/main/states/gameplay/interrupts.asm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ INCLUDE "src/main/utils/hardware.inc"
55
SECTION "Interrupts", ROM0
66

77
DisableInterrupts::
8-
ld a, 0
8+
xor a
99
ldh [rSTAT], a
1010
di
1111
ret
@@ -14,7 +14,7 @@ InitStatInterrupts::
1414

1515
ld a, IEF_STAT
1616
ldh [rIE], a
17-
xor a, a ; This is equivalent to `ld a, 0`!
17+
xor a
1818
ldh [rIF], a
1919
ei
2020

@@ -24,7 +24,7 @@ InitStatInterrupts::
2424

2525
; We'll start with the first scanline
2626
; The first stat interrupt will call the next time rLY = 0
27-
ld a, 0
27+
xor a
2828
ldh [rLYC], a
2929

3030
ret
@@ -39,13 +39,13 @@ StatInterrupt:
3939

4040
; Check if we are on the first scanline
4141
ldh a, [rLYC]
42-
cp 0
42+
and a
4343
jp z, LYCEqualsZero
4444

4545
LYCEquals8:
4646

4747
; Don't call the next stat interrupt until scanline 8
48-
ld a, 0
48+
xor a
4949
ldh [rLYC], a
5050

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

7272
reti;
73-
; ANCHOR_END: interrupts-section
73+
; ANCHOR_END: interrupts-section

0 commit comments

Comments
 (0)