
A bootable CD image with a retro game in a single tweet - chetanhs
https://www.quaxio.com/bootable_cd_retro_game_tweet/
======
jobu
This reminds me a bit of the science of nanoinformatics as described in one of
the Expanse novellas (The Vital Abyss):

" _A thought experiment from my first course in the program: Take a bar of
metal and put a single notch in it. The two lengths thus defined have a
relationship that can be expressed as the ratio between them. In theory,
therefore, any rational number can be expressed with a single mark on a bar of
metal. Using a simple alphabetic code, a mark that calculated to a ratio
of.12152205 could be read as 12-15-22-05, or “l-o-v-e.” The complete plays of
Shakespeare could be written in a single mark, if it were possible to measure
accurately enough. Or the machine language expression of the most advanced
expert systems, though by then the notch might be small enough that Planck’s
constant got in the way. How massive amounts of information could be expressed
in and retrieved from infinitesimal objects was the driving concern of my
college years. "_

Pure fiction at this point, but it would be an interesting experiment to
encode data into objects that could be expressed using the mathematical ratio
of their shapes or sizes.

~~~
haser_au
The same has been said about Pi (3.14). If you can compute, store and search
enough the digits of Pi, you can reference anything by just providing the
'start' and 'finish' locations. Unfortunately, with enough digits of Pi, the
'start' and 'finish' numbers can get quite long themselves.

~~~
troupe
Years ago I tried this and basically ended up proving that if Pi is random and
you are "compressing" random data, on average the start and finish numbers
together are at least as long as the numbers you are trying to "compress."

~~~
ibotty
Did you proove it formally or only by experiment. If it were a real proof, did
you publish it somewhere?

~~~
OscarCunningham
In fact, any lossless compression algorithm has the property that the output
is (on average) at least as long as the input. The best you can hope for is an
algorithm that compresses the kind of data that humans want to store, at the
expense of making other data a bit longer. If you're trying to compress random
data then you just can't do it.

Here's a proof: consider the strings of length n or less, suppose there are M
of them in total. Their average length is just the sum of all their lengths
divided by M, and the average length of their compressed versions is just the
total length of the compressed versions divided by M. Since the compression is
lossless the compressed strings must all be different.

Since there are M strings, if any of them mapped to a string of length more
than n then there must be some string of length at most n not being mapped to,
so the average length can be improved by instead mapping that string to the
shorter string. So any optimal compression method must map only to the strings
of length at most n.

So the M outputs are just the M inputs, possibly permuted. So their total
length is the same, and hence their average length is the same.

~~~
aengvs
>In fact, any lossless compression algorithm has the property that the output
is (on average) at least as long as the input

I don't think this is true. If it was, lossless compression would be useless
in a lot of applications. It's pretty easy to come up with a counter example.

E.g.

(simple huffman code off the top of my head, not optimal)

symbol -> code

"00" -> "0"

"01" -> "10"

"10" -> "110"

"11" -> "111"

If "00" will appear 99.999% of the time, and the other 3 symbols only appear
0.001% of the time, the output will "on average" be slightly more than half
the length of the input.

~~~
OscarCunningham
Sure, I'm assuming that (a) you are trying to encode all strings of length at
most n and (b) you have the uniform distribution over those strings. This
makes sense in the original context of encoding random data.

~~~
aengvs
>you have the uniform distribution over those strings. This makes sense in the
original context of encoding random data.

Lossless compression is nothing more than taking advantage of prior knowledge
of the distribution of the data you are compressing.

Random data isn't always (or even often) uniformly distributed. Everything we
compress is "random" (in the context of information theory), so I disagree
that it makes sense to assume uniformly distributed data.

~~~
OscarCunningham
Then the original statement about not being able to use pi as a data
compression method is false. It could be the case that 99% of the time you
want to encode the string "141592653".

~~~
aengvs
The efficacy of a compression algorithm is dependent on the data it is
compressing, so that statement is true for some data.

------
barbegal
I was confused as to how you could represent a bootable CD image in printable
characters. It turns out that you can't. This is a tweet of a perl script
which creates a cd.iso file that you can then boot from. The perl script
significantly decompresses the data in the tweet.

