Using a Kempston Joystick Interface with a ZX81

Discussions about Sinclair ZX80 and ZX81 Hardware
Post Reply
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Using a Kempston Joystick Interface with a ZX81

Post by 1024MAK »

This only applies to the Kempston (or compatible) joystick interfaces that have a ZX81 sized edge-connector socket.

Line 1 contains machine code that is called by the USR function later in the program.

Note that in these programs, you MUST type in line 1 and line 2 exactly as shown below:-

In line 1, after the REM, type the following on the keyboard using the “one entry keyword” method, so ‘<=’ (on key R), ‘3’ then enter a space, then the graphic character on key Y, then a space and then the ‘TAN’ keyword (key E).
Both the ‘<=’ and the ‘TAN’ are entered using the single key entry system, NOT as separate symbols and letters.

Then list line 1 before proceeding. It should look like the program listing except you will have a space instead of a question mark.

Now enter line 2. Then RUN the program. If you now list the program, lines 1 & 2 should look exactly the same as the listings of my screenshots.

You can then enter the rest of the program.
Kempston joystick interface - simple ZX81 test program.
Kempston joystick interface - simple ZX81 test program.
Kempston joystick interface - More complex  ZX81 test program
Kempston joystick interface - More complex ZX81 test program
Screenshot
Screenshot
The machine code is

Code: Select all

IN A,(1F)       DB 1F
LD C,A          4F
LD B,0          06 00
RET             C9
(numbers are in hexadecimal)

I should also say the the second program can only handle one joystick action at a time, so if you press fire and then move the joystick, the program will ignore the movement of the joystick.

Mark
Last edited by 1024MAK on Tue Jul 09, 2019 2:33 pm, edited 1 time in total.
Reason: Correct a typo in the machine code listing
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Using a Kempston Joystick Interface with a ZX81

Post by XavSnap »

Hi Mark,

Can you test or check this routine, EO & Xur can't simulate it…
TEST.P
(1.13 KiB) Downloaded 221 times
Thanks.
Note: ( 0=0; 1=1; 2=2; 4=3; 8=4)= Bit range…
In this decoder, the ASM routine can't test UP&RIGHT, LEFT&DOWN... multi-states joystick commands!
:shock:
You can't press 'fire' while using another direction.

But, we can use the pur IN A,($1F) value, and generate a decimal value "00" to "15" …
( AND 16 = "FIRE" )

Not: 8 bits are tested, but, only 5 bits (0 to 4) are used.

Code: Select all

     0  REM [HEX:\
DB,1F,01,00,07,0C,CB,47,\
20,05,1F,10,F8,0E,00,79,\
C6,1C,2A,29,40,01,08,00,\
09,77,C9 ]

     1 LET J=VAL "16514"
     5 PRINT AT 5,5;
    10 RAND USR J
    20 GOSUB VAL ("0")*20+100
    30 GOTO 5
   100 PRINT "     "
   110 RETURN 
   120 PRINT "RIGHT"
   130 RETURN 
   140 PRINT "LEFT "
   150 RETURN 
   160 PRINT "DOWN "
   170 RETURN 
   180 PRINT "UP   "
   190 RETURN 
   200 PRINT "FIRE "
   210 RETURN 

Code: Select all

.org 16514

	IN A,($1F) ; GET IORQ
	LD BC,$0700 ; B=7... but, can be equal to 5.(0 to 4) #0-3: dir … #4=fire.
Test1:
	INC C
	BIT 0,A ; Test the bit#0
	JR nz,Lb1 ; Bit=1 jump to lb1
	RRA ; rotate A to right.
	DJNZ Test1 ; loop (7 times= 7 bits)
	LD C,$00 ; IORQ=0 (nothing on the port)
