GBA C/C++ Programming tutorial ---Lesson 1

GBA开发入门:做一个名叫Hello World的游戏 文章目录1.关于GBA的一些背景知识2.GBA程序开发准备2.1 GBA编译器 - Arm Gcc || ArmSDT2.1.1 GBA开发包 - DevKitAdv2.2 GBA模拟器 - VisualBoyAdvance2.3 图形转换工具 - kaleid_1-2-32.4 声音转换工具 - wav2gbac.exe3.第一个GBA程序:Hello World3.1 helloword.h3... 阅读详情

Gameboy Advance (GBA)

 

GBA has a 32 bit ARM7TDMI processor (RISC) with a cpu speed of about 16.67 MHz. It has also got its own graphics processor to support the main cpu . The gba includes a Z80 processor which is used to run games for the gameboy and gameboy color (this is not the subject of these lessons). GBA has 96Kb video memory (VRAM), 32Kb fast internal memory, and 256Kb external memory. The screen resolution is 240x160 pixels in all modes except mode 5, and can show a maximum of 32768 colors.

 

 

Graphic modes

 

GBA has 6 different graphics modes. Here comes a description of each of these modes, but first a brief explanation. Mode 0, 1 and 2 are called tile modes, which means these modes are built up from small squares (tiles) of 8x8 pixels that make up the background(s) in the different modes. Mode 3, 4 and 5 are bitmapped modes, which means they give the programmer the opportunity to write directly to a pixel on the screen. This can be done in two ways: by writing a 15 bit color code to the address that represents the specific pixel on the screen, or input a reference to a color stored in a palette.

 

Tiles

 

 

Tile backgrounds are made up from tiles. Tiles are small, self made squares of 8x8 pixels size. These tiles can either be in 16 or 256 colors.

 

What I refer to as a tile map (see top next page) is actually a 2D table that consists of numbers that reference the tiles that we want to place at the chosen location in the table.  Tiles can be used more than once in the same tile map, and they can be turned up side down and sideways. Because of this we won’t need that many different tiles to create a background.  Tile maps can also be rotated and scaled, but not all modes have the same possibilities.

 

Sprites

 

 

Sprite characters are animations like this smurf that you will find in most games. These characters can move freely over the screen without destroying any of the background like any other graphics would have done. This is the reason we almost always want to use sprites when programming games.

 

The sprites are made by hardware (the graphics processor) so we don’t need to think about what actually happens when we are using sprites. We just specify the size of the sprite, how many colors its going to have (16 or 256), if its going to be rotated, turned upside down, sideways or scaled.

 

 

 

 

Mode 0:

1        All 4 available backgrounds

2        No rotation or scaling

3        16 or 256 colors

4        Maximum 1024 tiles

 

Mode 1:

1        Only background 0, 1 and 2 are available

2        Background 2 supports rotation/scaling

3        256 colors

4        Maximum 256 tiles

 

Mode 2:

1        Only background 2 and 3 are available

2        Both backgrounds support rotation/scaling

3        256 colors

4        Maximum 256 tiles

 

Mode 3:

1        Only background 2 is available

2        240x160 pixels

3        32768 colors

 

Mode 4:

1        Only background 2 is available

2        240x160 pixels

3        Supports double buffering

4        256 different color entries from a palette made up from 32768 colors

 

Mode 5:

1        Only background 2 is available

2        160x128 pixels

3        Supports double buffering

4        32768 colors

 

 

How can you program the GBA ?

 

To be able to program the GBA you have to know C/C++ programming, and you need to have a special C compiler or assembler made for the gba cpu. Its probably easiest to use a C compiler for programming, but if you want to get the most out of the gba hardware you would be better of with the assembler. In these lectures I will only use a C compiler, and that’s what I will suggest for anyone who is new to handheld development. And by the way I haven’t heard of anyone who solely programs their games in assembler. Usually parts or functions are rewritten in assembler if they need to be very fast, but the rest of the program is written in C/C++. Nintendo is selling a C/C++ compiler, but I think it costs about $5000.  A free unofficial compiler (DevKitAdv) is available at http://devkitadv.sourceforge.net/index.html

 

When you have downloaded DevKitAdv you can just unzip it to c:/.DevKitAdv  To write your code you can use notepad, and save your program as ‘myprogram.c’. Always remember to press enter after the last ‘}’ in your code or the compiler will complain.

 

