Joysticks and noise on the sound output

Hardware Hacking, Programming and Game Solutions/Cheats
Post Reply
pser1
Posts: 1655
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Joysticks and noise on the sound output

Post by pser1 »

Hello,
I am using the right joystick to move a sprite on screen and to check the two axis I am not using the Basic ROM.
The problem is that I hear no noise at all on XRoar while moving the joysticks ...
But on the real machine I can hear a noticiable noise level.
I had a look at the code used by Tandy to avoid the noise and so I thought it had to work on the Dragon too, but it doesn't
I am attaching here the code for the Joystick and sound control used in the program.
Maybe someone will find the flaw(s) in that procedure!

Code: Select all

 
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
; Joystick controls	- special for 6809 machines (using 6 bit DAC)
; besides the 2 axis (UD, LR) and button, KEYS 'Z' and 'I' must be checked
; defines three zones: UP or LEFT  	  (00-07) - 12,5%
;							  NEUTRAL    	  (08-55) - 75%
;							  DOWN or RIGHT  (56-63) - 12,5% 
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
												; fills variables $015a-$015b (X - Y axis right joystick)
JoyJoy	lbsr	AudiOff						; turn off audio
			leas	-3,s							; 3 bytes for counters
			ldx	#$015c						; point to end of right joystick table
			ldb	#$01							; axis to read -1 (right joystick)
RdJyAx	lda	#$0a							; max number of tries
			std	1,s							; save counters
			bsr	MuxBits						; set both bits
RdJyDo	ldd	#$4080						; $80 first value to DAC, $40 increment
RdJy00	sta	,s								; save 'step'
			orb	#2								; keep RS232 serial out marking
			stb	$ff20							; send 'start' to DAC
			eorb	#2								; put RS232 back to zero
			tst	$ff00							; read data from joystick
			bmi	RdJy01						; data sent too big?
			subb	,s								; deduct step value
			fcb	$8c							; skip next
RdJy01	addb	,s								; add step
			lsra									; logarithmic search (or binary search?)
			cmpa	#1								; lowest step value?
			bne	RdJy00						; not yet
			lsrb									; value in b2-b7
			lsrb									; to b0-b5
			cmpb	-1,x							; compare to last value
			beq	RdSame						; same value twice
			dec	1,s							; debouncing
			bne	RdJyDo						; redetermine
RdSame	stb	,-x							; save value in table
			ldb	2,s							; number of axis
			decb									; decrement it
			bpl	RdJyAx						; next axis
			clr	$ff20							; avoid sound spikes
			bsr	AudiOn						; set audio on again
			leas	3,s							; clean stack
			clr	<reg_E						; result to zero
												; process special keys 'I','Z'
			ldx	#keys+6						; point to values table
			lda	,x								; get column value for 'I' (64)
			bsr	KTest							; test for it
		 	rol	<reg_E						; shift into output register
		 	lda	,-x							; get colun value for 'Z' (32)
			bsr	KTest							; test for it
		 	rol	<reg_E						; shift into output register
		 										; process button 
			andcc	#%11111110					; clear carry
			lda	$ff00							; is button of right Joystick pressed (16)?
			bita	#1								; bit0 is the value (0=YES)
			bne	PutButt						; not pressed
			orcc	#%00000001					; set carry (button is pressed)
PutButt	rol	<reg_E						; shift into output register
												; process 2 axis
JoyAxis	lda	>$015b						; get Y axis value
			cmpa	#8								; is it move Up? (now less that 18) was 26
			rol	<reg_E						; puts 1 if it was up (08)
			lda	#55							; is it Down? (now greater than 45) was 37
			cmpa	>$015b						; compare to Y axis
			rol	<reg_E						; puts 1 if it was down (04)
			lda	>$015a						; get X axis value
			cmpa	#8								; is it move Left? (now less than 18) was 26
			rol	<reg_E						; puts 1 if it was right (02)
			lda	#55							; is it move Right? (now greater than 45) was 37
			cmpa	>$015a						; compare to X axis
			rol	<reg_E						; puts 1 if it was right (01)
JoyJo1	lda	<reg_E						; get result							
JoyJo2	sta	<joyVal						; save into variable								
			rts									; return												
; ------------------------------------------------------------------------------
; INPUT: two lower bits in regB -> mutiplex bits									
; ------------------------------------------------------------------------------
MuxBits	ldu	#$ff01						; point to PIA0 CRA
			bsr	MuxB01						; set/reset CA2
MuxB01	lda	,u								; get value from CRA - CRB
			anda	#$f7							; set to zero CA2 - CB2
			rorb									; send bit to carry
			bcc	MuxB02						; not set?
			ora	#8								; set to 1 CA2 - CB2
MuxB02	sta	,u++							; save value, point to CRB
			rts									; return
; ------------------------------------------------------------------------------
AudiOff	clra									; bit 3 of ACCA = 0 disable analog MUX
			fcb	$8c							; skip next
AudiOn	lda	#8								; bit 3 of ACA = 1 enable analog MUX
			sta	,-s							; save on stack
			lda	$ff23							; get ctrl register of PIA1 side-B
			anda	#$f7							; reset bit 3
			ora	,s+							; set desired status
			sta	$ff23							; update PIA
			rts
; ------------------------------------------------------------------------------
Any hint will be highly appreciated!!
cheers
pere

Ps I attach the source file here to make copying it easier
Joysticks.zip
(1.64 KiB) Downloaded 547 times
pser1
Posts: 1655
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Re: Joysticks and noise on the sound output

Post by pser1 »

