ae a spumunsennnsesmmaensens CET ae a seeennees ee a ee ae oceans - Ne seenenenneennenerereeneen



casi OMe Boorey os

soe ail wort

ponent” cost! aa

Robin Nixon

Digitized by Google


ROBIN NIXON Programs written and documented by Chris Nixon

SIGMA PRESS —- Wilmslow, United Kingdom

This One


Copyright ©, R. Nixon and C. Nixon, 1993

All Rights Reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without prior written permission.

First published in 1993 by

Sigma Press, 1 South Oak Lane, Wilmslow, Cheshire SK9 6AR, England. British Library Cataloguing in Publication Data

A CIP catalogue record for this book is available from the British Library.

ISBN: 1-85058-515-6

Typesetting and design by Sigma Press, Wilmslow

Printed in Malta by Interprint Ltd.

Distributed by

John Wiley & Sons Ltd., Baffins Lane, Chichester, West Sussex, England.

Acknowledgement of copyright names

Within this book, various proprietary trade names and names protected by copyright are mentioned for descriptive purposes. Full acknowledgment is hereby made of all such protection.


At first sight it might seem a step backwards and a rather surprising move for Amstrad to release a 64K Z80-based ‘laptop’-type computer when the market definitely looks like PC-compatible is the way to go, and laptops being the fastest growth area. |

But maybe that’s the point. There is a large group of people who know that all they need is a cheap, easy-to-use and (as the Notepads proudly proclaim) user-friendly interface - without having to learn about using DOS or Windows.

Amstrad are renowned for using tried and tested formulae, which the Z80 certainly is - just look at how well they did with the PCW family. What’s more, Z80s are cheap, as are the additional chip sets that go with them and, because of their low power consumption, you get up to 40 hours use out of an NC100 - about 10 times more than with most PC-compatible laptops.

And Amstrad made a very sensible decision in their choice of software. By porting Protext across to it they have a top-selling word-processor also available on a number of platforms, including the Amstrad CPC and PCW, Archimedes, Atari ST, Amiga and PC compatibles. In one go, Amstrad have a product that can be file compatible with just about every other popular computer.

By removing Protext’s command mode (well, not entirely, as you’ll see later), they came up with a very simple system of colour-coded key combinations so that, no matter where you are in the Notepad, you can move to any other in-built application at a key press. But, in my opinion, one of the best things to be incorporated was the BBC Basic ROM which allows you to adapt the computer fully to your own requirements.

And that is what this book concentrates on. In it you will discover how you can use BBC Basic to write applications to complement seamlessly the in-built applications, with the user never even knowing they are in Basic.

Even if you’re not a programmer, the explanations of how the Notepad works should interest you, but if not a large proportion of this book is taken up with ready-made

iv The Amstrad Notepad

programs ready for you to type in and run. So, without needing to know a thing about programming, you can add a writing style checker to your Notepad, or there’s a full scientific calculator, a food additive database, a graphical world time zone viewer, a mortgage calculator and a whole lot more.

For the more technically minded, full details on the Notepad’s firmware calls, input/output ports and system variables are provided, including how you can make use of them yourself. You’ll even learn how to create entire system applications to run from a RAM card. Everything you need to know in order to do this is in this book, even down to a fully working Z80 disassembler you can type in and use immediately.

In fact this book is packed with undocumented information about the Notepad (and even the Z80 microprocessor itself) that you are unlikely to find anywhere else. Along with the comprehensive index, you will find it to be a complete, one-stop reference to using and writing Notepad programs, as well as a valuable source of additional software for your Notepad.

Thanks are due to Mark Tilley and Gavin Every at Amor Ltd (the programming team) as well as to Cliff Lawson the Notepad Project Manager at Amstrad Plc for much of the technical information that appears here. Because these details came directly from the programmers you can be sure that they are as accurate as possible.

Thanks also to John Blackburn for his invaluable assistance in the preparation of this book, and to Richard Russell, the author of the Notepad BBC Basic interpreter, for his assistance with the final manuscript.

Robin Nixon

To Julie and Naomi


SECTION 1 - THE PROGRAMS.......... cc cece eee reece eee L