To be able to compile the C code you have written you would need to run a  .bat file that starts the compiler.

 

Recipe: How to make a .bat file

 

1        Open notepad

2        Write this:

path=c:/devkitadv/bin

gcc  -o Test.elf Test.cpp  -lm

objcopy -O binary Test.elf Test.bin

3        Store this file as Make.bat

 

 

I have chosen to call my program Test.c, that is why I have the name Test in the Make.bat file. If you want to change the name of your C program to something else, you will have to change the name in the Make.bat file. Don’t use space or foreign letters in the program names or path names, this can be a problem for the compiler. Its also very important that you write the correct path to the /bin folder in DevKitAdv, or the compiler will not work.

 

Testing your programs (emulators)

 

To test your programs, the fastest and most used method is to use emulators that emulate the gba hardware. There are lots of free emulators on the internet, VisualBoyAdvance and mappy are the most used.

 

If you put VisualBoyAdvance in the c:/devkitadv/bin folder, and put the line (VisualBoyAdvance test.bin) at the end of the Make.bat file, your program will compile and execute every time you run Make.bat.

 

Tools

 

Lots of tools have been made for converting pictures from different picture-formats used on computers to the formats that the gba understands. These tools can be specially made for making bitmapped pictures, sprites, tiles, or even tile maps. These are some of my favorites.

 

3        gifs2sprites 

4        gfx2gba

5        bimbo (bitmap editor)

6        GBAMapEditor (tile map editor)

 

Tiles and sprites are made exactly the same way and can often use the same converter.

 

Transferring programs to hardware

 

If you have made a program/game that runs on the gba emulator its a lot more fun to se it run on real hardware than to see it on a big monitor on the computer. To accomplish this you need a flash cart

 

This is a flash cart.

 

You can connect the flash cart to a special box called a linker when you want to program it. The linker is connected to the PC and a program on the PC lets you send programs to the flash cart connected to the linker. You can then put the flash cart into your gba and see the result on your gba hardware. Some flash carts can be programmed while connected to the gba hardware, through a cable in the linker port of the gba.

 

A cheaper alternative is to buy an MBV II cable that is designed to transfer small programs directly into the gba memory. This cable must be connected to the linker port of the gba, and cannot be removed after you have transferred the program to the gba. This cable uses the internal memory of the gba and the biggest sized programs you can transfer with an MVB II is 256Kb (actually about 240Kb).

 

This is what the MBV II looks like. It connects to the parallel port on the computer, there is a micro controller inside the parallel connector, and it comes with special software to transfer programs from the computer to the gba.

 

Information on the internet

 

There is an IRC channel especially for gba development on EFnet, called #GBADEV. On this channel people are very helpful and have good knowledge of the gba hardware. Tutorials and lectures about gba programming are available online, have a look at www.gbajunkie.co.uk, or PERN project at http://www.thepernproject.com/index2.htm. 

devkitadv-GBA开发工具 devkitadv GBA开发工具 任天堂GBA官方开发包安装及开发环境的设置 Romandoo 解压安装包至某目录后,安照以下步骤操作: 一: 安装CYGWIN工具 运行CYGWIN_SETUP目录下setup.exe进行cygwin的安装 选INSTALL FROM LOCAL DIRECTORY 在SELECT INSTALL ROOT diretory 选择安装目录 next> 再NEXT 在弹出的窗口中,在Perv Curr Exp 中选Curr 点开列表栏中各项, 选 base 的 cygwin ash bash login sh-utils 选 devel 的 autoconf automake binutils gcc gdb make 选 shell下的 ash bash sh-utils 置NEW栏显示版本号,表示将其安装,而其它的工具选为skip表示跳过不安装 最后选next开始安装! (注意,我为了节省空间,我删除了许多不重要的东西,其实cygwin下有高达几百m的各式各样的工具,今后你可根据自已需要到网上下载安装去) 二、安装任天堂官方开发包 在 AGB LIBRARY3.0中点 agbsetup1安装 注意,一定要安装到c:\agb目录下,因为这是官方的默认目录,有一些例子与这个目录关连了 所以最好选这个目录 ,不然可能编不过去。否则自已设置会麻烦一点的。 修改c:\autoexec.bat 文件增加如下代码行 SET AGBDIR=C:\AGB 三、安装CYGWIN补丁 (由于刚安装完的cygwin版本并不支持arm cpu,所以需要将某些程序、库覆盖成arm相关的程序库) 将arm-thumb-elf连目录一起copy到安装好的cygwin目录的\lib\gcc-lib下 将bin-patch目录下的所有文件copy到cygwin目录的bin下面覆盖 将include patch目录下文件copy到cygwin目录的include下面 四:编绎例子程序 OK!前三步已经将我们的开发环境构好了!! 现在我们可以正式进行开发了,至于开发技术吗,在agb目录的doc下应有尽有,大家可以好好研究一下子。 下面我就介绍如何编绎代码了。 编绎也是很简单的一件事情了。 官方资料里有许多的例子,和两个游戏demo源代码。 我们就拿里面的一个具有代表性的例子编绎吧 functional_sample 在编绎之前,你必须重起你的机器,因为刚才我们修改了 autoexec.bat 而设置此时需要生效才行。(当然也有其它办法不必重起就生效,说来话长了) 好,重起之后,我们运行刚才装好的cygwin程序 进入了一个控制台窗口 这个控制台shell,命令行支持的是类式linux的指令,你可能不太了解,不过你不用担心呵 我们不需要记太多的命令指令,很简单的几句这可以了 就当是dos命令,只不过命令名称变了而已 下面是几个对应 ls 相当于dos下的dir指令 cd 相当于dos下的cd 指令 你也就需要这两个指令就搞定了,呵 行,那么我们正式开始: cd c: cd agb cd src cd samples cd functional_sample //以上几步作的就是进入c:\agb\src\samples\functional_sample目录下,和dos一样吧,呵 然后注意了,忘了提醒有关functional_sample这个例子的一个问题, 就是这个例子源代码share.c 中定义了 vu16 Cont; vu16 Trg; 但是在share.h中又申明为 extern u16 Cont; extern u16 Trg; 该编绎器检查认为是错误,所以你要改一下 将share.h文件里改成 extern vu16 Cont; extern vu16 Trg; 否则编绎报错。 好,改好share.h之后,我们输入 make 回车! 好,你可以看到现在开始正式编绎了,太爽了,官方的例子在被编绎,呵 过了几十秒编绎完成之后,就会生成了bin与elf文件 你用visualBoyAdvance打开bin文件看一看是 什么例子,哇,原来是个非常强的GBA各个功能展示,有alpha混合,有图层显示 有马塞可显示,有放大缩小,有精灵移动,旋转,字体显示,声音,有地图显示,有窗口模式。 但是需要注意的一个问题:::::: 如果你想使用gcc里面的库函数 需要在makefile里面修改一下 CFLAGS 中加入 -I"C:\cygwin\include" LDFLAGS 中加入 -lm 否则你将无法使用sin,cos,sqrt等有用的库函数 编完这个,你可以再去试试看 立即下载

相关推荐

DevKit Advance devkitadv GBA开发环境

DevKit Advance devkitadv GBA开发环境 在人说在网上下载到的有毒,官网下的又装不了,现在我把我以前用的贡献出来。 如果你打算开发一个文件叫main.c的游戏,那么最好建个这样的.bat文件来帮助编译: PATH=C:\devkitadv\bin;%PATH% gcc -lm -o main.elf main.c objcopy -v -O binary main.elf main.bin pause

从GBA开始,步入ARM开发的殿堂(初学者入门篇)

GBA开始,步入ARM开发的殿堂(初学者入门篇)1.为什么要选用GBA作为嵌入式系统学习平台我们知道,任天堂公司的GameBoy Advance(简称GBA)一款非常出色的掌上游戏机,该产品占领了全球90%以上的掌上游戏机市场。抛开游戏功能不说,GBA本身就是一个很好的嵌入式系统开发学习平台,因为GBA采用ARM7 CPU(RISC),拥有240×160 64K色彩色液晶、立体声系统、按键、DMA

virginia的专栏 1万+

shiny-ninja:用 C++ 编写的 GBA 模拟器

