atm959

GBA Thing

Feb 3rd, 2020
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 13.99 KB | None | 0 0
  1. #include <gba_base.h>
  2. #include <gba_video.h>
  3. #include <gba_systemcalls.h>
  4. #include <gba_interrupt.h>
  5. #include <gba_input.h>
  6.  
  7. #include <string.h>
  8.  
  9. #include <maxmod.h>
  10.  
  11. #include "soundbank.h"
  12. #include "soundbank_bin.h"
  13.  
  14. #include "tiles.h"
  15.  
  16. // --------------------------------------------------------------------
  17.  
  18. #define ALIGN4 __attribute__((aligned(4)))
  19.  
  20. #define MAPADDRESS0     MAP_BASE_ADR(28)    // our base map address
  21. #define MAPADDRESS1     MAP_BASE_ADR(29)
  22. #define MAPADDRESS2     MAP_BASE_ADR(30)
  23. #define MAPADDRESS3     MAP_BASE_ADR(31)
  24.  
  25. // --------------------------------------------------------------------
  26.  
  27. u16 map[32*32];
  28.  
  29. u32 i;
  30. char currentLevel = 0;
  31. char characterX = 1, characterY = 1;
  32.  
  33. const u16 palette[] = {
  34.     RGB8(0x00, 0x00, 0x00),
  35.     RGB8(0x2A, 0x2A, 0x2A),
  36.     RGB8(0x80, 0x80, 0x80),
  37.     RGB8(0x08, 0x08, 0x08),
  38.     RGB8(0xFF, 0xFF, 0xFF)
  39. };
  40.  
  41. // --------------------------------------------------------------------
  42.  
  43. void loadTilesAndPalette(){
  44.     u16 *temppointer, *temppointer2;
  45.    
  46.     for(i = 0; i < (32 * 32); i++){
  47.         map[i] = 0;
  48.     }
  49.    
  50.     //BG is 30x20 on screen
  51.  
  52.     // load the palette for the background, 7 colors
  53.     temppointer = BG_COLORS;
  54.     temppointer2 = OBJ_COLORS;
  55.     for(i=0; i<5; i++) {
  56.         *temppointer++ = palette[i];
  57.         *temppointer2++ = palette[i];
  58.     }
  59.  
  60.     CpuFastSet(tiles_chr, (u16*)0x06010000,(tiles_chr_size/4) | COPY32);
  61.     CpuFastSet(tiles_chr, (u16*)VRAM, (tiles_chr_size / 4) | COPY32);
  62.  
  63.     // clear screen map with tile 0 ('space' tile) (256x256 halfwords)
  64.  
  65.     CpuFastSet(MAPADDRESS0, MAPADDRESS0, FILL | COPY32 | (0x800/4));
  66.  
  67.     // set screen H and V scroll positions
  68.     for(i = 0; i < 4; i++){
  69.         BG_OFFSET[i].x = 0; BG_OFFSET[i].y = 0;
  70.     }
  71.  
  72.     // set the screen base to 31 (0x600F800) and char base to 0 (0x6000000)
  73.     BGCTRL[0] = SCREEN_BASE(28);
  74.     BGCTRL[1] = SCREEN_BASE(29);
  75. }
  76.  
  77. char level1[30 * 20] = {
  78.     0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  79.     0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01,
  80.     0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  81.     0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  82.     0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  83.     0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  84.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  85.     0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  86.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  87.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  88.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  89.     0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  90.     0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  91.     0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  92.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  93.     0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  94.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  95.     0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  96.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  97.     0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
  98. };
  99.  
  100. char level2[30 * 20] = {
  101.     0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  102.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  103.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  104.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  105.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  106.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  107.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  108.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  109.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  110.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  111.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  112.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  113.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  114.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  115.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  116.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  117.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  118.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  119.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  120.     0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
  121. };
  122.  
  123. char* levelTable[2] = {
  124.     level1,
  125.     level2
  126. };
  127.  
  128. void loadLevel(char* levelData){
  129.     int j = 0;
  130.     int k = 0;
  131.     i = 0;
  132.     while(j < (30 * 20)){
  133.         if((k % 32) < 30){
  134.             map[i] = levelData[j];
  135.             j++;
  136.         }
  137.         k++;
  138.         i++;
  139.     }
  140. }
  141.  
  142. u8 colors[256][3];
  143.  
  144. void fadeOut(){
  145.     for(int i = 0; i < 256; i++){
  146.         colors[i][0] = BG_COLORS[i] & 0b0000000000011111;
  147.         colors[i][1] = (BG_COLORS[i] & 0b0000001111100000) >> 5;
  148.         colors[i][2] = (BG_COLORS[i] & 0b0111110000000000) >> 10;
  149.     }
  150.     bool fullyFadedOut = false;
  151.     while(!fullyFadedOut){
  152.         fullyFadedOut = true;
  153.         for(int i = 0; i < 256; i++){
  154.             if((colors[i][0] != 0x00) || (colors[i][1] != 0x00) || (colors[i][2] != 0x00)){
  155.                 if(colors[i][0] > 0x00) colors[i][0]--;
  156.                 if(colors[i][1] > 0x00) colors[i][1]--;
  157.                 if(colors[i][2] > 0x00) colors[i][2]--;
  158.                 BG_COLORS[i] = (u16)((colors[i][2] << 10) | (colors[i][1] << 5) | colors[i][0]);
  159.                 OBJ_COLORS[i] = (u16)((colors[i][2] << 10) | (colors[i][1] << 5) | colors[i][0]);
  160.                 fullyFadedOut = false;
  161.             }
  162.         }
  163.         VBlankIntrWait();
  164.     }
  165. }
  166.  
  167. u8 colorsToFadeTo[256][3];
  168.  
  169. void fadeIn(){
  170.     for(int i = 0; i < 5; i++){
  171.         colorsToFadeTo[i][0] = palette[i] & 0b0000000000011111;
  172.         colorsToFadeTo[i][1] = (palette[i] & 0b0000001111100000) >> 5;
  173.         colorsToFadeTo[i][2] = (palette[i] & 0b0111110000000000) >> 10;
  174.     }
  175.     bool fullyFadedIn = false;
  176.     while(!fullyFadedIn){
  177.         fullyFadedIn = true;
  178.         for(int i = 0; i < 5; i++){
  179.             if((colors[i][0] != colorsToFadeTo[i][0]) || (colors[i][1] != colorsToFadeTo[i][1]) || (colors[i][2] != colorsToFadeTo[i][2])){
  180.                 if(colors[i][0] < colorsToFadeTo[i][0]) colors[i][0]++;
  181.                 if(colors[i][1] < colorsToFadeTo[i][1]) colors[i][1]++;
  182.                 if(colors[i][2] < colorsToFadeTo[i][2]) colors[i][2]++;
  183.                 BG_COLORS[i] = (u16)((colors[i][2] << 10) | (colors[i][1] << 5) | colors[i][0]);
  184.                 OBJ_COLORS[i] = (u16)((colors[i][2] << 10) | (colors[i][1] << 5) | colors[i][0]);
  185.                 fullyFadedIn = false;
  186.             }
  187.         }
  188.         VBlankIntrWait();
  189.     }
  190. }
  191.  
  192. void unloadLevel(){
  193.     for(i = 0; i < (32 * 32); i++){
  194.         *((u16 *)MAPADDRESS1 + i) = 0x00;
  195.     }
  196. }
  197.  
  198. void vblank(){
  199.     mmFrame();
  200.     mmVBlank();
  201. }
  202.  
  203. void gotoNextLevel(){
  204.     currentLevel++;
  205.     fadeOut();
  206.     *((u16 *)MAPADDRESS0) = 0x00;
  207.     *((u16 *)MAPADDRESS0 + 1) = 0x00;
  208.     *((u16 *)MAPADDRESS0 + 2) = 0x00;
  209.     *((u16 *)MAPADDRESS0 + 3) = 0x00;
  210.     unloadLevel();
  211.     *((u16 *)MAPADDRESS0 + 299) = 'L';
  212.     *((u16 *)MAPADDRESS0 + 300) = 'E';
  213.     *((u16 *)MAPADDRESS0 + 301) = 'V';
  214.     *((u16 *)MAPADDRESS0 + 302) = 'E';
  215.     *((u16 *)MAPADDRESS0 + 303) = 'L';
  216.     *((u16 *)MAPADDRESS0 + 305) = '0' + (((currentLevel + 1) / 10) % 10);
  217.     *((u16 *)MAPADDRESS0 + 306) = '0' + ((currentLevel + 1) % 10);
  218.     *((u16 *)0x07000000 + 2) = 0x0000;
  219.     fadeIn();
  220.     for(int i = 0; i < 60; i++) VBlankIntrWait();
  221.     fadeOut();
  222.     *((u16 *)MAPADDRESS0 + 299) = 0x00;
  223.     *((u16 *)MAPADDRESS0 + 300) = 0x00;
  224.     *((u16 *)MAPADDRESS0 + 301) = 0x00;
  225.     *((u16 *)MAPADDRESS0 + 302) = 0x00;
  226.     *((u16 *)MAPADDRESS0 + 303) = 0x00;
  227.     *((u16 *)MAPADDRESS0 + 305) = 0x00;
  228.     *((u16 *)MAPADDRESS0 + 306) = 0x00;
  229.     loadLevel(levelTable[(int)currentLevel]);
  230.     for(i = 0; i < 32*32; i++){
  231.         *((u16 *)MAPADDRESS1 + i) = map[i];
  232.     }
  233.     *((u16 *)MAPADDRESS0) = 'L';
  234.     *((u16 *)MAPADDRESS0 + 1) = 'V';
  235.     *((u16 *)MAPADDRESS0 + 2) = '0' + (((currentLevel + 1) / 10) % 10);
  236.     *((u16 *)MAPADDRESS0 + 3) = '0' + ((currentLevel + 1) % 10);
  237.     *((u16 *)0x07000000 + 2) = 0b0000000000000000 | ((u8)0x04);
  238.     fadeIn();
  239. }
  240.  
  241. int main() {
  242.     // Set up the interrupt handlers
  243.     irqInit();
  244.     irqSet(IRQ_VBLANK, vblank);
  245.     // Enable Vblank Interrupt to allow VblankIntrWait
  246.     irqEnable(IRQ_VBLANK);
  247.    
  248.     mmInitDefault((mm_addr)soundbank_bin, 18); //Initialize MaxMod with 8 channels
  249.     mmStart(MOD_DROZERIX___CRUSH, MM_PLAY_LOOP);
  250.  
  251.     loadTilesAndPalette();
  252.    
  253.     SetMode( MODE_0 | BG0_ON | BG1_ON | OBJ_ON);
  254.    
  255.     fadeOut();
  256.    
  257.     *((u16 *)MAPADDRESS0) = 'L';
  258.     *((u16 *)MAPADDRESS0 + 1) = 'V';
  259.     *((u16 *)MAPADDRESS0 + 2) = '0' + (((currentLevel + 1) / 10) % 10);
  260.     *((u16 *)MAPADDRESS0 + 3) = '0' + ((currentLevel + 1) % 10);
  261.     loadLevel(levelTable[0]);
  262.     for(i = 0; i < 32*32; i++){
  263.         *((u16 *)MAPADDRESS1 + i) = map[i];
  264.     }
  265.    
  266.     fadeIn();
  267.    
  268.     while(1) {
  269.    
  270.         scanKeys();
  271.         u16 pad = keysDown();
  272.        
  273.         if(pad & KEY_A) {
  274.             gotoNextLevel();
  275.         }
  276.        
  277.         if(pad & KEY_B) {
  278.             currentLevel = -1;
  279.         }
  280.        
  281.         if(pad & KEY_UP){
  282.             if(map[(((characterY - 1) * 32) + characterX)] != 0x01) characterY--;
  283.         }
  284.        
  285.         if(pad & KEY_DOWN){
  286.             if(map[(((characterY + 1) * 32) + characterX)] != 0x01) characterY++;
  287.         }
  288.        
  289.         if(pad & KEY_LEFT){
  290.             if(map[((characterY * 32) + (characterX - 1))] != 0x01) characterX--;
  291.         }
  292.        
  293.         if(pad & KEY_RIGHT){
  294.             if(map[((characterY * 32) + (characterX + 1))] != 0x01) characterX++;
  295.         }
  296.        
  297.         *((u16 *)0x07000000) = 0b0000000000000000 | (characterY * 8);
  298.         *((u16 *)0x07000000 + 1) = 0b0000000000000000 | (characterX * 8);
  299.         *((u16 *)0x07000000 + 2) = 0b0000000000000000 | ((u8)0x04);
  300.        
  301.         if(map[((characterY * 32) + characterX)] == 0x02) gotoNextLevel();
  302.        
  303.         for(i = 0; i < 32*32; i++){
  304.             *((u16 *)MAPADDRESS1 + i) = map[i];
  305.         }
  306.        
  307.         VBlankIntrWait();
  308.     }
  309.  
  310. }
Advertisement
Add Comment
Please, Sign In to add comment