8 ms·
Floppy Bird: A Flappy Bird clone in 16-bit x86 assembly
- salgernon 12y agoThanks for wasting 4 minutes of my life! For some reason, I picked up a Wyse Winterminal S50 from Weird Stuff last week... a thin linux client box from 2006 that has some sort of underpowered x86 and very little memory. So I was playing with it and it has this weird linux on it that lets you set it up to very slowly browse the web and such, but it wasn't very interesting, all told. When I saw this project come up, I grabbed the .img, wrote it to a spare usb stick and damn if the thing didn't just boot up to floppy bird. Nice work! Now I wonder what other dumb PCs I have sitting around that can boot it...
- danelectro 12y agoTurns out after you have written the floppy IMG to a blank uFD or HDD, and it boots and plays the game, then you can partition the drive (I used Linux Mint), format it as FAT32 or NTFS, and use the full drive for mass storage without a conflict. Same drive still boots to Floppy Bird only, unless you install some other OS or something which overwrites the Floppy Bird bootloader on sector 0, and give up the bird. Partitioning and formatting alone do not overwrite the MBR, even if it is just a custom floppy boot sector at the time.
- andrewstuart2 12y agoFloppy bird? Written in assembly, I half expected it to be called "Snappy Bird."
- Narishma 12y agoIt's called like that because it's a booter[1], so it's loaded from a floppy disk at boot time. 1. http://en.wikipedia.org/wiki/PC_booter http://en.wikipedia.org/wiki/PC_booter
- michaelq 12y agoThis is really cool. Is there a practical reason why you would write a game in assembly (speed? portability?)
- dllthomas 12y agoAssembly is about as nonportable as you can get. Hardware access (not exposed by other languages), speed, and possibly executable size are the practical reasons one would write in assembly. The second and third are almost entirely outdated - storage of executables is free relative to storage of data; hardware speeds have made "slow" programs plenty fast for most things; and compilers can do better than you can quickly do, very quickly. The first is still a valid reason to use assembly, but typically in the form of a small snippet of inline assembly in C/C++ code.
- michaelq 12y agoThanks for the in-depth answer. Was there a hardware access issue here, or did you just write this for the challenge/practice?
- dllthomas 12y agoI didn't write this at all, but I assume it was just for hack value, much like the myriad 2048 clones.
- aprdm 12y agoWell, in the embedded system field Assembly is still pretty much used everywhere, I think you are talking about doing asm for the regular PC. http://spectrum.ieee.org/static/interactive-the-top-programming-languages#index/0/0/0/1/1/50/1/50/1/50/1/30/1/30/1/30/1/20/1/20/1/5/1/5/1/20/1/100/ http://spectrum.ieee.org/static/interactive-the-top-programm...
- dllthomas 12y agoDoes anyone still use assembly for embedded? Of course. Is it a good idea? For some of them, and for the reasons I listed (I suppose I should add "you are working on a legacy assembly codebase"). "Still used pretty much everywhere" is just not the case anymore, even in embedded. At least, that's what the chart seems to say and it matches my experience working alongside embedded developers, knowing some embedded developers I've never had the pleasure of working alongside, and doing a small amount of embedded work myself. (Edited to remove: Right in that link, both C and C++ are used more than assembly in the embedded space, and Arduino (more C/C++) follows closely behind assembly. The chart is unclear, but the rankings seem to be based on numbers that don't change when different filters are applied, which would mean that it does not show this. It is still certainly consistent with "assembly no longer dominates embedded", though - some of the C and C++ will be embedded, and all of the Arduino will be embedded.)
- e12e 12y agoThis is just beautiful: https://github.com/icebreaker/floppybird/blob/master/src/main.asm https://github.com/icebreaker/floppybird/blob/master/src/mai... Nicely structured code! I'm almost tempted to port it to amd64, just for fun. After all we really don't need any more x86/16bit example code, we need more amd64 code! :-)
- agumonkey 12y agoAlmost Forth like. That should be read in schools.
- girvo 12y agoI've been saying this to my co-workers over the past week as I've gotten into modern day assembly (ARM, but still): It's basically a high level language at this point! It's amazing how much structure you can actually give yourself with modern tools.
- jarradhope 12y agoany recommended resources?
- e12e 12y agoI'm not sure you really need much in the form of modern tools to achieve this -- the code base above is basically include macros and jump labels? As mentioned by agumonkey, it feels a little bit like Forth. In fact, I seem to recall a rather excellent tutorial on 68000 assembly featured very similar structure (even if I never finished it -- at the time I was defeated by my own bugs and the fact that those bugs, without an MMU or memory protection, could easily crash the entire machine. It was rather demotivating...). For another example, see the original source of Apple II DOS, posted here a while back: http://www.computerhistory.org/atchm/apple-ii-dos-source-code/ http://www.computerhistory.org/atchm/apple-ii-dos-source-cod... Fundamentally I don't think the structure of the code is all that different? (Please correct me if I'm oversimplifying, or missing something).
- smegel 12y ago> It's amazing how much structure you can actually give yourself with modern tools. Like a compiler? >:)
- spiritplumber 12y agoSuper sweet! Does it have a switch that lets the computer cheat? http://www.catb.org/jargon/html/story-of-mel.html http://www.catb.org/jargon/html/story-of-mel.html
- zimbu668 12y agoMel wrote in machine code, not even assembly.
- ErikRogneby 12y agoI had not read that before.. a great read. thank you.
- ginko 12y agoDoes anyone know why GIMP is listed as a build dependency? I don't see it being called anywhere in the Makefile.
- sovok 12y agoIt's probably just used to create the .tga images loaded in https://github.com/icebreaker/floppybird/blob/master/src/game/data.asm https://github.com/icebreaker/floppybird/blob/master/src/gam...
- habosa 12y agoFirst of all, this is really cool and I think the closest thing I have seen to 'readable' assembly. Tiny nitpick: doesn't running asm still require an operating system? I haven't read all of the code but I assume that there are instructions for I/O or other traps that require the OS. Isn't the OS just the layer between the hardware resources and programs that want to access those resources?
- Scuds 12y ago> Tiny nitpick: doesn't running asm still require an operating system? The great 8-bit systems of the 80's - Apple II, C64 - booted their apps and games off of floppies all the time.
- dllthomas 12y agoIf you write ASM that makes system calls, yes. If you write ASM that just talks directly to your devices, no. For the latter, ASM isn't even strictly necessary outside possibly some narrow things that could (/should, if this was a "real" project) be inline assembly in a C program. Obviously, your C couldn't call any system calls and (depending on the runtime) might even need to forego malloc and similar.
- bane 12y agoNo. ASM is just a slightly easier mnemonic version of the raw machine language. All software basically compiles down to this form. The OS functions are provided here. The "game" is just an application in the OS (kinda). The BIOS provides whatever the OS needs to hook into to use the hardware. Here's a high-level overview of how this works http://duartes.org/gustavo/blog/post/how-computers-boot-up/ http://duartes.org/gustavo/blog/post/how-computers-boot-up/ OS's don't need to be very complicated, just a few bytes in some cases depending on what you want to do. For example, you can just use the standard VGA modes (here, he's using 13h) to get something to display, and just write directly to the video memory. The BIOS helps handle some of the interface work to the various standard components. This is the real old-school way of doing things and the code is really well done and commented. If you know x86 asm basics, you can read through most of the system-level stuff without too much trouble.
- anoxic 12y ago
- 3327 12y agogreat work always looking forward to seeing amazing examples like this on HN. Thanks you
- deleted 12y ago[deleted]
- nsxwolf 12y ago"Floppy Bird is a clone of the infamous Flappy Bird written in 16 bit (x86) assembly. In other words it works on RAW METAL and doesn't require an Operating System." The second statement doesn't quite follow the first. You can certainly write a 16 bit x86 assembly DOS application.
- dllthomas 12y agoAnd in principle you can write in a higher level language and build for a target without an OS. In practice, you can certainly write the bulk of your code in C and only write (possibly) a little initialization and (possibly) some IO code in assembly - mostly inline assembly.
- bri3d 12y agoIt's also not really running on "RAW METAL" because it's using BIOS interrupt routines for drawing and input. It's still awesome, though, and the code is really cleanly written and easy to follow. Because the code is so nice, this would be a fun project to try to port to Protected Mode with its own HAL and maybe drivers for one set of hardware (perhaps QEMU's). Could be a fun experiment in why OSes are hard and x86 is painful.
- drivers99 12y agovga.asm copies bytes directly to video memory in a raw manner, once it's in VGA mode. It only uses BIOS to switch into VGA mode ("mov ax, 0x13" and then "int 10h"), and back to text mode before rebooting when you quit. It does use BIOS to read the keyboard. It also reads bytes from sectors of the disk using BIOS rather than the OS when it starts up. The sound is a beep created with raw "OUT" commands on the data ports (for the PC speaker presumably). In other words, it's using BIOS for input, but not drawing.
- asveikau 12y agoticks() and sleep() also use BIOS. The author could have implemented this by handling IRQ 0. :-) Come to think of it handling the keyboard interrupts isn't that hard either... Also looks like boot.asm uses the BIOS to read the rest of the program...
- wwhhyy 12y agojust added this as a option to a fog server
- fogleman 12y agoMechanics seem... a little off.
- edpichler 12y agoFirst time I'm understanding Assembly easily, very good this source code.
- NickWarner775 12y agoThis simple game has gotten so much attention since it was released (and ten taken down).
- carlsborg 12y agoNice work, thanks for posting.
- carlsborg 12y agoFor systems running Debian you might need to install a mkisofs replacement. $apt-get install genisoimage $ln -s /usr/bin/genisoimage /usr/bin/mkisofs builds fine after this.
- nemasu 12y agoYes! Enjoying the assembly love recently. Awesome work!
- sfeng 12y agoI would love to see a chart of when each of these ports came out. It would be a pretty interesting representation of the difficulty of building the exact same thing in various languages.
- gangster_dave 12y agoI like his girlfriend implementation better: https://github.com/icebreaker/girlfriend https://github.com/icebreaker/girlfriend
- PhasmaFelis 12y agoIs "I made a Flappy Bird/2048 clone with a TWIST" the 2014 equivalent of "I installed Linux on my hat"? Although I admit this is more impressive than the usual "Floppy Bird only slightly different."
- golergka 12y agoAnd all of that, in 24 lines of javascript.
- michaelgrafl 12y agoI'm wondering: how hard would it be to add sound to this thing? I think it uses Piezo sound, which is probably easily addressed. But what about midi or PCM output? Would you have to target every manufacturer specifically? I really liked how fast my computer "booted" into the game. I would totally start collecting games like these if there were a scene.
- zokier 12y agoCorrect me if I'm wrong, but I think you could cover fairly wide range of hardware with two generic drivers, AC'97 and HDA. edit: for this project specifically there is the small problem that you probably need to enter protected mode for "modern" audio.