Skip to content

Commit

Permalink
[Decompilation] [th01] Shootout lasers: Rendering and collision detec…
Browse files Browse the repository at this point in the history
…tion

Part of P0122, funded by Yanga.
  • Loading branch information
nmlgc committed Oct 6, 2020
1 parent 6155985 commit 243dbf8
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 174 deletions.
82 changes: 82 additions & 0 deletions th01/main/bullet/laser_s.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
extern "C" {
#include "libs/master.lib/master.h"
#include "platform.h"
#include "pc98.h"
#include "planar.h"
#include "th01/sprites/laser_s.h"
#include "th01/hardware/egc.h"
#include "th01/hardware/graph.h"
#include "th01/hardware/input.hpp"
#include "th01/main/playfld.hpp"
#include "th01/main/player/player.hpp"
#include "th01/main/bullet/laser_s.hpp"
}

void CShootoutLaser::spawn(
screen_x_t _origin_left,
Expand Down Expand Up @@ -44,3 +53,76 @@ void CShootoutLaser::spawn(
ray_moveout_speed = ray_extend_speed;
ray_length = 0;
}

void CShootoutLaser::hittest_and_render(void)
{
screen_x_t left = ray_i_left.to_pixel();
vram_y_t y = ray_i_y.to_pixel();
unsigned int i;
vram_offset_t vram_offset;
int preshift = (width_cel * PRESHIFT);
dots16_t dots = 0;
unsigned int pixel_count;

if(put_flag) {
pixel_count = ray_length;
grcg_setcolor_rmw(col);
} else {
pixel_count = ray_moveout_speed;
}

for(i = 0; i < pixel_count; i++) {
if(
((left >> 3) != ray_i_left.to_vram_byte_amount()) ||
(y != ray_i_y.to_pixel())
) {
if(put_flag) {
vram_offset = vram_offset_shift(left, y);
grcg_put(vram_offset, dots, 16);
dots = 0;

if(!player_invincible && damaging) {
if(
(y > (player_top + 8)) &&
((player_left + ((PLAYER_W / 8) * 1)) <= left) &&
((player_left + ((PLAYER_W / 8) * 6)) > left)
) {
done = true;
}
}
}
left = ray_i_left.to_pixel();
y = ray_i_y.to_pixel();
if(
(left > (PLAYFIELD_RIGHT - 2)) ||
(left < PLAYFIELD_LEFT) ||
(y < PLAYFIELD_TOP) ||
(y > (PLAYFIELD_BOTTOM - 1))
) {
break;
}
}

// MODDERS: Should just be
// sSHOOTOUT_LASER[preshift][(ray_i_left.to_pixel()...)].
// (Or actually, how about throwing away that sprite altogether?)
dots |= sSHOOTOUT_LASER[0][
preshift + (ray_i_left.to_pixel() & (BYTE_DOTS - 1))
];

if(put_flag == SL_RAY_UNPUT) {
egc_copy_rect_1_to_0_16(
ray_i_left.to_pixel(),
ray_i_y.to_pixel(),
(sizeof(dots) * BYTE_DOTS),
1
);
}
ray_i_left.v += step_x.v;
ray_i_y.v += step_y.v;
}

if(put_flag) {
grcg_off_func();
}
}
11 changes: 11 additions & 0 deletions th01/main/bullet/laser_s.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class LaserPixel {
// Code generation will require direct access to [v], if performing
// arithmetic with a local variable...
laser_pixel_t v;

int32_t to_pixel() const {
return (v >> 8);
}

int32_t to_vram_byte_amount() const {
return (v >> 11);
}
};
/// ------------------------

Expand Down Expand Up @@ -58,8 +66,11 @@ class CShootoutLaser {
char id; // unused

protected:
// MODDERS: Just turn into a parameter of hittest_and_render().
enum { SL_RAY_UNPUT = false, SL_RAY_PUT = true } put_flag;

void hittest_and_render(void);

public:
// Does nothing if this laser is already [alive]. No idea why the speed
// has to be passed like that - the function simply divides it by 8,
Expand Down
177 changes: 3 additions & 174 deletions th01_reiiden.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4572,179 +4572,14 @@ main_14_TEXT ends
; Segment type: Pure code
main_15_TEXT segment byte public 'CODE' use16
extern @CShootoutLaser@spawn$qiiiiiucii:proc
extern @CShootoutLaser@hittest_and_render$qv:proc
main_15_TEXT ends

main_15__TEXT segment byte public 'CODE' use16
assume cs:main_15
;org 0Dh
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing

; =============== S U B R O U T I N E =======================================

; Attributes: bp-based frame

sub_121AC proc far

var_A = word ptr -0Ah
@@dots = word ptr -8
var_6 = word ptr -6
var_4 = word ptr -4
var_2 = word ptr -2
arg_0 = dword ptr 6

enter 0Ah, 0
push si
push di
les bx, [bp+arg_0]
mov eax, es:[bx+10h]
sar eax, 8
mov si, ax
mov eax, es:[bx+14h]
sar eax, 8
mov di, ax
mov al, es:[bx+41h]
mov ah, 0
shl ax, 3
mov [bp+var_6], ax
mov [bp+@@dots], 0
cmp byte ptr es:[bx+44h], 0
jz short loc_121F9
mov ax, es:[bx+18h]
mov [bp+var_A], ax
mov al, es:[bx+40h]
mov ah, 0
call _grcg_setcolor_rmw stdcall, ax
pop cx
jmp short loc_12203
; ---------------------------------------------------------------------------

loc_121F9:
les bx, [bp+arg_0]
mov ax, es:[bx+1Ah]
mov [bp+var_A], ax

loc_12203:
mov [bp+var_2], 0
jmp loc_1232A
; ---------------------------------------------------------------------------

loc_1220B:
mov ax, si
sar ax, 3
cwde
les bx, [bp+arg_0]
mov edx, es:[bx+10h]
sar edx, 0Bh
cmp eax, edx
jnz short loc_12237
movsx eax, di
mov edx, es:[bx+14h]
sar edx, 8
cmp eax, edx
jz loc_122C7

loc_12237:
les bx, [bp+arg_0]
cmp byte ptr es:[bx+44h], 0
jz short loc_12299
mov ax, si
sar ax, 3
mov dx, di
shl dx, 6
add ax, dx
mov dx, di
shl dx, 4
add ax, dx
mov [bp+var_4], ax
les bx, _VRAM_PLANE_B
add bx, [bp+var_4]
mov ax, [bp+@@dots]
mov es:[bx], ax
mov [bp+@@dots], 0
cmp _player_invincible, 0
jnz short loc_12299
les bx, [bp+arg_0]
cmp byte ptr es:[bx+42h], 0
jz short loc_12299
cmp di, 178h
jle short loc_12299
mov ax, _player_left
add ax, 4
cmp ax, si
jg short loc_12299
mov ax, _player_left
add ax, 24
cmp ax, si
jle short loc_12299
mov _done, 1

loc_12299:
les bx, [bp+arg_0]
mov eax, es:[bx+10h]
sar eax, 8
mov si, ax
mov eax, es:[bx+14h]
sar eax, 8
mov di, ax
cmp si, 27Eh
jg short loc_12334
or si, si
jl short loc_12334
cmp di, 40h
jl short loc_12334
cmp di, 18Fh
jg short loc_12334

loc_122C7:
les bx, [bp+arg_0]
mov eax, es:[bx+10h]
sar eax, 8
and ax, 7
add ax, [bp+var_6]
add ax, ax
mov bx, ax
mov ax, word ptr _sSHOOTOUT_LASER[bx]
or [bp+@@dots], ax
mov bx, word ptr [bp+arg_0]
cmp byte ptr es:[bx+44h], 0
jnz short loc_12310
push (1 shl 16) or 16
mov eax, es:[bx+14h]
sar eax, 8
push ax
mov eax, es:[bx+10h]
sar eax, 8
push ax
call _egc_copy_rect_1_to_0_16
add sp, 8

loc_12310:
les bx, [bp+arg_0]
mov eax, es:[bx+32h]
add es:[bx+10h], eax
mov eax, es:[bx+2Ah]
add es:[bx+14h], eax
inc [bp+var_2]

loc_1232A:
mov ax, [bp+var_2]
cmp ax, [bp+var_A]
jb loc_1220B

loc_12334:
les bx, [bp+arg_0]
cmp byte ptr es:[bx+44h], 0
jz short loc_12343
call _grcg_off_func

loc_12343:
pop di
pop si
leave
retf
sub_121AC endp


; =============== S U B R O U T I N E =======================================

; Attributes: bp-based frame
Expand All @@ -4767,10 +4602,7 @@ arg_0 = dword ptr 6
mov eax, es:[bx+0Ch]
mov es:[bx+14h], eax
mov byte ptr es:[bx+44h], 0
push word ptr [bp+arg_0+2]
push bx
call sub_121AC
add sp, 4
call @CShootoutLaser@hittest_and_render$qv c, bx, word ptr [bp+arg_0+2]
les bx, [bp+arg_0]
mov eax, es:[bx+10h]
mov es:[bx+8], eax
Expand Down Expand Up @@ -4805,10 +4637,7 @@ loc_123DD:
mov eax, es:[bx+0Ch]
mov es:[bx+14h], eax
mov byte ptr es:[bx+44h], 1
push word ptr [bp+arg_0+2]
push bx
call sub_121AC
add sp, 4
call @CShootoutLaser@hittest_and_render$qv c, bx, word ptr [bp+arg_0+2]

loc_12408:
pop bp
Expand Down

0 comments on commit 243dbf8

Please sign in to comment.