joy.c (10644) | joy.c (12502) |
---|---|
1/*- 2 * Copyright (c) 1995 Jean-Marc Zucconi 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 27 unchanged lines hidden (view full) --- 36#include <sys/systm.h> 37 38#include <machine/joystick.h> 39 40#include <i386/isa/isa.h> 41#include <i386/isa/isa_device.h> 42#include <i386/isa/timerreg.h> 43 | 1/*- 2 * Copyright (c) 1995 Jean-Marc Zucconi 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 27 unchanged lines hidden (view full) --- 36#include <sys/systm.h> 37 38#include <machine/joystick.h> 39 40#include <i386/isa/isa.h> 41#include <i386/isa/isa_device.h> 42#include <i386/isa/timerreg.h> 43 |
44#ifdef JREMOD 45#include <sys/conf.h> 46#define CDEV_MAJOR 51 47static void joy_devsw_install(); 48#endif /*JREMOD*/ 49 |
|
44/* The game port can manage 4 buttons and 4 variable resistors (usually 2 45 * joysticks, each with 2 buttons and 2 pots.) via the port at address 0x201. 46 * Getting the state of the buttons is done by reading the game port: 47 * buttons 1-4 correspond to bits 4-7 and resistors 1-4 (X1, Y1, X2, Y2) 48 * to bits 0-3. 49 * if button 1 (resp 2, 3, 4) is pressed, the bit 4 (resp 5, 6, 7) is set to 0 50 * to get the value of a resistor, write the value 0xff at port and 51 * wait until the corresponding bit returns to 0. --- 42 unchanged lines hidden (view full) --- 94 95int 96joyattach (struct isa_device *dev) 97{ 98 joy[dev->id_unit].port = dev->id_iobase; 99 joy[dev->id_unit].timeout[0] = joy[dev->id_unit].timeout[1] = 0; 100 printf("joy%d: joystick\n", dev->id_unit); 101 | 50/* The game port can manage 4 buttons and 4 variable resistors (usually 2 51 * joysticks, each with 2 buttons and 2 pots.) via the port at address 0x201. 52 * Getting the state of the buttons is done by reading the game port: 53 * buttons 1-4 correspond to bits 4-7 and resistors 1-4 (X1, Y1, X2, Y2) 54 * to bits 0-3. 55 * if button 1 (resp 2, 3, 4) is pressed, the bit 4 (resp 5, 6, 7) is set to 0 56 * to get the value of a resistor, write the value 0xff at port and 57 * wait until the corresponding bit returns to 0. --- 42 unchanged lines hidden (view full) --- 100 101int 102joyattach (struct isa_device *dev) 103{ 104 joy[dev->id_unit].port = dev->id_iobase; 105 joy[dev->id_unit].timeout[0] = joy[dev->id_unit].timeout[1] = 0; 106 printf("joy%d: joystick\n", dev->id_unit); 107 |
108#ifdef JREMOD 109 joy_devsw_install(); 110#endif /*JREMOD*/ 111 |
|
102 return 1; 103} 104 105int 106joyopen (dev_t dev, int flags, int fmt, struct proc *p) 107{ 108 int unit = UNIT (dev); 109 int i = joypart (dev); --- 90 unchanged lines hidden (view full) --- 200 201 outb (TIMER_MODE, TIMER_SEL0); 202 low = inb (TIMER_CNTR0); 203 high = inb (TIMER_CNTR0); 204 205 return (high << 8) | low; 206} 207 | 112 return 1; 113} 114 115int 116joyopen (dev_t dev, int flags, int fmt, struct proc *p) 117{ 118 int unit = UNIT (dev); 119 int i = joypart (dev); --- 90 unchanged lines hidden (view full) --- 210 211 outb (TIMER_MODE, TIMER_SEL0); 212 low = inb (TIMER_CNTR0); 213 high = inb (TIMER_CNTR0); 214 215 return (high << 8) | low; 216} 217 |
218 219#ifdef JREMOD 220struct cdevsw joy_cdevsw = 221 { joyopen, joyclose, joyread, nowrite, /*51*/ 222 joyioctl, nostop, nullreset, nodevtotty,/*joystick */ 223 seltrue, nommap, NULL}; 224 225static joy_devsw_installed = 0; 226 227static void joy_devsw_install() 228{ 229 dev_t descript; 230 if( ! joy_devsw_installed ) { 231 descript = makedev(CDEV_MAJOR,0); 232 cdevsw_add(&descript,&joy_cdevsw,NULL); 233#if defined(BDEV_MAJOR) 234 descript = makedev(BDEV_MAJOR,0); 235 bdevsw_add(&descript,&joy_bdevsw,NULL); 236#endif /*BDEV_MAJOR*/ 237 joy_devsw_installed = 1; 238 } 239} 240#endif /* JREMOD */ |
|
208#endif /* NJOY > 0 */ | 241#endif /* NJOY > 0 */ |