Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert...

8
Homebrew Computer Club Robert Reiling, Editor □ Post Office Box 626, Mountain View, CA 94042 □ Joel Miller, Staff Writer Typesetting, graphics and editorial services donated by Laurel Publications, 17235 Laurel Rd., Los Gatos, CA 95030 (408) 353-3609 RANDOM DATA By Robert Reiling You will want to be at the next Club meeting Nov. 12, 1976. A representitive of Anderson Jacobson, Inc. will be on hand to discuss interfacing of Selectric ter minals. This should really be interesting for hard copy. And...at the same meeting Marty Spergel, M&R Enterprises will turn on the Astral 2000. You will see, according to Marty, a demonstration of Astral 2000 BASIC, the most powerful package ever implemented in a microcomputer. A unique feature of Astral 2000 BASIC is user selectable precision in the floating point package. You BASIC fans should look this sys tem over. Microcomputer user and hardware buffs will want to attend the S-100 System symposium, 1 to 4 p.m., Nov. 20, 1976 at Diablo Valley Jr. College. The S-100 is, of course, the Altair, IMSAI, etc. bus system. The bus, its viability for commercial applications, improve ments and products employing the bus arrangement will be discussed by prominent authorities including Harry Garland, vice Chairman Stanford Electrical Engi neering Department.; George Morrow, consultant ex perienced in S-100 design and Lee Felsenstein, moder ator of Homebrew Computer Club Meeting and an ex perienced hardware designer. Jim Warren, Editor of Dr. Dobbs Journal , will participate along with manufac turers of S-100 systems in this symposium. A fee of $5.00 will be charged for admission. Micro Computer News, a digest translated from Japanese, describes the activities of Japan’s first micro computer club. Nine symposiums are scheduled during October and November, each one covering a different manufacturer’s microcomputer. Both Japanese and American products are featured. Visitors to Japan may contact the club at this address: Japan Microcomputer Club The 1st Ohkura Building, 4F 2-1 Nihonbashi, Chuo-ku Tokyo,Japan The first hobbyist club in British Columbia, Canada is in the process of forming. At the first meeting Sept. 8, 1976 a total of 19 people attended. Future meetings will be held the first Wednesday of each month. Con tact Karl Brachhaus, 203-1625 W. 13th Ave., Vancou ver, Canada V6J 2G9, telephone (604) 738-9341 for information on the location. Did you know that Mini Micro Mart publishes a newsletter? They do, and you will probably find it in teresting. Write for a copy to Maury Goldberg, Mini Micro Mart, 1618 James Street, Syracuse, N.Y. 13203. Tell him you learned about the newsletter in the Homebrew Computer Club Newsletter. The U.S. Postal System managed to lose some of the items scheduled for the Bulletin Board this month. I sent several items to Joel at Laurel Publications and, this time, did not keep a copy. Recovery is therefore impossible for me. Please send in your items again for next month’s Newsletter. □ ^ THE COMPLETE AND UTTER IDIOT’S GUIDE TO COMPUTER PROGRAMMING oy ¡\ewett mw I The First Thing About Computers The first thing you probably would like to know about computers is, “How do you get information into and out of them?” The answer is, generally, eight bits at a time. There are many diffferent devices that have been either specifically designed to be used with a computer or they have been adapted to either talk to, or listen to a computer. There are two common ways to talk to a computer: serial and parallel. If you think about the information as only going in one direction for purposes of this discussion it sorts out as follows: Serial transfer requires a two wire circuit that is either connected or disconnected (make or break/mark or space/on or off). It requires that both the transmit ting and the receiving device can agree on how fast the transmission is taking place (i.e. the Baud rate). Baud rate is ten times the number of bytes being transferred per second, and is simply a timing convention so every thing is talking to everything else at the same rate. Serial transfer generally uses a big chip called a “UART” (Universal Asynchronous Receiver/ Transmit ter) which means that once synchronized with the data stream it can either receive or transmit. Tho UART takes the agreed upon Baud rate and divides it by some number (say 16) and sets its own counter. It looks at the incoming line and takes 16 looks at the line per bit, 1 HCCNewsletter/Vol. 2, Issue 10/October 29, 1976

Transcript of Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert...

Page 1: Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert Reiling, Editor Post Office Box 626, Mountain View, CA 94042 Joel Miller, ... M&R Enterprises

Homebrew Computer ClubRobert Reiling, Editor □ Post Office Box 626, Mountain View, CA 94042 □ Joel M iller, Staff WriterT y pesetting , graphics and editorial services d o n a ted by Laurel Publications, 17235 Laurel R d., Los G atos, CA 9 5 0 3 0 (408) 353-3609

RANDOM D A TABy Robert Reiling

You will want to be at the next Club meeting Nov. 12, 1976. A representitive of Anderson Jacobson, Inc. will be on hand to discuss interfacing of Selectric te r­minals. This should really be interesting for hard copy.

