From 0e103c6f8833266d877f190f80e28772392fd32e Mon Sep 17 00:00:00 2001 From: nmlgc Date: Fri, 24 Mar 2023 02:26:45 +0100 Subject: [PATCH] [Maintenance] Add a VRAM offset roll macro Part of P0235, funded by Ember2528. --- planar.h | 9 +++++++++ th02/main/bullet/pellet_r.cpp | 7 ++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/planar.h b/planar.h index 59351d9d..c68b8ce0 100644 --- a/planar.h +++ b/planar.h @@ -84,6 +84,15 @@ typedef uint16_t uvram_offset_t; #define VRAM_OFFSET_SHIFT(x, y) \ (x >> BYTE_BITS) + (y << 6) + (y << 4) +// Adds [imm] to [vo] and rolls [vo] back to the top of VRAM if it crossed the +// bottom. Necessary with hardware scrolling. +#define vram_offset_add_and_roll(vo, imm) { \ + vo += imm; \ + if(static_cast(vo) >= PLANE_SIZE) { \ + vo -= PLANE_SIZE; \ + } \ +} + #ifdef __cplusplus // MODDERS: Replace with a single function static inline vram_offset_t vram_offset_shift(screen_x_t x, vram_y_t y) { diff --git a/th02/main/bullet/pellet_r.cpp b/th02/main/bullet/pellet_r.cpp index ab00bb0a..8b8e7ed9 100644 --- a/th02/main/bullet/pellet_r.cpp +++ b/th02/main/bullet/pellet_r.cpp @@ -18,10 +18,7 @@ void pascal near pellet_render(screen_x_t left, vram_y_t top) _CX = 8; put_loop: { asm { movsw; } - _DI += (ROW_SIZE - sizeof(dots16_t)); - if(static_cast(_DI) >= PLANE_SIZE) { - _DI -= PLANE_SIZE; - } + vram_offset_add_and_roll(_DI, (ROW_SIZE - sizeof(dots16_t))); + asm { loop put_loop; } } - asm { loop put_loop; } }