Hello everyone,

 

The start of another wet weekend in my part of the world is just the excuse I

needed to resume my ZX81 projects. In 1997 I designed an interface which

connects a NINTENDO game-pad to my ZX97 or a ZX81 with a 8255 I/O adapter

(which I will post next). I have interfaced both the wired NES controller version

and the more interesting wireless infrared (IR) game pad unit.

 

Aside from it's obvious use for games, you will be surprised by the many other

possible applications for this game controller. Talk about instant results: most of

the work is already done and you only need to solder a DB25 connector, add a few

jumpers, batteries and some software to get up and running. So pick up an old

Nintendo game-pad at your local thrift shop for a few dollars and take a couple of

hours of your time to "get connected". Then share your ideas with the rest of us!

 

enjoy

 

wilf

 

                ZX GAMEPAD 1997 - NINTENDO game-pad

                     to ZX81/97 adapter by Wilf Rigter

                        

 

In this easy to construct project, we mate a NINTENDO (NES) game-pad

with a ZX97 or a ZX81 with a 8255 type parallel printer port.

 

The NINTENDO (NES) game-pad circuit, shown in FIG 1, uses a standard CMOS 8 bit

parallel to serial shift register (MC4021B) connected to 8 switch contacts. Switch

data is loaded into the shift register by the game system with a positive pulse on

the P/S line. The data is clocked out on the rising edge of each clock pulse on the

CLK line. The eight data bits appear sequentially on the Q8 line with the A switch first.

 

                                             0V                  +5V

            _________________________________|                    |

           |              __________________ | ___________________|

           |             |                   |                    |

           |    RESNET [10K]   MC14021B      |                    |

           |             |      _______      |                    |

 RIGHT     |------o_o----+----7|P1  VDD|16-- | -------------------|

 LEFT      |------o_o----+----6|P2     |     |                    |

 DOWN      |------o_o----+----5|P3   DS|11---|          __        |

 UP        |------o_o----+----4|P4  VSS|8----+--BRN----|0  \      |

 START     |------o_o----+---13|P5  CLK|10------RED----|0  0|-WHT-+

 SELECT    |------o_o----+---14|P6  P/S|9-------OR-----|0  0|

 B         |------o_o----+---15|P7   Q8|3-------YEL----|0  0|

 A         +------o_o----+----1|P8     |               |____|

              SWITCH 1-8       |_______|              NINTENDO

                                                      CONNECTOR

 

                                FIG 1 - NINTENDO (NES) GAME-PAD DISASSEMBLED

 

The game-pad is adapted to a standard PC type printer port as shown in Fig 2, by

replacing the NINTENDO connector with a male DB 25 connector.

 

Since the game-pad uses a CMOS chip with low clock rates, it requires less than 1 mA

of current easily supplied by 3 AAA batteries or equal. When disconnected and no keys

are depressed the current is essentially zero. A second NES game-pad can be added by

connecting all lines in parallel except output Q8b which is wired separately to pin 14.

 

                            MALE DB25

                            FRONT VIEW

             +4.5V____WHT____________________

               Q8b____YEL_______________     |

                               __       |    |

               Q8a ---YEL----1|o  \     |    |

               P\S ---OR-----2|o  o|14__|    |  4.5V

               CLK ---RED----3|o  o|        _-_

                              |o  o|       | + |

                              |o  o|       |   |

                              |o  o|       |   |

                              |o  o|       |   |

                              |o  o|       |___|

                              |o  o|         |

                              |o  o|         |

                              |o  o|         |

                              |o  o|         |

                              |o  o|25-------|

                              |___/          |

               0V_____BRN____________________|

 

                                  FIG 2 PRINTER PORT ADAPTER

 

The infrared wireless game-pad made by Radio Shack (58-9854) is shown in FIG 3.

It uses a single chip remote IR transmitter to convert 8 contacts to a serial bit

stream which modulates a 40 KHz IR carrier. In addition, there are the "turbo"

keys which produce pulsing A and B signals.  The P1/P2 switch selects one of

two game-pads which can be used simultaneously with the IR receiver. The IR

remote use 3 AAA type batteries with 22 mA average current when transmitting

but no power drain unless a contact is closed. The IR transmitter range is about

30 feet "line of sight" and about 20 feet when bounced of a white ceiling.

 

                                          \\   \\

 4.5V      -----+----------+------------|>|----|>|----270----+

                |          |              IR LED             |

                | SWITCH11 |    _______                     |/

P1/P2           +-o_o---+  +--6|VDD OUT|7-------------------|  2N2222A

           +------o o---+----16|P1/P2  |             //     |\

    0V     |------------------8|VSS  ON|4-----|>|---|>|------+-----0V

 RIGHT     |------o_o--------19|P1     |   1N4448  RED LED

 LEFT      |------o_o---------1|P2     |                   470p

 DOWN      |------o_o--------20|P3  OSC|9___________________||______0V

 UP        |------o_o---------2|P4     |      |       |     ||

 START     |------o_o--------17|P5     |      |     _ | _

 SELECT    |------o_o--------18|P6     |     1M     _|_|_  455KHz

 B         |------o_o--------14|P7     |      |       |

 A         |------o_o--------12|P8  OSC|10____|_______|_____||______0V

 TURBO A   |------o_o--------11|P9     |                    ||

 TURBO B   |------o_o--------13|P10    |                   470p

           |    SWITCH 1-10    |_______|

          0V

                                    FIG 3 - RADIO SHACK IR GAME-PAD DISASSEMBLED

 

The infrared serial data from the remotes is demodulated with the Radio Shack

IR receiver (58-9855) which can receive 16 bits of data from two 8 bit remote units.

The same data transfer protocol as the NES game pad is used and the demo

software is compatible. The IR receiver is normally connected via two NINTENDO

connectors which are replaced with a single cable and male DB25 connector in FIG 4.

The two P/S and two CLK lines are operated in parallel and are joined with two

jumpers and connected to pins 2 and 3. The two Q8 lines are connected separately

to pins 1 and 14. The 0V line is connected to pin 25 of the DB25. In addition, two

double AA battery holders are placed in the base of the receiver to supply the +5V

supply. The IR receiver unit draws about 3 mA and batteries should be removed

to conserve power when the unit is not in use.

 

 

                                                       MALE DB25

   470p             ________                           FRONT VIEW

0V__||____________1|OSC     |

    ||   |    |    |     Q8b|10__________________WHT______________

       __|__  |    |        |                             ___     |

 455K  _|_|_ 1M    |     Q8a|7___________________YEL____1|o   \   |

         |    |    |    P/Sa|4___________________OR_____2|o  o|14_|

0V__||___|____|__16|OSC P/Sb|12____|      _______RED____3|o  o|

    ||             |    CLKa|5___________|               |o  o|

   470p            |    CLKb|13__________|               |o  o|

                   |     VDD|15_________________         |o  o|

                   |        |     220uf|        |  4.5V  |o  o|

                   |        |    __||__|       _-_       |o  o|

                   |        |   |  ||+        | + |      |o  o|

                   |     VSS|3__|________     |   |      |o  o|

                   |     VSS|2___________|    |   |      |o  o|

                   |________|            |    |___|      |o  o|

                                         |      |        |o  o|25_

                                         |      |        |___/    |

                                         |______|_BRN_____________|

 

               FIG 4 RADIO SHACK IR RECEIVER CIRCUIT WITH DB25 ADAPTER

 

This project has many possible remote sensing and control applications.

The game-pad data can be read with the ZX81/ZX97 machine code program in

listing 2. The 16 bits of data are stored as "1" or "0" in array A$. This makes it

easy to test the individual bits or bit combinations in a BASIC program using

various string commands as shown in the short example in listing 1, using a

game-pad to control the PLOT position.

 

I have included a decimal listing of the machine code in listing 3 which must be

poked in a 63 byte REM line starting at address 16514.

 

LISTING 1

 

1   REM machine code in listing 1

2   DIM A$(2,8)

10  X=0

