From 07561f4824a7a4af3cf9e99fd8e23e9cdd6aae42 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Mon, 7 Feb 2022 17:21:35 +0100 Subject: [PATCH] [Reverse-engineering] [th03] Collision bitmap: Drawing vertical lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ironically only used for pellets, which are now confirmed to have a 2×2 (screen) / 2×1 (VRAM) hitbox. Might have been "decompilable", but it's sandwiched between undecompilable functions. Part of P0182, funded by Lmocinemod and [Anonymous]. --- th03/main/collmap.asm | 60 +++++++++++++++++++++++++++++++++++++++++++ th03/main/collmap.hpp | 7 +++++ th03_main.asm | 55 ++------------------------------------- 3 files changed, 69 insertions(+), 53 deletions(-) diff --git a/th03/main/collmap.asm b/th03/main/collmap.asm index a4414d38..94e1abaa 100644 --- a/th03/main/collmap.asm +++ b/th03/main/collmap.asm @@ -10,6 +10,7 @@ include th03/main/collmap.inc extrn _collmap_topleft:Point extrn _collmap_stripe_tile_w:word +extrn _collmap_tile_h:word extrn _collmap_bottomright:Point extrn _collmap_pid:byte extrn _collmap:byte:(PLAYER_COUNT * COLLMAP_SIZE) @@ -31,6 +32,65 @@ MAIN_04 group COLLMAP_TEXT .code assume cs:MAIN_04 +public _collmap_set_vline +_collmap_set_vline proc far + @@pattern equ + @@first_bit equ + @@first_bit_wide equ ; Just remove this + @@rows_from_bottom equ ; Ensures clipping at the bottom edge + @@collmap_p equ + + mov ax, _collmap_topleft.x + mov dx, _collmap_topleft.y + + ; Clip + or ax, ax + js short @@ret + cmp ax, (PLAYFIELD_W shl 4) + jge short @@ret + or dx, dx + js short @@ret + cmp dx, (PLAYFIELD_H shl 4) + jge short @@ret + + xor @@collmap_p, @@collmap_p + cmp _collmap_pid, 0 + jz short @@set_collmap_p + mov @@collmap_p, COLLMAP_SIZE + +@@set_collmap_p: + add @@collmap_p, offset _collmap + + sar ax, (SUBPIXEL_BITS + COLLMAP_TILE_W_BITS) + sar dx, (SUBPIXEL_BITS + COLLMAP_TILE_H_BITS) + + mov @@first_bit_wide, ax ; first_bit = AX; + sar ax, 3 ; AX /= 8; (bits per byte) + and @@first_bit_wide, (8 - 1) ; first_bit &= (8 - 1); + add @@collmap_p, dx ; collmap_p += ( + offset_x ax, al ; DX + (AX * COLLMAP_H) + add @@collmap_p, ax ; ); + + mov ax, COLLMAP_H + sub ax, dx + mov @@rows_from_bottom, ax + mov @@pattern, 80h + shr @@pattern, @@first_bit + mov cx, _collmap_tile_h + even + +@@row_loop: + or [@@collmap_p], @@pattern + inc @@collmap_p + dec @@rows_from_bottom + loopne @@row_loop + +@@ret: + ret +_collmap_set_vline endp + even + + public _collmap_set_slope_striped _collmap_set_slope_striped proc c far uses si, di diff --git a/th03/main/collmap.hpp b/th03/main/collmap.hpp index 9e2c1586..1b5a6252 100644 --- a/th03/main/collmap.hpp +++ b/th03/main/collmap.hpp @@ -41,6 +41,13 @@ extern unsigned char collmap_pid; extern uint8_t collmap[PLAYER_COUNT][COLLMAP_MEMORY_W][COLLMAP_H]; // ------------------- +// Sets all bits on a straight 1-tile wide vertical line, clipped to the +// height of the collision bitmap. Takes the following parameters: +// • [collmap_topleft] (X and Y) +// • [collmap_tile_h] (height of the line) +// • [collmap_pid] +void collmap_set_vline(); + // Sets all bits on every [COLLMAP_SLOPE_VSTRIPE_DISTANCE]th row of a // potentially sloped vertical line across one whole playfield. // Takes the following parameters: diff --git a/th03_main.asm b/th03_main.asm index afe01765..e490439b 100644 --- a/th03_main.asm +++ b/th03_main.asm @@ -17080,61 +17080,10 @@ loc_13B2C: locret_13B41: retf sub_13A6E endp - - -; =============== S U B R O U T I N E ======================================= - - -sub_13B42 proc far - mov ax, _collmap_topleft.x - mov dx, _collmap_topleft.y - or ax, ax - js short locret_13B98 - cmp ax, (PLAYFIELD_W shl 4) - jge short locret_13B98 - or dx, dx - js short locret_13B98 - cmp dx, (PLAYFIELD_H shl 4) - jge short locret_13B98 - xor bx, bx - cmp _collmap_pid, 0 - jz short loc_13B68 - mov bx, COLLMAP_SIZE - -loc_13B68: - add bx, offset _collmap - sar ax, 5 - sar dx, 5 - mov cx, ax - sar ax, 3 - and cx, 7 - add bx, dx - mov ah, COLLMAP_H - mul ah - add bx, ax - mov ax, COLLMAP_H - sub ax, dx - mov dx, ax - mov ah, 80h - shr ah, cl - mov cx, _collmap_tile_h - nop - -loc_13B92: - or [bx], ah - inc bx - dec dx - loopne loc_13B92 - -locret_13B98: - retf -sub_13B42 endp - -; --------------------------------------------------------------------------- - nop main_04_TEXT ends COLLMAP_TEXT segment byte public 'CODE' use16 + extern _collmap_set_vline:proc extern _collmap_set_slope_striped:proc COLLMAP_TEXT ends @@ -24959,7 +24908,7 @@ loc_17BA9: mov _collmap_topleft.y, ax mov al, [si+10h] mov _collmap_pid, al - call sub_13B42 + call _collmap_set_vline loc_17BCA: jmp loc_17A3D