home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / emulator / unix / z80pack / z80sim / sim3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-10  |  15.9 KB  |  787 lines

  1. /*
  2.  * Z80SIM  -  a    Z80-CPU    simulator
  3.  *
  4.  * Copyright (C) 1987-92 by Udo Munk
  5.  *
  6.  * This module of the Z80-CPU simulator must not be modified by a user,
  7.  * see license agreement!
  8.  *
  9.  * History:
  10.  * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V.3
  11.  * 11-JAN-89 Release 1.1
  12.  * 08-FEB-89 Release 1.2
  13.  * 13-MAR-89 Release 1.3
  14.  * 09-FEB-90 Release 1.4 Ported to TARGON/31 M10/30
  15.  * 20-DEC-90 Release 1.5 Ported to COHERENT 3.0
  16.  * 10-JUN-92 Release 1.6 long casting problem solved with COHERENT 3.2
  17.  *             and some optimization
  18.  * 25-JUN-92 Release 1.7 comments in english
  19.  */
  20.  
  21. /*
  22.  *    Like the function "cpu()" this one emulates multi byte opcodes
  23.  *    starting with 0xdd
  24.  */
  25.  
  26. #include "sim.h"
  27. #include "simglb.h"
  28.  
  29. long op_dd_handel()
  30. {
  31.     long trap_dd();
  32.     long op_popix(), op_pusix();
  33.     long op_jpix();
  34.     long op_exspx();
  35.     long op_ldspx();
  36.     long op_ldixnn(), op_ldixinn(),    op_ldinx();
  37.     long op_adaxd(), op_acaxd(), op_suaxd(), op_scaxd();
  38.     long op_andxd(), op_xorxd(), op_orxd(),    op_cpxd();
  39.     long op_decxd(), op_incxd();
  40.     long op_addxb(), op_addxd(), op_addxs(), op_addxx();
  41.     long op_incix(), op_decix();
  42.     long op_ldaxd(), op_ldbxd(), op_ldcxd(), op_lddxd(), op_ldexd();
  43.     long op_ldhxd(), op_ldlxd();
  44.     long op_ldxda(), op_ldxdb(), op_ldxdc(), op_ldxdd(), op_ldxde();
  45.     long op_ldxdh(), op_ldxdl(), op_ldxdn();
  46.     extern long op_ddcb_handel();
  47.  
  48.     static long (*op_dd[256]) () = {
  49.         trap_dd,            /* 0x00    */
  50.         trap_dd,            /* 0x01    */
  51.         trap_dd,            /* 0x02    */
  52.         trap_dd,            /* 0x03    */
  53.         trap_dd,            /* 0x04    */
  54.         trap_dd,            /* 0x05    */
  55.         trap_dd,            /* 0x06    */
  56.         trap_dd,            /* 0x07    */
  57.         trap_dd,            /* 0x08    */
  58.         op_addxb,            /* 0x09    */
  59.         trap_dd,            /* 0x0a    */
  60.         trap_dd,            /* 0x0b    */
  61.         trap_dd,            /* 0x0c    */
  62.         trap_dd,            /* 0x0d    */
  63.         trap_dd,            /* 0x0e    */
  64.         trap_dd,            /* 0x0f    */
  65.         trap_dd,            /* 0x10    */
  66.         trap_dd,            /* 0x11    */
  67.         trap_dd,            /* 0x12    */
  68.         trap_dd,            /* 0x13    */
  69.         trap_dd,            /* 0x14    */
  70.         trap_dd,            /* 0x15    */
  71.         trap_dd,            /* 0x16    */
  72.         trap_dd,            /* 0x17    */
  73.         trap_dd,            /* 0x18    */
  74.         op_addxd,            /* 0x19    */
  75.         trap_dd,            /* 0x1a    */
  76.         trap_dd,            /* 0x1b    */
  77.         trap_dd,            /* 0x1c    */
  78.         trap_dd,            /* 0x1d    */
  79.         trap_dd,            /* 0x1e    */
  80.         trap_dd,            /* 0x1f    */
  81.         trap_dd,            /* 0x20    */
  82.         op_ldixnn,            /* 0x21    */
  83.         op_ldinx,            /* 0x22    */
  84.         op_incix,            /* 0x23    */
  85.         trap_dd,            /* 0x24    */
  86.         trap_dd,            /* 0x25    */
  87.         trap_dd,            /* 0x26    */
  88.         trap_dd,            /* 0x27    */
  89.         trap_dd,            /* 0x28    */
  90.         op_addxx,            /* 0x29    */
  91.         op_ldixinn,            /* 0x2a    */
  92.         op_decix,            /* 0x2b    */
  93.         trap_dd,            /* 0x2c    */
  94.         trap_dd,            /* 0x2d    */
  95.         trap_dd,            /* 0x2e    */
  96.         trap_dd,            /* 0x2f    */
  97.         trap_dd,            /* 0x30    */
  98.         trap_dd,            /* 0x31    */
  99.         trap_dd,            /* 0x32    */
  100.         trap_dd,            /* 0x33    */
  101.         op_incxd,            /* 0x34    */
  102.         op_decxd,            /* 0x35    */
  103.         op_ldxdn,            /* 0x36    */
  104.         trap_dd,            /* 0x37    */
  105.         trap_dd,            /* 0x38    */
  106.         op_addxs,            /* 0x39    */
  107.         trap_dd,            /* 0x3a    */
  108.         trap_dd,            /* 0x3b    */
  109.         trap_dd,            /* 0x3c    */
  110.         trap_dd,            /* 0x3d    */
  111.         trap_dd,            /* 0x3e    */
  112.         trap_dd,            /* 0x3f    */
  113.         trap_dd,            /* 0x40    */
  114.         trap_dd,            /* 0x41    */
  115.         trap_dd,            /* 0x42    */
  116.         trap_dd,            /* 0x43    */
  117.         trap_dd,            /* 0x44    */
  118.         trap_dd,            /* 0x45    */
  119.         op_ldbxd,            /* 0x46    */
  120.         trap_dd,            /* 0x47    */
  121.         trap_dd,            /* 0x48    */
  122.         trap_dd,            /* 0x49    */
  123.         trap_dd,            /* 0x4a    */
  124.         trap_dd,            /* 0x4b    */
  125.         trap_dd,            /* 0x4c    */
  126.         trap_dd,            /* 0x4d    */
  127.         op_ldcxd,            /* 0x4e    */
  128.         trap_dd,            /* 0x4f    */
  129.         trap_dd,            /* 0x50    */
  130.         trap_dd,            /* 0x51    */
  131.         trap_dd,            /* 0x52    */
  132.         trap_dd,            /* 0x53    */
  133.         trap_dd,            /* 0x54    */
  134.         trap_dd,            /* 0x55    */
  135.         op_lddxd,            /* 0x56    */
  136.         trap_dd,            /* 0x57    */
  137.         trap_dd,            /* 0x58    */
  138.         trap_dd,            /* 0x59    */
  139.         trap_dd,            /* 0x5a    */
  140.         trap_dd,            /* 0x5b    */
  141.         trap_dd,            /* 0x5c    */
  142.         trap_dd,            /* 0x5d    */
  143.         op_ldexd,            /* 0x5e    */
  144.         trap_dd,            /* 0x5f    */
  145.         trap_dd,            /* 0x60    */
  146.         trap_dd,            /* 0x61    */
  147.         trap_dd,            /* 0x62    */
  148.         trap_dd,            /* 0x63    */
  149.         trap_dd,            /* 0x64    */
  150.         trap_dd,            /* 0x65    */
  151.         op_ldhxd,            /* 0x66    */
  152.         trap_dd,            /* 0x67    */
  153.         trap_dd,            /* 0x68    */
  154.         trap_dd,            /* 0x69    */
  155.         trap_dd,            /* 0x6a    */
  156.         trap_dd,            /* 0x6b    */
  157.         trap_dd,            /* 0x6c    */
  158.         trap_dd,            /* 0x6d    */
  159.         op_ldlxd,            /* 0x6e    */
  160.         trap_dd,            /* 0x6f    */
  161.         op_ldxdb,            /* 0x70    */
  162.         op_ldxdc,            /* 0x71    */
  163.         op_ldxdd,            /* 0x72    */
  164.         op_ldxde,            /* 0x73    */
  165.         op_ldxdh,            /* 0x74    */
  166.         op_ldxdl,            /* 0x75    */
  167.         trap_dd,            /* 0x76    */
  168.         op_ldxda,            /* 0x77    */
  169.         trap_dd,            /* 0x78    */
  170.         trap_dd,            /* 0x79    */
  171.         trap_dd,            /* 0x7a    */
  172.         trap_dd,            /* 0x7b    */
  173.         trap_dd,            /* 0x7c    */
  174.         trap_dd,            /* 0x7d    */
  175.         op_ldaxd,            /* 0x7e    */
  176.         trap_dd,            /* 0x7f    */
  177.         trap_dd,            /* 0x80    */
  178.         trap_dd,            /* 0x81    */
  179.         trap_dd,            /* 0x82    */
  180.         trap_dd,            /* 0x83    */
  181.         trap_dd,            /* 0x84    */
  182.         trap_dd,            /* 0x85    */
  183.         op_adaxd,            /* 0x86    */
  184.         trap_dd,            /* 0x87    */
  185.         trap_dd,            /* 0x88    */
  186.         trap_dd,            /* 0x89    */
  187.         trap_dd,            /* 0x8a    */
  188.         trap_dd,            /* 0x8b    */
  189.         trap_dd,            /* 0x8c    */
  190.         trap_dd,            /* 0x8d    */
  191.         op_acaxd,            /* 0x8e    */
  192.         trap_dd,            /* 0x8f    */
  193.         trap_dd,            /* 0x90    */
  194.         trap_dd,            /* 0x91    */
  195.         trap_dd,            /* 0x92    */
  196.         trap_dd,            /* 0x93    */
  197.         trap_dd,            /* 0x94    */
  198.         trap_dd,            /* 0x95    */
  199.         op_suaxd,            /* 0x96    */
  200.         trap_dd,            /* 0x97    */
  201.         trap_dd,            /* 0x98    */
  202.         trap_dd,            /* 0x99    */
  203.         trap_dd,            /* 0x9a    */
  204.         trap_dd,            /* 0x9b    */
  205.         trap_dd,            /* 0x9c    */
  206.         trap_dd,            /* 0x9d    */
  207.         op_scaxd,            /* 0x9e    */
  208.         trap_dd,            /* 0x9f    */
  209.         trap_dd,            /* 0xa0    */
  210.         trap_dd,            /* 0xa1    */
  211.         trap_dd,            /* 0xa2    */
  212.         trap_dd,            /* 0xa3    */
  213.         trap_dd,            /* 0xa4    */
  214.         trap_dd,            /* 0xa5    */
  215.         op_andxd,            /* 0xa6    */
  216.         trap_dd,            /* 0xa7    */
  217.         trap_dd,            /* 0xa8    */
  218.         trap_dd,            /* 0xa9    */
  219.         trap_dd,            /* 0xaa    */
  220.         trap_dd,            /* 0xab    */
  221.         trap_dd,            /* 0xac    */
  222.         trap_dd,            /* 0xad    */
  223.         op_xorxd,            /* 0xae    */
  224.         trap_dd,            /* 0xaf    */
  225.         trap_dd,            /* 0xb0    */
  226.         trap_dd,            /* 0xb1    */
  227.         trap_dd,            /* 0xb2    */
  228.         trap_dd,            /* 0xb3    */
  229.         trap_dd,            /* 0xb4    */
  230.         trap_dd,            /* 0xb5    */
  231.         op_orxd,            /* 0xb6    */
  232.         trap_dd,            /* 0xb7    */
  233.         trap_dd,            /* 0xb8    */
  234.         trap_dd,            /* 0xb9    */
  235.         trap_dd,            /* 0xba    */
  236.         trap_dd,            /* 0xbb    */
  237.         trap_dd,            /* 0xbc    */
  238.         trap_dd,            /* 0xbd    */
  239.         op_cpxd,            /* 0xbe    */
  240.         trap_dd,            /* 0xbf    */
  241.         trap_dd,            /* 0xc0    */
  242.         trap_dd,            /* 0xc1    */
  243.         trap_dd,            /* 0xc2    */
  244.         trap_dd,            /* 0xc3    */
  245.         trap_dd,            /* 0xc4    */
  246.         trap_dd,            /* 0xc5    */
  247.         trap_dd,            /* 0xc6    */
  248.         trap_dd,            /* 0xc7    */
  249.         trap_dd,            /* 0xc8    */
  250.         trap_dd,            /* 0xc9    */
  251.         trap_dd,            /* 0xca    */
  252.         op_ddcb_handel,            /* 0xcb    */
  253.         trap_dd,            /* 0xcc    */
  254.         trap_dd,            /* 0xcd    */
  255.         trap_dd,            /* 0xce    */
  256.         trap_dd,            /* 0xcf    */
  257.         trap_dd,            /* 0xd0    */
  258.         trap_dd,            /* 0xd1    */
  259.         trap_dd,            /* 0xd2    */
  260.         trap_dd,            /* 0xd3    */
  261.         trap_dd,            /* 0xd4    */
  262.         trap_dd,            /* 0xd5    */
  263.         trap_dd,            /* 0xd6    */
  264.         trap_dd,            /* 0xd7    */
  265.         trap_dd,            /* 0xd8    */
  266.         trap_dd,            /* 0xd9    */
  267.         trap_dd,            /* 0xda    */
  268.         trap_dd,            /* 0xdb    */
  269.         trap_dd,            /* 0xdc    */
  270.         trap_dd,            /* 0xdd    */
  271.         trap_dd,            /* 0xde    */
  272.         trap_dd,            /* 0xdf    */
  273.         trap_dd,            /* 0xe0    */
  274.         op_popix,            /* 0xe1    */
  275.         trap_dd,            /* 0xe2    */
  276.         op_exspx,            /* 0xe3    */
  277.         trap_dd,            /* 0xe4    */
  278.         op_pusix,            /* 0xe5    */
  279.         trap_dd,            /* 0xe6    */
  280.         trap_dd,            /* 0xe7    */
  281.         trap_dd,            /* 0xe8    */
  282.         op_jpix,            /* 0xe9    */
  283.         trap_dd,            /* 0xea    */
  284.         trap_dd,            /* 0xeb    */
  285.         trap_dd,            /* 0xec    */
  286.         trap_dd,            /* 0xed    */
  287.         trap_dd,            /* 0xee    */
  288.         trap_dd,            /* 0xef    */
  289.         trap_dd,            /* 0xf0    */
  290.         trap_dd,            /* 0xf1    */
  291.         trap_dd,            /* 0xf2    */
  292.         trap_dd,            /* 0xf3    */
  293.         trap_dd,            /* 0xf4    */
  294.         trap_dd,            /* 0xf5    */
  295.         trap_dd,            /* 0xf6    */
  296.         trap_dd,            /* 0xf7    */
  297.         trap_dd,            /* 0xf8    */
  298.         op_ldspx,            /* 0xf9    */
  299.         trap_dd,            /* 0xfa    */
  300.         trap_dd,            /* 0xfb    */
  301.         trap_dd,            /* 0xfc    */
  302.         trap_dd,            /* 0xfd    */
  303.         trap_dd,            /* 0xfe    */
  304.         trap_dd                /* 0xff    */
  305.     };
  306.  
  307.  
  308. #ifdef WANT_TIM
  309.     register long t;
  310.     t = (*op_dd[*PC++]) ();        /* execute next opcode */
  311. #else
  312.     (*op_dd[*PC++]) ();
  313. #endif
  314.  
  315. #ifdef WANT_PCC
  316.         if (PC > ram + 65535)    /* correct PC overrun */
  317.             PC = ram;
  318. #endif
  319.  
  320. #ifdef WANT_TIM
  321.     return(t);
  322. #endif
  323. }
  324.  
  325. /*
  326.  *    This function traps all illegal opcodes following the
  327.  *    initial 0xdd of a multi byte opcode.
  328.  */
  329. static long trap_dd()
  330. {
  331.     cpu_error = OPTRAP2;
  332.     cpu_state = STOPPED;
  333. #ifdef WANT_TIM
  334.     return(0L);
  335. #endif
  336. }
  337.  
  338. static long op_popix()             /*    POP IX */
  339. {
  340. #ifdef WANT_SPC
  341.     if (STACK <= ram)
  342.         STACK =    ram + 65536L;
  343. #endif
  344.     IX = *STACK++;
  345. #ifdef WANT_SPC
  346.     if (STACK <= ram)
  347.         STACK =    ram + 65536L;
  348. #endif
  349.     IX += *STACK++ << 8;
  350. #ifdef WANT_TIM
  351.     return(14L);
  352. #endif
  353. }
  354.  
  355. static long op_pusix()             /*    PUSH IX    */
  356. {
  357. #ifdef WANT_SPC
  358.     if (STACK <= ram)
  359.         STACK =    ram + 65536L;
  360. #endif
  361.     *--STACK = IX >> 8;
  362. #ifdef WANT_SPC
  363.     if (STACK <= ram)
  364.         STACK =    ram + 65536L;
  365. #endif
  366.     *--STACK = IX;
  367. #ifdef WANT_TIM
  368.     return(15L);
  369. #endif
  370. }
  371.  
  372. static long op_jpix()             /*    JP (IX)    */
  373. {
  374.     PC = ram + IX;
  375. #ifdef WANT_TIM
  376.     return(8L);
  377. #endif
  378. }
  379.  
  380. static long op_exspx()             /*    EX (SP),IX */
  381. {
  382.     register int i;
  383.  
  384.     i = *STACK + (*(STACK +    1) << 8);
  385.     *STACK = IX;
  386.     *(STACK    + 1) = IX >> 8;
  387.     IX = i;
  388. #ifdef WANT_TIM
  389.     return(23L);
  390. #endif
  391. }
  392.  
  393. static long op_ldspx()             /*    LD SP,IX */
  394. {
  395.     STACK =    ram + IX;
  396. #ifdef WANT_TIM
  397.     return(10L);
  398. #endif
  399. }
  400.  
  401. static long op_ldixnn()             /*    LD IX,nn */
  402. {
  403.     IX = *PC++;
  404.     IX += *PC++ << 8;
  405. #ifdef WANT_TIM
  406.     return(14L);
  407. #endif
  408. }
  409.  
  410. static long op_ldixinn()         /*    LD IX,(nn) */
  411. {
  412.     register BYTE *p;
  413.  
  414.     p = ram    + *PC++;
  415.     p += *PC++ << 8;
  416.     IX = *p++;
  417.     IX += *p << 8;
  418. #ifdef WANT_TIM
  419.     return(20L);
  420. #endif
  421. }
  422.  
  423. static long op_ldinx()             /*    LD (nn),IX */
  424. {
  425.     register BYTE *p;
  426.  
  427.     p = ram    + *PC++;
  428.     p += *PC++ << 8;
  429.     *p++ = IX;
  430.     *p = IX    >> 8;
  431. #ifdef WANT_TIM
  432.     return(20L);
  433. #endif
  434. }
  435.  
  436. static long op_adaxd()             /*    ADD A,(IX+d) */
  437. {
  438.     register int i;
  439.     register BYTE P;
  440.  
  441.     P = *(ram + IX + (char)    *PC++);
  442.     ((A & 0xf) + (P    & 0xf) > 0xf) ?    (F |= H_FLAG) :    (F &= ~H_FLAG);
  443.     (A + P > 255) ?    (F |= C_FLAG) :    (F &= ~C_FLAG);
  444.     A = i =    (char) A + (char) P;
  445.     (i < -128 || i > 127) ?    (F |= P_FLAG) :    (F &= ~P_FLAG);
  446.     (i & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG);
  447.     (A) ? (F &= ~Z_FLAG) : (F |= Z_FLAG);
  448.     F &= ~N_FLAG;
  449. #ifdef WANT_TIM
  450.     return(19L);
  451. #endif
  452. }
  453.  
  454. static long op_acaxd()             /*    ADC A,(IX+d) */
  455. {
  456.     register int i,    carry;
  457.     register BYTE P;
  458.  
  459.     carry =    (F & C_FLAG) ? 1 : 0;
  460.     P = *(ram + IX + (char)    *PC++);
  461.     ((A & 0xf) + (P    & 0xf) + carry > 0xf) ?    (F |= H_FLAG) :    (F &= ~H_FLAG);
  462.     (A + P + carry > 255) ?    (F |= C_FLAG) :    (F &= ~C_FLAG);
  463.     A = i =    (char) A + (char) P + carry;
  464.     (i < -128 || i > 127) ?    (F |= P_FLAG) :    (F &= ~P_FLAG);
  465.     (i & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG);
  466.     (A) ? (F &= ~Z_FLAG) : (F |= Z_FLAG);
  467.     F &= ~N_FLAG;
  468. #ifdef WANT_TIM
  469.     return(19L);
  470. #endif
  471. }
  472.  
  473. static long op_suaxd()             /*    SUB A,(IX+d) */
  474. {
  475.     register int i;
  476.     register BYTE P;
  477.  
  478.     P = *(ram + IX + (char)    *PC++);
  479.     ((P & 0xf) > (A    & 0xf))    ? (F |=    H_FLAG)    : (F &=    ~H_FLAG);
  480.     (P > A)    ? (F |=    C_FLAG)    : (F &=    ~C_FLAG);
  481.     A = i =    (char) A - (char) P;
  482.     (i < -128 || i > 127) ?    (F |= P_FLAG) :    (F &= ~P_FLAG);
  483.     (i & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG);
  484.     (A) ? (F &= ~Z_FLAG) : (F |= Z_FLAG);
  485.     F |= N_FLAG;
  486. #ifdef WANT_TIM
  487.     return(19L);
  488. #endif
  489. }
  490.  
  491. static long op_scaxd()             /*    SBC A,(IX+d) */
  492. {
  493.     register int i,    carry;
  494.     register BYTE P;
  495.  
  496.     carry =    (F & C_FLAG) ? 1 : 0;
  497.     P = *(ram + IX + (char)    *PC++);
  498.     ((P & 0xf) + carry > (A    & 0xf))    ? (F |=    H_FLAG)    : (F &=    ~H_FLAG);
  499.     (P + carry > A)    ? (F |=    C_FLAG)    : (F &=    ~C_FLAG);
  500.     A = i =    (char) A - (char) P - carry;
  501.     (i < -128 || i > 127) ?    (F |= P_FLAG) :    (F &= ~P_FLAG);
  502.     (i & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG);
  503.     (A) ? (F &= ~Z_FLAG) : (F |= Z_FLAG);
  504.     F |= N_FLAG;
  505. #ifdef WANT_TIM
  506.     return(19L);
  507. #endif
  508. }
  509.  
  510. static long op_andxd()             /*    AND (IX+d) */
  511. {
  512.     A &= *(ram + IX    + (char) *PC++);
  513.     (A & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG);
  514.     (A) ? (F &= ~Z_FLAG) : (F |= Z_FLAG);
  515.     F |= H_FLAG;
  516.     (parrity[A]) ? (F &= ~P_FLAG) :    (F |= P_FLAG);
  517.     F &= ~(N_FLAG |    C_FLAG);
  518. #ifdef WANT_TIM
  519.     return(19L);
  520. #endif
  521. }
  522.  
  523. static long op_xorxd()             /*    XOR (IX+d) */
  524. {
  525.     A ^= *(ram + IX    + (char) *PC++);
  526.     (A & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG);
  527.     (A) ? (F &= ~Z_FLAG) : (F |= Z_FLAG);
  528.     (parrity[A]) ? (F &= ~P_FLAG) :    (F |= P_FLAG);
  529.     F &= ~(H_FLAG |    N_FLAG | C_FLAG);
  530. #ifdef WANT_TIM
  531.     return(19L);
  532. #endif
  533. }
  534.  
  535. static long op_orxd()             /*    OR (IX+d) */
  536. {
  537.     A |= *(ram + IX    + (char) *PC++);
  538.     (A & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG);
  539.     (A) ? (F &= ~Z_FLAG) : (F |= Z_FLAG);
  540.     (parrity[A]) ? (F &= ~P_FLAG) :    (F |= P_FLAG);
  541.     F &= ~(H_FLAG |    N_FLAG | C_FLAG);
  542. #ifdef WANT_TIM
  543.     return(19L);
  544. #endif
  545. }
  546.  
  547. static long op_cpxd()             /*    CP (IX+d) */
  548. {
  549.     register int i;
  550.     register BYTE P;
  551.  
  552.     P = *(ram + IX + (char)    *PC++);
  553.     ((P & 0xf) > (A    & 0xf))    ? (F |=    H_FLAG)    : (F &=    ~H_FLAG);
  554.     (P > A)    ? (F |=    C_FLAG)    : (F &=    ~C_FLAG);
  555.     i = (char) A - (char) P;
  556.     (i < -128 || i > 127) ?    (F |= P_FLAG) :    (F &= ~P_FLAG);
  557.     (i & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG);
  558.     (i) ? (F &= ~Z_FLAG) : (F |= Z_FLAG);
  559.     F |= N_FLAG;
  560. #ifdef WANT_TIM
  561.     return(19L);
  562. #endif
  563. }
  564.  
  565. static long op_incxd()             /*    INC (IX+d) */
  566. {
  567.     register BYTE *p;
  568.  
  569.     p = ram    + IX + (char) *PC++;
  570.     ((*p & 0xf) + 1    > 0xf) ? (F |= H_FLAG) : (F &= ~H_FLAG);
  571.     (*p)++;
  572.     (*p == 128) ? (F |= P_FLAG) : (F &= ~P_FLAG);
  573.     (*p & 128) ? (F    |= S_FLAG) : (F    &= ~S_FLAG);
  574.     (*p) ? (F &= ~Z_FLAG) :    (F |= Z_FLAG);
  575.     F &= ~N_FLAG;
  576. #ifdef WANT_TIM
  577.     return(23L);
  578. #endif
  579. }
  580.  
  581. static long op_decxd()             /*    DEC (IX+d) */
  582. {
  583.     register BYTE *p;
  584.  
  585.     p = ram    + IX + (char) *PC++;
  586.     ((*p - 1 & 0xf)    == 0xf)    ? (F |=    H_FLAG)    : (F &=    ~H_FLAG);
  587.     (*p)--;
  588.     (*p == 127) ? (F |= P_FLAG) : (F &= ~P_FLAG);
  589.     (*p & 128) ? (F    |= S_FLAG) : (F    &= ~S_FLAG);
  590.     (*p) ? (F &= ~Z_FLAG) :    (F |= Z_FLAG);
  591.     F |= N_FLAG;
  592. #ifdef WANT_TIM
  593.     return(23L);
  594. #endif
  595. }
  596.  
  597. static long op_addxb()             /*    ADD IX,BC */
  598. {
  599.     register long i;
  600.  
  601.     i = (((long)IX) + (((long)B) << 8) + C);
  602.     (i > 0xffffL) ?    (F |= C_FLAG) :    (F &= ~C_FLAG);
  603.     IX = i;
  604.     F &= ~N_FLAG;
  605. #ifdef WANT_TIM
  606.     return(15L);
  607. #endif
  608. }
  609.  
  610. static long op_addxd()             /*    ADD IX,DE */
  611. {
  612.     register long i;
  613.  
  614.     i = (((long)IX) + (((long)D) << 8) + E);
  615.     (i > 0xffffL) ?    (F |= C_FLAG) :    (F &= ~C_FLAG);
  616.     IX = i;
  617.     F &= ~N_FLAG;
  618. #ifdef WANT_TIM
  619.     return(15L);
  620. #endif
  621. }
  622.  
  623. static long op_addxs()             /*    ADD IX,SP */
  624. {
  625.     register long i;
  626.  
  627.     i = ((long)IX) + ((long)STACK) - ((long)ram);
  628.     (i > 0xffffL) ?    (F |= C_FLAG) :    (F &= ~C_FLAG);
  629.     IX = i;
  630.     F &= ~N_FLAG;
  631. #ifdef WANT_TIM
  632.     return(15L);
  633. #endif
  634. }
  635.  
  636. static long op_addxx()             /*    ADD IX,IX */
  637. {
  638.     register long i;
  639.  
  640.     i = (((long)IX) << 1);
  641.     (i > 0xffffL) ?    (F |= C_FLAG) :    (F &= ~C_FLAG);
  642.     IX = i;
  643.     F &= ~N_FLAG;
  644. #ifdef WANT_TIM
  645.     return(15L);
  646. #endif
  647. }
  648.  
  649. static long op_incix()             /*    INC IX */
  650. {
  651.     IX++;
  652. #ifdef WANT_TIM
  653.     return(10L);
  654. #endif
  655. }
  656.  
  657. static long op_decix()             /*    DEC IX */
  658. {
  659.     IX--;
  660. #ifdef WANT_TIM
  661.     return(10L);
  662. #endif
  663. }
  664.  
  665. static long op_ldaxd()             /*    LD A,(IX+d) */
  666. {
  667.     A = *(IX + (char) *PC++    + ram);
  668. #ifdef WANT_TIM
  669.     return(19L);
  670. #endif
  671. }
  672.  
  673. static long op_ldbxd()             /*    LD B,(IX+d) */
  674. {
  675.     B = *(IX + (char) *PC++    + ram);
  676. #ifdef WANT_TIM
  677.     return(19L);
  678. #endif
  679. }
  680.  
  681. static long op_ldcxd()             /*    LD C,(IX+d) */
  682. {
  683.     C = *(IX + (char) *PC++    + ram);
  684. #ifdef WANT_TIM
  685.     return(19L);
  686. #endif
  687. }
  688.  
  689. static long op_lddxd()             /*    LD D,(IX+d) */
  690. {
  691.     D = *(IX + (char) *PC++    + ram);
  692. #ifdef WANT_TIM
  693.     return(19L);
  694. #endif
  695. }
  696.  
  697. static long op_ldexd()             /*    LD E,(IX+d) */
  698. {
  699.     E = *(IX + (char) *PC++    + ram);
  700. #ifdef WANT_TIM
  701.     return(19L);
  702. #endif
  703. }
  704.  
  705. static long op_ldhxd()             /*    LD H,(IX+d) */
  706. {
  707.     H = *(IX + (char) *PC++    + ram);
  708. #ifdef WANT_TIM
  709.     return(19L);
  710. #endif
  711. }
  712.  
  713. static long op_ldlxd()             /*    LD L,(IX+d) */
  714. {
  715.     L = *(IX + (char) *PC++    + ram);
  716. #ifdef WANT_TIM
  717.     return(19L);
  718. #endif
  719. }
  720.  
  721. static long op_ldxda()             /*    LD (IX+d),A */
  722. {
  723.     *(IX + (char) *PC++ + ram) = A;
  724. #ifdef WANT_TIM
  725.     return(19L);
  726. #endif
  727. }
  728.  
  729. static long op_ldxdb()             /*    LD (IX+d),B */
  730. {
  731.     *(IX + (char) *PC++ + ram) = B;
  732. #ifdef WANT_TIM
  733.     return(19L);
  734. #endif
  735. }
  736.  
  737. static long op_ldxdc()             /*    LD (IX+d),C */
  738. {
  739.     *(IX + (char) *PC++ + ram) = C;
  740. #ifdef WANT_TIM
  741.     return(19L);
  742. #endif
  743. }
  744.  
  745. static long op_ldxdd()             /*    LD (IX+d),D */
  746. {
  747.     *(IX + (char) *PC++ + ram) = D;
  748. #ifdef WANT_TIM
  749.     return(19L);
  750. #endif
  751. }
  752.  
  753. static long op_ldxde()             /*    LD (IX+d),E */
  754. {
  755.     *(IX + (char) *PC++ + ram) = E;
  756. #ifdef WANT_TIM
  757.     return(19L);
  758. #endif
  759. }
  760.  
  761. static long op_ldxdh()             /*    LD (IX+d),H */
  762. {
  763.     *(IX + (char) *PC++ + ram) = H;
  764. #ifdef WANT_TIM
  765.     return(19L);
  766. #endif
  767. }
  768.  
  769. static long op_ldxdl()             /*    LD (IX+d),L */
  770. {
  771.     *(IX + (char) *PC++ + ram) = L;
  772. #ifdef WANT_TIM
  773.     return(19L);
  774. #endif
  775. }
  776.  
  777. static long op_ldxdn()             /*    LD (IX+d),n */
  778. {
  779.     register int d;
  780.  
  781.     d = (char) *PC++;
  782.     *(IX + d + ram)    = *PC++;
  783. #ifdef WANT_TIM
  784.     return(19L);
  785. #endif
  786. }
  787.