Classic Computer Magazine Archive COMPUTE II ISSUE 3 / AUGUST/SEPTEMBER 1980 / PAGE 4

The Single-Board 6502

Eric Rehnke

Getting Hooked Up

Well, I finally did it. Got myself an APPLE II to play with. No, I'm not abandoning KIM. Just wanted to see what all the hullaballoo was about.

Sure is easier to demonstrate than KIM. Who wants to see an assembler when they can see some neat video-arcade like games in action?

…And Ever The Twain Shall Meet

While I was preparing to take an AIM 65 system to the local computer club for a demo, it became painfully obvious that I would either have to build a special version of the sound generator board for my AIM 65/MTU system or, somehow, adapt the sound board that was built for my KIM-1/HDE system. I decided to adapt rather than fight with a new board from the ground up. Luckily, in my MTU card cage, the bottom row of slots are not used because of the way the MTU backplane board has been raised to accommodate the AIM 65. Also, the spacing between the card guide on the right hand side of the cage and the edge connector turned out to be just perfect for supporting the 4.5"×6.0" HDE size card. It was almost like the cage was designed to accommodate the standard 4.5"×6.0" size prototyping cards. (Keep this in mind when you need a quick and cheap proto board in your MTU system as they can be obtained for less than $10).

Interestingly, a week later, I needed to adapt an MTU card (the Visible Memory graphics board) to my KIM-1/HDE system. Because of the size of the Visible Memory card it had to be mounted outside the HDE cage. A cheap 4.5"×6.0" proto board was installed in the HDE system with ribbon cable to extend the bus out to a 44-pin card edge connector which plugged on to the MTU card.

Both transplants are doing fine, thank you. And, on nights off from doing serious development work, big KIM can relax with some pleasing graphics as well as some interesting sound effects.

Here's how to cross pollinate your own system:


KIM-1/HDE         SIGNAL NAME         MTU/AIM-65
BACKPLANE   BACKPLANE
B                                     AB0                                     A
C                                     AB1                                     B
D                                     AB2                                     C
E                                     AB3                                     D
F                                     AB4                                     E
H                                     AB5                                     F
J                                     AB6                                     H
K                                     AB7                                     J
L                                     AB8                                     K
M                                     AB9                                     L
N                                     AB10                                     M
P                                     AB11                                     N
R                                     AB12                                     P
S                                     AB13                                     R
T                                     AB14                                     S
U                                     AB15                                     T
8                                     DB7                                     8
9                                     DB6                                     9
10                                     DB5                                     10
11                                     DB4                                     11
12                                     DB3                                     12
13                                     DB2                                     13
14                                     DB1                                     14
15                                     DB0                                     15
19                                     + 8                                     18
22                                     GND                                     22
7                                     RES                                     7
X                                     02                                     Y
17                                     + 16                                     X
W                                     R/W                                     V

                         Signal Conversion Table



Sound Chip Driver

As promised, here is the low level driver software for interfacing a 6522 VIA to the General Instruments AY3-8910 Programmable Sound Generator (PSG). The explosion routine is included to satisfy yourself that the interface works correctly. The clock circuit was duplicated from page 33 of the PSG manual.

The 1 MHZ system clock (01 or 02) could have been used to save a few dollars but then all example values given in the documentation would have to be recalculated. Building the suggested clock input circuitry seemed to be the easier of the two alternatives since I had the parts on hand anyway.

The audio output circuitry was duplicated from page 6 of the PSG manual and used to feed one of the cheap (under $10) Radio Shack speaker/amplifiers.

Connections from the 6522 to the PSG are similar to the scheme presented on page 43 of the PSG manual except that BC2 (pin 28) is connected to + 5 volts (not PB1), and BDIR (pin 27) is connected to PB1 (not PB2).

This way, three additional PSG chips can be connected to the 6522 as my drawing indicated in issue #3 of COMPUTE (page 104).

I should mention that there was one thing about the PSG manual that really messed me up for awhile. All the register numbers and values are expressed in octal! Once I realized this, programming the chip went much easier.

OK. I've shown you how to hook up this neat chip and even threw in some software to get you going.

What kinds of interesting sounds can you come up with? Can you program wind chimes or bells? I'll publish any neat sound programs.



