-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpreter.c
138 lines (124 loc) · 3.69 KB
/
interpreter.c
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
#ifndef INTERPRETER_C
#define INTERPRETER_C
#include <evo.h>
#include "bytecode.h"
#include "int_fragments.c"
struct vm_cmd {
u8 id;
u8 count;
u8 length;
u8 p0;
i16 p1;
i16 p2;
i16 p3;
i16 p4;
i16 p5;
i16 p6;
i16 p7;
};
typedef struct vm_cmd VMCmd;
u8 *code;
u16 pc = 0 ;
u8 exec_cnt = 0;
u8 executing = 0;
static void init_vm(u8 *level)
{
pc = 0;
exec_cnt = 0;
code = level;
executing = 1;
}
static void vm_step()
{
VMCmd* curCmd;
if (!executing)
return;
curCmd = (void*) (code + pc);
if (exec_cnt >= curCmd->count) {
exec_cnt = 0;
pc += curCmd->length;
curCmd = (void*) (code + pc);
}
switch (curCmd->id)
{
case NOP_CMD:
break;
case JUST_STAR_CMD:
push_star(curCmd->p1, curCmd->p2);
break;
case ENEMIES_PAIR_CMD:
int_enemies_pair(curCmd->p0, curCmd->p1, curCmd->p2);
break;
case MAKE_CARAVAN_CMD:
int_make_caravan(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4);
break;
case MAKE_LEFT_FLYERS_CMD:
int_make_left_flyers(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4);
break;
case MAKE_RIGHT_FLYERS_CMD:
int_make_right_flyers(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4);
break;
case MAKE_BOOM_FAIRY_CMD:
int_make_boom_fairy(curCmd->p1, curCmd->p0, curCmd->p2);
break;
case ENEMY_WAVE_CMD:
int_enemy_wave(curCmd->p1, curCmd->p0, curCmd->p2);
break;
case MID_BOSS1_CMD:
int_mid_boss1(curCmd->p1, curCmd->p2);
break;
case DOUBLE_CARAVAN_CMD:
int_double_caravan(curCmd->p1, curCmd->p0, curCmd->p2, curCmd->p3);
break;
case MAKE_SHOOTING_STAR_CMD:
int_make_shooting_star(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4);
break;
case PUSH_NPC_CMD:
int_push_npc(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4, curCmd->p5, curCmd->p6, curCmd->p7);
break;
case TRIANGLE_CMD:
int_triangle(curCmd->p0, curCmd->p1, curCmd->p2);
break;
case MAKE_CORRIDOR_CMD:
int_make_corridor(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3);
break;
case TRIANGLE_HALF_CMD:
int_make_triangle_half(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3);
break;
case DROPPED_ENEMY_CMD:
int_dropped_enemy(curCmd->p0, curCmd->p1, curCmd->p2);
break;
case FIRING_TRAP_CMD:
int_firing_trap(curCmd->p1);
break;
case MID_BOSS2_CMD:
int_mid_boss2(curCmd->p1, curCmd->p2);
break;
case AIMED_SIDE_ENEMIES_CMD:
int_aimed_side_enemies(curCmd->p0, curCmd->p1);
break;
case AIMED_CIRCLE_CMD:
int_aimed_circle(curCmd->p0, curCmd->p1);
break;
case MARISA_HELP_CMD:
int_marisa_help();
break;
case SET_SPEED_CMD:
int_set_speed(curCmd->p0, curCmd->p1, curCmd->p2);
break;
case AIMED_SHOT_CMD:
int_aimed_shoot(curCmd->p0);
break;
case END_CMD:
executing = 0;
break;
default:
__asm
di
halt
__endasm;
break;
}
exec_cnt ++ ;
}
#endif