home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / CROSSASM / 68ASMSIM.ZIP / simsrc / code6.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-09  |  5.7 KB  |  370 lines

  1.  
  2. /***************************** 68000 SIMULATOR ****************************
  3.  
  4. File Name: CODE6.C
  5. Version: 1.0
  6.  
  7. The instructions implemented in this file are the logical arithmetic
  8.    operations:
  9.  
  10.         AND, ANDI, ANDI_TO_CCR, ANDI_TO_SR, OR, ORI, ORI_TO_CCR,
  11.         ORI_TO_SR, EOR, EORI, EORI_TO_CCR, EORI_TO_SR, NOT
  12.  
  13.  
  14. ***************************************************************************/
  15.  
  16.  
  17. #include <stdio.h>
  18. #include "extern.h"         /* contains global "extern" declarations */
  19.  
  20.  
  21.  
  22. int    AND()
  23. {
  24. int    addr_modes_mask, reg;
  25. long    size;
  26.  
  27. addr_modes_mask = (inst & 0x0100) ? MEM_ALT_ADDR : DATA_ADDR;
  28.  
  29. if ((decode_size(&size)) ||
  30.     (eff_addr (size, addr_modes_mask, TRUE)))
  31.     return (BAD_INST);            /* bad instruction format */
  32.  
  33. reg = (inst >> 9) & 0x0007;
  34.  
  35. if (inst & 0x0100)
  36.     {
  37.     source = D[reg] & size;
  38.     dest = EV1 & size;
  39.     put (EA1, dest & source, size);
  40.     value_of (EA1, &result, size);
  41.     }
  42. else
  43.     {
  44.     source = EV1 & size;
  45.     dest = D[reg] & size;
  46.     put (&D[reg], dest & source, size);
  47.     result = D[reg] & size;
  48.     }
  49.  
  50. cc_update (N_A, GEN, GEN, ZER, ZER, source, dest, result, size, 0);
  51.  
  52. if (inst & 0x0100) 
  53.     inc_cyc ( (size == LONG) ? 12 : 8);
  54. else {
  55.     if (size == LONG) {
  56.         if ( (!(inst & 0x0030)) || ((inst & 0x003f) == 0x003c) )
  57.             inc_cyc (8);
  58.         else
  59.             inc_cyc (6);
  60.         }
  61.     else {
  62.         inc_cyc (4);
  63.         }
  64.     }
  65.  
  66. return SUCCESS;
  67.  
  68. }
  69.  
  70.  
  71.  
  72. int    ANDI()
  73. {
  74. long    size;
  75.  
  76. if (decode_size(&size))
  77.     return (BAD_INST);            /* bad instruction format */
  78.  
  79. mem_request (&PC, size, &source);
  80.  
  81. if (eff_addr (size, DATA_ALT_ADDR, TRUE))
  82.     return (BAD_INST);            /* bad instruction format */
  83.  
  84. dest = EV1 & size;
  85.  
  86. put (EA1, source & dest, size);
  87. value_of (EA1, &result, size);
  88.  
  89. cc_update (N_A, GEN, GEN, ZER, ZER, source, dest, result, size, 0);
  90.  
  91. if (inst & 0x0038)
  92.     inc_cyc ( (size == LONG) ? 20 : 12);
  93. else
  94.     inc_cyc ( (size == LONG) ? 16 : 8);
  95.  
  96. return SUCCESS;
  97.  
  98. }
  99.  
  100.  
  101. int    ANDI_TO_CCR()
  102. {
  103. long    temp;
  104.  
  105. mem_request (&PC, (long) WORD, &temp);
  106.  
  107. SR &= temp | 0xff00;
  108.  
  109. inc_cyc (20);
  110.  
  111. return SUCCESS;
  112.  
  113. }
  114.  
  115.  
  116. int    ANDI_TO_SR()
  117. {
  118. long    temp;
  119.  
  120. if (!(SR & sbit))
  121.     return (NO_PRIVILEGE);
  122.  
  123. mem_request (&PC, (long) WORD, &temp);
  124. SR &= temp;
  125.  
  126. inc_cyc (20);
  127.  
  128. return SUCCESS;
  129.  
  130. }
  131.  
  132.  
  133.  
  134.  
  135. int    OR()
  136. {
  137. long    size;
  138. int    mask, reg;
  139.  
  140. mask = (inst & 0x0100) ? MEM_ALT_ADDR : DATA_ADDR;
  141.  
  142. if ((decode_size(&size)) || 
  143.     (eff_addr(size, mask, TRUE)))
  144.     return (BAD_INST);        /* bad instruction format */
  145.  
  146. reg = (inst >> 9) & 0x0007;
  147.  
  148. if (inst & 0x0100)
  149.     {
  150.     source = D[reg] & size;
  151.     dest = EV1 & size;
  152.     put (EA1, source | dest, size);
  153.     value_of (EA1, &result, size);
  154.     }
  155. else
  156.     {
  157.     source = EV1 & size;
  158.     dest = D[reg] & size;
  159.     put (&D[reg], source | dest, size);
  160.     result = D[reg] & size;
  161.     }
  162.  
  163. cc_update (N_A, GEN, GEN, ZER, ZER, source, dest, result, size, 0);
  164.  
  165. if (inst & 0x0100) 
  166.     inc_cyc ( (size == LONG) ? 12 : 8);
  167. else {
  168.     if (size == LONG) {
  169.         if ( (!(inst & 0x0030)) || ((inst & 0x003f) == 0x003c) )
  170.             inc_cyc (8);
  171.         else
  172.             inc_cyc (6);
  173.         }
  174.     else 
  175.         inc_cyc (4);
  176.     }
  177.  
  178. return SUCCESS;
  179.  
  180. }
  181.  
  182.  
  183.  
  184.  
  185. int    ORI()
  186. {
  187. long    size;
  188.  
  189. if (decode_size(&size))
  190.     return (BAD_INST);            /* bad instruction format */
  191.  
  192. mem_request (&PC, size, &source);
  193.  
  194. if (eff_addr (size, DATA_ALT_ADDR, TRUE))
  195.     return (BAD_INST);            /* bad instruction format */
  196.  
  197. dest = EV1 & size;
  198.  
  199. put (EA1, source | dest, size);
  200. value_of (EA1, &result, size);
  201.  
  202. cc_update (N_A, GEN, GEN, ZER, ZER, source, dest, result, size, 0);
  203.  
  204. if (inst & 0x0038) {
  205.     inc_cyc ( (size == LONG) ? 20 : 12);
  206.     }
  207. else {
  208.     inc_cyc ( (size == LONG) ? 16 : 8);
  209.     }
  210.  
  211. return SUCCESS;
  212.  
  213. }
  214.  
  215.  
  216. int    ORI_TO_CCR()
  217. {
  218. long    temp;
  219.  
  220. mem_request (&PC, (long) WORD, &temp);
  221.  
  222. SR |= temp;
  223.  
  224. inc_cyc (20);
  225.  
  226. return SUCCESS;
  227.  
  228. }
  229.  
  230.  
  231. int    ORI_TO_SR()
  232. {
  233. long    temp;
  234.  
  235. if (!(SR & sbit))
  236.     return (NO_PRIVILEGE);
  237.  
  238. mem_request (&PC, (long) WORD, &temp);
  239. SR |= temp;
  240.  
  241. inc_cyc (20);
  242.  
  243. return SUCCESS;
  244.  
  245. }
  246.  
  247.  
  248.  
  249. int    EOR()
  250. {
  251. long    size;
  252. int    reg;
  253.  
  254. if ((decode_size(&size)) ||
  255.     (eff_addr (size, DATA_ALT_ADDR, TRUE)))
  256.     return (BAD_INST);            /* bad instruction format */
  257.  
  258. reg = (inst >> 9) & 0x0007;
  259.  
  260. source = D[reg] & size;
  261. dest = EV1 & size;
  262.  
  263. put (EA1, EV1 ^ D[reg], size);
  264. value_of (EA1, &result, size);
  265.  
  266. cc_update (N_A, GEN, GEN, ZER, ZER, source, dest, result, size, 0);
  267.  
  268. if (inst & 0x0038)
  269.     inc_cyc ( (size == LONG) ? 12 : 8);
  270. else
  271.     inc_cyc ( (size == LONG) ? 8 : 4);
  272.  
  273. return SUCCESS;
  274.  
  275. }
  276.  
  277.  
  278.  
  279. int    EORI()
  280. {
  281. long    size;
  282. int    data;
  283.  
  284. if (decode_size(&size))
  285.     return (BAD_INST);            /* bad instruction format */
  286.  
  287. mem_request (&PC, size, &source);
  288.  
  289. if (eff_addr (size, DATA_ALT_ADDR, TRUE))
  290.     return (BAD_INST);            /* bad instruction format */
  291.  
  292. dest = EV1 & size;
  293.  
  294. put (EA1, source ^ dest, size);
  295. value_of (EA1, &result, size);
  296.  
  297. cc_update (N_A, GEN, GEN, ZER, ZER, source, dest, result, size, 0);
  298.  
  299. if (inst & 0x0038) {
  300.     inc_cyc ( (size == LONG) ? 20 : 12);
  301.     }
  302. else {
  303.     inc_cyc ( (size == LONG) ? 16 : 8);
  304.     }
  305.  
  306. return SUCCESS;
  307.  
  308. }
  309.  
  310.  
  311. int    EORI_TO_CCR()
  312. {
  313. long    temp;
  314.  
  315. mem_request (&PC, (long) WORD, &temp);
  316.  
  317. SR ^= temp;
  318.  
  319. inc_cyc (20);
  320.  
  321. return SUCCESS;
  322.  
  323. }
  324.  
  325.  
  326. int    EORI_TO_SR()
  327. {
  328. long    temp;
  329.  
  330. if (!(SR & sbit))
  331.     return (NO_PRIVILEGE);
  332.  
  333. mem_request (&PC, (long) WORD, &temp);
  334. SR ^= temp;
  335.  
  336. inc_cyc (20);
  337.  
  338. return SUCCESS;
  339.  
  340. }
  341.  
  342.  
  343. int    NOT()
  344. {
  345. long    size;
  346.  
  347. if ((decode_size(&size)) ||
  348.     (eff_addr (size, DATA_ALT_ADDR, TRUE)))
  349.     return (BAD_INST);        /* bad instruction format */
  350.  
  351. source = dest = EV1 & size;
  352.  
  353. /* perform the NOT operation */
  354. put (EA1, ~dest, size);
  355. value_of (EA1, &result, size);
  356.  
  357. cc_update (N_A, GEN, GEN, ZER, ZER, source, dest, result, size, 0);
  358.  
  359. if (inst & 0x0030) {
  360.     inc_cyc ( (size == LONG) ? 12 : 8);
  361.     }
  362. else {
  363.     inc_cyc ( (size == LONG) ? 6 : 4);
  364.     }
  365.  
  366. return SUCCESS;
  367.  
  368. }
  369.  
  370.