kmcprintf.c 1.88 KB
#include "xstdio.h"
#include "osint.h"
/* #include "os_internal.h" */
#include "rdb.h"

#ifndef _FINALROM
static void *proutSyncPrintf(void *str, const char *buf, size_t n)
{
    size_t  sent = 0;

    while(sent < n)
    {
	sent += __osRdbSend((u8*)&buf[sent],(u32)(n-sent),(size_t)RDB_TYPE_GtoH_PRINT);
    }
    return ((void *) 1);   /* return a fake pointer so that it's not NULL */
}

volatile static unsigned *stat= (unsigned *)0xbff08004;
volatile static unsigned *wport=(unsigned *)0xbff08000;
volatile static unsigned *piok= (unsigned *)0xa4600010;

extern s32 __kmc_pt_mode;

static void rmonPutchar(char c)
{
    while((*piok & 3)!=0) ;
    while((*stat & 4)==0) ;
    *wport=(unsigned int)c;
}


static void *kmc_proutSyncPrintf(void *str, const char *buf, int n)
{
    int i;
    char c,*p,*q,xbuf[128];
    static int column = 0;

    p=xbuf;
    for(i=0;i<n;++i){
	c=*(buf++);
	switch (c) {
	case '\n':
	    *(p++)='\n';
	    column = 0;
	    break;
	case '\t':
	    do{
		*(p++)=' ';
	    }while(++column % 8);
	    break;
	default:
	    column++;
	    *(p++)=c;
	    break;
	}
	if(c=='\n' || (p-xbuf)>100){
	    rmonPutchar((char)((p-xbuf)-1));
	    q=xbuf;
	    while(q!=p){
		rmonPutchar(*(q++));
	    }
	    p=xbuf;
	}
    }
    if(p!=xbuf){
	rmonPutchar((char)((p-xbuf)-1));
	q=xbuf;
	while(q!=p){
	    rmonPutchar(*(q++));
	}
    }
    return ((void *) 1);   /* return a fake pointer so that it's not NULL */
}

#endif

static void	kmcErrorHandler(s16, s16, ...);

#include "oserr.h"
OSErrorHandler	__kmcErrorHandler = kmcErrorHandler;

static void
kmcErrorHandler(s16 code, s16 numArgs, ...)
{
#ifndef _FINALROM
	int ans;
	va_list ap;
	char * fmt;

	fmt = __os_error_message[code];

	va_start(ap, numArgs);
	if(__kmc_pt_mode){
	    ans = _Printf((void *)&kmc_proutSyncPrintf, NULL, fmt, ap);
	}
	else{
	    ans = _Printf(&proutSyncPrintf, NULL, fmt, ap);
	}
	va_end(ap);

	osSyncPrintf("\n");
#endif

}