[Reverse-engineering] [th04/th05] Player character display

Including options and the death explosions.

Part of P0035, funded by zorg.
This commit is contained in:
nmlgc 2019-09-23 17:24:45 +02:00
parent 68c9a3c79c
commit 290935fe3e
6 changed files with 166 additions and 308 deletions

View File

@ -75,6 +75,12 @@ PLAYFIELD_X = 32
PLAYFIELD_Y = 16
PLAYFIELD_W = 384
PLAYFIELD_H = 368
PLAYFIELD_LEFT = PLAYFIELD_X
PLAYFIELD_TOP = PLAYFIELD_Y
PLAYFIELD_RIGHT = PLAYFIELD_X + PLAYFIELD_W
PLAYFIELD_BOTTOM = PLAYFIELD_Y + PLAYFIELD_H
PLAYFIELD_VRAM_X = PLAYFIELD_X / 8
PLAYFIELD_VRAM_W = PLAYFIELD_W / 8

2
th02/player/player.inc Normal file
View File

@ -0,0 +1,2 @@
PLAYER_W = 32
PLAYER_H = 48

View File

@ -1,5 +1,25 @@
include th02/player/player.inc
PLAYER_OPTION_W = 16
PLAYER_OPTION_H = 16
MISS_ANIM_FRAMES = 32
MISS_ANIM_FLASH_AT = 28
MISS_ANIM_EXPLODE_UNTIL = 31
MISS_EXPLOSION_COUNT = 8
MISS_EXPLOSION_W = 48
MISS_EXPLOSION_H = 48
MISS_EXPLOSION_CLIP macro clip_label
cmp _drawpoint.y, ((PLAYFIELD_TOP - (MISS_EXPLOSION_H / 2)) shl 4)
jl short clip_label
; Yes, the next two are incorrect
cmp _drawpoint.y, ((PLAYFIELD_BOTTOM - 8) shl 4)
jge short clip_label
cmp _drawpoint.x, ((PLAYFIELD_LEFT - 40) shl 4)
jl short clip_label
cmp _drawpoint.x, ((PLAYFIELD_RIGHT - (MISS_EXPLOSION_W / 2)) shl 4)
jge short clip_label
endm
MISS_INVINCIBILITY_FRAMES = 192

132
th04/player/render.asm Normal file
View File

