1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#include "common/endian.h"
#include "sci/sci.h"
#include "sci/engine/segment.h"
#include "sci/engine/seg_manager.h"
#include "sci/engine/state.h"
namespace Sci {
//#define GC_DEBUG // Debug garbage collection
//#define GC_DEBUG_VERBOSE // Debug garbage verbosely
SegmentObj *SegmentObj::createSegmentObj(SegmentType type) {
SegmentObj *mem = 0;
switch (type) {
case SEG_TYPE_SCRIPT:
mem = new Script();
break;
case SEG_TYPE_CLONES:
mem = new CloneTable();
break;
case SEG_TYPE_LOCALS:
mem = new LocalVariables();
break;
case SEG_TYPE_SYS_STRINGS:
mem = new SystemStrings();
break;
case SEG_TYPE_STACK:
mem = new DataStack();
break;
case SEG_TYPE_HUNK:
mem = new HunkTable();
break;
case SEG_TYPE_LISTS:
mem = new ListTable();
break;
case SEG_TYPE_NODES:
mem = new NodeTable();
break;
case SEG_TYPE_DYNMEM:
mem = new DynMem();
break;
#ifdef ENABLE_SCI32
case SEG_TYPE_ARRAY:
mem = new ArrayTable();
break;
case SEG_TYPE_STRING:
mem = new StringTable();
break;
#endif
default:
error("Unknown SegmentObj type %d", type);
break;
}
assert(mem);
assert(mem->_type == type);
return mem;
}
Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) {
_nr = 0;
_buf = NULL;
_bufSize = 0;
_scriptSize = 0;
_heapSize = 0;
_synonyms = NULL;
_heapStart = NULL;
_exportTable = NULL;
_localsOffset = 0;
_localsSegment = 0;
_localsBlock = NULL;
_relocated = false;
_markedAsDeleted = 0;
}
Script::~Script() {
freeScript();
}
void Script::freeScript() {
free(_buf);
_buf = NULL;
_bufSize = 0;
_objects.clear();
_codeBlocks.clear();
}
bool Script::init(int script_nr, ResourceManager *resMan) {
setScriptSize(script_nr, resMan);
_buf = (byte *)malloc(_bufSize);
if (!_buf) {
freeScript();
warning("Not enough memory space for script size");
_bufSize = 0;
return false;
}
_localsOffset = 0;
_localsBlock = NULL;
_codeBlocks.clear();
_relocated = false;
_markedAsDeleted = false;
_nr = script_nr;
if (getSciVersion() >= SCI_VERSION_1_1)
_heapStart = _buf + _scriptSize;
else
_heapStart = _buf;
return true;
}
void Script::setScriptSize(int script_nr, ResourceManager *resMan) {
Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0);
Resource *heap = resMan->findResource(ResourceId(kResourceTypeHeap, script_nr), 0);
bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY);
_scriptSize = script->size;
_heapSize = 0; // Set later
if (!script || (getSciVersion() >= SCI_VERSION_1_1 && !heap)) {
error("SegManager::setScriptSize: failed to load %s", !script ? "script" : "heap");
}
if (oldScriptHeader) {
_bufSize = script->size + READ_LE_UINT16(script->data) * 2;
//locals_size = READ_LE_UINT16(script->data) * 2;
} else if (getSciVersion() < SCI_VERSION_1_1) {
_bufSize = script->size;
} else {
_bufSize = script->size + heap->size;
_heapSize = heap->size;
// Ensure that the start of the heap resource can be word-aligned.
if (script->size & 2) {
_bufSize++;
_scriptSize++;
}
if (_bufSize > 65535) {
error("Script and heap sizes combined exceed 64K."
"This means a fundamental design bug was made in SCI\n"
"regarding SCI1.1 games.\nPlease report this so it can be"
"fixed in the next major version");
return;
}
}
}
Object *Script::allocateObject(uint16 offset) {
return &_objects[offset];
}
Object *Script::getObject(uint16 offset) {
if (_objects.contains(offset))
return &_objects[offset];
else
return 0;
}
Object *Script::scriptObjInit(reg_t obj_pos) {
Object *obj;
if (getSciVersion() < SCI_VERSION_1_1)
obj_pos.offset += 8; // magic offset (SCRIPT_OBJECT_MAGIC_OFFSET)
VERIFY(obj_pos.offset < _bufSize, "Attempt to initialize object beyond end of script\n");
obj = allocateObject(obj_pos.offset);
VERIFY(obj_pos.offset + SCRIPT_FUNCTAREAPTR_OFFSET < (int)_bufSize, "Function area pointer stored beyond end of script\n");
obj->init(_buf, obj_pos);
return obj;
}
void Script::scriptObjRemove(reg_t obj_pos) {
if (getSciVersion() < SCI_VERSION_1_1)
obj_pos.offset += 8;
_objects.erase(obj_pos.toUint16());
}
int Script::relocateBlock(Common::Array<reg_t> &block, int block_location, SegmentId segment, int location) {
int rel = location - block_location;
if (rel < 0)
return 0;
uint idx = rel >> 1;
if (idx >= block.size())
return 0;
if (rel & 1) {
warning("Attempt to relocate odd variable #%d.5e (relative to %04x)\n", idx, block_location);
return 0;
}
block[idx].segment = segment; // Perform relocation
if (getSciVersion() >= SCI_VERSION_1_1)
block[idx].offset += _scriptSize;
return 1;
}
int Script::relocateLocal(SegmentId segment, int location) {
if (_localsBlock)
return relocateBlock(_localsBlock->_locals, _localsOffset, segment, location);
else
return 0; // No hands, no cookies
}
int Script::relocateObject(Object &obj, SegmentId segment, int location) {
return relocateBlock(obj._variables, obj.getPos().offset, segment, location);
}
void Script::scriptAddCodeBlock(reg_t location) {
CodeBlock cb;
cb.pos = location;
cb.size = READ_LE_UINT16(_buf + location.offset - 2);
_codeBlocks.push_back(cb);
}
void Script::scriptRelocate(reg_t block) {
VERIFY(block.offset < (uint16)_bufSize && READ_LE_UINT16(_buf + block.offset) * 2 + block.offset < (uint16)_bufSize,
"Relocation block outside of script\n");
int count = READ_LE_UINT16(_buf + block.offset);
for (int i = 0; i <= count; i++) {
int pos = READ_LE_UINT16(_buf + block.offset + 2 + (i * 2));
if (!pos)
continue; // FIXME: A hack pending investigation
if (!relocateLocal(block.segment, pos)) {
bool done = false;
uint k;
ObjMap::iterator it;
const ObjMap::iterator end = _objects.end();
for (it = _objects.begin(); !done && it != end; ++it) {
if (relocateObject(it->_value, block.segment, pos))
done = true;
}
for (k = 0; !done && k < _codeBlocks.size(); k++) {
if (pos >= _codeBlocks[k].pos.offset &&
pos < _codeBlocks[k].pos.offset + _codeBlocks[k].size)
done = true;
}
if (!done) {
printf("While processing relocation block %04x:%04x:\n", PRINT_REG(block));
printf("Relocation failed for index %04x (%d/%d)\n", pos, i + 1, count);
if (_localsBlock)
printf("- locals: %d at %04x\n", _localsBlock->_locals.size(), _localsOffset);
else
printf("- No locals\n");
for (it = _objects.begin(), k = 0; it != end; ++it, ++k)
printf("- obj#%d at %04x w/ %d vars\n", k, it->_value.getPos().offset, it->_value.getVarCount());
// SQ3 script 71 has broken relocation entries.
printf("Trying to continue anyway...\n");
}
}
}
}
void Script::heapRelocate(reg_t block) {
VERIFY(block.offset < (uint16)_heapSize && READ_LE_UINT16(_heapStart + block.offset) * 2 + block.offset < (uint16)_bufSize,
"Relocation block outside of script\n");
if (_relocated)
return;
_relocated = true;
int count = READ_LE_UINT16(_heapStart + block.offset);
for (int i = 0; i < count; i++) {
int pos = READ_LE_UINT16(_heapStart + block.offset + 2 + (i * 2)) + _scriptSize;
if (!relocateLocal(block.segment, pos)) {
bool done = false;
uint k;
ObjMap::iterator it;
const ObjMap::iterator end = _objects.end();
for (it = _objects.begin(); !done && it != end; ++it) {
if (relocateObject(it->_value, block.segment, pos))
done = true;
}
if (!done) {
printf("While processing relocation block %04x:%04x:\n", PRINT_REG(block));
printf("Relocation failed for index %04x (%d/%d)\n", pos, i + 1, count);
if (_localsBlock)
printf("- locals: %d at %04x\n", _localsBlock->_locals.size(), _localsOffset);
else
printf("- No locals\n");
for (it = _objects.begin(), k = 0; it != end; ++it, ++k)
printf("- obj#%d at %04x w/ %d vars\n", k, it->_value.getPos().offset, it->_value.getVarCount());
error("Breakpoint in %s, line %d", __FILE__, __LINE__);
}
}
}
}
void Script::incrementLockers() {
_lockers++;
}
void Script::decrementLockers() {
if (_lockers > 0)
_lockers--;
}
int Script::getLockers() const {
return _lockers;
}
void Script::setLockers(int lockers) {
_lockers = lockers;
}
void Script::setExportTableOffset(int offset) {
if (offset) {
_exportTable = (uint16 *)(_buf + offset + 2);
_numExports = READ_LE_UINT16((byte *)(_exportTable - 1));
} else {
_exportTable = NULL;
_numExports = 0;
}
}
// TODO: This method should be Script method. The only reason
// that it isn't is that it uses _exportsAreWide, which is true if
// detectLofsType() == SCI_VERSION_1_MIDDLE
// Maybe _exportsAreWide should become a Script member var, e.g. set
// by setExportTableOffset?
uint16 SegManager::validateExportFunc(int pubfunct, SegmentId seg) {
Script *scr = getScript(seg);
if (scr->_numExports <= pubfunct) {
warning("validateExportFunc(): pubfunct is invalid");
return 0;
}
if (_exportsAreWide)
pubfunct *= 2;
uint16 offset = READ_LE_UINT16((byte *)(scr->_exportTable + pubfunct));
VERIFY(offset < scr->_bufSize, "invalid export function pointer");
return offset;
}
void Script::setSynonymsOffset(int offset) {
_synonyms = _buf + offset;
}
byte *Script::getSynonyms() const {
return _synonyms;
}
void Script::setSynonymsNr(int n) {
_numSynonyms = n;
}
int Script::getSynonymsNr() const {
return _numSynonyms;
}
// memory operations
void Script::mcpyInOut(int dst, const void *src, size_t n) {
if (_buf) {
assert(dst + n <= _bufSize);
memcpy(_buf + dst, src, n);
}
}
int16 Script::getHeap(uint16 offset) const {
assert(offset + 1 < (int)_bufSize);
return READ_LE_UINT16(_buf + offset);
// return (_buf[offset] | (_buf[offset+1]) << 8);
}
SegmentRef SegmentObj::dereference(reg_t pointer) {
error("Error: Trying to dereference pointer %04x:%04x to inappropriate segment",
PRINT_REG(pointer));
return SegmentRef();
}
bool Script::isValidOffset(uint16 offset) const {
return offset < _bufSize;
}
SegmentRef Script::dereference(reg_t pointer) {
if (pointer.offset > _bufSize) {
warning("Script::dereference(): Attempt to dereference invalid pointer %04x:%04x into script segment (script size=%d)",
PRINT_REG(pointer), (uint)_bufSize);
return SegmentRef();
}
SegmentRef ret;
ret.isRaw = true;
ret.maxSize = _bufSize - pointer.offset;
ret.raw = _buf + pointer.offset;
return ret;
}
bool LocalVariables::isValidOffset(uint16 offset) const {
return offset < _locals.size() * 2;
}
SegmentRef LocalVariables::dereference(reg_t pointer) {
SegmentRef ret;
ret.isRaw = false; // reg_t based data!
ret.maxSize = (_locals.size() - pointer.offset / 2) * 2;
if (pointer.offset & 1) {
ret.maxSize -= 1;
ret.skipByte = true;
}
if (ret.maxSize > 0) {
ret.reg = &_locals[pointer.offset / 2];
} else {
warning("LocalVariables::dereference: Offset at end or out of bounds %04x:%04x", PRINT_REG(pointer));
ret.reg = 0;
}
return ret;
}
bool DataStack::isValidOffset(uint16 offset) const {
return offset < _capacity * 2;
}
SegmentRef DataStack::dereference(reg_t pointer) {
SegmentRef ret;
ret.isRaw = false; // reg_t based data!
ret.maxSize = (_capacity - pointer.offset / 2) * 2;
if (pointer.offset & 1) {
ret.maxSize -= 1;
ret.skipByte = true;
}
ret.reg = &_entries[pointer.offset / 2];
return ret;
}
bool DynMem::isValidOffset(uint16 offset) const {
return offset < _size;
}
SegmentRef DynMem::dereference(reg_t pointer) {
SegmentRef ret;
ret.isRaw = true;
ret.maxSize = _size - pointer.offset;
ret.raw = _buf + pointer.offset;
return ret;
}
bool SystemStrings::isValidOffset(uint16 offset) const {
return offset < SYS_STRINGS_MAX && !_strings[offset]._name.empty();
}
SegmentRef SystemStrings::dereference(reg_t pointer) {
SegmentRef ret;
ret.isRaw = true;
ret.maxSize = _strings[pointer.offset]._maxSize;
if (isValidOffset(pointer.offset))
ret.raw = (byte *)(_strings[pointer.offset]._value);
else {
// This occurs in KQ5CD when interacting with certain objects
warning("SystemStrings::dereference(): Attempt to dereference invalid pointer %04x:%04x", PRINT_REG(pointer));
}
return ret;
}
//-------------------- script --------------------
reg_t Script::findCanonicAddress(SegManager *segMan, reg_t addr) {
addr.offset = 0;
return addr;
}
void Script::freeAtAddress(SegManager *segMan, reg_t addr) {
/*
debugC(2, kDebugLevelGC, "[GC] Freeing script %04x:%04x", PRINT_REG(addr));
if (_localsSegment)
debugC(2, kDebugLevelGC, "[GC] Freeing locals %04x:0000", _localsSegment);
*/
if (_markedAsDeleted)
segMan->deallocateScript(_nr);
}
void Script::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) {
(*note)(param, make_reg(segId, 0));
}
void Script::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) {
if (addr.offset <= _bufSize && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(_buf + addr.offset)) {
Object *obj = getObject(addr.offset);
if (obj) {
// Note all local variables, if we have a local variable environment
if (_localsSegment)
(*note)(param, make_reg(_localsSegment, 0));
for (uint i = 0; i < obj->getVarCount(); i++)
(*note)(param, obj->getVariable(i));
} else {
warning("Request for outgoing script-object reference at %04x:%04x failed", PRINT_REG(addr));
}
} else {
/* warning("Unexpected request for outgoing script-object references at %04x:%04x", PRINT_REG(addr));*/
/* Happens e.g. when we're looking into strings */
}
}
//-------------------- clones --------------------
void CloneTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) {
Clone *clone;
// assert(addr.segment == _segId);
if (!isValidEntry(addr.offset)) {
error("Unexpected request for outgoing references from clone at %04x:%04x", PRINT_REG(addr));
}
clone = &(_table[addr.offset]);
// Emit all member variables (including references to the 'super' delegate)
for (uint i = 0; i < clone->getVarCount(); i++)
(*note)(param, clone->getVariable(i));
// Note that this also includes the 'base' object, which is part of the script and therefore also emits the locals.
(*note)(param, clone->getPos());
//debugC(2, kDebugLevelGC, "[GC] Reporting clone-pos %04x:%04x", PRINT_REG(clone->pos));
}
void CloneTable::freeAtAddress(SegManager *segMan, reg_t addr) {
#ifdef GC_DEBUG
Object *victim_obj;
// assert(addr.segment == _segId);
victim_obj = &(_table[addr.offset]);
if (!(victim_obj->_flags & OBJECT_FLAG_FREED))
warning("[GC] Clone %04x:%04x not reachable and not freed (freeing now)", PRINT_REG(addr));
#ifdef GC_DEBUG_VERBOSE
else
warning("[GC-DEBUG] Clone %04x:%04x: Freeing", PRINT_REG(addr));
#endif
#endif
/*
warning("[GC] Clone %04x:%04x: Freeing", PRINT_REG(addr));
warning("[GC] Clone had pos %04x:%04x", PRINT_REG(victim_obj->pos));
*/
freeEntry(addr.offset);
}
//-------------------- locals --------------------
reg_t LocalVariables::findCanonicAddress(SegManager *segMan, reg_t addr) {
// Reference the owning script
SegmentId owner_seg = segMan->getScriptSegment(script_id);
assert(owner_seg > 0);
return make_reg(owner_seg, 0);
}
void LocalVariables::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) {
// assert(addr.segment == _segId);
for (uint i = 0; i < _locals.size(); i++)
(*note)(param, _locals[i]);
}
//-------------------- stack --------------------
reg_t DataStack::findCanonicAddress(SegManager *segMan, reg_t addr) {
addr.offset = 0;
return addr;
}
void DataStack::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) {
fprintf(stderr, "Emitting %d stack entries\n", _capacity);
for (int i = 0; i < _capacity; i++)
(*note)(param, _entries[i]);
fprintf(stderr, "DONE");
}
//-------------------- lists --------------------
void ListTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) {
freeEntry(sub_addr.offset);
}
void ListTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) {
if (!isValidEntry(addr.offset)) {
warning("Invalid list referenced for outgoing references: %04x:%04x", PRINT_REG(addr));
return;
}
List *list = &(_table[addr.offset]);
note(param, list->first);
note(param, list->last);
// We could probably get away with just one of them, but
// let's be conservative here.
}
//-------------------- nodes --------------------
void NodeTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) {
freeEntry(sub_addr.offset);
}
void NodeTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) {
if (!isValidEntry(addr.offset)) {
warning("Invalid node referenced for outgoing references: %04x:%04x", PRINT_REG(addr));
return;
}
Node *node = &(_table[addr.offset]);
// We need all four here. Can't just stick with 'pred' OR 'succ' because node operations allow us
// to walk around from any given node
note(param, node->pred);
note(param, node->succ);
note(param, node->key);
note(param, node->value);
}
//-------------------- hunk --------------------
//-------------------- dynamic memory --------------------
reg_t DynMem::findCanonicAddress(SegManager *segMan, reg_t addr) {
addr.offset = 0;
return addr;
}
void DynMem::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) {
(*note)(param, make_reg(segId, 0));
}
#ifdef ENABLE_SCI32
SegmentRef ArrayTable::dereference(reg_t pointer) {
SegmentRef ret;
ret.isRaw = false;
ret.maxSize = _table[pointer.offset].getSize() * 2;
ret.reg = _table[pointer.offset].getRawData();
return ret;
}
void ArrayTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) {
_table[sub_addr.offset].destroy();
freeEntry(sub_addr.offset);
}
void ArrayTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) {
if (!isValidEntry(addr.offset)) {
warning("Invalid array referenced for outgoing references: %04x:%04x", PRINT_REG(addr));
return;
}
SciArray<reg_t> *array = &(_table[addr.offset]);
for (uint32 i = 0; i < array->getSize(); i++) {
reg_t value = array->getValue(i);
if (value.segment != 0)
note(param, value);
}
}
Common::String SciString::toString() {
if (_type != 3)
error("SciString::toString(): Array is not a string");
Common::String string;
for (uint32 i = 0; i < _size && _data[i] != 0; i++)
string += _data[i];
return string;
}
void SciString::fromString(Common::String string) {
if (_type != 3)
error("SciString::fromString(): Array is not a string");
if (string.size() > _size)
setSize(string.size());
for (uint32 i = 0; i < string.size(); i++)
_data[i] = string[i];
}
SegmentRef StringTable::dereference(reg_t pointer) {
SegmentRef ret;
ret.isRaw = true;
ret.maxSize = _table[pointer.offset].getSize();
ret.raw = (byte*)_table[pointer.offset].getRawData();
return ret;
}
void StringTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) {
_table[sub_addr.offset].destroy();
freeEntry(sub_addr.offset);
}
#endif
} // End of namespace Sci
|