Reference Text
https://blog.csdn.net/weixin_43837555/article/details/88326567
GBA Development Kit - DevKitAdv
DevKitAdv consists of two main parts: the GCC++ compiler and the GBA library.
The GCC++ compiler functions much like our common VC, except there are few text editors to edit the source code, and there is no support for class es, which can only be replaced by struct. Its purpose is to compile the code we write into a binary executable that is, of course, relative to GBA and GBA emulators. Just as the EXE file in Windows cannot be used on a Mac;
The GBA library provides a series of functions for image, control and sound, and is used in conjunction with GCC+.
Download and install the DevKitAdv development kit to the C:\devkitadv-r5-beta-3 directory (note: environment variables need to be set if directory location is not this)
Notice that https://sourceforge.net/projects/devkitadv/files/Windows/Release 5 (Beta 3)/ There are many files in the address. I didn't know which to download at first. In fact, each section has its own function. It is recommended that you download all the files and then unzip them into C drive one by one.
Sound Conversion Tool - wav2gbac.exe
http://www.gbadev.org/tools.php?showinfo=189
Graphics Conversion Tool - kaleid_1-2-3
http://www.gbadev.org/tools.php?showinfo=132
It is important to note that whether kaleid is functioning properly does not have much to do with 32-bit or 64-bit systems (parental testing)
However, there is a key factor that will ultimately prevent the export of the *.h file, which is the picture requirements must be: 256-color bmp pictures
Graphics Conversion Tool - bmp2gba
https://www.gbadev.org/tools.php?showinfo=163
256 color bitmaps only
bitmap must be equal or bigger than 240*160
64 bitmaps each time only (should be enough though)
main.c
typedef unsigned char u8; typedef unsigned short u16; typedef unsigned long u32; #define REG_DISPCNT *(u16*)0x04000000 //Display Register Address #define VRAM 0x06000000 //Image Buffer Address #define PALETTE 0x5000000 //palette address #Define MODE_ 40x04 // Mode4 flag #Define BG2_ ENABLE 0x0400 // BG_ 2 Signs #define SetMode(Mode) REG_DISPCNT=(Mode)//Macro Definition for Setting Display Mode #include "helloworld.h" //Header file containing image palette and data u16* palette_mem=(u16*)PALETTE; // system palette u16* video_buffer=(u16*)VRAM; // Image Buffer void Draw(u16* src_palette,u16* src_data,u16* dst_palette,u16* dst_data); int main() { // Set screen mode, use MODE_here 4 SetMode (MODE_4 | BG2_ENABLE); // helloworld_pal and helloworld_gfx is the palette and image data array name defined in "helloworld.h" Draw((u16*)helloworld_pal,(u16*)helloworld_gfx,palette_mem,video_buffer); // Dead cycle while(1) { ;} } // MODE_4 Drawing functions void Draw(u16* src_palette,u16* src_data,u16* dst_palette,u16* dst_data) { int loop,x,y; // Write Target Palette for(loop = 0; loop < 256; loop++) dst_palette[loop] = src_palette[loop]; // Write image buffer for(x = 0; x < 120; x++) for(y = 0; y < 160; y++) dst_data[(y) *120 + (x)]=src_data[(y) *120 + (x)]; }
Compile Files
gcc -lm -o main.elf main.c objcopy -v -O binary main.elf main.bin
When using make command, configure Arm Gcc
Or write the following command to a new Makefile file
CC=arm-agb-elf-gcc OBJCOPY=arm-agb-elf-objcopy NAME=main all: main-bin main-bin: main-elf $(OBJCOPY) -v -O binary $(NAME).elf $(NAME).bin main-elf: $(CC) -lm -o $(NAME).elf $(NAME).c clean: rm -f *.elf *.bin
Use DevKitAdv to make
Generate main.gba
To add to this, the last game extensions we played, like Pocket Monster, were all *.gba. It's really easy to generate executable GBA files in the end. Just change the $(OBJCOPY) -v-O binary $(NAME).elf $(NAME).bin in Makefile to $(OBJCOPY) -v-O binary $(NAME).elf $(NAME).gba, Or change objcopy-v-O binary main.elf main.bin in make.bat to objcopy-v-O binary main.elf main.gba