Boot Sector Games

Boot Sector Games


I’ve always been fascinated by very efficiently
programmed games or demos. The Atari 2600 is an interesting example on
its own since the early games like Pac-Man had to fit in 4K of ROM. While later cartridges ended up using bank
switching to get 8K or even more, the early games really had to be coded very efficiently,
and often meant sacrificing complex features of the game. But if you think 4K would be tough to code
for, how about 2K? My friend Robin Harbron coded this little
game called Minima, which is a play on words for the Ultima games. It’s a little role playing game that fits
in 2K of code. Very impressive. But can you go even smaller? Well, yeah. Here’s another one. This is called “SPlatform” and fits in
a meager 1K of RAM. So, to put things into perspective, how much
is 1K exactly? Well, each of these dots represents a single
byte. And here’s 1,024 of them. Now, you’re typical assembly language instruction
takes up anywhere from 1 to 3 bytes. So, you could probably have a total of around
400 actual instructions. But that wouldn’t leave any room for data,
graphics, sound, or even text. So, it would be a very delicate balance between
instructions and data. But what about even smaller than this? Indeed, could games be written in just 512
bytes of RAM? It turns out, yes they can. In fact, 512 bytes is a magic number because
that means it can fit into a boot sector! So, just a refresher here from my floppy disk
documentary from a couple of years ago. Your typical 360K floppy disk for an IBM or
compatible has 40 tracks starting from the outer rim to the inner core. And then the disk is divided up into 9 sectors
like this. The boot sector is the first sector of track
zero. And as you can see, it’s a very small portion
of the disk surface. Of course, that’s a 360K disk. What about the more common 1.44 MB floppy
disk that most people are familiar with? That format has twice as many tracks, and
twice as many sectors. But a single sector is still just 512 bytes,
so that means it is an even smaller portion of the disk surface. So, what does this boot sector do? Well, the BIOS is in a ROM chip on the motherboard,
but that’s not really an operating system. So, the BIOS has just enough code to read
the boot sector into RAM and then execute it. But the boot sector isn’t big enough to
contain a whole operating system, so it’s purpose is to load the real operating system
into RAM, such as DOS, Windows, or Linux. You might be surprised to find that, at least
on the IBM PC and compatible computers, every floppy disk and hard disk has a boot sector. And, there’s a program installed on every
boot sector, even if the disk is blank. Have you ever accidentally left a floppy disk
in the drive during boot and see the message that says “Invalid System Disk. Replace the disk, then press any key.” Now, you might think this message is coming
from the BIOS ROM. And that would be a good guess. But if that were the case, then how would
you explain this. When I put a different blank disk in, the
message changes. Now it says “non system disk or disk error.” What’s the difference? Well, the first disk was formatted with Windows
95, the second disk was formatted with MS-DOS. And that message you seen the screen is actually
a small program in the boot sector of an otherwise blank disk, which displays this message. Using a sector editor, you could actually
change this message to anything. For example, I changed the message on the
Planet X3 disk so that it says a custom message, and then continues to boot to your hard drive
if you have one. Boot sectors were also historically targeted
by viruses. The viruses were just small programs that
lived in the boot sector and then they would load the operating system afterwords. And then, they would copy themselves to either
the boot sector on your hard drive or other floppy disks and because the virus loaded
in the boot sector, that means it loaded before the operating system, giving it a higher level
of control. Now that you definitely know what a boot sector
is, can you imagine how hard it would be to write an actual game that fits in just 512
bytes? Well, what I have here is a space invaders
game written by Oscar Toledo. And the whole thing is on the boot sector. And I want you to watch how quickly this boots
up. Keep in mind it hasn’t even finished the
power on self test yet. And there it is. I want to illustrate this from a different
angle. See there, that’s the floppy disk light
during the test cycle. The next time you see that light, that means
it’s trying to boot, so watch how quickly the game starts after you see the light. Its super fast, not only because there is
no operating system to load first, but because the drive’s head doesn’t even have to
seek. Literally, all it takes is a single revolution
of the disk to get the boot sector read into system RAM. Of course, this isn’t the best version of
space invaders ever. Its very clear that many concessions were
made. For example, there is no score board, no UFO
across the top, and all of the aliens look exactly the same. Oh, and there are no sound effects or music
either. But still, you can’t deny the skill involved
to make this fit in a boot sector. So, besides space invaders, what other games
are out there? This is another one. It’s called F-Bird, and if it isn’t obvious
it’s a knock-off of flappy bird. Only, this version runs in text mode, using
only ASCII characters for the graphics. One interesting thing about this game is that
I think it’s the only one I have to show you today that actually has sound effects
of any sort. Here’s another one, this is called Pillman. I guess because he eats so many little pills. With all of those ghosts chasing him, I hope
they are Xanax. Anyway, this one also runs in VGA graphics
mode, but there’s something I find very interesting about it. If you look down in the bottom-left corner
you’ll see some weird flashing pixels. It looks like about 20 of them. I suspect what is happening here is that the
author of this game is using the extra screen RAM as variable space for the game. You can actually see specific changes, for
example, when Pillman changes direction. Which means, this game may only need a couple
of dozen bytes of RAM for variables. It’s really blurry trying to zoom into these
from a screen capture, but here’s a still-shot from DOSBOX. This is reminiscent of the Atari 2600, since
it only had 128 bytes of RAM. Speaking of DOSBOX. Many people may be wondering how I’m booting
a raw disk image like this from DOSBOX. Well, it’s actually quite easy. So, once you have DOSBOX open, you just type
the command BOOT, following by the path to the disk image you want to use, in this case
TetrOS. I assume that is an amalgamation of the words
Tetris and Operating System, since the game is its own operating system. So yeah, this is a very playable version of
Tetris, that fits completely in a boot sector. There are other things besides games. For example, this is a functional version
off BASIC that runs from a boot sector. This is one of the example programs you can
type in, which creates a pascal triangle. This version of BASIC is very limited, however. It has a very limited command set, and each
line can only be 19 characters long. So you aren’t going to be able to make anything
super exciting. Plus, I don’t think there is any way to
load and save your work. OK, now being realistic for a moment, none
of these games are that great in that you’re not going to want to sit down and play them
for hours on end. I suspect the people who wrote the games probably
had more fun writing them than they did playing them. And of course, that’s the whole point of
these games is to challenge one’s self to see, you know, how much you can fit into a
very confined space. And so, I just, I have a great admiration
for anyone who can fit a game into 512 bytes of RAM, but anyway that’s actually all I’ve
got for this episode, so stick around for the next one and thanks for watching!

