implement some review comments from Klemens
This commit is contained in:
parent
8b94dd5ed0
commit
669072be49
@ -38,7 +38,7 @@ void makeHexDump(bool base_2, uint16_t ram[])
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(fp=fopen(timestamp,"wb")))
|
if(NULL==(fp=fopen(timestamp,"w")))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"File system access failed, hexdump canceled\n");
|
fprintf(stderr,"File system access failed, hexdump canceled\n");
|
||||||
return;
|
return;
|
||||||
@ -48,7 +48,8 @@ void makeHexDump(bool base_2, uint16_t ram[])
|
|||||||
for(int i=0; i<RAM_SIZE; i++) fprintBits(sizeof(uint16_t),ram+i,fp);
|
for(int i=0; i<RAM_SIZE; i++) fprintBits(sizeof(uint16_t),ram+i,fp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for(int i=1; i<=RAM_SIZE; i++) fprintf(fp,"%X\n",ram[i]);
|
{
|
||||||
|
for(int i=0; i<RAM_SIZE; i++) fprintf(fp,"%X\n",ram[i]);
|
||||||
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
11
src/main.c
11
src/main.c
@ -14,12 +14,12 @@ int main(int argc, char *argv[])
|
|||||||
uint16_t ir=0; //Instruction Register
|
uint16_t ir=0; //Instruction Register
|
||||||
uint8_t op_code; //CPU Operation Code
|
uint8_t op_code; //CPU Operation Code
|
||||||
uint16_t pc = 0; //Program Counter
|
uint16_t pc = 0; //Program Counter
|
||||||
int data_addr=0; //Adress of the 2nd operator (1. is ACCU)
|
int data_addr=0; //Adress of the 2nd operand (1. is ACCU)
|
||||||
int quit='n'; //Helper for program-flow exit (not part of CPU)
|
int quit='n'; //Helper for program-flow exit (not part of CPU)
|
||||||
bool run = true; //CPU halt and reset.(make better a coredamp befor)
|
bool run = true; //CPU halt and reset.(make better a coredamp befor)
|
||||||
|
|
||||||
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++\n+Boot: "CPU_TYPE
|
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++\n+Boot: "CPU_TYPE
|
||||||
" wite %zu x %zu Bit RAM.+\n+++++++++++++++++++++++++++++++++++++++++++++++\n\n"
|
" with %zu x %zu Bit RAM.+\n+++++++++++++++++++++++++++++++++++++++++++++++\n\n"
|
||||||
,(sizeof(ram)/sizeof(ram[0])),sizeof(ram[0])*8);
|
,(sizeof(ram)/sizeof(ram[0])),sizeof(ram[0])*8);
|
||||||
|
|
||||||
if(initialise_ram(ram,argc,argv)==-1) return 1; //load data from command line into RAM
|
if(initialise_ram(ram,argc,argv)==-1) return 1; //load data from command line into RAM
|
||||||
@ -41,9 +41,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
//CPU control flow
|
//CPU control flow
|
||||||
if(execute(op_code,data_addr,ram)) //EXECUTE instruction, jump if ALU says
|
if(execute(op_code,data_addr,ram)) //EXECUTE instruction, jump if ALU says
|
||||||
pc=find_data(ram[pc]);
|
pc=find_data(ir);
|
||||||
else pc++;
|
else pc++;
|
||||||
if(pc>4095) pc = pc % 4096; //TOY_CPU can only address 12 Bit
|
|
||||||
|
if(pc>=RAM_SIZE) pc %= RAM_SIZE; //TOY_CPU can only address 12 Bit
|
||||||
|
|
||||||
//Handele user output
|
//Handele user output
|
||||||
printf("PROGRAM COUNTER: %" PRIu16 "\n",pc);
|
printf("PROGRAM COUNTER: %" PRIu16 "\n",pc);
|
||||||
@ -57,7 +58,7 @@ int main(int argc, char *argv[])
|
|||||||
else if(quit == 'q')
|
else if(quit == 'q')
|
||||||
{
|
{
|
||||||
run = false;
|
run = false;
|
||||||
printf("\nThis is an interpreter for the Koopman_TOY_CPU by\n"
|
printf("\nThis is an interpreter for the "CPU_TYPE" by\n"
|
||||||
"\tmichael.krause@uni-leipzig.de\n\n");
|
"\tmichael.krause@uni-leipzig.de\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(fp=fopen(argv[1],"rb")))
|
if(NULL==(fp=fopen(argv[1],"r")))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s","open input stream fault !\n");
|
fprintf(stderr,"%s","open input stream fault !\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -81,6 +81,7 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
|
|||||||
if(tempS[i]!='1' && tempS[i]!='0' && i<CPU_WORD_SIZE)
|
if(tempS[i]!='1' && tempS[i]!='0' && i<CPU_WORD_SIZE)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s","input file corrupted\n");
|
fprintf(stderr,"%s","input file corrupted\n");
|
||||||
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user