llemarie’s weblog

Programming, tinkering – Lionel LemariĆ©

Archive for February, 2010

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
   2010-02

   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

	Serial.begin(9600);
}

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;
	}
}
Advertisements

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 »