From:	CSBVAX::CSBVAX::MRGATE::"SMTP::VAXMFG.TECH.NWU.EDU::CHOJNACKI"  2-MAR-1989 21:57
To:	MRGATE::"ARISIA::EVERHART"
Subj:	March 2 UNMACRO source 4/8


Received: from vaxmfg.tech.nwu.edu by accuvax.nwu.edu id aa12130;
          2 Mar 89 11:14 CST
Date: Thu, 2 Mar 89 11:24 CST
From: Bob Chojnacki <CHOJNACKI@vaxmfg.tech.nwu.edu>
Subject: March 2 UNMACRO source 4/8
To: EVERHART%ARISIA.decnet@ge-crd.arpa
X-VMS-To: IN%"EVERHART%ARISIA.decnet@ge-crd.arpa"
Message-ID:  <8903021114.aa12130@accuvax.nwu.edu>

+-+-+-+ Beginning of part 4 +-+-+-+
X   3, 3, 4, 4, 5, 5, 6, 6,
X   1, 1, 2, 2, 3, 3, 3, 4,`009/* 30 */
X   4, 4, 3, 3, 2, 4, 2, 1,
X   2, 3, 2, 3, 2, 3, 2, 3,`009/* 40 */
X   2, 2, 2, 2, 2, 2, 2, 4,
X   2, 2, 2, 1, 5, 3, 2, -1,`009/* 50 */
X   2, -1, -1, -1, 2, 2, 2, 2,
X   2, 3, 2, 3, 2, 3, 2, 3,`009/* 60 */
X   2, 2, 2, 2, 2, 2, 2, 4,
X   2, 2, 2, 1, 5, 3, 2, -1,`009/* 70 */
X   3, 3, 4, 4, 1, 2, 2, 1,
X   2, 3, 2, 3, 2, 3, 2, 3,`009/* 80 */
X   2, 3, 2, 3, 2, 3, 2, 3,
X   2, 2, 2, 2, 1, 1, 1, 1,`009/* 90 */
X   2, 2, 2, 2, 3, 4, 2, 1,
X   2, 3, 2, 3, 2, 3, 2, 3,`009/* A0 */
X   2, 3, 2, 3, 2, 3, 2, 3,
X   2, 2, 2, 2, 1, 1, 1, 1,`009/* B0 */
X   1, 1, 1, 1, 1, 1, 1, 1,
X   2, 3, 2, 3, 2, 3, 2, 3,`009/* C0 */
X   2, 3, 2, 3, 2, 3, 2, 3,
X   2, 2, 2, 2, 1, 1, 1, 1,`009/* D0 */
X   2, 2, 2, 2, 1, 1, 2, 1,
X   3, 3, 3, 3, 3, 3, 3, 3,`009/* E0 */
X   2, 2, 4, 4, 4, 4, 4, 4,
X   4, 4, 3, 3, 2, 2, 2, 2,`009/* F0 */
X   6, 3, 2, 2, 0, 0, 0, -1`125;
X/*
X  comment
X*/
X  debmsg("<instuctions>");
X  opcode = opcode & 0xff;`009`009/* clear top bytes */
X  strcpy(line, opcodes[opcode]);`009/* return the opcode string */
V  strcpy(altline, alt_opcodes[opcode]);`009/* return the alternate opcode strin
Xg */
X  *alt = opcode_flags[opcode];`009`009/* return type of opcode */
X  return(opcode_args[opcode]);`009`009/* return # of opcode arguments */
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "I_TYPE.C"
$ CHECKSUM_IS = 1781014238
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  returns the instruction type based on its opcode
X
X    i_type  type
X    ------  ----
X       0    Normal operands
X       1    Byte Branch
X       2    Mask
X       3    Case
X       4    Word Branch
X       5    CALLG or CALLS
X
X  Copyright (c) 1988 By Robert Thomas Chojnacki, All rights reserved.
X*/
X#include <stdio.h>
X#include "unmacro.h"
X#include "debug.h"
Xi_type(opcode, arg_num)
Xint opcode;
Xint *arg_num;`009/* operand referred to by i_type */
X`123
X  int op_typ[256] = `123
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* 00 */
X   1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,`009/* 10 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* 20 */
X   4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0,`009/* 30 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,`009/* 40 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* 50 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,`009/* 60 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* 70 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,`009/* 80 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0,`009/* 90 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,`009/* A0 */
X   0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0,`009/* B0 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,`009/* C0 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* D0 */
X   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,`009/* E0 */
X   0, 4, 1, 1, 1, 1, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0`125;`009/* F0 */
X  int op_ref[256] = `123
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* 00 */
X   1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,`009/* 10 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* 20 */
X   1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0,`009/* 30 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,`009/* 40 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* 50 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,`009/* 60 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* 70 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* 80 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0,`009/* 90 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* A0 */
X   0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 1, 0, 0, 0, 0,`009/* B0 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* C0 */
X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,`009/* D0 */
X   3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0,`009/* E0 */
X   4, 0, 3, 3, 2, 2, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0`125;`009/* F0 */
X   debmsg("<i_type>");
X#ifdef`009debug
X  printf("op_typ, op_ref = %d, %d\n", op_ref[opcode & 0xff],
X   op_typ[opcode & 0xff]);
X#endif
X  *arg_num = op_ref[opcode & 0xff];
X  return(op_typ[opcode & 0xff]);
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "MAKE_UNMACRO.COM"
$ CHECKSUM_IS = 592526233
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$ @UnMacro.Cmp
X$ @UnMacro
X$ Library/Create/Help UnMacro UnMacro
$ GOSUB UNPACK_FILE
$ FILE_IS = "MASKS.C"
$ CHECKSUM_IS = 1800682140
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  Converts an operand to a ascii mask
X
X  Copyright (c) 1988 By Robert Thomas Chojnacki, All rights reserved.
X*/
X#include <stdio.h>
X#include "unmacro.h"
X#include "getdata.h"
X#include "debug.h"
Xmasks(operand, line)
Xchar operand;
Xchar *line;
X`123
X  char temp[8];
X  int i, mask;
X
X  debmsg("<masks>");
X  mask = (operand & 0xff) + (getbyte() & 0xff)*256;
X  if (mask) `123
X    strcpy(line, "`094m<");
X    for (i = 0; i < 12; i++)
X      if ((1 << i) & mask) `123
X`009sprintf(temp, "r%d,", i);
X`009strcat(line, temp);
X      `125
X    if (mask & 4096)
X      strcat(line, "ap,");
X    if (mask & 8192)
X      strcat(line, "fp,");
X    if (mask & 16384)
X      strcat(line, "iv,");
X    if (mask & 32768)
X      strcat(line, "dv,");
X    line[strlen(line)-1] = '>';`009/* remove last comma */
X  `125 else
X    strcpy(line, "`094m<>");
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "OPERANDS.C"
$ CHECKSUM_IS = 1561117840
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  Convert a binary operand to ascii
X
X  Copyright (c) 1988 By Robert Thomas Chojnacki, All rights reserved.
X*/
X#include <stdio.h>
X#include "unmacro.h"
X#include "commands.h"
X#include "posneg.h"
X#include "getdata.h"
X#include "debug.h"
Xoperands(boperand, literal_type, line)
Xchar boperand;
Xint literal_type;
Xchar *line;
X`123
X  char sreg[4];
X  int operand, mode, reg, byte, address;
X/*
X  comment
X*/
X  debmsg("<operands>");
X  operand = boperand & 0xff;`009/* clear top bytes */
X  mode = (operand >> 4) & 0xf;`009/* get mode */
X  reg = operand & 0xf;`009`009/* get register */
X#ifdef`009debug
X  fprintf(stderr, "op, mode, reg = %2X, %X, %X", operand, mode, reg);
X#endif
X  if (reg < 12) `123
X    sprintf(sreg, "r%d", reg);
X  `125 else if (reg == 12) `123
X    strcpy(sreg, "ap");
X  `125 else if (reg == 13) `123
X    strcpy(sreg, "fp");
X  `125 else if (reg == 14) `123
X    strcpy(sreg, "sp");
X  `125 else if (reg == 15) `123
X    strcpy(sreg, "pc");
X  `125
X#ifdef`009debug
X  fprintf(stderr, " (%s)\n", sreg);
X#endif
X/*
X  extract operand based on its mode
X*/
X  switch (mode) `123
X   case 0:`009`009`009`009/* literals */
X   case 1:
X   case 2:
X   case 3:
X    sprintf(line, "s`094#`094x%X", operand);
X    lastliteral = boperand;
X    break;
X   case 4:`009`009`009`009/* indexed mode */
X    if (reg < 15) `123
X      sprintf(line, "[%s]", sreg);
X    `125 else `123
X      return(-mode);`009`009/* cant use this mode with PC */
X    `125
X    break;
X   case 5:`009`009`009`009/* register mode */
X    if (reg < 15) `123
X      sprintf(line, "%s", sreg);
X    `125 else `123
X      return(-mode);`009`009/* cant use this mode with PC */
X    `125
X    break;
X   case 6:`009`009`009`009/* register deferred */
X    if (reg < 15) `123
X      sprintf(line, "(%s)", sreg);
X    `125 else `123
X      return(-mode);`009`009/* cant use this mode with PC */
X    `125
X    break;
X   case 7:`009`009`009`009/* autodecrement */
X    if (reg < 15) `123
X      sprintf(line, "-(%s)", sreg);
X    `125 else `123
X      return(-mode);`009`009/* cant use this mode with PC */
X    `125
X    break;
X   case 8:`009`009`009`009/* autoincrement */
X    if (reg < 15) `123
X      sprintf(line, "(%s)+", sreg);
X    `125 else `123
X      lastliteral = getlong();
X      sprintf(line, "i`094#`094x%8X", lastliteral);
X    `125
X    break;
X   case 9:`009`009`009`009/* autoincrement deferred */
X    if (reg < 15) `123
X      sprintf(line, "@(%s)+", sreg);
X    `125 else `123
X      address = getlong();
X      sprintf(line, "@#`094x%8X", address);
X      if ((address >= base) && (address <= top)) `123
X`009bytetype[address-base] = neg(bytetype[address-base]);
X      `125
X    `125
X    break;
X   case 10:
X    if (reg < 15) `123
X      sprintf(line, "b`094`094x0%X(%s)", getbyte() & 0xff, sreg);
X    `125 else `123
X      sprintf(line, "b`094`094x0%X", getbyte() + pc);
X    `125
X    break;
X   case 11:
X    if (reg < 15) `123
X      sprintf(line, "@b`094`094x0%X(%s)", getbyte() & 0xff, sreg);
X    `125 else `123
X      sprintf(line, "b`094`094x%0X", getbyte() + pc);
X    `125
X    break;
X   case 12:
X    if (reg < 15) `123
X      sprintf(line, "w`094`094x0%X(%s)", getword() & 0xffff, sreg);
X    `125 else `123
X      sprintf(line, "w`094`094x0%X", getword() + pc);
X    `125
X    break;
X   case 13:
X    if (reg < 15) `123
X      sprintf(line, "@w`094`094x0%X(%s)", getword() & 0xffff, sreg);
X    `125 else `123
X      sprintf(line, "@w`094`094x0%X", getword() + pc);
X    `125
X    break;
X   case 14:
X    if (reg < 15) `123
X      sprintf(line, "l`094`094x%X(%s)", getlong(), sreg);
X    `125 else `123
X      address = getlong() + pc;
X      sprintf(line, "l`094`094x%X", address);
X      if ((address >= base) && (address <= top)) `123
X`009bytetype[address-base] = neg(bytetype[address-base]);
X      `125
X    `125
X    break;
X   case 15:
X    if (reg < 15) `123
X      sprintf(line, "@l`094`094x%X(%s)", getlong(), sreg);
X    `125 else `123
X      address = getlong() + pc;
X      sprintf(line, "@l`094`094x%X", address);
X      if ((address >= base) && (address <= top)) `123
X`009bytetype[address-base] = -C0_LONG;
X      `125
X    `125
X    break;
X  `125
X  debmsg(">operands<");
X  return(mode);
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "POSNEG.C"
$ CHECKSUM_IS = 138032123
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  defines the pos and neg functions
X
X  Copyright (c) 1988 By Robert Thomas Chojnacki, All rights reserved.
X*/
X#include <stdio.h>
X#include "debug.h"
Xchar pos(b)
Xchar b;
X`123
X  debmsg("<pos>");
X  return((b < 0) ? -b : b);
X`125
X
Xchar neg(b)
Xchar b;
X`123
X  debmsg("<neg>");
X  return((b < 0) ? b : -b);
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "POSNEG.H"
$ CHECKSUM_IS = 1161772545
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  defines the pos and neg functions
X
X  Copyright (c) 1988 By Robert Thomas Chojnacki, All rights reserved.
X*/
Xchar pos(char b);
Xchar neg(char b);
$ GOSUB UNPACK_FILE
$ FILE_IS = "SYMTAB.C"
$ CHECKSUM_IS = 22903110
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  Routines to add, remove, modify, and retrieve symbol names and values to
X  and from a symbol table.
X
X  Copyright (c) 1989 by Robert Thomas Chojnacki
X*/
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X
X#define symtab`009`009/* for symtab.h */
X#include "symtab.h"
X
X/*
X  Add a name to the symbol table
X*/
Xsym_add(name, value)
Xchar *name;
Xint value;
X`123
X  int len;
X/*
X  make sure everything is OK
X*/
X  if (sym_count == MAXSYM) `123
X    fprintf(stderr, "sym_add: symbol table full\n");
X    return 1;
X  `125 else if ((len = strlen(name)) > SYMNAMALLO) `123
X    name[SYMNAMALLO-1] = 0;
X    fprintf(stderr, "sym_add: symbol name truncated to '%s'\n", name);
X  `125 else if (sym_findname(value)) `123
X    fprintf(stderr, "sym_add: symbol value already assigned to '%s'\n",
X     sym_findname(value));
X    return 2;
X  `125 else if (!value) `123
X    fprintf(stderr, "sym_add: cannot use value of zero.\n");
X    return 3;
X  `125 else if (sym_findvalue(name)) `123
X    fprintf(stderr, "sym_add: symbol name already assigned to '%08X'\n",
X     sym_findvalue(name));
X    return 4;
X  `125
X/*
X  allocate some buffer space for name
X*/
X  if (!(sym_name[sym_count] = malloc(len))) `123
X    fprintf(stderr, "sym_add: unable to allocate %d bytes\n", len);
X    return 5;
X  `125
X/*
X  insert name and value then leave
X*/
X  strcpy(sym_name[sym_count], name);
X  sym_value[sym_count++] = value;
X  return 0;
X`125
X
X/*
X  Find name by value
X*/
Xchar *sym_findname(value)
Xint value;
X`123
X  int i;
X
X  for (i=0; i<sym_count; i++)
X    if (sym_value[i] == value)
X      return sym_name[i];
X
X  return 0;
X`125
X
X/*
X  Find value by name;
X*/
Xsym_findvalue(name)
Xchar *name;
X`123
X  int i;
X
X  for (i=0; i<sym_count; i++)
X    if (!strcmp(sym_name[i], name))
X      return sym_value[i];
X
X  return 0;
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "SYMTAB.H"
$ CHECKSUM_IS = 1583343193
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  definitions for the symbol table routines
X
X  Copyright (c) 1989 by Robert Thomas Chojnacki
X*/
X#define MAXSYM 512`009`009/* maximum number of symbols in symbol table */
X#define SYMNAMALLO`00932`009/* number of bytes to allocate per symbol name*/
X
Xchar *sym_findname();
X
X#ifdef symtab
X/*
X  pointers to symbol names
X*/
Xchar *sym_name[MAXSYM] = `123
X  "SYS$QIOW",`009`009`009/* 0 */
X  "SYS$QIOW_2",
X  "SYS$QIOW_3",
X  "SYS$CLI",
X  "SYS$ADJSTK",
X  "SYS$ADJWSL",
X  "SYS$ALCDNP",
X  "SYS$ALLOC",
X  "SYS$ASCEFC",
X  "SYS$ASCTIM",
X  "SYS$ASSIGN",
X  "SYS$BINTIM",
X  "SYS$CANCEL",
X  "SYS$CANTIM",
X  "SYS$CANWAK",
X  "SYS$CRMPSC",
X  "SYS$CLRPAR",`009`009`009/* 10 */
X  "SYS$CMEXEC",
X  "SYS$CMKRNL",
X  "SYS$CLREF",
X  "SYS$CNTREG",
X  "SYS$GETPTI",
X  "SYS$CRELOG",
X  "SYS$CREMBX",
X  "SYS$CREPRC",
X  "SYS$CRETVA",
X  "SYS$DACEFC",
X  "SYS$DALLOC",
X  "SYS$DASSGN",
X  "SYS$DCLAST",
X  "SYS$DCLEXH",
X  "SYS$DELLOG",
X  "SYS$DELMBX",`009`009`009/* 20 */
X  "SYS$DELPRC",
X  "SYS$DELTVA",
X  "SYS$DGBLSC",
X  "SYS$DLCDNP",
X  "SYS$DLCEFC",
X  "SYS$UPDSEC",
X  "SYS$SNDERR",
X  "SYS$EXIT",
X  "SYS$EXPREG",
X  "SYS$FAO",
X  "SYS$FAOL",
X  "SYS$FORCEX",
X  "SYS$IMGSTA",
X  "SYS$SNDJBC",
X  "SYS$GETTIM",
X  "SYS$UPDSECW",`009`009/* 30 */
X  "SYS$HIBER",
X  "SYS$IMGACT",
X  "SYS$LCKPAG",
X  "SYS$LKWSET",
X  "SYS$MGBLSC",
X  "SYS$PURGWS",
X  "SYS$NUMTIM",
X  "SYS$SNDOPR",
X  "SYS$QIO",
X  "SYS$READEF",
X  "SYS$RESUME",
X  "SYS$RUNDWN",
X  "SYS$SNDSMB",
X  "SYS$SCHDWK",
X  "SYS$SETAST",
X  "SYS$SETEF",`009`009`009/* 40 */
X  "SYS$SETEXV",
X  "SYS$SETPRN",
X  "SYS$SETPRA",
X  "SYS$SETIMR",
X  "SYS$SETPRI",
X  "SYS$SETPRT",
X  "SYS$SETRWM",
X  "SYS$SETSFM",
X  "SYS$SETSWM",
X  "SYS$SUSPND",
X  "SYS$TRNLOG",
X  "SYS$ULKPAG",
X  "SYS$ULWSET",
X  "SYS$UNWIND",
X  "SYS$WAITFR",
X  "SYS$WAKE",`009`009`009/* 50 */
X  "SYS$WFLAND",
X  "SYS$WFLOR",
X  "SYS$BRDCST",
X  "SYS$DCLCMH",
X  "SYS$SETPFM",
X  "SYS$GETMSG",
X  "SYS$DERLMB",
X  "SYS$CANEXH",
X  "SYS$GETCHN",
X  "SYS$GETDEV",
X  "SYS$GETJPI",
X  "SYS$PUTMSG",
X  "SYS$EXCMSG",
X  "SYS$SNDACC",
X  "SYS$SETIME",
X  "SYS$SETPRV",`009`009`009/* 60 */
X  "SYS$CLRAST",
X  "SYS$GL_ASTRET",
X  "SYS$GL_COMMON",
X  "SYS$SRCHANDLER",
X  "SYS$WAIT_FORM",`009`009/* 64 */
X  "RMS$DELETE",`009`009`009/* 6D */
X  "RMS$FIND",
X  "RMS$FREE",
X  "RMS$GET",`009`009`009/* 70 */
X  "RMS$PUT",
-+-+-+-+-+ End of part 4 +-+-+-+-+-