That said, this is a playable game in around 60 bytes of actual data which is
impressive.

~~~
mirimir
I'm reminded of the RSA in Perl "weapon" t-shirt :)

[https://upload.wikimedia.org/wikipedia/commons/9/96/Munition...](https://upload.wikimedia.org/wikipedia/commons/9/96/Munitions_T-
shirt_%28front%29.jpg)

~~~
cheeze
Man that shirt is awesome... But man I would never wear that shirt as that
looks like the crown jewel of any neckbeards collection

~~~
OscarCunningham
It sounds like you've been trained to hate something that you actually love.
That's kind of sad. Couldn't you just wear the awesome shirt while avoiding
the negative aspects of neckbeards?

------
myth_drannon
If you want to see demos (as in demoscene) in a tweet of 140 characters -
[https://www.dwitter.net/](https://www.dwitter.net/)

~~~
acutesoftware
nice to see demos in action without running random code - thanks. Demos are
without a doubt the best way to show the maths can look cool.

------
a1k0n
Hats off for making use of the AAA instruction. That's a very clever sequence
converting up/down/left/right to -320/+320/-1/+1.

~~~
amenghra
For those who don’t know, x86 had support for binary coded decimal (you end up
wasting a bunch of bits).

AAA converts the result of the addition of two valid unpacked BCD digits to a
valid 2-digit BCD number.

------
KyeRussell
As someone that develops almost exclusively in high-level languages on top of
may levels of abstraction, it's nice to see what can be accomplished close to
the metal.

This reminds me of Steve Gibson's SpinRite, which (from what I recall) is a
fully functional disk recovery utility written entirely in assembly.
[https://www.grc.com/spinrite.htm](https://www.grc.com/spinrite.htm). Say what
you want about the man, but this is something that's saved me on at least one
occasion, and is smaller than things I produce that do a lot lot less.

~~~
jjeaff
There are people that will argue until they are blue in the face that his
recovery software is useless.

But I have also had some success with it.

Everything that he releases is amazingly tiny. It just shows how much bloat
modern software tends to have.

~~~
exikyut
What I've read is that SpinRite simply just reads and writes to the disk,
triggering the disk firmware to reallocate bad sectors. I think it just tries
to read many times, which can sometimes help.

The other argument is that the various things SR tries to "manage" (sector
interleave, getting various timing parameters "perfect", etc) were only
relevant with ST-506 (!!) and similar disks from the 80s/very early 90s, and
that anything remotely modern (even IDE, virtually 100% of SATA) generally
doesn't provide enough low-level control surface that trying to micro-manage
the disk's behavior will do anything particularly special.

Of course, I'm sure each manufacturer has their own tools and widgets that can
use undocumented proprietary SATA/SCSI commands to control the drive's
behavior at a very low level, but those kinds of tools are a) rare as hens'
teeth and b) probably very easy to break disks with due to poor UI design and
lack of documentation. Chances are the most expensive data recovery centers
probably have some of these tools, and more importantly the training to know
how not to kill HDDs with them :P

TL;DR: Yes, SR works, but probably just as well as dd3rescue; as always, if
you think a disk is this side of dead and you think you have a chance without
specialized tools, _just imaging it_ is probably the best first step, because
SR and all other tools will of course stress it.

With all of this said, I really, really like SR's startup animation :3 and I
agree that it's refreshingly small.

------
yebyen
Your snake game doesn't even have food for the snake to eat? The snake just
grows without eating, until the head collides with the tail somewhere? Pssh,
amateur hour...

/s (Just kidding this is actually super cool.)

~~~
amenghra
It's Tron-ish (the post says Tron, where did you read snake?) :P

~~~
reificator
It's a fair assumption to make, as the difference between Tron and Snake is
effectively just single player vs multiplayer.

~~~
derrasterpunkt
No it isn't. In TRON you leave a trail behind. In Snake, you grow as you eat
and drag your body along the path you crawled. TRON's trail is static, Snakes
body is dynamic.

~~~
reificator
I said effectively.

> _TRON 's trail is static, Snakes body is dynamic._

And that difference only exists to support the single player vs multiplayer
dynamic. If Snake left a Tron tail then it would be a very short, unfun
experience. If Tron didn't leave a permanent trail then matches would last too
long.

