English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 09 May 2014, 19:32   #21
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,727
Quote:
Originally Posted by jotd View Post
That makes me think: what could explain that some games work OK with the joystick, but when you plug in a CD32 joypad, red button is not recognized? (ex: Moktar, and another one I don't remember)
I guess they have 3rd button line active forcing pad in CD32 pad mode.

Quote:
Originally Posted by robinsonb5 View Post
The CD32 pad contains a serial shift register
You were faster than me

Quote:
Pin 5 is used as a select line - normally high (in which case only the red button is readable, as a normal fire button)
Blue should be also readable as a normal second fire button in "not cd32 pad" mode.
Toni Wilen is offline  
Old 10 May 2014, 12:26   #22
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 644
@robinsonb5
Thanks a lot for explanation


about second point, there is a bug (of course mine )

2.
Set POTGO (calls WritePotgo, D0=$2000,D1=$3000 / D0=$0200,D1=$0300. Direct write to POTGO should work fine.)

Writing $3000 or $300 set up pin 5 to output. So its mean that we detects button's with pin 5, right ?
Asman is offline  
Old 10 May 2014, 12:51   #23
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,727
Quote:
Originally Posted by Asman View Post
Set POTGO (calls WritePotgo, D0=$2000,D1=$3000 / D0=$0200,D1=$0300. Direct write to POTGO should work fine.)

Writing $3000 or $300 set up pin 5 to output. So its mean that we detects button's with pin 5, right ?
WriteProtgo D0 = value, D1 = mask. D0=$2000 D1=$3000 means only bits 12 and 13 are modified ($3000) with value in D0: bit 12 is cleared, 13 is set ($2000)

Pin 5 = mode: output, data: 0v. This sets pad to "CD32 mode", shift register enabled. Data 5v (high) or input mode sets it to "normal pad" mode, red and blue buttons work as normal 2 button joystick.
Toni Wilen is offline  
Old 10 May 2014, 13:12   #24
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 644
@Toni

Thanks a lot.

But I just found that somewhere is a bug.

On the amiga dev docs there is http://amigadev.elowar.com/read/ADCD.../node018B.html

Table 8-4: POTGO ($DFF034) and POTGOR ($DFF016) Registers
Code:

       Bit
       Number    Name    Function
       ------    ----    --------
       15        OUTRY   Output enable for bit 14 (1=output)
       14        DATRY   data for port 2, pin 9
       13        OUTRX   Output enable for bit 12
       12        DATRX   data for port 2, pin 5
       11        OUTLY   Output enable for bit 10
       10        DATLY   data for port 1, pin 9 (right mouse button)
       09        OUTLX   Output enable for bit 8
       08        DATLX   data for port 1, pin 5 (middle mouse button)
       07-01       X     chip revision identification number
       00        START   Start pots (dump capacitors, start counters)
But on this http://www.winnicki.net/amiga/memmap/POTGO.html

Bit definitions for both POTGOR and POTGO:
Code:

 +------+-------+--------------------------------------------------------+
 | BITS | FUNC  | DESCRIPTION                                            |
 +------+-------+--------------------------------------------------------+
 |  15  | OUTRY | Output enable for Paula pin 33 (= pin 5, port 1)       |
 |  14  | DATRY | I/O data Paula pin 33          (= pin 5, port 1)       |
 |  13  | OUTRX | Output enable for Paula pin 32 (= pin 9, port 1)       |
 |  12  | DATRX | I/O data Paula pin 32          (= pin 9, port 1)       |
 |  11  | OUTLY | Output enable for Paula pin 36 (= pin 5, port 0 = RMB) |
 |  10  | DATLY | I/O data Paula pin 36          (= pin 5, port 0 = RMB) |
 |   9  | OUTLX | Output enable for Paula pin 35 (= pin 9, port 0 = MMB) |
 |   8  | DATLX | I/O data  Paula pin 35         (= pin 9, port 0 = MMB) |
 |  7-1 |   X   | Paula 8364 chip revision identification number         |
 |      |       | (presently all zeroes, there's only on Paula revision!)|
 |   0  | START | Start pots (dump capacitors,start counters)            |
 +------+-------+--------------------------------------------------------+
So, which link is proper ? I guess that second one is proper one, right ?

And I was wrong again with pin 5 ???

Last edited by prowler; 10 May 2014 at 21:42. Reason: Added CODE boxes for formatting.
Asman is offline  
Old 10 May 2014, 15:32   #25
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 577
Quote:
Originally Posted by Asman View Post
So, which link is proper ? I guess that second one is proper one, right ?
Nope, Winniki seems to have it backwards; pin 9 is right mouse button (blue button, clocked data from shift register), pin 5 is middle button (shift register enable.)
robinsonb5 is offline  
Old 10 May 2014, 21:36   #26
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 2,466
ok, so to sum it up: in the joypad read routine:

1) we should save POTGOR value first
2) set POTGO as in the code (but not first bit to 1 right?)
3) in the end, write saved value of POTGOR in POTGO and not the $CC01 crap
jotd is offline  
Old 10 May 2014, 22:39   #27
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 644
@Toni, robinsonb5, jotd
Thanks a lot for posts and answering my questions

