/*
 * corewar.h
 *
 *  Scott Adkins
 *    sadkins@bigbird.cs.ohiou.edu
 *    sadkins@oucsace.cs.ohiou.edu
 *
 *  Purpose: Contains most of the definitions and structures for the game.
 *
 */

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <curses.h>


#define VersionString 	"Version 1.3"
#define Major 		1
#define Minor		3

#define MAX_PROG	16

#define ON		1
#define OFF		0

#define ASSEMBLE	0
#define LOAD		1

#define SINGLES		0
#define CHALLENGE	1
#define ROUNDS		2
#define DEBUG		3

#define DEF_SIZE	8000
#define DEF_CYCLES	100000
#define DEF_BATTLES	1
#define DEF_PROCESS	64
#define DEF_DISPLAY	100
#define DEF_FADE	0
#define DEF_ARENA	16
#define DEF_STATS	ON
#define DEF_CONFIG	ON
#define DEF_RESULTS	ON
#define DEF_TOTALS	ON
#define DEF_FIGHT	SINGLES
#define DEF_LOAD	LOAD

#define DAT		0
#define MOV		1
#define ADD		2
#define SUB		3
#define JMP		4
#define JMZ		5
#define JMN		6
#define DJN		7
#define CMP		8
#define SLT		9
#define SPL		10
#define EQU		11
#define END		12

#define IMMEDIATE	0
#define DIRECT		1
#define INDIRECT	2
#define PREDECREMENT	3


static char *OpcodeString[] = {
	"dat", "mov", "add", "sub", "jmp", "jmz", "jmn",
	"djn", "cmp", "slt", "spl", "equ", "end", ""
};

static char *ModeString[] = {
	"#", " ", "@", "<"
};


typedef struct label {
	char label[81];			/* Label in the program */
	int address;			/* Address the label occures at */
	struct label *next;		/* Next label in the program */
} LABEL;

typedef struct program {
	char filename[81];		/* Name of the program */
	int length;			/* Length of the program */
	int address;			/* Start address in core */
	int start;			/* Start line in program */
	int index;			/* Index into the list */
	int wins;			/* Winning results */
	int losses;			/* Losing results */
	int ties;			/* Tying results */
	int twins;			/* Total wins */
	int tlosses;			/* Total losses */
	int tties;			/* Total ties */
	struct program *next;		/* Next program */
} PROGRAM;

typedef struct Statement_Register {
	int Control;			/* Opcodes and modes */
	int AField;			/* Address of operand #1 */
	int BField;			/* Address of operand #2 */
	int Owner;			/* Ownership of the code */
	int Aging;			/* How long since last change */
} CORE;

typedef struct CoreNode {
	struct CoreNode *last;		/* Last task to execute */
	int PC;				/* Pointer counter for task */
	struct CoreNode *next;		/* Next task to execute; */
} TASKS;
