This repository has been archived by the owner on Feb 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 256
/
Copy pathDPMI.H
175 lines (146 loc) · 6.16 KB
/
DPMI.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
** Command & Conquer(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* $Header: F:\projects\c&c\vcs\code\dpmi.h_v 2.17 16 Oct 1995 16:44:52 JOE_BOSTIC $ */
/***********************************************************************************************
*** 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 ***
***********************************************************************************************
* *
* Project Name : Command & Conquer *
* *
* File Name : DPMI.H *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : July 2, 1994 *
* *
* Last Update : July 2, 1994 [JLB] *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#ifndef DPMI_H
#define DPMI_H
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#include <mem.h>
extern void output(short port, short data);
class DOSSegmentClass {
/*
** This is the selector/segment value. In real mode it is the segment, in protected
** mode it is the selector (also 16 bits). This value is moved into DS or ES when
** accessing memory.
** Note: in Watcom flat addressing, Selector == Segment<<4 (ex: 0A0000h)
*/
unsigned int Selector;
/*
** These are C equivalents for pushing and popping the DS segment register. By using
** these, it is possible to create very small code that uses a segment and
** offset without damaging the DS register. These are especially useful in protected
** mode, but they are legal in real mode as well.
*/
void Push_DS(void) {/*__emit__(0x1E);*/};
void Pop_DS(void) {/*__emit__(0x1F);*/};
public:
DOSSegmentClass(void);
~DOSSegmentClass(void);
DOSSegmentClass(unsigned short segment, long size=(1024L*64L));
unsigned int Get_Selector(void);
/*
** This routine is used to assign where the descriptor actually points to in
** low DOS memory. In real mode, this is a simple segment assignment and the size
** is always 64K regardless of what is specified. In protected mode, the segment
** is used to update the selector and the size can be any length.
** In Watcom flat mode, it sets Selector == segment<<4
*/
void Assign(unsigned short segment, long size=(1024L*64L));
/*
** These routines will move the data to/from regular memory and the segment/descriptor
** memory.
*/
void Copy_To(void *source, int dest, int size);
void Copy_From(void *dest, int source, int size);
void Copy_Word_To(short data, int dest);
void Copy_Byte_To(char data, int dest);
void Copy_DWord_To(long data, int dest);
short Copy_Word_From(int source);
char Copy_Byte_From(int source);
long Copy_DWord_From(int source);
/*
** These routines move data around between sections of segmented (descriptor) memory.
** Typically, this is used when accessing DOS memory in protected mode or when dealing
** with hard memory areas such as the screen.
*/
static void Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size);
static void Swap(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size);
};
inline DOSSegmentClass::DOSSegmentClass(void)
{
Selector = 0xB0000;
}
inline DOSSegmentClass::~DOSSegmentClass(void)
{
}
inline void DOSSegmentClass::Copy_Word_To(short data, int dest)
{
*(short *)(Selector+dest) = data;
}
inline void DOSSegmentClass::Copy_Byte_To(char data, int dest)
{
*(char *)(Selector+dest) = data;
}
inline void DOSSegmentClass::Copy_DWord_To(long data, int dest)
{
*(long *)(Selector+dest) = data;
}
inline DOSSegmentClass::DOSSegmentClass(unsigned short segment, long)
{
Assign(segment);
}
inline void DOSSegmentClass::Assign(unsigned short segment, long)
{
Selector = (long)(segment)<<4L;
}
inline void DOSSegmentClass::Copy_To(void *source, int dest, int size)
{
memmove((void*)(Selector+dest), source, size);
}
inline void DOSSegmentClass::Copy_From(void *dest, int source, int size)
{
memmove(dest, (void*)(Selector+source), size);
}
inline void DOSSegmentClass::Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size) {
memmove((void*)(dest.Selector+doffset), (void*)(src.Selector+soffset), size);
}
inline short DOSSegmentClass::Copy_Word_From(int source)
{
return *(short*)(Selector+source);
}
inline char DOSSegmentClass::Copy_Byte_From(int source)
{
return *(char*)(Selector+source);
}
inline long DOSSegmentClass::Copy_DWord_From(int source)
{
return *(long*)(Selector+source);
}
inline unsigned int DOSSegmentClass::Get_Selector(void)
{
return Selector;
}
#endif