
#include "debug.h"


/****************************************************************************************************/
/* Debug stuff used to display text and errors*******************************************************/
/****************************************************************************************************/

/* note : debug stuff only used if DEBUG is defined ... */

/*
 * The functions to use in your program :
 *
 * LogOut("truc=%d", (Sint32)truc)
 * ReLogOut("machin")
 * Error("bidule")
 *
 */


#ifdef DEBUG

/*
 * the DEBUG fcts; don't use as-is : see below.
 */


/* Display text in a STATUS_NB_LINE text line scrolled window starting at STATUS_INIT */
#define STATUS_INIT 13
#define STATUS_NB_LINE 15
int status_line = STATUS_INIT;

/* display error text, wait 42 frames and erase text */
void Error_internal(char* text)
{
    Uint32 wait;

    slPrint(text, slLocate(1, 10));

    for (wait=0; wait<42; wait++)
        slSynch();

    slPrint("                                        ", slLocate(0, 10));

}


void LogOut_internal(char *string, ...)
{
    va_list argptr;
    char buff[512];

    /* Print the log message to the memory. */
    va_start(argptr, string);
    vsnprintf(buff, sizeof(buff), string, argptr);
    va_end(argptr);
    buff[sizeof(buff)-1] = '\0';

    /* Send the debug message to SatCom debugger. */
    scd_logout("Debug>%s", buff);

    int i;
    slPrint("*-----------------------*", slLocate(0, STATUS_INIT - 1));
    slPrint(buff, slLocate(1, status_line));
    slPrint("*-----------------------*", slLocate(0, STATUS_INIT + STATUS_NB_LINE + 1));

    for(i=STATUS_INIT; i<=STATUS_INIT + STATUS_NB_LINE; i++)
    {
        slPrint("*", slLocate( 0, i));
        slPrint("*", slLocate(24, i));
    }

    if (status_line == STATUS_INIT + STATUS_NB_LINE)
        status_line = STATUS_INIT;
    else
        status_line++;

    slPrint(" >                      ", slLocate(0, status_line));
}




#endif