100 Comments on "Boot Sector Games"


  1. Great video, never seen such small games run on a PC. The drawing for ter floppy drive sectors is not acurate though – a 9 sector disk has 4 and a half sectors on each side per track.

    Reply

  2. I remember the magic of the early demo scene. Put a floppy into my Amiga, it reads for a second, and then some unbelievable high class graphics stuff and awesome music pops up. Good times.

    Reply

  3. It makes me remember of those 64K animation contests… One of them generated more than 14min of audio and videos with textures… Out of the curve guys.

    Reply

  4. Era have changed so much. Now we have got 8G, 16G, 32G or more of RAM, compared with those years when they only have 16K, 64K or 128K of RAM, they have got infinite of RAM, so they no need to consider efficiency coding, add more useless features. Like Win 10, I believe many of users actually only use features already exists in 2000, XP, or even 98.

    Reply

  5. I once made a loader that allowed 256 byte DOS demos to run from a bootsector. The loader prepared the environment like DOS would while little to no modifications were required to the demos. The loader is 80 bytes and requires 16-byte alignment which means that the last 16 bytes of the bootsector are unusable (to keep the signature). Then you should also keep 80 odd bytes unchanged at the start to allow the floppy to work normally as DOS storage media. The first 3 bytes of any bootsector or MBR are for a jmp instruction to your code, so review that to go to the start of the demo loader rather than the original unaligned booting program.

    Reply

  6. If you want to be impressed by boot sector games, check out ones written for the Amiga. The game still has to be tiny, but you have access to the Amiga ROM code and custom chips, so they can do an incredible amount of work for you… if you know how to juggle. 🙂

    Reply

  7. Yikes and I complain about verilog being too low of a level of a language to handle 😂😂 these guys are writing games in ASCII code in the booting area.

    Reply

  8. Half expected the guy in the video to say at the end “which is why I attempted to do this and here’s the game I came up with”

    Reply

  9. @5:34 geez… that pac-man clone is better than the official Atari 2600 released version. I could never get my first IBM to work or load up anything. I kept seeing "Press and key" and this day I still haven't found the 'any' key.

    Reply

  10. Man, not only you automatically made me come back to my childhood but you actually taught that boy something!

    Reply

  11. The most creative way to save space is with noise compression and back-filling. Honestly, it has never been done. (Because I made it up.) It was derived from a current project I was working on, where you could use a singular set of seeds to ensure that players can't cheat, as much, and there seems to be zero lag with online games.

    In the concept of "space savings"… This is the concept.

    1: You program what you need to function, text, graphics, randomization code, etc… with all available space, minus any "levels", and leaving a few hundred bytes for the next steps.

    2: Now, the only thing you need are the "maps" and "sounds" and "effects". Those, you depend on the randomization codes for. There is already, what seems like, random data in all the memory for the game you programmed above, as well as all over the whole computer in the other chips. You harbor these details to create "map layouts", "sounds" and "effects", by using an external program which has the same random code, but allows you to alter the seeds.

    3: You add the seeds to the end, in the order needed, and play the game with those spaces filled, wherever a seed was required. Which could have been within the code, and seeds being 000000 initially, until you find the ones you needed.

    Additionally, seeds off seeds off seeds, is how you can actually "craft", semi-specific outputs to your desire. (Using AND, NOT, XOR, etc…) Until you get something that resembles some deeply involved game. Quite honestly, you can make it an infinite open-world game, as you can with any game that exists, using similar methods. Not only that, but you can "continue", to another game, with more graphics, by simply altering the graphics or code, by a similar method.

    It doesn't take a complex program to find manipulated random values that simply output exactly what you want. In the end, it consumes less space to record a few byte-seeds, which can be used to create massive worlds, as opposed to manually "painting" and "recording" each individual digital-space that they would physically occupy, in memory.

    You can also use this, as well as "bit-seeking", to create a chaotic form of data-compression. Do you know how many times "0010011101111011000100011101110" can be found within the chips of the system's data-bits? Doesn't matter… Surely some variation of a long chain will exist, which is ALSO needed in a chunk of your code. You simply point to that data-chunk, using a special character and you have just created more data in less space. Even if it only exists once, and saves you 8 bits, that is one whole byte you have left to add more code.

    P.S. Those same bits can exist in reverse or inverted or inverted and reversed too. That quadruples your chances of finding a match. Using a bit-shift loop, you have infinite potential to find a 100% match for any binary data, inside other existing binary data, free of charge with nearly zero space consumption. (Not to mention that you can "randomly", create strings of bits, with a tiny seed seed value. With the same inversion and flipping, etc… All it takes is time to find the data you want. Each game update could make the files smaller and smaller, as you find new locations and seeds that work better.)

    Our memory works the same way. We generalize what we see, we are not video-recording what we see. We generalize "person A" was at "my house", at "some daylight time", wearing "something blue on top and red below". We are not actually "recording", "Bob came to 123 Lane South, at 3:21 PM, wearing a navy-blue Gucci jacket and Lava red alligator pants." We simply make notations of any extra details, also as generalizations of generalizations. When we "remember", we are literally repainting what we "Believe", we saw, as far as our memory is concerned. (Actually Bob wore gray slacks that day, but we liked him better in those red alligator pants, so that is what we remembered. We also remembered him stopping by at 1:00 PM, just after lunch, but we were wrong, obviously.)

    Reply

  12. 2:54 I gotta admit… I haven’t.

    In fact, entering the boot menu on my shitty laptop is about as deep as I get when it comes to computers.

    I’m just here because I’m on an information bender and I’m watching random videos so I can tell people about the cool new thing I learned about movie tropes or outer space or something

    Reply

  13. Hey David – hope you see this. I think you might be interested in this little bit of my coding here: loads BMPs in 239 bytes, essentially without an operating system. The whole package will run from an IMG file on a CD(or an actual floppy). The whole package actually finds all Type-2 8 bit BMP on the C drive(as seen by the form of DOS you're using) that are 320×200 or smaller, writes the first 3.9MiB of them to the unused space on an SD card, writes boot code(while retaining the partition table) to the SD Card, so that on a legacy boot the BMPs will all load in turn. Since it doesn't actually use the logical drive it survives everything done to it(zeroization, format, whatever). Since all colour modes of Planet X3 will fit into 320×200 space, might be fun to create SD-cards that display screenshots from the game or something.
    https://github.com/Jethro82/SDCard-WhiteSpace-BMPLoader
    I'd appreciate knowing if you saw this message. Thanks.

    Reply

  14. I have also more admiration for the virus writers, because if you want to keep the disk bootable and readable from a partition perspective, you might have to keep your code under 380 bytes, and possibly load a second sector and offset a shadow copy of the original boot sector into the int vector handler so it appears all normal.

    Reply

  15. I made a game in python, it only took 64 bytes.
    Code:
    print("2+2=?")
    a = input("")
    if a == "4":
    print("You win! ")

    Reply

  16. This is way cool. It reminds me of when I read about people trying to make a Turing-complete programming language using as few functions as possible.

    Reply

  17. There is no need for the game code and data to be less than 510 bytes to fit on the boot sector, as long the computer has enough ram. They could be compressed on disk and then decompress in RAM before execution.

    Reply

  18. This is still one of my top favourite bit of coding. 256byte demo on the c64. I keep watching it over and over.
    https://youtu.be/sWblpsLZ-O8

    Reply

  19. Pretty amazing since I can write an assembly program on my Mac that all it does is count to 4 billion and it's 4k

    Reply

  20. I was a huge fan of one-liner games printed in SoftSide magazine. It was mainly the TRS-80 code I would use.

    Reply

  21. I thought it was nifty that Micro Mages was made within 40KB of ram. I'm assuming they worked within such a tight constraint because it made it cheaper to produce, not having to add extra hardware in the cartridge to make a bigger game.

    Reply

  22. No doubt that the pacman clone is indeed using screen ram for variables. Many Sega Genesis/Mega Drive games do this, but the dots are invisible since it's in the overscan area.

    Reply

  23. I'll be waiting for games like Skyrim or The Witcher 3 being remastered and ported… To UEFI!!!!
    No Windows required, hahahaha!

    (Works best for games that aren't updated anymore)

    Reply

  24. There's a missed opportunity in this video. You should have said that the boot sector version of basic is…quite basic.

    Reply

  25. At 0:24, you said Pac-Man was an early Atari 2600 game that had to fit into a 4-kb rom. That's incorrect. It was actually released in the middle of the 2600's lifespan, and by that point there were 8kb and 16 kb rom chips available. Atari just chose a 4kb rom to save money.

    Reply

  26. Generation 1: 8 GB games
    Generation 2: 16 GB games
    Generation 3: 32 GB games
    Generation 4: 84 GB games

    I think that some math went awfully wrong somewhere around there, i can't quite put my finger on it

    Reply

  27. I love old DOS games
    I have spent hours and hours playing Elite, and nearly all of the Apogee games.

    I still have them, and even learnt a machine code hack in Elite to give me millions of credits.
    I have also played Elite without cheating.

    Reply

  28. Извини друг за дизлайк.
    Но ничего не было понятным!

    Reply

  29. I am pretty sure that Gynvael Coldwind had a contest during a stream for a 512 bytes game for x86 no graphics mode

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *