diff options
Diffstat (limited to 'apps/plugins/xworld/vm.h')
-rw-r--r-- | apps/plugins/xworld/vm.h | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/apps/plugins/xworld/vm.h b/apps/plugins/xworld/vm.h new file mode 100644 index 0000000000..1409dd47e3 --- /dev/null +++ b/apps/plugins/xworld/vm.h | |||
@@ -0,0 +1,184 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2014 Franklin Wei, Benjamin Brown | ||
11 | * Copyright (C) 2004 Gregory Montoir | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ***************************************************************************/ | ||
22 | |||
23 | #ifndef __LOGIC_H__ | ||
24 | #define __LOGIC_H__ | ||
25 | |||
26 | |||
27 | |||
28 | #include "intern.h" | ||
29 | |||
30 | #define VM_NUM_THREADS 64 | ||
31 | #define VM_NUM_VARIABLES 256 | ||
32 | #define VM_NO_SETVEC_REQUESTED 0xFFFF | ||
33 | #define VM_INACTIVE_THREAD 0xFFFF | ||
34 | |||
35 | |||
36 | #define VM_VARIABLE_RANDOM_SEED 0x3C | ||
37 | |||
38 | #define VM_VARIABLE_LAST_KEYCHAR 0xDA | ||
39 | |||
40 | #define VM_VARIABLE_HERO_POS_UP_DOWN 0xE5 | ||
41 | #define VM_VARIABLE_MUS_MARK 0xF4 | ||
42 | |||
43 | #define VM_VARIABLE_SCROLL_Y 0xF9 | ||
44 | #define VM_VARIABLE_HERO_ACTION 0xFA | ||
45 | #define VM_VARIABLE_HERO_POS_JUMP_DOWN 0xFB | ||
46 | #define VM_VARIABLE_HERO_POS_LEFT_RIGHT 0xFC | ||
47 | #define VM_VARIABLE_HERO_POS_MASK 0xFD | ||
48 | #define VM_VARIABLE_HERO_ACTION_POS_MASK 0xFE | ||
49 | #define VM_VARIABLE_PAUSE_SLICES 0xFF | ||
50 | |||
51 | struct Mixer; | ||
52 | struct Resource; | ||
53 | struct Serializer; | ||
54 | struct SfxPlayer; | ||
55 | struct System; | ||
56 | struct Video; | ||
57 | |||
58 | //For threadsData navigation | ||
59 | #define PC_OFFSET 0 | ||
60 | #define REQUESTED_PC_OFFSET 1 | ||
61 | #define NUM_DATA_FIELDS 2 | ||
62 | |||
63 | //For vmIsChannelActive navigation | ||
64 | #define CURR_STATE 0 | ||
65 | #define REQUESTED_STATE 1 | ||
66 | #define NUM_THREAD_FIELDS 2 | ||
67 | |||
68 | struct VirtualMachine; | ||
69 | |||
70 | void vm_create(struct VirtualMachine*, struct Mixer *mix, struct Resource *res, struct SfxPlayer *ply, struct Video *vid, struct System *stub); | ||
71 | void vm_init(struct VirtualMachine*); | ||
72 | |||
73 | void vm_op_movConst(struct VirtualMachine*); | ||
74 | void vm_op_mov(struct VirtualMachine*); | ||
75 | void vm_op_add(struct VirtualMachine*); | ||
76 | void vm_op_addConst(struct VirtualMachine*); | ||
77 | void vm_op_call(struct VirtualMachine*); | ||
78 | void vm_op_ret(struct VirtualMachine*); | ||
79 | void vm_op_pauseThread(struct VirtualMachine*); | ||
80 | void vm_op_jmp(struct VirtualMachine*); | ||
81 | void vm_op_setSetVect(struct VirtualMachine*); | ||
82 | void vm_op_jnz(struct VirtualMachine*); | ||
83 | void vm_op_condJmp(struct VirtualMachine*); | ||
84 | void vm_op_setPalette(struct VirtualMachine*); | ||
85 | void vm_op_resetThread(struct VirtualMachine*); | ||
86 | void vm_op_selectVideoPage(struct VirtualMachine*); | ||
87 | void vm_op_fillVideoPage(struct VirtualMachine*); | ||
88 | void vm_op_copyVideoPage(struct VirtualMachine*); | ||
89 | void vm_op_blitFramebuffer(struct VirtualMachine*); | ||
90 | void vm_op_killThread(struct VirtualMachine*); | ||
91 | void vm_op_drawString(struct VirtualMachine*); | ||
92 | void vm_op_sub(struct VirtualMachine*); | ||
93 | void vm_op_and(struct VirtualMachine*); | ||
94 | void vm_op_or(struct VirtualMachine*); | ||
95 | void vm_op_shl(struct VirtualMachine*); | ||
96 | void vm_op_shr(struct VirtualMachine*); | ||
97 | void vm_op_playSound(struct VirtualMachine*); | ||
98 | void vm_op_updateMemList(struct VirtualMachine*); | ||
99 | void vm_op_playMusic(struct VirtualMachine*); | ||
100 | |||
101 | void vm_initForPart(struct VirtualMachine*, uint16_t partId); | ||
102 | void vm_setupPart(struct VirtualMachine*, uint16_t partId); | ||
103 | void vm_checkThreadRequests(struct VirtualMachine*); | ||
104 | void vm_hostFrame(struct VirtualMachine*); | ||
105 | void vm_executeThread(struct VirtualMachine*); | ||
106 | |||
107 | void vm_inp_updatePlayer(struct VirtualMachine*); | ||
108 | void vm_inp_handleSpecialKeys(struct VirtualMachine*); | ||
109 | |||
110 | void vm_snd_playSound(struct VirtualMachine*, uint16_t resNum, uint8_t freq, uint8_t vol, uint8_t channel); | ||
111 | void vm_snd_playMusic(struct VirtualMachine*, uint16_t resNum, uint16_t delay, uint8_t pos); | ||
112 | |||
113 | void vm_saveOrLoad(struct VirtualMachine*, struct Serializer *ser); | ||
114 | void vm_bypassProtection(struct VirtualMachine*); | ||
115 | |||
116 | typedef void (*OpcodeStub)(struct VirtualMachine*); | ||
117 | |||
118 | // The type of entries in opcodeTable. This allows "fast" branching | ||
119 | static const OpcodeStub vm_opcodeTable[] = { | ||
120 | /* 0x00 */ | ||
121 | &vm_op_movConst, | ||
122 | &vm_op_mov, | ||
123 | &vm_op_add, | ||
124 | &vm_op_addConst, | ||
125 | /* 0x04 */ | ||
126 | &vm_op_call, | ||
127 | &vm_op_ret, | ||
128 | &vm_op_pauseThread, | ||
129 | &vm_op_jmp, | ||
130 | /* 0x08 */ | ||
131 | &vm_op_setSetVect, | ||
132 | &vm_op_jnz, | ||
133 | &vm_op_condJmp, | ||
134 | &vm_op_setPalette, | ||
135 | /* 0x0C */ | ||
136 | &vm_op_resetThread, | ||
137 | &vm_op_selectVideoPage, | ||
138 | &vm_op_fillVideoPage, | ||
139 | &vm_op_copyVideoPage, | ||
140 | /* 0x10 */ | ||
141 | &vm_op_blitFramebuffer, | ||
142 | &vm_op_killThread, | ||
143 | &vm_op_drawString, | ||
144 | &vm_op_sub, | ||
145 | /* 0x14 */ | ||
146 | &vm_op_and, | ||
147 | &vm_op_or, | ||
148 | &vm_op_shl, | ||
149 | &vm_op_shr, | ||
150 | /* 0x18 */ | ||
151 | &vm_op_playSound, | ||
152 | &vm_op_updateMemList, | ||
153 | &vm_op_playMusic | ||
154 | }; | ||
155 | |||
156 | struct VirtualMachine { | ||
157 | //This table is used to play a sound | ||
158 | //static const uint16_t frequenceTable[]; | ||
159 | /* FW: moved from staticres.c to vm.c */ | ||
160 | |||
161 | struct Mixer *mixer; | ||
162 | struct Resource *res; | ||
163 | struct SfxPlayer *player; | ||
164 | struct Video *video; | ||
165 | struct System *sys; | ||
166 | |||
167 | int16_t vmVariables[VM_NUM_VARIABLES]; | ||
168 | uint16_t _scriptStackCalls[VM_NUM_THREADS]; | ||
169 | |||
170 | uint16_t threadsData[NUM_DATA_FIELDS][VM_NUM_THREADS]; | ||
171 | // This array is used: | ||
172 | // 0 to save the channel's instruction pointer | ||
173 | // when the channel release control (this happens on a break). | ||
174 | |||
175 | // 1 When a setVec is requested for the next vm frame. | ||
176 | |||
177 | uint8_t vmIsChannelActive[NUM_THREAD_FIELDS][VM_NUM_THREADS]; | ||
178 | |||
179 | struct Ptr _scriptPtr; | ||
180 | uint8_t _stackPtr; | ||
181 | bool gotoNextThread; | ||
182 | bool _fastMode; | ||
183 | }; | ||
184 | #endif | ||