A n d ...a t the same meeting Marty Spergel, M&R Enterprises will turn on the Astral 2000. You will see, according to Marty, a dem onstration of Astral 2000 BASIC, the m ost powerful package ever implemented in a m icrocom puter. A unique feature of Astral 2000 BASIC is user selectable precision in the floating point package. You BASIC fans should look this sys­tem over.

M icrocomputer user and hardware buffs will want to attend the S-100 System symposium, 1 to 4 p.m., Nov. 20, 1976 at Diablo Valley Jr. College. The S-100 is, of course, the Altair, IMSAI, etc. bus system. The bus, its viability for commercial applications, improve­ments and products employing the bus arrangement will be discussed by prom inent authorities including Harry Garland, vice Chairman Stanford Electrical Engi­neering Departm ent.; George Morrow, consultant ex­perienced in S-100 design and Lee Felsenstein, m oder­ator of Homebrew Com puter Club Meeting and an ex­perienced hardware designer. Jim Warren, Editor of Dr. Dobbs Journal, will participate along with m anufac­turers of S-100 systems in this symposium. A fee of $5.00 will be charged for admission.

Micro Computer News, a digest translated from Japanese, describes the activities of Japan’s first m icro­com puter club. Nine symposiums are scheduled during October and November, each one covering a different m anufacturer’s m icrocom puter. Both Japanese and American products are featured. Visitors to Japan may contact the club at this address:

Japan M icrocomputer Club The 1st Ohkura Building, 4F

2-1 Nihonbashi, Chuo-ku T okyo ,Japan

The first hobbyist club in British Columbia, Canada is in the process of forming. At the first meeting Sept. 8, 1976 a to tal of 19 people attended. Future meetings will be held the first Wednesday of each m onth. Con­tac t Karl Brachhaus, 203-1625 W. 13th Ave., Vancou­

ver, Canada V6J 2G9, telephone (604) 738-9341 for inform ation on the location.

Did you know that Mini Micro Mart publishes a newsletter? They do, and you will probably find it in­teresting. Write for a copy to Maury Goldberg, Mini Micro Mart, 1618 James Street, Syracuse, N.Y. 13203. Tell him you learned about the newsletter in the Homebrew Com puter Club Newsletter.

The U.S. Postal System managed to lose some of the items scheduled for the Bulletin Board this m onth. I sent several items to Joel at Laurel Publications and, this tim e, did no t keep a copy. Recovery is therefore impossible for me. Please send in your items again for next m on th ’s Newsletter. □

^ THE COMPLETE AND UTTER ID IO T’S GUIDE

TO COMPUTER PROGRAMMINGo y ¡\ewett m w I

The First Thing A b o u t Computers

The first thing you probably would like to know about com puters is, “ How do you get inform ation into and ou t of them ?” The answer is, generally, eight bits at a time. There are many diffferent devices tha t have been either specifically designed to be used with a com puter or they have been adapted to either talk to, or listen to a com puter. There are two comm on ways to talk to a com puter: serial and parallel. If you think about the inform ation as only going in one direction for purposes of this discussion it sorts ou t as follows:

Serial transfer requires a two wire circuit tha t is either connected or disconnected (make or break/m ark or space/on or off). It requires tha t both the transm it­ting and the receiving device can agree on how fast the transmission is taking place (i.e. the Baud rate). Baud rate is ten times the num ber of bytes being transferred per second, and is simply a timing convention so every­thing is talking to everything else at the same rate.

Serial transfer generally uses a big chip called a “ UART” (Universal Asynchronous Receiver/ Transm it­ter) which means tha t once synchronized with the data stream it can either receive or transmit. Tho UART takes the agreed upon Baud rate and divides it by some num ber (say 16) and sets its own counter. It looks at the incoming line and takes 16 looks a t the line per bit,

1 HCCNewsletter/Vol. 2, Issue 10/October 29, 1976

Page 2: Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert Reiling, Editor Post Office Box 626, Mountain View, CA 94042 Joel Miller, ... M&R Enterprises

decides what it probably is and stores what it thinks it probably was. Since it has to know when the byte begins and ends, it requires some kind of signal tha t there is going to be a byte coming. The bit devoted to telling it to start is called the “ start b it” and it is always a disconnect/break/off so tha t when the line circuit breaks it begins to take its 16 samples of each of the incoming bits, making up its mind whether the bit was a zero or a one. Now counting the start bit we have:

/ S T A R T / D 0 / D 1 / D 2 / D 3 / D 4 / D 5 / D 6 / D 7 /

And only one more thing is required: a stop bit, which is always a connect/m ake/on circuit condition. Differ­en t devices require different lengths of tim e for the stop bit. Some take 1, some IV2 and some take 2. So the serial line is divided into the following stream:

/ S T A R T / D0 / D1 / D 2 / D 3 / D 4 / D 5 / D 6 / D 7 / S T O P /

