PAlib: Fichier source de PA_Tile.h

Page principale | Modules | Liste des fichiers | Portée globale | Rechercher

# PA_Tile.h

Aller à la documentation de ce fichier.

    00001 #ifndef _PA_Tile
    00002 #define _PA_Tile
    00003
    00004
    00005 #include "PA_Sprite.h"
    00006
    00007
    00008 // Extracts the size from PAGfx convertions
    00009 extern inline u8 PA_GetPAGfxBgSize(u16 width, u16 height)
    00010 {
    00011        u8 bg_size = 0;
    00012        if (height == 512)   bg_size = 2;
    00013        if (width == 512)    bg_size ++;
    00014        return bg_size;
    00015 }
    00016
    00017 // Extracts the size from PAGfx convertions
    00018 extern inline u8 PA_GetPAGfxRotBgSize(u16 width)
    00019 {
    00020        u8 bg_size = 1; //256x256 by default
    00021        if (width <= 128)    bg_size = 0;
    00022        else if (width <= 256)      bg_size = 1;
    00023        else if (width <= 512)      bg_size = 2;
    00024        else if (width <= 1024) bg_size = 3;
    00025
    00026        return bg_size;
    00027 }
    00028
    00035 //#include "../PA.h"
    00036
    00037
    00038
    00040 // Système de Tiles
    00042
    00043
    00044 //background memory offset macros
    00045 #define CharBaseBlock(screen, n) (((n)*0x4000) + 0x6000000 + (0x200000 *  screen))
    00046 #define ScreenBaseBlock(screen, n) (((n)*0x800) + 0x6000000 + (0x200000 *  screen))
    00047 extern u32 PA_bgmap[2][4]; // Pointeur vers les maps, 4 maps par screen
    00048 extern u8 tilesetchar[2][4];
    00049
    00050 // Quantité de données à charger en fonction de la taille de la map...
    00051 extern u16 bg_sizes[4];
    00052 extern u8 bg_place[4];
    00053
    00054 extern u16 *PA_DrawBg[2]; // Fond dessinable
    00055
    00056
    00057 extern u8 charblocks[2][70];
    00058 extern u16 tilesetsize[2][4]; // Place utilisée pour chaque tileset
    00059 extern u16 mapsize[2][4]; // Place utilisée pour chaque map
    00060 extern u8 tilesetchar[2][4];  // Emplacement mémoire de chaque tileset
    00061 extern u8 mapchar[2][4];  // Emplacement mémoire de chaque map
    00062
    00063 extern u8 charsetstart[2];
    00064
    00065
    00066
    00067
    00068
    00069 extern s32 PA_parallaxX[2][4];
    00070 extern s32 PA_parallaxY[2][4];
    00071
    00072
    00073
    00074
    00075 typedef struct {
    00076        u8 infscroll; // Passe à 1 si scrolling infini activé...
    00077        u16* bg_map; // Map
    00078 //     s32 x, y;
    00079        s32 lx, ly;
    00080        s32 scrollx, scrolly;
    00081        s32 maxx; // 32 ou 64, en fonction de la largeur...
    00082 //     s32 startx, starty;
    00083 }scrollpositions;
    00084
    00085 extern scrollpositions scrollpos[2][4]; // Pour chaque écran et pour chaque fond :)
    00086
    00087
    00088
    00089
    00090
    00091
    00092 // Mode de couleur
    00093 #define BG_COLOR16 0x00
    00094 #define BG_COLOR256 0x80
    00095
    00096
    00097 #define CHAR_SHIFT 2
    00098 #define SCREEN_SHIFT 8
    00099 #define WRAPAROUND 0x1
    00100
    00101 #define SCREEN_TILES 24576  // Taille à convertir pour avoir un écran complet...
    00102
    00103
    00104 //scrolling registers for background 0
    00105
    00106
    00107 // Registre pour les controles de chaque écran
    00108
    00109 #define REG_BGSCREEN0  0x04000000
    00110 #define REG_BGSCREEN1  0x04001000
    00111 #define REG_BGSCREEN(screen) (0x04000000 + (screen * 0x1000))
    00112
    00113 #define REG_BGCNT(screen, bg_number) (0x4000008 + (screen * 0x1000) + (bg_number << 1))
    00114
    00115 // Premier registre pour les scroll. On en déduit les autres en ajoutant pour le screen et le numéro du Bg
    00116 #define REG_BGSCROLLX 0x4000010
    00117 #define REG_BGSCROLLY 0x4000012
    00118
    00119
    00120 // Tailles pour les Bg :
    00121 #define BG_256X256 0
    00122 #define BG_512X256 1
    00123 #define BG_256X512 2
    00124 #define BG_512X512 3
    00125
    00126 #define BG_ROT_128X128 0
    00127 #define BG_ROT_256X256 1
    00128 #define BG_ROT_512X512 2
    00129 #define BG_ROT_1024X1024 3
    00130
    00131 void PA_LoadRotBgMap(u8 screen, u8 bg_select, void* bg_map, u8 bg_size);
    00132
    00133
    00134 //ALL_BUT() pour faire tout sauf...
    00135 #define TILE_N 1023
    00136 #define TILE_PAL 61440
    00137 #define TILE_HFLIP 1024
    00138 #define TILE_VFLIP 2048
    00139
    00140 #define PA_BGXX(screen, bg) _REG32(0x4000008 + (0x1000 * screen) + (bg << 4))
    00141 #define PA_BGXY(screen, bg) _REG32(0x400000C + (0x1000 * screen) + (bg << 4))
    00142 #define PA_BGXPA(screen, bg) _REG16(0x4000000 + (0x1000 * screen) + (bg << 4))
    00143 #define PA_BGXPB(screen, bg) _REG16(0x4000002 + (0x1000 * screen) + (bg << 4))
    00144 #define PA_BGXPC(screen, bg) _REG16(0x4000004 + (0x1000 * screen) + (bg << 4))
    00145 #define PA_BGXPD(screen, bg) _REG16(0x4000006 + (0x1000 * screen) + (bg << 4))
    00146
    00147
    00148
    00149
    00150
    00162 void PA_ResetBgSys(void);
    00163
    00186 void PA_InitBg(u8 screen, u8 bg_select, u8 bg_size, u8 wraparound, u8 color_mode);
    00187 //#define PA_InitBg(screen, bg_select, bg_size, wraparound, color_mode) {    PA_bgmap[screen][bg_select] = ScreenBaseBlock(screen, ((bg_select + 1) << 3) - bg_place[bg_size]);_REG16(REG_BGSCREEN(screen)) |= (0x100 << (bg_select)); _REG16(REG_BGCNT(screen, bg_select)) = ((bg_select) | (bg_size << 14) |((((bg_select + 1) << 3) - bg_place[bg_size]) << SCREEN_SHIFT) | (wraparound << 13) | ((bg_select) << 2)) + (color_mode << 7);}
    00188
    00189
    00202 #define PA_HideBg(screen, bg_select) _REG16(REG_BGSCREEN(screen)) &= ~(0x100 << (bg_select))
    00203
    00204
    00217 #define PA_ShowBg(screen, bg_select) _REG16(REG_BGSCREEN(screen)) |= (0x100 << (bg_select))
    00218
    00219
    00229 #define PA_ResetBg(screen) _REG16(REG_BGSCREEN(screen)) &= ~(0xF00)
    00230
    00231
    00232
    00248 #define PA_LoadBgTiles(screen, bg_select, bg_tiles) PA_LoadBgTilesEx(screen, bg_select, (void*)bg_tiles, SIZEOF_16BIT(bg_tiles))
    00249 //#define PA_LoadBgTiles(screen, bg_select, bg_tiles) {DMA_Copy((void*)(bg_tiles), (void*)CharBaseBlock(screen, bg_select),SIZEOF_16BIT(bg_tiles), DMA_16NOW);}
    00250
    00251
    00271 void PA_LoadBgTilesEx(u8 screen, u8 bg_select, void* bg_tiles, u16 size);
    00272
    00273
    00289 void PA_ReLoadBgTiles(u8 screen, u8 bg_select, void* bg_tiles);
    00290
    00291
    00304 void PA_DeleteTiles(u8 screen, u8 bg_select);
    00305
    00306
    00319 void PA_DeleteMap(u8 screen, u8 bg_select);
    00320
    00321
    00322
    00335 extern inline void PA_DeleteBg(u8 screen, u8 bg_select) {
    00336        PA_HideBg(screen, bg_select);
    00337        PA_DeleteTiles(screen, bg_select);
    00338        PA_DeleteMap(screen, bg_select);
    00339 }
    00340
    00360 void PA_LoadBgMap(u8 screen, u8 bg_select, void* bg_map, u8 bg_size);
    00361
    00362
    00363
    00364
    00365
    00382 #define PA_LoadTiledBg(screen, bg_number, bg_name){\
    00383        PA_LoadBgPal(screen, bg_number, (void*)bg_name##_Pal); \
    00384        PA_LoadSimpleBg(screen, bg_number, bg_name##_Tiles, bg_name##_Map, PA_GetPAGfxBgSize(bg_name##_Width, bg_name##_Height), 0, 1);}
    00385
    00386
    00387
    00388
    00417 #define PA_LoadSimpleBg(screen, bg_select, bg_tiles, bg_map, bg_size, wraparound, color_mode) {\
    00418 PA_DeleteBg(screen, bg_select);\
    00419 PA_LoadBgTiles(screen, bg_select, bg_tiles); \
    00420 PA_LoadBgMap(screen, bg_select, (void*)bg_map, bg_size); \
    00421 PA_InitBg(screen, bg_select, bg_size, 0, color_mode);\
    00422 PA_BGScrollXY(screen, bg_select, 0, 0);}
    00423
    00424
    00425
    00450 #define PA_LoadRotBg(screen, bg_select, bg_tiles, bg_map, bg_size, wraparound) {\
    00451 PA_DeleteBg(screen, bg_select);\
    00452 PA_LoadBgTiles(screen, bg_select, bg_tiles); \
    00453 PA_LoadRotBgMap(screen, bg_select, (void*)bg_map, bg_size); \
    00454 PA_InitBg(screen, bg_select, bg_size, wraparound, 1);\
    00455 PA_SetBgRot(screen, bg_select, 0, 0, 0, 0, 0, 256);\
    00456 }
    00457
    00458 void PA_SetBgRot(u8 screen, u8 bg_select, s32 x_scroll, s32 y_scroll, s32 x_rotcentre, s32 y_rotcentre, s16 bg_angle, s32 bg_zoom);
    00459
    00491 #define PA_LoadBg(screen, bg_select, bg_tiles, tile_size, bg_map, bg_size, wraparound, color_mode) {\
    00492 PA_LoadBgTilesEx(screen, bg_select, (void*)bg_tiles, tile_size); \
    00493 PA_LoadBgMap(screen, bg_select, (void*)bg_map, bg_size); \
    00494 PA_InitBg(screen, bg_select, bg_size, 0, color_mode);\
    00495 PA_BGScrollXY(screen, bg_select, 0, 0);}
    00496
    00497
    00498
    00514 #define PA_BGScrollX(screen, bg_number, x) _REG16(REG_BGSCROLLX + ((screen) * 0x1000) + ((bg_number) << 2)) = (x)&1023
    00515
    00531 #define PA_BGScrollY(screen, bg_number, y) _REG16(REG_BGSCROLLY + ((screen) * 0x1000) + ((bg_number) << 2)) = (y)&1023
    00532
    00533
    00534
    00535
    00554 #define PA_BGScrollXY(screen, bg_number, x, y) {PA_BGScrollX(screen, bg_number, x); PA_BGScrollY(screen, bg_number, y);}
    00555
    00556
    00557
    00558
    00580 extern inline void PA_SetMapTile(u8 screen, u8 bg_select, s16 x, s16 y, s16 tile_number) {
    00581 *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) &= ~(TILE_N);
    00582 *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) |= ((tile_number)&TILE_N);
    00583 }
    00584
    00585
    00607 extern inline void PA_SetMapTileAll(u8 screen, u8 bg_select, s16 x, s16 y, u16 tile_info){
    00608        *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) = tile_info;
    00609 }
    00610
    00611
    00612
    00613
    00635 extern inline void PA_SetLargeMapTile(u8 screen, u8 bg_select, s32 x, s32 y, u32 tile_info) {
    00636        u32 truex;
    00637        u32 mapblock = 0;
    00638        truex = x&31;
    00639        mapblock = (x >> 5) << 11; // Permet d'avoir le bon block...
    00640
    00641        *(u16*)(PA_bgmap[screen][bg_select] + ((truex) << 1) + ((y) << 6) + mapblock) = tile_info;
    00642 }
    00643
    00644
    00645
    00667 #define PA_SetMapTileHflip(screen, bg_select, x, y, hflip) {*(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) &= ALL_BUT(TILE_HFLIP); *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) |= ((hflip) << 10);}
    00668
    00669
    00691 #define PA_SetMapTileVflip(screen, bg_select, x, y, vflip) {*(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) &= ALL_BUT(TILE_VFLIP); *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) |= ((vflip) << 11);}
    00692
    00693
    00715 #define PA_SetMapTilePal(screen, bg_select, x, y, palette_number) {*(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) &= ALL_BUT(TILE_PAL); *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) |= ((palette_number) << 12);}
    00716
    00717
    00748 extern inline void PA_SetMapTileEx(u8 screen, u8 bg_select, s16 x, s16 y, u16 tile_number, u8 hflip, u8 vflip, u8 palette_number) {
    00749        *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) = (tile_number) + ((hflip) << 10) + ((vflip) << 11) + ((palette_number) << 12);
    00750 }
    00751
    00752
    00753
    00766 #define PA_LoadTiledBitmap(screen, tiled_bitmap) PA_LoadBg(screen, 0, tiled_bitmap, SCREEN_TILES, bitmap, BG_256X256, 1, 1)
    00767
    00768
    00769
    00788 #define PA_LoadPAGfxRotBg(screen, bg_select, bg_name, wraparound) {\
    00789 PA_LoadNormalBgPal(screen, (void*)bg_name##_Pal);\
    00790 PA_LoadRotBg(screen, bg_select, bg_name##_Tiles, bg_name##_Map, PA_GetPAGfxRotBgSize(bg_name##_Width), wraparound);\
    00791 }
    00792
    00793
    00794
    00795
    00796
    00824 #define PA_LoadLargeBg(screen, bg_select, bg_tiles, bg_map, color_mode, lx, ly) {\
    00825 PA_LoadSimpleBg(screen, bg_select, bg_tiles, Blank, BG_512X256, 0, color_mode);\
    00826 PA_InitLargeBg(screen, bg_select, lx, ly, (void*)bg_map);}
    00827
    00828
    00829
    00830
    00846 #define PA_LoadPAGfxLargeBg(screen, bg_number, bg_name){\
    00847        PA_LoadBgPal(screen, bg_number, (void*)bg_name##_Pal); \
    00848        PA_LoadLargeBg(screen, bg_number, bg_name##_Tiles, bg_name##_Map, 1, (bg_name##_Width) >> 3, (bg_name##_Height) >> 3);}
    00849
    00850
    00851
    00882 #define PA_LoadLargeBgEx(screen, bg_select, bg_tiles, tile_size, bg_map, color_mode, lx, ly) {\
    00883 PA_LoadBg(screen, bg_select, bg_tiles, tile_size, Blank, BG_512X256, 0, color_mode);\
    00884 PA_InitLargeBg(screen, bg_select, lx, ly, (void*)bg_map);}
    00885
    00886
    00887
    00888
    00904 void PA_InfLargeScrollX(u8 screen, u8 bg_select, s32 x);
    00905
    00906
    00922 void PA_InfLargeScrollY(u8 screen, u8 bg_select, s32 y);
    00923
    00924
    00925
    00944 extern inline void PA_InfLargeScrollXY(u8 screen, u8 bg_select, s32 x, s32 y){
    00945        PA_InfLargeScrollX(screen, bg_select, x);
    00946        PA_InfLargeScrollY(screen, bg_select, y);
    00947 }
    00948
    00964 void PA_LargeScrollX(u8 screen, u8 bg_select, s32 x);
    00965
    00966
    00982 void PA_LargeScrollY(u8 screen, u8 bg_select, s32 y);
    00983
    00984
    00985
    01004 extern inline void PA_LargeScrollXY(u8 screen, u8 bg_select, s32 x, s32 y){
    01005        PA_LargeScrollX(screen, bg_select, x);
    01006        PA_LargeScrollY(screen, bg_select, y);
    01007 }
    01008
    01009
    01010
    01032 extern inline void PA_InitParallaxX(u8 screen, s32 bg0, s32 bg1, s32 bg2, s32 bg3) {
    01033         PA_parallaxX[screen][0] = bg0;
    01034         PA_parallaxX[screen][1] = bg1;
    01035         PA_parallaxX[screen][2] = bg2;
    01036         PA_parallaxX[screen][3] = bg3;
    01037 }
    01038
    01060 extern inline void PA_InitParallaxY(u8 screen, s32 bg0, s32 bg1, s32 bg2, s32 bg3) {
    01061         PA_parallaxY[screen][0] = bg0;
    01062         PA_parallaxY[screen][1] = bg1;
    01063         PA_parallaxY[screen][2] = bg2;
    01064         PA_parallaxY[screen][3] = bg3;
    01065 }
    01066
    01067
    01068
    01081 extern inline void PA_ParallaxScrollX(u8 screen, s32 x){
    01082 u8 i;
    01083        for(i = 0; i < 4; i++) {
    01084               if (PA_parallaxX[screen][i])  {
    01085                      if(scrollpos[screen][i].infscroll) PA_InfLargeScrollX(screen, i, (PA_parallaxX[screen][i] * x) >> 8); // Si bg en scrolling infini
    01086                      else PA_BGScrollX(screen, i, (PA_parallaxX[screen][i] * x) >> 8); // Sinon scrolling normal
    01087               }
    01088        }
    01089 }
    01090
    01091
    01104 extern inline void PA_ParallaxScrollY(u8 screen, s32 y){
    01105 u8 i;
    01106        for(i = 0; i < 4; i++) {
    01107               if (PA_parallaxY[screen][i])  {
    01108                      if(scrollpos[screen][i].infscroll) PA_InfLargeScrollY(screen, i, (PA_parallaxY[screen][i] * y) >> 8); // Si bg en scrolling infini
    01109                      else PA_BGScrollY(screen, i, (PA_parallaxY[screen][i] * y) >> 8); // Sinon scrolling normal
    01110               }
    01111        }
    01112 }
    01113
    01114
    01130 extern inline void PA_ParallaxScrollXY(u8 screen, s32 x, s32 y){
    01131        PA_ParallaxScrollX(screen, x);
    01132        PA_ParallaxScrollY(screen, y);
    01133 }
    01134
    01135
    01136
    01152 extern inline void PA_SetBgPrio(u8 screen, u8 bg, u8 prio) {
    01153        _REG16(REG_BGCNT(screen, bg)) &= ~3;
    01154        _REG16(REG_BGCNT(screen, bg)) |= prio;
    01155 }
    01156
    01157 extern inline void PA_CreateBgFromTiles(u8 screen, u8 bg_select, u8 bg_tiles, void *bg_map, u8 bg_size){
    01158 PA_LoadBgMap(screen, bg_select, bg_map, bg_size);
    01159 scrollpos[screen][bg_select].infscroll = 0; // Par défaut pas de scrolling infini...
    01160 PA_bgmap[screen][bg_select] = ScreenBaseBlock(screen, mapchar[screen][bg_select]);
    01161 tilesetchar[screen][bg_select] = tilesetchar[screen][bg_tiles];
    01162 tilesetsize[screen][bg_select] = tilesetsize[screen][bg_tiles];
    01163
    01164 _REG16(REG_BGSCREEN(screen)) |= (0x100 << (bg_select));
    01165 _REG16(REG_BGCNT(screen, bg_select)) = bg_select | (bg_size << 14) |(mapchar[screen][bg_select] << SCREEN_SHIFT) | (1 << 13) | (tilesetchar[screen][bg_select] << 2) | (1 << 7);
    01166 PA_BGScrollXY(screen, bg_select, 0, 0);
    01167 }
    01168
    01169
    01181 extern inline void PA_ClearBg(u8 screen, u8 bg_select){
    01182 u8 i, j;
    01183 for (i = 0; i < 32; i++) for (j = 0; j < 32; j++) PA_SetMapTileAll(screen, bg_select, i, j, 0);
    01184 }
    01185
    01186  // end of Backgrounds
    01188
    01189
    01190
    01191 // Pas utilisé en direct par le programmaeur
    01192 void PA_InitLargeBg(u8 screen, u8 bg_select, s32 lx, s32 ly, void* bg_map);
    01193
    01194
    01195
    01196 #endif
    01197