change some data types for loops/array index

fix some spelling and formatting errors
This commit is contained in:
lux 2017-10-01 21:11:40 +02:00
parent 2be60bb718
commit a717499339
2 changed files with 13 additions and 12 deletions

View File

@ -17,7 +17,7 @@ int main(int argc, char *argv[])
uint16_t ir=0; //Instruction Register
uint8_t op_code; //CPU Operation Code
uint16_t pc = 0; //Program Counter
int data_addr=0; //Adress of the 2nd operand (1. is ACCU)
uint16_t data_addr=0; //Adress of the 2nd operand (1. is ACCU)
int quit='n'; //Helper for program-flow exit (not part of CPU)
bool run = true; //CPU halt and reset.(make better a coredamp befor)
@ -25,21 +25,20 @@ int main(int argc, char *argv[])
" with %zu x %zu Bit RAM.+\n+++++++++++++++++++++++++++++++++++++++++++++++\n\n"
,(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
//(-1 in case of error,
//else number of correct read worts)
if(initialise_ram(ram,argc,argv)==-1) return 1; /*load data from command line into RAM
(-1 in case of error,
else number of correct read worts)*/
while(run)
{
ir = ram[pc]; //get instruction from RAM
op_code = get_opcode(ir); //determine the instruction form
data_addr=get_data(ir); //locate the 2nd operand (ignord from OP_Code 8 to 15)
//Handele user output
//handle user output
printf("\ninstruction: ");
fprintBits(sizeof(*ram), ram+pc,stdout);
printf("OP Code: %"PRIu8"\t",op_code);
printf("Adresse: %u\n",data_addr);
printf("Adresse: %"PRIu16"\n",data_addr);
printf("\ninstruction result:\n");
//CPU control flow
@ -49,7 +48,8 @@ int main(int argc, char *argv[])
if(pc>=RAM_SIZE) pc %= RAM_SIZE; //TOY_CPU can only address 12 Bit
//Handele user output
//handle user output
printf("ACCU: %d\n",get2compl(*ACCU));
printf("PROGRAM COUNTER: %" PRIu16 "\n",pc);
printf("\x1b[32m \n(n)ext step or (q)uit or (c)oredump ?\n \x1b[0m");

View File

@ -46,10 +46,11 @@ int initialise_ram(uint16_t *ram, int argc, char **argv )
//open and check the input stream
FILE *fp;
int j=0,int_cache=0;
int int_cache=0;
size_t j=0;
char tempS[CPU_WORD_SIZE+1]; //+1 for "\0
for(int i=0;i<RAM_SIZE;i++) ram[i]=0; //initialize the toy-RAM with NULL
for(size_t i=0;i<RAM_SIZE;i++) ram[i]=0; //initialize the toy-RAM with NULL
if(argc<2)
{