File: gba.inc - Tab length: 1 2 4 8 - Lines: on off - No wrap: on off

001: @@@@@@@@@ CONTENTS @@@@@@@@@
002: @ 1. Key pad defines
003: @ 2. Display
004: @ 3. Sprites
005: @ 4. Background
006: @ 5. Sound
007: @ 6. DMA
008: @ 7. Interrupts
009: @ 8. BIOS Functions
010: 
011: @@@@@@@@@ 1. KEY PAD DEFINES @@@@@@@@@
012: KEY_A       = 1
013: KEY_B       = 2
014: KEY_SELECT  = 4
015: KEY_START   = 8
016: KEY_RIGHT   = 16
017: KEY_LEFT    = 32
018: KEY_UP      = 64
019: KEY_DOWN    = 128
020: KEY_R       = 256
021: KEY_L       = 512
022: KEYS        = 0x04000130
023: KEYS_HIGH   = 0x04000000
024: KEYS_LOW    = 0x00000130
025: 
026: @@@@@@@@@ 2. Display @@@@@@@@@
027: @ Tile modes
028: MODE_0 = 0x00   @ All 4 BG layers available, but no rotation/scaling
029: MODE_1 = 0x01   @ 3 BG layers (0-2), BG2 can rotate/scale
030: MODE_2 = 0x02   @ 2 BG layers (2-3), both can scale/rotate
031: @ Bitmap modes : BG2 only
032: MODE_3 = 0x03   @ 16 bit color bitmap, cuts into available sprite data area
033: MODE_4 = 0x04   @ Like Mode 3, but with 8-bit references (and palette)
034: MODE_5 = 0x05   @ 16 bit color bitmap, with backbuffer. Screen limited to 160x128
035: 
036: BACKBUFFER = 0x010
037: H_BLANK_OAM = 0x020
038: 
039: OBJ_MAP_2D = 0x000
040: OBJ_MAP_1D = 0x040
041: 
042: FORCE_BLANK = 0x080
043: 
044: BG0_ENABLE = 0x0100
045: BG1_ENABLE = 0x0200
046: BG2_ENABLE = 0x0400
047: BG3_ENABLE = 0x0800
048: OBJ_ENABLE = 0x01000        @ = SPRITES_ENABLE: enable sprites
049: WIN1_ENABLE = 0x02000
050: WIN2_ENABLE = 0x04000
051: WINOBJ_ENABLE = 0x08000
052: VRAM = 0x06000000
053: VPAL = 0x05000000
054: REG_DISPCNT = 0x04000000    @
055: REG_VCOUNT  = 0x04000006
056: @@@@@@@@@ 3. SPRITES @@@@@@@@@
057: 
058: @*** Attribute 0 ***
059: @ F E D C  B A 9 8  7 6 5 4  3 2 1 0
060: @ S S A M  T T D R  J J J J  J J J J
061: @ 0-7   (J) = Y coordinate of the sprite (pixels)
062: @ 8     (R) = Rotation/Scaling on/off
063: @ 9     (D) = 0 - sprite is single sized;
064: @             1 - sprite is virtually double sized
065: @ A-B   (T) = 00 - normal
066: @             01 - semi-transparent
067: @             10 - obj window
068: @ C     (M) = enables mosaic for this sprite.
069: @ D     (A) = 256 color if on, 16 color if off
070: @ E-F   (S) = Size, MSB in attribute 0, LSB in attribute 1
071: 
072: @ Byte 1 = Y coordinate of the sprite, in pixels
073: @ Byte 2
074: ROTATION_FLAG   =  0x100
075: SIZE_DOUBLE     =  0x200
076: MODE_NORMAL     =  0x000
077: MODE_TRANSPERANT=  0x400
078: MODE_WINDOWED   =  0x800
079: MOSAIC          = 0x1000
080: COLOR_16        = 0x0000
081: COLOR_256       = 0x2000
082: SIZE_8          = 0x0000 @ Only valid for SQUARE
083: SIZE_16         = 0x4000
084: SIZE_32         = 0x8000
085: SIZE_64         = 0xC000
086: 
087: @*** Atribute 1 ***
088: @ FEDC BA98 7654 3210
089: @ SSVH XXXI IIII IIII   (standard sprites)
090: @ SSFF FFFI IIII IIII   (rotation/scaling on)
091: @ 0-8 (I) = X coordinate of the sprite (pixels)
092: @ C   (H) = flip horizinal bit
093: @ D   (V) = flip vertical bit
094: @ 9-D (F) = rotation index (0-31). rotation/scaling data in OAM attribute 3
095: @ E-F (S) = Size of the sprite (LSB)
096: @           4-bit value which sets the size of the sprite in the following way:
097: @           00 00: 8  x 8       10 00: 8  x 16
098: @           00 01: 16 x 16      10 01: 8  x 32
099: @           00 10: 32 x 32      10 10: 16 x 32
100: @           00 11: 64 x 64      10 11: 32 x 64
101: @           01 00: 16 x 8       11 00: Not used
102: @           01 01: 32 x 8       11 01: Not used
103: @           01 10: 32 x 16      11 10: Not used
104: @           01 11: 64 x 32      11 11: Not used
105: 
106: @ Byte 3+1 bit = X coordinate of the sprite, in pixels (9-bit value)
107: @ Byte 4
108: SQUARE          = 0x0000
109: WIDE            = 0x4000
110: TALL            = 0x8000
111: HORIZONTAL_FLIP = 0x1000
112: VERTICAL_FLIP   = 0x2000
113: OAM             = 0x07000000
114: OBJPAL          = 0x5000200
115: CHARMEM         = 0x6010000     @ SPRITE MEM
116: CHARMEM_MODE3   = 0x6012BFD
117: 
118: @@@@@@@@@ 4. Background @@@@@@@@@
119: @ These four addresses handle the BG layers
120: REG_BG0CNT  = 0x4000008
121: REG_BG1CNT  = 0x400000A
122: REG_BG2CNT  = 0x400000C
123: REG_BG3CNT  = 0x400000E
124: 
125: REG_BG0HOFS = 0x4000010 @ Horizontal offset
126: REG_BG0VOFS = 0x4000012 @ Vertical offset
127: REG_BG1HOFS = 0x4000014
128: REG_BG1VOFS = 0x4000016
129: REG_BG2HOFS = 0x4000018
130: REG_BG2VOFS = 0x400001A
131: REG_BG3HOFS = 0x400001C
132: REG_BG3VOFS = 0x400001E
133: REG_BG2PA   = 0x4000020
134: REG_BG2PB   = 0x4000022
135: REG_BG2PC   = 0x4000024
136: REG_BG2PD   = 0x4000026
137: REG_BG2X    = 0x4000028
138: REG_BG2X_L  = 0x4000028
139: REG_BG2X_H  = 0x400002A
140: REG_BG2Y    = 0x400002C
141: REG_BG2Y_L  = 0x400002C
142: REG_BG2Y_H  = 0x400002E
143: REG_BG3PA   = 0x4000030
144: REG_BG3PB   = 0x4000032
145: REG_BG3PC   = 0x4000034
146: REG_BG3PD   = 0x4000036
147: REG_BG3X    = 0x4000038
148: REG_BG3X_L  = 0x4000038
149: REG_BG3X_H  = 0x400003A
150: REG_BG3Y    = 0x400003C
151: REG_BG3Y_L  = 0x400003C
152: REG_BG3Y_H  = 0x400003E
153: 
154: BG_COLOR_16     = 0x0
155: BG_MOSAIC_ENABLE = 0x40
156: BG_COLOR_256    = 0x80
157: 
158: TEXTBG_SIZE_256x256 = 0x0       @ 16x16 8*8 for text backgrounds
159: TEXTBG_SIZE_512x256 = 0x4000    @ 64x32
160: TEXTBG_SIZE_256x512 = 0x8000    @ 32x64
161: TEXTBG_SIZE_512x512 = 0xC000    @ 64x64
162: 
163: ROTBG_SIZE_128x128 = 0x0        @ 16x16 8*8 tiles for rotational backgrounds
164: ROTBG_SIZE_256x256 = 0x4000     @ 32x32 tiles
165: ROTBG_SIZE_512x512 = 0x8000     @ 64x64 tiles
166: ROTBG_SIZE_1024x1024 = 0xC000   @ 128x128 tiles
167: 
168: WRAPAROUND = 0x2000
169: 
170: CHAR_SHIFT = 2      @ Used to shift the number over to the right place in REG_BGxCNT
171: SCREEN_SHIFT = 8
172: 
173: @ Defines for all 32 screen (map data) blocks and 4 character (bitmap data) blocks
174: @ Some of this might not be correct
175: CHAR_BLOCK_0 = 0x6000000
176: CHAR_BLOCK_1 = 0x6004000
177: CHAR_BLOCK_2 = 0x6008000
178: CHAR_BLOCK_3 = 0x600C000
179: SCREEN_BLOCK_0 = 0x6000000
180: SCREEN_BLOCK_1 = 0x6000800
181: SCREEN_BLOCK_2 = 0x6001000
182: SCREEN_BLOCK_3 = 0x6001800
183: SCREEN_BLOCK_4 = 0x6002000
184: SCREEN_BLOCK_5 = 0x6002800
185: SCREEN_BLOCK_6 = 0x6003000
186: SCREEN_BLOCK_7 = 0x6003800
187: SCREEN_BLOCK_8 = 0x6004000
188: SCREEN_BLOCK_9 = 0x6004800
189: SCREEN_BLOCK_10 = 0x6005000
190: SCREEN_BLOCK_11 = 0x6005800
191: SCREEN_BLOCK_12 = 0x6006000
192: SCREEN_BLOCK_13 = 0x6006800
193: SCREEN_BLOCK_14 = 0x6007000
194: SCREEN_BLOCK_15 = 0x6007800
195: SCREEN_BLOCK_16 = 0x6008000
196: SCREEN_BLOCK_17 = 0x6008800
197: SCREEN_BLOCK_18 = 0x6009000
198: SCREEN_BLOCK_19 = 0x6009800
199: SCREEN_BLOCK_20 = 0x600A000
200: SCREEN_BLOCK_21 = 0x600A800
201: SCREEN_BLOCK_22 = 0x600B000
202: SCREEN_BLOCK_23 = 0x600B800
203: SCREEN_BLOCK_24 = 0x600C000
204: SCREEN_BLOCK_25 = 0x600C800
205: SCREEN_BLOCK_26 = 0x600D000
206: SCREEN_BLOCK_27 = 0x600D800
207: SCREEN_BLOCK_28 = 0x600E000
208: SCREEN_BLOCK_29 = 0x600E800
209: SCREEN_BLOCK_30 = 0x600F000
210: SCREEN_BLOCK_31 = 0x600F800
211: 
212: @@@@@@@@@ 5. Sound @@@@@@@@@
213: @ To turn sound on:
214: @   ldr r1,=REG_SOUNDCNT_X
215: @   ldr r0,=0x0081
216: @   str r0,[r1]
217: 
218: REG_SOUND1CNT_L = 0x04000060 @ Sound 1 Sweep control
219: REG_SOUND1CNT_H = 0x04000062 @ Sound 1 Length, wave duty and envelope control
220: REG_SOUND1CNT_X = 0x04000064 @ Sound 1 Frequency, reset and loop control
221: REG_SOUND2CNT_L = 0x04000068 @ Sound 2 Length, wave duty and envelope control
222: REG_SOUND2CNT_H = 0x0400006C @ Sound 2 Frequency, reset and loop control
223: REG_SOUND3CNT_L = 0x04000070 @ Sound 3 Enable and wave ram bank control
224: REG_SOUND3CNT_H = 0x04000072 @ Sound 3 Sound Length and output level control
225: REG_SOUND3CNT_X = 0x04000074 @ Sound 3 Frequency, reset and loop control
226: REG_SOUND4CNT_L = 0x04000078 @ Sound 4 Length, output level and envelope control
227: REG_SOUND4CNT_H = 0x0400007C @ Sound 4 Noise parameters, reset and loop control
228: REG_SOUNDCNT_L  = 0x04000080 @ Sound 1-4 Output level and Stereo control
229: REG_SOUNDCNT_H  = 0x04000082 @ Direct Sound control and Sound 1-4 output ratio
230: REG_SOUNDCNT_X  = 0x04000084 @ Master sound enable and Sound 1-4 play status
231: REG_SOUNDBIAS   = 0x04000088 @ Sound bias and Amplitude resolution control
232: REG_WAVE_RAM0_L = 0x04000090 @ Sound 3 samples 0-3
233: REG_WAVE_RAM0_H = 0x04000092 @ Sound 3 samples 4-7
234: REG_WAVE_RAM1_L = 0x04000094 @ Sound 3 samples 8-11
235: REG_WAVE_RAM1_H = 0x04000096 @ Sound 3 samples 12-15
236: REG_WAVE_RAM2_L = 0x04000098 @ Sound 3 samples 16-19
237: REG_WAVE_RAM2_H = 0x0400009A @ Sound 3 samples 20-23
238: REG_WAVE_RAM3_L = 0x0400009C @ Sound 3 samples 23-27
239: REG_WAVE_RAM3_H = 0x0400009E @ Sound 3 samples 28-31
240: REG_FIFO_A_L    = 0x040000A0 @ Direct Sound channel A samples 0-1
241: REG_FIFO_A_H    = 0x040000A2 @ Direct Sound channel A samples 2-3
242: REG_FIFO_B_L    = 0x040000A4 @ Direct Sound channel B samples 0-1
243: REG_FIFO_B_H    = 0x040000A6 @ Direct Sound channel B samples 2-3
244: 
245: @@@@@@@@@ 6. DMA @@@@@@@@@
246: 
247: DMA_ENABLE  = 0x80000000
248: DMA_INTERUPT_ENABLE = 0x40000000
249: DMA_TIMEING_IMMEDIATE   = 0x00000000
250: DMA_TIMEING_VBLANK  = 0x10000000
251: DMA_TIMEING_HBLANK  = 0x20000000
252: DMA_TIMEING_SYNC_TO_DISPLAY = 0x30000000
253: DMA_16  = 0x00000000
254: DMA_32  = 0x04000000
255: DMA_REPEAT  = 0x02000000
256: DMA_SOURCE_INCREMENT    = 0x00000000
257: DMA_SOURCE_DECREMENT    = 0x00800000
258: DMA_SOURCE_FIXED    = 0x01000000
259: DMA_DEST_INCREMENT  = 0x00000000
260: DMA_DEST_DECREMENT  = 0x00200000
261: DMA_DEST_FIXED  = 0x00400000
262: DMA_DEST_RELOAD = 0x00600000
263: 
264: @ register defines, ripped from GBA.h from DevKitAdvanced
265: REG_DMA0SAD     = 0x40000B0
266: REG_DMA0SAD_L   = 0x40000B0
267: REG_DMA0SAD_H   = 0x40000B2
268: REG_DMA0DAD     = 0x40000B4
269: REG_DMA0DAD_L   = 0x40000B4
270: REG_DMA0DAD_H   = 0x40000B6
271: REG_DMA0CNT     = 0x40000B8
272: REG_DMA0CNT_L   = 0x40000B8
273: REG_DMA0CNT_H   = 0x40000BA
274: REG_DMA1SAD     = 0x40000BC
275: REG_DMA1SAD_L   = 0x40000BC
276: REG_DMA1SAD_H   = 0x40000BE
277: REG_DMA1DAD     = 0x40000C0
278: REG_DMA1DAD_L   = 0x40000C0
279: REG_DMA1DAD_H   = 0x40000C2
280: REG_DMA1CNT     = 0x40000C4
281: REG_DMA1CNT_L   = 0x40000C4
282: REG_DMA1CNT_H   = 0x40000C6
283: REG_DMA2SAD     = 0x40000C8
284: REG_DMA2SAD_L   = 0x40000C8
285: REG_DMA2SAD_H   = 0x40000CA
286: REG_DMA2DAD     = 0x40000CC
287: REG_DMA2DAD_L   = 0x40000CC
288: REG_DMA2DAD_H   = 0x40000CE
289: REG_DMA2CNT     = 0x40000D0
290: REG_DMA2CNT_L   = 0x40000D0
291: REG_DMA2CNT_H   = 0x40000D2
292: REG_DMA3SAD     = 0x40000D4
293: REG_DMA3SAD_L   = 0x40000D4
294: REG_DMA3SAD_H   = 0x40000D6
295: REG_DMA3DAD     = 0x40000D8
296: REG_DMA3DAD_L   = 0x40000D8
297: REG_DMA3DAD_H   = 0x40000DA
298: REG_DMA3CNT     = 0x40000DC
299: REG_DMA3CNT_L   = 0x40000DC
300: REG_DMA3CNT_H   = 0x40000DE
301: 
302: @ These defines group common options to save typing
303: @ You may notice that I don't have to include the option to increment the source and address register as that is the default.
304: @ DMA_32NOW DMA_ENABLE|DMA_TIMEING_IMMEDIATE|DMA_32
305: @ DMA_16NOW DMA_ENABLE|DMA_TIMEING_IMMEDIATE|DMA_16
306: DMA_32NOW   = 0x84000000
307: DMA_16NOW   = 0x80000000
308: 
309: @@@@@@@@@ 7. INTERRUPTS @@@@@@@@@
310: 
311: INT_VBLANK      = 0x0001
312: INT_HBLANK      = 0x0002
313: INT_VCOUNT      = 0x0004        @ you can set the display to generate an interrupt when it reaches a particular line on the screen
314: INT_TIMER0      = 0x0008
315: INT_TIMER1      = 0x0010
316: INT_TIMER2      = 0x0020
317: INT_TIMER3      = 0x0040
318: INT_COMUNICATION    = 0x0080    @ Serial communication interupt
319: INT_DMA0        = 0x0100
320: INT_DMA1        = 0x0200
321: INT_DMA2        = 0x0400
322: INT_DMA3        = 0x0800
323: INT_KEYBOARD    = 0x1000
324: INT_CART        = 0x2000        @ The cart can actually generate an interupt
325: 
326: INT_ENABLE      = 0x1
327: 
328: REG_INTADDR     = 0x3007FFC
329: 
330: REG_IE          = 0x4000200     @ Interrupt Enable Register
331: REG_IF          = 0x4000202
332: REG_IME         = 0x4000208     @ Interrupt Master Enable Register
333:                                 @ bit 0 = Enable interupts (1)/Disable all interrupts (0)
334:                                 @         if 1, it will look in REG_IE for interrupt type
335: REG_DISPSTAT    = 0x4000004     @ Display Status:
336: STAT_VBLANK     = 1             @ bit 0 = V Refresh (0 = VDraw, 1 = VBlank)
337: STAT_HBLANK     = 2             @ bit 1 = H Refresh (0 = HDraw, 1 = HBlank)
338:                                 @ bit 2 = VCount Triggered Status (1 = Y trigger interrupt occured)
339: STAT_VBLANK_IRQ = 8             @ bit 3 = Enables LCD VBlank IRQ
340: STAT_HBLANK_IRQ = 16            @ bit 4 = Enables LCD HBlank IRQ
341:                                 @ bit 5 = Enables VCount trigger
342:                                 @ bit 8-F = VCount line trigger: Vcount value you wish to trigger an interrupt
343:    
344: 
345: @@@@@@@@@ 8. BIOS FUNCTIONS @@@@@@@@@
346: 
347: SoftReset           = 0x00
348: RegisterRamReset    = 0x01
349: Halt                = 0x02
350: Stop_Sleep          = 0x03
351: IntrWait            = 0x04
352: VBlankIntrWait      = 0x05
353: Div                 = 0x06
354: DivArm              = 0x07
355: Sqrt                = 0x08
356: ArcTan              = 0x09
357: ArcTan2             = 0x0A
358: CpuSet              = 0x0B
359: CpuFastSet          = 0x0C
360: GetBiosChecksum     = 0x0D
361: BgAffineSet         = 0x0E
362: ObjAffineSet        = 0x0F
363: BitUnPack           = 0x10
364: LZ77UnCompWram      = 0x11
365: LZ77UnCompVram      = 0x12
366: HuffUnComp          = 0x13
367: RLUnCompWram        = 0x14
368: RLUnCompVram        = 0x15
369: Diff8bitUnFilterWram    = 0x16
370: Diff8bitUnFilterVram    = 0x17
371: Diff16bitUnFilter   = 0x18
372: SoundBias           = 0x19
373: SoundDriverInit     = 0x1A
374: SoundDriverMode     = 0x1B
375: SoundDriverMain     = 0x1C
376: SoundDriverVSync    = 0x1D
377: SoundChannelClear   = 0x1E
378: MidiKey2Freq        = 0x1F
379: SoundWhatever0      = 0x20
380: SoundWhatever1      = 0x21
381: SoundWhatever2      = 0x22
382: SoundWhatever3      = 0x23
383: SoundWhatever4      = 0x24
384: MultiBoot           = 0x25
385: HardReset           = 0x26
386: CustomHalt          = 0x27
387: SoundDriverVSyncOff = 0x28
388: SoundDriverVSyncOn  = 0x29
389: SoundGetJumpList    = 0x2A