// Scrolling background stuff // Coded by Scott Evans 9/5/97 // Last modified 24/5/97 #ifndef _BACKGRND_H #define _BACKGRND_H #include #include // Structure for scrolling background maps typedef struct { _word x,y,w,h; // Display area of BG (could use RECT) _word rows,columns; // Size of BG in number of rows and columns _word xoff,yoff; // Offsets into BG _byte bw,bh; // block width and height _word u,v; // offset into tpage of first block sprite _word basecy; // Y pos of 1st CLUT GsSPRITE *blocks; // Pointer to sprites which make up background __byte *data; // BG data, which blocks go where SprHeader *hdr; }SpriteBG; // Set SpriteBG structure values #define _SetSpriteBG(P,X,Y,W,H,R,C,S,D,XO,YO,BW,BH,U,V,B,HD) \ (P)->x=(X),(P)->y=(Y),(P)->w=(W),(P)->h=(H),(P)->rows=R,(P)->columns=(C),(P)->blocks=(S),\ (P)->data=(D),(P)->xoff=(XO),(P)->yoff=(YO),(P)->bw=(BW),(P)->bh=(BH),(P)->u=(U),(P)->v=(V),\ (P)->basecy=(B),(P)->hdr=(HD) // Set up background ready for use // bg - address of background structure // sh - location of sprites which make up background // tp - texture page id of sprites // r - display area of background // cx,cy - background palette void InitSpriteBG(SpriteBG *bg,SprHeader *sh,_word tp,RECT *r,_word cx,_word cy) { static GsSPRITE block; // Get width and height of blocks _word w=_GetSprPblks(sh)->w,h=_GetSprPblks(sh)->h; // Set sprite parameters and background parameters _SetSPRITE(&block,noEffects,0,0,w,h,tp,0,0,cx,cy,0x80,0x80,0x80,0,0,ONE,ONE,0); _SetSpriteBG(bg,r->x,r->y,r->w,r->h,0,0,&block,0,0,0,w,h,0,0,cy,sh); } // Draw background made up of sprites // bg - background to draw // ot - ordering table to register background in // p - priority of background void GsSortSpriteBG(SpriteBG *bg,GsOT *ot,_word p) { _word x,y=bg->y,r,c,w=bg->w,h=bg->h,offset; _byte blkw=bg->bw,blkh=bg->bh,nprow=TPWDTH/blkw,npcol=TPHGHT/blkh; __byte blkno; // Draw the map a row at a time, going down the screen for(r=0;rx; offset=(r+bg->yoff)*w; // Calculate y offset into map for(c=0;cdata[c+offset])&0x80)) // -ve values are not drawn { bg->blocks->x=x; bg->blocks->y=y; // calculate offset into texture page bg->blocks->u=bg->u+(blkno%nprow)*nprow; bg->blocks->v=bg->v+(blkno/blkh)*blkh; bg->blocks->cy=_GetSprCLUTy(bg->hdr,blkno,bg->basecy); GsSortFastSprite(bg->blocks,ot,p); } x+=blkw; // Next block position } y+=blkh; // Next line down } } // Move map up one row #define _SpriteBGup(P,B) \ ((P)<(B)->rows-(B)->h ? ++(B)->yoff : (P)) // Move map down one row #define _SpriteBGdown(P,B) \ ((P)>0 ? --(B)->yoff : (P)) // Find sprite image number of block in level map at r,c #define _GetBlockId(b,r,c)\ ((b)->data[(((r+(b)->yoff)<<4)+((r+(b)->yoff)<<2))+(c)]) // Put a block into a level map #define _SetBlockId(b,r,c,n)\ (b)->data[(((r+(b)->yoff)<<4)+((r+(b)->yoff)<<2))+(c)]=(n) #endif