diff --git a/cpu.c b/cpu.c index 535907f..5ad1161 100644 --- a/cpu.c +++ b/cpu.c @@ -50,7 +50,7 @@ void teq(uint16_t dst, uint16_t a, uint16_t b) { b = regs[b % (MAX_INT+1)]; } - regs[dst % (MAX_INT+1)] = (a == b); + regs[dst % (MAX_INT+1)] = (uint16_t)(a == b); } void tgt(uint16_t dst, uint16_t a, uint16_t b) @@ -63,7 +63,7 @@ void tgt(uint16_t dst, uint16_t a, uint16_t b) { b = regs[b % (MAX_INT+1)]; } - regs[dst % (MAX_INT+1)] = (a > b); + regs[dst % (MAX_INT+1)] = (uint16_t)(a > b); } void jmp(uint16_t dst) @@ -112,7 +112,7 @@ void add(uint16_t dst, uint16_t a, uint16_t b) { b = regs[b % (MAX_INT+1)]; } - regs[dst % (MAX_INT+1)] = (a + b) % (MAX_INT+1); + regs[dst % (MAX_INT+1)] = (uint16_t)((a + b) % (MAX_INT+1)); } void mul(uint16_t dst, uint16_t a, uint16_t b) @@ -125,7 +125,7 @@ void mul(uint16_t dst, uint16_t a, uint16_t b) { b = regs[b % (MAX_INT+1)]; } - regs[dst % (MAX_INT+1)] = (a * b) % (MAX_INT+1); + regs[dst % (MAX_INT+1)] = (uint16_t)((a * b) % (MAX_INT+1)); } void mod(uint16_t dst, uint16_t a, uint16_t b) @@ -173,7 +173,7 @@ void not(uint16_t dst, uint16_t src) { src = regs[src % (MAX_INT+1)]; } - regs[dst % (MAX_INT+1)] = ~src & 0x7FFF; + regs[dst % (MAX_INT+1)] = (uint16_t)(~src & 0x7FFF); } void load(uint16_t dst, uint16_t src) diff --git a/debug.c b/debug.c index ee9a64d..a1d7aa7 100644 --- a/debug.c +++ b/debug.c @@ -30,7 +30,8 @@ void load_state(char *filename) uint16_t regsdump[NUM_REGISTERS+1]; uint16_t memdump[MEMSIZE]; uint16_t *stackdump; - uint32_t stacksize, stackpos; + uint32_t stacksize; + long stackpos; fread(regsdump,sizeof(uint16_t),NUM_REGISTERS+1,state); fread(memdump,sizeof(uint16_t),MEMSIZE,state); @@ -99,7 +100,7 @@ void query() sscanf(input,"b %hu\n",&bpoint); fprintf(stderr,"Set breakpoint %hu to %hu",nbpoints,bpoint); breakpoints[nbpoints] = bpoint; - nbpoints = nbpoints + 1 % 0xFF; + nbpoints = (uint16_t)(nbpoints + 1 % 0xFF); break; case 'd': sscanf(input,"d %hu\n",&bpoint); diff --git a/main.c b/main.c index b9fd14b..21f9876 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,6 @@ #include "mem.h" #include "stack.h" #include "disasm.h" -#include "debug.h" uint32_t load_program(const char* path) { @@ -14,7 +13,7 @@ uint32_t load_program(const char* path) rewind(fp); fread(mem,1,(size_t)file_size,fp); fclose(fp); - return file_size/2; + return (uint32_t)file_size/2; } void initializevm(char *program) @@ -51,8 +50,8 @@ int main(int argc, char** argv) uint8_t disasm_flag = 0; uint8_t err = 0; char c; - char *program; - while ((c = getopt(argc, argv, "s:d:")) != -1) + char *program = NULL; + while ((c = (char)getopt(argc, argv, "s:d:")) != -1) { switch(c) { @@ -65,6 +64,7 @@ int main(int argc, char** argv) program = optarg; break; case '?': + default: err = 1; break; } diff --git a/stack.c b/stack.c index 1c62189..776c07f 100644 --- a/stack.c +++ b/stack.c @@ -9,7 +9,7 @@ uint8_t STACK_FAULT = 0; uint32_t stack_size = EXTEND_SIZE; -uint32_t stack_pos = -1; +uint32_t stack_pos = 0xFFFF; uint32_t stack_elems = 0; uint16_t *stack; @@ -64,7 +64,7 @@ uint16_t stack_pop() if(!stack_elems) { STACK_FAULT = 1; - return -1; + return 0xFFFF; } uint16_t value = stack[stack_pos--]; if(stack_size - --stack_elems == 2*EXTEND_SIZE)