HP-41C/CV/CX MicroCode Emulator for HP-49G and HP-48S/SX/G/G+/GX (Version 1.15)
Copyright (C) 1983-2001 by HrastProgrammer <http://hrastprogrammer.tripod.com>

Warning: There are separate distribution files for the HP-49G and for
         the HP-48S/SX/G/G+/GX. This file is identical for all of them.

This is true microcode emulator of the HP-41C/CV/CX calculator. It emulates all
instructions of the famous Nut CPU (CocoNut, HalfNut, HoneyNut, ...), standard
and synthetical programming, display (all characters and punctuation) and
keyboard behaviour (Press -> Command -> NULL), various relevant hardware, etc,
etc. Display is emulated without any flicking and keyboard reactions are
immediate. It even simulates auto turn-off feature and BEEP/TONE commands.
On my HP-48G+/GX/49G it is about 70-90% faster than real one (depending on the
application). On the old HP-48SX it is about 10-30% faster. HP-48S/G version
is slower for about 35%.

The following versions of the emulator are available:

HP41E47     Lite C version with 64 registers
HP41E48/49  Basic C version with 64 registers
HP41EV48/49 Basic CV version with 320 registers
HP41EM48/49 CV version with XF/XM Module
HP41ME48/49 CV version with XF/XM and 2 additional XM Modules
HP41EX48/49 Basic CX version
HP41XE48/49 CX version with 2 additional XM Modules
HP41EP48/49 CX version with Printer Module
HP41PE48/49 CX version with Printer and 2 additional XM Modules
HP41EY48/49 CX version with Printer and Advantage Module
HP41YE48/49 CX version with Printer, Advantage and 2 additional XM Modules

Other combinations are possible, of course.

Lite version is provided for the owners of HP-48S/G with 32K RAM and differs
from its big brothers in the following: (1) It is about 35% slower, (2) Only 64
registers for data and programs (like the basic HP-41C), (3) No splash screen
and the frame, (4) Much 'uglier' font, (5) Special characters cannot have
punctuation, (6) No Enhanced and Temporary Alpha Mode, (7) No auto turn-off
simulation, (8) No cold start, (9) No RAM loading and saving to a variable,
(10) Only ON&F, ON&DEL and ON&<- combinations are available. There are also
few less important differences.

Short description and instructions:
(there is no Help file associated with the emulator)

1. Running the emulator:

  Simply transfer the program HP41xymn to your calculator (where 'xy' can be
  E,EV,EM,ME,EX,EP,EY,XE,PE,YE and 'mn' can be 47,48,49). The emulator is
  stand-alone object: it can be stored to the variable or the port, recalled
  to stack, evaluated from variable, port and stack, transferred to another
  calculator, ... all this with the state of calculator totally preserved.
  You can simply run the emulator from global variable, write the program,
  run the program, make some other work and return to HP-48/49 with the key F
  (from 'Finish'). Then you can run it again with all memory preserved. You
  can even transfer the emulator to the another HP-48/49 and run it: all state
  is preserved. And another important thing: all data and code addressing is
  relative and emulator can be executed from every memory location. When you
  run the emulator for the first time you will get 'MEMORY LOST', of course.

2. Keyboard mapping for HP-48:
   (one HP-41 key can be assigned to more-than-one HP-48 keys)

  HP-41   HP-48
  ------- ------
  ON:     MTH
  USER:   CST
  PRGM:   PRG
  ALPHA:  Alpha
  Sigma+: A, Y^X
  1/X:    B, 1/X
  SQRT:   C, SQRT
  LOG:    D
  LN:     E
  X<>Y:   LeftArrow
  RDN:    DownArrow
  SIN:    SIN
  COS:    COS
  TAN:    TAN
  SHIFT:  LeftShift, RightShift, UpArrow
  XEQ:    '
  STO:    STO
  RCL:    EVAL, VAR
  SST:    NXT, RightArrow
  ENTER^: ENTER
  CHS:    +/-
  EEX:    EEX
  <-:     <-
  -:      -
  7:      7
  8:      8
  9:      9
  +:      +
  4:      4
  5:      5
  6:      6
  *:      *
  1:      1
  2:      2
  3:      3
  /:      /
  0:      0
  .:      .
  R/S:    SPC

