home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / h / hp11 / Amiga_Code / c / translate < prev   
Encoding:
Text File  |  1992-05-07  |  2.6 KB  |  63 lines

  1. /* Title:   -> $.!hp11.amiga.c.translate
  2.  *
  3.  *   A module to provide translation between the Kcodes used internally by
  4.  *   hp11.c and the coding normally used in the HP documentation.
  5.  *
  6.  */
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #include "types.h"
  11. #include "translate.h"
  12. #include "codes.h"
  13. #include "hp11.h"
  14. #include "prog_codes.h"
  15. #include "io.h"
  16.  
  17. /*---------------------------------------------------------------------------*/
  18. /*================              GLOBAL CONSTANTS               ==============*/
  19. /*---------------------------------------------------------------------------*/
  20.  
  21. char *code_buffer;
  22.  
  23. /*---------------------------------------------------------------------------*/
  24. /*================            TRANSLATION FUNCTIONS            ==============*/
  25. /*---------------------------------------------------------------------------*/
  26. int hp11_encode(void)
  27. /* encodes the current program into key names and key codes, in the buffer
  28.    pointed to by code_buffer.  Returns the number of characters in the buffer
  29.    excluding the final null character */
  30. {
  31.   register int i, c1, c2, c3, buffer_length;
  32.   static char _buf[MAXCODE+1], _insbuf[MAXCODE+1];
  33.   register char *buf = _buf, *insbuf = _insbuf;
  34.   register int point = comma ? ',' : '.';  /* separator according to setting */
  35.  
  36.   buffer_length = sprintf(code_buffer, "f CLEAR PRGM     000-\n");
  37.   for (i=1; i<=lastIns; i++) {
  38.     sprintf(buf, "%15s  %03d-", key_names[Prog[i]], i);/* start program line */
  39.     c1 = keycodes[Prog[i]].c1;
  40.     c2 = keycodes[Prog[i]].c2;
  41.     c3 = keycodes[Prog[i]].c3;
  42.     switch (keycodes[Prog[i]].Type) {      /* Now prepare instruction buffer */
  43.       case ONECODE:                                        /* nn eg SIN or 9 */
  44.         sprintf(insbuf, "%8d\n", c1); break;                 
  45.       case TWOCODE:                                       /*  nn nn eg g LOG */
  46.         sprintf(insbuf, "%5d%3d\n", c1, c2); break;         
  47.       case TWOCODE_9:                                       /* nn n eg STO 5 */
  48.         sprintf(insbuf, "%5d%3d\n", c1, c2); break; 
  49.       case TWOCODE_PT:                                    /* nn .n eg RCL .6 */
  50.         sprintf(insbuf, "%5d %c%1d\n", c1, point, c2); break; 
  51.       case THREECODE:                               /* nn,nn,nn eg f HYP SIN */
  52.         sprintf(insbuf, "%2d,%2d,%2d\n", c1, c2, c3); break; 
  53.       case THREECODE_PT:                            /* nn,nn, .n eg STO + .0 */
  54.         sprintf(insbuf, "%2d,%2d,%c%1d\n", c1, c2, point, c3); break; 
  55.     }
  56.     buffer_length += sprintf(sizeof(char)*buffer_length + code_buffer, "%s",
  57.                                                           strcat(buf, insbuf));
  58.   }
  59.   return(buffer_length);
  60. }  
  61.  
  62.  
  63.