A bit disappointingly (not meant as a complaint against the authors, it's fun to see them squeeze it into the small space nevertheless) the mechanism used to make the "polyglot" part work is very simple:
The C64 doesn't care at all what it loads. It just treats the first two bytes as an address to load the data into (not used unless you explicitly request it with an extra flag when loading). So it loads the whole file, excluding the first two bytes but including the html/js, straight into memory.
The browser, on the other hand, accepts pretty much any junk prior to the body tag and ignores it.
So this is just one of those cases where two formats can pretty much just be concatenated.
It'd be fun to use the same mechanism to have the two programs e.g. share data tables.
Oh, it's cool. And clever. Part of my "disappointment" was that I hadn't thought through how simple it would be, and so was half expecting some crazy trickery.
The C64 doesn't care at all what it loads. It just treats the first two bytes as an address to load the data into (not used unless you explicitly request it with an extra flag when loading). So it loads the whole file, excluding the first two bytes but including the html/js, straight into memory.
The browser, on the other hand, accepts pretty much any junk prior to the body tag and ignores it.
So this is just one of those cases where two formats can pretty much just be concatenated.
It'd be fun to use the same mechanism to have the two programs e.g. share data tables.