+/*
+* Computer-m
+* by tacyas
+*/
+
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include "./computer-m.h"
Computer_m comp;
argCheck(&comp, argc, argv);
+
+ comm_Read(&comp, 0);
+ comm_Exec(&comp, 0);
+
+ return 0;
}
int
argCheck(Computer_m* comp, int argc, char* argv[])
{
int result;
- while((result=getopt(argc, argv, "hi:o:p:c:"))!=-1) {
+ while((result=getopt(argc, argv, "hi:o:p:l:"))!=-1) {
switch(result) {
case 'h':
usage(stderr);
break;
- case 'i':
- case 'o':
- case 'p':
- case 'c':
- fprintf(stderr, "%c %s\n", result, optarg);
+ case 'i': {
+ comp->inputDevice = fopen(optarg, "r");
+ if(NULL!=comp->inputDevice) {
+ fprintf(stderr, "Cannot open as inputDevice: %s\n", optarg);
+ usage(stderr);
+ }
+ break;
+ }
+ case 'o': {
+ comp->outputDevice = fopen(optarg, "a");
+ if(NULL!=comp->outputDevice) {
+ fprintf(stderr, "Cannot open as outputDevice: %s\n", optarg);
+ usage(stderr);
+ }
+ break;
+ }
+ case 'p': {
+ comp->programList = fopen(optarg, "r");
+ if(NULL!=comp->programList) {
+ fprintf(stderr, "Cannot open as programList: %s\n", optarg);
+ usage(stderr);
+ }
break;
+ }
+ case 'l': {
+ comp->logDevice = fopen(optarg, "a");
+ if(NULL!=comp->logDevice) {
+ fprintf(stderr, "Cannot open as logDevice: %s\n", optarg);
+ usage(stderr);
+ }
+ break;
+ }
case ':':
fprintf(stderr, "%c needs value\n", result);
break;
break;
}
}
-
+ return 0;
}
int
usage(FILE* fpt)
{
- fprintf(stderr, "-i filename or stdin\n");
- fprintf(stderr, "-o filename or stdout\n");
- fprintf(stderr, "-p filename \n");
+ fprintf(fpt, "-i inputFilename(RSEND) or stdin \n");
+ fprintf(fpt, "-o outputFilename(ASEND) or stdout \n");
+ fprintf(fpt, "-p program-data-List\n");
+ fprintf(fpt, "-l logfile or stderr \n");
+
+ fprintf(fpt, ">>>> program-data-list Format\n");
+ fprintf(fpt, "PC: InitPC\n");
+ fprintf(fpt, "CCR: InitCCR\n");
+ fprintf(fpt, "[ReadyQueue: program-ID0 PC0 IR0 CCR0]\n");
+ fprintf(fpt, "[....]\n");
+ fprintf(fpt, "ID: program-ID0\n");
+ fprintf(fpt, "MMU: Address Instruction_Or_Data\n");
+ fprintf(fpt, "MMU: ....\n");
+ fprintf(fpt, "[ID: program-ID1]\n");
+ fprintf(fpt, "[MMU: ....]\n");
+
+ exit(EXIT_FAILURE);
+ return 0;
}
+
#ifndef COMPUTER_M_H
#define COMPUTER_M_H
+/*
+ computer-m
+*/
+
#include <stdio.h>
#define MAX_INSTRUCTION (512)
typedef enum __Computer_m_Instruction {
CmI_ADD=0,
CmI_SUB=1,
- CmI_GT =2,
- CmI_EQUAL=3,
- CmI_JUMP=4,
- CmI_JOT=5,
- CmI_JOF=6,
- CmI_HALT=7
+ CmI_MUL=2,
+ CmI_DIV=3,
+ CmI_MOV=4,
+ CmI_EQUAL=5,
+ CmI_GT =6,
+ CmI_GE =7,
+ CmI_JUMP=8,
+ CmI_JOT=9,
+ CmI_JOF=10,
+ CmI_HALT=11,
+ CmI_SEND=12,
+ CmI_RSEND=13,
+ CmI_ASEND=14,
+ CmI_REC=15,
+ CmI_RREC=16,
+ CmI_AREC=17
} Computer_m_Instruction;
typedef struct __Computer_m_CPU {
typedef char* Computer_m_CELL;
typedef struct __Computer_m_MMU {
- char Cell[MEMSIZE];
+ char* Cell[MEMSIZE];
} Computer_m_MMU;
typedef struct __Computer_m {
FILE* inputDevice;
FILE* outputDevice;
+ FILE* programList;
+ FILE* logDevice;
Computer_m_CPU CPU;
Computer_m_MMU MMU;
} Computer_m;
+extern void comm_Read(Computer_m* comp, int mode);
+extern void comm_Exec(Computer_m* comp, int mode);
+
#endif