SECTION I USING THE PRINTER from BASIC FILE INTER.I In INTRO we found out how to print out files from CP/M, and this is the best way to get printed copies of the many text files in this course, but now I want to discuss the ways in which the printer can be controlled from within the BASIC environment. LLIST This command is usually used in direct mode to print out a ===== whole program listing or part of a listing, from one line upwards. It is used in the same way as LIST but outputs to the printer instead of to the screen. As you probably realise, the program must be LOADed before LLIST will work. The commands are :- LLIST lists the whole program LLIST 2000-3000 lists lines 2000 to 3000 inclusive LLIST -300 lists all lines up to line 300 LLIST 10000- lists all lines from line 10000 onwards. This command is very easy to understand but is most useful. Use it for checking a program that you have just typed in, for studying a program, or to copy a line or lines before editing, so as to see what you started with. LPRINT More often used from within a BASIC program, but can also be ====== used in direct mode. It is used in the same way as PRINT but outputs to the printer instead of to the screen:- LPRINT " Message " Print a string LPRINT name$ Print a string variable LPRINT a% Print a numeric variable(integer) etc., The obvious use from within a program is to print out results, such as answers to calculations carried out by the computer. There would often be, built into the program, a request to indicate whether the results are to be printed to the screen or to the printer. The program would then be diverted to a section of program (a module) based on the command PRINT for printing to screen or to an identical module based on the command LPRINT for producing hard copy on the printer. A more sophisticated method is to make a temporary file in memory containing the required data or calculations arising from the program which can then be diverted to screen or printer, but this is beyond the scope of this course. *** ESCAPE CODES *** In section G we examined Escape codes which affected the screen display. There are also a number of codes which send instructions to the printer concerning type styles and paper parameters. The whole set can be seen in your CP/M manual, Appendix II "Advanced use of the printer" but in this section we see how to use them from BASIC. In the same way that screen codes were used with the PRINT command, printer codes are used with the LPRINT command. e.g:- LPRINT CHR$(27)+"M" would turn on 'Elite' typestyle. The following table shows the possible changes of state and the standard or 'DEFAULT' state. However, you can create your own default state if you wish PARAMETER DEFAULT a) Pica, Elite, Condensed or Proportionally Spaced typestyle Pica b) Upright or italic Upright c) Enlarged or ordinary size Ordinary d) Bold,double strike or ordinary Ordinary e) Superscript, subscript or ordinary Ordinary f) Underlined or no No g) Zero with or without slash Without h) National character set UK ASCII j) High quality or draft Draft k) Continuous paper or sheets Single sheet l) Left and right margins RH-0 , LH -80 m) Line spacing 1/6 in. p) Page length and gap 70 lines,gap 3 q) Paper end detection on/off Off r) Automatic line feed No s) Tabs Every eighth column You will see from this table that printing can be closely controlled from BASIC. Each of the above parameters has it's own escape code which can be written into the program, but in addition there is a very useful MIXED PRINT MODE, which enables a single escape code plus a number to specify some combinations of typestyle and emphasis, for example Bold Enlarged Elite, or Double strike condensed; but more of this later, for now we shall look at the Escape codes. Not all of these codes can be used willy-nilly as some are mutually exclusive . For example Super and Subscript will not print High Quality or Double strike, but Bold ; and Condensed will not print in Bold. Don't worry about it, just experiment to find your favourite typestyles.The programs following this text will help a lot. a) Change to ELITE typestyle (12 cpi) CHR$(27)+"M" Return to PICA (10cpi) CHR$(27)+"P" Select CONDENSED (17cpi) CHR$(27)+CHR$(15) Return to PICA (10cpi) CHR$(27)+CHR$(18) Select PROPORTIONAL spacing CHR$(27)+"p"+CHR$(1) Return to PICA CHR$(27)+"p"+CHR$(0) b) Change to ITALIC CHR$(27)+"4" Return to upright CHR$(27)+"5" c) Select ENLARGED (Doubles cpi) * CHR$(27)+CHR$(14) Cancel " CHR$(27)+CHR$(20) Select ENLARGED (Doubles cpi) ' CHR$(27)+"W"+CHR$(1) Cancel " CHR$(27)+"W"+CHR$(0) * Prints one line enlarged then returns to normal ' Prints enlarged continuously d) Select BOLD text CHR$(27)+"E" Cancel BOLD text CHR$(27)+"F" Select DOUBLE STRIKE CHR$(27)+"G" Cancel DOUBLE STRIKE CHR$(27)+"H" e) Select SUPERSCRIPT CHR$(27)+"S"+CHR$(0) Select SUBSCRIPT CHR$(27)+"S"+CHR$(1) Cancel SUPERSCRIPT or SUBSCRIPT CHR$(27)+"T" f) Select UNDERLINE CHR$(27)-"1" Cancel UNDERLINE CHR$(27)-"0" g) Select ZERO with SLASH CHR$(27)+"X" Select ZERO without SLASH CHR$(27)+"o" h) Select NATIONAL CHARACTER SET CHR$(27)+"R"+ n Where n=0 USA : n=1 French : n=3 UK : n=4 Danish n=5 Swedish : n=6 Italian : n=7 Spanish : n=8 Japanese j) Select HIGH QUALITY CHR$(27)+"x"+CHR$(1) Select DRAFT QUALITY CHR$(27)+"x"+CHR$(0) k) Select CONTINUOUS PAPER CHR$(27)+"c" Select SINGLE SHEETS CHR$(27)+"$" l) Set LEFT MARGIN CHR$(27)+"l"+CHR$(n) Set RIGHT MARGIN CHR$(27)+"Q"+CHR$(n) Where n= margin width in no. of characters of current typestyle m) Set LINE SPACING 1/8in apart CHR$(27)+"0" 7/12 in apart CHR$(27)+"1" 1/6in apart CHR$(27)+"2" Lines n/216in apart where n=0 to 255 CHR$(27)+"3"+CHR$(n) n/72in apart where n=0 to 85 CHR$(27)+"A"+CHR$(n) p) Set PAGE LENGTH in lines (n=1 to 127) CHR$(27)+"C"+CHR$(n) Set PAGE LENGTH in inches(n=1 to 22) CHR$(27)+"C"+"0"+CHR$(n) Set GAP (n=1 to 127) CHR$(27)+"N"+CHR$(n) Cancel previous GAP instruction CHR$(27)+"O" NB. Page length and gap can be used for continuous (fanfold) paper to tell the printer what the sheet length is and what gap you want left over the paper joints . The default setting is for A4 single sheets q) PAPER END DETECTION OFF CHR$(27)+"8" ON CHR$(27)+"9" r) To ADVANCE THE PAPER a specified distance Where the distance is n/216 and n=0 to 255 CHR$(27)+"J"+CHR$(n) s) Set TABS CHR$(27)+"D"+"n"+"0" Where n is a list of numbers representing the TAB positions reqd. Max no of tabs are 32. n= column nos. in ascending order. Column to immediate right of left margin is 0. Altering left margin resets tabs to default. DEFAULT SETTINGS When you "boot" CP/M and BASIC the above ================ parameters are set as shown in the first table. These values are known as the "DEFAULT" values, but as you can see, can be altered from BASIC to suit your requirements. The command lines can be entered either from direct mode or embedded in a program and each will remain in effect until cancelled. You can make your new parameters the default set by the command line :- LPRINT CHR$(27)+"d" ,and the new default set will remain valid until you switch off or reset CP/M. You could make a short BASIC file of those defaults that you want to change, ending with :- LPRINT CHR$(27)+"d" and RUN it at the start of a session After changing a parameter, it can be cancelled by issuing the reverse command line, for example to turn underlining on and off, but at any time you wish to return to the default set use:- CHR$(27)+"@". MIXED PRINT MODE Earlier I promised that we would look at a means of selecting a variety of typestyles by using one command only. This code is :- CHR$(27)+"!"+chr$(n) where n is a number between 0 and 63 For the technically minded a decimal number is interpreted by the computer into a binary number and each 1 or 0 is known as a 'bit' Decimal 63 = 111111 in Binary . 1 1 1 1 1 1 32+16+ 8+ 4+ 2+ 1 = 63 Other numbers are similarly interpreted,e.g 010100=0+16+0+4+0+0 =20 The leftmost 'bit' is no.5, the rightmost is bit no.0. Each bit represents a parameter and the table below shows this Bit no. Decimal Parameter 5 32 Enlarged 4 16 Double Strike 3 8 Bold 2 4 Condensed 1 2 Elite 0 1 Pica 0 0 Default To use this table select the parameters that you require, add the decimal numbers together and use it as 'n' in the given code; e.g CHR$(27)+"!"+CHR$(2) is Elite ; CHR$+"!"+CHR$(20) is Double strike, Condensed etc. Any number within reason (even greater than 63) can be used as 'n'; you are not restricted to those shown but the leftmost bit always takes precedence so all numbers other than additions as shown will have redundant 'bits'. Also some combinations are not permissible so if you select bold with condensed, you will get double strike with condensed. This is in line with the usual restrictions governing printing. Changing your selection is easy. Simply make your new choice and put in the new command line. The old command line is cancelled and the new takes over. AND NOW - ODDS AND ENDS There are a few codes which remain :- ======================= LPRINT CHR$(12) will execute form feed, where the sheet of paper feeds forward to it's end. LPRINT CHR$(10) executes a line feed. Unless you have special needs within a BASIC program, both these actions can be initiated from the printer status line. Press [PTR], move the cursor over the action required and press [+] An odd man out is WIDTH LPRINT n where n is a number to tell BASIC how many characters (max) to print to a line VARIABLES AND DEF FN Instead of writing the whole command line each ==================== time it is used, a code can be equated to a string variable just as any other string. For instance you could write ul$+CHR$(27)+"-1", then each time you put LPRINT ul$ you would invoke underlining, and so on. For codes which need input of a number variable use DF FN ( Define function). For example to advance the paper put :- DEF FNadv$(n)=CHR$(27)+"J"+CHR$(n) , and to use it:- LPRINT FNadv$(125) THE UNTAMED PRINTER From time to time the printer gets very =================== obstinate and will not behave as you would wish,but in reality it is behaving quite logically. When writing a program involving the printer be even more careful to save to disk before trying a test RUN. In the event of an unintentional loop causing the printer to keep printing, the only option may be to reload CP/M thus losing any part of the program not saved. Try it!!. Before asking the printer to perform think about it. It is easy to type LLIST when you really meant LLIST -200, so instead of getting the first few lines of a program you get the lot. If you do this it is easiest to let the beast carry on rather than to try to stop it. Make sure also that when the printer stops it has not simply run out of paper, as this message is not always put on screen. There is a PRINT BUFFER which holds the next characters to be printed. You may forget, or not realise, that there is more to be printed but your printer won't. If your keyboard locks up whilst printing so that not even [STOP] works this could be the problem, printer constipation. Load some paper and find out CONCLUSION This file is long, but contains a lot of reference data ========== most of which you may use but rarely, but which is of interest. We have covered the following:- 1) The command LLIST 2) The command LPRINT 3) Printing Parameters and their Escape Codes 4) Default printing parameters 5) Changing the default parameters 6) Mixed print mode 7) Putting escape codes into variables 8) Diagnosis of a printer problem The following BASIC programs will show you how the Escape Codes work and study of the LISTed program will reinforce the above text. Try to write short programs ( start at 50000 on, where you can call on the various codes - each line is a subroutine. The first is to demonstrate various combinations of typestyle chosen by yourself; each time the program cycles round the typestyle is set back to default. The second illustrates Superscript and Subscript. Superscript occupies the upper half of the line, Subscript the lower. You may find a use for it some day. Next is the Mixed mode, which can be very useful, and the last demonstrates, as far as possible, paper and type management, e.g Margins, Width, Tabs and paper advance. Hope that you enjoy them End of file INTER.I  Margins, Width, Tabs and paper a