LONG ISLAND SINCLAIR ТТМЕХ GROUP INCORPORATING % NYTSE OF NEW YORK CITY Issue; January 990
X NEW YORK TIMEX SINCLAIR ENTHUSIASTS: NEXT MEETING Feb II
LIST MEMBERSHIP IS $15.00. LIBRARY TAPES ARE AVALIABLE, WRITE THE ADDRESS PRINTED BELOM.
NOTICE NOTICE “NOTICE $^ SPE.. UMUTILITY SPECTRUM UTILITY
= USER GROUPS USER GROUPS ЖЕ. ps
BUY SELL Е d lag | tse
LIST,
5 PERI LANE
VALLEY STREAM, NY 11581 —
а Don Lambert JAN/91 Т0: 3310 Clover Dr. S.W. Cedar Rapids, ТА 52404
FIRST CLASS MAIL
4 вот онл конным
rnan Yr Dn кетт
<ноы
TING СЕМТЕБ.
ion
fao
m
ul E
MEMBER
тан озат OMe Dn
Сағ MEDES
AND
FFERED
CHRIS
LIST exclusive bulletin
Loa SPECTRUM PROGRAMS FROM C Ds !! ہر ر ہے ХЦ
Yes, Code Masters of the ИК (wevwidshire (мї phin UK улі до thank you) announce the fit. cb фе the Spectum (wau b gol!) Jt has 30 f their ames 3M рэа ваб an ordina CD, which you lead jn your Spec. tum with an adinan CD ployer,
No, you 9o wot nee? 3 CD-ROM JiscDrive; ше the vend same CD player you play sudio Cds on. Complete kit consists of cable connect CD player to Specvum, tape или shart MC ртт db allow the superfast bps rete $ the CD, instruc- tons for ж 30 prgrams m the disc, nd the vein Disc itself
Other UK firms are considering do © [ош Code Macte? lead! Imagine, an adventure uth thousands of levels! А ww sim untk millions А eadi army! Racing ләте unt true crosscountyy courses! Complete price Ys onl 22 I Ад Mox read it in LISTA al (ТЕЛ J <8
MULTIFLICATION, GRADE SIX
This tutorial demonstrates the simplicity with which а 64K computer can be programmed to Provide а no-fritl means of de- уеісріпа an unlimited number of
math practice session of a Six- grader. Тһе program Listing is short and can readily be con- verted to the basic language of other computers.
One of the biggest drawbacks of most software packages Pro- vided bu the schools today for their students is that the pro- grams are too elaborately шгіі- ten. Thru these programs the inanimate computers are expect- ed to teach, but they cannot anticipate а child's needs, and are thus very inefficient as a teaching medium. Rs a conse- quence students can spend up to eighty percent of their time standing bu.... watching crude computer animations, slow deyel- oping and fancy Picture embel- Lishments, repetitious displays Of the credit and introductory screens unclear menus, confus- ingly abbreviated instructions, and the Like. Much of this rot ig created by the programmers and producers of the software,
With demonstrating their pro- агаттіпа ability than they аге the education of the child. The
relatively poor grades that stu- dents currently are scoring on standard tests, compared to the grades in the gears before com- puters entered the classrooms. is ргіпсіраііч due to this in- efficient method of teaching. But, Computers сап. be of help in providing a student with Practice exercises to follow up оп Classroom instruction, by a teacher. H-24 is a program Written for this purpose.
Routine H-34 does nothing more fancu than to develop tuo decimat numbers for НЫ
e ° 3 о з v v т ° ET т © т n n Е
а
s
2
computer
dicates whether it is correct or not.
There are tuo subroutines in this program suitable for use іп other programs, The опе іп Lines 1000 to 1240 generates decimal and integral numbers in the range of 1 to 900%. They are developed as "Strings" so that the individual digits can be manipulated. They are then converted to numbers for compu- tation and display.
The subroutine in 500 to 680 reviews all INPUT and rejects anything that cannot be а valid answer, In other words, it monitors input so that nothing Other than positive lor печа- tive) numbers of 2 or more dig- its get by.
LONG DIUISION, GRRDE SIX
Routine H-35 covers problems in tong division and is similar in construction to H-34. Th tuo routines could have been" Combined and supplied with a
Multiplication is usually taught several weeks be- ore long division. They are
f
not taught concurrently. Hence there if Little to be gained bu а combination.
It is very easy on the 152068 te convert one similar program into another, as editin is Sim— Ple оп this computer, Starting With the LISTina of H-34, I al- tered the following tines....
Б, 10. 20, 40, 80, 108, 5 120
Bu comparing them uou should be able to discern the particu- lar action taken. But line 120 mau need a further explanation. In H-34 ue compared the stu- dent's response "tru" with the computer's "ans", апа аі і ошеа them to differ bu no more than «ӘЗ in value, Іп division the difference is not a good crite- rion as all of the answers will be smali. Therefore we used a ratio in the H-35 routine so t to score correctly, the ference between the ішо yal- ivided bu the computer's
agrees to within 6 signi- t figures. This requires he Student carry his work 6 figures, but it also his work to this extent.
noe
5 has an added subroutine, 1508 to 1540, which gener—
the traditional division
t which is not on most com—
5, including the Timex.
Symbol, once generated.
e printed cut simply bù
ing for CHRS 146, or by the "R" in graphics. In this
ial the graphics Letter ñ
and the sumbol printed
асе, Опе of the many
ures of the Timex is itu to mix graphics and
пч time and anu where сееп, Host other
, Operating in basic, this.
cT ш Безе, пото се 352
D mmo т Onn w ес
You can use this subroutine in other programs and can add up to 19 additional special symbols. Моге than 20 can be added but an explanation of the method will have to wait for an Other dau. Тһе first two sub- routines can also be incorporat— ed into other programs. They тач need to be altered stightly to suit your application.
Warren Fricke 273 Canton Street Depew, NY 14043
H- 34
5 REM зж "I-16", 1-6-90, UF 18 REM xx MULTIPLICATION, GRRDE SIX
ге RANDOMIZE
зё CLS : LET F=0
40 PRINT "You are expected to be within «93 of the correct answer to be marked correc i."
50 FOR I-1 TO 10
во 59 SUB 1002: LET N1=VAL H$
70 GO SUB 1000: LET N2=VAL N$
8@ LET ans=NisNe
За PRINT "QUESTION Мо. "jI 100 PRINT " ";N1;" X ":N2; =
110 INPUT T$: GO SUB 500 115 LET try=VAL H$: PRINT try 120 IF RBS (ап= -1гч) ›.03 THEN С
132 FRINT " Correct. Press E NTER."
140 LET F=F+1: GO TO 160 "
150 PRINT " Wrong. Answer is
“Sans: PRINT " Press ENTER.”
160 INPUT z$: NEXT I
170 PRINT “"Your score was “;
" out of 10. Press Birek i ° play again.
188 INPUT 28: со TO зо
306 REM ++ INPUT MONITOR $10 LET Н%-Т%
$15 IF LEN Em THEN GO ТО ә
520 IF Тф(1)="+"° ОР T$(1) =" Ë š НЕН LET T$=T$(2 ТО) 530 GO TO 600 T=1 TO 120: NEXT T: GO
LEN T$ (T$(T) e"Q" OR T$1T)»"9") тэст! (o"," THEN GO TO 110
i TO LEN T$ 650 IF T$(T)s"," THEN LET Бабкі 660 IF T THEN 60 TO 110
1000 REM ss HUMBER GENERATOR 1010 LET R*=STR$ (1+900 +RND+RND)} Зах
LET w=2+INT (6¢RND) 1959 LET N$=A$(1 TO un 1040 RETURN
You are expected t .03 of the correc be marked corr
QUESTION No. 1 197.9 X 11 = 2176.9 Correct. Press ENTER.
QUESTION No. 2 З.З X 354 = 1168.2 Correct. Press ENTER.
QUESTION Ho. 3 144 X 114 - 16514 Urong. Answer is 16416 Press ENTER.
9 be within t answer to
H- 35
Б REM ss "I-17", 1-6-90, ЧР 10 REH ++ LONG DIVISION, GRADE SIX
20 RANDOMIZE : 0 SUB 1509
30 CLS : LET F
40 PRINT "You are expected to be correct іп the first 6 signi ficant fig- ures to be marked co erect.”
SQ FOR 1-1 TO 10 60 cO SUB 1000: LET H1-URL H$ та со SUB 1000: LET N2-URL H$ 80 LET ans=Ni/N2 за PRINT '"OUESTION „100 PRINT " ";Hi1;" ina} з ; 110 INPUT T$: GO SUB 500 115 LET try=VAL H$: PRINT beg 120 IF RBS (апе -1гу) хапѕ›1Е-$ Т
НЕН GO TD 150
"TED PRINT " Correct. Press E 140 LET F-F*1: GO TO 160 150 PRINT " Urong. Answer is "ians: PRINT " Press ENTER."
150 INPUT z$: NEXT I
170 PRINT '"Your score was “;Ғ; T Eh of m Press ENTER t o play agai
159 INPUT LEM со TO 30
208 REM ++ INPUT MONITOR
510 LET Н4-Т%
515 IF LEM Т%<2 THEN GO то 560 528 IF T$(1)="+" OR T$(1)="-" T НЕМ LET T$-T$(2 TO )
530 бо TO eee Тз1 TO 120: МЕХТ T: 60
500 FOR T-1 TO LEH T$
610 IF (Те(т) "е" OR 761702599 AND T$(T) <>“, ” THEM GO TO 118 620 NEXT T
TO LEN T$
650 IF T$tT)="." THEN LET 5=5+1 660 IF 521 THEN GO TO 11
670 NEXT T
680 RETURN
1000 REM ++ NUNGER GENERATOR 10га Ет 8%-5Т78% (1+900+RNDRND)
1020 LET w-24INT (S#RND) 1030 LET N$=A$(1 TO ш) 1848 RETURH
1500 REM ++ SERE + SYM 1510 FOR T-US TO USR 1520 RERD w: Boke Tow: МЕХ 1530 DATA 0,24,0,255,0,24,
1540 RETURN
You аге expected to be cor in the first 6 significant Ures to be marked correct,
QUESTION NO. 1 33 + 77,8318 = 9.423991 Correct. Press ENTER.
QUESTION No. 2 116.6 + 12.9 = 9.03872 Correct. Press ENTER.
QUESTION No. 2 209 + 3.78436 = 55.182 Urong. Answer is 55.081753 Press ENTER.
re f
Table 1. Offset No of Bytes.
Description Number of sets of data. Start address of data.
Angle about X axis
Angle about Y axis
Angle about Z axis
Address of free memory after 30 data
6“МИМВ + DRAWS
Poke this with 0 the first time you use the 3D image.
3D ROTATOR
IN JULY OF LAST YEAR, 1 wrote а program for Your Computer calied ЗЮ Rotator. This program allowed the Basic programmer to manipulate simply defined 3D figures at machine-code speeds. A typical time was 0.5 seconds for a cube. Though this was extremely fast relative to Basic it was not fast enough for practical dynamic games. With this in mind T have speeded up the 3D routine by as much as eight times and made it more versatile. The speeds achieved now are as fast as those seen in commercial games such as 3D Tank Duel, with the advantage that they can be called from Basic.
Data is stored as blocks of code at any memory location that you specify. The data should be followed by а blank area which = 12 * (number of sets of data). Therefore the total memory required for any one image = 19 * (number of sets of data). The data itself is made up of three 2's complement numbers and one 1 byte number. A 2's complement number is a 2 byte number where the negative form is 65536- number, e.g, -5 =65536-5 апа +5=5: А 2 byte number is Poked into memory as described on page 173 of the Spectrum manual.
The numbers stored are as follows: x co- ordinate, y co-ordinate, z co-ordinate and the 1 byte number 0 to indicate a plot at x, у, z or І to draw з line from the last point plotted to x, у, 2. include a Rasic program — program A — which will handle conversion of data into а suitable form for the machine-code program. The Basic program will also store the essential parameters such as the poiater to the data, number of sets of data etc., for that figure,
Producing the data for a simple 3D figure is relatively easy. 1 refer you for further informa- tion to my article 3D Rotator of July 1983 and lan Angell's article ВВС 3D Graphics in the February 1984 edition of Your Computer.
Тһе 3D program allows the parameters for up to 16 3D images. These parameters are stored in fixed areas from 65032 onwards and in blocks of 20 bytes. Thus the start of the para- meter area for figure 4 = 4°20 + 65032 — see table 1.
Each 3D image stored in memory should have a separate set of parameters though they
Mark Jones with a program which makes his 3D rotator published in the July 1983 issue up to eight times faster.
45
might share a common set of data. Draws need not point to a memory area after your 3D data but Í find 1 keep track of my memory state better by doing so. For example, fig.0 and fig.1 might both be pyramids and so use the same data. Draws for fig. із as normal, after the data, but draws for fig.l points at another section of free memory and its ADDR points to the fig.0 data.
If it has all seemed rather complicated so far, do not worry — it is really quite easy to use these 3D routines. Here is an example:
To set up fig.0 as a cube first of all work out your data and then store it in data statements in Basic program А. For а cube there are 16 sets of data so adjust line 15 accordingly, The data is going to be stored at 40000 onwards so first of all ensure this area is free from the Basic system with a
CLEAR 39999
and then adjust line 10 accordingly. Finally, this is going to be figure 0 so adjust line 5. Now run program А.
Once the program is complete it will give you a printout of the next free memory available for data, 40316, and also the position of the parameters area, 65032. H you now wished to have another cube that could move indepen- dently of fig.0 then simply make line 10 read
LET ADDA = 40316
Line 5 should read
-B-
and run the program й
This із, of course, ап example and actual addresses will depend on the number of sets of data you use. Program А as printed will set up fig.0 as a cube аз in the above example.
Now to actually produce a 3D image on the screen there are 2 number of steps:
E Select the current tigurs by Poking gre
with the required figure number 0-1 М RAND USA 64234 actually converts your
data to a list of plots and draws stored in the figure's--esseciated free area о! memory, pointed to by Draws. ® RAND USR 64692 produces the 30 image оп the screen from the list of plots and draws:
МЕ РАНО USR 64679 deletes the last image drawn by the above routine.
Therefore using various sequences of these routines you can produce 3D images бот within your Basic programs. As an added feature Í have included a machine-code demon- stration program which will put the current figure indicated by
PEEK 64976 through its paces. The number of steps, and so speed of this demonstration, can be altered by Poking 63501 with a number between І and 150.
The routine is called with RAND USR 63500
Finally, to alter a given figures position on the screen, distance from you or angle simple alter the 27% complement numbers PX, PY, PZ, Phi, Theta and Psi in the parameters for that figure.
To run a demonstration of the routines from Basic load with program A and then бою 5000. This sets up three cubes, shows off the machine-code demonstration and then leaves the three cubes to float around in space spinning.
If you remember the 3D Rotator routine in my last article you may be interested (o compare it with these new routines, The routine to handle the 3D conversions is written more efficiently, uses 2 byte x, ,y,z co-ordinates and does not draw the figure straight away. This allows a number of figures to be produced
“in memory but not drawn until needed. This routine also handles calculations for 7 dines partially off screen ensuring that the tine eventually produced for the draw routine does not go off screen,
The routines to draw and delete figures use а draw routine specially written for this program which is extremely fast. The routine does not draw a line by plotting but by manipulating screen addresses and rotating a mask.
To use the plot! routine for yourself use the following method: зе! up an unused figure e.g., fig 15 by
Poking both DrawS апа DrawP with the
same value, the address of an unused area Í
of memory. Next Poke STFLG with 255. Wi Store your piots and draws at this address. in the following form:
P,x,y where P = 0 to plot at ху Р = 1 to draw from the last
рана pidlied to жу Р = 255 to end the data
x is a normal x co-ordinate
Y has the range 0-191 where O is the
bottom line of the edit area. e.g. To draw a frame around the screen the. data would be: 0,0,0, 1,2550, 1,255,191, 1,0,191, 1,0,0, 255.
Type program A into your computer and then Save й. Never try юю run this program without the 3D machinecode routines in memory. For the 3D routines type in program В and then Save it. Now try running it. If an error is reported correct your error, resave the program and (гу again. Once the program has run successfully save the code as instrucied іп line 9999.
You now no longer need program B. You now have a machine-code program saved as code and a Basic program. Do not try and run the machine code without a valid set of рага-
meters and data in memory. To see the various. demonstrations load up with the Basic and then. the code and then Goto 5000. Or to store an. image type Run.
Program А.
1 REM "Data Stora3e Program" 2 CLS + CLEAR 39599
4 КЕП 5 LET fi9=0: REM “Figure 9-15
Э РЕМ
18 LET addr=40900: REM "dita storage address”
14 КЕН
15 LET нееі6- sets of data"
16 GO SUB 17: STOP
17 LET store=65832+f i 9K20: РОК E store,No: LET addri*store*i: L ЕТ с=здаг: GO sud 506
18 LET addri=addr
29 FOR f=1 то No
39 READ x,v,Z,P
48 LET c=x' GO SUB 229
43 LET cm. GO SUB Seg
EI Seo-
ss POKE addr i.e
68 LET addr i=addrt+1
75 NEXT f
88 LET sParesi2*(Nos15
82 LET free=sParetaddel
85 LET ceaddrl' LET addrisstor «+15: GO SUB 5ө2: LET cesPare/2* <' GO SUB 509! FOKE ачагі,
95 PRINT "Data stored for fisu
REM “Humber of
re "fis
100 PRINT "data at “saddr
105 PRINT "next free memory at "ifree
119 PRINT "Parameters at "stor 7 to "ustore+13
128 RETURN
598 IF с<8 THEN LET с«65536%с 505 POKE addri+1, INT (с/256) 518 POKE addri, INT (2564027 256- INT Сс/256 22);
515 LET ааа саата
520 RETURI
999 REM cube data
1009 DATA 29, -га, ге, 8, га, -ге, -га (1, 720, -20, -20,1, 720, -29. 20, 1,20 ^-20,28,1.20.20.20,1.20,20,-20,1 2720.28, -г8, 1,-га, гд, 20, 1, 20, 20, 28, 1,20, -20,-20, а, га, 20,-20,1,-2 9, -го, -20,0, -20. 20,-20,1,-20,-20 :20,0,-20, 20, 20.1
4537 REM
4996 БЕН Demonstration
E RESTORE ' LET fig=0: SET a drz40900: LET Ноз16: GO Ste
5910 RESTORE : LET #19=1: tet Tia drafree: GO SUB 17: RESTORE + LE 1 fis-2: LET addrefree: GO SUB 1
5011 POKE 63501,10: CLS : FOKE 64376,1: RANDOMIZE USR 63586: ҒО КЕ 64976.9: RANDOMIZE USR 63500: FOKE 64576,2: RANDOMIZE USR 635
99
5812 FOR f-$ ТО 95 STEP 10: РОК Е 63501,4: RANDOMIZE USR 63500 MEXT £
5915 FOR f=65891 TO 65086: PUKE f.@' NEXT f
2016 FORE 63501,10
5019 FOKE 65075,49: POKE 65979,2 Өй: FÜKE 65836,0: POKE 6556.2: POKE 65038.0: POKE 65037,9: FOLE 65058,0: PIKE 65057.0: FOKE ESO 33, 158: gles oo 9: POKE 65059
5825 FOR pe]
HEAT h
5949 НЕХТ €
Fen RANDOMIZE USF ©3508 501
6000 POKE 649/6,h: RANUONIZE USR 5434 РАНООИ. USK ©4679: РАН FETEH
50 (o
ўз! 32
Program B.
üddeselzer 1+{й@йе
mezdrO4aeBlüfiBpde erfdilulgl,
SafSrlsubblz
9751#8935036с35ӣ E
fdodSclcb4üz 21 DATA 1192 зӣ DATA "201: гадвае 7
18 DATA "Зебабегазайг зера й #21ғед0с5еб Sdde te3cdd?fa
20 DATA "4berfdeS3ebrs6 doeld9ügelcle э43004е44316ғҒ477 30B4ecd44lefr4fbBinao
: 841434951691 699
агйдатасв20вЕз2ба?сававетазсыд12 S6ecb7y3Z0060f 3D072c190407208 12d4
SdScSedb
cbld22d4f
а А cdarfccdb азрат
Scdeaf 91
515513419
УИВЬЕГТРЗВЕ Sre] ested, ard?edS52205fe22e5 31 DATA 31468480 "2anlfezuz9ecdB5bd4F 36
4 21t LP Je 2lfitdd 10168
(Program В continued оп пех! раде)
ledS3edi dd s2aed di
efeftdr сс 141 САТА эй DATA ааа
18715
DATA
та LEN $ ЗТЕР 2
ODE збаў: LET b=LOp
THEH LET THEH LET
THEH F (10: STOP
EP ‚2.8: PRINT "i ЕСТЕУ": PRINT " A, 1473"
E Вы x
Printer Ploys
From
NANANANSASANANSS М МА А
So Uncle Clive hes killed оН the ZX Printer — one of the most useful and impressive little toys he ever gave us. But then he gave us Interface І and who can resist plugging іп a real live full- width printer to its little 85232 port?
But now that we all have a real printer, can we make best use of it? The first essential is some software to make the thing work properly — some- thing like Tasword 2, perhaps, which will format our print-outs with neatly justified right-hand margins. But that's just a start. Do your documents involve typ- ing the same name or formula over and over again? Well, if your software allows you to seek and replace a word, you can save yourself a great deal of finger-tapping. For example, 1 spend most of my hours at my Spectrum pretending it’s a word-processor in order to write plays. Now the one thing you can be sure of in writing a play is that you are going to have а fot of repetitive typing: every time a character speaks you need his name in full. A page of quick-fire dialogue may use a character's name 20 ог 30 times, especially when you consider that you not only begin every speech with the speaker's name, you also
usin
have the characters constantly addressing each other by name: You've seen the kind of thing:
MURGATROYD: Daphne! DAPHNE: Murgatroyd! It's you! MURGATROYD: As you say Daphne, it is 1.
DAPHNE: At last, Murgatroyd.
Four Murgatroyds and four Daphnes in just four fines of deathless dialogue. Most writers cheat, when writing their draft versions of the text, and use abbreviations for the names. Ever noticed how characters’ names always begin with different letters of the alphabet? That way we can just use the initial letter for identifica tion in the early scripts. (We're way ahead of one William Shakespeare here: Macbeth. Malcolm, Macduff — all in one play. He must have been fonder of quill-scratching than | am of keyboard-tapping.)
Once the rough draft has been cleaned up and polished. you just have to use the find- and-replace function to find ай your character-identification in- itials and replace them with the names іп full, So, the draft looks.
Charles A Barron gets to grips with g his printer
ZZZZZZZZZ ДИ ZZZ/ZZ/ZZ
like this:
M: D!
D: M! It's you!
M: As you say, D. It isl. D: At last, M.
And the filled out version looks like the quotation above. A sav- ing of 56 key-taps in four lines!
Once the play, or whatever, is complete, you'll want to give it a finished look. Page numbers. Maybe even page headers? (That is where the title of the piece appears at the top of every page.) An unconscionable amount of typing for just a little fancy decoration. And none of the software packages for the Spectrum that I've come across allows automatic page number- ing. That is the only really desirable function of those £5000 word processors that is missing on Uncle Clive's little
wonder. (Though by the time you've added Interface and the printer and a couple of microdrive cartridges to store your prose on, it is beginning to Cost about as much as the £5000 job!)
Here is a little program that will give you automatic page numbering and automatic page headers at the cost of typing it not only once. It will only work if your printer/interface/software combination allows you to pro- gram in a form feed instruction: that moves the paper through the printer one full fanfold. You should also set them to give you automatic skip over the perfora- tions, if that is possible.
Run off your document, keeping the perforations intact; tear off the last sheet and then feed in page one again, setting the top of the page carefully to where you would want the page header to come. Set the pro- gram running and the printer will tun your printed play or White Paper through again, pausing only once every page to add the titles and page numbers.
In the program listing, which should work for the common types of dot matrix printers, you will have to set the baud rate to suit your own set-up, and put enough spaces into your title in line 20 to bring it to the desired position on the page. If your printer can be programmed with TAB settings, then you can use these instead of the row of spaces. The program begins by asking you how many pages your opus runs to. If you are too tired after composing the thing to face counting them, you can always lie to your computer and pretend to have written 2000 pages — it will give up the pro- gram of its own accord when it runs out of paper. (But it may never trust you to tell the truth ада.
СНАЗ 12 is simply the Form Feed control code; your machine may need a different code, though that is unlikely. Refer. as they say, to the manual and adjust the program accor- dingly. ‘As The Bat At Noon’ is what we call in the trade a variable; please don't name all your documents after my play.
PROGRAM LISTING
“Мо of pages?
FORMAT “
FORa-
LPRINT ^^ LPRINT CHR$ 12 NEXT a
CLOSE #3
4800: OPEN Я3;
TOn
As The Bat At Noon “a
se
ces
Coventry's Carol Brooksbank wrote this utility to find bugs in her programs and she thought she'd share it with us.
з. MEE.
| don't know about you, but I don't think that ! have ever writ- ten a machine code program which ran perfectly first time. You know the feeling. Eageriy, you type in your latest master- piece, enter RANDOMIZE USR something-or-other and CRASH! There you sit, with a frozen keyboard and only а blank screen or a pretty psychedelic pattern to look at. You have no idea whether there is a fault in the logic of your pro- gram, whether you have made a typing mistake or miscounted a displacement, and you don't know where to start looking for the trouble, because you do not know how far into the program the crash occurred. Well, help is at hand.
This machine code program will give vou a hex trace at the right of the screen, as your pro- gram runs. It is only a partial trace, as it does not show the address of every instructions as it is executed — if it did, the display would change so fast that you would never be able to read it — but every 1/50 second it gives you the address that the program has reached. This is enough to let you keep an eye on the progress of your program, and to see where things start to go wrong. For instance, й the crash is caused by the program getting into an endless loop, you will see the same sequence of bytes repeated over and over again after the crash happens. И you left out a return instruction, 50 that the prograrn starts runn- ing through the empty bytes above your program, that too will be obvious. But remember that the trouble is not always at the point where the crash hap pens. À wrong displacement in- struction may be some way away from the point to which it directs the program. You will still have to think for yourself to decide why the program runs as it does.
Why is the display іп hex? Two reasons, The first is purely
personal. 1 wrote the program for myself in the first place, and! always work in hex, so a decimal display would not be very helpful. (One of these days ! shall find myself asking the greengrocer for “QA pounds of potatoes, please’’.) The second reasonis rather more important. Thereis a directrelationship bet- ween the binary form of a number — the bit pattern held in the registers — and the hex form. which makes the conver- sion between the two very straightforward. Converting an address to decima! would in volve multiplying the high byte by 256, adding the low byte, then isolating the 5 digits one by one for printing, ай of which would make the routine much more complicated. Since the trace routine is in the form of an interrupt subroutine, it is desirable that it should be as short and simple as possible.
The routine makes use of the fact that, whenever the Spec- trum performs a subroutine, the return address is pushed onto the stack. On an interrupt subroutine, the return address is the program counter, the point reached in the main program. If we can retrieve this address from the stack and display it, we have a trace. Obviously, there are alot of instructions perform- ed in between the interrupts which are not displayed, but this is usually enough to let you see where a program takes a wrong turning. So. if your machine code program crashes, load in this routine with your own pro- gram — l am assuming that you always take the precaution of taping your programs before running them, just in case enter RANDOMIZE USR 65271 (48K), 32503 (16K), run your program again, and all should be revealed.
Details
The program is explained by the notes in the listing, but there are
one or two details which need more explanation. The interrupt subroutine starts by saving the present value of HL in the two spare bytes in the system variables area at 5CBO. This is necessary because the existing values of registers must always be saved at the start of an inter- rupt subroutine, and if we push it onto the stack, it will cover up the address we are trying 10 retrieve. The address is then POPped from the stack in HL, PUSHed back again so that it is in its correct place when the return is made from the sub- routine, and the other register values can then be saved on the stack. The other spare byte among the system variables, 5С81.4$ used as аъ interrupt counter. If this has reached 22d, the printing position is set to the top of the screen and the counter reset to O. Otherwise, the routine jumps forward to print the address.
The print subroutine starts with the instruction AND OF, which has the effext of resetting bits 4-7 of the A register, leaving bits O-3 unchanged, isolating the number we wish to print. PRINT must Бе called, therefore, with the number to be printed in bits O-3 of A. И the number tobe printedis the “left папа” digit of the two in the A register, the in- struction RRA is performed 4 times, to move it to the "'right- hand” position, but the print subroutine is called directly when the “right-hand” digit it to be printed. When PRINT is сай- ed, the DE register holds the first byte of the screen position for the digit, and at the end of the PRINT subroutine, DE is restored to that position.
Since there are only 16 digits which we shail need to print. 0-9 and A F, a table is set up, star- ting at FED? (7ED7 16K), which holds the start addresses of the bit patterns of those digits in the ROM character table. Doubling the value of the number to print and adding it to the address of
Q-
our table, points to the correct place in the table to retrieve the ROM address for that character. The digit can then be printed. After the 4 digits have been printed, the program variable SCRP at FF 13 (7F13! is pointed to the next screen row down, and the program exits via the normal interrupt subroutine. The listing is for the 48K machine. 16K folk should change the initial ""F'' in the ad. dresses to “7”, each CALL PRINT instruction should read CDB97E, and the bytes at 7EBD, which point to HL to the start of the table should be 21077E. At START, the high byte of the interrupt vector ad. dress should be 28, giving the bytes 3E28. The interrupt vec- tor address is not required at 7EFF, sothe four bytesbetween 7EFO and 7FO1 may be chang- ed to NOP if you wish, though if they are left as they are the pro- gram will simply ignore them.
Saving To SAVE the routine on tape: SAVE "m/c trace" CODE
65116, 184 (48K)
SAVE “т/с trace" CODE 32348, 184 (16K)
To START the trace:
RANDOMIZE USR 65271 (48K) RANDOMIZE USR 32503 (16K)
To STOP the trace:
RANDOMIZE USR 65292 (ABK)
RANDOMIZE USR 32524 (16K)
Finally, remember that the trace will not work if the interrupts are disabled. You must change your DI and El instructions to NOP while using the trace, and restore them when you have corrected your problems.
MACHINE CODE TRACE PROGRAM LISTING
ADD. M/CODE LABEL ASSEMBLY NOTES 2280 INT S/R LD(5CB0),HL Save present value oí HL FESE gree POP HL ' Fetch program counter FESO PUSH HL Save it again 437 PUSH АҒ бауе FES? PUSH BC all FEO? PUSH DE registers FEb4 LD A, (5081) Fetch progres counter FET Inc А update апі — Fess LO(SCB1) A store it again РЕБЕ СР 15 Has counter reached 2297 FESD JRNZ CONT Jump forward if not FEOF LD DE,401C Set variable to — — ҒЕ?2 LD(SCÉP) DE first screen position FE76 АҒ XOR A Set counter FE77 52815С LO(SC81) Añ to 0 ЕЕ РЕЈА EDSBISFF CONT ір DE, (SÈRP) Fetch current screen position FE7E 7С LD A,H Fetch first two digits FE7F 1F RRA First digit FEBO 1F RRA to bits РЕВ iF RRA 0-3 FEE? 1F RRA of & register FEBS CDBSFE CALL PRINT Print first digit к FERS 12 INC DE Point to next screen position FE87 7C LD А,Н fetch second digit FE88 CDB9FE CALL PRINT Print second digit РЕЗЕ 12 INC DE Next screen position FEEC 70 LD A,L Fetch last two digits РЕВО IF RRA Third digit FERE IF RRA to bits FEBF 1F RRA 1-2 РЕЗО iF RRA of A register FE91 CDESFE CALL PRINT Frint third digit FES4-15 Es Hic DE Next screen position FE95 70 іх а, Fetch last digit FES CDB9FE CALL PRINT Print last digit ҒЕ99 ZALIFF LD HL, (СКР) Fetch current screen position FE9C СРІС RR Point HL FESE CRIC RR H to next FERO CRIC RR H screen row FEA? 012000 LD BC,0020 down FEAS EDA4A ADD HL,BC FEA? СВІ4 RL Н FEA? CB14 RL H FEAB СВ14 RL H FEAD 2213FF LDISCRP) „НЫ Save new screen position FEBO DI POP DE Restore FEBI СІ FOP BC all FER2 F1 РОР AF registers FEBS 2АВ LD HL,(SCBO) Restore HL Қ РЕВЬ C33 20038 Exit via normal interrupt s/r FEB? E60 PRINT AND OF Isolate number to print FEBB 87 ADD A,A Double it FEEC ES PUSH HL Save program counter LD HL,FED7 Start of table to HL LD 8,40 Displacement to , ADD HL,BC Add to start of table LD B, (HL) Fetch ROM INC HL character table LD С, (HL) address for digit PUSH BC and transfer to POP HL HL LD B,08 Counter oí bytes to print RPT LD A, (HL) Fetch byte to print LD (DE) ,A Print it INC HL Point to next character byte INC D Point to next screen byte DINZ ЕРТ june back unless 8 bytes printed LD A.D Restore DE SUB $8 to screen position
TABLE
START
PASS
STOP
SCRP
or оо з
вос mmmmmm
= mi OU nmmmmmmmmmmmmmma
рол OOL QU од CO QD CD CO CD QU QU 50 CO 00 to zx? ООО
DE
лот
CD I7 (7 420 e 7 I7 C7 X OUT cor oou; аны
гіпс жж єз єз кэ а сп эсэ га ПУГА тїгї ГА
ma m
PERE ppp ppp pp ppp ppb
for digit 1 Fetch program counter А
Exit subroutine
Store first
screen position
By-pass
interrupt vector address Set interrupt counter
to 0
High byte of interrupt vector address to I register Select interrupt mode Return
Select normal interrupt mode Normal interrupt value
to І register
Return
Program variable
SCREEN DUMP OF MACHINE CODE TRACE DISPLAY