aboutsummaryrefslogtreecommitdiff
path: root/engines/dreamweb
diff options
context:
space:
mode:
authorFilippos Karapetis2011-12-27 01:48:25 +0200
committerFilippos Karapetis2011-12-27 02:02:54 +0200
commitb4062765293df384f8db8633bd1cd8bd88f79e95 (patch)
tree405a4644f01adbfc2da3f8a307c1afd8761b58b9 /engines/dreamweb
parent72800fac9dab26d1a774a7a76ddc3b7c3c870ccf (diff)
downloadscummvm-rg350-b4062765293df384f8db8633bd1cd8bd88f79e95.tar.gz
scummvm-rg350-b4062765293df384f8db8633bd1cd8bd88f79e95.tar.bz2
scummvm-rg350-b4062765293df384f8db8633bd1cd8bd88f79e95.zip
DREAMWEB: Cleanup of getKeyAndLogo(), dirFile() and read()
Diffstat (limited to 'engines/dreamweb')
-rw-r--r--engines/dreamweb/monitor.cpp219
-rw-r--r--engines/dreamweb/stubs.h3
2 files changed, 89 insertions, 133 deletions
diff --git a/engines/dreamweb/monitor.cpp b/engines/dreamweb/monitor.cpp
index 72cb4a3735..ddf12777e5 100644
--- a/engines/dreamweb/monitor.cpp
+++ b/engines/dreamweb/monitor.cpp
@@ -436,74 +436,43 @@ void DreamBase::showKeys() {
scrollMonitor();
}
-bool DreamGenContext::getKeyAndLogo() {
- byte newLogo = es.byte(bx + 1) - 48;
- byte keyNum = es.byte(bx + 1 + 2) - 48;
- bx += 1 + 2 + 1;
+bool DreamGenContext::getKeyAndLogo(const char *foundString) {
+ byte newLogo = foundString[1] - 48;
+ byte keyNum = foundString[3] - 48;
if (monitorKeyEntries[keyNum].keyAssigned == 1) {
// Key OK
data.byte(kLogonum) = newLogo;
- return false;
+ return true;
} else {
monMessage(12); // "Access denied, key required -"
monPrint(monitorKeyEntries[keyNum].username);
scrollMonitor();
- return true;
+ return false;
}
}
-void DreamGenContext::dirFile() {
- bool foundFile = false;
-
- es.byte(di) = 34;
-
- ds = data.word(kTextfile1);
- si = kTextstart;
- searchForString();
- if (al == 0) {
- foundFile = true;
- } else {
- ds = data.word(kTextfile2);
- si = kTextstart;
- searchForString();
- if (al == 0) {
- foundFile = true;
- } else {
- ds = data.word(kTextfile3);
- si = kTextstart;
- searchForString();
- if (al == 0)
- foundFile = true;
- }
- }
+const char *DreamBase::searchForString(const char *topic, const char *text) {
+ char delim = *topic;
- if (!foundFile) {
- monMessage(7);
- return;
- }
+ while (true) {
+ const char *s = topic;
+ int delimCount = 0;
- // "foundfile"
- if (getKeyAndLogo())
- return;
+ char c;
+ do {
+ c = makeCaps(*text++);
- // "keyok2"
- memcpy(data.ptr(kCurrentfile+1, 0), data.ptr(offset_operand1+1, 0), 12);
- monitorLogo();
- scrollMonitor();
- monMessage(10);
+ if (c == '*' || (delim == '=' && c == 34))
+ return 0;
- while (true) {
- al = es.byte(bx);
- bx++;
- if (al == 34 || al == '*') {
- // "endofdir2"
- scrollMonitor();
- return;
- }
+ if (c == delim) {
+ delimCount++;
+ if (delimCount == 2)
+ return text;
+ }
- if (al == '=')
- monPrint();
+ } while (c == *s++);
}
}
@@ -529,9 +498,54 @@ void DreamGenContext::dirCom() {
scrollMonitor();
}
-void DreamGenContext::read() {
- bool foundFile = false;
+void DreamGenContext::dirFile() {
+ es.byte(di) = 34;
+ const char *topic = (const char*)es.ptr(di, 0);
+
+ const char *text = (const char *)getSegment(data.word(kTextfile1)).ptr(kTextstart, 0);
+ const char *found = searchForString(topic, text);
+ if (!found) {
+ text = (const char *)getSegment(data.word(kTextfile2)).ptr(kTextstart, 0);
+ found = searchForString(topic, text);
+ if (!found) {
+ text = (const char *)getSegment(data.word(kTextfile3)).ptr(kTextstart, 0);
+ found = searchForString(topic, text);
+ }
+ }
+
+ if (found) {
+ if (!getKeyAndLogo(found))
+ return;
+ } else {
+ monMessage(7);
+ return;
+ }
+
+ // "keyok2"
+ memcpy(data.ptr(kCurrentfile+1, 0), data.ptr(offset_operand1+1, 0), 12);
+ monitorLogo();
+ scrollMonitor();
+ monMessage(10);
+
+ byte curChar;
+ found += 1 + 2 + 1;
+
+ while (true) {
+ curChar = found[0];
+ found++;
+ if (curChar == 34 || curChar == '*') {
+ // "endofdir2"
+ scrollMonitor();
+ return;
+ }
+
+ if (curChar == '=')
+ found = monPrint(found);
+ }
+}
+
+void DreamGenContext::read() {
randomAccess(40);
const char *name = parser();
if (name[1] == 0) {
@@ -539,61 +553,45 @@ void DreamGenContext::read() {
return;
}
- es = cs;
- di = kCurrentfile;
+ const char *topic = (const char*)cs.ptr(kCurrentfile, 0);
- data.word(kMonsource) = data.word(kTextfile1);
- ds = data.word(kMonsource);
- si = kTextstart;
- searchForString();
- if (al == 0) {
- foundFile = true;
- } else {
- data.word(kMonsource) = data.word(kTextfile2);
- ds = data.word(kMonsource);
- si = kTextstart;
- searchForString();
- if (al == 0) {
- foundFile = true;
- } else {
- data.word(kMonsource) = data.word(kTextfile3);
- ds = data.word(kMonsource);
- si = kTextstart;
- searchForString();
- if (al == 0)
- foundFile = true;
+ const char *text = (const char *)getSegment(data.word(kTextfile1)).ptr(kTextstart, 0);
+ const char *found = searchForString(topic, text);
+ if (!found) {
+ text = (const char *)getSegment(data.word(kTextfile2)).ptr(kTextstart, 0);
+ found = searchForString(topic, text);
+ if (!found) {
+ text = (const char *)getSegment(data.word(kTextfile3)).ptr(kTextstart, 0);
+ found = searchForString(topic, text);
}
}
- if (!foundFile) {
+ if (found) {
+ if (!getKeyAndLogo(found))
+ return;
+ } else {
monMessage(7);
return;
}
- // "foundfile2"
- if (getKeyAndLogo())
- return;
-
// "keyok1"
- es = cs;
- di = offset_operand1;
- ds = data.word(kMonsource);
- searchForString();
- if (al != 0) {
+ topic = (const char*)cs.ptr(offset_operand1, 0);
+ found = searchForString(topic, found);
+ if (!found) {
data.byte(kLogonum) = data.byte(kOldlogonum);
monMessage(11);
return;
}
// "findtopictext"
- bx++;
-
monitorLogo();
scrollMonitor();
+ found++;
+
while (true) {
- monPrint();
- if (es.byte(bx) == 34 || es.byte(bx) == '=' || es.byte(bx) == '*') {
+ found = monPrint(found);
+ if (found[0] == 34 || found[0] == '=' || found[0] == '*') {
// "endoftopic"
scrollMonitor();
return;
@@ -715,45 +713,4 @@ const char *DreamBase::parser() {
return output;
}
-void DreamGenContext::searchForString() {
- const char *topic = (const char*)es.ptr(di, 0);
- const char *text = (const char*)ds.ptr(si, 0);
- const char *found = searchForString(topic, text);
- if (!found) {
- al = 1;
- } else {
- es = ds;
- bx = si + (found - text);
- si = bx;
- al = 0;
- }
-}
-
-// input: es:di : topic
-// ds:si : monitor text
-const char *DreamBase::searchForString(const char *topic, const char *text) {
- char delim = *topic;
-
- while (true) {
- const char *s = topic;
- int delimCount = 0;
-
- char c;
- do {
- c = makeCaps(*text++);
-
- if (c == '*' || (delim == '=' && c == 34))
- return 0;
-
- if (c == delim) {
- delimCount++;
- if (delimCount == 2)
- return text;
- }
-
- } while (c == *s++);
- }
-}
-
-
} // End of namespace DreamGen
diff --git a/engines/dreamweb/stubs.h b/engines/dreamweb/stubs.h
index ce2fefb615..79b708d7b3 100644
--- a/engines/dreamweb/stubs.h
+++ b/engines/dreamweb/stubs.h
@@ -90,10 +90,9 @@
bool execCommand();
void identifyOb();
void selectOb();
- bool getKeyAndLogo();
+ bool getKeyAndLogo(const char *foundString);
void read();
void dirCom();
- void searchForString();
const char *searchForString(const char *topic, const char *text) {
return DreamBase::searchForString(topic, text);
}