Put Your Inkjet in Plotter Mode

Author(s): Kent Cook
Publication: SyncWare News
Pub Details: SyncWare News v4 n5 (Volume 4, Issue 5)
Date: May/June 1987
Pages: 9-12

OLIVETTI PR2300 “PLOTTER” MODE

Here is an answer to Robert Haley‘s letter in FORUM, SWN 4/2. I suspect the chief problem is understanding the PR2300 User Guide. It seems to have been written in Italian and translated into UK English (rather than American English) by someone whose first tongue was NOT English.

Awkward User’s Guide notwithstanding, the PR2300 has some things to its credit. It uses ordinary paper, it’s not expensive, and it has bit-mapped graphic capabilities.

According to the PR2300 User Guide there are two types of PR2300 firmware. I presume Mr. Haley has FWM 001, the regular ISO ASCII printer with plotter/graphics features.

Background

First of all, the PR2300 is NOT a plotter in the sense normally associated with plotting. It will not function directly as an X-Y plotter. The “PLOTTER PROGRAMMING CODES (FWM 001)” described in chapter 11 of PR2300 User Guide are the same as the “GRAPHIC MODE (FMW 001)” in chapter 6. THE PR2300 will print bit-mapped dots. This is the basis for the hi-res screen copy routines in commercial software. This feature may be used to “plot” bit-mapped data.

The PR2300 enters the graphics mode when it receives an ESC G. This command disables the PR2300’s character generator and must be followed by several parameters which define the manner in which the data will be printed.

The first is a number from 1 to 255 which tells the PR2300 which dot column to start in. In other words, this defines the left-hand margin. A semicolon must follow the margin parameter.

The second is a number from 1 to 110 which defines the width of the map in 8-bit bytes. A semicolon must follow this parameter also.

Third is a number from 1 to 255 which defines the vertical dimension of the map in 8-line rows. This parameter is optional to the PR2300 processor. If this is omitted, the bit map will be only one dot row having a length defined in the second parameter. If this parameter is expressed and followed by the fourth parameter, they must be separated by a semicolon. If this parameter is omitted, the last parameter must also be omitted.

The fourth and last parameter is also optional. It may be a number from 1 to 9 and defines the vertical resolution. Its default is 2 which gives vertical dot size equal to horizontal dot size. I like to set this to 3 for copying text. It makes it more readable for me.

The parameters must be terminated with ESC Z.

The control codes and parameters must be sent in the language understood by the PR2300, i.e. ISO ASCII. The references above to ESC G, and ESC Z mean the ASCII values for those characters must be sent to the printer. The parameters are not numerical values, but are the ASCII codes for the digits of the numbers. Leading 0’s in the parameters may be omitted. I recommend fully expressing all the parameters to make the data easier to understand and change. The table shows this better than words.

The graphics mode control code may be preceeded by either the zoom command (ESC /) or reverse image command (ESC -) or both. Zoom doubles the image horizontally and vertically. Reverse prints a negative image.

Here is an example of the command-code sequence to set up a map for a zoom image of 32 bytes horizontally by 24 bytes vertically (a ZX/TS screen map). The margin of 192 centers a zoom image on 80 column paper.

ASCII Hex Decimal

 ESC   1B   27   Zoom
  /    2F   47   Image.
 ESC   1B   27   Graphic map
  G    47   71   info to follow.
  1    31   49   Left
  9    39   57   margin
  2    32   50   =192.
  ;    3B   59   Separator.
  0    30   48   Map horiz
  3    33   51   dimension =
  2    32   50   32 8-bit bytes.
  ;    3B   59   Separator.
  0    30   48   Map vert
  2    32   50   dimension =
  4    34   52   24 8-line rows.
  ;    3B   59   Separator.
  2    32   50   Normal vert resolution.
 ESC   1B   27   End of command
  Z    5A   90   code sequence.

Please Note: These are NOT ZX-81/TS1000 character codes. ZX/TS alpha codes can be translated to ASCII by adding 27 dec; number codes by adding 20 dec.

The PR2300 will now fill the map with data bytes. The map is filled from left to right, top to bottom. Bytes are mapped MSB to LSB from left to right. When the map is full, the PR2300 returns to the normal mode with no further commands necessary.

The printer must be sent the exact number of bytes as defined in the command-code sequence. If too few are sent, the printer buffer may not be emptied. Too many will result in garbage being printed when the PR2300 returns to normal mode.

In the ZX/TS screen copy map described above, there are 32 horizontal bytes/line X 8 lines/row X 24 rows. A total of 6144 bytes are required to fill the map.

