From 4cbeadde9673b02801582d5de9fdfced8cde0cbb Mon Sep 17 00:00:00 2001 From: nmlgc Date: Thu, 24 Jun 2021 20:46:39 +0200 Subject: [PATCH] [Decompilation] [th04] Bullets: Sprite selection by angle Part of P0150, funded by Blue Bolt. --- th04/main/bullet/add.cpp | 9 +++++++++ th04/main/bullet/bullet.hpp | 2 +- th04/main/bullet/patnum_for_angle.asm | 17 ----------------- th04_main.asm | 4 ++-- 4 files changed, 12 insertions(+), 20 deletions(-) delete mode 100644 th04/main/bullet/patnum_for_angle.asm diff --git a/th04/main/bullet/add.cpp b/th04/main/bullet/add.cpp index c493ce45..6b9d3845 100644 --- a/th04/main/bullet/add.cpp +++ b/th04/main/bullet/add.cpp @@ -419,3 +419,12 @@ void near bullet_template_speedtune_for_playperf(void) bullet_template.speed.set(0.5f); } } + +static const unsigned char ANGLE_PER_SPRITE = (0x80 / BULLET_D_CELS); + +unsigned char pascal near bullet_patnum_for_angle(unsigned char angle) +{ + return ( + ((angle + (ANGLE_PER_SPRITE / 2) - 1) & (0x80 - 1)) / ANGLE_PER_SPRITE + ); +} diff --git a/th04/main/bullet/bullet.hpp b/th04/main/bullet/bullet.hpp index 719ccab5..1f036ada 100644 --- a/th04/main/bullet/bullet.hpp +++ b/th04/main/bullet/bullet.hpp @@ -107,7 +107,7 @@ void pascal near bullet_update_patnum(bullet_t near *bullet); // Returns the offset for a directional bullet sprite that shows the given // [angle]. -int pascal near bullet_patnum_for_angle(unsigned char angle); +unsigned char pascal near bullet_patnum_for_angle(unsigned char angle); // Turns every 4th bullet into a point item when zapping bullets. extern bool bullet_zap_drop_point_items; diff --git a/th04/main/bullet/patnum_for_angle.asm b/th04/main/bullet/patnum_for_angle.asm deleted file mode 100644 index 1b80726a..00000000 --- a/th04/main/bullet/patnum_for_angle.asm +++ /dev/null @@ -1,17 +0,0 @@ -public BULLET_PATNUM_FOR_ANGLE -bullet_patnum_for_angle proc near - -@@angle = byte ptr 4 - - push bp - mov bp, sp - mov al, [bp+@@angle] - mov ah, 0 - add ax, 3 - and ax, 7Fh - mov bx, 8 - cwd - idiv bx - pop bp - retn 2 -bullet_patnum_for_angle endp diff --git a/th04_main.asm b/th04_main.asm index 4a5c4678..42518855 100644 --- a/th04_main.asm +++ b/th04_main.asm @@ -28228,8 +28228,8 @@ main_033_TEXT segment byte public 'CODE' use16 BULLET_VELOCITY_AND_ANGLE_SET procdesc pascal near \ i:word _bullet_template_speedtune_for_pl procdesc near - -include th04/main/bullet/patnum_for_angle.asm + BULLET_PATNUM_FOR_ANGLE procdesc pascal near \ + angle:byte ; =============== S U B R O U T I N E =======================================