~~~
hacksoi
> And that difference only exists to support the single player vs multiplayer
> dynamic

Maybe the single player vs multiplayer difference only exists to support the
different tail mechanics.

~~~
crtasm
In the middle ground, NIBBLES.BAS was snake and had a competitive 2 player
mode plus a selection of levels/arenas.

------
ryandrake
This is great, and ironically it’s sitting next to another HN article where,
in the comments, someone is actually defending a NYT news article that weighs
in at 6MB.

In a time when most software is filled with superfluous waste and endless
layers of abstraction and libraries, it’s nice to see that the art of writing
minimal software is not completely lost.

~~~
icebraining
Further irony: this page weighs over _30MBs_ , thanks to a huge GIF that is
arguably not necessary for the article.

~~~
mynewtb
Yeah, not happy about that idiocy (probably 1MB as video) burning through 10%
of my monthly bandwidth on the first day of the month...

~~~
CydeWeys
Wow, how low is your monthly download cap?? What ISP and where?

~~~
flukus
Probably mobile, here are the plans mine offers (I'm on the 2GB one):
[https://www.whistleout.com.au/MobilePhones/Carriers/iiNet](https://www.whistleout.com.au/MobilePhones/Carriers/iiNet)

So page bloat is a real issue, not just "old man rants about good old days". A
shame really because the rest of the page is pretty light wieght, 5.2kb for
the content and 2.2 for the css.

Even worse is that the static preview of the monster gif is the second largest
element.

------
varjag
The actual tweet:
[https://twitter.com/alokmenghrajani/status/10075143375929876...](https://twitter.com/alokmenghrajani/status/1007514337592987648)

------
amenghra
Make sure you check out the floppy version from ~3 years ago. Fits in “old”
tweets (ie 140 chars):
[https://www.quaxio.com/bootloader_retro_game_tweet/](https://www.quaxio.com/bootloader_retro_game_tweet/)

~~~
CGamesPlay
You should investigate adding an RSS feed!

------
antoineMoPa
That's the kind of thing I come here for! Tiny hacks of all sorts.

~~~
vinhboy
Same. I come here to witness what is basically programming magic to me. I'll
need a couple of life times before I can become this skilled.

~~~
amenghra
You can do “magic” with relatively easy things. For example, spend a weekend
with [https://forthsalon.appspot.com](https://forthsalon.appspot.com) or
processing.org and see where you can get to...

~~~
exikyut
Awww. That first link silently requires WebGL in order for the animations to
work, and doesn't implement a fallback. :'(

------
komali2
This is the second time this week I've seen someone note that ISO standards
are expensive - are they copyrighted or something? Why doesn't someone just
publish them online for free?

~~~
tomcam
Yes, they are copyrighted. The link to article points to this equivalent, free
ECMA 119 standard:
[https://www.quaxio.com/files/2018/bootable_cd_retro_game_twe...](https://www.quaxio.com/files/2018/bootable_cd_retro_game_tweet/ecma-119.pdf)

------
Klathmon
Man I love these things. Back before Twitter upped their character limits, I
remember a trick to cram more data in a tweet was to abuse how Twitter counts
characters (it attempts to count visually rather than by byte), so by using a
ton of multipart emojis or larger Unicode characters to over double the
information that could fit in a tweet.

~~~
amenghra
I thought about using Unicode, but it felt like cheating.

Perhaps someone can fit two games in a single multibyte tweet?

~~~
lucb1e
Multibyte chars is optimizing for Twitter, not for a set amount of bytes. If
you try to fit in 140 bytes and you use >140 bytes because they are multibyte
chars, then yeah, you're cheating. But if you're trying to "fit in a tweet",
I'd say that's perfectly fair game.

Anyhow, two games... cool, but to be perfectly honest, I thought the game was
going to be more like the real snake than just drawing a non-overlapping line
on screen. A more impressive game might be more impressive than two games.

Then again, two games is also pretty darn cool.

------
andyidsinga
i love love love this.

This is a fantastic way to get into low level programming with a fun,tangible
and approachable result.

back in "the day (TM)", we used to do this with ..achem ..viruses on floppies
:) Putting it in a tweet is just brilliant.

anyone remember the one where it would say "smoke more weed dude"? (or
something of the sort) :)

------
xellisx
Not as cool as this, but here are some PHP "frameworks" in a tweet (140
characters):

[http://www.twitto.org/](http://www.twitto.org/)

[https://gist.github.com/mathiasverraes/9046427](https://gist.github.com/mathiasverraes/9046427)

[https://philsturgeon.uk/php/2009/12/15/Twiny-Framework-
the-f...](https://philsturgeon.uk/php/2009/12/15/Twiny-Framework-the-
framework-small-enough-to-tweet/)

[https://gist.github.com/jeremeamia/2720020](https://gist.github.com/jeremeamia/2720020)

------
sjtrny
The explanation is quite good but is there even more detail on what the
assembly instructions are doing on a line by line basis? I’ve only written
MIPS assembly and that was a long time ago.

------
rootbear
Very cool. My version of base64 wants -d, not -D, though.

~~~
amenghra
Linux vs BSD (ie Mac OS X). Sorry about that. Also, you shouldn’t paste weird
looking things from the internet in your console :P

~~~
mygo
yeah paste it into your plain text editor first and then do a code review and
then save it to a jump drive and spin up the old backup computer that’s been
wiped clean and then open up a sandboxed vm and then remove the wifi chip and
then run it

~~~
exikyut
If it was March last year, you wouldn't have wanted to run anything marked
"only works in Edge", particularly if you were using Win10 on VMWare -
[https://arstechnica.com/information-
technology/2017/03/hack-...](https://arstechnica.com/information-
technology/2017/03/hack-that-escapes-vm-by-exploiting-edge-browser-
fetches-105000-at-pwn2own/)

------
starpilot
Wow, that's pretty leet.

------
narrator
I remember x86 real mode back in the day. Pretty hideous and hacky compared to
what we have now.

~~~
saagarjha
> what we have now

x86 processors still boot into real mode…

~~~
yjftsjthsd-h
It's my understanding that UEFI actually comes up directly into long mode?

"UEFI firmware performs those same steps, but also prepares a protected mode
environment with flat segmentation and for x86-64 CPUs, a long mode
environment with identity-mapped paging. The A20 gate is enabled as well."

\- [https://wiki.osdev.org/UEFI](https://wiki.osdev.org/UEFI)

~~~
dlubarov
Unfortunately most BIOS services are only available in real mode, so it's
often necessary to switch back and forth.

------
tomxor
Looks like the turbo button needs to be in the on position for this one: 0.05
FPS in a qemu KVM on my old P8600... I presume the game loop uses the hardware
clock :P

btw my base64 util needed lower case -d

~~~
amenghra
There’s a comment on the page.

For some reason, emulators (at least the ones I tried) wait 4x what real
machines wait when you use BIOS int 15b 86h. You can tweak the code if you
want to play at a faster speed.

There’s probably a sound explanation for this discrepancy...

~~~
BGZq7
I can't say I entirely understand how the Elapsed Time Wait works, but testing
in qemu, I was able to get it to a good speed by replacing the

    
    
      inc cl
    

with a

    
    
      nop
      inc dx
    

By opening in a hex editor, finding

    
    
      bf86 fec1
    

and replacing with

    
    
      bf86 9042
    

If you're on a very slow system, maybe just use 2 nops or a 2-byte nop.

~~~
exikyut
I couldn't find "bf86 fec1". I did however find "b486 fec1".

"bf86 9042" made it literally so fast I physically couldn't keep up. The
following worked for me (w/ QEMU on old (no KVM) Pentium M), this may be too
fast on newer machines:

    
    
      xxd cd.iso | sed 's/89c3 01de b486 fec1 cd15 b445/89c3 01de b486 9042 cd15 b445/' | xxd -r > cd2.iso
    

(Note the creation of "> cd2.iso")

------
utopcell
So beautifully retro. Like twitter :-)

------
classichasclass
There's almost as much header information as there is code!

------
wintorez
What is this sorcery!?

------
wojtczyk
Love it!

------
fmfamaral
Well done, sir.

