Previous column ComputerAnswers    Next column ComputerAnswers


ComputerAnswers Column 18


Copyright 1984-1989 Simon N Goodwin

Computer Answers is PCW's help column. We offer advice about all kinds of specific hardware and software problem, through the pages of the magazine. We also welcome further information in response to published queries.

(( SUB PLEASE NOTE: This month's submission is deliberately about 6K shorter than usual, as discussed with Lauraine on 11/3/86; the reason is that I'd like to 'use up' some of the overmatter; new questions are always coming in about similar subjects and it's tricky to know whether or not to handle them when I'm not sure what's in the pipeline. As far as I know, existing overmatter is headed: DAISYWHEEL PRINTER INFO / QL DISPLAY GLITCHES / THE BROTHER & THE BEEB / TEXAS D-I-Y. Please 'use these up' in the June issue ))


I am attempting to produce a program which can calculate the difference in days between two dates, allowing for leap-years, different months etc. I have a working version in BBC BASIC but the effort of translating it to Microsoft BASIC is beyond me. Do you know of any public domain software which would work? Is there a directory of public domain software libraries?
D Scott, London SW1.

I know of no public domain software directory, perhaps because there's no money to be made publicising 'free' software. Public domain libraries are maintained by computer clubs, the organisers of some phone-in 'bulletin boards', and a handful of specialist computer magazines. In most cases you have to pay a small membership fee to have access to the software - thereafter you pay only the cost of the duplicated media. Contact the Amateur Computer Club for details of specialist clubs and organisations that might be able to help with your specific needs; relevant addresses are printed regularly in PCW's monthly Amateur Computer Club column, ACC News.

The quality of public domain software is very mixed, as you might expect when you consider that the authors receive no payment for submissions. Games, programming utilities and packages for obscure applications predominate; 'support' for the programs is usually non- existent or informal (you may get the author's address).

Your specific problem is a common one, which I am happy to solve through Computer Answers. In essence you only need two lines of code to convert a date into a number of days since a fixed day; then you can compare or test dates easily. The next explanation is written out in English, rather than BASIC, so that it can be converted to more or less any programming language. For clarity I'll assume that you want to work with dates this century, although you can work outside this range if you take acount of the switch to the Gregorian calendar in 1582, and the special rules about leap-years in 'century' years.

In any case, you'll need to set up an array for the twelve months, where each element indicates the total number of days in the previous months, if any. Thus the entries for January, February and March would be 0, 31, and 59 (the number of days in January and February; ignore leap years for the time being).

The first line of code multiplies the year number (0-99) by 365.25, the number of days in a year, and takes only the whole-number part of the result (use INT in BASIC). The fraction .25 gives a leap year every four years. Add the value of the day-counting array for the month concerned (59 for March, 90 for April etc), to get the number of days up to the start of the month, then add the day number (e.g. 10 for March 10th). Strictly speaking you must then subtract one to get the number of days since 1st January 1900, as that is 'day zero', but you needn't bother to do this if you're just going to compare dates.

That can all be written as a single program statement, which converts a year, a month and a day into a count of days. However the extra day in a leap-year is counted as if it happened at the start of the year, rather than after February 28th; a further test is needed to correct this.

We need to subtract one from the day count if the number of the year is evenly divisible by 4 (so it is a leap year) and the month number is less than 3 (i.e. it is January or February). This does treat February 29th correctly, if you think about it.

In many languages you can build the extra check into the main calculation, but it is generally clearer to use a separate IF test. In BASIC, for example, you might write:

IF INT(year/4)*4=year AND mnth<3 THEN days=days-1

There are obviously several other ways to convert dates to days, but this algorithm is quite general, efficient, and easy to understand. I have tested it in Microsoft BASIC on a Video Genie.


In PCW No. 11, 1985, there's an Oric assembler in the Program File. A disassembler - obviously in machine code - is mentioned in the text, but where is it?
Lars-Owe Ivarsson, Heby, Sweden.

The Atmos disassembler was not listed in the magazine because of lack of space, but copies of the disassembler listing are available by post. If you would like a copy please send an SAE to Owen Linderholm, PCW Program Filer, at our usual editorial address.


I own the 'Perfect' package, Perfect Writer/Speller, Perfect Filer and Perfect Calc, and use a Pied Piper computer.

The computer operates on CP/M 80 version 2.2, and I have no languages. I wish to use control codes to select the Epson FX-80 printer modes shown in the Epson manual. However the examples are in BASIC, a language not provided on my computer.

My problem is that I do not know how to obtain different styles and types of print when using the Perfect Writer word-processor. The manuals only explain how to produce Boldface and Italic print.
Alan G Newton, Beccles, Suffolk.

You can select other print styles from within Perfect Writer II, but the word-processor does not handle them very well and you may find problems keeping margins tidy when you use styles of character that are not the standard width. You're also limited to three 'user defined' print styles at a time.

This reply is expanded from Appendix A of the Perfect Writer manual, which tells you how to create a new 'driver' (a file of printer-specific information). When you run the program PFCONFIG from CP/M, your answers to questions 25 to 30 indicate user defined styles.

You are asked to specify the sequence of characters which the printer recognises as codes to select each of three styles. The appendix contains an example of how you would enter the codes to select the Epson's Condensed character set. The codes for this (from the FX-80 manual) are ESCAPE SI. ESCAPE corresponds to the ESCAPE key, or the printed character with code 27, and SI stands for Shift In (rather than the two letters). Shift In has the printing code 15, as you can find by looking up condensed mode in the Epson manual. Each type style can be selected or turned off with specific codes, most of which start with an ESCAPE character.

In BASIC you select condensed characters by printing those two characters before the text you wished to appear in the new style; PRINT CHR$(27);CHR$(15) does the trick. In Perfect Writer you can get the same effect by associating those character codes with either F1, F2, or F3, using the PFCONFIG program.

Unprintable codes such as ESCAPE or SI must be entered in a special way, so that the program recognises them. Enter ESCAPE by pressing Control Q (to warn the computer that an unprintable code is coming up) and then press the escape key. Since SI has the numeric code 15, you can enter it by holding down the ALT key - to indicate that you're entering a code, not a sequence of characters to be taking literally - and pressing 0 1 5. You must type three characters, which is the reason for the leading zero. You should be able to see that an alternative way of entering the ESCAPE code would be to press ALT and type 0 2 7.

Questions 25, 27 and 29 allow you to set three such sequences. These are accessed, once you're in the word processor by typing @ F1, @ F2 or @ F3, respectively - rather as you type @ B for bold text or @ A for italics. I have not been able to borrow of a Pied Piper machine to try this on, but believe that you can get the effect of the dedicated function keys F1, F2 etc on larger systems by pressing FUNCT and a digit on the Pied Piper.

The snag of these new sequences is that the computer behaves as if characters printed after such a command will be printed in the same width as other characters, even though this may not be the case. As a result lines containing 'expanded' characters may spill out past the right-hand margin, and lines containing 'condensed' text may be unexpectedly short when printed out.

You can manually compensate for these effects by adjusting the line-lengths and margin positions on such lines, but the computer won't do the appropriate arithmetic for you; a few trial printouts may be needed in order to get things right. Sadly, very few word-processors keep printed margins tidy through changes in type-size; those that do tend to run slowly and restrict the user to a small range of printers.


I have trouble listing the "Amstrad Amsquill" program, which appeared in the November issue of PCW. I have checked this in a number of different ways, including comparison with a computer print-out, but I can only get it to work partially. I would appreciate if you would kindly let me know if there were errors in the magazine listing.
E Newbould, Sleaford, Lincs.

There were no errors in the listing of Amsquill - we know that, because we've heard from readers who have got it working without problems. However you may not have realised that the printer control options only work with an Epson FX-80, as the author states on page 237, under the catch-all heading 'Features'! Lines 2930 to 3090 translate Amstrad control characters - after the IF tests - into Epson printer- control codes. If your printer is not compatible with the FX-80, you must change the characters printed to channel 8 after the IF tests. Use the appropriate characters for your printer, taken from the printer manual. The FX-80 is an unusually versatile beast, and you may find that your printer physically cannot do everything that the FX-80 allows. Popular printers that are compatable with the FX-80 include the Canon PW-1080A and the Taxan Kaga KP-810.


I am a consultant surgeon with hospital as well as private practice. I am also involved in teching undergraduate students. At my service in the hospital is an NCR Decision Mate V computer, which is only used for filing. At home I have a Spectrum and Yamaha AX 200, both with disk drives. I also have a Yamaha PN-101 printer.

I have three problems. How can I get medical teachimg programs for the NCR (especially medical statistics)? I need software to use the AX-200 as a file at home for my patients, and to perform spreadsheet calculations. Finally, how can I get the printer attached to the Spectrum?
W.G Gazala, Mosul, Iraq.

Unfortunately we can't help with your questions about the Yamaha computer, since it seems to be unknown in the UK. However you should be able to connect the printer to your Spectrum without much trouble. Find out whether it uses an RS-232 or Centronics interface. If it uses anything else, you're in trouble and it is probably not worth trying to connect it to the Spectrum, but this is unlikely.

Sinclair include a serial RS-232 interface in their Spectrum add-on, Interface 1. This interface is rather non- standard but it should be adequate for driving a printer. Centronics (parallel) interfaces for the Spectrum are widely available; I use the Euroelectronics ZX LPRINT, from Transform of 24 West Oak, Beckenham, Kent BR3 2EZ. Several other firms make similar devices; it is worth checking with the supplier that the interface you choose is compatible with your existing software and add-ons - this is not always the case.

Medical software is thin on the ground in the UK; what little there is is mainly written for ICL computers, as those are widely used in our National Health Service. NCR have identified two firms that might be able to supply medical software for your machine. Medical Systems Ltd produce medical research packages; they are at Turnpike Road, Cressex, High Wycombe, Bucks HP12 3TF. Talkdata, of 67 Shelton Street, London WC2, offer the 'Drug Master 2' package. It would probably be worth getting in touch with these firms even if their software does not meet your exact needs - they might be able to pass your enquiry on to another specialist supplier.

Link to the top of this document    Link to the main index
Previous column ComputerAnswers    Next column ComputerAnswers