diff options
author | Max Horn | 2009-09-14 12:59:42 +0000 |
---|---|---|
committer | Max Horn | 2009-09-14 12:59:42 +0000 |
commit | c00edfb64f160c0f3d428c4c4ac71dc7628fc2d6 (patch) | |
tree | b3fbdf9285f9f4788ae2682a4305c85273f6d4dc /engines | |
parent | 53450cc2e114d10c8e937c42aa7bfa9e0d4c6f7a (diff) | |
download | scummvm-rg350-c00edfb64f160c0f3d428c4c4ac71dc7628fc2d6.tar.gz scummvm-rg350-c00edfb64f160c0f3d428c4c4ac71dc7628fc2d6.tar.bz2 scummvm-rg350-c00edfb64f160c0f3d428c4c4ac71dc7628fc2d6.zip |
SCI: Merge kernelDerefCharPtr and kernelDerefString and change it from a macro to a function
svn-id: r44081
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/kernel.cpp | 8 | ||||
-rw-r--r-- | engines/sci/engine/kernel.h | 3 | ||||
-rw-r--r-- | engines/sci/engine/kfile.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/kgraphics.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/kstring.cpp | 20 |
5 files changed, 21 insertions, 18 deletions
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index 098cb8d237..2aa70789c9 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -742,11 +742,15 @@ static void *_kernel_dereference_pointer(SegManager *segMan, reg_t pointer, int } byte *kernelDerefBulkPtr(SegManager *segMan, reg_t pointer, int entries) { - return (byte*)_kernel_dereference_pointer(segMan, pointer, entries, 1); + return (byte *)_kernel_dereference_pointer(segMan, pointer, entries, 1); } reg_t *kernelDerefRegPtr(SegManager *segMan, reg_t pointer, int entries) { - return (reg_t*)_kernel_dereference_pointer(segMan, pointer, entries, sizeof(reg_t)); + return (reg_t *)_kernel_dereference_pointer(segMan, pointer, entries, sizeof(reg_t)); +} + +char *kernelDerefString(SegManager *segMan, reg_t pointer, int entries) { + return (char *)_kernel_dereference_pointer(segMan, pointer, entries, 1); } void Kernel::setDefaultKernelNames() { diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index 60840a514c..d849d80d0c 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -238,8 +238,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index); */ reg_t *kernelDerefRegPtr(SegManager *segMan, reg_t pointer, int entries); byte *kernelDerefBulkPtr(SegManager *segMan, reg_t pointer, int entries); -#define kernelDerefCharPtr(state, pointer, entries) ((char*)kernelDerefBulkPtr(state, pointer, entries)) -#define kernelDerefString(state, pointer) ((char*)kernelDerefBulkPtr(state, pointer, 0)) +char *kernelDerefString(SegManager *segMan, reg_t pointer, int entries = 0); /******************** Priority macros/functions ********************/ /** diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp index 4159e75a74..5f2cd7f5ce 100644 --- a/engines/sci/engine/kfile.cpp +++ b/engines/sci/engine/kfile.cpp @@ -811,7 +811,7 @@ reg_t kFileIO(EngineState *s, int, int argc, reg_t *argv) { case K_FILEIO_WRITE_STRING : { int handle = argv[1].toUint16(); int size = argv[3].toUint16(); - char *buf = kernelDerefCharPtr(s->segMan, argv[2], size); + char *buf = kernelDerefString(s->segMan, argv[2], size); debug(3, "K_FILEIO_WRITE_STRING(%d,%d)", handle, size); // FIXME: What is the difference between K_FILEIO_WRITE_STRING and diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index 29361b3e75..f2370c5aad 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -602,14 +602,14 @@ reg_t kGraph(EngineState *s, int, int argc, reg_t *argv) { reg_t kTextSize(EngineState *s, int, int argc, reg_t *argv) { int width, height; - char *text = argv[1].segment ? (char *) kernelDerefBulkPtr(s->segMan, argv[1], 0) : NULL; + char *text = argv[1].segment ? kernelDerefString(s->segMan, argv[1]) : NULL; const char *sep = NULL; reg_t *dest = kernelDerefRegPtr(s->segMan, argv[0], 4); int maxwidth = (argc > 3) ? argv[3].toUint16() : 0; int font_nr = argv[2].toUint16(); if ((argc > 4) && (argv[4].segment)) - sep = (const char *)kernelDerefBulkPtr(s->segMan, argv[4], 0); + sep = kernelDerefString(s->segMan, argv[4]); if (maxwidth < 0) maxwidth = 0; @@ -3135,7 +3135,7 @@ reg_t kDisplay(EngineState *s, int, int argc, reg_t *argv) { if (textp.segment) { argpt = 1; - text = (char *)kernelDerefBulkPtr(s->segMan, textp, 0); + text = kernelDerefString(s->segMan, textp); } else { argpt = 2; text = kernel_lookup_text(s, textp, index); diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 6fd438bd62..d12e890d40 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -44,7 +44,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index) { Resource *textres; if (address.segment) - return (char *)kernelDerefBulkPtr(s->segMan, address, 0); + return kernelDerefString(s->segMan, address); else { int textlen; int _index = index; @@ -87,7 +87,7 @@ reg_t kSaid(EngineState *s, int, int argc, reg_t *argv) { if (!heap_said_block.segment) return NULL_REG; - said_block = (byte *) kernelDerefBulkPtr(s->segMan, heap_said_block, 0); + said_block = (byte *)kernelDerefBulkPtr(s->segMan, heap_said_block, 0); if (!said_block) { warning("Said on non-string, pointer %04x:%04x", PRINT_REG(heap_said_block)); @@ -287,8 +287,8 @@ reg_t kStrCmp(EngineState *s, int, int argc, reg_t *argv) { reg_t kStrCpy(EngineState *s, int, int argc, reg_t *argv) { - char *dest = (char *) kernelDerefBulkPtr(s->segMan, argv[0], 0); - char *src = (char *) kernelDerefBulkPtr(s->segMan, argv[1], 0); + char *dest = kernelDerefString(s->segMan, argv[0]); + char *src = kernelDerefString(s->segMan, argv[1]); if (!dest) { warning("Attempt to strcpy TO invalid pointer %04x:%04x", @@ -352,7 +352,7 @@ static int is_print_str(const char *str) { reg_t kStrAt(EngineState *s, int, int argc, reg_t *argv) { - byte *dest = (byte *)kernelDerefBulkPtr(s->segMan, argv[0], 0); + char *dest = kernelDerefString(s->segMan, argv[0]); reg_t *dest2; if (!dest) { @@ -380,7 +380,7 @@ reg_t kStrAt(EngineState *s, int, int argc, reg_t *argv) { int odd = !(argv[1].toUint16() & 1); #endif dest2 = ((reg_t *) dest) + (argv[1].toUint16() / 2); - dest = ((byte *)(&dest2->offset)) + odd; + dest = ((char *)(&dest2->offset)) + odd; } else dest += argv[1].toUint16(); @@ -420,7 +420,7 @@ reg_t kReadNumber(EngineState *s, int, int argc, reg_t *argv) { reg_t kFormat(EngineState *s, int, int argc, reg_t *argv) { int *arguments; reg_t dest = argv[0]; - char *target = (char *) kernelDerefBulkPtr(s->segMan, dest, 0); + char *target = kernelDerefString(s->segMan, dest); reg_t position = argv[1]; /* source */ int index = argv[2].toUint16(); char *source; @@ -740,7 +740,7 @@ reg_t kMessage(EngineState *s, int, int argc, reg_t *argv) { if (!bufferReg.isNull()) { int len = str.size() + 1; - buffer = kernelDerefCharPtr(s->segMan, bufferReg, len); + buffer = kernelDerefString(s->segMan, bufferReg, len); if (buffer) { strcpy(buffer, str.c_str()); @@ -748,7 +748,7 @@ reg_t kMessage(EngineState *s, int, int argc, reg_t *argv) { warning("Message: buffer %04x:%04x invalid or too small to hold the following text of %i bytes: '%s'", PRINT_REG(bufferReg), len, str.c_str()); // Set buffer to empty string if possible - buffer = kernelDerefCharPtr(s->segMan, bufferReg, 1); + buffer = kernelDerefString(s->segMan, bufferReg, 1); if (buffer) *buffer = 0; } @@ -821,7 +821,7 @@ reg_t kStrSplit(EngineState *s, int, int argc, reg_t *argv) { Common::String str = s->strSplit(format, sep); // Make sure target buffer is large enough - char *buf = kernelDerefCharPtr(s->segMan, argv[0], str.size() + 1); + char *buf = kernelDerefString(s->segMan, argv[0], str.size() + 1); if (buf) { strcpy(buf, str.c_str()); |