aboutsummaryrefslogtreecommitdiff
path: root/saga
diff options
context:
space:
mode:
authorEugene Sandulenko2004-05-04 03:33:03 +0000
committerEugene Sandulenko2004-05-04 03:33:03 +0000
commit8de181f4f0b6f974016eaee6ec238bbdfb5ded2f (patch)
tree0079332b27bf2ca641387f8a6f2a0bb02db339de /saga
parentb9ebd68022f5614b0db6b30d8494062e911a8cc5 (diff)
downloadscummvm-rg350-8de181f4f0b6f974016eaee6ec238bbdfb5ded2f.tar.gz
scummvm-rg350-8de181f4f0b6f974016eaee6ec238bbdfb5ded2f.tar.bz2
scummvm-rg350-8de181f4f0b6f974016eaee6ec238bbdfb5ded2f.zip
Move from ys_binread.cpp and ys_binwrite.cpp to MemoryReadStream.
In fact there were no binary writes at all. svn-id: r13773
Diffstat (limited to 'saga')
-rw-r--r--saga/actionmap.cpp24
-rw-r--r--saga/actor.cpp8
-rw-r--r--saga/animation.cpp249
-rw-r--r--saga/animation.h10
-rw-r--r--saga/font.cpp23
-rw-r--r--saga/image.cpp11
-rw-r--r--saga/isomap.cpp47
-rw-r--r--saga/module.mk2
-rw-r--r--saga/objectmap.cpp39
-rw-r--r--saga/palanim.cpp21
-rw-r--r--saga/rscfile.cpp20
-rw-r--r--saga/scene.cpp31
-rw-r--r--saga/script.cpp49
-rw-r--r--saga/script.h1
-rw-r--r--saga/sdebug.cpp118
-rw-r--r--saga/sndres.cpp51
-rw-r--r--saga/sprite.cpp42
-rw-r--r--saga/sthread.cpp116
-rw-r--r--saga/sthread.h1
-rw-r--r--saga/ys_binread.cpp185
-rw-r--r--saga/ys_binwrite.cpp59
-rw-r--r--saga/yslib.h36
22 files changed, 408 insertions, 735 deletions
diff --git a/saga/actionmap.cpp b/saga/actionmap.cpp
index 33cffadb59..e884b716f1 100644
--- a/saga/actionmap.cpp
+++ b/saga/actionmap.cpp
@@ -25,8 +25,6 @@
#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
-
#include "cvar_mod.h"
#include "console_mod.h"
#include "gfx_mod.h"
@@ -60,10 +58,10 @@ int ACTIONMAP_Load(const byte * exmap_res, size_t exmap_res_len) {
assert(ActmapModule.init);
assert(exmap_res != NULL);
- MemoryReadStream *exmapStream = new MemoryReadStream(exmap_res, exmap_res_len);
+ MemoryReadStream *readS = new MemoryReadStream(exmap_res, exmap_res_len);
// Load exits
- exit_ct = exmapStream->readSint16LE();
+ exit_ct = readS->readSint16LE();
if (exit_ct < 0) {
return R_FAILURE;
}
@@ -75,12 +73,12 @@ int ACTIONMAP_Load(const byte * exmap_res, size_t exmap_res_len) {
}
for (i = 0; i < exit_ct; i++) {
- exmap_entry[i].unknown00 = exmapStream->readSint16LE();
- exmap_entry[i].unknown02 = exmapStream->readSint16LE();
- exmap_entry[i].exit_scene = exmapStream->readSint16LE();
- exmap_entry[i].unknown06 = exmapStream->readSint16LE();
+ exmap_entry[i].unknown00 = readS->readSint16LE();
+ exmap_entry[i].unknown02 = readS->readSint16LE();
+ exmap_entry[i].exit_scene = readS->readSint16LE();
+ exmap_entry[i].unknown06 = readS->readSint16LE();
- exmap_entry[i].pt_count = exmapStream->readSint16LE();
+ exmap_entry[i].pt_count = readS->readSint16LE();
if (exmap_entry[i].pt_count < 0) {
free(exmap_entry);
return R_FAILURE;
@@ -93,8 +91,8 @@ int ACTIONMAP_Load(const byte * exmap_res, size_t exmap_res_len) {
}
for (pt = 0; pt < exmap_entry[i].pt_count; pt++) {
- exmap_pt_tbl[pt].x = exmapStream->readSint16LE();
- exmap_pt_tbl[pt].y = exmapStream->readSint16LE();
+ exmap_pt_tbl[pt].x = readS->readSint16LE();
+ exmap_pt_tbl[pt].y = readS->readSint16LE();
}
exmap_entry[i].pt_tbl = exmap_pt_tbl;
@@ -167,8 +165,8 @@ void CF_action_info(int argc, char *argv[]) {
int i;
int pt_i;
- YS_IGNORE_PARAM(argc);
- YS_IGNORE_PARAM(argv);
+ (void)(argc);
+ (void)(argv);
if (!ActmapModule.exits_loaded) {
return;
diff --git a/saga/actor.cpp b/saga/actor.cpp
index d9793e5d03..4a05a917e7 100644
--- a/saga/actor.cpp
+++ b/saga/actor.cpp
@@ -670,7 +670,7 @@ int LoadActorSpriteIndex(R_ACTOR * actor, int si_rn, int *last_frame_p) {
R_printf(R_STDOUT, "Sprite resource contains %d sprite actions.\n", s_action_ct);
action_p = (R_ACTORACTION *)malloc(sizeof(R_ACTORACTION) * s_action_ct);
- MemoryReadStream *resStream = new MemoryReadStream(res_p, res_len);
+ MemoryReadStream *readS = new MemoryReadStream(res_p, res_len);
if (action_p == NULL) {
R_printf(R_STDERR, "Couldn't allocate memory for sprite actions.\n");
@@ -683,8 +683,8 @@ int LoadActorSpriteIndex(R_ACTOR * actor, int si_rn, int *last_frame_p) {
for (i = 0; i < s_action_ct; i++) {
for (orient = 0; orient < 4; orient++) {
// Load all four orientations
- action_p[i].dir[orient].frame_index = resStream->readUint16LE();
- action_p[i].dir[orient].frame_count = resStream->readUint16LE();
+ action_p[i].dir[orient].frame_index = readS->readUint16LE();
+ action_p[i].dir[orient].frame_count = readS->readUint16LE();
if (action_p[i].dir[orient].frame_index > last_frame) {
last_frame = action_p[i].dir[orient].frame_index;
}
@@ -1078,7 +1078,7 @@ static void CF_actor_add(int argc, char *argv[]) {
static void CF_actor_del(int argc, char *argv[]) {
int id;
-
+
if (argc < 0)
return;
diff --git a/saga/animation.cpp b/saga/animation.cpp
index 81552d5584..92195afad4 100644
--- a/saga/animation.cpp
+++ b/saga/animation.cpp
@@ -24,7 +24,6 @@
// Background animation management module
#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
#include "cvar_mod.h"
#include "console_mod.h"
@@ -94,7 +93,7 @@ int ANIM_Load(const byte *anim_resdata, size_t anim_resdata_len, uint16 *anim_id
new_anim->resdata_len = anim_resdata_len;
if (GAME_GetGameType() == R_GAMETYPE_ITE) {
- if (ANIM_GetNumFrames(anim_resdata, &new_anim->n_frames) != R_SUCCESS) {
+ if (ANIM_GetNumFrames(anim_resdata, anim_resdata_len, &new_anim->n_frames) != R_SUCCESS) {
R_printf(R_STDERR, "Error: Couldn't get animation frame count.\n");
return R_FAILURE;
}
@@ -107,12 +106,12 @@ int ANIM_Load(const byte *anim_resdata, size_t anim_resdata_len, uint16 *anim_id
}
for (i = 0; i < new_anim->n_frames; i++) {
- ANIM_GetFrameOffset(anim_resdata, i + 1, &new_anim->frame_offsets[i]);
+ ANIM_GetFrameOffset(anim_resdata, anim_resdata_len, i + 1, &new_anim->frame_offsets[i]);
}
} else {
new_anim->cur_frame_p = anim_resdata + SAGA_FRAME_HEADER_LEN;
new_anim->cur_frame_len = anim_resdata_len - SAGA_FRAME_HEADER_LEN;
- ANIM_GetNumFrames(anim_resdata, &new_anim->n_frames);
+ ANIM_GetNumFrames(anim_resdata, anim_resdata_len, &new_anim->n_frames);
}
// Set animation data
@@ -193,7 +192,7 @@ int ANIM_Play(uint16 anim_id, int vector_time) {
if (anim->play_flag) {
frame = anim->current_frame;
if (GAME_GetGameType() == R_GAMETYPE_ITE) {
- result = ITE_DecodeFrame(anim->resdata, anim->frame_offsets[frame - 1], display_buf,
+ result = ITE_DecodeFrame(anim->resdata, anim->resdata_len, anim->frame_offsets[frame - 1], display_buf,
disp_info.logical_w * disp_info.logical_h);
if (result != R_SUCCESS) {
R_printf(R_STDERR, "ANIM_Play: Error decoding frame %u", anim->current_frame);
@@ -346,7 +345,7 @@ int ANIM_Free(uint16 anim_id) {
// sometimes less than number present in the .nframes member of the
// animation header. For this reason, the function attempts to find
// the last valid frame number, which it returns via 'n_frames'
-int ANIM_GetNumFrames(const byte *anim_resource, uint16 *n_frames) {
+int ANIM_GetNumFrames(const byte *anim_resource, size_t anim_resource_len, uint16 *n_frames) {
R_ANIMATION_HEADER ah;
size_t offset;
@@ -354,19 +353,19 @@ int ANIM_GetNumFrames(const byte *anim_resource, uint16 *n_frames) {
int x;
- const byte *read_p = anim_resource;
-
if (!AnimInfo.initialized) {
return R_FAILURE;
}
- ah.magic = ys_read_u16_le(read_p, &read_p);
- ah.screen_w = ys_read_u16_le(read_p, &read_p);
- ah.screen_h = ys_read_u16_le(read_p, &read_p);
+ MemoryReadStream *readS = new MemoryReadStream(anim_resource, anim_resource_len);
+
+ ah.magic = readS->readUint16LE();
+ ah.screen_w = readS->readUint16LE();
+ ah.screen_h = readS->readUint16LE();
- ah.unknown06 = ys_read_u8(read_p, &read_p);
- ah.unknown07 = ys_read_u8(read_p, &read_p);
- ah.nframes = ys_read_u8(read_p, NULL);
+ ah.unknown06 = readS->readByte();
+ ah.unknown07 = readS->readByte();
+ ah.nframes = readS->readByte();
if (GAME_GetGameType() == R_GAMETYPE_IHNM) {
*n_frames = ah.nframes;
@@ -374,7 +373,7 @@ int ANIM_GetNumFrames(const byte *anim_resource, uint16 *n_frames) {
if (ah.magic == 68) {
for (x = ah.nframes; x > 0; x--) {
- if (ANIM_GetFrameOffset(anim_resource, x, &offset) != R_SUCCESS) {
+ if (ANIM_GetFrameOffset(anim_resource, anim_resource_len, x, &offset) != R_SUCCESS) {
return R_FAILURE;
}
@@ -391,11 +390,10 @@ int ANIM_GetNumFrames(const byte *anim_resource, uint16 *n_frames) {
return R_FAILURE;
}
-int ITE_DecodeFrame(const byte * resdata, size_t frame_offset, byte * buf, size_t buf_len) {
+int ITE_DecodeFrame(const byte *resdata, size_t resdata_len, size_t frame_offset, byte *buf, size_t buf_len) {
R_ANIMATION_HEADER ah;
R_FRAME_HEADER fh;
- const byte *read_p = resdata;
byte *write_p;
uint16 magic;
@@ -421,16 +419,17 @@ int ITE_DecodeFrame(const byte * resdata, size_t frame_offset, byte * buf, size_
return R_FAILURE;
}
+ MemoryReadStream *readS = new MemoryReadStream(resdata, resdata_len);
// Read animation header
- ah.magic = ys_read_u16_le(read_p, &read_p);
- ah.screen_w = ys_read_u16_le(read_p, &read_p);
- ah.screen_h = ys_read_u16_le(read_p, &read_p);
- ah.unknown06 = ys_read_u8(read_p, &read_p);
- ah.unknown07 = ys_read_u8(read_p, &read_p);
- ah.nframes = ys_read_u8(read_p, &read_p);
- ah.flags = ys_read_u8(read_p, &read_p);
- ah.unknown10 = ys_read_u8(read_p, &read_p);
- ah.unknown11 = ys_read_u8(read_p, &read_p);
+ ah.magic = readS->readUint16LE();
+ ah.screen_w = readS->readUint16LE();
+ ah.screen_h = readS->readUint16LE();
+ ah.unknown06 = readS->readByte();
+ ah.unknown07 = readS->readByte();
+ ah.nframes = readS->readByte();
+ ah.flags = readS->readByte();
+ ah.unknown10 = readS->readByte();
+ ah.unknown11 = readS->readByte();
screen_w = ah.screen_w;
screen_h = ah.screen_h;
@@ -442,10 +441,10 @@ int ITE_DecodeFrame(const byte * resdata, size_t frame_offset, byte * buf, size_
}
// Read frame header
- read_p = resdata + frame_offset;
+ readS = new MemoryReadStream(resdata + frame_offset, resdata_len - frame_offset);
// Check for frame magic byte
- magic = ys_read_u8(read_p, &read_p);
+ magic = readS->readByte();
if (magic != SAGA_FRAME_HEADER_MAGIC) {
R_printf(R_STDERR, "ITE_DecodeFrame: Invalid frame offset.\n");
return R_FAILURE;
@@ -455,13 +454,13 @@ int ITE_DecodeFrame(const byte * resdata, size_t frame_offset, byte * buf, size_
// endian format, but the actual RLE encoded frame data,
// including the frame header, is in big endian format.
- fh.x_start = ys_read_u16_be(read_p, &read_p);
- fh.y_start = ys_read_u8(read_p, &read_p);
- read_p++; /* Skip pad byte */
- fh.x_pos = ys_read_u16_be(read_p, &read_p);
- fh.y_pos = ys_read_u16_be(read_p, &read_p);
- fh.width = ys_read_u16_be(read_p, &read_p);
- fh.height = ys_read_u16_be(read_p, &read_p);
+ fh.x_start = readS->readUint16BE();
+ fh.y_start = readS->readByte();
+ readS->readByte(); /* Skip pad byte */
+ fh.x_pos = readS->readUint16BE();
+ fh.y_pos = readS->readUint16BE();
+ fh.width = readS->readUint16BE();
+ fh.height = readS->readUint16BE();
x_start = fh.x_start;
y_start = fh.y_start;
@@ -471,36 +470,36 @@ int ITE_DecodeFrame(const byte * resdata, size_t frame_offset, byte * buf, size_
// Begin RLE decompression to output buffer
do {
- mark_byte = ys_read_u8(read_p, &read_p);
+ mark_byte = readS->readByte();
switch (mark_byte) {
case 0x10: // Long Unencoded Run
- runcount = ys_read_s16_be(read_p, &read_p);
+ runcount = readS->readSint16BE();
for (i = 0; i < runcount; i++) {
- if (*read_p != 0) {
- *write_p = *read_p;
+ data_byte = readS->readByte();
+ if (data_byte != 0) {
+ *write_p = data_byte;
}
write_p++;
- read_p++;
}
continue;
break;
case 0x20: // Long encoded run
- runcount = ys_read_s16_be(read_p, &read_p);
- data_byte = *read_p++;
+ runcount = readS->readSint16BE();
+ data_byte = readS->readByte();
for (i = 0; i < runcount; i++) {
*write_p++ = data_byte;
}
continue;
break;
case 0x2F: // End of row
- x_vector = ys_read_s16_be(read_p, &read_p);
- new_row = ys_read_u8(read_p, &read_p);
+ x_vector = readS->readSint16BE();
+ new_row = readS->readByte();
// Set write pointer to the new draw origin
write_p = buf + ((y_start + new_row) * screen_w) + x_start + x_vector;
continue;
break;
case 0x30: // Reposition command
- x_vector = ys_read_s16_be(read_p, &read_p);
+ x_vector = readS->readSint16BE();
write_p += x_vector;
continue;
break;
@@ -524,7 +523,7 @@ int ITE_DecodeFrame(const byte * resdata, size_t frame_offset, byte * buf, size_
case 0x80: // 1000 0000
// Run of compressed data
runcount = param_ch + 1;
- data_byte = *read_p++;
+ data_byte = readS->readByte();
for (i = 0; i < runcount; i++) {
*write_p++ = data_byte;
}
@@ -534,11 +533,11 @@ int ITE_DecodeFrame(const byte * resdata, size_t frame_offset, byte * buf, size_
// Uncompressed run
runcount = param_ch + 1;
for (i = 0; i < runcount; i++) {
- if (*read_p != 0) {
- *write_p = *read_p;
+ data_byte = readS->readByte();
+ if (data_byte != 0) {
+ *write_p = data_byte;
}
write_p++;
- read_p++;
}
continue;
break;
@@ -571,8 +570,7 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_
size_t in_ch_offset;
- const byte *inbuf_p = thisf_p;
- size_t inbuf_remain = thisf_len;
+ MemoryReadStream *readS = new MemoryReadStream(thisf_p, thisf_len);
byte *outbuf_p = decode_buf;
byte *outbuf_endp = (decode_buf + decode_buf_len) - 1;
@@ -585,9 +583,8 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_
*nextf_p = NULL;
for (; cont_flag; decoded_data = 1) {
- in_ch_offset = (size_t) (inbuf_p - thisf_p);
- in_ch = *inbuf_p++;
- inbuf_remain--;
+ in_ch_offset = readS->tell();
+ in_ch = readS->readByte();
switch (in_ch) {
case 0x0F: // 15: Frame header
{
@@ -598,20 +595,18 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_
int param5;
int param6;
- if (inbuf_remain < 13) {
+ if (thisf_len - readS->tell() < 13) {
R_printf(R_STDERR, "0x%02X: Input buffer underrun.", in_ch);
return R_FAILURE;
}
- param1 = ys_read_u16_be(inbuf_p, &inbuf_p);
- param2 = ys_read_u16_be(inbuf_p, &inbuf_p);
- inbuf_p++; // skip 1?
- param3 = ys_read_u16_be(inbuf_p, &inbuf_p);
- param4 = ys_read_u16_be(inbuf_p, &inbuf_p);
- param5 = ys_read_u16_be(inbuf_p, &inbuf_p);
- param6 = ys_read_u16_be(inbuf_p, &inbuf_p);
-
- inbuf_remain -= 13;
+ param1 = readS->readUint16BE();
+ param2 = readS->readUint16BE();
+ readS->readByte(); // skip 1?
+ param3 = readS->readUint16BE();
+ param4 = readS->readUint16BE();
+ param5 = readS->readUint16BE();
+ param6 = readS->readUint16BE();
x_origin = param1;
y_origin = param2;
@@ -629,8 +624,8 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_
}
break;
case 0x10: // Long Unencoded Run
- runcount = ys_read_s16_be(inbuf_p, &inbuf_p);
- if (inbuf_remain < runcount) {
+ runcount = readS->readSint16BE();
+ if (thisf_len - readS->tell() < runcount) {
R_printf(R_STDERR, "0x%02X: Input buffer underrun.", in_ch);
return R_FAILURE;
}
@@ -640,64 +635,62 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_
}
for (c = 0; c < runcount; c++) {
- if (*inbuf_p != 0) {
- *outbuf_p = *inbuf_p;
+ data_pixel = readS->readByte();
+ if (data_pixel != 0) {
+ *outbuf_p = data_pixel;
}
outbuf_p++;
- inbuf_p++;
}
- inbuf_remain -= runcount;
outbuf_remain -= runcount;
continue;
break;
case 0x1F: // 31: Unusued?
- if (inbuf_remain < 3) {
+ if (thisf_len - readS->tell() < 3) {
R_printf(R_STDERR, "0x%02X: Input buffer underrun.", in_ch);
return R_FAILURE;
}
- inbuf_p += 3;
- inbuf_remain -= 3;
+ readS->readByte();
+ readS->readByte();
+ readS->readByte();
continue;
break;
case 0x20: // Long compressed run
- if (inbuf_remain <= 3) {
+ if (thisf_len - readS->tell() <= 3) {
R_printf(R_STDERR, "0x%02X: Input buffer underrun.", in_ch);
return R_FAILURE;
}
- runcount = ys_read_s16_be(inbuf_p, &inbuf_p);
- data_pixel = *inbuf_p++;
+ runcount = readS->readSint16BE();
+ data_pixel = readS->readByte();
for (c = 0; c < runcount; c++) {
*outbuf_p++ = data_pixel;
}
outbuf_remain -= runcount;
- inbuf_remain -= 1;
continue;
break;
case 0x2F: // End of row
- if (inbuf_remain <= 4) {
+ if (thisf_len - readS->tell() <= 4) {
return R_FAILURE;
}
- x_vector = ys_read_s16_be(inbuf_p, &inbuf_p);
- new_row = ys_read_s16_be(inbuf_p, &inbuf_p);
+ x_vector = readS->readSint16BE();
+ new_row = readS->readSint16BE();
outbuf_p = decode_buf + ((y_origin + new_row) * di.logical_w) + x_origin + x_vector;
- inbuf_remain -= 4;
outbuf_remain = (outbuf_endp - outbuf_p) + 1;
continue;
break;
case 0x30: // Reposition command
- if (inbuf_remain < 2) {
+ if (thisf_len - readS->tell() < 2) {
return R_FAILURE;
}
- x_vector = ys_read_s16_be(inbuf_p, &inbuf_p);
+ x_vector = readS->readSint16BE();
if (((x_vector > 0) && ((size_t) x_vector > outbuf_remain)) || (-x_vector > outbuf_p - decode_buf)) {
R_printf(R_STDERR, "0x30: Invalid x_vector.\n");
@@ -706,15 +699,14 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_
outbuf_p += x_vector;
outbuf_remain -= x_vector;
- inbuf_remain -= 2;
continue;
break;
case 0x3F: // 68: Frame end marker
printf("0x3F: Frame end marker\n");
- if (decoded_data && inbuf_remain > 0) {
- *nextf_p = inbuf_p;
- *nextf_len = inbuf_remain;
+ if (decoded_data && (thisf_len - readS->tell() > 0)) {
+ *nextf_p = thisf_p + readS->tell();
+ *nextf_len = thisf_len - readS->tell();
} else {
*nextf_p = NULL;
*nextf_len = 0;
@@ -744,15 +736,13 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_
break;
case 0x80: // Run of compressed data
runcount = param_ch + 1;
- if ((outbuf_remain < runcount) || (inbuf_remain <= 1)) {
+ if ((outbuf_remain < runcount) || (thisf_len - readS->tell() <= 1)) {
return R_FAILURE;
}
- data_pixel = *inbuf_p++;
- inbuf_remain--;
+ data_pixel = readS->readByte();
for (c = 0; c < runcount; c++) {
-
*outbuf_p++ = data_pixel;
}
@@ -761,19 +751,18 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_
break;
case 0x40: // Uncompressed run
runcount = param_ch + 1;
- if ((outbuf_remain < runcount) || (inbuf_remain < runcount)) {
+ if ((outbuf_remain < runcount) || (thisf_len - readS->tell() < runcount)) {
return R_FAILURE;
}
for (c = 0; c < runcount; c++) {
- if (*inbuf_p != 0) {
- *outbuf_p = *inbuf_p;
+ data_pixel = readS->readByte();
+ if (data_pixel != 0) {
+ *outbuf_p = data_pixel;
}
outbuf_p++;
- inbuf_p++;
}
- inbuf_remain -= runcount;
outbuf_remain -= runcount;
continue;
@@ -787,34 +776,35 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_
return R_SUCCESS;
}
-int ANIM_GetFrameOffset(const byte *resdata, uint16 find_frame, size_t *frame_offset_p) {
+int ANIM_GetFrameOffset(const byte *resdata, size_t resdata_len, uint16 find_frame, size_t *frame_offset_p) {
R_ANIMATION_HEADER ah;
uint16 num_frames;
uint16 current_frame;
- const byte *read_p = resdata;
- const byte *search_ptr;
-
byte mark_byte;
uint16 control;
uint16 runcount;
uint16 magic;
+ int i;
+
if (!AnimInfo.initialized) {
return R_FAILURE;
}
+ MemoryReadStream *readS = new MemoryReadStream(resdata, resdata_len);
+
// Read animation header
- ah.magic = ys_read_u16_le(read_p, &read_p);
- ah.screen_w = ys_read_u16_le(read_p, &read_p);
- ah.screen_h = ys_read_u16_le(read_p, &read_p);
- ah.unknown06 = ys_read_u8(read_p, &read_p);
- ah.unknown07 = ys_read_u8(read_p, &read_p);
- ah.nframes = ys_read_u8(read_p, &read_p);
- ah.flags = ys_read_u8(read_p, &read_p);
- ah.unknown10 = ys_read_u8(read_p, &read_p);
- ah.unknown11 = ys_read_u8(read_p, &read_p);
+ ah.magic = readS->readUint16LE();
+ ah.screen_w = readS->readUint16LE();
+ ah.screen_h = readS->readUint16LE();
+ ah.unknown06 = readS->readByte();
+ ah.unknown07 = readS->readByte();
+ ah.nframes = readS->readByte();
+ ah.flags = readS->readByte();
+ ah.unknown10 = readS->readByte();
+ ah.unknown11 = readS->readByte();
num_frames = ah.nframes;
@@ -822,42 +812,48 @@ int ANIM_GetFrameOffset(const byte *resdata, uint16 find_frame, size_t *frame_of
return R_FAILURE;
}
- search_ptr = read_p;
for (current_frame = 1; current_frame < find_frame; current_frame++) {
- magic = ys_read_u8(search_ptr, &search_ptr);
+ magic = readS->readByte();
if (magic != SAGA_FRAME_HEADER_MAGIC) {
// Frame sync failure. Magic Number not found
return R_FAILURE;
}
- search_ptr += SAGA_FRAME_HEADER_LEN;
+ // skip header
+ for (i = 0; i < SAGA_FRAME_HEADER_LEN; i++)
+ readS->readByte();
+
// For some strange reason, the animation header is in little
// endian format, but the actual RLE encoded frame data,
// including the frame header, is in big endian format. */
do {
- mark_byte = *search_ptr;
+ mark_byte = readS->readByte();
switch (mark_byte) {
case 0x3F: // End of frame marker
- search_ptr++;
continue;
break;
case 0x30: // Reposition command
- search_ptr += 3;
+ readS->readByte();
+ readS->readByte();
continue;
break;
case 0x2F: // End of row marker
- search_ptr += 4;
+ readS->readByte();
+ readS->readByte();
+ readS->readByte();
continue;
break;
case 0x20: // Long compressed run marker
- search_ptr += 4;
+ readS->readByte();
+ readS->readByte();
+ readS->readByte();
continue;
break;
case 0x10: // (16) 0001 0000
// Long Uncompressed Run
- search_ptr++;
- runcount = ys_read_s16_be(search_ptr, &search_ptr);
- search_ptr += runcount;
+ runcount = readS->readSint16BE();
+ for (i = 0; i < runcount; i++)
+ readS->readByte();
continue;
break;
default:
@@ -869,19 +865,18 @@ int ANIM_GetFrameOffset(const byte *resdata, uint16 find_frame, size_t *frame_of
switch (control) {
case 0xC0:
// Run of empty pixels
- search_ptr++;
continue;
break;
case 0x80:
// Run of compressed data
- search_ptr += 2; // Skip data byte
+ readS->readByte(); // Skip data byte
continue;
break;
case 0x40:
// Uncompressed run
- search_ptr++;
runcount = (mark_byte & 0x3f) + 1;
- search_ptr += runcount;
+ for (i = 0; i < runcount; i++)
+ readS->readByte();
continue;
break;
default:
@@ -892,7 +887,7 @@ int ANIM_GetFrameOffset(const byte *resdata, uint16 find_frame, size_t *frame_of
} while (mark_byte != 63);
}
- *frame_offset_p = (search_ptr - resdata);
+ *frame_offset_p = readS->tell();
return R_SUCCESS;
}
@@ -901,8 +896,8 @@ static void CF_anim_info(int argc, char *argv[]) {
uint16 i;
uint16 idx;
- YS_IGNORE_PARAM(argc);
- YS_IGNORE_PARAM(argv);
+ (void)(argc);
+ (void)(argv);
anim_ct = AnimInfo.anim_count;
diff --git a/saga/animation.h b/saga/animation.h
index cd775765db..9cb0f95adb 100644
--- a/saga/animation.h
+++ b/saga/animation.h
@@ -93,11 +93,11 @@ struct R_ANIMINFO {
R_ANIMATION *anim_tbl[R_MAX_ANIMATIONS];
};
-int ANIM_GetNumFrames(const byte *anim_resource, uint16 *n_frames);
-int ITE_DecodeFrame(const byte * anim_resource, size_t frame_offset, byte * buf, size_t buf_len);
-int IHNM_DecodeFrame(byte * decode_buf, size_t decode_buf_len, const byte * thisf_p,
- size_t thisf_len, const byte ** nextf_p, size_t * nextf_len);
-int ANIM_GetFrameOffset(const byte * anim_resource, uint16 find_frame, size_t * frame_offset);
+int ANIM_GetNumFrames(const byte *anim_resource, size_t anim_resource_len, uint16 *n_frames);
+int ITE_DecodeFrame(const byte *anim_resource, size_t anim_resource_len, size_t frame_offset, byte *buf, size_t buf_len);
+int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_p,
+ size_t thisf_len, const byte **nextf_p, size_t *nextf_len);
+int ANIM_GetFrameOffset(const byte *anim_resource, size_t anim_resource_len, uint16 find_frame, size_t *frame_offset);
static void CF_anim_info(int argc, char *argv[]);
} // End of namespace Saga
diff --git a/saga/font.cpp b/saga/font.cpp
index 64c280bae2..f073d85c46 100644
--- a/saga/font.cpp
+++ b/saga/font.cpp
@@ -25,8 +25,6 @@
#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
-
#include "rscfile_mod.h"
#include "game_mod.h"
@@ -103,8 +101,6 @@ int FONT_Load(uint32 font_rn, int font_id) {
R_FONT_STYLE *normal_font;
byte *fontres_p;
size_t fontres_len;
- size_t remain;
- const byte *read_p;
int nbits;
int c;
@@ -122,8 +118,7 @@ int FONT_Load(uint32 font_rn, int font_id) {
FontModule.err_str = "Invalid font length.";
}
- read_p = fontres_p;
- remain = fontres_len;
+ MemoryReadStream *readS = new MemoryReadStream(fontres_p, fontres_len);
// Create new font structure
font = (R_FONT *)malloc(sizeof *font);
@@ -133,9 +128,9 @@ int FONT_Load(uint32 font_rn, int font_id) {
}
// Read font header
- fh.c_height = ys_read_u16_le(read_p, &read_p);
- fh.c_width = ys_read_u16_le(read_p, &read_p);
- fh.row_length = ys_read_u16_le(read_p, &read_p);
+ fh.c_height = readS->readUint16LE();
+ fh.c_width = readS->readUint16LE();
+ fh.row_length = readS->readUint16LE();
#if R_FONT_DBGLVL >= R_DEBUG_INFO
R_printf(R_STDOUT, "FONT_Load(): Reading font resource...\n");
@@ -161,23 +156,23 @@ int FONT_Load(uint32 font_rn, int font_id) {
normal_font->hdr.row_length = fh.row_length;
for (c = 0; c < R_FONT_CHARCOUNT; c++) {
- normal_font->fce[c].index = ys_read_u16_le(read_p, &read_p);
+ normal_font->fce[c].index = readS->readUint16LE();
}
for (c = 0; c < R_FONT_CHARCOUNT; c++) {
- nbits = normal_font->fce[c].width = ys_read_u8(read_p, &read_p);
+ nbits = normal_font->fce[c].width = readS->readByte();
normal_font->fce[c].byte_width = GetByteLen(nbits);
}
for (c = 0; c < R_FONT_CHARCOUNT; c++) {
- normal_font->fce[c].flag = ys_read_u8(read_p, &read_p);
+ normal_font->fce[c].flag = readS->readByte();
}
for (c = 0; c < R_FONT_CHARCOUNT; c++) {
- normal_font->fce[c].tracking = ys_read_u8(read_p, &read_p);
+ normal_font->fce[c].tracking = readS->readByte();
}
- if ((read_p - fontres_p) != R_FONT_DESCSIZE) {
+ if (readS->tell() != R_FONT_DESCSIZE) {
R_printf(R_STDERR, "Invalid font resource size.\n");
return R_FAILURE;
}
diff --git a/saga/image.cpp b/saga/image.cpp
index 1db32b7bcc..9b6200dbaa 100644
--- a/saga/image.cpp
+++ b/saga/image.cpp
@@ -62,17 +62,18 @@ int IMG_DecodeBGImage(const byte * image_data, size_t image_size,
size_t decode_buf_len;
byte *out_buf;
size_t out_buf_len;
- const byte *read_p = image_data;
if (image_size <= SAGA_IMAGE_DATA_OFFSET) {
/* Image size is way too small */
return R_FAILURE;
}
- hdr.width = ys_read_u16_le(read_p, &read_p);
- hdr.height = ys_read_u16_le(read_p, &read_p);
- hdr.unknown4 = ys_read_u16_le(read_p, &read_p);
- hdr.unknown6 = ys_read_u16_le(read_p, &read_p);
+ MemoryReadStream *readS = new MemoryReadStream(image_data, image_size);
+
+ hdr.width = readS->readUint16LE();
+ hdr.height = readS->readUint16LE();
+ hdr.unknown4 = readS->readUint16LE();
+ hdr.unknown6 = readS->readUint16LE();
RLE_data_ptr = image_data + SAGA_IMAGE_DATA_OFFSET;
RLE_data_len = image_size - SAGA_IMAGE_DATA_OFFSET;
diff --git a/saga/isomap.cpp b/saga/isomap.cpp
index 894d6a55f4..8396ea10b0 100644
--- a/saga/isomap.cpp
+++ b/saga/isomap.cpp
@@ -25,8 +25,6 @@
#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
-
#include "game_mod.h"
#include "gfx_mod.h"
@@ -49,19 +47,17 @@ int ISOMAP_LoadTileset(const byte *tileres_p, size_t tileres_len) {
uint16 i;
- const byte *read_p = tileres_p;
- size_t read_len = tileres_len;
-
assert((IsoModule.init) && (!IsoModule.tiles_loaded));
assert((tileres_p != NULL) && (tileres_len > 0));
- read_p += 2;
- first_entry.tile_offset = ys_read_u16_le(read_p, &read_p);
+ MemoryReadStream *readS = new MemoryReadStream(tileres_p, tileres_len);
+
+ readS->readUint16LE(); // skip
+ first_entry.tile_offset = readS->readUint16LE();
IsoModule.tile_ct = first_entry.tile_offset / SAGA_ISOTILE_ENTRY_LEN;
- read_p = tileres_p;
- read_len = tileres_len;
+ readS->rewind();
tile_tbl = (R_ISOTILE_ENTRY *)malloc(IsoModule.tile_ct * sizeof *tile_tbl);
if (tile_tbl == NULL) {
@@ -69,11 +65,11 @@ int ISOMAP_LoadTileset(const byte *tileres_p, size_t tileres_len) {
}
for (i = 0; i < IsoModule.tile_ct; i++) {
- tile_tbl[i].tile_h = ys_read_u8(read_p, &read_p);
- tile_tbl[i].unknown01 = ys_read_u8(read_p, &read_p);
- tile_tbl[i].tile_offset = ys_read_u16_le(read_p, &read_p);
- tile_tbl[i].unknown04 = ys_read_s16_le(read_p, &read_p);
- tile_tbl[i].unknown06 = ys_read_s16_le(read_p, &read_p);
+ tile_tbl[i].tile_h = readS->readByte();
+ tile_tbl[i].unknown01 = readS->readByte();
+ tile_tbl[i].tile_offset = readS->readUint16LE();
+ tile_tbl[i].unknown04 = readS->readSint16LE();
+ tile_tbl[i].unknown06 = readS->readSint16LE();
}
IsoModule.tiles_loaded = 1;
@@ -86,8 +82,6 @@ int ISOMAP_LoadTileset(const byte *tileres_p, size_t tileres_len) {
int ISOMAP_LoadMetaTileset(const byte *mtileres_p, size_t mtileres_len) {
R_ISO_METATILE_ENTRY *mtile_tbl;
- const byte *read_p = mtileres_p;
- size_t read_len = mtileres_len;
uint16 mtile_ct;
uint16 ct;
int i;
@@ -95,7 +89,7 @@ int ISOMAP_LoadMetaTileset(const byte *mtileres_p, size_t mtileres_len) {
assert(IsoModule.init);
assert((mtileres_p != NULL) && (mtileres_len > 0));
- (void)read_len;
+ MemoryReadStream *readS = new MemoryReadStream(mtileres_p, mtileres_len);
mtile_ct = mtileres_len / SAGA_METATILE_ENTRY_LEN;
mtile_tbl = (R_ISO_METATILE_ENTRY *)malloc(mtile_ct * sizeof *mtile_tbl);
@@ -104,13 +98,13 @@ int ISOMAP_LoadMetaTileset(const byte *mtileres_p, size_t mtileres_len) {
}
for (ct = 0; ct < mtile_ct; ct++) {
- mtile_tbl[ct].mtile_n = ys_read_u16_le(read_p, &read_p);
- mtile_tbl[ct].unknown02 = ys_read_s16_le(read_p, &read_p);
- mtile_tbl[ct].unknown04 = ys_read_s16_le(read_p, &read_p);
- mtile_tbl[ct].unknown06 = ys_read_s16_le(read_p, &read_p);
+ mtile_tbl[ct].mtile_n = readS->readUint16LE();
+ mtile_tbl[ct].unknown02 = readS->readSint16LE();
+ mtile_tbl[ct].unknown04 = readS->readSint16LE();
+ mtile_tbl[ct].unknown06 = readS->readSint16LE();
for (i = 0; i < SAGA_METATILE_SIZE; i++) {
- mtile_tbl[ct].tile_tbl[i] = ys_read_u16_le(read_p, &read_p);
+ mtile_tbl[ct].tile_tbl[i] = readS->readUint16LE();
}
}
@@ -125,16 +119,13 @@ int ISOMAP_LoadMetaTileset(const byte *mtileres_p, size_t mtileres_len) {
}
int ISOMAP_LoadMetamap(const byte *mm_res_p, size_t mm_res_len) {
- const byte *read_p = mm_res_p;
- size_t read_len = mm_res_len;
int i;
- (void)read_len;
-
- IsoModule.metamap_n = ys_read_s16_le(read_p, &read_p);
+ MemoryReadStream *readS = new MemoryReadStream(mm_res_p, mm_res_len);
+ IsoModule.metamap_n = readS->readSint16LE();
for (i = 0; i < SAGA_METAMAP_SIZE; i++) {
- IsoModule.metamap_tbl[i] = ys_read_u16_le(read_p, &read_p);
+ IsoModule.metamap_tbl[i] = readS->readUint16LE();
}
IsoModule.mm_res_p = mm_res_p;
diff --git a/saga/module.mk b/saga/module.mk
index acbf5daa2f..7069cc7631 100644
--- a/saga/module.mk
+++ b/saga/module.mk
@@ -35,8 +35,6 @@ MODULE_OBJS = \
saga/sthread.o \
saga/text.o \
saga/transitions.o \
- saga/ys_binread.o \
- saga/ys_binwrite.o \
saga/ys_dl_list.o \
saga/input.o \
saga/timer.o \
diff --git a/saga/objectmap.cpp b/saga/objectmap.cpp
index 3a428fa309..5115cc9650 100644
--- a/saga/objectmap.cpp
+++ b/saga/objectmap.cpp
@@ -21,17 +21,14 @@
*
*/
-
// Object map / Object click-area module
// Polygon Hit Test code ( HitTestPoly() ) adapted from code (C) Eric Haines
// appearing in Graphics Gems IV, "Point in Polygon Strategies."
// p. 24-46, code: p. 34-45
-
+#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
-
#include "cvar_mod.h"
#include "console_mod.h"
#include "gfx_mod.h"
@@ -79,15 +76,13 @@ int OBJECTMAP_Shutdown() {
// Loads an object map resource ( objects ( clickareas ( points ) ) )
int OBJECTMAP_Load(const byte *om_res, size_t om_res_len) {
- const unsigned char *read_p = om_res;
-
R_OBJECTMAP_ENTRY *object_map;
R_CLICKAREA *clickarea;
R_POINT *point;
int i, k, m;
- YS_IGNORE_PARAM(om_res_len);
+ MemoryReadStream *readS = new MemoryReadStream(om_res, om_res_len);
if (!OMInfo.initialized) {
R_printf(R_STDERR, "Error: Object map module not initialized!\n");
@@ -99,7 +94,7 @@ int OBJECTMAP_Load(const byte *om_res, size_t om_res_len) {
}
// Obtain object count N and allocate space for N objects
- OMInfo.n_objects = ys_read_u16_le(read_p, &read_p);
+ OMInfo.n_objects = readS->readUint16LE();
OMInfo.object_maps = (R_OBJECTMAP_ENTRY *)malloc(OMInfo.n_objects * sizeof *OMInfo.object_maps);
@@ -111,11 +106,11 @@ int OBJECTMAP_Load(const byte *om_res, size_t om_res_len) {
// Load all N objects
for (i = 0; i < OMInfo.n_objects; i++) {
object_map = &OMInfo.object_maps[i];
- object_map->unknown0 = ys_read_u8(read_p, &read_p);
- object_map->n_clickareas = ys_read_u8(read_p, &read_p);
- object_map->flags = ys_read_u16_le(read_p, &read_p);
- object_map->object_num = ys_read_u16_le(read_p, &read_p);
- object_map->script_num = ys_read_u16_le(read_p, &read_p);
+ object_map->unknown0 = readS->readByte();
+ object_map->n_clickareas = readS->readByte();
+ object_map->flags = readS->readUint16LE();
+ object_map->object_num = readS->readUint16LE();
+ object_map->script_num = readS->readUint16LE();
object_map->clickareas = (R_CLICKAREA *)malloc(object_map->n_clickareas * sizeof *(object_map->clickareas));
if (object_map->clickareas == NULL) {
@@ -126,7 +121,7 @@ int OBJECTMAP_Load(const byte *om_res, size_t om_res_len) {
// Load all clickareas for this object
for (k = 0; k < object_map->n_clickareas; k++) {
clickarea = &object_map->clickareas[k];
- clickarea->n_points = ys_read_u16_le(read_p, &read_p);
+ clickarea->n_points = readS->readUint16LE();
assert(clickarea->n_points != 0);
clickarea->points = (R_POINT *)malloc(clickarea->n_points * sizeof *(clickarea->points));
@@ -138,8 +133,8 @@ int OBJECTMAP_Load(const byte *om_res, size_t om_res_len) {
// Load all points for this clickarea
for (m = 0; m < clickarea->n_points; m++) {
point = &clickarea->points[m];
- point->x = ys_read_s16_le(read_p, &read_p);
- point->y = ys_read_s16_le(read_p, &read_p);
+ point->x = readS->readSint16LE();
+ point->y = readS->readSint16LE();
}
#if R_OBJECTMAP_DEBUG >= R_DEBUG_PARANOID
R_printf(R_STDOUT, "OBJECTMAP_Load(): Read %d points for clickarea %d in object %d.\n",
@@ -184,21 +179,19 @@ int OBJECTMAP_Free() {
// Loads an object name list resource
int OBJECTMAP_LoadNames(const unsigned char *onl_res, size_t onl_res_len) {
- const unsigned char *read_p = onl_res;
-
int table_len;
int n_names;
size_t name_offset;
int i;
- YS_IGNORE_PARAM(onl_res_len);
+ MemoryReadStream *readS = new MemoryReadStream(onl_res, onl_res_len);
if (OMInfo.names_loaded) {
OBJECTMAP_FreeNames();
}
- table_len = ys_read_u16_le(read_p, &read_p);
+ table_len = readS->readUint16LE();
n_names = table_len / 2 - 2;
OMInfo.n_names = n_names;
@@ -216,7 +209,7 @@ int OBJECTMAP_LoadNames(const unsigned char *onl_res, size_t onl_res_len) {
}
for (i = 0; i < n_names; i++) {
- name_offset = ys_read_u16_le(read_p, &read_p);
+ name_offset = readS->readUint16LE();
OMInfo.names[i] = (const char *)(onl_res + name_offset);
#if R_OBJECTMAP_DEBUG >= R_DEBUG_VERBOSE
@@ -446,8 +439,8 @@ int OBJECTMAP_HitTest(R_POINT * imouse_pt, int *object_num) {
static void CF_object_info(int argc, char *argv[]) {
int i;
- YS_IGNORE_PARAM(argc);
- YS_IGNORE_PARAM(argv);
+ (void)(argc);
+ (void)(argv);
if (!OMInfo.initialized) {
return;
diff --git a/saga/palanim.cpp b/saga/palanim.cpp
index e1759c4790..d0d3565952 100644
--- a/saga/palanim.cpp
+++ b/saga/palanim.cpp
@@ -25,8 +25,6 @@
#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
-
#include "events_mod.h"
#include "game_mod.h"
@@ -38,13 +36,10 @@ namespace Saga {
static PALANIM_DATA PAnimData;
int PALANIM_Load(const byte *resdata, size_t resdata_len) {
- const byte *read_p = resdata;
void *test_p;
uint16 i;
- YS_IGNORE_PARAM(resdata_len);
-
if (PAnimData.loaded) {
PALANIM_Free();
}
@@ -53,11 +48,13 @@ int PALANIM_Load(const byte *resdata, size_t resdata_len) {
return R_FAILURE;
}
+ MemoryReadStream *readS = new MemoryReadStream(resdata, resdata_len);
+
if (GAME_GetGameType() == R_GAMETYPE_IHNM) {
return R_SUCCESS;
}
- PAnimData.entry_count = ys_read_u16_le(read_p, &read_p);
+ PAnimData.entry_count = readS->readUint16LE();
R_printf(R_STDOUT, "PALANIM_Load(): Loading %d PALANIM entries.\n", PAnimData.entry_count);
@@ -74,8 +71,8 @@ int PALANIM_Load(const byte *resdata, size_t resdata_len) {
int pal_count;
int p, c;
- color_count = ys_read_u16_le(read_p, &read_p);
- pal_count = ys_read_u16_le(read_p, &read_p);
+ color_count = readS->readUint16LE();
+ pal_count = readS->readUint16LE();
PAnimData.entries[i].pal_count = pal_count;
PAnimData.entries[i].color_count = color_count;
@@ -105,13 +102,13 @@ int PALANIM_Load(const byte *resdata, size_t resdata_len) {
PAnimData.entries[i].colors = (R_COLOR *)test_p;
for (p = 0; p < pal_count; p++) {
- PAnimData.entries[i].pal_index[p] = (byte) ys_read_u8(read_p, &read_p);
+ PAnimData.entries[i].pal_index[p] = readS->readByte();
}
for (c = 0; c < color_count; c++) {
- PAnimData.entries[i].colors[c].red = (byte) ys_read_u8(read_p, &read_p);
- PAnimData.entries[i].colors[c].green = (byte) ys_read_u8(read_p, &read_p);
- PAnimData.entries[i].colors[c].blue = (byte) ys_read_u8(read_p, &read_p);
+ PAnimData.entries[i].colors[c].red = readS->readByte();
+ PAnimData.entries[i].colors[c].green = readS->readByte();
+ PAnimData.entries[i].colors[c].blue = readS->readByte();
}
}
diff --git a/saga/rscfile.cpp b/saga/rscfile.cpp
index 7110af0be3..fc9222e990 100644
--- a/saga/rscfile.cpp
+++ b/saga/rscfile.cpp
@@ -22,11 +22,9 @@
*/
// RSC Resource file management module
-
+#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
-
#include "rscfile_mod.h"
#include "rscfile.h"
@@ -105,10 +103,6 @@ int RSC_LoadRSC(R_RSCFILE_CONTEXT *rsc) {
R_RSCFILE_RESOURCE *rsc_restbl;
- const byte *read_p;
-
- read_p = tblinfo_buf;
-
if (rsc->rc_file.size() < RSC_MIN_FILESIZE) {
return R_FAILURE;
}
@@ -120,8 +114,10 @@ int RSC_LoadRSC(R_RSCFILE_CONTEXT *rsc) {
return R_FAILURE;
}
- res_tbl_offset = ys_read_u32_le(read_p, &read_p);
- res_tbl_ct = ys_read_u32_le(read_p, NULL);
+ MemoryReadStream *readS = new MemoryReadStream(tblinfo_buf, RSC_TABLEINFO_SIZE);
+
+ res_tbl_offset = readS->readUint32LE();
+ res_tbl_ct = readS->readUint32LE();
// Check for sane table offset
if (res_tbl_offset != rsc->rc_file.size() - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * res_tbl_ct) {
@@ -150,11 +146,11 @@ int RSC_LoadRSC(R_RSCFILE_CONTEXT *rsc) {
return R_FAILURE;
}
- read_p = tbl_buf;
+ readS = new MemoryReadStream(tbl_buf, tbl_len);
for (i = 0; i < res_tbl_ct; i++) {
- rsc_restbl[i].res_offset = ys_read_u32_le(read_p, &read_p);
- rsc_restbl[i].res_size = ys_read_u32_le(read_p, &read_p);
+ rsc_restbl[i].res_offset = readS->readUint32LE();
+ rsc_restbl[i].res_size = readS->readUint32LE();
if ((rsc_restbl[i].res_offset > rsc->rc_file.size()) || (rsc_restbl[i].res_size > rsc->rc_file.size())) {
free(tbl_buf);
free(rsc_restbl);
diff --git a/saga/scene.cpp b/saga/scene.cpp
index 6ddef0eac5..9c4e39c9d5 100644
--- a/saga/scene.cpp
+++ b/saga/scene.cpp
@@ -62,7 +62,6 @@ int SCENE_Init() {
R_GAME_SCENEDESC gs_desc;
byte *scene_lut_p;
size_t scene_lut_len;
- const byte *read_p;
int result;
int i;
@@ -98,10 +97,10 @@ int SCENE_Init() {
return R_MEM;
}
- read_p = scene_lut_p;
+ MemoryReadStream *readS = new MemoryReadStream(scene_lut_p, scene_lut_len);
for (i = 0; i < SceneModule.scene_max; i++) {
- SceneModule.scene_lut[i] = ys_read_u16_le(read_p, &read_p);
+ SceneModule.scene_lut[i] = readS->readUint16LE();
}
free(scene_lut_p);
@@ -496,7 +495,6 @@ int SCENE_Load(int scene_num, int load_flag, R_SCENE_PROC scene_proc, R_SCENE_DE
int LoadSceneDescriptor(uint32 res_number) {
byte *scene_desc_data;
size_t scene_desc_len;
- const byte *read_p;
int result;
result = RSC_LoadResource(SceneModule.scene_ctxt, res_number, &scene_desc_data, &scene_desc_len);
@@ -510,16 +508,16 @@ int LoadSceneDescriptor(uint32 res_number) {
return R_FAILURE;
}
- read_p = scene_desc_data;
+ MemoryReadStream *readS = new MemoryReadStream(scene_desc_data, scene_desc_len);
- SceneModule.desc.unknown0 = ys_read_u16_le(read_p, &read_p);
- SceneModule.desc.res_list_rn = ys_read_u16_le(read_p, &read_p);
- SceneModule.desc.end_slope = ys_read_u16_le(read_p, &read_p);
- SceneModule.desc.begin_slope = ys_read_u16_le(read_p, &read_p);
- SceneModule.desc.script_num = ys_read_u16_le(read_p, &read_p);
- SceneModule.desc.scene_scriptnum = ys_read_u16_le(read_p, &read_p);
- SceneModule.desc.start_scriptnum = ys_read_u16_le(read_p, &read_p);
- SceneModule.desc.music_rn = ys_read_s16_le(read_p, &read_p);
+ SceneModule.desc.unknown0 = readS->readUint16LE();
+ SceneModule.desc.res_list_rn = readS->readUint16LE();
+ SceneModule.desc.end_slope = readS->readUint16LE();
+ SceneModule.desc.begin_slope = readS->readUint16LE();
+ SceneModule.desc.script_num = readS->readUint16LE();
+ SceneModule.desc.scene_scriptnum = readS->readUint16LE();
+ SceneModule.desc.start_scriptnum = readS->readUint16LE();
+ SceneModule.desc.music_rn = readS->readSint16LE();
RSC_FreeResource(scene_desc_data);
@@ -529,7 +527,6 @@ int LoadSceneDescriptor(uint32 res_number) {
int LoadSceneResourceList(uint32 reslist_rn) {
byte *resource_list;
size_t resource_list_len;
- const byte *read_p;
int result;
int i;
@@ -540,7 +537,7 @@ int LoadSceneResourceList(uint32 reslist_rn) {
return R_FAILURE;
}
- read_p = resource_list;
+ MemoryReadStream *readS = new MemoryReadStream(resource_list, resource_list_len);
// Allocate memory for scene resource list
SceneModule.reslist_entries = resource_list_len / SAGA_RESLIST_ENTRY_LEN;
@@ -557,8 +554,8 @@ int LoadSceneResourceList(uint32 reslist_rn) {
R_printf(R_STDOUT, "Loading scene resource list...\n");
for (i = 0; i < SceneModule.reslist_entries; i++) {
- SceneModule.reslist[i].res_number = ys_read_u16_le(read_p, &read_p);
- SceneModule.reslist[i].res_type = ys_read_u16_le(read_p, &read_p);
+ SceneModule.reslist[i].res_number = readS->readUint16LE();
+ SceneModule.reslist[i].res_type = readS->readUint16LE();
}
RSC_FreeResource(resource_list);
diff --git a/saga/script.cpp b/saga/script.cpp
index 103ea24711..21f7677e93 100644
--- a/saga/script.cpp
+++ b/saga/script.cpp
@@ -56,10 +56,9 @@ int SCRIPT_Init() {
R_RSCFILE_CONTEXT *s_lut_ctxt;
byte *rsc_ptr;
size_t rsc_len;
- const byte *read_ptr;
- const byte *read_ptr2;
+ int prevTell;
int result;
- int i;
+ int i, j;
R_printf(R_STDOUT, "Initializing scripting subsystem.\n");
// Load script resource file context
@@ -103,14 +102,15 @@ int SCRIPT_Init() {
}
// Convert LUT resource to logical LUT
- read_ptr = rsc_ptr;
+ MemoryReadStream *readS = new MemoryReadStream(rsc_ptr, rsc_len);
for (i = 0; i < ScriptModule.script_lut_max; i++) {
- read_ptr2 = read_ptr;
- ScriptModule.script_lut[i].script_rn = ys_read_u16_le(read_ptr2, &read_ptr2);
- ScriptModule.script_lut[i].diag_list_rn = ys_read_u16_le(read_ptr2, &read_ptr2);
- ScriptModule.script_lut[i].voice_lut_rn = ys_read_u16_le(read_ptr2, &read_ptr2);
+ prevTell = readS->tell();
+ ScriptModule.script_lut[i].script_rn = readS->readUint16LE();
+ ScriptModule.script_lut[i].diag_list_rn = readS->readUint16LE();
+ ScriptModule.script_lut[i].voice_lut_rn = readS->readUint16LE();
// Skip the unused portion of the structure
- read_ptr += ScriptModule.script_lut_entrylen;
+ for (j = readS->tell(); j < prevTell + ScriptModule.script_lut_entrylen; j++)
+ readS->readByte();
}
RSC_FreeResource(rsc_ptr);
@@ -320,7 +320,6 @@ int SCRIPT_Free() {
// Reads the entrypoint table from a script bytecode resource in memory.
// Returns NULL on failure.
R_SCRIPT_BYTECODE *SCRIPT_LoadBytecode(byte *bytecode_p, size_t bytecode_len) {
- const byte *read_p = bytecode_p;
R_PROC_TBLENTRY *bc_ep_tbl = NULL;
R_SCRIPT_BYTECODE *bc_new_data = NULL;
@@ -330,11 +329,12 @@ R_SCRIPT_BYTECODE *SCRIPT_LoadBytecode(byte *bytecode_p, size_t bytecode_len) {
R_printf(R_STDOUT, "Loading script bytecode...\n");
+ MemoryReadStream *readS = new MemoryReadStream(bytecode_p, bytecode_len);
+
// The first two uint32 values are the number of entrypoints, and the
// offset to the entrypoint table, respectively.
-
- n_entrypoints = ys_read_u32_le(read_p, &read_p);
- ep_tbl_offset = ys_read_u32_le(read_p, &read_p);
+ n_entrypoints = readS->readUint32LE();
+ ep_tbl_offset = readS->readUint32LE();
// Check that the entrypoint table offset is valid.
if ((bytecode_len - ep_tbl_offset) < (n_entrypoints * R_SCRIPT_TBLENTRY_LEN)) {
@@ -365,14 +365,15 @@ R_SCRIPT_BYTECODE *SCRIPT_LoadBytecode(byte *bytecode_p, size_t bytecode_len) {
// Read in the entrypoint table
- read_p = bytecode_p + ep_tbl_offset;
+ while (readS->tell() < ep_tbl_offset)
+ readS->readByte();
for (i = 0; i < n_entrypoints; i++) {
// First uint16 is the offset of the entrypoint name from the start
// of the bytecode resource, second uint16 is the offset of the
// bytecode itself for said entrypoint
- bc_ep_tbl[i].name_offset = ys_read_u16_le(read_p, &read_p);
- bc_ep_tbl[i].offset = ys_read_u16_le(read_p, &read_p);
+ bc_ep_tbl[i].name_offset = readS->readUint16LE();
+ bc_ep_tbl[i].offset = readS->readUint16LE();
// Perform a simple range check on offset values
if ((bc_ep_tbl[i].name_offset > bytecode_len) || (bc_ep_tbl[i].offset > bytecode_len)) {
@@ -396,7 +397,6 @@ R_SCRIPT_BYTECODE *SCRIPT_LoadBytecode(byte *bytecode_p, size_t bytecode_len) {
// Reads a logical dialogue list from a dialogue list resource in memory.
// Returns NULL on failure.
R_DIALOGUE_LIST *SCRIPT_LoadDialogue(const byte *dialogue_p, size_t dialogue_len) {
- const byte *read_p = dialogue_p;
R_DIALOGUE_LIST *dialogue_list;
uint16 n_dialogue;
uint16 i;
@@ -410,8 +410,10 @@ R_DIALOGUE_LIST *SCRIPT_LoadDialogue(const byte *dialogue_p, size_t dialogue_len
return NULL;
}
+ MemoryReadStream *readS = new MemoryReadStream(dialogue_p, dialogue_len);
+
// First uint16 is the offset of the first string
- offset = ys_read_u16_le(read_p, &read_p);
+ offset = readS->readUint16LE();
if (offset > dialogue_len) {
R_printf(R_STDERR, "Error, invalid string offset.\n");
return NULL;
@@ -437,9 +439,9 @@ R_DIALOGUE_LIST *SCRIPT_LoadDialogue(const byte *dialogue_p, size_t dialogue_len
}
// Read in tables from dialogue list resource
- read_p = dialogue_p;
+ readS->rewind();
for (i = 0; i < n_dialogue; i++) {
- offset = ys_read_u16_le(read_p, &read_p);
+ offset = readS->readUint16LE();
if (offset > dialogue_len) {
R_printf(R_STDERR, "Error, invalid string offset.\n");
free(dialogue_list->str);
@@ -457,8 +459,6 @@ R_DIALOGUE_LIST *SCRIPT_LoadDialogue(const byte *dialogue_p, size_t dialogue_len
// Reads a logical voice LUT from a voice LUT resource in memory.
// Returns NULL on failure.
R_VOICE_LUT *SCRIPT_LoadVoiceLUT(const byte *voicelut_p, size_t voicelut_len, R_SCRIPTDATA *script) {
- const byte *read_p = voicelut_p;
-
R_VOICE_LUT *voice_lut;
uint16 n_voices;
@@ -481,9 +481,10 @@ R_VOICE_LUT *SCRIPT_LoadVoiceLUT(const byte *voicelut_p, size_t voicelut_len, R_
return NULL;
}
- for (i = 0; i < n_voices; i++) {
+ MemoryReadStream *readS = new MemoryReadStream(voicelut_p, voicelut_len);
- voice_lut->voices[i] = ys_read_u16_le(read_p, &read_p);
+ for (i = 0; i < n_voices; i++) {
+ voice_lut->voices[i] = readS->readUint16LE();
}
return voice_lut;
diff --git a/saga/script.h b/saga/script.h
index 3e0c32c3e5..a7f03b3a4f 100644
--- a/saga/script.h
+++ b/saga/script.h
@@ -28,6 +28,7 @@
#include "sstack.h"
#include "sdata.h"
+#include "yslib.h"
namespace Saga {
diff --git a/saga/sdebug.cpp b/saga/sdebug.cpp
index c51dd417b8..bdf9d56300 100644
--- a/saga/sdebug.cpp
+++ b/saga/sdebug.cpp
@@ -22,11 +22,9 @@
*/
// Scripting module simple thread debugging support
-
+#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
-
#include "actor_mod.h"
#include "console_mod.h"
#include "text_mod.h"
@@ -43,8 +41,6 @@ namespace Saga {
int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
R_TEXTLIST_ENTRY tl_e;
- const byte *start_p;
- const byte *read_p;
char tmp_buf[80] = { 0 };
static char disp_buf[SD_DISPLAY_LEN] = { 0 };
int in_char;
@@ -71,9 +67,13 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
tl_e.string = disp_buf;
tl_e.display = 1;
- read_p = ScriptModule.current_script->bytecode->bytecode_p + thread->i_offset;
- start_p = read_p;
- in_char = ys_read_u8(read_p, &read_p);
+ // XXX
+ MemoryReadStream *readS =
+ new MemoryReadStream(ScriptModule.current_script->bytecode->bytecode_p
+ + thread->i_offset,
+ ScriptModule.current_script->bytecode->bytecode_len
+ - thread->i_offset);
+ in_char = readS->readByte();
sprintf(tmp_buf, "%04lX | %02X | ", thread->i_offset, in_char);
strncat(disp_buf, tmp_buf, SD_DISPLAY_LEN);
@@ -104,7 +104,7 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param;
SD_ADDTXT("PSHD | ");
- param = ys_read_u16_le(read_p, &read_p);
+ param = readS->readUint16LE();
sprintf(tmp_buf, "%02X", param);
SD_ADDTXT(tmp_buf);
/*
@@ -123,7 +123,7 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param;
SD_ADDTXT("PUSH | ");
- param = ys_read_u16_le(read_p, &read_p);
+ param = readS->readUint16LE();
sprintf(tmp_buf, "%04X", param);
SD_ADDTXT(tmp_buf);
}
@@ -135,8 +135,8 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param2;
SD_ADDTXT("TSTF | ");
- param1 = *read_p++;
- param2 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readByte();
+ param2 = readS->readUint16LE();
sprintf(tmp_buf, "%02X %04X", param1, param2);
SD_ADDTXT(tmp_buf);
}
@@ -148,8 +148,8 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param2;
SD_ADDTXT("GETW | ");
- param1 = *read_p++;
- param2 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readByte();
+ param2 = readS->readUint16LE();
sprintf(tmp_buf, "%02X %04X", param1, param2);
SD_ADDTXT(tmp_buf);
}
@@ -161,8 +161,8 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param2;
SD_ADDTXT("MODF | ");
- param1 = *read_p++;
- param2 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readByte();
+ param2 = readS->readUint16LE();
sprintf(tmp_buf, "%02X %04X", param1, param2);
SD_ADDTXT(tmp_buf);
}
@@ -174,8 +174,8 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param2;
SD_ADDTXT("PUTW | ");
- param1 = *read_p++;
- param2 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readByte();
+ param2 = readS->readUint16LE();
sprintf(tmp_buf, "%02X %04X", param1, param2);
SD_ADDTXT(tmp_buf);
}
@@ -187,8 +187,8 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param2;
SD_ADDTXT("MDFP | ");
- param1 = *read_p++;
- param2 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readByte();
+ param2 = readS->readUint16LE();
sprintf(tmp_buf, "%02X %04X", param1, param2);
SD_ADDTXT(tmp_buf);
}
@@ -200,8 +200,8 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param2;
SD_ADDTXT("PTWP | ");
- param1 = *read_p++;
- param2 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readByte();
+ param2 = readS->readUint16LE();
sprintf(tmp_buf, "%02X %04X", param1, param2);
SD_ADDTXT(tmp_buf);
@@ -215,9 +215,9 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param3;
SD_ADDTXT("GOSB | ");
- param1 = *read_p++;
- param2 = *read_p++;
- param3 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readByte();
+ param2 = readS->readByte();
+ param3 = readS->readUint16LE();
sprintf(tmp_buf, "%02X %02X %04X", param1, param2, param3);
SD_ADDTXT(tmp_buf);
}
@@ -230,10 +230,10 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param;
SD_ADDTXT("CALL | ");
- func_num = *read_p++;
+ func_num = readS->readByte();
sprintf(tmp_buf, "%02X ", func_num);
SD_ADDTXT(tmp_buf);
- param = ys_read_u16_le(read_p, &read_p);
+ param = readS->readUint16LE();
sprintf(tmp_buf, "%04X ", param);
SD_ADDTXT(tmp_buf);
}
@@ -244,7 +244,7 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param;
SD_ADDTXT("ENTR | ");
- param = ys_read_u16_le(read_p, &read_p);
+ param = readS->readUint16LE();
sprintf(tmp_buf, "%04X ", param);
SD_ADDTXT(tmp_buf);
/*
@@ -270,7 +270,7 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param1;
SD_ADDTXT("JMP | ");
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
sprintf(tmp_buf, "%04X", param1);
SD_ADDTXT(tmp_buf);
}
@@ -281,7 +281,7 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param1;
SD_ADDTXT("JNZP | ");
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
sprintf(tmp_buf, "%04X", param1);
SD_ADDTXT(tmp_buf);
}
@@ -292,7 +292,7 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param1;
SD_ADDTXT("JZP | ");
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
sprintf(tmp_buf, "%04X", param1);
SD_ADDTXT(tmp_buf);
}
@@ -302,7 +302,7 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
{
int param1;
SD_ADDTXT("JNZ | ");
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
sprintf(tmp_buf, "%04X", param1);
SD_ADDTXT(tmp_buf);
}
@@ -314,7 +314,7 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param1;
SD_ADDTXT("JZ | ");
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
sprintf(tmp_buf, "%04X", param1);
SD_ADDTXT(tmp_buf);
}
@@ -327,15 +327,15 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int default_jmp;
SD_ADDTXT("SWCH | ");
- n_switch = ys_read_u16_le(read_p, &read_p);
+ n_switch = readS->readUint16LE();
sprintf(tmp_buf, "%02X\n", n_switch);
SD_ADDTXT(tmp_buf);
for (i = 0; i < n_switch; i++) {
- switch_num = ys_read_u16_le(read_p, &read_p);
- switch_jmp = ys_read_u16_le(read_p, &read_p);
+ switch_num = readS->readUint16LE();
+ switch_jmp = readS->readUint16LE();
// printf( R_TAB "CASE %04X, %04X\n", switch_num, switch_jmp);
}
- default_jmp = ys_read_u16_le(read_p, &read_p);
+ default_jmp = readS->readUint16LE();
//printf( R_TAB "DEF %04X", default_jmp);
}
break;
@@ -348,14 +348,14 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
SD_ADDTXT("RJMP | ");
// Ignored?
- ys_read_u16_le(read_p, &read_p);
- n_switch2 = ys_read_u16_le(read_p, &read_p);
+ readS->readUint16LE();
+ n_switch2 = readS->readUint16LE();
sprintf(tmp_buf, "%04X", n_switch2);
SD_ADDTXT(tmp_buf);
for (i = 0; i < n_switch2; i++) {
//printf("\n");
- switch_num = ys_read_u16_le(read_p, &read_p);
- switch_jmp = ys_read_u16_le(read_p, &read_p);
+ switch_num = readS->readUint16LE();
+ switch_jmp = readS->readUint16LE();
//printf( R_TAB "WEIGHT %04X, %04X", switch_num, switch_jmp);
}
}
@@ -371,23 +371,23 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
break;
case 0x28:
SD_ADDTXT("??? ");
- read_p++;
- ys_read_u16_le(read_p, &read_p);
+ readS->readByte();
+ readS->readUint16LE();
break;
case 0x29:
SD_ADDTXT("??? ");
- read_p++;
- ys_read_u16_le(read_p, &read_p);
+ readS->readByte();
+ readS->readUint16LE();
break;
case 0x2A:
SD_ADDTXT("??? ");
- read_p++;
- ys_read_u16_le(read_p, &read_p);
+ readS->readByte();
+ readS->readUint16LE();
break;
case 0x2B:
SD_ADDTXT("??? ");
- read_p++;
- ys_read_u16_le(read_p, &read_p);
+ readS->readByte();
+ readS->readUint16LE();
break;
// Addition
case 0x2C:
@@ -464,11 +464,11 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param2;
SD_ADDTXT("DLGP | ");
- n_voices = *read_p++;
- param1 = ys_read_u16_le(read_p, &read_p);
- param2 = *read_p++;
+ n_voices = readS->readByte();
+ param1 = readS->readUint16LE();
+ param2 = readS->readByte();
// ignored ?
- ys_read_u16_le(read_p, &read_p);
+ readS->readUint16LE();
sprintf(tmp_buf, "%02X %04X %02X", n_voices, param1, param2);
SD_ADDTXT(tmp_buf);
}
@@ -486,12 +486,12 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param3;
SD_ADDTXT("DLGO | ");
- param1 = *read_p++;
- param2 = *read_p++;
+ param1 = readS->readByte();
+ param2 = readS->readByte();
sprintf(tmp_buf, "%02X %02X ", param1, param2);
SD_ADDTXT(tmp_buf);
if (param2 > 0) {
- param3 = ys_read_u16_le(read_p, &read_p);
+ param3 = readS->readUint16LE();
sprintf(tmp_buf, "%04X", param3);
SD_ADDTXT(tmp_buf);
}
@@ -504,9 +504,9 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
int param3;
SD_ADDTXT("JMPS | ");
- param1 = ys_read_u16_le(read_p, &read_p);
- param2 = ys_read_u16_le(read_p, &read_p);
- param3 = *read_p++;
+ param1 = readS->readUint16LE();
+ param2 = readS->readUint16LE();
+ param3 = readS->readByte();
sprintf(tmp_buf, "%04X %04X %02X", param1, param2, param3);
SD_ADDTXT(tmp_buf);
}
diff --git a/saga/sndres.cpp b/saga/sndres.cpp
index abb1d4c1b2..6be5b51e1e 100644
--- a/saga/sndres.cpp
+++ b/saga/sndres.cpp
@@ -26,8 +26,6 @@
#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
-
#include "game_mod.h"
#include "rscfile_mod.h"
@@ -124,58 +122,51 @@ int SndRes::loadVocSound(byte *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_b
R_VOC_BLOCK1 voc_b1;
long byte_rate;
+ size_t i;
- const byte *read_p;
- uint16 read_len;
-
- read_p = snd_res;
- read_len = snd_res_len;
-
- if (read_len < R_VOC_HEADER_BLOCK_LEN) {
+ if (snd_res_len < R_VOC_HEADER_BLOCK_LEN) {
return R_FAILURE;
}
- memcpy(voc_hb.ft_desc, read_p, R_VOC_FILE_DESC_LEN);
- read_p += R_VOC_FILE_DESC_LEN;
- read_len -= R_VOC_FILE_DESC_LEN;
+ MemoryReadStream *readS = new MemoryReadStream(snd_res, snd_res_len);
+
+ for (i = 0; i < R_VOC_FILE_DESC_LEN; i++)
+ voc_hb.ft_desc[i] = readS->readByte();
if (memcmp(voc_hb.ft_desc, R_VOC_FILE_DESC, R_VOC_FILE_DESC_LEN) != 0) {
/* Voc file desc string not found */
return R_FAILURE;
}
- voc_hb.db_offset = ys_read_u16_le(read_p, &read_p);
- voc_hb.voc_version = ys_read_u16_le(read_p, &read_p);
- voc_hb.voc_fileid = ys_read_u16_le(read_p, &read_p);
+ voc_hb.db_offset = readS->readUint16LE();
+ voc_hb.voc_version = readS->readUint16LE();
+ voc_hb.voc_fileid = readS->readUint16LE();
- if (read_len < voc_hb.db_offset + R_VOC_GENBLOCK_LEN) {
+ if (snd_res_len - readS->tell() < voc_hb.db_offset + R_VOC_GENBLOCK_LEN) {
return R_FAILURE;
}
- read_p = snd_res + voc_hb.db_offset;
- read_len = snd_res_len - voc_hb.db_offset;
+ while (readS->tell() < voc_hb.db_offset)
+ readS->readByte();
for (;;) {
/* Read generic block header */
- if (read_len < R_VOC_GENBLOCK_LEN) {
+ if (snd_res_len - readS->tell() < R_VOC_GENBLOCK_LEN) {
return R_FAILURE;
}
- voc_gb.block_id = ys_read_u8(read_p, &read_p);
+ voc_gb.block_id = readS->readByte();
if (voc_gb.block_id == 0) {
return R_FAILURE;
}
- voc_gb.block_len = ys_read_u24_le(read_p, &read_p);
-
- read_len -= R_VOC_GENBLOCK_LEN;
+ voc_gb.block_len = readS->readUint24LE();
/* Process block */
switch (voc_gb.block_id) {
case 1: /* Sound data block */
- voc_b1.time_constant = ys_read_u8(read_p, &read_p);
- voc_b1.pack_method = ys_read_u8(read_p, &read_p);
- read_len -= 2;
+ voc_b1.time_constant = readS->readByte();
+ voc_b1.pack_method = readS->readByte();
if (voc_b1.pack_method != 0) {
debug(0, "Packed VOC files not supported");
@@ -191,15 +182,15 @@ int SndRes::loadVocSound(byte *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_b
snd_buf_i->res_data = snd_res;
snd_buf_i->res_len = snd_res_len;
- snd_buf_i->s_buf = read_p;
- snd_buf_i->s_buf_len = read_len - 1; /* -1 for end block */
+ snd_buf_i->s_buf = snd_res + readS->tell();
+ snd_buf_i->s_buf_len = snd_res_len - readS->tell() - 1; /* -1 for end block */
snd_buf_i->s_signed = 0;
return R_SUCCESS;
break;
default:
- read_p += voc_gb.block_len;
- read_len -= voc_gb.block_len;
+ for (i = 0; i < voc_gb.block_len; i++)
+ readS->readByte();
break;
}
}
diff --git a/saga/sprite.cpp b/saga/sprite.cpp
index e401261264..5ab962e285 100644
--- a/saga/sprite.cpp
+++ b/saga/sprite.cpp
@@ -25,8 +25,6 @@
#include "saga.h"
#include "reinherit.h"
-#include "yslib.h"
-
#include "game_mod.h"
#include "gfx_mod.h"
#include "scene_mod.h"
@@ -85,7 +83,6 @@ int SPRITE_LoadList(int resource_num, R_SPRITELIST **sprite_list_p) {
R_SPRITELIST *new_slist;
byte *spritelist_data;
size_t spritelist_len;
- const byte *read_p;
uint16 sprite_count;
uint16 i;
@@ -98,9 +95,9 @@ int SPRITE_LoadList(int resource_num, R_SPRITELIST **sprite_list_p) {
return R_FAILURE;
}
- read_p = spritelist_data;
+ MemoryReadStream *readS = new MemoryReadStream(spritelist_data, spritelist_len);
- sprite_count = ys_read_u16_le(read_p, &read_p);
+ sprite_count = readS->readUint16LE();
new_slist->sprite_count = sprite_count;
@@ -112,7 +109,7 @@ int SPRITE_LoadList(int resource_num, R_SPRITELIST **sprite_list_p) {
for (i = 0; i < sprite_count; i++) {
new_slist->offset_list[i].data_idx = 0;
- new_slist->offset_list[i].offset = ys_read_u16_le(read_p, &read_p);
+ new_slist->offset_list[i].offset = readS->readUint16LE();
}
new_slist->slist_rn = resource_num;
@@ -127,7 +124,6 @@ int SPRITE_LoadList(int resource_num, R_SPRITELIST **sprite_list_p) {
int SPRITE_AppendList(int resource_num, R_SPRITELIST *spritelist) {
byte *spritelist_data;
size_t spritelist_len;
- const byte *read_p;
void *test_p;
uint16 old_sprite_count;
uint16 new_sprite_count;
@@ -142,9 +138,9 @@ int SPRITE_AppendList(int resource_num, R_SPRITELIST *spritelist) {
return R_FAILURE;
}
- read_p = spritelist_data;
+ MemoryReadStream *readS = new MemoryReadStream(spritelist_data, spritelist_len);
- sprite_count = ys_read_u16_le(read_p, &read_p);
+ sprite_count = readS->readUint16LE();
old_sprite_count = spritelist->sprite_count;
new_sprite_count = spritelist->sprite_count + sprite_count;
@@ -161,7 +157,7 @@ int SPRITE_AppendList(int resource_num, R_SPRITELIST *spritelist) {
for (i = old_sprite_count; i < spritelist->sprite_count; i++) {
spritelist->offset_list[i].data_idx = spritelist->append_count;
- spritelist->offset_list[i].offset = ys_read_u16_le(read_p, &read_p);
+ spritelist->offset_list[i].offset = readS->readUint16LE();
}
spritelist->sprite_data[spritelist->append_count] = spritelist_data;
@@ -192,7 +188,6 @@ int SPRITE_Draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int sp
int offset_idx;
byte *sprite_p;
const byte *sprite_data_p;
- const byte *read_p;
int i, j;
byte *buf_row_p;
byte *src_row_p;
@@ -213,15 +208,15 @@ int SPRITE_Draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int sp
sprite_p = sprite_list->sprite_data[offset_idx];
sprite_p += offset;
- read_p = (byte *) sprite_p;
+ MemoryReadStream *readS = new MemoryReadStream(sprite_p, 5);
- x_align = ys_read_s8(read_p, &read_p);
- y_align = ys_read_s8(read_p, &read_p);
+ x_align = readS->readSByte();
+ y_align = readS->readSByte();
- s_width = ys_read_u8(read_p, &read_p);
- s_height = ys_read_u8(read_p, &read_p);
+ s_width = readS->readByte();
+ s_height = readS->readByte();
- sprite_data_p = read_p;
+ sprite_data_p = sprite_p + readS->tell();
spr_x += x_align;
spr_y += y_align;
@@ -269,7 +264,6 @@ int SPRITE_DrawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num
int offset_idx;
byte *sprite_p;
const byte *sprite_data_p;
- const byte *read_p;
int i;
int x, y;
byte *dst_row_p;
@@ -322,17 +316,17 @@ int SPRITE_DrawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num
sprite_p = sprite_list->sprite_data[offset_idx];
sprite_p += offset;
- read_p = sprite_p;
+ MemoryReadStream *readS = new MemoryReadStream(sprite_p, 5);
// Read sprite dimensions -- should probably cache this stuff in
// sprite list
- x_align = ys_read_s8(read_p, &read_p);
- y_align = ys_read_s8(read_p, &read_p);
+ x_align = readS->readSByte();
+ y_align = readS->readSByte();
- s_width = ys_read_u8(read_p, &read_p);
- s_height = ys_read_u8(read_p, &read_p);
+ s_width = readS->readByte();
+ s_height = readS->readByte();
- sprite_data_p = read_p;
+ sprite_data_p = sprite_p + readS->tell();
// Create actor Z occlusion LUT
SCENE_GetZInfo(&zinfo);
diff --git a/saga/sthread.cpp b/saga/sthread.cpp
index 03ae108f20..61869d65a4 100644
--- a/saga/sthread.cpp
+++ b/saga/sthread.cpp
@@ -139,6 +139,11 @@ unsigned long GetReadOffset(const byte *read_p) {
return (unsigned long)(read_p - (unsigned char *)ScriptModule.current_script->bytecode->bytecode_p);
}
+size_t GetReadLen(R_SCRIPT_THREAD *thread) {
+ return ScriptModule.current_script->bytecode->bytecode_len - thread->i_offset;
+}
+
+
int STHREAD_HoldSem(R_SEMAPHORE *sem) {
if (sem == NULL) {
return R_FAILURE;
@@ -172,7 +177,6 @@ int STHREAD_DebugStep() {
int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int instr_count;
- const byte *read_p;
uint32 saved_offset;
SDataWord_T param1;
SDataWord_T param2;
@@ -219,9 +223,9 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
#if 0
R_printf(R_STDOUT, "Executing thread offset: %lu", thread->i_offset);
#endif
- read_p = GetReadPtr(thread);
+ MemoryReadStream *readS = new MemoryReadStream(GetReadPtr(thread), GetReadLen(thread));
- in_char = ys_read_u8(read_p, &read_p);
+ in_char = readS->readByte();
switch (in_char) {
// Align (ALGN)
@@ -248,12 +252,12 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
// Push word (PUSH)
case 0x06:
- param1 = (SDataWord_T) ys_read_u16_le(read_p, &read_p);
+ param1 = (SDataWord_T)readS->readUint16LE();
SSTACK_Push(thread->stack, param1);
break;
// Push word (PSHD) (dialogue string index)
case 0x08:
- param1 = (SDataWord_T) ys_read_u16_le(read_p, &read_p);
+ param1 = (SDataWord_T)readS->readUint16LE();
SSTACK_Push(thread->stack, param1);
break;
@@ -261,22 +265,22 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// Test flag (TSTF)
case 0x0B:
- n_buf = *read_p++;
- param1 = (SDataWord_T) ys_read_u16_le(read_p, &read_p);
+ n_buf = readS->readByte();
+ param1 = (SDataWord_T)readS->readUint16LE();
SDATA_GetBit(n_buf, param1, &bitstate);
SSTACK_Push(thread->stack, bitstate);
break;
// Get word (GETW)
case 0x0C:
- n_buf = *read_p++;
- param1 = ys_read_u16_le(read_p, &read_p);
+ n_buf = readS->readByte();
+ param1 = readS->readUint16LE();
SDATA_GetWord(n_buf, param1, &data);
SSTACK_Push(thread->stack, data);
break;
// Modify flag (MODF)
case 0x0F:
- n_buf = *read_p++;
- param1 = (SDataWord_T) ys_read_u16_le(read_p, &read_p);
+ n_buf = readS->readByte();
+ param1 = (SDataWord_T)readS->readUint16LE();
bitstate = SDATA_ReadWordU(param1);
SSTACK_Top(thread->stack, &data);
if (bitstate) {
@@ -287,15 +291,15 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
// Put word (PUTW)
case 0x10:
- n_buf = *read_p++;
- param1 = (SDataWord_T) ys_read_u16_le(read_p, &read_p);
+ n_buf = readS->readByte();
+ param1 = (SDataWord_T)readS->readUint16LE();
SSTACK_Top(thread->stack, &data);
SDATA_PutWord(n_buf, param1, data);
break;
// Modify flag and pop (MDFP)
case 0x13:
- n_buf = *read_p++;
- param1 = (SDataWord_T) ys_read_u16_le(read_p, &read_p);
+ n_buf = readS->readByte();
+ param1 = (SDataWord_T)readS->readUint16LE();
SSTACK_Pop(thread->stack, &param1);
bitstate = SDATA_ReadWordU(param1);
if (bitstate) {
@@ -306,8 +310,8 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
// Put word and pop (PTWP)
case 0x14:
- n_buf = *read_p++;
- param1 = (SDataWord_T) ys_read_u16_le(read_p, &read_p);
+ n_buf = readS->readByte();
+ param1 = (SDataWord_T)readS->readUint16LE();
SSTACK_Top(thread->stack, &data);
SDATA_PutWord(n_buf, param1, data);
break;
@@ -320,10 +324,10 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int temp;
int temp2;
- temp = *read_p++;
- temp2 = *read_p++;
- param1 = (SDataWord_T) ys_read_u16_le(read_p, &read_p);
- data = GetReadOffset(read_p);
+ temp = readS->readByte();
+ temp2 = readS->readByte();
+ param1 = (SDataWord_T)readS->readUint16LE();
+ data = readS->tell();
//SSTACK_Push(thread->stack, (SDataWord_T)temp);
SSTACK_Push(thread->stack, data);
thread->i_offset = (unsigned long)param1;
@@ -338,8 +342,8 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int FIXME_SHADOWED_result;
SFunc_T sfunc;
- n_args = ys_read_u8(read_p, &read_p);
- func_num = ys_read_u16_le(read_p, &read_p);
+ n_args = readS->readByte();
+ func_num = readS->readUint16LE();
if (func_num >= R_SFUNC_NUM) {
CON_Print(S_ERROR_PREFIX "Invalid script function number: (%X)\n", func_num);
thread->executing = 0;
@@ -364,7 +368,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
// (ENTR) Enter the dragon
case 0x1A:
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
break;
// (?) Unknown
case 0x1B:
@@ -385,12 +389,12 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// (JMP): Unconditional jump
case 0x1D:
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
thread->i_offset = (unsigned long)param1;
break;
// (JNZP): Jump if nonzero + POP
case 0x1E:
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
SSTACK_Pop(thread->stack, &data);
if (data) {
thread->i_offset = (unsigned long)param1;
@@ -398,7 +402,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
// (JZP): Jump if zero + POP
case 0x1F:
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
SSTACK_Pop(thread->stack, &data);
if (!data) {
thread->i_offset = (unsigned long)param1;
@@ -406,7 +410,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
// (JNZ): Jump if nonzero
case 0x20:
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
SSTACK_Top(thread->stack, &data);
if (data) {
thread->i_offset = (unsigned long)param1;
@@ -414,7 +418,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
// (JZ): Jump if zero
case 0x21:
- param1 = ys_read_u16_le(read_p, &read_p);
+ param1 = readS->readUint16LE();
SSTACK_Top(thread->stack, &data);
if (!data) {
thread->i_offset = (unsigned long)param1;
@@ -423,9 +427,9 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// (JMPR): Relative jump
case 0x57:
// ignored?
- ys_read_u16_le(read_p, &read_p);
- ys_read_u16_le(read_p, &read_p);
- iparam1 = (long)*read_p++;
+ readS->readUint16LE();
+ readS->readUint16LE();
+ iparam1 = (long)readS->readByte();
thread->i_offset += iparam1;
break;
// (SWCH): Switch
@@ -438,10 +442,10 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int case_found = 0;
SSTACK_Pop(thread->stack, &data);
- n_switch = ys_read_u16_le(read_p, &read_p);
+ n_switch = readS->readUint16LE();
for (i = 0; i < n_switch; i++) {
- switch_num = ys_read_u16_le(read_p, &read_p);
- switch_jmp = ys_read_u16_le(read_p, &read_p);
+ switch_num = readS->readUint16LE();
+ switch_jmp = readS->readUint16LE();
// Found the specified case
if (data == (SDataWord_T) switch_num) {
thread->i_offset = switch_jmp;
@@ -452,7 +456,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// Jump to default case
if (!case_found) {
- default_jmp = ys_read_u16_le(read_p, &read_p);
+ default_jmp = readS->readUint16LE();
thread->i_offset = default_jmp;
}
}
@@ -467,11 +471,11 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int branch_found = 0;
// Ignored?
- ys_read_u16_le(read_p, &read_p);
- n_branch = ys_read_u16_le(read_p, &read_p);
+ readS->readUint16LE();
+ n_branch = readS->readUint16LE();
for (i = 0; i < n_branch; i++) {
- branch_wt = ys_read_u16_le(read_p, &read_p);
- branch_jmp = ys_read_u16_le(read_p, &read_p);
+ branch_wt = readS->readUint16LE();
+ branch_jmp = readS->readUint16LE();
if (rand_sel == i) {
thread->i_offset = branch_jmp;
branch_found = 1;
@@ -509,29 +513,29 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
case 0x28:
unhandled = 1;
printf("??? ");
- read_p++;
- ys_read_u16_le(read_p, &read_p);
+ readS->readByte();
+ readS->readUint16LE();
break;
// (?)
case 0x29:
unhandled = 1;
printf("??? ");
- read_p++;
- ys_read_u16_le(read_p, &read_p);
+ readS->readByte();
+ readS->readUint16LE();
break;
// (?)
case 0x2A:
unhandled = 1;
printf("??? ");
- read_p++;
- ys_read_u16_le(read_p, &read_p);
+ readS->readByte();
+ readS->readUint16LE();
break;
// (?)
case 0x2B:
unhandled = 1;
printf("??? ");
- read_p++;
- ys_read_u16_le(read_p, &read_p);
+ readS->readByte();
+ readS->readUint16LE();
break;
// ARITHMETIC INSTRUCTIONS
@@ -714,11 +718,11 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int a_index;
int voice_rn;
- n_voices = *read_p++;
- param1 = (SDataWord_T) ys_read_u16_le(read_p, &read_p);
+ n_voices = readS->readByte();
+ param1 = (SDataWord_T) readS->readUint16LE();
// ignored ?
- *read_p++;
- ys_read_u16_le(read_p, &read_p);
+ readS->readByte();
+ readS->readUint16LE();
a_index = ACTOR_GetActorIndex(param1);
if (a_index < 0) {
@@ -752,12 +756,12 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int FIXME_SHADOWED_param3;
printf("DLGO | ");
- FIXME_SHADOWED_param1 = *read_p++;
- FIXME_SHADOWED_param2 = *read_p++;
+ FIXME_SHADOWED_param1 = readS->readByte();
+ FIXME_SHADOWED_param2 = readS->readByte();
printf("%02X %02X ", FIXME_SHADOWED_param1, FIXME_SHADOWED_param2);
if (FIXME_SHADOWED_param2 > 0) {
- FIXME_SHADOWED_param3 = ys_read_u16_le(read_p, &read_p);
+ FIXME_SHADOWED_param3 = readS->readUint16LE();
printf("%04X", FIXME_SHADOWED_param3);
}
}
@@ -774,7 +778,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// Set instruction offset only if a previous instruction didn't branch
if (saved_offset == thread->i_offset) {
- thread->i_offset = GetReadOffset(read_p);
+ thread->i_offset = readS->tell();
}
if (unhandled) {
CON_Print(S_ERROR_PREFIX "%X: Unhandled opcode.\n", thread->i_offset);
diff --git a/saga/sthread.h b/saga/sthread.h
index f6b77f2544..6eb7329870 100644
--- a/saga/sthread.h
+++ b/saga/sthread.h
@@ -55,6 +55,7 @@ int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num);
int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec);
unsigned long GetReadOffset(const byte *read_p);
unsigned char *GetReadPtr(R_SCRIPT_THREAD *thread);
+size_t GetReadLen(R_SCRIPT_THREAD *thread);
int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread);
} // End of namespace Saga
diff --git a/saga/ys_binread.cpp b/saga/ys_binread.cpp
deleted file mode 100644
index 4eba5acb2c..0000000000
--- a/saga/ys_binread.cpp
+++ /dev/null
@@ -1,185 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2004 The ScummVM project
- *
- * The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Header$
- *
- */
-
-#include "saga.h"
-#include "yslib.h"
-
-namespace Saga {
-
-void ys_read_4cc(char *fourcc, const unsigned char *data_p, const unsigned char **data_pp) {
- fourcc[0] = (char)data_p[0];
- fourcc[1] = (char)data_p[1];
- fourcc[2] = (char)data_p[2];
- fourcc[3] = (char)data_p[3];
-
- if (data_pp) {
- *data_pp = data_p + 4;
- }
-
- return;
-}
-
-// Reads an unsigned 8 bit integer in from the array of bytes pointed to by
-// 'data_p'. If 'data_pp' is not null, it will set '*data_pp' to point past
-// the integer read.
-unsigned int ys_read_u8(const unsigned char *data_p, const unsigned char **data_pp) {
- unsigned int u8 = *data_p;
-
- if (data_pp != NULL) {
- *data_pp = data_p + 1;
- }
-
- return u8;
-}
-
-// Reads a signed 8 bit integer in two's complement notation from the array
-// of bytes pointed to by 'data_p'. If 'data_pp' is not null, it will set
-//'*data_pp' to point past the integer read.
-int ys_read_s8(const unsigned char *data_p, const unsigned char **data_pp) {
- unsigned int u8 = *data_p;
- int s8;
-
-#ifndef YS_ASSUME_2S_COMP
- if (u8 & 0x80U) {
- s8 = (int)(u8 - 0x80U) - 0x7F - 1;
- } else
-#endif
- s8 = u8;
-
- if (data_pp != NULL) {
- *data_pp = data_p + 1;
- }
-
- return s8;
-}
-
-// Reads a signed 8 bit integer in two's complement notation from the array
-// of bytes pointed to by 'data_p'. If 'data_pp' is not null, it will set
-// '*data_pp' to point past the integer read.
-unsigned int ys_read_u16_be(const unsigned char *data_p, const unsigned char **data_pp) {
- unsigned int u16_be = ((unsigned int)data_p[0] << 8) | data_p[1];
-
- if (data_pp != NULL) {
- *data_pp = data_p + 2;
- }
-
- return u16_be;
-}
-
-// Reads an unsigned 16 bit integer in little-endian format from the array of
-// bytes pointed to by 'data_p'. If 'data_pp' is not null, it will set
-// '*data_pp' to point past the integer read.
-unsigned int ys_read_u16_le(const unsigned char *data_p, const unsigned char **data_pp) {
- unsigned int u16_le = ((unsigned int)data_p[1] << 8) | data_p[0];
-
- if (data_pp != NULL) {
- *data_pp = data_p + 2;
- }
-
- return u16_le;
-}
-
-// Reads a signed 16 bit integer in big-endian, 2's complement format from
-// the array of bytes pointed to by 'data_p'.
-// If 'data_pp' is not null, it will set '*data_pp' to point past the integer read.
-int ys_read_s16_be(const unsigned char *data_p, const unsigned char **data_pp) {
- unsigned int u16_be = ((unsigned int)data_p[0] << 8) | data_p[1];
- int s16_be;
-
-#ifndef YS_ASSUME_2S_COMP
- if (u16_be & 0x8000U) {
- s16_be = (int)(u16_be - 0x8000U) - 0x7FFF - 1;
- } else
-#endif
- s16_be = u16_be;
-
- if (data_pp != NULL) {
- *data_pp = data_p + 2;
- }
-
- return s16_be;
-}
-
-// Reads a signed 16 bit integer in little-endian, 2's complement format from
-// the array of bytes pointed to by 'data_p'.
-// If 'data_pp' is not null, it will set '*data_pp' to point past the integer read.
-int ys_read_s16_le(const unsigned char *data_p, const unsigned char **data_pp) {
- unsigned int u16_le = ((unsigned int)data_p[1] << 8) | data_p[0];
- int s16_le;
-
-#ifndef YS_ASSUME_2S_COMP
- if (u16_le & 0x8000U) {
- s16_le = (int)(u16_le - 0x8000U) - 0x7FFF - 1;
- } else
-#endif
- s16_le = u16_le;
-
- if (data_pp != NULL) {
- *data_pp = data_p + 2;
- }
-
- return s16_le;
-}
-
-// Reads an unsigned 24 bit integer in big-endian format from the array of
-// bytes pointed to by 'data_p'. If 'data_pp' is not null, it will set
-// '*data_pp' to point past the integer read.
-unsigned long ys_read_u24_le(const unsigned char *data_p, const unsigned char **data_pp) {
- unsigned long u24_le = ((unsigned long)data_p[3] << 16) | ((unsigned long)data_p[2] << 8) | data_p[0];
-
- if (data_pp != NULL) {
- *data_pp = data_p + 3;
- }
-
- return u24_le;
-}
-
-// Reads an unsigned 32 bit integer in big-endian format from the array of
-// bytes pointed to by 'data_p'. If 'data_pp' is not null, it will set
-// '*data_pp' to point past the integer read.
-unsigned long ys_read_u32_be(const unsigned char *data_p, const unsigned char **data_pp) {
- unsigned long u32_be = ((unsigned long)data_p[0] << 24) | ((unsigned long)data_p[1] << 16) |
- ((unsigned long)data_p[2] << 8) | data_p[3];
-
- if (data_pp != NULL) {
- *data_pp = data_p + 4;
- }
-
- return u32_be;
-}
-
-// Reads an unsigned 32 bit integer in little-endian format from the array of
-// bytes pointed to by 'data_p'. If 'data_pp' is not null, it will set
-// '*data_pp' to point past the integer read.
-unsigned long ys_read_u32_le(const unsigned char *data_p, const unsigned char **data_pp) {
- unsigned long u32_le = ((unsigned long)data_p[3] << 24) | ((unsigned long)data_p[2] << 16) |
- ((unsigned long)data_p[1] << 8) | data_p[0];
-
- if (data_pp != NULL) {
- *data_pp = data_p + 4;
- }
-
- return u32_le;
-}
-
-} // End of namespace Saga
diff --git a/saga/ys_binwrite.cpp b/saga/ys_binwrite.cpp
deleted file mode 100644
index 10ca28fa85..0000000000
--- a/saga/ys_binwrite.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2004 The ScummVM project
- *
- * The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Header$
- *
- */
-#include "saga.h"
-
-namespace Saga {
-
-// Writes an unsigned 16 bit integer in big-endian format to the buffer
-// pointed to by 'data_p'.
-// If 'data_pp' is not null, the function will set it to point just beyond
-// the integer written.
-void ys_write_u16_be(unsigned int u16_be, unsigned char *data_p, unsigned char **data_pp) {
- data_p[0] = (unsigned char)((u16_be >> 8) & 0xFFU);
- data_p[1] = (unsigned char)(u16_be & 0xFFU);
-
- if (data_pp != NULL) {
- *data_pp = data_p + 2;
- }
-
- return;
-}
-
-// Writes an unsigned 32 bit integer in big-endian format to the buffer
-// pointed to by 'data_p'.
-// If 'data_pp' is not null, the function will set it to point just beyond
-// the integer written.
-void ys_write_u32_be(unsigned long u32_be, unsigned char *data_p, unsigned char **data_pp) {
- data_p[0] = (unsigned char)((u32_be >> 24) & 0xFFU);
- data_p[1] = (unsigned char)((u32_be >> 16) & 0xFFU);
- data_p[2] = (unsigned char)((u32_be >> 8) & 0xFFU);
- data_p[3] = (unsigned char)(u32_be & 0xFFU);
-
- if (data_pp != NULL) {
- *data_pp = data_p + 4;
- }
-
- return;
-}
-
-} // End of namespace Saga
diff --git a/saga/yslib.h b/saga/yslib.h
index 5fca102cdd..c876ab14b1 100644
--- a/saga/yslib.h
+++ b/saga/yslib.h
@@ -47,42 +47,6 @@ typedef int (YS_COMPARE_FUNC) (const void *, const void *);
//#define YS_ASSUME_2S_COMP
-// Read a 4CC ( Four characater code )
-void ys_read_4cc(char *fourcc, const unsigned char *data_p, const unsigned char **data_pp);
-
-// Read 8 bit unsigned integer
-unsigned int ys_read_u8(const unsigned char *, const unsigned char **);
-
-// Read 8 bit signed integer
-int ys_read_s8(const unsigned char *, const unsigned char **);
-
-// Read 16 bit unsigned integer, big-endian
-unsigned int ys_read_u16_be(const unsigned char *, const unsigned char **);
-
-// Read 16 bit unsigned integer, little-endian
-unsigned int ys_read_u16_le(const unsigned char *, const unsigned char **);
-
-// Read 16 bit signed integer, 2's complement, big-endian
-int ys_read_s16_be(const unsigned char *, const unsigned char **);
-
-// Read 16 bit signed integer, 2's complement, little-endian
-int ys_read_s16_le(const unsigned char *, const unsigned char **);
-
-// Read 24 bit unsigned integer, little-endian
-unsigned long ys_read_u24_le(const unsigned char *, const unsigned char **);
-
-// Read 32 bit unsigned integer, big-endian
-unsigned long ys_read_u32_be(const unsigned char *, const unsigned char **);
-
-// Read 32 bit unsigned integer, little-endian
-unsigned long ys_read_u32_le(const unsigned char *, const unsigned char **);
-
-// Write 16 bit unsigned integer, big-endian
-void ys_write_u16_be(unsigned int, unsigned char *, unsigned char **);
-
-// Write 32 bit unsigned integer, big-endian
-void ys_write_u32_be(unsigned long, unsigned char *, unsigned char **);
-
// Shared declarations for list modules
enum YS_WALK_DIRECTIONS {
YS_WALK_BACKWARD = 0,