#include <stdio.h>
#include <stdarg.h>
#include <string.h>

// %r3 = %r3 & 0x2000000
//void cygPut(char ch){
////	*(volatile UINT32*)0x7FEA101C = 0xae010000; // only needed once usually
//	*(volatile unsigned long*)0x7fea1014 = ch<<24;
//	while((*(volatile unsigned long*)0x7fea1018)&0x2000000){;}
//}

#ifdef __cplusplus
extern "C" {
#endif
#pragma warning(push)
#pragma warning(disable: 4100) // unreferenced formal param
#pragma warning(disable: 4996) // _s not used warning
void cygPut(char ch)
{
	__asm
	{
		lis 	r4, 0x7fea
		slwi 	r3, r3, 24
		stw 	r3, 0x1014(r4)
	1:
		lwz 	r3, 0x1018(r4)
		rlwinm. r3, r3, 0, 6, 6
		beq 	1b
	}
}

void cprintf(const char* s, ...)
{
    va_list argp;
	int i, j;
    char temp[512];
	
    va_start(argp, s);
    vsnprintf(temp, 512, s, argp);
    va_end(argp);
	j = strlen(temp);
	for(i=0; i<j; i++)
	{
		cygPut(temp[i]);
	}
}

#pragma warning(pop)

#ifdef __cplusplus
}
#endif
