GBA Exploration Diary (2)

zhaozj2021-02-08  198

GBA Exploration Diary (II) Obj and Oamobj refers to the wizard of one by one, or the picture of small pieces in GBA. It is actually similar to BG. Just it is small. It is also a layer. The RPG game in GBA likes to achieve one of the characters. This makes it easy to control their location. Of course, it can also be seen from the GBA Explore Diary (-). It is also very convenient to see the control of BG. And OBJ and The difference in BG is the size.

If you set the display mode of the program in use OBJ So, set the display mode when the need to DISP_OBJ_ON and DISP_OBJ_CHAR_1D_MAP added to the list * (vu16 *) REG_DISPCNT = DISP_MODE_1 | DISP_OBJ_ON | DISP_OBJ_CHAR_1D_MAP; #define DISP_OBJ_CHAR_1D_MAP 0x0040 // OBJ Character Data 1D Mapping #define DISP_OBJ_ON 0X1000 // Obj On

Let's take a look at how the OBJ is implemented in GBA. The first thing to explain is that OBJ is displayed in GBA. It is also made up of a small piece of 8x8, like BG. There are 12 sizes .0000: 8 x 8 1000: 64 x 321010: 64 x 64 1011: 64 x 6401: 16 x 8 0101: 32 x 8 0110: 32 x 16 011: 64 X 32 OBJ data division three .1.Character It is the same as the BG's data format, which is image data of 8x8 small tiles. And you can also convert the BG's character. So It is said that the data structure of BG and OBJ is basically the same. However, all OBJ's CHARACTER cannot exceed 32K.256 colors of OBJ can have 512 character, each of the Characters 8 * 8 = 64bytes. The 16-color Characters can have 1024. Each Character accounted for 8 * 8/2 = 32bytes. It seems to be more than a BG's 256 character? But BG can have multiple, different BG can have different Character, and all OBJ can only share this 512 CHARATER.2.Palette palette does not have to be said, it is the same as BG, supports a 256-color tone panel or 16 16-color palette. 3.oamoam is an abbreviation of Obj AttribURE Memory. It is to control the OBJ property. Data parts. For example, the location of the OBJ is placed here. Each OBJ's OAM accounts for 8 bytes, OAM is from 07000000h to 070003FFH, a total of 1024 = 8 * 128, so Oam can have 128 .

