Thbg

From ProjectWiki
Revision as of 13:52, 1 February 2009 by 74.241.20.41 (Talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
typedef void(*_pBgStartFunc)(void);	//Background Setup Function (called first)
typedef void(*_pBgUpdateFunc)(int);	//Background update function
typedef void(*_pBgFinishFunc)(void);	//Background destroy function 
 
typedef struct {
	_pBgStartFunc 	start;
	_pBgUpdateFunc	update;
	_pBgFinishFunc	finish;
	void 		*bgdat;		//background set specific data
} thbg_t;
 
void thBgInit(void);		//get everything ready
void thBgUpdate(int frame);	//call this every vblank
void thBgStart(thbg_t *thbg);	//call this to start a bg (will first stop any already running)
void thBgFinish(void);		//stops bg, erases bg mem, etc
 
void thUpdateBgPalette(uint16 *pal, int dstpal, int size);
void thUpdateBgSubPalette(uint16 *pal, int dstpal, int size);
 
 
 
//Note there rly shouldnt ever be > 4 bg loaded at a time
//aslo map allocs grow from top downward...
#define THMAXBGTILES	(128/16)	//max tile slots (128K / 16K tile slot boundries)
#define THMAXBGMAPS	31		//max map slots (128K / 1K map slot boundries)
 
//for thBgLoad
#define BGDEFAULTS	-1
 
typedef struct _THBG_T {
	int	map;
	int	tilealloc;	//tiles grow from top of vram.. 
	int	tile;
	bool	used;
} THBG_T;
 
#define THMAXBG	0x4	//each screen only has up to 4 bg right?
#define THMAXSCR 0x2
 
//macro to find proper bg control reg
#define BGCR(s,b) (*(vuint16*)(0x04000008+((s)<<12)+((b)<<1)))
#define BGX(s,b) (*(vuint16*)(0x04000010+((s)<<12)+((b)<<2)))
#define BGY(s,b) (*(vuint16*)(0x04000012+((s)<<12)+((b)<<2)))
 
 
//bitmap same as tile 0x4000 boundries ^^
#define BGBMPRAM(s,b)  (((b)<<14) + 0x06000000+((s)<<21))
#define BGTILERAM(s,b) (((b)<<14) + 0x06000000+((s)<<21))
#define BGMAPRAM(s,b)  (((b)<<11) +  0x06000000+((s)<<21))
#define DISPLAYCR(s)       (*(vuint32*)(0x04000000+((s)<<12)))
 
enum {
	BGNORMAL=0,
	BGROTSCALE=1,
	BGBMP=2
};
 
#define thBgSetMode(m) ((*(vuint32*)0x04000000)=((*(vuint32*)0x04000000)&0xfffffff8)|(m))
#define thBgGetMode() ((*(vuint32*)0x04000000)&0x7)
#define thBgSetModeSub(m) ((*(vuint32*)0x04001000)=((*(vuint32*)0x04001000)&0xfffffff8)|(m))
#define thBgGetModeSub() ((*(vuint32*)0x04001000)&0x7)
 
extern THBG_T thbgs[THMAXSCR][THMAXBG];
 
 
//Macros to get the allocated tile and map locations for a particular screen
#define thBgTile(s,b) (thbgs[(s)][(b)].tile)
#define thBgMap(s,b) (thbgs[(s)][(b)].map)
 
inline void thBgEnable(int screen, int bg);
 
inline void thBgDisable(int screen, int bg);
 
//This is exactly the same malloc scheme i keep ripping off from vram malloc... rly i should just make a universal malloc code and consolidate all these...
//vram alloc element
typedef struct _bgre {
	u16	size;	//in tiles
	u16	tile;
	bool	used;
	struct _bgre *next;
} bgre;
 
void setBgVBlank(void);		//set the BgVblank int
void vblankInt(void);		//this function needs to be called during vblank, calling setBgVBlank() sets this as vblank interrupt..
 
void thBgVramAllocInit(void);		//alloc init (called in bg init)
inline int thBgMAlloc(int screen, u32 size);	//bg map alloc (size in map slots 0x800 boundries)
inline int thBgTAlloc(int screen, u32 size);	//bg tile alloc (size in tile slots 0x4000 bounds)
inline bool thBgMFree(int screen, int map);	//free for each of above 
inline bool thBgTFree(int screen, int tile);
bool thBgCreateAlloc(int screen, int bg, int tilesize, int mapsize);	//alloc for both tiles and maps, and store values into bg table
bool thBgCreate(int screen, int bg, u16 bgnfo, u16 *tiles, int tilesize, u16 *map, int mapsize);
bool thBgLoad(int screen, int bg, const char *fileprefix, int opts);
bool thBgDestroy(int screen, int bg); //frees any used vram, and otherwise disables specified background.. returns true if bg exists
void thBgSetRotScale(int screen, int bg, u16 angle, int xmag, int ymag, u32 scrollx, u32 scrolly, u32 xc, u32 yc);
Personal tools
irssi scripts
eggdrop scripts