ZXpand Joystick - programming.

Discussions about Sinclair ZX80 and ZX81 Hardware
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: ZXpand Joystick - programming.

Post by bobs »

The code should be pretty simple. At 0x73DF I test for the existence of the interface:

Code: Select all

	; Test for the existance of a ZXpand interface.
	xor a
	ld (GLOBAL_HARDWARESTATE), a
	ld bc, %1110000000000111
	ld a, $aa
	out (c), a
	nop
	nop
	nop	; [some small delay, 10 clocks or so]
	in a, (c)
	cp $f0
	jr nz, FRONTEND_NOZXPAND
	ld a, $55
	out (c), a
	nop
	nop
	nop	; [some small delay, 10 clocks or so]
	in a, (c)
	cp $0f
	jr nz, FRONTEND_NOZXPAND
	; ZXpand detected.
	ld hl, GLOBAL_HARDWARESTATE
	set CONST_HARDWARESTATEBIT_ZXPAND, (hl)
FRONTEND_NOZXPAND
And then in the main game-loop, at 0x69AB I read the joystick and react accordingly:

Code: Select all

	; Check for ZXpand interface.
	ld hl, GLOBAL_HARDWARESTATE
	bit CONST_HARDWARESTATEBIT_ZXPAND, (hl)
	jr z, SUB_DOFIRSTTURN_USEKEYBOARD
SUB_DOFIRSTTURN_USEZXPAND
	; Read the joystick.
	push bc
	ld bc, %1110000000000111
	ld a, $a0
	out (c), a
	nop
	nop
	nop	; [some small delay, 10 clocks or so]
	in a, (c)
	pop bc
	; Check for moving left.
	bit 5, a
	jr z, SUB_DOFIRSTTURN_MOVELEFT
	; Check for moving right.
	bit 4, a
	jr z, SUB_DOFIRSTTURN_MOVERIGHT
	; Check for moving up.
	bit 7, a
	jp z, SUB_DOFIRSTTURN_MOVEUP
	; Check for moving down.
	bit 6, a
	jp z, SUB_DOFIRSTTURN_MOVEDOWN
SUB_DOFIRSTTURN_USEKEYBOARD
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZXpand Joystick - programming.

Post by sirmorris »

Thanks Bobs, I suspect the interface isn't being detected.

I'll try another hack and invert the sense of the zxpand test, see what happens.

C
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZXpand Joystick - programming.

Post by sirmorris »

I've written some test code and it appears you need at least 4 NOPs between the OUT and INs in both the interface detect and the joystick read. Make it 5 to be sure ;¬) Three is right on the edge, there is significant noise with the values flickering between the $80 of the 'ready' state and the correct value.

I'll update the docs, if you wouldn't mind updating the code..!

If any ZXpand owners out there wouldn't mind running the program and telling me which number is steady that would be appreciated. You're looking for a rock steady 'F0'.


C
Attachments
tjoy.zip
(1.21 KiB) Downloaded 135 times
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: ZXpand Joystick - programming.

Post by bobs »

sirmorris wrote:I'll update the docs, if you wouldn't mind updating the code..!
I've updated the code to use 5 NOPs (so 20 tstates) at each point, and uploaded a new build - http://www.bobs-stuff.co.uk/extras/minermanzxpand.zip if somebody would like to test it.
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZXpand Joystick - programming.

Post by sirmorris »

Success! It was good before ... but with joystick control it's absolutely storming!

Now then, can't stop to type ... got to get back to level 4...
dr beep
Posts: 2080
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZXpand Joystick - programming.

Post by dr beep »

sirmorris wrote:Success! It was good before ... but with joystick control it's absolutely storming!

Now then, can't stop to type ... got to get back to level 4...

21 T states delay in just 2 bytes
PUSH HL
POP HL
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZXpand Joystick - programming.

Post by sirmorris »

Thanks! I was considering options - I'm too vain to have 5 nops in the code - I think it looks ugly ;¬)

ex (sp),hl
ex (sp),hl

would give a bit more margin - 38 clocks.

C
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: ZXpand Joystick - programming.

Post by bobs »

sirmorris wrote:Success! It was good before ... but with joystick control it's absolutely storming!

Now then, can't stop to type ... got to get back to level 4...
Thanks! I've updated the main download with this version now.
Post Reply