forked from ydeinega/corwar_fin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_ind.c
47 lines (42 loc) · 1.6 KB
/
extract_ind.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* extract_ind.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ydeineha <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/06 18:55:00 by ydeineha #+# #+# */
/* Updated: 2018/09/06 18:55:03 by ydeineha ### ########.fr */
/* */
/* ************************************************************************** */
#include "corewar.h"
static int get_pc_new(t_process *process, int delta, int base)
{
int pc_new;
pc_new = 0;
if (base)
{
if (process->opcode != 10 && process->opcode != 14)
pc_new = (process->pc + ((short)delta % base)) % MEM_SIZE;
else
pc_new = (process->pc + (delta % base)) % MEM_SIZE;
}
else
{
if (process->opcode != 10 && process->opcode != 14)
pc_new = (process->pc + (short)delta) % MEM_SIZE;
else
pc_new = (process->pc + delta) % MEM_SIZE;
}
if (pc_new < 0)
pc_new = MEM_SIZE + pc_new;
return (pc_new);
}
unsigned int extract_ind(t_process *process, int delta, int base)
{
unsigned int res;
int pc_new;
pc_new = get_pc_new(process, delta, base);
res = read_from_board(pc_new, 4);
return (res);
}