01-0020 2000            ;SOUND CHIP DRIVER PROGRAM
01-0025 2000            ;WRITTEN BY ERIC C. REHNKE
01-0030 2000
01-0040 2000            ;6522 DEFINITIONS
01-0050 2000
01-0060 2000            IOBASE  =$0810
01-0070 2000
01-0080 2000            ORB     =IOBASE
01-0090 2000            DDRB    =IOBASE+2
01-0100 2000            DDRA    =IOBASE+3
01-0110 2000            OREGA   =IOBASE+15
01-0120 2000
01-0130 2000            PRTBYT  =$1E3B         ;KIM HEX TO ASCII ROUTINE
01-0140 2000            CRLF    =$1E2F
01-0150 2000            OUTSP   =$1E9E
01-0160 2000
01-0170 2000            STBUF   =$2500
01-0180 2000            ;MAINLINE ROUTINE
01-0190 2000                    *=$2000
01-0200 2000            ;
01-0210 2000            ;******OUTPUT TO THE SOUND CHIP******
01-0220 2000            ;IN ORDER TO SET A SOUND CHIP REGISTER TO
01-0230 2000            ;A PARTICULAR VALUE, ENTER THIS ROUTINE WITH
01-0240 2000            ;THE 'X' REGISTER CONTAINING THE SOUND CHIP
01-0250 2000            ;REGISTER NUMBER AND THE ACCUMULATOR CONTAINING
01-0260 2000            ;THE DATA TO BE LOADED INTO THAT REGISTER.
01-0270 2000            ;
01-0280 2000 A8         OUTPUT  TAY           ;SAVE DATA  
01-0290 2001 20 10 20           JSR LATCH
01-0300 2004 20 26 20           JSR WRITE
01-0310 2007 60                 RTS
01-0320 2008            ;
01-0330 2008            ;******INPUT FROM THE SOUND CHIP******
01-0340 2008            ;IN ORDER TO READ THE CONTENTS OF A
01-0350 2008            ;PARTICULAR SOUND CHIP REGISTER, ENTER
01-0360 2008            ;THIS ROUTINE WITH THE SOUND CHIP REGISTER
01-0370 2008            ;NUMBER IN THE 'X' REGISTER. UPON RETURN,
01-0380 2008            ;THE DESIRED REGISTER DATA WILL BE FOUND
01-0390 2008            ;IN THE ACCUMULATOR
01-0400 2008            ;
01-0410 2008 20 10 20   INPUT   JSR LATCH 
01-0420 200B 20 35 20           JSR READ
01-0430 200E 98                 TYA           ;RESTORE DATA
01-0440 200F 60                 RTS
01-0450 2010
01-0460 2110            ;THE 'LATCH' ROUTINE SIMPLY LATCHES
01-0470 2010            ;THE SOUND CHIP REGISTER NUMBER INTO
01-0480 2010            ;THE SOUND CHIP ADDRESS REGISTER FOR
01-0490 2010            ;A SUBSEQUENT READ OR WRITE.
01-0500 2010            ;
01-0510 2010 A9 FF      LATCH   LDA #$FF      ;MAKE IT ALL OUTPUTS  
01-0520 2012 8D 13 08           STA DDRA
01-0530 2015 8D 12 08           STA DDRB
01-0540 2018 8E 1F 08           STX OREGA
01-0550 201B A9 03              LDA #3        ;STROBE IN THE REG ADDRESS
01-0560 201D 8D 10 08           STA ORB
01-0570 2020 A9 00              LDA #0
01-0580 2022 8D 10 08           STA ORB
01-0590 2025 60                 RTS
01-0600 2026   
01-0610 2026            ;THE 'WRITE' ROUTINE ASSUMES THE
01-0620 2026            ;PROPER REGISTER VALUE HAS ALREADY 
01-0630 2026            ;SETUP IN THE SOUND CHIP AND LOADS
01-0640 2026            ;THE PROPER SOUND CHIP REGISTER WITH
01-0650 2026            ;THE CONTENTS OF THE ACCUMULATOR.
01-0655 2026            ;
01-0660 2026 98         WRITE   TYA   
01-0670 2027 8D 1F 08           STA OREGA
01-0680 202A A9 02              LDA #2
01-0690 202C 8D 10 08           STA ORB
01-0700 202F A9 00              LDA #0
01-0710 2031 8D 10 08           STA ORB
01-0720 2034 60                 RTS
01-0730 2035
01-0731 2035            ;THE 'READ' ROUTINE ASSUMES THE PROPER
01-0732 2035            ;SOUND REGISTER CHIP HAS BEEN SELECTED   
01-0733 2035            ;AND READS THAT REGISTER INTO THE
01-0734 2035            ;ACCUMULATOR.
01-0735 2035            ; 
01-0740 2035 A9 00      READ    LDA #0   
01-0750 2037 8D 13 08           STA DDRA
01-0760 203A A9 01              LDA #1
01-0770 203C 8D 10 08           STA ORB   
01-0780 203F AD 1F 08           LDA OREGA     ;GET DATA
01-0790 2042 A8                 TAY
01-0800 2043 A9 00              LDA #0
01-0810 2045 8D 10 08           STA ORB
01-0820 2048 60                 RTS
01-0830 2049 
01-0831 2049            ;THE 'CLEAR' ROUTINE ZEROS ALL THE REGISTERS
01-0832 2049            ;IN THE SOUND CHIP.
01-0835 2049            ;
01-0840 2049 20 73 20   CLEAR   JSR INITS
01-0850 204C A2 00              LDX #0
01-0860 204E A9 00      DOIT    LDA #0
01-0870 2050 20 00 20           JSR OUTPUT
01-0880 2053 E8                 INX
01-0890 2054 E0 11              CPX #17
01-0900 2056 D0 F6              BNE DOIT
01-0910 2058 00                 BRK
01-0920 2059   
01-0925 2059            ;THE 'CHECK' DUMPS THE CONTENTS OF
01-0926 2059            ;ALL THE SOUND CHIP REGISTERS TO
01-0927 2059            ;THE SERIAL TERMINAL.
01-0928 2059            ;
01-0930 2059 20 73 20   CHECK   JSR INITS
01-0940 205C 20 2F 1E           JSR CRLF
01-0950 205F A2 00              LDX #0
01-0960 2061 20 08 20   GETIT   JSR INPUT
01-0970 2064 20 3B 1E           JSR PRTBYT 
01-0980 2067 20 9E 1E           JSR OUTSP
01-0990 206A E8                 INX
01-1000 206B E0 11              CPX #17
01-1010 206D D0 F2              BNE GETIT
01-1020 206F 20 2F 1E           JSR CRLF
01-1030 2072 00                 BRK
01-1040 2073
01-1060 2073
01-1061 2073            ;THE 'INITS' ROUTINE SETS UP THE
01-1062 2073            ;6522 WITH PB0-PB7 AS OUTPUTS
01-1063 2073            ;AND WRITES A $00 TO THAT PORT.
01-1064 2073            ;
01-1070 2073 A9 FF      INITS   LDA #$FF
01-1080 2075 8D 12 08           STA DDRB
01-1090 2078 A9 00              LDA #0
01-1100 207A 8D 10 08           STA ORB
01-1110 207D 60                 RTS
01-1120 207E
01-1130 207E
01-1140 207E
01-1150 207E            ;EXPLOSION SOUND EFFECT
01-1160 207E
01-1170 207E A9 00      EXPLOS  LDA #$0
01-1180 2080 A2 06              LDX #6        ;SETUP REG 6
01-1190 2082 20 00 20           JSR OUTPUT
01-1200 2085 A9 07              LDA #$7
01-1210 2087 A2 07              LDX #7        ;SAME FOR REG 7
01-1220 2089 20 00 20           JSR OUTPUT
01-1230 208C A9 10              LDA #$10
01-1240 208E A2 08              LDX #8
01-1250 2090 20 00 20           JSR OUTPUT
01-1260 2093 A9 38              LDA #$38
01-1270 2095 A2 0C              LDX #12
01-1280 2097 20 00 20           JSR OUTPUT
01-1290 209A A9 10              LDA #$10
01-1300 209C A2 09              LDX #9
01-1310 209E 20 00 20           JSR OUTPUT
01-1320 20A1 A9 10              LDA #$10
01-1330 20A3 A2 0A              LDX #10
01-1340 20A5 20 00 20           JSR OUTPUT
01-1350 20A8 A9 00              LDA #0
01-1360 20AA A2 0D              LDX #13
01-1370 20AC 20 00 20           JSR OUTPUT
01-1380 20AF 00                 BRK
01-1390 20B0
01-1400 20B0
01-1410 20B0            ;THIS SECTION LOADS THE SOUND CHIP
01-1420 20B0            ;WITH THE FIRST 16 BYTES STARTING AT
01-1430 20B0            ;LOCATION $2500
01-1440 20B0   
01-1442 20B0
01-1450 20B0 A2 00      LOAD    LDX #0
01-1460 20B2 BD 00 25   LOOP1   LDA STBUF,X   ;NOW GET DATA
01-1470 20B5 20 00 20           JSR OUTPUT
01-1480 20B8 E8                 INX
01-1490 20B9 E0 11              CPX #17       ;DONE YET?
01-1500 20BB D0 F5              BNE LOOP1
01-1510 20BD 4C 59 20           JMP CHECK     ;DUMP THE CONTENTS
01-1520 20C0                                         OF THE CHIP
01-1530 20C0                    .END


