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

  1.  
  2. /***************************** 68000 SIMULATOR ****************************
  3.  
  4. File Name: CODE8.C
  5. Version: 1.0
  6.  
  7. The instructions implemented in this file are the program control operations:
  8.  
  9.         BCC, DBCC, SCC, BRA, BSR, JMP, JSR, RTE, RTR, RTS, NOP
  10.  
  11.  
  12. ***************************************************************************/
  13.  
  14.  
  15. #include <stdio.h>
  16. #include "extern.h"         /* contains global "extern" declarations */
  17.  
  18.  
  19.  
  20.  
  21.  
  22. int    BCC()
  23. {
  24. long    displacement;
  25. int    condition;
  26.  
  27. displacement = inst & 0xff;
  28. if (displacement == 0)
  29.     {
  30.     mem_request (&PC, (long) WORD, &displacement);
  31.     from_2s_comp (displacement, (long) WORD, &displacement);
  32.     }
  33. else
  34.     from_2s_comp (displacement, (long) BYTE, &displacement);
  35.  
  36. condition = (inst >> 8) & 0x0f;
  37.  
  38. /* perform the BCC operation */
  39. if (check_condition (condition))
  40.     PC = OLD_PC + displacement + 2;        
  41.             /* displacement is relative to the end of the instructin word */
  42.  
  43. if (check_condition (condition))
  44.     inc_cyc (10);
  45. else
  46.     inc_cyc ((inst & 0xff != 0) ? 12 : 8);
  47.  
  48. return SUCCESS;
  49.  
  50. }
  51.  
  52.  
  53.  
  54.  
  55. int    DBCC()
  56. {
  57. long    displacement;
  58. int    reg;
  59.  
  60. mem_request(&PC, (long) WORD, &displacement);
  61. from_2s_comp (displacement, (long) WORD, &displacement);
  62. reg = inst & 0x07;
  63.  
  64. /* perform the DBCC operation */
  65. if (check_condition ((inst >> 8) & 0x0f))
  66.     inc_cyc (12);
  67. else
  68.     {
  69.     D[reg] = (D[reg] & ~WORD) | ((short)((D[reg] & 0xffff) - 1));
  70.     if ((D[reg] & 0xffff) == -1)
  71.         inc_cyc (14);
  72.     else
  73.         {
  74.         inc_cyc (10);
  75.         PC = OLD_PC + displacement + 2;
  76.             /* displacement is relative to the end of the instructin word */
  77.         }
  78.     }
  79.  
  80. return SUCCESS;
  81.  
  82. }
  83.  
  84.  
  85. int    SCC()
  86. {
  87. int    condition;
  88.  
  89. if (eff_addr ((long) BYTE, DATA_ALT_ADDR, TRUE))
  90.     return (BAD_INST);        /* bad instruction format */
  91.  
  92. /* perform the SCC operation */
  93. condition = (inst >> 8) & 0x0f;
  94. if (check_condition (condition))
  95.     put (EA1, (long) BYTE, (long) BYTE);
  96. else
  97.     put (EA1, (long) 0, (long) BYTE);
  98.  
  99. if (inst & 0x0030 == 0)
  100.     inc_cyc (check_condition (condition) ? 6 : 4);
  101. else
  102.     inc_cyc (8);
  103.  
  104. return SUCCESS;
  105.  
  106. }
  107.  
  108.  
  109.  
  110. int    BRA()
  111. {
  112. long    displacement;
  113.  
  114. displacement = inst & 0xff;
  115. if (displacement == 0) 
  116.     {
  117.     mem_request (&PC, (long) WORD, &displacement);
  118.     from_2s_comp (displacement, (long) WORD, &displacement);
  119.     }
  120. else
  121.     from_2s_comp (displacement, (long) BYTE, &displacement);
  122.  
  123. /* perform the BRA operation */
  124. PC = OLD_PC + displacement + 2;
  125.             /* displacement is relative to the end of the instructin word */
  126.  
  127. inc_cyc (10);
  128.  
  129. return SUCCESS;
  130.  
  131. }
  132.  
  133.  
  134.  
  135. int    BSR()
  136. {
  137. long    displacement;
  138.  
  139. displacement = inst & 0xff;
  140. if (displacement == 0) 
  141.     {
  142.     mem_request (&PC, (long) WORD, &displacement);
  143.     from_2s_comp (displacement, (long) WORD, &displacement);
  144.     }
  145. else
  146.     from_2s_comp (displacement, (long) BYTE, &displacement);
  147.  
  148. /* perform the BSR operation */
  149. A[a_reg(7)] -= 4;
  150. put (&memory[A[a_reg(7)]], PC, LONG);
  151. PC = OLD_PC + displacement + 2;
  152.             /* displacement is relative to the end of the instructin word */
  153.  
  154. inc_cyc (18);
  155.  
  156. return SUCCESS;
  157.  
  158. }
  159.  
  160.  
  161.  
  162. int    JMP()
  163. {
  164.  
  165. if (eff_addr ((long) WORD, CONTROL_ADDR, FALSE))
  166.     return (BAD_INST);        /* bad instruction format */
  167.  
  168. /* perform the JMP operation */
  169. PC = (int) ((int)EA1 - (int)&memory[0]);
  170.  
  171. switch (eff_addr_code (inst, 0)) {
  172.     case 0x02 : inc_cyc (8);
  173.                 break;
  174.     case 0x05 : inc_cyc (10);
  175.                 break;
  176.     case 0x06 : inc_cyc (14);
  177.                 break;
  178.     case 0x07 : inc_cyc (10);
  179.                 break;
  180.     case 0x08 : inc_cyc (12);
  181.                 break;
  182.     case 0x09 : inc_cyc (10);
  183.                 break;
  184.     case 0x0a : inc_cyc (14);
  185.                 break;
  186.     default   : break;
  187.     }
  188.  
  189. return SUCCESS;
  190.  
  191. }
  192.  
  193.  
  194.  
  195.  
  196.  
  197. int    JSR()
  198. {
  199.  
  200. if (eff_addr ((long) WORD, CONTROL_ADDR, FALSE))
  201.     return (BAD_INST);        /* bad instruction format */
  202.  
  203. /* push the longword address immediately following PC on the system stack */
  204. /* then change the PC */
  205. A[a_reg(7)] -= 4;
  206. put (&memory[A[a_reg(7)]], PC, LONG);
  207. PC = (int) ((int)EA1 - (int)&memory[0]);
  208.  
  209. switch (eff_addr_code (inst, 0)) {
  210.     case 0x02 : inc_cyc (16);
  211.                 break;
  212.     case 0x05 : inc_cyc (18);
  213.                 break;
  214.     case 0x06 : inc_cyc (22);
  215.                 break;
  216.     case 0x07 : inc_cyc (18);
  217.                 break;
  218.     case 0x08 : inc_cyc (20);
  219.                 break;
  220.     case 0x09 : inc_cyc (18);
  221.                 break;
  222.     case 0x0a : inc_cyc (22);
  223.                 break;
  224.     default   : break;
  225.     }
  226.  
  227. return SUCCESS;
  228.  
  229. }
  230.  
  231.  
  232. int    RTE()
  233. {
  234. long    temp;
  235.  
  236. if (!(SR & sbit))
  237.     return (NO_PRIVILEGE);
  238.  
  239. mem_request (&A[8], (long) WORD, &temp);
  240. SR = temp & WORD;
  241. mem_request (&A[8], LONG, &PC);
  242.  
  243. inc_cyc (20);
  244.  
  245. return SUCCESS;
  246.  
  247. }
  248.  
  249.  
  250.  
  251. int    RTR()
  252. {
  253. long    temp;
  254.  
  255. mem_request (&A[a_reg(7)], (long) BYTE, &temp);
  256. SR = (SR & 0xff00) | (temp & 0xff);
  257.  
  258. mem_request (&A[a_reg(7)], LONG, &PC);
  259.  
  260. inc_cyc (20);
  261.  
  262. return SUCCESS;
  263.  
  264. }
  265.  
  266.  
  267.  
  268. int    RTS()
  269. {
  270.  
  271. mem_request (&A[a_reg(7)], LONG, &PC);
  272.  
  273. inc_cyc (16);
  274.  
  275. return SUCCESS;
  276.  
  277. }
  278.  
  279.  
  280.  
  281. int    NOP()
  282. {
  283.  
  284. inc_cyc (4);
  285.  
  286. return SUCCESS;
  287.  
  288. }
  289.  
  290.