Monday, November 1, 2010

Bitmapped Sprites on the GirlTech IMME

by Travis Goodspeed <travis at>
with sprites by Eli Skipp,
extending Dave's LCD reversing,
and with thanks to Mike Ossmann.


The GirlTech IMME is a fine platform for radio hacking and embedded programming, but the LCD of the device is by no means designed for lightning fast graphics. In this brief article, I demonstrate the method by which a sprite library can be constructed which abstracts away the less neighborly minutia of the LCD in favor of a row-wise framebuffer that gets flushed to the LCD as appropriate. This isn't fast enough for a port of Sonic the Hedgehog, but it's certainly sufficient for ZombieGotcha, a network disease simulation game that Eli Skipp and I are prototyping.

To quickly recap, the GirlTech IMME is a children's toy powered by the CC1110F32, which combines an 8051 microcontroller with a versatile sub-GHz radio. The toy also includes a text LCD controller and keyboard, making it a delightful platform for embedded systems hacking and prototyping. Thanks to Dave's article on attaching a debugger and reversing the LCD, it is possible to wire a GoodFET into the IMME, allowing for debugging and reprogramming of the device.

Since the days of the first raster displays, computers have been drawing images as rows, because that's the way that a television's electron stream is traced along the display. The IMME draws rows internally, but because it is intended to draw fonts, its rows are eight pixels tall. For example, the bytes {0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00} are pushed to the LCD in order to draw an uppercase letter H in Dave's LCD Demo for the IMME. Drawing this on graph paper or rendering it by Python, it becomes clear that 0x7F represents a side of the letter, 0x08 represents the bar, and 0x00 is the space following the letter.

IMME Font 'H'

Rather than attempting to natively store a framebuffer in the LCD's format, I chose to internally index by row, then to translate during the export of the framebuffer to the LCD. My primary reason for doing this is to maintain portability of the ZombieGotcha code to custom hardware. It also simplifies the transcription of sprites from original bitmaps to C structures.

Having an internal framebuffer is not without cost, however. The buffer is 132 pixels wide and 64 pixels tall. Even with bit-packing, this is more than a kilobyte in size, consuming more than a quarter of the CC1110's 4kB of XDATA RAM. (Programs and sprites are stored in CODE Flash memory, of which there is 32kB, so this limit is not quite so severe as it sounds.)


My sprite toolchain is begun with bitmap images submitted by the artist. I cannot stress enough how important it is that your pixel artist understand pixels. Every sprite must be drawn at native resolution, with proper offsets of each frame and an understanding that the LCD is what it is, regardless of what Photoshop might render.

From the original bitmap sprites, PNM files are produced that are more easily parsed by Perl. This format consists of whitespace-delimited words for the format, width, and height of the sprite. In this case, the sprite consists of three frames, each of them being 24 pixels width and 32 pixels tall. Other sizes are possible, of course, but it is convenient for bit packing that the width is an even multiple of 8, so that the old pixels needn't be read back in.

PNM Format

It is then necessary to use an ugly Perl script to convert the sprite from a PNM to a C array of bytes. Pretty Perl won't work, of course, because such a thing doesn't exist. My script,, takes a 24-bit color PNM file and converts it to a 1-bit map that is byte-packed. Each of these is included by the preprocessor as a __code unsigned char[], with the __code keyword implying that the object should be stored in Flash rather than RAM.

Sprite animations are performed by storing the frame count along with the width and height in the C structure. Considering the resource constraints of this system, frame counts change very rarely and are stored within the C code.


Dumping the frame-buffer to the LCD is as simple as writing every stripe of data to the screen. Potentially, as an optimization, you could keep track of which stripes have been invalidated across what horizontal range, updating only where necessary.

Keeping in mind that the LCD is updated as stripes of 8 pixels in height, code such as the following will refresh the entire LCD from the frame-buffer. Be sure not to erase the LCD between writes, as that would cause unnecessary flickering.

Framebuffer Dump

The framebuffer elements themselves are grabbed by selecting the pixel index divided by 8, then masking off the selected bit. The following functions work admirably for this purpose.


If greater performance is required, a game should certainly be designed with a custom graphics library that optimizes the few things it does most. Performances can be gained by storing sprites and the frame-buffer natively in the row/stripe format that the LCD expects, simplifying conversion. Mike Ossmann used the technique of basing most graphics around vertical lines in his spectrum analyzer firmware, allowing for channels to be redrawned as they are scanned rather than flushed from a frame-buffer.

As the ZombieGotcha game is largely turn-based and the frame-rate is not a dire concern, I don't expect to optimize the sprite library much beyond what is presented here.

One major addition will be that of screenshots, as I'd like to produce animated GIFs of game action for the website. Screenshots can be produced by the method that I outline in CC1110 Instrumentation with Python, dumping the frame-buffer from XDATA with a GoodFET and writing that to disk. Alternatively, full-speed screenshots could be dumped by sniffing the LCD's SPI bus using a Total Phase Beagle or other SPI protocol analyzer.

