3
"$Header: d:/cvsroot/tads/TADS2/msdos/OSDBG.C,v 1.2 1999/05/17 02:52:18 MJRoberts Exp $";
7
* Copyright (c) 1990, 2002 Michael J. Roberts. All Rights Reserved.
9
* Please see the accompanying license file, LICENSE.TXT, for information
10
* on using and copying this software.
14
osdbg - os routines for debugger
16
Implements os routines for windowing DOS debugger.
20
04/21/92 MJRoberts - creation (from tads 1.2 osgen.c)
41
* For Win32, use the console API to access the screen. Keep track of
42
* two console handles - the standard one, and the new one we create for
43
* the debugger screen. [0] is the standard handle, which we use for
44
* the game screen, and [1] is the debugger screen.
46
HANDLE G_screen_bufhdl[2];
48
/* global with current output handle - see ossdos32.c */
49
extern HANDLE G_out_bufhdl;
51
#endif /* __WIN32__ */
58
/* adjust assembler keywords */
60
# define interrupt __interrupt
64
# define interrupt _interrupt
67
# endif /* _MSC_VER >= 700 */
71
void osdbgclr(oswdef *win)
73
ossclr(win->oswy1, win->oswx1, win->oswy2, win->oswx2, win->oswcolor);
77
typedef struct pagedef
87
int osdbgini(int rows, int cols)
89
size_t size = 2 * rows * cols;
91
pages[0] = (pagedef *)malloc(size + sizeof(pagedef) - 2);
92
pages[1] = (pagedef *)malloc(size + sizeof(pagedef) - 2);
93
pages[0]->row = pages[1]->row = 0;
94
pages[0]->col = pages[1]->col = 0;
95
pages[0]->size = pages[1]->size = size;
96
memset(pages[0]->cells, 0, size);
97
memset(pages[1]->cells, 0, size);
103
int osdbgini(int rows, int cols)
106
* initialize our array of output screen buffer handles -- the first
107
* entry is the default entry, which we use for the game screen; the
108
* second entry is a new handle we create, which we use for the
111
G_screen_bufhdl[0] = G_out_bufhdl;
112
G_screen_bufhdl[1] = CreateConsoleScreenBuffer(GENERIC_WRITE, 0,
113
0, CONSOLE_TEXTMODE_BUFFER, 0);
119
#else /* __WIN32__ */
121
int osdbgini(int rows, int cols)
126
#endif /* __WIN32__ */
141
if (pg == prvpg) return(prvpg);
143
siz = (USHORT)pages[prvpg]->size;
144
VioReadCellStr(pages[prvpg]->cells, &siz, (USHORT)0, (USHORT)0, (HVIO)0);
145
VioGetCurPos(&pages[prvpg]->row, &pages[prvpg]->col, (HVIO)0);
147
VioWrtCellStr(pages[pg]->cells, (USHORT)pages[pg]->size,
148
(USHORT)0, (USHORT)0, (HVIO)0);
149
VioSetCurPos(pages[pg]->row, pages[pg]->col, (HVIO)0);
155
/* set ossdos32.c's output handle to the selected page's handle */
156
G_out_bufhdl = G_screen_bufhdl[pg];
158
/* show the selected page */
159
SetConsoleActiveScreenBuffer(G_out_bufhdl);
160
#else /* __WIN32__ */
168
mov ax, (25 * 80 * 2) + 96
175
add word ptr [scrbase], ax
179
#endif /* __WIN32__ */
185
/* scroll a window up a line */
186
static void osdbgsc(oswdef *win)
188
ossscr(win->oswy1, win->oswx1, win->oswy2, win->oswx2, win->oswcolor);
191
/* print a string in a debugger window */
192
void osdbgpt(oswdef *win, char *fmt, ...)
198
va_start(argptr, fmt);
199
vsprintf(buf, fmt, argptr);
206
if ((win->oswflg & OSWFMORE) && win->oswx == win->oswx1 &&
207
win->oswmore+1 >= win->oswy2 - win->oswy1)
212
ossdsp(win->oswy, win->oswx, win->oswcolor, "[More]");
213
ossdbgloc((char)win->oswy, (char)(win->oswx+6));
217
switch(c = os_getc())
229
if (os_getc() == CMD_EOF)
236
} while (c != ' ' && c != '\n' && c != '\r' && !eof);
238
ossdsp(win->oswy, win->oswx, win->oswcolor, " ");
241
for (p1 = p ; *p1 && *p1 != '\n' && *p1 != '\r' && *p1 != '\t'; p1++);
242
if (*p1 == '\n' || *p1 == '\r' || *p1 == '\t')
248
if ((size_t)win->oswx + strlen(p) > (size_t)win->oswx2 &&
249
(win->oswflg & OSWFCLIP))
250
p[win->oswx2 - win->oswx + 1] = '\0';
251
ossdsp(win->oswy, win->oswx, win->oswcolor, p);
256
win->oswx = win->oswx1;
257
if (win->oswy > win->oswy2)
259
win->oswy = win->oswy2;
266
win->oswx += strlen(p);
269
ossdsp(win->oswy, win->oswx, win->oswcolor, " ");
271
if (win->oswx > win->oswx2 && (win->oswflg & OSWFCLIP))
273
} while ((win->oswx - 2) & 7);
276
if (win->oswx > win->oswx2) return;
280
if ((size_t)win->oswx + strlen(p) > (size_t)win->oswx2
281
&& (win->oswflg & OSWFCLIP))
282
p[win->oswx2 - win->oswx + 1] = '\0';
283
ossdsp(win->oswy, win->oswx, win->oswcolor, p);
284
win->oswx += strlen(p);
290
/* open a window - set up location */
291
void osdbgwop(oswdef *win, int x1, int y1, int x2, int y2, int color)
293
win->oswx1 = win->oswx = x1;
295
win->oswy1 = win->oswy = y1;
297
win->oswcolor = color;
301
/* locate the cursor */
302
void ossdbgloc(char y, char x)
304
#if defined(MSOS2) || defined(__WIN32__)
314
__dpmi_int(0x10, ®s);
330
int osdbggts(oswdef *win, char *buf, int (*cmdfn)(void *, char), void *cmdctx)
334
char *eob = buf + 127;
340
for (buf[0] = '\0' ; ; )
344
ossdbgloc((char)y, (char)x);
345
switch(c = os_getc())
354
for ( q=(--p) ; q<eol ; q++ ) *q = *( q+1 );
364
for ( q=p, tmpbuf[1]='\0' ; q<=eol ; q++ )
367
ossdsp( thisy, thisx, win->oswcolor, tmpbuf );
368
if ( ++thisx > win->oswx2 )
380
* Scroll the screen to account for the carriage return,
381
* position the cursor at the end of the new line, and
382
* null-terminate the line.
388
if ( ++x > win->oswx2 )
395
if ( y == win->oswy2 ) osdbgsc(win);
398
ossdbgloc((char)y, (char)x);
401
* Finally, copy the buffer to the screen save buffer (if
402
* applicable), and return the contents of the buffer. Note
403
* that we add an extra carriage return if we were already on
404
* the last line, since we scrolled the screen in this case;
405
* otherwise, ossaddsbe will add all the blank lines that are
413
switch(c = os_getc())
436
if ( x > win->oswx2 )
448
int thisx=x, thisy=y;
450
for ( q=p ; q<eol ; q++ ) *q = *(q+1);
453
for ( q=p, tmpbuf[1]='\0' ; q<=eol ; q++ )
456
ossdsp( thisy, thisx, win->oswcolor, tmpbuf );
457
if ( ++thisx > win->oswx2 )
478
if ( c == CMD_HOME ) break;
480
* We're at the start of the line now; fall through for
481
* KILL, UP, and DOWN to the code which deletes to the
488
int thisx=x, thisy=y;
490
for ( q=p ; q<eol ; q++ )
492
ossdsp( thisy, thisx, win->oswcolor, " " );
493
if ( ++thisx > win->oswx2 )
502
if (cmd) return(cmd);
508
if ( ++x > win->oswx2 )
517
if (cmd = (*cmdfn)(cmdctx, c))
526
if ( c >= ' ' && c < 127 && eol<eob )
531
int thisy=y, thisx=x;
534
for ( q=(++eol) ; q>p ; q-- ) *q=*(q-1);
536
for ( q=p++, tmpbuf[1] = '\0' ; q<eol ; q++ )
539
ossdsp( thisy, thisx, win->oswcolor, tmpbuf );
541
if ( thisx > win->oswx2 )
544
if ( thisy == win->oswy2 )
552
if ( ++x > win->oswx2 )
563
ossdsp( y, x, win->oswcolor, p-1 );
564
if ( ++x > win->oswx2 )
567
if ( y == win->oswy2 )