@ -0,0 +1,132 @@
; void pascal near player_render(void);
public PLAYER_RENDER
player_render proc near
@@angle = byte ptr -5
@@i = word ptr -4
@@screen_y = word ptr -2
@@patnum equ si
enter 6, 0
push si
push di
cmp _miss_time, 0
jz short @@alive
cmp _miss_time, MISS_ANIM_FRAMES
jbe @@in_miss_anim
@@alive:
mov ax, player_pos.cur.x
sar ax, 4
add ax, PLAYFIELD_X - (PLAYER_W / 2)
mov di, ax
mov ax, player_pos.cur.y
add ax, ((PLAYFIELD_Y - (PLAYER_H / 2)) shl 4)
call scroll_subpixel_y_to_vram_seg1 pascal, ax
mov [bp+@@screen_y], ax
cmp player_pos.velocity.x, 0
jge short @@moving_right?
mov @@patnum, 1
jmp short @@invincible?
@@moving_right?:
cmp player_pos.velocity.x, 0
jz short @@no_x_movement
mov @@patnum, 2
jmp short @@invincible?
@@no_x_movement:
xor @@patnum, @@patnum
; ---------------------------------------------------------------------------
@@invincible?:
cmp _player_invincibility_time, 0
jz short @@render_regular
cmp frame_mod4, 0
jnz short @@render_regular
call super_roll_put_1plane pascal, di, [bp+@@screen_y], @@patnum, large PLANE_PUT or GC_BRGI
jmp short @@got_options?
@@render_regular:
call super_roll_put pascal, di, [bp+@@screen_y], @@patnum
@@got_options?:
cmp shot_level, 2
jb @@ret
call grcg_setmode_rmw_1
mov ax, _player_option_pos_cur.x
sar ax, 4
; Technically, DI = AX + PLAYFIELD_X - (PLAYER_W / 2) - PLAYER_OPTION_W
mov di, ax
mov ax, _player_option_pos_cur.y
add ax, ((PLAYFIELD_Y - (PLAYER_OPTION_H / 2)) shl 4)
call scroll_subpixel_y_to_vram_seg1 pascal, ax
mov [bp+@@screen_y], ax
mov ax, di
mov dx, [bp+@@screen_y]
push _player_option_patnum
call z_super_roll_put_tiny
lea ax, [di + PLAYER_OPTION_W + PLAYER_W]
mov dx, [bp+@@screen_y]
push _player_option_patnum
call z_super_roll_put_tiny
GRCG_OFF_CLOBBERING dx
jmp @@ret
; ---------------------------------------------------------------------------
@@in_miss_anim:
cmp _miss_time, MISS_ANIM_FRAMES - MISS_ANIM_EXPLODE_UNTIL
jbe @@ret
mov si, _miss_explosion_radius
mov [bp+@@i], 0
mov al, _miss_explosion_angle
jmp short @@more?
@@loop:
cmp [bp+@@i], MISS_EXPLOSION_COUNT / 2
jnz short @@put
mov ax, si
cwd
sub ax, dx
sar ax, 1
mov si, ax
mov al, [bp+@@angle]
neg al
mov [bp+@@angle], al
@@put:
push offset _drawpoint
push player_pos.cur.x
push player_pos.cur.y
push si
mov al, [bp+@@angle]
mov ah, 0
push ax
call vector2_at
MISS_EXPLOSION_CLIP @@next
mov ax, _drawpoint.x
sar ax, 4
add ax, PLAYFIELD_X - (MISS_EXPLOSION_W / 2)
mov di, ax
mov ax, _drawpoint.y
add ax, ((PLAYFIELD_Y - (MISS_EXPLOSION_H / 2)) shl 4)
call scroll_subpixel_y_to_vram_seg1 pascal, ax
mov [bp+@@screen_y], ax
call super_roll_put pascal, di, ax, 3
@@next:
inc [bp+@@i]
mov al, [bp+@@angle]
add al, 256 / (MISS_EXPLOSION_COUNT / 2)
@@more?:
mov [bp+@@angle], al
cmp [bp+@@i], MISS_EXPLOSION_COUNT
jl short @@loop
@@ret:
pop di
pop si
leave
retn
player_render endp

View File

