home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Boot_Images / 2.11_on_rl02 / pdpsim.tz / pdpsim / pdp18b_sys.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-29  |  21.2 KB  |  649 lines

  1. /* pdp18b_sys.c: 18b PDP's simulator interface
  2.  
  3.    Copyright (c) 1993, 1994, 1995, 1996, Robert M Supnik,
  4.    Digital Equipment Corporation
  5.    All rights reserved
  6. */
  7.  
  8. #include "pdp18b_defs.h"
  9. #include <ctype.h>
  10.  
  11. extern DEVICE cpu_dev;
  12. extern DEVICE ptr_dev, ptp_dev;
  13. extern DEVICE tti_dev, tto_dev;
  14. extern DEVICE clk_dev;
  15. extern DEVICE lpt_dev;
  16. #if defined (DRM)
  17. extern DEVICE drm_dev;
  18. #endif
  19. #if defined (RF)
  20. extern DEVICE rf_dev;
  21. #endif
  22. #if defined (RP)
  23. extern DEVICE rp_dev;
  24. #endif
  25. #if defined (MTA)
  26. extern DEVICE mt_dev;
  27. #endif
  28. extern REG cpu_reg[];
  29. extern unsigned int M[];
  30. extern int memm;
  31. extern char *get_glyph (char *cptr, char *gbuf, char term);
  32. extern int get_unum (char *cptr, int radix, unsigned int max,
  33.     unsigned int *val);
  34.  
  35. /* SCP data structures and interface routines
  36.  
  37.    sim_name        simulator name string
  38.    sim_PC        pointer to saved PC register descriptor
  39.    sim_emax        number of words for examine
  40.    sim_devices        array of pointers to simulated devices
  41.    sim_stop_messages    array of pointers to stop messages
  42.    sim_load        binary loader
  43. */
  44.  
  45. #if defined (PDP4)
  46. char sim_name[] = "PDP-4";
  47. #elif defined (PDP7)
  48. char sim_name[] = "PDP-7";
  49. #elif defined (PDP9)
  50. char sim_name[] = "PDP-9";
  51. #elif defined (PDP15)
  52. char sim_name[] = "PDP-15";
  53. #endif
  54.  
  55. REG *sim_PC = &cpu_reg[0];
  56.  
  57. int sim_emax = 3;
  58.  
  59. DEVICE *sim_devices[] = { &cpu_dev,
  60.     &ptr_dev, &ptp_dev, &tti_dev, &tto_dev,
  61.     &clk_dev, &lpt_dev,
  62. #if defined (DRM)
  63.     &drm_dev,
  64. #endif
  65. #if defined (RF)
  66.     &rf_dev,
  67. #endif
  68. #if defined (RP)
  69.     &rp_dev,
  70. #endif
  71. #if defined (MTA)
  72.     &mt_dev,
  73. #endif
  74.     NULL };
  75.  
  76. const char *sim_stop_messages[] = {
  77.     "Unknown error",
  78.     "Undefined instruction",
  79.     "HALT instruction",
  80.     "Breakpoint",
  81.     "Nested XCT's"  };
  82.  
  83. /* Binary loader
  84.  
  85.    Not implemented: format not documented
  86. */
  87.  
  88. int sim_load (FILE *fileref)
  89. {
  90. return SCPE_FMT;                    /* error */
  91. }
  92.  
  93. /* Symbol tables */
  94.  
  95. #define I_V_FL        18                /* inst class */
  96. #define    I_M_FL        017                /* class mask */
  97. #define I_V_DC        22                /* default count */
  98. #define I_V_NPN        0                /* no operand */
  99. #define I_V_NPI        1                /* no operand IOT */
  100. #define I_V_IOT        2                /* IOT */
  101. #define I_V_MRF        3                /* memory reference */
  102. #define I_V_OPR        4                /* OPR */
  103. #define I_V_LAW        5                /* LAW */
  104. #define I_V_XR        6                /* index */
  105. #define I_V_XR9        7                /* index literal */
  106. #define I_V_EST        8                /* EAE setup */
  107. #define I_V_ESH        9                /* EAE shift */
  108. #define I_V_EMD        10                /* EAE mul-div */
  109. #define I_NPN        (I_V_NPN << I_V_FL)        /* no operand */
  110. #define I_NPI        (I_V_NPI << I_V_FL)        /* no operand IOT */
  111. #define I_IOT        (I_V_IOT << I_V_FL)        /* IOT */
  112. #define I_MRF        (I_V_MRF << I_V_FL)        /* memory reference */
  113. #define I_OPR        (I_V_OPR << I_V_FL)        /* OPR */
  114. #define I_LAW        (I_V_LAW << I_V_FL)        /* LAW */
  115. #define I_XR        (I_V_XR << I_V_FL)        /* index */
  116. #define I_XR9        (I_V_XR9 << I_V_FL)        /* index literal */
  117. #define I_EST        (I_V_EST << I_V_FL)        /* EAE setup */
  118. #define I_ESH        (I_V_ESH << I_V_FL)        /* EAE shift */
  119. #define I_EMD        (I_V_EMD << I_V_FL)        /* EAE mul-div */
  120. #define MD(x) ((I_EMD) + ((x) << I_V_DC))
  121.  
  122. static const int masks[] = {
  123.  0777777, 0777767, 0740000, 0740000,
  124.  0763730, 0760000, 0777000, 0777000,
  125.  0740700, 0760700, 0777700 };
  126.  
  127. static const char *opcode[] = {
  128.  "CAL", "DAC", "JMS", "DZM",                /* mem refs */
  129.  "LAC", "XOR", "ADD", "TAD",
  130.  "XCT", "ISZ", "AND", "SAD",
  131.  "JMP", "LAW",
  132.  
  133.  "LACQ", "LACS", "ABS", "GSM", "LMQ",            /* EAE */
  134.  "MUL", "MULS", "DIV", "DIVS",
  135.  "IDIV", "IDIVS", "FRDIV", "FRDIVS",
  136.  "NORM", "NORMS",
  137.  "MUY", "LLK MUY", "DVI", "LLK DVI",
  138.  "NMI", "NMIS", "LRS", "LRSS",
  139.  "LLS", "LLSS", "ALS", "ALSS",
  140.  "EAE-setup", "EAE",                    /* setup, general */
  141.  
  142.  "CLSF", "IOF", "ION", "CLOF", "CLON",            /* standard IO devs */
  143.  "RSF", "RRB", "RCF", "RSA", "RSB",
  144.  "PSF", "PCF", "PSA", "PSB", "PLS",
  145.  "KSF", "KRB", "KCF", "IORS", "IOOS",
  146.  "TSF", "TCF", "TPC", "TLS",
  147. #if defined (TYPE62)                    /* PDP-4 LPT */
  148.  "LPSF", "LPCF", "LPLD", "LPSE",
  149.  "LSSF", "LSCF", "LSPR",
  150. #elif defined (TYPE647)                    /* PDP-7, PDP-9 LPT */
  151.  "LPSF", "LPCB", "LPCD", "LPCD", "LPCD",
  152.  "LPL2", "LPLD", "LPL1",
  153.  "LPEF", "LPCF", "LPCF", "LPCF", "LPCF",
  154.  "LPPB", "LPLS", "LPPS",
  155. #elif defined (LP15)
  156.  "LPSF", "LPPM", "LPP1", "LPDI",
  157.  "LPRS", "LPOS", "LPEI", "LPCD", "LPCF",
  158. #endif
  159. #if defined (DRM)                    /* drum */
  160.  "DRLR", "DRLW", "DRSS", "DRCS",
  161.  "DRSF", "DRSN", "DRCF",
  162.  "DRLCRD", "DRLCWR", "DRLBLK", "DRCONT",
  163.  "DRSF", "DRSOK", "DRCF",
  164. #endif
  165. #if defined (RF)                    /* RF09 */
  166.  "DSSF", "DSCC", "DSCF",
  167.  "DRBR", "DRAL", "DSFX", "DRAH",
  168.  "DLBR", "DLAL", "DSCN", "DLAH",
  169.  "DLOK",         "DSCD", "DSRS",
  170.  "DGHS", "DGSS",
  171. #endif
  172. #if defined (RP)
  173.  "DPSF", "DPSA", "DPSJ", "DPSE",
  174.  "DPRSA", "DPOSA", "DPRSB", "DPOSB",
  175.  "DPRM", "DPOM",
  176.  "DPLA", "DPCS", "DPCA", "DPWC",
  177.  "DPLM", "DPEM", "DPSN",
  178.  "DPRU", "DPOU", "DPRA", "DPOA",
  179.  "DPRC", "DPOC", "DPRW", "DPOW",
  180.  "DPCF", "DPLZ", "DPCN", "DPLO", "DPLF",
  181. #endif
  182. #if defined (MTA)                    /* TC59 */
  183.  "MTTR", "MTCR", "MTSF", "MTRC", "MTAF",
  184.  "MTRS", "MTGO", "MTCM", "MTLC",
  185. #endif
  186. #if defined (PDP7)
  187.  "ITON", "TTS", "SKP7", "CAF",
  188.  "SEM", "EEM", "EMIR", "LEM",
  189. #elif defined (PDP9)
  190.  "PFSF", "TTS", "SKP7", "CAF",
  191.  "DBR", "SEM", "EEM", "LEM",
  192.  "MPSK", "MPSNE", "MPCV", "MPEU",
  193.  "MPLD", "MPCNE",
  194.  "LPDI", "LPEI",
  195. #elif defined (PDP15)
  196.  "PFSF", "TTS", "SPCO", "CAF",
  197.  "DBR", "SKP15", "SBA", "DBA", "EBA",
  198.  "PAX", "PAL", "AAC", "PXA",
  199.  "AXS", "PXL", "PLA", "PLX",
  200.  "CLX", "CLL", "AXR",
  201. #endif
  202.  "IOT",                            /* general */
  203.  
  204.  "NOP", "STL", "RCL", "RCR",
  205.  "CLC", "LAS", "GLK",
  206.  "OPR", "SMA", "SZA", "SZA SMA",
  207.  "SNL", "SNL SMA", "SNL SZA", "SNL SZA SMA",
  208.  "SKP", "SPA", "SNA", "SNA SPA",
  209.  "SZL", "SZL SPA", "SZL SNA", "SZL SZA SPA",
  210.  "RAL", "SMA RAL", "SZA RAL", "SZA SMA RAL",
  211.  "SNL RAL", "SNL SMA RAL", "SNL SZA RAL", "SNL SZA SMA RAL",
  212.  "SKP RAL", "SPA RAL", "SNA RAL", "SNA SPA RAL",
  213.  "SZL RAL", "SZL SPA RAL", "SZL SNA RAL", "SZL SZA SPA RAL",
  214.  "RAR", "SMA RAR", "SZA RAR", "SZA SMA RAR",
  215.  "SNL RAR", "SNL SMA RAR", "SNL SZA RAR", "SNL SZA SMA RAR",
  216.  "SKP RAR", "SPA RAR", "SNA RAR", "SNA SPA RAR",
  217.  "SZL RAR", "SZL SPA RAR", "SZL SNA RAR", "SZL SZA SPA RAR",
  218. #if defined (PDP15)
  219.  "IAC", "SMA IAC", "SZA IAC", "SZA SMA IAC",
  220.  "SNL IAC", "SNL SMA IAC", "SNL SZA IAC", "SNL SZA SMA IAC",
  221.  "SKP IAC", "SPA IAC", "SNA IAC", "SNA SPA IAC",
  222.  "SZL IAC", "SZL SPA IAC", "SZL SNA IAC", "SZL SZA SPA IAC",
  223. #else
  224.  "RAL RAR", "SMA RAL RAR", "SZA RAL RAR", "SZA SMA RAL RAR",
  225.  "SNL RAL RAR", "SNL SMA RAL RAR", "SNL SZA RAL RAR", "SNL SZA SMA RAL RAR",
  226.  "SKP RAL RAR", "SPA RAL RAR", "SNA RAL RAR", "SNA SPA RAL RAR",
  227.  "SZL RAL RAR", "SZL SPA RAL RAR", "SZL SNA RAL RAR", "SZL SZA SPA RAL RAR",
  228. #endif
  229.  "RTWO", "SMA RTWO", "SZA RTWO", "SZA SMA RTWO",
  230.  "SNL RTWO", "SNL SMA RTWO", "SNL SZA RTWO", "SNL SZA SMA RTWO",
  231.  "SKP RTWO", "SPA RTWO", "SNA RTWO", "SNA SPA RTWO",
  232.  "SZL RTWO", "SZL SPA RTWO", "SZL SNA RTWO", "SZL SZA SPA RTWO",
  233.  "RTL", "SMA RTL", "SZA RTL", "SZA SMA RTL",
  234.  "SNL RTL", "SNL SMA RTL", "SNL SZA RTL", "SNL SZA SMA RTL",
  235.  "SKP RTL", "SPA RTL", "SNA RTL", "SNA SPA RTL",
  236.  "SZL RTL", "SZL SPA RTL", "SZL SNA RTL", "SZL SZA SPA RTL",
  237.  "RTR", "SMA RTR", "SZA RTR", "SZA SMA RTR",
  238.  "SNL RTR", "SNL SMA RTR", "SNL SZA RTR", "SNL SZA SMA RTR",
  239.  "SKP RTR", "SPA RTR", "SNA RTR", "SNA SPA RTR",
  240.  "SZL RTR", "SZL SPA RTR", "SZL SNA RTR", "SZL SZA SPA RTR",
  241. #if defined (PDP15)
  242.  "BSW", "SMA BSW", "SZA BSW", "SZA SMA BSW",
  243.  "SNL BSW", "SNL SMA BSW", "SNL SZA BSW", "SNL SZA SMA BSW",
  244.  "SKP BSW", "SPA BSW", "SNA BSW", "SNA SPA BSW",
  245.  "SZL BSW", "SZL SPA BSW", "SZL SNA BSW", "SZL SZA SPA BSW",
  246. #else
  247.  "RTL RTR", "SMA RTL RTR", "SZA RTL RTR", "SZA SMA RTL RTR",
  248.  "SNL RTL RTR", "SNL SMA RTL RTR", "SNL SZA RTL RTR", "SNL SZA SMA RTL RTR",
  249.  "SKP RTL RTR", "SPA RTL RTR", "SNA RTL RTR", "SNA SPA RTL RTR",
  250.  "SZL RTL RTR", "SZL SPA RTL RTR", "SZL SNA RTL RTR", "SZL SZA SPA RTL RTR",
  251. #endif
  252.  
  253.  "LLK", "CLQ", "LSN", "OACQ", "ECLA",            /* encode only masks */
  254.  "CMQ", "OMQ", "OSC", 
  255.  "CLA", "CLL", "CML", "CMA",
  256.  "OAS", "HLT",
  257.   NULL  };
  258.  
  259. static const int opc_val[] = {
  260.  0000000+I_MRF, 0040000+I_MRF, 0100000+I_MRF, 0140000+I_MRF,
  261.  0200000+I_MRF, 0240000+I_MRF, 0300000+I_MRF, 0340000+I_MRF,
  262.  0400000+I_MRF, 0440000+I_MRF, 0500000+I_MRF, 0540000+I_MRF,
  263.  0600000+I_MRF, 0760000+I_LAW,
  264.  
  265.  0641002+I_NPN, 0641001+I_NPN, 0644000+I_NPN, 0664000+I_NPN, 0652000+I_NPN,
  266.  0653100+MD(022), 0657100+MD(022), 0640300+MD(023), 0644300+MD(023),
  267.  0653300+MD(023), 0657300+MD(023), 0650300+MD(023), 0654300+MD(023),
  268.  0640400+MD(044), 0660400+MD(044),
  269.  0640100+I_ESH, 0660100+I_ESH, 0640300+I_ESH, 0660300+I_ESH,
  270.  0640400+I_ESH, 0660400+I_ESH, 0640500+I_ESH, 0660500+I_ESH,
  271.  0640600+I_ESH, 0660600+I_ESH, 0640700+I_ESH, 0660700+I_ESH,
  272.  0640000+I_EST, 0640000+I_IOT, 
  273.  
  274.  0700001+I_NPI, 0700002+I_NPI, 0700042+I_NPI, 0700004+I_NPI, 0700044+I_NPI,
  275.  0700101+I_NPI, 0700112+I_NPN, 0700102+I_NPI, 0700104+I_NPI, 0700144+I_NPI,
  276.  0700201+I_NPI, 0700202+I_NPI, 0700204+I_NPI, 0700244+I_NPI, 0700206+I_NPI,
  277.  0700301+I_NPI, 0700312+I_NPN, 0700302+I_NPI, 0700314+I_NPN, 0700304+I_NPI,
  278.  0700401+I_NPI, 0700402+I_NPI, 0700404+I_NPI, 0700406+I_NPI,
  279. #if defined (TYPE62)
  280.  0706501+I_NPI, 0706502+I_NPI, 0706542+I_NPI, 0706506+I_NPI,
  281.  0706601+I_NPI, 0706602+I_NPI, 0706606+I_NPI,
  282. #elif defined (TYPE647)
  283.  0706501+I_NPI, 0706502+I_NPI, 0706522+I_NPI, 0706542+I_NPI, 0706562+I_NPI,
  284.  0706526+I_NPI, 0706546+I_NPI, 0706566+I_NPI,
  285.  0706601+I_NPI, 0706602+I_NPI, 0706622+I_NPI, 0706642+I_NPI, 0706662+I_NPI, 
  286.  0706606+I_NPI, 0706626+I_NPI, 0706646+I_NPI,
  287. #elif defined (LP15)
  288.  0706501+I_NPI, 0706521+I_NPI, 0706541+I_NPI, 0706561+I_NPI,
  289.  0706552+I_NPN, 0706542+I_NPI, 0706544+I_NPI, 0706621+I_NPI, 0706641+I_NPI,
  290. #endif
  291. #if defined (DRM)
  292.  0706006+I_NPI, 0706046+I_NPI, 0706106+I_NPI, 0706204+I_NPI,
  293.  0706101+I_NPI, 0706201+I_NPI, 0706102+I_NPI,
  294.  0706006+I_NPI, 0706046+I_NPI, 0706106+I_NPI, 0706204+I_NPI,
  295.  0706101+I_NPI, 0706201+I_NPI, 0706102+I_NPI,
  296. #endif
  297. #if defined (RF)
  298.  0707001+I_NPI, 0707021+I_NPI, 0707041+I_NPI,
  299.  0707002+I_NPI, 0707022+I_NPI, 0707042+I_NPI, 0707062+I_NPI,
  300.  0707004+I_NPI, 0707024+I_NPI, 0707044+I_NPI, 0707064+I_NPI,
  301.  0707202+I_NPI,                0707242+I_NPI, 0707262+I_NPI,
  302.  0707204+I_NPI, 0707224+I_NPI,
  303. #endif
  304. #if defined (RP)
  305.  0706301+I_NPI, 0706321+I_NPI, 0706341+I_NPI, 0706361+I_NPI,
  306.  0706312+I_NPN, 0706302+I_NPI, 0706332+I_NPN, 0706322+I_NPI, 
  307.  0706342+I_NPN, 0706352+I_NPI,
  308.  0706304+I_NPI, 0706324+I_NPI, 0706344+I_NPI, 0706364+I_NPI,
  309.  0706411+I_NPN, 0706401+I_NPI, 0706421+I_NPI,
  310.  0706412+I_NPN, 0706402+I_NPI, 0706432+I_NPN, 0706422+I_NPI, 
  311.  0706452+I_NPN, 0706442+I_NPI, 0706472+I_NPN, 0706462+I_NPI, 
  312.  0706404+I_NPI, 0706424+I_NPI, 0706454+I_NPN, 0706444+I_NPI, 0706464+I_NPI,
  313. #endif 
  314. #if defined (MTA)
  315.  0707301+I_NPI, 0707321+I_NPI, 0707341+I_NPI, 0707312+I_NPN, 0707322+I_NPI,
  316.  0707352+I_NPN, 0707304+I_NPI, 0707324+I_NPI, 0707326+I_NPI, 
  317. #endif
  318. #if defined (PDP7)
  319.  0703201+I_NPI, 0703301+I_NPI, 0703341+I_NPI, 0703302+I_NPI,
  320.  0707701+I_NPI, 0707702+I_NPI, 0707742+I_NPI, 0707704+I_NPI,
  321. #elif defined (PDP9)
  322.  0700062+I_NPI, 0703301+I_NPI, 0703341+I_NPI, 0703302+I_NPI,
  323.  0703344+I_NPI, 0707701+I_NPI, 0707702+I_NPI, 0707704+I_NPI,
  324.  0701701+I_NPI, 0701741+I_NPI, 0701702+I_NPI, 0701742+I_NPI,
  325.  0701704+I_NPI, 0701644+I_NPI,
  326.  0706504+I_NPI, 0706604+I_NPI,
  327. #elif defined (PDP15)
  328.  0700062+I_NPI, 0703301+I_NPI, 0703341+I_NPI, 0703302+I_NPI,
  329.  0703344+I_NPI, 0707741+I_NPI, 0707761+I_NPI, 0707762+I_NPI, 0707764+I_NPI,
  330.  0721000+I_XR, 0722000+I_XR, 0723000+I_XR9, 0724000+I_XR,
  331.  0725000+I_XR9, 0726000+I_XR, 0730000+I_XR, 0731000+I_XR,
  332.  0735000+I_XR, 0736000+I_XR, 0737000+I_XR9,
  333. #endif
  334.  0700000+I_IOT,
  335.  
  336.  0740000+I_NPN, 0744002+I_NPN, 0744010+I_NPN, 0744020+I_NPN,
  337.  0750001+I_NPN, 0750004+I_NPN, 0750010+I_NPN,
  338.  0740000+I_OPR, 0740100+I_OPR, 0740200+I_OPR, 0740300+I_OPR,
  339.  0740400+I_OPR, 0740500+I_OPR, 0740600+I_OPR, 0740700+I_OPR,
  340.  0741000+I_OPR, 0741100+I_OPR, 0741200+I_OPR, 0741300+I_OPR,
  341.  0741400+I_OPR, 0741500+I_OPR, 0741600+I_OPR, 0741700+I_OPR,
  342.  0740010+I_OPR, 0740110+I_OPR, 0740210+I_OPR, 0740310+I_OPR,
  343.  0740410+I_OPR, 0740510+I_OPR, 0740610+I_OPR, 0740710+I_OPR,
  344.  0741010+I_OPR, 0741110+I_OPR, 0741210+I_OPR, 0741310+I_OPR,
  345.  0741410+I_OPR, 0741510+I_OPR, 0741610+I_OPR, 0741710+I_OPR,
  346.  0740020+I_OPR, 0740120+I_OPR, 0740220+I_OPR, 0740320+I_OPR,
  347.  0740420+I_OPR, 0740520+I_OPR, 0740620+I_OPR, 0740720+I_OPR,
  348.  0741020+I_OPR, 0741120+I_OPR, 0741220+I_OPR, 0741320+I_OPR,
  349.  0741420+I_OPR, 0741520+I_OPR, 0741620+I_OPR, 0741720+I_OPR,
  350.  0740030+I_OPR, 0740130+I_OPR, 0740230+I_OPR, 0740330+I_OPR,
  351.  0740430+I_OPR, 0740530+I_OPR, 0740630+I_OPR, 0740730+I_OPR,
  352.  0741030+I_OPR, 0741130+I_OPR, 0741230+I_OPR, 0741330+I_OPR,
  353.  0741430+I_OPR, 0741530+I_OPR, 0741630+I_OPR, 0741730+I_OPR,
  354.  0742000+I_OPR, 0742100+I_OPR, 0742200+I_OPR, 0742300+I_OPR,
  355.  0742400+I_OPR, 0742500+I_OPR, 0742600+I_OPR, 0742700+I_OPR,
  356.  0743000+I_OPR, 0743100+I_OPR, 0743200+I_OPR, 0743300+I_OPR,
  357.  0743400+I_OPR, 0743500+I_OPR, 0743600+I_OPR, 0743700+I_OPR,
  358.  0742010+I_OPR, 0742110+I_OPR, 0742210+I_OPR, 0742310+I_OPR,
  359.  0742410+I_OPR, 0742510+I_OPR, 0742610+I_OPR, 0742710+I_OPR,
  360.  0743010+I_OPR, 0743110+I_OPR, 0743210+I_OPR, 0743310+I_OPR,
  361.  0743410+I_OPR, 0743510+I_OPR, 0743610+I_OPR, 0743710+I_OPR,
  362.  0742020+I_OPR, 0742120+I_OPR, 0742220+I_OPR, 0742320+I_OPR,
  363.  0742420+I_OPR, 0742520+I_OPR, 0742620+I_OPR, 0742720+I_OPR,
  364.  0743020+I_OPR, 0743120+I_OPR, 0743220+I_OPR, 0743320+I_OPR,
  365.  0743420+I_OPR, 0743520+I_OPR, 0743620+I_OPR, 0743720+I_OPR,
  366.  0742030+I_OPR, 0742130+I_OPR, 0742230+I_OPR, 0742330+I_OPR,
  367.  0742430+I_OPR, 0742530+I_OPR, 0742630+I_OPR, 0742730+I_OPR,
  368.  0743030+I_OPR, 0743130+I_OPR, 0743230+I_OPR, 0743330+I_OPR,
  369.  0743430+I_OPR, 0743530+I_OPR, 0743630+I_OPR, 0743730+I_OPR,
  370.  
  371.  0660000+I_EST, 0650000+I_EST, 0644000+I_EST, 0642000+I_EST, 0641000+I_EST,
  372.  0640004+I_EST, 0640002+I_EST, 0640001+I_EST,
  373.  0750000+I_OPR, 0744000+I_OPR, 0740002+I_OPR, 0740001+I_OPR,
  374.  0740004+I_OPR, 0740040+I_OPR,
  375.  -1 };
  376.  
  377. /* Operate or EAE decode
  378.  
  379.    Inputs:
  380.     inst    =    mask bits
  381.     class    =    instruction class code
  382.     sp    =    space needed?
  383.    Outputs:
  384.     status    =    space needed?
  385. */
  386.  
  387. int oprf (int inst, int class, int sp)
  388. {
  389. int i, j;
  390.  
  391. for (i = 0; opc_val[i] >= 0; i++) {            /* loop thru ops */
  392.     j = (opc_val[i] >> I_V_FL) & I_M_FL;        /* get class */
  393.     if ((j == class) && (opc_val[i] & inst)) {    /* same class? */
  394.         inst = inst & ~opc_val[i];        /* mask bit set? */
  395.         printf ((sp? " %s": "%s"), opcode[i]);
  396.         sp = 1;  }  }
  397. return sp;
  398. }
  399.  
  400. /* Symbolic decode
  401.  
  402.    Inputs:
  403.     addr    =    current PC
  404.     *val    =    pointer to values
  405.     cflag    =    true if decoding for CPU
  406.     sw    =    switches
  407.    Outputs:
  408.     return    =    status code
  409. */
  410.  
  411. #define FMTASC(x) ((x) < 040)? "<%03o>": "%c", (x)
  412. #define SIXTOASC(x) (((x) >= 040)? (x): (x) + 0100)
  413. int print_sym (unsigned int addr, unsigned int *val, int cflag, int sw)
  414. {
  415. int i, j, k, sp, inst, disp, ma;
  416.  
  417. if (sw & SWMASK ('A')) {                /* ASCII? */
  418.     if (val[0] > 0377) return SCPE_ARG;
  419.     printf (FMTASC (val[0] & 0177));
  420.     return SCPE_OK;  }
  421. if (sw & SWMASK ('C')) {                /* character? */
  422.     putchar (SIXTOASC ((val[0] >> 12) & 077));
  423.     putchar (SIXTOASC ((val[0] >> 6) & 077));
  424.     putchar (SIXTOASC (val[0] & 077));
  425.     return SCPE_OK;  }
  426. #if defined (PDP15)
  427. if (sw & SWMASK ('P')) {                /* packed ASCII? */
  428.     printf (FMTASC ((val[0] >> 11) & 0177));
  429.     printf (FMTASC ((val[0] >> 4) & 0177));
  430.     printf (FMTASC (((val[0] << 3) | (val[1] >> 15)) & 0177));
  431.     printf (FMTASC ((val[1] >> 8) & 0177));
  432.     printf (FMTASC ((val[1] >> 1) & 0177));
  433.     return -1;  }
  434. #endif
  435. if (!(sw & SWMASK ('M'))) return SCPE_ARG;
  436.  
  437. /* Instruction decode */
  438.  
  439. inst = val[0];
  440. for (i = 0; opc_val[i] >= 0; i++) {            /* loop thru ops */
  441.     j = (opc_val[i] >> I_V_FL) & I_M_FL;        /* get class */
  442.     if ((opc_val[i] & 0777777) == (inst & masks[j])) {    /* match? */
  443.  
  444.     switch (j) {                    /* case on class */
  445.     case I_V_NPN:                    /* no operands */
  446.     case I_V_XR:                    /* index no opers */
  447.         printf ("%s", opcode[i]);        /* opcode */
  448.         break;
  449.     case I_V_NPI:                    /* IOT no operand */
  450.         printf ("%s", opcode[i]);        /* opcode */
  451.         if (inst & 010) printf (" +10");
  452.         break;
  453.     case I_V_IOT:                    /* IOT or EAE */
  454.         printf ("%s %-o", opcode[i], inst & 037777);
  455.         break;
  456.     case I_V_MRF:                    /* mem ref */
  457. #if defined (PDP15)
  458.         if (memm) {
  459.             disp = inst & 017777;  
  460.             ma = (addr & 0760000) | disp;  }
  461.         else {    disp = inst & 007777;
  462.             ma = (addr & 0770000) | disp;  }
  463. #else
  464.         disp = inst & 017777;
  465.         ma = (addr & 0760000) | disp;
  466. #endif
  467. #if defined (PDP9) || (PDP15)
  468.         if ((disp & ~07) == 00010) ma = ma & 00017;
  469. #endif
  470. #if defined (PDP15)
  471.         printf ("%s%s%-o", opcode[i],
  472.             ((inst & 0020000)? " @": " "), 
  473.             (cflag? ma & ADDRMASK: disp));
  474.         if (!memm && (inst & 0010000)) printf (",X");
  475. #else
  476.         printf ("%s%s%-o", opcode[i],
  477.             ((inst & 0020000)? " I ": " "),
  478.             (cflag? ma & ADDRMASK: disp));
  479. #endif
  480.         break;
  481.     case I_V_OPR:                    /* operate */
  482.         if (sp = (inst & 03730)) printf ("%s", opcode[i]);
  483.         oprf (inst & 014047, I_V_OPR, sp);
  484.         break;
  485.     case I_V_LAW:                    /* LAW */
  486.         printf ("%s %-o", opcode[i], inst & 017777);
  487.         break;
  488.     case I_V_XR9:                    /* index with lit */
  489.         disp = inst & 0777;
  490.         if (disp & 0400) printf ("%s -%-o", opcode[i], 01000 - disp);
  491.         else printf ("%s %-o", opcode[i], disp);
  492.         break;
  493.     case I_V_EST:                    /* EAE setup */
  494.         oprf (inst & 037007, I_V_EST, 0);    /* all masks */
  495.         break;
  496.     case I_V_ESH:                    /* EAE shift */
  497.         sp = oprf (inst & 017000, I_V_EST, 0);    /* shift masks */
  498.         printf ((sp? " %s %-o": "%s %-o"), opcode[i], inst & 077);
  499.         break;
  500.     case I_V_EMD:                    /* EAE mul-div */
  501.         disp = inst & 077;            /* get actual val */
  502.         k = (opc_val[i] >> I_V_DC) & 077;    /* get default val */
  503.         if (disp == k) printf ("%s", opcode[i]);
  504.         else if (disp < k) printf ("%s -%-o", opcode[i], k - disp);
  505.         else printf ("%s +%-o", opcode[i], disp - k);
  506.         break;  }                /* end case */
  507.     return SCPE_OK;  }                /* end if */
  508.     }                        /* end for */
  509. return SCPE_ARG;
  510. }
  511.  
  512. /* Get 18b signed number
  513.  
  514.    Inputs:
  515.     *cptr    =    pointer to input string
  516.     *sign    =    pointer to sign
  517.     *val    =    pointer to output value
  518.    Outputs:
  519.     status    =    error status
  520. */
  521.  
  522. int get_snum (char *cptr, int *sign, unsigned int *val)
  523. {
  524. *sign = 0;
  525. if (*cptr == '+') {
  526.     *sign = 1;
  527.     cptr++;  }
  528. else if (*cptr == '-') {
  529.     *sign = -1;
  530.     cptr++;  }
  531. return get_unum (cptr, 8, 0777777, val);
  532. }
  533.  
  534. /* Symbolic input
  535.  
  536.    Inputs:
  537.     *cptr    =    pointer to input string
  538.     addr    =    current PC
  539.     cflag    =    true if parsing for CPU
  540.     *val    =    pointer to output values
  541.    Outputs:
  542.     status    =    error status
  543. */
  544.  
  545. int parse_sym (char *cptr, unsigned int addr, int cflag, unsigned int *val)
  546. {
  547. int i, j, k, sign, dmask, epcmask;
  548. unsigned int r;
  549. char gbuf[CBUFSIZE];
  550.  
  551. while (isspace (*cptr)) cptr++;
  552. for (i = 1; (i < 5) && (cptr[i] != 0); i++)
  553.     if (cptr[i] == 0) for (j = i + 1; j <= 5; j++) cptr[j] = 0;
  554. if (cptr[0] == '\'') {                    /* single char? */
  555.     if (cptr[1] == 0) return SCPE_ARG;
  556.     val[0] = (unsigned int) cptr[1] | 0200;
  557.     return SCPE_OK;  }
  558. if (cptr[0] == '"') {                    /* string? */
  559.     if (cptr[1] == 0) return SCPE_ARG;
  560.     val[0] = (((unsigned int) cptr[1] & 077) << 12) |
  561.          (((unsigned int) cptr[2] & 077) << 6) |
  562.           ((unsigned int) cptr[3] & 077);
  563.     return SCPE_OK;  }
  564. #if defined (PDP15)
  565. if (cptr[0] == '#') {                    /* packed? */
  566.     if (cptr[1] == 0) return SCPE_ARG;
  567.     val[0] = (((unsigned int) cptr[1] & 0177) << 11) |
  568.          (((unsigned int) cptr[2] & 0177) << 4) |
  569.          (((unsigned int) cptr[3] & 0170) >> 3);
  570.     val[1] = (((unsigned int) cptr[3] & 0007) << 15) |
  571.          (((unsigned int) cptr[4] & 0177) << 8) |
  572.          (((unsigned int) cptr[5] & 0177) << 1);
  573.     return -1;  }
  574. #endif
  575.  
  576. /* Symbolic input, continued */
  577.  
  578. cptr = get_glyph (cptr, gbuf, 0);            /* get opcode */
  579. for (i = 0; (opcode[i] != NULL) && (strcmp (opcode[i], gbuf) != 0) ; i++) ;
  580. if (opcode[i] == NULL) return SCPE_ARG;
  581. val[0] = opc_val[i] & 0777777;                /* get value */
  582. j = (opc_val[i] >> I_V_FL) & I_M_FL;            /* get class */
  583.  
  584. switch (j) {                        /* case on class */
  585. case I_V_XR:                        /* index */
  586.     break;
  587. case I_V_XR9:                        /* index literal */
  588.     cptr = get_glyph (cptr, gbuf, 0);        /* get next field */
  589.     if (get_snum (gbuf, &sign, &r) != SCPE_OK) return SCPE_ARG;
  590.     if (((sign >= 0) && (r > 0377)) || ((sign < 0) && (r > 0400)))
  591.         return SCPE_ARG;
  592.     val[0] = val[0] | ((sign >= 0)? r: (01000 - r));
  593.     break;
  594. case I_V_LAW:                        /* law */
  595.     cptr = get_glyph (cptr, gbuf, 0);        /* get next field */
  596.     if (get_unum (gbuf, 8, 017777, &r) != SCPE_OK) return SCPE_ARG;
  597.     val[0] = val[0] | r;
  598.     break;
  599. case I_V_MRF:                        /* mem ref */
  600. #if !defined (PDP15)
  601.     dmask = 017777;
  602.     cptr = get_glyph (cptr, gbuf, 0);        /* get next field */
  603.     if (strcmp (gbuf, "I") == 0) {            /* indirect? */
  604.         val[0] = val[0] | 020000;
  605.         cptr = get_glyph (cptr, gbuf, 0);  }
  606. #else
  607.     if (memm) dmask = 017777;
  608.     else dmask = 07777;
  609.     if (*cptr == '@') {                /* indirect? */
  610.         val[0] = val[0] | 020000;
  611.         cptr++;  }
  612.     cptr = get_glyph (cptr, gbuf, ',');        /* get glyph */
  613. #endif
  614.     epcmask = ADDRMASK & ~dmask;
  615.     if (get_unum (gbuf, 8, ADDRMASK, &r) != SCPE_OK) return SCPE_ARG;
  616.     if (r <= dmask) val[0] = val[0] | r;
  617.     else if (cflag && (((addr ^ r) & epcmask) == 0))
  618.         val[0] = val[0] | (r & dmask);
  619.     else return SCPE_ARG;
  620. #if defined (PDP15)
  621.     if (!memm) {
  622.         cptr = get_glyph (cptr, gbuf, 0);
  623.         if (gbuf[0] != 0) {
  624.             if (strcmp (gbuf, "X") != 0) return SCPE_ARG;
  625.             val[0] = val[0] + 010000;  }  }
  626. #endif
  627.     break;
  628. case I_V_EMD:                        /* or'able */
  629.     val[0] = val[0] | ((opc_val[i] >> I_V_DC) & 077); /* default shift */
  630. case I_V_EST: case I_V_ESH: 
  631. case I_V_NPN: case I_V_NPI: case I_V_IOT: case I_V_OPR:
  632.     for (cptr = get_glyph (cptr, gbuf, 0); gbuf[0] != 0;
  633.         cptr = get_glyph (cptr, gbuf, 0)) {
  634.         for (i = 0; (opcode[i] != NULL) &&
  635.             (strcmp (opcode[i], gbuf) != 0) ; i++) ;
  636.         if (opcode[i] != NULL) {
  637.             k = opc_val[i] & 0777777;
  638.             if (((k ^ val[0]) & 0740000) != 0) return SCPE_ARG;
  639.             val[0] = val[0] | k;  }
  640.         else {    if (get_snum (gbuf, & sign, &r) != SCPE_OK)
  641.                 return SCPE_ARG;
  642.             if (sign > 0) val[0] = val[0] + r;  
  643.             else if (sign < 0) val[0] = val[0] - r;
  644.             else val[0] = val[0] | r;  }  }
  645.     break;  }                    /* end case */
  646. if (*cptr != 0) return SCPE_ARG;            /* junk at end? */
  647. return SCPE_OK;
  648. }
  649.