forked from ydeinega/corwar_fin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_from_board.c
46 lines (41 loc) · 1.43 KB
/
read_from_board.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read_from_board.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ydeineha <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/06 19:04:13 by ydeineha #+# #+# */
/* Updated: 2018/09/06 19:04:16 by ydeineha ### ########.fr */
/* */
/* ************************************************************************** */
#include "corewar.h"
unsigned char *extract_line(int pc, int length)
{
int i;
unsigned char *line;
i = 0;
if (!(line = (unsigned char *)malloc(sizeof(unsigned char) * length)))
{
perror("malloc() in extract_line() failed ");
error(-1);
}
while (i < length)
{
line[i] = g_game.board[pc];
i++;
pc = (pc + 1) % MEM_SIZE;
}
return (line);
}
unsigned int read_from_board(int pc, int length)
{
unsigned char *line;
unsigned int res;
line = NULL;
res = 0;
line = extract_line(pc, length);
res = conv_hex(line, length);
free(line);
return (res);
}