home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 405.lha / AppleII_Emulators_src / src-2 / ap_memchk.c < prev    next >
C/C++ Source or Header  |  1990-06-28  |  24KB  |  704 lines

  1. #include <cpu_prog_model.h>
  2. #include <stdio.h>
  3.  
  4. #define _READ  0
  5. #define _WRITE 1
  6.  
  7. #define FALSE  0
  8. #define TRUE   1
  9.  
  10. void  home(),
  11.       bascalc(),
  12.       wait();
  13.  
  14. short real_time(),
  15.       touch_char(),
  16.       dos_io(),
  17.       rwts();
  18.  
  19. short display_page(),
  20.       refresh();
  21.  
  22. char  take_char();
  23.  
  24. fortran void recycl(),
  25.              sleep$();
  26.  
  27. void mem_check( address, value, code, type)
  28. unsigned short int   address;
  29. short              * value;
  30. PM                 * code;
  31. short                type;
  32. {
  33.    char          tecken;
  34.    short         bit_8,
  35.                  area,
  36.                  loop,
  37.                  dummy;
  38.  
  39.    static short  char_number_flag;
  40.  
  41.    switch (type)
  42.    {
  43.       case Func_JSR:   case Func_JMP:
  44.          switch (address >> 12)
  45.          {
  46.             case 0x0:
  47.                switch ( (address >> 8) & 0xF)
  48.                {
  49.                   case 0x3:
  50.                      switch ( (address >> 4) & 0xF)
  51.                      {
  52.                         case 0xD:
  53.                            switch (address & 0xF)
  54.                            {
  55. case 99:/*                              case 0x9:   /* 03D9 */
  56.                                  printf("RWTS\n");
  57.                                  exit(-1);
  58.                                  break;
  59.                            }
  60.                            break;
  61.                      }
  62.                      break;
  63.  
  64.                }
  65.                break;
  66.  
  67.             /* Ordiary RAM */
  68.             case 0x1:   case 0x2:
  69.                break;
  70.  
  71.             case 0x3:
  72.                switch ( (address >> 8) & 0xF)
  73.                {
  74.                   case 0xA:
  75.                      switch ( (address >> 4) & 0xF)
  76.                      {
  77.                         case 0x0:
  78.                            switch (address & 0xF)
  79.                            {
  80.                               case 0x0:   /* 3A00 */
  81.                                  if ( (code->Me [0x3A00] != 0xA2) ||
  82.                                       (code->Me [0x3A01] != 0x11) ||
  83.                                       (code->Me [0x3A02] != 0xCA) ||
  84.                                       (code->Me [0x3A03] != 0xD0) ||
  85.                                       (code->Me [0x3A04] != 0xFD)   )
  86.                                  break;
  87.  
  88.                                  do
  89.                                  {
  90.                                     code->Xr         = 0x00;
  91.                                     code->Me [0x46] += 0x01;
  92.                                     if (code->Me [0x46] == 0x100)
  93.                                     {
  94.                                        code->Me [0x46]  = 0x00;
  95.                                        code->Me [0x47] += 0x01;
  96.                                        code->Me [0x47] &= 0xFF;
  97.                                     }
  98.                                     code->Ac        -= 0x01;
  99.                                  }  while (code->Ac != 0x00);
  100.                                  code->PC = 0x3A10;
  101.                                  break;
  102.                            }
  103.                            break;
  104.                      }
  105.                      break;
  106.  
  107.                }
  108.                break;
  109.  
  110.             /* Ordiary RAM */
  111.             case 0x4:   case 0x5:   case 0x6:   case 0x7:   case 0x8:
  112.             case 0x9:   case 0xA:
  113.                break;
  114.  
  115.             case 0xB:
  116.                switch ( (address >> 8) & 0xF)
  117.                {
  118.                   case 0xA:
  119.                      switch ( (address >> 4) & 0xF)
  120.                      {
  121.                         case 0x0:
  122.                            switch (address & 0xF)
  123.                            {
  124.                               case 0x0:   /* BA00 */
  125.                                  if ( (code->Me [0x3A00] != 0xA2) ||
  126.                                       (code->Me [0x3A01] != 0x11) ||
  127.                                       (code->Me [0x3A02] != 0xCA) ||
  128.                                       (code->Me [0x3A03] != 0xD0) ||
  129.                                       (code->Me [0x3A04] != 0xFD)   )
  130.                                  break;
  131.  
  132.                                  do
  133.                                  {
  134.                                     code->Xr         = 0x00;
  135.                                     code->Me [0x46] += 0x01;
  136.                                     if (code->Me [0x46] == 0x100)
  137.                                     {
  138.                                        code->Me [0x46]  = 0x00;
  139.                                        code->Me [0x47] += 0x01;
  140.                                        code->Me [0x47] &= 0xFF;
  141.                                     }
  142.                                     code->Ac        -= 0x01;
  143.                                  }  while (code->Ac != 0x00);
  144.                                  code->PC = 0x3A10;
  145.                                  break;
  146.                            }
  147.                            break;
  148.                      }
  149.                      break;
  150.  
  151.                   case 0x7:
  152.                      switch ( (address >> 4) & 0xF)
  153.                      {
  154.                         case 0xB:
  155.                            switch (address & 0xF)
  156.                            {
  157.                               case 0x5:   /* B7B5 */
  158.                                  if (code->Tr)
  159.                                     printf("Attempt to use RWTS from $B7B5.\n");
  160.                                  rwts( code);
  161.                                  break;
  162.                            }
  163.                            break;
  164.                      }
  165.                      break;
  166.                }
  167.                break;
  168.  
  169.             case 0xC:
  170.                switch ( (address >> 8) & 0xF)
  171.                {
  172.                   case 0x0:
  173.                      printf( "Access violation.\n");
  174.                      exit (-1);
  175.  
  176.                   case 0x1:
  177.                      switch ( (address >> 4) & 0xF)
  178.                      {
  179.                         case 0x0:
  180.                            printf("Back to primos\n");
  181.                            code->Qu = TRUE;
  182.                            code->Ex = TRUE;
  183.                            break;
  184.                      }
  185.                      break;
  186.  
  187.                   case 0x3:
  188.                      switch ( (address >> 4) & 0xF)
  189.                      {
  190.                         case 0x0:
  191.                            switch (address & 0xF)
  192.                            {
  193.                               case 0x0:   /* C300 */
  194.                                  if (code->Me [0xC300] == 0)
  195.                                  {
  196.                                     printf("80-Screen isn't included yet.\n");
  197.                                     code->PC = 0xFE93;   /* Setvid (PR#0) */
  198.                                  }
  199.                                  break;
  200.  
  201.                               case 0x1:   /* C301 */
  202.                                  refresh( code);
  203.                                  RTS( code);
  204.                                  break;
  205.                            }
  206.                            break;
  207.                      }
  208.                      break;
  209.  
  210.                   case 0x5:    /* C500 */
  211.                      if (code->Me [0xC500] == 0)
  212.                      {
  213.                         printf("Time isn't included yet.\n");
  214.                         code->PC = 0xFE93;   /* Setvid (PR#0) */
  215.                      }
  216.                      break;
  217.  
  218.                   case 0x6:
  219.                      /* Disk drive */
  220.                      break;
  221.  
  222.                   default:
  223.                      printf("Can't find $C%03x\n", address & 0xFFF);
  224.                      exit(-1);
  225.                }
  226.                break;
  227.  
  228.             case 0xD:   case 0xE:
  229.                /* Basic */
  230.                break;
  231.  
  232.             case 0xF:
  233.                switch ( (address >> 8) & 0xF)
  234.                {
  235.                   case 0xB:
  236.                      switch ( (address >> 4) & 0xF)
  237.                      {
  238.                         case 0xC:
  239.                            switch (address & 0xF)
  240.                            {
  241.                               case 0x1:   /* FBC1 */
  242.                                  bascalc( code->Ac, code);
  243.                                  code->Tl --;
  244.                                  code->PC = 0xFBD8;
  245.                            }
  246.                            break;
  247.  
  248.                         case 0xF:
  249.                            switch (address & 0xF)
  250.                            {
  251. case 999:/*                              case 0xD:   /* FBFD   vidout */
  252.                                  tecken = code->Ac;
  253.                                  switch (tecken >> 5)
  254.                                  {
  255.                                     case 0x4:  /* Ctrls */
  256.                                        switch (tecken & 0x1F)
  257.                                        {
  258.                                           case 0x7:
  259.                                              printf("\207");
  260.                                              code->Tl --;
  261.                                              code->PC = 0xFC2B;
  262.                                              break;
  263.                                        }
  264.                                        break;
  265.  
  266.                                     case 0x5:   case 0x6:   /* Normal */
  267.                                        printf( "%c", tecken | 0x80);
  268.  
  269.                                        bascalc( code->Me [0x25], code);
  270.  
  271.                                        if (code->Me [0x24] < code->Me [0x21])
  272.                                        {
  273.                                           printf( "%c", tecken | 0x80);
  274.                                           (code->Me [0x24])++;
  275.                                           code->Tl --;
  276.                                           code->PC = 0xFDFF;
  277.                                        }
  278.                                        break;
  279.  
  280.                                     default:
  281.                                        /* Let is pas without no ation */
  282. /*printf( "[^%c]", tecken | 0x40);*/
  283.                                  }
  284.                                  break;
  285.  
  286.                               default:
  287. /*
  288.                                  printf("Can't find $FBF%x\n", address & 0xF);
  289. */
  290.                            }
  291.                            break;
  292.  
  293.                         default:
  294. /*
  295.                            printf("Can't find $FB%x\n", address & 0xFF);
  296. */
  297.                   }
  298.                   break;
  299.  
  300.                   case 0xC:
  301.                      switch ( (address >> 4) & 0xF)
  302.                      {
  303.                         case 0x5:
  304.                            switch (address & 0xF)
  305.                            {
  306.                               case 0x8:   /* FC58 = HOME */
  307.                                  home( code);
  308.                                  code->PC = 0xFC22;  /* VTAB */
  309.                                  break;
  310.  
  311.                            }
  312.                            break;
  313.  
  314.                         case 0xA:
  315.                            switch (address & 0xF)
  316.                            {
  317.                               case 0x8:   /* FCA8 */
  318.                                  wait( code);
  319.                                  code->Tl --;
  320.                                  code->PC = 0xFCB3;
  321.                                  break;
  322.  
  323.                               default:
  324. /*
  325.                                  printf("Can't find $FCA%x\n", address & 0xF);
  326. */
  327.                            }
  328.                            break;
  329.  
  330.                         default:
  331. /*
  332.                            printf("Can't find $FC%02x\n", address & 0xFF);
  333. */
  334.                       }
  335.                      break;
  336.  
  337.                   case 0xF:
  338.                      switch ( (address >> 4) & 0xF)
  339.                      {
  340.                         case 0x3:
  341.                            switch (address & 0xF)
  342.                            {
  343.                               case 0xA:   /* FF3A = BELL */
  344.                                  printf("\207");
  345.                                  code->Tl --;
  346.                                  code->PC = 0xFDFF;  /* RTS */
  347.                                  break;
  348.  
  349.                               default:
  350. /*
  351.                                  printf("Can't find $FF3%x\n", address & 0xF);
  352. */
  353.                            }
  354.                            break;
  355.  
  356.                         default:
  357. /*
  358.                            printf("Can't find $FF%02x\n", address & 0xFF);
  359. */
  360.                      }
  361.                      break;
  362.  
  363.                   default:
  364. /*
  365.                      printf("Can't find $F%03x\n", address & 0xFFF);
  366. */
  367.                }
  368.                break;
  369.  
  370.             default:
  371.                printf("Can't find $%04x\n", address);
  372.          }
  373.          break;
  374.  
  375.       case Func_LOAD:
  376.          switch ( (address >> 12) & 0xF)
  377.          {
  378.             case 0x0:
  379.                switch ( (address >> 8) & 0xF)
  380.                {
  381.                   /* Take no action, this is the screen */
  382.                   case 0x4:   case 0x5:   case 0x6:   case 0x7:
  383.                      break;
  384.                }
  385.                break;
  386.  
  387.             case 0xC:
  388.                switch ( (address >> 8) & 0xF)
  389.                {
  390.                   case 0x0:
  391.                      switch ( (address >> 4) & 0xF)
  392.                      {
  393.                         case 0x0:   /* 0xC000 */
  394.                            if (code->Qu)
  395.                               return;
  396.  
  397.                            if (touch_char( value) )
  398.                            {
  399.                               char_number_flag = 0;
  400.  
  401.                               if (*value == '\233')
  402.                               {
  403.                                  short tecken;
  404.  
  405.                                  skip_if_char();     /* Skip the first ESC */
  406.                                  tecken = take_char();   /* And check next */
  407.  
  408.                                  if (tecken == '\233')
  409.                                  {
  410.                                     code->Qu = TRUE;
  411.                                     code->Mo = Mode_SLOW;
  412.                                     *value  &= 0x7F;  /* value is'n present */
  413.                                     return;
  414.                                  }
  415.                                  char_take_back( *value);
  416.                                  char_take_back( tecken);
  417.  
  418.                               }
  419.                            }
  420.  
  421.                            else
  422.                            {
  423.                               if (char_number_flag < 10)
  424.                                  char_number_flag ++;
  425.                               else
  426. sleep$(100l);
  427. /*                                 recycl();*/
  428.                            }
  429.                            break;
  430.  
  431.                         case 0x1:
  432.                            skip_if_char();
  433.                            break;
  434.  
  435.                         case 0x3:
  436. /*                           printf("Speaker not allowed now! (LOAD)\n");
  437. /*                           exit (-1);*/
  438.                            break;
  439.  
  440.                         case 0x5:
  441.                            switch (address & 0xF)
  442.                            {
  443.                               defalut:
  444.                                  printf("Referns to undefined function.\n");
  445.                                  exit(-1);
  446.                                  break;
  447.  
  448.                            }
  449.                            break;
  450.  
  451.                         case 0xB:
  452.                            switch (address & 0xF)
  453.                            {
  454.                               case 0x1:    case 0x2:
  455.                                  *value = code->Me [address];
  456.                                  break;
  457.  
  458.                               case 0x3:
  459.                                  *value = code->Sl;
  460.  
  461.                            }
  462.                            break;
  463.  
  464.                         case 0xD:
  465.                            switch (address & 0xF)
  466.                            {
  467.                               case 0x0:
  468.                                  *value = real_time( HOUR);
  469.                                  break;
  470.  
  471.                               case 0x1:
  472.                                  *value = real_time( MINUTE);
  473.                                  break;
  474.  
  475.                               case 0x2:
  476.                                  *value = real_time( SECOND);
  477.                                  break;
  478.                            }
  479.                            break;
  480.  
  481.                         case 0x8:
  482.                            if (code->Tr)
  483.                            {
  484.                               printf("\n");
  485.                               printf("Can't Read on address $%04x.\n", address);
  486.                            }
  487. /*
  488.                            code->Mo = Mode_SLOW;
  489.                            code->Qu = TRUE;
  490. */
  491.                            break;
  492.  
  493.                         case 0xE:
  494.                            dos_io( address & 0xF, value, code, _READ);
  495.                            break;
  496.  
  497.                         default:
  498.                            printf("Can't Read on address $%04x.\n", address);
  499.                            code->Mo = Mode_SLOW;
  500.                            code->Qu = TRUE;
  501.                            break;
  502.                      }  /* End of Switch (C0xx) */
  503.                      break;
  504.  
  505.                   default:
  506. /*
  507.                      printf("Can't Read on address $%04x.\n", address);
  508.                      exit(-1);
  509. */
  510.                      break;
  511.                }  /* End of switch (Cxxx) */
  512.                break;
  513.  
  514.             default:
  515.                /* Take no care of the rest */
  516.                break;
  517.          }
  518.          break;
  519.  
  520.       case Func_STORE:
  521.          switch ( (address >> 12) & 0xF)
  522.          {
  523.             case 0x0:
  524.                switch ( (address >> 8) & 0xF)
  525.                {
  526.                   case 0x0:
  527.                      switch ( (address >> 4) & 0xF)
  528.                      {
  529.                         case 0x3:
  530.                            switch (address & 0xF)
  531.                            {
  532.                               case 0x7:   /* (0037) CSWH */
  533.                                  if ( ((code->Sl & 0x10) != 0x10) &&
  534.                                       ((code->Sl & 0x0F) == 0x03) &&
  535.                                       (*value != 0xC3)              )
  536.                                  {
  537. break;
  538.                                     refresh( code);
  539.                                     code->Sl &= 0xF0;
  540.                                     code->Sl |= 0x10;
  541.                                  }
  542.                                  break;
  543.                            }
  544.                            break;
  545.                      }
  546.                      break;
  547.  
  548.                   case 0x4:   case 0x5:   case 0x6:   case 0x7:
  549.                      /* Test if there is a realy Srceen */
  550.                      if ( ((area = display_page( address)) != 0) &&
  551.                           ((code->Sl & 0x0F) != 0x03)               )
  552.                         to_video( address, area, *value);
  553.  
  554.                }
  555.                break;
  556.  
  557.             case 0xC:
  558.                switch ( (address >> 8) & 0xF)
  559.                {
  560.                   case 0x0:
  561.                      switch ( (address >> 4) & 0xF)
  562.                      {
  563.                         case 0x0:
  564. /*
  565.                            printf("Can't Write to 0xC000 $%04x.\n", code->PC);
  566.                            abort();
  567. */
  568.                            break;
  569.  
  570.                         case 0x1:
  571.                            skip_if_char();
  572.                            break;
  573.  
  574.                         case 0x3:   /* C030 */
  575.                            printf("Bell (Not now)\n");
  576. /*                           exit (-1);*/
  577.                            break;
  578.  
  579.                         case 0x5:
  580.                            switch (address & 0xF)
  581.                            {
  582.                               case 0:
  583.                                  printf("Switch to Graph.\n");
  584.                                  exit(-1);
  585.                                  break;
  586.  
  587.                               case 1:
  588.                                  printf("Switch to TEXT.\n");
  589.                                  break;
  590.  
  591.                               case 2:
  592.                                  printf("Switch to Hole_Screen.\n");
  593.                                  break;
  594.  
  595.                               case 3:
  596.                                  printf("Switch to Mixt_screen.\n");
  597.                                  break;
  598.  
  599.                               case 4:
  600.                                  printf("Switch to Screen_1.\n");
  601.                                  break;
  602.  
  603.                               case 5:
  604.                                  printf("Switch to screen_2.\n");
  605.                                  break;
  606.  
  607.                               case 6:
  608.                                  printf("Switch to LOW_Res.\n");
  609.                                  break;
  610.  
  611.                               case 7:
  612.                                  printf("Switch to HI_Res.\n");
  613.                                  break;
  614.  
  615.                            }
  616.                            break;
  617.  
  618.                         case 0x8:
  619.                            switch (address & 0xF)
  620.                            {
  621.                               case 0x0:
  622.                                  if (code->Tr)
  623.                                     printf("RAM card ON.\n");
  624. /*
  625.                                  exit (-1);
  626. */
  627.                                  break;
  628.  
  629.                               case 0x1:
  630.                                  if (code->Tr)
  631.                                     printf("RAM card OFF.\n");
  632. /*
  633.                                  exit (-1);
  634. */
  635.                                  break;
  636.  
  637.                            }
  638.                            break;
  639.  
  640.                         case 0xB:
  641.                            switch (address & 0xF)
  642.                            {
  643.                               case 0x0:   /* C0B0 */
  644.                                  switch( *value)
  645.                                  {
  646.                                     case 0x8D:
  647.                                        printf("\n");
  648.                                        break;
  649.  
  650.                                     default:
  651.                                        printf("%c", *value | 0x80);
  652.                                        break;
  653.                                  }
  654.                                  break;
  655.  
  656.                               case 0x1:    case 0x2:
  657.                                  code->Me [address] = *value;
  658.                                  break;
  659.  
  660.                               case 0x3:
  661.                                  code->Sl = *value;
  662.                                  break;
  663.  
  664.                            }
  665.                            break;
  666.  
  667.                         case 0xE:
  668.                            dos_io( address & 0xF, value, code, _WRITE);
  669.                            break;
  670.  
  671.                         default:
  672.                            printf("Illegal Slot: It's activated.\n");
  673.                            abort();
  674.                            break;
  675.                      }
  676.                      break;
  677.  
  678.                   case 0x1:   case 0x2:   case 0x3:   case 0x4:   case 0x5:
  679.                   case 0x6:   case 0x7:   case 0x8:   case 0x9:   case 0xA:
  680.                   case 0xB:   case 0xC:   case 0xD:   case 0xE:   case 0xF:
  681.                      /* Dos rom */
  682.                      break;
  683.  
  684.                   default:
  685.                      printf("Que!   $%04x.\n", address);
  686.                      abort();
  687.                      break;
  688.                }
  689.  
  690.             default:
  691.                /* Take no care of the rest */
  692.                break;
  693.          }
  694.          break;
  695.  
  696.       default:
  697.          printf("Wrong type (%d) of address check.\n", type);
  698.          exit(-1);
  699.    }
  700.  
  701. }
  702.  
  703.  
  704.