home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff274.lzh / HP11 / hp11.c < prev    next >
C/C++ Source or Header  |  1989-11-16  |  5KB  |  163 lines

  1. #include "exec/types.h"
  2. #include "proto/dos.h"
  3.  
  4. #include "hp11/hp11.h"
  5. #include "hp11/amiga/amiga.h"
  6. #include "hp11/io.h"
  7. #include "hp11/support.h"
  8. #include "hp11/ins.h"
  9. #include "hp11/codes.h"
  10.  
  11. #include <stdlib.h>
  12.  
  13. /* Values for Cback */
  14. LONG _stack = 4000;
  15. char *_procname = "HP11C";
  16. LONG _BackGroundIO = 0;
  17. LONG _priority = 0;
  18.  
  19. struct Regs hp11r;
  20. int running, fast, error, skip;
  21. int PC, retStack[MAXSTACK], retCnt;
  22. int Flags;
  23.  
  24. int quit, on = TRUE; /* Set to false to quit */
  25.  
  26. static void ExecAction(int act) /* Execute an Action in normal mode */
  27. {
  28.    if (act >= IGTO_LINE) { /* GTO .nnn where act = IGTO_LINE + nnn */
  29.       entering = FALSE; /* Digit entry disabled */
  30.       GTOLine(act - IGTO_LINE);
  31.    }
  32.    else switch (act) {
  33.       case ISST: SST(); break;
  34.       case IBST: BST(); break;
  35.       case IP_R: ProgramEntry(); break;
  36.       case IUSER: USER(); break;
  37.       case ICLR_PRGM: RTN(); break; /* Clear Prgm = RTN() in normal mode */
  38.       case ION: on = !RelKey(); break; /* Allow user to change his mind */
  39.       case IMEM: MEM(); break;
  40.       case ICLR_PREFIX: PREFIX(); break;
  41.       case IBACK:if (entering) EnterNum(-IBACK); /* Correct during digit entry */
  42.          else CLX();
  43.          break;
  44.    }
  45. }
  46.  
  47. void ExecIns(ins) /* Execute an instruction (normal or run mode) */
  48. register int ins;
  49. {
  50.    skip = FALSE;
  51.  
  52.    if (ins < KCOMPLEX) (*insfunc[ins])(); /* miscellaneous ins */
  53.    else if (ins < KFLAGS + OCF) SF(ins - (KFLAGS + OSF));
  54.    else if (ins < KFLAGS + OSET) SF(ins - (KFLAGS + OSF));
  55.    else if (ins < KFIG) SF(ins - (KFLAGS + OSF));
  56.    else if (ins < KFIX) EnterNum(ins);
  57.    else if (ins < KSCI) FIX(ins - KFIX);
  58.    else if (ins < KENG) SCI(ins - KSCI);
  59.    else if (ins < KLBL) ENG(ins - KENG);
  60.    else if (ins < KGTO) ENABLE() /* LBL : ignore, just enable stack */;
  61.    else if (ins < KGSB) GTO(ins - KGTO);
  62.    else if (ins < KSTO) GSB(ins - KGSB);
  63.    else if (ins < KRCL) STO((ins - KSTO) % OPLUS,
  64.                 (enum StoTypes)((ins - KSTO) / OPLUS));
  65.       /* compute type of operation to do : there are 21 regs per operation,
  66.      + indirect, the codes are sequential : all the stos, all the pluses ...
  67.      PLUS is first so it is 22, hence the division to determine the operation */
  68.    else if (ins < KRCL + 22) RCL(ins - KRCL);
  69.  
  70.    X = Check(X); Y = Check(Y); /* Check the values in X & Y to conform to HP11
  71.       limits. The testing is done here to save code space so that all the instructions
  72.       don't have to include the check */
  73. }
  74.  
  75. static BOOL Init(int argc, APTR argv) /* Initialize the calculator, return FALSE if it fails */
  76. {
  77.    DEG(); /* Initial state, all other values are zero */
  78.    FIX(4);
  79.  
  80.    /* Computer specific intialisation, can load an initial program */
  81.    return(AmigaInit(argc, argv));
  82. }
  83.  
  84. static void CleanUp(void)
  85. {
  86.    AmigaCleanUp();
  87. }
  88.  
  89. /* Standard version of sleep */
  90. /* On Amiga, iconifies (special routine in amiga.c */
  91. /* static void sleep()
  92. {
  93.    int key;
  94.  
  95.    Display("");
  96.  
  97.    while (!quit && !on) {
  98.       key = PollKey(TRUE);
  99.       RelKey();
  100.       on = key == 30 (* ON *), replace ( with / if you uncomment this;
  101.    }
  102. } */
  103.  
  104. void main(int argc, char **argv)
  105. {
  106.    WORD code;
  107.    enum KeyTypes type;
  108.  
  109.    if (Init(argc, (APTR)argv))
  110.       do { /* while (!quit) */
  111.      while (on && !quit) { /* Exit when calculator turned off */
  112.         Disp();
  113.         error = FALSE; overflow = FALSE;
  114.  
  115.         if (running) { /* Run mode */
  116.            if (PollKey(FALSE) != -1) { /* User pressed a key */
  117.           running = FALSE;
  118.           RelKey(); /* Wait for him to release it */
  119.            }
  120.            else {
  121.           if (!fast) Wait50(2L); /* Slow calculator down to make it more realistic (wait 2/50 s) */
  122.           ExecIns(Prog[PC]); /* Exec current ins */
  123.           if (error || overflow) running = FALSE; /* An error occured, halt */
  124.           else {
  125.              if (skip) PC++; /* A conditional instruction asked for the next
  126.             instruction to be skipped */
  127.              PC++;
  128.              while (PC > lastIns) { /* There is an implicit return at the end of the program */
  129.             RTN();
  130.             PC++;
  131.              }
  132.           }
  133.            }
  134.         }
  135.         else { /* normal mode operation */
  136.            MenusOn();
  137.            EditOn();
  138.            type = ReadKey(&code);
  139.            EditOff();
  140.            switch (type) { /* Read an instruction/action */
  141.           case Action:
  142.              ExecAction(code); /* Execute corresponding action */
  143.              break;
  144.           case Instruction:
  145.              ExecIns(code); /* Interpret instruction */
  146.              break;
  147.            }
  148.            MenusOff();
  149.            RelKey();
  150.         }
  151.  
  152.      }
  153.  
  154.      if (!quit) {
  155.         sleep(); /* Wait till woken up */
  156.         ENABLE();
  157.      }
  158.       } while (!quit);
  159.  
  160.    CleanUp();
  161. }
  162.  
  163.