llemarie’s weblog

Programming, tinkering – Lionel Lemarié

Project: Javascript Game Boy Emulator

Posted by llemarie on February 6, 2011

Game Boy Emulator in Javascript

Game Boy Emulator in Javascript

A quick and dirty Game Boy emulator in Javascript.

– Can run Super Mario Land and Tetris (and not much else).
– Full speed (60fps) in Chrome 9.
– Menu to switch cartridges.
– Fast debugger.
– Register view.
– Code and data breakpoints.
– Memory view.
– Program flow trace with disassembler.
– Runs super-slow on iPhone.
– Comes as a single HTML file, data is embedded.

Give it a try here: Game Boy Emulator in Javascript. You’ll probably need Chrome or Safari.


Game Boy CPU Manual

Pan Docs

Game Boy Emulation in Javascript article series

Other implementations of the emulator:



Posted in Gameboy Emulator, Programming, Projects | 1 Comment »

Breakpoint 2010

Posted by llemarie on April 12, 2010

Breakpoint 2010Breakpoint ist tot ):

Posted in Breakpoint, Demoparty | Leave a Comment »

Project: The Black Art of Video Game Console Design

Posted by llemarie on April 11, 2010

XGS PEFor Christmas I got a game console: an XGameStation Pico Edition. It’s a small kit with all the components needed to build an 8-bit console. It comes with a breadboard and an optional swish PCB. The accompanying book The Black Art of Video Game Console Design, by André LaMothe, is a thousand page brick that takes you from what an electron is, through how to read resistors, how to read and draw schematics, how to use and interface logic gates, what’s in the power supply, what different 8-bit microprocessors and microcontrollers are offering (Z80, 6502, SX52), how to generate the video and sound signals in hardware with and without dedicated chips, to the final complete design of a working video game console. The final chapter takes you through the steps of building the XGS PE on a breadboard.
That was a very good read (although the first few chapters really are quite basic), and gave me a lot of ideas for a design of my own.

The XGS uses a SX52 microcontroller at 80MHz, which is quite powerful. I’m eying a 6502 and possibly 6581 for sound for my next project. I’ve got everything I need, all I need to do now is design it on paper to use a NES joystick and output mono sound and a PAL signal, lay it out in Eagle CAD, etch and drill the PCB, solder the chips and components, write a game in assembly, burn the machine code to the EEPROM, power the thing with a 9V battery and switch it on. Should work first time, I don’t see what could possibly cause trouble.

Posted in Projects, Propeller SX, Video Game Console | Leave a Comment »

Projects: ASCII keyboard emulator for Apple I Replica

Posted by llemarie on February 20, 2010

ArduinoASCII keyboard emulator

Last week I built an Apple I Replica from a Briel Computers kit. While I loved the completed machine, I suffered a bit from the fact that backspace doesn’t work (you have to type the assembly *exactly* correct), and of course it loses the RAM contents when shut down.

I wanted to make an interface to the PC so I could use a modern editor and simply copy-paste to the Apple I. As a quick and dirty solution to the problem, I used an Arduino, wired it to the ASCII keyboard port of the Apple I and wrote a small sketch that listens on the serial port and sets the data pins accordingly.

Photos on Flickr.

Here’s the Arduino sketch, real simple:

   ASCII keyboard
   Lionel Lemarie

   Listens on the serial port for characters from a PC.
   Outputs the codes like an ASCII keyboard.
   Compatible with Apple I Replica.

// The order of the pins is chosen for minimal wire crossing
// when connected to an ASCII keyboard socket.
int ASCII0 = 7;
int ASCII1 = 8;
int ASCII2 = 3;
int ASCII3 = 5;
int ASCII4 = 4;
int ASCII5 = 6;
int ASCII6 = 2;
int STROBE = 10;
int NRESET = 9; //reset active low

// LED will blink when a character is emitted
int LED = 13;
unsigned long previousMillis = 0;
unsigned long interval = 200;

