2011-06-10 05:45:18 +00:00
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#ifndef __VGA13H__
|
|
|
|
#define __VGA13H__
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-27 08:57:58 +00:00
|
|
|
#include "graphics/surface.h"
|
2011-06-13 09:57:24 +00:00
|
|
|
#include "cge/general.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "cge/bitmap.h"
|
|
|
|
#include "cge/snail.h"
|
2011-06-26 23:03:47 +00:00
|
|
|
#include "cge/cge.h"
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
namespace CGE {
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#define TMR_RATE1 16
|
|
|
|
#define TMR_RATE2 4
|
|
|
|
#define TMR_RATE (TMR_RATE1 * TMR_RATE2)
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#define MAX_NAME 20
|
|
|
|
#define VIDEO 0x10
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#define NO_CLEAR 0x80
|
|
|
|
#define TEXT_MODE 0x03
|
|
|
|
#define M13H 0x13
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#ifndef SCR_WID
|
|
|
|
#define SCR_WID 320
|
2011-06-09 06:20:53 +00:00
|
|
|
#endif
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#ifndef SCR_HIG
|
|
|
|
#define SCR_HIG 200
|
2011-06-09 06:20:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
2011-06-13 09:57:24 +00:00
|
|
|
#define LIGHT 0xFF
|
|
|
|
#define DARK 0x00
|
|
|
|
#define DGRAY 0xF6
|
|
|
|
#define GRAY 0xFC
|
|
|
|
#define LGRAY 0xFF
|
2011-06-09 06:20:53 +00:00
|
|
|
#else
|
2011-06-13 09:57:24 +00:00
|
|
|
#define LIGHT 0xFF
|
|
|
|
#define DARK 207
|
|
|
|
#define DGRAY 225 /*219*/
|
|
|
|
#define GRAY 231
|
|
|
|
#define LGRAY 237
|
2011-06-09 06:20:53 +00:00
|
|
|
#endif
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#define NO_SEQ (-1)
|
|
|
|
#define NO_PTR ((uint8)-1)
|
|
|
|
|
|
|
|
#define SPR_EXT ".SPR"
|
|
|
|
|
|
|
|
#define IsFile(s) (access(s, 0) == 0)
|
|
|
|
#define IsWrit(s) (access(s, 2) == 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
struct Rgb {
|
2011-06-13 09:57:24 +00:00
|
|
|
uint16 r : 2;
|
|
|
|
uint16 R : 6;
|
|
|
|
uint16 g : 2;
|
|
|
|
uint16 G : 6;
|
|
|
|
uint16 b : 2;
|
|
|
|
uint16 B : 6;
|
2011-06-28 22:35:21 +00:00
|
|
|
};
|
2011-06-13 09:57:24 +00:00
|
|
|
|
|
|
|
typedef union {
|
2011-07-01 06:37:40 +00:00
|
|
|
Dac dac;
|
2011-06-28 22:35:21 +00:00
|
|
|
Rgb rgb;
|
2011-06-13 09:57:24 +00:00
|
|
|
} TRGB;
|
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
struct VgaRegBlk {
|
|
|
|
uint8 idx;
|
|
|
|
uint8 adr;
|
|
|
|
uint8 clr;
|
|
|
|
uint8 set;
|
|
|
|
};
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
struct Seq {
|
|
|
|
uint8 Now;
|
|
|
|
uint8 Next;
|
|
|
|
int8 Dx;
|
|
|
|
int8 Dy;
|
2011-06-13 09:57:24 +00:00
|
|
|
int Dly;
|
2011-06-28 22:35:21 +00:00
|
|
|
};
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
extern Seq _seq1[];
|
|
|
|
extern Seq _seq2[];
|
2011-06-13 09:57:24 +00:00
|
|
|
//extern SEQ * Compass[];
|
|
|
|
//extern SEQ TurnToS[];
|
|
|
|
|
|
|
|
#define PAL_CNT 256
|
2011-06-27 08:57:58 +00:00
|
|
|
#define PAL_SIZ (PAL_CNT * 3)
|
2011-06-13 09:57:24 +00:00
|
|
|
#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)
|
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
class Heart : public Engine_ {
|
|
|
|
friend class Engine_;
|
2011-06-09 06:20:53 +00:00
|
|
|
public:
|
2011-06-28 22:35:21 +00:00
|
|
|
Heart();
|
|
|
|
|
|
|
|
bool _enable;
|
|
|
|
uint16 *_xTimer;
|
2011-06-19 22:55:47 +00:00
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
void setXTimer(uint16 *ptr);
|
|
|
|
void setXTimer(uint16 *ptr, uint16 time);
|
2011-06-09 06:20:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
class SprExt {
|
2011-06-09 06:20:53 +00:00
|
|
|
public:
|
2011-06-28 22:35:21 +00:00
|
|
|
int _x0, _y0;
|
|
|
|
int _x1, _y1;
|
|
|
|
BMP_PTR _b0, _b1;
|
|
|
|
BMP_PTR *_shpList;
|
|
|
|
Seq *_seq;
|
|
|
|
char *_name;
|
|
|
|
SNAIL::COM *_near, *_take;
|
|
|
|
SprExt() :
|
|
|
|
_x0(0), _y0(0),
|
|
|
|
_x1(0), _y1(0),
|
|
|
|
_b0(NULL), _b1(NULL),
|
|
|
|
_shpList(NULL), _seq(NULL),
|
|
|
|
_name(NULL), _near(NULL), _take(NULL)
|
2011-06-13 09:57:24 +00:00
|
|
|
{}
|
2011-06-09 06:20:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
class Sprite {
|
2011-06-09 06:20:53 +00:00
|
|
|
protected:
|
2011-06-28 22:35:21 +00:00
|
|
|
SprExt *_ext;
|
2011-06-09 06:20:53 +00:00
|
|
|
public:
|
2011-06-28 22:35:21 +00:00
|
|
|
int _ref;
|
|
|
|
signed char _cave;
|
2011-06-13 09:57:24 +00:00
|
|
|
struct FLAGS {
|
2011-06-29 14:13:17 +00:00
|
|
|
uint16 _hide : 1; // general visibility switch
|
|
|
|
uint16 _near : 1; // Near action lock
|
|
|
|
uint16 _drag : 1; // sprite is moveable
|
|
|
|
uint16 _hold : 1; // sprite is held with mouse
|
|
|
|
uint16 _____ : 1; // intrrupt driven animation
|
|
|
|
uint16 _slav : 1; // slave object
|
|
|
|
uint16 _syst : 1; // system object
|
|
|
|
uint16 _kill : 1; // dispose memory after remove
|
|
|
|
uint16 _xlat : 1; // 2nd way display: xlat table
|
|
|
|
uint16 _port : 1; // portable
|
|
|
|
uint16 _kept : 1; // kept in pocket
|
|
|
|
uint16 _east : 1; // talk to east (in opposite to west)
|
|
|
|
uint16 _shad : 1; // shadow
|
|
|
|
uint16 _back : 1; // 'send to background' request
|
|
|
|
uint16 _bDel : 1; // delete bitmaps in ~SPRITE
|
|
|
|
uint16 _tran : 1; // transparent (untouchable)
|
|
|
|
} _flags;
|
|
|
|
int _x;
|
|
|
|
int _y;
|
|
|
|
signed char _z;
|
|
|
|
uint16 _w;
|
|
|
|
uint16 _h;
|
|
|
|
uint16 _time;
|
2011-07-01 23:02:14 +00:00
|
|
|
uint8 _nearPtr;
|
|
|
|
uint8 _takePtr;
|
2011-06-29 14:13:17 +00:00
|
|
|
int _seqPtr;
|
|
|
|
int _shpCnt;
|
2011-07-01 23:02:14 +00:00
|
|
|
char _file[MAXFILE];
|
2011-06-29 14:13:17 +00:00
|
|
|
Sprite *_prev;
|
|
|
|
Sprite *_next;
|
2011-07-01 23:02:14 +00:00
|
|
|
bool works(Sprite *spr);
|
|
|
|
bool seqTest(int n);
|
|
|
|
inline bool active() {
|
2011-06-28 22:35:21 +00:00
|
|
|
return _ext != NULL;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite(CGEEngine *vm, BMP_PTR *shp);
|
|
|
|
virtual ~Sprite(void);
|
2011-07-01 23:02:14 +00:00
|
|
|
BMP_PTR shp();
|
|
|
|
BMP_PTR *setShapeList(BMP_PTR *shp);
|
|
|
|
void moveShapes(uint8 *buf);
|
|
|
|
Sprite *expand();
|
|
|
|
Sprite *contract();
|
|
|
|
Sprite *backShow(bool fast = false);
|
|
|
|
void setName(char *n);
|
|
|
|
inline char *name() {
|
2011-06-28 22:35:21 +00:00
|
|
|
return (_ext) ? _ext->_name : NULL;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-07-01 23:02:14 +00:00
|
|
|
void gotoxy(int x, int y);
|
|
|
|
void center();
|
|
|
|
void show();
|
|
|
|
void hide();
|
|
|
|
BMP_PTR ghost();
|
|
|
|
void show(uint16 pg);
|
|
|
|
void makeXlat(uint8 *x);
|
|
|
|
void killXlat();
|
|
|
|
void step(int nr = -1);
|
|
|
|
Seq *setSeq(Seq *seq);
|
|
|
|
SNAIL::COM *snList(SNLIST type);
|
|
|
|
virtual void touch(uint16 mask, int x, int y);
|
|
|
|
virtual void tick();
|
2011-06-26 23:03:47 +00:00
|
|
|
private:
|
|
|
|
CGEEngine *_vm;
|
2011-06-09 06:20:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
class QUEUE {
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *Head, * Tail;
|
2011-06-09 06:20:53 +00:00
|
|
|
public:
|
2011-06-13 09:57:24 +00:00
|
|
|
bool Show;
|
2011-06-19 22:13:41 +00:00
|
|
|
QUEUE(bool show);
|
2011-06-13 09:57:24 +00:00
|
|
|
~QUEUE(void);
|
2011-06-28 22:35:21 +00:00
|
|
|
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) {
|
2011-06-13 09:57:24 +00:00
|
|
|
return Head;
|
|
|
|
}
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *Last(void) {
|
2011-06-13 09:57:24 +00:00
|
|
|
return Tail;
|
|
|
|
}
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *Locate(int ref);
|
2011-06-13 09:57:24 +00:00
|
|
|
void Clear(void);
|
2011-06-09 06:20:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
class VGA {
|
2011-06-19 22:13:41 +00:00
|
|
|
uint16 OldMode;
|
|
|
|
uint16 *OldScreen;
|
|
|
|
uint16 StatAdr;
|
|
|
|
bool SetPal;
|
2011-07-01 06:37:40 +00:00
|
|
|
Dac *OldColors;
|
|
|
|
Dac *NewColors;
|
2011-06-19 22:13:41 +00:00
|
|
|
const char *Msg;
|
|
|
|
const char *Nam;
|
|
|
|
|
|
|
|
int SetMode(int mode);
|
|
|
|
void UpdateColors(void);
|
|
|
|
void SetColors(void);
|
|
|
|
void SetStatAdr(void);
|
|
|
|
void WaitVR(bool on);
|
2011-06-09 06:20:53 +00:00
|
|
|
public:
|
2011-06-13 09:57:24 +00:00
|
|
|
uint32 FrmCnt;
|
2011-06-19 22:13:41 +00:00
|
|
|
QUEUE *ShowQ, *SpareQ;
|
|
|
|
int Mono;
|
2011-06-27 08:57:58 +00:00
|
|
|
static Graphics::Surface *Page[4];
|
2011-07-01 06:37:40 +00:00
|
|
|
static Dac *SysPal;
|
2011-06-19 22:13:41 +00:00
|
|
|
|
|
|
|
VGA(int mode);
|
2011-06-13 09:57:24 +00:00
|
|
|
~VGA(void);
|
2011-06-27 08:57:58 +00:00
|
|
|
static void init();
|
|
|
|
static void deinit();
|
2011-06-19 22:13:41 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
void Setup(VgaRegBlk *vrb);
|
2011-07-01 06:37:40 +00:00
|
|
|
void GetColors(Dac *tab);
|
|
|
|
void SetColors(Dac *tab, int lum);
|
2011-06-19 22:13:41 +00:00
|
|
|
void Clear(uint8 color);
|
|
|
|
void CopyPage(uint16 d, uint16 s);
|
2011-07-01 06:37:40 +00:00
|
|
|
void Sunrise(Dac *tab);
|
2011-07-01 23:02:14 +00:00
|
|
|
void Sunset();
|
|
|
|
void Show();
|
|
|
|
void Update();
|
2011-06-27 08:57:58 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
static void pal2DAC(const byte *palData, Dac *tab);
|
|
|
|
static void DAC2pal(const Dac *tab, byte *palData);
|
2011-06-09 06:20:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
Dac MkDAC(uint8 r, uint8 g, uint8 b);
|
2011-06-28 22:35:21 +00:00
|
|
|
Rgb MkRGB(uint8 r, uint8 g, uint8 b);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
template <class CBLK>
|
2011-06-13 09:57:24 +00:00
|
|
|
uint8 Closest(CBLK *pal, CBLK x) {
|
|
|
|
#define f(col, lum) ((((uint16)(col)) << 8) / lum)
|
|
|
|
uint16 i, dif = 0xFFFF, found = 0;
|
2011-07-01 06:37:40 +00:00
|
|
|
uint16 L = x._r + x._g + x._b;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (!L)
|
2011-06-13 09:57:24 +00:00
|
|
|
++L;
|
2011-07-01 06:37:40 +00:00
|
|
|
uint16 R = f(x._r, L), G = f(x._g, L), B = f(x._b, L);
|
2011-06-26 10:07:42 +00:00
|
|
|
for (i = 0; i < 256; i++) {
|
2011-07-01 06:37:40 +00:00
|
|
|
uint16 l = pal[i]._r + pal[i]._g + pal[i]._b;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (! l)
|
2011-06-13 09:57:24 +00:00
|
|
|
++l;
|
2011-07-01 06:37:40 +00:00
|
|
|
int r = f(pal[i]._r, l), g = f(pal[i]._g, l), b = f(pal[i]._b, l);
|
2011-06-13 09:57:24 +00:00
|
|
|
uint16 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;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (D == 0)
|
2011-06-13 09:57:24 +00:00
|
|
|
break; // exact!
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
return found;
|
|
|
|
#undef f
|
2011-06-18 06:54:22 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
char *NumStr(char *str, int num);
|
2011-06-13 09:57:24 +00:00
|
|
|
//static void Video (void);
|
2011-06-28 22:35:21 +00:00
|
|
|
uint16 *SaveScreen(void);
|
|
|
|
void RestoreScreen(uint16 * &sav);
|
|
|
|
Sprite *SpriteAt(int x, int y);
|
|
|
|
Sprite *Locate(int ref);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
extern bool SpeedTest;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-29 07:57:16 +00:00
|
|
|
} // End of namespace CGE
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
#endif
|