当前位置:网站首页>基于Bevy游戏引擎和FPGA的双人游戏
基于Bevy游戏引擎和FPGA的双人游戏
2022-07-06 22:42:00 【biyezuopinvip】
资源下载地址:https://download.csdn.net/download/sheziqiong/85931377
资源下载地址:https://download.csdn.net/download/sheziqiong/85931377
接口技术
实验目的
- 熟悉 MIPSfpga 的软硬件协同开发
- 学会硬件调试方法
实验环境
操作系统:Windows 10
开发环境:
- 硬件开发:Vivado 2018.2
- 软件编译:MIPS 工具链
- GUI 实现:Bevy 游戏引擎
语言:
- MIPSfpga 软件:C
- GUI 实现:Rust
- 项目设计与实现
- 总体设计与实现
- 设计:通过 FPGA 上的串口功能,与 X86 主机进行信息交流,进而实现对游戏人物的移动控制。
实现:学校提供的 FPGA 实验平台有 UART 串口模块,通过串口转 USB 线可以实现和 X86 主机的信息收发,这点已经在前面的实验中实践过了。那么如何实现在程序中收到串口信息呢?很多编程语言都会有已经实现好的串口编程支持库,我们只需要调用 API 就行了。
硬件实现
硬件实现主要包括两部分,GPIO 和 UART 模块。
首先在 vivado 工程里面添加 GPIO 模块:
并且将中断源接到中断控制器 7 号端口:
然后添加 UART 模块并接到 AXI 总线上:
修改约束文件,将 SWITCH 相关的约束注释去掉:
在原先实验四代码的基础上,在中断处理函数_mips_handle_irq 里面添加对 GPIO 中断来源的判断,如果确认是来自 GPIO 的中断源,从 GPIO 里面读取值,然后通过 UART 发送到主机上。
代码:
void _mips_handle_irq(void* ctx, int reason) {
volatile unsigned int period;
volatile unsigned int rxData;
*WRITE_IO(IO_LEDR) = 0xF00F; // Display 0xF00F on LEDs to indicate enter the interrupt
data_received = 0x0;
if(reason & IS_UART_INTR && !(reason & IS_TIME_INTR)) {
/* Read an input value from the console. */
rxData = *READ_IO(UART_BASE + rbr);
data_received = 0x1;
}
else if(reason & IS_PWM_INTR) {
// 设置 pwm 值为 0
*WRITE_IO(PWM_BASE) = 0 * 110000;
}
else if(reason & IS_TIME_INTR) {
asm volatile ("mtc0 $0, $11");
asm volatile ("li $9, 0x1");
asm volatile ("mtc0 $9, $9");
}
else if(reason & IS_GPIO_INTR) {
volatile unsigned int sw = 0;
sw = *READ_IO(SW_LEDR);
uart_outbyte((char)sw);
}
else {
uart_print("Other interrupts occurred!\n\r");
uart_print(my_itoa(reason));
}
return;
}
然后 GUI 程序是使用了 Rust 语言编写,基于 Rust 语言开发的 Bevy 游戏引擎,我们实现了一款双人射击小游戏,两个角色分别通过键盘和 FPGA 板子进行控制。这里的关键问题是我们如何在 Rust 程序里面收到由 FPGA 发过来的信息呢?Rust 社区里面有一个实现好的开源串口编程库,我们调用这个库的 API 即可较为方便地实现串口通信功能。这个库的 GitHub 地址在这里:。然后用 Rust 语言实现的小游戏代码的 GitHub 地址在这里:。
软硬件结合起来的效果就是,拨动 FPGA 上的 switch 按键,会产生一个外部中断,这个中断在 C 程序里面的中断处理函数_mips_handle_irq 中被捕获,然后通过串口给主机发信息,主机收到信息后进行解析,然后角色进行相应的移动操作。这样子就实现了通过 FPGA 板子控制角色移动进行游戏。
系统运行结果
硬件连接:
游戏运行结果:
资源下载地址:https://download.csdn.net/download/sheziqiong/85931377
资源下载地址:https://download.csdn.net/download/sheziqiong/85931377
边栏推荐
- JS variable
- Why do many people misunderstand technical debt
- Markdown编辑器
- Test interview | how much can you answer the real test interview question of an Internet company?
- Detect when a tab bar item is pressed
- Ansible中的inventory主机清单(预祝你我有数不尽的鲜花和浪漫)
- 九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
- 史上最全学习率调整策略lr_scheduler
- Local tool [Navicat] connects to remote [MySQL] operation
- In depth analysis of kubebuilder
猜你喜欢
3GPP信道模型路损基础知识
[Android kotlin collaboration] use coroutinecontext to realize the retry logic after a network request fails
Lessons and thoughts of the first SQL injection
窗口可不是什么便宜的东西
Function pointer and pointer function in C language
AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘
Analyse approfondie de kubebuilder
R language principal component PCA, factor analysis, clustering analysis of regional economy analysis of Chongqing Economic Indicators
[hand torn STL] list
Ansible reports an error: "MSG": "invalid/incorrect password: permission denied, please try again“
随机推荐
3.基金的类型
[Yugong series] go teaching course 005 variables in July 2022
npm ERR! 400 Bad Request - PUT xxx - “devDependencies“ dep “xx“ is not a valid dependency name
Jetson nano configures pytorch deep learning environment / / to be improved
Windows are not cheap things
JS variable case
Leetcode notes
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot microservice code analysis and dialogue experim
If you ask me about R code debugging, I will tell you head, STR, help
STM32F103ZE+SHT30检测环境温度与湿度(IIC模拟时序)
Test interview | how much can you answer the real test interview question of an Internet company?
Wechat can play the trumpet. Pinduoduo was found guilty of infringement. The shipment of byte VR equipment ranks second in the world. Today, more big news is here
Oracle - views and sequences
Talk about the importance of making it clear
DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
R descriptive statistics and hypothesis testing
Leetcode minimum difference in student scores
How to design API interface and realize unified format return?
【Android Kotlin协程】利用CoroutineContext实现网络请求失败后重试逻辑
01 machine learning related regulations