Hi,
for maybe it could help ... I upload here a zip containing the source code of a program that shows this noise
when run on a Dragon 32/64, at the same time I include an VDK file to create a disk if desired.
The program will also run on a CoCo2

Thanks beforehand
pere
JOYSTK.ZIP
(5.42 KiB) Downloaded 546 times
Ps I copied the Joystick read procedure form the 'CoCo Unraveled series' so I thought this could not happen ...
it seems that I made something wrong in the hardware configuration, but I cannot spot the flaw(s)
pser1
Posts: 1655
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Re: Joysticks and noise on the sound output

Post by pser1 »

sorry, I forgot to say that this program uses the LEFT joystick.
Basically to avoid conflicts with keys number 1-2-3-4

It scans the four directions (axis) of the left joystick and its button.
Then it scans six keys: Z, I, 1, 2, 3, 4

Anyone found pressed is shown on the screen with a coloured square.
I can 'hear' the noise just mving the stick even inside the 'zero' area

cheers
pere
pser1
Posts: 1655
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Re: Joysticks and noise on the sound output

Post by pser1 »

Hi,
it doesn't matter what I do, noise keeps there!
Even using this small Basic program creates an unexpected (to me) sound

Code: Select all

100 CLS
110 AUDIOOFF
120 A=JOYSTK(0)
130 POKE&HFF20,PEEK(&HFF20)AND3
140 AUDIOON
150 PRINT@128,A;"   ";
160 POKE&HFF20,PEEK(&HFF20)AND3
170 GOTO 110
Does anyone know how could sound be switched off and on without any noise output?
I would really appreciate any hint / advice
Thanks a lot
pere
Alastair
Posts: 669
Joined: Fri Jul 18, 2008 11:33 pm

Re: Joysticks and noise on the sound output

Post by Alastair »

Pere, is there anything in this thread from 2010 that is of any use to you?
pser1
Posts: 1655
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Re: Joysticks and noise on the sound output

Post by pser1 »

Alastair wrote:Pere, is there anything in this thread from 2010 that is of any use to you?
Hello,
thanks a lot for the link!
I had the soft uploaded by Steve but in my case didn't cancel the noise.
I am reading the joysticks 50-60 times per second and despite disabling audio before that read, there is a low but noticiable
noise.
In the end, I have changed the call to [$A00A] by a shortened version of the ROM routine and that way it is *almost* acceptable
Phill Harvey-Smith (via Kees van Oss) and Stewart Orchard have given some hints/tricks to reduce that noise as much as possible.
The 'version' I am testing right now seems good enough for me, so I am planning to include it in my AGD engine conversion ...
Thanks to everyone for your help!
cheers
pere
User avatar
Bosco
Posts: 330
Joined: Tue Mar 04, 2014 11:49 pm
Location: Nottingham, UK

Re: Joysticks and noise on the sound output

Post by Bosco »

Hi Pere.

I went through the same thing trying to eliminate `buzzing' when reading the joystick. As you've discovered it can only be minimised but not stopped altogether. :(

Stew was a great help and managed to shed quite a bit of light on what's happening to create the buzzing including why different speaker setups can make it more or less noticeable.

Glad you've got it to an acceptable state. :)
pser1
Posts: 1655
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Re: Joysticks and noise on the sound output

Post by pser1 »

Bosco wrote:Hi Pere.
I went through the same thing trying to eliminate `buzzing' when reading the joystick. As you've discovered it can only be minimised but not stopped altogether. :(
Stew was a great help and managed to shed quite a bit of light on what's happening to create the buzzing including why different speaker setups can make it more or less noticeable.
Glad you've got it to an acceptable state. :)
Hi,
as Stew said to me, it is highly dependent on the hardware connected to the computer .... but today I have been using my Tano that contains
a CoCo-VGA and with the CoCo-SDC I have been testing some of the converted AGD games using my engine ...
Much to my surprise the Tano generates almost no noise at all. I have to turn the power very high to hear it, so I am thinking that maybe the
power supply could be a source of noise too? Just thinking out loud ... not sure but there must be a reason for this difference using the same TV set
cheers
pere
User avatar
Bosco
Posts: 330
Joined: Tue Mar 04, 2014 11:49 pm
Location: Nottingham, UK

Re: Joysticks and noise on the sound output

Post by Bosco »

That's interesting Pere.

After fine tuning my joystick routine to minimise the potential for `buzz' I found hooking the Dragon up to a TV using RF produced nice clean audio. This would have been my setup as a child which explains why I don't remember background buzz being a problem in the eighties.

Of course these days I prefer composite which is where the problems start. I did ask Stew if a circuit could be placed between the Dragon's composite out and the display device to eliminate buzz and he suggested a simple buffer amplifier. This kind of stuff is a little out of my wheelhouse but I like the idea of a `buzz-kill' widget. :)
pser1
Posts: 1655
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Re: Joysticks and noise on the sound output

Post by pser1 »

Bosco wrote:That's interesting Pere.

After fine tuning my joystick routine to minimise the potential for `buzz' I found hooking the Dragon up to a TV using RF produced nice clean audio. This would have been my setup as a child which explains why I don't remember background buzz being a problem in the eighties.

Of course these days I prefer composite which is where the problems start. I did ask Stew if a circuit could be placed between the Dragon's composite out and the display device to eliminate buzz and he suggested a simple buffer amplifier. This kind of stuff is a little out of my wheelhouse but I like the idea of a `buzz-kill' widget. :)
Right!
It seems that the better the used TV set, the more noise is reproduced, pity!
Not sure if I would go for a pre-amplifier to cancel that noise ... maybe even a mute circuit if level is lower than a thresold fixed could work.
cheers
pere
Post Reply