The manner of transmitting the data to the PR2300 depends on the user’s system. For a memory-mapped printer port, the data could be sent with POKEs. For I/O-mapping, extended-BASIC OUT commands would work. A printer driver utility may allow the user to send the data by LPRINTing a string containing the command-code sequence or bits to be plotted, however, a machine code routine is probably the best method regardless of the type of port.

The BASIC

The included BASIC program allows the user to specify the location of the machine code routine, whether the printer port is I/O or memory mapped, the port status-read and data-write addresses, and margin size for screen copies. It also asks for the dimensions of the plot map in 8-bit columns and 8-line rows.

The program displays the calling addresses for zoom and normal copies and the addresses for plotter set-up and plotting, and asks for verification. Upon a positive response, the program will move RAMTOP if requested, create a REM if required, put the machine code in place, make a zoom copy of the final screen if the PR2300 is on line, and remove the BASIC program.

The BASIC is only a means of loading the machine code and adapting it to the user’s system. Hopefully, the user will have some means of saving just the code. This could be a tape utility such as Z-XLR8, my 2K-SDP system, or saving the code in a REM to be merged with programs by means of Delphic or Z-Tools, Etc.

Machine Code

Please Note: The disassembly listing will not work as shown. The code must be personalized to the users system and the parameters must be set. This is done by the BASIC program but could be accomplished with pokes to the code if it is already in place. The 3-byte sequence at STAT (printer status-read) must contain an IN A,(nn) instruction for an I/O mapped port or a LD A,(nnnn) instruction for a memory-mapped port. “nn” or “nnnn” is the address of the status port. Likewise, DATA (printer data-write) must be changed to OUT (nn),A or LD (nnnn),A. If a 2-byte IN or OUT instruction is used, the third space is simply left at “00”. Other necessary changes are the 3 blank bytes right after NRML and the two 3-byte blanks in PLOT. The first is the space for the left margin parameter for a screen copy. The second and third are the horizontal and vertical dimensions for the plot map, respectively.

The machine code presumes that the printer port reads BUSY on status bit 4 and PAPER EMPTY on status bit 1. It gives report code “D” for break and report code “P” for printer error (open lid, paper empty, etc). If the user’s hardware does not read the PAPER EMPTY status bit, the six bytes of the code starting with ERR? may be replaced with zeros.

The machine code has four entry points. The first three are S-ZO (setup zoom), S-NR (setup normal), and S-PL (setup plot). By calling into the code at one of these points, the desired command-code sequence is transmitted to the PR2300. This is accomplished by loading an address offset value in to the BC pair and a 01 or 03 into the E register. The call to TFAS at OSET (offset) leaves the return address from the call submerged on the stack. It is brought to the surface, popped into the HL pair and added to BC. When the code gets to XCMD (transmit command-code sequence), the HL pair is pointing 1 byte below the start of the data string and the E register has bit 0 set to indicate a command-code sequence. Bit 1 of the E register is set for screen copy and reset for plot setup.

The fourth entry point is X-SD (transmit SEED). Calling in at this point loads the least significant byte of SEED into the A register and loads the E reg. with zero, indicating a single byte is to be transmitted to the PR2300. This is intended to be used as a means of plotting a byte which may be calculated in BASIC and put into SEED with a RAND statement (See the example plot programs. Beware of RAND 0. It doesn’t work. To be safe, add 256 to all values. The MSB is ignored anyway). This routine may also be used in the PR2300 normal mode to print an ASCII character by RANDing the character code and calling X-SD with USR.

By calculating the command-code address and using the E register to keep track of things in the above manner, I was able to write the code with only relative jumps and no calls within the code itself. The code will run without modification anywhere the user’s system will execute machine code. The only stipulation is the data strings containing the command-code sequence must be kept in the same position relative to the code (I.E. Move everything together).

The first two entry points in the code lead to XDFL (transmit display file), the screen copy program, which works with either a collapsed or an expanded display file. It does require that the character dot patterns are in the normal location in the ROM. The program loops through the display columns and lines, getting the character codes from the display file and locating the dot patterns in the ROM. The dot pattern code is complemented for inverse characters and the bits are sent to the PR2300.

The third and fourth entry points are called to set up a plot map and send data to the map as described above. A full-sized map of 110 X 110 bytes contains 774,400 bit locations. The sine wave plot demonstration program, which calculates a value for every bit, took nearly sixteen hours to run.

