From 0f184f2b7199acdad5a63a9fb93f3a22e21fe313 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sun, 7 Oct 2018 00:32:36 -0500 Subject: [PATCH] Move assembly to _asm.cpp (#388) --- Makefile | 2 +- MakefileVC | 4 +- Source/_asm.cpp | 135 ++++++++++++++++++++++++++++++++++++++++ Source/render.cpp | 153 +++------------------------------------------- 4 files changed, 147 insertions(+), 147 deletions(-) create mode 100644 Source/_asm.cpp diff --git a/Makefile b/Makefile index d2867df56..b3c39f61e 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ debug: CXXFLAGS += -D_DEBUG debug: CPPFLAGS += -D_DEBUG debug: devilution.exe -DIABLO_SRC=$(wildcard Source/*.cpp) +DIABLO_SRC=$(sort $(filter-out Source/_asm.cpp, $(wildcard Source/*.cpp))) OBJS=$(DIABLO_SRC:.cpp=.o) PKWARE_SRC=$(wildcard 3rdParty/PKWare/*.cpp) diff --git a/MakefileVC b/MakefileVC index d11f97a46..081ba66a9 100644 --- a/MakefileVC +++ b/MakefileVC @@ -52,8 +52,8 @@ all: Diablo.exe debug: CFLAGS += /D "_DEBUG" debug: Diablo.exe -# fix compilation order to match the VC6 workspace files -DIABLO_SRC=$(sort $(filter-out Source/render.cpp, $(wildcard Source/*.cpp))) +# fix compilation order to match the VC6 workspace files and exclude local assembly functions +DIABLO_SRC=$(sort $(filter-out Source/_asm.cpp Source/render.cpp, $(wildcard Source/*.cpp))) DIABLO_SRC += Source/render.cpp OBJS=$(DIABLO_SRC:.cpp=.obj) diff --git a/Source/_asm.cpp b/Source/_asm.cpp new file mode 100644 index 000000000..bb6578cce --- /dev/null +++ b/Source/_asm.cpp @@ -0,0 +1,135 @@ +static inline void asm_cel_light_edge(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); +static inline void asm_cel_light_square(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); +static inline void asm_trans_light_cel_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); +static inline void asm_trans_light_edge_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); +static inline void asm_trans_light_square_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); +static inline void asm_trans_light_cel_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); +static inline void asm_trans_light_edge_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); +static inline void asm_trans_light_square_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); +static inline void asm_trans_light_mask(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src, unsigned int mask); + +static inline void asm_cel_light_edge(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) +{ + unsigned char l = w >> 1; + + if ( w & 1 ) + { + dst[0] = tbl[src[0]]; + src++; + dst++; + } + if ( l & 1 ) + { + dst[0] = tbl[src[0]]; + dst[1] = tbl[src[1]]; + src += 2; + dst += 2; + } + + asm_cel_light_square(l >> 1, tbl, dst, src); +} + +static inline void asm_cel_light_square(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) +{ + for ( ; w; --w ) + { + dst[0] = tbl[src[0]]; + dst[1] = tbl[src[1]]; + dst[2] = tbl[src[2]]; + dst[3] = tbl[src[3]]; + src += 4; + dst += 4; + } +} + +static inline void asm_trans_light_cel_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) +{ + if ( !(w & 1) ) + { + asm_trans_light_edge_1_3(w >> 1, tbl, dst, src); + } + else + { + src++; + dst++; + asm_trans_light_edge_0_2(w >> 1, tbl, dst, src); + } +} + +static inline void asm_trans_light_edge_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) +{ + unsigned char l = w >> 1; + + if ( w & 1 ) + { + dst[0] = tbl[src[0]]; + src += 2; + dst += 2; + } + if ( l ) + { + asm_trans_light_square_0_2(l, tbl, dst, src); + } +} + +static inline void asm_trans_light_square_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) +{ + for ( ; w; --w ) + { + dst[0] = tbl[src[0]]; + dst[2] = tbl[src[2]]; + src += 4; + dst += 4; + } +} + +static inline void asm_trans_light_cel_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) +{ + if ( !(w & 1) ) + { + asm_trans_light_edge_0_2(w >> 1, tbl, dst, src); + } + else + { + dst[0] = tbl[src[0]]; + src++; + dst++; + asm_trans_light_edge_1_3(w >> 1, tbl, dst, src); + } +} + +static inline void asm_trans_light_edge_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) +{ + unsigned char l = w >> 1; + + if ( w & 1 ) + { + dst[1] = tbl[src[1]]; + src += 2; + dst += 2; + } + if ( l ) + { + asm_trans_light_square_1_3(l, tbl, dst, src); + } +} + +static inline void asm_trans_light_square_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) +{ + for ( ; w; --w ) + { + dst[1] = tbl[src[1]]; + dst[3] = tbl[src[3]]; + src += 4; + dst += 4; + } +} + +static inline void asm_trans_light_mask(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src, unsigned int mask) +{ + for ( ; w; --w, src++, dst++, mask *= 2 ) + { + if ( mask & 0x80000000 ) + dst[0] = tbl[src[0]]; + } +} diff --git a/Source/render.cpp b/Source/render.cpp index e02be99df..c73ee0687 100644 --- a/Source/render.cpp +++ b/Source/render.cpp @@ -1,6 +1,7 @@ //HEADER_GOES_HERE #include "../types.h" +#include "_asm.cpp" int WorldBoolFlag = 0; unsigned int gdwCurrentMask = 0; @@ -80,142 +81,6 @@ int WorldTbl17_2[17] = { 0, 32, 60, 88, 112, 136, 156, 176, 192, 208, 220, 232, |/ */ -inline void asm_cel_light_edge(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); -inline void asm_cel_light_square(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); -inline void asm_cel_light_mask(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src, unsigned int mask); -inline void asm_trans_light_cel_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); -inline void asm_trans_light_edge_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); -inline void asm_trans_light_square_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); -inline void asm_trans_light_cel_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); -inline void asm_trans_light_edge_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); -inline void asm_trans_light_square_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src); - -inline void asm_cel_light_edge(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) -{ - unsigned char l = w >> 1; - - if ( w & 1 ) - { - dst[0] = tbl[src[0]]; - src++; - dst++; - } - if ( l & 1 ) - { - dst[0] = tbl[src[0]]; - dst[1] = tbl[src[1]]; - src += 2; - dst += 2; - } - - asm_cel_light_square(l >> 1, tbl, dst, src); -} - -inline void asm_cel_light_square(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) -{ - for ( ; w; --w ) - { - dst[0] = tbl[src[0]]; - dst[1] = tbl[src[1]]; - dst[2] = tbl[src[2]]; - dst[3] = tbl[src[3]]; - src += 4; - dst += 4; - } -} - -inline void asm_cel_light_mask(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src, unsigned int mask) -{ - for ( ; w; --w, src++, dst++, mask *= 2 ) - { - if ( mask & 0x80000000 ) - dst[0] = tbl[src[0]]; - } -} - -inline void asm_trans_light_cel_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) -{ - if ( !(w & 1) ) - { - asm_trans_light_edge_1_3(w >> 1, tbl, dst, src); - } - else - { - src++; - dst++; - asm_trans_light_edge_0_2(w >> 1, tbl, dst, src); - } -} - -inline void asm_trans_light_edge_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) -{ - unsigned char l = w >> 1; - - if ( w & 1 ) - { - dst[0] = tbl[src[0]]; - src += 2; - dst += 2; - } - if ( l ) - { - asm_trans_light_square_0_2(l, tbl, dst, src); - } -} - -inline void asm_trans_light_square_0_2(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) -{ - for ( ; w; --w ) - { - dst[0] = tbl[src[0]]; - dst[2] = tbl[src[2]]; - src += 4; - dst += 4; - } -} - -inline void asm_trans_light_cel_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) -{ - if ( !(w & 1) ) - { - asm_trans_light_edge_0_2(w >> 1, tbl, dst, src); - } - else - { - dst[0] = tbl[src[0]]; - src++; - dst++; - asm_trans_light_edge_1_3(w >> 1, tbl, dst, src); - } -} - -inline void asm_trans_light_edge_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) -{ - unsigned char l = w >> 1; - - if ( w & 1 ) - { - dst[1] = tbl[src[1]]; - src += 2; - dst += 2; - } - if ( l ) - { - asm_trans_light_square_1_3(l, tbl, dst, src); - } -} - -inline void asm_trans_light_square_1_3(unsigned char w, BYTE *tbl, BYTE *&dst, BYTE *&src) -{ - for ( ; w; --w ) - { - dst[1] = tbl[src[1]]; - dst[3] = tbl[src[3]]; - src += 4; - dst += 4; - } -} - void __fastcall drawTopArchesUpperScreen(unsigned char *pbDst) { unsigned char *dst; // edi MAPDST @@ -1820,7 +1685,7 @@ LABEL_129: { if ( dst < gpBufEnd ) break; - asm_cel_light_mask(32, tbl, dst, src, *gpDrawMask); + asm_trans_light_mask(32, tbl, dst, src, *gpDrawMask); dst -= 800; --gpDrawMask; --xx_32; @@ -1851,7 +1716,7 @@ LABEL_129: yy_32 -= width; if ( dst < gpBufEnd ) return; - asm_cel_light_mask(width, tbl, dst, src, gdwCurrentMask); + asm_trans_light_mask(width, tbl, dst, src, gdwCurrentMask); } while ( yy_32 ); LABEL_50: @@ -1931,7 +1796,7 @@ LABEL_50: if ( dst < gpBufEnd ) break; src += (unsigned char)src & 2; - asm_cel_light_mask(32, tbl, dst, src, *gpDrawMask); + asm_trans_light_mask(32, tbl, dst, src, *gpDrawMask); dst -= 800; --gpDrawMask; --yy_32; @@ -1957,7 +1822,7 @@ LABEL_50: { if ( dst < gpBufEnd ) break; - asm_cel_light_mask(32, tbl, dst, src, *gpDrawMask); + asm_trans_light_mask(32, tbl, dst, src, *gpDrawMask); src += (unsigned char)src & 2; dst -= 800; --gpDrawMask; @@ -5005,7 +4870,7 @@ LABEL_252: { if ( dst < gpBufEnd ) { - asm_cel_light_mask(32, tbl, dst, src, *gpDrawMask); + asm_trans_light_mask(32, tbl, dst, src, *gpDrawMask); } else { @@ -5034,7 +4899,7 @@ LABEL_252: yy_32 -= width; if ( dst < gpBufEnd ) { - asm_cel_light_mask(width, tbl, dst, src, gdwCurrentMask); + asm_trans_light_mask(width, tbl, dst, src, gdwCurrentMask); } else { @@ -5167,7 +5032,7 @@ LABEL_98: { if ( dst < gpBufEnd ) { - asm_cel_light_mask(32, tbl, dst, src, *gpDrawMask); + asm_trans_light_mask(32, tbl, dst, src, *gpDrawMask); } else { @@ -5212,7 +5077,7 @@ LABEL_117: { if ( dst < gpBufEnd ) { - asm_cel_light_mask(32, tbl, dst, src, *gpDrawMask); + asm_trans_light_mask(32, tbl, dst, src, *gpDrawMask); src += (unsigned char)src & 2; } else