CnC_Remastered_Collection

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

DPMI.H (6465B)


      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.h_v   4.43   05 Jul 1996 17:58:40   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.H                                                       *
     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 
     35 
     36 #ifndef DPMI_Hx
     37 #define DPMI_Hx
     38 #include	<dos.h>
     39 #include	<stdlib.h>
     40 #include	<stdio.h>
     41 //#include	<mem.h>
     42 
     43 
     44 extern void output(short port, short data);
     45 
     46 
     47 class DOSSegmentClass {
     48 		/*
     49 		**	This is the selector/segment value. In real mode it is the segment, in protected
     50 		**	mode it is the selector (also 16 bits). This value is moved into DS or ES when
     51 		**	accessing memory.
     52 		** Note: in Watcom flat addressing, Selector == Segment<<4 (ex: 0A0000h)
     53 		*/
     54 		unsigned int Selector;
     55 
     56 		/*
     57 		**	These are C equivalents for pushing and popping the DS segment register. By using
     58 		**	these, it is possible to create very small code that uses a segment and
     59 		**	offset without damaging the DS register. These are especially useful in protected
     60 		**	mode, but they are legal in real mode as well.
     61 		*/
     62 		void Push_DS(void) {/*__emit__(0x1E);*/};
     63 		void Pop_DS(void) {/*__emit__(0x1F);*/};
     64 
     65 	public:
     66 		DOSSegmentClass(void);
     67 		~DOSSegmentClass(void);
     68 		DOSSegmentClass(unsigned short segment, long size=(1024L*64L));
     69 
     70 		unsigned int Get_Selector(void);
     71 
     72 		/*
     73 		**	This routine is used to assign where the descriptor actually points to in
     74 		**	low DOS memory. In real mode, this is a simple segment assignment and the size
     75 		**	is always 64K regardless of what is specified. In protected mode, the segment
     76 		**	is used to update the selector and the size can be any length.
     77 		** In Watcom flat mode, it sets Selector == segment<<4
     78 		*/
     79 		void Assign(unsigned short segment, long size=(1024L*64L));
     80 
     81 		/*
     82 		**	These routines will move the data to/from regular memory and the segment/descriptor
     83 		**	memory.
     84 		*/
     85 		void Copy_To(void *source, int dest, int size);
     86 		void Copy_From(void *dest, int source, int size);
     87 		void Copy_Word_To(short data, int dest);
     88 		void Copy_Byte_To(char data, int dest);
     89 		void Copy_DWord_To(long data, int dest);
     90 		short Copy_Word_From(int source);
     91 		char Copy_Byte_From(int source);
     92 		long Copy_DWord_From(int source);
     93 
     94 		/*
     95 		**	These routines move data around between sections of segmented (descriptor) memory.
     96 		**	Typically, this is used when accessing DOS memory in protected mode or when dealing
     97 		**	with hard memory areas such as the screen.
     98 		*/
     99 		static void Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size);
    100 		static void Swap(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size);
    101 };
    102 
    103 
    104 inline DOSSegmentClass::DOSSegmentClass(void)
    105 {
    106 	Selector = 0xB0000;
    107 }
    108 
    109 inline DOSSegmentClass::~DOSSegmentClass(void)
    110 {
    111 }
    112 
    113 inline void DOSSegmentClass::Copy_Word_To(short data, int dest)
    114 {
    115 	*(short *)(Selector+dest) = data;
    116 }
    117 
    118 inline void DOSSegmentClass::Copy_Byte_To(char data, int dest)
    119 {
    120 	*(char *)(Selector+dest) = data;
    121 }
    122 
    123 inline void DOSSegmentClass::Copy_DWord_To(long data, int dest)
    124 {
    125 	*(long *)(Selector+dest) = data;
    126 }
    127 
    128 inline void DOSSegmentClass::Assign(unsigned short segment, long)
    129 {
    130 	Selector = (long)(segment)<<4L;
    131 }
    132 
    133 inline DOSSegmentClass::DOSSegmentClass(unsigned short segment, long)
    134 {
    135 	Assign(segment);
    136 }
    137 
    138 inline void DOSSegmentClass::Copy_To(void *source, int dest, int size)
    139 {
    140 	memmove((void*)(Selector+dest), source, (unsigned)size);
    141 }
    142 
    143 inline void DOSSegmentClass::Copy_From(void *dest, int source, int size)
    144 {
    145 	memmove(dest, (void*)(Selector+source), (unsigned)size);
    146 }
    147 
    148 inline void DOSSegmentClass::Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size) {
    149 	memmove((void*)(dest.Selector+doffset), (void*)(src.Selector+soffset), (unsigned)size);
    150 }
    151 
    152 inline short DOSSegmentClass::Copy_Word_From(int source)
    153 {
    154 	return *(short*)(Selector+source);
    155 }
    156 
    157 inline char DOSSegmentClass::Copy_Byte_From(int source)
    158 {
    159 	return *(char*)(Selector+source);
    160 }
    161 
    162 inline long DOSSegmentClass::Copy_DWord_From(int source)
    163 {
    164 	return *(long*)(Selector+source);
    165 }
    166 
    167 inline unsigned int DOSSegmentClass::Get_Selector(void)
    168 {
    169 	return Selector;
    170 }
    171 #endif
    172 
    173