Skip to content

Commit 49162d1

Browse files
authored
Console: improvements by porting code from libctru (#220)
* console improvements ported from libctru : extends ansi escape code support and allows codes to be spread across multiple prints * console: implement 90 - 97 (bright fg) and 100 - 107 (bright bg) * prefer console.h to consol.h * simplify console init * provide defines for base console colors
1 parent e85d412 commit 49162d1

File tree

4 files changed

+849
-418
lines changed

4 files changed

+849
-418
lines changed

gc/ogc/consol.h

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1 @@
1-
#ifndef __CONSOL_H__
2-
#define __CONSOL_H__
3-
4-
/*!
5-
* \file consol.h
6-
* \brief Console subsystem
7-
*
8-
*/
9-
10-
#include "gx_struct.h"
11-
12-
/* macros to support old function names */
13-
#define console_init CON_Init
14-
#define SYS_ConsoleInit CON_InitEx
15-
16-
#ifdef __cplusplus
17-
extern "C" {
18-
#endif
19-
20-
/*!
21-
* \fn CON_Init(void *framebuffer,int xstart,int ystart,int xres,int yres,int stride)
22-
* \brief Initializes the console subsystem with given parameters
23-
*
24-
* \param[in] framebuffer pointer to the framebuffer used for drawing the characters
25-
* \param[in] xstart,ystart start position of the console output in pixel
26-
* \param[in] xres,yres size of the console in pixel
27-
* \param[in] stride size of one line of the framebuffer in bytes
28-
*
29-
* \return none
30-
*/
31-
void CON_Init(void *framebuffer,int xstart,int ystart,int xres,int yres,int stride);
32-
33-
/*!
34-
* \fn s32 CON_InitEx(GXRModeObj *rmode, s32 conXOrigin,s32 conYOrigin,s32 conWidth,s32 conHeight)
35-
* \brief Initialize stdout console
36-
* \param[in] rmode pointer to the video/render mode configuration
37-
* \param[in] conXOrigin starting pixel in X direction of the console output on the external framebuffer
38-
* \param[in] conYOrigin starting pixel in Y direction of the console output on the external framebuffer
39-
* \param[in] conWidth width of the console output 'window' to be drawn
40-
* \param[in] conHeight height of the console output 'window' to be drawn
41-
*
42-
* \return 0 on success, <0 on error
43-
*/
44-
s32 CON_InitEx(GXRModeObj *rmode, s32 conXOrigin,s32 conYOrigin,s32 conWidth,s32 conHeight);
45-
46-
/*!
47-
* \fn CON_GetMetrics(int *cols, int *rows)
48-
* \brief retrieve the columns and rows of the current console
49-
*
50-
* \param[out] cols,rows number of columns and rows of the current console
51-
*
52-
* \return none
53-
*/
54-
void CON_GetMetrics(int *cols, int *rows);
55-
56-
/*!
57-
* \fn CON_GetPosition(int *col, int *row)
58-
* \brief retrieve the current cursor position of the current console
59-
*
60-
* \param[out] col,row current cursor position
61-
*
62-
* \return none
63-
*/
64-
void CON_GetPosition(int *cols, int *rows);
65-
66-
/*!
67-
* \fn CON_EnableGecko(int channel, int safe)
68-
* \brief Enable or disable the USB gecko console.
69-
*
70-
* \param[in] channel EXI channel, or -1 ¨to disable the gecko console
71-
* \param[in] safe If true, use safe mode (wait for peer)
72-
*
73-
* \return none
74-
*/
75-
void CON_EnableGecko(int channel,int safe);
76-
77-
#ifdef __cplusplus
78-
}
79-
#endif
80-
81-
#endif
1+
#include "console.h"

gc/ogc/console.h

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#ifndef __LIBOGC_CONSOLE_H__
2+
#define __LIBOGC_CONSOLE_H__
3+
4+
/*!
5+
* \file console.h
6+
* \brief Console subsystem
7+
*
8+
*/
9+
10+
#include "gx_struct.h"
11+
12+
/* macros to support old function names */
13+
#define console_init CON_Init
14+
#define SYS_ConsoleInit CON_InitEx
15+
16+
#define CONSOLE_ESC(x) "\x1b[" #x
17+
#define CONSOLE_RESET CONSOLE_ESC(0m)
18+
#define CONSOLE_BLACK CONSOLE_ESC(30m)
19+
#define CONSOLE_RED CONSOLE_ESC(31;1m)
20+
#define CONSOLE_GREEN CONSOLE_ESC(32;1m)
21+
#define CONSOLE_YELLOW CONSOLE_ESC(33;1m)
22+
#define CONSOLE_BLUE CONSOLE_ESC(34;1m)
23+
#define CONSOLE_MAGENTA CONSOLE_ESC(35;1m)
24+
#define CONSOLE_CYAN CONSOLE_ESC(36;1m)
25+
#define CONSOLE_WHITE CONSOLE_ESC(37;1m)
26+
27+
#define CONSOLE_COLOR_BLACK 0
28+
#define CONSOLE_COLOR_RED 1
29+
#define CONSOLE_COLOR_GREEN 2
30+
#define CONSOLE_COLOR_YELLOW 3
31+
#define CONSOLE_COLOR_BLUE 4
32+
#define CONSOLE_COLOR_MAGENTA 5
33+
#define CONSOLE_COLOR_CYAN 6
34+
#define CONSOLE_COLOR_WHITE 7
35+
36+
#ifdef __cplusplus
37+
extern "C" {
38+
#endif
39+
40+
/*!
41+
* \fn CON_Init(void *framebuffer,int xstart,int ystart,int xres,int yres,int stride)
42+
* \brief Initializes the console subsystem with given parameters
43+
*
44+
* \param[in] framebuffer pointer to the framebuffer used for drawing the characters
45+
* \param[in] xstart,ystart start position of the console output in pixel
46+
* \param[in] xres,yres size of the console in pixel
47+
* \param[in] stride size of one line of the framebuffer in bytes
48+
*
49+
* \return none
50+
*/
51+
void CON_Init(void *framebuffer,int xstart,int ystart,int xres,int yres,int stride);
52+
53+
/*!
54+
* \fn s32 CON_InitEx(GXRModeObj *rmode, s32 conXOrigin,s32 conYOrigin,s32 conWidth,s32 conHeight)
55+
* \brief Initialize stdout console
56+
* \param[in] rmode pointer to the video/render mode configuration
57+
* \param[in] conXOrigin starting pixel in X direction of the console output on the external framebuffer
58+
* \param[in] conYOrigin starting pixel in Y direction of the console output on the external framebuffer
59+
* \param[in] conWidth width of the console output 'window' to be drawn
60+
* \param[in] conHeight height of the console output 'window' to be drawn
61+
*
62+
* \return 0 on success, <0 on error
63+
*/
64+
s32 CON_InitEx(GXRModeObj *rmode, s32 conXOrigin,s32 conYOrigin,s32 conWidth,s32 conHeight);
65+
66+
/*!
67+
* \fn CON_GetMetrics(int *cols, int *rows)
68+
* \brief retrieve the columns and rows of the current console
69+
*
70+
* \param[out] cols,rows number of columns and rows of the current console
71+
*
72+
* \return none
73+
*/
74+
void CON_GetMetrics(int *cols, int *rows);
75+
76+
/*!
77+
* \fn CON_GetPosition(int *col, int *row)
78+
* \brief retrieve the current cursor position of the current console
79+
*
80+
* \param[out] col,row current cursor position
81+
*
82+
* \return none
83+
*/
84+
void CON_GetPosition(int *cols, int *rows);
85+
86+
/*!
87+
* \fn CON_EnableGecko(int channel, int safe)
88+
* \brief Enable or disable the USB gecko console.
89+
*
90+
* \param[in] channel EXI channel, or -1 ¨to disable the gecko console
91+
* \param[in] safe If true, use safe mode (wait for peer)
92+
*
93+
* \return none
94+
*/
95+
void CON_EnableGecko(int channel,int safe);
96+
97+
#ifdef __cplusplus
98+
}
99+
#endif
100+
101+
#endif

0 commit comments

Comments
 (0)