Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 1 | /*
|
| 2 | * besm6_sys.c: BESM-6 simulator interface
|
| 3 | *
|
| 4 | * Copyright (c) 2009, Serge Vakulenko
|
| 5 | * Copyright (c) 2009, Leonid Broukhis
|
| 6 | *
|
Leo Broukhis | aa16857 | 2015-01-04 23:14:51 -0800 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining a
|
| 8 | * copy of this software and associated documentation files (the "Software"),
|
| 9 | * to deal in the Software without restriction, including without limitation
|
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
| 11 | * and/or sell copies of the Software, and to permit persons to whom the
|
| 12 | * Software is furnished to do so, subject to the following conditions:
|
| 13 |
|
| 14 | * The above copyright notice and this permission notice shall be included in
|
| 15 | * all copies or substantial portions of the Software.
|
| 16 |
|
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
| 20 | * SERGE VAKULENKO OR LEONID BROUKHIS BE LIABLE FOR ANY CLAIM, DAMAGES
|
| 21 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
Serge Vakulenko | 5ed1909 | 2015-01-21 12:29:29 -0800 | [diff] [blame] | 22 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
Leo Broukhis | aa16857 | 2015-01-04 23:14:51 -0800 | [diff] [blame] | 23 | * OR OTHER DEALINGS IN THE SOFTWARE.
|
| 24 |
|
| 25 | * Except as contained in this notice, the name of Leonid Broukhis or
|
| 26 | * Serge Vakulenko shall not be used in advertising or otherwise to promote
|
| 27 | * the sale, use or other dealings in this Software without prior written
|
| 28 | * authorization from Leonid Broukhis and Serge Vakulenko.
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 29 | *
|
| 30 | * This file implements three essential functions:
|
| 31 | *
|
| 32 | * sim_load() - loading and dumping memory and CPU state
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 33 | * in a way, specific for BESM-6 architecture
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 34 | * fprint_sym() - print a machune instruction using
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 35 | * opcode mnemonic or in a digital format
|
| 36 | * parse_sym() - scan a string and build an instruction
|
| 37 | * word from it
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 38 | */
|
| 39 | #include "besm6_defs.h"
|
| 40 | #include <math.h>
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 41 |
|
| 42 | const char *opname_short_bemsh [64] = {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 43 | "зп", "зпм", "рег", "счм", "сл", "вч", "вчоб","вчаб",
|
| 44 | "сч", "и", "нтж", "слц", "знак","или", "дел", "умн",
|
| 45 | "сбр", "рзб", "чед", "нед", "слп", "вчп", "сд", "рж",
|
| 46 | "счрж","счмр","э32", "увв", "слпа","вчпа","сда", "ржа",
|
| 47 | "уи", "уим", "счи", "счим","уии", "сли", "э46", "э47",
|
| 48 | "э50", "э51", "э52", "э53", "э54", "э55", "э56", "э57",
|
| 49 | "э60", "э61", "э62", "э63", "э64", "э65", "э66", "э67",
|
| 50 | "э70", "э71", "э72", "э73", "э74", "э75", "э76", "э77",
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 51 | };
|
| 52 |
|
| 53 | static const char *opname_long_bemsh [16] = {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 54 | "э20", "э21", "мода","мод", "уиа", "слиа","по", "пе",
|
| 55 | "пб", "пв", "выпр","стоп","пио", "пино","э36", "цикл",
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 56 | };
|
| 57 |
|
| 58 | const char *opname_short_madlen [64] = {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 59 | "atx", "stx", "mod", "xts", "a+x", "a-x", "x-a", "amx",
|
| 60 | "xta", "aax", "aex", "arx", "avx", "aox", "a/x", "a*x",
|
| 61 | "apx", "aux", "acx", "anx", "e+x", "e-x", "asx", "xtr",
|
| 62 | "rte", "yta", "*32", "ext", "e+n", "e-n", "asn", "ntr",
|
| 63 | "ati", "sti", "ita", "its", "mtj", "j+m", "*46", "*47",
|
| 64 | "*50", "*51", "*52", "*53", "*54", "*55", "*56", "*57",
|
| 65 | "*60", "*61", "*62", "*63", "*64", "*65", "*66", "*67",
|
| 66 | "*70", "*71", "*72", "*73", "*74", "*75", "*76", "*77",
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 67 | };
|
| 68 |
|
| 69 | static const char *opname_long_madlen [16] = {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 70 | "*20", "*21", "utc", "wtc", "vtm", "utm", "uza", "u1a",
|
| 71 | "uj", "vjm", "ij", "stop", "vzm", "v1m", "*36", "vlm",
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 72 | };
|
| 73 |
|
| 74 | /*
|
| 75 | * Выдача мнемоники по коду инструкции.
|
| 76 | * Код должен быть в диапазоне 000..077 или 0200..0370.
|
| 77 | */
|
| 78 | const char *besm6_opname (int opcode)
|
| 79 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 80 | if (sim_switches & SWMASK ('L')) {
|
| 81 | /* Latin mnemonics. */
|
| 82 | if (opcode & 0200)
|
| 83 | return opname_long_madlen [(opcode >> 3) & 017];
|
| 84 | return opname_short_madlen [opcode];
|
| 85 | }
|
| 86 | if (opcode & 0200)
|
| 87 | return opname_long_bemsh [(opcode >> 3) & 017];
|
| 88 | return opname_short_bemsh [opcode];
|
| 89 | }
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 90 |
|
| 91 | /*
|
| 92 | * Выдача кода инструкции по мнемонике (UTF-8).
|
| 93 | */
|
| 94 | int besm6_opcode (char *instr)
|
| 95 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 96 | int i;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 97 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 98 | for (i=0; i<64; ++i)
|
| 99 | if (strcmp (opname_short_bemsh[i], instr) == 0 ||
|
| 100 | strcmp (opname_short_madlen[i], instr) == 0)
|
| 101 | return i;
|
| 102 | for (i=0; i<16; ++i)
|
| 103 | if (strcmp (opname_long_bemsh[i], instr) == 0 ||
|
| 104 | strcmp (opname_long_madlen[i], instr) == 0)
|
| 105 | return (i << 3) | 0200;
|
| 106 | return -1;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 107 | }
|
| 108 |
|
| 109 | /*
|
| 110 | * Выдача на консоль и в файл протокола.
|
| 111 | * Если первый символ формата - подчерк, на консоль не печатаем.
|
| 112 | * Добавляет перевод строки.
|
| 113 | */
|
| 114 | void besm6_log (const char *fmt, ...)
|
| 115 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 116 | va_list args;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 117 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 118 | if (*fmt == '_')
|
| 119 | ++fmt;
|
| 120 | else {
|
| 121 | va_start (args, fmt);
|
| 122 | vprintf (fmt, args);
|
| 123 | printf ("\r\n");
|
| 124 | va_end (args);
|
| 125 | }
|
| 126 | if (sim_log) {
|
| 127 | va_start (args, fmt);
|
| 128 | vfprintf (sim_log, fmt, args);
|
| 129 | if (sim_log == stdout)
|
| 130 | fprintf (sim_log, "\r");
|
| 131 | fprintf (sim_log, "\n");
|
| 132 | fflush (sim_log);
|
| 133 | va_end (args);
|
| 134 | }
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 135 | }
|
| 136 |
|
| 137 | /*
|
| 138 | * Не добавляет перевод строки.
|
| 139 | */
|
| 140 | void besm6_log_cont (const char *fmt, ...)
|
| 141 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 142 | va_list args;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 143 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 144 | if (*fmt == '_')
|
| 145 | ++fmt;
|
| 146 | else {
|
| 147 | va_start (args, fmt);
|
| 148 | vprintf (fmt, args);
|
| 149 | va_end (args);
|
| 150 | }
|
| 151 | if (sim_log) {
|
| 152 | va_start (args, fmt);
|
| 153 | vfprintf (sim_log, fmt, args);
|
| 154 | fflush (sim_log);
|
| 155 | va_end (args);
|
| 156 | }
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 157 | }
|
| 158 |
|
| 159 | /*
|
| 160 | * Выдача на консоль и в файл отладки: если включён режим "cpu debug".
|
| 161 | * Добавляет перевод строки.
|
| 162 | */
|
| 163 | void besm6_debug (const char *fmt, ...)
|
| 164 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 165 | va_list args;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 166 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 167 | va_start (args, fmt);
|
| 168 | vprintf (fmt, args);
|
| 169 | printf ("\r\n");
|
| 170 | va_end (args);
|
| 171 | if (sim_deb && sim_deb != stdout) {
|
| 172 | va_start (args, fmt);
|
| 173 | vfprintf (sim_deb, fmt, args);
|
| 174 | fprintf (sim_deb, "\n");
|
| 175 | fflush (sim_deb);
|
| 176 | va_end (args);
|
| 177 | }
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 178 | }
|
| 179 |
|
| 180 | /*
|
| 181 | * Преобразование вещественного числа в формат БЭСМ-6.
|
| 182 | *
|
| 183 | * Представление чисел в IEEE 754 (double):
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 184 | * 64 63———53 52————–1
|
| 185 | * знак порядок мантисса
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 186 | * Старший (53-й) бит мантиссы не хранится и всегда равен 1.
|
| 187 | *
|
| 188 | * Представление чисел в БЭСМ-6:
|
| 189 | * 48——–42 41 40————————————————–1
|
| 190 | * порядок знак мантисса в доп. коде
|
| 191 | */
|
| 192 | t_value ieee_to_besm6 (double d)
|
| 193 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 194 | t_value word;
|
| 195 | int exponent;
|
| 196 | int sign;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 197 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 198 | sign = d < 0;
|
| 199 | if (sign)
|
| 200 | d = -d;
|
| 201 | d = frexp (d, &exponent);
|
| 202 | /* 0.5 <= d < 1.0 */
|
| 203 | d = ldexp (d, 40);
|
Mark Pizzolato | 76dd31a | 2014-12-30 17:52:13 -0800 | [diff] [blame] | 204 | word = (t_value)d;
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 205 | if (d - word >= 0.5)
|
| 206 | word += 1; /* Округление. */
|
| 207 | if (exponent < -64)
|
| 208 | return 0LL; /* Близкое к нулю число */
|
| 209 | if (exponent > 63) {
|
| 210 | return sign ?
|
| 211 | 0xFEFFFFFFFFFFLL : /* Максимальное число */
|
| 212 | 0xFF0000000000LL; /* Минимальное число */
|
| 213 | }
|
| 214 | if (sign)
|
| 215 | word = 0x20000000000LL-word; /* Знак. */
|
| 216 | word |= ((t_value) (exponent + 64)) << 41;
|
| 217 | return word;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 218 | }
|
| 219 |
|
| 220 | double besm6_to_ieee (t_value word)
|
| 221 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 222 | double mantissa;
|
Mark Pizzolato | 76dd31a | 2014-12-30 17:52:13 -0800 | [diff] [blame] | 223 | int exponent;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 224 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 225 | /* Убираем свертку */
|
| 226 | word &= BITS48;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 227 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 228 | /* Сдвигаем так, чтобы знак мантиссы пришелся на знак целого;
|
| 229 | * таким образом, mantissa равно исходной мантиссе, умноженной на 2**63.
|
| 230 | */
|
Mark Pizzolato | 76dd31a | 2014-12-30 17:52:13 -0800 | [diff] [blame] | 231 | mantissa = (double)(((t_int64) word) << (64 - 48 + 7));
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 232 |
|
Mark Pizzolato | 76dd31a | 2014-12-30 17:52:13 -0800 | [diff] [blame] | 233 | exponent = word >> 41;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 234 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 235 | /* Порядок смещен вверх на 64, и мантиссу нужно скорректировать */
|
| 236 | return ldexp (mantissa, exponent - 64 - 63);
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 237 | }
|
| 238 |
|
| 239 | /*
|
| 240 | * Пропуск пробелов.
|
| 241 | */
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 242 | CONST char *skip_spaces (CONST char *p)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 243 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 244 | for (;;) {
|
| 245 | if (*p == (char) 0xEF && p[1] == (char) 0xBB && p[2] == (char) 0xBF) {
|
| 246 | /* Skip zero width no-break space. */
|
| 247 | p += 3;
|
| 248 | continue;
|
| 249 | }
|
| 250 | if (*p == ' ' || *p == '\t' || *p == '\r') {
|
| 251 | ++p;
|
| 252 | continue;
|
| 253 | }
|
| 254 | return p;
|
| 255 | }
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 256 | }
|
| 257 |
|
| 258 | /*
|
| 259 | * Fetch Unicode symbol from UTF-8 string.
|
| 260 | * Advance string pointer.
|
| 261 | */
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 262 | int utf8_to_unicode (CONST char **p)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 263 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 264 | int c1, c2, c3;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 265 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 266 | c1 = (unsigned char) *(*p)++;
|
| 267 | if (! (c1 & 0x80))
|
| 268 | return c1;
|
| 269 | c2 = (unsigned char) *(*p)++;
|
| 270 | if (! (c1 & 0x20))
|
| 271 | return (c1 & 0x1f) << 6 | (c2 & 0x3f);
|
| 272 | c3 = (unsigned char) *(*p)++;
|
| 273 | return (c1 & 0x0f) << 12 | (c2 & 0x3f) << 6 | (c3 & 0x3f);
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 274 | }
|
| 275 |
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 276 | char *besm6_parse_octal (const char *cptr, int *offset)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 277 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 278 | char *eptr;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 279 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 280 | *offset = strtol (cptr, &eptr, 8);
|
| 281 | if (eptr == cptr)
|
| 282 | return 0;
|
| 283 | return eptr;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 284 | }
|
| 285 |
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 286 | static CONST char *get_alnum (CONST char *iptr, char *optr)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 287 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 288 | while ((*iptr >= 'a' && *iptr<='z') ||
|
| 289 | (*iptr >= 'A' && *iptr<='Z') ||
|
| 290 | (*iptr >= '0' && *iptr<='9') || (*iptr & 0x80)) {
|
| 291 | *optr++ = *iptr++;
|
| 292 | }
|
| 293 | *optr = 0;
|
| 294 | return iptr;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 295 | }
|
| 296 |
|
| 297 | /*
|
| 298 | * Parse single instruction (half word).
|
| 299 | * Allow mnemonics or octal code.
|
| 300 | */
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 301 | CONST char *parse_instruction (CONST char *cptr, uint32 *val)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 302 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 303 | int opcode, reg, addr, negate;
|
| 304 | char gbuf[CBUFSIZE];
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 305 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 306 | cptr = skip_spaces (cptr); /* absorb spaces */
|
| 307 | if (*cptr >= '0' && *cptr <= '7') {
|
| 308 | /* Восьмеричное представление. */
|
| 309 | cptr = besm6_parse_octal (cptr, ®); /* get register */
|
| 310 | if (! cptr || reg > 15) {
|
| 311 | /*printf ("Bad register\n");*/
|
| 312 | return 0;
|
| 313 | }
|
| 314 | cptr = skip_spaces (cptr); /* absorb spaces */
|
| 315 | if (*cptr == '2' || *cptr == '3') {
|
| 316 | /* Длинная команда. */
|
| 317 | cptr = besm6_parse_octal (cptr, &opcode);
|
| 318 | if (! cptr || opcode < 020 || opcode > 037) {
|
| 319 | /*printf ("Bad long opcode\n");*/
|
| 320 | return 0;
|
| 321 | }
|
| 322 | opcode <<= 3;
|
| 323 | } else {
|
| 324 | /* Короткая команда. */
|
| 325 | cptr = besm6_parse_octal (cptr, &opcode);
|
| 326 | if (! cptr || opcode > 0177) {
|
| 327 | /*printf ("Bad short opcode\n");*/
|
| 328 | return 0;
|
| 329 | }
|
| 330 | }
|
| 331 | cptr = besm6_parse_octal (cptr, &addr); /* get address */
|
| 332 | if (! cptr || addr > BITS(15) ||
|
| 333 | (opcode <= 0177 && addr > BITS(12))) {
|
| 334 | /*printf ("Bad address\n");*/
|
| 335 | return 0;
|
| 336 | }
|
| 337 | } else {
|
| 338 | /* Мнемоническое представление команды. */
|
| 339 | cptr = get_alnum (cptr, gbuf); /* get opcode */
|
| 340 | opcode = besm6_opcode (gbuf);
|
| 341 | if (opcode < 0) {
|
| 342 | /*printf ("Bad opname: %s\n", gbuf);*/
|
| 343 | return 0;
|
| 344 | }
|
| 345 | negate = 0;
|
| 346 | cptr = skip_spaces (cptr); /* absorb spaces */
|
| 347 | if (*cptr == '-') { /* negative offset */
|
| 348 | negate = 1;
|
| 349 | cptr = skip_spaces (cptr + 1); /* absorb spaces */
|
| 350 | }
|
| 351 | addr = 0;
|
| 352 | if (*cptr >= '0' && *cptr <= '7') {
|
| 353 | /* Восьмеричный адрес. */
|
| 354 | cptr = besm6_parse_octal (cptr, &addr);
|
| 355 | if (! cptr || addr > BITS(15)) {
|
| 356 | /*printf ("Bad address: %o\n", addr);*/
|
| 357 | return 0;
|
| 358 | }
|
| 359 | if (negate)
|
| 360 | addr = (- addr) & BITS(15);
|
| 361 | if (opcode <= 077 && addr > BITS(12)) {
|
| 362 | if (addr < 070000) {
|
| 363 | /*printf ("Bad short address: %o\n", addr);*/
|
| 364 | return 0;
|
| 365 | }
|
| 366 | opcode |= 0100;
|
| 367 | addr &= BITS(12);
|
| 368 | }
|
| 369 | }
|
| 370 | reg = 0;
|
| 371 | cptr = skip_spaces (cptr); /* absorb spaces */
|
| 372 | if (*cptr == '(') {
|
| 373 | /* Индекс-регистр в скобках. */
|
| 374 | cptr = besm6_parse_octal (cptr+1, ®);
|
| 375 | if (! cptr || reg > 15) {
|
| 376 | /*printf ("Bad register: %o\n", reg);*/
|
| 377 | return 0;
|
| 378 | }
|
| 379 | cptr = skip_spaces (cptr); /* absorb spaces */
|
| 380 | if (*cptr != ')') {
|
| 381 | /*printf ("No closing brace\n");*/
|
| 382 | return 0;
|
| 383 | }
|
| 384 | ++cptr;
|
| 385 | }
|
| 386 | }
|
| 387 | *val = reg << 20 | opcode << 12 | addr;
|
| 388 | return cptr;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 389 | }
|
| 390 |
|
| 391 | /*
|
| 392 | * Instruction parse: two commands per word.
|
| 393 | */
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 394 | t_stat parse_instruction_word (CONST char *cptr, t_value *val)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 395 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 396 | uint32 left, right;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 397 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 398 | *val = 0;
|
| 399 | cptr = parse_instruction (cptr, &left);
|
| 400 | if (! cptr)
|
| 401 | return SCPE_ARG;
|
| 402 | right = 0;
|
| 403 | cptr = skip_spaces (cptr);
|
| 404 | if (*cptr == ',') {
|
| 405 | cptr = parse_instruction (cptr + 1, &right);
|
| 406 | if (! cptr)
|
| 407 | return SCPE_ARG;
|
| 408 | }
|
| 409 | cptr = skip_spaces (cptr); /* absorb spaces */
|
| 410 | if (*cptr != 0 && *cptr != ';' && *cptr != '\n' && *cptr != '\r') {
|
| 411 | /*printf ("Extra symbols at eoln: %s\n", cptr);*/
|
| 412 | return SCPE_2MARG;
|
| 413 | }
|
| 414 | *val = (t_value) left << 24 | right;
|
| 415 | return SCPE_OK;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 416 | }
|
| 417 |
|
| 418 | /*
|
| 419 | * Печать машинной инструкции с мнемоникой.
|
| 420 | */
|
| 421 | void besm6_fprint_cmd (FILE *of, uint32 cmd)
|
| 422 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 423 | int reg, opcode, addr;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 424 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 425 | reg = (cmd >> 20) & 017;
|
| 426 | if (cmd & BBIT(20)) {
|
| 427 | opcode = (cmd >> 12) & 0370;
|
| 428 | addr = cmd & BITS(15);
|
| 429 | } else {
|
| 430 | opcode = (cmd >> 12) & 077;
|
| 431 | addr = cmd & 07777;
|
| 432 | if (cmd & BBIT(19))
|
| 433 | addr |= 070000;
|
| 434 | }
|
| 435 | fprintf (of, "%s", besm6_opname (opcode));
|
| 436 | if (addr) {
|
| 437 | fprintf (of, " ");
|
| 438 | if (addr >= 077700)
|
| 439 | fprintf (of, "-%o", (addr ^ 077777) + 1);
|
| 440 | else
|
| 441 | fprintf (of, "%o", addr);
|
| 442 | }
|
| 443 | if (reg) {
|
| 444 | if (! addr)
|
| 445 | fprintf (of, " ");
|
| 446 | fprintf (of, "(%o)", reg);
|
| 447 | }
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 448 | }
|
| 449 |
|
| 450 | /*
|
| 451 | * Печать машинной инструкции в восьмеричном виде.
|
| 452 | */
|
| 453 | void besm6_fprint_insn (FILE *of, uint32 insn)
|
| 454 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 455 | if (insn & BBIT(20))
|
| 456 | fprintf (of, "%02o %02o %05o ",
|
| 457 | insn >> 20, (insn >> 15) & 037, insn & BITS(15));
|
| 458 | else
|
| 459 | fprintf (of, "%02o %03o %04o ",
|
| 460 | insn >> 20, (insn >> 12) & 0177, insn & 07777);
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 461 | }
|
| 462 |
|
| 463 | /*
|
| 464 | * Symbolic decode
|
| 465 | *
|
| 466 | * Inputs:
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 467 | * *of = output stream
|
| 468 | * addr = current PC
|
| 469 | * *val = pointer to data
|
| 470 | * *uptr = pointer to unit
|
| 471 | * sw = switches
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 472 | * Outputs:
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 473 | * return = status code
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 474 | */
|
| 475 | t_stat fprint_sym (FILE *of, t_addr addr, t_value *val,
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 476 | UNIT *uptr, int32 sw)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 477 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 478 | t_value cmd;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 479 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 480 | if (uptr && (uptr != &cpu_unit)) /* must be CPU */
|
| 481 | return SCPE_ARG;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 482 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 483 | cmd = val[0];
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 484 |
|
| 485 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 486 | if (sw & SWMASK ('M')) { /* symbolic decode? */
|
| 487 | if (sw & SIM_SW_STOP && addr == PC && !(RUU & RUU_RIGHT_INSTR))
|
| 488 | fprintf (of, "-> ");
|
Mark Pizzolato | 76dd31a | 2014-12-30 17:52:13 -0800 | [diff] [blame] | 489 | besm6_fprint_cmd (of, (uint32)(cmd >> 24));
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 490 | if (sw & SIM_SW_STOP) /* stop point */
|
| 491 | fprintf (of, ", ");
|
| 492 | else
|
| 493 | fprintf (of, ",\n\t");
|
| 494 | if (sw & SIM_SW_STOP && addr == PC && (RUU & RUU_RIGHT_INSTR))
|
| 495 | fprintf (of, "-> ");
|
| 496 | besm6_fprint_cmd (of, cmd & BITS(24));
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 497 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 498 | } else if (sw & SWMASK ('I')) {
|
| 499 | besm6_fprint_insn (of, (cmd >> 24) & BITS(24));
|
| 500 | besm6_fprint_insn (of, cmd & BITS(24));
|
| 501 | } else if (sw & SWMASK ('F')) {
|
| 502 | fprintf (of, "%#.2g", besm6_to_ieee(cmd));
|
| 503 | } else if (sw & SWMASK ('B')) {
|
| 504 | fprintf (of, "%03o %03o %03o %03o %03o %03o",
|
| 505 | (int) (cmd >> 40) & 0377,
|
| 506 | (int) (cmd >> 32) & 0377,
|
| 507 | (int) (cmd >> 24) & 0377,
|
| 508 | (int) (cmd >> 16) & 0377,
|
| 509 | (int) (cmd >> 8) & 0377,
|
| 510 | (int) cmd & 0377);
|
| 511 | } else if (sw & SWMASK ('X')) {
|
| 512 | fprintf (of, "%013llx", cmd);
|
| 513 | } else
|
| 514 | fprintf (of, "%04o %04o %04o %04o",
|
| 515 | (int) (cmd >> 36) & 07777,
|
| 516 | (int) (cmd >> 24) & 07777,
|
| 517 | (int) (cmd >> 12) & 07777,
|
| 518 | (int) cmd & 07777);
|
| 519 | return SCPE_OK;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 520 | }
|
| 521 |
|
| 522 | /*
|
| 523 | * Symbolic input
|
| 524 | *
|
| 525 | * Inputs:
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 526 | * *cptr = pointer to input string
|
| 527 | * addr = current PC
|
| 528 | * *uptr = pointer to unit
|
| 529 | * *val = pointer to output values
|
| 530 | * sw = switches
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 531 | * Outputs:
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 532 | * status = error status
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 533 | */
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 534 | t_stat parse_sym (CONST char *cptr, t_addr addr, UNIT *uptr, t_value *val, int32 sw)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 535 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 536 | int32 i;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 537 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 538 | if (uptr && (uptr != &cpu_unit)) /* must be CPU */
|
| 539 | return SCPE_ARG;
|
| 540 | if (! parse_instruction_word (cptr, val)) /* symbolic parse? */
|
| 541 | return SCPE_OK;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 542 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 543 | val[0] = 0;
|
| 544 | for (i=0; i<16; i++) {
|
| 545 | if (*cptr < '0' || *cptr > '7')
|
| 546 | break;
|
| 547 | val[0] = (val[0] << 3) | (*cptr - '0');
|
| 548 | cptr = skip_spaces (cptr+1); /* next char */
|
| 549 | }
|
| 550 | if (*cptr != 0 && *cptr != ';' && *cptr != '\n' && *cptr != '\r') {
|
| 551 | /*printf ("Extra symbols at eoln: %s\n", cptr);*/
|
| 552 | return SCPE_2MARG;
|
| 553 | }
|
| 554 | return SCPE_OK;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 555 | }
|
| 556 |
|
| 557 | /*
|
| 558 | * Чтение строки входного файла.
|
| 559 | * Форматы строк:
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 560 | * п 76543 - адрес пуска
|
| 561 | * в 12345 - адрес ввода
|
Serge Vakulenko | 5ed1909 | 2015-01-21 12:29:29 -0800 | [diff] [blame] | 562 | * ч -123.45e+6 - вещественное число
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 563 | * с 0123 4567 0123 4567 - восьмеричное слово
|
| 564 | * к 00 22 00000 00 010 0000 - команды
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 565 | */
|
| 566 | t_stat besm6_read_line (FILE *input, int *type, t_value *val)
|
| 567 | {
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 568 | char buf [512];
|
| 569 | CONST char *p;
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 570 | int i, c;
|
| 571 | again:
|
| 572 | if (! fgets (buf, sizeof (buf), input)) {
|
| 573 | *type = 0;
|
| 574 | return SCPE_OK;
|
| 575 | }
|
| 576 | p = skip_spaces (buf);
|
| 577 | if (*p == '\n' || *p == ';')
|
| 578 | goto again;
|
| 579 | c = utf8_to_unicode (&p);
|
| 580 | if (c == CYRILLIC_SMALL_LETTER_VE ||
|
| 581 | c == CYRILLIC_CAPITAL_LETTER_VE ||
|
| 582 | c == 'b' || c == 'B') {
|
| 583 | /* Адрес размещения данных. */
|
| 584 | *type = ':';
|
| 585 | *val = strtol (p, 0, 8);
|
| 586 | return SCPE_OK;
|
| 587 | }
|
| 588 | if (c == CYRILLIC_SMALL_LETTER_PE ||
|
| 589 | c == CYRILLIC_CAPITAL_LETTER_PE ||
|
| 590 | c == 'p' || c == 'P') {
|
| 591 | /* Стартовый адрес. */
|
| 592 | *type = '@';
|
| 593 | *val = strtol (p, 0, 8);
|
| 594 | return SCPE_OK;
|
| 595 | }
|
| 596 | if (c == CYRILLIC_SMALL_LETTER_CHE ||
|
| 597 | c == CYRILLIC_CAPITAL_LETTER_CHE ||
|
| 598 | c == 'f' || c == 'F') {
|
| 599 | /* Вещественное число. */
|
| 600 | *type = '=';
|
| 601 | *val = ieee_to_besm6 (strtod (p, 0));
|
| 602 | return SCPE_OK;
|
| 603 | }
|
| 604 | if (c == CYRILLIC_SMALL_LETTER_ES ||
|
| 605 | c == CYRILLIC_CAPITAL_LETTER_ES ||
|
| 606 | c == 'c' || c == 'C') {
|
| 607 | /* Восьмеричное слово. */
|
| 608 | *type = '=';
|
| 609 | *val = 0;
|
| 610 | for (i=0; i<16; ++i) {
|
| 611 | p = skip_spaces (p);
|
| 612 | if (*p < '0' || *p > '7') {
|
| 613 | if (i == 0) {
|
| 614 | /* слишком короткое слово */
|
| 615 | goto bad;
|
| 616 | }
|
| 617 | break;
|
| 618 | }
|
| 619 | *val = *val << 3 | (*p++ - '0');
|
| 620 | }
|
| 621 | return SCPE_OK;
|
| 622 | }
|
| 623 | if (c == CYRILLIC_SMALL_LETTER_KA ||
|
| 624 | c == CYRILLIC_CAPITAL_LETTER_KA ||
|
| 625 | c == 'k' || c == 'K') {
|
| 626 | /* Команда. */
|
| 627 | *type = '*';
|
| 628 | if (parse_instruction_word (p, val) != SCPE_OK)
|
| 629 | goto bad;
|
| 630 | return SCPE_OK;
|
| 631 | }
|
| 632 | /* Неверная строка входного файла */
|
| 633 | bad: besm6_log ("Invalid input line: %s", buf);
|
| 634 | return SCPE_FMT;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 635 | }
|
| 636 |
|
| 637 | /*
|
| 638 | * Load memory from file.
|
| 639 | */
|
| 640 | t_stat besm6_load (FILE *input)
|
| 641 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 642 | int addr, type;
|
| 643 | t_value word;
|
| 644 | t_stat err;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 645 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 646 | addr = 1;
|
| 647 | PC = 1;
|
| 648 | for (;;) {
|
| 649 | err = besm6_read_line (input, &type, &word);
|
| 650 | if (err)
|
| 651 | return err;
|
| 652 | switch (type) {
|
| 653 | case 0: /* EOF */
|
| 654 | return SCPE_OK;
|
| 655 | case ':': /* address */
|
Mark Pizzolato | 76dd31a | 2014-12-30 17:52:13 -0800 | [diff] [blame] | 656 | addr = (int)word;
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 657 | break;
|
| 658 | case '=': /* word */
|
| 659 | if (addr < 010)
|
Leo Broukhis | d4cb5e8 | 2015-02-13 09:33:40 -0800 | [diff] [blame] | 660 | pult [0][addr] = SET_PARITY (word, PARITY_NUMBER);
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 661 | else
|
Leo Broukhis | d4cb5e8 | 2015-02-13 09:33:40 -0800 | [diff] [blame] | 662 | memory [addr] = SET_PARITY (word, PARITY_NUMBER);
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 663 | ++addr;
|
| 664 | break;
|
| 665 | case '*': /* instruction */
|
| 666 | if (addr < 010)
|
Leo Broukhis | d4cb5e8 | 2015-02-13 09:33:40 -0800 | [diff] [blame] | 667 | pult [0][addr] = SET_PARITY (word, PARITY_INSN);
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 668 | else
|
Leo Broukhis | d4cb5e8 | 2015-02-13 09:33:40 -0800 | [diff] [blame] | 669 | memory [addr] = SET_PARITY (word, PARITY_INSN);
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 670 | ++addr;
|
| 671 | break;
|
| 672 | case '@': /* start address */
|
Mark Pizzolato | 76dd31a | 2014-12-30 17:52:13 -0800 | [diff] [blame] | 673 | PC = (uint32)word;
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 674 | break;
|
| 675 | }
|
| 676 | if (addr > MEMSIZE)
|
| 677 | return SCPE_FMT;
|
| 678 | }
|
| 679 | return SCPE_OK;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 680 | }
|
| 681 |
|
| 682 | /*
|
| 683 | * Dump memory to file.
|
| 684 | */
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 685 | t_stat besm6_dump (FILE *of, const char *fnam)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 686 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 687 | int addr, last_addr = -1;
|
| 688 | t_value word;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 689 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 690 | fprintf (of, "; %s\n", fnam);
|
| 691 | for (addr=1; addr<MEMSIZE; ++addr) {
|
| 692 | if (addr < 010)
|
Leo Broukhis | 9ff642f | 2015-01-14 00:39:55 -0800 | [diff] [blame] | 693 | word = pult [0][addr];
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 694 | else
|
| 695 | word = memory [addr];
|
| 696 | if (word == 0)
|
| 697 | continue;
|
| 698 | if (addr != last_addr+1) {
|
| 699 | fprintf (of, "\nв %05o\n", addr);
|
| 700 | }
|
| 701 | last_addr = addr;
|
| 702 | if (IS_INSN (word)) {
|
| 703 | fprintf (of, "к ");
|
Mark Pizzolato | 76dd31a | 2014-12-30 17:52:13 -0800 | [diff] [blame] | 704 | besm6_fprint_cmd (of, (uint32)(word >> 24));
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 705 | fprintf (of, ", ");
|
| 706 | besm6_fprint_cmd (of, word & BITS(24));
|
| 707 | fprintf (of, "\t\t; %05o - ", addr);
|
| 708 | fprintf (of, "%04o %04o %04o %04o\n",
|
| 709 | (int) (word >> 36) & 07777,
|
| 710 | (int) (word >> 24) & 07777,
|
| 711 | (int) (word >> 12) & 07777,
|
| 712 | (int) word & 07777);
|
| 713 | } else {
|
| 714 | fprintf (of, "с %04o %04o %04o %04o",
|
| 715 | (int) (word >> 36) & 07777,
|
| 716 | (int) (word >> 24) & 07777,
|
| 717 | (int) (word >> 12) & 07777,
|
| 718 | (int) word & 07777);
|
| 719 | fprintf (of, "\t\t; %05o\n", addr);
|
| 720 | }
|
| 721 | }
|
| 722 | return SCPE_OK;
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 723 | }
|
| 724 |
|
| 725 | /*
|
| 726 | * Loader/dumper
|
| 727 | */
|
Mark Pizzolato | 5531ccb | 2016-05-15 15:25:33 -0700 | [diff] [blame] | 728 | t_stat sim_load (FILE *fi, CONST char *cptr, CONST char *fnam, int dump_flag)
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 729 | {
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 730 | if (dump_flag)
|
| 731 | return besm6_dump (fi, fnam);
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 732 |
|
Leo Broukhis | cc33257 | 2014-12-30 11:42:52 -0800 | [diff] [blame] | 733 | return besm6_load (fi);
|
Leo Broukhis | b4eeaa7 | 2014-12-30 00:41:31 -0800 | [diff] [blame] | 734 | }
|