📄 gba.h
字号:
#define REG_TM0D *(volatile u16*)0x4000100
#define REG_TM0CNT *(volatile u16*)0x4000102
#define REG_TM1D *(volatile u16*)0x4000104
#define REG_TM1CNT *(volatile u16*)0x4000106
#define REG_TM2D *(volatile u16*)0x4000108
#define REG_TM2CNT *(volatile u16*)0x400010A
#define REG_TM3D *(volatile u16*)0x400010C
#define REG_TM3CNT *(volatile u16*)0x400010E
#define REG_SCD0 *(volatile u16*)0x4000120
#define REG_SCD1 *(volatile u16*)0x4000122
#define REG_SCD2 *(volatile u16*)0x4000124
#define REG_SCD3 *(volatile u16*)0x4000126
#define REG_SCCNT *(volatile u32*)0x4000128
#define REG_SCCNT_L *(volatile u16*)0x4000128
#define REG_SCCNT_H *(volatile u16*)0x400012A
#define REG_P1 *(volatile u16*)0x4000130
#define REG_KEY *(volatile u16*)0x4000130
#define REG_P1CNT *(volatile u16*)0x4000132
#define REG_KEYCNT *(volatile u16*)0x4000132
#define REG_R *(volatile u16*)0x4000134
#define REG_HS_CTRL *(volatile u16*)0x4000140
#define REG_JOYRE *(volatile u32*)0x4000150
#define REG_JOYRE_L *(volatile u16*)0x4000150
#define REG_JOYRE_H *(volatile u16*)0x4000152
#define REG_JOYTR *(volatile u32*)0x4000154
#define REG_JOYTR_L *(volatile u16*)0x4000154
#define REG_JOYTR_H *(volatile u16*)0x4000156
#define REG_JSTAT *(volatile u32*)0x4000158
#define REG_JSTAT_L *(volatile u16*)0x4000158
#define REG_JSTAT_H *(volatile u16*)0x400015A
#define REG_IE *(volatile u16*)0x4000200
#define REG_IF *(volatile u16*)0x4000202
#define REG_WSCNT *(volatile u16*)0x4000204
#define REG_IME *(volatile u16*)0x4000208
#define REG_PAUSE *(volatile u16*)0x4000300
/*
---------------------------------------------------
BASE Globals
System wide external variables/arrays
(initialized in mygba_sys.c)
---------------------------------------------------
*/
extern void (*IntrTable[14])(void);
/*
---------------------------------------------------
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_VBL 0
#define INT_HBL 1
#define INT_VCNT 2
#define INT_TIM0 3
#define INT_TIM1 4
#define INT_TIM2 5
#define INT_TIM3 6
#define INT_SIO 7
#define INT_DMA0 8
#define INT_DMA1 9
#define INT_DMA2 10
#define INT_DMA3 11
#define INT_KEY 12
#define INT_CART 13
/*
---------------------------------------------------
---------------------------------------------------
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)
// 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))
// General access for memory locations
#define ACCESS8(location) *(volatile u8 *) (location)
#define ACCESS16(location) *(volatile u16 *) (location)
#define ACCESS32(location) *(volatile u32 *) (location)
//define the bits that control the screen mode 0-5
#define MODE_0 0x0
#define MODE_1 0x1
#define MODE_2 0x2
#define MODE_3 0x3
#define MODE_4 0x4
#define MODE_5 0x5
//define the buffer which is used to set the active buffer
//when using double buffering
#define backbuffer 0x10
//This bit, when set allows OAM(Object Attribute Memory) to
//be updated during a horizontal blank
#define H_BLANK_OAM 0x20
//use these two defines to choose which mapping mode is used
//for sprite graphics 2D or 1D
#define OBJ_MAP_2D 0x0
#define OBJ_MAP_1D 0x40
//Causes the screen to go white by using a forced blank
#define FORCE_BLANK 0x80
//define the flags for enabling backgrounds and objects(sprites)
#define BG0_ENABLE 0x100
#define BG1_ENABLE 0x200
#define BG2_ENABLE 0x400
#define BG3_ENABLE 0x800
#define OBJ_ENABLE 0x1000
//allows window displays (dont worry about these)
#define WIN1_ENABLE 0x2000
#define WIN2_ENABLE 0x4000
#define WINOBJ_ENABLE 0x8000
//Set the mode that you want to use, logical AND them together as below:
//e.g. SetMode(MODE_2 | OBJ_ENABLE | OBJ_MAP_1D);
#define SetMode(mode) REG_DISPCNT = (mode)
// 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 + -