From 21b0c130564ed8839b1025b61a722929b1e7fe11 Mon Sep 17 00:00:00 2001 From: lux Date: Tue, 3 Oct 2017 03:03:45 +0200 Subject: [PATCH] Improve user interface - prints an OP-Code into a humen-readable word. - Show the content of the current pointer to a memory address. - Clear shell colors to be compatible with M$-Windows. - Delete invalid path in make-file. --- makefile | 2 +- src/main.c | 18 +++++++++++------- src/toy.c | 24 ++++++++++++++++++++++++ src/toy.h | 7 +++++++ 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/makefile b/makefile index 95467d1..574eafe 100644 --- a/makefile +++ b/makefile @@ -5,7 +5,7 @@ LDFLAGs = DEBUG = -DNDEBUG -VPATH = src src/debug +VPATH = src #--------------Linker-Part----------------- toy_cpu : main.o toy.o helper.o echo $@ is now linked diff --git a/src/main.c b/src/main.c index a3ba141..2a25fd2 100644 --- a/src/main.c +++ b/src/main.c @@ -32,13 +32,16 @@ int main(int argc, char *argv[]) { 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) - + data_addr=get_data(ir); /*locate the 2nd operand + (ignord from OP_Code 8 to 15)*/ //handle user output - printf("\ninstruction: "); + printf("\ninstruction:\t"); fprintBits(sizeof(*ram), ram+pc,stdout); - printf("OP Code: %"PRIu8"\t",op_code); - printf("Adresse: %"PRIu16"\n",data_addr); + printf("OP CODE: %"PRIu8"\tmeans: ",op_code); + print_instruction(op_code); + printf("address: %"PRIu16"\tcontent:%" + PRIu16"\n",data_addr,ram[data_addr]); + printf("RAM position:\t%"PRIu16"\n",pc); printf("\ninstruction result:\n"); //CPU control flow @@ -50,8 +53,9 @@ int main(int argc, char *argv[]) //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"); + printf("PROGRAM COUNTER: %" PRIu16 + "\n-----------------------------------",pc); + printf("\n(n)ext step or (q)uit or (c)oredump ?\n"); //handle program flow while((quit = getchar()) != '\n') diff --git a/src/toy.c b/src/toy.c index b85257d..e601f6f 100644 --- a/src/toy.c +++ b/src/toy.c @@ -41,6 +41,30 @@ void print_instructionSet(void) "\tmichael.krause@uni-leipzig.de\n"); } +void print_instruction(uint8_t opcode) +{ + opcode%=16; + switch(opcode) + { + case 0: printf("STORE\n"); break; + case 1: printf("LOAD\n"); break; + case 2: printf("JMP\n"); break; + case 3: printf("ADD\n"); break; + case 4: printf("SUB\n"); break; + case 5: printf("OR\n"); break; + case 6: printf("AND\n"); break; + case 7: printf("XOR\n"); break; + case 8: printf("NOT\n"); break; + case 9: printf("INC\n"); break; + case 10: printf("DEC\n"); break; + case 11: printf("ZERO\n"); break; + case 12: printf("NOP\n"); break; + case 13: printf("NOP\n"); break; + case 14: printf("NOP\n"); break; + case 15: printf("NOP\n"); break; + } +} + int initialise_ram(uint16_t *ram, int argc, char **argv ) { diff --git a/src/toy.h b/src/toy.h index 31b3d46..f431e6f 100644 --- a/src/toy.h +++ b/src/toy.h @@ -17,6 +17,13 @@ extern const uint16_t * const ACCU; //read only access to accu void print_instructionSet(void); +/** +* print_instruction(): converts a OP-Code into a human word. +* Return: none +*/ + +void print_instruction(uint8_t opcode); + /** * initialise_ram(): reads inputstream into the toy-ram. * Return: