Skip to content

Commit 985abb8

Browse files
committed
Revert "console: fix all examples to correctly use consoles (#25)"
This was a misunderstanding of the console functions which arose after fixing the offsets to actually move the origin of the console rendering. The dimensions passed to CON_Init (aka console_init) are the extents of the framebuffer being passed not the console. Adjusting the ranges internally to account for the origin which is conceptually an offset into the given framebuffer prevents crashes in user code due to writing out of bounds which can often be difficult to debug.
1 parent 96089f5 commit 985abb8

13 files changed

Lines changed: 13 additions & 44 deletions

File tree

audio/modplay/source/template.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,14 @@ int main(int argc, char **argv) {
3333
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
3434

3535
// Initialise the console, required for printf
36-
console_init(xfb,20,20,rmode->fbWidth-20,rmode->xfbHeight-20,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
36+
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
3737

3838
// Set up the video registers with the chosen mode
3939
VIDEO_Configure(rmode);
4040

4141
// Tell the video hardware where our display memory is
4242
VIDEO_SetNextFramebuffer(xfb);
4343

44-
// Clear the framebuffer
45-
VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
46-
4744
// Make the display visible
4845
VIDEO_SetBlack(false);
4946

audio/mp3player/source/template.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,14 @@ int main(int argc, char **argv) {
3333
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
3434

3535
// Initialise the console, required for printf
36-
console_init(xfb,20,20,rmode->fbWidth-20,rmode->xfbHeight-20,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
36+
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
3737

3838
// Set up the video registers with the chosen mode
3939
VIDEO_Configure(rmode);
4040

4141
// Tell the video hardware where our display memory is
4242
VIDEO_SetNextFramebuffer(xfb);
4343

44-
// Clear the framebuffer
45-
VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
46-
4744
// Make the display visible
4845
VIDEO_SetBlack(false);
4946

audio/oggplayer/source/template.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ int main(int argc, char **argv) {
3838
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
3939

4040
// Initialise the console, required for printf
41-
console_init(xfb,20,20,rmode->fbWidth-20,rmode->xfbHeight-20,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
41+
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
4242

4343
// Set up the video registers with the chosen mode
4444
VIDEO_Configure(rmode);
4545

4646
// Tell the video hardware where our display memory is
4747
VIDEO_SetNextFramebuffer(xfb);
48-
49-
// Clear the framebuffer
50-
VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
5148

5249
// Make the display visible
5350
VIDEO_SetBlack(false);

crypto/source/crypto.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,14 @@ int main(int argc, char **argv) {
6666
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
6767

6868
// Initialise the console, required for printf
69-
console_init(xfb,20,20,rmode->fbWidth-20,rmode->xfbHeight-20,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
69+
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
7070

7171
// Set up the video registers with the chosen mode
7272
VIDEO_Configure(rmode);
7373

7474
// Tell the video hardware where our display memory is
7575
VIDEO_SetNextFramebuffer(xfb);
7676

77-
// Clear the framebuffer
78-
VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
79-
8077
// Make the display visible
8178
VIDEO_SetBlack(FALSE);
8279

devices/network/sockettest/source/sockettest.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,10 @@ void *initialise() {
155155

156156
rmode = VIDEO_GetPreferredMode(NULL);
157157
framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
158-
console_init(framebuffer,20,20,rmode->fbWidth-20,rmode->xfbHeight-20,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
158+
console_init(framebuffer,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
159159

160160
VIDEO_Configure(rmode);
161161
VIDEO_SetNextFramebuffer(framebuffer);
162-
VIDEO_ClearFrameBuffer(rmode, framebuffer, COLOR_BLACK);
163162
VIDEO_SetBlack(false);
164163
VIDEO_Flush();
165164
VIDEO_WaitVSync();

devices/network/udptest/source/udptest.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ static void initialise() {
2020

2121
rmode = VIDEO_GetPreferredMode(NULL);
2222
framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
23-
console_init(framebuffer, 20, 20, rmode->fbWidth-20, rmode->xfbHeight-20,
23+
console_init(framebuffer, 20, 20, rmode->fbWidth, rmode->xfbHeight,
2424
rmode->fbWidth * VI_DISPLAY_PIX_SZ);
2525

2626
VIDEO_Configure(rmode);
2727
VIDEO_SetNextFramebuffer(framebuffer);
28-
VIDEO_ClearFrameBuffer(rmode, framebuffer, COLOR_BLACK);
2928
VIDEO_SetBlack(false);
3029
VIDEO_Flush();
3130
VIDEO_WaitVSync();

devices/usbgecko/gdbstub/source/gdbstub.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ int main() {
1818
rmode = VIDEO_GetPreferredMode(NULL);
1919

2020
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
21-
console_init(xfb,20,20,rmode->fbWidth-20,rmode->xfbHeight-20,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
21+
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
2222

2323
VIDEO_Configure(rmode);
2424
VIDEO_SetNextFramebuffer(xfb);
25-
VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
2625
VIDEO_SetBlack(false);
2726
VIDEO_Flush();
2827
VIDEO_WaitVSync();

devices/usbkeyboard/basic_stdin/source/basic_stdin.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int main(int argc, char **argv)
3535
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
3636

3737
// Initialise the console, required for printf
38-
console_init(xfb, 20, 20, rmode->fbWidth-20, rmode->xfbHeight-20,
38+
console_init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight,
3939
rmode->fbWidth * VI_DISPLAY_PIX_SZ);
4040

4141
// Set up the video registers with the chosen mode
@@ -44,9 +44,6 @@ int main(int argc, char **argv)
4444
// Tell the video hardware where our display memory is
4545
VIDEO_SetNextFramebuffer(xfb);
4646

47-
// Clear the framebuffer
48-
VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
49-
5047
// Make the display visible
5148
VIDEO_SetBlack(false);
5249

filesystem/directory/isfs/source/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,10 @@ static void Init() {
320320
// Please refer to templates to understand this.
321321
rmode = VIDEO_GetPreferredMode(NULL);
322322
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
323-
console_init(xfb,20,20,rmode->fbWidth-20,rmode->xfbHeight-20,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
323+
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
324324
//SYS_STDIO_Report(true);
325325
VIDEO_Configure(rmode);
326326
VIDEO_SetNextFramebuffer(xfb);
327-
VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
328327
VIDEO_SetBlack(false);
329328
VIDEO_Flush();
330329
VIDEO_WaitVSync();

filesystem/directory/sd/source/directory.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ int main(int argc, char **argv) {
3232
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
3333

3434
// Initialise the console, required for printf
35-
console_init(xfb,20,20,rmode->fbWidth-20,rmode->xfbHeight-20,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
35+
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
3636

3737
// Set up the video registers with the chosen mode
3838
VIDEO_Configure(rmode);
3939

4040
// Tell the video hardware where our display memory is
4141
VIDEO_SetNextFramebuffer(xfb);
4242

43-
// Clear the framebuffer
44-
VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
45-
4643
// Make the display visible
4744
VIDEO_SetBlack(false);
4845

0 commit comments

Comments
 (0)