Skip to content

Commit f7e2bbf

Browse files
committed
consolidate console documentation and offset usage
introduces helper functions to avoid the repetition and mistakes logic was verified equivalent or better by hand but not runtime-tested fixes various issues having to do with out of bounds writes misc changes to extraneous whitespace noticed during the refactor
1 parent 9d99fec commit f7e2bbf

2 files changed

Lines changed: 155 additions & 97 deletions

File tree

gc/ogc/console.h

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
* \brief Initializes the console subsystem with given parameters
5656
*
5757
* \param[in] framebuffer pointer to the framebuffer used for drawing the characters
58-
* \param[in] xstart,ystart start position of the console output in pixel
59-
* \param[in] xres,yres size of the console in pixel
60-
* \param[in] stride size of one line of the framebuffer in bytes
58+
* \param[in] xstart,ystart start position of the console output, in pixels
59+
* \param[in] xres,yres size of the console, in pixels
60+
* \param[in] stride size of one line of the framebuffer, in bytes
6161
*
6262
* \return none
6363
*/
@@ -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
73-
* \param[in] conHeight height of the console output 'window' to be drawn
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
7474
*
7575
* \return 0 on success, <0 on error
7676
*/
@@ -80,7 +80,7 @@ s32 CON_InitEx(GXRModeObj *rmode, s32 conXOrigin,s32 conYOrigin,s32 conWidth,s32
8080
* \fn CON_GetMetrics(int *cols, int *rows)
8181
* \brief retrieve the columns and rows of the current console
8282
*
83-
* \param[out] cols,rows number of columns and rows of the current console
83+
* \param[out] cols,rows number of columns and rows of the current console, in tiles, 1-indexed.
8484
*
8585
* \return none
8686
*/
@@ -90,7 +90,7 @@ void CON_GetMetrics(int *cols, int *rows);
9090
* \fn CON_GetPosition(int *col, int *row)
9191
* \brief retrieve the current cursor position of the current console
9292
*
93-
* \param[out] col,row current cursor position
93+
* \param[out] col,row current cursor position, in tiles, 1-indexed.
9494
*
9595
* \return none
9696
*/
@@ -100,7 +100,7 @@ void CON_GetPosition(int *cols, int *rows);
100100
* \fn CON_EnableGecko(int channel, int safe)
101101
* \brief Enable or disable the USB gecko console.
102102
*
103-
* \param[in] channel EXI channel, or -1 ¨to disable the gecko console
103+
* \param[in] channel EXI channel, or -1 to disable the gecko console
104104
* \param[in] safe If true, use safe mode (wait for peer)
105105
*
106106
* \return none
@@ -152,22 +152,24 @@ typedef struct PrintConsole
152152
ConsoleFont font; ///< Font of the console
153153

154154
void *destbuffer; ///< Framebuffer address
155-
int con_xres,con_yres,con_stride;
156-
int target_x,target_y, tgt_stride;
155+
int con_xres, con_yres; ///< Console buffer width/height, in pixels
156+
int con_stride; ///< Size of one row in the console buffer, in bytes
157+
int target_x, target_y; ///< Target buffer x/y offset to start the console, in pixels
158+
int tgt_stride; ///< Size of one row in the target buffer, in bytes
157159

158-
int cursorX; ///< Current X location of the cursor (as a tile offset by default)
159-
int cursorY; ///< Current Y location of the cursor (as a tile offset by default)
160+
int cursorX; ///< Current X location of the cursor in the window, in tiles, 1-indexed: 1 <= cursorX <= windowWidth, cursorX > windowWidth wraps to the next line and resets to cursorX = 1
161+
int cursorY; ///< Current Y location of the cursor in the window, in tiles, 1-indexed
160162

161163
int prevCursorX; ///< Internal state
162164
int prevCursorY; ///< Internal state
163165

164-
int con_cols; ///< Width of the console hardware layer in characters
165-
int con_rows; ///< Height of the console hardware layer in characters
166+
int con_cols; ///< Width of the console hardware layer, in characters (amount of tiles)
167+
int con_rows; ///< Height of the console hardware layer, in characters (amount of tiles)
166168

167-
int windowX; ///< Window X location in characters (not implemented)
168-
int windowY; ///< Window Y location in characters (not implemented)
169-
int windowWidth; ///< Window width in characters (not implemented)
170-
int windowHeight; ///< Window height in characters (not implemented)
169+
int windowX; ///< Window X location, in tiles, 1-indexed, 1 <= windowX < con_cols
170+
int windowY; ///< Window Y location, in tiles, 1-indexed
171+
int windowWidth; ///< Window width, in amount of tiles, 1 <= windowWidth <= con_cols
172+
int windowHeight; ///< Window height, in amount of tiles
171173

172174
int tabSize; ///< Size of a tab
173175
unsigned int fg; ///< Foreground color
@@ -196,10 +198,10 @@ void consoleSetFont(PrintConsole* console, ConsoleFont* font);
196198
/**
197199
* @brief Sets the print window.
198200
* @param console Console to set, if NULL it will set the current console window.
199-
* @param x X location of the window.
200-
* @param y Y location of the window.
201-
* @param width Width of the window.
202-
* @param height Height of the window.
201+
* @param x X location of the window, in tiles, 1-indexed.
202+
* @param y Y location of the window, in tiles, 1-indexed.
203+
* @param width Width of the window, in tiles, 1-indexed.
204+
* @param height Height of the window, in tiles, 1-indexed.
203205
*/
204206
void consoleSetWindow(PrintConsole* console, unsigned int x, unsigned int y, unsigned int width, unsigned int height);
205207

0 commit comments

Comments
 (0)