From bb591b5415bcf63f554c14d5be9d74bba9e5b6cc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 21 Aug 2011 11:15:28 +0200 Subject: CGE: Some clean up in Vga class --- engines/cge/cge.cpp | 2 +- engines/cge/cge_main.cpp | 19 ++++++------ engines/cge/snail.cpp | 16 +++++----- engines/cge/talk.cpp | 16 +++++----- engines/cge/talk.h | 4 +-- engines/cge/vga13h.cpp | 81 ++++++++++-------------------------------------- engines/cge/vga13h.h | 81 ++++++++++-------------------------------------- engines/cge/vmenu.h | 4 +-- 8 files changed, 65 insertions(+), 158 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 936aeea75a..584512b69a 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -126,7 +126,7 @@ void CGEEngine::setup() { // Initialise engine objects _text = new Text(this, progName(), 128); - _vga = new Vga(M13H); + _vga = new Vga(); _sys = new System(this); _pocLight = new PocLight(this); for (int i = 0; i < kPocketNX; i++) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 759f942c29..e9ea9bd428 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -961,27 +961,27 @@ void Sprite::touch(uint16 mask, int x, int y) { mask |= kMouseLeftUp; } else { if (_hero->distance(this) < kDistMax) { - /// if (_flags._port) { - if (_vm->findPocket(NULL) < 0) + if (_vm->findPocket(NULL) < 0) { _vm->pocFul(); - else { + } else { _snail->addCom(kSnReach, -1, -1, this); _snail->addCom(kSnKeep, -1, -1, this); _flags._port = false; } } else { - if (_takePtr != NO_PTR) { + if (_takePtr != kNoPtr) { if (snList(kTake)[_takePtr]._com == kSnNext) _vm->offUse(); else _vm->feedSnail(this, kTake); - } else + } else { _vm->offUse(); + } } - }/// - else + } else { _vm->tooFar(); + } } } } @@ -994,8 +994,9 @@ void Sprite::touch(uint16 mask, int x, int y) { break; } } - } else + } else { _snail->addCom(kSnWalk, -1, -1, this); // Hero->FindWay(this); + } } } @@ -1018,7 +1019,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int int i, lcnt = 0; char line[kLineMax]; - mergeExt(line, fname, SPR_EXT); + mergeExt(line, fname, kSprExt); if (INI_FILE::exist(line)) { // sprite description file exist INI_FILE sprf(line); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index ef766b9a4e..756c2675aa 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -314,7 +314,7 @@ void CGEEngine::feedSnail(Sprite *spr, SnList snq) { uint8 ptr = (snq == kTake) ? spr->_takePtr : spr->_nearPtr; - if (ptr == NO_PTR) + if (ptr == kNoPtr) return; Snail::Com *comtab = spr->snList(snq); @@ -340,7 +340,7 @@ void CGEEngine::feedSnail(Sprite *spr, SnList snq) { Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); if (s) { uint8 *idx = (snq == kTake) ? &s->_takePtr : &s->_nearPtr; - if (*idx != NO_PTR) { + if (*idx != kNoPtr) { int v; switch (c->_val) { case -1 : @@ -458,7 +458,7 @@ void CGEEngine::snNNext(Sprite *spr, int p) { debugC(1, kCGEDebugEngine, "CGEEngine::snNNext(spr, %d)", p); if (spr) - if (spr->_nearPtr != NO_PTR) + if (spr->_nearPtr != kNoPtr) spr->_nearPtr = p; } @@ -466,7 +466,7 @@ void CGEEngine::snTNext(Sprite *spr, int p) { debugC(1, kCGEDebugEngine, "CGEEngine::snTNext(spr, %d)", p); if (spr) - if (spr->_takePtr != NO_PTR) + if (spr->_takePtr != kNoPtr) spr->_takePtr = p; } @@ -474,7 +474,7 @@ void CGEEngine::snRNNext(Sprite *spr, int p) { debugC(1, kCGEDebugEngine, "CGEEngine::snRNNext(spr, %d)", p); if (spr) - if (spr->_nearPtr != NO_PTR) + if (spr->_nearPtr != kNoPtr) spr->_nearPtr += p; } @@ -483,7 +483,7 @@ void CGEEngine::snRTNext(Sprite *spr, int p) { debugC(1, kCGEDebugEngine, "CGEEngine::snRTNext(spr, %d)", p); if (spr) - if (spr->_takePtr != NO_PTR) + if (spr->_takePtr != kNoPtr) spr->_takePtr += p; } @@ -515,14 +515,14 @@ void CGEEngine::snRmNear(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::snRmNear(spr)"); if (spr) - spr->_nearPtr = NO_PTR; + spr->_nearPtr = kNoPtr; } void CGEEngine::snRmTake(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::snRmTake(spr)"); if (spr) - spr->_takePtr = NO_PTR; + spr->_takePtr = kNoPtr; } void CGEEngine::snSeq(Sprite *spr, int val) { diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 4bcd5cb715..812fa1d9dc 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -166,12 +166,12 @@ Bitmap *Talk::box(uint16 w, uint16 h) { if (_mode) { uint8 *p = b; uint8 *q = b + n - w; - memset(p, LGRAY, w); - memset(q, DGRAY, w); + memset(p, kVgaColLightGray, w); + memset(q, kVgaColDarkGray, w); while (p < q) { p += w; - *(p - 1) = DGRAY; - *p = LGRAY; + *(p - 1) = kVgaColDarkGray; + *p = kVgaColLightGray; } p = b; const uint16 r = (_mode == kTBRound) ? kTextRoundCorner : 0; @@ -183,10 +183,10 @@ Bitmap *Talk::box(uint16 w, uint16 h) { q[j] = kPixelTransp; q[w - j - 1] = kPixelTransp; } - p[j] = LGRAY; - p[w - j - 1] = DGRAY; - q[j] = LGRAY; - q[w - j - 1] = DGRAY; + p[j] = kVgaColLightGray; + p[w - j - 1] = kVgaColDarkGray; + q[j] = kVgaColLightGray; + q[w - j - 1] = kVgaColDarkGray; p += w; q -= w; } diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 71db57c887..9a999e5e8e 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -34,8 +34,8 @@ namespace CGE { -#define kTextColFG DARK // foreground color -#define kTextColBG GRAY // background color +#define kTextColFG kVgaColDark // foreground color +#define kTextColBG kVgaColGray // background color #define kTextHMargin (6&~1) // EVEN horizontal margins! #define kTextVMargin 5 // vertical margins #define kTextLineSpace 2 // line spacing diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index feaa005643..8213a1bcf3 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -38,25 +38,6 @@ namespace CGE { -static VgaRegBlk VideoMode[] = { - { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode - { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 - { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 - { 0x06, VGAGRA, 0x02, 0x00 }, // misc - { 0x14, VGACRT, 0x40, 0x00 }, // underline - { 0x13, VGACRT, 0xFF, 0x28 }, // screen width - { 0x17, VGACRT, 0xFF, 0xC3 }, // mode control - { 0x11, VGACRT, 0x80, 0x00 }, // vert retrace end - { 0x09, VGACRT, 0xEF, 0x01 }, // max scan line - { 0x30, VGAATR, 0x00, 0x20 }, // 256 color mode -// { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end -// { 0x15, VGACRT, 0xFF, 0x7F }, // start vb -// { 0x10, VGACRT, 0xFF, 0x94 }, // start vr - { 0x00, 0x00, 0x00, 0x00 } -}; - -bool SpeedTest = false; - Seq *getConstantSeq(bool seqFlag) { const Seq seq1[] = { { 0, 0, 0, 0, 0 } }; const Seq seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; @@ -76,15 +57,6 @@ Seq *getConstantSeq(bool seqFlag) { extern "C" void SNDMIDIPlay(); -uint16 *SaveScreen() { - // In ScummVM, we don't need to worry about saving the original screen mode - return 0; -} - -void RestoreScreen(uint16 * &sav) { - // In ScummVM, we don't need to restore the original text screen when the game exits -} - Dac mkDac(uint8 r, uint8 g, uint8 b) { static Dac x; x._r = r; @@ -100,7 +72,7 @@ Sprite *locate(int ref) { Sprite::Sprite(CGEEngine *vm, BitmapPtr *shpP) : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), - _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), + _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), _ext(NULL), _ref(-1), _cave(0), _vm(vm) { memset(_file, 0, sizeof(_file)); *((uint16 *)&_flags) = 0; @@ -196,7 +168,7 @@ Seq *Sprite::setSeq(Seq *seq) { Seq *s = _ext->_seq; _ext->_seq = seq; - if (_seqPtr == NO_SEQ) + if (_seqPtr == kNoSeq) step(0); else if (_time == 0) step(_seqPtr); @@ -246,7 +218,9 @@ Sprite *Sprite::expand() { char line[kLineMax], fname[kPathMax]; Common::Array shplist; - for (int i = 0; i < _shpCnt + 1; ++i) shplist.push_back(NULL); + for (int i = 0; i < _shpCnt + 1; ++i) + shplist.push_back(NULL); + Seq *seq = NULL; int shpcnt = 0, seqcnt = 0, @@ -257,7 +231,7 @@ Sprite *Sprite::expand() { Snail::Com *nea = NULL; Snail::Com *tak = NULL; - mergeExt(fname, _file, SPR_EXT); + mergeExt(fname, _file, kSprExt); if (INI_FILE::exist(fname)) { // sprite description file exist INI_FILE sprf(fname); if (!(sprf._error==0)) @@ -311,7 +285,7 @@ Sprite *Sprite::expand() { break; case 3: // Near - if (_nearPtr == NO_PTR) + if (_nearPtr == kNoPtr) break; nea = (Snail::Com *) realloc(nea, (neacnt + 1) * sizeof(*nea)); assert(nea != NULL); @@ -324,7 +298,7 @@ Sprite *Sprite::expand() { break; case 4: // Take - if (_takePtr == NO_PTR) + if (_takePtr == kNoPtr) break; tak = (Snail::Com *) realloc(tak, (takcnt + 1) * sizeof(*tak)); assert(tak != NULL); @@ -362,11 +336,11 @@ Sprite *Sprite::expand() { if (nea) nea[neacnt - 1]._ptr = _ext->_near = nea; else - _nearPtr = NO_PTR; + _nearPtr = kNoPtr; if (tak) tak[takcnt - 1]._ptr = _ext->_take = tak; else - _takePtr = NO_PTR; + _takePtr = kNoPtr; return this; } @@ -721,9 +695,8 @@ void Vga::deinit() { delete[] _sysPal; } -Vga::Vga(int mode) - : _frmCnt(0), _oldMode(0), _oldScreen(NULL), _statAdr(VGAST1_), - _msg(NULL), _name(NULL), _setPal(false), _mono(0) { +Vga::Vga() + : _frmCnt(0), _msg(NULL), _name(NULL), _setPal(false), _mono(0) { _oldColors = NULL; _newColors = NULL; _showQ = new Queue(true); @@ -741,17 +714,11 @@ Vga::Vga(int mode) // warning(Copr); warning("TODO: Fix Copr"); - setStatAdr(); - if (_statAdr != VGAST1_) - _mono++; _oldColors = (Dac *) malloc(sizeof(Dac) * kPalCount); _newColors = (Dac *) malloc(sizeof(Dac) * kPalCount); - _oldScreen = SaveScreen(); getColors(_oldColors); sunset(); - _oldMode = setMode(mode); setColors(); - setup(VideoMode); clear(0); } @@ -779,26 +746,12 @@ Vga::~Vga() { delete _spareQ; } -void Vga::setStatAdr() { - // No implementation needed for ScummVM -} - -#pragma argsused -void Vga::waitVR(bool on) { +void Vga::waitVR() { // Since some of the game parts rely on using vertical sync as a delay mechanism, // we're introducing a short delay to simulate it g_system->delayMillis(5); } -void Vga::setup(VgaRegBlk *vrb) { - // No direct VGA setup required, since ScummVM provides it's own graphics interface -} - -int Vga::setMode(int mode) { - // ScummVM provides it's own vieo services - return 0; -} - void Vga::getColors(Dac *tab) { byte palData[kPalSize]; g_system->getPaletteManager()->grabPalette(palData, 0, kPalCount); @@ -850,9 +803,9 @@ void Vga::setColors() { } void Vga::sunrise(Dac *tab) { - for (int i = 0; i <= 64; i += FADE_STEP) { + for (int i = 0; i <= 64; i += kFadeStep) { setColors(tab, i); - waitVR(true); + waitVR(); updateColors(); } } @@ -860,9 +813,9 @@ void Vga::sunrise(Dac *tab) { void Vga::sunset() { Dac tab[256]; getColors(tab); - for (int i = 64; i >= 0; i -= FADE_STEP) { + for (int i = 64; i >= 0; i -= kFadeStep) { setColors(tab, i); - waitVR(true); + waitVR(); updateColors(); } } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 8576752d07..9649201021 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -37,40 +37,18 @@ namespace CGE { -#define FADE_STEP 2 -#define TMR_DIV ((0x8000/TMR_RATE)*2) -#define NREP 9 -#define FREP 24 - -#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 - -#define LIGHT 0xFF -#define DARK 207 -#define DGRAY 225 /*219*/ -#define GRAY 231 -#define LGRAY 237 -#define kPixelTransp 0xFE - -#define NO_SEQ (-1) -#define NO_PTR ((uint8)-1) - -#define SPR_EXT ".SPR" - -struct VgaRegBlk { - uint8 _idx; - uint8 _adr; - uint8 _clr; - uint8 _set; -}; +#define kFadeStep 2 +#define kVgaColDark 207 +#define kVgaColDarkGray 225 /*219*/ +#define kVgaColGray 231 +#define kVgaColLightGray 237 +#define kPixelTransp 0xFE +#define kNoSeq (-1) +#define kNoPtr ((uint8)-1) +#define kSprExt ".SPR" +#define kPalCount 256 +#define kPalSize (kPalCount * 3) + struct Seq { uint8 _now; @@ -82,21 +60,6 @@ struct Seq { extern Seq _seq1[]; extern Seq _seq2[]; -//extern SEQ * Compass[]; -//extern SEQ TurnToS[]; - -#define kPalCount 256 -#define kPalSize (kPalCount * 3) - -#define VGAATR_ 0x3C0 -#define VGASEQ_ 0x3C4 -#define VGAGRA_ 0x3CE -#define VGACRT_ 0x3D4 -#define VGAST1_ 0x3DA -#define VGAATR (VGAATR_ & 0xFF) -#define VGASEQ (VGASEQ_ & 0xFF) -#define VGAGRA (VGAGRA_ & 0xFF) -#define VGACRT (VGACRT_ & 0xFF) class SprExt { public: @@ -219,20 +182,15 @@ public: }; class Vga { - uint16 _oldMode; - uint16 *_oldScreen; - uint16 _statAdr; bool _setPal; Dac *_oldColors; Dac *_newColors; const char *_msg; const char *_name; - int setMode(int mode); void updateColors(); void setColors(); - void setStatAdr(); - void waitVR(bool on); + void waitVR(); public: uint32 _frmCnt; Queue *_showQ; @@ -241,12 +199,11 @@ public: static Graphics::Surface *_page[4]; static Dac *_sysPal; - Vga(int mode); + Vga(); ~Vga(); static void init(); static void deinit(); - void setup(VgaRegBlk *vrb); void getColors(Dac *tab); void setColors(Dac *tab, int lum); void clear(uint8 color); @@ -288,12 +245,12 @@ uint8 closest(CBLK *pal, CBLK x) { uint16 i, dif = 0xFFFF, found = 0; uint16 L = x._r + x._g + x._b; if (!L) - ++L; + L++; uint16 R = f(x._r, L), G = f(x._g, L), B = f(x._b, L); for (i = 0; i < 256; i++) { uint16 l = pal[i]._r + pal[i]._g + pal[i]._b; - if (! l) - ++l; + if (!l) + l++; int r = f(pal[i]._r, l), g = f(pal[i]._g, l), b = f(pal[i]._b, l); uint16 D = ((r > R) ? (r - R) : (R - r)) + ((g > G) ? (g - G) : (G - g)) + @@ -311,13 +268,9 @@ uint8 closest(CBLK *pal, CBLK x) { #undef f } -uint16 *saveScreen(); -void restoreScreen(uint16 * &sav); Sprite *spriteAt(int x, int y); Sprite *locate(int ref); -extern bool _speedTest; - } // End of namespace CGE #endif diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 93979b5895..0ddcfdb91d 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -34,8 +34,8 @@ namespace CGE { #define kMenuBarVM 1 #define kMenuBarHM 3 -#define kMenuBarLT LGRAY -#define kMenuBarRB DGRAY +#define kMenuBarLT kVgaColLightGray +#define kMenuBarRB kVgaColDarkGray struct Choice { -- cgit v1.2.3