home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Emulation / Atari800 / sio_obsolete.c < prev    next >
C/C++ Source or Header  |  1997-08-13  |  7KB  |  350 lines

  1. void SIO_SEROUT (unsigned char byte, int cmd)
  2. {
  3.   checksum += (unsigned char)byte;
  4.   while (checksum > 255)
  5.     checksum = checksum - 255;
  6.  
  7. #ifdef DEBUG
  8.   printf ("SIO_SEROUT: byte = %x, checksum = %x, cmd = %d\n",
  9.       byte, checksum, cmd);
  10. #endif
  11.  
  12.   if (cmd)
  13.     {
  14.       CommandFrame[ncmd++] = byte;
  15.       if (ncmd == 5)
  16.     {
  17.       Command_Frame ();
  18.  
  19.       offst = 0;
  20.       checksum = 0;
  21.       ncmd = 0;
  22.     }
  23.       else
  24.     {
  25.       DELAYED_SEROUT_IRQ = 1;
  26.     }
  27.  
  28.       if (CommandFrame[0] == 0)
  29.     ncmd = 0;
  30.     }
  31.   else if (sio_state == SIO_Put)
  32.     {
  33.       DataBuffer[buffer_offset++] = byte;
  34.       if (buffer_offset == 130)
  35.     {
  36.       int sector;
  37.       int dskno;
  38.       int i;
  39.  
  40.       checksum = 0;
  41.  
  42.       for (i=1;i<129;i++)
  43.         {
  44.           checksum += (unsigned char)DataBuffer[i];
  45.           while (checksum > 255)
  46.         checksum = checksum - 255;
  47.         }
  48.  
  49.       if (checksum != DataBuffer[129])
  50.         {
  51.           printf ("Direct SIO Write Error\n");
  52.           printf ("Calculated Checksum = %x\n", checksum);
  53.           printf ("Actual Checksum = %x\n", DataBuffer[129]);
  54.           exit (1);
  55.         }
  56.  
  57.       dskno = CommandFrame[0] - 0x31;
  58.       sector = CommandFrame[2] + CommandFrame[3] * 256;
  59.  
  60. #ifdef DEBUG
  61.       printf ("Sector: %d(%x)\n", sector, sector);
  62. #endif
  63.  
  64.       SeekSector (dskno, sector);
  65.  
  66.       write (disk[dskno], &DataBuffer[1], 128);
  67.       DataBuffer[buffer_offset] = 0x41; /* ACK */
  68.       DataBuffer[buffer_offset+1] = 0x43; /* OPERATION COMPLETE */
  69.       buffer_size = buffer_offset + 2;
  70.       DELAYED_SEROUT_IRQ = 1;
  71.       DELAYED_XMTDONE_IRQ = 3;
  72.       DELAYED_SERIN_IRQ = 7;
  73.       DELAYED_XMTDONE_IRQ = 5;
  74.       DELAYED_SERIN_IRQ = 150;
  75.     }
  76.       else
  77.     {
  78.       DELAYED_SEROUT_IRQ = 4;
  79.     }
  80.     }
  81.   else
  82.     {
  83.       DELAYED_SEROUT_IRQ = 1;
  84.       ncmd = 0;
  85.     }
  86. }
  87.  
  88. int SIO_SERIN (void)
  89. {
  90.   int byte;
  91.  
  92.   if (buffer_offset < buffer_size)
  93.     {
  94.       byte = (int)DataBuffer[buffer_offset++];
  95.  
  96. #ifdef DEBUG
  97.       printf ("SERIN: byte = %x\n", byte);
  98. #endif
  99.  
  100.       if (buffer_offset < buffer_size)
  101.     {
  102. #ifdef DEBUG
  103.       printf ("Setting SERIN Interrupt again\n");
  104. #endif
  105.       DELAYED_SERIN_IRQ = 3;
  106.       DELAYED_SERIN_IRQ = 4;
  107.     }
  108.     }
  109.  
  110.   return byte;
  111. }
  112.  
  113. void SIO (void)
  114. {
  115.   /* UBYTE DDEVIC = memory[0x0300]; */
  116.   UBYTE DUNIT = memory[0x0301];
  117.   UBYTE DCOMND = memory[0x0302];
  118.   /* UBYTE DSTATS = memory[0x0303]; */
  119.   UBYTE DBUFLO = memory[0x0304];
  120.   UBYTE DBUFHI = memory[0x0305];
  121.   /* UBYTE DTIMLO = memory[0x0306]; */
  122.   UBYTE DBYTLO = memory[0x0308];
  123.   UBYTE DBYTHI = memory[0x0309];
  124.   UBYTE DAUX1 = memory[0x030a];
  125.   UBYTE DAUX2 = memory[0x030b];
  126.  
  127.   int    sector;
  128.   int    buffer;
  129.   int    count;
  130.   int    i;
  131.  
  132.   if (drive_status[DUNIT-1] != Off)
  133.     {
  134.       if (disk[DUNIT-1] != -1)
  135.     {
  136.       int offset;
  137.  
  138.       sector = DAUX1 + DAUX2 * 256;
  139.       buffer = DBUFLO + DBUFHI * 256;
  140.       count = DBYTLO + DBYTHI * 256;
  141.  
  142.       switch (format[DUNIT-1])
  143.         {
  144.         case XFD :
  145.           offset = (sector-1)*128+0;
  146.           break;
  147.         case ATR :
  148.           if (sector < 4)
  149.         offset = (sector-1) * 128 + 16;
  150.           else
  151.         offset = (sector - 1) * sectorsize[DUNIT-1] + 16;
  152. /*
  153.    offset = 3*128 + (sector-4) * sectorsize[DUNIT-1] + 16;
  154. */
  155.           break;
  156.         default :
  157.           printf ("Fatal Error in atari_sio.c\n");
  158.           Atari800_Exit (FALSE);
  159.           exit (1);
  160.         }
  161.  
  162.       lseek (disk[DUNIT-1], offset, SEEK_SET);
  163.  
  164. #ifdef DEBUG
  165.       printf ("SIO: DCOMND = %x, SECTOR = %d, BUFADR = %x, BUFLEN = %d\n",
  166.           DCOMND, sector, buffer, count);
  167. #endif
  168.  
  169.       switch (DCOMND)
  170.         {
  171.         case 0x50 :
  172.         case 0x57 :
  173.           if (drive_status[DUNIT-1] == ReadWrite)
  174.         {
  175.           write (disk[DUNIT-1], &memory[buffer], count);
  176.           regY = 1;
  177.           ClrN;
  178.         }
  179.           else
  180.         {
  181.           regY = 146;
  182.           SetN;
  183.         }
  184.           break;
  185.         case 0x52 :
  186.           read (disk[DUNIT-1], &memory[buffer], count);
  187.           regY = 1;
  188.           ClrN;
  189.           break;
  190.         case 0x21 : /* Single Density Format */
  191.         case 0x22 : /* Duel Density Format */
  192.         case 0x66 : /* US Doubler Format - I think! */
  193.           regY = 1;
  194.           ClrN;
  195.           break;
  196. /*
  197.    Status Request from Atari 400/800 Technical Reference Notes
  198.  
  199.    DVSTAT + 0    Command Status
  200.    DVSTAT + 1    Hardware Status
  201.    DVSTAT + 2    Timeout
  202.    DVSTAT + 3    Unused
  203.  
  204.    Command Status Bits
  205.  
  206.    Bit 0 = 1 indicates an invalid command frame was received
  207.    Bit 1 = 1 indicates an invalid data frame was received
  208.    Bit 2 = 1 indicates that a PUT operation was unsuccessful
  209.    Bit 3 = 1 indicates that the diskete is write protected
  210.    Bit 4 = 1 indicates active/standby
  211.    
  212.    plus
  213.  
  214.    Bit 5 = 1 indicates double density
  215.    Bit 7 = 1 indicates duel density disk (1050 format)
  216. */
  217.         case 0x53 :    /* Get Status */
  218.           /*
  219.           for (i=0;i<count;i++)
  220.         {
  221.           if (sectorsize[DUNIT-1] == 256)
  222.             memory[buffer+i] = 32 + 16;
  223.           else
  224.             memory[buffer+i] = 16;
  225.         }
  226.         */
  227.           if (count!=4) {
  228.         regY = 146;
  229.         SetN;
  230.         break;
  231.           }
  232.           if (drive_status[DUNIT-1] == ReadWrite) {
  233.         memory[buffer]=(sectorsize[DUNIT-1] == 256)?(32+16):(16);
  234.         memory[buffer+1]=192;
  235.           } else {
  236.         memory[buffer]=(sectorsize[DUNIT-1] == 256)?(32):(0);
  237.         memory[buffer+1]=64;
  238.           }        
  239.           if (sectorcount[DUNIT-1]==1040) memory[buffer]|=128;
  240.           memory[buffer+2]=1;
  241.           memory[buffer+3]=0;
  242.           regY = 1;
  243.           ClrN;
  244.           break;
  245.         default :
  246.           printf ("SIO: DCOMND = %0x\n", DCOMND);
  247.           regY = 146;
  248.           SetN;
  249.           break;
  250.         }
  251.     }
  252.       else
  253.     {
  254.       regY = 146;
  255.       SetN;
  256.     }
  257.     }
  258.   else
  259.     {
  260.       regY = 138;
  261.       SetN;
  262.     }
  263.  
  264.   memory[0x0303] = regY;
  265. }
  266. /*
  267.   printf ("Command frame: %02x %02x %02x %02x %02x\n",
  268.       CommandFrame[0], CommandFrame[1], CommandFrame[2],
  269.       CommandFrame[3], CommandFrame[4]);
  270. */
  271.   
  272.   switch (CommandFrame[1]) {
  273.     case 'R' : /* Read */
  274.       {
  275.     int sector;
  276.     int dskno;
  277.     int i;
  278.     int checksum;
  279.  
  280.     dskno = CommandFrame[0] - 0x31;
  281.     sector = CommandFrame[2] + CommandFrame[3] * 256;
  282.     SeekSector (dskno, sector);
  283.     
  284.     DataBuffer[0] = 0x41; /* ACK */
  285.     DataBuffer[1] = 0x43; /* OPERATION COMPLETE */
  286.  
  287.     read (disk[dskno], &DataBuffer[2], 128);
  288.     checksum = 0;
  289.     for (i=2;i<130;i++) {
  290.         checksum += (unsigned char)(DataBuffer[i]);
  291.         while (checksum > 255)
  292.           checksum = checksum - 255;
  293.       }
  294.     DataBuffer[130] = checksum;
  295.     ExpectedBytes = 131;
  296.     DataIndex = 0;
  297.     DELAYED_SERIN_IRQ += SERIN_INTERVAL+312;
  298.       }
  299.       break;
  300.     case 'S' : /* Status */
  301. #ifdef DEBUG
  302.       printf ("Status command\n");
  303. #endif
  304.       DataBuffer[0] = 0x41; /* ACK */
  305.       DataBuffer[1] = 0x43; /* OPERATION COMPLETE */
  306.  
  307.       /* Should be really done in a different way */
  308.       DataBuffer[2] = 0x10; /* 2ea */
  309.       DataBuffer[3] = 0x00; /* 2eb */
  310.       DataBuffer[4] = 0x01; /* 2ec */
  311.       DataBuffer[5] = 0x00; /* 2ed */
  312.       DataBuffer[6] = 0x11; /* Checksum */
  313.  
  314.       ExpectedBytes = 7;
  315.       DataIndex = 0;
  316.       DELAYED_SERIN_IRQ += SERIN_INTERVAL;
  317.       break;
  318.     case 'W' : /* Write with verify */
  319.     case 'P' : /* Put without verify */
  320.       DataBuffer[0] = 0x41; /* ACK */
  321.       
  322.       ExpectedBytes = 1;
  323.       DataIndex = 0;
  324.  
  325.       DELAYED_SERIN_IRQ += SERIN_INTERVAL;
  326.       break;
  327.     case '!' : /* Format */
  328.       printf ("Format command\n");
  329.       break;
  330.     case 'T' : /* Read Address */
  331.       printf ("Read Address command\n");
  332.       break;
  333.     case 'Q' : /* Read Spin */
  334.       printf ("Read Spin command\n");
  335.       break;
  336.     case 'U' : /* Motor On */
  337.       printf ("Motor On command\n");
  338.       break;
  339.     case 'V' : /* Verify Sector */
  340.       printf ("Verify Sector\n");
  341.       break;
  342.     default :
  343.       printf ("Command frame: %02x %02x %02x %02x %02x\n",
  344.           CommandFrame[0], CommandFrame[1], CommandFrame[2],
  345.           CommandFrame[3], CommandFrame[4]);
  346.       break;
  347.   }
  348. }
  349.  
  350.