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

📄 gba.h

📁 ucos的gba移植原始版
💻 H
📖 第 1 页 / 共 2 页
字号:
#define REG_PAUSE      *(volatile u16*)0x4000300


/*
---------------------------------------------------
    BASE Globals

    System wide external variables/arrays
    (initialized in mygba_sys.c)
---------------------------------------------------
*/

extern void (*IntrTable[14])(void);

/*
---------------------------------------------------
      BG defines
      These are helper vals for the BG functions
      in HAMlib
---------------------------------------------------
*/

#define BG_0            (0)
#define BG_1            (1)
#define BG_2            (2)
#define BG_3            (3)

#define BG_PRIO_0       (0)
#define BG_PRIO_1       (1)
#define BG_PRIO_2       (2)
#define BG_PRIO_3       (3)

#define BG_ACTIVE_ON    (1)
#define BG_ACTIVE_OFF   (0)

#define BG_MOSAIC_ON    (1)
#define BG_MOSAIC_OFF   (0)

/*
---------------------------------------------------
      WIN defines
      These are helper vals for the Window functions
      in HAMlib
---------------------------------------------------
*/

#define WIN_BG0 0x01
#define WIN_BG1 0x02
#define WIN_BG2 0x04
#define WIN_BG3 0x08
#define WIN_OBJ 0x10


/*
---------------------------------------------------
      OBJ defines
      These are helper vals for the OBJ functions
      in HAMlib
---------------------------------------------------
*/

#define OBJ_MODE_NORMAL             0x00
#define OBJ_MODE_SEMITRANSPARENT    0x01
#define OBJ_MODE_OBJWINDOW          0x02

#define OBJ_SIZE_8X8                 0,0
#define OBJ_SIZE_16X16               0,1
#define OBJ_SIZE_32X32               0,2
#define OBJ_SIZE_64X64               0,3

#define OBJ_SIZE_16X8                1,0
#define OBJ_SIZE_32X8                1,1
#define OBJ_SIZE_32X16               1,2
#define OBJ_SIZE_64X32               1,3

#define OBJ_SIZE_8X16                2,0
#define OBJ_SIZE_8X32                2,1
#define OBJ_SIZE_16X32               2,2
#define OBJ_SIZE_32X64               2,3

/*
---------------------------------------------------
      Palette color defines
      These are helper vals for the Palette functions
      named ham_SetBgPalCol() and ham_SetObjPalCol()
      in HAMlib.
      Thanks to Peter Schraut for these values.
---------------------------------------------------
*/
#define COLOR_BLACK        0x0000
#define COLOR_MAROON       0x0010
#define COLOR_GREEN        0x0200
#define COLOR_OLIVE        0x0210
#define COLOR_NAVY         0x4000
#define COLOR_PURPLE       0x4010
#define COLOR_TEAL         0x4200
#define COLOR_GRAY         0x4210
#define COLOR_SILVER       0x6318
#define COLOR_RED          0x001F
#define COLOR_LIME         0x03E0
#define COLOR_YELLOW       0x03FF
#define COLOR_BLUE         0x7C00
#define COLOR_FUCHSIA      0x7C1F
#define COLOR_WHITE        0x7FFF
#define COLOR_MONEYGREEN   0x6378
#define COLOR_SKYBLUE      0x7B34
#define COLOR_CREAM        0x7BFF
#define COLOR_MEDGRAY      0x5294

/*
---------------------------------------------------
      Special FX defines
      These are helper vals for the ham_Fx functions
      in HAMlib
---------------------------------------------------
*/

// different Blending Modes available
#define FX_MODE_OFF         0
#define FX_MODE_ALPHABLEND  1
#define FX_MODE_LIGHTEN     2
#define FX_MODE_DARKEN      3

// Feed this Macro 0 or 1 to select / deselect a certain Layer
// this is a helper macro that can be used with ham_SetFxMode()
#define FX_LAYER_SELECT(BG0,BG1,BG2,BG3,OBJ,BD) \
        ( \
         (BG0)       | \
        ((BG1) << 1) | \
        ((BG2) << 2) | \
        ((BG3) << 3) | \
        ((OBJ) << 4) | \
        ((BD)  << 5)    \
        )
/*
---------------------------------------------------
      GFX defines
      Just some general stuff on GBA GFX hardware
      that is not related to any registers.
---------------------------------------------------
*/

#define GFX_MODE3_WIDTH  240
#define GFX_MODE4_WIDTH  240
#define GFX_MODE5_WIDTH  160
#define GFX_MODE3_HEIGHT 160
#define GFX_MODE4_HEIGHT 160
#define GFX_MODE5_HEIGHT 120

/*
---------------------------------------------------
      DMA defines
      Just some general stuff on GBA DMA hardware
      that is not related to any specific registers.
---------------------------------------------------
*/


#define DMA_STARTAT_NOW			0
#define DMA_STARTAT_VBL			1
#define DMA_STARTAT_HBL			2
#define DMA_STARTAT_SOUND_FIFO	3


#define DMA_TRANSFER_16BIT		0
#define DMA_TRANSFER_32BIT		1

/*
---------------------------------------------------

      Music defines
	  (GBC/GBA specific frequency table)
      Very experimental, only for playing around
	  Actually thought of removing these, but if you
	  wanna do some silly music, you might like them :)
---------------------------------------------------
*/

#define SND_FREQU_A_1		1750
#define SND_FREQU_H_1		1782
#define SND_FREQU_C_2		1797
#define SND_FREQU_CIS_2		1811
#define SND_FREQU_D_2		1824
#define SND_FREQU_DIS_2		1837
#define SND_FREQU_E_2		1849
#define SND_FREQU_F_2		1860
#define SND_FREQU_FIS_2		1870
#define SND_FREQU_G_2		1880
#define SND_FREQU_GIS_2		1890
#define SND_FREQU_A_2		1899
#define SND_FREQU_CIS_2		1811


/*
---------------------------------------------------

    Interrupt table enumeration

---------------------------------------------------
*/

#define INT_TYPE_VBL    0
#define INT_TYPE_HBL    1
#define INT_TYPE_VCNT   2
#define INT_TYPE_TIM0   3
#define INT_TYPE_TIM1   4
#define INT_TYPE_TIM2   5
#define INT_TYPE_TIM3   6
#define INT_TYPE_SIO    7
#define INT_TYPE_DMA0   8
#define INT_TYPE_DMA1   9
#define INT_TYPE_DMA2   10
#define INT_TYPE_DMA3   11
#define INT_TYPE_KEY    12
#define INT_TYPE_CART   13

/*
---------------------------------------------------

Save RAM types supported by HAMlib. See the Save RAM
documentation for details

---------------------------------------------------
*/
#define RAM_TYPE_SRAM_256K   0x00
#define RAM_TYPE_EEPROM_4K   0x01
#define RAM_TYPE_EEPROM_64K  0x02
#define RAM_TYPE_UNDEFINED   0xFF


/*
---------------------------------------------------
---------------------------------------------------

      Memory Map related

---------------------------------------------------
---------------------------------------------------
*/

/*
------------------------------
Memory Map Base locations
------------------------------
*/


//Memory locations

#define MEM_SYSROM			0x00000000	// System ROM, for BIOS Calls
#define MEM_EXRAM			0x02000000	// External WRAM, slow, also used for Multiboot uploads
#define MEM_RAM				0x03000000	// Fast CPU internal RAM
#define MEM_IO				0x04000000	// Register Base, all HW Registers are in here.
#define MEM_PAL				0x05000000	// Palette Base
#define MEM_PAL_BG			0x05000000	// Palette for BG
#define MEM_PAL_OBJ			0x05000200	// Palette for OBJ
#define MEM_VRAM			0x06000000	// GBA Video RAM
#define MEM_BG				0x06000000	// GBA Video RAM (in BG mode)
#define MEM_OBJ				0x06010000  // OBJ memoryspace (32 kBytes)
#define MEM_OAM			0x07000000	// Object control space for sprites
#define MEM_ROM0			0x08000000	// Rom Space 0 (fastest, 0 wait)
#define MEM_ROM1			0x0A000000	// Rom Space 1 (1 wait)
#define MEM_ROM2			0x0C000000	// Rom Space 2 (slowest, 2 wait)
#define MEM_EEPROM			0x0D000000	// Gamepak EEPROM, if any.
#define MEM_SRAM			0x0E000000	// Gamepak SRAM, if any.