void setup()
	analogReference(EXTERNAL); // Is this needed? 

	// Initialize the digital pins as output
	pinMode(ASCII0, OUTPUT);    
	pinMode(ASCII1, OUTPUT);    
	pinMode(ASCII2, OUTPUT);    
	pinMode(ASCII3, OUTPUT);    
	pinMode(ASCII4, OUTPUT);    
	pinMode(ASCII5, OUTPUT);    
	pinMode(ASCII6, OUTPUT);    
	pinMode(STROBE, OUTPUT);    
	pinMode(NRESET, OUTPUT);    

	pinMode(LED, OUTPUT);

	digitalWrite(STROBE, LOW);   // set the STROBE pin to inactive
	digitalWrite(NRESET, HIGH);  // set the RESET  pin to inactive


void loop()                    
	unsigned long currentMillis = millis();

	if (Serial.available() > 0)
		int iInput = Serial.read();
		iInput &= 127;

		if (iInput)
			if (iInput>='a' && iInput<='z')
				iInput = iInput - 'a' + 'A';

			int D6 = LOW;
			int D5 = LOW;
			int D4 = LOW;
			int D3 = LOW;
			int D2 = LOW;
			int D1 = LOW;
			int D0 = LOW;

			if ( iInput & 64 ) D6 = HIGH;
			if ( iInput & 32 ) D5 = HIGH;
			if ( iInput & 16 ) D4 = HIGH;
			if ( iInput &  8 ) D3 = HIGH;
			if ( iInput &  4 ) D2 = HIGH;
			if ( iInput &  2 ) D1 = HIGH;
			if ( iInput &  1 ) D0 = HIGH;

			digitalWrite(LED, HIGH);
			previousMillis = currentMillis;

			// Output an A (100 0001)
			digitalWrite(ASCII6, D6);
			digitalWrite(ASCII5, D5);
			digitalWrite(ASCII4, D4);
			digitalWrite(ASCII3, D3);
			digitalWrite(ASCII2, D2);
			digitalWrite(ASCII1, D1);
			digitalWrite(ASCII0, D0);
			digitalWrite(STROBE, HIGH);
			delay(40);  // strobe for 40ms
			digitalWrite(STROBE, LOW); 

	if ( (previousMillis>0) && (currentMillis-previousMillis>interval) )
		digitalWrite(LED, LOW);
		previousMillis = 0;

Posted in Apple I Replica, Arduino, Blogroll, Programming, Projects | 3 Comments »

Projects: Apple I Replica

Posted by llemarie on February 14, 2010

Apple I Replica

So last august I came across and bought an Apple I Replica kit, from Briel Computers. It’s a very cool little kit which includes a smallish PCB, a handful of components, all the ICs required (including the 6502 microprocessor and a Parallax microcontroller) and very easy instructions. The EEPROM has BASIC and an Assembler already in, so once you assemble the whole thing it’s ready to use. The schematics and manuals are included on a CD, although the package on the website is slightly more recent.

I had a couple of mishaps (dry solder joints, couldn’t find a suitable power supply, plugged in the ROM in the wrong slot). But nothing that destroyed the board, which is a bonus.

See all the steps in pictures in the Flickr set.

Next: make a hardware interface to connect a PC to the ASCII keyboard socket. I want to be able to type on the PC and send the keystrokes to the board, as if it was receiving it from a keyboard. The point being that I would type the programs in vi or notepad and “copy/paste” the code to the Apple I Replica. I plan to use an Atmel microcontroller to listen to the PC on USB or serial and simulate the keystroke for the ASCII keyboard port. Details on the (proper) ASCII keyboard can be found here.

Posted in Apple I Replica, Blogroll, Projects | Leave a Comment »

Tip: Connect to your iPhone using VNC and SSH

Posted by llemarie on September 5, 2009

VNC connection to iPhone

VNC connection to iPhone

After a short hiatus I thought I’d post something short and sweet to ease back into it.

There’s been quite a bit of news of people getting the location of their stolen iPhones via MobileMe. It’s also nice for your own peace of mind to be able to tell the phone to wipe itself so all your precious data doesn’t fall into thieving hands.

MobileMe is $99 a year though. Count me out.

Now I’ve previously talked about how to setup a tunnel to connect to a remote PC securely via Remote Desktop. In the same way it’s possible to connect to your iPhone securely, and, more importantly, wherever it has data access!

