From 4902e75ad893c40e39607d96d39ec5bd110b43fe Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Tue, 27 Dec 2016 17:49:41 +0100 Subject: [PATCH] Small fixes. Register setting in debugger does now work (don't ever use inttypes on scanf) --- cpu.c | 6 +----- debug.c | 10 +++++----- main.c | 12 +++++++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cpu.c b/cpu.c index e07966c..535907f 100644 --- a/cpu.c +++ b/cpu.c @@ -339,11 +339,7 @@ uint8_t execute_instruction(uint16_t opcode, uint16_t arg1, uint16_t arg2, uint1 call(arg1); break; case RET: - if(ret()) - { - return 1; - } - break; + return ret(); case OUT: out(arg1); break; diff --git a/debug.c b/debug.c index 545cf12..2b0a6c9 100644 --- a/debug.c +++ b/debug.c @@ -72,18 +72,19 @@ void query() { //TODO discard stdin uint8_t end = 0; - uint16_t bpoint; - uint16_t mempos; + unsigned int bpoint; + unsigned int mempos; char input[100] = {0}; char filename[32]; - uint8_t reg; - uint8_t value; + unsigned int reg; + unsigned int value; while(!end) { printf("\n> "); char command = 0; fgets(input,100,stdin); command = input[0]; + //FIXME: Input is not validated in any way. Crashes *will* occur on misuse. Have fun! if (command != '\n') { lastchoice = command; @@ -130,7 +131,6 @@ void query() fprintf(stderr,"Loaded state as %s",filename); break; case 'w': - //FIXME ALREADY sscanf(input,"w r%d %d\n",®,&value); fprintf(stderr,"Setting r%d = %02X",reg,value); regs[reg] = value; diff --git a/main.c b/main.c index 4e93d9c..b9fd14b 100644 --- a/main.c +++ b/main.c @@ -17,12 +17,17 @@ uint32_t load_program(const char* path) return file_size/2; } -void startvm(char *program) +void initializevm(char *program) { initialize_stack(); memset(regs,0x00,sizeof(uint16_t)*NUM_REGISTERS); memset(mem,0x00,sizeof(uint16_t)*MEMSIZE); load_program(program); +} + +void startvm(char *program) +{ + initializevm(program); start_execution(); free_stack(); } @@ -35,10 +40,7 @@ void disasm(char *program) void debug(char *program) { - initialize_stack(); - memset(regs,0x00,sizeof(uint16_t)*NUM_REGISTERS); - memset(mem,0x00,sizeof(uint16_t)*MEMSIZE); - load_program(program); + initializevm(program); debug_program(); free_stack(); } -- libgit2 0.22.2