THREE GOLDEN: RULES iy oie Se os ae ele eee we Gade ee dees 2 GEE TE RIGHS a8 deeds ohio 8 coast Gk Sk Boh ne ed hare ee ee leew 2 PT 55a acca a ah se Gaeta: Sse aie ane nts d ener bh ear eae OLE, & OS DORI Deere Baas 3 USING THE PROGRAM (2.42405 ei aV came eek tates eee we 3 HOW ATE WORKS 2eaiada da otitet sus cede eet bathe ate es 4 BIOMON. BAS <3.5.c3-6eice tice tee a Be tes os aye 6 USING THE PROGRAM :/..¢ oie aku eww tes GE eons 4 oak Ae ee 6 HOW TE WORKS i5.0-4 oe he a as Soe aie ard ws ee Ue ae ee eee 7 CALC BAS 5c. cate Suh ee P AChE eee OA eeks pat es eee ee 12 USING THE PROGRAM) g:¢.24202 Uo kee bade e eee te een ee ae 13 HOW TT WORKS 36.5 406 ale ak rete ea ee eh See gas 15 CHART.BAS...... Se ee ee ea ee a eee ee ee ee ee 22 USING THE PROGKAM 34.4. ctpas Up hee eee eal ae Cae ad 23 HOW TE WORKS ossc Ue 2s shee eee net hake bac ae bea eek 23 COOKIE. BAS 340080460 4 e ede anise eeds sense eee eee a 26 USING THE PROGRAM eoxcstased tere dwletecs eed ded cated 26 HOW: TT WORKS cc: peeve tanto deere iat eee ee cae wkeeexs 27 DEVIL BAS os6 dese S061 e 2S ee oe oe aw Sie. Oe ee OES < 33 USING THE: PROGRAM (:.2-5-2. on den wee he awe daa Bede ets, Som ave 34 HOW TE WORKS. 4 stances baton earn eaten Dade bag eo cewek 35 FOOD.BAS ........... Teer e Te tee Tee ee ee ee ee re ee 47 USING THE PROGRAM ox oindels} eueewt Rea ae Oe ewe Bis 48 HOW TP WORKS coc 2eeu eu as oe Gee Rape e Anh sea eee eee 49 INR EY BAS. 6 oie 6 escent a8 tisvedn eed ee ee See aid eros 56 USING: THE PROGRAM <2 oi.x 63 peawed a laeasheaeee b ew ew a Ss oe Sees 57 HOW TT WORK Sec c'erard de Gsh due ain easy ees ne Rd, Se ane a 57 MORTGAGE BAS itd ate e Amite Oo bee CAS a a kn k eaten Be 58 USING THE PROGRAWK: ¢. iawn ay hteed See Oe ESAS RS 59

vi The Amstrad Notepad READY REC DAS 6.566204. Wb 4604 bE ROSSOW hs oS 61 LISING- THE PROGRAM 3.03 828044 a ea bee eae Ree ak 62

HOW LE WORKS esos cca ¥ oh hos Ot a ecara ase ierertes Cada oer ho. ee eS 63 SCALES: DAS. «.2:4.5.0 9944603 644-4 5544.0 055.45 6 OSES SG RS Roses ees 68 USING THE: PROGRAM) ¢nc6hc ores eee Cee ee eN 2 oh PEERS 69

HOW IT WORKS. 4\24.64.046i-2 ee jokew als eaek need acres towed 69 STYLE BAS s wcc ceed 8. ohh ews be eee ea ds ease ae eee 75 USING THE-PROGRA Messiica.estbcg endb hohe a ek A Be ak Be Mls 76

HOW: It WORKS esgic ee 4, ah ee thie dds RS Add EEE eS: 77 TIMEZONE DAS. 6550.4 6-3.66 35h oa eh OK ERS eS 88 USING THE - PROGRAM ge) 3 sis oy 85,4: 6 has Re eS SRN ae Ee 89

HOW TT WORKSs 42.5 653 SiR POOR es OSes 85a OES 89

PAV BAS osces ho tS aa ee a eS eR Sh Ree 100 USING THE. PROGRAM ie ie%se wha abt hak ede Race eee BOER 101

HOW TT WORKS v2.46 oe ew eawed O28 Hao eee i SEO Bh we 101 SECTION 2 REFERENCE ............ ccc ccc ee eee 121 1. CONTINUED ... FROM THE NOTEPAD MANUAL............... 122 REGISTER VARIABLES @ 9 sos a ocd 6S bh a SS SE a ew ee 126

2. UNDOCUMENTED FEATURES. ............. ccc ecw cece ce eees 129 TRANSFERRING BBC BASIC PROGRAMS.................... 129 QUICK MACRO ASSIGNING ....... 0.0.0... cee eee eee eee 129

LINE DRAWING CHARACTERS............. 00.0000 eee ee eee 130 PAGE DISPLAY MODE: «2:3 die decioos.-ep 6-8 od dew argce RA he tele he bate ewer 130 USING * THE FILE SELECTOR 3s ose Siete ten aie Week ty Ree 131 PEERING ABOUT 6 ied a0 oe ie atari oite baw eRe edo eet 131 UNDOCUMENTED SELF-TEST.....................0....0005 133 SAVING THE. SCREEN 4 cy oA Scale Bak Seka ck occ aces eo hans 134

