SCI: Implement kFileIOCopy

Allows patching a Phantasmagoria 1 script to copy instead of rename.
Although most games can call this through their File:copy script, none
have been discovered yet that do.
This commit is contained in:
sluicebox 2019-12-20 21:39:46 -07:00
parent 568a5bcd7c
commit 649c801839
3 changed files with 21 additions and 0 deletions

View File

@ -725,6 +725,7 @@ reg_t kFileIOFindFirst(EngineState *s, int argc, reg_t *argv);
reg_t kFileIOFindNext(EngineState *s, int argc, reg_t *argv);
reg_t kFileIOExists(EngineState *s, int argc, reg_t *argv);
reg_t kFileIORename(EngineState *s, int argc, reg_t *argv);
reg_t kFileIOCopy(EngineState *s, int argc, reg_t *argv);
#ifdef ENABLE_SCI32
reg_t kFileIOReadByte(EngineState *s, int argc, reg_t *argv);
reg_t kFileIOWriteByte(EngineState *s, int argc, reg_t *argv);

View File

@ -322,6 +322,7 @@ static const SciKernelMapSubEntry kFileIO_subops[] = {
{ SIG_SCIALL, 9, MAP_CALL(FileIOFindNext), "r", NULL },
{ SIG_SCIALL, 10, MAP_CALL(FileIOExists), "r", NULL },
{ SIG_SINCE_SCI11, 11, MAP_CALL(FileIORename), "rr", NULL },
{ SIG_SINCE_SCI11, 12, MAP_CALL(FileIOCopy), "rr", NULL },
#ifdef ENABLE_SCI32
{ SIG_SINCE_SCI21MID, 13, MAP_CALL(FileIOReadByte), "i", NULL },
{ SIG_SINCE_SCI21MID, 14, MAP_CALL(FileIOWriteByte), "ii", NULL },

View File

@ -912,6 +912,25 @@ reg_t kFileIORename(EngineState *s, int argc, reg_t *argv) {
return SIGNAL_REG;
}
reg_t kFileIOCopy(EngineState *s, int argc, reg_t *argv) {
Common::String oldName = s->_segMan->getString(argv[0]);
Common::String newName = s->_segMan->getString(argv[1]);
oldName = g_sci->wrapFilename(oldName);
newName = g_sci->wrapFilename(newName);
// Phantasmagoria 1 files are small and interoperable with the
// original interpreter so they aren't compressed, see file_open().
bool isCompressed = (g_sci->getGameId() != GID_PHANTASMAGORIA);
// SCI1.1 returns 0 on success and a DOS error code on fail. SCI32
// returns -1 on fail. We just return -1 for all versions.
if (g_sci->getSaveFileManager()->copySavefile(oldName, newName, isCompressed))
return NULL_REG;
else
return SIGNAL_REG;
}
#ifdef ENABLE_SCI32
reg_t kFileIOReadByte(EngineState *s, int argc, reg_t *argv) {
// Read the byte into the low byte of the accumulator