2001-10-09 14:30:12 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2001-11-06 20:00:47 +00:00
|
|
|
* $Header$
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "scumm.h"
|
|
|
|
|
|
|
|
int CharsetRenderer::getStringWidth(int arg, byte *text, int pos) {
|
|
|
|
byte *ptr;
|
|
|
|
int width,offs,w;
|
|
|
|
byte chr;
|
|
|
|
|
|
|
|
width = 1;
|
2001-11-05 19:21:49 +00:00
|
|
|
ptr = _vm->getResourceAddress(rtCharset, _curId) + 29;
|
2002-02-12 21:28:07 +00:00
|
|
|
if(_vm->_features & GF_SMALL_HEADER)
|
|
|
|
ptr-=12;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
while ( (chr = text[pos++]) != 0) {
|
|
|
|
if (chr==0xD)
|
|
|
|
break;
|
|
|
|
if (chr=='@')
|
|
|
|
continue;
|
|
|
|
if (chr==254) chr=255;
|
|
|
|
if (chr==255) {
|
|
|
|
chr=text[pos++];
|
|
|
|
if (chr==3)
|
|
|
|
break;
|
|
|
|
if (chr==8) {
|
|
|
|
if (arg==1)
|
|
|
|
break;
|
|
|
|
while (text[pos]==' ')
|
|
|
|
text[pos++] = '@';
|
|
|
|
continue;
|
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
if (chr==10 || chr==21 || chr==12 || chr==13) {
|
|
|
|
pos += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (chr==9 || chr==1 || chr==2)
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (chr==14) {
|
|
|
|
int set = text[pos] | (text[pos+1]<<8);
|
|
|
|
pos+=2;
|
2001-11-05 19:21:49 +00:00
|
|
|
ptr = _vm->getResourceAddress(rtCharset, set) + 29;
|
2002-02-12 21:28:07 +00:00
|
|
|
if(_vm->_features & GF_SMALL_HEADER)
|
|
|
|
ptr-=12;
|
2001-10-16 10:01:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
offs = READ_LE_UINT32(ptr + chr*4 + 4);
|
|
|
|
if (offs) {
|
|
|
|
if (ptr[offs+2]>=0x80) {
|
|
|
|
w = ptr[offs+2] - 0x100;
|
|
|
|
} else {
|
|
|
|
w = ptr[offs+2];
|
|
|
|
}
|
|
|
|
width += ptr[offs] + w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharsetRenderer::addLinebreaks(int a, byte *str, int pos, int maxwidth) {
|
|
|
|
int lastspace = -1;
|
|
|
|
int curw = 1;
|
|
|
|
int offs,w;
|
|
|
|
byte *ptr;
|
|
|
|
byte chr;
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
ptr = _vm->getResourceAddress(rtCharset, _curId) + 29;
|
2002-02-12 21:28:07 +00:00
|
|
|
if(_vm->_features & GF_SMALL_HEADER)
|
|
|
|
ptr-=12;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
while ( (chr=str[pos++]) != 0) {
|
|
|
|
if (chr=='@')
|
|
|
|
continue;
|
|
|
|
if (chr==254) chr=255;
|
|
|
|
if (chr==255) {
|
|
|
|
chr = str[pos++];
|
|
|
|
if (chr==3)
|
|
|
|
break;
|
|
|
|
if (chr==8) {
|
|
|
|
if (a==1) {
|
|
|
|
curw = 1;
|
|
|
|
} else {
|
|
|
|
while (str[pos]==' ')
|
|
|
|
str[pos++] = '@';
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
if (chr==10 || chr==21 || chr==12 || chr==13) {
|
|
|
|
pos += 2;
|
|
|
|
continue;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
if (chr==1) {
|
|
|
|
curw = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (chr==2)
|
|
|
|
break;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (chr==14) {
|
|
|
|
int set = str[pos] | (str[pos+1]<<8);
|
|
|
|
pos+=2;
|
2001-11-05 19:21:49 +00:00
|
|
|
ptr = _vm->getResourceAddress(rtCharset, set) + 29;
|
2002-02-12 21:28:07 +00:00
|
|
|
if(_vm->_features & GF_SMALL_HEADER)
|
|
|
|
ptr-=12;
|
2001-10-16 10:01:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (chr==' ')
|
|
|
|
lastspace = pos - 1;
|
|
|
|
|
|
|
|
offs = READ_LE_UINT32(ptr + chr*4 + 4);
|
|
|
|
if (offs) {
|
|
|
|
if (ptr[offs+2]>=0x80) {
|
|
|
|
w = ptr[offs+2] - 0x100;
|
|
|
|
} else {
|
|
|
|
w = ptr[offs+2];
|
|
|
|
}
|
|
|
|
curw += w + ptr[offs];
|
|
|
|
}
|
|
|
|
if (lastspace==-1)
|
|
|
|
continue;
|
|
|
|
if (curw > maxwidth) {
|
|
|
|
str[lastspace] = 0xD;
|
|
|
|
curw = 1;
|
|
|
|
pos = lastspace + 1;
|
|
|
|
lastspace = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scumm::unkMessage1() {
|
2001-11-05 19:21:49 +00:00
|
|
|
byte buffer[100];
|
|
|
|
_msgPtrToAdd = buffer;
|
2001-10-09 14:30:12 +00:00
|
|
|
_messagePtr = addMessageToStack(_messagePtr);
|
2001-10-26 17:34:50 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
if (buffer[0] == 0xFF && buffer[1]==10) {
|
|
|
|
uint32 a,b;
|
|
|
|
|
|
|
|
a = buffer[2] | (buffer[3]<<8) | (buffer[6]<<16) | (buffer[7]<<24);
|
|
|
|
b = buffer[10] | (buffer[11]<<8) | (buffer[14]<<16) | (buffer[15]<<24);
|
|
|
|
talkSound(a,b,1);
|
|
|
|
}
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
// warning("unkMessage1(\"%s\")", buf);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scumm::unkMessage2() {
|
|
|
|
byte buf[100], *tmp;
|
|
|
|
|
|
|
|
_msgPtrToAdd = buf;
|
|
|
|
tmp = _messagePtr = addMessageToStack(_messagePtr);
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
if (string[3].color==0)
|
|
|
|
string[3].color = 4;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
warning("unkMessage2(\"%s\")", buf);
|
2001-10-09 14:30:12 +00:00
|
|
|
_messagePtr = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Scumm::CHARSET_1() {
|
|
|
|
int s, i, t, c;
|
|
|
|
int frme;
|
|
|
|
Actor *a;
|
2001-11-05 19:21:49 +00:00
|
|
|
byte *buffer;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-12-27 17:51:58 +00:00
|
|
|
#if !defined(FULL_THROTTLE)
|
|
|
|
if (!_haveMsg || (camera._dest.x>>3) != (camera._cur.x>>3) ||
|
|
|
|
camera._cur.x != camera._last.x
|
2001-10-09 14:30:12 +00:00
|
|
|
) return;
|
2001-12-27 17:51:58 +00:00
|
|
|
#else
|
|
|
|
if (!_haveMsg)
|
|
|
|
return;
|
|
|
|
#endif
|
2001-10-09 14:30:12 +00:00
|
|
|
a = NULL;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_vars[VAR_TALK_ACTOR] != 0xFF)
|
|
|
|
a = derefActorSafe(_vars[VAR_TALK_ACTOR], "CHARSET_1");
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
if (a && string[0].overhead!=0) {
|
2001-11-26 19:57:57 +00:00
|
|
|
if (!(_features & GF_AFTER_V6)) {
|
2001-12-27 17:51:58 +00:00
|
|
|
string[0].xpos = a->x - camera._cur.x + 160;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
if (_vars[VAR_V5_TALK_STRING_Y] < 0) {
|
|
|
|
s = (a->scaley * (int)_vars[VAR_V5_TALK_STRING_Y]) / 0xFF;
|
|
|
|
string[0].ypos = ((_vars[VAR_V5_TALK_STRING_Y]-s)>>1) + s - a->elevation + a->y;
|
2001-10-23 19:51:50 +00:00
|
|
|
} else {
|
2001-10-26 17:34:50 +00:00
|
|
|
string[0].ypos = _vars[VAR_V5_TALK_STRING_Y];
|
2001-10-23 19:51:50 +00:00
|
|
|
}
|
|
|
|
if (string[0].ypos < 1)
|
|
|
|
string[0].ypos = 1;
|
|
|
|
|
|
|
|
if (string[0].xpos < 80)
|
|
|
|
string[0].xpos = 80;
|
|
|
|
if (string[0].xpos > 240)
|
|
|
|
string[0].xpos = 240;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2001-10-23 19:51:50 +00:00
|
|
|
s = a->scaley * a->new_1 / 0xFF;
|
|
|
|
string[0].ypos = ((a->new_1 - s)>>1) + s - a->elevation + a->y;
|
|
|
|
if (string[0].ypos<1)
|
|
|
|
string[0].ypos = 1;
|
|
|
|
|
|
|
|
s = a->scalex * a->new_2 / 0xFF;
|
2001-12-27 17:51:58 +00:00
|
|
|
string[0].xpos = ((a->new_2 - s)>>1) + s + a->x - camera._cur.x + 160;
|
2001-10-23 19:51:50 +00:00
|
|
|
if (string[0].xpos < 80)
|
|
|
|
string[0].xpos = 80;
|
|
|
|
if (string[0].xpos > 240)
|
|
|
|
string[0].xpos = 240;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-23 19:51:50 +00:00
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
charset._top = string[0].ypos;
|
|
|
|
charset._left = string[0].xpos;
|
|
|
|
charset._left2 = string[0].xpos;
|
|
|
|
charset._curId = string[0].charset;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (a && a->charset)
|
|
|
|
charset._curId = a->charset;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
charset._center = string[0].center;
|
|
|
|
charset._right = string[0].right;
|
2001-10-09 14:30:12 +00:00
|
|
|
charset._color = _charsetColor;
|
2001-10-26 17:34:50 +00:00
|
|
|
_bkColor = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
for (i=0; i<4; i++)
|
2002-02-12 21:28:07 +00:00
|
|
|
if(_features & GF_SMALL_HEADER)
|
|
|
|
charset._colorMap[i] = _charsetData[charset._curId][i-12];
|
|
|
|
else
|
|
|
|
charset._colorMap[i] = _charsetData[charset._curId][i];
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_keepText) {
|
2001-11-07 18:10:52 +00:00
|
|
|
charset._strLeft = gdi._mask_left;
|
|
|
|
charset._strRight = gdi._mask_right;
|
|
|
|
charset._strTop = gdi._mask_top;
|
|
|
|
charset._strBottom = gdi._mask_bottom;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_haveMsg || _talkDelay)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_haveMsg!=0xFF) {
|
2001-11-05 19:21:49 +00:00
|
|
|
if (_sfxMode==0)
|
|
|
|
stopTalk();
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
if (a && !string[0].no_talk_anim) {
|
2001-11-26 19:57:57 +00:00
|
|
|
startAnimActor(a, a->talkFrame1);
|
2001-11-05 19:21:49 +00:00
|
|
|
_useTalkAnims = true;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_talkDelay = _defaultTalkDelay;
|
|
|
|
|
|
|
|
if (!_keepText) {
|
|
|
|
restoreCharsetBg();
|
2001-11-07 18:10:52 +00:00
|
|
|
charset._xpos2 = string[0].xpos;
|
|
|
|
charset._ypos2 = string[0].ypos;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
t = charset._right - string[0].xpos - 1;
|
2001-10-09 14:30:12 +00:00
|
|
|
if (charset._center) {
|
2001-11-07 18:10:52 +00:00
|
|
|
if (t > charset._xpos2)
|
|
|
|
t = charset._xpos2;
|
2001-10-09 14:30:12 +00:00
|
|
|
t <<= 1;
|
|
|
|
}
|
2001-11-05 19:21:49 +00:00
|
|
|
|
|
|
|
buffer = charset._buffer + charset._bufPos;
|
|
|
|
|
|
|
|
charset.addLinebreaks(0, buffer,0, t);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
_lastXstart = virtscr[0].xstart;
|
|
|
|
if (charset._center) {
|
2001-11-07 18:10:52 +00:00
|
|
|
charset._xpos2 -= charset.getStringWidth(0, buffer,0) >> 1;
|
2001-11-14 18:40:39 +00:00
|
|
|
if (charset._xpos2<0)
|
|
|
|
charset._xpos2 = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
charset._disableOffsX = charset._unk12 = !_keepText;
|
|
|
|
|
|
|
|
do {
|
2001-11-05 19:21:49 +00:00
|
|
|
c = *buffer++;
|
2001-10-09 14:30:12 +00:00
|
|
|
if (c==0) {
|
|
|
|
_haveMsg = 1;
|
|
|
|
_keepText = false;
|
|
|
|
break;
|
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
if (c == 13) {
|
|
|
|
newLine:;
|
2001-11-07 18:10:52 +00:00
|
|
|
charset._xpos2 = string[0].xpos;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (charset._center) {
|
2001-11-07 18:10:52 +00:00
|
|
|
charset._xpos2 -= charset.getStringWidth(0, buffer, 0)>>1;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-11-07 18:10:52 +00:00
|
|
|
charset._ypos2 += getResourceAddress(rtCharset,charset._curId)[30];
|
2001-10-16 10:01:48 +00:00
|
|
|
charset._disableOffsX = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
if (c==0xFE) c=0xFF;
|
|
|
|
|
|
|
|
if (c!=0xFF) {
|
2001-11-07 18:10:52 +00:00
|
|
|
charset._left = charset._xpos2;
|
|
|
|
charset._top = charset._ypos2;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
if (!(_features&GF_AFTER_V6)) {
|
2002-02-12 21:28:07 +00:00
|
|
|
// if (!_vars[VAR_V5_CHARFLAG]) { /* FIXME */
|
2001-10-26 17:34:50 +00:00
|
|
|
charset.printChar(c);
|
2002-02-12 21:28:07 +00:00
|
|
|
// }
|
2001-10-26 17:34:50 +00:00
|
|
|
} else {
|
2001-10-16 10:01:48 +00:00
|
|
|
charset.printChar(c);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-10-26 17:34:50 +00:00
|
|
|
|
2001-11-07 18:10:52 +00:00
|
|
|
charset._xpos2 = charset._left;
|
|
|
|
charset._ypos2 = charset._top;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
|
|
|
_talkDelay += _vars[VAR_CHARINC];
|
|
|
|
continue;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
c = *buffer++;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (c==3) {
|
|
|
|
_haveMsg = 0xFF;
|
|
|
|
_keepText = false;
|
|
|
|
break;
|
|
|
|
} else if (c==1) {
|
|
|
|
goto newLine;
|
|
|
|
} else if (c==2) {
|
|
|
|
_haveMsg = 0;
|
|
|
|
_keepText = true;
|
|
|
|
break;
|
|
|
|
} else if (c==9) {
|
2001-11-05 19:21:49 +00:00
|
|
|
frme = *buffer++;
|
|
|
|
frme |= *buffer++<<8;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (a)
|
2001-11-26 19:57:57 +00:00
|
|
|
startAnimActor(a, frme);
|
2001-10-16 10:01:48 +00:00
|
|
|
} else if (c==10) {
|
2001-11-05 19:21:49 +00:00
|
|
|
uint32 a,b;
|
|
|
|
|
|
|
|
a = buffer[0] | (buffer[1]<<8) | (buffer[4]<<16) | (buffer[5]<<24);
|
|
|
|
b = buffer[8] | (buffer[9]<<8) | (buffer[12]<<16) | (buffer[13]<<24);
|
|
|
|
talkSound(a,b,2);
|
|
|
|
buffer += 14;
|
2001-10-16 10:01:48 +00:00
|
|
|
} else if (c==14) {
|
2001-11-05 19:21:49 +00:00
|
|
|
int oldy = getResourceAddress(rtCharset,charset._curId)[30];
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
charset._curId = *buffer++;
|
|
|
|
buffer += 2;
|
2001-10-16 10:01:48 +00:00
|
|
|
for (i=0; i<4; i++)
|
2002-02-12 21:28:07 +00:00
|
|
|
if(_features & GF_SMALL_HEADER)
|
|
|
|
charset._colorMap[i] = _charsetData[charset._curId][i-12];
|
|
|
|
else
|
|
|
|
charset._colorMap[i] = _charsetData[charset._curId][i];
|
2001-11-07 18:10:52 +00:00
|
|
|
charset._ypos2 -= getResourceAddress(rtCharset,charset._curId)[30] - oldy;
|
2001-10-16 10:01:48 +00:00
|
|
|
} else if (c==12) {
|
|
|
|
int color;
|
2001-11-05 19:21:49 +00:00
|
|
|
color = *buffer++;
|
|
|
|
color |= *buffer++<<8;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (color==0xFF)
|
|
|
|
charset._color = _charsetColor;
|
|
|
|
else
|
|
|
|
charset._color = color;
|
|
|
|
} else if (c==13) {
|
2001-11-05 19:21:49 +00:00
|
|
|
buffer += 2;
|
2001-10-16 10:01:48 +00:00
|
|
|
} else {
|
|
|
|
warning("CHARSET_1: invalid code %d", c);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
charset._bufPos = buffer - charset._buffer;
|
|
|
|
|
2001-11-07 18:10:52 +00:00
|
|
|
gdi._mask_left = charset._strLeft;
|
|
|
|
gdi._mask_right = charset._strRight;
|
|
|
|
gdi._mask_top = charset._strTop;
|
|
|
|
gdi._mask_bottom = charset._strBottom;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scumm::drawString(int a) {
|
|
|
|
byte buf[256];
|
|
|
|
byte *charsetptr,*space;
|
|
|
|
int i;
|
|
|
|
byte byte1, chr;
|
2001-10-26 17:34:50 +00:00
|
|
|
uint color;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
_msgPtrToAdd = buf;
|
|
|
|
_messagePtr = addMessageToStack(_messagePtr);
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
charset._left2 = charset._left = string[a].xpos;
|
|
|
|
charset._top = string[a].ypos;
|
|
|
|
charset._curId = string[a].charset;
|
|
|
|
charset._center = string[a].center;
|
|
|
|
charset._right = string[a].right;
|
|
|
|
charset._color = string[a].color;
|
2001-10-26 17:34:50 +00:00
|
|
|
_bkColor = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
charset._unk12 = 1;
|
|
|
|
charset._disableOffsX = 1;
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
charsetptr = getResourceAddress(rtCharset, charset._curId);
|
2001-10-09 14:30:12 +00:00
|
|
|
assert(charsetptr);
|
|
|
|
charsetptr += 29;
|
2002-02-12 21:28:07 +00:00
|
|
|
if(_features & GF_SMALL_HEADER)
|
|
|
|
charsetptr-=12;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
for(i=0; i<4; i++)
|
2002-02-12 21:28:07 +00:00
|
|
|
if(_features & GF_SMALL_HEADER)
|
|
|
|
charset._colorMap[i] = _charsetData[charset._curId][i-12];
|
|
|
|
else
|
|
|
|
charset._colorMap[i] = _charsetData[charset._curId][i];
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
byte1 = charsetptr[1];
|
|
|
|
|
|
|
|
_msgPtrToAdd = buf;
|
|
|
|
|
|
|
|
/* trim from the right */
|
|
|
|
space = NULL;
|
|
|
|
while (*_msgPtrToAdd){
|
|
|
|
if (*_msgPtrToAdd==' ') {
|
|
|
|
if (!space) space = _msgPtrToAdd;
|
|
|
|
} else {
|
|
|
|
space = NULL;
|
|
|
|
}
|
|
|
|
_msgPtrToAdd++;
|
|
|
|
}
|
|
|
|
if(space) *space='\0';
|
|
|
|
|
|
|
|
if (charset._center) {
|
|
|
|
charset._left -= charset.getStringWidth(a, buf, 0) >> 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
charset._ignoreCharsetMask = 1;
|
|
|
|
|
|
|
|
if (!buf[0]) {
|
|
|
|
buf[0] = ' ';
|
|
|
|
buf[1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; (chr=buf[i++]) != 0; ) {
|
|
|
|
if (chr==254) chr=255;
|
|
|
|
if (chr==255) {
|
|
|
|
chr = buf[i++];
|
|
|
|
switch(chr) {
|
|
|
|
case 9:
|
2001-10-26 17:34:50 +00:00
|
|
|
case 10: case 13: case 14:
|
2001-10-09 14:30:12 +00:00
|
|
|
i += 2;
|
|
|
|
break;
|
|
|
|
case 1: case 8:
|
|
|
|
if (charset._center) {
|
|
|
|
charset._left = charset._left2 - charset.getStringWidth(a, buf, i);
|
|
|
|
} else {
|
|
|
|
charset._left = charset._left2;
|
|
|
|
}
|
2001-10-26 17:34:50 +00:00
|
|
|
charset._top += byte1;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
color = buf[i] + (buf[i+1]<<8);
|
|
|
|
i+=2;
|
|
|
|
if (color==0xFF)
|
|
|
|
charset._color = string[a].color;
|
|
|
|
else
|
|
|
|
charset._color = color;
|
|
|
|
break;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
2001-11-26 19:57:57 +00:00
|
|
|
if (a==1 && (_features&GF_AFTER_V6))
|
2001-10-26 17:34:50 +00:00
|
|
|
charset._blitAlso = true;
|
2001-10-09 14:30:12 +00:00
|
|
|
charset.printChar(chr);
|
2001-10-26 17:34:50 +00:00
|
|
|
charset._blitAlso = false;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
charset._ignoreCharsetMask = 0;
|
2001-11-07 18:10:52 +00:00
|
|
|
|
|
|
|
if (a==0) {
|
|
|
|
charset._xpos2 = charset._left;
|
|
|
|
charset._ypos2 = charset._top;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
byte *Scumm::addMessageToStack(byte *msg) {
|
|
|
|
int num, numorg;
|
|
|
|
byte *ptr, chr;
|
|
|
|
|
|
|
|
numorg = num = _numInMsgStack;
|
2001-11-05 19:21:49 +00:00
|
|
|
ptr = getResourceAddress(rtTemp, 6);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (ptr==NULL)
|
|
|
|
error("Message stack not allocated");
|
|
|
|
|
2002-02-12 21:28:07 +00:00
|
|
|
if (msg==NULL)
|
|
|
|
error("Bad message in addMessageToStack");
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
while ( (chr=*msg++) != 0) {
|
|
|
|
if (num > 500)
|
|
|
|
error("Message stack overflow");
|
|
|
|
|
|
|
|
ptr[num++] = chr;
|
|
|
|
|
|
|
|
if (chr==255) {
|
|
|
|
ptr[num++] = chr = *msg++;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
if (chr!=1 && chr!=2 && chr!=3 && chr!=8) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ptr[num++] = chr = *msg++;
|
|
|
|
ptr[num++] = chr = *msg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr[num++] = 0;
|
|
|
|
|
|
|
|
_numInMsgStack = num;
|
|
|
|
num = numorg;
|
|
|
|
|
|
|
|
while (1) {
|
2001-11-05 19:21:49 +00:00
|
|
|
ptr = getResourceAddress(rtTemp, 6);
|
2001-10-09 14:30:12 +00:00
|
|
|
chr = ptr[num++];
|
|
|
|
if (chr == 0)
|
|
|
|
break;
|
|
|
|
if (chr == 0xFF) {
|
|
|
|
chr = ptr[num++];
|
|
|
|
switch(chr) {
|
|
|
|
case 4:
|
2001-10-16 10:01:48 +00:00
|
|
|
unkAddMsgToStack2(READ_LE_UINT16(ptr + num));
|
2001-10-09 14:30:12 +00:00
|
|
|
num+=2;
|
|
|
|
break;
|
|
|
|
case 5:
|
2001-10-16 10:01:48 +00:00
|
|
|
unkAddMsgToStack3(READ_LE_UINT16(ptr + num));
|
2001-10-09 14:30:12 +00:00
|
|
|
num+=2;
|
|
|
|
break;
|
|
|
|
case 6:
|
2001-10-16 10:01:48 +00:00
|
|
|
unkAddMsgToStack4(READ_LE_UINT16(ptr + num));
|
2001-10-09 14:30:12 +00:00
|
|
|
num+=2;
|
|
|
|
break;
|
|
|
|
case 7:
|
2001-10-16 10:01:48 +00:00
|
|
|
unkAddMsgToStack5(READ_LE_UINT16(ptr + num));
|
2001-10-09 14:30:12 +00:00
|
|
|
num+=2;
|
|
|
|
break;
|
2001-10-16 10:01:48 +00:00
|
|
|
case 9:
|
2001-10-23 19:51:50 +00:00
|
|
|
//#if defined(DOTT)
|
2001-10-16 10:01:48 +00:00
|
|
|
case 10: case 12: case 13: case 14:
|
2001-10-23 19:51:50 +00:00
|
|
|
//#endif
|
2001-10-09 14:30:12 +00:00
|
|
|
*_msgPtrToAdd++ = 0xFF;
|
|
|
|
*_msgPtrToAdd++ = chr;
|
2001-10-16 10:01:48 +00:00
|
|
|
*_msgPtrToAdd++ = ptr[num++];
|
|
|
|
*_msgPtrToAdd++ = ptr[num++];
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*_msgPtrToAdd++ = 0xFF;
|
|
|
|
*_msgPtrToAdd++ = chr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (chr!='@') {
|
|
|
|
*_msgPtrToAdd++ = chr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*_msgPtrToAdd = 0;
|
|
|
|
_numInMsgStack = numorg;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scumm::unkAddMsgToStack2(int var) {
|
|
|
|
int num,max;
|
|
|
|
byte flag;
|
|
|
|
|
|
|
|
num = readVar(var);
|
|
|
|
if (num < 0) {
|
|
|
|
*_msgPtrToAdd++ = '-';
|
|
|
|
num = -num;
|
|
|
|
}
|
|
|
|
|
|
|
|
flag = 0;
|
|
|
|
max = 10000;
|
|
|
|
do {
|
|
|
|
if (num>=max || flag) {
|
|
|
|
*_msgPtrToAdd++ = num/max + '0';
|
|
|
|
num -= (num/max)*max;
|
|
|
|
flag=1;
|
|
|
|
}
|
|
|
|
max/=10;
|
|
|
|
if (max==1) flag=1;
|
|
|
|
} while (max);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scumm::unkAddMsgToStack3(int var) {
|
|
|
|
int num,i;
|
|
|
|
|
|
|
|
num = readVar(var);
|
|
|
|
if (num) {
|
|
|
|
for (i=1; i<_maxVerbs; i++) {
|
2001-10-16 10:01:48 +00:00
|
|
|
if (num==_verbs[i].verbid && !_verbs[i].type && !_verbs[i].saveid) {
|
2001-11-05 19:21:49 +00:00
|
|
|
addMessageToStack(getResourceAddress(rtVerb, i));
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addMessageToStack((byte*)"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scumm::unkAddMsgToStack4(int var) {
|
|
|
|
int num;
|
|
|
|
|
|
|
|
num = readVar(var);
|
|
|
|
if (num) {
|
|
|
|
addMessageToStack(getObjOrActorName(num));
|
|
|
|
} else {
|
|
|
|
addMessageToStack((byte*)"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scumm::unkAddMsgToStack5(int var) {
|
|
|
|
byte *ptr;
|
2001-10-24 20:12:52 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
if (_features&GF_AFTER_V6)
|
2001-10-24 20:12:52 +00:00
|
|
|
var = readVar(var);
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (var) {
|
2001-10-24 20:12:52 +00:00
|
|
|
ptr = getStringAddress(var);
|
2001-10-09 14:30:12 +00:00
|
|
|
if (ptr) {
|
|
|
|
addMessageToStack(ptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addMessageToStack((byte*)"");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scumm::initCharset(int charsetno) {
|
|
|
|
int i;
|
|
|
|
|
2002-02-12 21:28:07 +00:00
|
|
|
if (_features & GF_SMALL_HEADER)
|
|
|
|
loadCharset(charsetno);
|
|
|
|
else
|
|
|
|
if (!getResourceAddress(rtCharset, charsetno))
|
|
|
|
loadCharset(charsetno);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
string[0].t_charset = charsetno;
|
|
|
|
string[1].t_charset = charsetno;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
for (i=0; i<0x10; i++)
|
2002-02-12 21:28:07 +00:00
|
|
|
if(_features & GF_SMALL_HEADER)
|
|
|
|
charset._colorMap[i] = _charsetData[charset._curId][i-12];
|
|
|
|
else
|
|
|
|
charset._colorMap[i] = _charsetData[charset._curId][i];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CharsetRenderer::printChar(int chr) {
|
|
|
|
int d,right;
|
|
|
|
VirtScreen *vs;
|
|
|
|
|
|
|
|
_vm->checkRange(_vm->_maxCharsets-1, 1, _curId, "Printing with bad charset %d");
|
2001-10-26 17:34:50 +00:00
|
|
|
if ((vs=_vm->findVirtScreen(_top)) == NULL)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (chr=='@')
|
|
|
|
return;
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
_ptr = _vm->getResourceAddress(rtCharset, _curId) + 29;
|
2002-02-12 22:46:30 +00:00
|
|
|
if (_vm->_features & GF_SMALL_HEADER)
|
|
|
|
_ptr -=12;
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
_bpp = _unk2 = *_ptr;
|
|
|
|
_invNumBits = 8 - _bpp;
|
|
|
|
_bitMask = 0xFF << _invNumBits;
|
|
|
|
_colorMap[1] = _color;
|
|
|
|
|
|
|
|
_charOffs = READ_LE_UINT32(_ptr + chr*4 + 4);
|
|
|
|
|
|
|
|
if (!_charOffs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(_charOffs < 0x10000);
|
|
|
|
|
|
|
|
_charPtr = _ptr + _charOffs;
|
|
|
|
|
|
|
|
_width = _charPtr[0];
|
|
|
|
_height = _charPtr[1];
|
|
|
|
if (_unk12) {
|
|
|
|
_strLeft = 0;
|
|
|
|
_strTop = 0;
|
|
|
|
_strRight = 0;
|
|
|
|
_strBottom = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_disableOffsX) {
|
|
|
|
_offsX = 0;
|
|
|
|
} else {
|
|
|
|
d = _charPtr[2];
|
|
|
|
if (d>=0x80)
|
|
|
|
d -= 0x100;
|
|
|
|
_offsX = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = _charPtr[3];
|
|
|
|
if(d>=0x80)
|
|
|
|
d -= 0x100;
|
|
|
|
_offsY = d;
|
|
|
|
|
|
|
|
_top += _offsY;
|
|
|
|
_left += _offsX;
|
|
|
|
|
|
|
|
right = _left + _width;
|
|
|
|
|
|
|
|
if (right>_right+1 || _left < 0) {
|
|
|
|
_left = right;
|
|
|
|
_top -= _offsY;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_disableOffsX = 0;
|
|
|
|
|
|
|
|
if (_unk12) {
|
|
|
|
_strLeft = _left;
|
|
|
|
_strTop = _top;
|
|
|
|
_strRight = _left;
|
|
|
|
_strBottom = _top;
|
|
|
|
_unk12 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_left < _strLeft)
|
|
|
|
_strLeft = _left;
|
|
|
|
|
|
|
|
if (_top < _strTop)
|
|
|
|
_strTop = _top;
|
|
|
|
|
|
|
|
_drawTop = _top - vs->topline;
|
2001-10-26 17:34:50 +00:00
|
|
|
if (_drawTop<0) _drawTop = 0;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
_bottom = _drawTop + _height + _offsY;
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
_vm->updateDirtyRect(vs->number, _left, right, _drawTop, _bottom, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
#if defined(OLD)
|
|
|
|
if (vs->number==0)
|
2001-10-09 14:30:12 +00:00
|
|
|
_hasMask = true;
|
2001-10-26 17:34:50 +00:00
|
|
|
#else
|
|
|
|
if (vs->number!=0)
|
|
|
|
_blitAlso = false;
|
|
|
|
if (vs->number==0 && _blitAlso==0)
|
|
|
|
_hasMask = true;
|
|
|
|
#endif
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-12-04 10:44:33 +00:00
|
|
|
_dest_ptr = _backbuff_ptr = _vm->getResourceAddress(rtBuffer, vs->number+1)
|
2001-10-09 14:30:12 +00:00
|
|
|
+ vs->xstart + _drawTop * 320 + _left;
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
#if !defined(OLD)
|
|
|
|
if (_blitAlso) {
|
|
|
|
#else
|
|
|
|
if (1) {
|
|
|
|
#endif
|
2001-12-04 10:44:33 +00:00
|
|
|
_dest_ptr = _bgbak_ptr = _vm->getResourceAddress(rtBuffer, vs->number+5)
|
2001-10-26 17:34:50 +00:00
|
|
|
+ vs->xstart + _drawTop * 320 + _left;
|
|
|
|
}
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
_mask_ptr = _vm->getResourceAddress(rtBuffer, 9)
|
2001-10-09 14:30:12 +00:00
|
|
|
+ _drawTop * 40 + _left/8
|
|
|
|
+ _vm->_screenStartStrip;
|
|
|
|
|
|
|
|
_revBitMask = revBitMask[_left&7];
|
|
|
|
|
|
|
|
_virtScreenHeight = vs->height;
|
|
|
|
_charPtr += 4;
|
|
|
|
|
|
|
|
drawBits();
|
2001-10-26 17:34:50 +00:00
|
|
|
|
|
|
|
#if !defined(OLD)
|
|
|
|
if (_blitAlso)
|
|
|
|
blit(_backbuff_ptr, _bgbak_ptr, _width, _height);
|
|
|
|
#endif
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
_left += _width;
|
|
|
|
if (_left > _strRight)
|
|
|
|
_strRight = _left;
|
|
|
|
|
|
|
|
if (_top + _height > _strBottom)
|
|
|
|
_strBottom = _top + _height;
|
|
|
|
|
|
|
|
_top -= _offsY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharsetRenderer::drawBits() {
|
|
|
|
bool usemask;
|
|
|
|
byte *dst, *mask,maskmask;
|
|
|
|
int y,x;
|
|
|
|
int maskpos;
|
|
|
|
int color;
|
|
|
|
byte numbits,bits;
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
usemask = (_vm->_curVirtScreen->number==0 && _ignoreCharsetMask==0);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
bits = *_charPtr++;
|
|
|
|
numbits = 8;
|
|
|
|
|
2001-12-04 10:44:33 +00:00
|
|
|
dst = _dest_ptr;
|
2001-10-09 14:30:12 +00:00
|
|
|
mask = _mask_ptr;
|
|
|
|
y = 0;
|
|
|
|
|
|
|
|
for(y=0; y<_height && y+_drawTop < _virtScreenHeight;) {
|
|
|
|
maskmask = _revBitMask;
|
|
|
|
maskpos = 0;
|
|
|
|
|
|
|
|
for (x=0; x<_width; x++) {
|
|
|
|
color = (bits&_bitMask)>>_invNumBits;
|
|
|
|
if (color) {
|
|
|
|
if (usemask) {
|
|
|
|
mask[maskpos] |= maskmask;
|
|
|
|
}
|
|
|
|
*dst = _colorMap[color];
|
|
|
|
}
|
|
|
|
dst++;
|
|
|
|
bits <<= _bpp;
|
|
|
|
if ((numbits -= _bpp)==0) {
|
|
|
|
bits = *_charPtr++;
|
|
|
|
numbits = 8;
|
|
|
|
}
|
|
|
|
if ((maskmask>>=1)==0) {
|
|
|
|
maskmask = 0x80;
|
|
|
|
maskpos++;
|
|
|
|
}
|
|
|
|
}
|
2001-12-04 10:44:33 +00:00
|
|
|
dst = (_dest_ptr += 320);
|
2001-10-09 14:30:12 +00:00
|
|
|
mask += 40;
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
}
|