The HP-21 has a blue function key at the top right of the keyboard. I tend to think of it as the “g” key but that’s just my background with the HP-67 which has a blue “g” key. Whatever you call it, the question is, how does it work?
We know, from the HP-21 keypress routine, that pressing a key gets you to instruction 00403. We also know, from the HP-21 scan codes article, that the blue function key (“g”) has a scancode of 0xb0 (= 1011 0000 = 10 110 000 = 0260). This means the calculator will goto 00660 to do the “g” action. You can see that happening here:
>>> g,403 Breakpoint 1 at 00403 >>> ts200 00403: keys -> rom address ; 00660: select rom 0 ; 00261: clear s ; 00262: 1 -> s 13 ; S=...3.5.......D.F 00263: if n/c goto 0007 ; 00007: display off ;
All the key does is set the s 13 flag. By the time it gets to 00007, it is in the display routine that happens after the main activity completes. (s3, 5, and 15 (F) are connected to hardware so they don’t clear during the “clear s” instruction – they remain unchanged. The s3 switch is still in the RADians position. The s5 power sense is still okay and the key we pressed to get here, “g”, is still pressed. It’s hard to let go of a key in just a few milliseconds. That’ll go up again shortly and s 15 will go back to 0.)
You can see the s 13 flag is clear when the calculator powers up:
C:\Test\hp21w>hp21w -d HP21w Ver 0.01 Copyright 2018 Greg Sydney-Smith CPU speed is 200 kHz >>> g >>> dr A=0000FFFFFFFFFF D=00000000000000 M1=00000000000000 P= 0 B=21000000000000 E=00000000000000 M2=00000000000000 C=00000000000000 F=00000000000000 S =...3.5.......... >>>
This makes s 13 the “shift” flag or “g” flag. When it is set, the “g” key was pressed.
If you press “g” and then CLx (scancode 0xd0 = 1101 0000 = 11 010 000 = 0320) you’ll see the processor goto 00720 and check the s 13 flag.
>>> dr A=0000FFFFFFFFFF D=00000000000000 M1=00000000000000 P= 0 B=21000000000000 E=00000000000000 M2=00000000000000 C=00000000000000 F=00000000000000 S =...3.5.......D.. >>> g,403 Breakpoint 1 at 00403 >>> ts200 00403: keys -> rom address ; 00720: if n/c goto 0254 ; 00654: if 0 = s 13 then goto 00004 ; 00656: clearregs ; A=00000000000000 B=00000000000000 00657: if n/c goto 0233 ; 00633: 1 -> s 2 ; S=..23.5.......D.F 00634: delayed rom 0 ; 00635: if n/c goto 0006 ; 00006: clear s ; S=..23.5.........F 00007: display off ;
s 13 is already set (…D.. above).
We pressed CLx and it went to 00403 then 00720.
That checked s 13 and, if it wasn’t set, would have gone to step 00004. But it was set so we stayed and got to 00656. That cleared all of the registers (“clearregs”) as the blue “CLR” written on the CLx key suggests.
It also sets the auto_enter flag, s2, so whilst CLx doesn’t result in the current X value getting pushed up the stack (eg 2 ENTER 3 CLx 4 -> Y=2 X=4); CLR does. (g CLR 4 -> T=0 Z=0 Y=0 X=0, T=Z Z=Y Y=X X=4. The result looks exactly the same (0,0,0,4) regardless given that CLR set them all to zeros – 0,0,0,0,4 looks identical to 0,0,0,0,4)
By the time we get to 00007 we are in the display routine.
This is part of the HP-21 topic.