diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-02 22:43:57 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-02 22:43:57 +0100 |
| commit | b7c41567892a7b3bd3782128926c6a223658a034 (patch) | |
| tree | 7cec8bdbf8d8b81ef627b6e4e07dd9e51cea9903 /src/bullets.s | |
| parent | 05fda0c6b9631e24bd1e097aed711ade5719717e (diff) | |
| download | jetpac.nes-b7c41567892a7b3bd3782128926c6a223658a034.tar.gz jetpac.nes-b7c41567892a7b3bd3782128926c6a223658a034.zip | |
Wrap around the saving of the last allocated bullet
If we don't do this, then it's possible to incur into a buffer overflow
as the last allocated index is set to the next (out of buffer)
position. Whenever we start over on this function, then it will compare
for a good bullet on this position, and if it's not exactly $FF, then it
will allocate it without problems.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'src/bullets.s')
| -rw-r--r-- | src/bullets.s | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/bullets.s b/src/bullets.s index 93ff8c5..1dd98e0 100644 --- a/src/bullets.s +++ b/src/bullets.s @@ -157,8 +157,13 @@ @set_bullet_x: sta zp_bullets_pool_base, x - ;; Save the index so it can be used in future bullet creation. + ;; Save the index so it can be used in future bullet creation. Also be + ;; careful to wrap around. inx + cpx #BULLETS_POOL_CAPACITY_BYTES + bne @set_last_allocated + ldx #0 + @set_last_allocated: stx zp_last_allocated_index ;; Increase the number of bullets on screen. |