So there is very first approach to make fine routine to read cd32 pad. Mean directions + buttons. This piece of code just should read only buttons from port 1 (mouse port)

Code:
	INCDIR	"includes:"
	INCLUDE	"hardware/cia.i"
	INCLUDE	"hardware/custom.i"
	INCLUDE	"hardware/dmabits.i"
	INCLUDE	"hardware/intbits.i"

_custom		equ	$dff000
_ciaa		equ	$bfe001
_ciab		equ	$bfd000





		lea	_custom,a0
		lea	_ciaa,a1

		moveq	#0,d0
		moveq	#CIAB_GAMEPORT0,d3
		moveq	#10,d4
		bset	d3,ciaddra(a1)		;pin set to output
		bclr	d3,ciapra(a1)		;pulls it low

		move.w	potinp(a0),d7		;store old potgo

		move.w	#$100,potgo(a0)		;shift register enable

		moveq	#9,d1

.loop		tst.b	(a1)
		tst.b	(a1)
		tst.b	(a1)
		tst.b	(a1)
		tst.b	(a1)
		tst.b	(a1)
		tst.b	(a1)
		tst.b	(a1)

		move.w	potinp(a0),d2

		btst	d4,d2
		bne	.next
		bset	d1,d0

;send a clock pulse to the shift register, placing the next button's on pin 9
.next		bset	d3,ciapra(a1)
		bclr	d3,ciapra(a1)

		dbf	d1,.loop

		bclr	d3,ciaddra(a1)		;pin set to input
		move.w	d7,potgo(a0)		;restore potgo value

		rts
Tommorow I will check this code with my cd32pad connected to my a1200.
Asman is offline  
Old 11 May 2014, 10:59   #28
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,727
I'd replace POTGO write with read POTGOR, mask and set, write POTGO. "Randomly" setting other ports bits may cause problems if both ports have CD32 pad inserted (or even some custom hardware).
Toni Wilen is offline  
Old 01 August 2017, 21:59   #29
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 2,466
Ok, digging into this old thread and I'm still at a loss when it comes to autodetect joystick vs CD32 joypad. I can't even understand what I wrote

So I know it's not possible to detect mouse vs joy, but I'm 100% sure it's possible to detect joystick/CD32 joypad, anyone can share some code?

Why I'm needing this:

ReadJoyPad.s (from whdload & EAB) source code reads all buttons, but on 2 button joysticks (not a joypad), when pressing the 2nd button, it makes ALL buttons pressed (triggers PAUSE), and that's an annoying issue, even with original CD32 games.

I'd like to detect the controller type and NOT check for pause (and others), but just the 2nd button, so 2nd button joystick users with an amiga can at least use this button (and trigger pause with P since they have a keyboard)