闪亮忍者 用 C++ 编写的 GBA 模拟器。 GUI 使用 Qt5。 ShinyNinja 也可以在没有 GUI 的情况下使用“--no-gui”参数启动,后跟要加载的 ROM 文件的路径。 待办事项清单 中央处理器 实现其余的 ARM 操作码 ARM.3:分支和交换(BX、BLX) ARM.4:分支和链接分支(B、BL、BLX) ARM.5:数据处理 ARM.6:PSR 传输(MRS、MSR) ARM.7:乘法和乘法累加(MUL,MLA) ARM.9:单数据传输(LDR、STR、PLD) ARM.10:半字、双字和有符号数据传输 ARM.11:块数据传输(LDM、STM) ARM.12:单数据交换 (SWP) ARM.13:软件中断 (SWI) ARM.14:协处理器数据操作 (CDP) ARM.15:协处理器数据传输(LDC、STC) ARM.16:

GBA 开发简单入门

GBA 开发简单入门一. GBA开发包--DevKitAdv 简介 DevKitAdv 主要包括两部分,一是GCC++编译器,二是 GBA库. GCC++编译器功能和我们常用的VC差不多,只不过少了个编辑源代码的文本编辑器(至少我没发现,我用的是EditPlus,UltraEdit也可以),还有就是--不支持类(class),真是让人头痛,只能用struct来替代.它的作用是把我们写的代码编译

CrazyBOY 3157

gba编程手册(含中文版)

三种格式的gba编程手册:doc,chm,pdf。 其中chm和doc格式的为部分中文版。 研究gba游戏开发必备。

政府科技管理者在推动科技成果转化过程中,如何解决科研成果与市场需求脱节的问题?.docx

政府科技管理者在推动科技成果转化过程中,如何解决科研成果与市场需求脱节的问题?

GBA硬件规格与系统参数

GBA硬件规格(第一部分CPU,内存) 原来想一口气把声音,输入控制,中断,DMA的例程都写出来,我的例程都是编译通过的。现在看来应该先把GBA的硬件规格先写出来。 GBA硬件规格(第一部分CPU,内存) GBA系统由以下部分组成: CPU -16.78MHz ARM/tdmi 内存-根据应用的情况,有8-11个内存分区,有的是只读的,有的是可写的,详细见后。 输入输出-系统提供了图形,声音,DM

CrazyBOY 1万+

QMI8658姿态传感器实战:从校准到自检的完整避坑指南

本文详细解析了QMI8658姿态传感器的校准与自检流程,提供了从硬件环境搭建到高级功能开发的完整避坑指南。通过真实案例揭示电源设计、接口优化、温度补偿等关键细节,帮助开发者提升传感器精度和可靠性,适用于工业级应用场景。

weixin_29184075的博客 455

linux如何将图片转为gba数组,GBA 开发简单入门

GBA 开发简单入门一. GBA开发包--DevKitAdv 简介DevKitAdv 主要包括两部分,一是GCC++编译器,二是 GBA库.GCC++编译器功能和我们常用的VC差不多,只不过少了个编辑源代码的文本编辑器(至少我没发现,我用的是EditPlus,UltraEdit也可以),还有就是--不支持类(class),真是让人头痛,只能用struct来替代.它的作用是把我们写的代码编译成二进制...

weixin_33894125的博客 480

华为昇腾Atlas 200I DK A2实战:从开箱到运行首个AI应用

本文详细介绍了华为昇腾Atlas 200I DK A2开发板从开箱到运行首个AI应用的全过程。包括硬件准备、系统烧录、开发板连接方案、AI应用运行及性能优化技巧,帮助开发者快速上手部署AI项目,提升开发效率。

weixin_27038245的博客 591

基于改进YOLO11的天际线检测算法:复杂光照与恶劣天气适配实战

针对特定任务的YOLO改进,不应追求通用SOTA,而应深入理解任务的物理退化机理。Retinex对应光照模型、FAD对应散射模型、Wise-IoU对应边界不确定性——每个改进都有明确的物理解释,而非盲目的模块堆叠。时序一致性:引入轻量级RNN/Transformer模块利用视频帧间信息补偿单帧退化;多模态融合:结合红外/NIR波段穿透雾霾,与可见光特征在FAD-Neck中交叉注意力融合;自监督预训练:在海量无标注天际线视频上用MAE预训练Backbone,缓解恶劣天气标注稀缺问题。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 96

