//////////////////////////////////////////////////////////////////
// File - ISAPNP_SCAN.C
//
// A utility for getting a list of the ISA PnP cards installed 
// and the resources allocated for each one of them (memory 
// ranges, IO ranges and interrupts).
// 
//////////////////////////////////////////////////////////////////

#include <windows.h>
#include <winioctl.h>
#include "../../include/windrvr.h"
#include "../shared/print_struct.h"
#include <stdio.h>

int main (int argc, char *argv[]) 
{
    HANDLE hWD;
    WD_VERSION ver;
    WD_ISAPNP_SCAN_CARDS scanCards;
    WD_ISAPNP_CARD_INFO cardInfo;
    DWORD i, j;

    hWD = WD_Open();
    // Check whether handle is valid and version OK
    if (hWD==INVALID_HANDLE_VALUE) 
    {
        printf("Cannot open WinDriver device\n");
        return -1;
    }

    BZERO(ver);
    WD_Version(hWD,&ver);
    if (ver.dwVer<WD_VER) 
    {
        printf("error - incorrect WinDriver version\n");
        WD_Close (hWD);
        return -1;
    }

    printf ("ISA PnP bus scan:\n\n");
    BZERO(scanCards);
    WD_IsapnpScanCards (hWD, &scanCards);
    for (i=0; i<scanCards.dwCards; i++)
    {
        printf ("Card %d: %s\n", i, scanCards.Card[i].cIdent);
        for (j=0; j<scanCards.Card[i].dwLogicalDevices; j++)
        {
            BZERO(cardInfo);
            cardInfo.cardId = scanCards.Card[i].cardId;
            cardInfo.dwLogicalDevice = j;
            WD_IsapnpGetCardInfo(hWD, &cardInfo);
            printf ("Device %d: %s\n", j, cardInfo.cIdent);
            WD_CARD_print(&cardInfo.Card, "   ");
        }
    }

    WD_Close (hWD);

    return 0;
}