[Reverse-engineering] [th05] Laser update and render functions

Funded by zorg.
This commit is contained in:
nmlgc 2018-12-17 00:26:44 +01:00
parent 8634e10b6d
commit 0cde4b7cd3
3 changed files with 425 additions and 428 deletions

View File

@ -0,0 +1,2 @@
public _laser_line_endpoint
_laser_line_endpoint Point <?>

View File

@ -0,0 +1,419 @@
; void lasers_update(void);
public lasers_update
lasers_update proc near
push bp
mov bp, sp
push si
push di
mov si, offset _lasers
xor di, di
jmp @@more?
@@loop:
cmp [si+laser_t.mode], LM_NONE
jz @@next
cmp _bullet_clear_time, 0
jnz short @@shootout
cmp _bullet_clear_trigger, 0
jz short @@switch
@@shootout:
cmp [si+laser_t.mode], LM_SHOOTOUT
jnz short @@switch
mov [si+laser_t.mode], LM_DECAY
mov ax, [si+laser_t.shootout_speed]
cwd
sub ax, dx
sar ax, 1
mov [si+laser_t.shootout_speed], ax
@@switch:
mov al, [si+laser_t.mode]
mov ah, 0
dec ax
mov bx, ax
cmp bx, 6
ja @@age_inc
add bx, bx
jmp cs:lasers_update_switch[bx]
laser_update_shootout:
cmp [si+laser_t.coords.starts_at_distance], (550 shl 4)
jge short loc_FC52
mov ax, [si+laser_t.shootout_speed]
add [si+laser_t.coords.ends_at_distance], ax
loc_FC52:
mov ax, [si+laser_t.LASER_age]
cmp ax, [si+laser_t.moveout_at_age]
jl short loc_FC60
mov ax, [si+laser_t.shootout_speed]
add [si+laser_t.coords.starts_at_distance], ax
loc_FC60:
call laser_hittest pascal, si
jmp @@age_inc
; ---------------------------------------------------------------------------
laser_update_fixed_wait_to_grow:
cmp [si+laser_t.grow_at_age], 0
jle @@age_inc
mov ax, [si+laser_t.LASER_age]
cmp ax, [si+laser_t.grow_at_age]
jl @@age_inc
inc [si+laser_t.mode]
call snd_se_play pascal, 6
jmp @@age_inc
; ---------------------------------------------------------------------------
laser_update_fixed_grow:
test byte ptr [si+laser_t.LASER_age], 1
jz short @@grow_step
mov al, [si+laser_t.coords.LASER_width]
add al, 2
mov [si+laser_t.coords.LASER_width], al
@@grow_step:
mov al, [si+laser_t.coords.LASER_width]
cmp al, [si+laser_t.grow_to_width]
jb short @@age_inc
jmp short @@next_mode
; ---------------------------------------------------------------------------
laser_update_fixed_active:
call laser_hittest pascal, si
cmp [si+laser_t.shrink_at_age], 0
jle short @@age_inc
mov ax, [si+laser_t.LASER_age]
cmp ax, [si+laser_t.shrink_at_age]
jl short @@age_inc
@@next_mode:
inc [si+laser_t.mode]
jmp short @@age_inc
; ---------------------------------------------------------------------------
laser_update_fixed_shrink:
test byte ptr [si+laser_t.LASER_age], 1
jz short @@delete?
mov al, [si+laser_t.coords.LASER_width]
add al, -2
mov [si+laser_t.coords.LASER_width], al
@@delete?:
cmp [si+laser_t.coords.LASER_width], 1
jge short @@age_inc
jmp short @@delete
; ---------------------------------------------------------------------------
laser_update_fixed_shrink_and_wait_to_grow:
test byte ptr [si+laser_t.LASER_age], 1
jz short @@shrink_and_wait_to_grow_step
mov al, [si+laser_t.coords.LASER_width]
add al, -2
mov [si+laser_t.coords.LASER_width], al
@@shrink_and_wait_to_grow_step:
cmp [si+laser_t.coords.LASER_width], 1
jg short @@age_inc
mov [si+laser_t.mode], LM_FIXED_WAIT_TO_GROW
mov [si+laser_t.LASER_age], 0
jmp short @@age_inc
; ---------------------------------------------------------------------------
laser_update_decay:
cmp [si+laser_t.coords.starts_at_distance], (550 shl 4)
jge short loc_FCF4
mov ax, [si+laser_t.shootout_speed]
add [si+laser_t.coords.ends_at_distance], ax
loc_FCF4:
mov ax, [si+laser_t.LASER_age]
cmp ax, [si+laser_t.moveout_at_age]
jl short loc_FD02
mov ax, [si+laser_t.shootout_speed]
add [si+laser_t.coords.starts_at_distance], ax
loc_FD02:
mov al, [si+laser_t.coords.LASER_width]
add al, 2
mov [si+laser_t.coords.LASER_width], al
cmp [si+laser_t.coords.LASER_width], 28
jb short @@age_inc
@@delete:
mov [si+laser_t.mode], LM_NONE
@@age_inc:
inc [si+laser_t.LASER_age]
@@next:
inc di
add si, size laser_t
@@more?:
cmp di, LASER_COUNT
jl @@loop
pop di
pop si
pop bp
retn
lasers_update endp
; ---------------------------------------------------------------------------
lasers_update_switch label word
dw offset laser_update_shootout
dw offset laser_update_fixed_wait_to_grow
dw offset laser_update_fixed_grow
dw offset laser_update_fixed_active
dw offset laser_update_fixed_shrink
dw offset laser_update_fixed_shrink_and_wait_to_grow
dw offset laser_update_decay
; ---------------------------------------------------------------------------
; void near lasers_render(void);
public lasers_render
lasers_render proc near
@@radius = byte ptr -0Ah
@@width_orig = byte ptr -9
@@end_distance_orig = word ptr -8
@@draw_y = word ptr -6
@@draw_x = word ptr -4
@@i = word ptr -2
push bp
mov bp, sp
sub sp, 0Ah
push si
push di
mov si, offset _lasers
mov [bp+@@i], 0
jmp @@more_lasers?
; ---------------------------------------------------------------------------
@@laser_loop:
cmp [si+laser_t.mode], LM_NONE
jz @@next_laser
mov al, [si+laser_t.coords.LASER_width]
mov [bp+@@width_orig], al
mov [bp+@@radius], al
push offset _drawpoint
push [si+laser_t.coords.origin.x]
push [si+laser_t.coords.origin.y]
push (16 shl 4)
mov al, [si+laser_t.coords.angle]
mov ah, 0
push ax
call vector2_at
mov ax, _drawpoint.x
sar ax, 4
add ax, 32
mov [bp+@@draw_x], ax
mov ax, _drawpoint.y
sar ax, 4
add ax, 16
mov [bp+@@draw_y], ax
cmp [si+laser_t.mode], LM_DECAY
jz @@decay
cmp [bp+@@radius], 2
jnb short @@draw_outer_circle?
mov [bp+@@radius], 2
@@draw_outer_circle?:
cmp [si+laser_t.coords.LASER_width], 3
jb short @@draw_inner_circle?
mov ah, [si+laser_t.LASER_color]
call _grcg_setcolor_direct_noint_1
cmp [si+laser_t.coords.starts_at_distance], (16 shl 4)
jg short @@draw_outer_ray?
push [bp+@@draw_x]
push [bp+@@draw_y]
mov al, [bp+@@radius]
mov ah, 0
push ax
call grcg_circlefill
mov al, [bp+@@radius]
add al, -2
mov [bp+@@radius], al
@@draw_outer_ray?:
cmp [si+laser_t.coords.ends_at_distance], (2 shl 4)
jle short @@draw_inner
mov ax, [si+laser_t.coords.ends_at_distance]
mov [bp+@@end_distance_orig], ax
sub [si+laser_t.coords.ends_at_distance], (2 shl 4)
lea ax, [si+laser_t.coords]
call laser_render_ray pascal, ax
mov ax, [bp+@@end_distance_orig]
mov [si+laser_t.coords.ends_at_distance], ax
@@draw_inner:
cmp [si+laser_t.coords.LASER_width], 5
jb short @@sub_2
mov al, [si+laser_t.coords.LASER_width]
add al, -4
jmp short @@set_inner_width
; ---------------------------------------------------------------------------
@@sub_2:
mov al, [si+laser_t.coords.LASER_width]
add al, -2
@@set_inner_width:
mov [si+laser_t.coords.LASER_width], al
@@draw_inner_circle?:
mov ah, 15
call _grcg_setcolor_direct_noint_1
cmp [si+laser_t.coords.starts_at_distance], (16 shl 4)
jg short @@draw_inner_ray_or_line?
push [bp+@@draw_x]
push [bp+@@draw_y]
mov al, [bp+@@radius]
mov ah, 0
push ax
call grcg_circlefill
@@draw_inner_ray_or_line?:
cmp [si+laser_t.coords.LASER_width], 1
ja short @@draw_inner_ray
push offset _drawpoint
push [si+laser_t.coords.origin.x]
push [si+laser_t.coords.origin.y]
push [si+laser_t.coords.starts_at_distance]
mov al, [si+laser_t.coords.angle]
mov ah, 0
push ax
call vector2_at
push offset _laser_line_endpoint
push [si+laser_t.coords.origin.x]
push [si+laser_t.coords.origin.y]
push [si+laser_t.coords.ends_at_distance]
mov al, [si+laser_t.coords.angle]
mov ah, 0
push ax
call vector2_at
mov ax, _drawpoint.x
sar ax, 4
add ax, 32
mov _drawpoint.x, ax
mov ax, _drawpoint.y
sar ax, 4
add ax, 16
mov _drawpoint.y, ax
mov ax, _laser_line_endpoint.x
sar ax, 4
add ax, 32
mov _laser_line_endpoint.x, ax
mov ax, _laser_line_endpoint.y
sar ax, 4
add ax, 16
mov _laser_line_endpoint.y, ax
push _drawpoint.x
push _drawpoint.y
push _laser_line_endpoint.x
push ax
call grcg_line
jmp @@width_reset
; ---------------------------------------------------------------------------
@@draw_inner_ray:
lea ax, [si+laser_t.coords]
call laser_render_ray pascal, ax
or ax, ax
jz @@width_reset
mov [si+laser_t.mode], LM_NONE
jmp @@width_reset
; ---------------------------------------------------------------------------
@@decay:
mov ah, 15
call _grcg_setcolor_direct_noint_1
shl [bp+@@radius], 3
push offset _drawpoint
push [si+laser_t.coords.origin.x]
push [si+laser_t.coords.origin.y]
mov al, [bp+@@radius]
mov ah, 0
push ax
mov al, [si+laser_t.coords.angle]
mov ah, 0
add ax, 64
push ax
call vector2_at
xor di, di
jmp @@more_decay_lines?
; ---------------------------------------------------------------------------
@@decay_line_draw:
push offset _laser_line_endpoint
push _drawpoint.x
push _drawpoint.y
push [si+laser_t.coords.ends_at_distance]
mov al, [si+laser_t.coords.angle]
mov ah, 0
push ax
call vector2_at
push offset _drawpoint
push _drawpoint.x
push _drawpoint.y
push [si+laser_t.coords.starts_at_distance]
mov al, [si+laser_t.coords.angle]
mov ah, 0
push ax
call vector2_at
mov ax, _drawpoint.x
sar ax, 4
add ax, 32
mov _drawpoint.x, ax
mov ax, _drawpoint.y
sar ax, 4
add ax, 16
mov _drawpoint.y, ax
mov ax, _laser_line_endpoint.x
sar ax, 4
add ax, 32
mov _laser_line_endpoint.x, ax
mov ax, _laser_line_endpoint.y
sar ax, 4
add ax, 16
mov _laser_line_endpoint.y, ax
push _drawpoint.x
push _drawpoint.y
push _laser_line_endpoint.x
push ax
call grcg_line
push offset _drawpoint
push [si+laser_t.coords.origin.x]
push [si+laser_t.coords.origin.y]
mov al, [bp+@@radius]
mov ah, 0
push ax
mov al, [si+laser_t.coords.angle]
mov ah, 0
add ax, (-4 shl 4)
push ax
call vector2_at
inc di
@@more_decay_lines?:
cmp di, 2
jl @@decay_line_draw
@@width_reset:
mov al, [bp+@@width_orig]
mov [si+laser_t.coords.LASER_width], al
@@next_laser:
inc [bp+@@i]
add si, size laser_t
@@more_lasers?:
cmp [bp+@@i], LASER_COUNT
jl @@laser_loop
pop di
pop si
leave
retn
lasers_render endp

