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