Corewar documentation 1.0.0
Loading...
Searching...
No Matches
corewar.h File Reference

The header of the corewar project. More...

#include "mymemory.h"
#include "myop.h"
#include "ncurses.h"

Go to the source code of this file.

Data Structures

struct  cell_s
 The cell structure. More...
 
struct  champion_s
 The champion structure. More...
 
struct  corewar_s
 The corewar structure. More...
 

Macros

#define COREWAR_H_
 
#define CHAMPION   ((champion_t *)tmp->data)
 
#define ARENA_LINE_NUMBER   96
 

Typedefs

typedef struct cell_s cell_t
 The cell structure.
 
typedef struct champion_s champion_t
 The champion structure.
 
typedef struct corewar_s corewar_t
 The corewar structure.
 

Functions

corewar_tget_corewar (void)
 Get the corewar structure.
 
void free_corewar (void)
 Free the corewar structure and all the memory allocated.
 
int corewar (void)
 The virtual machine of the corewar.
 
int parse_args (int argc, char **argv)
 Parse the arguments.
 
int get_next_champion_number (void)
 Get the next champion number disponible.
 
int champion_number_exist (int number)
 Check if a champion number exist.
 
int analyse_champions (void)
 Analyse each champion files and complete the champion structure.
 
champion_tget_champion_by_number (int number)
 Get a champion by its number.
 
void update_program_counter (champion_t *champion, int value)
 Update the program counter of a champion.
 
void update_carry (champion_t *champion, int value)
 Update the carry of a champion.
 
char * read_file (char *filepath, int size, int start)
 Read a file and return the content.
 
int get_prog_size (char *header)
 Get the program size.
 
int is_valid_magic (char *header)
 Check if the magic number is valid.
 
int build_arena (void)
 Build the arena.
 
void display_arena (void)
 Display the arena.
 
node_tget_arena_node (int address)
 Get the arena node from an address.
 
void check_alive_champions (void)
 Check if the champions are alive.
 
void display_winner (node_t *champions)
 Display the winner.
 
int check_champions_number (node_t *champions)
 Check the number of champions.
 
void execute_instructions (champion_t *champion)
 Execute the instructions.
 
int get_int_from_address (node_t *address, int size)
 Get int from address.
 
void write_int_in_address (champion_t *champion, node_t *address, int value)
 Write int in address.
 
int read_int_in_address (node_t *address, int size)
 Read int in address.
 
char get_code_byte_index (char coding_byte, int index)
 Get the type of byte with the coding byte at the index.
 
char get_size_from_type (char type, bool max_size)
 Get the size of the type.
 
char get_size_of_coding_byte (char coding_byte, bool max_size)
 Get the size of the coding byte.
 
void exec_add (champion_t *champion, node_t *address)
 The add function.
 
void exec_aff (champion_t *champion, node_t *address)
 The aff function.
 
void exec_and (champion_t *champion, node_t *address)
 The and function.
 
void exec_fork (champion_t *champion, node_t *address)
 The fork function.
 
void exec_ld (champion_t *champion, node_t *address)
 The ld function.
 
void exec_ldi (champion_t *champion, node_t *address)
 The ldi function.
 
void exec_lfork (champion_t *champion, node_t *address)
 The lfork function.
 
void exec_live (champion_t *champion, node_t *address)
 The live function.
 
void exec_lld (champion_t *champion, node_t *address)
 The lld function.
 
void exec_lldi (champion_t *champion, node_t *address)
 The lldi function.
 
void exec_or (champion_t *champion, node_t *address)
 The or function.
 
void exec_st (champion_t *champion, node_t *address)
 The st function.
 
void exec_sti (champion_t *champion, node_t *address)
 The sti function.
 
void exec_sub (champion_t *champion, node_t *address)
 The sub function.
 
void exec_xor (champion_t *champion, node_t *address)
 The xor function.
 
void exec_zjmp (champion_t *champion, node_t *address)
 The zjmp function.
 
void update_max_visual_index (corewar_t *corewar)
 Update the max visual index.
 
int check_touch (corewar_t *corewar)
 Check the touch.
 
void init_display (corewar_t *corewar)
 Initialize the display.
 
void set_color (int address, char *owner)
 Set the color of the texte.
 
