示例#1
0
文件: interp.c 项目: mdhender/jolson
static int symbolcomp(struct object *left, struct object *right) {
    int leftsize = SIZE(left);
    int rightsize = SIZE(right);
    int minsize = leftsize;
    register int i;

    if (rightsize < minsize) {
        minsize = rightsize;
    }

    for (i = 0; i < minsize; i++) {
        if (bytePtr(left)[i] != bytePtr(right)[i]) {
            return bytePtr(left)[i] - bytePtr(right)[i];
        }
    }

    return leftsize - rightsize;
}
SoundBuffer::SoundBuffer(const SoundBuffer &sb) throw()
{
	soundData_.reset();
	format_ = sb.format_;
	buffer_ = sb.buffer_;

	if(sb.soundData_) {
		soundData_ = bytePtr(new BYTE[buffer_.AudioBytes]);
		CopyMemory(soundData_.get(), sb.soundData_.get(), buffer_.AudioBytes);
		buffer_.pAudioData = soundData_.get();
	}
}
示例#3
0
void ObjectStruct::byteAtPut(int i, int x)
{
    byte *bp;
    if ((i <= 0) || (i > 2 * - size)) 
    {
        sysError("index out of range", "byteAtPut");
    }
    else 
    {
        bp = bytePtr();
        bp[i-1] = x;
    }
}
示例#4
0
int ObjectStruct::byteAt(int i)
{
    byte* bp;
    unsigned char t;

    if((i <= 0) || (i > 2 * - size))
        sysError("index out of range", "byteAt");
    else
    {
        bp = bytePtr();
        t = bp[i-1];
        i = (int) t;
    }
    return i;
}
示例#5
0
static void
backTrace(struct object * aContext)
{
	printf("back trace\n");
	while (aContext && (aContext != nilObject)) {
		struct object * arguments; int i;
		printf("message %s ", 
			bytePtr(aContext->data[methodInContext]
				->data[nameInMethod]));
		arguments = aContext->data[argumentsInContext];
		if (arguments && (arguments != nilObject)) {
			printf("(");
			for (i = 0; i < SIZE(arguments); i++)
				printf("%s%s", 
				((i == 0) ? "" : ", "),
				bytePtr(arguments->data[i]->class->
					data[nameInClass]));
			printf(")");
			}
		printf("\n");
		aContext = aContext->data[previousContextInContext];
		}
bool SoundBuffer::LoadFile(const char *soundFile)
{
	if(soundFile == NULL)
		throw Exception(err.SoundBuffer_Fatal_Error, "Cannot find sound file, name is NULL.");

	std::ifstream inputSoundFile(soundFile, std::ios::binary | std::ios::in);
	if(inputSoundFile.bad())
		throw Exception(err.SoundBuffer_Fatal_Error, "Sound file is bad or corrupted.");
		
	DWORD dwChunkId = 0, dwFileSize = 0, dwChunkSize = 0, dwExtra = 0;

	//find for 'RIFF' chunk identifier
	inputSoundFile.seekg(0, std::ios::beg);
	inputSoundFile.read(reinterpret_cast<char*>(&dwChunkId), sizeof(dwChunkId));
	if(dwChunkId != 'FFIR') {
		inputSoundFile.close();
		throw Exception(err.SoundBuffer_Fatal_Error, "Couldn't find the RIFF chunk identifier.\nFile may be corrupted.");
	}
	
	//Get file size
	inputSoundFile.seekg(4, std::ios::beg);
	inputSoundFile.read(reinterpret_cast<char*>(&dwFileSize), sizeof(dwFileSize));
	if(dwFileSize <= 16) {
		inputSoundFile.close();
		throw Exception(err.SoundBuffer_Fatal_Error, "Could not determine file size.\nFile may be corrupted.");
	}
	
	//Get file format
	inputSoundFile.seekg(8, std::ios::beg);
	inputSoundFile.read(reinterpret_cast<char*>(&dwExtra), sizeof(dwExtra));
	if(dwExtra != 'EVAW') {
		inputSoundFile.close();
		throw Exception(err.SoundBuffer_Fatal_Error, "Could not determine file format.\nFile may be corrupted.");
	}
	
	//find 'fmt ' in the chunk id
	bool isFormatOK = false;
	for(unsigned int i = 12; i < dwFileSize; ) {
		inputSoundFile.seekg(i, std::ios::beg);
		inputSoundFile.read(reinterpret_cast<char*>(&dwChunkId), sizeof(dwChunkId));
		inputSoundFile.seekg(i + 4, std::ios::beg);
		inputSoundFile.read(reinterpret_cast<char*>(&dwChunkSize), sizeof(dwChunkSize));
		if(dwChunkId == ' tmf') {
			inputSoundFile.seekg(i + 8, std::ios::beg);
			inputSoundFile.read(reinterpret_cast<char*>(&format_), sizeof(format_));
			isFormatOK = true;
			break;
		}
		dwChunkSize += 8; //add offsets of the chunk id, and chunk size data entries
		dwChunkSize += 1;
		dwChunkSize &= 0xfffffffe; //guarantees WORD padding alignment
		i += dwChunkSize;
	}
	
	if(!isFormatOK) {
		inputSoundFile.close();
		throw Exception(err.SoundBuffer_Fatal_Error, "Couldn't find \'fmt\' in chunk id, sound file may be corrupted");
	}
	
	//find 'data' in the chunk id
	bool isDataOK = false;
	for(unsigned int i = 12; i < dwFileSize; ) {
		inputSoundFile.seekg(i, std::ios::beg);
		inputSoundFile.read(reinterpret_cast<char*>(&dwChunkId), sizeof(dwChunkId));
		inputSoundFile.seekg(i + 4, std::ios::beg);
		inputSoundFile.read(reinterpret_cast<char*>(&dwChunkSize), sizeof(dwChunkSize));
		if(dwChunkId == 'atad') {
			soundData_ = bytePtr(new BYTE[dwChunkSize]);
			inputSoundFile.seekg((i + 8), std::ios::beg);
			inputSoundFile.read(reinterpret_cast<char*>(soundData_.get()), dwChunkSize);
			buffer_.AudioBytes = dwChunkSize;
			buffer_.pAudioData = soundData_.get();
			buffer_.PlayBegin = 0;
			buffer_.PlayLength = 0;
			isDataOK = true;
			break;
		}
		dwChunkSize += 8; //add offsets of the chunk id, and chunk size data entries
		dwChunkSize += 1;
		dwChunkSize &= 0xfffffffe; //guarantees WORD padding alignment
		i += dwChunkSize;
	}
	
	if(!isDataOK) {
		inputSoundFile.close();
		throw Exception(err.SoundBuffer_Fatal_Error, "Couldn't find \'data\' in chunk id, sound file may be corrupted");
	}

	inputSoundFile.close();
	return true;
}