constify simon engine; turned global var vc_get_out_of_code into a member of class SimonEngine

svn-id: r16106
This commit is contained in:
Max Horn 2004-12-18 01:33:21 +00:00
parent b93dd59a44
commit 0ceb634fd4
5 changed files with 90 additions and 91 deletions

View File

@ -169,7 +169,7 @@ void SimonEngine::dumpSubroutines() {
}
}
void SimonEngine::dump_video_script(byte *src, bool one_opcode_only) {
void SimonEngine::dump_video_script(const byte *src, bool one_opcode_only) {
uint opcode;
const char *str, *strn;
@ -233,43 +233,43 @@ void SimonEngine::dump_video_script(byte *src, bool one_opcode_only) {
} while (!one_opcode_only);
}
void SimonEngine::dump_vga_file(byte *vga) {
void SimonEngine::dump_vga_file(const byte *vga) {
{
byte *pp;
byte *p;
const byte *pp;
const byte *p;
int count;
pp = vga;
p = pp + READ_BE_UINT16(&((VgaFile1Header *) pp)->hdr2_start);
count = READ_BE_UINT16(&((VgaFile1Header2 *) p)->id_count);
p = pp + READ_BE_UINT16(&((VgaFile1Header2 *) p)->id_table);
p = pp + READ_BE_UINT16(&((const VgaFile1Header *) pp)->hdr2_start);
count = READ_BE_UINT16(&((const VgaFile1Header2 *) p)->id_count);
p = pp + READ_BE_UINT16(&((const VgaFile1Header2 *) p)->id_table);
while (--count >= 0) {
int id = READ_BE_UINT16(&((VgaFile1Struct0x6 *) p)->id);
int id = READ_BE_UINT16(&((const VgaFile1Struct0x6 *) p)->id);
dump_vga_script_always(vga + READ_BE_UINT16(&((VgaFile1Struct0x6 *) p)->script_offs), id / 100, id);
dump_vga_script_always(vga + READ_BE_UINT16(&((const VgaFile1Struct0x6 *) p)->script_offs), id / 100, id);
p += sizeof(VgaFile1Struct0x6);
}
}
{
byte *bb, *b;
const byte *bb, *b;
int c;
bb = vga;
b = bb + READ_BE_UINT16(&((VgaFile1Header *) bb)->hdr2_start);
c = READ_BE_UINT16(&((VgaFile1Header2 *) b)->unk1);
b = bb + READ_BE_UINT16(&((VgaFile1Header2 *) b)->unk2_offs);
b = bb + READ_BE_UINT16(&((const VgaFile1Header *) bb)->hdr2_start);
c = READ_BE_UINT16(&((const VgaFile1Header2 *) b)->unk1);
b = bb + READ_BE_UINT16(&((const VgaFile1Header2 *) b)->unk2_offs);
while (--c >= 0) {
int id = READ_BE_UINT16(&((VgaFile1Struct0x8 *) b)->id);
int id = READ_BE_UINT16(&((const VgaFile1Struct0x8 *) b)->id);
dump_vga_script_always(vga + READ_BE_UINT16(&((VgaFile1Struct0x8 *) b)->script_offs), id / 100, id);
dump_vga_script_always(vga + READ_BE_UINT16(&((const VgaFile1Struct0x8 *) b)->script_offs), id / 100, id);
b += sizeof(VgaFile1Struct0x8);
}
}
}
const byte bmp_hdr[] = {
static const byte bmp_hdr[] = {
0x42, 0x4D,
0x9E, 0x14, 0x00, 0x00, /* offset 2, file size */
0x00, 0x00, 0x00, 0x00,
@ -323,7 +323,7 @@ void dump_bmp(const char *filename, int w, int h, const byte *bytes, const uint3
fclose(out);
}
void dump_bitmap(const char *filename, byte *offs, int w, int h, int flags, const byte *palette,
static void dump_bitmap(const char *filename, const byte *offs, int w, int h, int flags, const byte *palette,
byte base)
{
/* allocate */
@ -351,7 +351,7 @@ void dump_bitmap(const char *filename, byte *offs, int w, int h, int flags, cons
free(b);
}
void SimonEngine::dump_single_bitmap(int file, int image, byte *offs, int w, int h, byte base) {
void SimonEngine::dump_single_bitmap(int file, int image, const byte *offs, int w, int h, byte base) {
char buf[40];
#if !defined(__PALM_OS__) && !defined(__DC__)
struct stat statbuf;
@ -390,11 +390,11 @@ void pal_load(byte *pal, const byte *vga1, int a, int b) {
} while (--num);
}
void SimonEngine::dump_vga_bitmaps(byte *vga, byte *vga1, int res) {
void SimonEngine::dump_vga_bitmaps(const byte *vga, byte *vga1, int res) {
int i;
uint32 offs;
byte *p2;
const byte *p2;
byte pal[768];
{
@ -411,14 +411,14 @@ void SimonEngine::dump_vga_bitmaps(byte *vga, byte *vga1, int res) {
for(i = 1; ; i++) {
p2 = vga + i * 8;
offs = TO_BE_32(*(uint32 *)p2);
offs = READ_BE_UINT32(p2);
/* try to detect end of images.
* assume the end when offset >= 200kb */
if (offs >= 200*1024)
return;
width = TO_BE_16(*(uint16 *)(p2 + 6));
width = READ_BE_UINT16(p2 + 6);
height = p2[5];
flags = p2[4];
@ -439,14 +439,14 @@ void SimonEngine::dump_vga_bitmaps(byte *vga, byte *vga1, int res) {
}
}
void SimonEngine::dump_vga_script_always(byte *ptr, uint res, uint sprite_id) {
void SimonEngine::dump_vga_script_always(const byte *ptr, uint res, uint sprite_id) {
fprintf(_dump_file, "; address=%x, vgafile=%d vgasprite=%d\n",
ptr - _vga_buffer_pointers[res].vgaFile1, res, sprite_id);
dump_video_script(ptr, false);
fprintf(_dump_file, "; end\n");
}
void SimonEngine::dump_vga_script(byte *ptr, uint res, uint sprite_id) {
void SimonEngine::dump_vga_script(const byte *ptr, uint res, uint sprite_id) {
dump_vga_script_always(ptr, res, sprite_id);
}

View File

@ -263,6 +263,7 @@ SimonEngine::SimonEngine(GameDetector *detector, OSystem *syst)
: Engine(syst), midi(syst) {
_vc_ptr = 0;
_vc_get_out_of_code = 0;
_game_offsets_ptr = 0;
const SimonGameSettings *g = simon_settings;
@ -2420,7 +2421,7 @@ void SimonEngine::set_video_mode_internal(uint mode, uint vga_res_id) {
VgaPointersEntry *vpe;
byte *bb, *b;
uint16 c;
byte *vc_ptr_org;
const byte *vc_ptr_org;
_video_palette_mode = mode;
_lock_word |= 0x20;
@ -2561,7 +2562,7 @@ void SimonEngine::expire_vga_timers() {
if (!--vte->delay) {
uint16 cur_file = vte->cur_vga_file;
uint16 cur_unk = vte->sprite_id;
byte *script_ptr = vte->script_pointer;
const byte *script_ptr = vte->script_pointer;
_next_vga_timer_to_process = vte + 1;
delete_vga_timer(vte);
@ -2601,7 +2602,7 @@ void SimonEngine::scroll_timeout() {
add_vga_timer(6, NULL, 0, 0);
}
void SimonEngine::vc_resume_sprite(byte *code_ptr, uint16 cur_file, uint16 cur_sprite) {
void SimonEngine::vc_resume_sprite(const byte *code_ptr, uint16 cur_file, uint16 cur_sprite) {
VgaPointersEntry *vpe;
_vga_cur_sprite_id = cur_sprite;
@ -2618,7 +2619,7 @@ void SimonEngine::vc_resume_sprite(byte *code_ptr, uint16 cur_file, uint16 cur_s
run_vga_script();
}
void SimonEngine::add_vga_timer(uint num, byte *code_ptr, uint cur_sprite, uint cur_file) {
void SimonEngine::add_vga_timer(uint num, const byte *code_ptr, uint cur_sprite, uint cur_file) {
VgaTimerEntry *vte;
// When Simon talks to the Golum about stew in French version of
@ -2711,7 +2712,7 @@ void SimonEngine::skip_speech() {
void SimonEngine::timer_vga_sprites() {
VgaSprite *vsp;
VgaPointersEntry *vpe;
byte *vc_ptr_org = _vc_ptr;
const byte *vc_ptr_org = _vc_ptr;
uint16 params[5]; // parameters to vc_10
if (_video_var_9 == 2)
@ -2743,7 +2744,7 @@ void SimonEngine::timer_vga_sprites() {
params[4] = READ_BE_UINT16(&vsp->unk4);
}
_vc_ptr = (byte *)params;
_vc_ptr = (const byte *)params;
vc_10_draw();
vsp++;
@ -2757,7 +2758,8 @@ void SimonEngine::timer_vga_sprites() {
}
void SimonEngine::timer_vga_sprites_helper() {
byte *dst = dx_lock_2(), *src;
byte *dst = dx_lock_2();
const byte *src;
uint x;
if (_vga_var3 < 0) {
@ -2774,7 +2776,7 @@ void SimonEngine::timer_vga_sprites_helper() {
}
src = _vga_var7 + x * 4;
decodeStripA(dst, src + READ_BE_UINT32(&*((uint32 *)src)), _vga_var5);
decodeStripA(dst, src + READ_BE_UINT32(src), _vga_var5);
dx_unlock_2();
@ -2793,7 +2795,7 @@ void SimonEngine::timer_vga_sprites_helper() {
void SimonEngine::timer_vga_sprites_2() {
VgaSprite *vsp;
VgaPointersEntry *vpe;
byte *vc_ptr_org = _vc_ptr;
const byte *vc_ptr_org = _vc_ptr;
uint16 params[5]; // parameters to vc_10_draw
if (_video_var_9 == 2)
@ -2817,7 +2819,7 @@ void SimonEngine::timer_vga_sprites_2() {
params[2] = READ_BE_UINT16(&vsp->x);
params[3] = READ_BE_UINT16(&vsp->y);
params[4] = READ_BE_UINT16(&vsp->unk4);
_vc_ptr = (byte *)params;
_vc_ptr = (const byte *)params;
vc_10_draw();
vsp++;
@ -3009,7 +3011,7 @@ uint SimonEngine::itemPtrToID(Item *id) {
}
void SimonEngine::o_pathfind(int x, int y, uint var_1, uint var_2) {
uint16 *p;
const uint16 *p;
uint i, j;
uint prev_i;
uint x_diff, y_diff;
@ -3021,7 +3023,7 @@ void SimonEngine::o_pathfind(int x, int y, uint var_1, uint var_2) {
prev_i = 21 - _variableArray[12];
for (i = 20; i != 0; --i) {
p = (uint16 *)_pathfind_array[20 - i];
p = (const uint16 *)_pathfind_array[20 - i];
if (!p)
continue;
for (j = 0; READ_BE_UINT16(&p[0]) != 999; j++, p += 2) { // 0xE703 = byteswapped 999

View File

@ -87,7 +87,7 @@ struct VgaSprite {
struct VgaSleepStruct {
uint16 ident;
byte *code_ptr;
const byte *code_ptr;
uint16 sprite_id;
uint16 cur_vga_file;
VgaSleepStruct() { memset(this, 0, sizeof(*this)); }
@ -95,7 +95,7 @@ struct VgaSleepStruct {
struct VgaTimerEntry {
uint16 delay;
byte *script_pointer;
const byte *script_pointer;
uint16 sprite_id;
uint16 cur_vga_file;
VgaTimerEntry() { memset(this, 0, sizeof(*this)); }
@ -112,7 +112,9 @@ class SimonEngine : public Engine {
protected:
void playSting(uint a);
byte *_vc_ptr; /* video code ptr */
const byte *_vc_ptr; /* video code ptr */
uint16 _vc_get_out_of_code;
uint32 *_game_offsets_ptr;
@ -211,7 +213,7 @@ protected:
int16 _script_unk_1;
bool _vga_var6;
int _x_scroll, _vga_var1, _vga_var2, _vga_var3, _vga_var5;
byte *_vga_var7;
const byte *_vga_var7;
byte _vga_var8;
int16 _script_cond_a, _script_cond_b, _script_cond_c;
@ -323,7 +325,7 @@ protected:
VgaSprite _vga_sprites[180];
VgaSleepStruct _vga_sleep_structs[30];
uint16 *_pathfind_array[20];
const uint16 *_pathfind_array[20];
uint8 _palette_backup[1024];
uint8 _palette[1024];
@ -371,7 +373,7 @@ protected:
Common::RandomSource _rnd;
byte *_vc_10_base_ptr_old;
const byte *_vc_10_base_ptr_old;
byte _hebrew_char_widths[32];
public:
@ -695,7 +697,7 @@ public:
protected:
void delete_vga_timer(VgaTimerEntry * vte);
void vc_resume_sprite(byte *code_ptr, uint16 cur_file, uint16 cur_sprite);
void vc_resume_sprite(const byte *code_ptr, uint16 cur_file, uint16 cur_sprite);
int vc_read_var_or_word();
uint vc_read_next_word();
uint vc_read_next_byte();
@ -707,7 +709,7 @@ protected:
bool itemIsParentOf(uint16 a, uint16 b);
bool vc_maybe_skip_proc_1(uint16 a, int16 b);
void add_vga_timer(uint num, byte *code_ptr, uint cur_sprite, uint cur_file);
void add_vga_timer(uint num, const byte *code_ptr, uint cur_sprite, uint cur_file);
VgaSprite *find_cur_sprite();
void vc_set_bit_to(uint bit, bool value);
@ -755,12 +757,12 @@ protected:
void dx_clear_surfaces(uint num_lines);
void dx_update_screen_and_palette();
void dump_video_script(byte *src, bool one_opcode_only);
void dump_vga_file(byte *vga);
void dump_vga_script(byte *ptr, uint res, uint sprite_id);
void dump_vga_script_always(byte *ptr, uint res, uint sprite_id);
void dump_vga_bitmaps(byte *vga, byte *vga1, int res);
void dump_single_bitmap(int file, int image, byte *offs, int w, int h, byte base);
void dump_video_script(const byte *src, bool one_opcode_only);
void dump_vga_file(const byte *vga);
void dump_vga_script(const byte *ptr, uint res, uint sprite_id);
void dump_vga_script_always(const byte *ptr, uint res, uint sprite_id);
void dump_vga_bitmaps(const byte *vga, byte *vga1, int res);
void dump_single_bitmap(int file, int image, const byte *offs, int w, int h, byte base);
void dx_clear_attached_from_top(uint lines);
void dx_copy_from_attached_to_2(uint x, uint y, uint w, uint h);
@ -773,8 +775,8 @@ protected:
void quick_load_or_save();
void shutdown();
byte *vc_10_depack_swap(byte *src, uint w, uint h);
byte *vc_10_no_depack_swap(byte *src, uint w, uint h);
byte *vc_10_depack_swap(const byte *src, uint w, uint h);
byte *vc_10_no_depack_swap(const byte *src, uint w, uint h);
Item *getNextItemPtrStrange();
@ -796,7 +798,7 @@ protected:
void o_190_helper(uint i);
void timer_vga_sprites_helper();
void decodeStripA(byte *dst, byte *src, int height);
void decodeStripA(byte *dst, const byte *src, int height);
void scroll_timeout();
void hitarea_stuff_helper_2();
void realizePalette();

View File

@ -28,7 +28,6 @@
namespace Simon {
typedef void (SimonEngine::*VgaOpcodeProc) ();
static uint16 vc_get_out_of_code = 0;
// Opcode tables
static const VgaOpcodeProc vga_opcode_table[] = {
@ -115,7 +114,7 @@ void SimonEngine::run_vga_script() {
uint opcode;
if (_continous_vgascript) {
if (_vc_ptr != (byte *)&vc_get_out_of_code) {
if (_vc_ptr != (const byte *)&_vc_get_out_of_code) {
fprintf(_dump_file, "%.5d %.5X: %5d %4d ", _vga_tick_counter, _vc_ptr - _cur_vga_file_1, _vga_cur_sprite_id, _vga_cur_file_id);
dump_video_script(_vc_ptr, true);
}
@ -223,7 +222,8 @@ void SimonEngine::vc_2_call() {
uint num;
uint res;
byte *old_file_1, *old_file_2;
byte *b, *bb, *vc_ptr_org;
byte *b, *bb;
const byte *vc_ptr_org;
num = vc_read_var_or_word();
@ -392,7 +392,7 @@ void SimonEngine::vc_9_skip_if_unk3_is() {
byte *vc_10_depack_column(VC10_state * vs) {
int8 a = vs->depack_cont;
byte *src = vs->depack_src;
const byte *src = vs->depack_src;
byte *dst = vs->depack_dest;
byte dh = vs->dh;
byte color;
@ -440,7 +440,7 @@ void vc_10_skip_cols(VC10_state *vs) {
}
}
byte *SimonEngine::vc_10_depack_swap(byte *src, uint w, uint h) {
byte *SimonEngine::vc_10_depack_swap(const byte *src, uint w, uint h) {
w <<= 3;
{
@ -513,7 +513,7 @@ byte *SimonEngine::vc_10_depack_swap(byte *src, uint w, uint h) {
return _video_buf_1;
}
byte *SimonEngine::vc_10_no_depack_swap(byte *src, uint w, uint h) {
byte *SimonEngine::vc_10_no_depack_swap(const byte *src, uint w, uint h) {
if (src == _vc_10_base_ptr_old)
return _video_buf_1;
@ -544,7 +544,7 @@ static uint16 _video_windows[128] = {
};
/* simon2 specific */
void SimonEngine::decodeStripA(byte *dst, byte *src, int height) {
void SimonEngine::decodeStripA(byte *dst, const byte *src, int height) {
const uint pitch = _dx_surface_pitch;
int8 reps = (int8)0x80;
byte color;
@ -642,7 +642,8 @@ void SimonEngine::vc_10_draw() {
}
if (_game & GF_SIMON2 && width >= 21) {
byte *src, *dst;
const byte *src;
byte *dst;
uint w;
_vga_var1 = width * 2 - 40;
@ -794,7 +795,8 @@ void SimonEngine::vc_10_draw() {
/* vc_10_helper_5 */
} else if (_lock_word & 0x20 && state.base_color == 0 || state.base_color == 0xC0) {
byte *src, *dst;
const byte *src;
byte *dst;
uint h, i;
if (!(state.e & 8)) {
@ -962,7 +964,8 @@ void SimonEngine::vc_10_draw() {
}
/* vc_10_helper_6 */
} else {
byte *src, *dst;
const byte *src;
byte *dst;
uint count;
src = state.depack_src + (width * state.y_skip) * 8;
@ -1025,7 +1028,7 @@ void SimonEngine::vc_12_delay() {
num += VGA_DELAY_BASE;
add_vga_timer(num, _vc_ptr, _vga_cur_sprite_id, _vga_cur_file_id);
_vc_ptr = (byte *)&vc_get_out_of_code;
_vc_ptr = (byte *)&_vc_get_out_of_code;
}
void SimonEngine::vc_13_set_sprite_offset_x() {
@ -1071,12 +1074,12 @@ void SimonEngine::vc_16_sleep_on_id() {
vfs->sprite_id = _vga_cur_sprite_id;
vfs->cur_vga_file = _vga_cur_file_id;
_vc_ptr = (byte *)&vc_get_out_of_code;
_vc_ptr = (byte *)&_vc_get_out_of_code;
}
void SimonEngine::vc_17_set_pathfind_item() {
uint a = vc_read_next_word();
_pathfind_array[a - 1] = (uint16 *)_vc_ptr;
_pathfind_array[a - 1] = (const uint16 *)_vc_ptr;
while (READ_BE_UINT16(_vc_ptr) != 999)
_vc_ptr += 4;
_vc_ptr += 2;
@ -1095,36 +1098,28 @@ void SimonEngine::vc_19_chain_to_script() {
/* helper routines */
/* write unaligned 16-bit */
static void write_16_le(void *p, uint16 a) {
((byte *)p)[0] = (byte)(a);
((byte *)p)[1] = (byte)(a >> 8);
}
/* read unaligned 16-bit */
static uint16 read_16_le(void *p) {
return ((byte *)p)[0] | (((byte *)p)[1] << 8);
}
/* FIXME: unaligned access */
void SimonEngine::vc_20_set_code_word() {
/* FIXME: This pücode is somewhat strange: it first reads a BE word from
* the script (advancing the script pointer in doing so); then it writes
* back the same word, this time as LE, into the script.
*/
uint16 a = vc_read_next_word();
write_16_le(_vc_ptr, a);
WRITE_LE_UINT16(const_cast<byte *>(_vc_ptr), a);
_vc_ptr += 2;
}
/* FIXME: unaligned access */
void SimonEngine::vc_21_jump_if_code_word() {
int16 a = vc_read_next_word();
byte *tmp = _vc_ptr + a;
const byte *tmp = _vc_ptr + a;
if (_game & GF_SIMON2)
tmp += 3;
else
tmp += 4;
uint16 val = read_16_le(tmp);
uint16 val = READ_LE_UINT16(tmp);
if (val != 0) {
write_16_le(tmp, val - 1);
// Decrement counter
WRITE_LE_UINT16(const_cast<byte *>(tmp), val - 1);
_vc_ptr = tmp + 2;
}
}
@ -1210,7 +1205,7 @@ void SimonEngine::vc_25_halt_sprite() {
memcpy(vsp, vsp + 1, sizeof(VgaSprite));
vsp++;
}
_vc_ptr = (byte *)&vc_get_out_of_code;
_vc_ptr = (byte *)&_vc_get_out_of_code;
_vga_sprite_changed++;
}
@ -1456,7 +1451,7 @@ void SimonEngine::vc_42_delay_if_not_eq() {
if (val != vc_read_next_word()) {
add_vga_timer(_vga_base_delay + 1, _vc_ptr - 4, _vga_cur_sprite_id, _vga_cur_file_id);
_vc_ptr = (byte *)&vc_get_out_of_code;
_vc_ptr = (byte *)&_vc_get_out_of_code;
}
}
@ -1493,7 +1488,7 @@ void SimonEngine::vc_48() {
uint a = (uint16)_variableArray[12];
uint b = (uint16)_variableArray[13];
int c = _variableArray[14];
uint16 *p = _pathfind_array[a - 1];
const uint16 *p = _pathfind_array[a - 1];
int step;
int y1, y2;
int16 *vp;
@ -1595,7 +1590,7 @@ void SimonEngine::vc_56_delay() {
uint num = vc_read_var_or_word() * _vga_base_delay;
add_vga_timer(num + VGA_DELAY_BASE, _vc_ptr, _vga_cur_sprite_id, _vga_cur_file_id);
_vc_ptr = (byte *)&vc_get_out_of_code;
_vc_ptr = (byte *)&_vc_get_out_of_code;
}
}
@ -1617,7 +1612,7 @@ void SimonEngine::vc_59() {
void SimonEngine::vc_58() {
uint sprite = _vga_cur_sprite_id;
uint file = _vga_cur_file_id;
byte *vc_ptr_org;
const byte *vc_ptr_org;
uint16 tmp;
_vga_cur_file_id = vc_read_next_word();
@ -1643,7 +1638,7 @@ void SimonEngine::vc_kill_sprite(uint file, uint sprite) {
VgaSleepStruct *vfs;
VgaSprite *vsp;
VgaTimerEntry *vte;
byte *vc_ptr_org;
const byte *vc_ptr_org;
old_sprite_id = _vga_cur_sprite_id;
old_cur_file_id = _vga_cur_file_id;
@ -1736,7 +1731,7 @@ void SimonEngine::vc_62_palette_thing() {
uint16 params[5]; /* parameters to vc_10_draw */
VgaSprite *vsp;
VgaPointersEntry *vpe;
byte *vc_ptr_org = _vc_ptr;
const byte *vc_ptr_org = _vc_ptr;
vsp = _vga_sprites;
while (vsp->id != 0) {

View File

@ -73,7 +73,7 @@ struct VC10_state {
byte dl, dh;
byte *depack_src;
const byte *depack_src;
int8 depack_cont;
byte depack_dest[200];