void display_corewar (corewar_t *corewar)
 Display the corewar.
 

Detailed Description

The header of the corewar project.

Typedef Documentation

◆ cell_t

typedef struct cell_s cell_t

The cell structure.

Note
A cell is a memory case of the arena

Function Documentation

◆ analyse_champions()

int analyse_champions ( void )

Analyse each champion files and complete the champion structure.

Returns
int 0 if the analyse is a success, 84 otherwise

◆ build_arena()

int build_arena ( void )

Build the arena.

Returns
int 0 if an error occurred, 84 otherwise

◆ champion_number_exist()

int champion_number_exist ( int number)

Check if a champion number exist.

Parameters
numberThe champion number
Returns
int 1 if the champion number exist, 0 otherwise

◆ check_alive_champions()

void check_alive_champions ( void )

Check if the champions are alive.

Returns
void

◆ check_champions_number()

int check_champions_number ( node_t * champions)

Check the number of champions.

Parameters
championsThe champions list
Returns
int 1 if the are more than one champion, 0 otherwise

◆ check_touch()

int check_touch ( corewar_t * corewar)

Check the touch.

Parameters
corewarThe corewar structure
Returns
int 1 if the terminal is too small, 0 otherwise

◆ corewar()

int corewar ( void )

The virtual machine of the corewar.

Returns
int 0 if the corewar is running, 84 otherwise

◆ display_arena()

void display_arena ( void )

Display the arena.

Returns
void

◆ display_corewar()

void display_corewar ( corewar_t * corewar)

Display the corewar.

Parameters
corewarThe corewar structure
Returns
void

◆ display_winner()

void display_winner ( node_t * champions)

Display the winner.

Parameters
championsThe champions list
Returns
void

◆ exec_add()

void exec_add ( champion_t * champion,
node_t * address )

The add function.

Parameters
championThe champion to execute the add function
addressThe address of the add function
Returns
void

◆ exec_aff()

void exec_aff ( champion_t * champion,
node_t * address )

The aff function.

Parameters
championThe champion to execute the aff function
addressThe address of the aff function
Returns
void

◆ exec_and()

void exec_and ( champion_t * champion,
node_t * address )

The and function.

Parameters
championThe champion to execute the and function
addressThe address of the and function
Returns
void

◆ exec_fork()

void exec_fork ( champion_t * champion,
node_t * address )

The fork function.

Parameters
championThe champion to execute the fork function
addressThe address of the fork function
Returns
void

◆ exec_ld()

void exec_ld ( champion_t * champion,
node_t * address )

The ld function.

Parameters
championThe champion to execute the ld function
addressThe address of the ld function
Returns
void

◆ exec_ldi()

void exec_ldi ( champion_t * champion,
node_t * address )

The ldi function.

Parameters
championThe champion to execute the ldi function
addressThe address of the ldi function
Returns
void

◆ exec_lfork()

void exec_lfork ( champion_t * champion,
node_t * address )

The lfork function.

Parameters
championThe champion to execute the lfork function
addressThe address of the lfork function
Returns
void

◆ exec_live()

void exec_live ( champion_t * champion,
node_t * address )

The live function.

Parameters
championThe champion to execute the live function
addressThe address of the live function
Returns
void

◆ exec_lld()

void exec_lld ( champion_t * champion,
node_t * address )

The lld function.

Parameters
championThe champion to execute the lld function
addressThe address of the lld function
Returns
void

◆ exec_lldi()

void exec_lldi ( champion_t * champion,
node_t * address )

The lldi function.

Parameters
championThe champion to execute the lldi function
addressThe address of the lldi function
Returns
void

◆ exec_or()

void exec_or ( champion_t * champion,
node_t * address )

The or function.

Parameters
championThe champion to execute the or function
addressThe address of the or function
Returns
void

◆ exec_st()

void exec_st ( champion_t * champion,
node_t * address )

The st function.

Parameters
championThe champion to execute the st function
addressThe address of the st function
Returns
void

◆ exec_sti()

void exec_sti ( champion_t * champion,
node_t * address )

The sti function.

Parameters
championThe champion to execute the sti function
addressThe address of the sti function
Returns
void

◆ exec_sub()

void exec_sub ( champion_t * champion,
node_t * address )

The sub function.

