// BGmap viewer v1.0 (c) 1998 James Shaughnessy // Serves as a simple example of how to have // a BgMap in your own games. // // Shows BGEDIT 8-bit raw map format data. // Requires both MAP.DAT and CELLS.TIM, the // 8-bit CLUT cell info image file. Ensure // image/clut are located safely on the frame // buffer, (320,0)/(320,256) is OK. // Note: BGmap cells MUST be 4 or 8-bit CLUT, // 15-bit direct is not supported by Net Yaroze. // // Default is 256x256 cells. Change NCELLW // and NCELLH defines below for different // map sizes. They can be hyouge! // // Cheers, // Jim // ----------------------------------------- // James Shaughnessy james@manc.u-net.com // http://www.netyaroze-europe.com/~shaughnj // ----------------------------------------- #include #include "pad.h" #define OT_LENGTH (1) #define NUM_SPRITES (1+1) #define MAP_ADDR (0x80090000) #define TILES_ADDR (0x800A0000) #define SCREENW (320) #define SCREENH (256) #define NCELLW (256) #define NCELLH (256) #define NUMCELLS (256) // BG work base primitive area u_long bgworkbase[(((SCREENW/16+1)*(SCREENH/16+2)*6+4)*2+2)]; // Two Ordering Tables, one for each buffer GsOT WorldOT[2]; // Two Ordering Table Tags, one for each buffer GsOT_TAG OTTag[2][1< (NCELLW<<4)-1) gsbg.scrollx -= (NCELLW<<4); if (gsbg.scrolly < 0) gsbg.scrolly += (NCELLH<<4); else if (gsbg.scrolly > (NCELLH<<4)-1) gsbg.scrolly -= (NCELLH<<4); } // Initialise Background map void InitBg() { RECT r; GsIMAGE im; int i; GsGetTimInfo((u_long *)TILES_ADDR+1, &im); setRECT(&r, im.px, im.py, im.pw, im.ph); LoadImage(&r, im.pixel); setRECT(&r, im.cx, im.cy, im.cw, im.ch); LoadImage(&r, im.clut); DrawSync(0); for (i=0; i < NUMCELLS; i++) { gscell[i].u = ((i%16)<<4); gscell[i].v = ((i/16)<<4); gscell[i].cba = GetClut(im.cx, im.cy); gscell[i].tpage = GetTPage(im.pmode, 0, im.px, im.py); } gsmap.cellw = 16; gsmap.cellh = 16; gsmap.ncellw = NCELLW; gsmap.ncellh = NCELLH; gsmap.base = gscell; gsmap.index = map; gsbg.attribute = (im.pmode<<24); gsbg.x = 0; gsbg.y = 0; gsbg.w = SCREENW; gsbg.h = SCREENH; gsbg.scrollx = (127<<4) - 160; gsbg.scrolly = (127<<4) - 128; gsbg.r = gsbg.g = gsbg.b = 128; gsbg.map = &gsmap; GsInitFixBg16(&gsbg, bgworkbase); // Loads map data from MAP_ADDR into map[] array by default LoadMapData(); } // Loads map data (map.dat) from MAP_ADDR into map[] array void LoadMapData() { int i; u_char *pmap = (u_char *)MAP_ADDR; // NULL cell (transparent) map[i] = 0xffff // This is set as index ZERO in map.dat // Set map array to that of map.dat file for (i = 0; i < (NCELLW*NCELLH); i++) { if (pmap[i]) map[i] = pmap[i]; else map[i] = 0xffff; } } // Initialises Video and the Frame Buffer void InitGraphics() { int i; // Setup graphics PAL 320x256 SetVideoMode(MODE_PAL); GsInitGraph(SCREENW, SCREENH, 4, 0, 0); GsDISPENV.screen.y = 20; GsDISPENV.screen.h = SCREENH; GsDefDispBuff(0, 0, 0, 256); // Init Ordering Tables for (i = 0; i < 2; i++) { WorldOT[i].length = OT_LENGTH; WorldOT[i].org = OTTag[i]; GsClearOt(0, 0, &WorldOT[i]); } // Loads the debug font into Frame Buffer FntLoad(960, 256); // Font printing location FntOpen(18, 20, 240, 236, 0, 512); } // ****** PAD routines ****** // call once only in program initialisation void PadInit (void) { GetPadBuf(&bb0, &bb1); } // call once per VSync(0) // puts controller pad status into unsigned long integer // please refer to the manuals if you want explanation // of the internals of this function u_long PadRead(void) { return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); }