Skip to content

Commit

Permalink
SCI32: Partially implement kCD
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover committed Aug 19, 2016
1 parent 051eae4 commit 0a4a256
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
2 changes: 2 additions & 0 deletions engines/sci/engine/kernel.h
Expand Up @@ -610,6 +610,8 @@ reg_t kSave(EngineState *s, int argc, reg_t *argv);
reg_t kAutoSave(EngineState *s, int argc, reg_t *argv);
reg_t kList(EngineState *s, int argc, reg_t *argv);
reg_t kCD(EngineState *s, int argc, reg_t *argv);
reg_t kCheckCD(EngineState *s, int argc, reg_t *argv);
reg_t kGetSavedCD(EngineState *s, int argc, reg_t *argv);
reg_t kAddPicAt(EngineState *s, int argc, reg_t *argv);
reg_t kAddBefore(EngineState *s, int argc, reg_t *argv);
reg_t kMoveToFront(EngineState *s, int argc, reg_t *argv);
Expand Down
9 changes: 8 additions & 1 deletion engines/sci/engine/kernel_tables.h
Expand Up @@ -395,6 +395,13 @@ static const SciKernelMapSubEntry kBitmap_subops[] = {
SCI_SUBOPENTRY_TERMINATOR
};

// version, subId, function-mapping, signature, workarounds
static const SciKernelMapSubEntry kCD_subops[] = {
{ SIG_SINCE_SCI21MID, 0, MAP_CALL(CheckCD), "(i)", NULL },
{ SIG_SINCE_SCI21MID, 1, MAP_CALL(GetSavedCD), "", NULL },
SCI_SUBOPENTRY_TERMINATOR
};

// version, subId, function-mapping, signature, workarounds
static const SciKernelMapSubEntry kList_subops[] = {
{ SIG_SINCE_SCI21, 0, MAP_CALL(NewList), "", NULL },
Expand Down Expand Up @@ -871,7 +878,7 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_DUMMY(PointSize), SIG_EVERYWHERE, "(.*)", NULL, NULL },

// SCI2.1 Kernel Functions
{ MAP_CALL(CD), SIG_EVERYWHERE, "(.*)", NULL, NULL },
{ MAP_CALL(CD), SIG_SINCE_SCI21MID, SIGFOR_ALL, "(.*)", kCD_subops, NULL },
{ MAP_CALL(IsOnMe), SIG_EVERYWHERE, "iioi", NULL, NULL },
{ MAP_CALL(List), SIG_SINCE_SCI21, SIGFOR_ALL, "(.*)", kList_subops, NULL },
{ MAP_CALL(MulDiv), SIG_EVERYWHERE, "iii", NULL, NULL },
Expand Down
38 changes: 20 additions & 18 deletions engines/sci/engine/kfile.cpp
Expand Up @@ -40,6 +40,9 @@
#include "sci/engine/savegame.h"
#include "sci/sound/audio.h"
#include "sci/console.h"
#ifdef ENABLE_SCI32
#include "sci/resource.h"
#endif

namespace Sci {

Expand Down Expand Up @@ -196,26 +199,25 @@ reg_t kValidPath(EngineState *s, int argc, reg_t *argv) {
#ifdef ENABLE_SCI32

reg_t kCD(EngineState *s, int argc, reg_t *argv) {
// TODO: Stub
switch (argv[0].toUint16()) {
case 0:
if (argc == 1) {
// Check if a disc is in the drive
return TRUE_REG;
} else {
// Check if the specified disc is in the drive
// and return the current disc number. We just
// return the requested disc number.
return argv[1];
}
case 1:
// Return the current CD number
return make_reg(0, 1);
default:
warning("CD(%d)", argv[0].toUint16());
if (!s)
return make_reg(0, getSciVersion());
error("not supposed to call this");
}

reg_t kCheckCD(EngineState *s, int argc, reg_t *argv) {
const int16 cdNo = argc > 0 ? argv[0].toSint16() : 0;

if (cdNo) {
g_sci->getResMan()->findDisc(cdNo);
}

return NULL_REG;
return make_reg(0, g_sci->getResMan()->getCurrentDiscNo());
}

reg_t kGetSavedCD(EngineState *s, int argc, reg_t *argv) {
// TODO: This is wrong, CD number needs to be available prior to
// the save game being loaded
return make_reg(0, g_sci->getResMan()->getCurrentDiscNo());
}

#endif
Expand Down
11 changes: 10 additions & 1 deletion engines/sci/resource.cpp
Expand Up @@ -859,6 +859,13 @@ void ResourceManager::addResourcesFromChunk(uint16 id) {
scanNewSources();
}

void ResourceManager::findDisc(const int16 discNo) {
// Since all resources are expected to be copied from the original discs
// into a single game directory, this call just records the number of the CD
// that the game has requested
_currentDiscNo = discNo;
}

#endif

void ResourceManager::freeResourceSources() {
Expand All @@ -878,7 +885,9 @@ void ResourceManager::init() {
_LRU.clear();
_resMap.clear();
_audioMapSCI1 = NULL;

#ifdef ENABLE_SCI32
_currentDiscNo = 1;
#endif
// FIXME: put this in an Init() function, so that we can error out if detection fails completely

_mapVersion = detectMapVersion();
Expand Down
18 changes: 18 additions & 0 deletions engines/sci/resource.h
Expand Up @@ -397,6 +397,24 @@ class ResourceManager {
* resource manager.
*/
void addResourcesFromChunk(uint16 id);

/**
* Updates the currently active disc number.
*/
void findDisc(const int16 discNo);

/**
* Gets the currently active disc number.
*/
int16 getCurrentDiscNo() const { return _currentDiscNo; }

private:
/**
* The currently active disc number.
*/
int16 _currentDiscNo;

public:
#endif

bool detectHires();
Expand Down

0 comments on commit 0a4a256

Please sign in to comment.