gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit de539e1c9adcaa8acd22ece7a99478b6d7a9a991 parent b02c1dc4c9d77467c569a5b38676396897dbfd38 Author: Toxa <untoxa@mail.ru> Date: Thu, 26 Aug 2021 00:52:49 +0300 SMS/GG: scroll_bkg() calculates modulus of 224 by Y to make smooth scroll without "jumps" Diffstat:
| M | gbdk-lib/examples/gg/large_map/large_map.c | 4 | ++-- |
| M | gbdk-lib/include/sms/sms.h | 3 | ++- |
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/gbdk-lib/examples/gg/large_map/large_map.c b/gbdk-lib/examples/gg/large_map/large_map.c @@ -21,7 +21,7 @@ uint8_t redraw; void set_camera() { // update hardware scroll position - move_bkg(camera_x, camera_y < (8 * 28) ? camera_y: (camera_y - (8 * 28))); + move_bkg(camera_x, camera_y % 224); // up or down map_pos_y = (uint8_t)(camera_y >> 3u); if (map_pos_y != old_map_pos_y) { @@ -58,7 +58,7 @@ void main(){ redraw = FALSE; - move_bkg(camera_x, camera_y); + move_bkg(camera_x, camera_y % 224); while (TRUE) { joy = joypad(); // up or down diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -109,7 +109,8 @@ inline void move_bkg(uint8_t x, uint8_t y) { inline void scroll_bkg(int8_t x, int8_t y) { __WRITE_VDP_REG(VDP_RSCX, __READ_VDP_REG(VDP_RSCX) - x); - __WRITE_VDP_REG(VDP_RSCY, __READ_VDP_REG(VDP_RSCY) + y); + int16_t tmp = __READ_VDP_REG(VDP_RSCY) + y; + __WRITE_VDP_REG(VDP_RSCY, (tmp < 0) ? 224 + tmp : tmp % 224u); } /** HALTs the CPU and waits for the vertical blank interrupt (VBL) to finish.
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.