3. Keyboard mapping for HP-49G:
   (one HP-41 key can be assigned to more-than-one HP-49G keys)

  HP-41   HP-49G
  ------- ------
  ON      HIST
  USER    MODE
  PRGM    APPS
  ALPHA   Alpha
  Sigma+  F1 (A), Y^X
  1/X     F2 (B), 1/X
  SQRT    F3 (C), SQRT
  LOG     F4 (D), EQW
  LN      F5 (E), SYMB
  X<>Y    LeftArrow
  RDN     DownArrow
  SIN     SIN
  COS     COS
  TAN     TAN
  SHIFT   LeftShift, RightShift, UpArrow
  XEQ     CAT, TOOL
  STO     STO >
  RCL     VAR
  SST     NXT, RightArrow
  ENTER^  ENTER, X
  CHS     +/-
  EEX     EEX
  <-      <-
  -       -
  7       7
  8       8
  9       9
  +       +
  4       4
  5       5
  6       6
  *       *
  1       1
  2       2
  3       3
  /       /
  0       0
  .       .
  R/S     SPC

4. Other keys on HP-48/49 used by the emulator:

  F       Return to the HP-48/49G operating system (not available in Enhanced
          or Temporary Alpha Mode - it produces letter 'F' instead).

  ON      Suspends the execution of the emulator until released.

  ON&key  ON&A Switch Enhanced Alpha Mode On.
          ON&B Switch Enhanced Alpha Mode Off.

          ON&DEL or ON&<- Warm Start.

          ON&+ and ON&- Change display contrast.

          ON&SIN Activate RAM loading on startup.
          ON&COS Deactivate RAM loading on startup.

          ON&STO Activate RAM saving on exit.
          ON&EVAL/VAR Deactivate RAM saving on exit.

          ON&Alpha Activate Temporary Alpha Mode.

          ON&F Return to the HP-48/49G operating system.

          This is introduced to support some features in the future which may
          require additional keys (like printer). They can't be assigned to
          the regular keyboard because there aren't enough keys on it. Most of
          the ON&key combinations aren't available in the Lite version of the
          emulator.

          Printer ON&key combinations (only available in EP,PE,EY,YE versions):

            ON&0 Printer OFF.
            ON&1 Printer mode MAN.
            ON&2 Printer mode NORM.
            ON&3 Printer mode TRACE.
            ON&. Printer ADV button.
            ON&* Printer Wire transmition ON.
            ON&/ Printer IR transmition ON (not available on HP-49G).

  DEL&MTH (on HP-48) or <-&HIST (on HP-49G)
          Cold start while emulator is turned off (DEL/<- followed immediately
          by MTH/HIST, you have to press MTH/HIST very fast - this is the
          prevention from accidental 'MEMORY LOST').

  Note: Because interrupts are disabled while emulator is running regular
        ON&key combinations are disabled, too. Some of them are emulated, like
        warm start and display contrast, but for the others you have to return
        to the HP-48/49G operating system.

5. Enhanced Alpha Mode:

  In the Enhanced Alpha Mode keys A..Z of the emulator correspond to keys A..Z
  of the standard HP-48 Alpha keyboard. This makes character input very simple
  and fast especially for sequences like XEQ ALPHA something ALPHA. Other keys
  (0..9,.,+,-,*,/,R/S) are unchanged (it means also that you enter numbers with
  SHIFT like on the real one). 

  The following special keys have different mapping in Enhanced Alpha Mode:

  HP-41  HP-48     HP-49G
  ------ --------- ----------
  ON     n/a       UpArrow
  USER   n/a       LeftArrow
  PRGM   ENTER     RightArrow
  SST    DEL       DownArrow

  Similar to Enhanced Alpha Mode is Temporary Alpha Mode which can be activated
  by ON&Alpha combination. This mode is very helpfull when keying commands like
  RCL Y, STO Z, etc. because keys act like the emulator is in the Alpha mode
  even if it is outside the Alpha mode. Temporary Alpha Mode is usually active
  for the next keystroke only.

6. RAM loading and saving:

  On exit, the complete state of the emulator is saved to global variable
  'RA41' in the current directory. State is saved as character string. If
  there is not enough free memory to save the state, an error will be generated.
  On start, the state is loaded from the same variable (if it exists). If the
  variable under such name doesn't exist, the emulator will use its current
  state. You can have many copies of emulator state and thus many different
  emulator environments can be obtained. Simply store your variable under the
  name 'RA41' in the current directory. This is also very usefull for backup
  purposes and exchanging programs. It is not a clever idea to mix RAM images
  between different versions of the emulator (especially between C/CV and CX
  versions).

7. What is emulated and supported?

   7.1. Hardware:

     Nut CPU
     Display hardware
     Keyboard hardware
     ROM memory & management
     External modules & management
     Internal and standard RAM memory & management
     Extended memory & management
     NPIC Nut Peripheral Interface Chip
     Helios Thermal Printer (non-graphics)
     Phineas Clock Chip

   7.2. Software:

     Machine language
     User programming language
     Synthetic programming
     Time functions (standard and CX)
     Extended functions (standard and CX)
     Printer functions
     Advantage functions

  7.3. Modules:

     Time module
     Extended functions module
     Printer module
     Advantage module
     Various other modules like Game Module etc.