Lb1:
	LD A,C
	ADD A,$1C ; "0" convert to a char number.
	LD HL,($4029) ; get the GOSUB line, (next line)
	LD BC,8
	ADD HL,BC
	LD (HL),a ; Put the char in the GOSUB VAL"x" argument. (don't move the RAND line/GOSUB line)
	RET ; return to the Basic...
.end
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Using a Kempston Joystick Interface with a ZX81

Post by XavSnap »

And, the full duplex release…
joy2.P
(1.19 KiB) Downloaded 201 times
Based a an array J() 1 to 5, set to "0" (false) or "1" (true) :

Code: Select all

     0  REM [HEX:\
DB,1F,47,E6,01,32,21,40,\
78,1F,2A,12,40,01,06,00,\
09,01,00,04,CB,47,36,00,\
28,02,36,81,1F,23,23,23,\
23,23,10,F0,ED,4B,21,40,\
06,00,C9 ]

     0 DIM J(5)
     5 LET J(1)=USR VAL "16514"
    20 PRINT AT 5,5;"                       ";AT 5,5;("RIGHT " AND J(1));("LEFT " AND J(2));("DOWN " AND J(3));("UP " AND J(4));("FIRE " AND J(5));
    30 GOTO 5

Code: Select all

DEST		.equ $4012
EXTERR		.equ $005B
SPARE8		.equ $4021

.org 16514

	IN A,($1F)
	LD B,A
	AND 1
	LD (SPARE8),A
	LD A,B
	RRA
	LD HL,(DEST)
	LD BC,6
	ADD HL,BC
	LD BC,$0400
Test1:
	BIT 0,A
	LD (HL),$00
	JR z,Lb1
	LD (HL),$81
Lb1:
	RRA
	INC HL
	INC HL
	INC HL
	INC HL
	INC HL
	DJNZ Test1
	LD BC,(SPARE8)
	LD B,0
	RET
.end
[Updated/new release]
Last edited by XavSnap on Tue Jul 30, 2019 12:07 am, edited 1 time in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
mrtinb
Posts: 1910
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Using a Kempston Joystick Interface with a ZX81

Post by mrtinb »

So if someone just want the real thing, one just appeared on eBay: https://www.ebay.com/itm/153561929093
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Using a Kempston Joystick Interface with a ZX81

Post by 1024MAK »

Sorry Xav, I forgot all about this :oops:

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Using a Kempston Joystick Interface with a ZX81

Post by XavSnap »

:lol:
A good way to have a look to emulators !
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
shirleyknott
Posts: 2
Joined: Thu May 23, 2019 4:09 pm

Re: Using a Kempston Joystick Interface with a ZX81

Post by shirleyknott »

Hi Mark, thanks for posting this. I was curious about this interface I had in a box of bits. It's branded 'RAM' (ironic as it's not a ram pack).

Your program works, and so my interface is indeed a Kempston interface. One small detail - The program wasn't returning the correct values, looks like i didn't get the machine code quite right. Looking at the actual hex, your screenshots are correct, but in the text you say the graphics character on Y but I think that should be the graphics character on T. Hope that helps anyone who finds this thread after Googling 'Kempston Interface ZX81' as I did.

Image
User avatar
Danjovic
Posts: 14
Joined: Fri Feb 07, 2014 1:06 am

Re: Using a Kempston Joystick Interface with a ZX81

Post by Danjovic »

It should be possible to connect a Master System Paddle using a cable adapter for playing breakout style games. I have wrote some asm code for Zeddy and for Speccy

https://github.com/Danjovic/ZX/tree/master/paddle

Adapter should route pin 7 (+5V) on Kempston interface to pin 5 on SMS controller.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Using a Kempston Joystick Interface with a ZX81

Post by XavSnap »

Code: Select all

	LD BC,$0000 
Lb4127:
	IN A,($1F) ; User port.
	BIT 5,A 
	JR NZ, Lb412E ; [$412E:16686]
	INC C
Lb412E:
	DJNZ Lb4127 ; [$4127:16679]
LD BC,$0000 is really set to $0000, not $0800...
DJNZ loop $FF times...
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply