diff --git a/Makefile.mak b/Makefile.mak index 577433ca..9326a7d8 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -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 @&&| $** | diff --git a/th03/formats/mrs.cpp b/th03/formats/mrs.cpp index 6312f5e5..4b472ee7 100644 --- a/th03/formats/mrs.cpp +++ b/th03/formats/mrs.cpp @@ -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(_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" diff --git a/th03/formats/mrs.hpp b/th03/formats/mrs.hpp index ef8ef6f5..ad9e19d4 100644 --- a/th03/formats/mrs.hpp +++ b/th03/formats/mrs.hpp @@ -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); /// --------------------------------------------------------------------------- diff --git a/th03/mrs.cpp b/th03/mrs.cpp new file mode 100644 index 00000000..54641495 --- /dev/null +++ b/th03/mrs.cpp @@ -0,0 +1 @@ +#include "th03/formats/mrs.cpp" diff --git a/th03_main.asm b/th03_main.asm index 5d596d33..c2670e35 100644 --- a/th03_main.asm +++ b/th03_main.asm @@ -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