掌上游戏机开发指南——GBA程序开发入门

  1.GBA简介Game Boy Advanced(GBA)是日本任天堂公司于2001年推出的一款32位掌上游戏机。它着重于游戏机的便携式,并且以2D游戏为主(3D游戏依然不错)。GBA有十分高效硬件图像处理加速,GBA基本上是现在全球公认的最佳的掌上游戏机。GBA的硬件功能十分多。它的CPU是以RISC为基础的32位ARM CPU,主频是16.78MHz。屏幕最大支持240x160的1

CrazyBOY 5671

huggingface使用git上传model或者Dataset到HF,当然也可以上传代码,以及大文件,很哇塞!!!

huggingface使用git上传model或者Dataset到HF,当然也可以上传代码,以及大文件,很哇塞!!! 第一次使用时,需要使用设置系统全局的huggingface token,这。点击huggingface首页右上角的头像 → settings → access tokens,创建一个write权限的token,名字可以随便取。

拥抱具身智能,昇腾Ascend C 3105

GBA程序开发入门1

GBA程序开发入门1.GBA简介 Game Boy Advanced(GBA)是日本任天堂公司于2001年推出的一款32位掌上游戏机.它着重于游戏机的便携式,并且以2D游戏为主(3D游戏依然不错).GBA有十分高效硬件图像处理加速,GBA基本上是现在全球公认的最佳的掌上游戏机.GBA的硬件功能十分多.它的CPU是以RISC为基础的32位ARM CPU,主频是16.78MHz.屏幕最

Liang Tang's 专栏 9492

万字长文,小白新手怎么开始做YOLO实验,从零开始教!整体思路在这里,科研指南针!

万字长文,小白新手怎么开始做YOLO实验,从零开始教!整体思路在这里,科研指南针!

Coding... 1万+

【深度学习新浪潮】Nano Banana(Gemini 2.5 Flash Image)技术解析与开发者实操指南

重新定义了 AI 图像生成的产业标准。它不仅是“平民化的视觉工厂”,更是推动内容生产从“创意试错”转向“精准制造”的关键工具。未来,随着视频生成能力的加入(谷歌计划支持“文字指令 - 动态场景 - 多平台适配”全流程),Nano Banana 有望进一步颠覆影视、广告等领域的创作范式。:批量生成多场景图,模特姿态自然,服装褶皱和材质细节高度一致,节省 90% 拍摄成本。模型的非正式代号,是一款革命性的 AI 图像生成与编辑工具,主打。:生成细节丰富的厨师特写,光影自然,皮肤纹理和刀具反光逼真。

专注:太空算力、AI infra、异构调度、大模型成本工程 893

GBA编程和汉化常用软件汇总

内容来自GBA吧中的痴狂小黑,本人只是做个汇总和搬运。 1.简易图片导入导出套装(PicSimpleImEx & AutoPicRock)Ver1.0 这两个软件是用C#写的,想要用,先装dotNetFx40_Full_x86_x64.exe,然后重启主机; 这两个软件目前只支持GBA,格式为GBA(4BPP),今后打算支持SFC和GBA(2BPP)格式,如果想支持其他格式,可自行改

二哈的世界你永远不懂! 1万+

【数据集】中国2003年至2022年全天空每日气温数据集

中国2003年至2022年全天空每日气温数据集

WW、forever的博客 603

安装Devkit的过程

安装Devkit的过程简单说一下 下载那个7z的包,然后解压到一个目录, 运行 Ruby代码 1.ruby dk.rb init 2.ruby dk.rb review 3.ruby dk.rb install

baalwolf 504

16、Cortex-M7处理器:高性能与复杂架构解析

本文深入解析了Cortex-M7处理器的高性能架构与复杂设计,涵盖AHB总线矩阵优化、超标量六阶段双发射流水线、增强型分支预测单元及双精度浮点支持。重点介绍了其独特的内存层次结构,包括指令与数据TCM、片上缓存和AXI-M 64位总线接口,提升系统并行性与执行效率。通过实际测试对比M4与M7性能差异,并演示如何将代码与数据定位到TCM以实现零等待运行。同时阐述了缓存机制的工作原理及其对系统性能的影响,为开发者提供全面的性能优化指导。

a1b2c3d的博客 126

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

上一篇: The MD5 Message-Digest Algorithm
下一篇: 通过串口收发短消息(上)
amdk_7
博客等级 码龄22年 12粉丝 2原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值