Here’s how to setup a persistent SSH tunnel from the iPhone to your home server that gives you SSH and VNC access to the phone.

You need:

– A home SSH server visible from the outside. If you want your phone to phone home, you need something to pick up.

– A jailbroken iPhone. If you don’t want to jailbreak it, there’s always MobileMe.

OpenSSH for iPhone. Install it via Cydia. Make sure you change the default passwd for both ‘root’ and ‘mobile’ users.

VNC server for iPhone. It’s called Veency, install it via Cydia. Go to the Settings and set a connection password.

Autossh. Install it via Cydia.

That’s it, now you just need a script to start the tunnel, another script to start the first script at load time, to register your phone ssh key on your home server and we’re done here.

The tunnel script, via the Terminal or a SFTP application (I recommend the free FileZilla), write it as /bin/autohome.sh:

export HOME=/var/root
autossh -M 20000 -f -2 -N -C -R *:50022:localhost:22 -R *:5901:localhost:5900 USERNAME@HOME

Set the permissions to 755 (chmod 755 /bin/autohome.sh, that’s read/write/execute as root, read/execute for others).

Easy enough. Set your USERNAME and HOME address to your public home SSH server. The only gotcha is the gatetime setting, it must be set to 0 to allow the connection to start at boot time: it will very likely fail a few times until the iPhone finds a data connection (3G or Wifi), but you want autossh to retry until it connects, which is not the default behaviour. Make sure that the file has the Linux end of lines.

The boot script, write it as /System/Library/LaunchDaemons/com.autohome.startup.plist:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”&gt;
<plist version=”1.0″>

Set the permissions to 644 (read/write as root, read only for others).

Now you need to be able to login to your home server from the phone without typing your password. You also don’t want to compromise the security of your home machine, if it can be avoided. For that, you can add a new user specifically for the phone (for instance ‘mobilemoi’), set its login shell to /bin/false (using the chsh command) and remove its password from the /etc/passwd file. Give this user access to nothing. Don’t forget to use this user in the tunnel script.

Login onto the iPhone via SSH as root (using putty.exe for example), run ssh-keygen using the default settings. We’ll need the public key that was just created, so cat ~/.ssh/id_rsa.pub and copy the string in the clipboard.

Login onto the home server as root, go in the ‘mobilemoi’ directory, create a .ssh directory, in there create a file called authorized_keys and paste the public key in there. From the mobilemoi directory, run chown -R mobilemoi.mobilemoi .ssh to set the right permissions.

Test it. On the phone, as root, run autohome.sh. On the home server, run netstat -a. After a short while, you should see the phone’s connections, lines like these:

tcp        0      0 Unknown-xxxx:ssh        xxxx:62595              ESTABLISHED
tcp6       0      0 [::]:20000              [::]:*                  LISTEN
tcp6       0      0 [::]:50022              [::]:*                  LISTEN
tcp6       0      0 [::]:5901               [::]:*                  LISTEN

If the connections look like “localhost:5901” instead of “*:5901” or “[::]:5901” then that’s a problem in the sshd config file. Edit /etc/ssh/sshd_config and add “GatewayPorts yes”. Restart the ssh server.

Now to connect to the iPhone and control it from any PC, install VNC, start the viewer, connect to the VNC server using your home SSH server address (likely on the internal IP) on port 1.

For example:

VNC Viewer settings

VNC Viewer settings

You can also use an SSH client to connect to the iPhone via the tunnel. Point the client to your home server (again the internal IP), on port 50022.

Right. Reboot your iPhone, make sure that the tunnels are created. You’re done.

Now every time you boot your iPhone, a tunnel is created to your home server. This gives you the IP of the phone (via the server logs), SSH access to the phone and VNC control of the phone. The possibilities are limitless!


As of the time of writing, I have not fully verified the drain on the battery that results from the permanent connection. I believe that it should be minimal, but it has yet to be observed. I will update the post with more information when I know for sure one way or the other. The connection parameters may need to be tweaked to minimise the impact on the battery life.

EDIT: After some experimentation, it appears that there is a toll on the battery life after all. I will continue to investigate.

Ideally the connection would start on demand. It would be nice to send a push message to the phone that would trigger the start of autossh. This would essentially be free (or no more costly than push notifications are) and offer the same functionality.

