Hacker News new | ask | show | jobs
by vidarh 1024 days ago
It wasn't all originally in C. AmigaDos infamously was originally BCPL, hence the nasty legacy of BPTR and BSTR types all of the places.

EDIT: To those unfamiliar, which I'm guessing is most people here, BPTR's are regular pointers shifted two bits down... BSTR's are BPTR's to a BCPL string, more commonly known as a "Pascal string" (single byte length as the first byte).

The reasoning for this is language simplicity (too much... I hate it, to be clear):

What in C would be array[index] is famously pretty much syntactic sugar for *(array + index). In BCPL it's !(array+index) or array!index. But whereas C is typed enough that C knows that (array + index) requires scaling index to the size of the elements of the array, BCPL is type-less. So if "index" is 1, array + index will add 1 to the address even if "array" holds 32 bit values.

Since every value is typically the size of a pointer (otherwise the typeless goes straight out the window), on M68k the elements are 4 bytes.

So to make (array + index) work, pointers needs to be left-shifted two bits. Then you can right-shift them two bits for any operations explicitly treating them as pointers (like "!")...

And then everyone having to ever interface with your code from any other language will hate you for all time.

1 comments

Just to add some more flavour:

AmigaDOS in AmigaOS 1.x was a port/adaption of TRIPOS [0] to 68000 by MetaComCo. This was because the intended disk OS/API, "CAOS", was nowhere near ready for the Amiga's 1985 launch. [1]

It's the conventions of TRIPOS that commands go in "c" / "C:", libraries go in "l" / "L:" and scripts go in "s" / "S:", which is why these directories and standard assigns are on Amiga disks... but AmigaDOS "libraries" are limited to filesystem handlers, real Amiga libraries are found in the "libs" / "LIBS:" directory.

Even the standard filesystem was from TRIPOS. It had 488 bytes of data and 24 bytes of metadata per 512-byte disk block!

There was a lot of wailing and gnashing of teeth trying to use AmigaDOS 1.x. Charlie Heath and others started the AmigaDOS Replacement Project (ARP, retroactively renamed "AmigaDOS Resource Project" to not sound so nasty) which rewrote all the standard C: commands in assembler and C, using a common arp.library, which also added one of the earliest "standard" filesystem requesters. [2]

Commodore took this onboard.

Commodore created FastFileSystem (FFS) to replace the retroactively-named "Old Filesystem" (OFS) in time for AmigaOS 1.3. FFS removed _all_ per-diskblock metadata and let you lay down contiguous runs of 512-byte blocks!

Commodore rewrote AmigaDOS and its commands in C and assembler for AmigaOS 2.0, retaining BCPL only where absolutely needed to keep filesystem handlers working. They also added a new asl.library with a standardized filesystem requester.

In short, ARP was completely successful in getting Commodore to ditch BCPL AmigaDOS for one written in C.

[0] https://en.wikipedia.org/wiki/TRIPOS

[1] https://web.archive.org/web/20190420095854/http://www.thule....

[2] http://aminet.net/package/misc/antiq/ARP_13

arp.library, asl.library and similar is another one of those things I miss. Having such rapid adoption of standard requesters everywhere was great.