gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 0bc85eec3beba0efe394437efdb9ff8b83388f3d
parent 6630f99c0afc7bf9cc7248df733ec2ce9b1dd7ca
Author: toxa <untoxa@mail.ru>
Date: Fri, 6 Nov 2020 13:05:55 +0300
variables cleanup to prevent "reading of uninitialized WRAM" exception in BGB (`{0}`array initialization style is not working correctly in the current builds of SDCC, it initializes only the first element)
Diffstat:
| M | gbdk-lib/examples/gb/rand/rand.c | 8 | ++++++-- |
| M | gbdk-lib/examples/gb/sgb_border/sgb_border.c | 17 | ++++++++--------- |
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/gbdk-lib/examples/gb/rand/rand.c b/gbdk-lib/examples/gb/rand/rand.c @@ -14,15 +14,19 @@ #include <rand.h> #include <gb/drawing.h> #include <stdio.h> +#include <string.h> -UBYTE accu[80] = {0}; -UBYTE accua[80] = {0}; +UBYTE accu[80]; +UBYTE accua[80]; void main(void) { UBYTE r, s, t = 0, u = 0; UWORD seed; + memset(accu, 0, sizeof(accu)); + memset(accua, 0, sizeof(accua)); + /* We use the DIV register to get a random initial seed */ puts("Getting seed"); puts("Push any key (1)"); diff --git a/gbdk-lib/examples/gb/sgb_border/sgb_border.c b/gbdk-lib/examples/gb/sgb_border/sgb_border.c @@ -1,5 +1,6 @@ #include "sgb_border.h" +#include <gb/gb.h> #include <gb/sgb.h> #include <string.h> @@ -9,7 +10,7 @@ #define SGB_SCR_FREEZE 1 #define SGB_SCR_UNFREEZE 0 -unsigned char map_buf[20] = {0}; +unsigned char map_buf[20]; #define SGB_TRANSFER(A,B) map_buf[0]=(A),map_buf[1]=(B),sgb_transfer(map_buf) @@ -36,16 +37,17 @@ void set_sgb_border(unsigned char * tiledata, size_t tiledata_size, unsigned char * tilemap, size_t tilemap_size, unsigned char * palette, size_t palette_size) { if (sgb_check()) { - BGP_REG = OBP0_REG = OBP1_REG = 0xE4U; + memset(map_buf, 0, sizeof(map_buf)); + SGB_TRANSFER((SGB_MASK_EN << 3) | 1, SGB_SCR_FREEZE); + BGP_REG = OBP0_REG = OBP1_REG = 0xE4U; + SCX_REG = SCY_REG = 0U; + UBYTE tmp_lcdc = LCDC_REG; HIDE_SPRITES, HIDE_WIN, SHOW_BKG; DISPLAY_ON; - - SCX_REG = SCY_REG = 0U; - // prepare tilemap for SGB_BORDER_CHR_TRN (should display all 256 tiles) UBYTE i = 0U; for (UBYTE y = 0; y != 14U; ++y) { @@ -64,10 +66,7 @@ void set_sgb_border(unsigned char * tiledata, size_t tiledata_size, LCDC_REG = tmp_lcdc; // clear SCREEN - memset(map_buf, 0, sizeof(map_buf)); - set_bkg_data(0, 1, map_buf); - for (UBYTE y = 0; y != 18U; ++y) - set_bkg_tiles(0, y, 20, 1, map_buf); + fill_bkg_rect(0, 0, 20, 18, 0); SGB_TRANSFER((SGB_MASK_EN << 3) | 1, SGB_SCR_UNFREEZE); }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.