Commit 4902e75ad893c40e39607d96d39ec5bd110b43fe

Authored by Imanol-Mikel Barba Sabariego
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
... ... @@ -339,11 +339,7 @@ uint8_t execute_instruction(uint16_t opcode, uint16_t arg1, uint16_t arg2, uint1
339 339 call(arg1);
340 340 break;
341 341 case RET:
342   - if(ret())
343   - {
344   - return 1;
345   - }
346   - break;
  342 + return ret();
347 343 case OUT:
348 344 out(arg1);
349 345 break;
... ...
... ... @@ -72,18 +72,19 @@ void query()
72 72 {
73 73 //TODO discard stdin
74 74 uint8_t end = 0;
75   - uint16_t bpoint;
76   - uint16_t mempos;
  75 + unsigned int bpoint;
  76 + unsigned int mempos;
77 77 char input[100] = {0};
78 78 char filename[32];
79   - uint8_t reg;
80   - uint8_t value;
  79 + unsigned int reg;
  80 + unsigned int value;
81 81 while(!end)
82 82 {
83 83 printf("\n> ");
84 84 char command = 0;
85 85 fgets(input,100,stdin);
86 86 command = input[0];
  87 + //FIXME: Input is not validated in any way. Crashes *will* occur on misuse. Have fun!
87 88 if (command != '\n')
88 89 {
89 90 lastchoice = command;
... ... @@ -130,7 +131,6 @@ void query()
130 131 fprintf(stderr,"Loaded state as %s",filename);
131 132 break;
132 133 case 'w':
133   - //FIXME ALREADY
134 134 sscanf(input,"w r%d %d\n",&reg,&value);
135 135 fprintf(stderr,"Setting r%d = %02X",reg,value);
136 136 regs[reg] = value;
... ...
... ... @@ -17,12 +17,17 @@ uint32_t load_program(const char* path)
17 17 return file_size/2;
18 18 }
19 19  
20   -void startvm(char *program)
  20 +void initializevm(char *program)
21 21 {
22 22 initialize_stack();
23 23 memset(regs,0x00,sizeof(uint16_t)*NUM_REGISTERS);
24 24 memset(mem,0x00,sizeof(uint16_t)*MEMSIZE);
25 25 load_program(program);
  26 +}
  27 +
  28 +void startvm(char *program)
  29 +{
  30 + initializevm(program);
26 31 start_execution();
27 32 free_stack();
28 33 }
... ... @@ -35,10 +40,7 @@ void disasm(char *program)
35 40  
36 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 44 debug_program();
43 45 free_stack();
44 46 }
... ...