Once the UART decides th a t the stop bit is there, it indicates tha t it has the whole byte by signalling “ input is ready.” This flag is variously called “ DAV” (data available), “ RDA”(receiver data available) or something like it. This signal indicates the status of the UART and is always available to any one who asks the UART what it is doing. Since a UART can be used as either input or ou tput, o ther status is also reported when requested, and we’ll get to tha t in a minute.

Now the incoming circuit has sent the data stream to the UART, and it has decided on what the eight bits were in the m anner just described. Now the eight bits received are sitting in a special register in the UART and the DAV/RDA flag is set. Now if and only if you ask for the UART’s status it will tell you tha t it is ready with the input. In code it looks like:

This is necessary because there may be a previous character tha t the UART is working on and may not be done with. Then:

LD A C H A R G E T T H E C H A R A C T E R INR E G I S T E R A

O U T D A T A P U T IT O U T T O T H E D EV I C E

The UART begins to transm it by breaking the line and counting to 16. Then it either makes or breaks the line, depending on whether the bit was zero or one. Then it counts to 16. Then it gets the next bit and so on until it has completed 16 counts for D7. Then it holds the line in a connect/m ake/m ark condition for 16 times the predeterm ined value of the stop bit.

Now as you can see, we have created a line condi­tion th a t is virtually identical to the incoming message.

Parallel Data Transmission

Since Samuel F. B. Morse and others who devel­oped the first data transmission devices were terribly short of wire and bytes hadn’t been invented yet, they never thought of sending eight bits at a time. Then, on Aug. 19, 1917, Octavius Parallel invented the line using eight wires. It was many years later tha t the technique found practical use with the addition of two more wires. Their names are:

1. DO Data Bit Zero2. D1 Data Bit One3. D2 Data Bit Two4. D3 Data Bit Three5. D4 Data Bit Four6. D5 Data Bit Five7. D6 Data Bit Six8. D7 Data Bit Seven9. TYG There You Go

10. IGI I G o t It

C H A R I N IN S T A T U S G E T U A R T S T A T U SANI D AV E R A S E A L L B U T D AV BITJ Z C H A R I N L O O P U N T I L IT C O M E S IN

The com puter wants to have the data presented to its data lines eight bits at a tim e, and the UART is capable of em ptying its special register ou t onto the data line eight bits a t a tim e so the next bunch of code looks like:

G E T C H R IN D A T A G E T C H A R A C T E R F R O M U A R TR E T R E T U R N W I T H C H A R A C T E R

IN R E G I S T E R A

Serial Transmission

Now that we know what the byte looks like coming in, it is easy to figure out what the UART does when it has to pu t a character ou t to some device. The com puter asks for the UART status and waits until the UART is ready to take the byte. The code is:

C H A R O U T I N S T A T U S G E T T H E U A R T S T A T U SANI T B E E R A S E A L L B U T T H E T R A N S ­

M I T T E R B U F F E R E M P T Y BIT J Z C H A R O U T L O O P U N T I L U A R T IS R E A D Y

Wires 9 and 10 are called “ handshake” wires and T Y G signals the receiving device tha t all 8 bits are now ready to read in parallel. When the receiving device has pulled the 8 bits in, it signals back IGI. So parallel transfer occurs as fast as the two devices can get the 8 bits and signal each other tha t the other has done its thing.

The code is almost the same, bu t it looks like:

P A R O U T O U T C H AN 1 P U T C O N T E N T S O F A ON P A R A L L E L O U T P U T P O R T

MVI A . T Y G G E T T H E F L A GO U T C H A N 2 P U T T Y G ON H A N D S H A K E LI NE

G O T I T IN C H A N 2 G E T T H E H A N D S H A K E LI NEANI IGI E R A S E A L L O T H E R BITSJ Z G O T I T L O O P U N T I L HE G E T S ITX R A A C L E A R T H E F L A GO U T C H A N 2

Please note th a t these examples of code are not exact examples of how to set up your own input and ou tput, bu t are instead only general outlines of the activities necessary. The m aker of your particular I/O device and the mainframe m aker have hopefully docu-

HCC Newsletter ¡Vol. 2, Issue 10/October 29, 1976 2

Page 3: Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert Reiling, Editor Post Office Box 626, Mountain View, CA 94042 Joel Miller, ... M&R Enterprises

m ented how to handle I/O. Som e producers have pub­lished booklets which explain how to handle their I/O board. Since I can’t possibly know what device or board you have and how you need the status bits set up, I can only give very general routines for handling the task. My hope is only to give enough background about what is going on to help you to better under­stand what the I/O routines do and then you can go off and design your own for your specific task. Very little, if any o f the code you see in this column will actually work as entered, and is only given as a general guide for writing your own. □

SO L ID S T A T E f M U SIC 8 K R A M B O A R D S.I New Product Release 1

................................ ,t......

Solid State Music announces the addition o f an 8K RAM board, MB6, to its line o f Altair, IMSAI plug com patible boards. MB6 uses low-power, 500ns, static RAMs and low-power Schottky support chips. As a re­sult, its power consum ption is approximately IV2A. Operation is made easy by DIP switch selection of address and wait cycles, making it unnecessary to solder and unsolder jumpers. The PC board has gold plated edge connector pads.

