/*
- * dbg.c
- *
- * Ullrich von Bassewitz, 08.08.1998
- *
- */
+** dbg.c
+**
+** Ullrich von Bassewitz, 08.08.1998
+**
+*/
/*****************************************************************************/
-/* Function forwards */
+/* Function forwards */
/*****************************************************************************/
static char HelpHandler (void);
/* Forwards for other functions */
-static void DisplayPrompt (char* s);
+static void DisplayPrompt (const char* s);
static void SingleStep (char StepInto);
static void RedrawStatic (char Frame);
static void Redraw (char Frame);
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
/* Color definitions */
-#if defined(__PLUS4__) || defined(__C16__)
-# define COLOR_BORDER (BCOLOR_DARKBLUE | CATTR_LUMA6)
-# define COLOR_BACKGROUND COLOR_WHITE
-# define COLOR_TEXTHIGH COLOR_BLACK
-# define COLOR_TEXTLOW COLOR_GRAY1
-# define COLOR_FRAMEHIGH COLOR_BLACK
-# define COLOR_FRAMELOW COLOR_GRAY2
+#if defined(__C16__)
+# define COLOR_BORDER (BCOLOR_DARKBLUE | CATTR_LUMA6)
+# define COLOR_BACKGROUND COLOR_WHITE
+# define COLOR_TEXTHIGH COLOR_BLACK
+# define COLOR_TEXTLOW COLOR_GRAY1
+# define COLOR_FRAMEHIGH COLOR_BLACK
+# define COLOR_FRAMELOW COLOR_GRAY2
#else
# if defined(COLOR_GRAY3)
-# define COLOR_BORDER COLOR_BLACK
-# define COLOR_BACKGROUND COLOR_BLACK
-# define COLOR_TEXTHIGH COLOR_WHITE
-# define COLOR_TEXTLOW COLOR_GRAY3
-# define COLOR_FRAMEHIGH COLOR_WHITE
-# define COLOR_FRAMELOW COLOR_GRAY3
+# define COLOR_BORDER COLOR_BLACK
+# define COLOR_BACKGROUND COLOR_BLACK
+# define COLOR_TEXTHIGH COLOR_WHITE
+# define COLOR_TEXTLOW COLOR_GRAY3
+# define COLOR_FRAMEHIGH COLOR_WHITE
+# define COLOR_FRAMELOW COLOR_GRAY3
# else
-# if defined(__APPLE2__) || defined(__APPLE2ENH__)
-# define COLOR_BORDER COLOR_BLACK
+# if defined(__APPLE2__)
+# define COLOR_BORDER COLOR_BLACK
# define COLOR_BACKGROUND COLOR_BLACK
-# define COLOR_TEXTHIGH COLOR_BLACK
-# define COLOR_TEXTLOW COLOR_BLACK
-# define COLOR_FRAMEHIGH COLOR_BLACK
-# define COLOR_FRAMELOW COLOR_BLACK
+# define COLOR_TEXTHIGH COLOR_BLACK
+# define COLOR_TEXTLOW COLOR_BLACK
+# define COLOR_FRAMEHIGH COLOR_BLACK
+# define COLOR_FRAMELOW COLOR_BLACK
# else
-# define COLOR_BORDER COLOR_BLACK
+# define COLOR_BORDER COLOR_BLACK
# define COLOR_BACKGROUND COLOR_BLACK
-# define COLOR_TEXTHIGH COLOR_WHITE
-# define COLOR_TEXTLOW COLOR_WHITE
-# define COLOR_FRAMEHIGH COLOR_WHITE
-# define COLOR_FRAMELOW COLOR_WHITE
+# define COLOR_TEXTHIGH COLOR_WHITE
+# define COLOR_TEXTLOW COLOR_WHITE
+# define COLOR_FRAMEHIGH COLOR_WHITE
+# define COLOR_FRAMELOW COLOR_WHITE
# endif
# endif
#endif
+#ifndef COLOR_BLACK
+# define COLOR_BLACK 0
+#endif
+#ifndef COLOR_WHITE
+# define COLOR_WHITE 1
+#endif
/* Screen definitions */
#if defined(__CBM610__)
# define BIGSCREEN
-# define MAX_X 80
-# define MAX_Y 25
-# define DUMP_BYTES 16
-#elif defined(__APPLE2__) || defined(__APPLE2ENH__) || defined(__ATARI__)
+# define MAX_X 80
+# define MAX_Y 25
+# define DUMP_BYTES 16
+#elif defined(__APPLE2__) || defined(__ATARI__)
# define MAX_X 40
# define MAX_Y 24
# define DUMP_BYTES 8
#else
-# define MAX_X 40
-# define MAX_Y 25
-# define DUMP_BYTES 8
+# define MAX_X 40
+# define MAX_Y 25
+# define DUMP_BYTES 8
#endif
/* Replacement key definitions */
-#if defined(__APPLE2__)
+#ifndef CH_DEL
# define CH_DEL ('H' - 'A' + 1) /* Ctrl+H */
#endif
+/* Replacement char definitions */
+#ifndef CH_ULCORNER
+# define CH_ULCORNER '+'
+#endif
+#ifndef CH_URCORNER
+# define CH_URCORNER '+'
+#endif
+#ifndef CH_LLCORNER
+# define CH_LLCORNER '+'
+#endif
+#ifndef CH_LRCORNER
+# define CH_LRCORNER '+'
+#endif
+#ifndef CH_TTEE
+# define CH_TTEE '+'
+#endif
+#ifndef CH_LTEE
+# define CH_LTEE '+'
+#endif
+#ifndef CH_RTEE
+# define CH_RTEE '+'
+#endif
+#ifndef CH_BTEE
+# define CH_BTEE '+'
+#endif
+#ifndef CH_CROSS
+# define CH_CROSS '+'
+#endif
+
/* Defines for opcodes */
-#define OPC_BRK 0x00
-#define OPC_BPL 0x10
-#define OPC_JSR 0x20
-#define OPC_BMI 0x30
-#define OPC_RTI 0x40
-#define OPC_JMP 0x4C
-#define OPC_BVC 0x50
-#define OPC_RTS 0x60
-#define OPC_JMPIND 0x6C
-#define OPC_BVS 0x70
-#define OPC_BCC 0x90
-#define OPC_BCS 0xB0
-#define OPC_BNE 0xD0
-#define OPC_BEQ 0xF0
+#define OPC_BRK 0x00
+#define OPC_BPL 0x10
+#define OPC_JSR 0x20
+#define OPC_BMI 0x30
+#define OPC_RTI 0x40
+#define OPC_JMP 0x4C
+#define OPC_BVC 0x50
+#define OPC_RTS 0x60
+#define OPC_JMPIND 0x6C
+#define OPC_BVS 0x70
+#define OPC_BCC 0x90
+#define OPC_BCS 0xB0
+#define OPC_BNE 0xD0
+#define OPC_BEQ 0xF0
/* Register values that are used also in the assembler stuff */
-extern unsigned char DbgSP; /* Stack pointer */
-extern unsigned DbgCS; /* C stack pointer */
-extern unsigned DbgHI; /* High 16 bit of primary reg */
+extern unsigned char DbgSP; /* Stack pointer */
+extern unsigned DbgCS; /* C stack pointer */
+extern unsigned DbgHI; /* High 16 bit of primary reg */
typedef struct {
unsigned char x;
unsigned char y;
- char* text;
+ const char* text;
} TextDesc;
/* Window descriptor */
typedef struct {
- unsigned char fd_tl; /* Top left char */
- unsigned char fd_tr; /* Top right char */
- unsigned char fd_bl; /* Bottom left char */
- unsigned char fd_br; /* Bottom right char */
- unsigned char fd_x1, fd_y1; /* Upper left corner */
- unsigned char fd_x2, fd_y2; /* Lower right corner */
- unsigned char fd_width, fd_height; /* Redundant but faster */
- unsigned char fd_visible; /* Is the window currently visible? */
- char (*fd_func) (void); /* Handler function */
- unsigned char fd_textcount; /* Number of text lines to print */
- TextDesc* fd_text; /* Static text in the window */
+ unsigned char fd_tl; /* Top left char */
+ unsigned char fd_tr; /* Top right char */
+ unsigned char fd_bl; /* Bottom left char */
+ unsigned char fd_br; /* Bottom right char */
+ unsigned char fd_x1, fd_y1; /* Upper left corner */
+ unsigned char fd_x2, fd_y2; /* Lower right corner */
+ unsigned char fd_width, fd_height; /* Redundant but faster */
+ unsigned char fd_visible; /* Is the window currently visible? */
+ char (*fd_func) (void); /* Handler function */
+ unsigned char fd_textcount; /* Number of text lines to print */
+ const TextDesc* fd_text; /* Static text in the window */
} FrameDesc;
/* Texts for the windows */
-static TextDesc RegText [] = {
+static const TextDesc RegText [] = {
{ 1, 0, "PC" },
{ 1, 1, "SR" },
{ 1, 2, "A" },
{ 1, 6, "CS" },
{ 1, 7, "HI" }
};
-static TextDesc HelpText [] = {
- { 1, 0, "F1, ? Help" },
- { 1, 1, "F2, t Toggle breakpoint" },
- { 1, 2, "F3, u Run until subroutine returns" },
- { 1, 3, "F4, h Run to cursor" },
- { 1, 4, "F7, space Step into" },
- { 1, 5, "F8, enter Step over" },
- { 1, 6, "1-5 Select active window" },
- { 1, 7, "+ Page down" },
- { 1, 8, "- Page up" },
- { 1, 9, "Cursor Move up/down" },
+static const TextDesc HelpText [] = {
+ { 1, 0, "F1, ? Help" },
+ { 1, 1, "F2, t Toggle breakpoint" },
+ { 1, 2, "F3, u Run until subroutine returns" },
+ { 1, 3, "F4, h Run to cursor" },
+ { 1, 4, "F7, space Step into" },
+ { 1, 5, "F8, enter Step over" },
+ { 1, 6, "1-5 Select active window" },
+ { 1, 7, "+ Page down" },
+ { 1, 8, "- Page up" },
+ { 1, 9, "Cursor Move up/down" },
{ 1, 10, "a/z Move up/down" },
- { 1, 11, "c Continue" },
- { 1, 12, "f Follow instruction" },
- { 1, 13, "o Goto origin" },
- { 1, 14, "p Use as new PC value" },
- { 1, 15, "q Quit" },
- { 1, 16, "r Redraw screen" },
- { 1, 17, "s Skip next instruction" },
+ { 1, 11, "c Continue" },
+ { 1, 12, "f Follow instruction" },
+ { 1, 13, "o Goto origin" },
+ { 1, 14, "p Use as new PC value" },
+ { 1, 15, "q Quit" },
+ { 1, 16, "r Redraw screen" },
+ { 1, 17, "s Skip next instruction" },
};
/* Window data */
-static FrameDesc AsmFrame = {
+static const FrameDesc AsmFrame = {
CH_ULCORNER, CH_TTEE, CH_LTEE, CH_CROSS,
0, 0, MAX_X - 10, 15,
MAX_X - 11, 14,
AsmHandler,
0, 0
};
-static FrameDesc RegFrame = {
+static const FrameDesc RegFrame = {
CH_TTEE, CH_URCORNER, CH_LTEE, CH_RTEE,
MAX_X - 10, 0, MAX_X - 1, 9,
8, 8,
RegHandler,
sizeof (RegText) / sizeof (RegText [0]), RegText
};
-static FrameDesc StackFrame = {
+static const FrameDesc StackFrame = {
CH_LTEE, CH_RTEE, CH_CROSS, CH_RTEE,
MAX_X - 10, 9, MAX_X - 1, 15,
8, 5,
StackHandler,
0, 0
};
-static FrameDesc CStackFrame = {
+static const FrameDesc CStackFrame = {
CH_CROSS, CH_RTEE, CH_BTEE, CH_LRCORNER,
MAX_X - 10, 15, MAX_X - 1, MAX_Y - 1,
8, MAX_Y - 17,
CStackHandler,
0, 0
};
-static FrameDesc DumpFrame = {
+static const FrameDesc DumpFrame = {
CH_LTEE, CH_CROSS, CH_LLCORNER, CH_BTEE,
0, 15, MAX_X - 10, MAX_Y-1,
MAX_X - 11, MAX_Y - 17,
DumpHandler,
0, 0
};
-static FrameDesc HelpFrame = {
+static const FrameDesc HelpFrame = {
CH_ULCORNER, CH_URCORNER, CH_LLCORNER, CH_LRCORNER,
0, 0, MAX_X - 1, MAX_Y-1,
MAX_X - 2, MAX_Y - 2,
HelpHandler,
sizeof (HelpText) / sizeof (HelpText [0]), HelpText
};
-static FrameDesc* Frames [] = {
+static const FrameDesc* const Frames [] = {
&AsmFrame,
&RegFrame,
&StackFrame,
static int ActiveFrame = -1;
/* Window names */
-#define WIN_ASM 0
-#define WIN_REG 1
-#define WIN_STACK 2
-#define WIN_CSTACK 3
-#define WIN_DUMP 4
-#define WIN_HELP 5
+#define WIN_ASM 0
+#define WIN_REG 1
+#define WIN_STACK 2
+#define WIN_CSTACK 3
+#define WIN_DUMP 4
+#define WIN_HELP 5
/* Other window data */
-static unsigned AsmAddr; /* Start address of output */
-static unsigned DumpAddr; /* Start address of output */
-static unsigned CStackAddr; /* Start address of output */
-static unsigned char StackAddr; /* Start address of output */
+static unsigned AsmAddr; /* Start address of output */
+static unsigned DumpAddr; /* Start address of output */
+static unsigned CStackAddr; /* Start address of output */
+static unsigned char StackAddr; /* Start address of output */
/* Prompt line data */
-static char* ActivePrompt = 0; /* Last prompt line displayed */
-static char PromptColor; /* Color behind prompt */
-static char PromptLength; /* Length of current prompt string */
+static const char* ActivePrompt = 0; /* Last prompt line displayed */
+static char PromptColor; /* Color behind prompt */
+static char PromptLength; /* Length of current prompt string */
/* Values for the bk_use field of struct BreakPoint */
-#define BRK_EMPTY 0x00
-#define BRK_USER 0x01
-#define BRK_TMP 0x80
+#define BRK_EMPTY 0x00
+#define BRK_USER 0x01
+#define BRK_TMP 0x80
/* Structure describing a breakpoint */
typedef struct {
- unsigned bk_addr; /* Address, 0 if unused */
- unsigned char bk_opc; /* Opcode */
- unsigned char bk_use; /* 1 if in use, 0 otherwise */
+ unsigned bk_addr; /* Address, 0 if unused */
+ unsigned char bk_opc; /* Opcode */
+ unsigned char bk_use; /* 1 if in use, 0 otherwise */
} BreakPoint;
/* Temporary breakpoints - also accessed from the assembler source */
-#define MAX_USERBREAKS 10
+#define MAX_USERBREAKS 10
unsigned char DbgBreakCount = 0;
BreakPoint DbgBreaks [MAX_USERBREAKS+2];
/*****************************************************************************/
-/* Forwards for functions in the assembler source */
+/* Forwards for functions in the assembler source */
/*****************************************************************************/
BreakPoint* DbgIsBreak (unsigned Addr);
/* Check if there is a user breakpoint at the given address, if so, return
- * a pointer to the slot, else return 0.
- */
+** a pointer to the slot, else return 0.
+*/
/*****************************************************************************/
-/* Frame/window drawing code */
+/* Frame/window drawing code */
/*****************************************************************************/
-static void DrawFrame (register FrameDesc* F, char Active)
+static void DrawFrame (register const FrameDesc* F, char Active)
/* Draw one window frame */
{
- TextDesc* T;
+ const TextDesc* T;
unsigned char Count;
unsigned char tl, tr, bl, br;
unsigned char x1, y1, width;
/* Determine the characters for the corners, set frame color */
if (Active) {
- OldColor = textcolor (COLOR_FRAMEHIGH);
- tl = CH_ULCORNER;
- tr = CH_URCORNER;
- bl = CH_LLCORNER;
- br = CH_LRCORNER;
+ OldColor = textcolor (COLOR_FRAMEHIGH);
+ tl = CH_ULCORNER;
+ tr = CH_URCORNER;
+ bl = CH_LLCORNER;
+ br = CH_LRCORNER;
} else {
- OldColor = textcolor (COLOR_FRAMELOW);
- tl = F->fd_tl;
- tr = F->fd_tr;
- bl = F->fd_bl;
- br = F->fd_br;
+ OldColor = textcolor (COLOR_FRAMELOW);
+ tl = F->fd_tl;
+ tr = F->fd_tr;
+ bl = F->fd_bl;
+ br = F->fd_br;
}
/* Get the coordinates into locals for faster access */
cvlinexy (F->fd_x2, y1, F->fd_height);
/* If the window has static text associated, print the text */
- textcolor (COLOR_TEXTLOW);
+ (void) textcolor (COLOR_TEXTLOW);
Count = F->fd_textcount;
T = F->fd_text;
while (Count--) {
- cputsxy (x1 + T->x, y1 + T->y, T->text);
- ++T;
+ cputsxy (x1 + T->x, y1 + T->y, T->text);
+ ++T;
}
/* Set the old color */
- textcolor (OldColor);
+ (void) textcolor (OldColor);
}
/* Draw all frames */
{
unsigned char I;
- FrameDesc* F;
+ const FrameDesc* F;
/* Build the frame layout of the screen */
for (I = 0; I < sizeof (Frames) / sizeof (Frames [0]); ++I) {
- F = Frames [I];
- if (F->fd_visible) {
- DrawFrame (F, 0);
- }
+ F = Frames [I];
+ if (F->fd_visible) {
+ DrawFrame (F, 0);
+ }
}
}
/* Activate a new frame, deactivate the old one */
{
unsigned char y;
- register FrameDesc* F;
+ register const FrameDesc* F;
if (ActiveFrame != Num) {
- /* Deactivate the old one */
- if (ActiveFrame >= 0) {
- DrawFrame (Frames [ActiveFrame], 0);
- }
-
- /* Activate the new one */
- if ((ActiveFrame = Num) >= 0) {
- F = Frames [ActiveFrame];
- /* Clear the frame if requested */
- if (Clear) {
- for (y = F->fd_y1+1; y < F->fd_y2; ++y) {
- cclearxy (F->fd_x1+1, y, F->fd_width);
- }
- }
- DrawFrame (F, 1);
- }
-
- /* Redraw the current prompt line */
- DisplayPrompt (ActivePrompt);
+ /* Deactivate the old one */
+ if (ActiveFrame >= 0) {
+ DrawFrame (Frames [ActiveFrame], 0);
+ }
+
+ /* Activate the new one */
+ if ((ActiveFrame = Num) >= 0) {
+ F = Frames [ActiveFrame];
+ /* Clear the frame if requested */
+ if (Clear) {
+ for (y = F->fd_y1+1; y < F->fd_y2; ++y) {
+ cclearxy (F->fd_x1+1, y, F->fd_width);
+ }
+ }
+ DrawFrame (F, 1);
+ }
+
+ /* Redraw the current prompt line */
+ DisplayPrompt (ActivePrompt);
}
}
/*****************************************************************************/
-/* Prompt line */
+/* Prompt line */
/*****************************************************************************/
-static void DisplayPrompt (char* s)
+static void DisplayPrompt (const char* s)
/* Display a prompt */
{
unsigned char OldColor;
/* Clear the old prompt if there is one */
if (ActivePrompt) {
- textcolor (PromptColor);
- chlinexy ((MAX_X - PromptLength) / 2, MAX_Y-1, PromptLength);
+ (void) textcolor (PromptColor);
+ chlinexy ((MAX_X - PromptLength) / 2, MAX_Y-1, PromptLength);
}
/* Get the new prompt data */
PromptLength = strlen (ActivePrompt);
/* Display the new prompt */
- textcolor (COLOR_TEXTHIGH);
+ (void) textcolor (COLOR_TEXTHIGH);
cputsxy ((MAX_X - PromptLength) / 2, MAX_Y-1, ActivePrompt);
/* Restore the old color */
- textcolor (PromptColor);
+ (void) textcolor (PromptColor);
}
if (C == CH_STOP) {
return 1;
}
+#endif
+#if !defined(CH_ESC) && !defined(CH_STOP)
+ /* Avoid compiler warning about unused parameter */
+ (void) C;
#endif
return 0;
}
/* Display the new prompt */
OldColor = textcolor (COLOR_TEXTHIGH);
cputsxy (0, MAX_Y-1, Prompt);
- textcolor (COLOR_TEXTLOW);
+ (void) textcolor (COLOR_TEXTLOW);
/* Remember where we are, enable the cursor */
x1 = wherex ();
/* Get input and handle it */
i = done = 0;
do {
- c = cgetc ();
- if (isalnum (c) && i < Count) {
- Buf [i] = c;
- cputcxy (x1 + i, MAX_Y-1, c);
- ++i;
- } else if (i > 0 && c == CH_DEL) {
- --i;
- cputcxy (x1 + i, MAX_Y-1, ' ');
- gotoxy (x1 + i, MAX_Y-1);
- } else if (c == '\n') {
- Buf [i] = '\0';
- done = 1;
- } else if (IsAbortKey (c)) {
- /* Abort */
- done = 2;
- }
+ c = cgetc ();
+ if (isalnum (c) && i < Count) {
+ Buf [i] = c;
+ cputcxy (x1 + i, MAX_Y-1, c);
+ ++i;
+ } else if (i > 0 && c == CH_DEL) {
+ --i;
+ cputcxy (x1 + i, MAX_Y-1, ' ');
+ gotoxy (x1 + i, MAX_Y-1);
+ } else if (c == '\n') {
+ Buf [i] = '\0';
+ done = 1;
+ } else if (IsAbortKey (c)) {
+ /* Abort */
+ done = 2;
+ }
} while (!done);
/* Reset settings, display old prompt line */
cursor (OldCursor);
- textcolor (OldColor);
+ (void) textcolor (OldColor);
DrawFrames ();
Frame = ActiveFrame;
ActiveFrame = -1;
/* Read input from the user (4 digits max), check input */
if (Input (Prompt, Buf, sizeof (Buf)-1) && isxdigit (Buf [0])) {
- /* Check the characters and convert to hex */
- P = Buf;
- V = 0;
- while ((C = *P) && isxdigit (C)) {
- V <<= 4;
- if (isdigit (C)) {
- C -= '0';
- } else {
- C = toupper (C) - ('A' - 10);
- }
- V += C;
- ++P;
- }
-
- /* Assign the value */
- *Val = V;
-
- /* Success */
- return 1;
+ /* Check the characters and convert to hex */
+ P = Buf;
+ V = 0;
+ while ((C = *P) && isxdigit (C)) {
+ V <<= 4;
+ if (isdigit (C)) {
+ C -= '0';
+ } else {
+ C = toupper (C) - ('A' - 10);
+ }
+ V += C;
+ ++P;
+ }
+
+ /* Assign the value */
+ *Val = V;
+
+ /* Success */
+ return 1;
} else {
-static void ErrorPrompt (char* Msg)
+static void ErrorPrompt (const char* Msg)
/* Display an error message and wait for a key */
{
/* Save the current prompt */
- char* OldPrompt = ActivePrompt;
+ const char* OldPrompt = ActivePrompt;
/* Display the new one */
DisplayPrompt (Msg);
/*****************************************************************************/
-/* Breakpoint handling */
+/* Breakpoint handling */
/*****************************************************************************/
register BreakPoint* B = DbgIsBreak (Addr);
if (B) {
- /* We have a breakpoint, remove it */
- B->bk_use = BRK_EMPTY;
- --DbgBreakCount;
+ /* We have a breakpoint, remove it */
+ B->bk_use = BRK_EMPTY;
+ --DbgBreakCount;
} else {
- /* We don't have a breakpoint, set one */
- if (DbgBreakCount >= MAX_USERBREAKS) {
- ErrorPrompt ("Too many breakpoints - press a key");
- } else {
- /* Test if we can set a breakpoint at that address */
- if (!DbgIsRAM (Addr)) {
- BreakInRomError ();
- } else {
- /* Set the breakpoint */
- B = DbgGetBreakSlot ();
- B->bk_addr = Addr;
- B->bk_use = BRK_USER;
- ++DbgBreakCount;
- }
- }
+ /* We don't have a breakpoint, set one */
+ if (DbgBreakCount >= MAX_USERBREAKS) {
+ ErrorPrompt ("Too many breakpoints - press a key");
+ } else {
+ /* Test if we can set a breakpoint at that address */
+ if (!DbgIsRAM (Addr)) {
+ BreakInRomError ();
+ } else {
+ /* Set the breakpoint */
+ B = DbgGetBreakSlot ();
+ B->bk_addr = Addr;
+ B->bk_use = BRK_USER;
+ ++DbgBreakCount;
+ }
+ }
}
}
BreakPoint* B = DbgBreaks;
for (i = 0; i < MAX_USERBREAKS; ++i) {
- if (B->bk_use == BRK_TMP) {
- B->bk_use = BRK_EMPTY;
- }
- ++B;
+ if (B->bk_use == BRK_TMP) {
+ B->bk_use = BRK_EMPTY;
+ }
+ ++B;
}
}
static unsigned char DbgTmpBreaksOk (void)
/* Check if the temporary breakpoints can be set, if so, return 1, if not,
- * reset them all and return 0.
- */
+** reset them all and return 0.
+*/
{
unsigned char i;
BreakPoint* B = DbgBreaks;
for (i = 0; i < MAX_USERBREAKS; ++i) {
- if (B->bk_use == BRK_TMP && !DbgIsRAM (B->bk_addr)) {
- BreakInRomError ();
- DbgResetTmpBreaks ();
- return 0;
- }
- ++B;
+ if (B->bk_use == BRK_TMP && !DbgIsRAM (B->bk_addr)) {
+ BreakInRomError ();
+ DbgResetTmpBreaks ();
+ return 0;
+ }
+ ++B;
}
return 1;
}
/*****************************************************************************/
-/* Assembler window stuff */
+/* Assembler window stuff */
/*****************************************************************************/
static unsigned AsmBack (unsigned mem, unsigned char lines)
/* Go back in the assembler window the given number of lines (calculate
- * new start address).
- */
+** new start address).
+*/
{
unsigned cur;
unsigned adr [32];
unsigned offs = 6;
while (1) {
- in = 0;
- cur = mem - (lines * 3) - offs;
- while (1) {
- cur += DbgDisAsmLen (cur);
- adr [in] = cur;
- in = (in + 1) & 0x1F;
- if (cur >= mem) {
- if (cur == mem || offs == 12) {
- /* Found */
- return adr [(in - lines - 1) & 0x1F];
- } else {
- /* The requested address is inside an instruction, go back
- * one more byte and try again.
- */
- ++offs;
- break;
- }
- }
- }
+ in = 0;
+ cur = mem - (lines * 3) - offs;
+ while (1) {
+ cur += DbgDisAsmLen (cur);
+ adr [in] = cur;
+ in = (in + 1) & 0x1F;
+ if (cur >= mem) {
+ if (cur == mem || offs == 12) {
+ /* Found */
+ return adr [(in - lines - 1) & 0x1F];
+ } else {
+ /* The requested address is inside an instruction, go back
+ ** one more byte and try again.
+ */
+ ++offs;
+ break;
+ }
+ }
+ }
}
}
unsigned m = AsmBack (AsmAddr, 2);
for (y = AsmFrame.fd_y1+1; y < AsmFrame.fd_y2; ++y) {
- len = DbgDisAsm (m, buf, width);
- if (m == brk_pc) {
- buf [4] = '-';
- buf [5] = '>';
- }
- if (DbgIsBreak (m)) {
- buf [5] = '*';
- }
- if (m == AsmAddr) {
- revers (1);
- cputsxy (1, y, buf);
- revers (0);
- } else {
- cputsxy (1, y, buf);
- }
- m += len;
+ len = DbgDisAsm (m, buf, width);
+ if (m == brk_pc) {
+ buf [4] = '-';
+ buf [5] = '>';
+ }
+ if (DbgIsBreak (m)) {
+ buf [5] = '*';
+ }
+ if (m == AsmAddr) {
+ revers (1);
+ cputsxy (1, y, buf);
+ revers (0);
+ } else {
+ cputsxy (1, y, buf);
+ }
+ m += len;
}
return m;
}
{
switch (*(unsigned char*) AsmAddr) {
- case OPC_JMP:
- case OPC_JSR:
- AsmAddr = AsmArg16 ();
- break;
+ case OPC_JMP:
+ case OPC_JSR:
+ AsmAddr = AsmArg16 ();
+ break;
case OPC_JMPIND:
- AsmAddr = *(unsigned*)AsmArg16 ();
- break;
-
- case OPC_BPL:
- case OPC_BMI:
- case OPC_BVC:
- case OPC_BVS:
- case OPC_BCC:
- case OPC_BCS:
- case OPC_BNE:
- case OPC_BEQ:
- AsmAddr = AsmAddr + 2 + *(signed char*)(AsmAddr+1);
- break;
+ AsmAddr = *(unsigned*)AsmArg16 ();
+ break;
+
+ case OPC_BPL:
+ case OPC_BMI:
+ case OPC_BVC:
+ case OPC_BVS:
+ case OPC_BCC:
+ case OPC_BCS:
+ case OPC_BNE:
+ case OPC_BEQ:
+ AsmAddr = AsmAddr + 2 + *(signed char*)(AsmAddr+1);
+ break;
case OPC_RTS:
- AsmAddr = (*(unsigned*) (DbgSP + 0x101) + 1);
- break;
+ AsmAddr = (*(unsigned*) (DbgSP + 0x101) + 1);
+ break;
case OPC_RTI:
- AsmAddr = *(unsigned*) (DbgSP + 0x102);
- break;
+ AsmAddr = *(unsigned*) (DbgSP + 0x102);
+ break;
}
}
while (1) {
- /* Update the window contents */
- Last = UpdateAsm ();
+ /* Update the window contents */
+ Last = UpdateAsm ();
- /* Read and handle input */
- switch (c = GetKeyUpdate ()) {
+ /* Read and handle input */
+ switch (c = GetKeyUpdate ()) {
- case '+':
- AsmAddr = Last;
- break;
+ case '+':
+ AsmAddr = Last;
+ break;
- case '-':
- AsmAddr = AsmBack (AsmAddr, AsmFrame.fd_height);
- break;
+ case '-':
+ AsmAddr = AsmBack (AsmAddr, AsmFrame.fd_height);
+ break;
- case 't':
+ case 't':
#ifdef CH_F2
- case CH_F2:
+ case CH_F2:
#endif
- DbgToggleUserBreak (AsmAddr);
- break;
+ DbgToggleUserBreak (AsmAddr);
+ break;
- case 'f':
- AsmFollow ();
- break;
+ case 'f':
+ AsmFollow ();
+ break;
- case 'g':
- InputGoto (&AsmAddr);
- break;
+ case 'g':
+ InputGoto (&AsmAddr);
+ break;
- case 'o':
- AsmHome ();
- break;
+ case 'o':
+ AsmHome ();
+ break;
- case 'p':
- brk_pc = AsmAddr;
- break;
+ case 'p':
+ brk_pc = AsmAddr;
+ break;
case 'a':
#ifdef CH_CURS_UP
- case CH_CURS_UP:
+ case CH_CURS_UP:
#endif
- AsmAddr = AsmBack (AsmAddr, 1);
- break;
+ AsmAddr = AsmBack (AsmAddr, 1);
+ break;
case 'z':
#ifdef CH_CURS_DOWN
- case CH_CURS_DOWN:
+ case CH_CURS_DOWN:
#endif
- AsmAddr += DbgDisAsmLen (AsmAddr);
- break;
+ AsmAddr += DbgDisAsmLen (AsmAddr);
+ break;
- default:
- return c;
+ default:
+ return c;
- }
+ }
}
}
/*****************************************************************************/
-/* Register window stuff */
+/* Register window stuff */
/*****************************************************************************/
unsigned char y = RegFrame.fd_y1;
/* Print the register contents */
- gotoxy (x1, ++y); cputhex16 (brk_pc);
- gotoxy (x2, ++y); cputhex8 (brk_sr);
- gotoxy (x2, ++y); cputhex8 (brk_a);
- gotoxy (x2, ++y); cputhex8 (brk_x);
- gotoxy (x2, ++y); cputhex8 (brk_y);
- gotoxy (x2, ++y); cputhex8 (DbgSP);
+ gotoxy (x1, ++y); cputhex16 (brk_pc);
+ gotoxy (x2, ++y); cputhex8 (brk_sr);
+ gotoxy (x2, ++y); cputhex8 (brk_a);
+ gotoxy (x2, ++y); cputhex8 (brk_x);
+ gotoxy (x2, ++y); cputhex8 (brk_y);
+ gotoxy (x2, ++y); cputhex8 (DbgSP);
gotoxy (x1, ++y); cputhex16 (DbgCS);
- gotoxy (x1, ++y); cputhex16 (DbgHI);
+ gotoxy (x1, ++y); cputhex16 (DbgHI);
/* Not needed */
return 0;
/*****************************************************************************/
-/* Stack window stuff */
+/* Stack window stuff */
/*****************************************************************************/
unsigned char y;
for (y = StackFrame.fd_y2-1; y > StackFrame.fd_y1; --y) {
- gotoxy (x1, y);
- cputhex8 (mem);
- gotoxy (x2, y);
- cputhex8 (* (unsigned char*) (mem + 0x100));
- ++mem;
+ gotoxy (x1, y);
+ cputhex8 (mem);
+ gotoxy (x2, y);
+ cputhex8 (* (unsigned char*) (mem + 0x100));
+ ++mem;
}
return mem;
}
while (1) {
- /* Read and handle input */
- switch (c = GetKeyUpdate ()) {
+ /* Read and handle input */
+ switch (c = GetKeyUpdate ()) {
- case '+':
- StackAddr += BytesPerPage;
- break;
+ case '+':
+ StackAddr += BytesPerPage;
+ break;
- case '-':
- StackAddr -= BytesPerPage;
- break;
+ case '-':
+ StackAddr -= BytesPerPage;
+ break;
- case 'o':
- StackHome ();
- break;
+ case 'o':
+ StackHome ();
+ break;
case 'a':
#ifdef CH_CURS_UP:
- case CH_CURS_UP:
+ case CH_CURS_UP:
#endif
- --StackAddr;
- break;
+ --StackAddr;
+ break;
case 'z':
#ifdef CH_CURS_DOWN
- case CH_CURS_DOWN:
+ case CH_CURS_DOWN:
#endif
- ++StackAddr;
- break;
+ ++StackAddr;
+ break;
- default:
- return c;
+ default:
+ return c;
- }
+ }
- /* Update the window contents */
- UpdateStack ();
+ /* Update the window contents */
+ UpdateStack ();
}
}
/*****************************************************************************/
-/* C Stack window stuff */
+/* C Stack window stuff */
/*****************************************************************************/
unsigned char y;
for (y = CStackFrame.fd_y2-1; y > CStackFrame.fd_y1; --y) {
- gotoxy (x, y);
- cputhex16 (* (unsigned*)mem);
- mem += 2;
+ gotoxy (x, y);
+ cputhex16 (* (unsigned*)mem);
+ mem += 2;
}
cputsxy (CStackFrame.fd_x1+1, CStackFrame.fd_y2-1, "->");
return mem;
while (1) {
- /* Read and handle input */
- switch (c = GetKeyUpdate ()) {
+ /* Read and handle input */
+ switch (c = GetKeyUpdate ()) {
- case '+':
- CStackAddr += BytesPerPage;
- break;
+ case '+':
+ CStackAddr += BytesPerPage;
+ break;
- case '-':
- CStackAddr -= BytesPerPage;
- break;
+ case '-':
+ CStackAddr -= BytesPerPage;
+ break;
- case 'o':
- CStackHome ();
- break;
+ case 'o':
+ CStackHome ();
+ break;
case 'a':
#ifdef CH_CURS_UP
- case CH_CURS_UP:
+ case CH_CURS_UP:
#endif
- CStackAddr -= 2;
- break;
+ CStackAddr -= 2;
+ break;
case 'z':
#ifdef CH_CURS_DOWN
- case CH_CURS_DOWN:
+ case CH_CURS_DOWN:
#endif
- CStackAddr += 2;
- break;
+ CStackAddr += 2;
+ break;
- default:
- return c;
+ default:
+ return c;
- }
+ }
- /* Update the window contents */
- UpdateCStack ();
+ /* Update the window contents */
+ UpdateCStack ();
}
}
/*****************************************************************************/
-/* Dump window stuff */
+/* Dump window stuff */
/*****************************************************************************/
unsigned char* p = (unsigned char*) mem;
for (y = DumpFrame.fd_y1+1; y < DumpFrame.fd_y2; ++y) {
- cputsxy (x, y, DbgMemDump (mem, Buf, DUMP_BYTES));
- mem += DUMP_BYTES;
+ cputsxy (x, y, DbgMemDump (mem, Buf, DUMP_BYTES));
+ mem += DUMP_BYTES;
}
return mem;
}
while (1) {
- /* Read and handle input */
- switch (c = GetKeyUpdate ()) {
+ /* Read and handle input */
+ switch (c = GetKeyUpdate ()) {
- case '+':
- DumpAddr += BytesPerPage;
- break;
+ case '+':
+ DumpAddr += BytesPerPage;
+ break;
- case '-':
- DumpAddr -= BytesPerPage;
- break;
+ case '-':
+ DumpAddr -= BytesPerPage;
+ break;
- case 'g':
- InputGoto (&DumpAddr);
- break;
+ case 'g':
+ InputGoto (&DumpAddr);
+ break;
- case 'o':
- DumpHome ();
- break;
+ case 'o':
+ DumpHome ();
+ break;
case 'a':
#ifdef CH_CURS_UP
- case CH_CURS_UP:
+ case CH_CURS_UP:
#endif
- DumpAddr -= 8;
- break;
+ DumpAddr -= 8;
+ break;
case 'z':
#ifdef CH_CURS_DOWN
- case CH_CURS_DOWN:
+ case CH_CURS_DOWN:
#endif
- DumpAddr += 8;
- break;
+ DumpAddr += 8;
+ break;
- default:
- return c;
+ default:
+ return c;
- }
+ }
- /* Update the window contents */
- UpdateDump ();
+ /* Update the window contents */
+ UpdateDump ();
}
}
/*****************************************************************************/
-/* Help window stuff */
+/* Help window stuff */
/*****************************************************************************/
/*****************************************************************************/
-/* Singlestep */
+/* Singlestep */
/*****************************************************************************/
switch (*(unsigned char*) brk_pc) {
case OPC_JMP:
- /* Set breakpoint at target */
- DbgSetTmpBreak (GetArg16 ());
- return;
-
- case OPC_JMPIND:
- /* Indirect jump, ignore CPU error when crossing page */
- DbgSetTmpBreak (*(unsigned*)GetArg16 ());
- return;
-
- case OPC_BPL:
- case OPC_BMI:
- case OPC_BVC:
- case OPC_BVS:
- case OPC_BCC:
- case OPC_BCS:
- case OPC_BNE:
- case OPC_BEQ:
- /* Be sure not to set the breakpoint twice if this is a jump to
- * the following instruction.
- */
- Offs = *(signed char*)(brk_pc+1);
- if (Offs) {
- DbgSetTmpBreak (brk_pc + Offs + 2);
- }
- break;
+ /* Set breakpoint at target */
+ DbgSetTmpBreak (GetArg16 ());
+ return;
+
+ case OPC_JMPIND:
+ /* Indirect jump, ignore CPU error when crossing page */
+ DbgSetTmpBreak (*(unsigned*)GetArg16 ());
+ return;
+
+ case OPC_BPL:
+ case OPC_BMI:
+ case OPC_BVC:
+ case OPC_BVS:
+ case OPC_BCC:
+ case OPC_BCS:
+ case OPC_BNE:
+ case OPC_BEQ:
+ /* Be sure not to set the breakpoint twice if this is a jump to
+ ** the following instruction.
+ */
+ Offs = ((signed char*)brk_pc)[1];
+ if (Offs) {
+ DbgSetTmpBreak (brk_pc + Offs + 2);
+ }
+ break;
case OPC_RTS:
- /* Set a breakpoint at the return target */
- SetRTSBreak ();
- return;
+ /* Set a breakpoint at the return target */
+ SetRTSBreak ();
+ return;
case OPC_RTI:
- /* Set a breakpoint at the return target */
- DbgSetTmpBreak (GetStack16 (1));
- return;
+ /* Set a breakpoint at the return target */
+ DbgSetTmpBreak (GetStack16 (1));
+ return;
case OPC_JSR:
- if (StepInto) {
- /* Set breakpoint at target */
- DbgSetTmpBreak (GetArg16 ());
- return;
- }
- break;
+ if (StepInto) {
+ /* Set breakpoint at target */
+ DbgSetTmpBreak (GetArg16 ());
+ return;
+ }
+ break;
}
/* Place a breakpoint behind the instruction */
/*****************************************************************************/
-/* High level window handling */
+/* High level window handling */
/*****************************************************************************/
ActiveFrame = -1;
/* Clear the screen hide the cursor */
- bordercolor (COLOR_BORDER);
- bgcolor (COLOR_BACKGROUND);
+ (void) bordercolor (COLOR_BORDER);
+ (void) bgcolor (COLOR_BACKGROUND);
clrscr ();
cursor (0);
/* Build the frame layout of the screen */
- textcolor (COLOR_FRAMELOW);
+ (void) textcolor (COLOR_FRAMELOW);
DrawFrames ();
/* Draw the prompt line */
/* While there are no keys... */
while (!kbhit ()) {
- switch (Win) {
+ switch (Win) {
- case 0:
- UpdateAsm ();
- break;
+ case 0:
+ UpdateAsm ();
+ break;
- case 1:
- UpdateStack ();
- break;
+ case 1:
+ UpdateStack ();
+ break;
- case 2:
- UpdateCStack ();
- break;
+ case 2:
+ UpdateCStack ();
+ break;
- case 3:
- UpdateDump ();
- break;
- }
+ case 3:
+ UpdateDump ();
+ break;
+ }
- Win = (Win + 1) & 0x03;
+ Win = (Win + 1) & 0x03;
}
/*****************************************************************************/
-/* Externally visible functions */
+/* Externally visible functions */
/*****************************************************************************/
/* If this is the first call, setup the display */
if (FirstTime) {
- FirstTime = 0;
-
- /* Draw the window, default active frame is ASM frame */
- RedrawStatic (WIN_ASM);
- InitAsm ();
- InitReg ();
- InitStack ();
- InitCStack ();
- UpdateDump ();
+ FirstTime = 0;
+
+ /* Draw the window, default active frame is ASM frame */
+ RedrawStatic (WIN_ASM);
+ InitAsm ();
+ InitReg ();
+ InitStack ();
+ InitCStack ();
+ UpdateDump ();
}
/* Only initialize variables here, don't do a display update. The actual
- * display update will be done while waiting for user input.
- */
+ ** display update will be done while waiting for user input.
+ */
AsmHome ();
- UpdateReg (); /* Must update this (static later) */
+ UpdateReg (); /* Must update this (static later) */
StackHome ();
CStackHome ();
/* Wait for user input */
done = 0;
while (!done) {
- c = Frames [ActiveFrame]->fd_func ();
- switch (c) {
-
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- ActivateFrame (c - '1', 0);
- break;
-
- case '?':
+ c = Frames [ActiveFrame]->fd_func ();
+ switch (c) {
+
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ ActivateFrame (c - '1', 0);
+ break;
+
+ case '?':
#ifdef CH_F1
- case CH_F1:
+ case CH_F1:
#endif
- HelpHandler ();
- break;
+ HelpHandler ();
+ break;
- case 'u':
+ case 'u':
#ifdef CH_F3
- case CH_F3:
+ case CH_F3:
#endif
- /* Go until return */
- SetRTSBreak ();
- done = 1;
- break;
+ /* Go until return */
+ SetRTSBreak ();
+ done = 1;
+ break;
- case 'h':
+ case 'h':
#ifdef CH_F4
- case CH_F4:
+ case CH_F4:
#endif
- /* Go to cursor, only possible if cursor not at current PC */
- if (AsmAddr != brk_pc) {
- DbgSetTmpBreak (AsmAddr);
- done = 1;
- }
- break;
-
- case ' ':
+ /* Go to cursor, only possible if cursor not at current PC */
+ if (AsmAddr != brk_pc) {
+ DbgSetTmpBreak (AsmAddr);
+ done = 1;
+ }
+ break;
+
+ case ' ':
#ifdef CH_F7
- case CH_F7:
+ case CH_F7:
#endif
- SingleStep (1);
- if (DbgTmpBreaksOk ()) {
- /* Could set breakpoints */
- done = 1;
- }
- break;
-
- case '\n':
+ SingleStep (1);
+ if (DbgTmpBreaksOk ()) {
+ /* Could set breakpoints */
+ done = 1;
+ }
+ break;
+
+ case '\n':
#ifdef CH_F8
- case CH_F8:
+ case CH_F8:
#endif
- SingleStep (0);
- if (DbgTmpBreaksOk ()) {
- /* Could set breakpoints */
- done = 1;
- }
- break;
-
- case 'c':
- case 0:
- done = 1;
- break;
-
- case 's':
- /* Skip instruction */
- brk_pc += DbgDisAsmLen (brk_pc);
- InitAsm ();
- break;
-
- case 'r':
- /* Redraw screen */
- Redraw (ActiveFrame);
- break;
-
- case 'q':
- /* Quit program */
- clrscr ();
- exit (1);
-
- }
+ SingleStep (0);
+ if (DbgTmpBreaksOk ()) {
+ /* Could set breakpoints */
+ done = 1;
+ }
+ break;
+
+ case 'c':
+ case 0:
+ done = 1;
+ break;
+
+ case 's':
+ /* Skip instruction */
+ brk_pc += DbgDisAsmLen (brk_pc);
+ InitAsm ();
+ break;
+
+ case 'r':
+ /* Redraw screen */
+ Redraw (ActiveFrame);
+ break;
+
+ case 'q':
+ /* Quit program */
+ clrscr ();
+ exit (1);
+
+ }
}
}