diff options
32 files changed, 382 insertions, 214 deletions
diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 5c416500d6..10f19029d6 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -27,19 +27,25 @@ #include "cge/bitmap.h" #include "cge/cfile.h" +#include "cge/jbw.h" #ifdef VOL #include "cge/vol.h" #endif -#ifdef DROP_H - #include "cge/drop.h" + +#ifndef DROP_H +// TODO replace printf by scummvm equivalent +#define DROP(m,n) {} +//#define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } #endif + //#include <alloc.h> //#include <dir.h> //#include <mem.h> #include <dos.h> +#include "cge/cfile.h" #include "common/system.h" namespace CGE { @@ -51,7 +57,7 @@ namespace CGE { DAC * BITMAP::Pal = NULL; - +#define MAXPATH 128 #pragma argsused BITMAP::BITMAP (const char * fname, bool rem) @@ -82,7 +88,7 @@ BITMAP::BITMAP (const char * fname, bool rem) Code(); if (rem) { - farfree(M); + free(M); M = NULL; } } @@ -151,11 +157,11 @@ BITMAP::BITMAP (const BITMAP& bmp) uint8 * v0 = bmp.V; if (v0) { - uint16 vsiz = FP_OFF(bmp.B) - FP_OFF(v0); + uint16 vsiz = (uint8*)(bmp.B) - (uint8*)(v0); uint16 siz = vsiz + H * sizeof(HideDesc); uint8 * v1 = farnew(uint8, siz); if (v1 == NULL) DROP("No core", NULL); - _fmemcpy(v1, v0, siz); + memcpy(v1, v0, siz); B = (HideDesc *) ((V = v1) + vsiz); } } @@ -168,12 +174,12 @@ BITMAP::~BITMAP (void) { switch (MemType(M)) { - case FAR_MEM : farfree(M); break; + case FAR_MEM : free(M); break; } switch (MemType(V)) { case NEAR_MEM : delete[] (uint8 *) V; break; - case FAR_MEM : farfree(V); break; + case FAR_MEM : free(V); break; } } @@ -185,15 +191,15 @@ BITMAP& BITMAP::operator = (const BITMAP& bmp) W = bmp.W; H = bmp.H; M = NULL; - if (MemType(V) == FAR_MEM) farfree(V); + if (MemType(V) == FAR_MEM) free(V); if (v0 == NULL) V = NULL; else { - uint16 vsiz = FP_OFF(bmp.B) - FP_OFF(v0); + uint16 vsiz = (uint8*)bmp.B - (uint8*)v0; uint16 siz = vsiz + H * sizeof(HideDesc); uint8 * v1 = farnew(uint8, siz); if (v1 == NULL) DROP("No core", NULL); - _fmemcpy(v1, v0, siz); + memcpy(v1, v0, siz); B = (HideDesc *) ((V = v1) + vsiz); } return *this; @@ -207,10 +213,10 @@ uint16 BITMAP::MoveVmap (uint8 * buf) { if (V) { - uint16 vsiz = FP_OFF(B) - FP_OFF(V); + uint16 vsiz = (uint8*)B - (uint8*)V; uint16 siz = vsiz + H * sizeof(HideDesc); - _fmemcpy(buf, V, siz); - if (MemType(V) == FAR_MEM) farfree(V); + memcpy(buf, V, siz); + if (MemType(V) == FAR_MEM) free(V); B = (HideDesc *) ((V = buf) + vsiz); return siz; } @@ -234,7 +240,7 @@ BMP_PTR BITMAP::Code (void) switch (MemType(V)) { case NEAR_MEM : delete[] (uint8 *) V; break; - case FAR_MEM : farfree(V); break; + case FAR_MEM : free(V); break; } V = NULL; } diff --git a/engines/cge/boot.h b/engines/cge/boot.h index d09afb6d1b..bc78b0e7fb 100644 --- a/engines/cge/boot.h +++ b/engines/cge/boot.h @@ -74,6 +74,6 @@ EC Boot * ReadBoot (int drive); EC uint8 CheckBoot (Boot * boot); EC bool WriteBoot (int drive, Boot * boot); -// End of namespace CGE +} // End of namespace CGE #endif diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 4068f323a0..1851068e2d 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -28,6 +28,7 @@ #include "cge/btfile.h" //#include <alloc.h> #include "common/system.h" +#include "common/str.h" #include <string.h> @@ -42,7 +43,9 @@ namespace CGE { #ifndef DROP_H - #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } + // TODO replace printf by scummvm equivalent +#define DROP(m,n) + //#define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } #endif #ifndef BT_SIZE @@ -126,7 +129,7 @@ BT_PAGE * BTFILE::GetPage (int lev, uint16 pgn) { Buff[lev].Page->Hea.Count = 0; Buff[lev].Page->Hea.Down = BT_NONE; - _fmemset(Buff[lev].Page->Data, '\0', sizeof(Buff[lev].Page->Data)); + memset(Buff[lev].Page->Data, '\0', sizeof(Buff[lev].Page->Data)); Buff[lev].Updt = TRUE; } Buff[lev].Indx = -1; @@ -138,7 +141,7 @@ BT_PAGE * BTFILE::GetPage (int lev, uint16 pgn) -BT_KEYPACK * BTFILE::Find (const uint8 * key) +BT_KEYPACK * BTFILE::Find (const char * key) { int lev = 0; uint16 nxt = BT_ROOT; @@ -150,7 +153,7 @@ BT_KEYPACK * BTFILE::Find (const uint8 * key) { int i; for (i = 0; i < pg->Hea.Count; i ++) - if (_fmemicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) + if (memicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) break; nxt = (i) ? pg->Inn[i-1].Down : pg->Hea.Down; Buff[lev].Indx = i-1; @@ -160,7 +163,7 @@ BT_KEYPACK * BTFILE::Find (const uint8 * key) { int i; for (i = 0; i < pg->Hea.Count-1; i ++) - if (_fstricmp(key, pg->Lea[i].Key) <= 0) + if (scumm_stricmp((const char*)key, (const char*)pg->Lea[i].Key) <= 0) break; Buff[lev].Indx = i; return &pg->Lea[i]; @@ -174,7 +177,7 @@ BT_KEYPACK * BTFILE::Find (const uint8 * key) int keycomp (const void * k1, const void * k2) { - return _fmemicmp(k1, k2, BT_KEYLEN); + return memicmp(k1, k2, BT_KEYLEN); } @@ -196,7 +199,7 @@ void BTFILE::Make(BT_KEYPACK * keypack, uint16 count) { PutPage(1, TRUE); // save filled page Leaf = GetPage(1, ++n); // take empty page - _fmemcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); + memcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); Root->Inn[Root->Hea.Count ++].Down = n; Buff[0].Updt = TRUE; } diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 0599bee72a..0df9636573 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -42,7 +42,7 @@ namespace CGE { struct BT_KEYPACK { - uint8 Key[BT_KEYLEN]; + char Key[BT_KEYLEN]; uint32 Mark; uint16 Size; }; @@ -89,7 +89,7 @@ class BTFILE : public IOHAND public: BTFILE (const char * name, IOMODE mode = REA, CRYPT * crpt = NULL); virtual ~BTFILE (void); - BT_KEYPACK * Find(const byte * key); + BT_KEYPACK * Find(const char * key); BT_KEYPACK * Next(void); void Make(BT_KEYPACK * keypack, uint16 count); }; diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 56383ca92e..4d555c979d 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -42,7 +42,9 @@ namespace CGE { #ifndef DROP_H - #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } + //TODO Replace by scummvm printf +#define DROP(m,n) {} + //#define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } #endif IOBUF::IOBUF (IOMODE mode, CRYPT * crpt) @@ -84,7 +86,7 @@ IOBUF::IOBUF (const char * name, IOMODE mode, CRYPT * crpt) IOBUF::~IOBUF (void) { if (Mode > REA) WriteBuff(); - if (Buff) farfree(Buff); + if (Buff) free(Buff); } @@ -127,8 +129,8 @@ uint16 IOBUF::Read (void *buf, uint16 len) if (n) { if (len < n) n = len; - _fmemcpy(buf, Buff+Ptr, n); - (uint8 *) buf += n; + memcpy(buf, Buff+Ptr, n); + buf = (uint8 *)buf + n; len -= n; total += n; Ptr += n; @@ -155,15 +157,15 @@ uint16 IOBUF::Read (uint8 * buf) if (n) { if (total + n >= LINE_MAX-2) n = LINE_MAX-2 - total; - uint8 * eol = (uint8 *) _fmemchr(p, '\r', n); + uint8 * eol = (uint8 *) memchr(p, '\r', n); if (eol) n = (uint16) (eol - p); - uint8 * eof = (uint8 *) _fmemchr(p, '\32', n); + uint8 * eof = (uint8 *) memchr(p, '\32', n); if (eof) // end-of-file { n = (uint16) (eof - p); Ptr = (uint16) (eof - Buff); } - if (n) _fmemcpy(buf, p, n); + if (n) memcpy(buf, p, n); buf += n; total += n; if (eof) break; @@ -199,10 +201,10 @@ uint16 IOBUF::Write (void * buf, uint16 len) if (n > len) n = len; if (n) { - _fmemcpy(Buff+Lim, buf, n); + memcpy(Buff+Lim, buf, n); Lim += n; len -= n; - (uint8 *) buf += n; + buf = (uint8 *)buf + n; tot += n; } else WriteBuff(); @@ -220,7 +222,7 @@ uint16 IOBUF::Write (uint8 * buf) uint16 len = 0; if (buf) { - len = _fstrlen((const char *) buf); + len = strlen((const char *) buf); if (len) if (buf[len-1] == '\n') -- len; len = Write(buf, len); if (len) @@ -302,9 +304,13 @@ void CFILE::Flush (void) { if (Mode > REA) WriteBuff(); else Lim = 0; + + // TODO replace by scummvm files. + /* _BX = Handle; _AH = 0x68; // Flush buffer asm int 0x21 + */ } diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index b08dc833b0..e8d494c2f9 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -59,7 +59,7 @@ public: IOBUF (const char * name, IOMODE mode, CRYPT * crpt = NULL); virtual ~IOBUF (void); uint16 Read (void * buf, uint16 len); - uint16 Read (char * buf); + uint16 Read (uint8 * buf); int Read (void); uint16 Write (void * buf, uint16 len); uint16 Write (uint8 * buf); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 36053d926c..ebf3f3f9fd 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -44,17 +44,19 @@ #include "cge/gettext.h" #include "cge/mixer.h" #include "cge/cge_main.h" -#include <alloc.h> +//#include <alloc.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dos.h> -#include <dir.h> +//#include <dir.h> #include <fcntl.h> -#include <bios.h> +//#include <bios.h> #include <io.h> +#include "common/str.h" + namespace CGE { #define STACK_SIZ (K(2)) @@ -189,7 +191,8 @@ uint8 & CLUSTER::Cell (void) bool CLUSTER::Protected (void) { if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) return true; - + // TODO AsM + /* _DX = (MAP_ZCNT << 8) + MAP_XCNT; _BX = (uint16) this; @@ -221,6 +224,8 @@ bool CLUSTER::Protected (void) // return Map[B][A] != 0; xit: return _AX; + */ + return TRUE; } @@ -309,7 +314,7 @@ static void LoadGame (XFILE& file, bool tiny = false) if (n != sizeof(S)) break; S.Prev = S.Next = NULL; - spr = (stricmp(S.File+2, "MUCHA") == 0) ? new FLY(NULL) + spr = (scumm_stricmp(S.File+2, "MUCHA") == 0) ? new FLY(NULL) : new SPRITE(NULL); if (spr == NULL) VGA::Exit("No core"); *spr = S; @@ -394,7 +399,7 @@ static void Trouble (int seq, int txt) static void OffUse (void) { - Trouble(OFF_USE, OFF_USE_TEXT+random(OffUseCount)); + Trouble(OFF_USE, OFF_USE_TEXT+new_random(OffUseCount)); } @@ -580,6 +585,8 @@ void WALK::Park (void) void WALK::FindWay (CLUSTER c) { + // TODO : Find1Way in ASM +/* bool Find1Way(void); extern uint16 Target; @@ -598,6 +605,7 @@ void WALK::FindWay (CLUSTER c) if (TracePtr < 0) NoWay(); Time = 1; } +*/ } @@ -732,17 +740,17 @@ static void SetMapBrick (int x, int z) //-------------------------------------------------------------------------- void dummy (void) { } -void SwitchMapping (void); -void SwitchColorMode (void); -void StartCountDown (void); -Debug( void SwitchDebug (void); ) -void SwitchMusic (void); -void KillSprite (void); -void PushSprite (void); -void PullSprite (void); -void BackPaint (void); -void NextStep (void); -void SaveMapping (void); +static void SwitchMapping (void); +static void SwitchColorMode (void); +static void StartCountDown (void); +Debug(static void SwitchDebug (void); ) +static void SwitchMusic (void); +static void KillSprite (void); +static void PushSprite (void); +static void PullSprite (void); +static void BackPaint (void); +static void NextStep (void); +static void SaveMapping (void); WALK * Hero = NULL; @@ -835,7 +843,8 @@ static void MiniStep (int stp) static void PostMiniStep (int stp) { static int recent = -2; - if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *) MiniStep); + //TODO Change the SNPOST message send to a special way to send function pointer + //if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *)&MiniStep); } @@ -993,7 +1002,8 @@ static void QGame (void) CaveDown(); OldLev = Lev; SaveSound(); - SaveGame(CFILE(UsrPath(UsrFnam), WRI, RCrypt)); + CFILE file = CFILE(UsrPath(UsrFnam), WRI, RCrypt); + SaveGame(file); Vga.Sunset(); Finis = true; } @@ -1009,7 +1019,8 @@ void SwitchCave (int cav) if (cav < 0) { SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - SNPOST(SNEXEC, -1, 0, (void *) QGame); // switch cave + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST(SNEXEC, -1, 0, (void *)&QGame); // switch cave } else { @@ -1030,7 +1041,8 @@ void SwitchCave (int cav) KillText(); if (! Startup) KeyClick(); SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - SNPOST(SNEXEC, 0, 0, (void *) XCave); // switch cave + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST(SNEXEC, 0, 0, (void *)&XCave); // switch cave } } } @@ -1198,7 +1210,7 @@ void SYSTEM::Tick (void) if (PAIN) HeroCover(9); else if (STARTUP::Core >= CORE_MID) { - int n = random(100); + int n = new_random(100); if (n > 96) HeroCover(6+(Hero->X+Hero->W/2 < SCR_WID/2)); else { @@ -1271,7 +1283,8 @@ static void SwitchMusic (void) else { SNPOST_(SNSEQ, 122, (Music = false), NULL); - SNPOST(SNEXEC, -1, 0, (void *) SelectSound); + //TODO Change the SNPOST message send to a special way to send function pointer + // SNPOST(SNEXEC, -1, 0, (void *)&SelectSound); } } else @@ -1665,12 +1678,12 @@ void SPRITE::Touch (uint16 mask, int x, int y) static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) { - static char * Comd[] = { "Name", "Type", "Phase", "East", + static const char * Comd[] = { "Name", "Type", "Phase", "East", "Left", "Right", "Top", "Bottom", "Seq", "Near", "Take", "Portable", "Transparent", NULL }; - static char * Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", + static const char * Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", "FLY", NULL }; char line[LINE_MAX]; @@ -1691,7 +1704,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro VGA::Exit("Bad SPR", line); } - while ((len = sprf.Read(line)) != 0) + while ((len = sprf.Read((uint8*)line)) != 0) { ++ lcnt; if (len && line[len-1] == '\n') line[-- len] = '\0'; @@ -1738,6 +1751,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro switch (type) { case 1 : // AUTO + { Sprite = new SPRITE(NULL); if (Sprite) { @@ -1745,7 +1759,9 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ } break; + } case 2 : // WALK + { WALK * w = new WALK(NULL); if (w && ref == 1) { @@ -1758,6 +1774,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro } Sprite = w; break; + } /* case 3 : // NEWTON NEWTON * n = new NEWTON(NULL); @@ -1774,6 +1791,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro break; */ case 4 : // LISSAJOUS + { VGA::Exit("Bad type", fname); /* LISSAJOUS * l = new LISSAJOUS(NULL); @@ -1791,15 +1809,20 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro Sprite = l; */ break; + } case 5 : // FLY + { FLY * f = new FLY(NULL); Sprite = f; //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ break; + } default: // DEAD + { Sprite = new SPRITE(NULL); if (Sprite) Sprite->Goto(col, row); break; + } } if (Sprite) { @@ -1811,8 +1834,10 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro Sprite->Flags.Tran = tran; Sprite->Flags.Kill = true; Sprite->Flags.BDel = true; - fnsplit(fname, NULL, NULL, Sprite->File, NULL); - Sprite->ShpCnt = shpcnt; + // TODO : Get Filename from entire path + //fnsplit(fname, NULL, NULL, Sprite->File, NULL); + + Sprite->ShpCnt = shpcnt; VGA::SpareQ.Append(Sprite); } } @@ -1834,7 +1859,7 @@ static void LoadScript (const char *fname) if (scrf.Error) return; - while (scrf.Read(line) != 0) + while (scrf.Read((uint8*)line) != 0) { char *p; @@ -1941,16 +1966,22 @@ void LoadUser (void) // set scene if (STARTUP::Mode == 0) // user .SVG file found { - LoadGame(CFILE(UsrPath(UsrFnam), REA, RCrypt)); + CFILE cfile = CFILE(UsrPath(UsrFnam), REA, RCrypt); + LoadGame(cfile); } else { - if (STARTUP::Mode == 1) LoadGame(SVG0FILE(SVG0NAME)); + if (STARTUP::Mode == 1) + { + SVG0FILE file = SVG0FILE(SVG0NAME); + LoadGame(file); + } else { LoadScript(ProgName(INI_EXT)); Music = true; - SaveGame(CFILE(SVG0NAME, WRI)); + CFILE file = CFILE(SVG0NAME, WRI); + SaveGame(file); VGA::Exit("Ok", SVG0NAME); } } @@ -2061,7 +2092,8 @@ static void RunGame (void) // main loop while (! Finis) { - if (FINIS) SNPOST(SNEXEC, -1, 0, (void *) QGame); + //TODO Change the SNPOST message send to a special way to send function pointer + // if (FINIS) SNPOST(SNEXEC, -1, 0, (void *)&QGame); MainLoop(); } @@ -2160,7 +2192,8 @@ bool ShowTitle (const char * name) #ifdef CD STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; #else - Boot * b = ReadBoot(getdisk()); + // TODO : do good boot... + Boot * b = ReadBoot(0); //getdisk()); uint32 sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; free(b); sn -= ((IDENT *)Copr)->disk; @@ -2187,7 +2220,8 @@ bool ShowTitle (const char * name) const char *n = UsrPath(UsrFnam); if (CFILE::Exist(n)) { - LoadGame(CFILE(n, REA, RCrypt), true); // only system vars + CFILE file = CFILE(n, REA, RCrypt); + LoadGame(file, true); // only system vars VGA::SetColors(SysPal, 64); Vga.Update(); if (FINIS) @@ -2242,7 +2276,7 @@ void cge_main (void) Debug( DebugLine.Flags.Hide = true; ) Debug( HorzLine.Flags.Hide = true; ) - srand((uint16) Timer()); + //srand((uint16) Timer()); Sys = new SYSTEM; if (Music && STARTUP::SoundOk) LoadMIDI(0); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 8605d17c55..30a07dd67e 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -29,6 +29,7 @@ #define __CGE__ #include "cge\wav.h" +#include "cge\vga13h.h" namespace CGE { diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 4add18bd43..38da4cda58 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -59,17 +59,17 @@ namespace CGE { #define DETECT 0xFFFF -void NONE (void); -void SB (void); -void SBM (void); -void GUS (void); -void GUSM (void); -void MIDI (void); -void AUTO (void); -void SetPortD (void); -void SetPortM (void); -void SetIRQ (void); -void SetDMA (void); +static void NONE (void); +static void SB (void); +static void SBM (void); +static void GUS (void); +static void GUSM (void); +static void MIDI (void); +static void AUTO (void); +static void SetPortD (void); +static void SetPortM (void); +static void SetIRQ (void); +static void SetDMA (void); static int DevName[] = { NONE_TEXT, SB_TEXT, SBM_TEXT, @@ -208,7 +208,8 @@ static void Select (CHOICE * cho, int hlp) { Cho = cho; Hlp = hlp; - SNPOST(SNEXEC, -1, 0, (void *) SNSelect); + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST(SNEXEC, -1, 0, (void *)&SNSelect); } diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index d9bcf916bb..b6530323e4 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -91,8 +91,8 @@ int FLY::L = 20, FLY::FLY (BITMAP ** shpl) : SPRITE(shpl), Tx(0), Ty(0) { - Step(random(2)); - Goto(L+random(R-L-W), T+random(B-T-H)); + Step(new_random(2)); + Goto(L+new_random(R-L-W), T+new_random(B-T-H)); } @@ -103,10 +103,10 @@ void FLY::Tick (void) Step(); if (! Flags.Kept) { - if (random(10) < 1) + if (new_random(10) < 1) { - Tx = random(3) - 1; - Ty = random(3) - 1; + Tx = new_random(3) - 1; + Ty = new_random(3) - 1; } if (X + Tx < L || X + Tx + W > R) Tx = -Tx; if (Y + Ty < T || Y + Ty + H > B) Ty = -Ty; diff --git a/engines/cge/general.h b/engines/cge/general.h index ac45f4b4ad..4633ba2d3c 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -29,6 +29,9 @@ #define __GENERAL__ #include "common/system.h" +#include "common/random.h" +#include "common/textconsole.h" +#include "common/str.h" #include "cge\jbw.h" #include <io.h> @@ -57,8 +60,9 @@ typedef struct { typedef uint16 CRYPT (void *buf, uint16 siz, uint16 seed); +extern Common::RandomSource randSrc; - +#define new_random(a) (randSrc.getRandomNumber(a)) @@ -87,8 +91,8 @@ public: class ENGINE { protected: - static void interrupt (* OldTimer) (...); - static void interrupt NewTimer (...); + static void (* OldTimer) (...); + static void NewTimer (...); public: ENGINE (uint16 tdiv); ~ENGINE (void); @@ -111,7 +115,7 @@ class EMM long Top, Lim; EMS * List; int Han; - static void _seg * Frame; + static void * Frame; public: EMM::EMM (long size = 0); EMM::~EMM (void); @@ -225,8 +229,8 @@ public: long Mark (void); long Size (void); long Seek (long pos); - ftime Time (void); - void SetTime (ftime t); + //timeb Time (void); + // void SetTime (timeb t); }; diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index f8de84f5fc..892ef5ee73 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -37,7 +37,7 @@ GET_TEXT * GET_TEXT::Ptr = NULL; GET_TEXT::GET_TEXT (const char * info, char * text, int size, void (*click)(void)) -: Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), +: Text(text), Size(min<int>(size, GTMAX)), Len(min<int>(Size, strlen(text))), Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)) { int i = 2 * TEXT_HM + Font.Width(info); diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 236a2e6ddb..8f6e0ea44e 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -28,8 +28,17 @@ #ifndef __JBW__ #define __JBW__ +#include "common/scummsys.h" + namespace CGE { +#define VOL +#define INI_FILE VFILE +#define PIC_FILE VFILE +#define BMP_MODE 0 +#define DROP {} // TODO error handling +#define DROP_H + #define BEL 7 #define BS 8 #define HT 9 @@ -37,6 +46,11 @@ namespace CGE { #define FF 12 #define CR 13 +#define TRUE 1 +#define FALSE 0 + +#define MAXFILE 128 + #define NULL 0 #define OFF false #define ON true @@ -49,11 +63,11 @@ namespace CGE { #define IsAlNum(c) (IsAlpha(c) || IsDigit(c)) #define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) -#define farnew(t,n) ((t *) farmalloc(sizeof(t) * (n))) +#define farnew(t,n) ((t *) malloc(sizeof(t) * (n))) #define ArrayCount(a) (sizeof(a)/sizeof((a)[0])) #define MAX_TIMER 0x1800B0L -typedef void (_loadds MouseFunType)(void); +typedef void (MouseFunType)(void); #define Lo(d) (((int *) &d)[0]) #define Hi(d) (((int *) &d)[1]) diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index dbbc06bcb2..e4858d1d04 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -46,15 +46,17 @@ uint16 KEYBOARD::Code[0x60] = { 0,Esc,'1','2','3','4','5','6','7','8','9','0', 0*0x54,0*0x55,0*0x56,F11,F12,0*0x59,0*0x5A, 0*0x5B,0*0x5C,0*0x5D,0*0x5E,0*0x5F }; -void interrupt (* KEYBOARD::OldKeyboard) (...); +void (* KEYBOARD::OldKeyboard) (...); KEYBOARD::KEYBOARD (void) { // steal keyboard interrupt + /* TODO replace totally by scummvm handling OldKeyboard = getvect(KEYBD_INT); setvect(KEYBD_INT, NewKeyboard); + */ } @@ -63,7 +65,9 @@ KEYBOARD::KEYBOARD (void) KEYBOARD::~KEYBOARD (void) { // bring back keyboard interrupt - setvect(KEYBD_INT, OldKeyboard); + /* TODO replace totally by scummvm handling + setvect(KEYBD_INT, OldKeyboard); + */ } @@ -79,9 +83,11 @@ SPRITE * KEYBOARD::SetClient (SPRITE * spr) -void interrupt KEYBOARD::NewKeyboard (...) +void KEYBOARD::NewKeyboard (...) { // table address + // TODO keyboard ASM + /* _SI = (uint16) Key; // take keyboard code @@ -139,6 +145,7 @@ void interrupt KEYBOARD::NewKeyboard (...) asm out 61h,al // write it back asm mov al,20h // send End-Of-Interrupt asm out 20h,al // to the 8259 IC + */ } } // End of namespace CGE diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h index b38481f7d3..5e6c9ac534 100644 --- a/engines/cge/keybd.h +++ b/engines/cge/keybd.h @@ -42,14 +42,14 @@ namespace CGE { class KEYBOARD { - static void interrupt (* OldKeyboard) (...); - static void interrupt NewKeyboard (...); +public: + static void (* OldKeyboard) (...); + static void NewKeyboard (...); static uint16 Code[0x60]; static uint16 Current; static SPRITE * Client; -public: static uint8 Key[0x60]; - static uint16 Last (void) { _AX = Current; Current = 0; return _AX; } + static uint16 Last (void) { uint16 cur = Current; Current = 0; return cur; } static SPRITE * SetClient (SPRITE * spr); KEYBOARD (void); ~KEYBOARD (void); diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 2ebede93be..346631b08a 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -31,7 +31,7 @@ #include "cge/mouse.h" #include "cge/snddrv.h" #include <string.h> -#include <alloc.h> +//#include <alloc.h> namespace CGE { @@ -151,7 +151,9 @@ void MIXER::Update (void) { Led[0]->Step(SNDDrvInfo.VOL4.ML); Led[1]->Step(SNDDrvInfo.VOL4.DL); - SNPOST_(SNEXEC, -1, 0, SNDSetVolume); + + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST_(SNEXEC, -1, 0, (void*)&SNDSetVolume); } } // End of namespace CGE diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 94f7cbf0ac..dff2a0ff8b 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -53,6 +53,7 @@ MOUSE::MOUSE (BITMAP ** shpl) static SEQ ms[] = { { 0,0,0,0,1 }, { 1,1,0,0,1 } }; SetSeq(ms); + /* TODO Mouse handling // Mouse reset _AX = 0x0000; // soft & hard reset (0x0021 soft reset does not work) __int__(0x33); @@ -62,6 +63,7 @@ MOUSE::MOUSE (BITMAP ** shpl) Goto(SCR_WID/2, SCR_HIG/2); Z = 127; Step(1); + */ } @@ -86,6 +88,8 @@ MOUSE::~MOUSE (void) void MOUSE::On (void) { + // TODO Mouse +/* if (SeqPtr && Exist) { _CX = X + X; // horizontal position @@ -117,6 +121,7 @@ void MOUSE::On (void) Step(0); if (Busy) Busy->Step(0); } +*/ } @@ -126,6 +131,8 @@ void MOUSE::On (void) void MOUSE::Off (void) { +//TODO MOuse ASM + /* if (SeqPtr == 0) { if (Exist) @@ -140,6 +147,7 @@ void MOUSE::Off (void) Step(1); if (Busy) Busy->Step(1); } + */ } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 67a16a8563..733acb2398 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -34,8 +34,8 @@ #include "cge/mouse.h" #include "cge/cge_main.h" #include <dos.h> -#include <alloc.h> -#include <mem.h> +//#include <alloc.h> +//#include <mem.h> #include <stdio.h> #include <stdlib.h> #include "cge/keybd.h" @@ -102,12 +102,12 @@ static void SNGame (SPRITE * spr, int num) if (Game) // continue game { - int i = random(3), hand = (dup[0]->ShpCnt == 6); + int i = new_random(3), hand = (dup[0]->ShpCnt == 6); ++ Stage; if (hand && Stage > DRESSED) ++ hand; if ( Debug( i >= 0 || ) - dup[i] == spr && random(3) == 0) + dup[i] == spr && new_random(3) == 0) { SNPOST(SNSEQ, -1, 3, dup[0]); // yes SNPOST(SNSEQ, -1, 3, dup[1]); // yes @@ -204,9 +204,9 @@ static void SNGame (SPRITE * spr, int num) } else // cont { - k1->Step(random(6)); - k2->Step(random(6)); - k3->Step(random(6)); + k1->Step(new_random(6)); + k2->Step(new_random(6)); + k3->Step(new_random(6)); ///-------------------- if (spr->Ref == 1 && KEYBOARD::Key[ALT]) { @@ -237,7 +237,7 @@ static void SNGame (SPRITE * spr, int num) Game = false; return; } - else k3->Step(random(5)); + else k3->Step(new_random(5)); } if (count < 100) { @@ -383,7 +383,8 @@ void Hide1 (SPRITE * spr) void SNGhost (BITMAP * bmp) { - bmp->Hide(FP_OFF(bmp->M), FP_SEG(bmp->M)); + // TODO : Get x and y from M but not using segment / offset + //bmp->Hide(FP_OFF(bmp->M), FP_SEG(bmp->M)); bmp->M = NULL; delete bmp; } @@ -470,7 +471,7 @@ void FeedSnail (SPRITE * spr, SNLIST snq) //-------------------------------------------------------------------------- -char * SNAIL::ComTxt[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", +const char * SNAIL::ComTxt[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", "HIDE", "SAY", "INF", "TIME", "CAVE", "KILL", "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", "GIVE", @@ -502,7 +503,7 @@ SNAIL::SNAIL (bool turbo) SNAIL::~SNAIL (void) { - if (SNList) farfree(SNList); + if (SNList) free(SNList); } @@ -766,7 +767,7 @@ void SNCover (SPRITE * spr, int xref) xspr->Cave = spr->Cave; xspr->Goto(spr->X, spr->Y); ExpandSprite(xspr); - if ((xspr->Flags.Shad = spr->Flags.Shad) == true) + if ((xspr->Flags.Shad = spr->Flags.Shad) == TRUE) { VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr->Prev), xspr); spr->Flags.Shad = false; @@ -786,7 +787,7 @@ void SNUncover (SPRITE * spr, SPRITE * xspr) spr->Flags.Hide = false; spr->Cave = xspr->Cave; spr->Goto(xspr->X, xspr->Y); - if ((spr->Flags.Shad = xspr->Flags.Shad) == true) + if ((spr->Flags.Shad = xspr->Flags.Shad) == TRUE) { VGA::ShowQ.Insert(VGA::ShowQ.Remove(xspr->Prev), spr); xspr->Flags.Shad = false; @@ -1099,7 +1100,7 @@ void SNFlash (bool on) if (pal) { int i; - _fmemcpy(pal, SysPal, PAL_SIZ); + memcpy(pal, SysPal, PAL_SIZ); for (i = 0; i < PAL_CNT; i ++) { register int c; @@ -1285,7 +1286,8 @@ void SNAIL::RunCom (void) case SNSOUND : SNSound(sprel, snc->Val, count); count = 1; break; case SNCOUNT : count = snc->Val; break; - case SNEXEC : ((void(*)(int)) (snc->Ptr))(snc->Val); break; + // TODO: Handle correctly the execution of function pointer coming from Message send SNPOST + //case SNEXEC : ((void(*)(int)) (snc->Ptr))(snc->Val); break; case SNSTEP : sprel->Step(); break; case SNZTRIM : SNZTrim(sprel); break; case SNGHOST : SNGhost((BITMAP *) snc->Ptr); break; diff --git a/engines/cge/snail.h b/engines/cge/snail.h index bf47fa13d4..88bb5f09dd 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -83,12 +83,12 @@ enum SNLIST { NEAR, TAKE }; class SNAIL { +public: struct COM { SNCOM Com; int Ref; int Val; void * Ptr; } * SNList; uint8 Head, Tail; bool Turbo, Busy, TextDelay; uint16 Pause; -public: - static char * ComTxt[]; + static const char * ComTxt[]; bool TalkEnable; SNAIL (bool turbo = false); ~SNAIL (void); diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 662d480778..8d29a807d7 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -130,6 +130,7 @@ EC void SNDMIDIStop (void); // WARNING: Uses ALL registers! EC void SNDMIDIPlay (void); -// End of namespace CGE +} // End of namespace CGE + #endif diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 81dd457603..11385c12e3 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -39,7 +39,7 @@ #include "cge/text.h" #include "cge/cfile.h" #include "cge/vol.h" -#include <alloc.h> +//#include <alloc.h> namespace CGE { @@ -95,7 +95,7 @@ void SOUND::Play (DATACK * wav, int pan, int cnt) if (wav) { Stop(); - smpinf.saddr = (char *) &*(wav->EAddr()); + smpinf.saddr = (uint8 *) &*(wav->EAddr()); smpinf.slen = (uint16)wav->Size(); smpinf.span = pan; smpinf.sflag = cnt; @@ -196,7 +196,8 @@ void FX::Preload (int ref0) { static char fname[] = "FX00000.WAV"; wtom(ref, fname+2, 10, 5); - DATACK * wav = LoadWave(&INI_FILE(fname), &Emm); + INI_FILE file = INI_FILE(fname); + DATACK * wav = LoadWave(&file, &Emm); if (wav) { HAN * p = &Cache[Find(0)]; @@ -216,7 +217,8 @@ DATACK * FX::Load (int idx, int ref) static char fname[] = "FX00000.WAV"; wtom(ref, fname+2, 10, 5); - DATACK * wav = LoadWave(&INI_FILE(fname), &Emm); + INI_FILE file = INI_FILE(fname); + DATACK * wav = LoadWave(&file, &Emm); if (wav) { HAN * p = &Cache[idx]; @@ -309,13 +311,13 @@ EC void * Patch (int pat) if (! snd.Error) { uint16 siz = (uint16) snd.Size(); - p = (uint8 *) farmalloc(siz); + p = (uint8 *) malloc(siz); if (p) { snd.Read(p, siz); if (snd.Error) { - farfree(p); + free(p); p = NULL; } } diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 0e45e65b73..7e5ac71782 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -34,7 +34,7 @@ #include <stdio.h> #include <process.h> #include <dos.h> -#include <alloc.h> +//#include <alloc.h> #include <string.h> #ifdef DEBUG @@ -60,17 +60,16 @@ static STARTUP StartUp; -void quit_now (int ref) -{ - fputs(Text[ref], stderr); - fputc('\n', stderr); - _exit(1); +void quit_now(int ref){ + error("%d\n", Text[ref]); } bool STARTUP::get_parms (void) { + // TODO do params + /* int i = _argc; while (i > 1) { @@ -114,6 +113,7 @@ bool STARTUP::get_parms (void) #endif #endif if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; + */ return true; } @@ -122,6 +122,8 @@ bool STARTUP::get_parms (void) STARTUP::STARTUP (void) { + //TOdO startup in scummvm + /* uint32 m = farcoreleft() >> 10; if (m < 0x7FFF) Core = (int) m; else Core = 0x7FFF; @@ -149,6 +151,7 @@ STARTUP::STARTUP (void) if (! cfg.Error) STARTUP::SoundOk = 1; } } + */ } diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 9c15ac1b65..d305d1d27e 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -31,8 +31,8 @@ #include "cge/game.h" #include "cge/mouse.h" #include <dos.h> -#include <alloc.h> -#include <mem.h> +//#include <alloc.h> +//#include <mem.h> namespace CGE { @@ -70,9 +70,9 @@ FONT::FONT (const char * name) FONT::~FONT (void) { - farfree(Map); - farfree(Pos); - farfree(Wid); + free(Map); + free(Pos); + free(Wid); } @@ -212,10 +212,10 @@ void TALK::Update (const char * tx) else { int cw = Font.Wid[*tx], i; - char * f = Font.Map + Font.Pos[*tx]; + uint8 * f = Font.Map + Font.Pos[*tx]; for (i = 0; i < cw; i ++) { - char * p = m; + uint8 * p = m; uint16 n; register uint16 b = * (f ++); for (n = 0; n < FONT_HIG; n ++) @@ -246,13 +246,13 @@ BITMAP * TALK::Box (uint16 w, uint16 h) if (h < 8) h = 8; b = farnew(uint8, n = w * h); if (! b) VGA::Exit("No core"); - _fmemset(b, TEXT_BG, n); + memset(b, TEXT_BG, n); if (Mode) { p = b; q = b + n - w; - _fmemset(p, LGRAY, w); - _fmemset(q, DGRAY, w); + memset(p, LGRAY, w); + memset(q, DGRAY, w); while (p < q) { p += w; @@ -301,10 +301,10 @@ void TALK::PutLine (int line, const char * text) // clear whole rectangle p = v; // assume blanked line above text - _fmemcpy(p, p-lsiz, rsiz); p += psiz; // tricky replicate lines for plane 0 - _fmemcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 1 - _fmemcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 2 - _fmemcpy(p, p-lsiz, rsiz); // same for plane 3 + memcpy(p, p-lsiz, rsiz); p += psiz; // tricky replicate lines for plane 0 + memcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 1 + memcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 2 + memcpy(p, p-lsiz, rsiz); // same for plane 3 // paint text line if (text) diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 76539fbcf9..aab6834c28 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -29,6 +29,8 @@ #define __TALK__ #include "cge/vga13h.h" +#include "cge/general.h" +#include "cge/jbw.h" //#include <dir.h> namespace CGE { @@ -45,7 +47,7 @@ namespace CGE { - +#define MAXPATH 128 class FONT { @@ -105,4 +107,4 @@ public: } // End of namespace CGE -#endif
\ No newline at end of file +#endif diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index df8ca4cfe5..9ee6244f22 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -50,11 +50,10 @@ TEXT::TEXT (const char * fname, int size) { Cache = new HAN[size]; MergeExt(FileName, fname, SAY_EXT); - if (! INI_FILE::Exist(FileName)) - { - fputs("No talk\n", stderr); - _exit(1); - } + if (! INI_FILE::Exist(FileName)) { + error("No talk\n"); + } + for (Size = 0; Size < size; Size ++) { Cache[Size].Ref = 0; @@ -124,7 +123,7 @@ void TEXT::Preload (int from, int upto) char line[LINE_MAX+1]; int n; - while ((n = tf.Read(line)) != 0) + while ((n = tf.Read((uint8*)line)) != 0) { char * s; int ref; @@ -168,7 +167,7 @@ char * TEXT::Load (int idx, int ref) char line[LINE_MAX+1]; int n; - while ((n = tf.Read(line)) != 0) + while ((n = tf.Read((uint8*)line)) != 0) { char * s; @@ -289,12 +288,15 @@ void Inf (const char * txt) void SayTime (SPRITE * spr) { +//TODO Get Time +/* static char t[] = "00:00"; struct time ti; gettime(&ti); wtom(ti.ti_hour, t+0, 10, 2); wtom(ti.ti_min, t+3, 10, 2); Say((*t == '0') ? (t+1) : t, spr); + */ } diff --git a/engines/cge/text.h b/engines/cge/text.h index 7394e04b3f..222a3abf7d 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -30,7 +30,7 @@ #include "cge/talk.h" #include "cge/jbw.h" -#include <dir.h> +//#include <dir.h> namespace CGE { @@ -83,4 +83,4 @@ void KillText (void); } // End of namespace CGE -#endif
\ No newline at end of file +#endif diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 415bff7225..86b04bfe0c 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -30,15 +30,15 @@ #include "cge/bitmap.h" #include "cge/vol.h" #include "cge/text.h" -#include <alloc.h> +//#include <alloc.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dos.h> -#include <dir.h> +//#include <dir.h> #include <fcntl.h> -#include <bios.h> +//#include <bios.h> #include <io.h> namespace CGE { @@ -112,11 +112,13 @@ char * NumStr (char * str, int num) - +// TODO Video ASM +/* static void Video (void) { static uint16 SP_S; + asm push bx asm push bp asm push si @@ -131,8 +133,9 @@ static void Video (void) asm pop si asm pop bp asm pop bx -} +} + */ @@ -140,6 +143,7 @@ static void Video (void) uint16 * SaveScreen (void) { + /* TODO ASM uint16 cxy, cur, siz, * scr = NULL, * sav; // horizontal size of text mode screen @@ -187,9 +191,11 @@ uint16 * SaveScreen (void) sav[0] = siz; sav[1] = cur; sav[2] = cxy; - _fmemcpy(sav+3, scr, siz * 2); + memcpy(sav+3, scr, siz * 2); } return sav; + */ + return 0; } @@ -198,6 +204,8 @@ uint16 * SaveScreen (void) void RestoreScreen (uint16 * &sav) { + // TODO RestoreScreen ASM + /* uint16 * scr = NULL; asm mov ax,0x40 // system data segment @@ -209,7 +217,7 @@ void RestoreScreen (uint16 * &sav) sto: // store screen address asm mov word ptr scr+2,ax - _fmemcpy(scr, sav+3, sav[0] * 2); + memcpy(scr, sav+3, sav[0] * 2); _AH = 0x0F; Video(); // active page @@ -221,8 +229,9 @@ void RestoreScreen (uint16 * &sav) _DX = sav[2]; _AH = 0x02; Video(); // set cursor - farfree(sav); + free(sav); sav = NULL; + */ } @@ -318,11 +327,12 @@ extern "C" void TimerProc (void) */ -void interrupt ENGINE::NewTimer (...) +void ENGINE::NewTimer (...) { static SPRITE * spr; static uint8 run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; - + // TODO Timer ASM + /* ___1152_Hz___: SNDMIDIPlay(); @@ -379,6 +389,8 @@ void interrupt ENGINE::NewTimer (...) asm mov sp,oldSP -- run; } + + */ } @@ -591,7 +603,7 @@ SPRITE * SPRITE::Expand (void) if ((Ext = new SPREXT) == NULL) DROP("No core", NULL); if (*File) { - static char * Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; + static const char * Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char line[LINE_MAX], fname[MAXPATH]; BMP_PTR * shplist = new BMP_PTR [ShpCnt+1]; SEQ * seq = NULL; @@ -615,7 +627,7 @@ SPRITE * SPRITE::Expand (void) VGA::Exit("Bad SPR", fname); } - while ((len = sprf.Read(line)) != 0) + while ((len = sprf.Read((uint8*)line)) != 0) { ++ lcnt; if (len && line[len-1] == '\n') line[-- len] = '\0'; @@ -624,11 +636,16 @@ SPRITE * SPRITE::Expand (void) switch (TakeEnum(Comd, strtok(line, " =\t"))) { case 0 : // Name + { SetName(strtok(NULL, "")); break; + } case 1 : // Phase + { shplist[shpcnt ++] = new BITMAP(strtok(NULL, " \t,;/")); break; + } case 2 : // Seq + { seq = (SEQ *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); if (seq == NULL) VGA::Exit("No core", fname); @@ -646,7 +663,9 @@ SPRITE * SPRITE::Expand (void) s->Dy = atoi(strtok(NULL, " \t,;/")); s->Dly = atoi(strtok(NULL, " \t,;/")); break; + } case 3 : // Near + { if (NearPtr != NO_PTR) { nea = (SNAIL::COM *) realloc(nea, (neacnt + 1) * sizeof(*nea)); @@ -661,8 +680,10 @@ SPRITE * SPRITE::Expand (void) c->Ptr = NULL; } } + } break; case 4 : // Take + { if (TakePtr != NO_PTR) { tak = (SNAIL::COM *) realloc(tak, (takcnt + 1) * sizeof(*tak)); @@ -678,6 +699,7 @@ SPRITE * SPRITE::Expand (void) } } break; + } } } } @@ -693,10 +715,10 @@ SPRITE * SPRITE::Expand (void) SetSeq(seq); } else SetSeq((ShpCnt == 1) ? Seq1 : Seq2); - disable(); + //disable(); // disable interupt SetShapeList(shplist); - enable(); + //enable(); // enable interupt if (nea) nea[neacnt-1].Ptr = Ext->Near = nea; else NearPtr = NO_PTR; if (tak) tak[takcnt-1].Ptr = Ext->Take = tak; else TakePtr = NO_PTR; } @@ -807,7 +829,7 @@ void SPRITE::KillXlat (void) switch (MemType(m)) { case NEAR_MEM : delete[] (uint8 *) m; break; - case FAR_MEM : farfree(m); break; + case FAR_MEM : free(m); break; } for (b = Ext->ShpList; *b; b ++) (*b)->M = NULL; Flags.Xlat = false; @@ -863,7 +885,7 @@ void SPRITE::Center (void) void SPRITE::Show (void) { register SPREXT * e; - asm cli // critic section... + // asm cli // critic section... e = Ext; e->x0 = e->x1; e->y0 = e->y1; @@ -871,7 +893,7 @@ void SPRITE::Show (void) e->x1 = X; e->y1 = Y; e->b1 = Shp(); - asm sti // ...done! +// asm sti // ...done! if (! Flags.Hide) { if (Flags.Xlat) e->b1->XShow(e->x1, e->y1); @@ -919,8 +941,9 @@ BMP_PTR SPRITE::Ghost (void) bmp->W = e->b1->W; bmp->H = e->b1->H; if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) VGA::Exit("No Core"); - bmp->V = (uint8 *) _fmemcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); - bmp->M = (uint8 *) MK_FP(e->y1, e->x1); + bmp->V = (uint8 *) memcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); + // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment + //bmp->M = (uint8 *) MK_FP(e->y1, e->x1); return bmp; } return NULL; @@ -1095,11 +1118,16 @@ DAC * VGA::NewColors = NULL; bool VGA::SetPal = false; int VGA::Mono = 0; QUEUE VGA::ShowQ = true, VGA::SpareQ = false; + +// TODO: Was direct mapping to VGA buffers.. need to create scummvm surfaces for that +uint8 * VGA::Page[4] = { 0, 0, 0, 0 }; + +/* uint8 * VGA::Page[4] = { (uint8 *) MK_FP(SCR_SEG, 0x0000), (uint8 *) MK_FP(SCR_SEG, 0x4000), (uint8 *) MK_FP(SCR_SEG, 0x8000), (uint8 *) MK_FP(SCR_SEG, 0xC000) }; - +*/ @@ -1114,13 +1142,16 @@ VGA::VGA (int mode) char * txt = Text[i]; if (txt) { - puts(txt); - #ifndef DEBUG +// puts(txt); + warning(txt); + #ifndef DEBUG std = false; #endif } } - if (std) puts(Copr); + if (std) +// puts(Copr); + warning(Copr); SetStatAdr(); if (StatAdr != VGAST1_) ++ Mono; if (IsVga()) @@ -1146,33 +1177,27 @@ VGA::~VGA (void) Mono = 0; if (IsVga()) { + Common::String buffer = ""; Clear(); SetMode(OldMode); SetColors(); RestoreScreen(OldScreen); Sunrise(OldColors); - if (OldColors) farfree(OldColors); - if (NewColors) farfree(NewColors); - if (Msg) fputs(Msg, stderr); + if (OldColors) free(OldColors); + if (NewColors) free(NewColors); + if (Msg) + buffer = Common::String(Msg); if (Nam) - { - fputs(" [", stderr); - fputs(Nam, stderr); - fputc(']', stderr); - } - if (Msg || Nam) fputc('\n', stderr); - #ifdef REPORT - fputs(Report, stderr); - #endif + buffer = buffer + " [" + Nam + "]"; + + warning(buffer.c_str()); } } - - - void VGA::SetStatAdr (void) { + /* TODO SetStatADR ASM asm mov dx,VGAMIr_ asm in al,dx asm test al,1 // CGA addressing mode flag @@ -1181,6 +1206,7 @@ void VGA::SetStatAdr (void) asm xor al,0x60 // MDA addressing set_mode_adr: StatAdr = _AX; + */ } @@ -1191,6 +1217,8 @@ void VGA::SetStatAdr (void) #pragma argsused void VGA::WaitVR (bool on) { + // TODO Wait vertical retrace ASM +/* _DX = StatAdr; _AH = (on) ? 0x00 : 0x08; @@ -1203,6 +1231,7 @@ void VGA::WaitVR (bool on) asm jnz wait asm xor ah,0x08 asm loop wait + */ } @@ -1212,6 +1241,7 @@ void VGA::WaitVR (bool on) void VGA::Setup (VgaRegBlk * vrb) { +/* TODO VGA setup WaitVR(); // *--LOOK!--* resets VGAATR logic asm cld asm mov si, vrb // take address of parameter table @@ -1248,6 +1278,7 @@ void VGA::Setup (VgaRegBlk * vrb) asm jmp write // continue standard routine xit: + */ } @@ -1257,6 +1288,8 @@ void VGA::Setup (VgaRegBlk * vrb) int VGA::SetMode (int mode) { + /* TODO VGA Set Mode + Clear(); // get current mode asm mov ah,0x0F @@ -1275,6 +1308,8 @@ int VGA::SetMode (int mode) // return previous mode asm pop ax return _AX; + */ + return 0; } @@ -1284,6 +1319,7 @@ int VGA::SetMode (int mode) void VGA::GetColors (DAC * tab) { + /* TODO GetColors ASM asm cld asm les di,tab // color table asm mov dx,0x3C7 // PEL address read mode register @@ -1300,6 +1336,8 @@ void VGA::GetColors (DAC * tab) sto: asm stosb // store 1 color asm loop gc // next one? + + */ } @@ -1307,6 +1345,9 @@ void VGA::GetColors (DAC * tab) void VGA::SetColors (DAC * tab, int lum) { + + /* TODO SetColors + DAC * des = NewColors; asm push ds @@ -1350,6 +1391,7 @@ void VGA::SetColors (DAC * tab, int lum) asm cmp di,cx asm jb mono } + */ SetPal = true; } @@ -1360,7 +1402,7 @@ void VGA::SetColors (DAC * tab, int lum) void VGA::SetColors (void) { - _fmemset(NewColors, 0, PAL_SIZ); + memset(NewColors, 0, PAL_SIZ); UpdateColors(); } @@ -1422,6 +1464,7 @@ void VGA::Show (void) void VGA::UpdateColors (void) { + /* TODO UpdateColors ASM DAC * tab = NewColors; asm push ds @@ -1445,6 +1488,7 @@ void VGA::UpdateColors (void) asm pop ds + */ } @@ -1455,6 +1499,8 @@ void VGA::UpdateColors (void) void VGA::Update (void) { + // TODO VGA Update + /* uint8 * p = Page[1]; Page[1] = Page[0]; Page[0] = p; @@ -1466,7 +1512,7 @@ void VGA::Update (void) asm dec al asm mov ah,byte ptr p+1 asm out dx,ax - +*/ if (! SpeedTest) WaitVR(); if (SetPal) @@ -1485,6 +1531,7 @@ void VGA::Update (void) void VGA::Clear (uint8 color) { + /* TODO Clear ASM uint8 * a = (uint8 *) MK_FP(SCR_SEG, 0); asm mov dx,VGASEQ_ @@ -1497,6 +1544,7 @@ void VGA::Clear (uint8 color) asm mov al,color asm rep stosb asm stosb + */ } @@ -1506,6 +1554,7 @@ void VGA::Clear (uint8 color) void VGA::CopyPage (uint16 d, uint16 s) { + /* TODO CopyPage uint8 * S = Page[s & 3], * D = Page[d & 3]; asm mov dx,VGAGRA_ @@ -1536,6 +1585,7 @@ void VGA::CopyPage (uint16 d, uint16 s) asm pop dx asm pop ax asm out dx,al // end of copy mode + */ } @@ -1546,13 +1596,17 @@ void VGA::CopyPage (uint16 d, uint16 s) void VGA::Exit (const char * txt, const char * name) { + // TODO Properly exit + /* Msg = txt; Nam = name; - #ifdef REPORT + + #ifdef REPORT wtom(coreleft(), Report + NREP, 10, 5); dwtom(farcoreleft(), Report + FREP, 10, 6); #endif exit(0); + */ } @@ -1573,6 +1627,8 @@ void VGA::Exit (int tref, const char * name) void BITMAP::XShow (int x, int y) { + // TODO XShow ASM + /* uint8 rmsk = x % 4, mask = 1 << rmsk, * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; @@ -1650,6 +1706,8 @@ void BITMAP::XShow (int x, int y) asm pop ds asm pop si asm pop bx + + */ } @@ -1659,6 +1717,9 @@ void BITMAP::XShow (int x, int y) void BITMAP::Show (int x, int y) { + + // TODO Show ASM + /* uint8 mask = 1 << (x & 3), * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); uint8 * v = V; @@ -1722,6 +1783,7 @@ void BITMAP::Show (int x, int y) asm cmp ah,mask asm jne plane asm pop ds + */ } @@ -1730,6 +1792,8 @@ void BITMAP::Show (int x, int y) void BITMAP::Hide (int x, int y) { + // TODO Bitmap Hide ASM + /* uint8 * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); HideDesc * b = B; @@ -1790,6 +1854,7 @@ void BITMAP::Hide (int x, int y) asm pop ds asm pop si // asm pop bx +*/ } } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index e5c34d238f..40dfc41a12 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -325,7 +325,7 @@ uint8 Closest (CBLK * pal, CBLK x) char * NumStr (char * str, int num); - void Video (void); + //static void Video (void); uint16 * SaveScreen (void); void RestoreScreen (uint16 * &sav); SPRITE * SpriteAt (int x, int y); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 8178868578..46bb45e9c9 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -28,7 +28,7 @@ #include "cge/vmenu.h" #include "cge/mouse.h" #include <string.h> -#include <alloc.h> +//#include <alloc.h> namespace CGE { @@ -51,9 +51,9 @@ MENU_BAR::MENU_BAR (uint16 w) int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; uint8 * p = farnew(uint8, i), * p1, * p2; - _fmemset(p+w, TRANS, i-2*w); - _fmemset(p, MB_LT, w); - _fmemset(p+i-w, MB_RB, w); + memset(p+w, TRANS, i-2*w); + memset(p, MB_LT, w); + memset(p+i-w, MB_RB, w); p1 = p; p2 = p+i-1; for (i = 0; i < h; i ++) @@ -89,7 +89,7 @@ char * VMGather (CHOICE * list) len += strlen(cp->Text); ++ h; } - vmgt = new uint8[len+h]; + vmgt = new char[len+h]; if (vmgt) { *vmgt = '\0'; diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 9f4391cc9a..40490f2271 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -28,6 +28,7 @@ #include "cge/vol.h" //#include <alloc.h> #include "common/system.h" +#include "common/str.h" #include <stdlib.h> #include <string.h> #include <errno.h> @@ -41,7 +42,10 @@ namespace CGE { #ifndef DROP_H - #define DROP(m,n) { printf("%s [%s]\n", (m), (n)); _exit(1); } + // TODO Replace printf by scummvm equivalent + + #define DROP(m,n) { } + //#define DROP(m,n) { printf("%s [%s]\n", (m), (n)); _exit(1); } #endif @@ -66,7 +70,7 @@ VFILE::VFILE (const char * name, IOMODE mode) { if (Dat.File.Error || Cat.Error) DROP("Bad volume data", NULL); BT_KEYPACK * kp = Cat.Find(name); - if (_fstricmp(kp->Key, name) != 0) Error = ENOFILE; + if (scumm_stricmp(kp->Key, name) != 0) Error = 1; EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; } #ifdef VOL_UPD @@ -89,7 +93,7 @@ VFILE::~VFILE (void) bool VFILE::Exist (const char * name) { - return _fstricmp(Cat.Find(name)->Key, name) == 0; + return scumm_stricmp(Cat.Find(name)->Key, name) == 0; } diff --git a/engines/cge/vol.h b/engines/cge/vol.h index b63b08e7a1..421bd7593c 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -54,7 +54,7 @@ namespace CGE { class DAT { - friend VFILE; + friend class VFILE; static VOLBASE File; public: static bool Append (uint8 * buf, uint16 len); diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 0d1408ccf6..a8da4f9e72 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -135,6 +135,7 @@ extern CKID DATA; DATACK * LoadWave (XFILE * file, EMM * emm = NULL); -// End of namespace CGE +} // End of namespace CGE + #endif |