@ -388,7 +388,7 @@ loc_ABD8:
call _midboss_render
call main_01:sub_10713
call main_01:sub_10552
call main_01:sub_10BFD
call main_01:player_render
call main_01:grcg_setmode_rmw_1
call sub_13C5C
call main_01:sparks_render
@ -11384,156 +11384,7 @@ loc_10BFA:
retn
sub_10ABF endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_10BFD proc near
var_5 = byte ptr -5
var_4 = word ptr -4
var_2 = word ptr -2
enter 6, 0
push si
push di
cmp _miss_time, 0
jz short loc_10C13
cmp _miss_time, MISS_ANIM_FRAMES
jbe loc_10CB2
loc_10C13:
mov ax, player_pos.cur.x
sar ax, 4
add ax, 10h
mov di, ax
mov ax, player_pos.cur.y
add ax, -128
call main_01:scroll_subpixel_y_to_vram_seg1 pascal, ax
mov [bp+var_2], ax
cmp player_pos.velocity.x, 0
jge short loc_10C37
mov si, 1
jmp short loc_10C45
; ---------------------------------------------------------------------------
loc_10C37:
cmp player_pos.velocity.x, 0
jz short loc_10C43
mov si, 2
jmp short loc_10C45
; ---------------------------------------------------------------------------
loc_10C43:
xor si, si
loc_10C45:
cmp _player_invincibility_time, 0
jz short loc_10C65
cmp frame_mod4, 0
jnz short loc_10C65
call super_roll_put_1plane pascal, di, [bp+var_2], si, large PLANE_PUT or GC_BRGI
jmp short loc_10C6F
; ---------------------------------------------------------------------------
loc_10C65:
push di
push [bp+var_2]
push si
call super_roll_put
loc_10C6F:
cmp shot_level, 2
jb loc_10D47
call main_01:grcg_setmode_rmw_1
mov ax, _player_option_pos_cur.x
sar ax, 4
mov di, ax
mov ax, _player_option_pos_cur.y
add ax, (8 shl 4)
call main_01:scroll_subpixel_y_to_vram_seg1 pascal, ax
mov [bp+var_2], ax
mov ax, di
mov dx, [bp+var_2]
push _player_option_patnum
call main_01:z_super_roll_put_tiny
lea ax, [di+30h]
mov dx, [bp+var_2]
push _player_option_patnum
call main_01:z_super_roll_put_tiny
GRCG_OFF_CLOBBERING dx
jmp loc_10D47
; ---------------------------------------------------------------------------
loc_10CB2:
cmp _miss_time, MISS_ANIM_FRAMES - MISS_ANIM_EXPLODE_UNTIL
jbe loc_10D47
mov si, _miss_explosion_radius
mov [bp+var_4], 0
mov al, _miss_explosion_angle
jmp short loc_10D3E
; ---------------------------------------------------------------------------
loc_10CC9:
cmp [bp+var_4], 4
jnz short loc_10CE0
mov ax, si
cwd
sub ax, dx
sar ax, 1
mov si, ax
mov al, [bp+var_5]
neg al
mov [bp+var_5], al
loc_10CE0:
push offset _drawpoint
push player_pos.cur.x
push player_pos.cur.y
push si
mov al, [bp+var_5]
mov ah, 0
push ax
call vector2_at
cmp _drawpoint.y, (-8 shl 4)
jl short loc_10D36
cmp _drawpoint.y, (376 shl 4)
jge short loc_10D36
cmp _drawpoint.x, (-8 shl 4)
jl short loc_10D36
cmp _drawpoint.x, (392 shl 4)
jge short loc_10D36
mov ax, _drawpoint.x
sar ax, 4
add ax, 8
mov di, ax
mov ax, _drawpoint.y
add ax, (-8 shl 4)
call main_01:scroll_subpixel_y_to_vram_seg1 pascal, ax
mov [bp+var_2], ax
push di
push ax
push 3
call super_roll_put
loc_10D36:
inc [bp+var_4]
mov al, [bp+var_5]
add al, 40h
loc_10D3E:
mov [bp+var_5], al
cmp [bp+var_4], 8
jl short loc_10CC9
loc_10D47:
pop di
pop si
leave
retn
sub_10BFD endp
include th04/player/render.asm
; =============== S U B R O U T I N E =======================================
@ -13212,9 +13063,7 @@ sub_11ECB proc near
mov _bullet_clear_trigger, 0
mov word_2CFFC, 0
mov _circles_color, GC_R
push 200010h
push 19F017Fh
call grc_setclip
call grc_setclip pascal, large (PLAYFIELD_X shl 16) or PLAYFIELD_Y, large ((PLAYFIELD_RIGHT - 1) shl 16) or (PLAYFIELD_BOTTOM - 1)
push offset _shots
push size _shots / 4
call main_01:sub_C34E

View File

