home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d130 / hp.lha / Hp / hp.c < prev    next >
C/C++ Source or Header  |  1988-03-13  |  6KB  |  234 lines

  1. #include "INCLUDE:Lattice/math.h"
  2. #include "INCLUDE:Lattice/stdio.h"
  3. #include "INCLUDE:exec/types.h"
  4. #include "INCLUDE:graphics/gfx.h"
  5. #include "INCLUDE:graphics/gfxmacros.h"
  6. #include "INCLUDE:exec/exec.h"
  7. #include "INCLUDE:exec/execbase.h"
  8. #include "INCLUDE:graphics/view.h"
  9. #include "INCLUDE:graphics/gfxbase.h"
  10. #include "INCLUDE:exec/libraries.h"
  11. #include "INCLUDE:intuition/intuition.h"
  12. #include "INCLUDE:graphics/text.h"
  13.  
  14. #include "hp_constants.h"
  15. #include "hp_data.include"
  16.  
  17. /*---------------------------------------*/
  18. /*             //  hp  //                */
  19. /*                                       */
  20. /*     A public-domain scientific        */
  21. /*      calculator for the Amiga         */
  22. /*                                       */
  23. /*            Version  1.0               */
  24. /*             March 1987                */
  25. /*            Steve Bonner               */
  26. /*---------------------------------------*/
  27.  
  28. main()
  29. {  int k;
  30.  
  31. GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  32. IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  33.  
  34. if( (GfxBase == NULL) || (IntuitionBase == NULL)) exit();
  35.  
  36. xstr[33] = 0;
  37. ystr[33] = 0;
  38.  
  39. print_on            = FALSE;
  40. error_occurred      = FALSE;
  41. entry_in_progress   = FALSE;
  42. screen_refresh_only = FALSE;
  43.  
  44. for ( k = 0; k < 16; k++) {
  45.     registers[k] = 0.0;
  46.    iregisters[k] = 0;     }
  47.  
  48. for ( k =  0; k <= 12; k++) key_valid[k] = TRUE;
  49. for ( k = 13; k <= 18; k++) key_valid[k] = FALSE;
  50. for ( k = 19; k <= 64; k++) key_valid[k] = TRUE;
  51.  
  52. SetUpHpGraphics();
  53.  
  54. DrawDisplay();
  55. screen_refresh_only = TRUE;
  56.  
  57. DrawKeys();
  58. LabelKeys();
  59.  
  60. SetAngleMode( DEGREES );
  61.  
  62. base = HEX;         /*  Forces SetBase routine to highlight     */
  63. SetBase( FLOAT );   /*  keys and zero out real and int stacks.  */
  64.  
  65. SetAPen( rp, GREY );
  66. SetBPen( rp, SCREENCOLOR );
  67. SetDrMd( rp, JAM2 );
  68.  
  69.  
  70. DisplayFloatXY();
  71.  
  72. inkey = 0;
  73.  
  74. while ( 1 == 1) {
  75.  
  76.   NextClick:
  77.  
  78.   /*  Print command entered for last key click */
  79.   PrintKey();
  80.  
  81.   KeyDown:
  82.  
  83.   /*  Wait for the next click:    */
  84.   WaitPort( hp_window -> UserPort );
  85.  
  86.   if ( GadgetPoked() )        {
  87.     CloseWindow( hp_window );
  88.     CloseScreen( hp_screen );
  89.     if ( print_on )      {
  90.       fputs("\33#1", printer );    /* restore default setting */
  91.       fclose( printer ); }
  92.     exit();                   }
  93.  
  94.   if ( message -> Code != SELECTDOWN ) goto KeyDown;
  95.  
  96.   inkey = KeyCode();
  97.  
  98.   entry_completed = FALSE;
  99.  
  100.   if ( inkey == 31 ) StoreRegister();
  101.   if ( inkey == 32 ) RecallRegister();
  102.  
  103.   if ( (inkey == 32) || (inkey == 32) ) goto NextClick;
  104.  
  105.   if ( key_valid[ inkey ] == FALSE ) {
  106.     BeepHpDisplay();
  107.     goto NextClick;                  }
  108.  
  109.   CheckModes();
  110.   if ( mode_changed ) goto NextClick;
  111.  
  112.  
  113.   if ( InkeyIsNumeric()  )              {
  114.  
  115.      if ( entry_in_progress )
  116.         ContinueNumEntry();
  117.      else
  118.         CommenceNumEntry();             }
  119.  
  120.  
  121.     else   /* Not numeric */            {
  122.  
  123.         if ( entry_in_progress )      {
  124.  
  125.           entry_completed = TRUE;
  126.  
  127.           /*  Convert instring to internal format   */
  128.           /*  and push onto stack unless number is  */
  129.           /*  being dropped:                        */
  130.           if ( inkey != 60 ) PushX(); }
  131.  
  132.           /*  Perform a stack operation if requested  */
  133.           CheckStack();
  134.  
  135.           error_occurred = FALSE;
  136.  
  137.           if ( base == FLOAT   )   ProcessFloat();
  138.           if ( base == COMPLEX )   ProcessComplex();
  139.           if ( base >= BINARY  )   ProcessInteger();
  140.  
  141.           entry_in_progress = FALSE;
  142.  
  143.           if ( error_occurred  )  {
  144.              x  = 0.0;
  145.              ix = 0;
  146.              if ( base == COMPLEX ) y = 0.0;
  147.              goto NextClick;       }
  148.  
  149.           if ( (inkey > 60) && (inkey < 64) ) {  TweakDisplay();
  150.                                                  goto NextClick; }
  151.  
  152.           if ( inkey == 64 ) {  if (print_on) fprintf(printer, "\n");
  153.                                 goto NextClick;          }
  154.  
  155.           if ( base < 2 )
  156.              DisplayFloatXY();
  157.           else
  158.              DisplayIntXY();
  159.                                           }  /* Not numeric */
  160.      
  161.  
  162.   }  /* WhileEnd */
  163.  
  164.  
  165. }  /* main */
  166.  
  167. /*--------------------------------------------------------*/
  168. /*    Bring in source code for subroutines:               */
  169. /*--------------------------------------------------------*/
  170.  
  171. #include "hp_graphics1.include"
  172. #include "hp_graphics2.include"
  173.  
  174. #include "hp_modes.include"
  175. #include "hp_user_inputs.include"
  176. #include "hp_conversions.include"
  177. #include "hp_math.include"
  178.  
  179. /*--------------------------------------------------------*/
  180. PrintKey()
  181. {
  182.  char *xp, *yp;
  183.  if ((inkey == 0) || (inkey > 60)) return(0);
  184.  
  185.  if ( inkey == 55 )
  186.    {
  187.    if ( print_on == TRUE )       {
  188.       print_on = FALSE;
  189.       fputs("\33#1", printer );    /* restore default setting */
  190.       fclose( printer );         }
  191.  
  192.    else                          {
  193.       print_on = TRUE;
  194.       printer  = fopen( "PRT:" , "w");
  195.       if ( printer == NULL ) BeepHpDisplay();
  196.  
  197.       /*  Use condensed print (required for printing binary numbers) */
  198.       fputs("\33[4w", printer);
  199.  
  200.       /*  Use printer color number 1  */
  201.       fputs("\33[31m", printer);   }
  202.    }
  203.  
  204.  if ( print_on == FALSE ) return(0);
  205.  
  206.  if ( entry_in_progress == FALSE )   {
  207.  
  208.    /*  If a new x-value has just been Pushed, it must be printed */
  209.    if ( entry_completed )        {
  210.      iptr = &instring[0];
  211.      instring[ next_digit ] = 0; }
  212.    else
  213.      iptr = &nullentry[0];
  214.  
  215.    if ( base < BINARY ) {  xp = xptr;
  216.                            yp = yptr;     }
  217.    else                 {  xp = &xstr[0];
  218.                            yp = &ystr[0]; }
  219.  
  220.  
  221.    /*  If command is STO or RCL, set pointer to identify register */
  222.    if ( (inkey == 31) || (inkey == 32))
  223.      regptr = opcode[ regcode ];
  224.    else
  225.      regptr = &no_register[0];
  226.  
  227.    fprintf( printer, "%-32s %5s %5s %-32s %-32s\n",
  228.          iptr, opcode[inkey], regptr, yp, xp );
  229.                                     }
  230. }
  231.  
  232.  
  233.  
  234.