3. WRITING EXTERNAL PROGRAMS..............2cc ccc ccccees 145 USING THE NOTEPAD’S LCD DISPLAY ....................0. 146

4. THE NOTEPAD’S INPUT/OUTPUT PORTS. .............c.ccee08 151 5. THE JUMPBLOCK ENTRIES ............... cc ccc ee eee cee eee 157 KEYBOARD FUNCTIONS i aoo 4446-04012 4 S498 ESA ae ees 158 SCREEN DISPLAY FUNCTIONS................ 0.000 e eee 160 PARALLEL AND SERIAL PORT FUNCTIONS. ................. 166 CEOCK. FUNC TIONS: 26 &.dogswtg ate gtdemndia tia: dey dosh ets oak Sg Becerra ace lore 169 MEMORY ALLOCATION FUNCTIONS...............02 000008 170

PILE 1O BUNCTIONS occ aries SIDES Ge Sd ob nade oes ae k 172

Advanced User Guide Vii

6. THE SYSTEM VARIABLES, ....... ee ceecceccecceeceecevcnce 182

BBC BASIC MAIN SYSTEM VARIABLES. ................0.06. 185 7. RECOVERING FROM LOCK-OUTS.......... 0 cee eeceececeecees 186 8. THE COMPLETE Z80 INSTRUCTION SET............ 0c ceeeees 188 9, THE UNDOCUMENTED Z80 INSTRUCTIONS ..........2-2eeeee- 219 SECTION 3 APPENDICES ........ cc cccccceccceecccvcece 225 APPENDIX 1; NC100 JUMPBLOCK ENTRY POINTS................ 226 APPENDIX 2: INPUT/OUTPUT PORTS (&0000 &O0FF)............. 229 APPENDIX 3: KEYBOARD SCAN CODES ........... cee ceeceeeees 230


APPENDIX 5: NEW NOTEPAD MODELS...........0 cece vcveccece 247 APPENDIX 6: EXTRAS 6: 5.6::5:5.:60909:9.4' 96 se: aise 0:0) © 9694.6 Sie. Bas-d See 248 GET CONNECTED WITH LAPCAT...... 0... cee cece ee eee 248 EXPAND YOUR NOTEPAD WITH A RAM CARD............... 248 ORDER THE DISK OF THE BOOK ............... 0. ce eee eee 248

ORDER FORM 4234 6.005303 see see hoo ie 249

Digitized by Google



Whether or not you are a programmer, this collection of programs has been designed to accompany the applications provided with your Notepad. They have been written in such a way that no knowledge of programming is required to use them and you can call them up by simply pressing [Function][B], so you don’t even need to know any Basic commands. Just type in the programs, check them and save them.

On the other hand, detailed descriptions accompany every program in this section, including line by line running commentaries, descriptions of the functions and procedures used, and an explanation of all the main arrays and variables.

Using all this information in conjunction with the listings you will be able to pick up on the various methods used and then incorporate any ideas you like into your own programs. To this end the variety of programs has been kept as wide as possible and a broad range of programming styles and techniques have been used, covering areas

such as using the built-in assembler, handling strings, variables: and arrays, processing and storing data, directly accessing the display RAM, the non-standard Notepad VDU codes and much more.

All the programs are wnitten in BBC Basic and some contain sections of assembly language to achieve effects that, if written in Basic, wouldn’t be possible, would take too much space to write, or would run unacceptably slowly.

The programs are self-contained, and range from a useful scientific calculator to a world clock featuring a map of the earth. There’s also a version of the classic game Towers of Hanoi to while away the odd hour, and if you are fond of writing you

2 The Amstrad Notepad

might like to pass your efforts through the compact style checker and see how they measure up.

Programmers may be particularly interested in the assembly language routine that performs an instant scan of the keyboard, in a similar fashion to BBC Basic’s negative INKEY(-n), (as opposed to Basic’s INKEY or INKEY$, which can only return keys at the speed of the current keyboard repeat rate). There’s a full chart of the Notepad’s character set useful for designing screen layouts or games, and a complete Z80 disassembler so you can delve into the inner workings of other programs.


There are three Golden Rules you must bear in mind when typing in program listings, and which you should always follow in order to prevent typing mistakes or even crashing or erasing programs.

Golden Rule number one: Make sure you save your work before you try it out. It’s very tempting to type RUN every so often to see the effect so far, but even if you save the program first you are

strongly advised against it especially where there is machine code involved, as you could lock-up your Notepad.

Golden Rule number two:

Read the listing carefully. A common error is to confuse any of the following for each other: Lower case "1" (lower L), "i" (lower I) and "1" (one). Another common mistake is to confuse the capital letter "O" with the number "0".

Golden Rule number three:

