Advertisement
Guest User

GBA Scroll (Wrap)

a guest
Sep 27th, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | Source Code | 0 0
  1. #include <gba.h>
  2.  
  3. // These are your tiles and map data
  4. #include "graphics.h"
  5. #include "map.h"
  6.  
  7. static void updateBGColumn(u16 column)
  8. {
  9.   const u16* src = (const u16*) map;
  10.   u16* dst = (u16*) SCREEN_BASE_BLOCK(16);
  11.   u16 updateX = (column + 32) % 32 - 1;
  12.   if (updateX > 0)
  13.   {
  14.     for (u16 j = 0; j < 32; ++j)
  15.     {
  16.        dst[y * 32 + updateX] = src[y * mapWidth + updateX + 32];
  17.     }
  18.   }
  19. }
  20.  
  21. int main(void)
  22. {
  23.   // Load the palette
  24.   CpuSet(bg_palette,
  25.          BG_PALETTE,
  26.          COPY16 | bg_palette_size / 2);
  27.  
  28.   // Load the tiles into VRAM, Char Block 0
  29.   CpuSet(tiles, CHAR_BASE_BLOCK(0), COPY16 | tiles_size / 2);
  30.  
  31.   // Load the first chunk of our map
  32.   const u16* src = (const u16*) map;
  33.   u16* dst = (u16*) SCREEN_BASE_BLOCK(16);
  34.  
  35.   for (u16 j = 0; j < 32; ++j)
  36.   {
  37.     for (u16 i = 0; i < 32; ++i)
  38.     {
  39.        dst[j * 32 + i] = src[j * map_width + i];
  40.     }
  41.   }
  42.  
  43.   SetMode(MODE_0 | BG0_ENABLE);
  44.  
  45.   irqInit();
  46.   irqEnable(IRQ_VBLANK);
  47.  
  48.   u16 delay = 0;
  49.   u16 xScroll = 0;
  50.   u16 mapX = 0;
  51.  
  52.   while (true)
  53.   {
  54.     VBlankIntrWait();
  55.    
  56.     if (delay++ % 10 == 0)
  57.     {
  58.       xScoll++;
  59.  
  60.       if (++xScroll % 8 == 0)
  61.       {
  62.         mapX += 1;
  63.         updateBGColumn(mapX);
  64.       }
  65.  
  66.       BG0HOFS = xScroll;
  67.     }
  68.   }
  69.  
  70.   return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement