⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gbass.c

📁 This a GBA(Game Boy Advance) animation sample code. It continue and reverse display 45 BMPs on GBA s
💻 C
字号:
#include <Agb.h>
#include "../Compatible.h"

#define img_width	(160)
#define img_height	(88)
#define scr_width	(240)
#define scr_height	(160)

#define Mode4_Page0 		(u8 *)VRAM
#define Mode4_Page1 		((u8 *)VRAM+0xA000)

void VBlankIntr(void);
/*-------------------- Global Variables ----------------------------*/

    u16      Cont, Trg;                  // Key input

    u32      IntrMainBuf[0x200];         // Buffer for interrupt main routine

    u16      BgBak[32*32];               // BG backup
    OamData  OamBak[128];                // OAM backup

extern void intr_main(void);
extern const u16 img01[];
extern const u16 img01pal[];

/*------------------------------------------------------------------*/
/*                      Interrupt Table                             */
/*------------------------------------------------------------------*/
typedef void (*IntrFuncp)(void);
void IntrDummy(void);
void VBlankIntr(void);

const IntrFuncp IntrTable[13] = {
    VBlankIntr,     // V Blank interrupt
    IntrDummy,      // H Blank interrupt
    IntrDummy,      // V Counter interrupt
    IntrDummy,      // Timer 0 interrupt
    IntrDummy,      // Timer 1 interrupt
    IntrDummy,      // Timer 2 interrupt
    IntrDummy,      // Timer 3 interrupt
    IntrDummy,      // Serial communication interrupt
    IntrDummy,      // DMA 0 interrupt
    IntrDummy,      // DMA 1 interrupt
    IntrDummy,      // DMA 2 interrupt
    IntrDummy,      // DMA 3 interrupt
    IntrDummy,      // Key interrupt
};

//==================================================================================
void showpic(int x, int y,void *pPic, void *pPal, u8 VideoPage)
{
	u8   loop;
	void *addr,*ppp;

	if(VideoPage==0)
		//SetMode( DISP_MODE_4 | DISP_BG2_ON );
		SetMode( 0x0404 );
	else
		//SetMode( DISP_MODE_4 | DISP_BG2_ON | 0x10 );
		SetMode( 0x0414 );

	//memcpy( (void *)BGPaletteMem, (void *)pPal, sizeof(u16)*256 );
	DmaCopy(3, (void *)pPal, (void *)PLTT, 512 ,16);
	
	addr=(void *)(y*scr_width+x+(VideoPage==0 ? Mode4_Page0 : Mode4_Page1 ) );
	ppp=pPic;
	
	for(loop=0; loop<img_height; loop++)
	{
		//memcpy( addr, ppp, img_width);
		DmaCopy( 3, ppp, addr, (img_width) ,16);
		ppp+=img_width;
		addr+=scr_width;
	}
	
	WaitVBL;
}
//==================================================================================
void delay1(int loop)
{
	int x,y,tmp;
	
	for(x=0; x<loop ; x++)
		for(y=0; y<13000 ; y++)
		    tmp=x;
}
//==================================================================================
int AgbMain()
{
	int idx,x,y,piccount;
	void *imgAddr=&img01;
	void *palAddr=&img01pal;

	DmaClear(3, 0,   EX_WRAM,  EX_WRAM_SIZE,         32);  // Clear external CPU work RAM
	DmaClear(3, 0,   CPU_WRAM, CPU_WRAM_SIZE - 0x200,32);  // Clear internal CPU work RAM
	DmaCopy(3, intr_main, IntrMainBuf, sizeof(IntrMainBuf), 32);// Interrupt main routine set
	
	SetMode(DISP_LCDC_OFF);

	piccount = 45;
	x=40;
	y=36;
	
	while(1)
	{
		for(idx=10; idx<piccount; idx++)
		{
			showpic(x,y, (void *)imgAddr+idx*14592, (void *)palAddr+idx*14592, (idx&1) );
			delay1(2);
		}

		for(idx=piccount-1; idx>=10; idx--)
		{
			showpic(x,y, (void *)imgAddr+idx*14592, (void *)palAddr+idx*14592, (idx&1) );
			delay1(2);
		}
	}	
}
/*------------------------------------------------------------------*/
/*                      V Blank Process                             */
/*------------------------------------------------------------------*/

void VBlankIntr(void)
{
   DmaArrayCopy(3, BgBak,  BG_VRAM, 32);           // Set BG screen
    DmaArrayCopy(3, OamBak, OAM,     32);           // Set OAM

    *(u16 *)INTR_CHECK_BUF = V_BLANK_INTR_FLAG;     // Set V Blank interrupt check
}
/*------------------------------------------------------------------*/
/*                      Interrupt Dummy Routine                     */
/*------------------------------------------------------------------*/

void IntrDummy(void)
{
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -