
*
	DebugPrint.c

	Package to output a text string to the second screen debugger.
*

include <stdio.h>
include <string.h>
define Syslit
define Sublit
include <CtosTypes.h>

extern erctype VidControl();

* external data used by this module *


* public data defined in this module *
static char			szContMsg[] = Press NEXT PAGE or SCROLL UP to continue;


* external procedures used by this module *

*
	debugprint

	print the passed string to the debugger screen
*

erctype debugprint(psz)
char  *psz;

{
	char		bChar;
	word		n;
	erctype		erc = 1;

	while (erc == 1)
	{
		* output string *
		erc = VidControl(19, psz);
		if (erc == 7) 
		{
			fprintf(stderr, s, psz);
			return ercOK;
		}
	
		* check for pause *	
		if (erc == 1)
		{
			for ( ; ; )
			{
				* output pause message *
				debugprint(szContMsg);

				* wait for key input to continue *
				if (ReadKbd(bChar) = 0) return 7;

				* take away pause message *
				debugprint(\0x1b\0x80);
				for (n = strlen(szContMsg); n > 0; n) debugprint(\x7F);

				* see what kind of action the key indicates *
				if (bChar == 0x0C * next page *)
				{
					debugprint(\0x1bP);
					break;
				}

				if (bChar == 0x11 * scroll up *)
				{
					debugprint(\0x1bL);
					break;
				}

				if (bChar == 0x07 * cancel *) return 1;
			}
		}
	}

	return erc;
}

*
	debugposcursor

	position the cursor to the passed location on the debugger screen, then 
	turn on or off according to flag.
*

erctype debugposcursor( x, y, fon)
word    x;
word    y;
flag    fon;

{
	char		s[9], *ps;

	ps = s;

	* setup cursor onoff *
	*ps++ = 0x1b;
	*ps++ = fon ? 'C' : 'c';

	if (x <= 79) * set x *
	{
		*ps++ = 0x1b;
		*ps++ = x + 0x80;

		* turn pause off *
		*ps++ = 0x1b;
		*ps++ = 'p';
	}

	if (y <= 28) * set y *
	{
		*ps++ = 0x1b;
		*ps++ = x + 0xD0;

		* turn pause off *
		*ps++ = 0x1b;
		*ps++ = 'p';
	}

	*ps++ = '\0';

	return debugprint(s);
}
