REminiscence/intern.h

294 lines
4.9 KiB
C
Raw Normal View History

2016-03-20 17:00:00 +01:00
/*
* REminiscence - Flashback interpreter
2019-10-27 17:00:00 +01:00
* Copyright (C) 2005-2019 Gregory Montoir (cyx@users.sourceforge.net)
2015-08-02 18:00:00 +02:00
*/
#ifndef INTERN_H__
#define INTERN_H__
2017-06-07 18:00:00 +02:00
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
2015-08-02 18:00:00 +02:00
#include <stdint.h>
2017-06-07 18:00:00 +02:00
#undef ARRAYSIZE
#define ARRAYSIZE(a) (int)(sizeof(a)/sizeof(a[0]))
2015-08-02 18:00:00 +02:00
inline uint16_t READ_BE_UINT16(const void *ptr) {
const uint8_t *b = (const uint8_t *)ptr;
return (b[0] << 8) | b[1];
}
inline uint32_t READ_BE_UINT32(const void *ptr) {
const uint8_t *b = (const uint8_t *)ptr;
return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
}
inline uint16_t READ_LE_UINT16(const void *ptr) {
const uint8_t *b = (const uint8_t *)ptr;
return (b[1] << 8) | b[0];
}
inline uint32_t READ_LE_UINT32(const void *ptr) {
const uint8_t *b = (const uint8_t *)ptr;
return (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0];
}
2016-05-09 18:00:00 +02:00
inline int16_t ADDC_S16(int a, int b) {
a += b;
if (a < -32768) {
a = -32768;
} else if (a > 32767) {
a = 32767;
}
return a;
}
2019-10-27 17:00:00 +01:00
inline int16_t S8_to_S16(int a) {
if (a < -128) {
return -32768;
} else if (a > 127) {
return 32767;
} else {
const uint8_t u8 = (a ^ 0x80);
return ((u8 << 8) | u8) - 32768;
}
}
2015-08-02 18:00:00 +02:00
template<typename T>
inline void SWAP(T &a, T &b) {
T tmp = a;
a = b;
b = tmp;
}
2018-03-18 17:00:00 +01:00
template<typename T>
inline T CLIP(const T& val, const T& a, const T& b) {
if (val < a) {
return a;
} else if (val > b) {
return b;
}
return val;
}
2019-10-27 17:00:00 +01:00
#undef MIN
template<typename T>
inline T MIN(T v1, T v2) {
return (v1 < v2) ? v1 : v2;
}
#undef MAX
template<typename T>
inline T MAX(T v1, T v2) {
return (v1 > v2) ? v1 : v2;
}
#undef ABS
template<typename T>
inline T ABS(T t) {
return (t < 0) ? -t : t;
}
2015-08-02 18:00:00 +02:00
enum Language {
LANG_FR,
LANG_EN,
LANG_DE,
LANG_SP,
2017-12-06 17:00:00 +01:00
LANG_IT,
LANG_JP,
2015-08-02 18:00:00 +02:00
};
enum ResourceType {
kResourceTypeAmiga,
2018-02-10 17:00:00 +01:00
kResourceTypeDOS,
kResourceTypeMac,
2016-03-20 17:00:00 +01:00
};
2018-01-20 17:00:00 +01:00
enum Skill {
kSkillEasy = 0,
kSkillNormal,
kSkillExpert,
};
2018-03-28 18:00:00 +02:00
enum WidescreenMode {
kWidescreenNone,
kWidescreenAdjacentRooms,
kWidescreenMirrorRoom,
2019-10-27 17:00:00 +01:00
kWidescreenBlur,
2018-03-28 18:00:00 +02:00
};
2016-03-20 17:00:00 +01:00
struct Options {
bool bypass_protection;
bool enable_password_menu;
2018-03-18 17:00:00 +01:00
bool enable_language_selection;
2016-03-20 17:00:00 +01:00
bool fade_out_palette;
2019-10-27 17:00:00 +01:00
bool use_tile_data;
2016-05-09 18:00:00 +02:00
bool use_text_cutscenes;
2017-06-07 18:00:00 +02:00
bool use_seq_cutscenes;
2019-10-27 17:00:00 +01:00
bool use_words_protection;
bool use_white_tshirt;
2018-02-10 17:00:00 +01:00
bool play_asc_cutscene;
bool play_caillou_cutscene;
bool play_metro_cutscene;
bool play_serrure_cutscene;
2019-10-27 17:00:00 +01:00
bool play_carte_cutscene;
bool play_gamesaved_sound;
2021-05-01 18:00:00 +02:00
bool restore_memo_cutscene;
2015-08-02 18:00:00 +02:00
};
struct Color {
uint8_t r;
uint8_t g;
uint8_t b;
};
struct Point {
int16_t x;
int16_t y;
};
2016-08-07 18:00:00 +02:00
struct Demo {
const char *name;
int level;
int room;
int x, y;
};
2015-08-02 18:00:00 +02:00
struct Level {
const char *name;
const char *name2;
const char *nameAmiga;
uint16_t cutscene_id;
uint8_t sound;
uint8_t track;
};
struct InitPGE {
uint16_t type;
int16_t pos_x;
int16_t pos_y;
uint16_t obj_node_number;
uint16_t life;
2021-05-01 18:00:00 +02:00
int16_t counter_values[4]; // data
2015-08-02 18:00:00 +02:00
uint8_t object_type;
uint8_t init_room;
uint8_t room_location;
uint8_t init_flags;
uint8_t colliding_icon_num;
uint8_t icon_num;
uint8_t object_id;
uint8_t skill;
uint8_t mirror_x;
2021-05-01 18:00:00 +02:00
uint8_t flags; // 1:xflip 4:active
2015-08-02 18:00:00 +02:00
uint8_t unk1C; // collidable, collision_data_len
uint16_t text_num;
};
struct LivePGE {
uint16_t obj_type;
int16_t pos_x;
int16_t pos_y;
uint8_t anim_seq;
uint8_t room_location;
int16_t life;
2019-10-27 17:00:00 +01:00
int16_t counter_value; // msg
2015-08-02 18:00:00 +02:00
uint8_t collision_slot;
uint8_t next_inventory_PGE;
uint8_t current_inventory_PGE;
uint8_t unkF; // unk_inventory_PGE
uint16_t anim_number;
uint8_t flags;
uint8_t index;
uint16_t first_obj_number;
LivePGE *next_PGE_in_room;
InitPGE *init_PGE;
};
2021-05-01 18:00:00 +02:00
struct MessagePGE {
MessagePGE *next_entry;
uint16_t index; // src_pge
uint16_t msg_num;
2015-08-02 18:00:00 +02:00
};
struct Object {
uint16_t type;
int8_t dx;
int8_t dy;
uint16_t init_obj_type;
uint8_t opcode2;
uint8_t opcode1;
uint8_t flags;
uint8_t opcode3;
uint16_t init_obj_number;
int16_t opcode_arg1;
int16_t opcode_arg2;
int16_t opcode_arg3;
};
struct ObjectNode {
uint16_t last_obj_number;
Object *objects;
uint16_t num_objects;
};
struct ObjectOpcodeArgs {
LivePGE *pge; // arg0
int16_t a; // arg2
int16_t b; // arg4
};
struct AnimBufferState {
int16_t x, y;
uint8_t w, h;
const uint8_t *dataPtr;
LivePGE *pge;
};
struct AnimBuffers {
AnimBufferState *_states[4];
uint8_t _curPos[4];
void addState(uint8_t stateNum, int16_t x, int16_t y, const uint8_t *dataPtr, LivePGE *pge, uint8_t w = 0, uint8_t h = 0);
};
struct CollisionSlot {
int16_t ct_pos;
CollisionSlot *prev_slot;
LivePGE *live_pge;
uint16_t index;
};
struct BankSlot {
uint16_t entryNum;
uint8_t *ptr;
};
struct CollisionSlot2 {
CollisionSlot2 *next_slot;
int8_t *unk2;
uint8_t data_size;
uint8_t data_buf[0x10]; // XXX check size
};
struct InventoryItem {
uint8_t icon_num;
InitPGE *init_pge;
LivePGE *live_pge;
};
struct SoundFx {
uint32_t offset;
uint16_t len;
2018-02-24 17:00:00 +01:00
uint16_t freq;
2015-08-02 18:00:00 +02:00
uint8_t *data;
2019-10-27 17:00:00 +01:00
int8_t peak;
2015-08-02 18:00:00 +02:00
};
2016-03-20 17:00:00 +01:00
extern Options g_options;
2015-08-02 18:00:00 +02:00
extern const char *g_caption;
#endif // INTERN_H__