home *** CD-ROM | disk | FTP | other *** search
- /* Title: -> $.!hp11.amiga.c.translate
- *
- * A module to provide translation between the Kcodes used internally by
- * hp11.c and the coding normally used in the HP documentation.
- *
- */
- #include <stdio.h>
- #include <string.h>
-
- #include "types.h"
- #include "translate.h"
- #include "codes.h"
- #include "hp11.h"
- #include "prog_codes.h"
- #include "io.h"
-
- /*---------------------------------------------------------------------------*/
- /*================ GLOBAL CONSTANTS ==============*/
- /*---------------------------------------------------------------------------*/
-
- char *code_buffer;
-
- /*---------------------------------------------------------------------------*/
- /*================ TRANSLATION FUNCTIONS ==============*/
- /*---------------------------------------------------------------------------*/
- int hp11_encode(void)
- /* encodes the current program into key names and key codes, in the buffer
- pointed to by code_buffer. Returns the number of characters in the buffer
- excluding the final null character */
- {
- register int i, c1, c2, c3, buffer_length;
- static char _buf[MAXCODE+1], _insbuf[MAXCODE+1];
- register char *buf = _buf, *insbuf = _insbuf;
- register int point = comma ? ',' : '.'; /* separator according to setting */
-
- buffer_length = sprintf(code_buffer, "f CLEAR PRGM 000-\n");
- for (i=1; i<=lastIns; i++) {
- sprintf(buf, "%15s %03d-", key_names[Prog[i]], i);/* start program line */
- c1 = keycodes[Prog[i]].c1;
- c2 = keycodes[Prog[i]].c2;
- c3 = keycodes[Prog[i]].c3;
- switch (keycodes[Prog[i]].Type) { /* Now prepare instruction buffer */
- case ONECODE: /* nn eg SIN or 9 */
- sprintf(insbuf, "%8d\n", c1); break;
- case TWOCODE: /* nn nn eg g LOG */
- sprintf(insbuf, "%5d%3d\n", c1, c2); break;
- case TWOCODE_9: /* nn n eg STO 5 */
- sprintf(insbuf, "%5d%3d\n", c1, c2); break;
- case TWOCODE_PT: /* nn .n eg RCL .6 */
- sprintf(insbuf, "%5d %c%1d\n", c1, point, c2); break;
- case THREECODE: /* nn,nn,nn eg f HYP SIN */
- sprintf(insbuf, "%2d,%2d,%2d\n", c1, c2, c3); break;
- case THREECODE_PT: /* nn,nn, .n eg STO + .0 */
- sprintf(insbuf, "%2d,%2d,%c%1d\n", c1, c2, point, c3); break;
- }
- buffer_length += sprintf(sizeof(char)*buffer_length + code_buffer, "%s",
- strcat(buf, insbuf));
- }
- return(buffer_length);
- }
-
-
-