Using a Kempston Joystick Interface with a ZX81

Discussions about Sinclair ZX80 and ZX81 Hardware
Post Reply
User avatar
1024MAK
Posts: 2484
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 » Tue Jul 09, 2019 2:09 pm

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.
8C27B716-8469-48EE-A458-3B5DB111A324.jpeg
Kempston joystick interface - simple ZX81 test program.
72E2813D-F415-4CCF-B2E9-3392CBCE3FD8.jpeg
Kempston joystick interface - More complex ZX81 test program
FFFDB50A-3923-4E49-B8F5-00A3E9EA6B88.jpeg
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

User avatar
XavSnap
Posts: 740
Joined: Sat May 10, 2008 4:23 pm

Re: Using a Kempston Joystick Interface with a ZX81

Post by XavSnap » Thu Jul 11, 2019 1:59 am

Hi Mark,

Can you test or check this routine, EO & Xur can't simulate it…
TEST.P
(1.13 KiB) Downloaded 20 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

User avatar
XavSnap
Posts: 740
Joined: Sat May 10, 2008 4:23 pm

Re: Using a Kempston Joystick Interface with a ZX81

Post by XavSnap » Thu Jul 11, 2019 11:06 am

And, the full duplex release…
joy2.P
(1.19 KiB) Downloaded 15 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.

User avatar
mrtinb
Posts: 1043
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Using a Kempston Joystick Interface with a ZX81

Post by mrtinb » Fri Jul 12, 2019 12:08 pm

So if someone just want the real thing, one just appeared on eBay: https://www.ebay.com/itm/153561929093
Martin
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube

User avatar
1024MAK
Posts: 2484
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 » Wed Oct 09, 2019 3:59 pm

Sorry Xav, I forgot all about this :oops:

Mark

User avatar
XavSnap
Posts: 740
Joined: Sat May 10, 2008 4:23 pm

Re: Using a Kempston Joystick Interface with a ZX81

Post by XavSnap » Thu Oct 10, 2019 12:17 am

:lol:
A good way to have a look to emulators !

Post Reply