From db9eb6441878ffbb2ef11d87de611e8c6d883dae Mon Sep 17 00:00:00 2001 From: crystalmoon <138562507+sabra55@users.noreply.github.com> Date: Wed, 17 Apr 2024 20:14:37 +0200 Subject: [PATCH] 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 --- galactic-armada/src/main/GalacticArmada.asm | 33 +++---- .../states/gameplay/gameplay-background.asm | 27 +++--- .../main/states/gameplay/gameplay-state.asm | 14 +-- .../src/main/states/gameplay/hud.asm | 19 ++-- .../src/main/states/gameplay/interrupts.asm | 12 +-- .../main/states/gameplay/objects/bullets.asm | 72 +++++++-------- .../collision/enemy-bullet-collision.asm | 32 +++---- .../collision/enemy-player-collision.asm | 18 ++-- .../main/states/gameplay/objects/enemies.asm | 85 ++++++++--------- .../main/states/gameplay/objects/player.asm | 92 +++++++++---------- .../src/main/states/story/story-state.asm | 8 +- .../title-screen/title-screen-state.asm | 9 +- .../src/main/utils/background-utils.asm | 10 +- .../src/main/utils/collision-utils.asm | 19 ++-- .../src/main/utils/input-utils.asm | 10 +- galactic-armada/src/main/utils/math.asm | 12 +-- .../src/main/utils/memory-utils.asm | 12 +-- .../src/main/utils/metasprites.asm | 18 ++-- .../src/main/utils/sprites-utils.asm | 31 +++---- galactic-armada/src/main/utils/text-utils.asm | 3 +- .../src/main/utils/vblank-utils.asm | 4 +- src/part3/entry-point.md | 8 +- 22 files changed, 263 insertions(+), 285 deletions(-) diff --git a/galactic-armada/src/main/GalacticArmada.asm b/galactic-armada/src/main/GalacticArmada.asm index 7d18967b..f71fce8e 100644 --- a/galactic-armada/src/main/GalacticArmada.asm +++ b/galactic-armada/src/main/GalacticArmada.asm @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file +; ANCHOR_END: next-game-state diff --git a/galactic-armada/src/main/states/gameplay/gameplay-background.asm b/galactic-armada/src/main/states/gameplay/gameplay-background.asm index 25d3e47d..23197b07 100644 --- a/galactic-armada/src/main/states/gameplay/gameplay-background.asm +++ b/galactic-armada/src/main/states/gameplay/gameplay-background.asm @@ -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 @@ -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 @@ -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 \ No newline at end of file +; ANCHOR_END: gameplay-background-update-end diff --git a/galactic-armada/src/main/states/gameplay/gameplay-state.asm b/galactic-armada/src/main/states/gameplay/gameplay-state.asm index 2e051ba0..34466de5 100644 --- a/galactic-armada/src/main/states/gameplay/gameplay-state.asm +++ b/galactic-armada/src/main/states/gameplay/gameplay-state.asm @@ -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 @@ -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 @@ -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 @@ -102,7 +102,7 @@ UpdateGameplayState:: ; ANCHOR: update-gameplay-end-update ld a, [wLives] - cp a, 250 + cp 250 jp nc, EndGameplay ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -127,4 +127,4 @@ EndGameplay: ld a, 0 ld [wGameState],a jp NextGameState -; ANCHOR_END: update-gameplay-end-update \ No newline at end of file +; ANCHOR_END: update-gameplay-end-update diff --git a/galactic-armada/src/main/states/gameplay/hud.asm b/galactic-armada/src/main/states/gameplay/hud.asm index 8eb420cc..2b82e083 100644 --- a/galactic-armada/src/main/states/gameplay/hud.asm +++ b/galactic-armada/src/main/states/gameplay/hud.asm @@ -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 @@ -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 @@ -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 @@ -83,4 +80,4 @@ DrawScore_Loop: inc de jp DrawScore_Loop -; ANCHOR_END: hud-draw-score \ No newline at end of file +; ANCHOR_END: hud-draw-score diff --git a/galactic-armada/src/main/states/gameplay/interrupts.asm b/galactic-armada/src/main/states/gameplay/interrupts.asm index a6397742..985e5194 100644 --- a/galactic-armada/src/main/states/gameplay/interrupts.asm +++ b/galactic-armada/src/main/states/gameplay/interrupts.asm @@ -5,7 +5,7 @@ INCLUDE "src/main/utils/hardware.inc" SECTION "Interrupts", ROM0 DisableInterrupts:: - ld a, 0 + xor a ldh [rSTAT], a di ret @@ -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 @@ -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 @@ -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 @@ -70,4 +70,4 @@ EndStatInterrupts: pop af reti; -; ANCHOR_END: interrupts-section \ No newline at end of file +; ANCHOR_END: interrupts-section diff --git a/galactic-armada/src/main/states/gameplay/objects/bullets.asm b/galactic-armada/src/main/states/gameplay/objects/bullets.asm index 52ae54d0..688df09d 100644 --- a/galactic-armada/src/main/states/gameplay/objects/bullets.asm +++ b/galactic-armada/src/main/states/gameplay/objects/bullets.asm @@ -5,13 +5,13 @@ include "src/main/utils/constants.inc" SECTION "BulletVariables", WRAM0 -wSpawnBullet:db +wSpawnBullet: db ; how many bullets are currently active wActiveBulletCounter:: db ; how many bullet's we've updated -wUpdateBulletsCounter:db +wUpdateBulletsCounter: db ; Bytes: active, x , y (low), y (high) wBullets:: ds MAX_BULLET_COUNT*PER_BULLET_BYTES_COUNT @@ -31,7 +31,7 @@ bulletTileDataEnd:: ; ANCHOR: bullets-initialize InitializeBullets:: - ld a, 0 + xor a ld [wSpawnBullet], a ; Copy the bullet tile data intto vram @@ -41,31 +41,29 @@ InitializeBullets:: call CopyDEintoMemoryAtHL ; Reset how many bullets are active to 0 - ld a,0 + xor a ld [wActiveBulletCounter],a - ld b, 0 + ld b, a ld hl, wBullets + ld [hl], a InitializeBullets_Loop: - ld a, 0 - ld [hl], a - ; Increase the address ld a, l - add a, PER_BULLET_BYTES_COUNT + add PER_BULLET_BYTES_COUNT ld l, a ld a, h - adc a, 0 + adc 0 ld h, a ; Increase how many bullets we have initailized ld a, b inc a - ld b ,a + ld b, a - cp a, MAX_BULLET_COUNT + cp MAX_BULLET_COUNT ret z jp InitializeBullets_Loop @@ -78,17 +76,17 @@ UpdateBullets:: ld a, [wSpawnBullet] ld b, a ld a, [wActiveBulletCounter] - or a,b - cp a, 0 + or b + cp 0 ret z ; Reset our counter for how many bullets we have checked - ld a, 0 + xor a ld [wUpdateBulletsCounter], a ; Get the address of the first bullet in hl ld a, LOW(wBullets) - ld l, a + ld l, a ld a, HIGH(wBullets) ld h, a @@ -106,15 +104,15 @@ UpdateBullets_Loop: ; Check if we've already ld a, [wUpdateBulletsCounter] - cp a, MAX_BULLET_COUNT + cp MAX_BULLET_COUNT ret nc ; Increase the bullet data our address is pointingtwo ld a, l - add a, PER_BULLET_BYTES_COUNT + add PER_BULLET_BYTES_COUNT ld l, a ld a, h - adc a, 0 + adc 0 ld h, a ; ANCHOR_END: bullets-update-loop @@ -124,23 +122,23 @@ UpdateBullets_PerBullet: ; The first byte is if the bullet is active ; If it's NOT zero, it's active, go to the normal update section ld a, [hl] - cp a, 0 + and a jp nz, UpdateBullets_PerBullet_Normal ; Do we need to spawn a bullet? ; If we dont, loop to the next enemy ld a, [wSpawnBullet] - cp a, 0 + and a jp z, UpdateBullets_Loop UpdateBullets_PerBullet_SpawnDeactivatedBullet: ; reset this variable so we don't spawn anymore - ld a, 0 + xor a ld [wSpawnBullet], a ; Increase how many bullets are active - ld a,[wActiveBulletCounter] + ld a, [wActiveBulletCounter] inc a ld [wActiveBulletCounter], a @@ -151,7 +149,7 @@ UpdateBullets_PerBullet_SpawnDeactivatedBullet: ld [hli], a ; Get the unscaled player x position in b - ld a, [wPlayerPositionX+0] + ld a, [wPlayerPositionX] ld b, a ld a, [wPlayerPositionX+1] ld d, a @@ -172,10 +170,10 @@ UpdateBullets_PerBullet_SpawnDeactivatedBullet: ld [hli], a ; Set the y position (low) - ld a, [wPlayerPositionY+0] + ld a, [wPlayerPositionY] ld [hli], a - ;Set the y position (high) + ; Set the y position (high) ld a, [wPlayerPositionY+1] ld [hli], a @@ -194,11 +192,11 @@ UpdateBullets_PerBullet_Normal: ; get our 16-bit y position ld a, [hl] - sub a, BULLET_MOVE_SPEED + sub BULLET_MOVE_SPEED ld [hli], a ld c, a ld a, [hl] - sbc a, 0 + sbc 0 ld [hl], a ld d, a @@ -216,8 +214,8 @@ UpdateBullets_PerBullet_Normal: ; See if our non scaled low byte is above 160 ld a, c - cp a, 178 - ; If it below 160, continue on to deactivate + cp 178 + ; If it's below 160, deactivate jp nc, UpdateBullets_DeActivateIfOutOfBounds ; ANCHOR_END: bullets-update-per @@ -232,20 +230,20 @@ UpdateBullets_PerBullet_Normal: ; Save the address of the metasprite into the 'wMetaspriteAddress' variable ; Our DrawMetasprites functoin uses that variable ld a, LOW(bulletMetasprite) - ld [wMetaspriteAddress+0], a + ld [wMetaspriteAddress], a ld a, HIGH(bulletMetasprite) ld [wMetaspriteAddress+1], a ; Save the x position ld a, b - ld [wMetaspriteX],a + ld [wMetaspriteX], a ; Save the y position ld a, c - ld [wMetaspriteY],a + ld [wMetaspriteY], a ; Actually call the 'DrawMetasprites function - call DrawMetasprites; + call DrawMetasprites ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -260,7 +258,7 @@ UpdateBullets_DeActivateIfOutOfBounds: ; if it's y value is grater than 160 ; Set as inactive - ld a, 0 + xor a ld [hl], a ; Decrease counter @@ -276,7 +274,7 @@ FireNextBullet:: ; Make sure we don't have the max amount of enmies ld a, [wActiveBulletCounter] - cp a, MAX_BULLET_COUNT + cp MAX_BULLET_COUNT ret nc ; Set our spawn bullet variable to true @@ -284,4 +282,4 @@ FireNextBullet:: ld [wSpawnBullet], a ret -; ANCHOR_END: fire-bullets \ No newline at end of file +; ANCHOR_END: fire-bullets diff --git a/galactic-armada/src/main/states/gameplay/objects/collision/enemy-bullet-collision.asm b/galactic-armada/src/main/states/gameplay/objects/collision/enemy-bullet-collision.asm index 44c75ce7..6c411b61 100644 --- a/galactic-armada/src/main/states/gameplay/objects/collision/enemy-bullet-collision.asm +++ b/galactic-armada/src/main/states/gameplay/objects/collision/enemy-bullet-collision.asm @@ -16,11 +16,11 @@ CheckCurrentEnemyAgainstBullets:: ld a, l - ld [wUpdateEnemiesCurrentEnemyAddress+0], a + ld [wUpdateEnemiesCurrentEnemyAddress], a ld a, h ld [wUpdateEnemiesCurrentEnemyAddress+1], a - ld a, 0 + xor a ld [wEnemyBulletCollisionCounter], a ; Copy our bullets address into wBulletAddress @@ -41,16 +41,16 @@ CheckCurrentEnemyAgainstBullets_Loop: ld [wEnemyBulletCollisionCounter], a ; Stop if we've checked all bullets - cp a, MAX_BULLET_COUNT + cp MAX_BULLET_COUNT ret nc ; Increase the data our address is pointing to ld a, l - add a, PER_BULLET_BYTES_COUNT - ld l, a + add PER_BULLET_BYTES_COUNT + ld l, a ld a, h - adc a, 0 - ld h, a + adc 0 + ld h, a ; ANCHOR_END: enemy-bullet-collision-loop @@ -58,7 +58,7 @@ CheckCurrentEnemyAgainstBullets_Loop: CheckCurrentEnemyAgainstBullets_PerBullet: ld a, [hl] - cp a, 1 + cp 1 jp nz, CheckCurrentEnemyAgainstBullets_Loop ; ANCHOR_END: enemy-bullet-collision-per-bullet-start @@ -72,7 +72,7 @@ CheckCurrentEnemyAgainstBullets_Check_X_Overlap: ; Get our x position ld a, [hli] - add a, 4 + add 4 ld b, a push hl @@ -87,7 +87,7 @@ CheckCurrentEnemyAgainstBullets_Check_X_Overlap: ; The second value ld a, [wCurrentEnemyX] - add a, 8 + add 8 ld [wObject2Value], a ; Save if the minimum distance @@ -98,7 +98,7 @@ CheckCurrentEnemyAgainstBullets_Check_X_Overlap: ld a, [wResult] - cp a, 0 + and a jp z, CheckCurrentEnemyAgainstBullets_Check_X_Overlap_Fail @@ -164,7 +164,7 @@ CheckCurrentEnemyAgainstBullets_PerBullet_Y_Overlap: pop hl ld a, [wResult] - cp a, 0 + and a jp z, CheckCurrentEnemyAgainstBullets_Loop jp CheckCurrentEnemyAgainstBullets_PerBullet_Collision @@ -179,7 +179,7 @@ CheckCurrentEnemyAgainstBullets_PerBullet_Y_Overlap: CheckCurrentEnemyAgainstBullets_PerBullet_Collision: ; set the active byte and x value to 0 for bullets - ld a, 0 + xor a ld [hli], a ld [hl], a @@ -189,11 +189,11 @@ CheckCurrentEnemyAgainstBullets_PerBullet_Collision: ld h, a ; set the active byte and x value to 0 for enemies - ld a, 0 + xor a ld [hli], a ld [hl], a - call IncreaseScore; + call IncreaseScore call DrawScore ; Decrease how many active enemies their are @@ -207,4 +207,4 @@ CheckCurrentEnemyAgainstBullets_PerBullet_Collision: ld [wActiveBulletCounter], a ret -; ANCHOR_END: enemy-bullet-collision-per-bullet-collision \ No newline at end of file +; ANCHOR_END: enemy-bullet-collision-per-bullet-collision diff --git a/galactic-armada/src/main/states/gameplay/objects/collision/enemy-player-collision.asm b/galactic-armada/src/main/states/gameplay/objects/collision/enemy-player-collision.asm index f85217fc..869e3ea5 100644 --- a/galactic-armada/src/main/states/gameplay/objects/collision/enemy-player-collision.asm +++ b/galactic-armada/src/main/states/gameplay/objects/collision/enemy-player-collision.asm @@ -8,11 +8,11 @@ SECTION "EnemiesPlayerCollision", ROM0 CheckEnemyPlayerCollision:: ; Get our player's unscaled x position in d - ld a, [wPlayerPositionX+0] - ld d,a + ld a, [wPlayerPositionX] + ld d, a ld a, [wPlayerPositionX+1] - ld e,a + ld e, a srl e rr d @@ -44,7 +44,7 @@ CheckEnemyPlayerCollision:: call CheckObjectPositionDifference ld a, [wResult] - cp a, 0 + and a jp z, NoCollisionWithPlayer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -54,10 +54,10 @@ CheckEnemyPlayerCollision:: ; ANCHOR: get-y ; Get our player's unscaled y position in d ld a, [wPlayerPositionY+0] - ld d,a + ld d, a ld a, [wPlayerPositionY+1] - ld e,a + ld e, a srl e rr d @@ -91,7 +91,7 @@ CheckEnemyPlayerCollision:: call CheckObjectPositionDifference ld a, [wResult] - cp a, 0 + and a jp z, NoCollisionWithPlayer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -106,9 +106,9 @@ CheckEnemyPlayerCollision:: NoCollisionWithPlayer:: - ld a, 0 + xor a ld [wResult], a ret -; ANCHOR_END: result \ No newline at end of file +; ANCHOR_END: result diff --git a/galactic-armada/src/main/states/gameplay/objects/enemies.asm b/galactic-armada/src/main/states/gameplay/objects/enemies.asm index ea4a2d5c..298f5f96 100644 --- a/galactic-armada/src/main/states/gameplay/objects/enemies.asm +++ b/galactic-armada/src/main/states/gameplay/objects/enemies.asm @@ -37,34 +37,32 @@ InitializeEnemies:: ld bc, enemyShipTileDataEnd - enemyShipTileData call CopyDEintoMemoryAtHL - ld a, 0 + xor a ld [wSpawnCounter], a ld [wActiveEnemyCounter], a ld [wNextEnemyXPosition], a - ld b, 0 + ld b, a ld hl, wEnemies InitializeEnemies_Loop: ; Set as inactive - ld a, 0 - ld [hl], a + ld [hl], 0 ; Increase the address ld a, l - add a, PER_ENEMY_BYTES_COUNT + add PER_ENEMY_BYTES_COUNT ld l, a ld a, h - adc a, 0 + adc 0 ld h, a + inc b ld a, b - inc a - ld b ,a - cp a, MAX_ENEMY_COUNT + cp MAX_ENEMY_COUNT ret z jp InitializeEnemies_Loop @@ -80,11 +78,11 @@ UpdateEnemies:: ld a, [wNextEnemyXPosition] ld b, a ld a, [wActiveEnemyCounter] - or a, b - cp a, 0 + or b + and a ret z - ld a, 0 + xor a ld [wUpdateEnemiesCounter], a ld a, LOW(wEnemies) @@ -104,17 +102,16 @@ UpdateEnemies_Loop: ld [wUpdateEnemiesCounter], a ; Compare against the active count - ld a, [wUpdateEnemiesCounter] - cp a, MAX_ENEMY_COUNT + cp MAX_ENEMY_COUNT ret nc ; Increase the enemy data our address is pointingtwo ld a, l - add a, PER_ENEMY_BYTES_COUNT - ld l, a + add PER_ENEMY_BYTES_COUNT + ld l, a ld a, h - adc a, 0 - ld h, a + adc 0 + ld h, a ; ANCHOR_END: enemies-update-loop @@ -124,7 +121,7 @@ UpdateEnemies_PerEnemy: ; The first byte is if the current object is active ; If it's not zero, it's active, go to the normal update section ld a, [hl] - cp 0 + and a jp nz, UpdateEnemies_PerEnemy_Update UpdateEnemies_SpawnNewEnemy: @@ -132,7 +129,7 @@ UpdateEnemies_SpawnNewEnemy: ; If this enemy is NOT active ; Check If we want to spawn a new enemy ld a, [wNextEnemyXPosition] - cp 0 + and a ; If we don't want to spawn a new enemy, we'll skip this (deactivated) enemy jp z, UpdateEnemies_Loop @@ -149,17 +146,15 @@ UpdateEnemies_SpawnNewEnemy: ld [hli], a ; Put the value for our enemies y position to equal 0 - ld a, 0 + xor a ld [hli], a ld [hld], a - - ld a, 0 ld [wNextEnemyXPosition], a pop hl ; Increase counter - ld a,[wActiveEnemyCounter] + ld a, [wActiveEnemyCounter] inc a ld [wActiveEnemyCounter], a @@ -187,16 +182,16 @@ UpdateEnemies_PerEnemy_Update: ; Get our x position ld a, [hli] ld b, a - ld [wCurrentEnemyX],a + ld [wCurrentEnemyX], a ; get our 16-bit y position ; increase it (by e), but also save it ld a, [hl] - add a, 10 + add 10 ld [hli], a ld c, a ld a, [hl] - adc a, 0 + adc 0 ld [hl], a ld d, a @@ -213,7 +208,7 @@ UpdateEnemies_PerEnemy_Update: rr c ld a, c - ld [wCurrentEnemyY],a + ld [wCurrentEnemyY], a ; ANCHOR_END: enemies-update-per-enemy2 @@ -224,16 +219,12 @@ UpdateEnemies_PerEnemy_CheckPlayerCollision: push hl call CheckCurrentEnemyAgainstBullets - - pop hl - push hl - call CheckEnemyPlayerCollision pop hl ld a, [wResult] - cp a, 0 + and a jp z, UpdateEnemies_NoCollisionWithPlayer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -252,11 +243,11 @@ UpdateEnemies_PerEnemy_CheckPlayerCollision: UpdateEnemies_DeActivateEnemy: ; Set as inactive - ld a, 0 + xor ld [hl], a ; Decrease counter - ld a,[wActiveEnemyCounter] + ld a, [wActiveEnemyCounter] dec a ld [wActiveEnemyCounter], a @@ -269,7 +260,7 @@ UpdateEnemies_NoCollisionWithPlayer:: ; See if our non scaled low byte is above 160 ld a, [wCurrentEnemyY] - cp a, 160 + cp 160 jp nc, UpdateEnemies_DeActivateEnemy push hl @@ -287,14 +278,14 @@ UpdateEnemies_NoCollisionWithPlayer:: ; Save the x position ld a, [wCurrentEnemyX] - ld [wMetaspriteX],a + ld [wMetaspriteX], a ; Save the y position ld a, [wCurrentEnemyY] - ld [wMetaspriteY],a + ld [wMetaspriteY], a ; Actually call the 'DrawMetasprites function - call DrawMetasprites; + call DrawMetasprites ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -318,18 +309,18 @@ TryToSpawnEnemies:: ; Check our spawn acounter ; Stop if it's below a given value ld a, [wSpawnCounter] - cp a, ENEMY_SPAWN_DELAY_MAX + cp ENEMY_SPAWN_DELAY_MAX ret c ; Check our next enemy x position variable ; Stop if it's non zero ld a, [wNextEnemyXPosition] - cp a, 0 + cp 0 ret nz ; Make sure we don't have the max amount of enmies ld a, [wActiveEnemyCounter] - cp a, MAX_ENEMY_COUNT + cp MAX_ENEMY_COUNT ret nc GetSpawnPosition: @@ -338,17 +329,17 @@ GetSpawnPosition: call rand ; make sure it's not above 150 - ld a,b - cp a, 150 + ld a, b + cp 150 ret nc ; make sure it's not below 24 ld a, b - cp a, 24 + cp 24 ret c ; reset our spawn counter - ld a, 0 + xor a ld [wSpawnCounter], a ld a, b @@ -356,4 +347,4 @@ GetSpawnPosition: ret -; ANCHOR_END: enemies-spawn \ No newline at end of file +; ANCHOR_END: enemies-spawn diff --git a/galactic-armada/src/main/states/gameplay/objects/player.asm b/galactic-armada/src/main/states/gameplay/objects/player.asm index 2b43c238..1ee70fa6 100644 --- a/galactic-armada/src/main/states/gameplay/objects/player.asm +++ b/galactic-armada/src/main/states/gameplay/objects/player.asm @@ -26,14 +26,14 @@ playerTestMetaSprite:: ; ANCHOR: player-initialize InitializePlayer:: - ld a, 0 - ld [mPlayerFlash+0],a - ld [mPlayerFlash+1],a + xor a + ld [mPlayerFlash], a + ld [mPlayerFlash+1], a ; Place in the middle of the screen - ld a, 0 - ld [wPlayerPositionX+0], a - ld [wPlayerPositionY+0], a + xor a + ld [wPlayerPositionX], a + ld [wPlayerPositionY], a ld a, 5 ld [wPlayerPositionX+1], a @@ -47,7 +47,7 @@ CopyPlayerTileDataIntoVRAM: ld bc, playerShipTileDataEnd - playerShipTileData call CopyDEintoMemoryAtHL - ret; + ret ; ANCHOR_END: player-initialize ; ANCHOR: player-update-start @@ -56,23 +56,23 @@ UpdatePlayer:: UpdatePlayer_HandleInput: ld a, [wCurKeys] - and a, PADF_UP + and PADF_UP call nz, MoveUp ld a, [wCurKeys] - and a, PADF_DOWN + and PADF_DOWN call nz, MoveDown ld a, [wCurKeys] - and a, PADF_LEFT + and PADF_LEFT call nz, MoveLeft ld a, [wCurKeys] - and a, PADF_RIGHT + and PADF_RIGHT call nz, MoveRight ld a, [wCurKeys] - and a, PADF_A + and PADF_A call nz, TryShoot ; ANCHOR_END: player-update-start @@ -87,22 +87,22 @@ UpdatePlayer_HandleInput: UpdatePlayer_UpdateSprite_CheckFlashing: ld a, b - or a, c + or c jp z, UpdatePlayer_UpdateSprite ; decrease bc by 5 ld a, b - sub a, 5 + sub 5 ld b, a ld a, c - sbc a, 0 + sbc 0 ld c, a UpdatePlayer_UpdateSprite_DecreaseFlashing: ld a, b - ld [mPlayerFlash+0], a + ld [mPlayerFlash], a ld a, c ld [mPlayerFlash+1], a @@ -117,7 +117,7 @@ UpdatePlayer_UpdateSprite_DecreaseFlashing: rr b ld a, b - cp a, 5 + cp 5 jp c, UpdatePlayer_UpdateSprite_StopFlashing @@ -126,11 +126,11 @@ UpdatePlayer_UpdateSprite_DecreaseFlashing: UpdatePlayer_UpdateSprite_Flashing: - ret; + ret UpdatePlayer_UpdateSprite_StopFlashing: - ld a, 0 - ld [mPlayerFlash+0],a + xor a + ld [mPlayerFlash],a ld [mPlayerFlash+1],a ; ANCHOR_END: player-update-flashing @@ -182,11 +182,11 @@ UpdatePlayer_UpdateSprite: ; Save the x position ld a, b - ld [wMetaspriteX],a + ld [wMetaspriteX], a ; Save the y position ld a, c - ld [wMetaspriteY],a + ld [wMetaspriteY], a ; Actually call the 'DrawMetasprites function call DrawMetasprites; @@ -201,12 +201,10 @@ UpdatePlayer_UpdateSprite: ; ANCHOR: player-shoot TryShoot: ld a, [wLastKeys] - and a, PADF_A + and PADF_A ret nz - call FireNextBullet; - - ret + jp FireNextBullet ; ANCHOR_END: player-shoot ; ANCHOR: player-damage @@ -214,9 +212,9 @@ DamagePlayer:: - ld a, 0 - ld [mPlayerFlash+0], a - ld a, 1 + xor a + ld [mPlayerFlash], a + inc a ld [mPlayerFlash+1], a ld a, [wLives] @@ -230,25 +228,25 @@ DamagePlayer:: MoveUp: ; decrease the player's y position - ld a, [wPlayerPositionY+0] - sub a, PLAYER_MOVE_SPEED - ld [wPlayerPositionY+0], a + ld a, [wPlayerPositionY] + sub PLAYER_MOVE_SPEED + ld [wPlayerPositionY], a - ld a, [wPlayerPositionY+1] - sbc a, 0 - ld [wPlayerPositionY+1], a + ld a, [wPlayerPositionY] + sbc 0 + ld [wPlayerPositionY], a ret MoveDown: ; increase the player's y position - ld a, [wPlayerPositionY+0] - add a, PLAYER_MOVE_SPEED - ld [wPlayerPositionY+0], a + ld a, [wPlayerPositionY] + add PLAYER_MOVE_SPEED + ld [wPlayerPositionY], a ld a, [wPlayerPositionY+1] - adc a, 0 + adc 0 ld [wPlayerPositionY+1], a ret @@ -256,24 +254,24 @@ MoveDown: MoveLeft: ; decrease the player's x position - ld a, [wPlayerPositionX+0] - sub a, PLAYER_MOVE_SPEED - ld [wPlayerPositionX+0], a + ld a, [wPlayerPositionX] + sub PLAYER_MOVE_SPEED + ld [wPlayerPositionX], a ld a, [wPlayerPositionX+1] - sbc a, 0 + sbc 0 ld [wPlayerPositionX+1], a ret MoveRight: ; increase the player's x position - ld a, [wPlayerPositionX+0] - add a, PLAYER_MOVE_SPEED - ld [wPlayerPositionX+0], a + ld a, [wPlayerPositionX] + add PLAYER_MOVE_SPEED + ld [wPlayerPositionX], a ld a, [wPlayerPositionX+1] - adc a, 0 + adc 0 ld [wPlayerPositionX+1], a ret diff --git a/galactic-armada/src/main/states/story/story-state.asm b/galactic-armada/src/main/states/story/story-state.asm index 5353137c..1811fae7 100644 --- a/galactic-armada/src/main/states/story/story-state.asm +++ b/galactic-armada/src/main/states/story/story-state.asm @@ -10,7 +10,7 @@ InitStoryState:: ld a, LCDCF_ON | LCDCF_BGON|LCDCF_OBJON | LCDCF_OBJ16 ld [rLCDC], a - ret; + ret ; ANCHOR_END: init-story-state ; ANCHOR: story-screen-data @@ -56,7 +56,7 @@ UpdateStoryState:: ; Save the passed value into the variable: mWaitKey ; The WaitForKeyFunction always checks against this vriable - ld a,PADF_A + ld a, PADF_A ld [mWaitKey], a call WaitForKeyFunction @@ -93,7 +93,7 @@ UpdateStoryState:: ; Save the passed value into the variable: mWaitKey ; The WaitForKeyFunction always checks against this vriable - ld a,PADF_A + ld a, PADF_A ld [mWaitKey], a call WaitForKeyFunction @@ -107,4 +107,4 @@ UpdateStoryState:: ld a, 2 ld [wGameState],a jp NextGameState -; ANCHOR_END: story-screen-end \ No newline at end of file +; ANCHOR_END: story-screen-end diff --git a/galactic-armada/src/main/states/title-screen/title-screen-state.asm b/galactic-armada/src/main/states/title-screen/title-screen-state.asm index 6953d815..177a4177 100644 --- a/galactic-armada/src/main/states/title-screen/title-screen-state.asm +++ b/galactic-armada/src/main/states/title-screen/title-screen-state.asm @@ -34,7 +34,7 @@ InitTitleScreenState:: ld a, LCDCF_ON | LCDCF_BGON|LCDCF_OBJON | LCDCF_OBJ16 ld [rLCDC], a - ret; + ret ; ANCHOR_END: title-screen-init ; ANCHOR: draw-title-screen @@ -44,15 +44,14 @@ DrawTitleScreen:: ld de, titleScreenTileData ; de contains the address where data will be copied from; ld hl, $9340 ; hl contains the address where data will be copied to; ld bc, titleScreenTileDataEnd - titleScreenTileData ; bc contains how many bytes we have to copy. - call CopyDEintoMemoryAtHL; + call CopyDEintoMemoryAtHL ; Copy the tilemap ld de, titleScreenTileMap ld hl, $9800 ld bc, titleScreenTileMapEnd - titleScreenTileMap - call CopyDEintoMemoryAtHL_With52Offset + jp CopyDEintoMemoryAtHL_With52Offset - ret ; ANCHOR_END: draw-title-screen ; ANCHOR: update-title-screen @@ -64,7 +63,7 @@ UpdateTitleScreenState:: ; Save the passed value into the variable: mWaitKey ; The WaitForKeyFunction always checks against this vriable - ld a,PADF_A + ld a, PADF_A ld [mWaitKey], a call WaitForKeyFunction diff --git a/galactic-armada/src/main/utils/background-utils.asm b/galactic-armada/src/main/utils/background-utils.asm index 6f5e220e..5bc62be5 100644 --- a/galactic-armada/src/main/utils/background-utils.asm +++ b/galactic-armada/src/main/utils/background-utils.asm @@ -6,21 +6,21 @@ SECTION "Background", ROM0 ClearBackground:: ; Turn the LCD off - ld a, 0 + xor a ld [rLCDC], a - ld bc,1024 + ld bc, 1024 ld hl, $9800 ClearBackgroundLoop: - ld a,0 + xor a ld [hli], a dec bc ld a, b - or a, c + or c jp nz, ClearBackgroundLoop @@ -31,4 +31,4 @@ ClearBackgroundLoop: ret -; ANCHOR_END: background-utils \ No newline at end of file +; ANCHOR_END: background-utils diff --git a/galactic-armada/src/main/utils/collision-utils.asm b/galactic-armada/src/main/utils/collision-utils.asm index 6142a2f0..8fc1fe2c 100644 --- a/galactic-armada/src/main/utils/collision-utils.asm +++ b/galactic-armada/src/main/utils/collision-utils.asm @@ -1,12 +1,11 @@ ; ANCHOR: collision-utils -include "src/main/utils/hardware.inc" include "src/main/utils/constants.inc" include "src/main/utils/hardware.inc" SECTION "CollisionUtilsVariables", WRAM0 -wResult::db; -wSize::db; +wResult:: db +wSize:: db wObject1Value:: db wObject2Value:: db @@ -28,8 +27,8 @@ CheckObjectPositionDifference:: ; carry means eb, means enemy.top is visually below bullet.y (no collision) ld a, e - sub a, d - cp a, b + sub d + cp b ; no carry means no collision jp nc, CheckObjectPositionDifference_Failure - ld a,1 + ld a, 1 ld [wResult], a - ret; + ret CheckObjectPositionDifference_Failure: @@ -54,4 +53,4 @@ CheckObjectPositionDifference_Failure: ld [wResult], a ret; -; ANCHOR_END: collision-utils \ No newline at end of file +; ANCHOR_END: collision-utils diff --git a/galactic-armada/src/main/utils/input-utils.asm b/galactic-armada/src/main/utils/input-utils.asm index 89878d04..94e26164 100644 --- a/galactic-armada/src/main/utils/input-utils.asm +++ b/galactic-armada/src/main/utils/input-utils.asm @@ -25,14 +25,14 @@ WaitForKeyFunction_Loop: ld a, [mWaitKey] - ld b,a + ld b, a ld a, [wCurKeys] and a, b - jp z,WaitForKeyFunction_NotPressed + jp WaitForKeyFunction_NotPressed ld a, [wLastKeys] - and a, b - jp nz,WaitForKeyFunction_NotPressed + and b + jp nz, WaitForKeyFunction_NotPressed ; restore our original value pop bc @@ -53,4 +53,4 @@ WaitForKeyFunction_NotPressed: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; jp WaitForKeyFunction_Loop -; ANCHOR_END: input-utils \ No newline at end of file +; ANCHOR_END: input-utils diff --git a/galactic-armada/src/main/utils/math.asm b/galactic-armada/src/main/utils/math.asm index 69d434f8..f74fdaa6 100644 --- a/galactic-armada/src/main/utils/math.asm +++ b/galactic-armada/src/main/utils/math.asm @@ -13,16 +13,16 @@ SECTION "Math", ROM0 ; C=state bits 23-16, HL trashed rand:: ; Add 0xB3 then multiply by 0x01010101 - ld hl, randstate+0 + ld hl, randstate ld a, [hl] - add a, $B3 + add $B3 ld [hl+], a - adc a, [hl] + adc [hl] ld [hl+], a - adc a, [hl] + adc [hl] ld [hl+], a ld c, a - adc a, [hl] + adc [hl] ld [hl], a ld b, a - ret \ No newline at end of file + ret diff --git a/galactic-armada/src/main/utils/memory-utils.asm b/galactic-armada/src/main/utils/memory-utils.asm index 8ddeb8b9..c536dc67 100644 --- a/galactic-armada/src/main/utils/memory-utils.asm +++ b/galactic-armada/src/main/utils/memory-utils.asm @@ -7,9 +7,9 @@ CopyDEintoMemoryAtHL:: inc de dec bc ld a, b - or a, c - jp nz, CopyDEintoMemoryAtHL ; Jump to COpyTiles, if the z flag is not set. (the last operation had a non zero result) - ret; + or c + jp nz, CopyDEintoMemoryAtHL ; Jump to CopyTiles if the last operation had a non zero result. + ret CopyDEintoMemoryAtHL_With52Offset:: ld a, [de] @@ -18,7 +18,7 @@ CopyDEintoMemoryAtHL_With52Offset:: inc de dec bc ld a, b - or a, c + or c jp nz, CopyDEintoMemoryAtHL_With52Offset ; Jump to COpyTiles, if the z flag is not set. (the last operation had a non zero result) - ret; -; ANCHOR_END: memory-utils \ No newline at end of file + ret +; ANCHOR_END: memory-utils diff --git a/galactic-armada/src/main/utils/metasprites.asm b/galactic-armada/src/main/utils/metasprites.asm index 0ae2d1c4..43b9cc7d 100644 --- a/galactic-armada/src/main/utils/metasprites.asm +++ b/galactic-armada/src/main/utils/metasprites.asm @@ -27,16 +27,16 @@ DrawMetasprites:: ret z ld a, [wMetaspriteY] - add a, b - ld [wMetaspriteY],a + add b + ld [wMetaspriteY], a ; Get the x position ld a, [hli] ld c, a ld a, [wMetaspriteX] - add a,c - ld [wMetaspriteX],a + add c + ld [wMetaspriteX], a ; Get the tile position ld a, [hli] @@ -47,7 +47,7 @@ DrawMetasprites:: ld e, a - ;Get our offset address in hl + ; Get our offset address in hl ld a,[wLastOAMAddress+0] ld l, a ld a, HIGH(wShadowOAM) @@ -68,12 +68,12 @@ DrawMetasprites:: call NextOAMSprite ; increase the wMetaspriteAddress - ld a, [wMetaspriteAddress+0] + ld a, [wMetaspriteAddress] add a, METASPRITE_BYTES_COUNT - ld [wMetaspriteAddress+0], a + ld [wMetaspriteAddress], a ld a, [wMetaspriteAddress+1] - adc a, 0 - ld [wMetaspriteAddress+1], a + adc 0 + ld [wMetaspriteAddress+1], a jp DrawMetasprites diff --git a/galactic-armada/src/main/utils/sprites-utils.asm b/galactic-armada/src/main/utils/sprites-utils.asm index 512b69b5..115f3a72 100644 --- a/galactic-armada/src/main/utils/sprites-utils.asm +++ b/galactic-armada/src/main/utils/sprites-utils.asm @@ -12,7 +12,7 @@ SECTION "Sprites", ROM0 ClearAllSprites:: ; Start clearing oam - ld a, 0 + xor a ld b, OAM_COUNT*sizeof_OAM_ATTRS ; 40 sprites times 4 bytes per sprite ld hl, wShadowOAM ; The start of our oam sprites in RAM @@ -20,40 +20,37 @@ ClearOamLoop:: ld [hli], a dec b jp nz, ClearOamLoop - ld a,0 - ld [wSpritesUsed],a + xor a + ld [wSpritesUsed], a ; from: https://github.com/eievui5/gb-sprobj-lib ; Finally, run the following code during VBlank: ld a, HIGH(wShadowOAM) - call hOAMDMA - - ret + jp hOAMDMA ClearRemainingSprites:: ClearRemainingSprites_Loop:: ;Get our offset address in hl - ld a,[wLastOAMAddress+0] + ld a,[wLastOAMAddress] ld l, a ld a, HIGH(wShadowOAM) ld h, a ld a, l - cp a, 160 - ret nc + cp 160 ret nc ; Set the y and x to be 0 - ld a, 0 + xor a ld [hli], a ld [hld], a ; Move up 4 bytes ld a, l - add a, 4 + add 4 ld l, a call NextOAMSprite @@ -64,11 +61,11 @@ ClearRemainingSprites_Loop:: ; ANCHOR: reset-oam-sprite-address ResetOAMSpriteAddress:: - ld a, 0 + xor a ld [wSpritesUsed], a ld a, LOW(wShadowOAM) - ld [wLastOAMAddress+0], a + ld [wLastOAMAddress], a ld a, HIGH(wShadowOAM) ld [wLastOAMAddress+1], a @@ -82,9 +79,9 @@ NextOAMSprite:: inc a ld [wSpritesUsed], a - ld a,[wLastOAMAddress+0] - add a, sizeof_OAM_ATTRS - ld [wLastOAMAddress+0], a + ld a,[wLastOAMAddress] + add sizeof_OAM_ATTRS + ld [wLastOAMAddress], a ld a, HIGH(wShadowOAM) ld [wLastOAMAddress+1], a @@ -92,4 +89,4 @@ NextOAMSprite:: ret ; ANCHOR_END: next-oam-sprite - \ No newline at end of file + diff --git a/galactic-armada/src/main/utils/text-utils.asm b/galactic-armada/src/main/utils/text-utils.asm index 4bbeed14..a3c554f3 100644 --- a/galactic-armada/src/main/utils/text-utils.asm +++ b/galactic-armada/src/main/utils/text-utils.asm @@ -9,8 +9,7 @@ LoadTextFontIntoVRAM:: ld de, textFontTileData ; de contains the address where data will be copied from; ld hl, $9000 ; hl contains the address where data will be copied to; ld bc, textFontTileDataEnd - textFontTileData ; bc contains how many bytes we have to copy. - call CopyDEintoMemoryAtHL - ret + jp CopyDEintoMemoryAtHL ; ANCHOR: draw-text-tiles DrawTextTilesLoop:: diff --git a/galactic-armada/src/main/utils/vblank-utils.asm b/galactic-armada/src/main/utils/vblank-utils.asm index 899c4f5d..20a86fe7 100644 --- a/galactic-armada/src/main/utils/vblank-utils.asm +++ b/galactic-armada/src/main/utils/vblank-utils.asm @@ -23,7 +23,7 @@ WaitForVBlankFunction_Loop:: jp c, WaitForVBlankFunction_Loop ; A conditional jump. The condition is that 'c' is set, the last operation overflowed ld a, [wVBlankCount] - sub a, 1 + sub 1 ld [wVBlankCount], a ret z @@ -35,4 +35,4 @@ WaitForVBlankFunction_Loop2:: jp WaitForVBlankFunction_Loop -; ANCHOR_END: vblank-utils \ No newline at end of file +; ANCHOR_END: vblank-utils diff --git a/src/part3/entry-point.md b/src/part3/entry-point.md index cc7fbd0e..f8d8a5ba 100644 --- a/src/part3/entry-point.md +++ b/src/part3/entry-point.md @@ -40,7 +40,13 @@ Getting back to our entry point. Were going to wait until a vertical blank begin :::tip -Even though we haven't specifically defined a color palette. The [emulicious](https://emulicious.net/) emulator may automatically apply a default color palette if in "Automatic" or "Gameboy Color" Mode +Even though we haven't specifically defined a color palette. The [emulicious](https://emulicious.net/) emulator may automatically apply a default color palette if in "Automatic" or "Gameboy Color" mode. + +::: + +:::tip + +Instead of `ld a, 0`, we can use `xor a` to set `a` to 0. It takes one byte less, which matters a lot on the Game Boy. :::