20  Y=0

30  RAND USR 16516

40  PRINT AT 0,0; A$(1)                        ;prints binary string

50  IF A$(1,8)="1" THEN IF X<63 THEN LET X=X+1 ;move cursor right

60  IF A$(1,5)="1" THEN IF Y<47 THEN LET Y=Y+1 ;move cursor up

70  IF A$(1,7)="1" THEN IF X>0 THEN LET X=X-1  ;move cursor left

80  IF A$(1,6)="1" THEN IF Y>0 THEN LET Y=Y-1  ;move cursor down

90  PLOT X,Y

100 IF A$(1,1)="0" THEN UNPLOT X,Y

100 GOTO 30

 

      ;LISTING 2

 

      ;READ DATA FROM TWO

      ;NINTENDO GAME-PADS

      ;AND WRITE TO A$

 

INIT  LD A,83                   ;SET UP 8255 MODE

      OUT DF,A

      LD HL,(4010)              ;START OF BASIC VARIABLES

      LD DE,0008                ;OFFSET TO FIRST ELEMENT

      ADD HL,DE                 ;OF A$(2,8)

      LD B,08

LOAD

      LD A,01                   ;PULSE PORTA/D0

      CALL OTP                  ;TO LOAD SHIFT REGISTER

READ

      IN A,D7                   ;READ PORTC

      LD C,A                    ;SAVE COPY

      CALL WRITE                ;WRITE "1" OR "0" TO A$(1,N)

      ADD HL,DE                 ;OFFSET TO A$(2,N)

      LD A,C                    ;GET COPY

      RRA                       ;SHIFT RIGHT

      CALL WRITE                ;NOW WRITE A$(2,N)

      SBC HL,DE                 ;OFFSET TO A$(1,N)

      INC HL                    ;NEXT N

      LD A,02                   ;PULSE PORTA/D1

      CALL OTP                  ;TO CLOCK NEXT BITS

      DJNZ READ

      RET

WRITE

      CPL                       ;OPEN SWITCH = 0

      AND 01                    ;MASK BIT 0

      ADD A,1C                  ;ADD "0"

      LD (HL),A                 'WRITE TO A$

      RET

OTP

      OUT C7,A                  ;PORT C = REG A

      XOR A                     ;REG A = 0

      OUT C7,A                  ;RESET PORT C

      RET

 

 

LISTING 3 - DECIMAL LISTING OF THE MACHINE CODE OF LISTING 2

 

16514 - 118,118,024,004,062,131,211,223,042,016,064,017,008,000,025,006,

16530 - 008,062,001,205,182,064,219,215,079,205,175,064,025,121,031,205,

16546 - 175,064,237,082,035,062,002,205,182,064,016,234,201,047,230,001,

16552 - 198,028,119,201,211,199,175,211,199,205,070,015,216,207,000

 

Another interesting application uses two game-pads and two IR receivers for

bi-directional data transfer between a PC and a ZX97 (or another PC).

Game-pad P1 and IR receiver P2 output is connected to a PC printer port.

Game-pad P2 and IR receiver P1 output is connected to a ZX97 as shown in FIG 5.

This arrangement would be quite useful in a robotics application.

 

 

     PC LPT                                                    ZX97 LPT

     _______       ______                       ______         _______

    |       |     |      |                     |      |------>|IN     |

    |  D0-7 |---->| TX   |      >>>>>>>>       |  RX  |       |PORTC  |

    |       |     |______|                     |______|<------|OUT    |

    |       |                                                 |       |

    |       |      ______                       ______        |       |

    | STATUS|<----|      |                     |      |       |       |

    |CONTROL|---->|  RX  |      <<<<<<<<       |  TX  |<------|PORTA  |

    |_______|     |______|                     |______|       |_______|

 

                   FIG 5 - DUPLEX DATA COMMUNICATION

 

 

 

Feel free to send your comments by mailto:wrigter@dccnet.com

 

If you get a chance to try out some of these ideas in your own applications, why not

write a little article about it and post it on ts1000.us

 

enjoy

 

wilf