Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gba.h>
- // These are your tiles and map data
- #include "graphics.h"
- #include "map.h"
- static void updateBGColumn(u16 column)
- {
- const u16* src = (const u16*) map;
- u16* dst = (u16*) SCREEN_BASE_BLOCK(16);
- u16 updateX = (column + 32) % 32 - 1;
- if (updateX > 0)
- {
- for (u16 j = 0; j < 32; ++j)
- {
- dst[y * 32 + updateX] = src[y * mapWidth + updateX + 32];
- }
- }
- }
- int main(void)
- {
- // Load the palette
- CpuSet(bg_palette,
- BG_PALETTE,
- COPY16 | bg_palette_size / 2);
- // Load the tiles into VRAM, Char Block 0
- CpuSet(tiles, CHAR_BASE_BLOCK(0), COPY16 | tiles_size / 2);
- // Load the first chunk of our map
- const u16* src = (const u16*) map;
- u16* dst = (u16*) SCREEN_BASE_BLOCK(16);
- for (u16 j = 0; j < 32; ++j)
- {
- for (u16 i = 0; i < 32; ++i)
- {
- dst[j * 32 + i] = src[j * map_width + i];
- }
- }
- SetMode(MODE_0 | BG0_ENABLE);
- irqInit();
- irqEnable(IRQ_VBLANK);
- u16 delay = 0;
- u16 xScroll = 0;
- u16 mapX = 0;
- while (true)
- {
- VBlankIntrWait();
- if (delay++ % 10 == 0)
- {
- xScoll++;
- if (++xScroll % 8 == 0)
- {
- mapX += 1;
- updateBGColumn(mapX);
- }
- BG0HOFS = xScroll;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement