[Decompilation] [th03] .MRS: Persistent horizontal flipping

Another function consisting almost entirely of inline ASM. Still worth
it though, if only to save us from duplicating any declarations in ASM
land.

Part of P0126, funded by [Anonymous] and Blue Bolt.
This commit is contained in:
nmlgc 2020-11-07 20:12:04 +01:00
parent 08a09aabb2
commit 5965930bd0
5 changed files with 59 additions and 59 deletions

View File

@ -104,7 +104,7 @@ bin\th03\op.exe: th03\op_01.cpp bin\th03\op.obj bin\th03\inp_m_w.obj bin\th03\cd
$**
|
bin\th03\main.exe: bin\th03\main.obj th03\main_01.cpp th03\sprite16.cpp
bin\th03\main.exe: bin\th03\main.obj th03\main_01.cpp th03\mrs.cpp th03\sprite16.cpp
$(CC) $(CFLAGS) -ml -Z -DGAME=3 -nbin\th03\ -eMAIN.EXE @&&|
$**
|

View File

@ -1,6 +1,9 @@
#pragma codeseg SHARED
#include "platform.h"
#include "pc98.h"
#include "planar.h"
#include "th03/formats/hfliplut.h"
#include "th03/formats/mrs.hpp"
static const vram_byte_amount_t MRS_BYTE_W = (MRS_W / BYTE_DOTS);
@ -17,3 +20,51 @@ struct mrs_t {
};
extern mrs_t far *mrs_images[MRS_SLOT_COUNT];
// Points [reg_sgm]:[reg_off] to the alpha plane of the .MRS image in the
// given [slot].
#define mrs_slot_assign(reg_sgm, reg_off, slot) { \
_BX = slot; \
_BX <<= 2; \
__asm { l##reg_sgm reg_off, mrs_images[bx]; } \
}
void pascal mrs_hflip(int slot)
{
_CX = sizeof(mrs_t);
mrs_slot_assign(es, di, slot);
reinterpret_cast<dots8_t near *>(_BX) = hflip_lut;
flip_dots_within_bytes: __asm {
mov al, es:[di];
xlat;
mov es:[di], al;
inc di;
loop flip_dots_within_bytes;
}
_CX = (sizeof(mrs_t) / MRS_BYTE_W);
/* vram_byte_amount_t offset_y */ _BX = 0;
flip_bytes: {
// Assumes that the offset part of all image pointers is 0. Storing
// segment pointers in [mrs_images] would have been clearer in this
// case...
/* vram_byte_amount_t offset_left */ _DI = 0;
/* vram_byte_amount_t offset_right */ _SI = (MRS_BYTE_W - 1);
do {
__asm {
mov al, es:[bx+di]
mov dl, es:[bx+si]
mov es:[bx+si], al
mov es:[bx+di], dl
}
_SI--;
_DI++;
} while(_DI <= ((MRS_BYTE_W / 2) - 1));
_BX += MRS_BYTE_W;
__asm { loop flip_bytes; }
}
}
#pragma codestring "\x90"

View File

@ -6,4 +6,7 @@
static const int MRS_SLOT_COUNT = 8;
static const pixel_t MRS_W = 288;
static const pixel_t MRS_H = 184;
// Persistently flips the image in [slot] horizontally, using the [hflip_lut].
void pascal mrs_hflip(int slot);
/// ---------------------------------------------------------------------------

1
th03/mrs.cpp Normal file
View File

@ -0,0 +1 @@
#include "th03/formats/mrs.cpp"

View File

@ -1583,10 +1583,8 @@ sub_A4A1 proc near
push bp
mov bp, sp
push 1
call sub_F0A6
push 3
call sub_F0A6
call @mrs_hflip$qi pascal, 1
call @mrs_hflip$qi pascal, 3
call respal_get_palettes
call far ptr palette_show
nopcall sub_A378
@ -9152,60 +9150,7 @@ sub_EFF4 endp
; ---------------------------------------------------------------------------
nop
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_F0A6 proc far
arg_0 = word ptr 6
push bp
mov bp, sp
loc_F0A9:
push si
push di
mov cx, 8160h
mov bx, [bp+arg_0]
shl bx, 2
les di, _mrs_images[bx]
mov bx, offset _hflip_lut
loc_F0BB:
mov al, es:[di]
xlat
mov es:[di], al
inc di
loop loc_F0BB
mov cx, 398h
xor bx, bx
loc_F0CA:
xor di, di
mov si, 23h ; '#'
loc_F0CF:
mov al, es:[bx+di]
mov dl, es:[bx+si]
mov es:[bx+si], al
mov es:[bx+di], dl
dec si
inc di
cmp di, 11h
jbe short loc_F0CF
add bx, 24h ; '$'
loop loc_F0CA
pop di
pop si
pop bp
retf 2
sub_F0A6 endp
; ---------------------------------------------------------------------------
nop
extern @MRS_HFLIP$QI:proc
SPRITE16_SPRITES_COMMIT procdesc pascal far
SPRITE16_PUT procdesc pascal far \
left:word, screen_top:word, sprite_offset:word