Joysticks and noise on the sound output
Posted: Sun Dec 02, 2018 8:28 pm
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!
Any hint will be highly appreciated!!
cheers
pere
Ps I attach the source file here to make copying it easier
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
; ------------------------------------------------------------------------------
cheers
pere
Ps I attach the source file here to make copying it easier