CnC_Remastered_Collection

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

DPMI.H (6433B)


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