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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
/* 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
*/
#ifndef __VGA13H__
#define __VGA13H__
#include "cge/general.h"
#include <stddef.h>
#include <dir.h>
#include "cge/bitmap.h"
#include "cge/snail.h"
#define TMR_RATE1 16
#define TMR_RATE2 4
#define TMR_RATE (TMR_RATE1*TMR_RATE2)
#define MAX_NAME 20
#define VIDEO 0x10
#define NO_CLEAR 0x80
#define TEXT_MODE 0x03
#define M13H 0x13
#ifndef SCR_WID
#define SCR_WID 320
#endif
#ifndef SCR_HIG
#define SCR_HIG 200
#endif
#if 0
#define LIGHT 0xFF
#define DARK 0x00
#define DGRAY 0xF6
#define GRAY 0xFC
#define LGRAY 0xFF
#else
#define LIGHT 0xFF
#define DARK 207
#define DGRAY 225 /*219*/
#define GRAY 231
#define LGRAY 237
#endif
#define NO_SEQ (-1)
#define NO_PTR ((byte)-1)
#define SPR_EXT ".SPR"
#define IsFile(s) (access(s,0)==0)
#define IsWrit(s) (access(s,2)==0)
typedef struct { word r : 2; word R : 6;
word g : 2; word G : 6;
word b : 2; word B : 6;
} RGB;
typedef union {
DAC dac;
RGB rgb;
} TRGB;
typedef struct { byte idx, adr; byte clr, set; } VgaRegBlk;
typedef struct { byte Now, Next; signed char Dx, Dy; int Dly; } SEQ;
extern SEQ Seq1[];
extern SEQ Seq2[];
//extern SEQ * Compass[];
//extern SEQ TurnToS[];
#define PAL_CNT 256
#define PAL_SIZ (PAL_CNT*sizeof(DAC))
#define VGAATR_ 0x3C0
#define VGAMIw_ 0x3C0
#define VGASEQ_ 0x3C4
#define VGAMIr_ 0x3CC
#define VGAGRA_ 0x3CE
#define VGACRT_ 0x3D4
#define VGAST1_ 0x3DA
#define VGAATR (VGAATR_ & 0xFF)
#define VGAMIw (VGAMIw_ & 0xFF)
#define VGASEQ (VGASEQ_ & 0xFF)
#define VGAMIr (VGAMIr_ & 0xFF)
#define VGAGRA (VGAGRA_ & 0xFF)
#define VGACRT (VGACRT_ & 0xFF)
#define VGAST1 (VGAST1_ & 0xFF)
class HEART : public ENGINE
{
friend ENGINE;
public:
static bool Enable;
static word * XTimer;
static void SetXTimer (word * ptr);
static void SetXTimer (word * ptr, word time);
HEART (void);
};
class SPREXT
{
public:
int x0, y0;
int x1, y1;
BMP_PTR b0, b1;
BMP_PTR * ShpList;
SEQ * Seq;
char * Name;
SNAIL::COM * Near, * Take;
SPREXT (void) :
x0(0), y0(0),
x1(0), y1(0),
b0(NULL), b1(NULL),
ShpList(NULL), Seq(NULL),
Name(NULL), Near(NULL), Take(NULL)
{}
};
class SPRITE
{
protected:
SPREXT * Ext;
public:
int Ref;
signed char Cave;
struct FLAGS { word Hide : 1; // general visibility switch
word Near : 1; // Near action lock
word Drag : 1; // sprite is moveable
word Hold : 1; // sprite is held with mouse
word ____ : 1; // intrrupt driven animation
word Slav : 1; // slave object
word Syst : 1; // system object
word Kill : 1; // dispose memory after remove
word Xlat : 1; // 2nd way display: xlat table
word Port : 1; // portable
word Kept : 1; // kept in pocket
word East : 1; // talk to east (in opposite to west)
word Shad : 1; // shadow
word Back : 1; // 'send to background' request
word BDel : 1; // delete bitmaps in ~SPRITE
word Tran : 1; // transparent (untouchable)
} Flags;
int X, Y;
signed char Z;
word W, H;
word Time;
byte NearPtr, TakePtr;
int SeqPtr;
int ShpCnt;
char File[MAXFILE];
SPRITE * Prev, * Next;
bool Works (SPRITE * spr);
bool SeqTest (int n);
inline bool Active (void) { return Ext != NULL; }
SPRITE (BMP_PTR * shp);
virtual ~SPRITE (void);
BMP_PTR Shp (void);
BMP_PTR * SetShapeList (BMP_PTR * shp);
void MoveShapes (byte * buf);
SPRITE * Expand (void);
SPRITE * Contract (void);
SPRITE * BackShow (bool fast = false);
void SetName(char * n);
inline char * Name(void) { return (Ext) ? Ext->Name : NULL; }
void Goto (int x, int y);
void Center (void);
void Show (void);
void Hide (void);
BMP_PTR Ghost (void);
void Show (word pg);
void MakeXlat (byte * x);
void KillXlat (void);
void Step (int nr = -1);
SEQ * SetSeq (SEQ * seq);
SNAIL::COM * SnList(SNLIST type);
virtual void Touch (word mask, int x, int y);
virtual void Tick (void);
};
class QUEUE
{
SPRITE * Head, * Tail;
public:
bool Show;
QUEUE (bool show = false);
~QUEUE (void);
void Append (SPRITE * spr);
void Insert (SPRITE * spr, SPRITE * nxt);
void Insert (SPRITE * spr);
SPRITE * Remove (SPRITE * spr);
void ForAll (void (*fun)(SPRITE *));
SPRITE * First (void) { return Head; }
SPRITE * Last (void) { return Tail; }
SPRITE * Locate (int ref);
void Clear (void);
};
class VGA
{
static word OldMode;
static word * OldScreen;
static word StatAdr;
static bool SetPal;
static DAC * OldColors, * NewColors;
static int SetMode (int mode);
static void UpdateColors (void);
static void SetColors (void);
static const char * Msg;
static const char * Nam;
static void SetStatAdr (void);
static void WaitVR (bool on = true);
public:
dword FrmCnt;
static QUEUE ShowQ, SpareQ;
static int Mono;
static byte * Page[4];
VGA (int mode = M13H);
~VGA (void);
void Setup (VgaRegBlk * vrb);
static void GetColors (DAC * tab);
static void SetColors (DAC * tab, int lum);
static void Clear (byte color = 0);
static void Exit (const char * txt = NULL, const char * name = NULL);
static void Exit (int tref, const char * name = NULL);
static void CopyPage (word d, word s = 3);
static void Sunrise (DAC * tab);
static void Sunset (void);
void Show (void);
void Update (void);
};
DAC MkDAC (byte r, byte g, byte b);
RGB MkRGB (byte r, byte g, byte b);
template <class CBLK>
byte Closest (CBLK * pal, CBLK x)
{
#define f(col,lum) ((((word)(col))<<8)/lum)
word i, dif = 0xFFFF, found;
word L = x.R + x.G + x.B; if (! L) ++ L;
word R = f(x.R, L), G = f(x.G, L), B = f(x.B, L);
for (i = 0; i < 256; i ++)
{
word l = pal[i].R + pal[i].G + pal[i].B; if (! l) ++ l;
int r = f(pal[i].R, l), g = f(pal[i].G, l), b = f(pal[i].B, l);
word D = ((r > R) ? (r - R) : (R - r)) +
((g > G) ? (g - G) : (G - g)) +
((b > B) ? (b - B) : (B - b)) +
((l > L) ? (l - L) : (L - l)) * 10 ;
if (D < dif)
{
found = i;
dif = D;
if (D == 0) break; // exact!
}
}
return found;
#undef f
};
char * NumStr (char * str, int num);
void Video (void);
word * SaveScreen (void);
void RestoreScreen (word * &sav);
SPRITE * SpriteAt (int x, int y);
SPRITE * Locate (int ref);
extern bool SpeedTest;
#endif
|