Skip to content

Commit

Permalink
PRINCE: O_SETSTRING(), O_INITDIALOG() update
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jul 3, 2014
1 parent a9a8eb0 commit 54d3dc9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 66 deletions.
1 change: 1 addition & 0 deletions engines/prince/prince.h
Expand Up @@ -400,6 +400,7 @@ class PrinceEngine : public Engine {

uint32 _dialogDatSize;
byte *_dialogDat;
byte *_dialogData; // on, off flags for lines of dialog text

bool _dialogFlag;
int _dialogWidth;
Expand Down
119 changes: 53 additions & 66 deletions engines/prince/script.cpp
Expand Up @@ -875,7 +875,8 @@ void Interpreter::O_SETSTRING() {
debugInterpreter("GetVaria %s", _string);
}
else if (offset < 2000) {
//dialogDat -> dialogData
_vm->_dialogData = &_vm->_dialogDat[offset * 4 - 4];

uint32 of = READ_LE_UINT32(_vm->_talkTxt + offset * 4);
const char *txt = (const char *)&_vm->_talkTxt[of];
_string = &_vm->_talkTxt[of];
Expand Down Expand Up @@ -1363,19 +1364,18 @@ int Interpreter::checkSeq(byte *string) {
void Interpreter::O_INITDIALOG() {
debugInterpreter("O_INITDIALOG");
if (_string[0] == 255) {
byte *stringESI = _string;
byte *stringEBP = _string;
stringESI++;
int32 adressOfFirstSequence = *stringESI; // eax
stringESI += 2;
_string = stringEBP + adressOfFirstSequence;
byte *stringCurrOff = _string;
byte *string = _string;
stringCurrOff++;
int32 adressOfFirstSequence = (int)READ_UINT16(stringCurrOff);
stringCurrOff += 2;
_string = string + adressOfFirstSequence;

for (uint i = 0; i < _vm->_dialogBoxList.size(); i++) {
_vm->_dialogBoxList[i].clear();
}
_vm->_dialogBoxList.clear();

// to global
byte *dialogBoxAddr[32]; // adresses of dialog windows
byte *dialogOptAddr[32]; // adresses of dialog options
int dialogOptLines[4 * 32]; // numbers of initial dialog lines
Expand All @@ -1389,83 +1389,70 @@ void Interpreter::O_INITDIALOG() {
dialogOptLines[i] = 0;
}

//loop_1
int16 c;
byte *eax;
int edi = 0;
while (1) {
c = (int)READ_UINT16(stringESI);
stringESI += 2;
if (c == -1) {
break;
}
if (c != 0) {
eax = stringEBP + c;
int16 off;
byte *line;

int dialogBox = 0;
while ((off = (int)READ_UINT16(stringCurrOff)) != -1) {
stringCurrOff += 2;
if (off) {
line = string + off;
}
dialogBoxAddr[edi] = eax;
edi++;
dialogBoxAddr[dialogBox] = line;
dialogBox++;
}
//box_done:
edi = 0;
while (1) {
c = (int)READ_UINT16(stringESI);
stringESI += 2;
if (c == -1) {
break;
}
if (c != 0) {
eax = stringEBP + c;
stringCurrOff += 2;

int dialogOpt = 0;
while ((off = (int)READ_UINT16(stringCurrOff)) != -1) {
stringCurrOff += 2;
if (off) {
line = string + off;
}
dialogOptAddr[edi] = eax;
edi++;
dialogOptAddr[dialogOpt] = line;
dialogOpt++;
}

int i = 0;
dialogBox = 0;
byte c;
int sentenceNumber;
DialogLine tempDialogLine;
Common::Array<DialogLine> tempDialogBox;
while (dialogBoxAddr[i] != 0) {
tempDialogBox.clear();
byte *boxAddr = dialogBoxAddr[i];

byte *stream = boxAddr;
int streamSize = 0;
while (*stream != 0xFF) {
stream++;
streamSize++;
}
streamSize++;
//int dialogDataValueEDI = (int)READ_UINT32(dialogData);
byte c;
int sentenceNumber;
DialogLine tempDialogLine;
Common::MemoryReadStream dialogStream(boxAddr, streamSize);
while ((sentenceNumber = dialogStream.readSByte()) != -1) {
tempDialogLine._line.clear();
//bt edi, eax
//jc skip_zdanko
// skip_sentence - TODO
tempDialogLine._nr = sentenceNumber;

while ((c = dialogStream.readByte())) {
tempDialogLine._line += c;
while (dialogBoxAddr[dialogBox]) {
tempDialogBox.clear();
byte *boxAddr = dialogBoxAddr[dialogBox];
int dialogDataValue = (int)READ_UINT32(_vm->_dialogData);
while ((sentenceNumber = *boxAddr) != 0xFF) {
boxAddr++;
if (!(dialogDataValue & (1 << sentenceNumber))) {
tempDialogLine._line.clear();
tempDialogLine._nr = sentenceNumber;
while ((c = *boxAddr)) {
tempDialogLine._line += c;
boxAddr++;
}
boxAddr++;
tempDialogBox.push_back(tempDialogLine);
} else {
do {
c = *boxAddr;
boxAddr++;
} while (c);
}
tempDialogBox.push_back(tempDialogLine);
}
_vm->_dialogBoxList.push_back(tempDialogBox);
i++;
dialogBox++;
}

//opt_done
int freeASlot = 0;
int freeBSlot = 0;
// TODO - dialogOptAddr, dialogOptLines
_flags->setFlagValue(Flags::VOICE_A_LINE, 0);
_flags->setFlagValue(Flags::VOICE_B_LINE, 0); // bx in original?

int freeHSlot = 0;
//check
for (int i = 31; i >= 0; i--) {
if (dialogOptAddr[i] != 0) {
i++;
debug("%s", (char *)dialogOptAddr[i]);
freeHSlot = i;
_flags->setFlagValue(Flags::VOICE_H_LINE, i);
break;
Expand Down

0 comments on commit 54d3dc9

Please sign in to comment.