I also have 32 and 64 column copy routines for the TS2068. These may be patched into commercial software, such as TECH-DRAW JR, which do not support the PR2300.

PLEASE NOTE: The author will supply a tape or EPROM versions of this program to interested individuals for a nominal cost. For more information, write:

Mr. Kent E. Cook
PO Box 1031
Terre Haute, IN 47808-1031

THE INVERSE GRAPHICS READ AS FOLLOWS:

 100 REM KEY-IN
200 REM DATA$ TO CODE$
300 REM POKE CODE
400 REM DEC TO HEX TO C$
500 REM DEC TO DEC TO C$
1000 REM CODE LOCATION
1015 LET O$=" OLIVETTI PR2300 COPY/PLOT "
1100 REM PORT DESCRIPTION
1200 REM COMMAND PARAMETERS
1300 REM SET RAMTOPVMAKE REM
1400 REM CREATE CODE $TRING
1600 REM REMOVE BASIC
1700 REM CHECKSUM FAILURE
   5 REM OLIVEPLOT (C) 1987     KENT E. COOK, BX 1031,          TERRE HAUTE, IN 47808
10 SAVE "OLIVEPLO▒"
15 GOTO 1000
100 REM KEY-IN
105 PAUSE 4E4
110 LET I$=INKEY$
115 RETURN
200 REM DATA$ TO CODE$
205 LET C$=""
210 LET CSUM=0
215 FOR X=1 TO LEN D$-1 STEP 2
225 LET C$=C$+CHR$ (16*CODE D$(X)+CODE D$(X+1)-476)
230 LET CSUM=CSUM+CODE C$(LEN C$)
235 NEXT X
240 RETURN
300 REM POKE CODE
305 FOR X=0 TO LEN C$-1
310 POKE A+X,CODE C$(X+1)
315 NEXT X
320 RETURN
400 REM DEC TO HEX TO C$
405 LET H=(INT (X/256))
410 LET C$(C+1)=CHR$ (X-256*H)
415 LET C$(C+2)=CHR$ H
420 RETURN
500 REM DEC TO DEC TO C$
505 LET H=INT (X/100)
510 LET T=INT ((X-100*H)/10)
515 LET U=X-100*H-10*T
520 LET C$(C)=CHR$ (H+48)
525 LET C$(C+1)=CHR$ (T+48)
530 LET C$(C+2)=CHR$ (U+48)
535 RETURN
1000 REM CODE LOCATION
1005 FAST
1010 CLS
1015 LET O$=" OLIVETTI PR2300 COPY/PLOT "
1020 PRINT O$,,,,"PRESS:",,,,,," ""1"" TO PLACE CODE ABOVE RAMTOP",,,,," ""2"" TO PLACE CODE IN REM",,,,," ""3"" TO SPECIFY ADDRESS"
1025 GOSUB 100
1030 IF I$<"1" OR I$>"3" THEN GOTO 1025
1035 LET RMTP=I$="1"
1040 LET REM=I$="2"
1045 IF I$="3" THEN GOTO 1060
1050 LET ADDR=(16514*REM)+((PEEK 16388+256*PEEK 16389-192)*RMTP)
1055 GOTO 1100
1060 CLS
1065 PRINT O$,,,,,,"MEMORY LOCATION FOR CODE = ";
1070 INPUT ADDR
1100 REM PORT DESCRIPTION
1105 CLS
1110 PRINT O$,,,,"PRESS:",,,,,," ""1"" FOR I/O MAPPED PORT",,,,," ""2"" FOR MEMORY MAPPED PORT"
1115 GOSUB 100
1120 IF I$<"1" OR I$>"2" THEN GOTO 1115
1125 LET IO=I$="1"
1130 CLS
1135 PRINT O$,,,,"I/O" AND IO;"MEMORY" AND NOT IO;" MAPPED PRINTER PORT",,,,,"STATUS PORT ADDRESS = ";
1140 INPUT STAT
1145 IF STAT<0 OR STAT>((255*IO)+(65535*NOT IO)) THEN GOTO 1140
1150 PRINT STAT
1155 PRINT "DATA PORT ADDRESS = ";
1160 INPUT DATA
1165 IF DATA<0 OR DATA>((255*IO)+(65535*NOT IO)) THEN GOTO 1160
1170 PRINT DATA
1200 REM COMMAND PARAMETERS
1205 PRINT ,,"LEFT MARGIN SIZE = ";
1210 INPUT LMRG
1215 IF LMRG<1 OR LMRG>255 THEN GOTO 1210
1220 PRINT LMRG
1225 PRINT ,,"PLOT MAP WIDTH = ";
1230 INPUT HOR
1235 IF HOR<1 OR HOR>110 THEN GOTO 1230
1240 PRINT HOR
1245 PRINT "PLOT MAP HEIGHT = ";
1250 INPUT VER
1255 IF VER<1 OR VER>110 THEN GOTO 1250
1260 PRINT VER
1265 PRINT ,,"ZOOM COPY = ""USR ";ADDR;"""","NORMAL COPY = ""USR ";ADDR+5;"""",,,"PLOT SETUP = ""USR ";ADDR+12;"""","PLOTTER = ""USR ";ADDR+103;"""",,,"OK? (Y/N)"
1270 GOSUB 100
1275 IF I$<>"Y" AND CODE I$<>118 THEN RUN 1000
1280 PRINT AT 20,0;" "
1300 REM SET RAMTOPVMAKE REM
1305 LET A=16444
1310 IF NOT RMTP THEN GOTO 1345
1315 LET D$="2A04401140FF192204402B363E2BF92B2B220240C37606"
1320 GOSUB 200
1325 LET FAIL=1300
1330 IF CSUM<>1529 THEN GOTO 1700
1335 GOSUB 300
1340 RAND USR A
1345 IF NOT REM THEN GOTO 1400
1350 LET D$="01C600217D40CD9E093E761297237723772336C223772336EA2A294001C60009222940C37606"
1355 GOSUB 200
1360 LET FAIL=1350
1365 IF CSUM<>3023 THEN GOTO 1700
1370 GOSUB 300
1375 RAND USR A
1400 REM CREATE CODE $TRING
1405 LET D$="017E0018030180001E0318050192001E01CDE7023B3BE109237EB72052CB4B286F"
1410 LET D$=D$+"2A0C40231E020618C50E00E5062056CB7228042B971837E56A2600CBBD292929D5"
1415 LET D$=D$+"11001E1916005919D1CB7A7EE1281E2F181B2310D8E10CCB5928CFC1CB762328FB10C41829"
1420 LET D$=D$+"CDE7023A32401E00F5CD460F3802CF0C000000CB4F2802CF18CB6720ECF1000000CB43208CCB4B20C4C30702"
1425 LET D$=D$+"1B2F1B470000003B3033323B3032343B321B5A001B473030313B0000003B0000003B321B5A0000000000000000"
1430 GOSUB 200
1435 LET FAIL=1400
1440 IF CSUM<>13511 THEN GOTO 1700
1445 LET H=INT (STAT/256)
1450 LET L=STAT-256*H
1455 LET C$(120)=CHR$ ((58*NOT IO)+(219*IO))
1460 LET C$(121)=CHR$ L
1465 LET C$(122)=CHR$ (H*NOT IO)
1470 LET H=INT (DATA/256)
1475 LET L=DATA-256*H
1480 LET C$(134)=CHR$ ((50*NOT IO)+(211 AND IO))
1485 LET C$(135)=CHR$ L
1490 LET C$(136)=CHR$ (H*NOT IO)
1495 LET X=LMRG
1500 LET C=152
1505 GOSUB 500
1510 LET X=HOR
1515 LET C=174
1520 GOSUB 500
1525 LET X=VER
1530 LET C=178
1535 GOSUB 500
1540 LET A=ADDR
1545 GOSUB 300
1600 REM REMOVE BASIC
1605 LET D$="2A0C40114341CD5D0ACD9A14217D402229402A3240E9"
1610 GOSUB 200
1615 LET FAIL=1600
1620 IF CSUM<>1704 THEN GOTO 1700
1625 IF REM THEN GOTO 1640
1630 LET C$(5)=CHR$ 125
1635 LET C$(6)=CHR$ 64
1640 LET A=16444
1645 GOSUB 300
1650 RAND ADDR
1655 RAND USR A
1700 REM CHECKSUM FAILURE
1705 CLS
1710 PRINT "CHECKSUM FAILURE","EXAMINE D$ CHARACTERS",,,
1715 LIST FAIL
7F40 017E00   S-ZO LD BC,007E
7F43 1803 JR SET3
7F45 018000 S-NR LD BC,0080
7F48 1E03 SET3 LD E,03
7F4A 1805 JR OSET
7F4C 019200 S-PL LD BC,0092
7F4F 1E01 SET1 LD E,01
7F51 CDE702 OSET CALL TFAS
7F54 3B DEC SP
7F55 3B DEC SP
7F56 E1 POP HL
7F57 09 ADD HL,BC
7F58 23 XCMD INC HL
7F59 7E LD A,(HL)
7F5A B7 OR A
7F5B 2052 JR NZ,XMTA
7F5D CB4B CNT? BIT 1,E
7F5F 286F JR Z,EXIT
7F61 2A0C40 XDFL LD HL,(DFIL)
7F64 23 INC HL
7F65 1E02 SET2 LD E,02
7F67 0618 LD B,18
7F69 C5 ROWS PUSH BC
7F6A 0E00 LD C,00
7F6C E5 LINE PUSH HL
7F6D 0620 LD B,20
7F6F 56 CLMN LD D,(HL)
7F70 CB72 PAD? BIT 6,D
7F72 2804 JR Z,MULT
7F74 2B PAD. DEC HL
7F75 97 SUB A
7F76 1837 JR XMTA
7F78 E5 MULT PUSH HL
7F79 6A LD L,D
7F7A 2600 LD H,00
7F7C CBBD RES 7,L
7F7E 29 ADD HL,HL
7F7F 29 ADD HL,HL
7F80 29 ADD HL,HL
7F81 D5 PUSH DE
7F82 11001E LD DE,CTBL
7F85 19 ADD HL,DE
7F86 1600 LD D,00
7F88 59 LD E,C
7F89 19 TABL ADD HL,DE
7F8A D1 POP DE
7F8B CB7A INV? BIT 7,D
7F8D 7E LD A,(HL)
7F8E E1 POP HL
7F8F 281E BITS JR Z,XMTA
7F91 2F INVT CPL
7F92 181B JR XMTA
7F94 23 XDF2 INC HL
7F95 10D8 CLM? DJNZ,CLMN
7F97 E1 POP HL
7F98 0C LIN? INC C
7F99 CB59 BIT 3,C
7F9B 28CF JR Z,LINE
7F9D C1 POP BC
7F9E CB76 END? BIT 6,(HL)
7FA0 23 INC HL
7FA1 28FB JR Z,END?
7FA3 10C4 ROW? DJNZ,ROWS
7FA5 1829 JR EXIT
7FA7 CDE702 X-SD CALL TFAS
7FAA 3A3240 LD A,(SEED)
7FAD 1E00 SET0 LD E,00
7FAF F5 XMTA PUSH AF
7FB0 CD460F BRK? CALL BREK
7FB3 3802 JR C,STAT
7FB5 CF ERRD RST 08H
7FB6 0C Error D
7FB7 00 STAT NOP
7FB8 00 NOP
7FB9 00 NOP
7FBA CB4F ERR? BIT 1,A
7FBC 2802 JR Z,BZY?
7FBE CF ERRP RST 08H
7FBF 18 Error P
7FC0 CB67 BZY? BIT 4,A
7FC2 20EC JR NZ,BRK?
7FC4 F1 POP AF
7FC5 00 DATA NOP
7FC6 00 NOP
7FC7 00 NOP
7FC8 CB43 CMD? BIT 0,E
7FCA 208C JR NZ,XCMD
7FCC CB4B DFL? BIT 1,E
7FCE 20C4 JR NZ,XDF2
7FD0 C30702 EXIT JP MDCK
7FD3 1B ZOOM DEC DE
7FD4 2F CPL
7FD5 1B NRML DEC DE
7FD6 47 LD B,A
7FD7 00 NOP
7FD8 00 NOP
7FD9 00 NOP
7FDA 3B DEC SP
7FDB 3033 JR NC,8010
7FDD 323B30 LD (303B),A
7FE0 32343B LD (3B34),A
7FE3 321B5A LD (5A1B),A
7FE6 00 NOP
7FE7 1B PLOT DEC DE
7FE8 47 LD B,A
7FE9 3030 JR NC,801B
7FEB 313B00 LD SP,003B
7FEE 00 NOP
7FEF 00 NOP
7FF0 3B DEC SP
7FF1 00 NOP
7FF2 00 NOP
7FF3 00 NOP
7FF4 3B DEC SP
7FF5 321B5A LD (5A1B),A
7FF8 00 NOP
7FF9 00 NOP
7FFA 00 NOP
7FFB 00 NOP
7FFC 00 NOP
7FFD 00 NOP
7FFE 00 NOP
7FFF 00 NOP
Zoom copy executed on a "2K" machine with collapsed display file
Zoom copy executed on a "2K" machine with collapsed display file
Normal copy executed on a "64K" machine with expanded display file
Normal copy executed on a "64K" machine with expanded display file

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.