Programming Concepts

Author(s): Albert F. Rodriguez
Pub Details: Time Designs Magazine v3 n3 (Volume 3, Issue 3)
Date: March/April 1987
Pages: 22
Timex Sinclair 1000 computer
Timex Sinclair 1000 computer

The following article deals with programing on a Sinclair ZX81 (or TS1000). It is just a portion of a large document, with the remainder to be published in the next issue of TDM, along with a program listing. The listing is a game program, “ZX81 TIC-TAC-TOE“, which will serve as the chief example and will be discussed extensively. If readers would like to get a “head start”, a complete listing of the program, declarations and array content are available for $6.20 ppd.; or a cassette is a available (nonlistable) for those who don’t want to key in the program, for $12.00, from the author. Albert F. Rodriguez, 1605 Pennsylvania Ave. #204, Miame Beach, FL 33139. (Foreign buyers add $2.00 for the cassette, or $1.00 for the listing).

(con’t from last issue)

From this observation I deduced that it would be prudent to locate my subroutines, as often as it was practicable, below and as near to the place that they have to be called from in order to acheive an optimal MC/PS ratio. This technique can be best implemented, given a program that is relatively as multi-functional as is mine, by using what I call: “drivers”. (For this term, but not the meaning given to it below, I am grateful to Mrrs. Frank L. Friedman/Elliot B Koffman, Problem Solving and Structured Programming In Fortran, Addison-Wesley Publishing Co., Inc., 2nd Edition, 1981, Page 299.)

A driver is similar to a “main program” (to learn about the concept of a main program see the chapter on Subroutines in the User Manual).

A driver calls one or more subroutines (or another driver(s)) within an overall program in that it is actually a suproutine that may called by a main program (e.g., see the driver routine Game in my program, which is called from line aa9 and consist of lines 7001-7011).

There should be only one main program within an overall program, but there can be many drivers within an overall program. The unique value of a driver is that it allows a subroutine or another driver, far below in the overall program, to be nearer to the actual place from where it is being called within the overall program. And this, indeed contributes to a better MC/PS ratio.

The proceedural rules derived from structuring (as effeciently as possible) the main program (see lines 112-120), drivers and subroutines (see Declarations below for exact line numbers) within my overall program are, for convenience sake, referred to as “Rules of Top-Down Design,” and can be summarized as follows:

1. A main program is placed immediately after the program’s name and any commands/initializations, if any, that appear at the beginning of the instruction area.
2. A main program begins with either a subroutine or a driver call, and it ends with a GOTO statement.
3. A main program calls either drivers or subroutines; it best calls itself with a GOTO statement.
4. A driver or subroutine are located best when they are below and nearest to where they are being called.
5. A driver or subroutine are located, in an overall program, in the order that it is first called by a main program or another driver.
6. If a driver and main program bothcall the same driver or subroutine , then, this same driver or subroutine is located in the overall program in the order first called by the main program.
7. A driver calls either one or more drivers or subroutines.
8. A driver or subroutine should contain at least one RETURN statement.
9. A driver or subroutine best calls itself by using a GOTO statement.
10. A subroutine, to be considered as a subroutine, must not contain either a driver or another subroutine.
11. Both a driver and subroutine are best called by a GOSUB statement unless they each call itself.
12. Always use the smallest line number possible when writing each line of a program.

So far I have been elucidating some of the proceedural techniques used in writing and structing my program. This presentation, howerver, would be incomplete without an explanation of what each particular section (form top to bottom) of the overall program does and why it was written. It is toward this end that I dedicate the rest of this work.

To clearly know what is being discussed next, the reader should have nearby a copy of the program list and its declarations (see below). The actual data stored within certain arrays in the variable store is not necessary to understand what follows. (A complete listing of the program, declarations and array content are available for $6.20, ppd, to whomever may decide to key in this program themselves rather than purchasing it in cassette form for $12.00. Foreign buyers add $2.00 more for the cassette and a $1.00 more for the listing and materials.)

The programm, on tape, is not listable on the screen. This precaution was taken so that a user would not accidentally disrupt the program if he/she happened to gain access to the code area of the program. To avoid reloading the program a user, whenever he/she has access to this area, should key in GOTO 7 to restart the game (see Profile sheet for instructions about how to stop and restart this program). No-mony-back-guarantee are the terms applicable to whomever buys this program in cassette form or not.

More of this article next issue.