Commit a0becc9532815c1024d86960f67b63bdc243b01b

Authored by Imanol-Mikel Barba Sabariego
1 parent b24f5df3

Implemented next/step

Showing 1 changed file with 24 additions and 2 deletions
... ... @@ -13,6 +13,7 @@ uint16_t breakpoints[0xFF];
13 13 uint16_t nbpoints = 0;
14 14 char lastchoice = 0;
15 15 uint8_t terminate = 0;
  16 +uint8_t break_on_next = 0;
16 17  
17 18 void to_debugger(int signal)
18 19 {
... ... @@ -112,6 +113,7 @@ void query()
112 113 end = 1;
113 114 break;
114 115 case 'n':
  116 + break_on_next = 1;
115 117 end = 1;
116 118 break;
117 119 case 'r':
... ... @@ -121,11 +123,14 @@ void query()
121 123 sscanf(input,"m %hX\n",&mempos);
122 124 fprintf(stderr,"%02X: %02x\n",mempos,mem[mempos]);
123 125 break;
124   - case 's':
125   - sscanf(input,"s %s\n",filename);
  126 + case 't':
  127 + sscanf(input,"t %s\n",filename);
126 128 save_state(filename);
127 129 fprintf(stderr,"Saved state as %s",filename);
128 130 break;
  131 + case 's':
  132 + end = 1;
  133 + break;
129 134 case 'l':
130 135 sscanf(input,"l %s\n",filename);
131 136 load_state(filename);
... ... @@ -140,6 +145,9 @@ void query()
140 145 terminate = 1;
141 146 end = 1;
142 147 break;
  148 + case 'h':
  149 + //print_debug_commands();
  150 + break;
143 151 default:
144 152 break;
145 153 }
... ... @@ -301,6 +309,7 @@ void debug_program()
301 309 }
302 310 if(breakpoint)
303 311 {
  312 + break_on_next = 0;
304 313 fprintf(stderr, "cycle: %d\n", cycle_count);
305 314 fprintf(stderr, "%02X: ", pc);
306 315 print_instruction(mem[pc], mem[pc+1], mem[pc+2], mem[pc+3]);
... ... @@ -315,6 +324,19 @@ void debug_program()
315 324 }
316 325 }
317 326 uint16_t opcode = fetch_debug();
  327 + if(opcode == CALL && break_on_next != 0)
  328 + {
  329 + breakpoint = 0;
  330 + break_on_next++;
  331 + }
  332 + else if(opcode == RET && break_on_next != 0)
  333 + {
  334 + if(--break_on_next == 1)
  335 + {
  336 + breakpoint = 1;
  337 + break_on_next = 0;
  338 + }
  339 + }
318 340 decode_instruction(opcode, &arg1, &arg2, &arg3);
319 341 if (execute_instruction(opcode, arg1, arg2, arg3))
320 342 {
... ...