home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2075 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  29.6 KB

  1. From: darcy@druid.uucp (D'Arcy J.M. Cain)
  2. Newsgroups: alt.sources
  3. Subject: Yet another CP/M emulator part 2 of 3
  4. Message-ID: <1990Nov15.203736.10568@druid.uucp>
  5. Date: 15 Nov 90 20:37:36 GMT
  6. >from: darcy@druid.uucp (D'Arcy J.M. Cain)
  7.  
  8. #!/bin/sh
  9. # this is cpm.02 (part 2 of a multipart archive)
  10. # do not concatenate these parts, unpack them in order with /bin/sh
  11. # file cpm.c continued
  12. #
  13. if test ! -r _shar_seq_.tmp; then
  14.     echo 'Please unpack part 1 first!'
  15.     exit 1
  16. fi
  17. (read Scheck
  18.  if test "$Scheck" != 2; then
  19.     echo Please unpack part "$Scheck" next!
  20.     exit 1
  21.  else
  22.     exit 0
  23.  fi
  24. ) < _shar_seq_.tmp || exit 1
  25. sed 's/^X//' << 'SHAR_EOF' >> 'cpm.c' &&
  26. X            return(-1);
  27. X        }
  28. X
  29. X        def_drive = *entry;
  30. X        strcpy(cpm_drive[0],cpm_drive[def_drive]);
  31. X        entry[0] = entry[1] = ' ';
  32. X        tail = chop_cmd(entry);
  33. X    }
  34. X
  35. X    if (*entry == 0)
  36. X        return(0);
  37. X
  38. X    debug(entry);
  39. X
  40. X    if (strcmp(entry, "DIR") == 0)
  41. X        fsystem("ls -C %s", tail);
  42. X    else if (strcmp(entry, "DUMP") == 0)
  43. X        fsystem("hd %s", tail);
  44. X    else if (strcmp(entry, "ED") == 0)
  45. X        fsystem("$EDITOR %s", tail);
  46. X    else if (strcmp(entry, "ERA") == 0)
  47. X        fsystem("rm %s", tail);
  48. #ifdef    CPM_DEBUG
  49. X    else if (strcmp(entry, "DASM") == 0)
  50. X    {
  51. X        if(++dasm_flag > 2)
  52. X            dasm_flag = 0;
  53. X
  54. X        fprintf(stderr, "DASM is %d\r\n", dasm_flag);
  55. X    }
  56. #endif
  57. X    else if (strcmp(entry, "SAVE") == 0)
  58. X    {
  59. X        char    *fname = chop_cmd(tail);
  60. X        int        p = atoi(tail);
  61. X
  62. X        if ((p == 0) || (*fname == 0))
  63. X            fprintf(stderr, "Usage: SAVE #pages filename\r\n");
  64. X        else
  65. X        {
  66. X            if ((fp = fopen(real_name(fname), "wb")) == NULL)
  67. X                perror("\aCan't open save file");
  68. X            else
  69. X            {
  70. X                if (fwrite(ram + 256, 256, p, fp) != p)
  71. X                    perror("\aCan't write to file");
  72. X
  73. X                fclose(fp);
  74. X            }
  75. X        }
  76. X    }
  77. X    else if (strcmp(entry, "TYPE") == 0)
  78. X    {
  79. X        char    *ptr;
  80. X
  81. X        while (*tail)
  82. X        {
  83. X            ptr = tail;
  84. X            tail = chop_cmd(ptr);
  85. X            fsystem("cat %s", ptr);
  86. X        }
  87. X    }
  88. X    else if (strcmp(entry, "EXIT") == 0)
  89. X        cleanup(0);
  90. X    else
  91. #ifdef    CPM_DEBUG
  92. X    {
  93. X        time_t    start = time(NULL);
  94. X        int        r = run(real_name(entry));
  95. X
  96. X        fprintf(stderr, "Run took %ld seconds\n\r", time(NULL) - start);
  97. X        return(r);
  98. X    }
  99. #else
  100. X        return(run(real_name(entry)));
  101. #endif
  102. X
  103. X    return(0);
  104. }
  105. #endif
  106. X
  107. void    main(int argc, char **argv)
  108. {
  109. #ifdef    COMPILE_TEST
  110. X    /* test code useful for testing different architectures */
  111. X    int        test;
  112. X
  113. X    test = (int)(&acc);
  114. X    printf("Position of A = %d\n", (int)(&A) - test);
  115. X    printf("Position of FLAGS = %d\n", (int)(&FLAGS) - test);
  116. X
  117. X    test = (int)(&gr);
  118. X    printf("Position of B = %d\n", (int)(&B) - test);
  119. X    printf("Position of C = %d\n", (int)(&C) - test);
  120. X    printf("Position of BC = %d\n", (int)(&BC) - test);
  121. X    printf("Position of D = %d\n", (int)(&D) - test);
  122. X    printf("Position of E = %d\n", (int)(&E) - test);
  123. X    printf("Position of DE = %d\n", (int)(&DE) - test);
  124. X    printf("Position of H = %d\n", (int)(&H) - test);
  125. X    printf("Position of L = %d\n", (int)(&L) - test);
  126. X    printf("Position of HL = %d\n", (int)(&HL) - test);
  127. X
  128. X    AF = 0x1234;
  129. X    printf("AF = %04.4x, A = %02.2x, FLAGS = %02.2x\n", AF, A, FLAGS);
  130. X    printf("Flags: S=%d Z=%d H=%d P=%d N=%d C=%d\n",
  131. X            SIGN, ZERO, HALF_CARRY, PARITY, BCD, CARRY);
  132. X    acc_bank = 1;
  133. X    AF = 0x4321;
  134. X    printf("AF = %04.4x, A = %02.2x, FLAGS = %02.2x\n", AF, A, FLAGS);
  135. X    printf("Flags: S=%d Z=%d H=%d P=%d N=%d C=%d\n",
  136. X            SIGN, ZERO, HALF_CARRY, PARITY, BCD, CARRY);
  137. X
  138. X    BC = 0x2345;
  139. X    printf("BC = %04.4x, B = %02.2x, C = %02.2x\n", BC, B, C);
  140. X    gr_bank = 1;
  141. X    BC = 0x5432;
  142. X    printf("BC = %04.4x, B = %02.2x, C = %02.2x\n", BC, B, C);
  143. X    gr_bank = 0;
  144. X
  145. X    DE = 0x3456;
  146. X    printf("DE = %04.4x, D = %02.2x, E = %02.2x\n", DE, D, E);
  147. X    gr_bank = 1;
  148. X    DE = 0x6543;
  149. X    printf("DE = %04.4x, D = %02.2x, E = %02.2x\n", DE, D, E);
  150. X    gr_bank = 0;
  151. X
  152. X    HL = 0x4567;
  153. X    printf("HL = %04.4x, H = %02.2x, L = %02.2x\n", HL, H, L);
  154. X    gr_bank = 1;
  155. X    HL = 0x7654;
  156. X    printf("HL = %04.4x, H = %02.2x, L = %02.2x\n", HL, H, L);
  157. X    gr_bank = 0;
  158. X
  159. X    A = BC = DE = HL = SP = PC = 0;
  160. X
  161. X    while (PC < TEST_SIZE)
  162. X    {
  163. X        dump_registers(stdout);
  164. X
  165. X        if (decode())
  166. X        {
  167. X            printf("* * * Processor error * * *\n");
  168. X            exit(1);
  169. X        }
  170. X    }
  171. X
  172. X    dump_registers(stdout);
  173. X
  174. X    for (test = 0; test < 0x10; test++)
  175. X        printf("%02.2x ", ram[test]);
  176. X
  177. X    printf("\n");
  178. X    for (test = 0xfff0; test < 0x10000; test++)
  179. X        printf("%02.2x ", ram[test]);
  180. X
  181. X    printf("\nTest code ended normally\n");
  182. X    exit(0);
  183. #else
  184. X
  185. X    char    entry[256];
  186. X    int        c;
  187. X
  188. X    getcwd(cpm_drive[1], 127);
  189. X    entry[0] = 0;
  190. X    debug("");
  191. X
  192. X    while ((c = getopt(argc, argv, "d:c:r:p:h")) != -1)
  193. X    {
  194. X        char    *ptr;
  195. X        int        k;
  196. X
  197. X        switch (c)
  198. X        {
  199. X            case 'd':
  200. X                ptr = optarg + 2;
  201. X
  202. X                if (optarg[1] == ':')
  203. X                    k = toupper(*optarg) - '@';
  204. X                else
  205. X                {
  206. X                    k = 1;
  207. X                    ptr = optarg;
  208. X
  209. X                    while ((k < 17) && (*cpm_drive[k]))
  210. X                        k++;
  211. X                }
  212. X
  213. X                if ((k < 1) || (k > 16))
  214. X                {
  215. X                    fprintf(stderr, "Can't set up %s\n", optarg);
  216. X                    exit(1);
  217. X                }
  218. X
  219. X                strcpy(cpm_drive[k], ptr);
  220. X                break;
  221. X
  222. X            case 'c':
  223. X                strcpy(entry, optarg);
  224. X                break;
  225. X
  226. X            case 'r':
  227. X                reader = open_device(optarg, "r");
  228. X                break;
  229. X
  230. X            case 'p':
  231. X                punch = open_device(optarg, "w");
  232. X                break;
  233. X
  234. X            case 'l':
  235. X                list = open_device(optarg, "w");
  236. X                break;
  237. X
  238. X            default:
  239. X                fprintf(stderr,
  240. "Usage:\n");
  241. X                fprintf(stderr,
  242. "cpm [options]\n");
  243. X                fprintf(stderr,
  244. "  Options:\n");
  245. X                fprintf(stderr,
  246. "    -d [d:]directory    map CP/M drive to Unix directory.  If the\n");
  247. X                fprintf(stderr,
  248. "                        second character is not a colon then the next\n");
  249. X                fprintf(stderr,
  250. "                        available drive letter is used otherwise the\n");
  251. X                fprintf(stderr,
  252. "                        letter preceding the colon is used.\n");
  253. X                fprintf(stderr,
  254. "    -c command          runs the command file then exits.  builtins\n");
  255. X                fprintf(stderr,
  256. "                        not supported.  COM file must exist\n");
  257. X                fprintf(stderr,
  258. "    -[r|p|l] dev        This allows the I/O to be routed through the\n");
  259. X                fprintf(stderr,
  260. "                        Unix file system.  The devices mapped are as\n");
  261. X                fprintf(stderr,
  262. "                        follows: r = RDR input, p = PUN output and l for\n");
  263. X                fprintf(stderr,
  264. "                        LST output.  The dev argument is opened as a Unix\n");
  265. X                fprintf(stderr,
  266. "                        file and I/O for specified device is done through\n");
  267. X                fprintf(stderr,
  268. "                        it.  If the first character is '!' then the rest\n");
  269. X                fprintf(stderr,
  270. "                        of the line is taken as a command and popen() is\n");
  271. X                fprintf(stderr,
  272. "                        called to handle the I/O.\n");
  273. X                fprintf(stderr,
  274. "    -h                  Show this help screen\n");
  275. X
  276. X                exit(1);
  277. X        }
  278. X    }
  279. X    strcpy(cpm_drive[0], cpm_drive[1]);
  280. X    def_drive = 1;
  281. X
  282. X    if ((console = open("/dev/tty", O_RDWR)) == -1)
  283. X    {
  284. X        perror("Can't open terminal");
  285. X        exit(1);
  286. X    }
  287. X
  288. X    if (ioctl(console, TCGETA, &old_term) == -1)
  289. X    {
  290. X        perror("Can't get terminal parameters");
  291. X        exit(-1);
  292. X    }
  293. X
  294. X    termp = old_term;
  295. X    termp.c_oflag =  0;
  296. X    termp.c_lflag =  ISIG;
  297. X    termp.c_cc[VEOF] = 1;
  298. X    termp.c_cc[VSWTCH] = 0xff;
  299. X    
  300. X    if (ioctl(console, TCSETA, &termp) == -1)
  301. X    {
  302. X        perror("Can't set terminal parameters");
  303. X        exit(1);
  304. X    }
  305. X
  306. X    signal(SIGHUP, cleanup);
  307. X    signal(SIGINT, cleanup);
  308. X    signal(SIGQUIT, cleanup);
  309. X    signal(SIGTERM, cleanup);
  310. X    debug("Signals captured");
  311. X
  312. X    setbuf(stdout, NULL);
  313. X
  314. X    fprintf(stderr, "\nCP/U - Control Program for Unix\r\n");
  315. X    fprintf(stderr, "CP/M emulator Version 0.900\r\n");
  316. X    fprintf(stderr, "Written by D'Arcy J.M. Cain\r\n");
  317. X    fprintf(stderr, "darcy@druid.UUCP\r\n");
  318. X
  319. X    if (*entry)
  320. X    {
  321. X        do_command(entry);
  322. X        ioctl(console, TCSETA, &old_term);
  323. X        exit(0);
  324. X    }
  325. X
  326. X    debug("Start main loop");
  327. X
  328. X    for (;;)
  329. X    {
  330. X        fprintf(stderr, "%c> ", def_drive + '@');
  331. X        entry[get_str(entry, 128)] = 0;
  332. X
  333. X        if (*entry)
  334. X        {
  335. X            if (do_command(entry) == -1)
  336. X            {
  337. X                debug("chop_cmd(entry)");
  338. X                chop_cmd(entry);
  339. X                debug("strtoup(entry)");
  340. X                strtoup(entry);
  341. X                debug("fprintf(stderr, \"%s?\r\n\", entry)");
  342. X                fprintf(stderr, "%s?\r\n", entry);
  343. X            }
  344. X        }
  345. X    }
  346. #endif
  347. }
  348. SHAR_EOF
  349. chmod 0640 cpm.c ||
  350. echo 'restore of cpm.c failed'
  351. Wc_c="`wc -c < 'cpm.c'`"
  352. test 26758 -eq "$Wc_c" ||
  353.     echo 'cpm.c: original size 26758, current size' "$Wc_c"
  354. # ============= dasm.c ==============
  355. sed 's/^X//' << 'SHAR_EOF' > 'dasm.c' &&
  356. /*
  357. dasm
  358. X
  359. CP/M emulator - instruction disassembler
  360. Written by D'Arcy J.M. Cain
  361. darcy@druid
  362. X
  363. */
  364. X
  365. #include    <stdio.h>
  366. #include    <string.h>
  367. #include    "cpm.h"
  368. X
  369. #define        get_prog_word(buf)    (buf[1] + (buf[2] << 8))
  370. #define        get_prog_byte(buf)    (*buf)
  371. X
  372. static char        *get_b_reg(int reg)
  373. {
  374. X    switch(reg & 0x07)
  375. X    {
  376. X        case 7:        return("A");
  377. X        case 6:        return("(HL)");
  378. X        case 0:        return("B");
  379. X        case 1:        return("C");
  380. X        case 2:        return("D");
  381. X        case 3:        return("E");
  382. X        case 4:        return("H");
  383. X        case 5:        return("L");
  384. X    }
  385. X
  386. X    return(NULL);
  387. }
  388. X
  389. static char        *get_w_reg(int reg)
  390. {
  391. X    switch (reg & 0x03)
  392. X    {
  393. X        case 2:        return("HL");
  394. X        case 1:        return("DE");
  395. X        case 0:        return("BC");
  396. X        case 3:        return("SP");
  397. X    }
  398. X
  399. X    return(NULL);
  400. }
  401. X
  402. static char        *get_s_reg(int reg)
  403. {
  404. X    switch (reg & 0x03)
  405. X    {
  406. X        case 2:        return("HL");
  407. X        case 1:        return("DE");
  408. X        case 0:        return("BC");
  409. X        case 3:        return("AF");
  410. X    }
  411. X
  412. X    return(NULL);
  413. }
  414. X
  415. static int        relative(int r)
  416. {
  417. X    if (r & 0x80)
  418. X        r |= -256;
  419. X
  420. X    return(PC + r + 2);
  421. }
  422. X
  423. static char        *condition(int word)
  424. {
  425. X    switch (word & 0x07)
  426. X    {
  427. X        case 0:        return("NZ");
  428. X        case 1:        return("Z");
  429. X        case 2:        return("NC");
  430. X        case 3:        return("C");
  431. X        case 4:        return("PO");
  432. X        case 5:        return("PE");
  433. X        case 6:        return("P");
  434. X        case 7:        return("M");
  435. X    }
  436. X
  437. X    return("\a* * * Internal error (condition()) * * *");
  438. }
  439. X
  440. const char     *dasm(const byte *buf)
  441. {
  442. X    static char    str[32];
  443. X    char        s[32];
  444. X
  445. X    switch (*buf & 0xc0)                /* get class of opcode */
  446. X    {
  447. X        case 0x40:                        /* data transfer */
  448. X            if (*buf == 0x76)            /* HALT - special case */
  449. X                return("HALT");
  450. X
  451. X            sprintf(str, "LD\t%s, %s", get_b_reg(*buf >> 3), get_b_reg(*buf));
  452. X            return(str);
  453. X
  454. X        case 0x80:                        /* 8 bit math & logic */
  455. X            strcpy(s, get_b_reg(*buf));
  456. X            strcpy(str, "* * * Internal error * * *");
  457. X
  458. math_immediate:                            /* comes from misc instructions */
  459. X            switch ((*buf >> 3) & 7)        /* logic op */
  460. X            {
  461. X                case 1:                    /* ADC */
  462. X                    sprintf(str, "ADC\tA, %s", s);
  463. X                    break;
  464. X
  465. X                case 0:                    /* ADD */
  466. X                    sprintf(str, "ADD\tA, %s", s);
  467. X                    break;
  468. X    
  469. X                case 3:                    /* SBC */
  470. X                    sprintf(str, "SBC\tA, %s", s);
  471. X                    break;
  472. X
  473. X                case 2:                    /* SUB */
  474. X                    sprintf(str, "SUB\tA, %s", s);
  475. X                    break;
  476. X
  477. X                case 4:                    /* AND */
  478. X                    sprintf(str, "AND\tA, %s", s);
  479. X                    break;
  480. X
  481. X                case 5:                    /* XOR */
  482. X                    sprintf(str, "XOR\tA, %s", s);
  483. X                    break;
  484. X
  485. X                case 6:                    /* OR */
  486. X                    sprintf(str, "OR\tA, %s", s);
  487. X                    break;
  488. X
  489. X                case 7:                    /* CP */
  490. X                    sprintf(str, "CP\tA, %s", s);
  491. X                    break;
  492. X            }                            /* end - logic op */
  493. X
  494. X            return(str);
  495. X
  496. X        case 0xc0:                        /* Misc */
  497. X            if ((*buf & 0x07) == 0x06)
  498. X            {
  499. X                sprintf(s, "0%02.2xH", buf[1]);
  500. X                goto math_immediate;    /* sometimes they're necessary */
  501. X            }
  502. X
  503. X            if ((*buf & 0x0f) == 1)        /* POP */
  504. X            {
  505. X                sprintf(str, "POP\t%s", get_s_reg(*buf >> 4));
  506. X                return(str);
  507. X            }
  508. X
  509. X            if ((*buf & 0x0f) == 5)        /* PUSH */
  510. X            {
  511. X                sprintf(str, "PUSH\t%s", get_s_reg(*buf >> 4));
  512. X                return(str);
  513. X            }
  514. X
  515. X
  516. X            switch (*buf & 0x07)        /* BRANCH */
  517. X            {
  518. X                case 0:                    /* RET cc */
  519. X                    sprintf(str, "RET\t%s", condition(*buf >> 3));
  520. X                    return(str);
  521. X
  522. X                case 2:                    /* JP cc */
  523. X                    sprintf(str, "JP\t%s, 0%02.2x%02.2xH",
  524. X                                condition(*buf >> 3), buf[2], buf[1]);
  525. X                    return(str);
  526. X
  527. X                case 4:                    /* CALL cc */
  528. X                    sprintf(str, "CALL\t%s, 0%02.2x%02.2xH",
  529. X                                condition(*buf >> 3), buf[2], buf[1]);
  530. X                    return(str);
  531. X
  532. X                case 7:                    /* RST n */
  533. X                    sprintf(str, "RST\t%d", (*buf >> 3) & 0x07);
  534. X                    return(str);
  535. X            }                            /* end - BRANCH */
  536. X
  537. X            switch (*buf)                /* misc */
  538. X            {
  539. X                case 0xcd:                /* CALL */
  540. X                    sprintf(str, "CALL\t0%02.2x%02.2xH", buf[2], buf[1]);
  541. X                    return(str);
  542. X
  543. X                case 0xc3:                /* JP */
  544. X                    sprintf(str, "JP\t0%02.2x%02.2xH", buf[2], buf[1]);
  545. X                    return(str);
  546. X
  547. X                case 0xc9:                /* RET */
  548. X                    sprintf(str, "RET");
  549. X                    return(str);
  550. X
  551. X                case 0xeb:                /* EX DE, HL */
  552. X                    return("EX\tDE, HL");
  553. X
  554. X                case 0xe9:                /* JP (HL) */
  555. X                    return("JP\t(HL)");
  556. X
  557. X                case 0xe3:                /* EX (SP), HL */
  558. X                    return("EX\t(SP), HL");
  559. X
  560. X                case 0xf9:                /* LD SP, HL */
  561. X                    return("LD\tSP, HL");
  562. X
  563. X                case 0xf3:                /* DI */
  564. X                    return("DI");
  565. X
  566. X                case 0xfb:                /* EI */
  567. X                    return("EI");
  568. X            }                                /* misc */
  569. X
  570. X            sprintf(str, "Unrecognized command (0x%02.2x)", *buf);
  571. X            return(str);
  572. X
  573. X        case 0:
  574. X            switch (*buf & 0x07)            /* misc data (3) */
  575. X            {
  576. X                case 4:                        /* INC byte */
  577. X                    sprintf(str, "INC\t%s", get_b_reg(*buf >> 3));
  578. X                    return(str);
  579. X
  580. X                case 5:                        /* DEC byte */
  581. X                    sprintf(str, "DEC\t%s", get_b_reg(*buf >> 3));
  582. X                    return(str);
  583. X
  584. X                case 6:                        /* LD byte immediate */
  585. X                    sprintf(str, "LD\t%s, 0%02.2xH",
  586. X                                get_b_reg(*buf >> 3), buf[1]);
  587. X                    return(str);
  588. X            }                                /* end - misc data (3) */
  589. X
  590. X            switch (*buf & 0x0f)            /* misc data (4) */
  591. X            {
  592. X                case 1:                        /* LD word immediate */
  593. X                    sprintf(str, "LD\t%s, 0%02.2x%02.2xH",
  594. X                                get_w_reg(*buf >> 4), buf[2], buf[1]);
  595. X                    return(str);
  596. X
  597. X                case 0x03:                    /* INC word */
  598. X                    sprintf(str, "INC\t%s", get_w_reg(*buf >> 4));
  599. X                    return(str);
  600. X
  601. X                case 0x0b:                    /* DEC word */
  602. X                    sprintf(str, "DEC\t%s", get_w_reg(*buf >> 4));
  603. X                    return(str);
  604. X
  605. X                case 0x09:                    /* ADD HL, ss */
  606. X                    sprintf(str, "ADD\tHL, %s", get_w_reg(*buf >> 4));
  607. X                    return(str);
  608. X            }                                /* end - misc date (4) */
  609. X
  610. X            switch (*buf)                    /* misc data */
  611. X            {
  612. X                case 0:                        /* NOP */
  613. X                    return("NOP");
  614. X
  615. X                case 0x02:                    /* LD (BC), A */
  616. X                    return("LD\t(BC), A");
  617. X
  618. X                case 0x10:
  619. X                    sprintf(str, "DJNZ\t0%04.4xH", relative(buf[1]));
  620. X                    return(str);
  621. X
  622. X                case 0x20:
  623. X                    sprintf(str, "JR\tNZ, 0%04.4xH", relative(buf[1]));
  624. X                    return(str);
  625. X
  626. X                case 0x30:
  627. X                    sprintf(str, "JR\tNC, 0%04.4xH", relative(buf[1]));
  628. X                    return(str);
  629. X
  630. X                case 0x18:
  631. X                    sprintf(str, "JR\t, 0%04.4xH", relative(buf[1]));
  632. X                    return(str);
  633. X
  634. X                case 0x28:
  635. X                    sprintf(str, "JR\tZ, 0%04.4xH", relative(buf[1]));
  636. X                    return(str);
  637. X
  638. X                case 0x38:
  639. X                    sprintf(str, "JR\tC, 0%04.4xH", relative(buf[1]));
  640. X                    return(str);
  641. X
  642. X                case 0x12:                    /* LD (DE), A */
  643. X                    return("LD\t(DE), A");
  644. X
  645. X                case 0x22:                    /* LD (nn), HL */
  646. X                    sprintf(str, "LD\t(0%02.2x%02.2xH), HL", buf[2], buf[1]);
  647. X                    return(str);
  648. X
  649. X                case 0x32:                    /* LD (nn), A */
  650. X                    sprintf(str, "LD\t(0%02.2x%02.2xH), A", buf[2], buf[1]);
  651. X                    return(str);
  652. X
  653. X                case 0x0a:                    /* LD A, (BC) */
  654. X                    return("LD\tA, (BC)");
  655. X
  656. X                case 0x1a:                    /* LD A, (DE) */
  657. X                    return("LD\tA, (DE)");
  658. X
  659. X                case 0x2a:                    /* LD HL, (nn) */
  660. X                    sprintf(str, "LD\tHL, (0%02.2x%02.2xH)", buf[2], buf[1]);
  661. X                    return(str);
  662. X
  663. X                case 0x3a:                    /* LD A, (nn) */
  664. X                    sprintf(str, "LD\tA, (0%02.2x%02.2xH)", buf[2], buf[1]);
  665. X                    return(str);
  666. X
  667. X                case 7:                        /* RLCA */
  668. X                    return("RLCA");
  669. X
  670. X                case 0x0f:                    /* RRCA */
  671. X                    return("RRCA");
  672. X
  673. X                case 0x17:                    /* RLA */
  674. X                    return("RLA");
  675. X
  676. X                case 0x1f:                    /* RRA */
  677. X                    return("RRA");
  678. X
  679. X                case 0x27:                    /* DAA */
  680. X                    return("DAA");
  681. X
  682. X                case 0x2f:                    /* CPL */
  683. X                    return("CPL");
  684. X
  685. X                case 0x37:                    /* SCF */
  686. X                    return("SCF");
  687. X
  688. X                case 0x3f:                    /* CCF */
  689. X                    return("CCF");
  690. X            }                                /* end - misc date */
  691. X
  692. X            return("* * * Internal error * * *");
  693. X    }                                        /* end class */
  694. X
  695. X    return("* * * Internal error * * *");
  696. }
  697. SHAR_EOF
  698. chmod 0640 dasm.c ||
  699. echo 'restore of dasm.c failed'
  700. Wc_c="`wc -c < 'dasm.c'`"
  701. test 7099 -eq "$Wc_c" ||
  702.     echo 'dasm.c: original size 7099, current size' "$Wc_c"
  703. # ============= decode.c ==============
  704. sed 's/^X//' << 'SHAR_EOF' > 'decode.c' &&
  705. /*
  706. X * execute()
  707. X *
  708. X * There are 256 possible opcodes.  The switch statement selects one.
  709. X * $Header: /g/zmob/zrun/RCS/execute.c,v 1.1.1.5 84/04/19 17:51:14 bennet Exp $
  710. X */
  711. X
  712. #include    "cpm.h"
  713. X
  714. static byte    partab[256]=        /* Parity table, 1=even */
  715. {
  716. X    1,0,0,1,0,1,1,0, 0,1,1,0,1,0,0,1,
  717. X    0,1,1,0,1,0,0,1, 1,0,0,1,0,1,1,0,
  718. X    0,1,1,0,1,0,0,1, 1,0,0,1,0,1,1,0,
  719. X    1,0,0,1,0,1,1,0, 0,1,1,0,1,0,0,1,
  720. X    0,1,1,0,1,0,0,1, 1,0,0,1,0,1,1,0,
  721. X    1,0,0,1,0,1,1,0, 0,1,1,0,1,0,0,1,
  722. X    1,0,0,1,0,1,1,0, 0,1,1,0,1,0,0,1,
  723. X    0,1,1,0,1,0,0,1, 1,0,0,1,0,1,1,0,
  724. X    0,1,1,0,1,0,0,1, 1,0,0,1,0,1,1,0,
  725. X    1,0,0,1,0,1,1,0, 0,1,1,0,1,0,0,1,
  726. X    1,0,0,1,0,1,1,0, 0,1,1,0,1,0,0,1,
  727. X    0,1,1,0,1,0,0,1, 1,0,0,1,0,1,1,0,
  728. X    1,0,0,1,0,1,1,0, 0,1,1,0,1,0,0,1,
  729. X    0,1,1,0,1,0,0,1, 1,0,0,1,0,1,1,0,
  730. X    0,1,1,0,1,0,0,1, 1,0,0,1,0,1,1,0,
  731. X    1,0,0,1,0,1,1,0, 0,1,1,0,1,0,0,1,
  732. };
  733. X
  734. static byte    setmask[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
  735. static byte    resmask[] = { ~1, ~2, ~4, ~8, ~16, ~32, ~64, ~128 };
  736. X
  737. int        pop(void)
  738. {
  739. X    long    r = ram[SP++];
  740. X    return(r + (ram[SP++] << 8));
  741. }
  742. X
  743. void    push(int v)
  744. {
  745. X    ram[--SP] = v >> 8;
  746. X    ram[--SP] = v & 0xff;
  747. }
  748. X
  749. int        decode(void)
  750. {
  751. X    byte    *ptr;
  752. X    long    a, s, s1;
  753. X    byte    opcode = ram[PC++];
  754. X
  755. X    if (PC >= BDOS)
  756. X    {
  757. X        PC = pop();
  758. X        return(0);
  759. X    }
  760. X
  761. X    switch(opcode)
  762. X    {
  763. X    case 0:            /* 00 NOP */
  764. X    when 1:            /* 01 LD BC,nn */
  765. X        C = ram[PC++];
  766. X        B = ram[PC++];
  767. X    when 2:            /* 02 LD (BC),A */
  768. X        ram[BC] = A;
  769. X    when 3:            /* 03 INC BC */
  770. X        ++BC;
  771. X    when 4:            /* 04 INC B */
  772. X        HALF_CARRY = (lonyb(B) == 0xf);
  773. X        ++B;
  774. X        SIGN = B >> 7;
  775. X        ZERO = B == 0;
  776. X        PARITY = B == 0x80;
  777. X        BCD = 0;
  778. X    when 5:            /* 05 DEC B */
  779. X        HALF_CARRY = lonyb(B) != 0;
  780. X        --B;
  781. X        SIGN = B >> 7;
  782. X        ZERO = B == 0;
  783. X        PARITY = B == 0x7f;
  784. X        BCD = 1;
  785. X    when 6:            /* 06 LD B,n */
  786. X        B = ram[PC++];
  787. X    when 7:            /* 07 RLCA */
  788. X        HALF_CARRY = BCD = 0;
  789. X        CARRY = A >> 7;
  790. X        A = (A << 1);
  791. X        if (CARRY) ++A;
  792. X    when 8:            /* 08 EX AF,AF' */
  793. X        acc_bank = acc_bank ? 0 : 1;
  794. X    when 9:            /* 09 ADD HL,BC */
  795. X        s = BC;
  796. X        a = (HL & 0xfff) + (s & 0xfff);
  797. X        s += HL;
  798. X        HL = s;
  799. X        BCD = 0;
  800. X        CARRY = s >> 16;
  801. X        HALF_CARRY = a >> 12;
  802. X    when 10:        /* 0a LD A,(BC) */
  803. X        A = ram[BC];
  804. X    when 11:        /* 0b DEC BC */
  805. X        --BC;
  806. X    when 12:        /* 0c INC C */
  807. X        HALF_CARRY = lonyb(C) == 0xf;
  808. X        ++C;
  809. X        SIGN = C >> 7;
  810. X        ZERO = C == 0;
  811. X        PARITY = C == 0x80;
  812. X        BCD = 0;
  813. X    when 13:        /* 0d DEC C */
  814. X        HALF_CARRY = lonyb(C) != 0;
  815. X        --C;
  816. X        SIGN = C >> 7;
  817. X        ZERO = C == 0;
  818. X        PARITY = C == 0x7f;
  819. X        BCD = 1;
  820. X    when 14:        /* 0e LD C,n */
  821. X        C = ram[PC++];
  822. X    when 15:        /* 0f RRCA */
  823. X        BCD = HALF_CARRY = 0;
  824. X        CARRY = A;
  825. X        A = (A >> 1) | (CARRY ? 128 : 0);
  826. X    when 16:        /* 10 DJNZ e */
  827. X        s = (int)(ram[PC++]);
  828. X        if (--B) PC += s;
  829. X    when 17:        /* 11 LD DE,nn */
  830. X        E = ram[PC++];
  831. X        D = ram[PC++];
  832. X    when 18:        /* 12 LD (DE),A */
  833. X        ram[DE] = A;
  834. X    when 19:        /* 13 INC DE */
  835. X        ++DE;
  836. X    when 20:        /* 14 INC D */
  837. X        HALF_CARRY = lonyb(D) == 0xf;
  838. X        ++D;
  839. X        SIGN = D >> 7;
  840. X        ZERO = D == 0;
  841. X        PARITY = D == 0x80;
  842. X        BCD = 0;
  843. X    when 21:        /* 15 DEC D */
  844. X        HALF_CARRY = lonyb(D) != 0;
  845. X        --D;
  846. X        SIGN = D >> 7;
  847. X        ZERO = D == 0;
  848. X        PARITY = D == 0x7f;
  849. X        BCD = 1;
  850. X    when 22:        /* 16 LD D,n */
  851. X        D = ram[PC++];
  852. X    when 23:        /* 17 RLA */
  853. X        s = A << 1;
  854. X        A = s | CARRY;
  855. X        CARRY = s >> 8;
  856. X        BCD = HALF_CARRY = 0;
  857. X    when 24:        /* 18 JR e */
  858. X        PC += (int)(ram[PC]);
  859. X    when 25:        /* 19 ADD HL,DE */
  860. X        s = DE;
  861. X        a = (HL & 0xfff) + (s & 0xfff);
  862. X        s += HL;
  863. X        HL = s;
  864. X        BCD = 0;
  865. X        CARRY = s >> 16;
  866. X        HALF_CARRY = a >> 12;
  867. X    when 26:        /* 1a LD A,(DE) */
  868. X        A = ram[DE];
  869. X    when 27:        /* 1b DEC DE */
  870. X        --DE;
  871. X    when 28:        /* 1c INC E */
  872. X        HALF_CARRY = lonyb(E) == 0xf;
  873. X        ++E;
  874. X        SIGN = E >> 7;
  875. X        ZERO = E == 0;
  876. X        PARITY = E == 0x80;
  877. X        BCD = 0;
  878. X    when 29:        /* 1d DEC E */
  879. X        HALF_CARRY = lonyb(E) != 0;
  880. X        --E;
  881. X        SIGN = E >> 7;
  882. X        ZERO = E == 0;
  883. X        PARITY = E == 0x7f;
  884. X        BCD = 1;
  885. X    when 30:        /* 1e LD E,n */
  886. X        E = ram[PC++];
  887. X    when 31:        /* 1f RRA */
  888. X        CARRY = (s = A | (CARRY << 8));
  889. X        A = s >> 1;
  890. X        BCD = HALF_CARRY = 0;
  891. X    when 32:        /* 20 JR NZ,e */
  892. X        if (ZERO) ++PC;
  893. X        else PC += (int)(ram[PC]);
  894. X    when 33:        /* 21 LD HL,nn */
  895. X        L = ram[PC++];
  896. X        H = ram[PC++];
  897. X    when 34:        /* 22 LD (nn),HL */
  898. X        TEMPL = ram[PC++];
  899. X        TEMPH = ram[PC++];
  900. X        ram[TEMP] = L;
  901. X        ram[TEMP + 1] = H;
  902. X    when 35:        /* 23 INC HL */
  903. X        ++HL;
  904. X    when 36:        /* 24 INC H */
  905. X        HALF_CARRY = lonyb(H) == 0xf;
  906. X        ++H;
  907. X        SIGN = H >> 7;
  908. X        ZERO = H == 0;
  909. X        PARITY = H == 0x80;
  910. X        BCD = 0;
  911. X    when 37:        /* 25 DEC H */
  912. X        HALF_CARRY = lonyb(H) != 0;
  913. X        --H;
  914. X        SIGN = H >> 7;
  915. X        ZERO = H == 0;
  916. X        PARITY = H == 0x7f;
  917. X        BCD = 1;
  918. X    when 38:        /* 26 LD H,n */
  919. X        H = ram[PC++];
  920. X    when 39:        /* 27 DAA */
  921. X        s = A & 0x0f;
  922. X        a = (A >> 4) & 0x0f;
  923. X        s1 = 0;
  924. X
  925. X        if (BCD)
  926. X        {
  927. X            if (CARRY)
  928. X            {
  929. X                if (HALF_CARRY)
  930. X                    s1 = ((a > 5) && (s > 5)) ? 0x9a : 0;
  931. X                else
  932. X                    s1 = ((a > 6) && (s < 10)) ? 0xa0 : 0;
  933. X            }
  934. X            else
  935. X                if(HALF_CARRY)
  936. X                    s1 = ((a < 9) && (s > 5)) ? 0xfa : 0;
  937. X        }
  938. X        else
  939. X        {
  940. X            if (CARRY)
  941. X            {
  942. X                if(HALF_CARRY)
  943. X                    s1 = ((a < 4) && (s < 4)) ? 0x66 : 0;
  944. X                else if (a < 3)
  945. X                    s1 = (s < 10) ? 0x60 : 0x66;
  946. X            }
  947. X            else
  948. X            {
  949. X                if(HALF_CARRY)
  950. X                {
  951. X                    if (s < 4)
  952. X                        if (a > 9)
  953. X                        {
  954. X                            s1 = 0x66;
  955. X                            CARRY = 1;
  956. X                        }
  957. X                        else s1 = 0x06;
  958. X                }
  959. X                else
  960. X                {
  961. X                    if ((a > 8) && (s > 9))
  962. X                    {
  963. X                        s1 = 0x66;
  964. X                        CARRY = 1;
  965. X                    }
  966. X                    else if ((a > 9) && (s < 10))
  967. X                    {
  968. X                        s1 = 0x60;
  969. X                        CARRY = 1;
  970. X                    }
  971. X                    else if ((a < 10) && (s < 10))
  972. X                            ;
  973. X                    else if ((a < 9) && (s > 9))
  974. X                        s1 = 6;
  975. X                }
  976. X            }
  977. X        }
  978. X
  979. X        HALF_CARRY = ((int)(A) + (int)(s1)) > 0xf;
  980. X        A += s1;
  981. X        SIGN = A >> 7;
  982. X        ZERO = (A == 0);
  983. X        PARITY = partab[A];
  984. X    when 40:        /* 28 JR Z,e */
  985. X        if (ZERO) PC += (int)(ram[PC]);
  986. X        else ++PC;
  987. X    when 41:        /* 29 ADD HL,HL */
  988. X        s = HL;
  989. X        a = (HL & 0xfff) + (s & 0xfff);
  990. X        s += HL;
  991. X        HL = s;
  992. X        BCD = 0;
  993. X        CARRY = s >> 16;
  994. X        HALF_CARRY = a >> 12;
  995. X    when 42:        /* 2a LD HL,(nn) */
  996. X        TEMPL = ram[PC++];
  997. X        TEMPH = ram[PC++];
  998. X        L = ram[TEMP];
  999. X        H = ram[TEMP + 1];
  1000. X    when 43:        /* 2b DEC HL */
  1001. X        --HL;
  1002. X    when 44:        /* 2c INC L */
  1003. X        HALF_CARRY = lonyb(L) == 0xf;
  1004. X        ++L;
  1005. X        SIGN = L >> 7;
  1006. X        ZERO = L == 0;
  1007. X        PARITY = L == 0x80;
  1008. X        BCD = 0;
  1009. X    when 45:        /* 2d DEC L */
  1010. X        HALF_CARRY = lonyb(L) != 0;
  1011. X        --L;
  1012. X        SIGN = L >> 7;
  1013. X        ZERO = L == 0;
  1014. X        PARITY = L == 0x7f;
  1015. X        BCD = 1;
  1016. X    when 46:        /* 2e LD L,n */
  1017. X        L = ram[PC++];
  1018. X    when 47:        /* 2f CPL */
  1019. X        A = ~A;
  1020. X        HALF_CARRY = BCD = 1;
  1021. X    when 48:        /* 30 JR NC,e */
  1022. X        if(CARRY) ++PC;
  1023. X        else PC += (int)(ram[PC]);
  1024. X    when 49:        /* 31 LD SP,nn */
  1025. X        SPL = ram[PC++];
  1026. X        SPH = ram[PC++];
  1027. X    when 50:        /* 32 LD (nn),A */
  1028. X        TEMPL = ram[PC++];
  1029. X        TEMPH = ram[PC++];
  1030. X        ram[TEMP] = A;
  1031. X    when 51:        /* 33 INC SP */
  1032. X        ++SP;
  1033. X    when 52:        /* 34 INC (HL) */
  1034. X        HALF_CARRY = lonyb(ram[HL]) == 0xf;
  1035. X        ++ram[HL];
  1036. X        SIGN = ram[HL] >> 7;
  1037. X        ZERO = ram[HL] == 0;
  1038. X        PARITY = ram[HL] == 0x80;
  1039. X        BCD = 0;
  1040. X    when 53:        /* 35 DEC (HL) */
  1041. X        HALF_CARRY = lonyb(ram[HL]) != 0;
  1042. X        --ram[HL];
  1043. X        SIGN = ram[HL] >> 7;
  1044. X        ZERO = ram[HL] == 0;
  1045. X        PARITY = ram[HL] == 0x7f;
  1046. X        BCD = 1;
  1047. X    when 54:        /* 36 LD (HL),n */
  1048. X        ram[HL] = ram[PC++];
  1049. X    when 55:        /* 37 SCF */
  1050. X        HALF_CARRY = BCD = 0;
  1051. X        CARRY = 1;
  1052. X    when 56:        /* 38 JR C,e */
  1053. X        if (CARRY) PC += (int)(ram[PC]);
  1054. X        else ++PC;
  1055. X    when 57:        /* 39 ADD HL,SP */
  1056. X        s = SP;
  1057. X        a = (HL & 0xfff) + (s & 0xfff);
  1058. X        s += HL;
  1059. X        HL = s;
  1060. X        BCD = 0;
  1061. X        CARRY = s >> 16;
  1062. X        HALF_CARRY = a >> 12;
  1063. X    when 58:        /* 3a LD A,(nn) */
  1064. X        TEMPL = ram[PC++];
  1065. X        TEMPH = ram[PC++];
  1066. X        A = ram[TEMP];
  1067. X    when 59:        /* 3b DEC SP */
  1068. X        --SP;
  1069. X    when 60:        /* 3c INC A */
  1070. X        HALF_CARRY = lonyb(A) == 0xf;
  1071. X        ++A;
  1072. X        SIGN = A >> 7;
  1073. X        ZERO = A == 0;
  1074. X        PARITY = A == 0x80;
  1075. X        BCD = 0;
  1076. X    when 61:        /* 3d DEC A */
  1077. X        HALF_CARRY = lonyb(A) != 0;
  1078. X        --A;
  1079. X        SIGN = A >> 7;
  1080. X        ZERO = A == 0;
  1081. X        PARITY = A == 0x7f;
  1082. X        BCD = 1;
  1083. X    when 62:        /* 3e LD A,n */
  1084. X        A = ram[PC++];
  1085. X    when 63:        /* 3f CCF */
  1086. X        HALF_CARRY = CARRY;
  1087. X        CARRY = ~CARRY;
  1088. X        BCD = 0;
  1089. X    when 64:        /* 40 LD B,B */
  1090. X    when 65:        /* 41 LD B,C */
  1091. X        B = C;
  1092. X    when 66:        /* 42 LD B,D */
  1093. X        B = D;
  1094. X    when 67:        /* 43 LD B,E */
  1095. X        B = E;
  1096. X    when 68:        /* 44 LD B,H */
  1097. X        B = H;
  1098. X    when 69:        /* 45 LD B,L */
  1099. X        B = L;
  1100. X    when 70:        /* 46 LD B, (HL) */
  1101. X        B = ram[HL];
  1102. X    when 71:        /* 47 LD B,A */
  1103. X        B = A;
  1104. X    when 72:        /* 48 LD C,B */
  1105. X        C = B;
  1106. X    when 73:        /* 49 LD C,C */
  1107. X    when 74:        /* 4a LD C,D */
  1108. X        C = D;
  1109. X    when 75:        /* 4b LD C,E */
  1110. X        C = E;
  1111. X    when 76:        /* 4c LD C,H */
  1112. X        C = H;
  1113. X    when 77:        /* 4d LD C,L */
  1114. X        C = L;
  1115. X    when 78:        /* 4e LD C, (HL) */
  1116. X        C = ram[HL];
  1117. X    when 79:        /* 4f LD C,A */
  1118. X        C = A;
  1119. X    when 80:        /* 50 LD D,B */
  1120. X        D = B;
  1121. X    when 81:        /* 51 LD D,C */
  1122. X        D = C;
  1123. X    when 82:        /* 52 LD D,D */
  1124. X    when 83:        /* 53 LD D,E */
  1125. X        D = E;
  1126. X    when 84:        /* 54 LD D,H */
  1127. X        D = H;
  1128. X    when 85:        /* 55 LD D,L */
  1129. X        D = L;
  1130. X    when 86:        /* 56 LD D, (HL) */
  1131. X        D = ram[HL];
  1132. X    when 87:        /* 57 LD D,A */
  1133. X        D = A;
  1134. X    when 88:        /* 58 LD E,B */
  1135. X        E = B;
  1136. X    when 89:        /* 59 LD E,C */
  1137. X        E = C;
  1138. X    when 90:        /* 5a LD E,D */
  1139. X        E = D;
  1140. X    when 91:        /* 5b LD E,E */
  1141. X    when 92:        /* 5c LD E,H */
  1142. X        E = H;
  1143. X    when 93:        /* 5d LD E,L */
  1144. X        E = L;
  1145. X    when 94:        /* 5e LD E, (HL) */
  1146. X        E = ram[HL];
  1147. X    when 95:        /* 5f LD E,A */
  1148. X        E = A;
  1149. X    when 96:        /* 60 LD H,B */
  1150. X        H = B;
  1151. X    when 97:        /* 61 LD H,C */
  1152. X        H = C;
  1153. X    when 98:        /* 62 LD H,D */
  1154. X        H = D;
  1155. X    when 99:        /* 63 LD H,E */
  1156. X        H = E;
  1157. X    when 100:        /* 64 LD H,H */
  1158. X    when 101:        /* 65 LD H,L */
  1159. X        H = L;
  1160. X    when 102:        /* 66 LD H, (HL) */
  1161. X        H = ram[HL];
  1162. X    when 103:        /* 67 LD H,A */
  1163. X        H = A;
  1164. X    when 104:        /* 68 LD L,B */
  1165. X        L = B;
  1166. X    when 105:        /* 69 LD L,C */
  1167. X        L = C;
  1168. X    when 106:        /* 6a LD L,D */
  1169. X        L = D;
  1170. X    when 107:        /* 6b LD L,E */
  1171. X        L = E;
  1172. X    when 108:        /* 6c LD L,H */
  1173. X        L = H;
  1174. X    when 109:        /* 6d LD L,L */
  1175. X    when 110:        /* 6e LD L,(HL) */
  1176. X        L = ram[HL];
  1177. X    when 111:        /* 6f LD L,A */
  1178. X        L = A;
  1179. X    when 112:        /* 70 LD (HL),B */
  1180. X        ram[HL] = B;
  1181. X    when 113:        /* 71 LD (HL),C */
  1182. X        ram[HL] = C;
  1183. X    when 114:        /* 72 LD (HL),D */
  1184. X        ram[HL] = D;
  1185. X    when 115:        /* 73 LD (HL),E */
  1186. X        ram[HL] = E;
  1187. X    when 116:        /* 74 LD (HL),H */
  1188. X        ram[HL] = H;
  1189. X    when 117:        /* 75 LD (HL),L */
  1190. X        ram[HL] = L;
  1191. X    when 118:        /* 76 HALT */
  1192. X        return(0x76);
  1193. X    when 119:        /* 77 LD (HL),A */
  1194. X        ram[HL] = A;
  1195. X    when 120:        /* 78 LD A,B */
  1196. X        A = B;
  1197. X    when 121:        /* 79 LD A,C */
  1198. X        A = C;
  1199. X    when 122:        /* 7a LD A,D */
  1200. X        A = D;
  1201. X    when 123:        /* 7b LD A,E */
  1202. X        A = E;
  1203. X    when 124:        /* 7c LD A,H */
  1204. X        A = H;
  1205. X    when 125:        /* 7d LD A,L */
  1206. X        A = L;
  1207. X    when 126:        /* 7e LD A,(HL) */
  1208. X        A = ram[HL];
  1209. X    when 127:        /* 7f LD A,A */
  1210. X    when 128:        /* 80 ADD A,B */
  1211. X        s = B;
  1212. X        goto add;
  1213. X    case 129:        /* 81 ADD A,C */
  1214. X        s = C;
  1215. X        goto add;
  1216. X    case 130:        /* 82 ADD A,D */
  1217. X        s = D;
  1218. X        goto add;
  1219. X    case 131:        /* 83 ADD A,E */
  1220. X        s = E;
  1221. X        goto add;
  1222. X    case 132:        /* 84 ADD A,H */
  1223. X        s = H;
  1224. X        goto add;
  1225. X    case 133:        /* 85 ADD A,L */
  1226. X        s = L;
  1227. X        goto add;
  1228. X    case 134:        /* 86 ADD A,(HL) */
  1229. X        s = ram[HL];
  1230. X        goto add;
  1231. X    case 135:        /* 87 ADD A,A */
  1232. X        s = A;
  1233. X        goto add;
  1234. X    case 136:        /* 88 ADC A,B */
  1235. X        s = B;
  1236. X        goto adc;
  1237. X    case 137:        /* 89 ADC A,C */
  1238. X        s = C;
  1239. X        goto adc;
  1240. X    case 138:        /* 8a ADC A,D */
  1241. X        s = D;
  1242. X        goto adc;
  1243. X    case 139:        /* 8b ADC A,E */
  1244. X        s = E;
  1245. X        goto adc;
  1246. X    case 140:        /* 8c ADC A,H */
  1247. X        s = H;
  1248. X        goto adc;
  1249. X    case 141:        /* 8d ADC A,L */
  1250. X        s = L;
  1251. X        goto adc;
  1252. X    case 142:        /* 8e ADC A,(HL) */
  1253. X        s = ram[HL];
  1254. X        goto adc;
  1255. X    case 143:        /* 8f ADC A,A */
  1256. X        s = A;
  1257. X
  1258. adc:
  1259. X        a = A & 0x0f;
  1260. X        s1 = s & 0x0f;
  1261. X        if (CARRY) { s++; a++; }
  1262. X        goto add1;
  1263. X
  1264. add:
  1265. X        a = A & 0x0f;
  1266. X        s1 = s & 0x0f;
  1267. X
  1268. add1:
  1269. X        BCD = 0;
  1270. X        s += A;
  1271. X        A = s;
  1272. X        a += s1;
  1273. X
  1274. set_flags:
  1275. X        CARRY = s >> 8;
  1276. X        HALF_CARRY = a >> 4;
  1277. X        SIGN = s >> 7;
  1278. X        ZERO = s ? 0 : 1;
  1279. X        PARITY = partab[A];
  1280. X
  1281. X    when 144:        /* 90 SUB A,B */
  1282. X        s = B;
  1283. X        goto sub;
  1284. X    case 145:        /* 91 SUB A,C */
  1285. X        s = C;
  1286. X        goto sub;
  1287. X    case 146:        /* 92 SUB A,D */
  1288. X        s = D;
  1289. X        goto sub;
  1290. X    case 147:        /* 93 SUB A,E */
  1291. X        s = E;
  1292. X        goto sub;
  1293. X    case 148:        /* 94 SUB A,H */
  1294. X        s = H;
  1295. X        goto sub;
  1296. X    case 149:        /* 95 SUB A,L */
  1297. X        s = L;
  1298. X        goto sub;
  1299. X    case 150:        /* 96 SUB A,(HL) */
  1300. X        s = ram[HL];
  1301. X        goto sub;
  1302. X    case 151:        /* 97 SUB A,A */
  1303. X        s = A;
  1304. X        goto sub;
  1305. X    case 152:        /* 98 SBC A,B */
  1306. X        s = B;
  1307. X        goto sbc;
  1308. X    case 153:        /* 99 SBC A,C */
  1309. X        s = C;
  1310. X        goto sbc;
  1311. X    case 154:        /* 9a SBC A,D */
  1312. X        s = D;
  1313. X        goto sbc;
  1314. X    case 155:        /* 9b SBC A,E */
  1315. X        s = E;
  1316. X        goto sbc;
  1317. X    case 156:        /* 9c SBC A,H */
  1318. X        s = H;
  1319. X        goto sbc;
  1320. X    case 157:        /* 9d SBC A,L */
  1321. X        s = L;
  1322. X        goto sbc;
  1323. X    case 158:        /* 9e SBC A,(HL) */
  1324. X        s = ram[HL];
  1325. X        goto sbc;
  1326. X    when 159:        /* 9f SBC A,A */
  1327. X        s = A;
  1328. X
  1329. sbc:
  1330. X        a = A & 0x0f;
  1331. X        s1 = s & 0x0f;
  1332. X        if (CARRY) { s--; a--; }
  1333. X        goto sub1;
  1334. X
  1335. sub:
  1336. X        a = A & 0x0f;
  1337. X        s1 = s & 0x0f;
  1338. X
  1339. sub1:
  1340. X        s = A - s;
  1341. X        A = s;
  1342. X        a -= s1;
  1343. X        BCD = 1;
  1344. X        goto set_flags;
  1345. X
  1346. X    when 160:        /* a0 AND A,B */
  1347. X        s = B;
  1348. X        goto and;
  1349. X    case 161:        /* a1 AND A,C */
  1350. X        s = C;
  1351. X        goto and;
  1352. X    case 162:        /* a2 AND A,D */
  1353. X        s = D;
  1354. X        goto and;
  1355. X    case 163:        /* a3 AND A,E */
  1356. X        s = E;
  1357. X        goto and;
  1358. X    case 164:        /* a4 AND A,H */
  1359. X        s = H;
  1360. X        goto and;
  1361. X    case 165:        /* a5 AND A,L */
  1362. X        s = L;
  1363. X        goto and;
  1364. X    case 166:        /* a6 AND A,(HL) */
  1365. X        s = ram[HL];
  1366. X        goto and;
  1367. X    case 167:        /* a7 AND A,A */
  1368. X        s = A;
  1369. X
  1370. and:
  1371. X        a = A & 0x0f;
  1372. X        s1 = s & 0x0f;
  1373. X
  1374. X        s &= A;
  1375. X        A = s;
  1376. X        a &= s;
  1377. X        goto set_flags;
  1378. X        
  1379. X    when 168:        /* a8 XOR A,B */
  1380. X        s = B;
  1381. X        goto xor;
  1382. X    case 169:        /* a9 XOR A,C */
  1383. X        s = C;
  1384. X        goto xor;
  1385. X    case 170:        /* aa XOR A,D */
  1386. X        s = D;
  1387. X        goto xor;
  1388. X    case 171:        /* ab XOR A,E */
  1389. X        s = E;
  1390. X        goto xor;
  1391. X    case 172:        /* ac XOR A,H */
  1392. X        s = H;
  1393. X        goto xor;
  1394. X    case 173:        /* ad XOR A,L */
  1395. X        s = L;
  1396. X        goto xor;
  1397. X    case 174:        /* ae XOR A,(HL) */
  1398. X        s = ram[HL];
  1399. X        goto xor;
  1400. X    case 175:        /* af XOR A,A */
  1401. X        s = A;
  1402. X
  1403. xor:
  1404. X        a = A & 0x0f;
  1405. X        s1 = s & 0x0f;
  1406. X
  1407. X        s ^= A;
  1408. X        A = s;
  1409. X        a ^= s;
  1410. X        goto set_flags;
  1411. X
  1412. X    when 176:        /* b1 OR B */
  1413. X        s = B;
  1414. X        goto or;
  1415. X    case 177:        /* b1 OR C */
  1416. X        s = C;
  1417. X        goto or;
  1418. X    case 178:        /* b2 OR D */
  1419. X        s = D;
  1420. X        goto or;
  1421. X    case 179:        /* b3 OR E */
  1422. X        s = E;
  1423. X        goto or;
  1424. X    case 180:        /* b4 OR H */
  1425. X        s = H;
  1426. X        goto or;
  1427. X    case 181:        /* b5 OR L */
  1428. X        s = L;
  1429. X        goto or;
  1430. X    case 182:        /* b6 OR (HL) */
  1431. SHAR_EOF
  1432. true || echo 'restore of decode.c failed'
  1433. echo 'End of part 2, continue with part 3'
  1434. echo 3 > _shar_seq_.tmp
  1435. exit 0
  1436.  
  1437. -- 
  1438. D'Arcy J.M. Cain (darcy@druid)     |
  1439. D'Arcy Cain Consulting             |   I support gun control.
  1440. West Hill, Ontario, Canada         |   Let's start with the government!
  1441. + 416 281 6094                     |
  1442.