For those of you with an IMME, Eli and I will be releasing the ZombieGotcha game at the Twenty-Seventh Chaos Communications Congress in Berlin this winter. We'll bring a bed of nails for reflashing IMME units on the spot, as well as GoodFET kits for modifying your IMME to be a development kit. (The ZombieGotcha will also run on full-custom hardware, but we are maintaining IMME support in parallel.)

As a final note, a teaser of the ZombieGotcha opening screen can be found here in the Intel-Hex format. I'll give a GoodFET40 kit to the first neighbor who sends me an animated GIF of it and a script to generate the same, either by a debugger or an emulator.


jrt-google said...

Used the Bus Pirate to sniff SPI, C program on PC to make PNM files, ImageMagick to render GIF.

The SPI bus ran too fast for Bus Pirate, so I had to hack the binary to lower the baud rate.

Will blog sources and method tomorrow.

Thanks for an evening's fun. Must sleep now...

Michael Ossmann said...

jrt-google is a real man.

jrt-google said...

Method and source code:

Thanks, that was a lot of fun :-)

lawyer said...
This comment has been removed by a blog administrator.
kite said...
This comment has been removed by a blog administrator.
PALMA said...

The GOODFET's microcontroller can be programed with the EZ430F2013??

Travis Goodspeed said...

Howdy Palma,

Every GoodFET is designed to be bootstrapped by USB. You do not need to already have a JTAG programmer of any kind in order to build it; just place the parts on the board and run 'goodfet.bsl --fromweb' to flash it.


Blogger said...

Searching for the Best Dating Website? Join to find your perfect date.

Blogger said...

If you want your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (no matter why you broke up) you must watch this video
right away...

(VIDEO) Text Your Ex Back?

Ana REx said...

If your man is pushing you away and acting distant

Or if the guy you’re after isn’t giving you the time of day...

Then it’s time to pull out all the stops.

Because 99% of the time, there is only 1 thing you can say to a standoffish guy that will grab him by the heartstrings-

And get his blood pumping at just the thought of you.

Insert subject line here and link it to: <=========> Your ex won’t be able to resist?

Once you say this to him, or even send this simple phrase in a text message...

It will flip his world upside down and you will suddenly find him chasing you-

And even begging to be with you.

Here’s what I’m talking about: <=========> Is your man hiding something? He may need your help?

Thanks again.

Michael Jones said...

Assignment Help online
Try to add only relevant data and information. If you feel that you are stuck, you can take assignment help online to get a proper idea. There are several web services which can help you to find out a suitable solution to your problems.

James Jenny said...

We know how difficult is to make time for writing assignments or completing your reports, especially when you have to meet a particular deadline. That's why we have assignment writing service, instant assignment help Australia for students. Enroll now!

gunmetal jeans said...

Thanks for some other informative website. Where else may just I get that type of information written in such a perfect means? I’ve a challenge that I am simply now working on, and I have been at the glance out for such info.

Shop Drawings Preparation in UK
Shop Drawings Preparation in India

Liam said... reviews

james cook said...

Allassignmenthelp is a web portal where students get assignment expert help for all the subjects, with the help of our experts. You will get 100% plagiarism free assignment.

Entertaining Game Channel said...

This is Very very nice article. Everyone should read. Thanks for sharing. Don't miss WORLD'S BEST TrainDrivingSimulatorFreeGames

Helen Henson said...

Awesome post

resellerclub | thesmespace | fstoppers | hubpages | mollysonic

Kelly Cain said...


Guest Blogger

Best Guest Blogging Site

Guest Posting Site

Guest Blogging Website

nike said...

Very informative Shop Drawings Preparation in UK

jacklinemelda said...

Every student has the chance of enjoying our affordable non plagiarized essays. The writers hired at the company are professionals with significant experience.

Neha Sharma said...

Rice Bags Manufacturers
Pouch Manufacturers
wall putty bag manufacturers
fertilizer bag manufacturers
Lyrics with music

Neha Sharma said...

we have provide the best ppc service.
ppc company in gurgaon
website designing company in Gurgaon
PPC company in Noida
seo company in gurgaon
PPC company in Mumbai
PPC company in Chandigarh

Neha Sharma said...

we have provide the best fridge repair service.
fridge repair in faridabad
Videocon Fridge Repair in Faridabad
Whirlpool Fridge Repair in Faridabad
Hitachi Fridge Repair In Faridabad
Washing Machine Repair in Noida
godrej washing machine repair in noida
whirlpool Washing Machine Repair in Noida
IFB washing Machine Repair in Noida
LG Washing Machine Repair in Noida

Neha Sharma said...

we have provide the best fridge repair service.
fridge repair in faridabad
Videocon Fridge Repair in Faridabad
Whirlpool Fridge Repair in Faridabad
Hitachi Fridge Repair In Faridabad
Washing Machine Repair in Noida
godrej washing machine repair in noida
whirlpool Washing Machine Repair in Noida
IFB washing Machine Repair in Noida
LG Washing Machine Repair in Noida

meldaresearch said...

We are prepared to deliver reliable and trusted Custom Research Paper Writing Services in all the outlined levels of study due to the many experts that we have in our company.Our Affordable Writing Services are affordable and cheap as well. Students have very limited cash flows, and their budgets are usually constrained.