/********************************************************************
* Function Name: PrintfXLCD *
* Return Value: new cursor postion *
* Parameters: cursor position, format string, params... *
* Description: a wrapper function which calls vfprintf() *
* with the address of the destination buffer *
* as the output stream. EOF is returned on *
* error, else the number of characters output.*
* Output stream is then sent to the Hitachi *
* HD44780 LCD controller. *
********************************************************************/
int PrintfXLCD (char cursor, const rom char *f, ...)
{
va_list ap;
char buf[40];
char *buf2;
int n;
// Make a copy of buf pointer to send to vfprintf
buf2 = buf;
// Grab the variable parameter list
va_start (ap, f);
// vfprintf writes to a buffer when file != -1 or -2
n = vfprintf ((FILE *) &buf2, f, ap);
// De-allocate the variable parameter list
va_end (ap);
// Null terminate the string
buf[n] = '\0';
// Move LCD Output Screen Pos
while (BusyXLCD());
SetDDRamAddr(cursor);
// Write buffer
while (BusyXLCD());
putsXLCD(buf);
return n;
} /* PrintfXLCD */