Previous chapter Index Next chapter

Chapter 4

Tailoring the Spectrum to your needs

When you bought CP/M for your Spectrum +3, it was set up to be used in a very conventional way with:

Moreover, the programs you use have probably been designed to take some information through the keyboard and other information from, say, the RS232 port and to send some messages to the screen and some, say, to the printer.

This is a perfectly satisfactory arrangement if, say, you use a parallel printer with your Spectrum but not if you have a serial printer (which you would need to attach to the RS232 port) or you want to use your Spectrum for communications. The RS232 port on the Spectrum is a very simple device, which cannot handle the simultaneous input and output of communications: instead you need this 'auxiliary' information to be handled by a dedicated Serial Interface attached to the Expansion port.

In addition, you might want to change how some of your input and output devices are set up. For example, you might want to replace your printer or your communications link with a new one that needs data sent to it at a different speed or checks the data has been sent correctly in a different way - or you might just want to change the speed at which data is sent to your current link.

Changing where information comes from and goes to would seem impossible without rewriting the program. But in fact such changes are made very easily because in the main your programs don't make use of your input and output devices directly. Instead, they use 'logical' devices (with names like CON:, LST: and AUX:) which CP/M links to the 'physical' devices CRT (your keyboard and your monitor), LPT (the Printer port), SIO (the RS232 port) and SERIAL (the Expansion port).

All you have to arrange is that each logical device is 'assigned' to the right physical device. In particular, you need to ensure that you don't assign a logical 'output' device to a physical 'input' device (such as the keyboard) or a logical 'input' device to a physical 'output' device (such as a printer). Your computer can't write to a keyboard and and you can't enter data through a printer!

This chapter explains how to tailor your Spectrum +3 to your needs by:

4.1 Setting up the parallel Printer port

The Printer Port on the back of the Spectrum +3 is a standard 8-bit Centronics Interface and so can be used to connect a wide range of parallel printers to your Spectrum. If your printer has a standard Centronics connector, you should be able to connect it directly to the Printer Port. If it has an IBM-type Centronics connector (with pins), you will need an adaptor. Consult your printer dealer for details.