Thanks to Saurik for the most of the software needed for this feature.

Posted in Blogroll, iPhone, Remote Desktop, Tips | 28 Comments »

Programming: Beanie Fighter

Posted by llemarie on March 23, 2008

Dancing NinjasLive greetings from Breakpoint!

After a year of on and off development, with serious on development in the last few months, I finally got to submit my new 96KB game entry for Breakpoint. It ended up in a huge anti-climax, when nobody else submitted an entry and the 96KB game competition had to be canceled. The game was shown in glorious 12m wide 1080p though, in front of a great crowd!

I also gave a seminar, called Multicore Mayhem, presenting a technique for distributing code to the available CPUs. The video will be available on the Breakpoint website after the event.

Update: Due to a technical problem during the recording, the video is not available unfortunately…


Download the game here.

Posted in Beanie Fighter, Programming | Tagged: , | 12 Comments »

Tip: Updated: Use a higher resolution desktop than your monitor can support

Posted by llemarie on March 8, 2008

With the Asus Eee PC being so popular, there’s a lot of people looking to improve the real estate of their small computers. Here’s an update to my previous post to get fullscreen higher resolution on your monitor, be it small or big.

To make it clear: even though this technique uses Remote Desktop, it connects to the local machine only, there are no remote computers involved, no internet connections required.

There were a number of drawbacks with the technique described previously. The most annoying problems were:

  • the Remote Desktop window was not fullscreen, you could see the titlebar constantly,
  • the need for a port forwarder.

Enterprising users found solutions to both problems, so I think it’s time for an update!

1. How to allow multiple users to connect at once on Windows XP.

Get the Terminal Patch and install it. It’s really easy, just run the installer, there’s nothing to it. You need to reboot.

You can now login into your machine using multiple accounts at once, locally and using Remote Desktop.

2. Create a new user account and enable Fast User Switching

Add a new user whose sole purpose will be to Remote Desktop to localhost. Log-in as the new user for the remaining steps. No need to set the theme or anything.

To add a new user, open the Control Panel, open User Accounts, click “Create a new account”. Then enable Fast User Switching by clicking “Change the way users log on or off”.

3. Create a saved RDP session with scaled settings

Follow the instructions from here to create a .rdp file and add “smart sizing” to it.

Set the server to “”. Note that normally the local computer is but Remote Desktop will not let you connect to that address. Connecting to works however, which is strange but convenient!

Set the username as your normal username, not the new one.

4. Make it fullscreen

Update: Paul in the comments mentioned that the CTRL-ALT-PAUSE/BREAK key combination makes the remote desktop window fullscreen. It works great! No need for additional software.

Download one of those applications (Desktop Enhancers) that make any window fullscreen. I use the shareware FullScreen 2.5, but if you find a good one as freeware please do post it in the comments. I might write one at some point if there’s a demand for it.

That’s it! When you want high-res, simply log-in with your new account, start the connection by double-clicking on the .rdp : you’re connected as your usual user, ctrl-right click on the title bar to go fullscreen and voila.

Posted in Blogroll, Remote Desktop, Tips | Tagged: , , | 5 Comments »

Project: Change Housing on Z610i

Posted by slemarie on March 2, 2008

phone(Posted by Sarah)

So, after inadvertently stealing Lionel’s thunder when he bluetoothed his headphones and the world gave me all the credit, I thought I better get a project on here to prove that I can totally do stuff too. And also because Lionel wrote on my (retired) blog one time, and I need to get revenge return the favour.

So here’s the first thing I did. Inspired by my husband’s penchant for doing so, I took something apart. But then in a ground breaking revelation, I put it back together again! And now with my super helpful flickr set to follow, you can too.

My unwitting victim was a Sony Ericsson Z610i. They are cellphones of the supershiny clamshell variety, google for ‘z610i’ and you will most likely hit 1001 forums with dudes talking about how they just bought one for their wife. Please understand that usually, I lust after a phone with some pointless great new feature that I will never use, but it will destroy my battery life (cf. wifi on my N80, which I have successfully used outside my own home approximately 0 times. But I still changed my cell phone number, just to get this phone). Anyhow this time around, I just wanted a straight up clamshell, that would not cost the earth, and maybe even look nice.

