Skip to content

Commit ebc1f32

Browse files
committed
CON_Init: truncate console to fit framebuffer, clear framebuffer to black
1 parent 2c1b6df commit ebc1f32

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

libogc/console.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,25 @@ ssize_t __console_write(struct _reent *r,void *fd,const char *ptr, size_t len)
10721072

10731073
void CON_Init(void *framebuffer,int xstart,int ystart,int xres,int yres,int stride)
10741074
{
1075+
1076+
// clear given framebuffer to black
1077+
u32 *ptr = (u32*)framebuffer;
1078+
1079+
for(int i=0; i<yres*stride/4; i++) {
1080+
ptr[i] = colorTable[0];
1081+
}
1082+
1083+
// xstart and ystart are offsets within the provided framebuffer
1084+
// reduce xres and yres accordingly to prevent OOB writes
1085+
xres = xres - xstart;
1086+
yres = yres - ystart;
1087+
10751088
// force xres, yres to be multiples of font size
10761089
xres = (xres / FONT_XSIZE) * FONT_XSIZE;
10771090
yres = (yres / FONT_YSIZE) * FONT_YSIZE;
10781091
__console_init(framebuffer,xstart,ystart,xres,yres,stride);
1092+
1093+
10791094
}
10801095

10811096
s32 CON_InitEx(GXRModeObj *rmode, s32 conXOrigin,s32 conYOrigin,s32 conWidth,s32 conHeight)

0 commit comments

Comments
 (0)