Hacker News new | past | comments | ask | show | jobs | submit login
Classic Calculator Was Reverse Engineered from the Bare Metal (ieee.org)
168 points by samizdis on May 24, 2020 | hide | past | favorite | 68 comments



> The Sinclair Scientific was able to reduce complexity by using reverse Polish notation, in which mathematical operators come after the numbers they are operating on—for instance, “5 + 4 =” becomes “5 4 +.”

This is a great example of a place where you shouldn't use punc-quote formatting. There is no . key on the calculator, but that's not obvious while you're reading the article.


> This is a great example of a place where you shouldn't use punc-quote formatting

There's no place where it should be used. It can only introduce ambiguities, never solve any.

Quote-punc, on the other hand, doesn't introduce any. What always drove me nuts in academic writing was the knowledge that no matter how well I chose to format my article, the publisher would always introduce punc-quote and wreck things.

I'd have to defensively write around the potential placement of a punctuation mark which is just insane.


My former boss, a university professor, is a very good writer and leaning towards the anal side when it comes to things like punctuation, wording, spelling, etc. I remember we once worked on a journal article together that was edited somewhere in India. She sent in a pristine source file, and got back a print proof where literally tens of mistakes had been introduced. She corrected them meticulously, sent the corrected version back, and received another proof with another tens of errors introduced.

This went on for quite a while, you can only admire my boss's perseverance. However, what I don't understand is how these mistakes could have been introduced in the first place? It almost felt like someone on the other end was actually retyping all of her writing, or else how was it possible to get all of these mistakes in there?


Was there money involved? Perhaps it was a scam, or a failure to pay the right bribe.


Good call, but no, it was for an Elsevier journal.


Elsevier is a mixed bag. They bought up thousands of journals with not that much centralized oversight. They have a long history in publishing but as a subsidiary of an increasingly broad conglomerate (RELX) they sometimes show more interest in exploiting their reputation than maintaining it. That leads to things like this:

https://en.wikipedia.org/wiki/Elsevier#Fake_journals

Disclosure: I formerly worked for MDPI, a rival.


Thanks for this info. In my case, it was a renowned journal though.


So a scam then.


You know I set you up for that joke, right? :)


Yea Elsevier just finds whatever warm (free) body they can to edit.


Strongly agree. When the rules are bad, don't conform to them. I always use Quote-punc in my own writing if there is any possibility of ambiguity.


I found an old printer's manual a while back. The original typesetting guideline was to put the quote and the period in the same column, one above the other. This evolved to punc-quote on typewriters.

So I blame proportional fonts for their missing ligatures. :-)


Curious where you found this. I used to hand-set lead type and I don't remember any ligatures that combined quotation marks with periods.


Not at all surprising, since that's how you would do it in handwriting.


Oh this is delightful. Can you share the reference if you have it still?


It is mostly the MLA handbook, https://style.mla.org/punctuation-and-quotation-marks/ and https://style.mla.org/the-placement-of-a-comma-or-period-aft....

I guess I misremembered. The old reference from the 1800's is https://babel.hathitrust.org/cgi/pt?id=hvd.hx521x&view=1up&s..., he clearly puts the quotes on the outside too.


Maybe my monkey programmer brain is broken already from doing syntax parsing all day, but I can never imagine any context where this formatting makes sense. I always place quotation marks "like this". The other way is not even consistent with the conventional parentheses placement (like this).


I think it makes sense to include the punctuation inside the quotes if you are quoting the punctuation, and not if you are not.


That’s what I stick to. If a sentence begins and ends within a quote, the stop is also within the quote. If the sentence starts outside of quotes, I end it outside of quotes, regardless of whether it’s “correct”.


This is what I do. Technical writing should communicate your ideas to the reader as clearly as possible. Sometimes I think people who focus too much on 'correctness' in grammar and such forget writing and language is used to communicate, that's it's primary purpose. If rules leave ambiguity in the intent of the communication, maybe those rules just kind of suck.


But then technically you’d need to add additional punctuation to actually end the outer sentence, “like this!”. I have a firm preference of putting punctuation that does not belong to the quote itself outside of it, and when I want to add punctuation that does belong to the quote inside, I usually work around the problem above by just putting the quote after a colon: “like this!”


The english language is full of idiosyncrasies that don't quite make sense. Punc-quote is the correct "formal" way but informally you're free to do anything you want.


I think that's only necessarily true for the US.

Edit: I mean the punctuation inside of the quotes being traditional.


While I agree with you and refuse to do it the "traditional" way, there is some interesting reading about it here: https://style.mla.org/punctuation-and-quotation-marks/


