diff options
author | Strangerke | 2011-07-12 07:24:20 +0200 |
---|---|---|
committer | Strangerke | 2011-07-12 07:24:20 +0200 |
commit | dab96401ad352512a8ffa8c1d7baeb431ade7b8c (patch) | |
tree | 8f5a019d1702c9ad626de5c1ffde2cb481c38380 | |
parent | 9ba5e2b304e6ba7ca9d0b782ad8e5dfd98317b02 (diff) | |
download | scummvm-rg350-dab96401ad352512a8ffa8c1d7baeb431ade7b8c.tar.gz scummvm-rg350-dab96401ad352512a8ffa8c1d7baeb431ade7b8c.tar.bz2 scummvm-rg350-dab96401ad352512a8ffa8c1d7baeb431ade7b8c.zip |
CGE: Implement snGhost by splitting _m field in two. Some cleanup.
-rw-r--r-- | engines/cge/bitmap.cpp | 317 | ||||
-rw-r--r-- | engines/cge/bitmap.h | 9 | ||||
-rw-r--r-- | engines/cge/general.h | 15 | ||||
-rw-r--r-- | engines/cge/snail.cpp | 5 | ||||
-rw-r--r-- | engines/cge/vga13h.cpp | 25 | ||||
-rw-r--r-- | engines/cge/vga13h.h | 8 |
6 files changed, 167 insertions, 212 deletions
diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index a8264e6c3f..48bfe1fafb 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -46,7 +46,7 @@ void Bitmap::deinit() { } #pragma argsused -Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { +Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { char pat[MAXPATH]; forceExt(pat, fname, ".VBM"); @@ -78,7 +78,7 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { } -Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL) { +Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL), _map(0) { if (map) code(); } @@ -90,7 +90,8 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL) Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) : _w((w + 3) & ~3), // only full uint32 allowed! _h(h), - _m(NULL) { + _m(NULL), + _map(0) { uint16 dsiz = _w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = _h * lsiz; // - last gape, but + plane trailer @@ -128,7 +129,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) } -Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL) { +Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0) { uint8 *v0 = bmp._v; if (v0) { uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); @@ -143,20 +144,9 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL) { Bitmap::~Bitmap() { - if (memType(_m) == FAR_MEM) + if (_m) free(_m); - - switch (memType(_v)) { - case NEAR_MEM : - delete[](uint8 *) _v; - break; - case FAR_MEM : - delete[] _v; - default: - warning("Unhandled MemType in Bitmap destructor"); - break; - break; - } + delete[] _v; } @@ -165,6 +155,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { _w = bmp._w; _h = bmp._h; _m = NULL; + _map = 0; if (memType(_v) == FAR_MEM) free(_v); if (v0 == NULL) @@ -197,128 +188,120 @@ uint16 Bitmap::moveVmap(uint8 *buf) { BMP_PTR Bitmap::code() { - if (_m) { - uint16 i, cnt; - - if (_v) { // old X-map exists, so remove it - switch (memType(_v)) { - case NEAR_MEM : - delete[](uint8 *) _v; - break; - case FAR_MEM : - delete[] _v; - break; - default: - warning("Unhandled MemType in Bitmap::Code()"); - break; - } - _v = NULL; - } + if (!_m) + return false; - while (true) { // at most 2 times: for (V == NULL) & for allocated block; - uint8 *im = _v + 2; - uint16 *cp = (uint16 *) _v; - int bpl; + uint16 i, cnt; - if (_v) { // 2nd pass - fill the hide table - for (i = 0; i < _h; i++) { - _b[i].skip = 0xFFFF; - _b[i].hide = 0x0000; - } + if (_v) { // old X-map exists, so remove it + delete[] _v; + _v = NULL; + } + + while (true) { // at most 2 times: for (V == NULL) & for allocated block; + uint8 *im = _v + 2; + uint16 *cp = (uint16 *) _v; + int bpl; + + if (_v) { // 2nd pass - fill the hide table + for (i = 0; i < _h; i++) { + _b[i].skip = 0xFFFF; + _b[i].hide = 0x0000; } - for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane - uint8 *bm = _m; - bool skip = (bm[bpl] == TRANS); - uint16 j; - - cnt = 0; - for (i = 0; i < _h; i++) { // once per each line - uint8 pix; - for (j = bpl; j < _w; j += 4) { - pix = bm[j]; - if (_v && pix != TRANS) { - if (j < _b[i].skip) - _b[i].skip = j; - - if (j >= _b[i].hide) - _b[i].hide = j + 1; - } - if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block - cnt |= (skip) ? SKP : CPY; - if (_v) - *cp = cnt; // store block description uint16 - - cp = (uint16 *) im; - im += 2; - skip = (pix == TRANS); - cnt = 0; - } - if (! skip) { - if (_v) - *im = pix; - ++ im; - } - ++ cnt; + } + for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane + uint8 *bm = _m; + bool skip = (bm[bpl] == TRANS); + uint16 j; + + cnt = 0; + for (i = 0; i < _h; i++) { // once per each line + uint8 pix; + for (j = bpl; j < _w; j += 4) { + pix = bm[j]; + if (_v && pix != TRANS) { + if (j < _b[i].skip) + _b[i].skip = j; + + if (j >= _b[i].hide) + _b[i].hide = j + 1; } - - bm += _w; - if (_w < SCR_WID) { - if (skip) { - cnt += (SCR_WID - j + 3) / 4; - } else { - cnt |= CPY; - if (_v) - *cp = cnt; - - cp = (uint16 *) im; - im += 2; - skip = true; - cnt = (SCR_WID - j + 3) / 4; - } + if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block + cnt |= (skip) ? SKP : CPY; + if (_v) + *cp = cnt; // store block description uint16 + + cp = (uint16 *) im; + im += 2; + skip = (pix == TRANS); + cnt = 0; } + if (! skip) { + if (_v) + *im = pix; + ++ im; + } + ++ cnt; } - if (cnt && ! skip) { - cnt |= CPY; - if (_v) - *cp = cnt; - cp = (uint16 *) im; - im += 2; + bm += _w; + if (_w < SCR_WID) { + if (skip) { + cnt += (SCR_WID - j + 3) / 4; + } else { + cnt |= CPY; + if (_v) + *cp = cnt; + + cp = (uint16 *) im; + im += 2; + skip = true; + cnt = (SCR_WID - j + 3) / 4; + } } + } + if (cnt && ! skip) { + cnt |= CPY; if (_v) - *cp = EOI; + *cp = cnt; + cp = (uint16 *) im; im += 2; } if (_v) - break; + *cp = EOI; + cp = (uint16 *) im; + im += 2; + } + if (_v) + break; - uint16 sizV = (uint16)(im - 2 - _v); - _v = new uint8[sizV + _h * sizeof(*_b)]; - if (!_v) - error("No core"); + uint16 sizV = (uint16)(im - 2 - _v); + _v = new uint8[sizV + _h * sizeof(*_b)]; + if (!_v) + error("No core"); - _b = (HideDesc *)(_v + sizV); - } - cnt = 0; - for (i = 0; i < _h; i++) { - if (_b[i].skip == 0xFFFF) { // whole line is skipped - _b[i].skip = (cnt + SCR_WID) >> 2; - cnt = 0; - } else { - uint16 s = _b[i].skip & ~3; - uint16 h = (_b[i].hide + 3) & ~3; - _b[i].skip = (cnt + s) >> 2; - _b[i].hide = (h - s) >> 2; - cnt = SCR_WID - h; - } + _b = (HideDesc *)(_v + sizV); + } + cnt = 0; + for (i = 0; i < _h; i++) { + if (_b[i].skip == 0xFFFF) { // whole line is skipped + _b[i].skip = (cnt + SCR_WID) >> 2; + cnt = 0; + } else { + uint16 s = _b[i].skip & ~3; + uint16 h = (_b[i].hide + 3) & ~3; + _b[i].skip = (cnt + s) >> 2; + _b[i].hide = (h - s) >> 2; + cnt = SCR_WID - h; } } + return this; } -bool Bitmap::solidAt(int x, int y) { +bool Bitmap::solidAt(int16 x, int16 y) { uint8 *m; uint16 r, n, n0; @@ -447,58 +430,58 @@ bool Bitmap::loadVBM(XFile *f) { } bool Bitmap::loadBMP(XFile *f) { - struct { - char BM[2]; - union { int16 len; int32 len_; }; - union { int16 _06; int32 _06_; }; - union { int16 hdr; int32 hdr_; }; - union { int16 _0E; int32 _0E_; }; - union { int16 wid; int32 wid_; }; - union { int16 hig; int32 hig_; }; - union { int16 _1A; int32 _1A_; }; - union { int16 _1E; int32 _1E_; }; - union { int16 _22; int32 _22_; }; - union { int16 _26; int32 _26_; }; - union { int16 _2A; int32 _2A_; }; - union { int16 _2E; int32 _2E_; }; - union { int16 _32; int32 _32_; }; - } hea; - - Bgr4 bpal[256]; - - f->read((byte *)&hea, sizeof(hea)); - if (f->_error == 0) { - if (hea.hdr == 0x436L) { - int16 i = (hea.hdr - sizeof(hea)) / sizeof(Bgr4); - f->read((byte *)&bpal, sizeof(bpal)); - if (f->_error == 0) { - if (_pal) { - for (i = 0; i < 256; i ++) { - _pal[i]._r = bpal[i]._R; - _pal[i]._g = bpal[i]._G; - _pal[i]._b = bpal[i]._B; + struct { + char BM[2]; + union { int16 len; int32 len_; }; + union { int16 _06; int32 _06_; }; + union { int16 hdr; int32 hdr_; }; + union { int16 _0E; int32 _0E_; }; + union { int16 wid; int32 wid_; }; + union { int16 hig; int32 hig_; }; + union { int16 _1A; int32 _1A_; }; + union { int16 _1E; int32 _1E_; }; + union { int16 _22; int32 _22_; }; + union { int16 _26; int32 _26_; }; + union { int16 _2A; int32 _2A_; }; + union { int16 _2E; int32 _2E_; }; + union { int16 _32; int32 _32_; }; + } hea; + + Bgr4 bpal[256]; + + f->read((byte *)&hea, sizeof(hea)); + if (f->_error == 0) { + if (hea.hdr == 0x436L) { + int16 i = (hea.hdr - sizeof(hea)) / sizeof(Bgr4); + f->read((byte *)&bpal, sizeof(bpal)); + if (f->_error == 0) { + if (_pal) { + for (i = 0; i < 256; i ++) { + _pal[i]._r = bpal[i]._R; + _pal[i]._g = bpal[i]._G; + _pal[i]._b = bpal[i]._B; + } + _pal = NULL; + } + _h = hea.hig; + _w = hea.wid; + if ((_m = farnew(byte, _h * _w)) != NULL) { + int16 r = (4 - (hea.wid & 3)) % 4; + byte buf[3]; + for (i = _h - 1; i >= 0; i--) { + f->read(_m + (_w * i), _w); + if (r && f->_error == 0) + f->read(buf, r); + if (f->_error) + break; + } + if (i < 0) + return true; + } } - _pal = NULL; - } - _h = hea.hig; - _w = hea.wid; - if ((_m = farnew(byte, _h * _w)) != NULL) { - int16 r = (4 - (hea.wid & 3)) % 4; - byte buf[3]; - for (i = _h - 1; i >= 0; i--) { - f->read(_m + (_w * i), _w); - if (r && f->_error == 0) - f->read(buf, r); - if (f->_error) - break; - } - if (i < 0) - return true; } - } } - } - return false; + return false; } } // End of namespace CGE diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 4c2b67b8df..3fdb673396 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -68,6 +68,7 @@ public: uint16 _h; uint8 *_m; uint8 *_v; + int32 _map; HideDesc *_b; Bitmap(const char *fname, bool rem); @@ -81,10 +82,10 @@ public: Bitmap *flipH(); Bitmap *code(); Bitmap &operator = (const Bitmap &bmp); - void hide(int x, int y); - void show(int x, int y); - void xShow(int x, int y); - bool solidAt(int x, int y); + void hide(int16 x, int16 y); + void show(int16 x, int16 y); + void xShow(int16 x, int16 y); + bool solidAt(int16 x, int16 y); bool saveVBM(XFile *f); uint16 moveVmap(uint8 *buf); }; diff --git a/engines/cge/general.h b/engines/cge/general.h index 7cf3ec3e41..2eebc01c62 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -39,22 +39,13 @@ namespace CGE { #define SEED 0xA5 -#define SCR_WID_ 320 -#define SCR_HIG_ 200 -#define SCR_WID ((uint16)SCR_WID_) -#define SCR_HIG ((uint16)SCR_HIG_) -#define SCR_SEG 0xA000 -#define SCR_ADR ((uint8 *) MK_FP(SCR_SEG, 0)) - - - -//enum CPU { _8086, _80186, _80286, _80386, _80486 }; enum MEM_TYPE { BAD_MEM, EMS_MEM, NEAR_MEM, FAR_MEM }; -enum ALLOC_MODE { FIRST_FIT, BEST_FIT, LAST_FIT }; enum IOMODE { REA, WRI, UPD }; struct Dac { - uint8 _r, _g, _b; + uint8 _r; + uint8 _g; + uint8 _b; }; typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 242fb067e7..bc9d212468 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -309,11 +309,10 @@ void CGEEngine::hide1(Sprite *spr) { } void CGEEngine::snGhost(Bitmap *bmp) { - // TODO : Get x and y from M but not using segment / offset - //bmp->Hide(FP_OFF(bmp->_m), FP_SEG(bmp->_m)); + bmp->hide(bmp->_map & 0xFFFF, bmp->_map >> 16); bmp->_m = NULL; + bmp->_map = 0; delete bmp; - warning("STUB: SNGhost"); } void CGEEngine::feedSnail(Sprite *spr, SNLIST snq) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d92b9e97f0..e85e13d20c 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -683,18 +683,9 @@ void Sprite::killXlat() { if (_flags._xlat && _ext) { BMP_PTR *b; uint8 *m = (*_ext->_shpList)->_m; - - switch (memType(m)) { - case NEAR_MEM : - delete[](uint8 *) m; - break; - case FAR_MEM : + if (m) free(m); - break; - default: - warning("Unhandled MemType in Sprite::KillXlat()"); - break; - } + for (b = _ext->_shpList; *b; b++) (*b)->_m = NULL; _flags._xlat = false; @@ -777,9 +768,7 @@ BMP_PTR Sprite::ghost() { if ((bmp->_b = new HideDesc[bmp->_h]) == NULL) error("No Core"); bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h); - // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment - //bmp->_m = (uint8 *) MK_FP(e->y1, e->x1); - warning("FIXME: SPRITE::Ghost"); + bmp->_map = (e->_y1 << 16) + e->_x1; return bmp; } return NULL; @@ -1209,7 +1198,7 @@ void Vga::copyPage(uint16 d, uint16 s) { //-------------------------------------------------------------------------- -void Bitmap::xShow(int x, int y) { +void Bitmap::xShow(int16 x, int16 y) { /* uint8 rmsk = x % 4, mask = 1 << rmsk, @@ -1291,7 +1280,7 @@ void Bitmap::xShow(int x, int y) { } -void Bitmap::show(int x, int y) { +void Bitmap::show(int16 x, int16 y) { const byte *srcP = (const byte *)_v; byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); @@ -1353,8 +1342,8 @@ void Bitmap::show(int x, int y) { } -void Bitmap::hide(int x, int y) { - for (int yp = y; yp < y + _h; ++yp) { +void Bitmap::hide(int16 x, int16 y) { + for (int yp = y; yp < y + _h; yp++) { const byte *srcP = (const byte *)Vga::_page[2]->getBasePtr(x, yp); byte *destP = (byte *)Vga::_page[1]->getBasePtr(x, yp); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 003be7c800..e29fa2eea4 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -57,19 +57,11 @@ namespace CGE { #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 ((uint8)-1) |