[C] Gameport programming

Pagina: 1
Acties:

  • Servowire
  • Registratie: September 2000
  • Laatst online: 22-08 11:33

Servowire

prutser:~#

Topicstarter
Om de waardes van een Gameport in de te lezen heb dit geschreven:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Servowire 2002 */
/* Fucking GNU Licence shit */

#include <asm/io.h>
#include <stdio.h>
#include <unistd.h>

#define JPORT   0x201
#define CMAX    999999

void joystick(int v[4], char b[4])
{
    int i, j;
    int mask = 15;

    for (i=1; mask && i<CMAX; i++) {
        j = inb(JPORT) ^ mask;
        if (j & 1) { v[0] = i; mask ^= 1; }
        if (j & 2) { v[1] = i; mask ^= 2; }
        if (j & 4) { v[2] = i; mask ^= 4; }
        if (j & 8) { v[3] = i; mask ^= 8; }
    }
    j = inb(JPORT);
    b[0] = !(j & 0x10);
    b[1] = !(j & 0x20);
    b[2] = !(j & 0x40);
    b[3] = !(j & 0x80);
}

main(int argc, char **argv)
{
    int  v[4];
    char b[4];
    memset(v, 0, sizeof(v));
    if (ioperm(JPORT, 3, 1)) 
        {   
        perror("ioperm() error"); 
        exit(1);
        }
    outb (0xff, JPORT);
    while (1) {
        joystick(v, b);
        printf("%3d %3d %3d %3d  %d %d %d %d\n",
            v[0], v[1], v[2], v[3], b[0], b[1], b[2], b[3]);
    }
}


Alleen ik krijg alleen maar NULL waardes op alle bits op dat adres, terwijl 0x201 toch echt het Gameport adres is.

Iemand een idee?

met papier mache kun je alles maken!!


Verwijderd

Fantastisch... en waarop wil je dat gaan draaien? Heeft dat OS zelf geen ondersteuning voor een gameport (drivers/API)? Dat heeft natuurlijk altijd de voorkeur boven zelf maar met I/O poorten klooien...

  • Servowire
  • Registratie: September 2000
  • Laatst online: 22-08 11:33

Servowire

prutser:~#

Topicstarter
Verwijderd schreef op 25 december 2002 @ 21:41:
Fantastisch... en waarop wil je dat gaan draaien? Heeft dat OS zelf geen ondersteuning voor een gameport (drivers/API)? Dat heeft natuurlijk altijd de voorkeur boven zelf maar met I/O poorten klooien...
Linux, maar de Joystick drivers zijn te omslachtig, heb zelf een circuitje gesoldeerd met NTC's en op deze manier wil ik de waardes uitlezen, de Gameport heeft zelf namelijk al een ADC (een 558)

update
even wat info:
Thus, to read the analog inputs, you first activate the multivibrator (with a port write; see below), then poll the state of the four axes (with repeated port reads) until they drop from high to low state, measuring their high period duration. This polling uses quite a lot of CPU time, and on a non-realtime multitasking system like (normal user-mode) Linux, the result is not very accurate because you cannot poll the port constantly (unless you use a kernel-level driver and disable interrupts while polling, but this wastes even more CPU time). If you know that the signal is going to take a long time (tens of ms) to go down, you can call usleep() before polling to give CPU time to other processes.

The only I/O port you need to access is port 0x201 (the other ports either behave identically or do nothing). Any write to this port (it doesn't matter what you write) activates the multivibrator. A read from this port returns the state of the input signals:

Bit 0: AX (status (1=high) of the multivibrator output)
Bit 1: AY (status (1=high) of the multivibrator output)
Bit 2: BX (status (1=high) of the multivibrator output)
Bit 3: BY (status (1=high) of the multivibrator output)
Bit 4: BA1 (digital input, 1=high)
Bit 5: BA2 (digital input, 1=high)
Bit 6: BB1 (digital input, 1=high)
Bit 7: BB2 (digital input, 1=high)

[ Voor 59% gewijzigd door Servowire op 25-12-2002 21:52 ]

met papier mache kun je alles maken!!


Verwijderd

Als je in je joystick() functie de waarde die je ingelezen hebt uitprint, staan er dan nog steeds alleen maar NULLs?
Weet je zeker dat je wilt XOR'en met je mask na 't inlezen?
(Ik zie niet direct wat er fout zou gaan in je code namelijk)

  • Super_ik
  • Registratie: Maart 2001
  • Laatst online: 12:50

Super_ik

haklust!

uhh, je moet joystick poort uitlezen met een lusje toch :s
edit:
codesample zoekt

[edit]k kan t zosnel ff nie vinden, maar k d8 dat je een 1 ofzo moest schijven naar 1 van die bits en dan de tijd dat je moest wachten voordat die bit weer 0 wordt is je joystick waarde.

[ Voor 72% gewijzigd door Super_ik op 26-12-2002 14:49 ]

8<------------------------------------------------------------------------------------
Als ik zo door ga haal ik m'n dood niet. | ik hou van goeie muziek


  • Servowire
  • Registratie: September 2000
  • Laatst online: 22-08 11:33

Servowire

prutser:~#

Topicstarter
Het is gelukt

met de bovenstaande code, maar moest nog de geluidskaart activeren via PNP
isa pnp


code:
1
ESS1868/-1[2]{ESS ES1868 Plug and Play AudioDrive}: Port 0x201; --- Enabled OK


en de output is nu

code:
1
 0 107   0   0  0 0 0 0


en dat klopt

woei :D

met papier mache kun je alles maken!!

Pagina: 1