// Base block locations
#define MEM_PAL_BG_16(x)    (MEM_PAL_BG	 + ((x)<<5))
#define MEM_PAL_OBJ_16(x)   (MEM_PAL_OBJ + ((x)<<5))

//this define returns a pointer to either the bg palette (0) or the obj palette (1)
#define MEM_PAL_256(x)      (MEM_PAL_BG	 + ((x)<<9))
//the following defines return the memory address of a color palette index
#define MEM_PAL_BG_COL_256(x)   (MEM_PAL_BG	 + ((x)<<1))
#define MEM_PAL_OBJ_COL_256(x)  (MEM_PAL_OBJ + ((x)<<1))

#define MEM_CHR_BB(x)       (MEM_BG + ((x)<<14))
#define MEM_SCR_BB(x)       (MEM_BG + ((x)<<11))
#define MEM_HAMBG_SLOT(x)   (MEM_BG + ((x)<<11))
#define MEM_OAM_ENTRY(x)	(MEM_OAM+ ((x)<<3))
#define MEM_HAMOBJ_SLOT(x)  (MEM_OBJ+ ((x)<<5))

#define MEM_SYSROM_SIZE		    0x00004000
#define MEM_EXRAM_SIZE		    0x00040000
#define MEM_RAM_SIZE		    0x00008000
#define MEM_PAL_SIZE		    0x00000400
#define MEM_VRAM_SIZE		    0x00018000
#define MEM_BG_MODE0_SIZE		0x00010000
#define MEM_BG_MODE1_SIZE		0x00010000
#define MEM_BG_MODE2_SIZE		0x00010000
#define MEM_BG_MODE3_BUFSIZE    0x00014000
#define MEM_BG_MODE4_BUFSIZE    0x0000A000
#define MEM_BG_MODE5_BUFSIZE    0x0000A000
#define MEM_BG_SIZE		        0x00010000
#define MEM_BG_SIZE		        0x00010000
#define MEM_OBJ_SIZE            0x00008000
#define MEM_OAM_SIZE		    0x00000400
#define MEM_ROM0_SIZE		    0x02000000
#define MEM_ROM1_SIZE		    0x02000000
#define MEM_ROM2_SIZE		    0x02000000
#define MEM_SRAM_SIZE		    0x00010000

// Misc important mem locations
#define MEM_SNDFIFO_A			(MEM_IO + 0xA0)
#define MEM_SNDFIFO_B			(MEM_IO + 0xA4)


// Memory Pointers
#define MEM_SYSROM_PTR			 (u8*)  0x00000000	// System ROM, for BIOS Calls
#define MEM_EXRAM_PTR			 (u8*)  0x02000000	// External WRAM, slow, also used for Multiboot uploads
#define MEM_RAM_PTR				 (u8*)  0x03000000	// Fast CPU internal RAM
#define MEM_IO_PTR				 (u8*)  0x04000000	// Register Base, all HW Registers are in here.
#define MEM_PAL_PTR				 (u16*) 0x05000000	// Palette Base
#define MEM_PAL_BG_PTR			 (u16*) 0x05000000	// Palette for BG start
#define MEM_PAL_OBJ_PTR			 (u16*) 0x05000200	// Palette for OBJ start
#define MEM_PAL_COL_PTR(x)		 (u16*) (0x05000000+(x<<1))	// Palette color pointer
#define MEM_VRAM_PTR			 (u16*) 0x06000000	// GBA Video RAM
#define MEM_BG_PTR	             (u16*) 0x06000000	// GBA Video RAM
#define MEM_BG_MODE0_PTR	     (u16*) 0x06000000	// GBA Video RAM
#define MEM_BG_MODE1_PTR	     (u16*) 0x06000000	// GBA Video RAM
#define MEM_BG_MODE2_PTR	     (u16*) 0x06000000	// GBA Video RAM
#define MEM_BG_MODE3_PTR	     (u16*) 0x06000000	// GBA Video RAM
#define MEM_BG_MODE4_PTR(buf)    (u16*) (0x06000000+ (buf) * 0xA000)	// GBA Video RAM
#define MEM_BG_MODE5_PTR(buf)    (u16*) (0x06000000+ (buf) * 0xA000)	// GBA Video RAM
#define MEM_OBJ_PTR              (u16*) 0x06010000   // OBJ memoryspace (32 kBytes)
#define MEM_OAM_PTR				 (u8*)  0x07000000	// Object control space for sprites
#define MEM_ROM0_PTR			 (u8*)  0x08000000	// Rom Space 0 (fastest, 0 wait)
#define MEM_ROM1_PTR			 (u8*)  0x0A000000	// Rom Space 1 (1 wait)
#define MEM_ROM2_PTR			 (u8*)  0x0C000000	// Rom Space 2 (slowest, 2 wait)
#define MEM_SRAM_PTR			 (u8*)  0x0E000000	// Gamepak SRAM, if any.

