From 2f85b4c7820d919497878d54dea530fe73a486c9 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 2 Mar 2026 23:18:55 +0100 Subject: Move enemy initialization into its own function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be useful whenever we implement the re-appearance of enemies. Signed-off-by: Miquel Sabaté Solà --- .nasm/segments.txt | 2 +- src/enemies.s | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.nasm/segments.txt b/.nasm/segments.txt index 3c85c8f..5b1f542 100644 --- a/.nasm/segments.txt +++ b/.nasm/segments.txt @@ -1,4 +1,4 @@ - HEADER: 16/16 (100%) -- ROM0: 5467/32762 (16.69%) +- ROM0: 5471/32762 (16.70%) - ROMV: 6/6 (100%) - ROM2: 8192/8192 (100%) diff --git a/src/enemies.s b/src/enemies.s index 7aa8df1..53f6685 100644 --- a/src/enemies.s +++ b/src/enemies.s @@ -116,6 +116,21 @@ sty zp_enemies_pool_size @enemies_init_loop: + jsr init_enemy_x + + ;; Next enemy! + dey + bne @enemies_init_loop + + rts + .endproc + + ;; Initialize the enemy from the pool as indexed by the 'x' register. + ;; + ;; NOTE: the 'x' register will be advanced by the amount of bytes it takes + ;; to store an enemy on the poll (i.e. 4 bytes). + ;; NOTE: the 'y' register is not touched. + .proc init_enemy_x ;; The state is set at random. stx Globals::zp_tmp0 jsr Prng::random_valid_y_coordinate @@ -148,10 +163,8 @@ inx sta zp_enemies_pool_base, x - ;; Next enemy! + ;; And point to the next enemy. inx - dey - bne @enemies_init_loop rts .endproc -- cgit v1.2.3