home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / resources / read_potinp.e < prev   
Text File  |  1977-12-31  |  2KB  |  66 lines

  1. -> Read_Potinp.e
  2. ->
  3. -> An example of using the potgo.resource to read pins 9 and 5 of port 1
  4. -> (the non-mouse port).  This bypasses the gameport.device.  When the right
  5. -> or middle button on a mouse plugged into port 1 is pressed, the read value
  6. -> will change.
  7. ->
  8. -> Use of port 0 (mouse) is unaffected.
  9.  
  10. -> E-Note: E does not (as of v3.1a) support Resources in the conventional way
  11. MODULE 'other/potgo',
  12.        'dos/dos',
  13.        'hardware/custom'
  14.  
  15. ENUM ERR_NONE, ERR_POT, ERR_RES
  16.  
  17. RAISE ERR_RES IF OpenResource()=NIL
  18.  
  19. CONST OUTRY=$8000, DATRY=$4000, OUTRX=$2000, DATRX=$1000
  20.  
  21. DEF potbits, value
  22.  
  23. PROC main() HANDLE
  24.   -> E-Note: set-up "custom"
  25.   DEF custom=CUSTOMADDR:PTR TO custom
  26.  
  27.   potgobase:=OpenResource('potgo.resource')
  28.  
  29.   -> Get the bits for the right and middle mouse buttons on the alternate
  30.   -> mouse port.
  31.   potbits:=allocPotBits(OUTRY OR DATRY OR OUTRX OR DATRX)
  32.  
  33.   IF potbits<>(OUTRY OR DATRY OR OUTRX OR DATRX)
  34.     freePotBits(potbits)
  35.     Raise(ERR_POT)
  36.   ENDIF
  37.  
  38.   -> Set all ones in the register (masked by potbits)
  39.   writePotgo($FFFFFFFF, potbits)
  40.  
  41.   WriteF('\n'+
  42.     'Plug a mouse into the second port.  This program will indicate when\n'+
  43.     'the right or middle button (if the mouse is so equipped) is pressed.\n'+
  44.     'Stop the program with Control-C. Press return now to begin.\n')
  45.   -> E-Note: stdout is valid (we've used WriteF()), so try that if no stdin
  46.   Inp(IF stdin THEN stdin ELSE stdout)
  47.  
  48.   REPEAT
  49.     -> Read word at $DFF016
  50.     value:=custom.potinp
  51.  
  52.     -> Show what was read (restricted to our allocated bits)
  53.     -> E-Note: use "\b" to prevent a linefeed, giving single line, fast update
  54.     WriteF('POTINP = $\h\b', value AND potbits)
  55.   UNTIL SIGBREAKF_CTRL_C AND SetSignal(0, 0)  -> Until CTRL-C is pressed
  56.   WriteF('\n')
  57.  
  58.   freePotBits(potbits)
  59.  
  60. EXCEPT DO
  61.   SELECT exception
  62.   CASE ERR_POT;  WriteF('Pot bits are already allocated! \h\n', potbits)
  63.   CASE ERR_RES;  WriteF('Could not open potgo.resource\n')
  64.   ENDSELECT
  65. ENDPROC
  66.