当前位置:网站首页>基于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
边栏推荐
- R语言主成分pca、因子分析、聚类对地区经济研究分析重庆市经济指标
- PLC模拟量输出 模拟量输出FB analog2NDA(三菱FX3U)
- 树与图的深度优先遍历模版原理
- Jetson nano配置pytorch深度学习环境//待完善
- Section 1: (3) logic chip process substrate selection
- STM32F103ZE+SHT30检测环境温度与湿度(IIC模拟时序)
- Tree map: tree view - draw covid-19 array diagram
- What work items do programmers hate most in their daily work?
- acwing 843. n-皇后问题
- Depth first traversal template principle of tree and graph
猜你喜欢
Monitoring cannot be started after Oracle modifies the computer name
【736. Lisp 语法解析】
Oracle - views and sequences
Field data acquisition and edge calculation scheme of CNC machine tools
Error: No named parameter with the name ‘foregroundColor‘
How to choose an offer and what factors should be considered
System framework of PureMVC
Tree map: tree view - draw covid-19 array diagram
How to design API interface and realize unified format return?
Ansible报错:“msg“: “Invalid/incorrect password: Permission denied, please try again.“
随机推荐
Function pointer and pointer function in C language
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
R descriptive statistics and hypothesis testing
【ArcGIS教程】专题图制作-人口密度分布图——人口密度分析
When knative meets webassembly
Vscode 如何使用内置浏览器?
STM32 system timer flashing LED
PLC模拟量输出 模拟量输出FB analog2NDA(三菱FX3U)
U++ 元数据说明符 学习笔记
Meow, come, come: do you really know if, if else
NiO related knowledge points (I)
Ansible中的inventory主機清單(預祝你我有數不盡的鮮花和浪漫)
Leetcode minimum difference in student scores
装饰器基础学习02
A simple and beautiful regression table is produced in one line of code~
Basic idea of counting and sorting
Leetcode longest public prefix
ClickHouse(03)ClickHouse怎么安装和部署
【Android Kotlin协程】利用CoroutineContext实现网络请求失败后重试逻辑
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