From f5a6ca0ce40184a49ff09a85855f7d004b152db7 Mon Sep 17 00:00:00 2001 From: Wayne Venables Date: Sun, 28 Sep 2025 17:21:28 -0700 Subject: [PATCH] Move stdio_init_all() to before video initialization --- examples/vga_ants/src/main.cpp | 8 ++++---- examples/vga_eggs/src/main.cpp | 8 ++++---- examples/vga_fifteen/src/main.cpp | 8 ++++---- examples/vga_ghostracing/src/main.cpp | 8 ++++---- examples/vga_gingerhouse/src/main.cpp | 8 ++++---- examples/vga_life/src/main.cpp | 6 +++--- examples/vga_mandelbrot/src/main.cpp | 8 ++++---- examples/vga_maze/src/main.cpp | 8 ++++---- examples/vga_monoscope/src/main.cpp | 8 ++++---- examples/vga_pacman/src/main.cpp | 8 ++++---- examples/vga_sokoban/src/main.cpp | 8 ++++---- examples/vga_tetris/src/main.cpp | 10 +++++----- examples/vga_train/src/main.cpp | 8 ++++---- pico_flash_region.ld | 2 +- src/picovga.h | 16 ++++++++-------- src/vga.h | 2 +- 16 files changed, 62 insertions(+), 62 deletions(-) diff --git a/examples/vga_ants/src/main.cpp b/examples/vga_ants/src/main.cpp index 68654cb..5790c60 100644 --- a/examples/vga_ants/src/main.cpp +++ b/examples/vga_ants/src/main.cpp @@ -277,7 +277,10 @@ void DispOpenSel() // main function int main() { - char ch; + // initialize stdio + stdio_init_all(); + + char ch; u32 t; // initialize random number generator @@ -289,9 +292,6 @@ int main() // initialize canvases InitImg(); - // initialize stdio - stdio_init_all(); - // initialize sound output PWMSndInit(); diff --git a/examples/vga_eggs/src/main.cpp b/examples/vga_eggs/src/main.cpp index 53dfccd..0d0f211 100644 --- a/examples/vga_eggs/src/main.cpp +++ b/examples/vga_eggs/src/main.cpp @@ -790,7 +790,10 @@ void PlayGame(Bool comp1, Bool comp2) // main function int main() { - char ch; + // initialize stdio + stdio_init_all(); + + char ch; // copy tiles images memcpy(TilesImg_Copy, TilesImg, sizeof(TilesImg)); @@ -805,9 +808,6 @@ int main() // initialize videomode Video(DEV_VGA, RES_EGA, FORM_8BIT, Box); - // initialize stdio - stdio_init_all(); - // initialize sound output PWMSndInit(); diff --git a/examples/vga_fifteen/src/main.cpp b/examples/vga_fifteen/src/main.cpp index 379e60c..2fe2b0d 100644 --- a/examples/vga_fifteen/src/main.cpp +++ b/examples/vga_fifteen/src/main.cpp @@ -118,7 +118,10 @@ Bool Check() // main function int main() { - int i; + // initialize stdio + stdio_init_all(); + + int i; // initialize random number generator RandInitSeed(); @@ -130,9 +133,6 @@ int main() Video(DEV_VGA, RES_ZX, FORM_TILE48, Board, TilesImg_Copy); pScreen->strip[0].seg[0].offx = -32; - // initialize stdio - stdio_init_all(); - // initialize sound output PWMSndInit(); diff --git a/examples/vga_ghostracing/src/main.cpp b/examples/vga_ghostracing/src/main.cpp index e1c8c8f..4dfb53a 100644 --- a/examples/vga_ghostracing/src/main.cpp +++ b/examples/vga_ghostracing/src/main.cpp @@ -329,7 +329,10 @@ void FlushChar() int main() { - int t0, t2; + // initialize stdio + stdio_init_all(); + + int t0, t2; float dt; // copy images @@ -350,9 +353,6 @@ int main() // initialize videomode VideoInit(170000); - // initialize stdio - stdio_init_all(); - // initialize sound output PWMSndInit(); diff --git a/examples/vga_gingerhouse/src/main.cpp b/examples/vga_gingerhouse/src/main.cpp index 46567fc..79139e9 100644 --- a/examples/vga_gingerhouse/src/main.cpp +++ b/examples/vga_gingerhouse/src/main.cpp @@ -294,7 +294,10 @@ void VideoInit() int main() { - char ch; + // initialize stdio + stdio_init_all(); + + char ch; // copy font to RAM buffer memcpy(Font_Copy, FontBold8x8, sizeof(FontBold8x8)); @@ -309,9 +312,6 @@ int main() Page = 0; OpenPage(); - // initialize stdio - stdio_init_all(); - // main loop while (true) { diff --git a/examples/vga_life/src/main.cpp b/examples/vga_life/src/main.cpp index 0625c2b..6d9a815 100644 --- a/examples/vga_life/src/main.cpp +++ b/examples/vga_life/src/main.cpp @@ -343,6 +343,9 @@ void InitSlot() int main() { + // initialize stdio + stdio_init_all(); + char ch; // copy tiles images to RAM buffer (flash would be too slow) @@ -369,9 +372,6 @@ int main() // VideoInit(); Video(DEV_VGA, RES_VGA, FORM_TILE16, Board, TilesImg_Copy); - // initialize stdio - stdio_init_all(); - // display help DispHelp(); diff --git a/examples/vga_mandelbrot/src/main.cpp b/examples/vga_mandelbrot/src/main.cpp index 924c635..5491163 100644 --- a/examples/vga_mandelbrot/src/main.cpp +++ b/examples/vga_mandelbrot/src/main.cpp @@ -380,7 +380,10 @@ void Help() int main() { - int c; + // initialize stdio + stdio_init_all(); + + int c; // run VGA core StartVgaCore(); @@ -388,9 +391,6 @@ int main() // setup videomode Init(); - // initialize stdio - stdio_init_all(); - // initialize debug LED gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); diff --git a/examples/vga_maze/src/main.cpp b/examples/vga_maze/src/main.cpp index 80bf256..00d8dd9 100644 --- a/examples/vga_maze/src/main.cpp +++ b/examples/vga_maze/src/main.cpp @@ -214,7 +214,10 @@ void Clear() int main() { - int i; + // initialize stdio + stdio_init_all(); + + int i; char ch; // initialize random number generator @@ -228,9 +231,6 @@ int main() if (MAZEW != MAPW) pScreen->strip[0].seg[0].offx = -4; // center image on the screen if (MAZEH != MAPH) pScreen->strip[0].seg[0].offy = -4; - // initialize stdio - stdio_init_all(); - // display help DispHelp(); diff --git a/examples/vga_monoscope/src/main.cpp b/examples/vga_monoscope/src/main.cpp index 602aa8d..32c954d 100644 --- a/examples/vga_monoscope/src/main.cpp +++ b/examples/vga_monoscope/src/main.cpp @@ -254,7 +254,10 @@ void MonoList() int main() { - char c; + // initialize stdio + stdio_init_all(); + + char c; // run VGA core StartVgaCore(); @@ -262,9 +265,6 @@ int main() // run default video mode VGA 640x480 MonoInit(22); - // initialize stdio - stdio_init_all(); - while (true) { // print list diff --git a/examples/vga_pacman/src/main.cpp b/examples/vga_pacman/src/main.cpp index 24bf0fb..24b3e95 100644 --- a/examples/vga_pacman/src/main.cpp +++ b/examples/vga_pacman/src/main.cpp @@ -200,7 +200,10 @@ void FlushChar() int main() { - // initialize random number generator + // initialize stdio + stdio_init_all(); + + // initialize random number generator RandInitSeed(); // initialize buffers on program start @@ -212,9 +215,6 @@ int main() // initialize videomode VideoInit(); - // initialize stdio - stdio_init_all(); - // some internal checks while ((sizeof(SpritesImg) != SPRITE_NUM*SPRITEW*SPRITEH) || (sizeof(TilesImg) != TILE_NUM*TILESIZE*TILESIZE)) diff --git a/examples/vga_sokoban/src/main.cpp b/examples/vga_sokoban/src/main.cpp index 750f5d4..a56551a 100644 --- a/examples/vga_sokoban/src/main.cpp +++ b/examples/vga_sokoban/src/main.cpp @@ -143,7 +143,10 @@ void FlushChar() int main() { - int i; + // initialize stdio + stdio_init_all(); + + int i; // initialize random number generator RandInitSeed(); @@ -157,9 +160,6 @@ int main() // initialize videomode VideoInit(); - // initialize stdio - stdio_init_all(); - // initialize sound output PWMSndInit(); diff --git a/examples/vga_tetris/src/main.cpp b/examples/vga_tetris/src/main.cpp index a9e17ba..1fda828 100644 --- a/examples/vga_tetris/src/main.cpp +++ b/examples/vga_tetris/src/main.cpp @@ -1006,7 +1006,10 @@ void PlayDemo() int main() { - // initialize random number generator + // initialize stdio + stdio_init_all(); + + // initialize random number generator RandInitSeed(); // copy tiles images to RAM buffer @@ -1022,10 +1025,7 @@ int main() Canvas.wb = TILESIZE; Canvas.format = CANVAS_8; - // initialize stdio - stdio_init_all(); - - // initialize sound output + // initialize sound output PWMSndInit(); // display help diff --git a/examples/vga_train/src/main.cpp b/examples/vga_train/src/main.cpp index 57dc939..0b45849 100644 --- a/examples/vga_train/src/main.cpp +++ b/examples/vga_train/src/main.cpp @@ -97,7 +97,10 @@ void FlushChar() int main() { - int i; + // initialize stdio + stdio_init_all(); + + int i; // initialize random number generator RandInitSeed(); @@ -117,9 +120,6 @@ int main() // initialize videomode VideoInit(); - // initialize stdio - stdio_init_all(); - // initialize sound output PWMSndInit(); diff --git a/pico_flash_region.ld b/pico_flash_region.ld index 382fcf4..df5e392 100644 --- a/pico_flash_region.ld +++ b/pico_flash_region.ld @@ -1 +1 @@ -FLASH(rx) : ORIGIN = 0x10000000, LENGTH = (16 * 1024 * 1024) +FLASH(rx) : ORIGIN = 0x10000000, LENGTH = (2 * 1024 * 1024) diff --git a/src/picovga.h b/src/picovga.h index a267ce1..3359920 100644 --- a/src/picovga.h +++ b/src/picovga.h @@ -73,14 +73,14 @@ typedef unsigned char Bool; // Constants // ---------------------------------------------------------------------------- -#define B0 (1<<0) -#define B1 (1<<1) -#define B2 (1<<2) -#define B3 (1<<3) -#define B4 (1<<4) -#define B5 (1<<5) -#define B6 (1<<6) -#define B7 (1<<7) +#define B0 (1U<<0) +#define B1 (1U<<1) +#define B2 (1U<<2) +#define B3 (1U<<3) +#define B4 (1U<<4) +#define B5 (1U<<5) +#define B6 (1U<<6) +#define B7 (1U<<7) #define B8 (1U<<8) #define B9 (1U<<9) #define B10 (1U<<10) diff --git a/src/vga.h b/src/vga.h index a01d17d..2294638 100644 --- a/src/vga.h +++ b/src/vga.h @@ -54,7 +54,7 @@ extern u32 CtrlBuf2[CBUF_MAX]; // control pairs: u32 count, read address (must b extern int CtrlBufSize[LAYERS_MAX]; // size of control buffers // render font pixel mask -extern u32 RenderTextMask[512]; +extern "C" u32 RenderTextMask[512]; // fill memory buffer with u32 words // buf ... data buffer, must be 32-bit aligned