8 extern unsigned short callback_stack
[100];
9 extern int callback_stack_pos
;
19 format_label( buffer
, walk
->addr
);
27 (walk
->tstates
)/(walk
->num_calls
),
28 (int)(100*walk
->tstates
/tstates
)
34 char *get_param( char *from
, int *storein
)
38 /* Find the first real character */
39 while (isspace(*from
)&&(*from
!='\0')) {
47 /* Search till the end of the string */
48 while (!isspace(*end
)&&(*end
!='\0')) {
54 *storein
= parse_label(from
);
59 int getparams( char *string
, int *start
, int *end
, int pc
, int defoffset
)
63 if ((tmp
=get_param(&string
[1],start
))!=NULL
) {
64 if ((tmp
=get_param(tmp
, end
))!=NULL
) {
68 *end
= *start
+defoffset
;
79 void show_callback_stack(void)
84 start
= callback_stack_pos
-5;
87 for (i
=start
; i
<callback_stack_pos
; i
++) {
88 format_label( buffer
, callback_stack
[i
] );
89 printf(" %s\n", buffer
);
93 int setBreakpoint( unsigned int addr
)
98 while ((i
<5)&&(breakpoints
[i
]!=addr
)) {
105 while ((i
<5)&&(breakpoints
[i
]!=0))
108 return -1; /* Couldnt set */
110 breakpoints
[i
] = addr
;
116 void printRegisters( pmregs regs
)
118 printf("BC = %02X%02X DE = %02X%02X HL = %02X%02X\n"
119 "A = %02X F = %02X PC = %04X\n"
121 ,*regs
->b
, *regs
->c
, *regs
->d
, *regs
->e
, *regs
->h
, *regs
->l
,
122 *regs
->a
, *regs
->f
, *regs
->pc
,
127 int clearBreakpoint( unsigned int addr
)
132 while ((i
<5)&&(breakpoints
[i
]!=addr
))
140 int enterDebugger( pmregs regs
)
144 unsigned int dpc
= *regs
->pc
;
145 int debugging
, updateLine
;
148 int start
, end
, dumpCount
, i
;
154 if (flags
& DLIMITEDRUN
) {
155 printf("Error: Tried to enter the debugger in a limited length run\n");
162 offset
= disass( NULL
, ppc
, dpc
);
163 /* printf("%4X: %s\n", dpc, string );*/
169 if (fgets( string
, sizeof(string
), stdin
) == NULL
) {
174 /* Dump: d [start] [end]
175 If no end, end = start + 0x40
178 getparams( string
, &start
, &end
, dpc
, 0x10 );
180 while (start
< end
) {
182 printf("%4X: ", start
);
184 printf(" %02X", mem
[start
++]);
189 if (dumpCount
== 16) {
191 for (i
=16; i
>0; i
--) {
192 if (isprint(mem
[start
-i
])) {
193 printf("%c", mem
[start
-i
]);
209 printRegisters( regs
);
214 /* Print float in HLDE */
215 printGBfloat((int)(*regs
->h
)<<8 |*regs
->l
, (int)(*regs
->d
)<<8 | (int)(*regs
->e
) );
220 /* Execute until next line */
221 breakpoints
[0] = dpc
+ offset
;
226 /* Trace into (run one instruction) */
236 *regs
->cpuRunning
= 0;
241 if (get_param( &string
[1], &start
)==NULL
) {
242 /* List breakpoints */
243 for (end
= 1; end
<5; end
++) {
244 printf("Breakpoint %u at %04X\n", end
, breakpoints
[end
]);
248 end
= setBreakpoint(start
);
251 printf("Couldnt set breakpoint.\n");
255 printf("Cleared breakpoint %i.\n", clearBreakpoint( start
));
259 printf("Set breakpoint %u to %04X.\n", end
, start
);
267 /* Unassemble: u [start] [end]
268 If no end, end = start + 0x8
269 If no start, start = pc
271 getparams( string
, &start
, &end
, dpc
, 0x8 );
273 while (start
< end
) {
274 offset
=disass( NULL
, ppc
, start
);
281 show_callback_stack();
285 printf("unassemble u [start] [end]\n"
286 "dump range d [start] [end]\n"
290 "breakpoint b addr\n"