CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

DPMI.CPP (5208B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /* $Header:   F:\projects\c&c0\vcs\code\dpmi.cpv   4.41   04 Jul 1996 16:12:42   JOE_BOSTIC  $ */
     17 /***********************************************************************************************
     18  ***              C O N F I D E N T I A L  ---  W E S T W O O D  S T U D I O S               ***
     19  ***********************************************************************************************
     20  *                                                                                             *
     21  *                 Project Name : Command & Conquer                                            *
     22  *                                                                                             *
     23  *                    File Name : DPMI.CPP                                                     *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : July 2, 1994                                                 *
     28  *                                                                                             *
     29  *                  Last Update : July 2, 1994   [JLB]                                         *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     34 #if (0)
     35 #ifdef __FLAT__
     36 #pragma inline
     37 #endif
     38 
     39 //#include	"function.h"
     40 #include "dpmi.h"
     41 
     42 #ifndef __FLAT__
     43 
     44 void DOSSegmentClass::Swap(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size)
     45 {
     46 	if (!size) return;
     47 
     48 	unsigned short ssel = src.Selector;
     49 	unsigned short dsel = dest.Selector;
     50 
     51 	asm {
     52 		push	es
     53 		push	ds
     54 
     55 		mov	si,soffset
     56 		mov	di,doffset
     57 		mov	cx,size
     58 		mov	ax,ssel
     59 		mov	dx,dsel
     60 		mov	ds,ax
     61 		mov	es,dx
     62 	}
     63 again:
     64 	asm {
     65 		mov	al,ds:[si]
     66 		mov	ah,es:[di]
     67 		mov	ds:[si],ah
     68 		mov	es:[di],al
     69 		inc	di
     70 		inc	si
     71 		dec	cx
     72 		jnz	again
     73 
     74 		pop	ds
     75 		pop	es
     76 	}
     77 }
     78 #endif
     79 
     80 
     81 void DOSSegmentClass::Swap(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size)
     82 {
     83 	extern void dss_swap(char *src, char *dest, int size);
     84 
     85 	#pragma aux dss_swap = 		\
     86 	"again: mov	al,[esi]"	\
     87 		"mov	ah,[edi]"		\
     88 		"mov	[esi],ah"		\
     89 		"stosb"					\
     90 		"inc	esi"				\
     91 		"loop	again"			\
     92 		parm	[esi] [edi] [ecx]	\
     93 		modify [ax];
     94 
     95 	if (!size) return;
     96 	dss_swap((char *)(src.Selector + soffset), (char *)(dest.Selector + doffset), size);
     97 }
     98 
     99 #ifdef OBSOLETE
    100 void DOSSegmentClass::Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size)
    101 {
    102 	extern void dss_copy(char *src, char *dest, int size);
    103 	#pragma aux dss_copy = 		\
    104 		"mov		ebx,ecx"			\
    105 		"shr		ecx,2"			\
    106 		"jecxz	copskip1"		\
    107 		"rep 		movsd"			\
    108 "copskip1: mov ecx,ebx"			\
    109 		"and		ecx,3"			\
    110 		"jecxz	copskip2"		\
    111 		"rep		movsb"			\
    112 "copskip2:"							\
    113 		parm	[esi edi ecx]		\
    114 		modify [ebx];
    115 
    116 	if (!size) return;
    117 	dss_copy((char *)(src.Selector + soffset), (char *)(dest.Selector + doffset), size);
    118 }
    119 #endif
    120 
    121 #ifdef OBSOLETE
    122 void DOSSegmentClass::Copy_To(void *source, int dest, int size)
    123 {
    124 	extern void dss_copy_to(void *src, (void *)dest, int size);
    125 
    126 	#pragma aux dss_copy_to =	\
    127 		"mov		ebx,ecx"			\
    128 		"shr		ecx,2"			\
    129 		"jecxz	cop2skip1"		\
    130 		"rep		movsd"			\
    131 "cop2skip1: mov ecx,ebx"		\
    132 		"and		ecx,3"			\
    133 		"jecxz	cop2skip2"		\
    134 		"rep		movsb"			\
    135 "cop2skip2:"						\
    136 		parm	[esi edi ecx]		\
    137 		modify [ebx];
    138 
    139 	if (!size) return;
    140 	dss_copy_to(src, (void *)(Selector + dest), size);
    141 
    142 }
    143 #endif
    144 
    145 #ifdef OBSOLETE
    146 void DOSSegmentClass::Copy_From(void *dest, int source, int size)
    147 {
    148 	extern void dss_copy_from(void *dest, (void *)source, int size);
    149 
    150 	#pragma aux dss_copy_from =	\
    151 		"mov		ebx,ecx"			\
    152 		"shr		ecx,2"			\
    153 		"jecxz	copfskip1"		\
    154 		"rep		movsd"			\
    155 "copfskip1: mov ecx,ebx"		\
    156 		"and		ecx,3"			\
    157 		"jecxz	copfskip2"		\
    158 		"rep		movsb"			\
    159 "copfskip2:"						\
    160 		parm	[edi esi ecx]		\
    161 		modify [ebx];
    162 
    163 	if (!size) return;
    164 	dss_copy_from(dest, (void *)(Selector + source), size);
    165 }
    166 #endif
    167 #endif