Thx
jotd is offline  
Old 01 August 2017, 22:05   #30
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,727
CD32 pad detection is easy: read 9 buttons (instead of normal 7) in CD32 mode. If "buttons" 8 and 9 have different pressed state (I don't remember if 8=pressed and 9=not pressed or vice versa), it is CD32 pad.
Toni Wilen is offline  
Old 01 August 2017, 22:31   #31
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 2,466
thanks Toni. Is there a way I can test this with WinUAE? I mean how to fiddle with input settings to put a joystick in port 1, then a CD32 joypad?
jotd is offline  
Old 01 August 2017, 22:50   #32
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,727
Quote:
Originally Posted by jotd View Post
thanks Toni. Is there a way I can test this with WinUAE? I mean how to fiddle with input settings to put a joystick in port 1, then a CD32 joypad?
Changing device type on the fly should work.
Toni Wilen is offline  
Old 02 August 2017, 09:45   #33
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 2,466
thanks Toni. On Winuae, both 8 & 9 readings yield 1 if joypad, and 0 if joystick. I'll assume != 0 => joypad.

thanks a lot.
jotd is offline  
Old 02 August 2017, 09:54   #34
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,727
Quote:
Originally Posted by jotd View Post
thanks Toni. On Winuae, both 8 & 9 readings yield 1 if joypad, and 0 if joystick. I'll assume != 0 => joypad.
That sounds wrong. First and second "non-existing" button should have different values. (Did you count from 0 or from 1? I counted from 1)
Toni Wilen is offline  
Old 02 August 2017, 10:43   #35
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 2,466
I used the following code:

Code:
_detect_controller_types:
	moveq	#0,d0
	bsr		.detect
	lea	controller_joypad_0(pc),a0
	move.b	D0,(A0)
	moveq	#1,d0
	bsr		.detect
	lea	controller_joypad_1(pc),a0
	move.b	D0,(A0)
	rts
	
.detect
		movem.l	d2-d6/a0-a1,-(a7)
	
		tst.l	d0
		bne.b	.port1

		moveq	#CIAB_GAMEPORT0,d3	; red button ( port 0 )
		moveq	#10,d4			; blue button ( port 0 )
		move.w	#$f600,d5		; for potgo port 0
		moveq	#joy0dat,d6		; port 0
		bra.b	.buttons
.port1
		moveq	#CIAB_GAMEPORT1,d3	; red button ( port 1 )
		moveq	#14,d4			; blue button ( port 1 )
		move.w	#$6f00,d5		; for potgo port 1
		moveq	#joy1dat,d6		; port 1

.buttons
		lea	$DFF000,a0
		lea	$BFE001,a1
		
		bset	d3,ciaddra(a1)	;set bit to out at ciapra
		bclr	d3,ciapra(a1)	;clr bit to in at ciapra

		move.w	d5,potgo(a0)

		moveq	#0,d0
		moveq	#10-1,d1	; read 9 times instead of 7. Only 2 last reads interest us
		bra.b	.gamecont4

.gamecont3	tst.b	ciapra(a1)
		tst.b	ciapra(a1)
.gamecont4	tst.b	ciapra(a1)	; wepl timing fix
		tst.b	ciapra(a1)
		tst.b	ciapra(a1)
		tst.b	ciapra(a1)
		tst.b	ciapra(a1)
		tst.b	ciapra(a1)

		move.w	potinp(a0),d2

		bset	d3,ciapra(a1)
		bclr	d3,ciapra(a1)
	
		btst	d4,d2
		bne.b	.gamecont5

		bset	d1,d0

.gamecont5	dbf	d1,.gamecont3

		bclr	d3,ciaddra(a1)		;set bit to in at ciapra
		move.w	#$ffff,potgo(a0)
		
		or.b	#$C0,ciapra(a1)	;reset port direction

		; test only last bits
		and.w	#03,D0
		
		movem.l	(a7)+,d2-d6/a0-a1
		rts
Result: 3 if pad, 0 if joy (winuae)
jotd is offline  
Old 02 August 2017, 10:46   #36
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,727
Does all "real" buttons still read correctly?

EDIT: My crystal ball says you need to call this function once, then wait 1 frame, then call it again to get correct result.
Toni Wilen is offline  
Old 02 August 2017, 12:03   #37
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 2,466
I don't know if real buttons read correctly. I ignore them, this is done at the start of the game. You're right, though, I need to wait between both readings. Since that's at the start of the game, interrupts are disabled. How much should I wait? Or does it really need VBI? I could check INTREQ for VBI.
jotd is offline  
Old 02 August 2017, 12:26   #38
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,727
My point was to confirm it working by checking all buttons one by one. Ignore the last two bits until buttons work.

Problem with this code is that it reads buttons firsts and then resets the pad shift register at the end (write to POTGO) = first read returns bogus data.

Wait for vblank, run this code, wait for vblank, run it again to get correct data.
Toni Wilen is offline  
Old 02 August 2017, 12:34   #39
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 2,466
ok Toni but this code works, it's been used in a lot of whdload slaves to read joypad buttons.
jotd is offline  
Old 02 August 2017, 13:11   #40
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,727
Quote:
Originally Posted by jotd View Post
ok Toni but this code works, it's been used in a lot of whdload slaves to read joypad buttons.
I didn't say it does not work, I only said first read should be ignored. Also this may cause about 1 frame input latency. (I need to re-remember how CD32 pad first to confirm it..)
Toni Wilen is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Lincs Amiga User Group aka "LAG" Meeting Confirmed for Sat 2nd of March" rockape News 2 21 February 2013 22:46
"Reminder "Lincs Amiga User Group aka "LAG" Meet Sat 5th of January 2013" rockape News 4 30 January 2013 00:06
CD32 Image-Name-Bug: "...(bla)[!].zip" -> "...(bla)[" / "...[test].zip" -> "...[tes" cfTrio support.WinUAE 8 18 December 2012 16:31
Shadowlands ("Mystery Tour" problem) Bolch support.Games 1 14 December 2007 15:48
Problems with "Thespywholovedme", "Flood", "Shinobi" sareks support.Games 12 03 May 2006 14:52

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:40.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.08717 seconds with 14 queries