-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm.h
158 lines (114 loc) · 3.66 KB
/
vm.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Raw - Another World Interpreter
* Copyright (C) 2004 Gregory Montoir
*
* 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.
*/
#ifndef __LOGIC_H__
#define __LOGIC_H__
#include "intern.h"
#define VM_NUM_THREADS 64
#define VM_NUM_VARIABLES 256
#define VM_NO_SETVEC_REQUESTED 0xFFFF
#define VM_INACTIVE_THREAD 0xFFFF
enum ScriptVars {
VM_VARIABLE_RANDOM_SEED = 0x3C,
VM_VARIABLE_LAST_KEYCHAR = 0xDA,
VM_VARIABLE_HERO_POS_UP_DOWN = 0xE5,
VM_VARIABLE_MUS_MARK = 0xF4,
VM_VARIABLE_SCROLL_Y = 0xF9, // = 239
VM_VARIABLE_HERO_ACTION = 0xFA,
VM_VARIABLE_HERO_POS_JUMP_DOWN = 0xFB,
VM_VARIABLE_HERO_POS_LEFT_RIGHT = 0xFC,
VM_VARIABLE_HERO_POS_MASK = 0xFD,
VM_VARIABLE_HERO_ACTION_POS_MASK = 0xFE,
VM_VARIABLE_PAUSE_SLICES = 0xFF
};
struct Mixer;
struct Resource;
struct Serializer;
struct SfxPlayer;
struct System;
struct Video;
//For threadsData navigation
#define PC_OFFSET 0
#define REQUESTED_PC_OFFSET 1
#define NUM_DATA_FIELDS 2
//For vmIsChannelActive navigation
#define CURR_STATE 0
#define REQUESTED_STATE 1
#define NUM_THREAD_FIELDS 2
struct VirtualMachine {
// The type of entries in opcodeTable. This allows "fast" branching
typedef void (VirtualMachine::*OpcodeStub)();
static const OpcodeStub opcodeTable[];
//This table is used to play a sound
static const uint16_t frequenceTable[];
Mixer *mixer;
Resource *res;
SfxPlayer *player;
Video *video;
System *sys;
int16_t vmVariables[VM_NUM_VARIABLES];
uint16_t _scriptStackCalls[VM_NUM_THREADS];
uint16_t threadsData[NUM_DATA_FIELDS][VM_NUM_THREADS];
// This array is used:
// 0 to save the channel's instruction pointer
// when the channel release control (this happens on a break).
// 1 When a setVec is requested for the next vm frame.
uint8_t vmIsChannelActive[NUM_THREAD_FIELDS][VM_NUM_THREADS];
Ptr _scriptPtr;
uint8_t _stackPtr;
bool gotoNextThread;
bool _fastMode;
VirtualMachine(Mixer *mix, Resource *res, SfxPlayer *ply, Video *vid, System *stub);
void init();
void op_movConst();
void op_mov();
void op_add();
void op_addConst();
void op_call();
void op_ret();
void op_pauseThread();
void op_jmp();
void op_setSetVect();
void op_jnz();
void op_condJmp();
void op_setPalette();
void op_resetThread();
void op_selectVideoPage();
void op_fillVideoPage();
void op_copyVideoPage();
void op_blitFramebuffer();
void op_killThread();
void op_drawString();
void op_sub();
void op_and();
void op_or();
void op_shl();
void op_shr();
void op_playSound();
void op_updateMemList();
void op_playMusic();
void initForPart(uint16_t partId);
void setupPart(uint16_t partId);
void checkThreadRequests();
void hostFrame();
void executeThread();
void inp_updatePlayer();
void inp_handleSpecialKeys();
void snd_playSound(uint16_t resNum, uint8_t freq, uint8_t vol, uint8_t channel);
void snd_playMusic(uint16_t resNum, uint16_t delay, uint8_t pos);
void saveOrLoad(Serializer &ser);
void bypassProtection();
};
#endif