How to create an OBJ? I have said that the tool that is converted by converting BG can also be used to convert OBJ. Previous conversion BG I suggest that BMP2Map.exe in Agblib, the same, convert OBJ also use BMP2Map.exe tools For example, put the Character Data in the number of sprite_gfx, put the Palette in Sprite_Pal. (There is no Map Data in the OBJ, you can convert Map Data when your conversion is converted, but you can't use it later) and then write in the program. Into:

DmaArrayCopy (3, sprite_gfx, obj_mode1_vram, 32); DmaArrayCopy (3, Sprite_Pal, Obj_pltt, 32);

Copy sprite_gfx, sprite_pal to the specified memory. Here is the OBJ_MODE1_VRAM and OBJ_PLTT two memory addresses or look at how to define them in Agblib. # Define plt 0x05000000 // Palette Ram # define plt_end (PLTT 0x400) #define BG_PLTT (PLTT 0x0) // BG Palette RAM # define BG_PLTT_END (PLTT 0x200) #define OBJ_PLTT (PLTT 0x200) // OBJ Palette RAM # define OBJ_PLTT_END (PLTT 0x400) #define VRAM 0x06000000 // VRAM # define VRAM_END (VRAM 0x18000) #define BG_VRAM (VRAM 0x0) // BG Character / Screen RAM # define OBJ_MODE0_VRAM (VRAM 0x10000) // OBJ Character RAM # define OBJ_MODE1_VRAM (VRAM 0x10000) #define OBJ_MODE2_VRAM (VRAM 0x10000 #define obj_mode3_vram (vram 0x14000) #define obj_mode4_vram (vram 0x14000) #define obj_mode5_vram (vram 0x14000) #define obj_vram_end (VRAM 0x18000) Here I also contain the address in BG recently, you can compare the address in BG and OBJ. Then you set up oam (Obj AttribURE Memory). Let's see how this OAM data structure in the official document. of.

Specially pointed out that Character Name in the above table refers to the reference of this OBJ's starting character.

I will introduce two mid methods to set.

The first method is very intuitive, it is very simple. This is the most I saw it online. First define the data structure typef struct tagoAmenTry {u16 attribute0; u16 attribute1; u16 attribute2; u16 attribute3;} OAMENTRY, * POAMENTRY; // attribute0 #define ROTATION_FLAG 0x100 # define SIZE_DOUBLE 0x200 # define MODE_NORMAL 0x0 # define MODE_TRANSPARENT 0x400 # define MODE_WINDOWED 0x800 # define MOSAIC 0x1000 # define COLOR_16 0x0000 # define COLOR_256 0x2000 # define SQUARE 0x0 # define TALL 0x4000 # define WIDE 0x8000

// attribute1 #define ROTDATA (n) ((n) << 9) #define HORIZONTAL_FLIP 0x1000 # define VERTICAL_FLIP 0x2000 # define SIZE_8 0x0 # define SIZE_16 0x4000 # define SIZE_32 0x8000 # define SIZE_64 0xC000 // atrribute2 #define PRIORITY (n) ((n) << 10) #define Palette (N) ((n) << 12)

Then write the code: OAMENTRY SPRITES [128]; // Here we define a total of 128 OBJ, but we only use the first void initializesprites () {u16 loop; for (loop = 0; loop <128; loop ) {Sprites [loop] .attribute0 = 160; // y to> 159 sprites [loop] .attribute1 = 240; // x to> 239}} void copyoam () {u16 loop; u16 * temp; u16 * _oam = (U16 *) 0x7000000; Temp = (u16 *) sprites; for (loop = 0; loop <128 * 4; loop ) {_oam [loop] = Temp [loop];}}

U16 spritex = 100; initializesprites (); sprites [0] .attribute0 = color_256 | Square | spritey; sprites [0] .attribute1 = size_16 | spritex; sprites [0] .attribute2 = 0 | Priority (0 );

Since this OBJ's character is written from the first address of OBJ_MODE1_VRAM, it should be 0. So Sprites [0] .attribute2 = 0 | priority (0);

Since the 16-color OBJ and 256 colors of the GBA are the same for the address of Characters. So, whether it is 16 colors or 256 colors of OBJ, their starting character, should be the vram character name of Obj * 32 (although 256 colors under 64bytes).

For example, take a look at the example below:

If you transfer 256 colored sprite's character data to OBJ_MODE1_VRAM N * 32's address DmaArrayCopy (3, sprite_gfx, obj_mode1_vram n * 32, 32); then its CHARACTER NAME in Attribute2 in its corresponding, should be n.sprites [0] .attribute2 = n; N range is 0-1023

For Attribute3, we are now not available now.

The next step is to write SPRITES to the OAM to constantly update OamWhile (1) {// WaitSync (); Copyoam ();}

The second method is the method used in agblib. For example, I want to display an OBJ directly define a VU32 BG_OAM_Buffer [2]; then write Character and Palette data into DmaArrayCopy (3, Sprite_GFX, Obj_Mode1_vram, 32); DmaArrayCopy 3, sprite_pal, OBJ_PLTT, 32); OAM provided when he wrote bg_oam_buffer [0] = OAM_COLOR_256 | OAM_SQUARE | OAM_SIZE_16x16 | (100) << OAM_H_POS_SHIFT | (72) << OAM_V_POS_SHIFT; bg_oam_buffer [1] = 0x0400; are given below Out of AgBlib for the above macro: #define oam_v_pos_shift 0 # define oam_h_pos_shift 16 # define oam_color_16 0x0000000000 // SELECT 16 # define Oam_Color_256 0x00002000 // SELECT 256 Colors

#define OAM_SIZE_8x8 0x00000000 // OBJ 8 x 8 dot # define OAM_SIZE_16x16 0x40000000 // OBJ 16 x 16 dot # define OAM_SIZE_32x32 0x80000000 // OBJ 32 x 32 dot # define OAM_SIZE_64x64 0xc0000000 // OBJ 64 x 64 dot # define OAM_SIZE_16x8 0x00004000 // OBJ 16 x 8 dot # define OAM_SIZE_32x8 0x40004000 // OBJ 32 x 8 dot # define OAM_SIZE_32x16 0x80004000 // OBJ 32 x 16 dot # define OAM_SIZE_64x32 0xc0004000 // OBJ 64 x 32 dot # define OAM_SIZE_8x16 0x00008000 // OBJ 8 x 16 dot # define OAM_SIZE_8x32 0x40008000 // OBJ 8 x 32 dot # define OAM_SIZE_16x32 0x80008000 // OBJ 16 x 32 dot # define OAM_SIZE_32x64 0xc0008000 // OBJ 32 x 64 dot you can see .bg_oam_buffer [0] is actually attribute0 first method, Attribute1 collection. BG_OAM_BUFFER [1] is the collection of Attribute2, Attribute3 of the first method. Then simultaneously update the write oamwhile (1) {DMACOPY (32); 8, 32); } This is the definition of Oam: #define oam 0x07000000 // oam # define oam_end (Oam 0x400)

转载请注明原文地址:https://www.9cbs.com/read-3174.html

New Post(0)