Skip to content

Commit 6edb95b

Browse files
committed
ensure con_xres,con_yres multiples of font size
avoids an unwritten right/bottom edge that's not part of a complete tile this caused graphical issues and inconsistencies between Init and InitEx document in the function doxygen comment make values in __console_vipostcb only computed once ptr directly from the global equal to destbuffer, less indirection
1 parent fe29640 commit 6edb95b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

gc/ogc/console.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*
5757
* \param[in] framebuffer pointer to the framebuffer used for drawing the characters
5858
* \param[in] xstart,ystart start position of the console output in pixels
59-
* \param[in] xres,yres size of the console in pixels
59+
* \param[in] xres,yres size of the console in pixels. Truncated to a multiple of font size if not already one
6060
* \param[in] stride size of one line of the framebuffer in bytes
6161
*
6262
* \return none
@@ -69,8 +69,8 @@ void CON_Init(void *framebuffer,int xstart,int ystart,int xres,int yres,int stri
6969
* \param[in] rmode pointer to the video/render mode configuration
7070
* \param[in] conXOrigin starting pixel in X direction of the console output on the external framebuffer
7171
* \param[in] conYOrigin starting pixel in Y direction of the console output on the external framebuffer
72-
* \param[in] conWidth width of the console output 'window' to be drawn in pixels
73-
* \param[in] conHeight height of the console output 'window' to be drawn in pixels
72+
* \param[in] conWidth width of the console output 'window' to be drawn in pixels. Truncated to a multiple of font width if not already one
73+
* \param[in] conHeight height of the console output 'window' to be drawn in pixels. Truncated to a multiple of font height if not already one
7474
*
7575
* \return 0 on success, <0 on error
7676
*/

libogc/console.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,16 @@ void __console_vipostcb(u32 retraceCnt)
213213
u8 *fb,*ptr;
214214

215215
do_xfb_copy = true;
216-
ptr = currentConsole->destbuffer;
216+
ptr = _console_buffer;
217217
fb = __console_offset_by_pixels(VIDEO_GetCurrentFramebuffer(), currentConsole->target_y, currentConsole->tgt_stride, currentConsole->target_x);
218218

219+
const u32 line_count = currentConsole->con_yres;
220+
const u32 bytes_per_line = currentConsole->con_xres * VI_DISPLAY_PIX_SZ;
221+
219222
// Copies 1 line of pixels at a time
220-
for(u16 ycnt = 0; ycnt < currentConsole->con_yres; ycnt++)
223+
for(u16 ycnt = 0; ycnt < line_count; ycnt++)
221224
{
222-
memcpy(fb, ptr, currentConsole->con_xres * VI_DISPLAY_PIX_SZ);
225+
memcpy(fb, ptr, bytes_per_line);
223226
ptr += currentConsole->con_stride;
224227
fb += currentConsole->tgt_stride;
225228
}
@@ -1059,6 +1062,9 @@ ssize_t __console_write(struct _reent *r,void *fd,const char *ptr, size_t len)
10591062

10601063
void CON_Init(void *framebuffer,int xstart,int ystart,int xres,int yres,int stride)
10611064
{
1065+
// force xres, yres to be multiples of font size
1066+
xres = (xres / FONT_XSIZE) * FONT_XSIZE;
1067+
yres = (yres / FONT_YSIZE) * FONT_YSIZE;
10621068
__console_init(framebuffer,xstart,ystart,xres,yres,stride);
10631069
}
10641070

@@ -1068,6 +1074,9 @@ s32 CON_InitEx(GXRModeObj *rmode, s32 conXOrigin,s32 conYOrigin,s32 conWidth,s32
10681074
if(_console_buffer)
10691075
free(_console_buffer);
10701076

1077+
// force conWidth, conHeight to be multiples of font size
1078+
conWidth = (conWidth / FONT_XSIZE) * FONT_XSIZE;
1079+
conHeight = (conHeight / FONT_YSIZE) * FONT_YSIZE;
10711080
_console_buffer = malloc(conWidth*conHeight*VI_DISPLAY_PIX_SZ);
10721081
if(!_console_buffer) return -1;
10731082

0 commit comments

Comments
 (0)