An unusual feature of this board is its memory pro­tect capabilities. Memory protect can be set in blocks of 256, 512, IK , 2K, 4K and 8K bytes. This allows the user greater flexibility and ease in programming. An additional RAM is used on the memory protect circuit.

Assembled, the board sells for $295. As a kit, it sells for $250. For further information, contact Solid State Music, 212A Walsh Ave., Santa Clara, CA 95050.

G E T TIN G ^

THE M O S T F RO M T I N Y B A SICBy Tom Pittman

TINY BASIC in the 6800 and 6502 was designed to be a small but powerful language for hobbyists. It allows the user to write and debug quite a variety o f programs in a language more “ natural” than hexideci- mal absolute, and programs written in TINY are reson- ably com pact. Because the language is small it is not as convenient for some applications as perhaps a larger BASIC might be, but the enterprising programmer will find that there is very little that cannot be done from TINY with only occasional recourse to machine language. This is, in fact, as it should be: the high level language provides the framework for the whole pro­gram, and the individual esoteric functions done in machine language fill in the gaps.

For the remainder o f this article we will assume one o f the standard TINY BASIC programs which fo l­low the memory allocations defined in Appendix D of the User Manual (1). Specifically, memory locations

Copyright 1976 by Tom Pittman. All rights reserved.

0020-0023 contain the boundries o f the user work space, and so on. If your system differs from this norm, you may have to make adjustments to Page 00 address locations referenced here, but everything else should be applicable. Because there are almost as many different starting addresses for the TINY BASIC code as there are versions, we will assume that the variable “ S ” contains the starting address. In other words, for the “ R ” version (Mikbug) S=256, the “ K” and “S ” ver­sions S=512, for the “T ” (KIM-2 4K) S=8192, etc.

The USR F unctionPerhaps the least understood feature o f TINY

BASIC is the machine language subroutine call facility. N ot only is it useful for calling your own machine lang­uage subroutines, but the tw o supplied routines let you get at nearly every hardware feature in your com puter from a TINY BASIC program, including input and out­put directly to your peripherals.

First, how do subroutines work? In machine lang­uage a subroutine is called with a JSR instruction. This pushes the return address onto the stack and jumps to the subroutine whose address in in the JSR instruction. When the subroutine has finished its operation it exe­cutes the RTS instruction, which retrieves that return address from the stack, returning control o f the com ­puter to the program that called it. Depending on what function the subroutine is to perform, data may be passed to the subroutine by the calling program in one or more o f the CPU registers, or results may be passed back from the subroutine to the main program in the same way. If the subroutine requires more data than will fit in the registers then memory is used, and the registers contain either addresses or more data. In some cases the subroutine has no need to pass data back and forth, so the contents o f the registers may be ignored.

If the main program and the subroutines are both written in TINY BASIC you simply use the GOSUB and RETURN commands to call and return from the subroutine. This is no problem. But suppose the main program is written in TINY and the subroutine is written in machine language? The GOSUB command in TINY is not implemented internally with a JSR in­struction, so it cannot be used. This is rather the pur­pose o f the USR function.

The USR function call may be written with up to three arguments. The first o f these is always the ad­dress o f the subroutine to be called. If you refer to USR (12345) it is the same as if you had written a machine language instruction JSR 12345; the com pu­ter saves its return address on the stack, and jumps to the subroutine at (decimal) address 12345. For those of you who worry about such things, TINY does not actually make up a JSR with the specified address in it, but rather simulates the JSR operation with a se­quence o f instructions designed to have the same effect; the interpreter is clean (“ pure cod e”), and does not m odify itself.

So now we can get to the subroutine from a TINY BASIC program. Getting back is easy. The subroutine still simply executes a RTS instruction, and TINY BASIC resumes from where it left off.

If you want to pass data to the subroutine in the

3 HCC Newsletter /Vol. 2, Issue 10/October 29, 1976

Page 4: Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert Reiling, Editor Post Office Box 626, Mountain View, CA 94042 Joel Miller, ... M&R Enterprises

CPU registers, TINY allows you to do tha t also. This is the purpose of the second and third arguments of the USR function call. If you write a second argum ent in the call, this is evaluated and placed in the index regis­te r s ) of the CPU; if you write a third argum ent it goes in to the accum ulator(s). If there are results from the subroutine’s operation, they may be returned in the accum ulator(s) and TINY will use tha t as the value of the function. Thus writing the TINY BASIC statem ent

LET P = USR (12345,0,13)

is approxim ately equivalent to writing the following in machine language:

LDX #0 LDAA #13 JSR 12345 STAA P

