Commit 4902e75ad893c40e39607d96d39ec5bd110b43fe
1 parent
6324b9c7
Small fixes. Register setting in debugger does now work (don't ever use inttypes on scanf)
Showing
3 changed files
with
13 additions
and
15 deletions
cpu.c
@@ -339,11 +339,7 @@ uint8_t execute_instruction(uint16_t opcode, uint16_t arg1, uint16_t arg2, uint1 | @@ -339,11 +339,7 @@ uint8_t execute_instruction(uint16_t opcode, uint16_t arg1, uint16_t arg2, uint1 | ||
339 | call(arg1); | 339 | call(arg1); |
340 | break; | 340 | break; |
341 | case RET: | 341 | case RET: |
342 | - if(ret()) | ||
343 | - { | ||
344 | - return 1; | ||
345 | - } | ||
346 | - break; | 342 | + return ret(); |
347 | case OUT: | 343 | case OUT: |
348 | out(arg1); | 344 | out(arg1); |
349 | break; | 345 | break; |
debug.c
@@ -72,18 +72,19 @@ void query() | @@ -72,18 +72,19 @@ void query() | ||
72 | { | 72 | { |
73 | //TODO discard stdin | 73 | //TODO discard stdin |
74 | uint8_t end = 0; | 74 | uint8_t end = 0; |
75 | - uint16_t bpoint; | ||
76 | - uint16_t mempos; | 75 | + unsigned int bpoint; |
76 | + unsigned int mempos; | ||
77 | char input[100] = {0}; | 77 | char input[100] = {0}; |
78 | char filename[32]; | 78 | char filename[32]; |
79 | - uint8_t reg; | ||
80 | - uint8_t value; | 79 | + unsigned int reg; |
80 | + unsigned int value; | ||
81 | while(!end) | 81 | while(!end) |
82 | { | 82 | { |
83 | printf("\n> "); | 83 | printf("\n> "); |
84 | char command = 0; | 84 | char command = 0; |
85 | fgets(input,100,stdin); | 85 | fgets(input,100,stdin); |
86 | command = input[0]; | 86 | command = input[0]; |
87 | + //FIXME: Input is not validated in any way. Crashes *will* occur on misuse. Have fun! | ||
87 | if (command != '\n') | 88 | if (command != '\n') |
88 | { | 89 | { |
89 | lastchoice = command; | 90 | lastchoice = command; |
@@ -130,7 +131,6 @@ void query() | @@ -130,7 +131,6 @@ void query() | ||
130 | fprintf(stderr,"Loaded state as %s",filename); | 131 | fprintf(stderr,"Loaded state as %s",filename); |
131 | break; | 132 | break; |
132 | case 'w': | 133 | case 'w': |
133 | - //FIXME ALREADY | ||
134 | sscanf(input,"w r%d %d\n",®,&value); | 134 | sscanf(input,"w r%d %d\n",®,&value); |
135 | fprintf(stderr,"Setting r%d = %02X",reg,value); | 135 | fprintf(stderr,"Setting r%d = %02X",reg,value); |
136 | regs[reg] = value; | 136 | regs[reg] = value; |
main.c
@@ -17,12 +17,17 @@ uint32_t load_program(const char* path) | @@ -17,12 +17,17 @@ uint32_t load_program(const char* path) | ||
17 | return file_size/2; | 17 | return file_size/2; |
18 | } | 18 | } |
19 | 19 | ||
20 | -void startvm(char *program) | 20 | +void initializevm(char *program) |
21 | { | 21 | { |
22 | initialize_stack(); | 22 | initialize_stack(); |
23 | memset(regs,0x00,sizeof(uint16_t)*NUM_REGISTERS); | 23 | memset(regs,0x00,sizeof(uint16_t)*NUM_REGISTERS); |
24 | memset(mem,0x00,sizeof(uint16_t)*MEMSIZE); | 24 | memset(mem,0x00,sizeof(uint16_t)*MEMSIZE); |
25 | load_program(program); | 25 | load_program(program); |
26 | +} | ||
27 | + | ||
28 | +void startvm(char *program) | ||
29 | +{ | ||
30 | + initializevm(program); | ||
26 | start_execution(); | 31 | start_execution(); |
27 | free_stack(); | 32 | free_stack(); |
28 | } | 33 | } |
@@ -35,10 +40,7 @@ void disasm(char *program) | @@ -35,10 +40,7 @@ void disasm(char *program) | ||
35 | 40 | ||
36 | void debug(char *program) | 41 | void debug(char *program) |
37 | { | 42 | { |
38 | - initialize_stack(); | ||
39 | - memset(regs,0x00,sizeof(uint16_t)*NUM_REGISTERS); | ||
40 | - memset(mem,0x00,sizeof(uint16_t)*MEMSIZE); | ||
41 | - load_program(program); | 43 | + initializevm(program); |
42 | debug_program(); | 44 | debug_program(); |
43 | free_stack(); | 45 | free_stack(); |
44 | } | 46 | } |