View File

@ -416,7 +416,7 @@ loc_AEF0:
call sub_C1B6
call sub_1214A
call sub_1240B
call sub_FBFB
call lasers_update
call sub_17C04
call sub_1607D
call farfp_2C990
@ -436,7 +436,7 @@ loc_AF2D:
call sub_12263
call _grcg_setmode_rmw_1
call fp_2D06C
call sub_FD33
call lasers_render
call sub_16B4E
call sub_C202
call sub_F7A5
@ -10231,430 +10231,7 @@ loc_FBF7:
retn
sub_FAA3 endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_FBFB proc near
push bp
mov bp, sp
push si
push di
mov si, offset _lasers
xor di, di
jmp loc_FD1A
; ---------------------------------------------------------------------------
loc_FC08:
cmp byte ptr [si], 0
jz loc_FD16
cmp _bullet_clear_time, 0
jnz short loc_FC1D
cmp _bullet_clear_trigger, 0
jz short loc_FC30
loc_FC1D:
cmp byte ptr [si], 1
jnz short loc_FC30
mov byte ptr [si], 7
mov ax, [si+0Ch]
cwd
sub ax, dx
sar ax, 1
mov [si+0Ch], ax
loc_FC30:
mov al, [si]
mov ah, 0
dec ax
mov bx, ax
cmp bx, 6
ja loc_FD13
add bx, bx
jmp cs:off_FD25[bx]
loc_FC45:
cmp word ptr [si+6], 2260h
jge short loc_FC52
mov ax, [si+0Ch]
add [si+8], ax
loc_FC52:
mov ax, [si+0Eh]
cmp ax, [si+10h]
jl short loc_FC60
mov ax, [si+0Ch]
add [si+6], ax
loc_FC60:
call laser_hittest pascal, si
jmp loc_FD13
; ---------------------------------------------------------------------------
loc_FC67:
cmp word ptr [si+10h], 0
jle loc_FD13
mov ax, [si+0Eh]
cmp ax, [si+10h]
jl loc_FD13
inc byte ptr [si]
call snd_se_play pascal, 6
jmp loc_FD13
; ---------------------------------------------------------------------------
loc_FC85:
test byte ptr [si+0Eh], 1
jz short loc_FC93
mov al, [si+0Bh]
add al, 2
mov [si+0Bh], al
loc_FC93:
mov al, [si+0Bh]
cmp al, [si+14h]
jb short loc_FD13
jmp short loc_FCAF
; ---------------------------------------------------------------------------
loc_FC9D:
call laser_hittest pascal, si
cmp word ptr [si+12h], 0
jle short loc_FD13
mov ax, [si+0Eh]
cmp ax, [si+12h]
jl short loc_FD13
loc_FCAF:
inc byte ptr [si]
jmp short loc_FD13
; ---------------------------------------------------------------------------
loc_FCB3:
test byte ptr [si+0Eh], 1
jz short loc_FCC1
mov al, [si+0Bh]
add al, 0FEh
mov [si+0Bh], al
loc_FCC1:
cmp byte ptr [si+0Bh], 1
jge short loc_FD13
jmp short loc_FD10
; ---------------------------------------------------------------------------
loc_FCC9:
test byte ptr [si+0Eh], 1
jz short loc_FCD7
mov al, [si+0Bh]
add al, 0FEh
mov [si+0Bh], al
loc_FCD7:
cmp byte ptr [si+0Bh], 1
jg short loc_FD13
mov byte ptr [si], 2
mov word ptr [si+0Eh], 0
jmp short loc_FD13
; ---------------------------------------------------------------------------
loc_FCE7:
cmp word ptr [si+6], 2260h
jge short loc_FCF4
mov ax, [si+0Ch]
add [si+8], ax
loc_FCF4:
mov ax, [si+0Eh]
cmp ax, [si+10h]
jl short loc_FD02
mov ax, [si+0Ch]
add [si+6], ax
loc_FD02:
mov al, [si+0Bh]
add al, 2
mov [si+0Bh], al
cmp byte ptr [si+0Bh], 1Ch
jb short loc_FD13
loc_FD10:
mov byte ptr [si], 0
loc_FD13:
inc word ptr [si+0Eh]
loc_FD16:
inc di
add si, 18h
loc_FD1A:
cmp di, 20h ; ' '
jl loc_FC08
pop di
pop si
pop bp
retn
sub_FBFB endp
; ---------------------------------------------------------------------------
off_FD25 dw offset loc_FC45
dw offset loc_FC67
dw offset loc_FC85
dw offset loc_FC9D
dw offset loc_FCB3
dw offset loc_FCC9
dw offset loc_FCE7
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_FD33 proc near
var_A = byte ptr -0Ah
var_9 = byte ptr -9
var_8 = word ptr -8
var_6 = word ptr -6
var_4 = word ptr -4
var_2 = word ptr -2
push bp
mov bp, sp
sub sp, 0Ah
push si
push di
mov si, offset _lasers
mov [bp+var_2], 0
jmp loc_FF6D
; ---------------------------------------------------------------------------
loc_FD46:
cmp byte ptr [si], 0
jz loc_FF67
mov al, [si+0Bh]
mov [bp+var_9], al
mov [bp+var_A], al
push offset _drawpoint
push word ptr [si+2]
push word ptr [si+4]
push (16 shl 4)
mov al, [si+0Ah]
mov ah, 0
push ax
call vector2_at
mov ax, _drawpoint.x
sar ax, 4
add ax, 32
mov [bp+var_4], ax
mov ax, _drawpoint.y
sar ax, 4
add ax, 16
mov [bp+var_6], ax
cmp byte ptr [si], 7
jz loc_FE9D
cmp [bp+var_A], 2
jnb short loc_FD96
mov [bp+var_A], 2
loc_FD96:
cmp byte ptr [si+0Bh], 3
jb short loc_FDF4
mov ah, [si+1]
call _grcg_setcolor_direct_noint_1
cmp word ptr [si+6], 100h
jg short loc_FDC2
push [bp+var_4]
push [bp+var_6]
mov al, [bp+var_A]
mov ah, 0
push ax
call grcg_circlefill
mov al, [bp+var_A]
add al, 0FEh
mov [bp+var_A], al
loc_FDC2:
cmp word ptr [si+8], 20h ; ' '
jle short loc_FDDF
mov ax, [si+8]
mov [bp+var_8], ax
sub word ptr [si+8], 20h ; ' '
lea ax, [si+2]
call laser_render_ray pascal, ax
mov ax, [bp+var_8]
mov [si+8], ax
loc_FDDF:
cmp byte ptr [si+0Bh], 5
jb short loc_FDEC
mov al, [si+0Bh]
add al, 0FCh
jmp short loc_FDF1
; ---------------------------------------------------------------------------
loc_FDEC:
mov al, [si+0Bh]
add al, 0FEh
loc_FDF1:
mov [si+0Bh], al
loc_FDF4:
mov ah, 0Fh
call _grcg_setcolor_direct_noint_1
cmp word ptr [si+6], 100h
jg short loc_FE11
push [bp+var_4]
push [bp+var_6]
mov al, [bp+var_A]
mov ah, 0
push ax
call grcg_circlefill
loc_FE11:
cmp byte ptr [si+0Bh], 1
ja short loc_FE8A
push offset _drawpoint
push word ptr [si+2]
push word ptr [si+4]
push word ptr [si+6]
mov al, [si+0Ah]
mov ah, 0
push ax
call vector2_at
push 0BFBEh
push word ptr [si+2]
push word ptr [si+4]
push word ptr [si+8]
mov al, [si+0Ah]
mov ah, 0
push ax
call vector2_at
mov ax, _drawpoint.x
sar ax, 4
add ax, 32
mov _drawpoint.x, ax
mov ax, _drawpoint.y
sar ax, 4
add ax, 16
mov _drawpoint.y, ax
mov ax, word_2C99E
sar ax, 4
add ax, 32
mov word_2C99E, ax
mov ax, word_2C9A0
sar ax, 4
add ax, 16
mov word_2C9A0, ax
push _drawpoint.x
push _drawpoint.y
push word_2C99E
push ax
call grcg_line
jmp loc_FF61
; ---------------------------------------------------------------------------
loc_FE8A:
lea ax, [si+2]
call laser_render_ray pascal, ax
or ax, ax
jz loc_FF61
mov byte ptr [si], 0
jmp loc_FF61
; ---------------------------------------------------------------------------
loc_FE9D:
mov ah, 0Fh
call _grcg_setcolor_direct_noint_1
shl [bp+var_A], 3
push offset _drawpoint
push word ptr [si+2]
push word ptr [si+4]
mov al, [bp+var_A]
mov ah, 0
push ax
mov al, [si+0Ah]
mov ah, 0
add ax, 40h
push ax
call vector2_at
xor di, di
jmp loc_FF5A
; ---------------------------------------------------------------------------
loc_FEC8:
push 0BFBEh
push _drawpoint.x
push _drawpoint.y
push word ptr [si+8]
mov al, [si+0Ah]
mov ah, 0
push ax
call vector2_at
push offset _drawpoint
push _drawpoint.x
push _drawpoint.y
push word ptr [si+6]
mov al, [si+0Ah]
mov ah, 0
push ax
call vector2_at
mov ax, _drawpoint.x
sar ax, 4
add ax, 32
mov _drawpoint.x, ax
mov ax, _drawpoint.y
sar ax, 4
add ax, 16
mov _drawpoint.y, ax
mov ax, word_2C99E
sar ax, 4
add ax, 32
mov word_2C99E, ax
mov ax, word_2C9A0
sar ax, 4
add ax, 16
mov word_2C9A0, ax
push _drawpoint.x
push _drawpoint.y
push word_2C99E
push ax
call grcg_line
push offset _drawpoint
push word ptr [si+2]
push word ptr [si+4]
mov al, [bp+var_A]
mov ah, 0
push ax
mov al, [si+0Ah]
mov ah, 0
add ax, (-4 shl 4)
push ax
call vector2_at
inc di
loc_FF5A:
cmp di, 2
jl loc_FEC8
loc_FF61:
mov al, [bp+var_9]
mov [si+0Bh], al
loc_FF67:
inc [bp+var_2]
add si, 18h
loc_FF6D:
cmp [bp+var_2], 20h ; ' '
jl loc_FD46
pop di
pop si
leave
retn
sub_FD33 endp
include th05/lasers_update_render.asm
; =============== S U B R O U T I N E =======================================
@ -52017,8 +51594,7 @@ farfp_2C996 dd ?
fp_2C99A dw ?
byte_2C99C db ?
db ?
word_2C99E dw ?
word_2C9A0 dw ?
include th05/lasers_render[bss].asm
dd ? ;
dd ? ;
dd ? ;