Now actually there are some discrepancies. The 6800 and the 6502 are 8-bit CPUs but TINY does everything in 16-bit numbers. So in the 6502 the sec­ond argum ent is actually split between the X and Y registers (the 6800 has a 16-bit index, so there is no problem ), and the third argum ent is split between the A and B registers in the 6800 (the 6502 has no register corresponding to B, so the m ost significant 8 bits are discarded); the returned value is expected to be 16 bits, so the m ost significant 8 bits are assumed to be in the B or Y register.

It is im portant to realize th a t the three arguments in the USR function are expressions. That is, any valid com bination of (decimal) numbers, variables or func­tion calls joined together by arithm etic operators can be used in any argument. If the variable 0=6800 or C— 6502 (depending on which CPU you have), the follow­ing is a perfectly valid statem ent in TINY BASIC:

13 P=P+0*USR (S+24,USR(S+20,46+C/6800),13)

When this line is executed, the inner USR call occurs first, jumping to the “ PEEK” subroutine ad­dress to look at the contents of either mem ory loca­tion 002E or 002F (depending on w hether C is less than 6800 or not); this byte is returned as its value, and is passed immediately as the second argument of the outer call, which stores a carriage return in the mem ory location addressed by th a t byte, We are not interested in any result data from the store operation, so the result is multiplied by 0 (giving zero) and added to some variable (in this case P), which leaves th a t vari­able unchanged.

What kinds of things can we use the USR function for? As we saw in the example above, we can use it with the two built-in subroutines to “ peek” or “ poke” at any mem ory location. In particular this gives us the ability to directly access the input and ou tpu t devices in the mem ory space.

Direct Input & OutputSuppose you have a PIA at mem ory address 8006-

8007 (the B side of the PIA used by Mikbug, bu t any PIA will do): We want to read a 4-bit BCD digiswitch in through the low four bits. For simplicity we will read in the switch setting, add one, and ou tpu t it to the display, then repeat. This program will do it:

100 REM SET UP PIA DATA DIRECTION 110 B=32768+6120 X*USR(S+24,B+1,0)+USR(S+24,B ,240)+USR(S+24,B+l,4)130 REM THE FIRST USR SETS THE CONTROL REGISTER135 REM TO POINT TO DATA DIRECTION REGISTER140 REM THE SECOND STORES HEX FO IN IT150 REM THE THIRD SETS THE CONTROL REGISTER155 REM TO POINT TO PERIPHERAL DATA160 REM X IS GARBAGE200 REM INPUT A NUMBER210 D=USR(S+20,B)220 REM REMOVE TRASH AND ADD ONE 230 D=D-D/16*16+1 240 REM OUTPUT IT 250 X=USR(S+24,B,D*16)260 GOTO 200

You can also use the USR function for direct access to the chacter input and ou tpu t routines, al­though for input you need to be careful tha t the char­acters do no t come faster that your TINY BASIC pro­gram can take them . The following program inputs characters, converts lower case letters to capitals, then outputs the results:

10 REM READ ONE CHARACTER 20 A=USR(S+6)30 REMOVE PARITY FOR TESTING40 A=A-A/128*12850 REM IF L.C., MAKE CAPS60 IF A»96 IF A«123 THEN A=A-3270 REM OUTPUT IT80 A=USR(S+9,A ,A)90 GO TO 10

Because of the possible tim ing lim itations of direct character input, it may be preferable to use the buf­fered line input controlled by the INPUT statem ent of TINY. Obviously for input of num bers and expressions there is no question, bu t for arbitrary tex t input it is also useful with a little help from the USR function. The only requirem ent is th a t the first non-blank char­acters be a num ber or (capital) letter. Then the com­mand,

300 INPUT X

where we do no t care about the value in X, will read in a line into the line buffer, affording the operator ( th a t’s you) the line editing facilities (backspace and cancel), and pu t what TINY thinks is the first num ber in the line into the variable X. Now, remembering tha t the line buffer is in 0030-0078 (approxim ately), we can use the USR function and the PEEK routine (S+20) to examine individual characters a t our leisure. To read the next line it is essential to convince the line scanner in TINY th a t it has reached the end of this line. Loca­tion 002E-002F normally contains the current pointer into the input line; if it points to a carriage return the

HCC Newsletter/Vol. 2, Issue 10/O ctober 29, 1976 4

Page 5: Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert Reiling, Editor Post Office Box 626, Mountain View, CA 94042 Joel Miller, ... M&R Enterprises

next INPUT statem ent will read a new line, so all that is needed is to store a carriage return (decimal 13) in the buffer memory location pointed to by this address (see line 13 above).

StringsAs we have seen, character input is no t such a diffi­

