wm: 5552

ref: 3128b86e38f6375c886cae173dc9deff3e4c0d3f
dir: /5552.h/

View raw version
#define MMAX	1 << 8
#define OPLEN	16
#define REGS	16
#define INSTLEN 3


/* internal */
enum
{
	WARN,
	ERR,

	SFLAG,
};

/* ops */
enum
{
	DRD, /* read from device */
	DWR, /* write to device */

	NOT,
	AND,
	NOR,
	XOR,

	ADD,
	SUB,

	INC,
	DEC,

	MUL,
	DIV,

	SHR,
	SHL,

	JMP,
};

/* registers */
enum
{
	ZERO,
	ONE,
	
	DUP,
	FLAGS,
	
	PC,
	STATE,
}

/* devices */
typedef enum
{
	REG,
	MEM,
	SIO,
	TP0,
}Dev;

/* states */
typedef enum
{
	OFF,
	ON,
	DED,
}State;

typedef int Word;
typedef char Byte;

typedef struct
{
	int inst;
	int arg1;
	int arg2;
	int line;
}Op;

typedef struct
{
	char *name;
	int pc;
}Label;


extern Op program[];
extern Label labels[];
extern int outfd;


/* emulator */
int mach_drd(Word dev, Word src, Word dst);
int mach_dwr(Word mode, Word arg1, Word arg2);

int mach_not(Word mode, Word arg1, Word arg2);
int mach_and(Word mode, Word arg1, Word arg2);
int mach_nor(Word mode, Word arg1, Word arg2);
int mach_xor(Word mode, Word arg1, Word arg2);

int mach_add(Word mode, Word arg1, Word arg2);
int mach_sub(Word mode, Word arg1, Word arg2);

int mach_inc(Word mode, Word arg1, Word arg2);
int mach_dec(Word mode, Word arg1, Word arg2);

int mach_mul(Word mode, Word arg1, Word arg2);
int mach_div(Word mode, Word arg1, Word arg2);

int mach_shr(Word mode, Word arg1, Word arg2);
int mach_shl(Word mode, Word arg1, Word arg2);
int mach_jmp(Word mode, Word arg1, Word arg2);

/* lint */
int lint_drd(Word mode, Word arg1, Word arg2);
int lint_dwr(Word mode, Word arg1, Word arg2);

int lint_not(Word mode, Word arg1, Word arg2);
int lint_and(Word mode, Word arg1, Word arg2);
int lint_nor(Word mode, Word arg1, Word arg2);
int lint_xor(Word mode, Word arg1, Word arg2);

int lint_add(Word mode, Word arg1, Word arg2);
int lint_sub(Word mode, Word arg1, Word arg2);

int lint_inc(Word mode, Word arg1, Word arg2);
int lint_dec(Word mode, Word arg1, Word arg2);

int lint_mul(Word mode, Word arg1, Word arg2);
int lint_div(Word mode, Word arg1, Word arg2);

int lint_shr(Word mode, Word arg1, Word arg2);
int lint_shl(Word mode, Word arg1, Word arg2);
int lint_jmp(Word mode, Word arg1, Word arg2);