Don’t delete any REM lines or lines containing just a colon ":". As a matter of style most of the programs in this book avoid GOTOs in the main code, but all of them contain at least one ON ERROR GOTO line (and listings from other sources may make more liberal use of GOTOs). So, if any GOTOs happen to point at a line that you've deleted as being unnecessary you'll get into all sorts of bother.


If all else fails (or even if you simply prefer not to type in the programs), you can order a disk containing all the listings fully tested and ready to run, along with a lead and software to transfer them to the Notepad, using the form in Appendix 6.

Please also remember that a Notepad without a RAM card may only be able to hold two to three or so small to medium Basic programs at any one time. If you really want to make use of your computer and not run into memory storage problems you should buy a RAM card. One such source is also given in Appendix 6.

Advanced User Guide 3


Menu system

~~ Yr YY YY 7 b> OPAL AUS rononorno—esae = pwc000—a



AUTO, the menu system for Basic programs

This is the first and most important of the programs because it provides an easy-to-use interface for running the other programs, without needing to enter BBC Basic’s command mode.

It works by taking advantage of a feature built into Notepad Basic which checks for a file called AUTO whenever you enter Basic (normally by pressing ([Function](B]). If such a file exists Basic proceeds to load and run it, rather than just dropping into command mode.


Type in the listing and save it as AUTO before trying it out. Note that you must NOT call it AUTO.BAS (although all the other programs should use the .BAS extension), or the file will not be recognised by Basic’s initialisation routines. It is also essential that you save the program before running it in case you have made any typing mistakes and something goes wrong or, perhaps, you did type it in correctly but accidentally loaded in another program while testing it.

Once saved type: RUN

and press [Return]. You should then see the Notepad’s standard file selector which you can now use to call up a program in the same way you might select a file for editing in the word processor.

Because this program prevents access to Basic’s command mode you might wonder how you are now going to be able to type in more programs. The answer’s simple: you can exit from AUTO at any time by pressing [Stop]. You are then dropped into command mode and, if you want to enter a new program, type:


4 The Amstrad Notepad

and off you go. Or, if you accidentally exited from AUTO you can get back in by pressing [Function][B].


The program is described as follows, with line numbers on the left and explanations on the right.

30-40 Clear memory and dimension A% so that it’s just big enough to hold the machine code which will be assembled.

50-60 Assemble the code and call it.

70 If the first character of the file name is O then there is no file name so print a message and exit.

80-110 Copy the file name returned by the machine code routine into the variable R$.

120 Check whether the file name has an extension of .BAS. If not, it

is not a Basic program (at least, not as far as the program is concerned, because the .BAS extension is the recommended method of declaring whether a file is a Basic program). So, if not, refuse to attempt to run it and call the file selector again.

130 Load the selected program into memory (replacing AUTO) and run it. 160-190 Prepare for a two-pass assembly using a FOR...NEXT loop and

set the program point (P%) to the machine code destination address at the start of each pass.

200 Call the Notepad’s built-in File selector.

210 Set the register DE to point to the start of where the File selector will have stored a file name if one was selected.

220-250 If the Carry flag is set then no file was selected because the user

pressed [Stop], so set the first byte of the file name which is to be passed back to Basic (pointed to by DE) to a zero to indicate this, and then return.

270-340 A file name was selected so copy all the characters in the name to a known location in memory starting at ‘buffer’ and then retum.

Functions and procedures

PROCselect Assembles the machine code required to call the File selector and then return the name of any selected file to a known area of memory that can be accessed from Basic.

Main variables and arrays

A% 22 bytes of memory used to hold the assembled machine code.

Advanced User Guide

buffer The start of 13 bytes of memory within A% which are used to hold any file names.

R$ Holds a copy of a selected file name ready to CHAIN it in.

S% Temporary loop counter used to control the copying of a file name from memory into the string R$.

P% The pointer to where machine code is to be assembled by the assembler.

found Start of machine routine where a file name has been found.

loop Label marking the start of the machine code loop to copy a file

name to a known location, useable from Basic.

The program

10 REM BBC Basic menu system 20 : 30 CLEAR 40 DIM A& 22 50 PROCselect 60 CALL A% 70 IF buffer?0 = 0 THEN CLS:PRINT "Press [Function] ([B] for menu.":PRINT: END 80 RS=" aw 90 FOR J%=0 TO 11 100 IF buffer?J% THEN RS=RS$+CHRS (buffer?J%) ELSE J%=12 110 NEXT 120 IF RIGHTS (RS,4) <> ".BAS" THEN GOTO 60 130 CHAIN RS 140 : 150 DEF PROCselect 160 FOR PASS=0 TO 2 STEP 2 170 P%=A% 180 [ 190 OPT PASS 200 CALL &B8C3 210 LD DE,buffer 220 JR C, found 230 LD A,O 240 LD (DE),A 250 RET 260 .found 270 LD B,12 280 .loop 290 LD A, (HL) 300 LD (DE),A 310 INC HL 320 INC DE 330 DJNZ loop 340 RET 350 .buffer 360 }j 370 NEXT 380 ENDPROC

6 The Amstrad Notepad


Biorhythm Monitor

Biorhythm Monitor

Enter your Date of Birth

Day (1-31):

BIOMON.BAS, showing physical, intellectual and emotional strength

The study of biorhythms is based on the ancient belief that our physical, intellectual and emotional states run in fixed, regular cycles from the day that we are born. Whether you believe this or not, it means that we can calculate these states for any day of a person’s life, given just their date of birth and today’s date. And as the cycles are regular, they lend themselves to rather attractive looking sine wave charts, which used to be hand-drawn by astrologists in the days before computers.

However, this is extremely time consuming, and as the formulae for calculating the number of days that lie between a person’s birthday and any other date are complex, they make an ideal subject for a computer program to handle. In fact, there probably isn’t a computer in existence that hasn’t had a biorhythm calculator written for it (as a demonstration of the machine’s graphics capabilities as much as for any other reason).

The program BIOMON.BAS uses the standard biorhythm cycles to plot a personal chart for a 35-day period with today’s date in the middle. It differs slightly from other programs of this type by telling the user in plain English what each line on the chart represents, and whether today’s level is good or bad for that particular chart line.


Type in the listing and save it as BIOMON.BAS before trying it out. This is essential in case you have made any typing mistakes and something goes wrong.

Now type:


and press [Return] and you will be prompted to enter your date of birth. Type in the day of the month on which you were born, and press [Return]. Then type in tke number of the month, press [Return], and then enter the year you can enter this. either in full, as in 1964, or in shorthand, as in 64. Don’t forget to press [Return] after

Advanced User Guide 7

entering the year. If you make a mistake at any one of these three stages, Biomon will repeat that stage until it’s happy with the result.

Biomon now makes a final, more involved check to see if the date you have just entered actually existed. It does this by checking that the month you have entered has at least the number of days you have given as the day of the month on which you were born, and leap years are taken into account at this stage. If Biomon finds an error it will report Bad date press SPACE, and you will have to re-enter the whole date.

If all is well with the date, the screen will clear and the plotting will begin. Each line is drawn with a different dot pattern, making it easier to tell them apart.

When the plot is finished (it takes about half a minute), the box on the chart representing today’s date will be highlighted in inverse, and the window on the left will show a key for each of the three chart lines together with a one-word summary of how good or bad each one is today.

If you can’t wait for the full plot you can cut it short by pressing [Q], which jumps straight to the summary screen useful if you’re not interested in seeing the general pattern of cycles.


40 Points the Basic error handler to Biomon’s own error handling routine at line 940.

50 Calls PROCsetup to initialise everything.

60 Calls PROCinput to get a birth date, followed by PROCdays to

count the number of days that have elapsed. Then calls PROCgraph to plot the chart, and finally PROCreport to summarise the current state of each chart line.

90-130 Initialise the main graphics constants. Altering these values will have a major effect on the resulting chart.

140-180 Dimension all arrays and read in all the data.

190 Draws a box enclosing the entire screen area.

200 Draws a vertical line to separate the graph area from the information window.

210 Prints the program title.

220 Calls the date prompt window into operation and returns from the procedure.

250 Flushes the keyboard buffer by calling INKEY$(0) until no keys are returned.

260 Prompts for the date of birth to be entered.


300-320 330

340 410



440-450 460 ©


560 590-600








The Amstrad Notepad

Repeatedly prompts for the day of the month until the input is within legal limits.

Repeatedly prompts for the month until the input is within legal limits.

Repeatedly prompts for the year until the input is within legal limits.

Check to see if the date specified exists.

Informs the user if the date doesn’t exist and waits for the message to be acknowledged.

Repeats the entire input process if the date entered doesn’t exist.

Extracts the current day of the month and the current year from the system clock.

Extracts the name of the month from the system clock and converts it into a number between 1 and 12, by comparing it against each entry in the array m$().

Multiplies the elapsed years by 365 to get the rough number of days involved.

Adjust the days according to the birth month and current month.

Adjusts the days further according to the day of the month of birth and the current day of the month.

Adjust the days further according to the number of leap days involved.

Calculates whether y% is a leap year or not.

Clear the information box and print the current date, together with the birthdate being plotted, in preparation for the plot. Sets up a graphics window and origin, and clears the new graphics window.

Draw the chart axis, and dotted boxes to delimit each of the 35 days to be charted.

Sets the start day to be 17 days ago and starts the main FOR...NEXT loop for the X coordinate, checking for the [Q] key at the start of each loop.

If [Q] wasn’t pressed, calls PROCbio() inside a further FOR...NEXT loop to plot the current Y position of each line.

Ends the main plot loop, inverts today’s box on the chart and exits the procedure.

Fetches the cycle length for the current line and whether it is in its dot or dash phase.

Plots a new point for the current line if it is inside its dot phase.

Advanced User Guide 9


720 760-830



890 900







Checks to see if current line’s dot or dash phase has reversed. If so, flips the line’s dot phase flag.

Stores the new dot phase flag setting for the current line.

Draw a short sample of each line’s dot pattern to be used as a key, during which time a score for each is calculated in line 810, representing an entry in the array of comments well$(). Display the report header when the loop is complete.

Print the name of each cycle, together with a single-word | comment from the list held in well$Q, pointed to by the relevant entry in the score table well%(Q) (which was calculated back in line 810).

Waits until [Space] is pressed before returning from the procedure.

Holds the data for the number of days in each month.

Holds the names of each month, as used in line 420 to calculate the number of the current month.

Holds the cycle length in days for each of the three chart lines, followed by the length of the dot and dash for that line, followed by the initial dot-dash phase to start with.

Holds the single-word comments which are used at the end of each plot to summarise the state of each chart line.

Points the Basic error handler to a full error report in the event of a further error occurring while attempting to run the menu program AUTO. This is in case AUTO isn’t present on your Notepad.

Attempts to run the menu program AUTO if the error was generated by pressing the [STOP] key.

If the error was caused by something else, or if AUTO isn’t on your Notepad, a full error report is displayed.

After the error report the Notepad will be left in BBC Basic, so

this message is displayed to remind users of how to return to the Notepad main menu.

Functions and procedures


PROCinput PROCwin1 PROCwin2 PROCdays

Dimensions arrays and reads in all data, initialises main variables and draws a box.

Prompts for the day, month and year of birth. Sets up a text window for the birthdate prompt. Sets up a date window for the birthdate input. Calculates number of days elapsed since birth.


PROC graph PROCbio PROCreport


The Amstrad Notepad

Plots a biorhythm chart for the birthdate just entered.

Plots a dot at the current X coordinate for any of the three lines. Called by PROCgraph.

Displays a key for the graph and a single-word summary for each line.

Returns TRUE or FALSE according to whether the passed variable is a leap year.

Main variables and arrays

m7%() m$() period%() gap%() flag%() well%() well$( yc% xc% px% xm% ym% d%


d1% m1% y1% d2% m2% m3% t% quit%

The program

Number of days in each month.

Abbreviation of month names.

Length of each cycle in days.

Length of each line’s dot and dash in pixels.

Keeps count of each line’s current dot or dash phase. Numbers representing how good or bad each cycle is today. Store of single-word summaries.

Y centre of graphic window.

X centre of graphic window.

Number of pixels per day horizontally.

Width of graphic window.

Height of graphic window.

Number of days since birth, as returned by PROCdays. Number of days since birth up to 15 days ago (the start of the plot).

Day of birth.

Month of birth.

Year of birth.

Today’s day of the month.

Today’s month.

Today’s year.

Number of current line being processed (1, 2 or 3). Whether Q was pressed during plot.

10 REM Biorhythms

20 : 30 CLS


50 PROCsetup

Advanced User Guide I]


REPEAT: PROCinput : PROCdays : PROCgraph:PROCreport: UNTIL FALSE


yo%=31:REM Y Centre of graphic window

xc%=155:REM X Centre of graphic window

px%=10:REM No. of pixels per day horizontally xm%=310:REM Width of graphic window

ymt=61:REM Height of graphic window

DIM m%(12):FOR d%=1 TO 12:READ m% (d%) :NEXT

DIM m$(12):FOR d%=1 TO 12:READ m§$ (d%) :NEXT

DIM period’ (3) ,gap% (3,2) , flag% (3) , we11% (3) , we1l1§ (7) FOR t%=1 TO 3:READ periods (t%) , gap% (t%, 0) , gap% (t%,1) , flag% (t%) :NEXT FOR w%=1 TO 7:READ wellS (w%) :NEXT

MOVE 0,0:DRAW 479,0:DRAW 479, 63:DRAW 0, 63:DRAW 0,0 MOVE 167,0:DRAW 167,63:PRINT TAB(5,1) ;CHRS§ (17); PRINT"Biorhythm Monitor"; CHRS (18) PROCwinl : CLS : ENDPROC

DEF PROCinput REPEAT: UNTIL INKEYS (0)="":REM Flush keyboard buffer

260 PROCwin1:CLS:PRINT TAB(1,0);"Enter your Date of Birth"; :PROCwin2: REPEAT

270 REPEAT: CLS: INPUT" Day (1-31): "d1%:UNTIL d1%>0 AND d1%<32

280 REPEAT:CLS: INPUT" Month (1-12): "m1%:UNTIL m1%>0 AND m1%<13

290 REPEAT:CLS: INPUT" Year (1900-): "y1l%:UNTIL y1%<100 OR y1%>1900

300 IF y1%<100 y1%=y1%+1900

310 legt=TRUE: IF y1%<1900 OR y1%>2020 legt=FALSE

320 IF d1%t>m% (m1%) +FNleap (y1%) * (m1%=2) legt=FALSE

330 IF legt=0 CLS:PRINT CHR$(17)" Bad date - press SPACE";CHRS$(18);: g%=GET


350 :

360 DEF PROCwin1:VDU 28,1, 6,26,3:ENDPROC

370 :

380 DEF PROCwin2:VDU 28,1,5,26,5:ENDPROC

390 :

400 DEF PROCdays

410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 610 620 630

d2%=VAL (MIDS (TIMES, 5,2) ) : y2%=VAL (MIDS (TIMES, 12, 4) )

m2%=0 : REPEAT : m2%=m2%+1 : mS=m$ (m2%) : UNTIL mS=MIDS (TIMES, 8, 3)

d%=365* (y2%-y1%)

IF m2%>1 FOR m%t=1 TO m2%-1:d%=d%+m% (m%) : NEXT IF ml1%>1 FOR m%=1 TO m1%-1:d%=d%-m% (m%) : NEXT dt=d%+d2%-d1%

yt=yl%-y1% MOD 4:REPEAT: yt=y%+4

IF y%<y2% IF FNleap(y%) d%t=d%+1

UNTIL y%>y2%

IF yl%=y2% IF FNleap(y1%) AND m1%<3 AND m2%>2 d%=d%+1:ENDPROC IF FNleap(y1%) AND m1%<3 d%=d%+1

IF FNleap(y2%) AND m2%>2 d%=d%+1


DEF FNleap (y%) IF ytMOD4=0 AND (y%MOD100<>0 OR y%MOD400=0) THEN =TRUE ELSE =FALSE


PROCwinl1:CLS:PRINT TAB(3,0);"Plot on ";MIDS (TIMES,5,11)

PRINT TAB(4,2); "For DoB ";CHRS (17) ;d1%;"-";m1%; "-"; y1%; CHRS (18) VDU24,168;1; 478; 62; 29,168;1; :CLG

MOVE 0,yc%:PLOT 21,xm%, yc%:MOVE xc%-px%/2,yc%:PLOT 1, px%,0

FOR x%=0 TO xm% STEP px%:MOVE x%,0:PLOT 21,x%, ym%: NEXT

12 The Amstrad Notepad

640 sd%=d%-17:quit%=FALSE:FOR x%=0 TO xm%:IF INKEY(0)=81 quit%=TRUE : x%=xm%

650 IF NOT quit%® FOR t%=1 TO 3:PROCbio (t%) :NEXT

660 NEXT:MOVE xc%-4,0:PLOT 102,xc%+4, ym%:VDU26:ENDPROC

670 :

680 DEF PROCbio (t%)

690 period%=periods (t%) : flagt=flagt (t%) :gapt=gap% (t%, flagt)

700 IF flagt PLOT 69,x%, yc%+ (yct*SIN (2*PI/period%* (sd%+x%t/px%) ) )

710 IF x% MOD gap%=0 flagt=flag%+1:IF flag%t=2 flagt%t=0

720 flag% (t%) =flag% : ENDPROC

730 :

740 DEF PROCreport

750 PROCwin1:CLS

760 FOR t%=1 TO 3:period%t=periods% (t%) : flagt=0

770 FOR x%=8 TU 28:gap%=gap% (t%, flag%)

780 IF flag PLOT 69,x%, 36-t%*8

790 IF x% MOD gap%=0 flagt=flag%+1:IF flagt=2 flag%=0

800 NEXT

810 well% (t%&) =(yc%+ (yc%*SIN (2*PI/periods* (sd%+ (xc%+px%) /px%) ))) / (ym%/6) +2

820 IF well%(t%)>7 well% (t%)=7

830 NEXT:PRINT TAB(0,0) ;CHRS(19);"Your Constitution Today Is";CHR§ (20)

840 PRINT TAB(5,1); "Physically"; SPC (5) ; well$ (we11% (1) );

850 PRINT TAB(5, 2); "Emotionally"; SPC (4) ; well1§ (wel1% (2) );

860 PRINT TAB(5,3);"Intellectually ";well$ (wel11% (3) );


880 :

890 DATA 31,28, 31,30, 31,30,31,31,30,31,30,31

900 DATA Jan,Feb,Mar,Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec

910 DATA 23,8,8,0,28,1,8,0,33,4,4,0

920 DATA Awful, Poor, Fair,Normal, Good, Great, Superb

930 :



960 REPORT:PRINT" at line ";ERL

970 PRINT:PRINT"Press [Function] [X] for Notepad Main Menu"


Scientific Calculator

Scientific Calculator 1.95845697 9,09090909E-2

TOTAL 8.551426631

6 .3551926681

CALC.BAS, a powerful scientific calculator

Most computer users complain at some time or another about the lack of a real calculator program for their system, which on the whole is a justifiable complaint

Advanced User Guide 13

especially in the PC compatible world, where hardware costing thousands of pounds often comes with no software installed.

By contrast, Amstrad Notepad users are lucky enough to have a built-in calculator featuring a large, friendly display. But sometimes it just isn’t up to the job, especially where you need to use scientific functions, or recall the results of previous calculations.

The program CALC.BAS aims to solve some of these frustrations by providing a large scratch pad on to which you can jot calculations of a highly complex nature. You are allowed to use all the functions normally available from BBC Basic inside your calculations, and you enter these in a large window on the left of the screen, while a matching window on the right displays the results of each calculation.

The windows scroll in both directions and are synchronised, allowing you to recall previous entries and their results. You can even modify earlier calculations without having to type in the whole lot again.

Calc remembers the result of the current calculation and displays it in a separate, stationary window so that you can scroll freely through several screens of work and not lose your position. It clears this value when you next enter a line.

A special feature of CALC is its ability to treat the value in this window as a running total accumulator. So, putting a +, —, * or / symbol at the start of your calculation turns it into an expression that takes the value in the Total window as its input. (See USING THE PROGRAM for a more detailed explanation of how this works).

Although it doesn’t support the use of variables or memories, you will be surprised at how useful this program is (it even gives the result of each calculation in hexadecimal, for any programmers who wouldn’t otherwise have found Calc suited to their particular needs).

USING THE PROGRAM Type in the listing and save it as CALC.BAS before trying it out. Type: RUN

and the cursor will now be sitting in the bottom left of the Input window, between the two arrows that indicate where your input will go. Now type in any number, or legal BBC Basic expression such as:

30+ (SIN (45) )

Notice that your input is shown in bold text as you type. In fact, the contents of the bottom line of the Input window is always shown in bold, because when you are

14 The Amstrad Notepad

scrolling through previous calculations it serves to highlight the one currently under the cursor.

Press [Return] and Calc will scroll both the Input and Result windows up one line, and the line in the Result window opposite the expression you have just entered shows the result in both hexadecimal (on the left) and decimal (on the right). The Total window just gives the result in decimal.

To try out the scrolling facility enter a few simple expressions, until the first one has completely scrolled off the top of the display. Now press [Up] a few times, watching as your previous entries (and their results) scroll back into view. Note the expressions turning bold one by one as they pass through the bottom line of the Input window.

Now stop at any time and edit an expression (one of the features of Calc is that it is permanently in edit mode, so you can change whatever is under the cursor at any time). Remember that you MUST press [Return] to register the change if you move off the line with [Up] or [Down], Calc will restore the old contents of the line.

You might think that Calc is limited by the seeming inability to pass on any results to the next calculation you enter. For example, if you were to enter:


then both the Result and Total windows would show the answer 10. But what if you wanted to add 10 to the result from the last calculation? Even the most basic pocket calculators allow you to do this by default. If you enter a sum like 4 + 30 + 15 on any calculator, it displays the interim total each time another operator key is pressed.

Calc allows you to emulate this quite well, simply by adding one of the four basic arithmetic operators to the start of an expression. For example, if you were to enter this line instead:


Calc assumes that you meant add 10 to the current running total which is exactly what is wanted. The same goes for more complex expressions such as:

* (COS (100) +PI) /9.073

which means multiply the current total by the result of this expression. In Basic the process might look something like this:

total=total* ( (COS (100) +PI) /9.073)

Notice the added brackets around everything after the *. This is because syntactically, Calc evaluates the whole expression (minus the operator, of course) BEFORE applying it to the total.

Advanced User Guide 15

The next time you enter an expression without a preceding operator Calc clears the

running total. If you would prefer to clear it to zero, just enter 0. Or to clear the entire scratch pad, type:


in upper case (because BBC Basic requires upper case for all keywords) before pressing [Return], and then confirm your decision with the [Y] key.

Full line editing is provided by Calc, and while it may not be quite as good as the Notepad’s default line editor, it does include all the standard editing key functions you would expect. Here’s a complete list of the movement and editing keys used in Calc:

[Right] Cursor right Moves the cursor one character to the right.

[Left] Cursor left Moves the cursor one character to