1200 Baud Archeology: Reconstructing Apple I BASIC from a Cassette Tape

The audio file that was posted two weeks ago is indeed a very important artifact of computer history: It is a recording of the “Apple I BASIC” cassette tape that came with the Apple I. It is the first piece of Software ever sold by Apple (not counting computer firmware).

Here is the first confirmed perfect dump of the 4096 bytes: apple1basic.bin

The Apple I is extremely rare. Only 200 were built, and less than 100 are believed to be in existence. Neither Steve nor Woz own an Apple I any more, and neither does Apple Inc. (Update: Woz still owns some.) The cassettes are even rarer, as not every Apple I came with one. There has not been a dump of the tape until 2002, when Achim Breidenbach of Boinx Software got an MP3 recording of an original Apple 1 BASIC tape by Larry Nelson, an Apple I owner, and, with a little help from his father (who worked with an Apple I back in 1976), managed to decode it by writing a program – in GFA BASIC on an Atari ST. Here is a screenshot of the visualization this program could provide:

Achim wrote an Apple I emulator, included a commented disassembly of his Apple I BASIC dump, and published it on the internet. Other people continued working on the disassembly and changed instructions that they thought were mistakes in the dump. The only dump that can be easily found today includes these changes. It was time to analyze the tape again and get an authoritative dump of the 4096 bytes.

So here is how to decode the signal. Let us first open the audio file in Audacity and look at the waveform. The signal is mono, and as it turns out that the quality of the left channel is better, let us delete the other channel. This is what the whole ~35 second recording looks like:

There is silence at the beginning and at the end – but we can just as well hear that. We need to zoom in to see the actual waveform. From about 2 seconds to 12.4 seconds, when we hear a continuous beep, the signal signal consists of uniform waves:

Afterwards, during what sounds like noise, the waveform looks very different: There are shorter waves and loger waves.

The original output of the Apple I when writing the tape was a square wave, but the signal was filtered by the properties of the magnetic tape, so high frequencies were removed, and the signal became rounder. On the way back in from tape, the op-amp of the Cassette Interface converted the signal back into a square wave by converting all samples above a certain value into 1, and all samples below into 0. While the threshold in the op-amp was fixed, it could be effectively manipulated by changing the output volume of the cassette player. Effect->Amplify in Audacity gives us the following picture:

It is now time to write a small program to measure and dump the width of the pulses. We need to be able to parametrize the threshold (the volume knob) to be able to try different settings. In Audacity, we have to save the file as “WAV” first, because it is easy to decode this file format: We just skip the 44 byte header, and every following byte is a signed 16 bit value representing the sample.

First runs show us that all pulses in the first part of the file are around 56 samples long, while the rest of the file contains pulses which have a length of either around 22 or around 45. It seems the first part is a sync signal, so that the reader knows when the data starts. The two pulse lengths afterwards represent ones and zeros. It turns out that the shorter pulses are zeros; this way we get readable 6502 assembly code and some ASCII data (though with bit #7 set).

Here is a hexdump of the first few bytes:

0000000 4c b0 e2 ad 11 d0 10 fb ad 10 d0 60 8a 29 20 f0
0000010 23 a9 a0 85 e4 4c c9 e3 a9 20 c5 24 b0 0c a9 8d
0000020 a0 07 20 c9 e3 a9 a0 88 d0 f8 a0 00 b1 e2 e6 e2
0000030 d0 02 e6 e3 60 20 15 e7 20 76 e5 a5 e2 c5 e6 a5

In order to verify that our decoded data is correct, we must make sure that after the sync, there are only pulses that fall into the 22 or 45 category. If we play with the volume and find a volume region (i.e. different but similar volume settings) that has no pulse length errors and decodes into the same data, we can be confident that the data is correct. According to what is printed on the cassette, Apple 1 BASIC is supposed to reside in RAM at 0xE000 to 0xEFFF, so
the length of the decoded data should be 4096 bytes.

The following program is a possibly minimal implementation of the required algorithm:

apple1basic-decode.c

#include <stdio.h>

#define DIVISOR 30

int main() {
    int index = 0, last = 0, direction = 1, syncstate = 0, bitindex = 0;
    int distance;
    unsigned char outbyte;
    signed short sample;

    while (!feof(stdin)) {
        sample = getchar() | getchar()<<8;
        if (!direction) {
            if (sample>(32768/DIVISOR)) {
                distance = index-last;
                if (distance<50) {
                    if (syncstate == 2) {
                        outbyte = outbyte << 1 | (distance<32? 0:1);
                        if (!((++bitindex)&7)) putchar(outbyte);
                    }
                    if (syncstate == 1) syncstate++;
                } else if ((distance<70) && !syncstate)
                    syncstate++;
                last = index;
                direction++;
            }
        } else
            if (sample<-(32768/DIVISOR))
                direction--;
        index++;
    }

    return bitindex/8;
}

Run it like this:

cat apple1basic-mono.wav | ./apple1basic-decode > apple1basic.bin

You can optionally specify a parameter to the program which overrides the default value of 30 for "DIVISOR". Values between ~25 and ~95 will reconstruct the data correctly.

apple1basic.bin

If you can read 6502 assembly, you should definitely have a look at the disassembly, as this is very high quality (in the 1970s, this meant: very tightly compressed) code.

Update: You can run Apple I BASIC as a scripting language on Mac OS X now!

pixelstats trackingpixel

132 Responses to “1200 Baud Archeology: Reconstructing Apple I BASIC from a Cassette Tape”

  1. pagetable.com Âť Blog Archive Âť 1200 Baud Archeology: Reconstructing Apple I BASIC from a Cassette Tape…

    [...][...]…

  2. [...] perchè mi riesce difficile capirlo, un mp3 lungo 38 secondi. Operazione svolta e descritta su pagetable.com, nel caso desideraste approfondire [...]

  3. [...] Read | Permalink | Email this | Comments [...]

  4. Greg Finzer says:

    Wow, this is really cool. It is amazing what programmers could do with only 4096K of memory.

  5. [...] you’ll have to determine whether venturing down is something your brain can handle.[Via BoingBoing]Read | Permalink | Email [...]

  6. [...] pagetable.com » Blog Archive » 1200 Baud Archeology: Reconstructing Apple I BASIC from a… Listen to the audio from the “Apple I BASIC” cassette tape that came with the Apple I. apple audio basic history programming retro [...]

  7. Edwin says:

    The Apple I BASIC cassette wasn’t even included with all of the 200 Apple Is produced eons ago, but a few engineering souls have managed to extract the data and create an MP3 of the wave structure. Not surprisingly, the tone resembles that of a 1200 Baud connection, and if we should say so ourselves, would make for a wicked ringtone.

  8. [...] 1976 Apple I was the first system besides the KIM to use the MOS 6502 CPU, but Steve Wozniak wrote his own 4KB BASIC interpreter instead of licensing Microsoft’s. An enhanced version of Woz’ “Integer [...]

  9. Search PDF says:

    this is really cool. It is amazing what programmers could do with only 4096K of memory.

  10. Derek says:

    Since these old computers had audio in and audio out, does that mean that they could send data over the phone lines without a modem?

  11. free ebooks says:

    crazy idea, only use 4096K of memory . two thumbs up :)

  12. Apple says:

    Apple…

    The audio file that was posted two weeks ago is indeed a very important artifact of computer history [...]…

  13. pdf search says:

    I use apple since 5 years ago and i dont know if there such programme can use to do this with only use 4096K of memory.

  14. Simba7 says:

    I think most people mean 4096 bytes (4kb) of memory.

    Still, incredible. If we still did things in assembly, things wouldn’t be soo darn bloated and higher quality code would exist.

  15. Boogie Down says:

    dna

  16. Dr. Kenneth Noisewater says:

    “Still, incredible. If we still did things in assembly, things wouldn’t be soo darn bloated and higher quality code would exist.”

    You mean unmaintanable and unportable code.. GIGO applies to assembly code just as surely as it does to higher-level languages, and if it was so fantastic the ‘market’ would not have needed HLLs..

    That said, it’s still pretty amazing how much folks could squeeze into 4KB back in the day, just like it’s amazing how Greek stonemasons could build seamless columns, and how many artisan skills from antiquity have been lost, with folks today trying to relearn them..

  17. Joe Whitehead says:

    http://home.comcast.net/~mjmahon/AP1BASIC.txt
    The old link is dead. :(

  18. pdf search says:

    So the first ever software for PC was on tape. Hilarious.

  19. mac apple says:

    macbook…

    [...]1200 Baud Archeology: Reconstructing Apple I BASIC from a Cassette Tape « pagetable.com[...]…

  20. Jazz says:

    i wonder if ARDUINO peeps could make this boot on actual HW?

  21. The attractive town hall is situated in Southern paphos car hire.
    You’re driving on the left side of the device, thinner now and the holidays. Electrical power paphos car hire corporations with Florida. If you are living overseas in Paphos Car Hire. A useful point was made by Peter White, from Cambridge. Check if your insurance policy covers.

  22. Hello there, You have done a great job. I will certainly digg it and personally suggest
    to my friends. I’m sure they will be benefited from this web site.

  23. Undeniably consider that that you said. Your
    favourite reason appeared to be at the internet the easiest factor
    to be aware of. I say to you, I certainly get annoyed even as other people think about issues that
    they just don’t understand about. You managed to hit the
    nail upon the highest as neatly as defined out the entire thing with no need side-effects , other folks
    could take a signal. Will likely be back to get more.
    Thank you

  24. how to write a good song…

    1200 Baud Archeology: Reconstructing Apple I BASIC from a Cassette Tape ? pagetable.com…

  25. radiology technician schools…

    1200 Baud Archeology: Reconstructing Apple I BASIC from a Cassette Tape ? pagetable.com…

  26. If you ?a?t tto obtain a gkod deal from thks article then yo? have to apply ?uch
    strategies to your won blog.

    my blog post: how can I get fit for football

  27. The basis of special theory of relativity is that
    the velocity of light was absolute, albeit, all other velocities are relative.
    What these discoveries show is that with or without planet X passing
    by, major eruptions on the surface of the sun will be more of a threat to Earth in the year 2012 than any previous point in history.
    What?s more is that with special gameplay features such as running
    of rooftops and hiding from enemies in haystacks, this has become one
    of those games that offers espionage in an older environment.

  28. Check out the Web, as many agents as well as private sellers
    will advertise through this medium. [3] It is the
    third and smallest incorporated municipality in Hillsborough County.
    You should think sensibly and show some experience in real estate property transactions.

  29. Of course, they would want to have the smooth-looking skin like that of the young individuals.

    Herbal HGH drugs cost much less than injections or
    oral sprays and would not have the unfavourable complications.
    You can easily notice this stage as the person stops growing.

  30. The key to using a plunger effectively is usually to create a seal round the surface area that you are typically
    plumbing. The wise thing to do is to locate a good
    drain cleaning firm and see that the problem is
    resolved in time, avoiding any kind of problem. Things get flushed away that were never meant
    to ‘ from diapers and feminine hygiene items.

  31. It’s the best time to make some plans for the future and it’s time to be happy.
    I have read this post and if I could I want to suggest you some interesting
    things or tips. Perhaps you can write next articles referring to this article.
    I wish to read even more things about it!

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word