// LPT_Test.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

/*
 * sample.cpp --- Sample File for Handling IOSCMctl.cpp.
 *
 * This sample is for Windows2000/XP.
 *
 * Copyright (C) 2003-2007 by mag44(JE1TSN/M.Watanabe), all rights reserved.
 */

#include "stdafx.h"
#include "ioscm.h"

#include <stdio.h>
#include <conio.h>
#include <dos.h>

// Change this address first, depending on your PC.
//#define PRN_PORT (0x3bc)
#define PRN_PORT (0x378)
 
int _tmain(int argc, _TCHAR* argv[])
{
    int ret;
    unsigned int  addr;
    int c;
	int d;

	addr = PRN_PORT; 
    printf("\nRead/Write Access to I/O Port '0x%x', hit any key (ESC to Cancel) : ", addr);
    if (getchar()  == 0x1b)
       {
       printf("\n");
       return(-1);
       }
    printf("\n");

    // Start I/O Access (IOSCM) 
    ret = IOSCM_Start();   // Call this first(Windows95/98/Me/NT/2000/XP)
    if (ret & IOSCM_ERROR) // Check Bit0 if error occurred or not.
       {
       if (ret & IOSCM_INVOS) // V1.01
          printf("\nError: GetVersionEx() Failed.\n\n");
       else 
          printf("\nError: Cannot Initialize IOSCM Device (WinNT/2000/XP).\n\n");
       return(-1);
       }

	// I/O access available.
	printf("\n 1: output cmd reg,  2: output data reg,  3: end program = ");
    scanf_s("%d",&c);
	while ((c==1)||(c==2))
 	   {
       if (c==1)
		  {
	      printf(" xx: data of output cmd reg = ");
          scanf_s("%x",&d);
          _outp(addr+2,d); // Output Command Register
	      }
          else
	      {
		  if (c==2)
	         {
		     printf(" xx: data of output data reg = ");
             scanf_s("%x",&d);
             _outp(addr,d); // Output Data Register
			 }
		  }
       // Display Registers
	   printf("I/O Port Address(0x%x) : %02x\n",addr, _inp(addr));
       printf("I/O Port Address(0x%x) : %02x\n",addr+1, _inp(addr+1));
       printf("I/O Port Address(0x%x) : %02x\n",addr+2, _inp(addr+2));
       // Next Command Input
       printf("\n 1: output cmd reg,  2: output data reg,  3: end program = ");
       scanf_s("%d",&c);
	   }

    // Stop I/O Access (IOSCM)
    ret = IOSCM_Stop(); // Call this last(Windows95/98/Me/NT/2000/XP)

	printf("\n press any keys....");
    getchar();
    return(ret);
}