From b728323df751a0aec5aee890cdce52f50796b12a Mon Sep 17 00:00:00 2001 From: Bertrand Augereau Date: Sun, 17 Jul 2011 16:06:19 +0200 Subject: DREAMWEB: 'getnumber' ported to C++ --- engines/dreamweb/dreamgen.cpp | 109 ------------------------------------------ engines/dreamweb/dreamgen.h | 3 +- engines/dreamweb/stubs.cpp | 59 +++++++++++++++++++++++ engines/dreamweb/stubs.h | 2 + 4 files changed, 62 insertions(+), 111 deletions(-) (limited to 'engines/dreamweb') diff --git a/engines/dreamweb/dreamgen.cpp b/engines/dreamweb/dreamgen.cpp index 3c10ea69d1..1a3b6a2497 100644 --- a/engines/dreamweb/dreamgen.cpp +++ b/engines/dreamweb/dreamgen.cpp @@ -5233,114 +5233,6 @@ nottrigger2: data.byte(kKerning) = 0; } -void DreamGenContext::getnumber() { - STACK_CHECK; - cx = 0; - push(si); - push(bx); - push(di); - push(ds); - push(es); - di = si; -wordloop: - push(cx); - push(dx); - getnextword(); - dx = pop(); - cx = pop(); - _cmp(al, 1); - if (flags.z()) - goto endoftext; - al = cl; - ah = 0; - push(bx); - bh = 0; - _add(ax, bx); - bx = pop(); - _sub(ax, 10); - dh = 0; - _cmp(ax, dx); - if (!flags.c()) - goto gotoverend; - _add(cl, bl); - _add(ch, bh); - goto wordloop; -gotoverend: - al = dl; - _and(al, 1); - if (flags.z()) - goto notcentre; - push(cx); - al = dl; - _and(al, 0xfe); - ah = 0; - ch = 0; - _sub(ax, cx); - _add(ax, 20); - _shr(ax, 1); - cx = pop(); - es = pop(); - ds = pop(); - di = pop(); - bx = pop(); - si = pop(); - _add(di, ax); - cl = ch; - return; -notcentre: - es = pop(); - ds = pop(); - di = pop(); - bx = pop(); - si = pop(); - cl = ch; - return; -endoftext: - al = cl; - ah = 0; - push(bx); - bh = 0; - _add(ax, bx); - bx = pop(); - _sub(ax, 10); - dh = 0; - _cmp(ax, dx); - if (!flags.c()) - goto gotoverend2; - _add(cl, bl); - _add(ch, bh); -gotoverend2: - al = dl; - _and(al, 1); - if (flags.z()) - goto notcent2; - push(cx); - al = dl; - _and(al, 0xfe); - _add(al, 2); - ah = 0; - ch = 0; - _add(ax, 20); - _sub(ax, cx); - _shr(ax, 1); - cx = pop(); - es = pop(); - ds = pop(); - di = pop(); - bx = pop(); - si = pop(); - _add(di, ax); - cl = ch; - return; -notcent2: - es = pop(); - ds = pop(); - di = pop(); - bx = pop(); - si = pop(); - cl = ch; -} - void DreamGenContext::fillryan() { STACK_CHECK; es = data.word(kBuffers); @@ -21554,7 +21446,6 @@ void DreamGenContext::__dispatch_call(uint16 addr) { case addr_printboth: printboth(); break; case addr_printdirect: printdirect(); break; case addr_monprint: monprint(); break; - case addr_getnumber: getnumber(); break; case addr_fillryan: fillryan(); break; case addr_fillopen: fillopen(); break; case addr_findallryan: findallryan(); break; diff --git a/engines/dreamweb/dreamgen.h b/engines/dreamweb/dreamgen.h index 88ecfd53d4..782f4845fc 100644 --- a/engines/dreamweb/dreamgen.h +++ b/engines/dreamweb/dreamgen.h @@ -584,7 +584,6 @@ public: static const uint16 addr_findallryan = 0xc328; static const uint16 addr_fillopen = 0xc324; static const uint16 addr_fillryan = 0xc320; - static const uint16 addr_getnumber = 0xc318; static const uint16 addr_monprint = 0xc314; static const uint16 addr_printdirect = 0xc310; static const uint16 addr_printboth = 0xc30c; @@ -1535,7 +1534,7 @@ public: //void printsprites(); void checkifperson(); void showallobs(); - void getnumber(); + //void getnumber(); void adjustleft(); void calledenslift(); void useclearbox(); diff --git a/engines/dreamweb/stubs.cpp b/engines/dreamweb/stubs.cpp index cd5350823a..b68f7e67df 100644 --- a/engines/dreamweb/stubs.cpp +++ b/engines/dreamweb/stubs.cpp @@ -271,6 +271,65 @@ void DreamGenContext::getnextword() { bh = charCount; } +void DreamGenContext::getnumber() { + cl = getnumber(dl, (bool)(dl & 1)); +} + +uint8 DreamGenContext::getnumber(uint16 maxWidth, bool centered) { + uint8 totalWidth = 0; + uint8 charCount = 0; + push(si); + push(bx); + push(di); + push(ds); + push(es); + di = si; + while (true) { + uint8 wordTotalWidth, wordCharCount; + uint8 done = getnextword(&wordTotalWidth, &wordCharCount); + + if (done == 1) { //endoftext + ax = totalWidth + wordTotalWidth - 10; + if (ax < maxWidth) { + totalWidth += wordTotalWidth; + charCount += wordCharCount; + } + + if (centered) { + ax = (maxWidth & 0xfe) + 2 + 20 - totalWidth; + ax /= 2; + } else { + ax = 0; + } + es = pop(); + ds = pop(); + di = pop(); + bx = pop(); + si = pop(); + _add(di, ax); + return charCount; + } + ax = totalWidth + wordTotalWidth - 10; + if (ax >= maxWidth) { //gotoverend + if (centered) { + ax = (maxWidth & 0xfe) - totalWidth + 20; + ax /= 2; + } else { + ax = 0; + } + es = pop(); + ds = pop(); + di = pop(); + bx = pop(); + si = pop(); + _add(di, ax); + return charCount; + } + totalWidth += wordTotalWidth; + charCount += wordCharCount; + } +} + uint8 DreamGenContext::kernchars(uint8 firstChar, uint8 secondChar, uint8 width) { if ((firstChar == 'a') || (al == 'u')) { if ((secondChar == 'n') || (secondChar == 't') || (secondChar == 'r') || (secondChar == 'i') || (secondChar == 'l')) diff --git a/engines/dreamweb/stubs.h b/engines/dreamweb/stubs.h index 6d9c08dd2d..b882172b4c 100644 --- a/engines/dreamweb/stubs.h +++ b/engines/dreamweb/stubs.h @@ -38,6 +38,8 @@ void quickquit2(); void getnextword(); uint8 getnextword(uint8 *totalWidth, uint8 *charCount); + void getnumber(); + uint8 getnumber(uint16 maxWidth, bool centered); void kernchars(); uint8 kernchars(uint8 firstChar, uint8 secondChar, uint8 width); Sprite *spritetable(); -- cgit v1.2.3