User:CarstenK/ConsoleNotes

From WiiBrew
Jump to navigation Jump to search

The first line of the console is never displayed, it seems to be a bug in the console. This is not a matter of the TV overscan, the first line is never displayed no matter how much yoffset, you have to always printf \n at the start!?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <wiiuse/wpad.h>

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

int main(int argc, char **argv) {
	
	VIDEO_Init();
	PAD_Init();
	WPAD_Init();
	
	rmode = VIDEO_GetPreferredMode(NULL);
	
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	int xorigin=0;
	int yorigin=0;
	console_init(xfb,xorigin,yorigin,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if (rmode->viTVMode&VI_NON_INTERLACE) {
		VIDEO_WaitVSync();
	}
	s32 Err;
	int xoff = 0;
	int yoff = 16;
	Err = CON_InitEx(rmode, xoff,yoff,rmode->fbWidth-(2*xoff),rmode->xfbHeight-(2*yoff));
	if (Err) printf("\n\nErr: %d",Err);
	int cols,rows;
	CON_GetMetrics(&cols, &rows);
	printf("1\n"); /*1st line not visible? */
	printf("1-345678-1-23456789212345678-3-2345678-4-2345678-5-2345678-6-2345678-7-2345678-8");
	printf(" 2 Hello World! Press HOME to exit.    w=%4d    h=%4d\n",rmode->fbWidth,rmode->xfbHeight);
	printf(" 3                                  cols=%4d rows=%4d\n",cols,rows);

	int h;
	for (h=4;h<rows;h++) {
//		printf("%2d\n",h);
		printf("%2d 45678-1123456789212345678-312345678-412345678-512345678-612345678-7\n",h);

	}

	int dohome = 0;
	int res;
	u32 type;
	WPADData *wd;
	
	while (!dohome)
	{
		
		VIDEO_WaitVSync();
		
		WPAD_ReadPending(WPAD_CHAN_ALL, 0 /*countevs*/);
		res = WPAD_Probe(0, &type);
		if (res == WPAD_ERR_NONE) {
			wd = WPAD_Data(0);
			if (wd->btns_h & WPAD_BUTTON_HOME) {
				dohome = 1;
			}
		}
		
	}
	
	
	printf("Exiting...\n");
	 exit(0); exit to loader
	return 0;
}