It’s Pi-day :D

GCat’s adventures with a credit card-sized computer.

It’s months now since I blogged about the Raspberry Pi. At the time I said I was getting really excited about it. Well, my excitement did start to wane a bit after getting up at 5.45am on the release day (February 29th) only to find the level of interest had practically melted the servers of both supplying companies and there was very little chance of getting hold of one any time soon. I was still intending to buy one when some of the mayhem had died down, but I hadn’t given it so much thought lately. Then suddenly yesterday one of my colleagues walked into my office without any warning and handed one to me!

I couldn’t wait to give it a try. Unfortunately I didn’t have a screen in the office that it could hook up to immediately (it needs HDMI or composite, VGA or DVI monitor plugs are no use) so all I could do was download the software ready to try it out (it needs a custom version of Linux on an SD card) while casting occasional excited glances at the box. But luckily there’s a nice HDMI TV in my living room…

My first reaction was: wow, this thing really is tiny! I mean, I knew it was credit card-sized and all, but even so, it’s still hard to believe just how small it is until you see one in the flesh, so to speak. I was even more amazed by the size of the main processor (the black square chip just by my fingernail in the photo and about the same size!).

Hooking everything up to it reminded me of connecting up one of our old computers and brought back happy memories of geekily spent Christmases and so on. In the picture, the power is coming from my HTC phone charger and going into the micro USB connector on the lower left corner. The SD card with the Linux OS is the blue thing protruding out from underneath the board just by the power connector. The grey plug going into the near side is the HDMI cable to my television. The green cable coiling round the whole thing is ethernet to connect it to the internet (it doesn’t have built in wifi so it needs either a cable connection or an external USB wifi dongle). Finally, the two black plugs next to the ethernet are my ordinary USB keyboard and mouse.

With trepidation, I double checked all the connections and then turned the power on. Would it work? I’d seen reports that certain SD cards wouldn’t work properly so I knew there was a chance I’d got a bad one or that I’d messed up the OS install.

Success! I could see the raspberry logo on the screen and the Linux boot messages scrolling past (looking very tiny in full 1080p resolution). Soon I had the desktop environment running and was verifying that it was indeed capable of viewing pointless web pages.

It was pretty easy to get up and running by following the quick-start instructions on the Raspberry Pi website. It was a little bit sluggish for browsing the net, but that’s to be expected with such a low-powered machine with a chip designed for mobile phones but running a full desktop system. Apparently this will get better once X Windows (the software that provides the graphical user interface on Linux) is using the Raspberry Pi’s rather capable GPU to do most of the drawing instead of doing everything on the main processor as it is at present.

But nice though it was to see my blog on the big screen courtesy of the Pi, I was more interested in getting some of my own code up and running on it. After a quick break to redo the partitioning on the SD card (so that I could use the full 16GB of space rather than the default less than 2) and install my favourite geeky text editor, it was time to delve into the code examples.

As the Raspberry Pi is intended for teaching programming, it comes with some nice example programs showing how to make it do various things (play video, play sound, display 3D graphics, etc.). I’d decided for my first project I was going to try and get one of my emulators up and running on it; the architecture is actually very similar to my phone’s so even though the emulators contain quite a lot of assembly language code that would have no chance of working on a normal PC, they should work on the Pi without too much trouble. I decided to start with the Master System one as it’s a bit simpler than the others.

After an hour or two of hacking, I had something working.

As expected I didn’t need to change very much in the code. I just replaced the “top layer” that previously communicated with the Android operating system with a new bit of code to send the graphics to the Raspberry Pi GPU via OpenGL ES. (Although that’s mainly for 3D graphics, you can do some nice 2D graphics on it too if you more or less just ignore the third dimension).

The emulator isn’t fully working yet… there’s no sound (I need to look at the sound example that came with the Pi but it shouldn’t be too hard), no way to actually control it (that screenshot is just showing the demo running on its own – I need to figure out how to get key presses in the right form), and there are a few other glitches (the graphics seem to extend slightly off the edges of the screen and the timing is a bit off). But overall I’m reasonably pleased with my first few hours with a Pi 🙂

Update: the Master System emulator is now closer to being finished and you can download it from here.

My Android Apps

I’ve had my Android phone about 18 months now. As the sort of person who likes to program everything that isn’t nailed down (starting from my dad’s ZX Spectrum and eventually progressing up to supercomputers) I just had to have a go at making some apps.

Android is good for coding your own apps, which is one of the reasons I chose it. For iPhone and iPad you need to use a Mac for development (which I don’t have and have no intention of getting) and you also have to either pay a developer fee of $99 per year or jailbreak your device. Even then you can’t test your code on anyone else’s phone unless they also pay the fee or jailbreak it. Thankfully Android is more accessible for programmers… you can just download a free software development kit for Windows, Mac or Linux and get started straight away.

Most of my apps are quite boring. There’s one that backs up all my contacts and text messages to a file and puts it in my Dropbox folder automatically. That was the first one I wrote and I’ve used it a lot ever since, though I improved it and added the Dropbox integration more recently. Another keeps track of my finances, and there’s one that allows me to access the task tracker I use (without which my life would probably be frighteningly close to unravelling completely) from my phone. But the most fun ones are the emulators.

Emulators are programs that make a computer behave like a different kind of computer. They let you run old programs on hardware that didn’t even exist when they were written. There are huge numbers of emulators out there allowing you to turn your PC into any kind of old, clunky computer or console imaginable. They’ve always interested me, partly because I like old computers for nostalgic reasons and partly because of the technical intricacy that goes into making emulators work. So since I started programming on the Spectrum and could still just about remember how it works inside out, it seemed fitting that I should code a Spectrum emulator for Android.

Here it is, running one of my favourite old games (Spellbound Dizzy) on my phone. I’m quite proud of it… I think it works rather well. (If your definition of “well” encompasses turning a cutting edge smartphone into an ancient, primitive computer, that is 😉 ). It runs at full speed, which the other emulators I tested didn’t seem to quite manage on my slow-ish HTC Wildfire.

Then I decided that at this point it wouldn’t be too much work to make a Sega Master System emulator as well. I never owned a Master System (went straight from the Spectrum to Megadrive and our first PC) but I loved playing Sonic on other people’s whenever I got the chance.

It uses exactly the same main processor as the Spectrum and a lot of the other emulator code could be shared as well, so I got it up and running a lot quicker than the first one. The only hard bit was getting the Master System’s graphics working properly.

Finally (for now) I did a Gameboy emulator as well:

Tetris is even fiddlier to play with the controller on the touchscreen, though.

If you have an Android phone and feel like reliving the games of the early 90s, you can play with my emulators too. I put them online here (you will need to have the “Unknown sources” box ticked in your application settings to be able to install them). I’ve only tested them on two phones so far so it’s possible they won’t play well on all devices. If they don’t seem to work properly, please feel free to get in touch and I might be able to fix them, though I can’t promise anything. There are probably better emulators out there for all these machines, I really just made these ones for my own amusement.

(As well as installing the emulator app, you will need to put some games on your memory card. There are hundreds if not thousands of Spectrum games on World of Spectrum, which seems to be at least semi-legitimate. I don’t know of any legal sites for Gameboy and Master System ROMs but they’re pretty easy to find by googling anyway).

Have fun :).