Parameters
championThe champion to execute the sub function
addressThe address of the sub function
Returns
void

◆ exec_xor()

void exec_xor ( champion_t * champion,
node_t * address )

The xor function.

Parameters
championThe champion to execute the xor function
addressThe address of the xor function
Returns
void

◆ exec_zjmp()

void exec_zjmp ( champion_t * champion,
node_t * address )

The zjmp function.

Parameters
championThe champion to execute the zjmp function
addressThe address of the zjmp function
Returns
void

◆ execute_instructions()

void execute_instructions ( champion_t * champion)

Execute the instructions.

Parameters
championThe champion to execute the instructions
Returns
void

◆ free_corewar()

void free_corewar ( void )

Free the corewar structure and all the memory allocated.

Returns
void

◆ get_arena_node()

node_t * get_arena_node ( int address)

Get the arena node from an address.

Parameters
addressThe address of the node
Returns
node_t* The arena

◆ get_champion_by_number()

champion_t * get_champion_by_number ( int number)

Get a champion by its number.

Parameters
numberThe champion number
Returns
champion_t* The champion

◆ get_code_byte_index()

char get_code_byte_index ( char coding_byte,
int index )

Get the type of byte with the coding byte at the index.

Parameters
coding_byteThe coding byte to get the index
indexThe index of the coding byte value
Returns
char The type of byte

◆ get_corewar()

corewar_t * get_corewar ( void )

Get the corewar structure.

Returns
corewar_t* The corewar structure

◆ get_int_from_address()

int get_int_from_address ( node_t * address,
int size )

Get int from address.

Parameters
addressThe address to get the int
sizeThe size of the int
Returns
int The int

◆ get_next_champion_number()

int get_next_champion_number ( void )

Get the next champion number disponible.

Returns
int The next champion number

◆ get_prog_size()

int get_prog_size ( char * header)

Get the program size.

Parameters
headerThe header of the program
Returns
int The program size

◆ get_size_from_type()

char get_size_from_type ( char type,
bool max_size )

Get the size of the type.

Parameters
typeThe type to get the size
max_sizeThe max size of the type
Returns
char The size of the type

◆ get_size_of_coding_byte()

char get_size_of_coding_byte ( char coding_byte,
bool max_size )

Get the size of the coding byte.

Parameters
coding_byteThe coding byte to get the size
max_sizeThe max size of the coding byte
Returns
char The size of the coding byte

◆ init_display()

void init_display ( corewar_t * corewar)

Initialize the display.

Parameters
corewarThe corewar structure
Returns
void

◆ is_valid_magic()

int is_valid_magic ( char * header)

Check if the magic number is valid.

Parameters
headerThe header of the program
Returns
int 1 if the magic number is valid, 0 otherwise

◆ parse_args()

int parse_args ( int argc,
char ** argv )

Parse the arguments.

Parameters
argcThe number of arguments
argvThe arguments
Returns
int 0 if the parsing is a success, 84 otherwise

◆ read_file()

char * read_file ( char * filepath,
int size,
int start )

Read a file and return the content.

Parameters
filepathThe file path
sizeThe size of the bytes to read
startThe start of the reading
Returns
char* The content of the file or NULL if an error occurred

◆ read_int_in_address()

int read_int_in_address ( node_t * address,
int size )

Read int in address.

Parameters
addressThe address to read the int
sizeThe size of the int
Returns
int The int read

◆ set_color()

void set_color ( int address,
char * owner )

Set the color of the texte.

Parameters
addressThe address of the cell
ownerThe owner of the cell
Returns
void

◆ update_carry()

void update_carry ( champion_t * champion,
int value )

Update the carry of a champion.

Parameters
championThe champion to update
valueThe value to check
Returns
void

◆ update_max_visual_index()

void update_max_visual_index ( corewar_t * corewar)

Update the max visual index.

Parameters
corewarThe corewar structure
Returns
void

◆ update_program_counter()

void update_program_counter ( champion_t * champion,
int value )

Update the program counter of a champion.

Parameters
championThe champion to update
valueThe value to add to the program counter
Returns
void

◆ write_int_in_address()

void write_int_in_address ( champion_t * champion,
node_t * address,
int value )

Write int in address.

Parameters
championThe champion to write the int
addressThe address to write the int
valueThe value to write