@ -433,7 +433,7 @@ loc_AF2D:
call _midboss_render
call sub_EBB7
call sub_125A3
call sub_12263
call player_render
call grcg_setmode_rmw_1
call _boss_custombullets_render
call lasers_render
@ -7158,9 +7158,7 @@ sub_EACE proc near
mov _bullet_clear_trigger, 0
mov word_2C97A, 0
mov _circles_color, GC_R
push 200010h
push 19F017Fh
call grc_setclip
call grc_setclip pascal, large (PLAYFIELD_X shl 16) or PLAYFIELD_Y, large ((PLAYFIELD_RIGHT - 1) shl 16) or (PLAYFIELD_BOTTOM - 1)
push offset _hitshots
push size _hitshots / 4
call sub_E708
@ -13005,156 +13003,7 @@ loc_12260:
retn
sub_1214A endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_12263 proc near
var_5 = byte ptr -5
var_4 = word ptr -4
var_2 = word ptr -2
enter 6, 0
push si
push di
cmp _miss_time, 0
jz short loc_12279
cmp _miss_time, MISS_ANIM_FRAMES
jbe loc_12314
loc_12279:
mov ax, player_pos.cur.x
sar ax, 4
add ax, 10h
mov di, ax
mov ax, player_pos.cur.y
add ax, -128
call scroll_subpixel_y_to_vram_seg1 pascal, ax
mov [bp+var_2], ax
cmp player_pos.velocity.x, 0
jge short loc_1229D
mov si, 1
jmp short loc_122AB
; ---------------------------------------------------------------------------
loc_1229D:
cmp player_pos.velocity.x, 0
jz short loc_122A9
mov si, 2
jmp short loc_122AB
; ---------------------------------------------------------------------------
loc_122A9:
xor si, si
loc_122AB:
cmp _player_invincibility_time, 0
jz short loc_122CB
cmp frame_mod4, 0
jnz short loc_122CB
call super_roll_put_1plane pascal, di, [bp+var_2], si, large PLANE_PUT or GC_BRGI
jmp short loc_122D5
; ---------------------------------------------------------------------------
loc_122CB:
push di
push [bp+var_2]
push si
call super_roll_put
loc_122D5:
cmp shot_level, 2
jb loc_123A9
call grcg_setmode_rmw_1
mov ax, _player_option_pos_cur.x
sar ax, 4
mov di, ax
mov ax, _player_option_pos_cur.y
add ax, (8 shl 4)
call scroll_subpixel_y_to_vram_seg1 pascal, ax
mov [bp+var_2], ax
mov ax, di
mov dx, [bp+var_2]
push _player_option_patnum
call z_super_roll_put_tiny
lea ax, [di+30h]
mov dx, [bp+var_2]
push _player_option_patnum
call z_super_roll_put_tiny
GRCG_OFF_CLOBBERING dx
jmp loc_123A9
; ---------------------------------------------------------------------------
loc_12314:
cmp _miss_time, MISS_ANIM_FRAMES - MISS_ANIM_EXPLODE_UNTIL
jbe loc_123A9
mov si, _miss_explosion_radius
mov [bp+var_4], 0
mov al, _miss_explosion_angle
jmp short loc_123A0
; ---------------------------------------------------------------------------
loc_1232B:
cmp [bp+var_4], 4
jnz short loc_12342
mov ax, si
cwd
sub ax, dx
sar ax, 1
mov si, ax
mov al, [bp+var_5]
neg al
mov [bp+var_5], al
loc_12342:
push offset _drawpoint
push player_pos.cur.x
push player_pos.cur.y
push si
mov al, [bp+var_5]
mov ah, 0
push ax
call vector2_at
cmp _drawpoint.y, (-8 shl 4)
jl short loc_12398
cmp _drawpoint.y, (376 shl 4)
jge short loc_12398
cmp _drawpoint.x, (-8 shl 4)
jl short loc_12398
cmp _drawpoint.x, (392 shl 4)
jge short loc_12398
mov ax, _drawpoint.x
sar ax, 4
add ax, 8
mov di, ax
mov ax, _drawpoint.y
add ax, (-8 shl 4)
call scroll_subpixel_y_to_vram_seg1 pascal, ax
mov [bp+var_2], ax
push di
push ax
push 3
call super_roll_put
loc_12398:
inc [bp+var_4]
mov al, [bp+var_5]
add al, 40h
loc_123A0:
mov [bp+var_5], al
cmp [bp+var_4], 8
jl short loc_1232B
loc_123A9:
pop di
pop si
leave
retn
sub_12263 endp
include th04/player/render.asm
; =============== S U B R O U T I N E =======================================