【Avnet|FRDM-MCXN947试用活动】+ 移植NES游戏模拟器
本次尝试使用MCXN947驱动屏幕移植一个nes模拟器玩玩。之前在开源网站上找了一个NES的模拟器代码,这次就来试试移植到MCXN947上。
首先用lvgl的代码工程添加nes的代码。
!(https://www.eefocus.com/forum/data/attachment/forum/202412/04/174239lph9edkme87mmmag.png)
开始移植的时候有很多错误,经过几天努力终于可以编译成功了。
过程就不详细说了,参考例子改了好多地方。
添加绘图处理如下:
```
#include "stdint.h"
#include "nes.h"
#include "rom_mario.h"
#include "Tanks.h"
nes_t nes_console;
#define RGB565(r,g,b)((((uint32_t)(r)&0xf8)<<8)|(((uint32_t)(g)&0xfc)<<3)|((uint32_t)(b)&0xf8)>>3)
#define RGB888(r,g,b)(((uint32_t)(r)<<16)|((uint32_t)(g)<<8)|(uint32_t)(b))
#define RGB(r,g,b)RGB565(r,g,b)
static const uint16_t rgb_palette =
{
RGB(0x7C,0x7C,0x7C), RGB(0x00,0x00,0xFC), RGB(0x00,0x00,0xBC), RGB(0x44,0x28,0xBC), RGB(0x94,0x00,0x84), RGB(0xA8,0x00,0x20), RGB(0xA8,0x10,0x00), RGB(0x88,0x14,0x00),
RGB(0x50,0x30,0x00), RGB(0x00,0x78,0x00), RGB(0x00,0x68,0x00), RGB(0x00,0x58,0x00), RGB(0x00,0x40,0x58), RGB(0x00,0x00,0x00), RGB(0x00,0x00,0x00), RGB(0x00,0x00,0x00),
RGB(0xBC,0xBC,0xBC), RGB(0x00,0x78,0xF8), RGB(0x00,0x58,0xF8), RGB(0x68,0x44,0xFC), RGB(0xD8,0x00,0xCC), RGB(0xE4,0x00,0x58), RGB(0xF8,0x38,0x00), RGB(0xE4,0x5C,0x10),
RGB(0xAC,0x7C,0x00), RGB(0x00,0xB8,0x00), RGB(0x00,0xA8,0x00), RGB(0x00,0xA8,0x44), RGB(0x00,0x88,0x88), RGB(0x00,0x00,0x00), RGB(0x00,0x00,0x00), RGB(0x00,0x00,0x00),
RGB(0xF8,0xF8,0xF8), RGB(0x3C,0xBC,0xFC), RGB(0x68,0x88,0xFC), RGB(0x98,0x78,0xF8), RGB(0xF8,0x78,0xF8), RGB(0xF8,0x58,0x98), RGB(0xF8,0x78,0x58), RGB(0xFC,0xA0,0x44),
RGB(0xF8,0xB8,0x00), RGB(0xB8,0xF8,0x18), RGB(0x58,0xD8,0x54), RGB(0x58,0xF8,0x98), RGB(0x00,0xE8,0xD8), RGB(0x78,0x78,0x78), RGB(0x00,0x00,0x00), RGB(0x00,0x00,0x00),
RGB(0xFC,0xFC,0xFC), RGB(0xA4,0xE4,0xFC), RGB(0xB8,0xB8,0xF8), RGB(0xD8,0xB8,0xF8), RGB(0xF8,0xB8,0xF8), RGB(0xF8,0xA4,0xC0), RGB(0xF0,0xD0,0xB0), RGB(0xFC,0xE0,0xA8),
RGB(0xF8,0xD8,0x78), RGB(0xD8,0xF8,0x78), RGB(0xB8,0xF8,0xB8), RGB(0xB8,0xF8,0xD8), RGB(0x00,0xFC,0xFC), RGB(0xF8,0xD8,0xF8), RGB(0x00,0x00,0x00), RGB(0x00,0x00,0x00),
};
extern void DEMO_DrawBitmap(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t *color_p);
uint16_t frame_buff;
uint16_t ypos = 0;
void draw_pixels(void *ptTag,
uint_fast8_t y,
uint_fast8_t x,
uint_fast8_t chColor)
{
frame_buff = rgb_palette;
if((0x0F == (y & 0x0F))&&(255 == x))
{
DEMO_DrawBitmap(100,y-15,355,y,(uint16_t *)frame_buff);
}
}
void update_frame(uint8_t *ptFrame)
{
}
```
主任务添加如下初始化和运行代码:
!(https://www.eefocus.com/forum/data/attachment/forum/202412/04/174553npfksv844g6gffvf.png)
编译下载之后就可以看到游戏界面了,目前还只解决了画面,还不能操控游戏,下一步准备把触摸操控加上去。
实际效果如下:
!(https://www.eefocus.com/forum/data/attachment/forum/202412/04/175018qggy7cg33bb1k3m3.png)
!(https://www.eefocus.com/forum/data/attachment/forum/202412/04/175036b67vanqafqq5qdfw.png)
整个工程太大了就不上传了。下面放上nes的移植代码:
页:
[1]