Wedding 'save the Date' Disk With Hidden Message

26K8253

Intro: Wedding 'save the Date' Disk With Hidden Message

My now wife came up with a wonderfully nerdy idea to send out 3.5 inch floppy disks as 'save the date' reminders for our wedding. Feeling that my status as 'nerdiest' in the relationship was threatened I thought...

"Wouldn't it be great if we could put a secret message on the disks. Some kind of program that displays a secret message when you boot up your computer with the disk in the drive".

This instructable is a description of how I wrote a helper script in python and a healthy does of 8086 assembly to regain my 'nerdiest' status.

STEP 1: Plan

To make the secret message I originally explored a few ideas:

 1. Copy a text and or image file to the disk
 2. Find a copy of some floppy disk linux distro and setup an init script to display a message on boot
 3. Write to the boot sector of the disk and hope someone is silly enough to put the disk in before turning on their computer

Number 1 would have been relatively easy, but not nearly as fun. 2 seemed doable however I had some difficulty finding a working distro and 3 sounded like oh so much fun.

So, the basic plan was to find some way to make a custom 'boot disk' that when the computer is powered on with the disk in the drive a secret message will appear on the screen. For those of you too impatient to read the instructable, you can find the code to make your own secret message floppy disks here:

http://github.com/braingram/floppysecret

STEP 2: Dusting Off Old Webpages

After some google searching I found a series of awesome tutorials on linuxgazette.net on 'Writing Your Own Toy OS':
Part 1: http://linuxgazette.net/issue77/krishnakumar.html
Part 2: http://linuxgazette.net/issue79/krishnakumar.html
Part 3: http://linuxgazette.net/issue82/raghu.html

In short, these tutorials detail how to write some assembly code for 8086 type processors (i.e. 386s, 486s, Pentiums, etc...) to do epic things like display a single letter A on screen and more! These actually covered everything I needed to know to display a simple secret message on screen.

Rather than try to duplicate the tutorials I will just highly recommend that you go through at least parts 1 and 2. If you don't have a floppy drive or disks on hand don't worry. I did all of the development and debugging using qemu, a processor emulator, and only burned the resulting image to actual disks when I had worked out most of the bugs.

STEP 3: Setting Up Software

If you're lucky enough to be on a *nix system it's likely that Qemu is available through whatever package manager you use. On ubuntu, you can install it by typing:

sudo apt-get install qemu

or by searching for qemu in the software center (*shiver*). It looks like it may soon be renamed to qemu-kvm

On Macs, last time I checked qemu was available through homebrew (possibly also macports, fink, etc.).

On Windows... not sure. If anyone has a good link, please include it in the comments.

Finally, the source is available at: http://wiki.qemu.org/Download

Other software that you will need includes:
 1. as86 and ld86 (on ubuntu, available in the bin86 package: sudo apt-get install bin86)
 2. gcc
 3. python
 4. make

Here is all of it on one line for you ubuntuers:

sudo apt-get install qemu bin86 gcc python make

STEP 4: Working Through Tutorial Part 1

Now that your computer has the necessary software, it's time to work through part 1 of the "Writing Your Own Toy OS" tutorial. Now if you're not using a physical floppy drive you'll have to use a slightly modified write.c that writes the image to a file, not to a floppy.

I will include the text of write.c at the bottom of this step and also attach the file.

Finally, test the image (boot) that you made in the tutorial in qemu. When I first made these images, ubuntu sensibly named the qemu binary 'qemu'. Now, it appears that at least in 12.04 qemu is now 'kvm'. So, if you're not using a recent ubuntu the command you will want to run may be slightly different.

On Ubuntu 12.04:

kvm -fda boot.img

On other platforms where qemu is referred to as... qemu (*sigh*)

qemu -fda boot.img

At this point, a  window should pop up where the first character (eventually) becomes a white A on a black background.

------------------------ write.c -------------------------
#include /* unistd.h needs this */
#include     /* contains read/write */
#include

int main()
{
        char boot_buf[512];
        int floppy_desc, file_desc;


        file_desc = open("./boot", O_RDONLY);
        read(file_desc, boot_buf, 510);
        close(file_desc);

        boot_buf[510] = 0x55;
        boot_buf[511] = 0xaa;

        floppy_desc = open("./boot.img", O_RDWR | O_CREAT);
        lseek(floppy_desc, 0, SEEK_CUR);
        write(floppy_desc, boot_buf, 512);
        close(floppy_desc);
}

STEP 5: What You Can Do So Far

So now you can make a boot disk that displays simple characters on screen. The meat of the code is as follows

mov [0],#0x41; set the first character to ascii code 0x41 "A"
mov [1],#0x1f; set the 'attribute' of the first character

The attribute bits set the color of the character and background. 0x1f or %00011111 sets the background to blue (first 4 bits, 0001) and foreground to white (1111). One word of warning here, when i tested this out on a real machine I discovered that at least the computer I used also had a blink bit (woot!). From the following link, it should be bit 7 or (%10000000 = blink).

You can find more info here:
http://geezer.osdevbrasil.net/osd/cons/index.htm

Feel free to do what I did here, and play around with making all sorts of colored text (make all you design friends cry with yellow text on a white background) and display funny things like 'Feed me' etc...

This seemed very promising however I ran into a limitation where the boot sector on a floppy disk is only 512 bytes. This is fine for short messages, however if you want to do something fancier or more complicated you'll have to move on to part 2.

STEP 6: Part 2

I'll let part 2 of "Writing Your Own Toy OS" explain all the nitty gritty of getting the computer to run code that is not on the boot sector. Again, you'll have to make a few changes to write.c if you're not using a physical floppy drive (see attachment).

If all you want to do is display a short message than just change the lines:

     mov     cx,#26
and
     .ascii "Handling BIOS interrupts"

Change the 26 to the length of your string + 2 and the text in quotes to your message.

For example, a message like "Hello Human" would be 11 characters long so:

    mov      cx,#13
and
    .ascii "Hello Human"

STEP 7: Secret Message

The message I ended up displaying was 80x25 characters (standard display size). Rather than writing the assembly directly, I wrote a python script that:

 1. reads in a text file
 2. reads the ascii code of each character
 3. generates the 8086 assembly code for sect2.s to display the characters

The script is terribly ugly, but hopefully with what you've learned from these tutorials, you can change it to your liking. Setting the attr variable at the beginning of the file will change the text attributes (if you don't like the white on pink). Also, if you edit secret.txt you might want to make sure each line has 80 characters so that you fully define what is on screen.

STEP 8: Reception

Overall the disks went over quite well. At first, we told no one that they contained anything, hoping that someone would foolishly try to boot it as I probably would :). After a few weeks of suspense (and a few broken disks in the mail) we let people know that the disk was bootable. After that, several people dusted off their old computers, booted up the disks and were quite pleased to find the secret message.

I then proposed a challenge to a few of the more technically inclined invitees and I will pose the same challenge to you. There is a secret within the secret. There is some way to trigger the display of a second secret message (which you can easily find in the code). If you figure out the trigger, please post it in the comments along with a brief description of how you figured it out.

I've attached a zip file containing all the files related to parts 1 and 2 of the 'Writing Your Own Toy OS' tutorial and the final disk image with the 2 secret messages. Happy hunting!

53 Comments

I figured out one of the secrets. It's a variation on the Konami code. In sequence you enter the following:

Up Up Down Down Left Right Left Right B A Return

I figured it out by reading and altering gen_asm.py. I took out most of the key compares in the keyloop, then ran a new version of the image and pressed buttons. (I know I could've looked up key constants and whatnot) When I hit UP, I figured that there were some repeats in the sequence that seemed familiar.

Gives you the nice little message "Grow Up! :-)"
Ding ding ding! We have a winner! Nice work :)
I was just playing around a bit, I wanted to thank you for this instructable. This is actually the first assembler code I've looked at in ages. (I'm not even famliar with x86 assembler to begin with).

You've sparked my interest to keep looking into these things and experiment away .
This is wonderful to hear!

It gave me a certain sense of glee to move registers around and see results. I'm just glad that I could pass along a little bit of the enjoyment.

Maybe I'll see if I can get a version of tetris working... :)
I'd love to see something alike tetris, it'd be awesome if you could log the development process and maybe post it as an instructable?
Also, on a small note. You hardcoded the text attributes in some lines, so if you're changing the attr value, not all of the screen would be (in my case) blue and white, for example. All it takes is look where text is written and substitute 0xdf or 0x00df for 0x"""+attr+"""

that pretty much fixed up the attribute things.
Good catch. I'll make the code changes and hopefully spare a few viewers from pink screens.
What's a 3.5 inch floppy?
Can you even buy these any more ??
It was fun trying to find enough of these and of the right colors. We ended up buying some off of ebay and the rest from meritline.com. I do wonder if there are still floppy disk factories out there or if we're just wasting through the remaining stock from the 'age of the floppy'.
I think they've mostly ceased production, although there may be some limited production still going on. I think SONY officially quit making/having made both the drives and the disks.
I don't know if any 3.5 floppies are still being manufactured or not (don't know about 5.25 floppies either. I have a few 5.25 discs and a 5.25 drive on a Windows 2000 computer that is still in daily service) but 3.5s are still available at select retail outlets.
sure can, though its getting a bit more difficult ... whats surprising is you can still buy brand new 5.25 inch disks in both HD and DD
I assume it's some new kind of high-density storage medium. I'm excited to hear about it because I'm having trouble carrying my music collection back and forth from work. How many 3.5 inch floppy disks would I need to store my 80Gb mp3 library?
Nope. 3.5" floppies are decades old and were the standard portable data storage medium when I was a kid, however they have long since been rendered obsolete by optical media and flash drives.
about 55,556 if you can manage to not waste any space on the disk's
Thanks for the help osgeld. Now let's see. 55,556 disks x ~25 grams per disk = ~1400kg = ~3,000lb. Anyone know where I can buy a heavy-duty trailer??

But seriously braingram, your project really is cute. It will be one of the few save-the-dates people don't throw away.
Somebody should build a trailer sized jukebox that operates on floppy disks just for the curiousity factor. :P
More Comments