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

  1.  
  2. /***************************** 68000 SIMULATOR ****************************
  3.  
  4. File Name: SIMOPS1.C
  5. Version: 1.0
  6.  
  7. This file contains various routines for simulator operation
  8.  
  9. The routines are :  
  10.  
  11.     mdis(), selbp(), sbpoint(), cbpoint(), dbpoint(), memread(), 
  12.     memwrite()
  13.  
  14. ***************************************************************************/
  15.  
  16.  
  17.  
  18. #include <stdio.h>
  19. #include "extern.h"
  20.  
  21.  
  22.  
  23. int mdis()                              /* display memory */
  24. {
  25. int    i, start, stop;
  26. int    value;
  27. char    mem_val;
  28. char    *inp;
  29.  
  30. inp = gettext(2,"Location? ");
  31. value = eval(inp);
  32. if (errflg)
  33.     {
  34.     windowLine();
  35.     printf("invalid location...");
  36.     return FAILURE;
  37.     }
  38. start = value;
  39.  
  40. if (wcount < 3)            /* check no. of operands entered */
  41.     {
  42.     stop = 0;                /* only one operand was entered, */
  43.                                 /* so only one loc. displayed */
  44.     }
  45. else
  46.     {
  47.     value = eval(wordptr[2]);    /* get second location */
  48.     if(errflg)
  49.         {
  50.         windowLine();
  51.         printf("invalid location...");
  52.         return;
  53.         }
  54.     stop = value - 1;
  55.     }
  56.  
  57.     for (;;)
  58.         {
  59.         windowLine();
  60.         printf("%04x : ",WORD & start);
  61.         for (i=0; i<8; i++)        /* display memory until */
  62.             {            /* stop location is reached */
  63.             mem_val = memread(start++, BYTE);
  64.             printf(" %02x", mem_val & 0xff);
  65.             if (start > stop)
  66.                 {
  67.                 windowLine();
  68.                 return SUCCESS;
  69.                 }
  70.             if (!(start & 0x7)) break;                 /* stay on even boundaries */
  71.  
  72.             if (chk_buf() == 8)                                /* "Halt" from keyboard */
  73.                 return SUCCESS;
  74.             }
  75.         }
  76. }
  77.  
  78.  
  79.  
  80. int selbp()          /* break point set, clear or display routine */
  81. {
  82.     char *choice;
  83.  
  84.     choice = gettext(2,"Set Point, Clear Point, or Display Point ? ");
  85.     if (same("sp",choice))
  86.         sbpoint();
  87.     else if (same("dp",choice))
  88.         dbpoint();
  89.     else if (same("cp",choice))
  90.         cbpoint();
  91.     else {
  92.         cmderr();
  93.         errflg = TRUE;
  94.         return FAILURE;
  95.         }
  96.  
  97. }
  98.  
  99.  
  100.  
  101. int sbpoint()                      /* set break point */
  102. {
  103.     int i, loc;
  104.     char *inp;
  105.  
  106.     inp = gettext(3,"Location? ");        /* get input */
  107.     loc = eval(inp);
  108.     if (errflg) {
  109.         windowLine();
  110.         printf("invalid location...");
  111.         return FAILURE;
  112.         }
  113.  
  114.     /* set breakpoint in table and increment counter */
  115.  
  116.     for (i = 0; i<bpoints; i++)
  117.         if(brkpt[i] == loc)
  118.             return;
  119.     brkpt[bpoints++] = loc;
  120.     if (bpoints > 100)
  121.         bpoints = 100;
  122.  
  123. }
  124.  
  125.  
  126.  
  127. int cbpoint()                   /* clear break point */
  128. {
  129.     int i, j, loc;
  130.     char *inp;
  131.  
  132.     inp = gettext(3,"Location? ");        /* get input */
  133.     loc = eval(inp);
  134.     if (errflg)    {
  135.         windowLine();
  136.         printf("invalid location...");
  137.         return FAILURE;
  138.         }
  139.  
  140.     if (same("all",wordptr[2])) {
  141.         bpoints = 0;
  142.         return SUCCESS;
  143.         }
  144.  
  145.     /* find break point specified */
  146.  
  147.     for (i = 0; i < bpoints; i++) if (brkpt[i] == loc) break;
  148.  
  149.     if (i == bpoints)    /* if not found, print message */
  150.         {
  151.         windowLine();
  152.         printf("no break point at %04x",loc);
  153.         return;
  154.         }
  155.     --bpoints;
  156.     for (j = i; j < bpoints; j++) /* adjust breakpoint table and */
  157.         brkpt[j] = brkpt[j + 1];    /* decrement counter */
  158.  
  159. }
  160.  
  161.  
  162.  
  163. int dbpoint()                         /* display break points */
  164. {
  165.     int i;
  166.  
  167.     windowLine();
  168.     printf("breakpoints are set at the following locations:");
  169.     windowLine();
  170.     for (i = 0; i < bpoints; i++)
  171.         printf("%2d)   %04x", i+1, WORD & brkpt[i]);
  172.     return SUCCESS;
  173.  
  174. }
  175.  
  176.  
  177.  
  178. int memread(loc, MASK)                    /* read memory at given location */
  179. int loc;            /* mask is used to prevent reading out of memory array */
  180. {
  181.     int value;
  182.  
  183.     /* handler for MC6850 PIA */
  184.     if ((loc & 0xfffe) == 0x1000) 
  185.         {
  186.          /* in folding of port1 */
  187.         if ((loc & 0x0001) == 0)    /* status register */
  188.             value = (port1[2] & 0x00ff);
  189.         else
  190.             {
  191.             value = (port1[3] & 0x00ff);    /* recieve data */
  192.             port1[2] &= 0xfe;
  193.             port1[2] |= 0x80;
  194.             }
  195.         return(value);
  196.         }
  197.     value = memory[loc & ADDRMASK] & MASK;
  198.     return value;
  199.  
  200. }
  201.  
  202.  
  203.  
  204. int memwrite(loc, value)          /* write given value into given location */
  205. int loc;                 /* mask is used to prevent writing outside memory */
  206. long value;                                                        
  207. {
  208.  
  209.     /* handler for MC6850 PIA                   THIS HANDLER IS COMMENTED OUT
  210.     if ((loc & 0xfffe) == 0x1000)
  211.         /* within port1 folding * /
  212.         {
  213.         p1dif = TRUE;
  214.         if ((loc & 0x0001) == 0)    /* control register * /
  215.             port1[0] = value;
  216.         else
  217.             /* transmit data * /
  218.             {
  219.             port1[1] = value;    /* load port * /
  220.             port1[2] &= 0xfd;    /* adjust status register * /
  221.             port1[2] |= 0x80;
  222.             }
  223.         return;
  224.         }
  225.  
  226.     */
  227.  
  228.         if ((value & 0xffff0000) != 0)
  229.             {
  230.             memory[loc & ADDRMASK] = (char) ((value >> 24) & BYTE);
  231.             memory[(loc + 1) & ADDRMASK] = (char) ((value >> 16) & BYTE);
  232.             memory[(loc + 2) & ADDRMASK] = (char) ((value >> 8) & BYTE);
  233.             memory[(loc + 3) & ADDRMASK] = (char) (value & BYTE);
  234.             }
  235.         else
  236.         if ((value & ~BYTE) != 0)
  237.             {
  238.             memory[loc & ADDRMASK] = (char) ((value & ~BYTE) >> 8);
  239.             memory[(loc + 1) & ADDRMASK] = (char) (value & BYTE);
  240.             }
  241.         else
  242.             memory[loc & ADDRMASK] = (char) value;
  243. }
  244.  
  245.  
  246.