This is why I try to mark things with something besides quotes: like bold, italics, or monospaced (unless it's a quotation in the old sense, something that someone said). In this calculator example, the two versions might have been better in <pre> tags, setting each on its own line, like this:

The Sinclair Scientific was able to reduce complexity by using reverse Polish notation, in which mathematical operators come after the numbers they are operating on — for instance:

  5 + 4
becomes:

  5 4 +
---

The U.S. chose its quotation-mark rules for graphical reasons, not logical ones. But the graphical improvement is slight, even debatable.

I wonder if my fellow Americans even notice the difference or remember which way is right. In fact, sometimes they look at it askew. One of my Facebook posts drew criticism from my friends, who said it was hard to parse. It was a post about different words, so several were in quotes, intermixed with commas, and I had diligently followed the American style.

I have hesitated to adopt quote-punc, just as I write color instead of colour. When a difference is slight, I think it's better to follow convention --- like contributing to source code and using the indentation style already there.

But after the Facebook incident and others, including this one, I'm beginning to think the difference isn't slight. Especially in the global melting pot of the Internet, it matters less to follow your own country's convention.


> ...you shouldn't use punc-quote formatting...

it seems like this is a really basic idea, but a web search is failing to explain to me what "punc-quote" formatting means. I get that it refers to how a command should be parsed, and how punctuation affects it, but can you give me a link to a formal explanation?


Hackers tend to use quotes as balanced delimiters like parentheses, much to the dismay of American editors. Thus, if “Jim is going” is a phrase, and so are “Bill runs” and “Spock groks”, then hackers generally prefer to write: “Jim is going”, “Bill runs”, and “Spock groks”. This is incorrect according to standard American usage (which would put the continuation commas and the final period inside the string quotes); however, it is counter-intuitive to hackers to mutilate literal strings with characters that don't belong in them. Given the sorts of examples that can come up in discussions of programming, American-style quoting can even be grossly misleading. When communicating command lines or small pieces of code, extra characters can be a real pain in the neck.

http://www.catb.org/~esr/jargon/html/writing-style.html


Nothing to do with parsing commands, just with writing sentences in articles (or elsewhere). It’s the difference between having punctuation that is not part of a quote in the quote, like when I said last Tuesday to “not do it like this,” or outside of them, “like this”.

The former is supposedly the “correct” way, at least in English, but you can see from my explanation that I’m absolute against it. I’m sorry, it’s just wrong on so many levels, and whoever invented it were not understanding what they were doing.


It's just how formal US English requires quite a bit of punctuation to be inside the quotes, even if the punctuation isn't being quoted.

https://blog.apastyle.org/apastyle/2011/08/punctuating-aroun...

This rule is obvs not super composable, and leads to a lot of confusion when punctuation (or lack thereof) is part of what you're trying to quote.


I would have padded the end of sentence with something else to avoid it or restructured the sentence entirely.


On the HP it's

    5 ENTER 4 +


On the Sinclair it is in fact

    5 + 4 +
because there is no ENTER key — the first ‘+’ is adding 5 to 0.


Odd. So you have to clear first, usually?


Apparently so. I don't have one, but see Ken Shirriff's emulator http://files.righto.com/calculator/sinclair_scientific_simul...


You are correct regarding the formatting, but there is "." key.


No, there is not. See the article, and https://en.wikipedia.org/wiki/File:Sinclair_Scientific.jpg


Ken Schirriff's blog has a much more detailed and interesting explanation including photos of the die that were used to reverse engineer it. http://files.righto.com/calculator/sinclair_scientific_simul...


> How can sine and cosine be computed efficiently in a calculator that has a hard time even doing multiplication? The trick is to do repeated rotations by 0.001 radians until the desired angle is reached.

Genius!


Thanks. My last name is "Shirriff", by the way (no "c").


Excellent. Thanks for that.


Somewhat off-topic, but why does the IEEE (a non-profit) have annoying ads on their site? I'm not using an ad-blocker and as soon as I clicked the link I was bombarded by one big half-page ad and a bunch of other ads that are irrelevant to the content of the article.

I would have thought that their very expensive membership fees and article/publication fees would have covered their operating expenses.


> I'm not using an ad-blocker

Why not? The advertising is never going to stop unless everyone blocks it. Content blockers should come pre-installed with all browsers. Ideally, they should be fully integrated features instead of mere extensions.

That's the only way for browsers to still retain their status as user agents. Browsers are supposed to act on our behalf by showing us the information we want to see. They aren't supposed to show us advertising noise for someone else's benefit.

> I would have thought that their very expensive membership fees and article/publication fees would have covered their operating expenses.

It's not about covering operating expenses. Memberships revenue + advertising revenue will always be greater than memberships revenue alone. It's an easy choice for them to make. Why would they actively choose to make less money than they could be making?

This advertising noise will never disappear on its own. We need to actively get rid of it. We need to make it so that advertising is a waste of money for companies. That's the only way to make them stop.


To rub salt into the wound, even dues-paying regular members aren't immune to such ridiculous ad bombardment.


> Somewhat off-topic, but why does the IEEE (a non-profit) have annoying ads on their site?

Because you forgot to install or enable an ad blocker. I know this is not a real answer to your question but it is the best answer to the annoying ads problem.


The patent https://patentimages.storage.googleapis.com/0d/b2/87/7f219f3... for the chip this calculator was based on (the TMS080x) is a real work of art. If you know how to make a transistor and a seven segment display, you can build yourself a fully working calculator with the information in the patent.

The architecture is truly odd, using 44 bit registers (11 x 4-bit BCD) and 11-bit opcodes. It is more like an electrical abacus than a microcontroller.


Most patents are worthless for learning anything, but Texas Instruments has some remarkably useful patents. That one, in particular, is a 61-page complete description of the calculator hardware with detailed schematics, as well as the software in flowchart and assembly form and the chip's instruction set. The patent has enough information to completely simulate the calculator (which I did: http://righto.com/ti). This patent was clearly written by the engineers and not the lawyers.

The funny thing is that what the patent actually claims is an obscure technique for connecting the ground lines in the calculator's ROM. In other words, almost all the detailed text in the patent is irrelevant to what is actually patented.


Thanks Ken, it's a great simulator. Is there any way others could write code for this simulator and play around with it as opposed to just running the original code?

And what are the best and worst features of this hardware architecture? Was there any little thing you think the designers should have done to improve it? Or was there something genius about it?


If you want to hack on the calculator, the code is on github: https://github.com/shirriff/TICalculatorJSSimulator

As far as the architecture of the calculator, it's kind of amazing that they were able to build a calculator chip at all, given the state of IC technology. The architecture is highly tuned to calculators, rather than being general-purpose. For instance, a "digit scan" register cycles through 10 scan lines to illuminate each digit. At the same time, it scans 10 rows of the keyboard.

Another interesting thing about the calculator chip is it has 11-bit opcodes. Powers of two are so ingrained in us that it seems bizarre to have 11-bit opcodes. But old computers often had random word lengths. The calculator's instruction set is very low-level, more like microcode than a "real" instruction set.


Why can't they mention "CORDIC" so that interested readers can find out the cool details about how to actually calculate "... trigonometric functions by repeatedly rotating an initial vector until the target angle was reached..." using only fixed-point add, subtract, and shift?


Nitpick: this calculator uses only one of the core ideas of CORDIC: that one can compute sines and cosines by repeated rotation. It doesn’t use the other core idea that you can approximate any angle by successively halving each step.

It doesn’t do the latter because of lack of memory to implement it in. http://files.righto.com/calculator/sinclair_scientific_simul...:

“How can sine and cosine be computed efficiently in a calculator that has a hard time even doing multiplication? The trick is to do repeated rotations by 0.001 radians until the desired angle is reached.

[…]

Other calculators use algorithms such as decimal CORDIC that are much faster and more accurate, taking time proportional to the number of digits.”


Here's someone who rebuilt the device with modern parts:

https://hackaday.io/project/91895-sinclair-scientific-calcul...


> ... the replica reproduced its behavior, by using an emulator running firmware that had been reverse engineered by visually examining the metal of an original processor.


> The Sinclair Scientific was able to reduce complexity by using reverse Polish notation, in which mathematical operators come after the numbers they are operating on—for instance, “5 + 4 =” becomes “5 4 +.”

It's not really RPN though. RPN lets you write "2 × (5+4)" as "2 5 4 + ×", but the Sinclair Scientific doesn't support that. It would have needed a stack for that, which wasn't available. Instead each operation simply acts on the previous result. You'd have to use "5 + 4 + 2 ×" instead.

Still very impressive how they managed to accomplish all that using that simple TI chip and only 320 instructions.


Technically, you still need delimiters in RPN, so "2 5 4 + ×" won't get you anything, because it's invalid. You need "2 ENTER 5 ENTER 4 + ×"

But that is both mentally more difficult to handle and physically more difficult to input than "5 ENTER 4 + 2 ×", so I wouldn't count this as a strike against the Sinclair even theoretically.


It’s not “5 4 + 2 x”?


That'd give you 54 x 2. You have to press + to delimit the initial value.


Actually 5.4 × 2; for 54 you have to enter 54E1 (5.4 × 10^1).


changing the order like that doesn't extend to "(5+4)*(3+2)"


That would be pretty cumbersome to calculate. I guess you'd have to remember the intermediate result. On paper, since the calculator didn't have any memory function.


OT but it's a real shame the bubble LED displays used in those calculators are not manufactured anymore. Something about the warm red glow and incandescent-like filament look appeals to me. They are also very compact, it's occasionally possible to find more recent bubble displays but quite bulkier, and outrageously expensive.


The UI design of calculators is fascinating. Where do you put the buttons? TI and friends have a randomish layout, let alone the TERRIBLE mobile calculator apps.

(Self-promotion) I always wanted to design a calculator and finally got around to it as a lockdown project - https://ucalc.app


That is one strange calculator. It's like having a car with 3 buttons; forward, backward and teleport.


Forward, backward and rotate left.


If childhood taight me anything, the minimum is just 2 buttons. Forward, reverse-left. Simple, usually effective, and maddenly oversimplified. I think I liked the one that only sent forward more, but it of course required a track.

People forget simple things like steering servos were not available to most kids until the 90s injection molding explosion that is so ubiq today.


Weren't there single-button ones that would continuously drive forward unless you pressed the remote control button, which would switch it to reverse-left?

So to "stop" you had to keep tapping the button.


Totally forgot about one of the cars I had that did that. Though, I always hated it thinking it was such a cheap toy.


There was also a model that had "forward" and "spin counterclockwise".


I was on a VPN and was getting http 418 from this server. Weird.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: