{"id":1964,"date":"2018-02-25T20:50:29","date_gmt":"2018-02-25T20:50:29","guid":{"rendered":"http:\/\/www.sydneysmith.com\/wordpress\/?p=1964"},"modified":"2018-02-26T11:38:02","modified_gmt":"2018-02-26T11:38:02","slug":"hp-21-wait-loop","status":"publish","type":"post","link":"https:\/\/www.sydneysmith.com\/wordpress\/1964\/hp-21-wait-loop\/","title":{"rendered":"HP-21 Wait Loop"},"content":{"rendered":"<p>You&#8217;ll never see a shorter wait loop than this one. <!--more--><\/p>\n<p>It looks like this:<br \/>\n<code><\/p>\n<pre>\r\n\r\nC:\\Test\\hp21w>hp21w -d\r\n\r\nHP21w Ver 0.01\r\nCopyright 2018 Greg Sydney-Smith\r\n\r\nCPU speed is 200 kHz\r\n\r\n>>> g\r\n>>> dr\r\nA=0000FFFFFFFFFF D=00000000000000 M1=00000000000000 P= 0\r\nB=21000000000000 E=00000000000000 M2=00000000000000\r\nC=00000000000000 F=00000000000000 S =...3.5..........\r\n>>> dp\r\n00376: if 0 = s 15 then goto 00376\r\n>>>\r\n<\/pre>\n<p><\/code><br \/>\nThat&#8217;s a one line wait loop.<\/p>\n<p>There is some sense to it. After all, it doesn&#8217;t need to check if a mag card is inserted into a card reader (it doesn&#8217;t have one). It doesn&#8217;t need to check if you&#8217;ve switched to PRGM mode (it doesn&#8217;t have one). This is one of the few calculators where you can almost make it this simple.<\/p>\n<p>Why almost? Well, there is a small flaw in this loop. It&#8217;s easy to miss and, in the same circumstances and at the same time, I probably would have missed it too.<\/p>\n<p>You see, to my amazement, the HP-21 had a software-driven low power display. I really thought this came in much later in the series. The classic series, before this, all had hardware driving the low power display. I&#8217;m pretty sure (guess but consistent with the release times) that the HP-21 was the first to move to this.<\/p>\n<p>On the HP-21, all of the dots, except the real one, light up to show low power. I thought of an inverter or an XOR gate  somewhere in the logic driving the decimal point line of the display and a voltage sensor driving it. If volts is too low then the output swaps. Dots get displayed where they wouldn&#8217;t be, and  don&#8217;t where they would. It should be easy in hardware but they did it in software (saves some hardware and you already have a processor right there on the printed circuit board).<\/p>\n<p>It&#8217;s quite possible that the idea to do it in software came up after the rest of the software, or this loop, had been written.<\/p>\n<p>The obvious problem, now that I&#8217;ve mentioned it, is &#8220;what about low power?&#8221;<\/p>\n<p>The calculator can sit in this loop, waiting for a keypress, until the battery runs out. The calculator is on. The display is on. Power is being consumed; but it only checks the low power situation after it gets out of this loop. If you don&#8217;t press a key, you&#8217;ll never know that the battery is about to run out.<\/p>\n<p>An interesting aspect of the microcode. It&#8217;s not a significant glitch as it would be a rare problem in the real world, and you probably shouldn&#8217;t leave your calculator on if you&#8217;re not using it (pressing keys). However, it may explain a few occasions where you pressed a key on the real thing, the low power indicator came on, and it died immediately afterward.<\/p>\n<p>The emulator used above is my <a href=\"http:\/\/www.sydneysmith.com\/wordpress\/hp21w\/\">hp21w<\/a>. It&#8217;s a free download with a 10 year trial period (which restarts if you you move to another computer anytime in the 10 years, and that restarts &#8230;). Yes, the intent is for you to just use it.<\/p>\n<p>This article will be part of the HP-21 topic (when I get that page done).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ll never see a shorter wait loop than this one.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,5,7,68],"tags":[32],"_links":{"self":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1964"}],"collection":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1964"}],"version-history":[{"count":6,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1964\/revisions"}],"predecessor-version":[{"id":1970,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1964\/revisions\/1970"}],"wp:attachment":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}