All pastes #253628 Raw Edit

Something

public c v1 · immutable
#253628 ·published 2006-11-20 23:15 UTC
rendered paste body
#include <dos.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>int main(){    unsigned short data;    int i;    asm("cli");    printf("Setting ATN to false to reinit drive\n");    outportb(0x37a, 0x24);    sleep(2);        printf("Setting ATN and clock to true, then waiting 1000us\n");    outportb(0x37a, 0x27);    usleep(1000);    printf("Checking if data flag is set to true\n");    if (!(inportb(0x37a) & 8))    {        printf("Data flag false, handshake failed\n");        exit(1);    }        outportb(0x37a, 0x25); // setting clock to false    for (i = 0; i < 65535; i++)    {        if (!(inportb(0x37a) & 8))            break;        usleep(1);    }    if (i == 65535)    {        printf("Data line still true, handshake failed\n");        exit(1);    }    outportb(0x37a, 0x27); // clock line to true    for (i = 0; i < 65535; i++)    {        if (inportb(0x37a) & 8)            break;        usleep(1);    }    if (i != 65535)    {        printf("Data: %x\n", inportb(0x37a));        printf("Data went high, drive's trying to ACK an EOI. Failed timing.\n");        exit(1);    }    data = 0x28;    for (i = 0; i < 8; i++)    {        usleep(10000);        if ((data & 1))        {            outportb(0x37a, 0x27);            outportb(0x37a, 0x25);        }        else        {            outportb(0x37a, 0x2f);            outportb(0x37a, 0x2d);        }        usleep(10000);        outportb(0x37a, 0x27);        data = data >> 1;    }    //printf("Data3: %x\n", inportb(0x37a));    if (i != 8)    {        printf("Send failed!\n");    }    else    {        for (i = 0; i < 655350; i++)        {            if (inportb(0x37a) & 8)                break;        }                if (i != 655350)        {            printf("Byte sent, %d\n", i);            printf("Data3: %x\n", inportb(0x37a));        }        else            printf("Byte send failed, timed out\n");    }    asm("sti");    return 0;}