More In Store

Now that we have sound output, it's only logical that we should have some sort of analog input. Besides, if we only hook one sound chip to the 6522 we have plenty of lines left — so let's use 'em. I happen to have a NATIONAL ADC0816 laying around that's just waiting to do something.

It's an 8 bit A/D converter with 16 analog inputs. The conversion time is around 100 μs and it runs on a single 5 volt supply. Ideal for joysticks and other analog devices.

Look for it in an upcoming column.

You Got Time?

What about the date? If your micro has need for the time and date, you'll be glad to hear that a new 18 pin, CMOS clock/calendar chip (MSM 5832) has been introduced by OKI Semiconductor (1333 Lawrence Expressway, Santa Clara, CA 95051 (408)984-4842) that can be easily interfaced to a 6522 VIA. In fact, it was made to interface with micros.

The MSM 5832 chip and necessary crystal (32.768 KHz) cost under $15 and is now generally available. If you can't find it locally, I got mine at Concord Computer Components (1973 So. State College, Anaheim, CA 92806 (714) 937-0637).

More On Communications

If you're interested in computer communications, two magazines recently had articles which will feed your enthusiasm.

Byte magazine (June 1980) had two useful articles which you will want to read.

The first article (on page 24) showed how to build a complete modem with pre-aligned filter modules which eliminates the need for complicated adjustments. The 6860 modem chip was used which is a perfect match for the new 6551 ACIA chip which is being manufactured by Rockwell and Synertek.