8. What is missing?

    HP-IL hardware & module
    Card reader hardware & module
    IR Printer hardware & module
    Graphics on Helios and IR Printer
    WAND hardware & module
    Service module from HP (Nut and Saturn CPUs are just too different)

    Support for above is either obsolete (like card reader) or depends on the
    Saturn CPU because all of this has to be done in software (in machine
    language) and could seriously affect the overall performance.

9. Comparision of speed between the real HP-41C and HP41E48 (approx. values):

  Test program                              Real       HP41E48    Speed of
  (standard settings: DEG FIX 4)            HP-41C     on HP-48GX the emulator
  ----------------------------------------- ---------- ---------- ------------
  LBL A 400 LBL 01 VIEW X DSE X GTO 01      87s        47s        185%
  "DONE" AVIEW TONE 0 END

  LBL A 800 LBL 01 DSE X GTO 01             75s        44s        170%
  "DONE" AVIEW TONE 0 END

  LBL A "START" AVIEW 800 LBL 01 DSE X      73s        38s        192%
  GTO 01 "DONE" AVIEW TONE 0 END

  LBL A 0 100 LBL 01 ENTER^ SIN SQRT        110s       60s        183%
  ABS PI * LN ST+ Z RDN DSE X GTO 01
  "DONE" AVIEW TONE 0 END

  SIZE 050 LBL A CLRG 10 STO 00 LBL 01      94s        53s        177%
  49 LBL 02 STO Y X<> IND Y STO IND Y
  RCL Y DSE X GTO 02 DSE 00 GTO 01
  "DONE" AVIEW TONE 0 END

  SIZE 050 LBL A "START" AVIEW CLRG 10      94s        49s        191%
  STO 00 LBL 01 49 LBL 02 STO Y
  X<> IND Y STO IND Y RCL Y DSE X GTO 02
  DSE 00 GTO 01 "DONE" AVIEW TONE 0 END

  The average speed is 183% compared to the real HP-41C. These values are
  measured with the Basic version of the emulator. Lite version is about 35%
  slower. EX, XE, EP, PE, EY and YE versions may be just few percent slower
  under some circumstances because of larger memory address space, bank
  switching, clock chip, printer emulation and some other factors. It would be
  very interesting to compare the speed of the emulator with the real HP-41CX
  but I don't own one so I cannot do it.

  It is obvious that less difference between the emulator and the real HP-41C
  occurs when the goose walks on display. This is very 'cheap' operation on
  the real calculator because it needs only one shifting which is done in
  hardware (display driver). The emulator has to refresh the whole display
  instead in order to emulate it properly. So, if you want to speed up the
  execution on the emulator just display some text with AVIEW (or some number
  with VIEW) so the emulator doesn't have to refresh it (because it is not
  changed) during the execution of the program.

10. Additional notes:

  10.1. When HP41E is turned off (either by auto turn-off or by the OFF key)
        it clears the emulator screen only. It means that the CPU is running
        all the time because it has to refresh the clock and check the alarms.
        It also means that power is drawing from the batteries as usual. So,
        if you want to save batteries then don't run the emulator when you
        don't need it. Exit the emulator and turn the calculator off.

  10.2. Clock on the CX versions is not very accurate. There is nothing I can
        do to improve this because there isn't enough CPU power inside.

  10.3. The printer is supported either via Wire or IR but I haven't been able
        to test it via IR because I don't own the 82240B printer. I tested it
        with serial cable connected to the PC running the 82240B emulator.

  10.4. Printer graphics is not implemented. Don't execute graphic commands
        because they could send a garbage to the printer output.

11. Final word:

Required ROM images are released by HP to the public under NOMAS license (NO
MAnufacturer Support) many years ago. They can be found elsewhere on the
Internet but I have included them to simplify the use of the emulator.

I am not responsible for anything you do with this software. The emulators
are not designed to make any (software or hardware) damage but (due to the
complexity of the code) if something goes wrong I am not responsible for that.
Again: use this software at your (and only your) own risk!

Consult the LICENSE.TXT before using this software.

Now you can enter your 'Byte Grabber' with ASN ALPHA + ALPHA LN ASN ALPHA
DEL ALPHA LOG USER PRGM LBL ALPHA T ALPHA CAT 1 R/S (while display shows
LBL "T") DEL 001 BST GTO .005 DEL 003 ALPHA ?AAAAAA ALPHA PRGM GTO ..
Press and hold 'LN' key and you will see XROM 28,63 followed by NULL.
What is following next depends on your imagination.

Please check my HP41E for Windows 95/98/Me/NT/2000, too.

Best regards,
HrastProgrammer.
