forked from akerou/fvp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
hcbdecoder.h
78 lines (62 loc) · 2.06 KB
/
hcbdecoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef HCBDECODER_H
#define HCBDECODER_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hcb_global.h>
#define MAX_IDXCOUNT 8192
#define VMSTACK_SIZE 16
#define MAX_SPEAKFUNC 50
#define OPHIST 6
extern _OP_DEF opdef[];
class HcbDecoder
{
public:
HcbDecoder() {}
int decode(const char *hcbname, const char *outname);
private:
typedef enum { T_TRUE, T_FALSE, T_INTEGER, T_FLOAT, T_STRING, T_RET } VM_TYPE;
typedef struct
{
unsigned char opcode;
const char *name;
_OPARG params;
} _OP_DEF;
typedef struct
{
unsigned char *hcbbuf;
unsigned char *p; //instruction pointer
int sp; //stack position
int framenum;
int status;
int qscan_state;
struct
{
VM_TYPE type;
int data;
} stack[VMSTACK_SIZE];
struct
{
int orig_sp;
unsigned char *retp;
} frame[3];
} VM_CONTEXT;
int getFuncIdFromOffset(unsigned int offset, unsigned int *func_index, int numfunc, int exact);
int indexFunctions(const unsigned char *buf, const unsigned char *p, const unsigned char *endcodep, unsigned int *idx, unsigned int *counted, int mode, const char *codemap);
int decode_op(const unsigned char *p);
const char *funcAlias(int funcId, int funcCount, unsigned char *buf, unsigned char *p);
void getSysImports(unsigned char *buf, char ***sys_imports);
FILE *outfile;
int txt_start;
char g_temp[32];
int speakfuncs[MAX_SPEAKFUNC], speak_count;
const char *getSpeakerName(unsigned char *hcbbuf, unsigned char *p);
void vm_execute(VM_CONTEXT *c);
void nothing(const char *x...);
void quickscan(VM_CONTEXT *c);
int isSpeakFunction(unsigned char *hcbbuf, unsigned int offset);
const char *getBgName(unsigned char *hcbbuf, unsigned char *p);
void findSpeakFuncs(unsigned char *hcbbuf, unsigned int *func_index, unsigned int func_count);
void vm_init(VM_CONTEXT *context, unsigned char *hcbbuf, unsigned char *p);
};
#endif // HCBDECODER_H