{"id":1190,"date":"2015-11-01T13:02:14","date_gmt":"2015-11-01T13:02:14","guid":{"rendered":"http:\/\/www.sydneysmith.com\/wordpress\/?p=1190"},"modified":"2017-05-14T01:44:59","modified_gmt":"2017-05-14T01:44:59","slug":"hp67-flags","status":"publish","type":"post","link":"https:\/\/www.sydneysmith.com\/wordpress\/1190\/hp67-flags\/","title":{"rendered":"HP67 Flags"},"content":{"rendered":"<p>The HP67 calculator has 4 flags. These can be set, cleared or tested. You use them in a user program to remember situations and to behave differently according to the situations. One example might be: the user entered a value (or not) and your program behaves suitably either way. There were a whole stack of programs at the time where you could enter a value and press [A], [B], [C] etc to store the value; or just press the button to calculate it. These included tax calculators, principal and interest calculators and ohms law &#8211; key in any two and press the third button for it to work out the third value.<!--more--><\/p>\n<p>Flag 3 was ideally suited to this type of situation because it gets automatically set if you type in a number. All you need to do is test it.<\/p>\n<p>Flags 2 and 3 are &#8220;test-cleared&#8221;. This means that anytime you test them they automatically get cleared too. With Flags 0 and 1 you have to clear them whenever you need them cleared. There are merits to both approaches and HP included both so you could choose whichever suits best.<\/p>\n<p>The commands are:<br \/>\nh SF {0-3} = 35 51 01 &#8211; 35 51 03<br \/>\nh CF {0-3} = 35 61 01 &#8211; 35 61 03<br \/>\nh F? {0-3} = 35 71 01 &#8211; 35 71 03<\/p>\n<h2>Program Codes<\/h2>\n<p>Internally, user program steps are stored as 8-bit values. The values used are:<br \/>\nh CF 0 &#8211; h CF 3 = 0x6a &#8211; 0x6d,<br \/>\nh SF 0 &#8211; h SF 3 = 0x8a &#8211; 0x8d, and<br \/>\nh F? 0 &#8211; h F? 3 = 0x58 &#8211; 0x5b.<\/p>\n<p>If you have the <a href=\"http:\/\/www.sydneysmith.com\/wordpress\/hp67u\/\">hp67u emulator<\/a>, you can see these internal codes in program memory by looking at menu, advanced, View RAM. Program memory is banks 1 and 2. That is registers 16-47 inclusive. As you key in program steps values start appearing in those registers. Each program step occupies two nibbles in a register so if you key in &#8220;h SF 0&#8221; you&#8217;ll see &#8220;8a&#8221; appear somewhere in one of the registers.<\/p>\n<h2>Extra Program Codes<\/h2>\n<p>There are a number of unused internal codes as 8 bits allows for 256 program codes and only 250 are used. Two of these are relevant to the HP67 flags as internal code 0x6e and 0x8e show up in the W\/PRGM display as &#8220;35 61 04&#8221; and &#8220;35 51 04&#8221; (h CF 4 and h SF 4). There are only 4 flags in the HP67 (flags 0-3). Flag 4 doesn&#8217;t exist and it can&#8217;t actually be set or cleared. Conventional thought says the two instructions do nothing. This could be checked in the microcode simulator.<\/p>\n<p>When the HP67 was released, people discovered that they could enter extra program codes by writing data cards, rewriting the card as a program, and physically pulling the card back out (or switching the calculator off) whilst it was still writing. This gave the mag card a &#8220;this is a program&#8221; header but it contained data. The calculator would load the data as program steps. If you got the right data and stopped the W\/PRGM in the right place, you&#8217;d end up with the remaining 6 program codes loaded as a user program.<\/p>\n<p>With the <a href=\"http:\/\/www.sydneysmith.com\/wordpress\/hp67u\/\">HP67u emulator<\/a> life is a lot easier. You can use the &#8220;menu, Advanced, View RAM&#8221; button to change the contents of user program memory directly. Despite the button name, any edits you make get copied directly into the calculator&#8217;s internal RAM.<\/p>\n<p>If you place an &#8220;8e&#8221; or &#8220;6e&#8221; in one of the bank 2 registers (ram[32-47]) it will show up somewhere in program steps 001-112. As a hint, ram[47] is program steps 001-007, ram[46] is steps 008-014, and so on. Bank 1 (registers ram[16-31]) is program steps 113-224.<\/p>\n<p>However, with the HP67u, there is an even easier way. If you use &#8220;menu, Program&#8221; and key in program code &#8220;99 01 42&#8221; it will put a 0x8e in that step for you. If you go to the W\/PRGM display, it will show &#8220;35 51 04&#8221; or h SF 4. 0x8e is 142 decimal. The convention I used for the 6 extra program codes is &#8220;99 0n nn&#8221; so 0x6e is 96+14=110 so &#8220;99 01 10&#8221; will insert program code 0x6e. Only the 6 extra codes use this convention. You should use normal key codes (eg &#8220;31 25 11&#8221; for f LBL A) for normal user program steps.<\/p>\n<h2>HP67 Internals<\/h2>\n<p>The flags are actually stored in the bottom 4 nibbles of register 62 (bank 3 register 14). Again you can see this via the Advanced page of the microcode simulator.<\/p>\n<h2>Microcode<\/h2>\n<p>A summary of the microcode for h SF 2 is:<\/p>\n<pre>\r\n(wait loop 00167 - 00213)\r\n[h] pressed\r\n\r\n(wait loop 00167 - 00213)\r\n[SF] pressed\r\n\r\n(wait loop 00167 - 00213)\r\n[2] pressed\r\n(scan code = 0x61)\r\n00256 a -&gt; rom address\r\n01437 ...\r\n01440 if n\/c go to 01612\r\n01612 ...\r\n01623 if n\/c go to 01474\r\n01474 ...\r\n01503 if n\/c go to 01566\r\n01566 delayed rom 01\r\n01567 if n\/c go to 0437\r\n00437 ...\r\n00441 delayed rom 02\r\n00442 jsb 01205            ; clear s 4,6,7,8,10,13\r\n00443 ...\r\n00445 delayed rom 014\r\n00446 if n\/c go to 06021\r\n06021 ...\r\n06027 a -&gt; rom address \r\n06010 if n\/c go to 06266\r\n06266 jsb 06335\r\n06267 if 1 = s 12 \r\n06270 then go to 07422\r\n07422 ...\r\n07423 jsb 07430\r\n.07430 jsb 07706           ; select ram bank 3\r\n<strong>.07431 data register -&gt; c 14 ; c= ram[48+14=62] p=3-0 for F0-F3\r\n.C=00000012220101          ; 0101= f0 f1 f2 f3<\/strong>\r\n.07432 ...\r\n.A=00000000000e00 P=13\r\n.A=00000000000f00 P=0\r\n.A=00000000000000 <strong>P=1<\/strong>\r\n.07440 return\r\n07424 <strong>load constant 1<\/strong> \r\n<strong>C=00000012220111           ; 0111 ie f2 now set\r\n07425 c -&gt; data register 14\r\n*** ram[62]=00000012220111<\/strong>\r\n07426 delayed rom 00 \r\n07427 if n\/c go to 0074\r\n00074 ... ; clear up\r\n00077 if n\/c go to 0124\r\n00124 ...\r\n00157 delayed rom 02       ; update display\r\n00160 jsb 01162\r\n.A=000000000f1000 C=60000000000222 P=4\r\n.A=00000000ff1000 C=50000000000222 P=5\r\n.A=0000000fff1000 C=40000000000222 P=6\r\n.A=000000ffff1000 C=30000000000222 P=7\r\n.A=00000fffff1000 C=20000000000222 P=8\r\n.A=0000ffffff1000 C=10000000000222 P=9\r\n.A=000fffffff1000 C=00000000000222 P=10\r\n.A=0000fffffff100\r\n.01202 load constant 3\r\n.C=03000000000022\r\n.01203 b exchange c[w]\r\n.B=03000000000022 (display now \"0.00\")\r\n.01204 return\r\n00161 hi im woodstock\r\n00162 display off\r\n00163 display toggle\r\n00164 0 -&gt; s 15\r\n00165 if 1 = s 15\r\n00166 then go to 0164\r\n\r\n(wait loop 00167 - 00213)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The HP67 calculator has 4 flags. These can be set, cleared or tested. You use them in a user program to remember situations and to behave differently according to the situations. One example might be: the user entered a value (or not) and your program behaves suitably either way. There were a whole stack of &hellip; <a href=\"https:\/\/www.sydneysmith.com\/wordpress\/1190\/hp67-flags\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">HP67 Flags<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,5,3],"tags":[30,33,32],"_links":{"self":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1190"}],"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=1190"}],"version-history":[{"count":5,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1190\/revisions"}],"predecessor-version":[{"id":1192,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1190\/revisions\/1192"}],"wp:attachment":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}