forked from ydeinega/corwar_fin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_codage.c
57 lines (52 loc) · 1.68 KB
/
get_codage.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_codage.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ydeineha <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/05 21:28:54 by ydeineha #+# #+# */
/* Updated: 2018/09/05 21:28:56 by ydeineha ### ########.fr */
/* */
/* ************************************************************************** */
#include "corewar.h"
t_arg_type *get_codage(t_process *process, int arg_num)
{
t_arg_type *arg_type;
int codage_pc;
unsigned int codage;
int i;
int shift;
i = 0;
shift = 6;
codage_pc = (process->pc + 1) % MEM_SIZE;
codage = conv_hex(&g_game.board[codage_pc], 1);
arg_type = ft_strnew(arg_num);
while (i < arg_num)
{
arg_type[i] = (codage >> shift) & 3;
if (arg_type[i] == REG_CODE)
arg_type[i] = T_REG;
else if (arg_type[i] == DIR_CODE)
arg_type[i] = T_DIR;
else if (arg_type[i] == IND_CODE)
arg_type[i] = T_IND;
shift -= 2;
i++;
}
return (arg_type);
}
bool codage_valid(t_arg_type *arg_type, t_arg_type *ref, int arg_num)
{
int i;
int check;
i = 0;
check = 0;
while (i < arg_num)
{
if ((arg_type[i] & ref[i]) > 0)
check++;
i++;
}
return (check == arg_num ? 1 : 0);
}