diff options
author | Paweł Kołodziejski | 2002-08-08 21:54:49 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2002-08-08 21:54:49 +0000 |
commit | 40a8a7ce1a13d9fc187024d6daf7caf5a3aa58e6 (patch) | |
tree | aa5c90cd0c38c9c1f19c04ddc3442bd689dc59d3 | |
parent | 9409960e599d862edbe7aee34ed765b9e9a7b8e7 (diff) | |
download | scummvm-rg350-40a8a7ce1a13d9fc187024d6daf7caf5a3aa58e6.tar.gz scummvm-rg350-40a8a7ce1a13d9fc187024d6daf7caf5a3aa58e6.tar.bz2 scummvm-rg350-40a8a7ce1a13d9fc187024d6daf7caf5a3aa58e6.zip |
SMUSH: attached to timer, moved to class
svn-id: r4719
-rw-r--r-- | insane.cpp | 409 | ||||
-rw-r--r-- | script_v2.cpp | 7 | ||||
-rw-r--r-- | smush.h | 174 | ||||
-rw-r--r-- | sound.cpp | 1 | ||||
-rw-r--r-- | timer.cpp | 13 | ||||
-rw-r--r-- | timer.h | 2 |
6 files changed, 268 insertions, 338 deletions
diff --git a/insane.cpp b/insane.cpp index 2d7bad16a9..8aba0b47b5 100644 --- a/insane.cpp +++ b/insane.cpp @@ -31,59 +31,70 @@ #include "scumm.h" #include "smush.h" -//#define SWAP2(a) ((((a)>>24)&0xFF) | (((a)>>8)&0xFF00) | (((a)<<8)&0xFF0000) | (((a)<<24)&0xFF000000)) #define MAX_STREAMER 10 -byte * SmushPlayer::loadTres() -{ +static SmushPlayer * h_sp; + +SmushPlayer::SmushPlayer(Scumm * parent) { + _scumm = parent; + h_sp = this; +} + +SmushPlayer::~SmushPlayer() { +} + +static int smush_handler (int t) { + h_sp->update(); + return t; +} + +byte * SmushPlayer::loadTres() { byte buf[100]; FILE * f_tres; uint32 tmp, l; - sprintf((char *)buf, "%sVIDEO/%sTXT.TRS", (char *)sm->_gameDataPath, - (char *)sm->_exe_name); - f_tres = fopen((char *)buf, "rb"); + sprintf((char *)buf, "%sVIDEO/DIGTXT.TRS", (byte *)_scumm->_gameDataPath); + f_tres = (FILE*)_scumm->fileOpen((char *)&buf, 1); if (f_tres == NULL) { - sprintf((char *)buf, "%svideo/%stxt.trs", (char *)sm->_gameDataPath, - (char *)sm->_exe_name); - f_tres = fopen((char *)buf, "rb"); - if (f_tres == NULL) + sprintf((char *)buf, "%svideo/digtxt.trs", (byte *)_scumm->_gameDataPath); + f_tres = (FILE*)_scumm->fileOpen((char *)&buf, 1); + if (f_tres == NULL) return NULL; } - if (fread(&tmp, 4, 1, f_tres) != 1) // read tag - error("error while reading TRES"); + _scumm->fileRead(f_tres, &tmp, 4); // read tag + if (_scumm->_fileReadFailed) + error("SP: error while reading TRES"); tmp = READ_BE_UINT32(&tmp); if (tmp == 'ETRS') { - fread(&tmp, 4, 1, f_tres); // read length + _scumm->fileRead(f_tres, &tmp, 4); // read length tmp = READ_BE_UINT32(&tmp); tmp -= 8; - _buffer_tres = (byte*)malloc (tmp + 1); - fread(_buffer_tres, 8, 1, f_tres); // skip 8 bytes - fread(_buffer_tres, tmp, 1, f_tres); + _bufferTres = (byte*)malloc (tmp + 1); + _scumm->fileRead(f_tres, _bufferTres, 8); // skip 8 bytes + _scumm->fileRead(f_tres, _bufferTres, tmp); for (l = 0; l < tmp; l++) - *(_buffer_tres + l) ^= 0xcc; - _buffer_tres[tmp] = 0; + *(_bufferTres + l) ^= 0xcc; + _bufferTres[tmp] = 0; } else { - fseek(f_tres, 0, SEEK_END); // assume file is unencrypted + _scumm->fileSeek(f_tres, 0, SEEK_END); // assume file is unencrypted tmp = ftell(f_tres); - fseek(f_tres, 0, SEEK_SET); - _buffer_tres = (byte*)malloc (tmp + 1); - fread(_buffer_tres, tmp, 1, f_tres); - _buffer_tres[tmp] = 0; + _scumm->fileSeek(f_tres, 0, SEEK_SET); + _bufferTres = (byte*)malloc (tmp + 1); + fread(_bufferTres, tmp, 1, f_tres); + _bufferTres[tmp] = 0; } - fclose (f_tres); + _scumm->fileClose(f_tres); - return _buffer_tres; + return _bufferTres; } -void SmushPlayer::loadFonts() -{ +void SmushPlayer::loadFonts() { byte buf[100]; FILE * f_tres; uint32 tmp; @@ -93,46 +104,45 @@ void SmushPlayer::loadFonts() for (l = 0; l < SP_MAX_FONTS; l++) { _fonts [l] = NULL; - sprintf((char *)buf, "%sVIDEO/FONT%d.NUT", (char *)sm->_gameDataPath, l); - f_tres = fopen((char *)buf, "rb"); + sprintf((char *)buf, "%sVIDEO/FONT%d.NUT", (char *)_scumm->_gameDataPath, l); + f_tres = (FILE*)_scumm->fileOpen((char *)buf, 1); if (f_tres == NULL) { - sprintf((char *)buf, "%svideo/font%d.nut", (char *)sm->_gameDataPath, l); - f_tres = fopen((char *)buf, "rb"); + sprintf((char *)buf, "%svideo/font%d.nut", (char *)_scumm->_gameDataPath, l); + f_tres = (FILE*)_scumm->fileOpen((char *)buf, 1); if (f_tres == NULL) continue; } - fread(&tmp, 4, 1, f_tres); // read tag + _scumm->fileRead(f_tres, &tmp, 4); // read tag tmp = READ_BE_UINT32(&tmp); if (tmp == 'ANIM') { - fread(&tmp, 4, 1, f_tres); // read length + _scumm->fileRead(f_tres, &tmp, 4); // read length tmp = READ_BE_UINT32(&tmp); buffer = (byte *)malloc(tmp); - fread(buffer, tmp, 1, f_tres); + _scumm->fileRead(f_tres, buffer, tmp); _fonts[l] = buffer; } - fclose (f_tres); + _scumm->fileClose(f_tres); } } -byte * SmushPlayer::getStringTRES(int32 number) -{ +byte * SmushPlayer::getStringTRES(int32 number) { byte * txt = NULL; uint32 l, i, j; for (l = 0;; l++) { - char t = *(_buffer_tres + l); + char t = *(_bufferTres + l); if (t == 0) break; if (t == '#') { byte buf[10]; - strncpy ((char*)buf, (char*)_buffer_tres + l + 1, 9); + strncpy ((char*)buf, (char*)_bufferTres + l + 1, 9); buf[9] = 0; if (strcmp ((char*)buf, "define a ") == 0) { l += 10; for (i = 0; i < 5; i++) { - buf[i] = *(_buffer_tres + l + i); + buf[i] = *(_bufferTres + l + i); if (buf[i] == 0x0d) { buf[i] = 0; @@ -142,12 +152,12 @@ byte * SmushPlayer::getStringTRES(int32 number) } if (atol((char*)buf) == number) { for (j = 0; j < 200; j++) { - t = *(_buffer_tres + l + j + i); + t = *(_bufferTres + l + j + i); if ((t == 0) || (t == '#')) break; } txt = (byte *)malloc(j + 1); - strncpy((char*)txt, (char*)_buffer_tres + l + i, j); + strncpy((char*)txt, (char*)_bufferTres + l + i, j); txt[j] = 0; return txt; } @@ -158,8 +168,7 @@ byte * SmushPlayer::getStringTRES(int32 number) return txt; } -uint32 SmushPlayer::getFontHeight(uint8 c_font) -{ +uint32 SmushPlayer::getFontHeight(uint8 c_font) { byte * font = _fonts[c_font]; uint32 offset = 0, t_offset = 0; @@ -181,8 +190,7 @@ uint32 SmushPlayer::getFontHeight(uint8 c_font) return READ_LE_UINT16(font + t_offset + 8); } -uint32 SmushPlayer::getCharWidth(uint8 c_font, byte txt) -{ +uint32 SmushPlayer::getCharWidth(uint8 c_font, byte txt) { byte * font = _fonts[c_font]; uint32 offset = 0, t_offset = 0, l; @@ -209,8 +217,7 @@ uint32 SmushPlayer::getCharWidth(uint8 c_font, byte txt) return READ_LE_UINT16(font + t_offset + 6); } -void SmushPlayer::drawStringTRES(uint32 x, uint32 y, byte * txt) -{ +void SmushPlayer::drawStringTRES(uint32 x, uint32 y, byte * txt) { char buf[4]; uint32 c_line = 0, l = 0, i, tmp_x, x_pos, last_l, t_width, t_height; uint8 c_font = 0, c_color = 0, last_j; @@ -321,8 +328,7 @@ exit_loop: ; } -void codec44_depack(byte *dst, byte *src, uint32 len) -{ +void SmushPlayer::codec44Depack(byte *dst, byte *src, uint32 len) { byte val; uint16 size_line; uint16 num; @@ -355,8 +361,7 @@ void codec44_depack(byte *dst, byte *src, uint32 len) } while (len > 1); } -void SmushPlayer::drawCharTRES(uint32 * x, uint32 y, uint32 c_line, uint8 c_font, uint8 color, uint8 txt) -{ +void SmushPlayer::drawCharTRES(uint32 * x, uint32 y, uint32 c_line, uint8 c_font, uint8 color, uint8 txt) { byte * font = _fonts[c_font]; uint32 offset = 0, t_offset = 0, l, width, height, length = 0; @@ -385,9 +390,7 @@ void SmushPlayer::drawCharTRES(uint32 * x, uint32 y, uint32 c_line, uint8 c_font byte * dst = (byte*)malloc (1000); byte * src = (byte*)(font + t_offset + 0x0e); - memset (dst, 0, 1000); - - codec44_depack (dst, src, length); + codec44Depack (dst, src, length); width = READ_LE_UINT16(font + t_offset + 6); height = READ_LE_UINT16(font + t_offset + 8); @@ -415,61 +418,28 @@ void SmushPlayer::drawCharTRES(uint32 * x, uint32 y, uint32 c_line, uint8 c_font free (dst); } -void invalidblock(uint32 tag) -{ - error("Encountered invalid block %c%c%c%c", tag >> 24, tag >> 16, tag >> 8, tag); -} - -int _frameChanged; -int _mixer_num; - -uint32 SmushPlayer::nextBE32() -{ +uint32 SmushPlayer::nextBE32() { uint32 a = READ_BE_UINT32(_cur); _cur += sizeof(uint32); return a; } -void SmushPlayer::fileRead(void *mem, int len) -{ - if (fread(mem, len, 1, _in) != 1) - error("EOF while reading"); - -} - -uint32 SmushPlayer::fileReadBE32() -{ - byte b[4]; - fread(b, sizeof(b), 1, _in); - return (b[0]<<24)|(b[1]<<16)|(b[2]<<8)|b[3]; -} - -uint32 SmushPlayer::fileReadLE32() -{ - byte b[4]; - fread(b, sizeof(b), 1, _in); - return (b[3]<<24)|(b[2]<<16)|(b[1]<<8)|b[0]; -} - -void SmushPlayer::openFile(byte *fileName) -{ +void SmushPlayer::openFile(byte *fileName) { byte buf[100]; - sprintf((char *)buf, "%sVIDEO/%s", (char *)sm->_gameDataPath, (char *)fileName); - _in = fopen((char *)buf, "rb"); + sprintf((char *)buf, "%sVIDEO/%s", (char *)_scumm->_gameDataPath, (char *)fileName); + _in = (FILE*)_scumm->fileOpen((char *)buf, 1); if (_in == NULL) { - sprintf((char *)buf, "%svideo/%s", (char *)sm->_gameDataPath, (char *)fileName); - _in = fopen((char *)buf, "rb"); - + sprintf((char *)buf, "%svideo/%s", (char *)_scumm->_gameDataPath, (char *)fileName); + _in = (FILE*)_scumm->fileOpen((char *)buf, 1); } } -void SmushPlayer::nextBlock() -{ - _blockTag = fileReadBE32(); - _blockSize = fileReadBE32(); +void SmushPlayer::nextBlock() { + _blockTag = _scumm->fileReadDwordBE(_in); + _blockSize = _scumm->fileReadDwordBE(_in); if (_block != NULL) free(_block); @@ -477,13 +447,12 @@ void SmushPlayer::nextBlock() _block = (byte *)malloc(_blockSize); if (_block == NULL) - error("cannot allocate memory"); + error("SP: cannot allocate memory"); - fileRead(_block, _blockSize); + _scumm->fileRead(_in, _block, _blockSize); } -bool SmushPlayer::parseTag() -{ +bool SmushPlayer::parseTag() { switch (nextBlock(), _blockTag) { case 'AHDR': @@ -495,26 +464,20 @@ bool SmushPlayer::parseTag() break; default: - invalidblock(_blockTag); + error("SP: Encountered invalid block %c%c%c%c", _blockTag >> 24, _blockTag >> 16, _blockTag >> 8, _blockTag); } return true; } - - -void SmushPlayer::parseAHDR() -{ +void SmushPlayer::parseAHDR() { memcpy(_fluPalette, _block + 6, 0x300); _paletteChanged = true; - -// printf("parse AHDR\n"); } - -void SmushPlayer::parseIACT() -{ - unsigned int pos, bpos, tag, sublen, subpos, trk, idx, flags; +void SmushPlayer::parseIACT() { + uint32 pos, bpos, tag, sublen, subpos, trk, idx; + byte flags; bool new_mixer = false; byte *buf; @@ -547,7 +510,7 @@ void SmushPlayer::parseIACT() return; } - pos += 8; /* FIXME: what are these ? */ + pos += 8; /* FIXME: what are these ? */ while (pos < _frmeSize) { @@ -661,17 +624,12 @@ void SmushPlayer::parseIACT() } } -void SmushPlayer::parseNPAL() -{ +void SmushPlayer::parseNPAL() { memcpy(_fluPalette, _cur, 0x300); - _paletteChanged = true; } - - -void codec1(CodecData * cd) -{ +void SmushPlayer::codec1(CodecData * cd) { uint y = cd->y; byte *src = cd->src; byte *dest = cd->out; @@ -706,14 +664,14 @@ void codec1(CodecData * cd) if (code & 1) { color = *src++; -// if ((color = *src++)!=0) { +// if ((color = *src++)!=0) { do { if ((uint) x < (uint) cd->outwidth) dest[x] = color; } while (++x, --num); -// } else { -// x += num; -// } +// } else { +// x += num; +// } } else { do { color = *src++; @@ -725,13 +683,10 @@ void codec1(CodecData * cd) } while (dest += cd->pitch, y++, --h); } - - -void codec37_bompdepack(byte *dst, byte *src, int len) -{ +void SmushPlayer::codec37BompDepack(byte *dst, byte *src, int32 len) { byte code; byte color; - int num; + int32 num; do { code = *src++; @@ -749,14 +704,13 @@ void codec37_bompdepack(byte *dst, byte *src, int len) } while (len -= num); } -void codec37_proc4(byte *dst, byte *src, int next_offs, int bw, int bh, int pitch, int16 *table) -{ +void SmushPlayer::codec37Proc4(byte *dst, byte *src, int32 next_offs, int32 bw, int32 bh, int32 pitch, int16 *table) { byte code, *tmp; - int i; + int32 i; uint32 t; if (pitch != 320) { - warning("invalid pitch"); + warning("SP: invalid pitch"); return; } @@ -877,15 +831,14 @@ void codec37_proc4(byte *dst, byte *src, int next_offs, int bw, int bh, int pitc } -void codec37_proc5(int game, byte *dst, byte *src, int next_offs, int bw, int bh, - int pitch, int16 *table) -{ +void SmushPlayer::codec37Proc5(int32 game, byte *dst, byte *src, int32 next_offs, int32 bw, int32 bh, + int32 pitch, int16 *table) { byte code, *tmp; - int i; + int32 i; uint32 t; if (pitch != 320) { - warning("invalid pitch"); + warning("SP: invalid pitch"); return; } @@ -976,7 +929,6 @@ void codec37_proc5(int game, byte *dst, byte *src, int next_offs, int bw, int bh } while (--bh); } - // this table is the same in FT and Dig static const int8 maketable_bytes[] = { 0, 0, 1, 0, 2, 0, 3, 0, 5, 0, 8, 0, 13, 0, 21, 0, @@ -1077,9 +1029,8 @@ static const int8 maketable_bytes[] = { -12, 19, 13, 19, -6, 22, 6, 22, 0, 23, }; -void codec37_maketable(PersistentCodecData37 * pcd, int pitch, byte idx) -{ - int i, j; +void SmushPlayer::codec37Maketable(PersistentCodecData37 * pcd, int32 pitch, byte idx) { + int32 i, j; if (pcd->table_last_pitch == pitch && pcd->table_last_flags == idx) return; @@ -1087,7 +1038,7 @@ void codec37_maketable(PersistentCodecData37 * pcd, int pitch, byte idx) pcd->table_last_pitch = pitch; pcd->table_last_flags = idx; - assert(idx * 255 + 254 < (int)(sizeof(maketable_bytes) / 2)); + assert(idx * 255 + 254 < (int32)(sizeof(maketable_bytes) / 2)); for (i = 0; i < 255; i++) { j = i + idx * 255; @@ -1095,14 +1046,11 @@ void codec37_maketable(PersistentCodecData37 * pcd, int pitch, byte idx) } } - - -int codec37(int game, CodecData * cd, PersistentCodecData37 * pcd) -{ - int width_in_blocks, height_in_blocks; - int src_pitch; +bool SmushPlayer::codec37(int32 game, CodecData * cd, PersistentCodecData37 * pcd) { + int32 width_in_blocks, height_in_blocks; + int32 src_pitch; byte *curbuf; - uint size; + int32 size; bool result = false; _frameChanged = 1; @@ -1111,7 +1059,7 @@ int codec37(int game, CodecData * cd, PersistentCodecData37 * pcd) height_in_blocks = (cd->h + 3) >> 2; src_pitch = width_in_blocks * 4; - codec37_maketable(pcd, src_pitch, cd->src[1]); + codec37Maketable(pcd, src_pitch, cd->src[1]); switch (cd->src[0]) { case 0:{ @@ -1127,7 +1075,7 @@ int codec37(int game, CodecData * cd, PersistentCodecData37 * pcd) size = READ_LE_UINT32(cd->src + 4); curbuf = pcd->deltaBufs[pcd->curtable]; if (size == 64000) - codec37_bompdepack(curbuf, cd->src + 16, size); + codec37BompDepack(curbuf, cd->src + 16, size); else return (1); @@ -1152,7 +1100,7 @@ int codec37(int game, CodecData * cd, PersistentCodecData37 * pcd) pcd->curtable ^= 1; } - codec37_proc5(game, pcd->deltaBufs[pcd->curtable], cd->src + 16, + codec37Proc5(game, pcd->deltaBufs[pcd->curtable], cd->src + 16, pcd->deltaBufs[pcd->curtable ^ 1] - pcd->deltaBufs[pcd->curtable], width_in_blocks, height_in_blocks, src_pitch, pcd->table1); @@ -1175,7 +1123,7 @@ int codec37(int game, CodecData * cd, PersistentCodecData37 * pcd) pcd->curtable ^= 1; } - codec37_proc4(pcd->deltaBufs[pcd->curtable], cd->src + 16, + codec37Proc4(pcd->deltaBufs[pcd->curtable], cd->src + 16, pcd->deltaBufs[pcd->curtable ^ 1] - pcd->deltaBufs[pcd->curtable], width_in_blocks, height_in_blocks, src_pitch, pcd->table1); @@ -1183,11 +1131,11 @@ int codec37(int game, CodecData * cd, PersistentCodecData37 * pcd) } case 1: - warning("code %d", cd->src[0]); + warning("SP: code %d", cd->src[0]); return (1); default: - error("codec37 default case"); + error("SP: codec37 default case"); } pcd->flags = READ_LE_UINT16(cd->src + 2); @@ -1201,8 +1149,7 @@ int codec37(int game, CodecData * cd, PersistentCodecData37 * pcd) return (_frameChanged); } -void codec37_init(PersistentCodecData37 * pcd, int width, int height) -{ +void SmushPlayer::codec37Init(PersistentCodecData37 * pcd, int32 width, int32 height) { pcd->width = width; pcd->height = height; pcd->deltaSize = width * height * 2 + 0x3E00 + 0xBA00; @@ -1213,8 +1160,7 @@ void codec37_init(PersistentCodecData37 * pcd, int width, int height) pcd->table1 = (int16 *)calloc(255, sizeof(uint16)); } -void SmushPlayer::parseFOBJ() -{ +void SmushPlayer::parseFOBJ() { byte codec; CodecData cd; @@ -1235,16 +1181,15 @@ void SmushPlayer::parseFOBJ() codec1(&cd); break; case 37: - _frameChanged = codec37(sm->_gameId, &cd, &pcd37); + _frameChanged = codec37(_scumm->_gameId, &cd, &pcd37); break; default: - error("invalid codec %d", codec); + error("SP: invalid codec %d", codec); } } -void SmushPlayer::parsePSAD() // FIXME: Needs to append to -{ // a sound buffer - unsigned int pos, sublen, tag, idx, trk; +void SmushPlayer::parsePSAD() { // FIXME: Needs to append to a sound buffer + uint32 pos, sublen, tag, idx, trk; bool new_mixer = false; byte *buf; pos = 0; @@ -1332,26 +1277,21 @@ void SmushPlayer::parsePSAD() // FIXME: Needs to append to } } -void SmushPlayer::parseTRES() -{ - // FIXME: Doesn't work for Full Throttle - if (sm->_gameId != GID_DIG) { - printf("getStringTRES(%d)\n", READ_LE_UINT16(_cur + 16)); - return; - } - if ((sm->_noSubtitles) && (READ_LE_UINT16(_cur + 4) != 0)) - return; +void SmushPlayer::parseTRES() { + if (_scumm->_gameId == GID_DIG) { + if ((_scumm->_noSubtitles) && (READ_LE_UINT16(_cur + 4) != 0)) + return; - byte * txt = getStringTRES (READ_LE_UINT16(_cur + 16)); - drawStringTRES (READ_LE_UINT16(_cur), READ_LE_UINT16(_cur + 2), txt); - if (txt != NULL) - free (txt); + byte * txt = getStringTRES (READ_LE_UINT16(_cur + 16)); + drawStringTRES (READ_LE_UINT16(_cur), READ_LE_UINT16(_cur + 2), txt); + if (txt != NULL) + free (txt); + } } -void SmushPlayer::parseXPAL() -{ - int num; - int i; +void SmushPlayer::parseXPAL() { + int32 num; + int32 i; num = READ_LE_UINT16(_cur + 2); if (num == 0 || num == 0x200) { @@ -1375,8 +1315,7 @@ void SmushPlayer::parseXPAL() _paletteChanged = true; } -void SmushPlayer::parseFRME() -{ +void SmushPlayer::parseFRME() { _cur = _block; do { @@ -1407,17 +1346,16 @@ void SmushPlayer::parseFRME() break; default: - invalidblock(_frmeTag); + error("SP: Encountered invalid block %c%c%c%c", _frmeTag >> 24, _frmeTag >> 16, _frmeTag >> 8, _frmeTag); } _cur += (_frmeSize + 1) & ~1; } while (_cur + 4 < _block + _blockSize); } -void SmushPlayer::init() -{ - _renderBitmap = sm->_videoBuffer; - codec37_init(&pcd37, 320, 200); +void SmushPlayer::init() { + _renderBitmap = _scumm->_videoBuffer; + codec37Init(&pcd37, 320, 200); memset(_saudSize, 0, sizeof(_saudSize)); memset(_saudSubSize, 0, sizeof(_saudSubSize)); @@ -1430,23 +1368,23 @@ void SmushPlayer::init() memset(_imusPos, 0, sizeof(_imusPos)); memset(_imusChan, 0, sizeof(_imusChan)); - if (sm->_gameId == GID_DIG) + if (_scumm->_gameId == GID_DIG) { for (uint8 l = 0; l < SP_MAX_FONTS; l++) { _fonts[l] = NULL; } - _buffer_tres = NULL; + _bufferTres = NULL; loadTres(); loadFonts(); } + _scumm->_timer->installProcedure(&smush_handler, 83); } -void SmushPlayer::deinit() -{ - if (sm->_gameId == GID_DIG) +void SmushPlayer::deinit() { + if (_scumm->_gameId == GID_DIG) { - if (_buffer_tres != NULL) - free (_buffer_tres); + if (_bufferTres != NULL) + free (_bufferTres); for (int l = 0; l < SP_MAX_FONTS; l++) { if (_fonts[l] != NULL) { @@ -1455,17 +1393,16 @@ void SmushPlayer::deinit() } } } + _scumm->_timer->releaseProcedure(&smush_handler); } -void SmushPlayer::go() -{ +void SmushPlayer::go() { while (parseTag()) { } } -void SmushPlayer::setPalette() -{ - int i; +void SmushPlayer::setPalette() { + int32 i; byte palette_colors[1024]; byte *p = palette_colors; byte *data = _fluPalette; @@ -1477,15 +1414,18 @@ void SmushPlayer::setPalette() p[3] = 0; } - sm->_system->set_palette(palette_colors, 0, 256); + _scumm->_system->set_palette(palette_colors, 0, 256); +} + +void SmushPlayer::update() { + _lock = false; } -void SmushPlayer::startVideo(short int arg, byte *videoFile) -{ - int frameIndex = 0; +void SmushPlayer::startVideo(short int arg, byte *videoFile) { + int32 frameIndex = 0; _in = NULL; - _paletteChanged = 0; + _paletteChanged = false; _block = NULL; _blockTag = 0; _blockSize = 0; @@ -1496,38 +1436,27 @@ void SmushPlayer::startVideo(short int arg, byte *videoFile) _frmeSize = 0; _deltaBuf = NULL; _deltaBufSize = 0; + _lock = true; - pcd37.deltaBuf = NULL; - pcd37.deltaBufs[0] = NULL; - pcd37.deltaBufs[1] = NULL; - pcd37.deltaSize = 0; - pcd37.width = 0; - pcd37.height = 0; - pcd37.curtable = 0; - pcd37.unk2 = 0; - pcd37.unk3 = 0; - pcd37.flags = 0; - pcd37.table1 = NULL; - pcd37.table_last_pitch = 0; - pcd37.table_last_flags = 0; - - sm->pauseBundleMusic(true); + memset (&pcd37, 0, sizeof (PersistentCodecData37)); + + _scumm->pauseBundleMusic(true); init(); openFile(videoFile); if (_in == NULL) return; - if (fileReadBE32() != 'ANIM') - error("file is not an anim"); + if (_scumm->fileReadDwordBE(_in) != 'ANIM') + error("SP: file is not an anim"); - fileSize = fileReadBE32(); + fileSize = _scumm->fileReadDwordBE(_in); - sm->videoFinished = 0; - sm->_insaneState = 1; + _scumm->videoFinished = 0; + _scumm->_insaneState = 1; do { - _frameChanged = 1; + _frameChanged = true; if (ftell(_in) >= fileSize) break; @@ -1541,26 +1470,26 @@ void SmushPlayer::startVideo(short int arg, byte *videoFile) if (_paletteChanged) { _paletteChanged = false; setPalette(); - sm->setDirtyColors(0, 255); + _scumm->setDirtyColors(0, 255); } if (_frameChanged) { - /* FIXME: not properly implemented after switch to new gfx code */ - - sm->_system->copy_rect(sm->_videoBuffer, 320, 0, 0, 320, 200); - sm->_system->update_screen(); - sm->waitForTimer(60); - - //sm->delta = sm->_system->waitTick(sm->delta); + _scumm->_system->copy_rect(_scumm->_videoBuffer, 320, 0, 0, 320, 200); + _scumm->_system->update_screen(); } - sm->processKbd(); + do { + _scumm->waitForTimer(10); + } while (_lock); + _lock = true; + + _scumm->processKbd(); - } while (!sm->videoFinished); + } while (!_scumm->videoFinished); deinit(); - sm->_insaneState = 0; - sm->exitCutscene(); - sm->pauseBundleMusic(false); + _scumm->_insaneState = 0; + _scumm->exitCutscene(); + _scumm->pauseBundleMusic(false); } diff --git a/script_v2.cpp b/script_v2.cpp index 2f83b01fe1..aeb91dd26b 100644 --- a/script_v2.cpp +++ b/script_v2.cpp @@ -2704,6 +2704,7 @@ void Scumm::o6_miscOps() Actor *a; IMuse *se = _imuse; //yazoo: not very nice + SmushPlayer * sp; getStackList(args, sizeof(args) / sizeof(args[0])); @@ -2713,9 +2714,9 @@ void Scumm::o6_miscOps() grabCursor(args[1], args[2], args[3], args[4]); break; case 6: - SmushPlayer localSp; - localSp.sm = this; - localSp.startVideo(args[1], getStringAddressVar(VAR_VIDEONAME)); + sp = new SmushPlayer(this); + sp->startVideo(args[1], getStringAddressVar(VAR_VIDEONAME)); + delete sp; break; case 7: warning("o6_miscOps: stub7()"); @@ -22,105 +22,115 @@ #define SP_MAX_FONTS 5 +class SmushPlayer { + +private: + struct PersistentCodecData37 { - byte *deltaBuf; - byte *deltaBufs[2]; - uint32 deltaSize; - uint width, height; - int curtable; - int unk2,unk3; - - uint16 flags; - - int16 *table1; - int table_last_pitch; - byte table_last_flags; + byte *deltaBuf; + byte *deltaBufs[2]; + uint32 deltaSize; + int32 width, height; + int32 curtable; + int32 unk2, unk3; + uint32 flags; + int16 *table1; + int32 table_last_pitch; + byte table_last_flags; }; struct CodecData { - byte *out,*src; - int x,y; - int outwidth,outheight; - int w,h,pitch; - - int flags; + byte * out, * src; + int32 x, y; + int32 outwidth, outheight; + int32 w, h, pitch; + uint32 flags; }; + FILE * _in; + int32 fileSize; + byte * _block; + uint32 _blockTag; + uint32 _blockSize; + + byte * _cur; + byte * _renderBitmap; + uint32 _frameSize; + uint32 _frmeTag, _frmeSize; + bool _frameChanged; -struct SmushPlayer { - FILE *_in; - bool _paletteChanged; - byte * _block; - uint32 _blockTag; - uint32 _blockSize; - byte *_cur; - byte *_renderBitmap; - uint32 _frameSize; - uint32 _frmeTag, _frmeSize; - - byte *_deltaBuf; - int _deltaBufSize; - - byte * _fonts[SP_MAX_FONTS]; - byte * _buffer_tres; - - PersistentCodecData37 pcd37; - - byte _fluPalette[768]; - uint16 _fluPalMul129[768]; - uint16 _fluPalWords[768]; - - byte * loadTres(); - void loadFonts(); - uint32 getCharWidth(uint8 c_font, byte txt); - uint32 getFontHeight(uint8 c_font); - byte * getStringTRES(int32 number); - void drawStringTRES(uint32 x, uint32 y, byte * txt); - void drawCharTRES(uint32 * x, uint32 y, uint32 c_line, uint8 c_font, uint8 color, uint8 txt); - - /* PSAD: Full Throttle audio */ + // Palette + uint16 _fluPalMul129[768]; + uint16 _fluPalWords[768]; + bool _paletteChanged; + byte _fluPalette[768]; + + // TRES + byte * _fonts[SP_MAX_FONTS]; + byte * _bufferTres; + + int32 _mixerNum; + + // PSAD: Full Throttle audio uint32 _saudSize[8], _saudSubSize[8]; - uint16 _psadTrk[8], _strkRate[8]; + uint32 _psadTrk[8], _strkRate[8]; uint32 _saudSubTag[8]; - /* IACT: The Dig audio */ + // IACT: The Dig audio uint32 _imusSize[8], _imusSubSize[8]; uint32 _imusTrk[8], _imusRate[8], _imusChan[8]; uint32 _imusSubTag[8]; byte _imusData[8][3]; uint32 _imusPos[8], _imusCodec[8]; - void openFile(byte* fileName); - void nextBlock(); - - uint32 fileReadBE32(); - uint32 fileReadLE32(); - void go(); - - bool parseTag(); - void parseAHDR(); - void parseFRME(); - - void parseNPAL(); - void parseFOBJ(); - void parsePSAD(); - void parseTRES(); - void parseXPAL(); + // Codec37 + PersistentCodecData37 pcd37; + byte * _deltaBuf; + int32 _deltaBufSize; + + bool _lock; + Scumm * _scumm; + + // TRES + byte * loadTres(); + void loadFonts(); + uint32 getCharWidth(uint8 c_font, byte txt); + uint32 getFontHeight(uint8 c_font); + byte * getStringTRES(int32 number); + void drawStringTRES(uint32 x, uint32 y, byte * txt); + void drawCharTRES(uint32 * x, uint32 y, uint32 c_line, uint8 c_font, uint8 color, uint8 txt); + + void openFile(byte* fileName); + + void setPalette(); + void codec44Depack(byte *dst, byte *src, uint32 len); + void codec1(CodecData * cd); + void codec37Maketable(PersistentCodecData37 * pcd, int32 pitch, byte idx); + bool codec37(int32 game, CodecData * cd, PersistentCodecData37 * pcd); + void codec37Init(PersistentCodecData37 * pcd, int32 width, int32 height); + void codec37Proc5(int32 game, byte *dst, byte *src, int32 next_offs, int32 bw, int32 bh, int32 pitch, int16 *table); + void codec37BompDepack(byte *dst, byte *src, int32 len); + void codec37Proc4(byte *dst, byte *src, int32 next_offs, int32 bw, int32 bh, int32 pitch, int16 *table); + uint32 nextBE32(); + void nextBlock(); + + bool parseTag(); + void parseAHDR(); + void parseFRME(); + void parseNPAL(); + void parseFOBJ(); + void parsePSAD(); + void parseTRES(); + void parseXPAL(); void parseIACT(); - void fileRead(void *mem, int len); - - uint32 nextBE32(); - void init(); - void deinit(); - - void startVideo(short int arg, byte* videofile); - - void setPalette(); - - long fileSize; - - Scumm *sm; - int _frameChanged; + void init(); + void deinit(); + void go(); +public: + SmushPlayer(Scumm * parent); + ~SmushPlayer(); + void startVideo(short int arg, byte* videofile); + void update(); }; @@ -6,6 +6,7 @@ * 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 @@ -43,13 +43,8 @@ static int timer_handler (int t) int Timer::handler(int * t) { uint32 interval, l; - uint32 beginTime, endTime; - - if (_timerRunning == false) - return *t; _osystem->lock_mutex(_mutex); - beginTime = _osystem->get_msecs(); if (_timerRunning) { _lastTime = _thisTime; @@ -67,14 +62,8 @@ int Timer::handler(int * t) { } } - endTime = _osystem->get_msecs(); - interval = endTime - beginTime; - if (interval < 10) interval = 10; - if (interval > 10000) interval = 10000; _osystem->unlock_mutex(_mutex); -// _osystem->set_timer (interval, &timer_handler); - return *t; } @@ -98,7 +87,7 @@ bool Timer::init() { _mutex = _osystem->create_mutex(); _thisTime = _osystem->get_msecs(); - _osystem->set_timer (1000, &timer_handler); + _osystem->set_timer (10, &timer_handler); _timerRunning = true; _initialized = true; @@ -23,7 +23,7 @@ #include "scummsys.h" -#define MAX_TIMERS 5 +#define MAX_TIMERS 3 class OSystem; |