aboutsummaryrefslogtreecommitdiff
path: root/engines/cge/ems.cpp
blob: abf118bda2b32f0a1b921d024cc8817c9621505c (plain)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

/*
 * This code is based on original Soltys source code
 * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
 */
 
#include "cge/general.h"

namespace CGE {

#define		EMS_INT		0x67
#define		PAGE_MASK	0x3FFF
#define		SIZ(n)		((n) ? ((long)n) : (0x10000L))


enum EMM_FUN { GET_STATUS = 0x40,
	       GET_FRAME,
	       GET_SIZE,
	       OPEN_HANDLE,
	       MAP_PAGE,
	       CLOSE_HANDLE,
	       GET_VER,
	       SAVE_CONTEXT,
	       REST_CONTEXT,
	       GET_PAGES = 0x4B,
	       GET_HANDLES,
	       GET_INFO,
	       CONTROL };


void *EMM::Frame = NULL;


EMM::EMM (long size): Han(-1), Top(0), Lim(0), List(NULL) {
/*
	if (Test())
    {
      asm	mov	ah,GET_FRAME	// get EMS frame segment
      asm	int	EMS_INT		// do it!
      asm	or	ah,ah		// see status
      asm	jnz	xit		// abort on error
      Frame = (void _seg *) _BX;	// save frame segment

      if (size == 0)
	{
	  asm	mov	ah,GET_SIZE	// get EMS memory size
	  asm	int	EMS_INT		// do it!
	  asm	or	ah,ah		// see status
	  asm	jnz	xit		// abort on error
	  asm	or	bx,bx		// test page count
	  asm	jz	xit		// abort if no free pages
	  // number of available pages in BX is ready to use by OPEN
	}
      else _BX = (uint16) ((size + PAGE_MASK) >> 14);
      asm	mov	ah,OPEN_HANDLE	// open EMM handle
      asm	int	EMS_INT		// do it!
      asm	or	ah,ah		// see status
      asm	jnz	xit		// abort on error
      Han = _DX;
      Lim = _BX;
      Lim <<= 14;
      _DX = Han;
      asm	mov	ah,SAVE_CONTEXT	// save mapping context
      asm	int	EMS_INT		// do it!
    }
  xit:
*/
	warning("STUB: EMM:EMM");
}


EMM::~EMM(void) {
/*
  Release();
  if (Han >= 0)
    {
      _DX = Han;
      asm	mov	ah,REST_CONTEXT
      asm	int	EMS_INT
      asm	mov	ah,CLOSE_HANDLE
      asm	int	EMS_INT
    }
*/
	warning("STUB: EMM::~EMM");
}



bool EMM::Test(void) {
/*
  static char e[] = "EMMXXXX0";

  asm	mov	ax,0x3D40
  asm	mov	dx,offset e
  asm	int	0x21
  asm	jc	fail

  asm	push	ax
  asm	mov	bx,ax
  asm	mov	ax,0x4407
  asm	int	0x21

  asm	pop	bx
  asm	push	ax
  asm	mov	ax,0x3E00
  asm	int	0x21
  asm	pop	ax

  asm	cmp	al,0x00
  asm	je	fail

  success:
  return TRUE;
  fail:
  return FALSE;
*/
	warning("EMM::Test");
	return FALSE;
}


EMS * EMM::Alloc (uint16 siz) {
/*
  long size = SIZ(siz),
       top = Top;

  uint16 pgn = (uint16) (top >> 14),
       cnt = (uint16) ((top + size + PAGE_MASK) >> 14) - pgn;

  if (cnt > 4)
    {
      top = (top + PAGE_MASK) & 0xFFFFC000L;
      ++ pgn;
      -- cnt;
    }

  if (size <= Lim - top)
    {
      EMS * e = new EMS, * f;

      if (e)
	{
	  Top = (e->Ptr = top) + (e->Siz = siz);
	  e->Emm = this;

	  if (List)
	    {
	      for (f = List; f->Nxt; f = f->Nxt);
	      return (f->Nxt = e);		// existing list: link to the end
	    }
	  else
	    {
	      return (List = e);		// empty list: link to the head
	    }
	}
    }
  fail: return NULL;
*/
	warning("STUB: EMM::Alloc");
	return NULL;
}


void EMM::Release (void) {
  while (List)
    {
      EMS * e = List;
      List = e->Nxt;
      delete e;
    }
  Top = 0;
}


EMS::EMS (void)
: Ptr(0), Siz(0), Nxt(NULL)
{
}


void * EMS::operator & () const
{
/*
  uint16 pgn = (uint16) (Ptr >> 14),
       off = (uint16) Ptr & PAGE_MASK,
       cnt = (uint16) ((Ptr + SIZ(Siz) + PAGE_MASK) >> 14) - pgn,
       cmd = MAP_PAGE << 8;

  _DX = Emm->Han;		// take EMM handle
  asm	dec	cnt		// prapare for deferred checking
  asm	or	dx,dx		// see if valid
  asm	jns	more		// negative handle = unavailable

  fail: return NULL;

  more:
  asm	mov	ax,cmd		// command + page frame index
  asm	mov	bx,pgn		// logical page number
  asm	int	EMS_INT		// do it!
  asm	or	ah,ah		// check error code
  asm	jnz	fail		// exit on error
  asm	inc	cmd		// advance page frame index
  asm	inc	pgn		// advance logical page number
  asm	cmp	al,byte ptr cnt	// all pages?
  asm	jb	more

  return (void *) (EMM::Frame + (void *) off);
*/
	warning("STUB: EMS::operator &");
	return NULL;
}


uint16 EMS::Size (void)
{
  return Siz;
}

} // End of namespace CGE