~ubuntu-branches/ubuntu/natty/pd-zexy/natty

« back to all changes in this revision

Viewing changes to src/winNT_portio.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, IOhannes m zmölnig, Jonas Smedegaard
  • Date: 2010-08-20 12:17:41 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100820121741-4kxozn8b9rhee9fr
Tags: 2.2.3-1
* New upstream version

[ IOhannes m zmölnig ]
* Adopt package, on behalf of Multimedia Team.
  Closes: #546964
* Simply debian/rules with CDBS, and don't unconditionally strip
  binaries.
  Closes: #437763
* Install into /usr/lib/pd/extra/zexy/. Document usage in REAME.Debian
  and warn about change in NEWS.
* git'ify package. Add Vcs-* stanzas to control file.
* Use dpkg source format 3.0 (quilt). Drop build-dependency on quilt.

[ Jonas Smedegaard ]
* Enable CDBS copyright-check routine.
* Add copyright and licensing header to debian/rules.
* Add myself as uploader.
* Rewrite debian/copyright using rev. 135 of draft DEP5 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * this is a wrapper for the cor port i/o functions for WinNT/2000/XP.
 
3
 * this is to be replaced by some functions that are platform/interface
 
4
 * specific to access the data lines.
 
5
 * for now, this is only for parport access, but in future there will be a way
 
6
 * to plug this on the usb bus.
 
7
 * if the interface changes, only this file has to be adopted for the target system
 
8
 */
 
9
#if defined __WIN32__ && defined Z_WANT_LPT
 
10
 
 
11
#include <stdio.h>
 
12
#include <windows.h>
 
13
 
 
14
int read_parport(int port);
 
15
void write_parport(int port, int value);
 
16
int open_port(int port);
 
17
 
 
18
static BOOL bPrivException = FALSE;
 
19
 
 
20
int read_parport(int port)
 
21
{
 
22
        unsigned char value;
 
23
#ifdef _MSC_VER
 
24
        __asm mov edx,port
 
25
        __asm in al,dx
 
26
        __asm mov value,al
 
27
#else
 
28
    /* hmm, i should read some documentation about inline assembler */
 
29
    post("lpt: cannot read from parport (recompile!)");
 
30
        return 0;
 
31
#endif
 
32
        return (int)value;
 
33
}
 
34
 
 
35
void write_parport(int port, int invalue)
 
36
{
 
37
  /* _outp((unsigned short)port, value); */
 
38
  BYTE value = (BYTE)invalue;
 
39
#ifdef _MSC_VER
 
40
  __asm mov edx,port
 
41
  __asm mov al,value
 
42
  __asm out dx,al
 
43
#else
 
44
    /*
 
45
     * hmm, i should read some documentation about inline assembler
 
46
     * and probably about assembler in general...
 
47
     */
 
48
    post("lpt: cannot write to parport (recompile!)");
 
49
    /*
 
50
    asm(
 
51
        "mov %%edx,%0\n"
 
52
        "mov %%al,%1\n"
 
53
        "out %%dx,%%al\n"
 
54
        :
 
55
        : "a"(port),"b"(value)
 
56
        );
 
57
    */
 
58
#endif
 
59
}
 
60
 
 
61
static LONG WINAPI HandlerExceptionFilter ( EXCEPTION_POINTERS *pExPtrs )
 
62
{
 
63
 
 
64
        if (pExPtrs->ExceptionRecord->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
 
65
        {
 
66
                pExPtrs->ContextRecord->Eip ++; /* Skip the OUT or IN instruction that caused the exception */
 
67
                bPrivException = TRUE;
 
68
                return EXCEPTION_CONTINUE_EXECUTION;
 
69
        }
 
70
        else
 
71
                return EXCEPTION_CONTINUE_SEARCH;
 
72
}
 
73
 
 
74
static BOOL StartUpIoPorts(UINT PortToAccess, BOOL bShowMessageBox, HWND hParentWnd)
 
75
{
 
76
        HANDLE hUserPort;
 
77
 
 
78
        hUserPort = CreateFile("\\\\.\\UserPort", GENERIC_READ, 0, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
79
        CloseHandle(hUserPort); /* Activate the driver */
 
80
        Sleep(100); /* We must make a process switch */
 
81
 
 
82
        SetUnhandledExceptionFilter(HandlerExceptionFilter);
 
83
        
 
84
        bPrivException = FALSE;
 
85
        read_parport(PortToAccess);  /* Try to access the given port address */
 
86
 
 
87
        if (bPrivException)
 
88
        {
 
89
                if (bShowMessageBox)
 
90
                {
 
91
#if 0
 
92
                MessageBox(hParentWnd,"Privileged instruction exception has occured!\r\n\r\n"
 
93
                                                                  "To use this external under Windows NT, 2000 or XP\r\n"
 
94
                                                                  "you need to install the driver 'UserPort.sys' and grant\r\n"
 
95
                                                                  "access to the ports used by this program.\r\n\r\n"
 
96
                                                                  "See the file README for further information!\r\n", NULL, MB_OK);
 
97
#endif
 
98
                }
 
99
                return FALSE;
 
100
        }
 
101
        return TRUE;
 
102
}
 
103
        /* check if we are running NT/2k/XP */
 
104
static int IsWinNT(void)
 
105
{
 
106
        OSVERSIONINFO OSVersionInfo;
 
107
        OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 
108
 
 
109
        GetVersionEx(&OSVersionInfo);
 
110
 
 
111
        return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
 
112
}
 
113
 
 
114
        /* open parport */
 
115
int open_port(int port)
 
116
{
 
117
        if(IsWinNT())   /* we are under NT and need kernel driver */
 
118
        {
 
119
                if(StartUpIoPorts(port, 1, 0))
 
120
                        return(0);
 
121
                return(-1);
 
122
        }
 
123
        else    /* no need to use kernel driver */
 
124
        {
 
125
                return(0);
 
126
        }
 
127
}
 
128
#endif /* __WIN32__ & Z_WANT_LPT */