Skip to content

Commit

Permalink
ACCESS: Added screen loading and file index load fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Aug 2, 2014
1 parent a35ba4c commit 7a63e12
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 36 deletions.
10 changes: 8 additions & 2 deletions engines/access/amazon/amazon_game.cpp
Expand Up @@ -35,8 +35,14 @@ void AmazonEngine::doTitle() {
_screen->forceFadeOut();
_events->hideCursor();

_sound->loadSound(98, 30);

_sound->_soundTable[0] = _sound->loadSound(98, 30);
_sound->_soundPriority[0] = 1;
_sound->_soundTable[1] = _sound->loadSound(98, 8);
_sound->_soundPriority[1] = 2;

_screen->_loadPalFlag = false;
byte *scr = _files->loadScreen(0, 3);
_screen->copyBuffer(scr);
}

} // End of namespace Amazon
Expand Down
71 changes: 51 additions & 20 deletions engines/access/files.cpp
Expand Up @@ -44,41 +44,72 @@ FileManager::~FileManager() {
_file.close();
}

void FileManager::loadFile(int fileNum, int subfile) {
byte *FileManager::loadFile(int fileNum, int subfile) {
setAppended(fileNum);
gotoAppended(subfile);

handleFile();
return handleFile();
}

void FileManager::loadFile(const Common::String &filename) {
byte *FileManager::loadFile(const Common::String &filename) {
// Open the file
openFile(filename);

// Get a stream for the entire file
delete _stream;
_stream = _file.readStream(_file.size());

return handleFile();
}

void FileManager::openFile(const Common::String &filename) {
// Open up the file
_fileNumber = -1;
_file.close();
if (_file.open(filename))
error("Could not open file - %s", filename.c_str());
}

// Get a stream for the entire file
byte *FileManager::loadScreen(int fileNum, int subfile) {
setAppended(fileNum);
gotoAppended(subfile);
_vm->_screen->loadPalette(_stream);

return handleFile();
}

byte *FileManager::loadScreen(const Common::String &filename) {
// Open the file
openFile(filename);

// Get the palette
_vm->_screen->loadPalette(_stream);

// Get a stream for the remainder of the file
delete _stream;
_stream = _file.readStream(_file.size());

handleFile();
return handleFile();
}

void FileManager::handleFile() {
byte *FileManager::handleFile() {
char header[3];
_stream->read(&header[0], 3);

if (!strncmp(header, "BDE", 3))
if (!strncmp(header, "DBE", 3))
// Decompress the resource
decompressFile();
else
// Not compressed, so move back to start of data
_stream->seek(0);
return decompressFile();

// Not compressed, so pass out all of the file
_stream->seek(0);
byte *data = new byte[_stream->size()];
_stream->read(data, _stream->size());

return data;
}

void FileManager::decompressFile() {
// TODO
byte *FileManager::decompressFile() {
error("TODO: decompression");
}

void FileManager::setAppended(int fileNum) {
Expand All @@ -90,17 +121,17 @@ void FileManager::setAppended(int fileNum) {
error("Could not open file %s", _filenames[fileNum]);

// Read in the file index
_fileIndex.resize(50);
for (int i = 0; i < 50; ++i) {
_fileIndex[i]._offset = _file.readUint32LE();
_fileIndex[i]._nextOffset = _file.readUint32LE();
}
int count = _file.readUint16LE();
assert(count <= 100);
_fileIndex.resize(count);
for (int i = 0; i < count; ++i)
_fileIndex[i] = _file.readUint32LE();
}
}

void FileManager::gotoAppended(int subfile) {
uint32 offset = _fileIndex[subfile]._offset;
uint32 size = _fileIndex[subfile]._nextOffset - offset;
uint32 offset = _fileIndex[subfile];
uint32 size = _fileIndex[subfile + 1] - offset;

_file.seek(offset);
delete _stream;
Expand Down
35 changes: 24 additions & 11 deletions engines/access/files.h
Expand Up @@ -24,47 +24,60 @@
#define ACCESS_FILES_H

#include "common/scummsys.h"
#include "common/array.h"
#include "common/file.h"

namespace Access {

class AccessEngine;

struct FileEntry {
uint32 _offset;
uint32 _nextOffset;
};

class FileManager {
private:
AccessEngine *_vm;
const char * const *_filenames;

void handleFile();
void openFile(const Common::String &filename);

byte *handleFile();

void decompressFile();
byte *decompressFile();

public:
int _fileNumber;
Common::File _file;
Common::SeekableReadStream *_stream;
Common::Array<FileEntry> _fileIndex;
Common::Array<uint32> _fileIndex;
uint32 _entryOffset;
uint32 _nextOffset;
public:
FileManager(AccessEngine *vm);
~FileManager();

void loadFile(int fileNum, int subfile);
/**
* Load a given subfile from a container file
*/
byte *loadFile(int fileNum, int subfile);

/**
* Load a given file by name
*/
byte *loadFile(const Common::String &filename);

void loadFile(const Common::String &filename);
/**
* Load a given scren from a container file
*/
byte *loadScreen(int fileNum, int subfile);

/**
* Load a given screen by name
*/
byte *loadScreen(const Common::String &filename);

/**
* Open up a sub-file container file
*/
void setAppended(int fileNum);


/**
* Open up a sub-file resource within an alrady opened container file.
*/
Expand Down
17 changes: 17 additions & 0 deletions engines/access/screen.cpp
Expand Up @@ -32,6 +32,7 @@ namespace Access {
Screen::Screen(AccessEngine *vm) : _vm(vm) {
create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
Common::fill(&_tempPalette[0], &_tempPalette[PALETTE_SIZE], 0);
_loadPalFlag = false;
}

void Screen::setDisplayScan() {
Expand All @@ -49,6 +50,16 @@ void Screen::setInitialPalettte() {
g_system->getPaletteManager()->setPalette(INITIAL_PALETTE, 0, 18);
}

void Screen::loadPalette(Common::SeekableReadStream *stream) {
stream->read(&_rawPalette[0], PALETTE_SIZE);
setPalette();
_loadPalFlag = true;
}

void Screen::setPalette() {
g_system->getPaletteManager()->setPalette(&_rawPalette[0], 0, PALETTE_COUNT);
}

void Screen::updatePalette() {
g_system->getPaletteManager()->setPalette(&_tempPalette[0], 0, PALETTE_COUNT);
updateScreen();
Expand Down Expand Up @@ -97,4 +108,10 @@ void Screen::forceFadeIn() {
} while (repeatFlag);
}

void Screen::copyBuffer(const byte *data) {
byte *destP = (byte *)getPixels();
Common::copy(data, data + (h * w), destP);
g_system->copyRectToScreen(destP, w, 0, 0, w, h);
}

} // End of namespace Access
12 changes: 12 additions & 0 deletions engines/access/screen.h
Expand Up @@ -25,6 +25,7 @@

#include "common/scummsys.h"
#include "common/rect.h"
#include "common/stream.h"
#include "graphics/surface.h"

namespace Access {
Expand All @@ -40,7 +41,11 @@ class Screen: public Graphics::Surface {
byte _tempPalette[PALETTE_SIZE];
byte _rawPalette[PALETTE_SIZE];

void setPalette();

void updatePalette();
public:
bool _loadPalFlag;
public:
Screen(AccessEngine *vm);

Expand All @@ -65,6 +70,13 @@ class Screen: public Graphics::Surface {
* Set the initial palette
*/
void setInitialPalettte();

void loadPalette(Common::SeekableReadStream *stream);

/**
* Copy a buffer to the screen
*/
void copyBuffer(const byte *data);
};

} // End of namespace Access
Expand Down
17 changes: 16 additions & 1 deletion engines/access/sound.cpp
Expand Up @@ -20,10 +20,25 @@
*
*/

#include "common/algorithm.h"
#include "access/access.h"
#include "access/sound.h"

namespace Access {

SoundManager::SoundManager(AccessEngine *vm) : _vm(vm) {}
SoundManager::SoundManager(AccessEngine *vm) : _vm(vm) {
Common::fill(&_soundTable[0], &_soundTable[MAX_SOUNDS], (byte *)nullptr);
Common::fill(&_soundPriority[0], &_soundPriority[MAX_SOUNDS], 0);
}

SoundManager::~SoundManager() {
for (int i = 0; i < MAX_SOUNDS; ++i)
delete _soundTable[i];
}

byte *SoundManager::loadSound(int fileNum, int subfile) {
return _vm->_files->loadFile(fileNum, subfile);
}


} // End of namespace Access
10 changes: 8 additions & 2 deletions engines/access/sound.h
Expand Up @@ -23,6 +23,10 @@
#ifndef ACCESS_SOUND_H
#define ACCESS_SOUND_H

#include "common/scummsys.h"

#define MAX_SOUNDS 20

namespace Access {

class AccessEngine;
Expand All @@ -31,11 +35,13 @@ class SoundManager {
private:
AccessEngine *_vm;
public:
int _soundPriority;
byte *_soundTable[MAX_SOUNDS];
int _soundPriority[MAX_SOUNDS];
public:
SoundManager(AccessEngine *vm);
~SoundManager();

void loadSound(int fileNum, int subfile) {}
byte *loadSound(int fileNum, int subfile);
};

} // End of namespace Access
Expand Down

0 comments on commit 7a63e12

Please sign in to comment.