[Reverse-engineering] [th03] Collision bitmap: Drawing vertical lines

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].
This commit is contained in:
nmlgc 2022-02-07 17:21:35 +01:00
parent c04ca8da91
commit 07561f4824
3 changed files with 69 additions and 53 deletions

View File

@ -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 <ah>
@@first_bit equ <cl>
@@first_bit_wide equ <cx> ; Just remove this
@@rows_from_bottom equ <dx> ; Ensures clipping at the bottom edge
@@collmap_p equ <bx>
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

View File

@ -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:

View File

@ -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