// Base block pointers to Screen and Character BBs

#define MEM_CHR_BB_PTR(x)       ((u8*) MEM_BG + ((x)*0x4000))
#define MEM_SCR_BB_PTR(x)       ((u8*) MEM_BG + ((x)*0x800))

// Pointers to OAM entries
#define MEM_OAM_ENTRY_PTR(x)	 ((u16*) MEM_OAM_ENTRY(x))
#define MEM_OAM_ATR0_PTR(x)		 ((u16*) (MEM_OAM_ENTRY(x)+0))
#define MEM_OAM_ATR1_PTR(x)		 ((u16*) (MEM_OAM_ENTRY(x)+2))
#define MEM_OAM_ATR2_PTR(x)		 ((u16*) (MEM_OAM_ENTRY(x)+4))
#define MEM_OAM_ROTATR_PTR(set,atrno) ((u16*) (MEM_OAM_ENTRY(set<<2)+(atrno<<3)+6))

// Base block pointers for the HAM BG memory manager

#define MEM_HAMBG_SLOT_PTR(x)       ((u16*) MEM_HAMBG_SLOT(x))
#define MEM_HAMOBJ_SLOT_PTR(x)      ((u16*) MEM_HAMOBJ_SLOT(x))

// General access for memory locations
#define ACCESS_8(location)		*(volatile u8 *)  (location)
#define ACCESS_16(location)		*(volatile u16 *) (location)
#define ACCESS_32(location)		*(volatile u32 *) (location)


// BG Macros define
#define ForceBlankon()  	setb(REG_DISPCNT ,7)
#define ForceBlankoff()  	clrb(REG_DISPCNT ,7)

#define Background0on() 	setb(REG_DISPCNT ,8)
#define Background0off()	clrb(REG_DISPCNT ,8)
                                             
#define Background1on() 	setb(REG_DISPCNT ,9)
#define Background1off()	clrb(REG_DISPCNT ,9)

#define Background2on() 	setb(REG_DISPCNT ,10)
#define Background2off()	clrb(REG_DISPCNT ,10)

#define Background3on() 	setb(REG_DISPCNT ,11)
#define Background3off()	clrb(REG_DISPCNT ,11)

#define Objectson()  	 	setb(REG_DISPCNT ,12)
#define Objectsoff()    	clrb(REG_DISPCNT ,12)

#define Set_Mode0()     	REG_DISPCNT &= 0xFFF8
#define Set_Mode1()     	REG_DISPCNT |= 0x0001; \
						REG_DISPCNT &= 0xFFF9
#define Set_Mode2()     	REG_DISPCNT |= 0x0002; \
						REG_DISPCNT &= 0xFFFA
#define Set_Mode3()     	REG_DISPCNT |= 0x0003; \
						REG_DISPCNT &= 0xFFFB
#define Set_Mode4()     	REG_DISPCNT |= 0x0004; \
						REG_DISPCNT &= 0xFFFC
#define Set_Mode5()     	REG_DISPCNT |= 0x0005; \
						REG_DISPCNT &= 0xFFFD

// key input mask
#define KEY_L		9	// L			
#define KEY_R		8	 // R       
#define KEY_DWN		7	 // DOWN    
#define KEY_UP		6  	// UP      
#define KEY_LF		5 	// LF      
#define KEY_RT		4	// RT      
#define KEY_ST		3	// START   
#define KEY_SL		2	// SELECT  
#define KEY_B		1	// B       
#define KEY_A		0	// A       

#ifdef __cplusplus
}
#endif

#endif

⌨️ 快捷键说明

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