cult proposition with a little help from the USR func­tion. (Character ou tpu t was alw'ays easy in the PRINT statem ent), What about storing and manipulating strings of characters? For small strings, we can use the mem ory space in 0000-001F and 00C8-00FF, proces­sing them one character a t a tim e with the USR func­tion. Or, if we are careful, we can fill up the beginning of the TINY BASIC program with long REM state­m ents, and use them to hold character strings (this allows them to be initialized when the program is typed in). For example:

2 REMTHIS IS A 50-CHARACTER DATA STRING FOR USE IN TINY3 REMO 1 2 3 4 54 REM12 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 05 REM...IT TAKES 56 BYTES IN MEMORY: 2 FOR THE LINE #,6 REM 3 FOR THE "REM", AND ONE FOR THE TERMINAL CR.

If you insert one line in front to GOTO the first program line, then your program will RUN a little faster, and you do not need the letters REM at the be­ginning of each line (though you still need the line num ber and the carriage return). If you are careful, you can remove the carriage returns from all bu t the last tex t line, and the line numbers from all bu t the first tex t line (replace them with data characters), and it will look like a single line to the interpreter. Under no circumstances should you use a carriage return as a data character; if you do, none of the GOTOs, GO- SUBs or RETURNS in your program will work. Gee, you say, if it weren’t for that last caveat, I could use the same technique for storing arrays of numbers.

ArraysSo the, question arises, can the USR function help

get around the fact tha t TINY BASIC does no t have arrays? The answer is, of course, yes. Obviously the small am ount of space left in Page 00 and elsewhere in your system after TINY has made its mem ory grab is no t enough to do anything useful. The possibility that one o f the numbers might take on the value 13 means th a t you cannot use the program space. What else is there? Remember the memory bounds in 0020-0023. If you start TINY with the Warm Start (S+3), you can pu t any memory limits you wish in here, and TINY will stay out of the rest of mem ory. Now you have room for array data, subroutines or anything else. You can let A hold the starting address of an array, and N the num ber of elements, and a bubble sort would look like this:

700 REM SUBTRACT DOLLARS AND CENTS FROM BALANCE 7X0 C=C-Y720 IF C>=0 THEN GOTO 750730 C=C+100740 D=D-1750 D=D—X760 IF D»=0 RETURN770 IF C=0 RETURN780 D=D+1790 C=C-100800 RETURN

Of course this is no t the m ost efficient sort routine and it will be veerrry slow. But it is probably faster than writing one in machine language, even though the machine language version would execute faster.

Bigger NumbersSixteen bits is only good for integers 0-65535 or

(-32768)-(+32767). This is fine for games and control applications, bu t sometimes we would like to handle fractional numbers (like dollars and cents), or very large range numbers as in scientific notation. L e t’s face it: regular BASIC has spoiled us. Granted. But if you could balance your checkbook in TINY BASIC, your wife might complain less about the hundreds of dollars you spent on the com puter. One com m on way to handle dollars and cents is to treat it as an integer num ­ber of cents. That would be OK if you balance never went over $327.67, bu t tha t seems a little unreason­able. Instead, break it up into two numbers, one for the dollars, the other for cents. Now your balance can go up to $32,767.99, which is good enough for now (if your balance goes over tha t you probably don ’t balance your own checkbook anyway). We will keep the dollars part of the balance in D and the cents in C. The follow­ing routine could be used to prin t your balance:

900 REM PRINT DOLLARS * CENTS910 IF D+C<0 GOTO 960920 PRINT "BALANCE IS $";D;".";930 IF C«10 THEN PRINT 0;940 PRINT C 950 RETURN960 PRINT "BALANCE IS -$";-D;"."(970 IF -C<10 THEN PRINT 0;980 PRINT -C 990 RETURN

If the line numbers 930 is om itted, then the balance of $62.03 would prin t as “ 62 .3” .

Reading in the dollars and cents is easy if you re­quire th a t the operator type a comm a instead of a per­iod for a decimal point (the European tradition). If th a t is unacceptable, you can input the dollars part, then increm ent the input line buffer pointer (memory location 002E-002F) by one to skip over the period, then input the cents part. Be careful tha t tha t was not the carriage return you increm ented over. The USR function and the peek and poke subroutines will do all these things nicely.

Adding and subtracting two-part numbers is no t very difficult. Assume that the check am ount has been input to X (dollars) and Y (cents). This routine will subtract the check am ount from the balance:

500 LET 1=1 510 LET K=0520 IF USR(S+20,A+I)>=USR(S+20,A+I-1) GOTO 540 530 K=USR(S+20,A+I)+USR(S+24,A+I,USR(S+20,A+I-1))*0 535 K=USR(S+24,A+I-1,K)*0+1 540 1=1+1550 IF I<N GOTO 520 560 IF K«»0 GOTO 500 570 END

5 HCC Newsletter/Vol. 2, Issue 10/O ctober 29, 1976

Page 6: Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert Reiling, Editor Post Office Box 626, Mountain View, CA 94042 Joel Miller, ... M&R Enterprises

Adding is a little easier, because you cannot go negative (except for overflow), so it is only necessary to check for “ C is greater than 99” ; if it is, subtract 100 and add 1 to D. If your dollars and cents are in proper form (i.e. no cents values over 99), the sum will never exceed 198, so it is no t necessary to retest after adjustm ent.

Using this same technique you can of course handle numbers with as many digits as you like, p u t­ting up to four digits in each piece. A similar technique may be used to do floating point arithm etic. The ex­ponent part is held in one variable, say E, and the frac­tional part is held in one or more additional variables; in the following example, we will use a four-digit frac­tional part in M, adding to it a num ber in F and N:

1000 REM FLOATING POINT ADD FOR TINY BASIC1010 IF E—4»F THEN RETURN1020 IF N=0 RETURN1030 IF E+4<F THEN LET M=01040 IF M=0 THEN LET E=F1050 IF E=F GOTO 11301060 IF E»F GOTO 11001070 E=E+11080 M=M/101090 GOTO 10401100 F=F+11110 N=N/101120 GOTO 10201130 M=M+N1140 IF M=0 THEN E=01150 IF M=0 RETURN1160 IF M»9999 THEN GOTO 12301170 IF M>999 RETURN1180 IF M<—9999 THEN GOTO 12301190 IF M<—999 RETURN1200 M=M*101210 E=E-11220 GOTO 11701230 E-E+l1240 M=M/101250 RETURN

This subroutine is a decimal floating point routine; by changing the divisors and m ultipliers appropriately, it can be made into a binary, hexadecimal, or even terniary floating point machine. By using the multiple precision techniques described in the checkbook bal­ance example, greater precision can be obtained in the fractional part.

Computed GOTOOne of the more powerful features of TINY BASIC

is the com puted line address for GOTO and GOSUB statem ents. A recently published [2] set of games to run in TINY had several large blocks of the program devoted to sequences of IF statem ents of the form,

110 IF 1=1 GOTO 1000 120 IF 1=2 GOTO 2000 130 IF 1=3 GOTO 3000 140 IF 1=4 GOTO 4000 150 GOTO 100

125 IF I»0 IF 1*5 GOTO 1*1000

does exactly the same thing in less mem ory, and pro­bably faster.

A nother part of this program simulated a card game, in which the internal numbers 11-14 were recog­nized (using the same kind of sequence of IFs) in three different places, and for each different num ber the name of the corresponding face card was printed. The astonishing thm g was tha t the sequence of IFs, PRINTs and GOTOs was repeated three different places in the program. Now I ’m glad tha t Carl enjoys using TINY BASIC, and tha t he likes to type in large programs to fill his voluminous mem ory, bu t as I said, I ’M lazy and I would rather type in one set of subroutines:

10110 p r i n t "j a c k ”10115 RETURN 10120 PRINT "QUEEN"10125 RETURN 10130 PRINT "KING"10135 RETURN 10140 PRINT "ACE"10145 RETURN

then in each of the three places where this is to be printed, use the simple formula,

2510 GOSUB 10000+B*10

Along the same line, when memory gets tight, you may be able to save a few bytes with a similar tech­nique. Suppose your program has thirteen “ GO TO 1234” statem ents in it; if you have an unused variable (say, U) you can, in the direct execution m ode, assign it the value 1234 (i.e. the line num ber that all those GOTOs go to), then replace each “ GO TO 1234” with a “ GOTOU” , squeezing out the extra spaces (TINY BASIC ignores them anyway). This will save th irty or forty bytes, and it will probably run 'faster also.

Now there is nothing wrong with this form of program, bu t I ’m too lazy to type all th a t , and besides, I could no t get the whole program into my mem ory. Instead of lines 110-140 above, the single line

—T o b e c o n c lu d e d n e x t m o n th .H CCNewsletter/Vol. 2, Issue 10/October 29, 1976 6

Page 7: Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert Reiling, Editor Post Office Box 626, Mountain View, CA 94042 Joel Miller, ... M&R Enterprises

E R R A T A

Volume 2, Issue 9, page 1 (Random Data). The telephone num ber for the Com m unity Com puter Cen­ter, 1919 Menalto Ave., Menlo Park, CA 94025 is (415) 326-4444.

Volume 2, Issue 9, page 4 (The Complete & U tter Id io t’s Guide To Com puter Programming). The total for the “ Lefthanded Layers Down” colum n should be 110 .

IM P RE SSIO N S OF Q U A L I T Y

CC GRAPHICS2 5 0 S A N A N T O N I O RD.

M O U N T A I N VI EW C A L I F O R N I A

9 4 0 4 0

415 * 948-1776

Gordon French, club librarian, has lots of interes­ting material and is able to loan it to anyone with a definite need, bu t . . . please adhere to the following:

ALimit your telephone calls to the hours of 7PM to 9PM weekdays only. This is im portant. G ordon’s phone num ber is (415) 325-4209 in Menlo Park.

■&Be specific with your requests and Gordon can probably help you—he cannot random ly review the contents of the library for you.

☆No reproductions will be made of any materials, ft All materials loaned m ust be returned so they are

available for others to use in the fu tu re .□

HOW TO GET THE NEWSLETTER

Anyone interested in com puters as a hobby may receive the- Newsletter by sending a request to the Homebrew Computer Club Newsletter, P.O. Box 626, M ountain View, CA 94042. The New sletter is distribu­ted m onthly at the club meetings and is also mailed to individuals who are unable to attend the meetings.

If you have an input to the Newsletter, send it in and it will be published as quickly as possible. However, the editors cannot promise tha t everything sent will be published immediately. All manuscripts m ust be typed and carefully proofed. All listings and diagrams should be as clear and easy to read as possible.

The Newsletter is made possible by your donations. Please remember tha t we m ust pay for postage, labels and printing. Donations may be given to Ray Boaz at the club meetings or sent to the above address.□

Laurel Publications is seeking additional work and is willing to pay a commission or finder’s fee to anyone establishing a productive contact. We specialize in elec­tronics manuals, advertising and technical art. We have a computerized typesetting system and the capability for drawing fine schematics and illustrations. We are experienced in the production of all types of technical literature. If you have any input, please call Joel Miller, Project Coordinator, at (408) 353-3609.

DAZZLER SOFTWARE CONTEST. The deadline forthe TV Dazzler contest sponsored by People’s Com­puter Company, P.O. Box 310, Menlo Park, CA 94025 has been extended to December 31, 1976. Prizes for this contest are hardware certificates from Cromemco with the value for first prize $500, for second prize $250 and for third prize $35 (10 each). In addition, there will be 16 honorable m ention prizes of the book What To Do A fter You H it Return, PCC’s First Book o f Com puter Games. The object of this contest is to develop a program resulting in a new and interesting display using the Cromemco TV Dazzler. (The Dazzler is an interface tha t permits a hom e color TV set to be a graphic term inal for certain m icrocom puters.) Contact Cromemco or People’s Com puter Company for full details on this contest.

MANAGER WANTED. A person is needed to set upand organize a hobbyist com puter store in San Fran­cisco specializing in kits, repairs and used peripherals. Telephone Bob at (415) 282-8000 or 282-3550 or write to Bootstrap Com puter Store, 3979-24th Street, San Francisco, CA 94114. Also wanted: key to disc system and/or disc drive and controller.

GROUP BUY of VT-4000 Video Com puter Terminals.A group buy has been arranged for a completely assem­bled term inal and also for a bare bones kit for the do- it-youselfer. Features of this term inal are: 12” M otor­ola m onitor (completely assembled buy only), 48 lines by 64 character display, 4K of RAM dedicated built-in, com plete cursor control, direct cursor addressing, scroll up and down, five clearing controls, character en­hance, all 32 control functions decoded, standard RS- 232 or TTL serial I/O, and selectable Baud rate (110 to 9600).

Complete terminal price is $800 plus 6%% tax and 2% handling. This includes delivery within the Bay Area. Shipping outside Bay Area extra. This is a 20% discount.

Bare bones kit has the following: the five boards needed, power supply and cabinet for unit. You supply parts for boards and a m onitor or TV. All part are standard parts available through all standard parts outlets. Bare bones kit price is $216 plus 614% tax and 2% handling. This includes delivery within the Bay Area. Shipping outside the Bay Area is extra. This is a 10% discount.

Send checks or m oney orders to: Norman Walters, 3107 Laneview Drive, San Jose, CA 95132. Make checks payable to Video Terminal Technology.

To qualify for a group buy, we m ust order at least ten. If we do no t get enough to qualify by December, all checks will be returned. Please include phone num ­ber you may be reached at in the evenings. If more inform ation is desired, call Norm at (408) 262-7874 on the weekends, or write for a 3-page description.

7 HCCNewsletter/ Vol. 2, Issue 10¡October 29, 1976

Page 8: Homebrew Computer Club - Stanford Universitypx564mk4553/... · Homebrew Computer Club Robert Reiling, Editor Post Office Box 626, Mountain View, CA 94042 Joel Miller, ... M&R Enterprises

HOMEBREW COMPUTER CLUB MEETINGSWhere & When

CONTENTS PAGE

Random Data, Robert Reiling ................................. 1The Complete & Utter Idiot’s Guide ToComputer Programming, Newett A w l ................... 1Solid State Music 8K RAM Board,New Product A nno u n cem en t................................. 3Getting The Most From TINY BASIC,Tom Pittm an ............................................................... 3Bulletin Board............................................................. 7

The Homebrew Computer Club meets at 7 p.m. at the Stanford Linear Accelerator Center Auditor­ium. Dates scheduled for the remainder of this year are November 12 & 26 and December 10 & 22. Please note that some of these dates are a change from the regular Wednesday schedule. The date and the location are subject to change. How­ever, if a change does occur, every effort will be made to provide advance notice in the Newsletter.

A U D I T O R I U M

PREEWa V

United States 13c

HOMEBREW COMPUTER CLUB NEWSLETTER

P.O. Box 626 Mountain View, CA 94042

FIRST CLASS MAIL

L M. BAKERd p t o f b i o . s c i e n c eSTANFORD UNIVERSITY STANFORD, CA

9 4 3 0 5

H CCNewsletter/Vol. 2, Issue 10/O ctober 29, 1976 8