2011-06-15 21:03:00 +00:00
|
|
|
#include "dreamweb/dreamweb.h"
|
|
|
|
#include "engines/util.h"
|
|
|
|
#include "graphics/surface.h"
|
|
|
|
|
2011-06-16 12:31:17 +00:00
|
|
|
namespace DreamGen {
|
2011-06-15 21:03:00 +00:00
|
|
|
|
|
|
|
Common::String getFilename(Context &context) {
|
|
|
|
uint16 name_ptr = context.dx;
|
|
|
|
Common::String name;
|
|
|
|
uint8 c;
|
|
|
|
while((c = context.cs.byte(name_ptr++)) != 0)
|
|
|
|
name += (char)c;
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::multiget() {
|
|
|
|
unsigned w = (uint8)cl, h = (uint8)ch;
|
|
|
|
unsigned x = (uint16)di, y = (uint16)bx;
|
2011-06-15 21:03:00 +00:00
|
|
|
unsigned src = x + y * kScreenwidth;
|
2011-06-16 20:30:39 +00:00
|
|
|
unsigned dst = (uint16)si;
|
|
|
|
es = ds;
|
|
|
|
ds = data.word(kWorkspace);
|
2011-06-15 21:03:00 +00:00
|
|
|
if (y + h > 200)
|
|
|
|
h = 200 - y;
|
|
|
|
if (x + w > 320)
|
|
|
|
w = 320 - x;
|
2011-06-16 20:30:39 +00:00
|
|
|
//debug(1, "multiget %u,%u %ux%u -> segment: %04x->%04x", x, y, w, h, (uint16)ds, (uint16)es);
|
2011-06-15 21:03:00 +00:00
|
|
|
for(unsigned l = 0; l < h; ++l) {
|
2011-06-16 20:30:39 +00:00
|
|
|
uint8 *src_p = ds.ptr(src + kScreenwidth * l, w);
|
|
|
|
uint8 *dst_p = es.ptr(dst + w * l, w);
|
2011-06-15 21:03:00 +00:00
|
|
|
memcpy(dst_p, src_p, w);
|
|
|
|
}
|
2011-06-16 20:30:39 +00:00
|
|
|
si += w * h;
|
|
|
|
di = src + kScreenwidth * h;
|
|
|
|
cx = 0;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::multiput() {
|
|
|
|
unsigned w = (uint8)cl, h = (uint8)ch;
|
|
|
|
unsigned x = (uint16)di, y = (uint16)bx;
|
|
|
|
unsigned src = (uint16)si;
|
2011-06-15 21:03:00 +00:00
|
|
|
unsigned dst = x + y * kScreenwidth;
|
2011-06-16 20:30:39 +00:00
|
|
|
es = data.word(kWorkspace);
|
2011-06-15 21:03:00 +00:00
|
|
|
if (y + h > 200)
|
|
|
|
h = 200 - y;
|
|
|
|
if (x + w > 320)
|
|
|
|
w = 320 - x;
|
2011-06-16 20:30:39 +00:00
|
|
|
//debug(1, "multiput %ux%u -> segment: %04x->%04x", w, h, (uint16)ds, (uint16)es);
|
2011-06-15 21:03:00 +00:00
|
|
|
for(unsigned l = 0; l < h; ++l) {
|
2011-06-16 20:30:39 +00:00
|
|
|
uint8 *src_p = ds.ptr(src + w * l, w);
|
|
|
|
uint8 *dst_p = es.ptr(dst + kScreenwidth * l, w);
|
2011-06-15 21:03:00 +00:00
|
|
|
memcpy(dst_p, src_p, w);
|
|
|
|
}
|
2011-06-16 20:30:39 +00:00
|
|
|
si += w * h;
|
|
|
|
di = dst + kScreenwidth * h;
|
|
|
|
cx = 0;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::multidump() {
|
|
|
|
ds = data.word(kWorkspace);
|
|
|
|
int w = (uint8)cl, h = (uint8)ch;
|
|
|
|
int x = (int16)di, y = (int16)bx;
|
2011-06-15 21:03:00 +00:00
|
|
|
unsigned offset = x + y * kScreenwidth;
|
2011-06-16 20:30:39 +00:00
|
|
|
//debug(1, "multidump %ux%u(segment: %04x) -> %d,%d(address: %d)", w, h, (uint16)ds, x, y, offset);
|
|
|
|
engine->blit(ds.ptr(offset, w * h), kScreenwidth, x, y, w, h);
|
|
|
|
si = di = offset + h * kScreenwidth;
|
|
|
|
cx = 0;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::worktoscreen() {
|
|
|
|
ds = data.word(kWorkspace);
|
2011-06-15 21:03:00 +00:00
|
|
|
uint size = 320 * 200;
|
2011-06-16 20:30:39 +00:00
|
|
|
engine->blit(ds.ptr(0, size), 320, 0, 0, 320, 200);
|
|
|
|
di = si = size;
|
|
|
|
cx = 0;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::printundermon() {
|
|
|
|
engine->printUnderMonitor();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::cls() {
|
|
|
|
engine->cls();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-26 15:03:17 +00:00
|
|
|
void DreamGenContext::frameoutnm(uint8* dst, const uint8* src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) {
|
|
|
|
dst += pitch * y + x;
|
|
|
|
|
|
|
|
for (uint16 j = 0; j < height; ++j) {
|
|
|
|
memcpy(dst, src, width);
|
|
|
|
dst += pitch;
|
|
|
|
src += width;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-26 17:32:02 +00:00
|
|
|
void DreamGenContext::frameoutbh(uint8* dst, const uint8* src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) {
|
|
|
|
uint16 stride = pitch - width;
|
|
|
|
dst += y * pitch + x;
|
|
|
|
|
|
|
|
for (uint16 i = 0; i < height; ++i) {
|
|
|
|
for (uint16 j = 0; j < width; ++j) {
|
|
|
|
if (*dst == 0xff) {
|
|
|
|
*dst = *src;
|
|
|
|
}
|
|
|
|
++src;
|
|
|
|
++dst;
|
|
|
|
}
|
|
|
|
dst += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::frameoutfx(uint8* dst, const uint8* src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) {
|
|
|
|
uint16 stride = pitch - width;
|
|
|
|
dst += y * pitch + x;
|
|
|
|
dst -= width;
|
|
|
|
|
|
|
|
for (uint16 j = 0; j < height; ++j) {
|
|
|
|
for (uint16 i = 0; i < width; ++i) {
|
|
|
|
uint8 pixel = src[width - i - 1];
|
|
|
|
if (pixel)
|
|
|
|
*dst = pixel;
|
|
|
|
++dst;
|
|
|
|
}
|
|
|
|
src += width;
|
|
|
|
dst += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::seecommandtail() {
|
|
|
|
data.word(kSoundbaseadd) = 0x220;
|
|
|
|
data.byte(kSoundint) = 5;
|
|
|
|
data.byte(kSounddmachannel) = 1;
|
|
|
|
data.byte(kBrightness) = 1;
|
|
|
|
data.word(kHowmuchalloc) = 0x9360;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::randomnumber() {
|
|
|
|
al = engine->randomNumber();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::quickquit() {
|
|
|
|
engine->quit();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::quickquit2() {
|
|
|
|
engine->quit();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::keyboardread() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("keyboardread"); //this keyboard int handler, must never be called
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::resetkeyboard() {
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::setkeyboardint() {
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::readfromfile() {
|
|
|
|
uint16 dst_offset = dx;
|
|
|
|
uint16 size = cx;
|
|
|
|
debug(1, "readfromfile(%04x:%u, %u)", (uint16)ds, dst_offset, size);
|
|
|
|
ax = engine->readFromFile(ds.ptr(dst_offset, size), size);
|
|
|
|
flags._c = false;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::closefile() {
|
|
|
|
engine->closeFile();
|
|
|
|
data.byte(kHandle) = 0;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::openforsave() {
|
|
|
|
const char *name = (const char *)ds.ptr(dx, 13);
|
2011-06-15 21:03:00 +00:00
|
|
|
debug(1, "openforsave(%s)", name);
|
2011-06-16 20:30:39 +00:00
|
|
|
engine->openSaveFileForWriting(name);
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::openfilenocheck() {
|
|
|
|
const char *name = (const char *)ds.ptr(dx, 13);
|
2011-06-15 21:03:00 +00:00
|
|
|
debug(1, "checksavefile(%s)", name);
|
2011-06-16 20:30:39 +00:00
|
|
|
bool ok = engine->openSaveFileForReading(name);
|
|
|
|
flags._c = !ok;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::openfilefromc() {
|
|
|
|
openfilenocheck();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::openfile() {
|
|
|
|
Common::String name = getFilename(*this);
|
2011-06-15 21:03:00 +00:00
|
|
|
debug(1, "opening file: %s", name.c_str());
|
2011-06-16 20:30:39 +00:00
|
|
|
engine->openFile(name);
|
|
|
|
cs.word(kHandle) = 1; //only one handle
|
|
|
|
flags._c = false;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::createfile() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("createfile");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::dontloadseg() {
|
|
|
|
ax = es.word(di);
|
|
|
|
_add(di, 2);
|
|
|
|
dx = ax;
|
|
|
|
cx = 0;
|
|
|
|
unsigned pos = engine->skipBytes(dx);
|
|
|
|
dx = pos >> 16;
|
|
|
|
ax = pos & 0xffff;
|
|
|
|
flags._c = false;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::mousecall() {
|
|
|
|
engine->mouseCall();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::setmouse() {
|
|
|
|
data.word(kOldpointerx) = 0xffff;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::gettime() {
|
2011-06-15 21:03:00 +00:00
|
|
|
TimeDate t;
|
|
|
|
g_system->getTimeAndDate(t);
|
|
|
|
debug(1, "\tgettime: %02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec);
|
2011-06-16 20:30:39 +00:00
|
|
|
ch = t.tm_hour;
|
|
|
|
cl = t.tm_min;
|
|
|
|
dh = t.tm_sec;
|
|
|
|
data.byte(kSecondcount) = dh;
|
|
|
|
data.byte(kMinutecount) = cl;
|
|
|
|
data.byte(kHourcount) = ch;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::allocatemem() {
|
|
|
|
uint size = (bx + 2) * 16;
|
2011-06-15 21:03:00 +00:00
|
|
|
debug(1, "allocate mem, %u bytes", size);
|
2011-06-16 20:30:39 +00:00
|
|
|
flags._c = false;
|
|
|
|
SegmentRef seg = allocateSegment(size);
|
|
|
|
ax = (uint16)seg;
|
|
|
|
debug(1, "\tsegment address -> %04x", (uint16)ax);
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::deallocatemem() {
|
|
|
|
uint16 id = (uint16)es;
|
2011-06-15 21:03:00 +00:00
|
|
|
debug(1, "deallocating segment %04x", id);
|
2011-06-16 20:30:39 +00:00
|
|
|
deallocateSegment(id);
|
2011-06-15 21:03:00 +00:00
|
|
|
|
|
|
|
//fixing invalid entries in the sprite table
|
2011-06-16 20:30:39 +00:00
|
|
|
es = data;
|
2011-06-15 21:03:00 +00:00
|
|
|
uint tsize = 16 * 32;
|
2011-06-16 20:30:39 +00:00
|
|
|
uint16 bseg = data.word(kBuffers);
|
2011-06-15 21:03:00 +00:00
|
|
|
if (!bseg)
|
|
|
|
return;
|
2011-06-16 20:30:39 +00:00
|
|
|
SegmentRef buffers(this);
|
2011-06-15 21:03:00 +00:00
|
|
|
buffers = bseg;
|
|
|
|
uint8 *ptr = buffers.ptr(kSpritetable, tsize);
|
|
|
|
for(uint i = 0; i < tsize; i += 32) {
|
|
|
|
uint16 seg = READ_LE_UINT16(ptr + i + 6);
|
|
|
|
//debug(1, "sprite segment = %04x", seg);
|
|
|
|
if (seg == id)
|
|
|
|
memset(ptr + i, 0xff, 32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::removeemm() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("removeemm");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::setupemm() {
|
2011-06-25 14:20:19 +00:00
|
|
|
//good place for early initialization
|
|
|
|
switch(engine->getLanguage()) {
|
|
|
|
case Common::EN_ANY:
|
|
|
|
case Common::EN_GRB:
|
|
|
|
case Common::EN_USA:
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
data.byte(kForeignrelease) = 1;
|
|
|
|
}
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::pitinterupt() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("pitinterupt");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::getridofpit() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("getridofpit");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::setuppit() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("setuppit");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::startdmablock() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("startdmablock");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::dmaend() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("dmaend");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::restoreems() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("restoreems");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::saveems() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("saveems");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::bothchannels() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("bothchannels");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::channel1only() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("channel1only");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::channel0only() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("channel0only");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::out22c() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("out22c");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::soundstartup() {}
|
|
|
|
void DreamGenContext::soundend() {}
|
2011-06-19 13:19:02 +00:00
|
|
|
void DreamGenContext::interupttest() {}
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::disablesoundint() {}
|
|
|
|
void DreamGenContext::enablesoundint() {}
|
|
|
|
void DreamGenContext::checksoundint() {
|
|
|
|
data.byte(kTestresult) = 1;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::setsoundoff() {
|
2011-06-15 21:03:00 +00:00
|
|
|
warning("setsoundoff: STUB");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::loadsample() {
|
|
|
|
engine->loadSounds(0, (const char *)data.ptr(dx, 13));
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::loadsecondsample() {
|
|
|
|
uint8 ch0 = data.byte(kCh0playing);
|
2011-06-15 21:03:00 +00:00
|
|
|
if (ch0 >= 12 && ch0 != 255)
|
2011-06-16 20:30:39 +00:00
|
|
|
cancelch0();
|
|
|
|
uint8 ch1 = data.byte(kCh1playing);
|
2011-06-15 21:03:00 +00:00
|
|
|
if (ch1 >= 12)
|
2011-06-16 20:30:39 +00:00
|
|
|
cancelch1();
|
|
|
|
engine->loadSounds(1, (const char *)data.ptr(dx, 13));
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::loadspeech() {
|
|
|
|
cancelch1();
|
|
|
|
data.byte(kSpeechloaded) = 0;
|
|
|
|
createname();
|
|
|
|
const char *name = (const char *)data.ptr(di, 13);
|
2011-06-15 21:03:00 +00:00
|
|
|
//warning("name = %s", name);
|
2011-06-16 20:30:39 +00:00
|
|
|
if (engine->loadSpeech(name))
|
|
|
|
data.byte(kSpeechloaded) = 1;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::saveseg() {
|
|
|
|
cx = es.word(di);
|
|
|
|
_add(di, 2);
|
|
|
|
savefilewrite();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::savefilewrite() {
|
|
|
|
ax = engine->writeToSaveFile(ds.ptr(dx, cx), cx);
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::savefileread() {
|
|
|
|
ax = engine->readFromSaveFile(ds.ptr(dx, cx), cx);
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::loadseg() {
|
|
|
|
ax = es.word(di);
|
|
|
|
di += 2;
|
2011-06-15 21:03:00 +00:00
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
uint16 dst_offset = dx;
|
|
|
|
uint16 size = ax;
|
2011-06-15 21:03:00 +00:00
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
debug(1, "loadseg(%04x:%u, %u)", (uint16)ds, dst_offset, size);
|
|
|
|
ax = engine->readFromFile(ds.ptr(dst_offset, size), size);
|
|
|
|
flags._c = false;
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::error() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("error");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::generalerror() {
|
2011-06-15 21:03:00 +00:00
|
|
|
::error("generalerror");
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::dosreturn() {
|
2011-06-19 11:24:31 +00:00
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
_cmp(data.byte(kCommandtype), 250);
|
2011-06-18 09:33:24 +00:00
|
|
|
if (!flags.z()) {
|
|
|
|
data.byte(kCommandtype) = 250;
|
|
|
|
al = 46;
|
|
|
|
commandonly();
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
ax = data.word(kMousebutton);
|
|
|
|
_and(ax, 1);
|
2011-06-19 22:59:48 +00:00
|
|
|
if (flags.z())
|
2011-06-18 09:33:24 +00:00
|
|
|
return;
|
2011-06-15 21:03:00 +00:00
|
|
|
|
2011-06-18 09:33:24 +00:00
|
|
|
data.word(kMousebutton) = 0;
|
|
|
|
engine->quit();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-18 10:29:10 +00:00
|
|
|
void DreamGenContext::set16colpalette() {
|
|
|
|
//fixme: this is a bit hackish, set16colpalette called after initialization and nearly before main loop.
|
|
|
|
engine->enableSavingOrLoading();
|
|
|
|
}
|
2011-06-15 21:03:00 +00:00
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::mode640x480() {
|
2011-06-15 21:03:00 +00:00
|
|
|
// Video mode 12h: 640x480 pixels, 16 colors, I believe
|
2011-06-16 20:30:39 +00:00
|
|
|
al = 0x12 + 128;
|
|
|
|
ah = 0;
|
2011-06-15 21:03:00 +00:00
|
|
|
initGraphics(640, 480, true);
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::showgroup() {
|
|
|
|
engine->setPalette();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::fadedos() {
|
|
|
|
engine->fadeDos();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::doshake() {
|
|
|
|
uint8 &counter = data.byte(kShakecounter);
|
|
|
|
_cmp(counter, 48);
|
|
|
|
if (flags.z())
|
2011-06-15 21:03:00 +00:00
|
|
|
return;
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
_add(counter, 1);
|
2011-06-15 21:03:00 +00:00
|
|
|
static const int shakeTable[] = {
|
|
|
|
0, -2, 3, -2, 0, 2, 4, -1,
|
|
|
|
1, -3, 3, 2, 0, -2, 3, -2,
|
|
|
|
0, 2, 4, -1, 1, -3, 3, 2,
|
|
|
|
0, -2, 3, -2, 0, 2, 4, -1,
|
|
|
|
|
|
|
|
1, -3, 3, 2, 0, -2, 3, -2,
|
|
|
|
0, 2, 4, -1, 1, -3, 3, 2,
|
|
|
|
0, -2, 3, -2, 0, 2, 4, -1,
|
|
|
|
1, -3, 3, 2, 0, -2, 3, -2,
|
|
|
|
|
|
|
|
0, 2, 4, -1, 1, -3, 3, 2,
|
|
|
|
0, -2, 3, -2, 0, 2, 4, -1,
|
|
|
|
1, -3, 3, 2, 0, -2, 3, -2,
|
|
|
|
0, 2, 4, -1, 1, -3, 3, 2,
|
|
|
|
|
|
|
|
0, -2, 3, -2, 0, 2, 4, -1,
|
|
|
|
1, -3, 3, 0,
|
|
|
|
};
|
|
|
|
int offset = shakeTable[counter];
|
2011-06-16 20:30:39 +00:00
|
|
|
engine->setShakePos(offset >= 0? offset: -offset);
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::vsync() {
|
2011-06-25 17:51:27 +00:00
|
|
|
push(ax);
|
|
|
|
push(bx);
|
|
|
|
push(cx);
|
|
|
|
push(dx);
|
|
|
|
push(si);
|
|
|
|
push(di);
|
|
|
|
push(es);
|
|
|
|
push(ds);
|
2011-06-16 20:30:39 +00:00
|
|
|
engine->waitForVSync();
|
2011-06-25 17:51:27 +00:00
|
|
|
ds = pop();
|
|
|
|
es = pop();
|
|
|
|
di = pop();
|
|
|
|
si = pop();
|
|
|
|
dx = pop();
|
|
|
|
cx = pop();
|
|
|
|
bx = pop();
|
|
|
|
ax = pop();
|
2011-06-15 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::setmode() {
|
|
|
|
vsync();
|
2011-06-15 21:03:00 +00:00
|
|
|
initGraphics(320, 200, false);
|
|
|
|
}
|
|
|
|
|
2011-06-16 20:30:39 +00:00
|
|
|
void DreamGenContext::showpcx() {
|
|
|
|
Common::String name = getFilename(*this);
|
2011-06-15 21:03:00 +00:00
|
|
|
Common::File pcxFile;
|
|
|
|
|
|
|
|
if (!pcxFile.open(name)) {
|
|
|
|
warning("showpcx: Could not open '%s'", name.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 *maingamepal;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
// Read the 16-color palette into the 'maingamepal' buffer. Note that
|
|
|
|
// the color components have to be adjusted from 8 to 6 bits.
|
|
|
|
|
|
|
|
pcxFile.seek(16, SEEK_SET);
|
2011-06-16 20:30:39 +00:00
|
|
|
es = data.word(kBuffers);
|
2011-06-20 18:16:21 +00:00
|
|
|
maingamepal = es.ptr(kMaingamepal, 768);
|
2011-06-15 21:03:00 +00:00
|
|
|
pcxFile.read(maingamepal, 48);
|
|
|
|
|
|
|
|
memset(maingamepal + 48, 0xff, 720);
|
|
|
|
for (i = 0; i < 48; i++) {
|
|
|
|
maingamepal[i] >>= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode the image data.
|
|
|
|
|
|
|
|
Graphics::Surface *s = g_system->lockScreen();
|
|
|
|
Common::Rect rect(640, 480);
|
|
|
|
|
|
|
|
s->fillRect(rect, 0);
|
|
|
|
pcxFile.seek(128, SEEK_SET);
|
|
|
|
|
|
|
|
for (int y = 0; y < 480; y++) {
|
|
|
|
byte *dst = (byte *)s->getBasePtr(0, y);
|
|
|
|
int decoded = 0;
|
|
|
|
|
|
|
|
while (decoded < 320) {
|
|
|
|
byte col = pcxFile.readByte();
|
|
|
|
byte len;
|
|
|
|
|
|
|
|
if ((col & 0xc0) == 0xc0) {
|
|
|
|
len = col & 0x3f;
|
|
|
|
col = pcxFile.readByte();
|
|
|
|
} else {
|
|
|
|
len = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The image uses 16 colors and is stored as four bit
|
|
|
|
// planes, one for each bit of the color, least
|
|
|
|
// significant bit plane first.
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
int plane = decoded / 80;
|
|
|
|
int pos = decoded % 80;
|
|
|
|
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
byte bit = (col >> (7 - j)) & 1;
|
|
|
|
dst[8 * pos + j] |= (bit << plane);
|
|
|
|
}
|
|
|
|
|
|
|
|
decoded++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_system->unlockScreen();
|
|
|
|
pcxFile.close();
|
|
|
|
}
|
|
|
|
|
2011-06-26 15:03:17 +00:00
|
|
|
/*
|
2011-06-22 21:11:44 +00:00
|
|
|
void DreamGenContext::frameoutv() {
|
|
|
|
uint16 pitch = dx;
|
|
|
|
uint16 width = cx & 0xff;
|
|
|
|
uint16 height = cx >> 8;
|
|
|
|
|
|
|
|
const uint8* src = ds.ptr(si, width * height);
|
2011-06-26 15:03:17 +00:00
|
|
|
uint8* dst = es.ptr(0, pitch * height);
|
2011-06-26 13:17:19 +00:00
|
|
|
|
2011-06-26 15:03:17 +00:00
|
|
|
frameoutv(dst, src, pitch, width, height, di, bx);
|
2011-06-26 13:17:19 +00:00
|
|
|
}
|
2011-06-26 15:03:17 +00:00
|
|
|
*/
|
2011-06-26 13:17:19 +00:00
|
|
|
|
2011-06-26 15:03:17 +00:00
|
|
|
void DreamGenContext::frameoutv(uint8* dst, const uint8* src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) {
|
2011-07-16 18:23:27 +00:00
|
|
|
// NB : These resilience checks were not in the original engine, but did they result in undefined behaviour
|
|
|
|
// or was something broken during porting to C++?
|
|
|
|
assert(pitch == 320);
|
|
|
|
|
|
|
|
if(x >= 320)
|
|
|
|
return;
|
|
|
|
if(y >= 200)
|
|
|
|
return;
|
|
|
|
if(x + width > 320) {
|
|
|
|
width = 320 - x;
|
|
|
|
}
|
|
|
|
if(y + height > 200) {
|
|
|
|
height = 200 - y;
|
|
|
|
}
|
|
|
|
|
2011-06-26 13:17:19 +00:00
|
|
|
uint16 stride = pitch - width;
|
2011-06-26 15:03:17 +00:00
|
|
|
dst += pitch * y + x;
|
2011-06-22 21:11:44 +00:00
|
|
|
|
2011-06-26 15:03:17 +00:00
|
|
|
for (uint16 j = 0; j < height; ++j) {
|
|
|
|
for (uint16 i = 0; i < width; ++i) {
|
2011-06-22 21:11:44 +00:00
|
|
|
uint8 pixel = *src++;
|
|
|
|
if (pixel)
|
|
|
|
*dst = pixel;
|
|
|
|
++dst;
|
|
|
|
}
|
|
|
|
dst += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-26 13:17:19 +00:00
|
|
|
Sprite* DreamGenContext::spritetable() {
|
|
|
|
push(es);
|
|
|
|
push(bx);
|
|
|
|
|
|
|
|
es = data.word(kBuffers);
|
|
|
|
bx = kSpritetable;
|
|
|
|
Sprite *sprite = (Sprite*)es.ptr(bx, 16*sizeof(Sprite));
|
|
|
|
|
|
|
|
bx = pop();
|
|
|
|
es = pop();
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
2011-06-26 15:03:17 +00:00
|
|
|
uint16 DreamGenContext::showframeCPP(uint16 dst, uint16 src, uint16 x, uint16 y, uint8 frameNumber, uint8 effectsFlag) {
|
|
|
|
es = dst;
|
|
|
|
ds = src;
|
|
|
|
di = x;
|
|
|
|
bx = y;
|
|
|
|
al = frameNumber;
|
|
|
|
ah = effectsFlag;
|
|
|
|
|
|
|
|
si = (ax & 0x1ff) * 6;
|
|
|
|
if (ds.word(si) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//notblankshow:
|
|
|
|
if ((effectsFlag & 128) == 0) {
|
|
|
|
di += ds.byte(si+4);
|
|
|
|
bx += ds.byte(si+5);
|
|
|
|
}
|
|
|
|
//skipoffsets:
|
|
|
|
cx = ds.word(si+0);
|
|
|
|
uint8 width = cl;
|
|
|
|
uint8 height = ch;
|
|
|
|
uint16 written = cx;
|
|
|
|
si = ds.word(si+2) + 2080;
|
|
|
|
|
|
|
|
if (effectsFlag) {
|
|
|
|
if (effectsFlag & 128) { //centred
|
|
|
|
di -= width / 2;
|
|
|
|
bx -= height / 2;
|
|
|
|
}
|
|
|
|
if (effectsFlag & 64) { //diffdest
|
2011-06-26 17:32:02 +00:00
|
|
|
frameoutfx(es.ptr(0, dx * height), ds.ptr(si, width * height), dx, width, height, di, bx);
|
2011-06-26 15:03:17 +00:00
|
|
|
return written;
|
|
|
|
}
|
|
|
|
if (effectsFlag & 8) { //printlist
|
|
|
|
push(ax);
|
|
|
|
ax = di - data.word(kMapadx);
|
|
|
|
push(bx);
|
|
|
|
bx -= data.word(kMapady);
|
|
|
|
ah = bl;
|
|
|
|
bx = pop();
|
|
|
|
//addtoprintlist(); // NB: Commented in the original asm
|
|
|
|
ax = pop();
|
|
|
|
}
|
|
|
|
if (effectsFlag & 4) { //flippedx
|
|
|
|
es = data.word(kWorkspace);
|
2011-06-26 17:32:02 +00:00
|
|
|
frameoutfx(es.ptr(0, 320 * height), ds.ptr(si, width * height), 320, width, height, di, bx);
|
2011-06-26 15:03:17 +00:00
|
|
|
return written;
|
|
|
|
}
|
|
|
|
if (effectsFlag & 2) { //nomask
|
|
|
|
es = data.word(kWorkspace);
|
|
|
|
frameoutnm(es.ptr(0, 320 * height), ds.ptr(si, width * height), 320, width, height, di, bx);
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
if (effectsFlag & 32) {
|
|
|
|
es = data.word(kWorkspace);
|
2011-06-26 17:32:02 +00:00
|
|
|
frameoutbh(es.ptr(0, 320 * height), ds.ptr(si, width * height), 320, width, height, di, bx);
|
2011-06-26 15:03:17 +00:00
|
|
|
return written;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//noeffects:
|
|
|
|
es = data.word(kWorkspace);
|
2011-07-16 18:23:27 +00:00
|
|
|
frameoutv(es.ptr(0, 65536), ds.ptr(si, width * height), 320, width, height, di, bx);
|
2011-06-26 15:03:17 +00:00
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::showframe() {
|
|
|
|
cx = showframeCPP(es, ds, di, bx, al, ah);
|
|
|
|
}
|
|
|
|
|
2011-06-26 13:17:19 +00:00
|
|
|
void DreamGenContext::printsprites() {
|
|
|
|
for (size_t priority = 0; priority < 7; ++priority) {
|
|
|
|
Sprite *sprites = spritetable();
|
|
|
|
for (size_t j = 0; j < 16; ++j) {
|
|
|
|
const Sprite &sprite = sprites[j];
|
|
|
|
if (READ_LE_UINT16(&sprite.updateCallback) == 0x0ffff)
|
|
|
|
continue;
|
|
|
|
if (priority != sprite.priority)
|
|
|
|
continue;
|
|
|
|
if (sprite.hidden == 1)
|
|
|
|
continue;
|
|
|
|
printasprite(&sprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::printasprite(const Sprite* sprite) {
|
|
|
|
push(es);
|
|
|
|
push(bx);
|
|
|
|
ds = READ_LE_UINT16(&sprite->w6);
|
|
|
|
ax = sprite->y;
|
|
|
|
if (al >= 220) {
|
|
|
|
bx = data.word(kMapady) - (256 - al);
|
|
|
|
} else {
|
|
|
|
bx = ax + data.word(kMapady);
|
|
|
|
}
|
|
|
|
|
|
|
|
ax = sprite->x;
|
|
|
|
if (al >= 220) {
|
|
|
|
di = data.word(kMapadx) - (256 - al);
|
|
|
|
} else {
|
|
|
|
di = ax + data.word(kMapadx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ax = sprite->b15;
|
2011-06-28 12:37:46 +00:00
|
|
|
if (sprite->b29 != 0)
|
2011-06-26 13:17:19 +00:00
|
|
|
ah = 8;
|
2011-06-26 15:03:17 +00:00
|
|
|
showframe();
|
2011-06-26 13:17:19 +00:00
|
|
|
|
|
|
|
bx = pop();
|
|
|
|
es = pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::eraseoldobs() {
|
|
|
|
if (data.byte(kNewobs) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Sprite *sprites = spritetable();
|
|
|
|
for (size_t i=0; i<16; ++i) {
|
|
|
|
Sprite &sprite = sprites[i];
|
|
|
|
if (READ_LE_UINT16(&sprite.obj_data) != 0xffff) {
|
|
|
|
memset(&sprite, 0xff, sizeof(Sprite));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::clearsprites() {
|
|
|
|
memset(spritetable(), 0xff, sizeof(Sprite)*16);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sprite* DreamGenContext::makesprite(uint8 x, uint8 y, uint16 updateCallback, uint16 somethingInDx, uint16 somethingInDi) {
|
|
|
|
Sprite *sprite = spritetable();
|
|
|
|
while (sprite->b15 != 0xff) { // NB: No boundchecking in the original code either
|
|
|
|
++sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
WRITE_LE_UINT16(&sprite->updateCallback, updateCallback);
|
|
|
|
sprite->x = x;
|
|
|
|
sprite->y = y;
|
|
|
|
WRITE_LE_UINT16(&sprite->w6, somethingInDx);
|
|
|
|
WRITE_LE_UINT16(&sprite->w8, somethingInDi);
|
|
|
|
sprite->w2 = 0xffff;
|
|
|
|
sprite->b15 = 0;
|
2011-06-27 06:53:39 +00:00
|
|
|
sprite->delay = 0;
|
2011-06-26 13:17:19 +00:00
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::makesprite() { // NB: returns new sprite in es:bx
|
|
|
|
Sprite *sprite = makesprite(si & 0xff, si >> 8, cx, dx, di);
|
|
|
|
|
|
|
|
// Recover es:bx from sprite
|
|
|
|
es = data.word(kBuffers);
|
|
|
|
bx = kSpritetable;
|
|
|
|
Sprite *sprites = (Sprite*)es.ptr(bx, sizeof(Sprite)*16);
|
|
|
|
bx += sizeof(Sprite)*(sprite-sprites);
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::spriteupdate() {
|
|
|
|
Sprite *sprites = spritetable();
|
|
|
|
sprites[0].hidden = data.byte(kRyanon);
|
|
|
|
|
|
|
|
Sprite *sprite = sprites;
|
|
|
|
for (size_t i=0; i<16; ++i) {
|
|
|
|
uint16 updateCallback = READ_LE_UINT16(&sprite->updateCallback);
|
|
|
|
if (updateCallback != 0xffff) {
|
|
|
|
sprite->w24 = sprite->w2;
|
|
|
|
if (updateCallback == addr_mainman) // NB : Let's consider the callback as an enum while more code is not ported to C++
|
|
|
|
mainmanCPP(sprite);
|
|
|
|
else {
|
|
|
|
assert(updateCallback == addr_backobject);
|
2011-06-27 06:53:39 +00:00
|
|
|
backobject(sprite);
|
2011-06-26 13:17:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.byte(kNowinnewroom) == 1)
|
|
|
|
break;
|
|
|
|
++sprite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 13:48:07 +00:00
|
|
|
void DreamGenContext::initman() {
|
|
|
|
Sprite *sprite = makesprite(data.byte(kRyanx), data.byte(kRyany), addr_mainman, data.word(kMainsprites), 0);
|
|
|
|
sprite->priority = 4;
|
|
|
|
sprite->b22 = 0;
|
|
|
|
sprite->b29 = 0;
|
|
|
|
|
|
|
|
// Recover es:bx from sprite
|
|
|
|
es = data.word(kBuffers);
|
|
|
|
bx = kSpritetable;
|
|
|
|
Sprite *sprites = (Sprite*)es.ptr(bx, sizeof(Sprite)*16);
|
|
|
|
bx += 32*(sprite-sprites);
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2011-06-26 13:17:19 +00:00
|
|
|
void DreamGenContext::mainmanCPP(Sprite* sprite) {
|
|
|
|
push(es);
|
|
|
|
push(ds);
|
|
|
|
|
|
|
|
// Recover es:bx from sprite
|
|
|
|
es = data.word(kBuffers);
|
|
|
|
bx = kSpritetable;
|
|
|
|
Sprite *sprites = (Sprite*)es.ptr(bx, sizeof(Sprite)*16);
|
|
|
|
bx += 32*(sprite-sprites);
|
|
|
|
//
|
|
|
|
|
2011-06-28 12:37:46 +00:00
|
|
|
if (data.byte(kResetmanxy) == 1) {
|
|
|
|
data.byte(kResetmanxy) = 0;
|
|
|
|
sprite->x = data.byte(kRyanx);
|
|
|
|
sprite->y = data.byte(kRyany);
|
|
|
|
sprite->b29 = 0;
|
|
|
|
}
|
|
|
|
--sprite->b22;
|
|
|
|
if (sprite->b22 != 0xff) {
|
|
|
|
ds = pop();
|
|
|
|
es = pop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sprite->b22 = 0;
|
|
|
|
if (data.byte(kTurntoface) != data.byte(kFacing)) {
|
2011-06-28 16:13:06 +00:00
|
|
|
aboutturn(sprite);
|
2011-06-28 12:37:46 +00:00
|
|
|
} else {
|
|
|
|
if ((data.byte(kTurndirection) != 0) && (data.byte(kLinepointer) == 254)) {
|
|
|
|
data.byte(kReasseschanges) = 1;
|
|
|
|
if (data.byte(kFacing) == data.byte(kLeavedirection))
|
|
|
|
checkforexit();
|
|
|
|
}
|
|
|
|
data.byte(kTurndirection) = 0;
|
|
|
|
if (data.byte(kLinepointer) == 254) {
|
|
|
|
sprite->b29 = 0;
|
|
|
|
} else {
|
|
|
|
++sprite->b29;
|
|
|
|
if (sprite->b29 == 11)
|
|
|
|
sprite->b29 = 1;
|
|
|
|
walking();
|
|
|
|
if (data.byte(kLinepointer) != 254) {
|
|
|
|
if ((data.byte(kFacing) & 1) == 0)
|
|
|
|
walking();
|
|
|
|
else if ((sprite->b29 != 2) && (sprite->b29 != 7))
|
|
|
|
walking();
|
|
|
|
}
|
|
|
|
if (data.byte(kLinepointer) == 254) {
|
|
|
|
if (data.byte(kTurntoface) == data.byte(kFacing)) {
|
|
|
|
data.byte(kReasseschanges) = 1;
|
|
|
|
if (data.byte(kFacing) == data.byte(kLeavedirection))
|
|
|
|
checkforexit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static const uint8 facelist[] = { 0,60,33,71,11,82,22,93 };
|
|
|
|
sprite->b15 = sprite->b29 + facelist[data.byte(kFacing)];
|
|
|
|
data.byte(kRyanx) = sprite->x;
|
|
|
|
data.byte(kRyany) = sprite->y;
|
2011-06-26 13:17:19 +00:00
|
|
|
|
|
|
|
ds = pop();
|
|
|
|
es = pop();
|
|
|
|
}
|
|
|
|
|
2011-06-28 12:54:26 +00:00
|
|
|
void DreamGenContext::walking() {
|
|
|
|
Sprite *sprite = (Sprite*)es.ptr(bx, sizeof(Sprite));
|
|
|
|
|
|
|
|
uint8 comp;
|
|
|
|
if (data.byte(kLinedirection) != 0) {
|
|
|
|
--data.byte(kLinepointer);
|
|
|
|
comp = 200;
|
|
|
|
} else {
|
|
|
|
++data.byte(kLinepointer);
|
|
|
|
comp = data.byte(kLinelength);
|
|
|
|
}
|
|
|
|
if (data.byte(kLinepointer) < comp) {
|
|
|
|
sprite->x = data.byte(kLinedata + data.byte(kLinepointer) * 2 + 0);
|
|
|
|
sprite->y = data.byte(kLinedata + data.byte(kLinepointer) * 2 + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.byte(kLinepointer) = 254;
|
|
|
|
data.byte(kManspath) = data.byte(kDestination);
|
|
|
|
if (data.byte(kDestination) == data.byte(kFinaldest)) {
|
|
|
|
facerightway();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data.byte(kDestination) = data.byte(kFinaldest);
|
|
|
|
push(es);
|
|
|
|
push(bx);
|
|
|
|
autosetwalk();
|
|
|
|
bx = pop();
|
|
|
|
es = pop();
|
|
|
|
}
|
|
|
|
|
2011-06-28 16:13:06 +00:00
|
|
|
void DreamGenContext::aboutturn(Sprite* sprite) {
|
|
|
|
if (data.byte(kTurndirection) == 1)
|
|
|
|
goto incdir;
|
|
|
|
else if ((int8)data.byte(kTurndirection) == -1)
|
|
|
|
goto decdir;
|
|
|
|
else {
|
|
|
|
if (data.byte(kFacing) < data.byte(kTurntoface)) {
|
|
|
|
uint8 delta = data.byte(kTurntoface) - data.byte(kFacing);
|
|
|
|
if (delta >= 4)
|
|
|
|
goto decdir;
|
|
|
|
else
|
|
|
|
goto incdir;
|
|
|
|
} else {
|
|
|
|
uint8 delta = data.byte(kFacing) - data.byte(kTurntoface);
|
|
|
|
if (delta >= 4)
|
|
|
|
goto incdir;
|
|
|
|
else
|
|
|
|
goto decdir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
incdir:
|
|
|
|
data.byte(kTurndirection) = 1;
|
|
|
|
data.byte(kFacing) = (data.byte(kFacing) + 1) & 7;
|
|
|
|
sprite->b29 = 0;
|
|
|
|
return;
|
|
|
|
decdir:
|
|
|
|
data.byte(kTurndirection) = -1;
|
|
|
|
data.byte(kFacing) = (data.byte(kFacing) - 1) & 7;
|
|
|
|
sprite->b29 = 0;
|
|
|
|
}
|
|
|
|
|
2011-06-27 06:53:39 +00:00
|
|
|
void DreamGenContext::backobject(Sprite* sprite) {
|
2011-06-26 13:17:19 +00:00
|
|
|
push(es);
|
|
|
|
push(ds);
|
|
|
|
|
|
|
|
// Recover es:bx from sprite
|
|
|
|
es = data.word(kBuffers);
|
|
|
|
bx = kSpritetable;
|
|
|
|
Sprite *sprites = (Sprite*)es.ptr(bx, sizeof(Sprite)*16);
|
|
|
|
bx += 32*(sprite-sprites);
|
|
|
|
//
|
|
|
|
|
2011-06-27 06:53:39 +00:00
|
|
|
ds = data.word(kSetdat);
|
|
|
|
di = READ_LE_UINT16(&sprite->obj_data);
|
|
|
|
ObjData* objData = (ObjData*)ds.ptr(di, 0);
|
|
|
|
|
|
|
|
if (sprite->delay != 0) {
|
|
|
|
--sprite->delay;
|
|
|
|
ds = pop();
|
|
|
|
es = pop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite->delay = objData->delay;
|
|
|
|
if (objData->type == 6)
|
2011-07-02 11:00:09 +00:00
|
|
|
widedoor(sprite, objData);
|
2011-06-27 06:53:39 +00:00
|
|
|
else if (objData->type == 5)
|
2011-06-28 14:05:58 +00:00
|
|
|
random(sprite, objData);
|
2011-06-27 06:53:39 +00:00
|
|
|
else if (objData->type == 4)
|
|
|
|
lockeddoorway();
|
|
|
|
else if (objData->type == 3)
|
2011-06-28 03:10:35 +00:00
|
|
|
liftsprite(sprite, objData);
|
2011-06-27 06:53:39 +00:00
|
|
|
else if (objData->type == 2)
|
2011-07-02 11:00:09 +00:00
|
|
|
doorway(sprite, objData);
|
2011-06-27 06:53:39 +00:00
|
|
|
else if (objData->type == 1)
|
2011-06-27 07:08:54 +00:00
|
|
|
constant(sprite, objData);
|
2011-06-27 06:53:39 +00:00
|
|
|
else
|
2011-06-27 07:08:54 +00:00
|
|
|
steady(sprite, objData);
|
2011-06-26 13:17:19 +00:00
|
|
|
|
|
|
|
ds = pop();
|
|
|
|
es = pop();
|
|
|
|
}
|
|
|
|
|
2011-06-27 07:08:54 +00:00
|
|
|
void DreamGenContext::constant(Sprite* sprite, ObjData* objData) {
|
2011-06-28 02:24:42 +00:00
|
|
|
++sprite->frame;
|
|
|
|
if (objData->b18[sprite->frame] == 255) {
|
|
|
|
sprite->frame = 0;
|
2011-06-27 07:08:54 +00:00
|
|
|
}
|
2011-06-28 02:24:42 +00:00
|
|
|
uint8 b18 = objData->b18[sprite->frame];
|
2011-06-27 07:08:54 +00:00
|
|
|
objData->b17 = b18;
|
|
|
|
sprite->b15 = b18;
|
|
|
|
}
|
|
|
|
|
2011-06-28 14:05:58 +00:00
|
|
|
void DreamGenContext::random(Sprite* sprite, ObjData* objData) {
|
|
|
|
randomnum1();
|
|
|
|
uint16 r = ax;
|
|
|
|
sprite->b15 = objData->b18[r&7];
|
|
|
|
}
|
2011-06-28 02:55:10 +00:00
|
|
|
|
2011-07-02 11:00:09 +00:00
|
|
|
void DreamGenContext::doorway(Sprite* sprite, ObjData* objData) {
|
|
|
|
data.byte(kDoorcheck1) = -24;
|
|
|
|
data.byte(kDoorcheck2) = 10;
|
|
|
|
data.byte(kDoorcheck3) = -30;
|
|
|
|
data.byte(kDoorcheck4) = 10;
|
|
|
|
dodoor(sprite, objData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::widedoor(Sprite* sprite, ObjData* objData) {
|
|
|
|
data.byte(kDoorcheck1) = -24;
|
|
|
|
data.byte(kDoorcheck2) = 24;
|
|
|
|
data.byte(kDoorcheck3) = -30;
|
|
|
|
data.byte(kDoorcheck4) = 24;
|
|
|
|
dodoor(sprite, objData);
|
|
|
|
}
|
|
|
|
|
2011-06-28 02:55:10 +00:00
|
|
|
void DreamGenContext::dodoor() {
|
|
|
|
Sprite *sprite = (Sprite*)es.ptr(bx, sizeof(Sprite));
|
|
|
|
ObjData *objData = (ObjData*)ds.ptr(di, 0);
|
|
|
|
dodoor(sprite, objData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::dodoor(Sprite* sprite, ObjData* objData) {
|
|
|
|
uint8 ryanx = data.byte(kRyanx);
|
|
|
|
uint8 ryany = data.byte(kRyany);
|
|
|
|
int8 deltax = ryanx - sprite->x;
|
|
|
|
int8 deltay = ryany - sprite->y;
|
|
|
|
if (ryanx < sprite->x) {
|
|
|
|
if (deltax < (int8)data.byte(kDoorcheck1))
|
|
|
|
goto shutdoor;
|
|
|
|
} else {
|
|
|
|
if (deltax >= data.byte(kDoorcheck2))
|
|
|
|
goto shutdoor;
|
|
|
|
}
|
|
|
|
if (ryany < sprite->y) {
|
|
|
|
if (deltay < (int8)data.byte(kDoorcheck3))
|
|
|
|
goto shutdoor;
|
|
|
|
} else {
|
|
|
|
if (deltay >= data.byte(kDoorcheck4))
|
|
|
|
goto shutdoor;
|
|
|
|
}
|
|
|
|
//opendoor:
|
|
|
|
if ((data.byte(kThroughdoor) == 1) && (sprite->frame == 0))
|
|
|
|
sprite->frame = 6;
|
|
|
|
|
|
|
|
++sprite->frame;
|
|
|
|
if (sprite->frame == 1) { //doorsound2
|
|
|
|
if (data.byte(kReallocation) == 5) //hoteldoor2
|
|
|
|
al = 13;
|
|
|
|
else
|
|
|
|
al = 0;
|
|
|
|
playchannel1();
|
|
|
|
}
|
|
|
|
if (objData->b18[sprite->frame] == 255) {
|
|
|
|
--sprite->frame;
|
|
|
|
}
|
|
|
|
sprite->b15 = objData->b17 = objData->b18[sprite->frame];
|
|
|
|
data.byte(kThroughdoor) = 1;
|
|
|
|
return;
|
|
|
|
shutdoor:
|
|
|
|
if (sprite->frame == 5) { //doorsound1;
|
|
|
|
if (data.byte(kReallocation) == 5) //hoteldoor1
|
|
|
|
al = 13;
|
|
|
|
else
|
|
|
|
al = 1;
|
|
|
|
playchannel1();
|
|
|
|
}
|
|
|
|
if (sprite->frame != 0) {
|
|
|
|
--sprite->frame;
|
|
|
|
}
|
|
|
|
sprite->b15 = objData->b17 = objData->b18[sprite->frame];
|
|
|
|
if (sprite->frame == 5) //nearly
|
|
|
|
data.byte(kThroughdoor) = 0;
|
|
|
|
}
|
|
|
|
|
2011-06-27 07:08:54 +00:00
|
|
|
void DreamGenContext::steady(Sprite* sprite, ObjData* objData) {
|
|
|
|
uint8 b18 = objData->b18[0];
|
|
|
|
objData->b17 = b18;
|
|
|
|
sprite->b15 = b18;
|
|
|
|
}
|
|
|
|
|
2011-06-28 03:10:35 +00:00
|
|
|
void DreamGenContext::turnpathonCPP(uint8 param) {
|
|
|
|
al = param;
|
|
|
|
push(es);
|
|
|
|
push(bx);
|
|
|
|
turnpathon();
|
|
|
|
bx = pop();
|
|
|
|
es = pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::turnpathoffCPP(uint8 param) {
|
|
|
|
al = param;
|
|
|
|
push(es);
|
|
|
|
push(bx);
|
|
|
|
turnpathoff();
|
|
|
|
bx = pop();
|
|
|
|
es = pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::liftsprite() {
|
|
|
|
Sprite *sprite = (Sprite*)es.ptr(bx, sizeof(Sprite));
|
|
|
|
ObjData *objData = (ObjData*)ds.ptr(di, 0);
|
|
|
|
liftsprite(sprite, objData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::liftsprite(Sprite* sprite, ObjData* objData) {
|
|
|
|
uint8 liftFlag = data.byte(kLiftflag);
|
|
|
|
if (liftFlag == 0) { //liftclosed
|
|
|
|
turnpathoffCPP(data.byte(kLiftpath));
|
|
|
|
|
|
|
|
if (data.byte(kCounttoopen) != 0) {
|
|
|
|
_dec(data.byte(kCounttoopen));
|
|
|
|
if (data.byte(kCounttoopen) == 0)
|
|
|
|
data.byte(kLiftflag) = 3;
|
|
|
|
}
|
|
|
|
sprite->frame = 0;
|
|
|
|
sprite->b15 = objData->b17 = objData->b18[sprite->frame];
|
|
|
|
}
|
|
|
|
else if (liftFlag == 1) { //liftopen
|
|
|
|
turnpathonCPP(data.byte(kLiftpath));
|
|
|
|
|
|
|
|
if (data.byte(kCounttoclose) != 0) {
|
|
|
|
_dec(data.byte(kCounttoclose));
|
|
|
|
if (data.byte(kCounttoclose) == 0)
|
|
|
|
data.byte(kLiftflag) = 2;
|
|
|
|
}
|
|
|
|
sprite->frame = 12;
|
|
|
|
sprite->b15 = objData->b17 = objData->b18[sprite->frame];
|
|
|
|
}
|
|
|
|
else if (liftFlag == 3) { //openlift
|
|
|
|
if (sprite->frame == 12) {
|
|
|
|
data.byte(kLiftflag) = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++sprite->frame;
|
|
|
|
if (sprite->frame == 1) {
|
|
|
|
al = 2;
|
|
|
|
liftnoise();
|
|
|
|
}
|
|
|
|
sprite->b15 = objData->b17 = objData->b18[sprite->frame];
|
|
|
|
} else { //closeLift
|
|
|
|
assert(liftFlag == 2);
|
|
|
|
if (sprite->frame == 0) {
|
|
|
|
data.byte(kLiftflag) = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
--sprite->frame;
|
|
|
|
if (sprite->frame == 11) {
|
|
|
|
al = 3;
|
|
|
|
liftnoise();
|
|
|
|
}
|
|
|
|
sprite->b15 = objData->b17 = objData->b18[sprite->frame];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-25 13:28:51 +00:00
|
|
|
void DreamGenContext::modifychar() {
|
|
|
|
al = engine->modifyChar(al);
|
|
|
|
}
|
|
|
|
|
2011-07-16 09:04:49 +00:00
|
|
|
void DreamGenContext::lockmon() {
|
|
|
|
// Pressing space pauses text output in the monitor. We use the "hard"
|
|
|
|
// key because calling readkey() drains characters from the input
|
|
|
|
// buffer, we we want the user to be able to type ahead while the text
|
|
|
|
// is being printed.
|
|
|
|
if (data.byte(kLasthardkey) == 57) {
|
|
|
|
// Clear the keyboard buffer. Otherwise the space that caused
|
2011-07-16 09:07:22 +00:00
|
|
|
// the pause will be read immediately unpause the game.
|
2011-07-16 09:04:49 +00:00
|
|
|
do {
|
|
|
|
readkey();
|
|
|
|
} while (data.byte(kCurrentkey) != 0);
|
|
|
|
|
|
|
|
locklighton();
|
|
|
|
while (!engine->shouldQuit()) {
|
|
|
|
engine->waitForVSync();
|
|
|
|
readkey();
|
|
|
|
if (data.byte(kCurrentkey) == ' ')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Forget the last "hard" key, otherwise the space that caused
|
|
|
|
// the unpausing will immediately re-pause the game.
|
|
|
|
data.byte(kLasthardkey) = 0;
|
|
|
|
locklightoff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-15 21:03:00 +00:00
|
|
|
} /*namespace dreamgen */
|
2011-06-28 12:37:46 +00:00
|
|
|
|