From e376cce16d2114a920c9610290ee66555ea0e1f4 Mon Sep 17 00:00:00 2001 From: Scott Percival Date: Thu, 14 Nov 2019 20:09:45 +0800 Subject: DIRECTOR: Fix formatting --- engines/director/archive.cpp | 8 +- engines/director/frame.cpp | 2 +- engines/director/lingo/lingo-bytecode.cpp | 180 +++++++++++++++--------------- engines/director/lingo/lingo-code.cpp | 122 ++++++++++---------- engines/director/lingo/lingo-gr.y | 6 +- engines/director/lingo/lingo.h | 3 - 6 files changed, 152 insertions(+), 169 deletions(-) diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp index de3a866524..bbcf26bef5 100644 --- a/engines/director/archive.cpp +++ b/engines/director/archive.cpp @@ -423,10 +423,10 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff tag == MKTAG('D', 'I', 'B', ' ') || tag == MKTAG('R', 'T', 'E', '0') || tag == MKTAG('R', 'T', 'E', '1') || - tag == MKTAG('R', 'T', 'E', '2') || - tag == MKTAG('L', 'c', 't', 'x') || - tag == MKTAG('L', 'n', 'a', 'm') || - tag == MKTAG('L', 's', 'c', 'r')) + tag == MKTAG('R', 'T', 'E', '2') || + tag == MKTAG('L', 'c', 't', 'x') || + tag == MKTAG('L', 'n', 'a', 'm') || + tag == MKTAG('L', 's', 'c', 'r')) _types[tag][i] = res; } diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp index dd6f9fc02e..6ea3930e58 100644 --- a/engines/director/frame.cpp +++ b/engines/director/frame.cpp @@ -627,7 +627,7 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) { int y = _sprites[i]->_startPoint.y - regY + rectTop; int height = _sprites[i]->_height; int width = _vm->getVersion() > 4 ? _sprites[i]->_bitmapCast->initialRect.width() : _sprites[i]->_width; - warning("drawRect: x=%d, y=%d, w=%d h=%d", x, y, width, height); + warning("drawRect: x=%d, y=%d, w=%d h=%d", x, y, width, height); Common::Rect drawRect(x, y, x + width, y + height); addDrawRect(i, drawRect); inkBasedBlit(surface, *(_sprites[i]->_bitmapCast->surface), i, drawRect); diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp index fcc2236a67..9302c46626 100644 --- a/engines/director/lingo/lingo-bytecode.cpp +++ b/engines/director/lingo/lingo-bytecode.cpp @@ -29,6 +29,7 @@ static struct LingoV4Bytecode { const inst func; const char *proto; } lingoV4[] = { + { 0x01, STOP, "" }, { 0x03, Lingo::c_voidpush, "" }, { 0x04, Lingo::c_mul, "" }, { 0x05, Lingo::c_add, "" }, @@ -56,7 +57,6 @@ static struct LingoV4Bytecode { { 0x1b, Lingo::c_field, "" }, { 0x1c, Lingo::c_tell, "" }, { 0x1d, Lingo::c_telldone, "" }, - { 0x41, Lingo::c_intpush, "b" }, { 0, 0, 0 } }; @@ -68,9 +68,7 @@ void Lingo::initBytecode() { } - - -void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType type, uint16 id) { +void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType type, uint16 id) { debugC(1, kDebugLingoCompile, "Add V4 bytecode for type %s with id %d", scriptType2str(type), id); if (_scriptContexts[type].contains(id)) { @@ -90,116 +88,118 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty for (uint32 i = 0; i < 0x10; i++) { stream.readByte(); } - uint16 code_store_offset = stream.readUint16(); + uint16 codeStoreOffset = stream.readUint16(); // unk2 for (uint32 i = 0; i < 0x2e; i++) { stream.readByte(); } - uint16 globals_offset = stream.readUint16(); - uint16 globals_count = stream.readUint16(); + uint16 globalsOffset = stream.readUint16(); + uint16 globalsCount = stream.readUint16(); // unk3 for (uint32 i = 0; i < 0x4; i++) { stream.readByte(); } - uint16 functions_count = stream.readUint16(); + uint16 functionsCount = stream.readUint16(); stream.readUint16(); - uint16 functions_offset = stream.readUint16(); - uint16 consts_count = stream.readUint16(); + uint16 functionsOffset = stream.readUint16(); + uint16 constsCount = stream.readUint16(); stream.readUint16(); - uint16 consts_offset = stream.readUint16(); + uint16 constsOffset = stream.readUint16(); stream.readUint16(); stream.readUint16(); stream.readUint16(); - uint16 consts_base = stream.readUint16(); + uint16 constsBase = stream.readUint16(); // preload all the constants! // these are stored as a reference table of 6 byte entries, followed by a storage area. // copy the storage area first. - uint32 consts_store_offset = consts_offset+6*consts_count; - uint32 consts_store_size = stream.size()-consts_store_offset; - stream.seek(consts_store_offset); - byte *const_store = (byte *)malloc(consts_store_size); - stream.read(const_store, consts_store_size); + uint32 constsStoreOffset = constsOffset + 6 * constsCount; + uint32 constsStoreSize = stream.size() - constsStoreOffset; + stream.seek(constsStoreOffset); + byte *constsStore = (byte *)malloc(constsStoreSize); + stream.read(constsStore, constsStoreSize); - Common::Array const_data; + Common::Array constsData; // read each entry in the reference table. - stream.seek(consts_offset); - for (uint16 i=0; i= constsStoreSize) { + warning("Constant string has no null terminator"); break; - } else { - constant.u.s += const_store[pointer]; } - pointer += 1; - } - if (pointer >= consts_store_size) { - warning("Constant string has no null terminator"); - break; } - } - break; + break; case 4: // Integer type constant.type = INT; constant.u.i = (int)value; break; - case 9: { // Float type - constant.type = FLOAT; - if (value < consts_store_offset) { - warning("Constant float start offset is out of bounds"); - break; - } else if (value+4 > consts_store_size) { - warning("Constant float end offset is out of bounds"); - break; + case 9: // Float type + { + constant.type = FLOAT; + if (value < constsStoreOffset) { + warning("Constant float start offset is out of bounds"); + break; + } else if (value + 4 > constsStoreSize) { + warning("Constant float end offset is out of bounds"); + break; + } + constant.u.f = *(float *)(constsStore + value); } - constant.u.f = *(float *)(const_store+value); - } - break; + break; default: warning("Unknown constant type %d", type); break; } - const_data.push_back(constant); + constsData.push_back(constant); } - free(const_store); + free(constsStore); // parse each function! // these are stored as a code storage area, followed by a reference table of 42 byte entries. // copy the storage area first. - uint32 code_store_size = functions_offset - code_store_offset; - stream.seek(code_store_offset); - byte *code_store = (byte *)malloc(code_store_size); - stream.read(code_store, code_store_size); + uint32 codeStoreSize = functionsOffset - codeStoreOffset; + stream.seek(codeStoreOffset); + byte *codeStore = (byte *)malloc(codeStoreSize); + stream.read(codeStore, codeStoreSize); // read each entry in the function table. - stream.seek(functions_offset); - for (uint16 i=0; ifunctions.push_back(new ScriptData); _currentScript = _currentScriptContext->functions[_currentScriptFunction]; - uint16 name_index = stream.readUint16(); + uint16 nameIndex = stream.readUint16(); stream.readUint16(); uint32 length = stream.readUint32(); - uint32 start_offset = stream.readUint32(); - uint16 arg_count = stream.readUint16(); - uint32 arg_offset = stream.readUint32(); - uint16 var_count = stream.readUint16(); - uint32 var_names_offset = stream.readUint32(); + uint32 startOffset = stream.readUint32(); + uint16 argCount = stream.readUint16(); + uint32 argOffset = stream.readUint32(); + uint16 varCount = stream.readUint16(); + uint32 varNamesOffset = stream.readUint32(); stream.readUint16(); stream.readUint16(); stream.readUint16(); @@ -210,35 +210,35 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty stream.readUint16(); stream.readUint16(); - if (start_offset < code_store_offset) { + if (startOffset < codeStoreOffset) { warning("Function %d start offset is out of bounds!", i); continue; - } else if (start_offset + length >= code_store_offset + code_store_size) { + } else if (startOffset + length >= codeStoreOffset + codeStoreSize) { warning("Function %d end offset is out of bounds", i); continue; } - uint16 pointer = start_offset-code_store_offset; - Common::Array offset_list; - while (pointer < start_offset+length-code_store_offset) { - uint8 opcode = code_store[pointer]; + uint16 pointer = startOffset - codeStoreOffset; + Common::Array offsetList; + while (pointer < startOffset + length - codeStoreOffset) { + uint8 opcode = codeStore[pointer]; pointer += 1; if (_lingoV4.contains(opcode)) { - offset_list.push_back(_currentScript->size()); + offsetList.push_back(_currentScript->size()); g_lingo->code1(_lingoV4[opcode]->func); size_t argc = strlen(_lingoV4[opcode]->proto); - for (uint c=0; cproto[c]) { case 'b': - offset_list.push_back(_currentScript->size()); - g_lingo->codeInt((int8)code_store[pointer]); + offsetList.push_back(_currentScript->size()); + g_lingo->codeInt((int8)codeStore[pointer]); pointer += 1; break; case 'w': - offset_list.push_back(_currentScript->size()); - offset_list.push_back(_currentScript->size()); - g_lingo->codeInt((int16)READ_UINT16(&code_store[pointer])); + offsetList.push_back(_currentScript->size()); + offsetList.push_back(_currentScript->size()); + g_lingo->codeInt((int16)READ_UINT16(&codeStore[pointer])); pointer += 2; break; default: @@ -247,37 +247,33 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty } } else { - // exit condition - if (opcode == 0x01) { - offset_list.push_back(_currentScript->size()); - g_lingo->code1(STOP); // unimplemented instruction - } else if (opcode < 0x40) { // 1 byte instruction - offset_list.push_back(_currentScript->size()); + if (opcode < 0x40) { // 1 byte instruction + offsetList.push_back(_currentScript->size()); g_lingo->code1(Lingo::c_unk); g_lingo->codeInt(opcode); } else if (opcode < 0x80) { // 2 byte instruction - offset_list.push_back(_currentScript->size()); + offsetList.push_back(_currentScript->size()); g_lingo->code1(Lingo::c_unk1); g_lingo->codeInt(opcode); - offset_list.push_back(_currentScript->size()); - g_lingo->codeInt((uint)code_store[pointer]); + offsetList.push_back(_currentScript->size()); + g_lingo->codeInt((uint)codeStore[pointer]); pointer += 1; } else { // 3 byte instruction - offset_list.push_back(_currentScript->size()); + offsetList.push_back(_currentScript->size()); g_lingo->code1(Lingo::c_unk2); g_lingo->codeInt(opcode); - offset_list.push_back(_currentScript->size()); - g_lingo->codeInt((uint)code_store[pointer]); - offset_list.push_back(_currentScript->size()); - g_lingo->codeInt((uint)code_store[pointer+1]); + offsetList.push_back(_currentScript->size()); + g_lingo->codeInt((uint)codeStore[pointer]); + offsetList.push_back(_currentScript->size()); + g_lingo->codeInt((uint)codeStore[pointer+1]); pointer += 2; } } } } - free(code_store); + free(codeStore); } diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp index 819053f89b..9cfe61397c 100644 --- a/engines/director/lingo/lingo-code.cpp +++ b/engines/director/lingo/lingo-code.cpp @@ -60,7 +60,7 @@ static struct FuncDescr { { Lingo::c_argspush, "c_argspush", "i" }, { Lingo::c_arraypush, "c_arraypush", "i" }, { Lingo::c_printtop, "c_printtop", "" }, - { Lingo::c_intpush, "c_intpush", "i" }, + { Lingo::c_intpush, "c_intpush", "i" }, { Lingo::c_voidpush, "c_voidpush", "" }, { Lingo::c_floatpush, "c_floatpush", "f" }, { Lingo::c_stringpush, "c_stringpush", "s" }, @@ -86,8 +86,8 @@ static struct FuncDescr { { Lingo::c_starts, "c_starts", "" }, { Lingo::c_intersects, "c_intersects", "" }, { Lingo::c_within, "c_within", "" }, - { Lingo::c_field, "c_field", "" }, - { Lingo::c_of, "c_of", "" }, // D9 + { Lingo::c_field, "c_field", "" }, + { Lingo::c_of, "c_of", "" }, // D9 { Lingo::c_charOf, "c_charOf", "" }, // D3 { Lingo::c_charToOf, "c_charToOf", "" }, // D3 { Lingo::c_itemOf, "c_itemOf", "" }, // D3 @@ -110,8 +110,8 @@ static struct FuncDescr { { Lingo::c_exitRepeat, "c_exitRepeat", "" }, { Lingo::c_ifcode, "c_ifcode", "oooi" }, { Lingo::c_tellcode, "c_tellcode", "o" }, - { Lingo::c_tell, "c_tell", "" }, - { Lingo::c_telldone, "c_telldone", "" }, + { Lingo::c_tell, "c_tell", "" }, + { Lingo::c_telldone, "c_telldone", "" }, { Lingo::c_whencode, "c_whencode", "os" }, { Lingo::c_goto, "c_goto", "" }, { Lingo::c_gotoloop, "c_gotoloop", "" }, @@ -125,12 +125,10 @@ static struct FuncDescr { { Lingo::c_property, "c_property", "s" }, { Lingo::c_instance, "c_instance", "s" }, { Lingo::c_open, "c_open", "" }, - { Lingo::c_hilite, "c_hilite", "" }, - { Lingo::c_jump, "c_jump", "" }, - { Lingo::c_jumpif, "c_jumpif", "" }, - { Lingo::c_unk, "c_unk", "i" }, - { Lingo::c_unk1, "c_unk1", "ii" }, - { Lingo::c_unk2, "c_unk2", "iii" }, + { Lingo::c_hilite, "c_hilite", "" }, + { Lingo::c_unk, "c_unk", "i" }, + { Lingo::c_unk1, "c_unk1", "ii" }, + { Lingo::c_unk2, "c_unk2", "iii" }, { 0, 0, 0 } }; @@ -667,30 +665,30 @@ void Lingo::c_within() { } void Lingo::c_field() { - Datum d1 = g_lingo->pop(); + Datum d1 = g_lingo->pop(); - warning("STUB: c_field: %d", d1.u.i); + warning("STUB: c_field: %d", d1.u.i); - g_lingo->push(d1); + g_lingo->push(d1); } void Lingo::c_of() { - Datum first_char = g_lingo->pop(); - Datum last_char = g_lingo->pop(); - Datum first_word = g_lingo->pop(); - Datum last_word = g_lingo->pop(); - Datum first_item = g_lingo->pop(); - Datum last_item = g_lingo->pop(); - Datum first_line = g_lingo->pop(); - Datum last_line = g_lingo->pop(); - Datum target = g_lingo->pop(); + Datum first_char = g_lingo->pop(); + Datum last_char = g_lingo->pop(); + Datum first_word = g_lingo->pop(); + Datum last_word = g_lingo->pop(); + Datum first_item = g_lingo->pop(); + Datum last_item = g_lingo->pop(); + Datum first_line = g_lingo->pop(); + Datum last_line = g_lingo->pop(); + Datum target = g_lingo->pop(); - warning("STUB: c_of: %d %d %d %d %d %d %d %d %s", - first_char.u.i, last_char.u.i, first_word.u.i, last_word.u.i, - first_item.u.i, last_item.u.i, first_line.u.i, last_line.u.i, - target.u.s->c_str()); + warning("STUB: c_of: %d %d %d %d %d %d %d %d %s", + first_char.u.i, last_char.u.i, first_word.u.i, last_word.u.i, + first_item.u.i, last_item.u.i, first_line.u.i, last_line.u.i, + target.u.s->c_str()); - g_lingo->push(target); + g_lingo->push(target); } @@ -1024,7 +1022,7 @@ void Lingo::c_tellcode() { } void Lingo::c_tell() { - Datum d1 = g_lingo->pop(); + Datum d1 = g_lingo->pop(); warning("STUB: c_tell %d", d1.u.i); } @@ -1251,52 +1249,44 @@ void Lingo::c_open() { } void Lingo::c_hilite() { - Datum first_char = g_lingo->pop(); - Datum last_char = g_lingo->pop(); - Datum first_word = g_lingo->pop(); - Datum last_word = g_lingo->pop(); - Datum first_item = g_lingo->pop(); - Datum last_item = g_lingo->pop(); - Datum first_line = g_lingo->pop(); - Datum last_line = g_lingo->pop(); - Datum cast_id = g_lingo->pop(); - - warning("STUB: c_hilite: %d %d %d %d %d %d %d %d %d", - first_char.u.i, last_char.u.i, first_word.u.i, last_word.u.i, - first_item.u.i, last_item.u.i, first_line.u.i, last_line.u.i, - cast_id.u.i); -} - -void Lingo::c_jump() { - -} - -void Lingo::c_jumpif() { - + Datum first_char = g_lingo->pop(); + Datum last_char = g_lingo->pop(); + Datum first_word = g_lingo->pop(); + Datum last_word = g_lingo->pop(); + Datum first_item = g_lingo->pop(); + Datum last_item = g_lingo->pop(); + Datum first_line = g_lingo->pop(); + Datum last_line = g_lingo->pop(); + Datum cast_id = g_lingo->pop(); + + warning("STUB: c_hilite: %d %d %d %d %d %d %d %d %d", + first_char.u.i, last_char.u.i, first_word.u.i, last_word.u.i, + first_item.u.i, last_item.u.i, first_line.u.i, last_line.u.i, + cast_id.u.i); } void Lingo::c_unk() { - int savepc = g_lingo->_pc; - uint opcode = READ_UINT32(&(*g_lingo->_currentScript)[savepc]); - warning("STUB: opcode 0x%02x", opcode); - g_lingo->_pc += 1; + int savepc = g_lingo->_pc; + uint opcode = READ_UINT32(&(*g_lingo->_currentScript)[savepc]); + warning("STUB: opcode 0x%02x", opcode); + g_lingo->_pc += 1; } void Lingo::c_unk1() { - int savepc = g_lingo->_pc; - uint opcode = READ_UINT32(&(*g_lingo->_currentScript)[savepc]); - uint arg1 = READ_UINT32(&(*g_lingo->_currentScript)[savepc+1]); - warning("STUB: opcode 0x%02x (%d)", opcode, arg1); - g_lingo->_pc += 2; + int savepc = g_lingo->_pc; + uint opcode = READ_UINT32(&(*g_lingo->_currentScript)[savepc]); + uint arg1 = READ_UINT32(&(*g_lingo->_currentScript)[savepc+1]); + warning("STUB: opcode 0x%02x (%d)", opcode, arg1); + g_lingo->_pc += 2; } void Lingo::c_unk2() { - int savepc = g_lingo->_pc; - uint opcode = READ_UINT32(&(*g_lingo->_currentScript)[savepc]); - uint arg1 = READ_UINT32(&(*g_lingo->_currentScript)[savepc+1]); - uint arg2 = READ_UINT32(&(*g_lingo->_currentScript)[savepc+2]); - warning("STUB: opcode 0x%02x (%d, %d)", opcode, arg1, arg2); - g_lingo->_pc += 3; + int savepc = g_lingo->_pc; + uint opcode = READ_UINT32(&(*g_lingo->_currentScript)[savepc]); + uint arg1 = READ_UINT32(&(*g_lingo->_currentScript)[savepc+1]); + uint arg2 = READ_UINT32(&(*g_lingo->_currentScript)[savepc+2]); + warning("STUB: opcode 0x%02x (%d, %d)", opcode, arg1, arg2); + g_lingo->_pc += 3; } diff --git a/engines/director/lingo/lingo-gr.y b/engines/director/lingo/lingo-gr.y index 71c9bbbb48..70e3edd911 100644 --- a/engines/director/lingo/lingo-gr.y +++ b/engines/director/lingo/lingo-gr.y @@ -151,7 +151,7 @@ asgn: tPUT expr tINTO ID { delete $2; } | tSET THEENTITY '=' expr { g_lingo->code1(g_lingo->c_intpush); - g_lingo->codeInt(0); // Put dummy id + g_lingo->codeInt(0); // Put dummy id g_lingo->code1(g_lingo->c_theentityassign); inst e = 0, f = 0; WRITE_UINT32(&e, $2[0]); @@ -416,9 +416,9 @@ tell: tTELL { $$ = g_lingo->code1(g_lingo->c_tellcode); g_lingo->code1(STOP); } -expr: INT { +expr: INT { $$ = g_lingo->code1(g_lingo->c_intpush); - g_lingo->codeInt($1); } + g_lingo->codeInt($1); } | FLOAT { $$ = g_lingo->code1(g_lingo->c_floatpush); g_lingo->codeFloat($1); } diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h index bae1fbb724..7556e90bc2 100644 --- a/engines/director/lingo/lingo.h +++ b/engines/director/lingo/lingo.h @@ -333,9 +333,6 @@ public: static void c_open(); static void c_hilite(); - static void c_jump(); - static void c_jumpif(); - // stubs for unknown instructions static void c_unk(); static void c_unk1(); -- cgit v1.2.3