Commit 746fe14d7546e5486bbb125293eb9efcc2837512
1 parent
eb337364
Now printing in HEX like god intended to. Also printing character in OUT instructions
Showing
3 changed files
with
47 additions
and
35 deletions
debug.c
@@ -161,7 +161,7 @@ void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg | @@ -161,7 +161,7 @@ void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg | ||
161 | } | 161 | } |
162 | else | 162 | else |
163 | { | 163 | { |
164 | - sprintf(arg1,"%d",a1); | 164 | + sprintf(arg1,"%02X",a1); |
165 | } | 165 | } |
166 | 166 | ||
167 | if(a2 > MAX_INT) | 167 | if(a2 > MAX_INT) |
@@ -170,7 +170,7 @@ void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg | @@ -170,7 +170,7 @@ void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg | ||
170 | } | 170 | } |
171 | else | 171 | else |
172 | { | 172 | { |
173 | - sprintf(arg2,"%d",a2); | 173 | + sprintf(arg2,"%02X",a2); |
174 | } | 174 | } |
175 | 175 | ||
176 | if(a3 > MAX_INT) | 176 | if(a3 > MAX_INT) |
@@ -179,7 +179,7 @@ void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg | @@ -179,7 +179,7 @@ void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg | ||
179 | } | 179 | } |
180 | else | 180 | else |
181 | { | 181 | { |
182 | - sprintf(arg3,"%d",a3); | 182 | + sprintf(arg3,"%02X",a3); |
183 | } | 183 | } |
184 | 184 | ||
185 | } | 185 | } |
@@ -193,64 +193,71 @@ void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3) | @@ -193,64 +193,71 @@ void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3) | ||
193 | switch(opcode) | 193 | switch(opcode) |
194 | { | 194 | { |
195 | case HALT: | 195 | case HALT: |
196 | - fprintf(stderr,"HALT\n"); | 196 | + fprintf(stderr, "HALT\n"); |
197 | break; | 197 | break; |
198 | case MOV: | 198 | case MOV: |
199 | - fprintf(stderr,"MOV %s %s\n",arg1,arg2); | 199 | + fprintf(stderr, "MOV %s %s\n", arg1, arg2); |
200 | break; | 200 | break; |
201 | case PUSH: | 201 | case PUSH: |
202 | - fprintf(stderr,"PUSH %s\n",arg1); | 202 | + fprintf(stderr, "PUSH %s\n", arg1); |
203 | break; | 203 | break; |
204 | case POP: | 204 | case POP: |
205 | - fprintf(stderr,"POP %s\n",arg1); | 205 | + fprintf(stderr, "POP %s\n", arg1); |
206 | break; | 206 | break; |
207 | case TEQ: | 207 | case TEQ: |
208 | - fprintf(stderr,"TEQ %s %s %s\n",arg1,arg2,arg3); | 208 | + fprintf(stderr, "TEQ %s %s %s\n", arg1, arg2, arg3); |
209 | break; | 209 | break; |
210 | case TGT: | 210 | case TGT: |
211 | - fprintf(stderr,"TGT %s %s %s\n",arg1,arg2,arg3); | 211 | + fprintf(stderr, "TGT %s %s %s\n", arg1, arg2, arg3); |
212 | break; | 212 | break; |
213 | case JMP: | 213 | case JMP: |
214 | - fprintf(stderr,"JMP %s\n",arg1); | 214 | + fprintf(stderr, "JMP %s\n", arg1); |
215 | break; | 215 | break; |
216 | case JNZ: | 216 | case JNZ: |
217 | - fprintf(stderr,"JNZ %s %s\n",arg1,arg2); | 217 | + fprintf(stderr, "JNZ %s %s\n", arg1, arg2); |
218 | break; | 218 | break; |
219 | case JZ: | 219 | case JZ: |
220 | - fprintf(stderr,"JZ %s %s\n",arg1,arg2); | 220 | + fprintf(stderr, "JZ %s %s\n", arg1, arg2); |
221 | break; | 221 | break; |
222 | case ADD: | 222 | case ADD: |
223 | - fprintf(stderr,"ADD %s %s %s\n",arg1,arg2,arg3); | 223 | + fprintf(stderr, "ADD %s %s %s\n", arg1, arg2, arg3); |
224 | break; | 224 | break; |
225 | case MUL: | 225 | case MUL: |
226 | - fprintf(stderr,"MUL %s %s %s\n",arg1,arg2,arg3); | 226 | + fprintf(stderr, "MUL %s %s %s\n", arg1, arg2, arg3); |
227 | break; | 227 | break; |
228 | case MOD: | 228 | case MOD: |
229 | - fprintf(stderr,"MOD %s %s %s\n",arg1,arg2,arg3); | 229 | + fprintf(stderr, "MOD %s %s %s\n", arg1, arg2, arg3); |
230 | break; | 230 | break; |
231 | case AND: | 231 | case AND: |
232 | - fprintf(stderr,"AND %s %s %s\n",arg1,arg2,arg3); | 232 | + fprintf(stderr, "AND %s %s %s\n", arg1, arg2, arg3); |
233 | break; | 233 | break; |
234 | case OR: | 234 | case OR: |
235 | - fprintf(stderr,"OR %s %s %s\n",arg1,arg2,arg3); | 235 | + fprintf(stderr, "OR %s %s %s\n", arg1, arg2, arg3); |
236 | break; | 236 | break; |
237 | case NOT: | 237 | case NOT: |
238 | - fprintf(stderr,"NOT %s %s\n",arg1,arg2); | 238 | + fprintf(stderr, "NOT %s %s\n", arg1, arg2); |
239 | break; | 239 | break; |
240 | case LOAD: | 240 | case LOAD: |
241 | - fprintf(stderr,"LOAD %s %s\n",arg1,arg2); | 241 | + fprintf(stderr, "LOAD %s %s\n", arg1, arg2); |
242 | break; | 242 | break; |
243 | case STOR: | 243 | case STOR: |
244 | - fprintf(stderr,"STOR %s %s\n",arg1,arg2); | 244 | + fprintf(stderr, "STOR %s %s\n", arg1, arg2); |
245 | break; | 245 | break; |
246 | case CALL: | 246 | case CALL: |
247 | - fprintf(stderr,"CALL %s\n",arg1); | 247 | + fprintf(stderr, "CALL %s\n", arg1); |
248 | break; | 248 | break; |
249 | case RET: | 249 | case RET: |
250 | - fprintf(stderr,"RET\n"); | 250 | + fprintf(stderr, "RET\n"); |
251 | break; | 251 | break; |
252 | case OUT: | 252 | case OUT: |
253 | - fprintf(stderr,"OUT %s\n",arg1); | 253 | + if (a1 <= MAX_INT) |
254 | + { | ||
255 | + fprintf(stderr, "OUT '%c'\n",a1); | ||
256 | + } | ||
257 | + else | ||
258 | + { | ||
259 | + fprintf(stderr, "OUT %s\n", arg1); | ||
260 | + } | ||
254 | break; | 261 | break; |
255 | case IN: | 262 | case IN: |
256 | fprintf(stderr,"IN %s\n",arg1); | 263 | fprintf(stderr,"IN %s\n",arg1); |
@@ -259,7 +266,7 @@ void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3) | @@ -259,7 +266,7 @@ void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3) | ||
259 | fprintf(stderr,"NOP\n"); | 266 | fprintf(stderr,"NOP\n"); |
260 | break; | 267 | break; |
261 | default: | 268 | default: |
262 | - fprintf(stderr,"UNK %d\n", opcode); | 269 | + fprintf(stderr,"UNK %02X\n", opcode); |
263 | break; | 270 | break; |
264 | } | 271 | } |
265 | } | 272 | } |
@@ -273,10 +280,15 @@ void debug_program() | @@ -273,10 +280,15 @@ void debug_program() | ||
273 | uint16_t arg3; | 280 | uint16_t arg3; |
274 | for(;;) | 281 | for(;;) |
275 | { | 282 | { |
283 | + if(in_breakpoint(pc)) | ||
284 | + { | ||
285 | + breakpoint = 1; | ||
286 | + fprintf(stderr,"Breakpoint hit @ pc=%02X",pc); | ||
287 | + } | ||
276 | if(in_breakpoint(pc) || breakpoint) | 288 | if(in_breakpoint(pc) || breakpoint) |
277 | { | 289 | { |
278 | breakpoint = 1; | 290 | breakpoint = 1; |
279 | - fprintf(stderr, "%d: ", pc); | 291 | + fprintf(stderr, "%02X: ", pc); |
280 | print_instruction(mem[pc], mem[pc+1], mem[pc+2], mem[pc+3]); | 292 | print_instruction(mem[pc], mem[pc+1], mem[pc+2], mem[pc+3]); |
281 | query(); | 293 | query(); |
282 | } | 294 | } |
disasm.c
@@ -11,7 +11,7 @@ void disassemble_program(uint32_t length) | @@ -11,7 +11,7 @@ void disassemble_program(uint32_t length) | ||
11 | { | 11 | { |
12 | break; | 12 | break; |
13 | } | 13 | } |
14 | - fprintf(stderr,"%d: ",pc); | 14 | + fprintf(stderr,"%02X: ",pc); |
15 | uint16_t opcode = fetch(); | 15 | uint16_t opcode = fetch(); |
16 | decode_instruction(opcode,&arg1,&arg2,&arg3); | 16 | decode_instruction(opcode,&arg1,&arg2,&arg3); |
17 | print_instruction(opcode,arg1,arg2,arg3); | 17 | print_instruction(opcode,arg1,arg2,arg3); |
registers.c
@@ -11,15 +11,15 @@ uint16_t pc = 0; | @@ -11,15 +11,15 @@ uint16_t pc = 0; | ||
11 | 11 | ||
12 | void print_regs() | 12 | void print_regs() |
13 | { | 13 | { |
14 | - fprintf(stderr,"r0: %2x\n",regs[0]); | ||
15 | - fprintf(stderr,"r1: %2x\n",regs[1]); | ||
16 | - fprintf(stderr,"r2: %2x\n",regs[2]); | ||
17 | - fprintf(stderr,"r3: %2x\n",regs[3]); | ||
18 | - fprintf(stderr,"r4: %2x\n",regs[4]); | ||
19 | - fprintf(stderr,"r5: %2x\n",regs[5]); | ||
20 | - fprintf(stderr,"r6: %2x\n",regs[6]); | ||
21 | - fprintf(stderr,"r7: %2x\n",regs[7]); | ||
22 | - fprintf(stderr,"pc: %2x\n",pc); | 14 | + fprintf(stderr,"r0: %02X\n",regs[0]); |
15 | + fprintf(stderr,"r1: %02X\n",regs[1]); | ||
16 | + fprintf(stderr,"r2: %02X\n",regs[2]); | ||
17 | + fprintf(stderr,"r3: %02X\n",regs[3]); | ||
18 | + fprintf(stderr,"r4: %02X\n",regs[4]); | ||
19 | + fprintf(stderr,"r5: %02X\n",regs[5]); | ||
20 | + fprintf(stderr,"r6: %02X\n",regs[6]); | ||
21 | + fprintf(stderr,"r7: %02X\n",regs[7]); | ||
22 | + fprintf(stderr,"pc: %02X\n",pc); | ||
23 | } | 23 | } |
24 | 24 | ||
25 | void dump_regs(uint16_t *dump) | 25 | void dump_regs(uint16_t *dump) |