[comp.sys.amiga.programmer] I *STILL* need help with the POTGO resource!

chymes@uri.csmil.umich.edu (Charles Hymes) (06/05/91)

I use basically the following lines to set up the POTGO resource.

potbits=AllocPotBits(OUTRY|DATRY|OUTRX|DATRX|START);             
/* Get the bits for port 1, pin 5 and 9 the Y and X POT registers
   on the alternate mouse port. */

WritePotgo(0x01L,potbits);
        /* Clear all data bits in the register but start the pot counter */

But reading the pots with the either of the following  lines don't give
me any values.

/*amplitude=(custom.potinp  & potbits);*/
/*amplitude=(pot1dat);*/

I tried other code as well, but the values at pot1dat never change no
matter what I do at the gameport. If I connect pins 5 or 9 to (the X
and Y pot pins) to pins 7 or 8 (+5 volts and Ground respectively)
Nothing changes at pot1dat.
Potinp changes the way you would expect it to, but I don't want on/off
values, I want the 8-bit values one expects from the Pots.

The (old white A1000) Hardware manual says that Potgo needs to be
reset each vertical blank, but it also says that that is taken care of
by the OS. Is this shut off when I use the POTGO resource?
I tryed the following line of C code after the line at wich I read the
registers but it didn't help. 
/*        WritePotgo(0x01L,potbits);*/ 

So whats the deal??!!!?

Charlweed Hymerfan

carolyn@cbmvax.commodore.com (Carolyn Scheppner - CATS) (06/08/91)

In article <-J#-M6C@engin.umich.edu> chymes@uri.csmil.umich.edu (Charles Hymes) writes:
>I use basically the following lines to set up the POTGO resource.
>[]
>I tried other code as well, but the values at pot1dat never change no
>matter what I do at the gameport. If I connect pins 5 or 9 to (the X
>and Y pot pins) to pins 7 or 8 (+5 volts and Ground respectively)
>Nothing changes at pot1dat.
>Potinp changes the way you would expect it to, but I don't want on/off
>values, I want the 8-bit values one expects from the Pots.
>
>The (old white A1000) Hardware manual says that Potgo needs to be
>reset each vertical blank, but it also says that that is taken care of
>by the OS. Is this shut off when I use the POTGO resource?

I think the HW manual says you have to EITHER read it during vertical
blank OR read it twice.

Meanwhile, here's an old piece of Phil Lindsay code that does use
vertical blank (little piece of asm at end)

potgo.c
/* potgo.c - read right port's x, y pots
 *	Remember to use options +lcd for MANX Aztec C (longs & A4 dependency)
 */
#include <exec/types.h>
#include <hardware/cia.h>
#include <hardware/intbits.h>
#include <exec/interrupts.h>
#include <resources/potgo.h>
#include <libraries/dos.h>

/* macro functions to grab pot x and y from pot1dat */
#define POTX(x)		((x) & 0x00ff)
#define POTY(y)        	((y) >> 8)

/* hard addresses for potgo and pot1dat */
#define POTGO		0xdff034
#define POT1DAT		0xdff014

/* vertical blank interrupt server priority   */
#define MYINTPRI	10L 	/* my priority is 10 higher than gamedev intr */

#define START_B		0	/* bit number defines for potgo ... */
#define DATRX_B		12	
#define DATRY_B		14
#define START_F		(1L << START_B)	/* masks ... */
#define DATRX_F		(1L << DATRX_B)
#define DATRY_F		(1L << DATRY_B)	

#define RPOTXY		(START_F | DATRX_F | DATRY_F) 

long	PotgoBase;	/* resource base */
UWORD 	potxy;		/* global for pot1dat storage */

extern void getpot(); 		/* vert. blank interrupt routine */

main()
{ 

 long  alloc;
 struct Interrupt myintr;

 PotgoBase = (long) OpenResource(POTGONAME);

 alloc = (long) AllocPotBits(RPOTXY);

 printf("Allocated: %lx\n",alloc);

 if(alloc != RPOTXY)
   {
    puts("Couldn't get potgo bits.");	
    FreePotBits(alloc);
    exit(TRUE);
   }		

/* intialize interrupt structure */
 setmem(&myintr,(long)sizeof(myintr),0L);
 myintr.is_Node.ln_Pri  = MYINTPRI;
 myintr.is_Data         = POT1DAT;
 myintr.is_Code         = getpot;
 
 AddIntServer(INTB_VERTB,&myintr);

/* loop while !ctrl-c */
 while(! (((ULONG)SetSignal(NULL,NULL)) & SIGBREAKF_CTRL_C) )
   printf("x=%ld, y=%ld\n",(long)POTX(potxy),(long)POTY(potxy));
 
 RemIntServer(INTB_VERTB,&myintr);

 FreePotBits(alloc); 

}