Page 140 (of the same issue) presents two methods of having KIM dial your phone. The first method uses the conventional relay approach while the second one uses a D/A converter (just like the one on the Micro Technology Unlimited D/A board) to generate and mix the two signals necessary to create the touch-tone pair.

Doctor Dobbs Journal (June/July 1980) devoted part of an issue to the subject of networking which included an update on the PCNET efforts of Dave Caulkins, several articles on networking and a description of MCALL-C, another communications protocol.

They also had a directory of phone numbers for 144 computerized bulletin board systems.

Lots of things are happening in this area of personal computing and commercial computing, as well. If you're looking for a possible future career in some area of computing, telecommunications is a good choice.

HDE Software Bank

Hudson DigitaI Electronics (Box 120, Allamuchy, N.J. 07820 (201) 362-6574) has just concluded negotiations which would put Progressive Computer Software Inc. (405 Carbin Rd., York, PA 17403) in charge of maintaining the HDE Users Library.

The plan is to offer utility and applications programs available at a nominal disk copying charge.

Contact HDE and/or Progressive for more details.

6502 High-Level Languages Available

Several high level languages arc available from the good folks at 6502 Program Exchange (2920 Moana, Reno, NV 89509). For AIM, KIM and SYM systems, they're offering FOCAL, TINY BASIC and XPLO (a compiler) as well as an editor and assembler.

These people have been around since the beginning and done much to help the 6502 attain its present popularity level.

Send $1 for their latest catalog.