PAlib: PA_Tile.h Source File

Main Page | Modules | File List | Globals | Search for

# PA_Tile.h

Go to the documentation of this file.

    00001 #ifndef _PA_Tile
    00002 #define _PA_Tile
    00003
    00004
    00005
    00006 // Extracts the size from PAGfx convertions
    00007 extern inline u8 PA_GetPAGfxBgSize(u16 width, u16 height)
    00008 {
    00009        u8 bg_size = 0;
    00010        if (height == 512)   bg_size = 2;
    00011        if (width == 512)    bg_size ++;
    00012        return bg_size;
    00013 }
    00014
    00015 // Extracts the size from PAGfx convertions
    00016 extern inline u8 PA_GetPAGfxRotBgSize(u16 width)
    00017 {
    00018        u8 bg_size = 1; //256x256 by default
    00019        if (width <= 128)    bg_size = 0;
    00020        else if (width <= 256)      bg_size = 1;
    00021        else if (width <= 512)      bg_size = 2;
    00022        else if (width <= 1024) bg_size = 3;
    00023
    00024        return bg_size;
    00025 }
    00026
    00033 //#include "../PA.h"
    00034
    00035
    00036
    00038 // Système de Tiles
    00040
    00041
    00042 //background memory offset macros
    00043 #define CharBaseBlock(screen, n) (((n)*0x4000) + 0x6000000 + (0x200000 *  screen))
    00044 #define ScreenBaseBlock(screen, n) (((n)*0x800) + 0x6000000 + (0x200000 *  screen))
    00045 extern u32 PA_bgmap[2][4]; // Pointeur vers les maps, 4 maps par screen
    00046 extern u8 tilesetchar[2][4];
    00047
    00048 // Quantité de données à charger en fonction de la taille de la map...
    00049 extern u16 bg_sizes[4];
    00050 extern u8 bg_place[4];
    00051
    00052 extern u16 *PA_DrawBg[2]; // Fond dessinable
    00053
    00054
    00055 extern bool charblocks[2][70];
    00056 extern u16 tilesetsize[2][4]; // Place utilisée pour chaque tileset
    00057 extern u16 mapsize[2][4]; // Place utilisée pour chaque map
    00058 extern u8 tilesetchar[2][4];  // Emplacement mémoire de chaque tileset
    00059 extern u8 mapchar[2][4];  // Emplacement mémoire de chaque map
    00060
    00061 extern u8 charsetstart[2];
    00062
    00063
    00064
    00065
    00066
    00067 extern s32 PA_parallaxX[2][4];
    00068 extern s32 PA_parallaxY[2][4];
    00069
    00070
    00071
    00072
    00073 typedef struct {
    00074        bool infscroll; // Passe à 1 si scrolling infini activé...
    00075        u16* bg_map; // Map
    00076 //     s32 x, y;
    00077        s32 lx, ly;
    00078        s32 scrollx, scrolly;
    00079        s32 maxx; // 32 ou 64, en fonction de la largeur...
    00080 //     s32 startx, starty;
    00081 }scrollpositions;
    00082
    00083 extern scrollpositions scrollpos[2][4]; // Pour chaque écran et pour chaque fond :)
    00084
    00085
    00086
    00087
    00088
    00089
    00090 // Mode de couleur
    00091 #define BG_COLOR16 0x00
    00092 #define BG_COLOR256 0x80
    00093
    00094
    00095 #define CHAR_SHIFT 2
    00096 #define SCREEN_SHIFT 8
    00097 #define WRAPAROUND 0x1
    00098
    00099 #define SCREEN_TILES 24576  // Taille à convertir pour avoir un écran complet...
    00100
    00101
    00102 //scrolling registers for background 0
    00103
    00104
    00105 // Registre pour les controles de chaque écran
    00106
    00107 #define REG_BGSCREEN0  0x04000000
    00108 #define REG_BGSCREEN1  0x04001000
    00109 #define REG_BGSCREEN(screen) (0x04000000 + (screen * 0x1000))
    00110
    00111 #define REG_BGCNT(screen, bg_number) (0x4000008 + (screen * 0x1000) + (bg_number << 1))
    00112
    00113 // Premier registre pour les scroll. On en déduit les autres en ajoutant pour le screen et le numéro du Bg
    00114 #define REG_BGSCROLLX 0x4000010
    00115 #define REG_BGSCROLLY 0x4000012
    00116
    00117
    00118 // Tailles pour les Bg :
    00119 #define BG_256X256 0
    00120 #define BG_512X256 1
    00121 #define BG_256X512 2
    00122 #define BG_512X512 3
    00123
    00124 #define BG_ROT_128X128 0
    00125 #define BG_ROT_256X256 1
    00126 #define BG_ROT_512X512 2
    00127 #define BG_ROT_1024X1024 3
    00128
    00129 void PA_LoadRotBgMap(bool screen, u8 bg_select, void* bg_map, u8 bg_size);
    00130
    00131
    00132 //ALL_BUT() pour faire tout sauf...
    00133 #define TILE_N 1023
    00134 #define TILE_PAL 61440
    00135 #define TILE_HFLIP 1024
    00136 #define TILE_VFLIP 2048
    00137
    00138 #define PA_BGXX(screen, bg) _REG32(0x4000008 + (0x1000 * screen) + (bg << 4))
    00139 #define PA_BGXY(screen, bg) _REG32(0x400000C + (0x1000 * screen) + (bg << 4))
    00140 #define PA_BGXPA(screen, bg) _REG16(0x4000000 + (0x1000 * screen) + (bg << 4))
    00141 #define PA_BGXPB(screen, bg) _REG16(0x4000002 + (0x1000 * screen) + (bg << 4))
    00142 #define PA_BGXPC(screen, bg) _REG16(0x4000004 + (0x1000 * screen) + (bg << 4))
    00143 #define PA_BGXPD(screen, bg) _REG16(0x4000006 + (0x1000 * screen) + (bg << 4))
    00144
    00145
    00146
    00147
    00148
    00160 void PA_ResetBgSys(void);
    00161
    00184 void PA_InitBg(bool screen, u8 bg_select, u8 bg_size, bool wraparound, bool color_mode);
    00185 //#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);}
    00186
    00187
    00200 #define PA_HideBg(screen, bg_select) _REG16(REG_BGSCREEN(screen)) &= ~(0x100 << (bg_select))
    00201
    00202
    00215 #define PA_ShowBg(screen, bg_select) _REG16(REG_BGSCREEN(screen)) |= (0x100 << (bg_select))
    00216
    00217
    00227 #define PA_ResetBg(screen) _REG16(REG_BGSCREEN(screen)) &= ~(0xF00)
    00228
    00229
    00230
    00246 #define PA_LoadBgTiles(screen, bg_select, bg_tiles) PA_LoadBgTilesEx(screen, bg_select, (void*)bg_tiles, SIZEOF_16BIT(bg_tiles))
    00247 //#define PA_LoadBgTiles(screen, bg_select, bg_tiles) {DMA_Copy((void*)(bg_tiles), (void*)CharBaseBlock(screen, bg_select),SIZEOF_16BIT(bg_tiles), DMA_16NOW);}
    00248
    00249
    00269 void PA_LoadBgTilesEx(bool screen, u8 bg_select, void* bg_tiles, u16 size);
    00270
    00271
    00287 void PA_ReLoadBgTiles(bool screen, u8 bg_select, void* bg_tiles);
    00288
    00289
    00302 void PA_DeleteTiles(bool screen, u8 bg_select);
    00303
    00304
    00317 void PA_DeleteMap(bool screen, u8 bg_select);
    00318
    00319
    00320
    00333 extern inline void PA_DeleteBg(bool screen, u8 bg_select) {
    00334        PA_HideBg(screen, bg_select);
    00335        PA_DeleteTiles(screen, bg_select);
    00336        PA_DeleteMap(screen, bg_select);
    00337 }
    00338
    00358 void PA_LoadBgMap(bool screen, u8 bg_select, void* bg_map, u8 bg_size);
    00359
    00360
    00361
    00362
    00363
    00380 #define PA_LoadTiledBg(screen, bg_number, bg_name){\
    00381        PA_LoadBgPal(screen, bg_number, (void*)bg_name##_Pal); \
    00382        PA_LoadSimpleBg(screen, bg_number, bg_name##_Tiles, bg_name##_Map, PA_GetPAGfxBgSize(bg_name##_Width, bg_name##_Height), 0, 1);}
    00383
    00384
    00385
    00386
    00415 #define PA_LoadSimpleBg(screen, bg_select, bg_tiles, bg_map, bg_size, wraparound, color_mode) {\
    00416 PA_DeleteBg(screen, bg_select);\
    00417 PA_LoadBgTiles(screen, bg_select, bg_tiles); \
    00418 PA_LoadBgMap(screen, bg_select, (void*)bg_map, bg_size); \
    00419 PA_InitBg(screen, bg_select, bg_size, 0, color_mode);\
    00420 PA_BGScrollXY(screen, bg_select, 0, 0);}
    00421
    00422
    00423
    00448 #define PA_LoadRotBg(screen, bg_select, bg_tiles, bg_map, bg_size, wraparound) {\
    00449 PA_DeleteBg(screen, bg_select);\
    00450 PA_LoadBgTiles(screen, bg_select, bg_tiles); \
    00451 PA_LoadRotBgMap(screen, bg_select, (void*)bg_map, bg_size); \
    00452 PA_InitBg(screen, bg_select, bg_size, wraparound, 1);\
    00453 PA_SetBgRot(screen, bg_select, 0, 0, 0, 0, 0, 256);\
    00454 }
    00455
    00456 void PA_SetBgRot(bool screen, u8 bg_select, s32 x_scroll, s32 y_scroll, s32 x_rotcentre, s32 y_rotcentre, s16 bg_angle, s32 bg_zoom);
    00457
    00489 #define PA_LoadBg(screen, bg_select, bg_tiles, tile_size, bg_map, bg_size, wraparound, color_mode) {\
    00490 PA_LoadBgTilesEx(screen, bg_select, (void*)bg_tiles, tile_size); \
    00491 PA_LoadBgMap(screen, bg_select, (void*)bg_map, bg_size); \
    00492 PA_InitBg(screen, bg_select, bg_size, 0, color_mode);\
    00493 PA_BGScrollXY(screen, bg_select, 0, 0);}
    00494
    00495
    00496
    00512 #define PA_BGScrollX(screen, bg_number, x) _REG16(REG_BGSCROLLX + ((screen) * 0x1000) + ((bg_number) << 2)) = (x)&1023
    00513
    00529 #define PA_BGScrollY(screen, bg_number, y) _REG16(REG_BGSCROLLY + ((screen) * 0x1000) + ((bg_number) << 2)) = (y)&1023
    00530
    00531
    00532
    00533
    00552 #define PA_BGScrollXY(screen, bg_number, x, y) {PA_BGScrollX(screen, bg_number, x); PA_BGScrollY(screen, bg_number, y);}
    00553
    00554
    00555
    00556
    00578 extern inline void PA_SetMapTile(bool screen, u8 bg_select, s16 x, s16 y, s16 tile_number) {
    00579 *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) &= ALL_BUT(TILE_N);
    00580 *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) |= ((tile_number)&TILE_N);
    00581 }
    00582
    00583
    00605 extern inline void PA_SetMapTileAll(bool screen, u8 bg_select, s16 x, s16 y, u16 tile_info){
    00606        *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) = tile_info;
    00607 }
    00608
    00609
    00610
    00611
    00633 extern inline void PA_SetLargeMapTile(bool screen, u8 bg_select, s32 x, s32 y, u32 tile_info) {
    00634        u32 truex;
    00635        u32 mapblock = 0;
    00636        truex = x&31;
    00637        mapblock = (x >> 5) << 11; // Permet d'avoir le bon block...
    00638
    00639        *(u16*)(PA_bgmap[screen][bg_select] + ((truex) << 1) + ((y) << 6) + mapblock) = tile_info;
    00640 }
    00641
    00642
    00643
    00665 #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);}
    00666
    00667
    00689 #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);}
    00690
    00691
    00713 #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);}
    00714
    00715
    00746 extern inline void PA_SetMapTileEx(bool screen, u8 bg_select, s16 x, s16 y, u16 tile_number, bool hflip, bool vflip, u8 palette_number) {
    00747        *(u16*)(PA_bgmap[screen][bg_select] + ((x) << 1) + ((y) << 6)) = (tile_number) + ((hflip) << 10) + ((vflip) << 11) + ((palette_number) << 12);
    00748 }
    00749
    00750
    00751
    00764 #define PA_LoadTiledBitmap(screen, tiled_bitmap) PA_LoadBg(screen, 0, tiled_bitmap, SCREEN_TILES, bitmap, BG_256X256, 1, 1)
    00765
    00766
    00767
    00786 #define PA_LoadPAGfxRotBg(screen, bg_select, bg_name, wraparound) {\
    00787 PA_LoadNormalBgPal(screen, (void*)bg_name##_Pal);\
    00788 PA_LoadRotBg(screen, bg_select, bg_name##_Tiles, bg_name##_Map, PA_GetPAGfxRotBgSize(bg_name##_Width), wraparound);\
    00789 }
    00790
    00791
    00792
    00793
    00794
    00822 #define PA_LoadLargeBg(screen, bg_select, bg_tiles, bg_map, color_mode, lx, ly) {\
    00823 PA_LoadSimpleBg(screen, bg_select, bg_tiles, Blank, BG_512X256, 0, color_mode);\
    00824 PA_InitLargeBg(screen, bg_select, lx, ly, (void*)bg_map);}
    00825
    00826
    00827
    00828
    00844 #define PA_LoadPAGfxLargeBg(screen, bg_number, bg_name){\
    00845        PA_LoadBgPal(screen, bg_number, (void*)bg_name##_Pal); \
    00846        PA_LoadLargeBg(screen, bg_number, bg_name##_Tiles, bg_name##_Map, 1, (bg_name##_Width) >> 3, (bg_name##_Height) >> 3);}
    00847
    00848
    00849
    00880 #define PA_LoadLargeBgEx(screen, bg_select, bg_tiles, tile_size, bg_map, color_mode, lx, ly) {\
    00881 PA_LoadBg(screen, bg_select, bg_tiles, tile_size, Blank, BG_512X256, 0, color_mode);\
    00882 PA_InitLargeBg(screen, bg_select, lx, ly, (void*)bg_map);}
    00883
    00884
    00885
    00886
    00902 void PA_InfLargeScrollX(bool screen, u8 bg_select, s32 x);
    00903
    00904
    00920 void PA_InfLargeScrollY(bool screen, u8 bg_select, s32 y);
    00921
    00922
    00923
    00942 extern inline void PA_InfLargeScrollXY(bool screen, u8 bg_select, s32 x, s32 y){
    00943        PA_InfLargeScrollX(screen, bg_select, x);
    00944        PA_InfLargeScrollY(screen, bg_select, y);
    00945 }
    00946
    00962 void PA_LargeScrollX(bool screen, u8 bg_select, s32 x);
    00963
    00964
    00980 void PA_LargeScrollY(bool screen, u8 bg_select, s32 y);
    00981
    00982
    00983
    01002 extern inline void PA_LargeScrollXY(bool screen, u8 bg_select, s32 x, s32 y){
    01003        PA_LargeScrollX(screen, bg_select, x);
    01004        PA_LargeScrollY(screen, bg_select, y);
    01005 }
    01006
    01007
    01008
    01030 extern inline void PA_InitParallaxX(bool screen, s32 bg0, s32 bg1, s32 bg2, s32 bg3) {
    01031         PA_parallaxX[screen][0] = bg0;
    01032         PA_parallaxX[screen][1] = bg1;
    01033         PA_parallaxX[screen][2] = bg2;
    01034         PA_parallaxX[screen][3] = bg3;
    01035 }
    01036
    01058 extern inline void PA_InitParallaxY(bool screen, s32 bg0, s32 bg1, s32 bg2, s32 bg3) {
    01059         PA_parallaxY[screen][0] = bg0;
    01060         PA_parallaxY[screen][1] = bg1;
    01061         PA_parallaxY[screen][2] = bg2;
    01062         PA_parallaxY[screen][3] = bg3;
    01063 }
    01064
    01065
    01066
    01079 extern inline void PA_ParallaxScrollX(bool screen, s32 x){
    01080 u8 i;
    01081        for(i = 0; i < 4; i++) {
    01082               if (PA_parallaxX[screen][i])  {
    01083                      if(scrollpos[screen][i].infscroll) PA_InfLargeScrollX(screen, i, (PA_parallaxX[screen][i] * x) >> 8); // Si bg en scrolling infini
    01084                      else PA_BGScrollX(screen, i, (PA_parallaxX[screen][i] * x) >> 8); // Sinon scrolling normal
    01085               }
    01086        }
    01087 }
    01088
    01089
    01102 extern inline void PA_ParallaxScrollY(bool screen, s32 y){
    01103 u8 i;
    01104        for(i = 0; i < 4; i++) {
    01105               if (PA_parallaxY[screen][i])  {
    01106                      if(scrollpos[screen][i].infscroll) PA_InfLargeScrollY(screen, i, (PA_parallaxY[screen][i] * y) >> 8); // Si bg en scrolling infini
    01107                      else PA_BGScrollY(screen, i, (PA_parallaxY[screen][i] * y) >> 8); // Sinon scrolling normal
    01108               }
    01109        }
    01110 }
    01111
    01112
    01128 extern inline void PA_ParallaxScrollXY(bool screen, s32 x, s32 y){
    01129        PA_ParallaxScrollX(screen, x);
    01130        PA_ParallaxScrollY(screen, y);
    01131 }
    01132
    01133
    01134
    01150 extern inline void PA_SetBgPrio(bool screen, u8 bg, u8 prio) {
    01151        _REG16(REG_BGCNT(screen, bg)) &= ~3;
    01152        _REG16(REG_BGCNT(screen, bg)) |= prio;
    01153 }
    01154
    01155 extern inline void PA_CreateBgFromTiles(bool screen, u8 bg_select, u8 bg_tiles, void *bg_map, u8 bg_size){
    01156 PA_LoadBgMap(screen, bg_select, bg_map, bg_size);
    01157 scrollpos[screen][bg_select].infscroll = 0; // Par défaut pas de scrolling infini...
    01158 PA_bgmap[screen][bg_select] = ScreenBaseBlock(screen, mapchar[screen][bg_select]);
    01159 tilesetchar[screen][bg_select] = tilesetchar[screen][bg_tiles];
    01160 tilesetsize[screen][bg_select] = tilesetsize[screen][bg_tiles];
    01161
    01162 _REG16(REG_BGSCREEN(screen)) |= (0x100 << (bg_select));
    01163 _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);
    01164 PA_BGScrollXY(screen, bg_select, 0, 0);
    01165 }
    01166
    01167
    01179 extern inline void PA_ClearBg(bool screen, u8 bg_select){
    01180 u8 i, j;
    01181 for (i = 0; i < 32; i++) for (j = 0; j < 32; j++) PA_SetMapTileAll(screen, bg_select, i, j, 0);
    01182 }
    01183
    01184  // end of Backgrounds
    01186
    01187
    01188
    01189 // Pas utilisé en direct par le programmaeur
    01190 void PA_InitLargeBg(bool screen, u8 bg_select, s32 lx, s32 ly, void* bg_map);
    01191
    01192
    01193
    01194 #endif
    01195