(If you have a Serial printer, you will have to connect it to your Spectrum's RS232 port. How you use this port is explained in Section 4.2)

Unfortunately, using a printer with a computer is rarely just a matter of connecting the two together. Some programs do all the hard work for you where the printer's own defaults don't give you the settings you want but often it falls to you to ensure that:

In addition, CP/M has a built-in timeout mechanism to stop your system 'hanging up' if you accidentally try to send some output to a printer (say) when none is connected. However, this can work against you rather than for you if it takes your printer a long time to feed a sheet of paper - so you might also need a way of overriding the timeout mechanism.

There are CP/M commands to do all these things. The details are given below.

Sending output to the Printer port

As we pointed out in the introduction to this chapter, the key to directing output to a particular device is in linking the logical device associated with this output to the correct physical device. In the case of printer output and the built-in Printer port, this means linking the LST: logical device to the LPT physical device.

Immediately after CP/M is loaded, LST: is assigned to LPT - ie. this is the normal assignment for LST:. However, it is always best to check that this is still true before you start printing. The command line to use is simply:


    DEVICE

CP/M responds with details of the available physical devices and the current assignments of the logical devices. For example, you might see:


    Physical devices:

    I=Input, O=Output, S=Serial, X=Xon-Xoff

    CRT    NONE   IO  LPT     NONE   O  SIO     NONE   IOS

    Current Assignments:

    CONIN:  =     CRT

    CONOUT: =     CRT

    AUXIN:  =     SIO

    AUXOUT: =     SIO

    LST:    =     LPT

    Enter new assignment or hit RETURN:

The section of this display you are interested in is the list of Current Assignments. CONIN: etc. on the left of this list are CP/M's logical devices; CRT etc. on the right are the physical devices to which the logical devices are currently assigned. Any Null Devices listed aren't real devices: they just record that these logical devices are unassigned. (Note: Output sent to a Null Device is simply thrown away.)

The line of this list to look at is the one for LST:. If this reads LST:=LPT, all is well and you should just press [Enter]. (The [Enter] key is the equivalent on the Spectruom of the RETURN key mentioned in the message.) If this line shows any other assignment, you should type:


    LST:=LPT [Enter]

Initialising the printer

When you initialise a printer, you typically clear its buffer of any text that might be waiting to be printed and then set how the printer will operate. In particular, you might set:

These are all aspectes of printing that can be set by sending special Printer Control codes to the printer, details of which should be given in the printer's own user guide. So the problem comes down to how you can send these codes to the printer.

One way of sending these codes is by running a BASIC program containing a number of LPRINT commands: this is described in Part II, Section 3.5. What we describe here is an alternative method in which you set up the details of the codes in a special file, called a Printer Definition file, and then use the CP/M utility SETLST to send the contents of the file to the printer. This method is very useful if you always need to set up the printer in a particular way because SETLST command can very easily be included in your PROFILE.SUB file and executed as part of loading CP/M.

The first part of the job is to set up the Printer Definition file. The codes are all single characters and they can be entered in the printer definition file in a number of different ways - char, ^'value', ^char or ^'name', depending on the code. Here char is the character corresponding to the code, value is either its decimal or hexadecimal value, ^char is the control code Control- char, and name is the special name associated with the code (see Appendix II.2). For example, the code corresponding to the capital letter A (decimal value 65) can be entered as A or as ^'65' or as ^'#41', while the control code Control-M (decimal value 13) which generates a Carriage Return can be entered as ^'13', ^'#0D', ^M or ^'CR'. However, the codes corresponding the characters ^ and " cannot be entered as char but they can be entered as ^^ and ^", respectively.

Printer Definition files are typically not very long. For example, the whole file might just be:


    ^'ESC'@^'ESC'l^'0'^'ESC'Q^'139'^'SI'^'ESC'd

This example string is made up of codes that are used by Epson-compatible printers. If this string were sent to such a printer, it would:
-reset the printer into FX-80 mode: ESC @
-set the left margin at character position 0: ESC l(lower case L)0(value zero)
-set the right margin at character position 139: ESC Q 139
-set Condensed (17 pitch characters): SI
-Make this the default set-up for the printer: ESC d

Note: Spaces between the codes are not significant in this file, so you can space the individual codes out any way you like.

Once you have created the Printer Definition file, you can initialise the printer simply by typing the command:


    SETLST filespec

For example, if your Printer definition file is called PRINTER.DEF, then the command you need is simply:


    SETLST PRINTER.DEF

Note: The printer that this command initialises is the one that is currently addressed by the logical device LST:. This normally points to the built-in Printer port, but this can be changed by using a DEVICE command. (For details, see the description of the DEVICE command in Chapter 5.)

Disabling the timeout

As a rule, CP/M Plus automatically times out sending information to a device in order to prevent the system 'locking up' completely because the information is being sent to a non-existent device. So, for example, if Control-P is typed accidentally when no printer is connected, CP/M will recognise after about 30 seconds that no printer is responding and produce a message like this:


    LPT not ready - Retry, Ignore or Cancel?

You can then either switch the printer on-line and Retry - or type C for Cancel. (Note: If you do select the Cancel option, you should follow this up as soon as possible by using DEVICE (as described above in the section on 'Sending printer output to the Printer port') to link LST: with a suitable physical device. Typing C told CP/M to throw away any further output that you or your program tries to send to the LST: device - which might not be what you want!

Unfortunately, some printers take such a long time feeding a sheet of paper that CP/M times out before the operation has finished, requiring you to type R to continue. The better solution is to disable the timeout for the device by using the TIMEOUT command:


    TIMEOUT device OFF

When you want timeout in operation again, you then simply type the command:


    TIMEOUT device ON

WARNING: IF 'TIMEOUT OFF' IS SELECTED FOR A DEVICE THAT IS NOT FITTED, CP/M WILL LOCK UP.

Ensuring that output is transferred correctly

Protocol

A standard issue in any kind of data transfer is how you ensure that data is transferred only when the receiver at the other end of the line is ready for it. This involves either establishing a protocol, under which the receiver sends specific codes to interrupt and to re-start the flow of data, or using one line of the cable between the two devices to signal when to stop and when to re-start. The latter method is known as handshaking.

When the Spectrum is attached to a parallel printer via the Printer port, handshaking between the two devices is automatically established and there's no protocol to be set up. You don't have to do anything.

A possible problem

It is possible that all of your printing comes out with double-line spacing under CP/M, even though you may have been printing satisfactorily on the same printer under Spectrum +3DOS. The problem can also occur in reverse, with the printer working fine under CP/M but each line simply overprinting the previous one under +3DOS. The reason for this effect is that Spectrum +3DOS normally sends only a carriage return (CR) code to the printer at the end of a line, while CP/M sends both a carriage return code and a line feed (LF) code.

So that most printers can move to the start of a new line correctly in both cases, most printers have an 'AUTO-LF' option with the following effect:

How you select or de-select AUTO-LF depends on your printer. The following notes, read alongside your printer's own manual, should help you decide what you need to do in your particular case. We also describe what actions are required in the specific case of a few popular printers.

Selection via option switches:

Many printers have one or more blocks of little switches (often in rather inaccessible places, but your printer manual should tell you where!), which provide various options, one of which may be used to determine the way in which CR is handled. If your printer has an option switch for AUTO-LF, simply set it to on when using +3DOS and off when using CP/M. (But see also the comments in 'Selection via escape sequences' and 'Using the AUTO FEED XT signal' below.) Note: Always turn off the printer before adjusting any option switches, and wait for at least five seconds before turning on again. The printer will then work to the new setting(s) of the option switches.

IMPORTANT:

  1. A fer printers have an option switch marked 'AUTO-CR'. This is not to be confused with AUTO-LF, as AUTO-CR means that any line feeds will have the side effect of producing a carriage return. The setting of this option switch in fact makes no difference here since any extra CRs have just the same effect as the CR code the software is giving us anyway!
  2. Just to add to the confusion, a few printers have yet another option switch marked 'AUTO CR/LF'. This switch allows a CR code and an LF code to be generated automatically when the print head passes the right-hand margin. Again, the setting of this switch makes no difference here.
Selection via escape sequences

With some printers, you can use escape sequences to control the interpretation of the CR code, over-riding the setting of any option switch. There are normally two sequences, one to select AUTO-LF and one to select CR only. The initial selection will normally be the option switch setting.

If your printer has this facility, we suggest you set the option switch for AUTO-LF, so that the printer will work correctly under +3DOS. When you want to print from CP/M, you need to send the sequence for 'CR only' before sending output to the printer (and to send the sequence for AUTO-LF prior to leaving CP/M). This may be done, for example, using Mallard BASIC and LPRINT commands. (The description of the Qume Sprint below gives an example of this.)

Using the AUTO FEED XT signal (Parallel printers only):

With many parallel printers, the way in which CR is handled depends on AUTO FEED XT signal, which appears at pin 14 of the parallel interface. The Spectrum permanently grounds this signal, which means that these printers will give AUTO-LF, whatever the setting of any other options. This can only be over-ridden by software if the printer has special escape sequences for setting the handling of CR. The only alternative is to cut line 14 on your parallel printer interface cable. (Line 1 will usually be marked by a red line down its length.)

A few printers do not give you the choice, but will always AUTO-LF on receiving a CR code. This is not a problem under +3DOS, but may be a problem under CP/M depending on how the LF code is treated by the printer. If the LF code is ignored by the printer, or ignored whenever the preceding character was a CR, you have no problem. If, however, the LF code always causes a line- feed, or if it is treated in exactly the same way as the CR code, all CP/M software using the printer will produce double-spaced text, unless the software can be 'configured' to cope with this.

Examples

Amstrad DMP3000 and DMP4000 series: These printers use pin 14 to force AUTO-LF, so this interface line must be cut if it is connected on your cable. (Note: This pin is referred to as AFD rather than AUTO FEED XT in the manual.) You then need to set the DS1-4 option switch to OFF for CP/M or to ON for +3DOS. The option switches are in two blocks at the back of the printer. DS1-4 is the fourth from the left on the left-hand block (looking from the back).

These printers do not have an escape sequence for setting or clearing AUTO- LF.

Amstrad LQ3500: AUTO-LF is selected in very much the same way as on the DMP3000/4000 printers described above. The only difference is that the switch we have to set is DS2-2 - ie. the second from the left, on the right-hand block of option switches.

Epson FX-80: This printer also uses the AUTO FEED XT signal, so the interface cable must have line 14 disconnected. You then have to set the SW2-4 option switch to OFF for CP/M or to ON for +3DOS.

The option switches are all under an access cover on the right-hand side of the printer. This cover is held in place by a single cross-point screw. If you remove the cover, you will see two blocks of option switches, one of which has eight switches (SW1) and the other four (SW2). The AUTO-LF switch (SW2-4) is the one in the SW2 block nearest to the SW1 block.

The printer does not have an escape sequence for setting or clearing AUTO-LF.

Epson LQ-2500+: This printer has both parallel and serial interfaces built in. If you are using the parallel interface, the interface cable must have the AUTO FEED XT line (line 14) disconnected. In both cases, you need to use the 'SelecType' from panel (which consists of four buttons and a liquid crystal display) as follows to inspect and, if necessary, change the AUTO-LF option:

  1. Check that the printer is ON-LINE (ie. the display showing ON-LINE and the light by the ON-LINE button lit: if not, press this button).
  2. Press the two right-hand buttons together, until the printer 'beeps' at you, whereupon you will see SelecType MODE on the display.
  3. Press the MENU button three times, or until the display shows *CHANGE DEFAULTS.
  4. Press the SETTING button twice, until the display shows >AUTO LINE FEED, together with the current setting - On or Off.
  5. AUTO LINE FEED needs to be OFF for CP/M or ON for +3DOS. To change the option, simply press the OPTION button.
  6. Finally, press the MENU button twice. The display will then show DEFAULTS SAVED, followed by *PRINT OUT SETTINGS.
  7. Turn off the printer, wait a minimum of five seconds, and then turn on again. This will select the option(s) you have set.

Juki 2200: This printer always produces an LF code in response to a CR code. However LF is ignored if it immediately follows a CR, so the Juki 2200 should print satisfactorily from both +3DOS and CP/M.

Qume Sprint 11: There are several models of this printer, some of which use a serial interface and some a parallel interface. Neither of the interfaces use a signal to control AUTO-LF, so no alterations are needed to the interface cable. Instead, the Sprint 11 has escape sequences for handling AUTO-LF: ESC , to turn ON AUTO-LF (for +3DOS) and ESC . to turn OFF AUTO-LF (for CP/M). You should also set the printer's AUTO LINE FEED switch. The commands to send these sequences from Mallard BASIC are as follows:
LPRINT CHR$(27) + "," to turn AUTO-LF ON.
LPRINT CHR$(27) + "." to turn AUTO-LF OFF.

There are three sets of option switches to contend with on this range of printers, including one set on the interface module. The Sprint 11/40 and 11/55 Plus have one set of switches at the front and another at the back: the Sprint 11/90 Plus has two sets at the back. The AUTO LINE FEED switch is the 'Front' SW4 switch on the 11/40 or 11/50 Plus, or the 'Back left' SW7 switch on the 11/90 Plus. Since we can control AUTO-LF by sending escape sequences, this switch may be left ON (the setting required for +3DOS).

4.2 Setting up the parallel Printer port

The RS232/MIDI Port on the back of the Spectrum +3 provides a suitable Serial Interface for a Serial printer. (If you have a Parallel printer, you will have to connect it to the Spectrum's parallel Printer port, as explained in Section 4.1)

Unfortunately, using a printer with a computer is rarely just a matter of connecting the two together. Some programs do all the hard work for you where the printer's own defaults don't give you the settings you want but often it falls to you to ensure that:

In addition, CP/M has a built-in timeout mechanism to stop your system 'hanging up' if you accidentally try to send some output to a printer (say) when none is connected. However, this can work against you rather than for you if it takes your printer a long time to feed a sheet of paper - so you might also need a way of overriding the timeout mechanism.

There are CP/M commands to do all these things. The details are given below.

Sending output to the RS232 port

As we pointed out in the introduction to this chapter, the key to directing output to a particular device is in linking the logical device associated with this output to the correct physical device. In the case of printer output and the built-in RS232 port, this means linking the LST: logical device to the SIO physical device.

Immediately after CP/M is loaded, LST: is assigned to LPT - the Printer port, so before you use your serial printer you need to re-assign it to SIO. The command line to use is simply:


    DEVICE LST:=SIO

In addition, there are various aspects of the data transfer you might have to set - in particular:

A DEVICE command will let you set the baud rate and protocol (see Chapter 5 for details) but the command that lets you set all these parameters is the SETSIO command.

The details you set depend on your printer, but the following command line illustrates the sort of command you might need:


    SETSIO 300, BITS 8, STOP 1, P NONE, XON OFF, H ON

The first figure is the baud rate - that is, the rate at which data is sent to the printer in bits per second. The allowed baud rates are 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600 and 19200. Your printer manual will tell you which rate to choose: if there is a choice, the general rule is to opt for the highest rate you can.

The next three parts of the command define the structure of the data - the number of data bits, the number of stop bits and the type of parity (used to check that the data is being transferred correctly). P stands for PARITY. Note: You can use either the full name or the first initial for any of these options.

The XON protocol and H (Handshake) options define the signalling system used for the transfer. Selecting the protocol option means that the printer will send codes to the computer to tell it when it is ready to receive more data. Selecting the handshake option means that a line of the cable is monitored to see when the printer is ready to receive further data.

The RS232 port is a fairly simple device and so handles input and output in a very simple fashion. As a result, you may experience problems using the XON protocol because this involves receiving information at the same time as sending it. So we recommend you to specify XON OFF and to use the Handshake option instead, just as we do for parallel printers (see Section 4.1).

Further details of the SETSIO utility are given in Chapter 5.

Initialising the printer

When you initialise a printer, you typically clear its buffer of any text that might be waiting to be printed and then set how the printer will operate. In particular, you might set:

These are all aspectes of printing that can be set by sending special Printer Control codes to the printer, details of which should be given in the printer's own user guide. So the problem comes down to how you can send these codes to the printer.

One way of sending these codes is by running a BASIC program containing a number of LPRINT commands: this is described in Part II, Section 3.5. What we describe here is an alternative method in which you set up the details of the codes in a special file, called a Printer Definition file, and then use the CP/M utility SETLST to send the contents of the file to the printer. This method is very useful if you always need to set up the printer in a particular way because SETLST command can very easily be included in your PROFILE.SUB file and executed as part of loading CP/M. Details of this method are given in Section 4.1.

IMPORTANT: Before you use either of these methods, you must direct the logical printer LST: to the RS232 port, by using the command:


    DEVICE LST:=SIO

Disabling the timeout

As a rule, CP/M Plus automatically times out sending information to a device in order to prevent the system 'locking up' completely because the information is being sent to a non-existent device. So, for example, if Control-P is typed accidentally when no printer is connected, CP/M will recognise after about 30 seconds that no printer is responding and produce a message like this:


    SIO not ready - Retry, Ignore or Cancel?

You can then either switch the printer on-line and Retry - or type C for Cancel. (Note: If you do select the Cancel option, you should follow this up as soon as possible by using DEVICE (as described above in the section on 'Sending printer output to the Printer port') to link LST: with a suitable physical device. Typing C told CP/M to throw away any further output that you or your program tries to send to the LST: device - which might not be what you want!

Unfortunately, some printers take such a long time feeding a sheet of paper that CP/M times out before the operation has finished, requiring you to type R to continue. The better solution is to disable the timeout for the device by using the TIMEOUT command:


    TIMEOUT device OFF

When you want timeout in operation again, you then simply type the command:


    TIMEOUT device ON

WARNING: IF 'TIMEOUT OFF' IS SELECTED FOR A DEVICE THAT IS NOT FITTED, CP/M WILL LOCK UP.

4.3 Using your Spectrum +3 for communications

You may well want to link your computer via a modem to electronic mail services like Telecom Gold or one of the many computing Bulletin Boards.

The RS232/MIDI Port on the back of the Spectrum +3 provides a Serial Interface which can be used from CP/M. However, while this interface is perfectly adequate for using with a Serial printer, it is not ideal for communications because it can only handle input and output in a very simple fashion. It does not work well with the simultaneous input and output that are part and parcel of using a modem.

If you want to use electronic mail, you need to attach a dedicated Serial Interface to the Expansion I/O socket on the back of the Spectrum and connect your modem to this. You also need to have suitable communications software to access the various electronic mail facilities. You may well find the interface and the communications software all provided in a single pack (the Spectre Comms Pack, for example, does this) or you may have to buy them separately. Consult your dealer for details.

As well as attaching your modem to your Spectrum and having communications software to run, you also have to ensure that data is transferred correctly along the line - very much as you do when you want to send output to a printer. The main difference is that CP/M doesn't normally access the Expansion port; for a start, it doesn't have a physical device name for it. So first you have to configure CP/M so that it can access this port and then you have to set up the details of the data transfer. Special software is supplied to do this, described below in 'Accessing the Expansion port' and in 'Setting up the Expansion port'.

The other feature of working with communications is that you need your computer to be constantly able to react to information being sent to it. Your modem needs to send information at any time and cannot be told to wait for computer to carry out some other task. The general task that takes too long is updating the screen. How you stop this from affecting your data transfer is described below in 'Communications and the screen'.

Again, it is a good idea to include the commands you need in your PROFILE.SUB file.

Accessing the Expansion port

CP/M itself ignores the Expansion port, so special steps need to be taken to access it. These are outside 'normal' CP/M, and in fact have been set up specially for the Spectrum +3 by Locomotive Software.

Essentially what happens is that CP/M's list of physical devices is expanded to include the Expansion port. This is done through a special extension to CP/M stored in the file SERIAL.FID. If this file is on your CP/M Start-up disc, then this is loaded at the same time as CP/M and the Expansion port becomes available as the physical device SERIAL. If this file isn't on the disc or it is given another name, then the Expansion port is ignored.

SERIAL.FID is supplied on Side 2 of the master disc. So to use the Expansion port, you have to copy this file to Side 1 of your CP/M Start-up disc. This can be done readily enough by using PIP (as described in Section 3.3). Before you do this, however, do check that you have at least 1k free on Side 1 of your Start-up disc to store SERIAL.FID. You may have to erase one of the utilities currently one Side 1 to make room for it. (You can always make a copy of the original of this utility on your Master disc and store this on Side 2 of your Start-up disc in place of the SERIAL.FID you have moved.)

Once you have SERIAL.FID on Side 1 of your CP/M Start-up disc, you can re- load CP/M. Now you should see the message SERIAL vx.x installed added to the initial Start-up message: this tells you that CP/M has been successfully configured and SERIAL has been added to its list of physical devices.

You can then link the two logical devices used by your communications program (AUXIN and AUXOUT) to the SERIAL physical device, by using the following DEVICE command:


    DEVICE AUX:=SERIAL

You now have access to the Expansion port and so to your modem. Before you use this, however, you need to define how the data is to be transferred. How to do this is described below.

Setting up the Expansion port

The Expansion port needs to be set up so that it sends information to the modem in the correct form for the modem to handle and also so that it interprets any information it receives back from the modem correctly. The utility you use to do this is called STSERIAL, and it too has been specially written for CP/M on the Spectrum.

STSERIAL is essentially just like SETSIO. It allows you to set:

The details you set depend on your modem and the service you are linked to, but the following command line illustrates the sort of command you might need:


    STSERIAL 300, BITS 8, STOP 1, P NONE, XON ON, H ON

The first figure is the baud rate - that is, the rate at which data is sent to the printer in bits per second. The allowed baud rates are 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600 and 19200. Read your modem manual to discover which rate to choose.

The next three parts of the command define the structure of the data - the number of data bits, the number of stop bits and the type of parity (used to check that the data is being transferred correctly). P stands for PARITY. Note: You can use either the full name or the first initial for any of these options.

The XON protocol and H (Handshake) options define the signalling system used for the transfer. Selecting the protocol option means that the printer will send codes to the computer to tell it when it is ready to receive more data. Selecting the handshake option means that a line of the cable is monitored to see when the printer is ready to receive further data.

Further details of the STSERIAL utility are given in Chapter 5.

Communications and the screen

Scrolling text on the screen as new information is displayed takes a significant amount of processor time and therefore means your Spectrum could well be busy when your modem is trying to send it information. There isn't any way of telling the modem to wait: it just passes the information it receives on as fast as possible. Instead, the answer is to use the screen in the alternative 'Page' mode. In this screen mode, new information wraps round from the bottom of the screen to the top, and then proceeds to overwrite the existing display. This is a very much faster operation than scrolling the whole screen.

Page mode is turned on and off by sending Escape sequences to the screen. The sequences you use are detailed in Appendix III and are typically sent to the screen from a program such as BASIC. However, they can also be sent by pressing keys while the A> prompt is displayed - in exactly the same way as you can press keys to turn the Status line on and off (see Section 1.3). The keys to press are as follows:

Note: If you need both to turn Page mode on and to set the Screen size, then set the Screen size first. Setting the Screen size always turns Page mode off.

Further details of Page mode are given in the technical description of CP/M Plus on the Spectrum (Appendix VI.1).

4.4 Configuring the Memory Disc

The CP/M system supplied on the disc is set up to give you a 12k Memory Disc while you work with CP/M. This gives you an area of memory which can be used to hold copies of a few frequently used programs or files, which in turn means that you can use these without changing the disc in the drive. The supplied PROFILE.SUB, for example, uses it to store copies of PIP and SET24X80 - two utilities which we expect you to want to have to hand.

The Memory Disc is accessed as Drive C.

The size of the Memory Disc is very small (the Spectrum has insufficient memory for it to be any larger) and so you may not find it very useful. The memory used for the Memory Disc doesn't affect the amount of working area for your programs (the TPA) but it does reduce the size of the buffer available for file transfers. It therefore makes reading or writing to disc slightly slower.

If the type of work you do means that your programs are for ever reading or writing files on disc and you don't want to use the Memory Disc, simply erase or rename the file RAMDISC.FID on the CP/M Start-up disc. This file holds a special extension to CP/M which sets up the Memory disc at the time CP/M is loaded: without this file on your Start-up disc, no Memory disc is formed.

Note: RAMDISC.FID provides a very good model of how you extend CP/M to support additional block devices. Anyone intending to extend the CP/M on the Spectrum to support a hard disc, for example, could usefully start from a copy of RAMDISC.FID. Further details are given in the description of field installable devices (Appendix VI.5).

4.5 Selecting the appropriate national language

When you use a program or a data file that has been prepared by someone else you may find that some of the characters are displayed 'wrong'. For example, you might see #s where you expect to see £s.

The reason for this effect is that you are using a different national language version of CP/M to the one used when the program or data file was set up. The selection of characters made available on computers sold in different countries are subject to national variations. As a result, CP/M has different national language versions of the screen characters.

Immediately after you load CP/M, it is set up to use the US character set - because the CP/M programs you buy are likely to assume that you are using this character set. Full details of this character set are given in Appendix II. When using particular programs or data files you may have to ensure that you are using the national version of CP/M that was used when the program or data file was set up. Otherwise some of the characters will appear to be misinterpreted.

All the different characters CP/M displays are actually handled as codes. The codes CP/M uses are simply numbers in the range 0...255 (though for many reasons, these numbers are usually written as two-digit hexadecimal numbers - that is, numbers given to the base of 16 - preceded by a # to show that a hexadecimal number follows). A handful of these codes represent different characters, depending on which national language is selected. For example the code #5D (decimal 93) represents ] in the English version of CP/M but in the German version. These language differences affect the character displayed in response to certain character codes in your data files.

All the different national language versions of CP/M are supported on the Spectrum +3 and a special utility has been incorporated into the CP/M system to allow the user to swap from one national language to another. This is the LANGUAGE utility. The instruction to adopt a particular national language is LANGUAGE n, where n is the number between 0 and 7 that corresponds to required language as follows:
0USA
1France
2Germany
3UK
4Denmark
5Sweden
6Italy
7Spain

On the Spectrum, the same range of characters can be displayed in all the different language versions: it is simply the codes used to represent certain characters that change.

The 'standard' set of codes and characters represented by these codes is the US character set. What happens in the other language versions is that certain codes in the first half of the character set (0...127) are associated with characters that are in the second half of the US character set and vice versa. In fact a straight swap is made between the code used for the special language character, and the character it substitutes. For example, in the US character set, the code for £ is #A3: when English is selected, £ replaces # as the character with code #23 - and # replaces £ as the character with code #A3.

The characters affected are shown in the table opposite. This shows the codes in the first half of the character set (0...127) that are displayed differently depending on which national language is selected and the characters they represent under the different languages. What you need to notice is where the character shown in the column for the national language you select is different from that shown in the US column: the codes used for both characters are affected by the change of language.

As well as changing how certain character codes in your data files will be displayed, changing from one language to another also affects which characters are displayed on the screen when you press particular keys. For example, under language 0 (US) pressing [Symb Shift] + D causes a backslash (\) to be displayed, but under Language 1 (French) the displayed character will be and under Language 7 (Spain) it will be .

The key combinations affected are the ones that generate the character codes which are associated with different characters depending on which national language is selected.

To find out the key combination to display the special language character in the language you are using, simply find the character in the appropriate language column of the table. The key combination you need is the one given in the same row of the table.

To discover the keystroking to use for the character it has displaced, find out from Appendix II.2 the key combination for the special language character when the US character set is selected: this is the key combination you need to use for the 'displaced' character.

Note: The keyboard continues to enter the same character codes. Changing language only affects the characters displayed on the screen as the result of your typing.
Hex US French German UK Danish Swedish Italian Spanish Key combn.
#23 # # # £ # # # Pt [Symb Shift] + 3
#40 @ @ @ @ @ [Symb Shift] + 2
#5B [ [ [Symb Shift] + Y
#5C \ \ \ [Symb Shift] + D
#5D ] ] [Symb Shift] + U
#5E ^ ^ ^ ^ ^ ^ ^ [Symb Shift] + H
#60 ` ` ` ` ` ` [Symb Shift] + I
#7B { { [Symb Shift] + F
#7C | | [Symb Shift] + S
#7D } } } [Symb Shift] + G
#7E ~ ~ ~ ~ [Symb Shift] + A

4.6 Redefining the keyboard

When you load the CP/M operating system, the keyboard is automatically set up so that the key combinations given in Appendix II.2 produce the characters listed in that section. In addition, the 'function' keys ([Edit], [Graph] etc.) have been set up to generate some of the CP/M Control codes. (Details of these keys and the Control codes they generate are given in Appendix II.2.2.)

The range of characters and codes and the key combinations you use to produce them have been selected to suit most of the CP/M applications programs that you will run on your Spectrum +3. However, this selection omits many characters that you may need to be able to type if, say, you want to prepare text in foreign languages and it won't necessarily suit every program that you want to run. A number of programs are designed to be used with a keyboard that is set up so that pressing a function key gives a particular action within the program. For example, WordStar could be set up so that pressing [Edit] deletes a line of the text.

Alternatively, you might simply want to set up your keyboard so that pressing a function key gives you a complete CP/M command line - to save you the effort of typing this command. This can be very helpful when you want to make your applications programs easy to use by someone who may not understand CP/M.

You get these facilities by re-defining the codes that particular key combinations generate, before you run the applications program in which you want to use the new definitions.

The permitted key combinations are the key on its own, [Caps Shift]+key, [Symb Shift]+key and [Extend Mode] (or [Caps Shift] + [Symb Shift])+key. [Caps Shift]+key, [Symb Shift]+key and [Extend Mode] are known as the Shift Keys.

To re-define your keyboard, you need a file containing details of the key combinations you want to re-define and the codes you want these keys to generate when you press them. This file is known as a Key Definition File and you can have a number of these on your discs - for example, one for when you want to use your spreadsheet program and another for when you want to play a particular computer game.

We describe how to set up a Key Definition File below.

Once you have the Key Definition File you require, you put all the changes it lists into practice by using a special CP/M utility called SETKEYS. This utility is stored on the CP/M Start-up disc. Running SETKEYS sets up the keys to have the meanings specified in the file - ready for running your chosen application program.

For example, the command:


    SETKEYS KEYS.WP

will implement the key definitions in KEYS.WP (assuming that SETKEYS.COM is on the search path and KEYS.WP is on the default drive).

The changes implemented by running SETKEYS will stay in force until you take steps to change these key definitions again or you reset your computer. Resetting your computer automatically sets up the keyboard afresh in the standard way.

Before you run a different program, you will probably want either to return to using the standard CP/M keyboard or to use another set of key definitions.

To return to using the standard CP/M keyboard without resetting your computer, you run SETKEYS with a special Key Definition file on the CP/M Start-up disc called RESET.KEY. Simply insert the CP/M Start-up disc in Drive A and type the command:


    A:SETKEYS RESET.KEY

To use another set of key definitions, you use another SETKEYS command as you might expect - but first, you need to restore the keyboard to the standard CP/M set of definitions as your Key Definition file will have been set up assuming that the standard keyboard will be in use immediately before the new definitions are implemented by SETKEYS. So, in this case, you should run SETKEYS with the RESET.KEY file as described above, before you use it with the new Key Definition file to implement the new definitions.

Key numbers

17* 18* 15 16 17 18 19 24 23 22 21 20 35*
20* 21* 10 11 12 13 14 29 28 27 26 25
0 + 36 15* 5 6 7 8 9 34 33 32 31 30
0 16* 1 2 3 4 39 38 37 37+ 0
36 26+ 25+ 19* 22* 35 23* 24* 38+ 36

* Also generates Caps Shift (Key 0)
+ Also generates Symb Shift (Key 36)

4.6.1 Setting up the Key Definition File

A Key Definition File is simply a text file that contains a list of the key combinations you want to redefine and the codes you want these key combinations to generate. Where necessary, the file also contains details of the command that you want the code to correspond to.

The lines of the Key Definition file that define the code that you want a particular key combination to produce, all have the form:


    key-number shift-state "code" [optional-comment]

The key-number specifies the character or function key that you will want to use in the key combination. These key numbers are shown in the diagram above. From this diagram you will see, for example, that when you want to specify the 1 key, you use the key number 15.

The shift-state specifies which of the 'Shift' keys [Caps Shift], [Symb Shift] and [Extend Mode] are included in the key combination. These keys are represented by a single letter - C for [Caps Shift], S for [Symb Shift] and E for [Extend Mode] (which is equivalent to [Caps Shift] + [Symb Shift]), along with N for Normal or Nothing (ie. unshifted).

Warning: Pressing many of the special function keys is exactly equivalent to pressing a letter or a digit key and either [Caps Shift] or [Symb Shift]. To specify these keys, you need to give both the key number and the letter representing this built-in Shift state. This is shown on the diagram above by putting * or + after the key number.

The code can be specified in a number of different ways:

The optional comment is any text that you care to include on the same line to remind you what the line does.

To make this clearer, we shall now look at three specific examples.

  1. Suppose, you wanted to specify that the key combination [Extend Mode] + N should produce the character .

    The N key has the key-number 38. Combining this key with [Extend Mode] means that the shift-state you want is E. The character you want has the value 249 or #F9. So the line to have in the Key Definition File would be:

    
        38 E "^'249'" Ext.mode N = L.case N tilde
    
    
    or:
    
        38 E "^'#F9'" Ext.mode N = L.case N tilde
    
    
    Ext.mode N = L.case N tilde is simply the commend we have included so that we can readily work out what this line of the file does if we look at it again some time later, eg. next week.
  2. Suppose you wanted to specify that the key combination [Extend Mode] + [True Video] should produce a Form Feed character.

    The [True Video] key has the key-number 18. Combining this key with [Extend Mode] means that the shift-state you want is E. The Form Feed character is the Control code with the name FF, and so the line you want in the Key Definition File would be:

    
        18 E "^'FF'" [comment]
    
    
    (The Form Feed also has the value 12 or #0C, so you could equally well make this line 18 E "^'12'" or 18 E "^'#0C'".
  3. Suppose you wanted to specify that pressing [Graph] enters the command line that runs Mallard BASIC - ie. BASIC [Enter]

    The first thing to consider is which Token you will use to represent this command line. Tokens are codes with values 128...158 (#80...#9E), but the tokens with values 128...139 have already been set up so unless you want to overwrite one of these, we would suggest using another token - say 140 (#8C).

    Having decided on the token you are going to use, you need a line in the Key Definition File that associates this token with the key combination you want to use. In this case the key combination is key-number 21 in shift-state C - because the [Graph] is set up to always act as if the [Caps Shift] key is pressed - so the line you need is:
    21 C "^'140'" [comment] (or, alternatively, 21 C "^'#8C'")

    You also need a line in the file that tells CP/M how to interpret this token. This line has the form:

    
        E token "string"
    
    
    where token is the value of the token you are setting and string is the string of characters and codes that you want the key to produce for you. Again, characters can be entered in this string as char or ^'value'; Control codes can be entered as ^'value', ^char or ^'name'.

    These two lines can appear in any order in the Key Definition file.

    In this example, we want to make pressing [Graph] (which we have already associated with token 140) produce the command line BASIC [Enter]. What pressing [Enter] does is send the Control code Control-M which is also known as CR, so the string we require is simply BASIC^M or alternatively BASIC^'CR' - giving us the complete line:
    E 140 "BASIC^M" or E 140 "BASIC^'CR'"

    Note: The example here both associates a token with a key combination and defines the string of characters and codes associated with this token. If you want to associate one of the supplied tokens with a particular key combination, you will just need the line that specifies the key combination and the token. If you want to keep the existing token but change its meaning, you just want the line setting the expansion token to the required string.

    Important: You can have a maximum of 120 characters and codes in these special strings - and the supplied set total about 30.

4.6.2 Making the redefined keyboard your standard

If you want to make the key definitions within a particular Key Definition file the standard as far as your machine is concerned, you can do this with the aid of the PROFILE.SUB file. All that is required is a line in that file that tells the system to run the SETKEYS utility, taking as its source your Key Definition file.

You will find more about the PROFILE.SUB file in Section 3.15 ('Shortening the command line').

4.7 Redirecting console input and output

Programs are usually designed to take additional information from the keyboard and to send program output to the monitor, unless told otherwise.

This section describes how you can use CP/M to

without any part of the program having to be re-written. This provides a way of, for example, transferring printer-output to your word-processing program.

4.7.1. Getting input from a file

The command that tells CP/M that your program's input is to come from a file is:


    GET CONSOLE INPUT FROM FILE filespec

This command, which should be typed immediately before the command that runs your program, tells CP/M to arrange that the program reads this file whenever it wants details that it would normally take from the keyboard. For example, the two commands


    GET CONSOLE INPUT FROM FILE MYFILE.DAT

	MYPROG

mean that all the keyboard input required by the program MYPROG is to be taken from the file MYFILE.DAT.

The program continues to take its input from this data file until it runs out of information - or the program finishes. Normally, everything that is taken from the file is also displayed on the screen and when the program finishes, CP/M reverts to taking information from the keyboard regardless of whether all the data in the file has been used.

If you don't want the information to be displayed on the screen or if you want CP/M to carry on taking keyboard input from this file, you have to specify this through options added to the end of your GET command:

NO ECHO
Stops the information being displayed on the screen
SYSTEM
Tells CP/M to continue to take keyboard input from the file after the program has finished. Of course, the next item of information in the file in that case must be the command to run another program.

To use one of these options, you put it between square brackets at the end of the command line; to use both options, you put them both in the same pair of square brackets separated by a comma. For example:

GET CONSOLE INPUT FROM FILE MYFILE.DAT [NO ECHO]
tells CP/M that information taken from MYFILE.DAT shouldn't be displayed on the screen.
GET CONSOLE INPUT FROM FILE MYFILE.DAT [SYSTEM,NO ECHO]
tells CP/M that both information and CP/M commands should be taken from MYFILE.DAT and that these should not be displayed on the screen.

Normally, when you specify the SYSTEM option, information and commands will be taken from this file until the file is exhausted. However, you can if you want include a command in the file which tells the system to take its input from the keyboard again even though information still remains in the file. This is the command:


    GET CONSOLE INPUT FROM CONSOLE

4.7.2 Sending output to a file

The commands that tell CP/M that your program's output is to be sent to a file are:
PUT CONSOLE OUTPUT TO FILE filespec(Screen output)
and PUT PRINTER OUTPUT TO FILE filespec(Printer output)

These commands, which should be typed immediately before the command that runs your program, tell CP/M to arrange that the output from the program should be sent to the given files. For example, the commands


    PUT CONSOLE OUTPUT TO FILE MYPROG.SCN

    PUT PRINTER OUTPUT TO FILE MYPROG.PTR

	MYPROG

would mean that all the screen output from the program MYPROG should be stored in the file MYPROG.SCN and that all the printer output from this program should be stored in the file MYPROG.PTR.

Normally, the printer output from the program is now sent just to the given file but the screen output continues to be displayed on the screen as well. Moreover, when the program finishes, CP/M reverts to sending printer output to the printer and screen output just to the screen.

If you don't want the information to be displayed on the screen or you still want the printer output to be printed, you have to specify this through options added to the end of your PUT commands:

NO ECHO
Stops the information being displayed on the screen
ECHO
Tells CP/M to continue printing the printer output

These options are the exact equivalents of the ones you can use with the GET command above. As with the GET command, you put the option(s) you require between square brackets at the end of the command line - if necessary, separated by a comma. For example:

PUT CONSOLE OUTUT TO FILE MYFILE.SCN [NO ECHO]
tells CP/M that the screen output should simply be stored in MYFILE.SCN; it shouldn't be displayed on the screen as well.

If you want CP/M to carry on storing output in these files after the program has finished, you can also specify this through an option - the SYSTEM option. For example:

PUT PRINTER TO FILE MYFILE.PTR [SYSTEM]
tells CP/M to send all printer output to the file MYFILE.PTR.

However, if you use the SYSTEM option for either Screen or Printer output you also need another PUT command to tell CP/M when to stop storing this output - because otherwise it will carry on putting your output into a file until you switch off (or run out of space on the disc!).

The commands you need are:


    PUT CONSOLE OUTPUT TO CONSOLE

and

    PUT PRINTER OUTPUT TO PRINTER

Output to the screen or to the printer originally includes a number of control codes that ensure that it is laid out correctly on the screen / the printer. Normally, these codes are all automatically removed before the output is stored but if you would like to retain them, you can opt to have them converted to printable characters by specifying the FILTER option in your PUT command. (You might want this to help you transfer your output to a typesetting system, say.)

As with the other options, you select the FILTER option by putting its name between square brackets at the end of the command line. So for example:

PUT PRINTER TO FILE MYPROG.PTR [FILTER]
tells CP/M to convert all the control codes in the printer output to printable characters before storing this output in MYPROG.PTR.

Previous chapter Index Next chapter