/* eof */
******************************************************************************
potgoint.asm
* Vertical Blank Interrupt Server code.

	xref	_PotgoBase		* get potgo resource base
	xref	_potxy			* global storage for pot1dat
        xref 	_LVOWritePotgo		* resource routine to write potgo

	xdef	_getpot
_getpot:
        move.w	(a1),_potxy 		* a1 points to pot1dat
	move.l 	_PotgoBase,a6 		* move resource base into a6
	move.l 	#1,d0			* potgo start bit = 1
	move.l	d0,d1 			* our mask is 1
	jsr 	_LVOWritePotgo(a6)	* call write potgo
	move.l #0,d0			* cont interrupt chain
	rts				* gone...
	end
* EOF


-- 
==========================================================================
 Carolyn Scheppner -- Tech. Mgr. CATS - Commodore Amiga Technical Support
 PHONE 215-431-9180 {uunet,rutgers}!cbmvax!carolyn  carolyn@commodore.com

 Integer math - it's all so pointless.
==========================================================================

marvin@messua.informatik.rwth-aachen.de (Andreas Schneider) (06/11/91)

chymes@uri.csmil.umich.edu (Charles Hymes) writes:

>I use basically the following lines to set up the POTGO resource.
  ...
>I tried other code as well, but the values at pot1dat never change no
>matter what I do at the gameport. If I connect pins 5 or 9 to (the X
>and Y pot pins) to pins 7 or 8 (+5 volts and Ground respectively)
>Nothing changes at pot1dat.
>Potinp changes the way you would expect it to, but I don't want on/off
>values, I want the 8-bit values one expects from the Pots.

>So whats the deal??!!!?

>Charlweed Hymerfan

I mailed this to you, but it seems you didn't get it.
As other people might also be interested in this: I post it.
 
A Modula-2 program I wrote reads the pots connected to the
Amiga's gameport and it works.
 
I don't speak the language too well, but this is how it should
work in C:
 
1. Open Potgo-Resource
 
   PotgoADR=OpenResource(ResName,Version)
 
   where:
   Node  *PotgoADR      (adress of resource)
   char  *ResName       (Pointer to string : "potgo.resource")
   ULONG Version        (use 0 to accept all versions)
 
   (Make sure PotgoADR !=0)
 
2. Tell resource which bits you need:
 
   BitsWanted=(DATRY|DATRX|START)
   BitsGot=AllocPotBits(BitsWanted)
 
   (Make sure that BitsWanted==BitsGot)
 
3. Tell resource to start measuring pots:
 
   WritePotgo(BitsGot,BitsGot)
 
   (in this case: start for Datrx and Datry)
 
4. Wait.
 
   This is very important because measuring the pots takes some time.
   You'll get wrong (too small) or no results if you don't wait.
   There are several ways to wait:
   - Start measuring at vertical blank and read results next vertical
     blank.
   - Delay(1)
   - Do something else that lasts as long as the time between two
     vertical blanks.
 
5. Finally: read result:
 
   result=(pot1dat)
 
   this gives you 2 bytes of information: one for each pot.
 
6. Continue with 3. (if you need more results).
 
This worked for me and I think it should work for you (in C)
If there are more questions about this: ask !
 
Bye
 
Andreas

jcs@crash.cts.com (John Schultz) (06/13/91)

In <-J#-M6C@engin.umich.edu> chymes@uri.csmil.umich.edu (Charles Hymes) writes:

>I tried other code as well, but the values at pot1dat never change no
>matter what I do at the gameport. If I connect pins 5 or 9 to (the X
>and Y pot pins) to pins 7 or 8 (+5 volts and Ground respectively)
>Nothing changes at pot1dat.
>Potinp changes the way you would expect it to, but I don't want on/off
>values, I want the 8-bit values one expects from the Pots.

  Allocate the bits (resource) first, then hit the hardware bits directly.
Get the latest RKM and hardware manuals. The old white manuals are extremely
outdated.  Complete examples of using the potgo resource exist in the public
domain.
  Another bit of info you'll need is this: 1Meg ohm pots are needed
to get 0-255 readings from the hardware. You can get close by adding
.22 microfarad capacitors across the pot lines of off-the-shelf IBM PC
joysticks. I recommend the CH Products Flight Stick. Smooth as silk. About
$50. One of these days I'll sell an adaptor/splitter to allow X-Specs and
an IBM analog joystick in the same port... Anyone interested?


  John