So I bought the most badly abused phone you have ever seen on eBay. If Bride of Chucky had a cellphone, this is what it would look like. It was cheap, OK?

I blame eBay for most of my failings in life, and this time was no different. If there weren’t a vast array of very accessible alternative phone housings on eBay, I’d never have found myself musing one day how fascinating it would be to take my cell phone to pieces, check out the guts, and then while I’m at it rebuild it back into a shiny new case. What fun! Two weeks and one package from Hong Kong later, my vision was realised and with no thought for the possible consequences whatsoever I set about taking my phone apart.

I learned several things while doing this project.

1. Don’t just look for screws. Look for screw covers. Under screw covers, ye will find more screws.
2. It’s really hard to take phones apart until all the screws are out.
3. Screws 1, plastic wedge tool 0.

If you’re patient enough to try this at home, check out the flickr set photo descriptions for some running commentary and obvious statements such as “take this out of the old housing and put it in the new housing, in the same place”.

Most steps are fairly straightforward. I began by removing the casing on the base half first to minimise the amount of time that I was waving around the naked LCD displays. This seemed to work as an approach. When you begin, prize apart the new casing your ordered first (WHY do they piece it together!?) and take your time. Prizing casings apart works best if you run slowly and gently around the entire casing seam in slow gentle movements. Thin cheap plastic bends if you so much as sigh in frustration near it, so take your time and never tug something too far in any one direction unless you’re totally confident about the consequences.

It’s hard to tell from the final finished photos, but I actually broke my new casing in two places while opening/fitting it. The upper half of the keypad housing is particularly vulnerable at each side, as you only have two thin struts of plastic there while you’re levering off the ends of the casing. One snapped almost instantly in the first 30 seconds of my phone destruction newbie-ism, one gave up during my base-half reopening session as I attempted to reunite the keypad with its underlay. Fortunately both breaks were clean and reseated into each other well once held in place by the rest of the housing.

On the second snap, that half of the casing was suddenly freed by both breaks and allowed me to sit the Franken-phone down with case components sticking out in all directions rather casually.

“I’m nearly done. Honest. Just a few bits to finish.”

All in all I spent about four hours messing with it, involving far too long believing I had removed all the screws, and far too long rebuilding the base without first putting in the keypad underlay. You really want the keypad underlay, it’s what makes your keys work, as it turns out.

Would I do it again? Actually, yes. Paying a small amount for a new housing of decent quality and then cleaning your phone out definitely beats carrying your phone around in some second skin housing that will never look as great as your phone does on its own. For the last 18 months I’ve carried an N80 in a crystal case covering, and while it has preserved the phone excellently, it’s been even bigger and fatter than all its phone peers for the duration. Naff.

Did it go totally smoothly? No. I snapped the casing – recoverable in my case, fortunately – and now the camera isn’t working. All other features work as advertised, but the camera does nothing. There’s a fairly large connector near the hinge that you can disconnect, and I did – I highly suspect this is the source of my problem. Sometime when I decide a camera on a cell phone beats a Nikon D40, I’ll get around to looking at that.

The Z610i is a strange beast. Its features are utterly average and yet for some reason I have an irrational love of it as a phone. And now that it’s a shiny as it was always meant to be, I am complete!

Tune in next week for ‘Changing the housing on your husband’s macbook’. Am I kidding? Am I?

Posted in Blogroll, Projects, Z610i | Tagged: | 8 Comments »

Project: Head-tracking on PS3 – Now without glasses

Posted by llemarie on February 28, 2008

Well, the R&D guys at SCEA went and did it. They’re using facial recognition to track on head on the screen, instead of using IR LEDs strapped to your head. They demonstrated it at GDC, cool stuff!

The feat was reported by Kotaku, Gizmodo, Joystiq and others, but essentially they all point to the same video on mtv.com which has a silly IP ban for UK, Japan and Canada. Those countries clearly have no right to know about glassless headtracking.

Same video on youtube with no IP ban:

Posted in Blogroll, Head Tracking, Projects | Tagged: , , | Leave a Comment »