User avatar
bitbank
Posts: 252
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

*NEW* - ILI9341(240x320 LCD) Library designed for gaming

Thu May 04, 2017 12:18 am

Due to my interest in retrogaming, I decided to write some code to talk directly to those inexpensive little 240x320 SPI LCD displays which use the ILI9341 controller. For my purposes, my game emulator code draws directly on the LCD, bypassing the framebuffer and its inherent latencies and limitations. My current game project (soon to be released) uses smart buffer management (dirty tiles) and hardware scrolling to achieve a steady 60fps output from many games. I've written emulators for NES, Genesis, TG16, GameBoy, GameGear/SMS and many coin-op titles. Today I'm releasing my ili9341 code which has the following features:

- Works in both landscape and portrait orientation
- Two sizes of text drawing with custom fg/bg color
- Fast 16x16 tile drawing for gaming
- Hardware scrolling (vertical/portrait direction only)
- Single pixel drawing
- Portable C code with wrapper functions for I/O; easy to compile on any system
- Uses either wiringPi, bcm2835, or PIGPIO to access SPI/GPIO

I will be releasing my game emulators (soon) which support this type of display and traditional framebuffer/SDL2/GTK output.

The git repo can be found here:
https://github.com/bitbank2/ILI9341

Here's an early video of my Pac-Man and Dig Dug (coin-op) emulators running with wiringPi (effectively 7fps of throughput), but getting 60fps through smart buffer management:
https://www.youtube.com/watch?v=tKnL1sJpcNo

I welcome any and all feedback.
Last edited by bitbank on Mon May 08, 2017 12:55 pm, edited 1 time in total.
The fastest code is none at all :)

User avatar
bitbank
Posts: 252
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: *NEW* - ILI9341 Library designed for gaming

Mon May 08, 2017 11:17 am

Progress update:
I've got my multi-system emulator running well on the RPi0W + 2.2" SPI LCD display. I'll release a binary of it soon and then the source code not long after that. The advantage it brings is that it makes those cheap SPI LCD displays more practical for gaming. No more 'tearing' on the display, and better frame rates since I eliminate the 'middle man' of the fbtft driver. Here's a short video of the latest code running a GBC game and a classic coin-op game:

https://goo.gl/photos/9DsgvQswbdPwUUuDA

If anyone is interested in helping me test it, please email me.
The fastest code is none at all :)

User avatar
bitbank
Posts: 252
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: *NEW* - ILI9341(240x320 LCD) Library designed for gaming

Sun May 14, 2017 1:39 pm

Latest update: I've now got the hardware scrolling working. For side-scrollers, this means less tearing and maintaining 60fps even with complicated scenery. Here's a short video showing how it looks:

https://www.youtube.com/watch?v=Pn4AXWC0IQs

I wrote the code to detect and implement hardware scrolling and the logic looked correct, but what tripped me up was unaligned memory accesses. It caused the program to misbehave, but not crash. On some ARM systems it causes an exception, but on the RPi, it causes inconsistent behavior. Now it's in good shape. I've also got direct GPIO pin reading for inputs (no need for GPioneer/Adafruit virtual keyboard). A few steps closer to release...

Update 5/15/07 - I've written a short article on the hows and whys of the project: https://docs.google.com/document/d/1NmE ... sp=sharing
The fastest code is none at all :)

Ti85
Posts: 19
Joined: Thu Oct 27, 2016 2:31 am

Re: *NEW* - ILI9341(240x320 LCD) Library designed for gaming

Wed May 17, 2017 5:13 pm

What a cool project...I look forward to more progress reports. I cannot wait to see the full emulator and LCD driver code

User avatar
bitbank
Posts: 252
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: *NEW* - ILI9341(240x320 LCD) Library designed for gaming

Thu Jun 08, 2017 9:21 pm

Quick update: I added support for a couple of other types of SPI LCD displays (st7735 - 128x160 and hx8357 - 320x480). I also added some simple code to read the x/y touch position from xpt2046 touch controllers. Since the project now supports more than just the ili9341, I deleted the ili9341 project and created a new repo:

https://github.com/bitbank2/SPI_LCD
The fastest code is none at all :)

User avatar
bitbank
Posts: 252
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: *NEW* - ILI9341(240x320 LCD) Library designed for gaming

Fri Jun 30, 2017 1:51 am

I'm now working with Shea Silverman and his PiPlay Portable project. The latest version of my emulator with an ili9341 on the PiPlay portable is looking pretty good. Very low latency and the usability is improving steadily. I'll keep updating here with news. Here's a video of the latest board running my code:

https://www.youtube.com/watch?v=J5SsFpn1SG8
The fastest code is none at all :)

Ti85
Posts: 19
Joined: Thu Oct 27, 2016 2:31 am

Re: *NEW* - ILI9341(240x320 LCD) Library designed for gaming

Thu Jul 27, 2017 11:56 pm

Bitbank

I noticed on your youtube channel you have a video showing a raspberry pi using sdl2.0. Can you post the code for that project on your github account. I have been trying to get sdl2.0 work on the raspberry for a longtime with little luck.

User avatar
bitbank
Posts: 252
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: *NEW* - ILI9341(240x320 LCD) Library designed for gaming

Tue Aug 01, 2017 3:29 pm

I'm not ready to share the whole source code yet. The key parts are to use a renderer and streaming texture. Code snipped below has error checking removed for brevity:

renderer = SDL_CreateRenderer(sdlwindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
texture = SDL_CreateTexture(renderer,
SDL_PIXELFORMAT_RGB565,
SDL_TEXTUREACCESS_STREAMING,
1024, 1024);

Then use SDL_RenderCopy() to get your pixels into the texture followed by SDL_RenderPresent() to display them on the screen. The opengl driver can scale the image in the SDL_RenderCopy() stage using hardware acceleration. This allows 60fps updates on a windowed SDL2 app on the RPi3.
The fastest code is none at all :)

Return to “Gaming”