- hp16c.doc - Release 1.1 May 25, 1996 ========== 1. Welcome ========== Welcome the "HP-16C Computer Scientist Simulator" for HP-48S/SX/G/GX, or HP16C for now on. HP16C performs many functions of the "hackers calculator", the HP-16C. 1.1 No Warranty =============== This software is provided "as is", NO warranty, either expressed or implied are given. Should HP16C prove defective, the user shall bear the entire cost of all necessary correction and all incidential or consequential damages. 1.2 Warning! ============ 1. HP16C does not work in covered ram on the HP-48G/GX. 2. Testing has been done on a HP-48GX rev R. I do not own any S/SX, but I borrowed one to test the most fundamental stuff. You are recommended to backup valuable data before trying HP16C. 1.3 Copyright ============= HP16C is copyrighted by Håkan Thörngren. email: hth@update.uu.se 1.4 Distribution ================ You are allowed to make as many copies of this software as you like, provided that you do not charge anything for it. Share and enjoy!!! 1.5 Installation ================ HP16C is a library (1558) with one entry point called SIM which starts the simulator. Just download HP16C to your calculator, store it to a port and perform a warm start. Refer to your calculator manaul if you need more help. =============== 2. Key features =============== + Variable word size, up to 64 bits. + Signed (two complement) and unsigned modes. + Arithmetic, logical operations and bit manipulations. + Works in four number bases (binary, octal, decimal and hexadecimal). + Old HP style 4-level stack with LastX register. Displays all four stack registers simultaneously. + 22 digit display permits all possible numbers in octal, decimal and hexadecimal to be on display without any scrolling. + Binary display uses octet grouping to simplify reading. + Large binary numbers can be viewed using a window feature. + Storage registers similar to HP-16C. Fast register number entry using technique similar to HP-41C. + Double operations, multiply, divide and remainder. + Remembers the machine state when you leave HP16C and restores it when you re-enter. + Useful on all HP48 machines, even the S/G models as the library does not gobble up all memory for you. 2.1 What is Missing =================== As I said above, HP16C performs many functions of the HP-16C, but not all. The following list describes what is missing: - One complement mode does not exist. Personally, I have never needed it. I can probably add it if there is any real use for it. - HP16C is currently not programmable. - Some double instructions works a little bit different (better in my opinion) compared to the original HP-16C, see below. - There are no floating point numbers in HP16C, but your HP-48 does that job very well. - There is no online help for shift/rotate operations. 2.2 What is Different ===================== - Double divide and remainder produce double results while the original HP-16C produces single result or an error message if the result is too large. ============= 3. The Manual ============= This section contains the basic information about HP16C. If you have experience with an HP-16C or the manual, it will help. HP16C is a library that contains one function "SIM" that starts the HP-16C simulator. A typical display can look as follows: (un)sign Word size mode Flags c v | ------/ Window (binary mode only) | | / | Number base - Hex c ws 32u 1/2 ----------------------------------- / T: 456AD \ / Z: 1 > Stack contents 4 line stack < Y: 0 / \ X: 50 / LOG SHIFT BASE SETUP MASK MEM - Current menu The number base (Hex, Dec, Oct or Bin) is always present in the top left corner. If any flag or carry of overflow is set, a `c' or `v' is shown. The word size together with current sign mode follows. Finally, in binary mode with a word size larger than 16, the current window is indicated as `window'/`max-window'. All stack registers are displayed except the LastX register. Recall that this is a 4-level RPN stack, which behaves slightly different compared to the RPL stack. Basically, it can be described as: - Always fixed to 4 levels. - A number entered goes into the X register. - ENTER terminates digit entry, duplicates X to Y (lifting the stack) and disables stack lifting. If another number is entered (or recalled), it is put into X without any stack lifting. T: 1 T: 2 T: 2 Z: 2 ENTER --> Z: 3 New number Z: 3 Y: 3 Y: 4 Y: 4 X: 4_ X: 4 (disabled) X: 5_ - A binary operation, such as + adds Y to X and drops stack. The previous value is stored into the LastX register. T: 2 T: 2 Z: 3 + --> T: 2 Y: 4 Y: 3 X: 5 X: 9 Notice that during stack drop, the T register keeps its old value. - Backspace rubs out the last entered digit. If there are no digit that can be erased, it will perform a CLX (clear X) operation. CLX stores zero into X and disables stack lifting. This means that if you enter another number, it will overwrite the zero in X. - All operations except the following enables stack lifting: ENTER CLX 3.1 Keyboard ============ Number entry is made using keys 0-9. The row that starts with SIN and ends with 1/X is used to enter hexadecimal digit A-F. A number being entered appears in stack register X. ENTER Terminate number entry, copy register X to Y and lift stack. Also disables stack lifting so that next number entered will not cause the stack to scroll up. <- Backspace during number entry. Performs CLX otherwise. CLX clears register X and disables stack lift. This means that the next number entered will not lift the stack (copying old X to Y). +/- If decimal digit entry, adds a negative sign to the number. Otherwise, terminate digit entry and negate number in X. / Divide Y/X. * Multiply Y*X. - Subtract Y-X. + Add Y+X ON Terminate HP16C and return the calculator to normal operation. EEX X<>Y, swap X and Y registers. Arrow up Roll the stack up. Arrow down Roll the stack down. Arrow left In binary mode this scrolls the display window left. Arrow right In binary mode this scrolls the display window right. STO Store X register in nibble memory. NEXT Move to next menu row if there is any. MTH Set binary mode. PRG Set octal mode. CST Set decimal mode. VAR Set hexadecimal mode. 3.1.1 Right shifted keys ------------------------ * Perform "Y AND X". + Perform "Y OR X". - Perform "Y XOR X". 1/X Perform "NOT X". . Recall last X register. RCL Recall a number from nibble memory. / Remainder. +/- Toggle sign/unsign mode. <- CLX, see above. ENTER Prompt for word size. ON Turns the calculator off, but does not leave HP16C mode. 3.2 Operations ============== Double operations works on word pairs. The zero fill mode can be useful when you view double numbers. DBL* Double multiply, perform X*Y and produce a double result in X:Y. DBL/ Double divide, perform "Y:Z / X" and store result in X:Y. NOTE: This is different from HP-16C which produces a result in X, or an error message if the quotient is too large. DBLR Double remainder, stack works in the same way as DBL/, but the remainder is returned as result. HP16C returns a double result while the original HP-16C produces a single result or an error message. 3.3 Soft menus ============== Soft keys that takes you to a menu has a short line of pixels turned on above the softkey. You do not go "up" from a menu, you always go to a menu. 3.3.1 Main menu --------------- This is the menu that is displayed when you first enter HP16C. It you are in another menu, you can get to this menu by pressing the soft key "HP16C" which is displayed as the last menu choice in every menu. LOG Logical operations menu. SHIFT Shift and rotate operations menu. BASE Base select menu. SETUP On the G/GX, an input form is displayed that lets you choose number base, word size, sign mode and more. On the S/SX, this takes you to the setup menu. MASK Mask operations menu. MEM Memory and stack operations menu. ARIT Arithmetic operations menu. ABOUT Display the about box. This includes the version number and my email address. Press any (full formed) key to get out of it. 3.3.2 Logical operations menu ----------------------------- AND Perform "Y AND X". OR Perform "Y OR X". XOR Perform "Y XOR X". NOT Perform "NOT X". HP16C Go to main menu. 3.3.3 Shift and rotate menu --------------------------- All shift and rotate operations shift/rotate one single step. By pressing the left arrow key, you will get a prompt asking you how many steps to shift/rotate the number. SL Shift left. Zero bits are shifted into the lowest bit and the bit shifted out goes to carry. +---------------------------------+ CY <--- | <---- | <-- 0 +---------------------------------+ RL Rotate left. Bits shifted out goes both into the carry and back to the first bit. +---------------------------------+ CY <-+- | <---- | <--+ | +---------------------------------+ | +-------------------------------------------+ SR Shift right. Bits shifted out goes into the carry. +---------------------------------+ 0 ---> | ----> | --> CY +---------------------------------+ RR Rotate right. Bits are rotated around and the last bit rotated around from lowest position to highest is also rotated into the carry. +---------------------------------+ +-> | ----> | -+-> CY | +---------------------------------+ | +-<-------------------------------------<-+ ASR Arithmetic shift right. This works as a SR except that the sign bit (highest bit) is copied so that it remains in its its initial location. +---------------------------------+ +->| ----> | --> CY | +---------------------------------+ | | --<-+ RLC Rotate left through carry. The carry works as an extension bit to the number. The intial carry is shifted into the lowest bit position. +---------------------------------+ CY <--- | <---- | <--+ | +---------------------------------+ | |--->--------------------------------------------+ RRC Rotate right through carry. The carry works as an extension bit to the number. The intial carry is shifted into the highest bit position. +---------------------------------+ +--> | ----> | ---> CY | +---------------------------------+ | +-------------------------------------------<---+ LJ Left justify the number in X. The number in X is shifted left until the leftmost 1 appears in the highest bit position. X is copied to Y and the number of shifts needed are stored in X. 3.3.4 Base select menu ---------------------- BIN Select binary number mode. OCT Select octal number mode. DEC Select decimal number mode. HEX Select hexadecimal number mode. 3.3.5 Setup menu (S/SX) ----------------------- The G/GX version uses an input form. BASE Base select menu. WSIZE Prompt for word size. SIZE Prompt for storage size. SIGN Sign/Unsign mode. ZERO Zero fill mode. CY Carry flag. OV Overflow flag. 3.3.6 Mask operations menu -------------------------- MSKL Create a left aligned mask of 1 bits. The number in X describes how many 1's will be set. MSKR Create a right aligned mask of 1 bits. The number in X describes how many 1's will be set. RB Clear bit number X in Y and drop stack. SB Set bit number X in Y and drop stack. #B Count number of bits set in X and replace X with that number. 3.3.7 Memory and stack menu --------------------------- All operations in this menu can also be performed using the normal keyboard. X<>Y Swap X and Y. RDN Rotate the stack down. R^ Rotate the stack up. LASTX Recall the LastX register to X. CLX Clear X and disable stack lift. STO Prompt for a register and store X in that register. RCL Prompt for a register and recall its contents to X. 3.3.8 Arithmetic menu --------------------- Double operations works on number pairs. This gives the ability to perform operations that result in up to 128 bit results. It can also be used to handle mixed operations, such as 16/8 divide. X:Y below means that the high part is stored in X and the low part in Y. DBL* Perform double multiply. Y is multiplied with X and the result is stored in X:Y. DBL/ Perform double divide. Y:Z is divded by X and the result is stored in X:Y. DBLR Perform double remainder. Y:Z is divided by X and the rest is stored in X:Y. MIRR Mirror bits in X. ABS Take the absolute value of X. NEG Negate X. 3.4 Storage facility ==================== You can allocate storage memory in HP16C. The actual memory is obtained by increasing the size of the library data object (the state). The size of memory is counted in nibbles. The allocated memory is mapped to actual register numbers. A nibble is never split betwen two registers. This means that a single bit takes as much memory space as a 4 bit word. An example will (hopefully) make it clear. You have allocated size 20, that is 20/2 = 10 bytes of memory. If you set the word size to 10, register 0 will correspond nibble 0, 1 and 2. You have 20/3 = 6 registers numbered 0-5. If you change word size, nothing happens to the memory itself. The mapping mechanism, however, changes and you can access multiple or parts of register compared to the previous mapping. In our example, this means that a 16 bit number would take register 0 and the first nibble of register 1. As you really allocate multiples of 4-bits, a recalled number that has bits set outside the current word size are trimmed. This only affects the number recalled to X, not the actual bits in memory. If you change the word size and only read from memory, you can always restore a previous word size and have all memory unharmed. 3.5 Number prompts ================== Certain operations prompts for a number using two or three underscores: STO _ _ _ The number entered is always a decimal number. The following keys are active during prompt: ON Abort entry. 0-9 Add digit to number <- Erase the last entered digit. Aborts entry if no digits has been entered or when you have erased all entered digits. The four top rows [Soft menu A] -- [1/X] works as a quick entry of number 0-23 provided that you have not entered anything so far. This is similar to how the two top rows behave on a HP-41C, if you are familar with that calculator. ======================== 4. Technical Information ======================== For those of you who are curious, here is some technical data related to HP16C. - I do not own an HP-16C, but I do own a manual which is very useful. - HP16C is mainly written in assembler with some SYSRPL code to deal with the user interface. - I use the GNU tools and x48 as the main test environment. JAZZ was very useful when I tracked down some very hard bugs. As a side note, almost all of these bugs were due to the braindead handling of comments in SASM. I really wish that it would *require* a comment character rather than silently tranforming my operand field to a comment. - I have just picked a library number, I do not know how good or bad this number is. Maybe I have to change it later... - HP16C would not have been possible without the excellent book "An Introducation to HP 48 System RPL and Assembly Language Programming" by James Donelly. Thank you very much for writing it!!! - In addition to this, I also used the saturn disassembler to get a ROM listing. This listing was very useful. ======================= 5. Bugs and Suggestions ======================= If you find a bug in HP16C, please send me enough information to reproduce it. I cannot promise that I will fix it, but it is likely since I use HP16C heavily myself. Suggestions are also very welcome. ============= 6. Bugs fixed ============= 1.1 * Added keys for: - Setting number base (MTH - VAR). - Word size prompt key at right shift ENTER. - AND, OR, XOR, NOT (right shift *, +, -, /) * Fixed successive (mixed) shift key presses to behave as they should.