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


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

+-+-+-+ Beginning of part 2 +-+-+-+
X`009  for (cmd3 = 0; cmd3 < sizeof(setmode)/4; cmd3++)
X`009    if (!strncmp(arg3, setmode[cmd3], strlen(arg3)))
X`009      break;
X`009  if (cmd3 == sizeof(setmode)/4) `123
X`009    command[0] = -1;
X            comderr("SET MODE", 1, setmode, sizeof(setmode)/4);
X`009    break;
X`009  `125 else `123
X`009    command[2] = cmd3;
X`009  `125
X`009  break;
X/*
X  SET CASE subcommands
X*/
X`009 case C1_CASE:
X`009  for (cmd3 = 0; cmd3 < sizeof(setcase)/4; cmd3++)
X`009    if (!strncmp(arg3, setcase[cmd3], strlen(arg3)))
X`009      break;
X`009  if (cmd3 == sizeof(setcase)/4) `123
X`009    command[0] = -1;
X            comderr("SET CASE", 1, setcase, sizeof(setcase)/4);
X`009      break;
X`009  `125 else `123
X`009    command[2] = cmd3;
X`009  `125
X`009  break;
X`009`125
X      `125
X      break;
X/*
X  SHOW - get sub-commands
X*/
X     case C_SHOW:`009`009/* SHOW */
X      for (cmd2 = 0; cmd2 < sizeof(setshow)/4; cmd2++)
X`009if (!strncmp(arg2, setshow[cmd2], strlen(arg2)))
X`009  break;
X      if (cmd2 == sizeof(setshow)/4) `123
X`009command[0] = -1;
X        comderr("SHOW", 1, setshow, sizeof(setshow)/4);
X      `125 else `123
X`009command[1] = cmd2;
X`009switch(cmd2) `123
X/*
X  SHOW BYTE/WORD/LONG/QUAD/OCTA subcommands
X*/
X`009 case C1_BYTE:
X`009 case C1_WORD:
X`009 case C1_LONG:
X`009 case C1_QUAD:
X`009 case C1_OCTA:
X`009  break;
X/*
X  SHOW MODE subcommands
X*/
X`009 case C1_MODE:
X`009  break;
X/*
X  SHOW CASE subcommands
X*/
X`009 case C1_CASE:
X`009  break;
X`009`125
X      `125
X      break;
X/*
X  GOTO - get address
X*/
X     case C_GOTO:`009`009/* GOTO */
X      if (!sscanf(arg2, "%x", &command[1])) `123
X`009fprintf(stderr, "bad address for GOTO\n");
X        command[1] = 0;
X      `125
X      break;
X/*
X  SYMBOL - symbol table names
X*/
X     case C_SYMBOL:`009`009/* SYMBOL */
X      for (cmd2 = 0; cmd2 < sizeof(symbol)/4; cmd2++)
X`009if (!strncmp(arg2, symbol[cmd2], strlen(arg2)))
X`009  break;
X      if (cmd2 == sizeof(symbol)/4) `123
X`009command[0] = -1;
X        comderr("SYMBOL", 1, symbol, sizeof(symbol)/4);
X      `125 else `123
X`009command[1] = cmd2;
X`009switch(cmd2) `123
X/*
X  SYMBOL DEFINE
X*/
X`009 case C13_DEFINE:
X`009  break;
X/*
X  SYMBOL LIST
X*/
X`009 case C13_LIST:
X`009  break;
X/*
X  SYMBOL REMOVE
X*/
X`009 case C13_REMOVE:
X`009  break;
X`009`125
X      `125
X      break;
X     `125
X   `125 else `123
X    command[0] = -1;
X    return(-1);
X   `125
X#ifdef`009debug
X  fprintf(stderr, "command[0,1,2,3] = %d, %d, %d, %d\n", command[0],
X   command[1], command[2], command[3]);
X#endif
X  return(0);
X`125
X/*
X  command error display routine
X*/
Xcomderr(t1, argno, textlist, textsize)
Xchar *t1;
Xint argno;
Xchar **textlist;
Xint textsize;
X`123
X  int i, linesize=0, newline;
X
X  fprintf(stderr, "Syntax error for %s (argument %d)\n", t1, argno);
X  fprintf(stderr, "Valid arguments are:\n");
X  for (i = 0; i < textsize; i++) `123
X    newline = 0;`032
X    fprintf(stderr, "%s ", textlist[i]);
X    linesize += strlen(textlist[i]) + 1;
X    if (linesize > 65) `123
X      fprintf(stderr, "\n");
X      newline = 1;
X      linesize = 0;
X    `125
X  `125
X  if (!newline)
X    fprintf(stderr, "\n");
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "COMMANDS.H"
$ CHECKSUM_IS = 275280144
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  command definitions
X
X  Copyright (c) 1988 By Robert Thomas Chojnacki, All rights reserved.
X*/
X/*
X  main commands
X*/
X#define`009C_DISASSEMBLE`0090
X#define`009C_SET`009`0091
X#define`009C_SHOW`009`0092
X#define`009C_QUIT`009`0093
X#define`009C_GOTO`009`0094
X#define`009C_SAVE`009`0095
X#define`009C_UNSAVE`0096
X#define`009C_DUMP`009`0097
X#define`009C_STATS`009`0098
X#define`009C_SEARCH`0099
X#define`009C_HEADER`00910
X#define`009C_HELP`009`00911
X#define`009C_WRITE`009`00912
X#define C_SYMBOL`00913
X#define C_EXIT`009`00914
X/*
X  DISASSEMBLE and SET/SHOW BYTE/WORD/LONG/QUAD/OCTA commands
X*/
X#define C0_UNDEFINED`0090
X#define`009C0_INSTRUCTION`0091
X#define`009C0_BYTE`009`0092
X#define`009C0_WORD`009`0093
X#define`009C0_LONG`009`0094
X#define`009C0_QUAD`009`0095
X#define`009C0_OCTA`009`0096
X#define`009C0_F_FLOATING`0097
X#define`009C0_D_FLOATING`0098
X#define`009C0_G_FLOATING`0099
X#define`009C0_H_FLOATING`00910
X#define`009C0_ASCII`00911
X#define`009C0_ASCIC`00912
X#define`009C0_ASCID`00913
X#define`009C0_ASCIZ`00914
X#define`009C0_BLKB`009`00915
X#define`009C0_BLKW`009`00916
X#define`009C0_BLKL`009`00917
X#define`009C0_BLKQ`009`00918
X#define`009C0_BLKO`009`00919
X#define`009C0_ADDRESS`00920
X#define`009C0_MASK`009`00921
X#define`009C0_ENTRY`00922
X#define`009C0_UNTIL`00923
X#define`009C0_ALL`009`00924
X/*
X  DISASSEMBLE UNTIL commands
X*/
X#define`009C0x22_END`0090
X#define`009C0x22_PC`0091
X#define`009C0x22_DATA`0092
X/*
X  SET SHOW commands
X*/
X#define`009C1_BYTE`009`0090
X#define`009C1_MODE`009`0091
X#define`009C1_CASE`009`0092
X#define`009C1_WORD`009`0093
X#define`009C1_LONG`009`0094
X#define`009C1_QUAD`009`0095
X#define`009C1_OCTA`009`0096
X#define`009C1_RANGE`0097
X#define`009C1_LABEL`0098
X#define`009C1_UNLABEL`0099
X/*
X  SET CASE commands
X*/
X#define`009C1x2_LOWER`0090
X#define`009C1x2_UPPER`0091
X/*
X  SET MODE commands
X*/
X#define`009C1x1_BINARY`0090
X#define`009C1x1_OCTAL`0090
X#define`009C1x1_DECIMAL`0090
X#define`009C1x1_HEXADECIMAL 0
X/*
X  SYMBOL commands
X*/
X#define C13_DEFINE`0090
X#define C13_LIST`0091
X#define C13_REMOVE`0092
X/*
X  command strings
X*/
X#ifdef`009commandsfile
Xchar prompt[] = "%08X> ";
Xchar *unmacrocommands[] = `123
X  "DISASSEMBLE",
X  "SET",
X  "SHOW",
X  "QUIT",
X  "GOTO",
X  "SAVE",
X  "UNSAVE",
X  "DUMP",
X  "STATS",
X  "SEARCH",
X  "HEADER",
X  "HELP",
X  "WRITE",
X  "SYMBOL",
X  "EXIT"`125;
Xint sizeof_unmacrocommands=sizeof(unmacrocommands)/4;
Xchar *disassembl[] = `123
X  "UNDEFINED",
X  "INSTRUCTION",
X  "BYTE",
X  "WORD",
X  "LONG",
X  "QUAD",
X  "OCTA",
X  "F_FLOATING",
X  "D_FLOATING",
X  "G_FLOATING",
X  "H_FLOATING",
X  "ASCII",
X  "ASCIC",
X  "ASCID",
X  "ASCIZ",
X  "BLKB",
X  "BLKW",
X  "BLKL",
X  "BLKQ",
X  "BLKO",
X  "ADDRESS",
X  "MASK",
X  "ENTRY",
X  "UNTIL",
X  "ALL"`125;
Xchar *disassembleuntil[] = `123
X  "END",
X  "PC",`009`009/* DISASSEMBLE UNTIL PC x */
X  "DATA"`125;`009/* Disassembles source until bytetype = data */
Xchar *setshow[] = `123
X  "BYTE",
X  "MODE",
X  "CASE",
X  "WORD",
X  "LONG",
X  "QUAD",
X  "OCTA",
X  "RANGE",
X  "LABEL",
X  "UNLABEL"`125;
Xchar *setshowbyte[] = `123
X  "UNDEFINED",
X  "INSTRUCTION",
X  "BYTE",
X  "WORD",
X  "LONG",
X  "QUAD",
X  "OCTA",
X  "F_FLOATING",
X  "D_FLOATING",
X  "G_FLOATING",
X  "H_FLOATING",
X  "ASCII",
X  "ASCIC",
X  "ASCID",
X  "ASCIZ",
X  "BLKB",
X  "BLKW",
X  "BLKL",
X  "BLKQ",
X  "BLKO",
X  "ADDRESS",
X  "MASK",
X  "ENTRY"`125;
Xchar *setcase[] = `123
X  "LOWER",
X  "UPPER"`125;
Xchar *setmode[] = `123
X  "BINARY",
X  "OCTAL",
X  "DECIMAL",
X  "HEXADECIMAL"`125;
Xchar *symbol[] = `123
X  "DEFINE",
X  "LIST",
X  "REMOVE"`125;
Xchar arg1[128], arg2[128], arg3[128], arg4[128];
X#else
Xextern char prompt[];
Xextern char *unmacrocommands[];
Xextern int sizeof_unmacrocommands;
Xextern char *disassembl[];
Xextern char *disassembleuntil[];
Xextern char *setshow[];
Xextern char *setshowbyte[];
Xextern char *setcase[];
Xextern char *setmode[];
Xextern char *symbol[];
Xextern char arg1[], arg2[], arg3[], arg4[];
X#endif
$ GOSUB UNPACK_FILE
$ FILE_IS = "DEBUG.H"
$ CHECKSUM_IS = 3879806
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  Remove the following comment to display debug messages
X
X  Copyright (c) 1988 By Robert Thomas Chojnacki, All rights reserved.
X*/
X/*#define`009debug*/
X#ifdef`009debug
X#define`009debmsg(a)`009fprintf(stderr, a);
X#else
X#define`009debmsg(a)`009;
X#endif
$ GOSUB UNPACK_FILE
$ FILE_IS = "DISASSEMBLE.C"
$ CHECKSUM_IS = 942420674
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  disassemble a line
X
X  Copyright (c) 1988 By Robert Thomas Chojnacki, All rights reserved.
X*/
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include "unmacro.h"
X#include "commands.h"
X#include "getdata.h"
X#include "posneg.h"
X#include "debug.h"
Xdisassemble()
X`123
X  char line[16], altline[16], arg_line[16];
X  int i, args, alt, mode, literal_type=0;
X  int opcode, operand, op_ref, op_type, pre_pc;
X  int address;
X  short int casedisp;
X  debmsg("<disassemble>");
X/*
X  disassemble instruction op-code
X*/
X  pre_pc = pc;
X  opcode = getbyte();
X  op_type = i_type(opcode, &op_ref);
X  args = instructions(opcode, line, &alt, altline);
X  operand = getbyte() & 0xff;
X  printf("\t");
X  if ((alt == 1) && (operand == 0xfd)) `123
X    printf("%s", altline);
X  `125 else if ((alt == 3) && (operand == 0xff)) `123
X    printf("%s", altline);
X  `125 else `123
X    printf("%s", line);
X  `125
X/*
X  disassemble instruction operands
X*/
X  if (args > 0) `123
X    mode = -1;
X    printf("\t");
X    for (i = 0; i < args; i++) `123
X      if ((i+1 == op_ref) && (op_type == 1)) `123
X`009displacements(operand, 1, arg_line);
X      `125 else if ((i+1 == op_ref) && (op_type == 2)) `123
X`009masks(operand, arg_line);
X      `125 else if ((i+1 == op_ref) && (op_type == 4)) `123
X`009displacements(operand, 2, arg_line);
X      `125 else if ((i == 1) && (op_type == 5)) `123
X        mode = operands(operand, literal_type, arg_line);
X`009if (mode == 14) `123
X`009  pc -= 4;
X`009  address = getlong() + pc;
X`009  if ((address >= base) && (address <= top))
X`009    bytetype[address-base] = C0_ENTRY;
X`009`125 else if (mode == 9) `123
X`009  pc -= 4;
X`009  address = getlong();
X`009  if (sym_findname(address))
X`009    sprintf(arg_line, "@#G`094%s", sym_findname(address));
X`009`125
X      `125 else `123
X        mode = operands(operand, literal_type, arg_line);
X`009if (mode == 4)
X`009  args++;
X      `125
X      printf("%s", arg_line);
X      if (i < args-1) `123
X        if (mode != 4)
X    `009  printf(",");
X      operand = getbyte() & 0xff;
X      `125
X    `125
X    printf("\t\t;%X\n", pre_pc);
X/*
X  handle CASE instructions
X*/
X    if (op_type == 3) `123
X      pre_pc = pc;
X      limit = lastliteral;
X      printf("L%X:", pre_pc);
X      for (i = 0; i <= limit; i++) `123
X`009casedisp = getword();
X`009printf("\t.word\tL%X - L%X\n", casedisp + pre_pc, pre_pc);
X`009bytetype[casedisp+pre_pc-base] = -C0_INSTRUCTION;
X      `125
X    `125
X  `125 else if (args == 0) `123
X    --pc;
X    printf("\t\t;%X\n", pre_pc);
X/*
X  Reserved instruction handling
X*/
X  `125 else `123
X    --pc;
X    printf(" operand at %X\n", pre_pc);
X  `125
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "DISPLACEMENTS.C"
$ CHECKSUM_IS = 1209885336
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  Converts an operand to a ascii displacement
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 "getdata.h"
X#include "debug.h"
Xdisplacements(operand, size, line)
Xchar operand;
Xint size;
Xchar *line;
X`123
X  union `123
X    char b[4];
X    int word;
X  `125 b;
X
X  debmsg("<displacements>");
X  if (size == 1) `123
X    sprintf(line, "L%X", operand + pc);
X    if (operand+pc <= top) `123
X      bytetype[operand+pc-base] = -C0_INSTRUCTION;
X    `125
X  `125 else `123
X    b.word = 0;
X    b.b[0] = operand;
X    b.b[1] = getbyte();
X    sprintf(line, "L%X", b.word + pc);
X    if (b.word+pc <= top) `123
X      bytetype[b.word+pc-base] = -C0_INSTRUCTION;
X    `125
X  `125
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "GETDATA.C"
$ CHECKSUM_IS = 1142072115
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  Copyright (c) 1988 by Robert Thomas Chojnacki, All rights reserved.
X*/
X/*
X  GetByte returns the next byte from the file
X*/
X#include "unmacro.h"
X#include "getdata.h"
X#include "debug.h"
X#include <stdio.h>
Xstatic int open=0;
Xchar getbyte()
X`123
X  debmsg("<getbyte>");
X/* get a byte */
X#ifdef`009debug
X  fprintf(stderr, " val, pc = %02X, %08X\n", image[pc-base] & 0xff, pc);
X#endif
X  if (pc <= top) `123
X    pc++;
X    return(image[pc-base-1]);
X  `125 else `123
X    fprintf(stderr, "past end of image\n");
X    return(-1);
X  `125
X`125
X/*
X  read in a word
X*/
Xshort int getword()
X`123
X  union `123
X    char b[4];
X    int word;
X  `125 b;
X
X  debmsg("<getword>");
X  b.word = 0;
X  b.b[0] = getbyte();
X  b.b[1] = getbyte();
X  return(b.word);
X`125
X/*
X  read in a long word
X*/
Xgetlong()
X`123
X  union `123
X    char b[4];
X    int longword;
X  `125 b;
X
X  debmsg("<getlong>");
X  b.b[0] = getbyte();
X  b.b[1] = getbyte();
X  b.b[2] = getbyte();
X  b.b[3] = getbyte();
X  return(b.longword);
X`125
$ GOSUB UNPACK_FILE
$ FILE_IS = "GETDATA.H"
$ CHECKSUM_IS = 846476409
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  get data definitions
X*/
Xchar getbyte();
Xshort int getword();
$ GOSUB UNPACK_FILE
$ FILE_IS = "CHECK_PORTABILITY.COM"
$ CHECKSUM_IS = 1865765225
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$ CCP := CC/NoObject/Standard=Portable
X$ CCP COMMANDS
X$ CCP DISASSEMBLE
X$ CCP DISPLACEMENTS
X$ CCP GETDATA
X$ CCP HEADER
X$ CCP INSTRUCTIONS
X$ CCP I_TYPE
X$ CCP MASKS
X$ CCP OPERANDS
X$ CCP POSNEG
X$ CCP SYMTAB
X$ CCP UNDATA
X$ CCP UNMACRO
X$ Exit
$ GOSUB UNPACK_FILE
$ FILE_IS = "HEADER.C"
$ CHECKSUM_IS = 354597488
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X  Get header information
X
X  Copyright (c) 1989 By Robert Thomas Chojnacki
X*/
X#include <stdio.h>
X#include <stdlib.h>
X#define header_main
X#include "header.h"
X
Xextern FILE *sfp;
X
Xheader()
X`123
X  char block[512];
X  int i, j;
X/*
X read in the first block
X*/
X  if (image_header == 'y') `123
X    hb[0] = malloc(512);
X    fread(hb[0], 512, 1, sfp);
X/*
X  Fixup portion of header
X*/
X    h_size = ghw(0);
X    b_offset = ghw(2);
X    c_offset = ghw(4);
X    d_offset = ghw(6);
X    e_offset = ghw(8);
X    h_majid = ghw(12);
X    h_minid = ghw(14);
X    h_blocks = hb[0][16] & 0xff;
X    h_itype = hb[0][17] & 0xff;
X    h_rpriv[0] = ghl(20);
X    h_rpriv[1] = ghl(24);
X    h_iochans = ghw(28);
X    h_iosegpag = ghw(30);
X    h_iflags = ghl(32);
X    h_gsid = ghl(36);
X    h_sysver = ghl(40);
X/*
X  Transfer address array
X*/
X    h_transfer1 = ghl(b_offset);
X    h_transfer2 = ghl(b_offset+4);
X    h_transfer3 = ghl(b_offset+8);
X    if (h_transfer1)
X      fprintf(stderr, "First transfer address = %08X\n", h_transfer1);
X    if (h_transfer2)
X      fprintf(stderr, "Second transfer address = %08X\n", h_transfer2);
X    if (h_transfer3)
X      fprintf(stderr, "Third transfer address = %08X\n", h_transfer3);
X/*
X  read in the rest of the header blocks
X*/
X    if (h_blocks != 1) `123
X      fprintf(stderr, "more than one image header block\n");
X      for (i=1;i<h_blocks;i++) `123
X        if ((hb[i] = malloc(512)) && (i < MAXHB)) `123
-+-+-+-+-+ End of part 2 +-+-+-+-+-
