$Id: lexmarkprotocol.txt,v 1.6 1999/03/26 21:20:03 henryk Exp $
(C) 1999 Henryk Paluch, paluch@bimbo.fjfi.cvut.cz

Many thanks to Peter B. West p.west@uq.net.au for a lot of contributed info
about Lexmark 5000


Lexmark 7000 - documentation of undocumented protocol
-----------------------------------------------------

This document describes communication protocol used by Lexmark 7000 printer.
The key problem is, that Lexmark consider the protocol top secret &
copyrighted, so all information bellow was guessed! Use on your own risk!


Lexmark 5700 uses a protocol similar to 7000. The only difference
is initialization and 6x?? magic bytes in printing escape.

All Escape sequences begin with
<- *
1B 2A


Lexmark 7000, Black & White, normal mode (600dpi), 63 bytes
1B 2A 6D 00 40 0F 03 10 11 
               15 3 16 17 - aligning 

A5 00 0B 50 E0 41 00 00 00 00 00 00 00 02 
   ^^ ^^ length of init data
A5 00 06 50 05 00 00 80 00
   ^^ ^^ ...
A5 00 04 50 04 0C 00 
   ^^ ^^ ..
1B 2A 07 73 30 
1B 2A 07 63
1B 2A 6D 00 42 00 00 
A5 00 05 40 E0 80 07 08 
      ^^
followed by paper move and print packets...


<- *  .  s  0
1B 2A 07 73 30
-------- EPSON (?) or PCL (?) sequence - length - various

<- *  .  c
1B 2A 07 63
-------- again EPSON (?) -- various length


1B 2A 6D 00 42 ...
-------------- various init ? -- length - various

<- *  .  .  .
1B 2A 03 04 EA     -- 5 bytes -- 4EAh means offset
-------- paper shift

<- *  .  .  .  .  .  .    .  .  .   .   .   .   .  .  
1B 2A 04 00 00 L1 L2 6x?? N1 N2 HS1 HS2 HE1 HE2 00 00 

   "  3  D  U
   22 33 44 55 01 N1,2x<packets>
-------- print pixels
L1,2  - complete length of the sequence (including data) BE order
N1,N2 - number of packes, BE order
HS1,2 - horizontal offset start
HE1,2 - horizontal offset end
Should be valid: N = (HE-HS)+1

packets

every packet define exatly one vertical line, but it contains information
for both left & right inkjets!

There are two kinds of packets:
001? ???? ???? ???? - 0x20 0x00 + 13 packet bits

000? ???? ???? ???? - 0x00 0x00 + 13 packet bits (?)

? = 0 means there are two data bytes
    1 means there is no data byte, i.e., white (print nothing).

Byte data are interlaced:
<--------byte1----------> <--------byte2---------->
| L1 R1 L2 R2 L3 R3 L4 R4 | L5 R5 L6 R6 L7 R7 L8 R8 |

L? = left ink
R? = right ink

ink jets layout:

         L1    
               R1
         L2    
               R2
         ........
         L8    
               R8

The distance between L? and R? seems to be always 16
It is called headSeparation in Stephen's driver.


2? ?? <bytes 2x zero bits in ?) byte format same as above (Li Ri)
For Example:

3F FC AA AA A0 00
2    F    F   C    LRLRLRLR LRLRLRLR LRLRLRLR LRLRLRLR
0011 1111 11111100 10101010 10101010 10100000 00000000
   ^             ^ highest jet  1= white 0=two bytes
     lowest jet

We should get (hopefully)
     0       -
           0  \
    .........   - number of   11 * 16 = 176 zeroes
     0      - /
           0
     1      -
           0 \
     .......   - 10 * Left black
     1       /
           0\
     .......  - 6 * white
     0      /
          0

    104  + 104 = 208 ink jets

2x xx sequence can drive 13 * 8 * 2 = 208 ink jets in head. This is legal
only for Black & White cartridge.
There is allowed only 12 * 8 * 2 = 192 ink jets for color printing.

There are up to 13*2=26 data bytes following 2 byte packet.

6x?? defines few important values:
* cartridge selection (Left/Right)
* horizontal speed, e.g., resolution
* bidirectional/unidirectional printing mode
* compression mode 

Common values for Lexmarks 7000 are:
00 02 01 01 1A 11 Black & White printing
00 03 01 00 18 11 Color printing
               ^^ ???
            ^^ -- compression type?
         ^^ ----- cartridge index, 00 = Color for 7000, Black for 5700
                                   01 = Black for 7000, Color 5700
   ^^ ----------- motor speed (horizontal resolution). Probably:
                  01 bidirectional 600 dpi
                  02 unidirectional 600 dpi
                  03 unidirectional 300 dpi on 7000 ?????
                  05 unidirectional 1200 dpi
^^ -------------- paper size ???
               


<- *  .  e
1B 2A 07 65 ...  Note: various bytes after sequence  ?? why ??
----------- Paper Eject 

Colour printing
----------------

It is possible to use same data packets for colour and Black & White
packets. 
Colour printing is more complex, because there is vertical space
between colors. It looks like this for one pass:
O        -| 
     O    |
O         |  64 Cyan Ink Jets
     O   -| 
  x
  x          small vertical space (!)
O        -| 
     O    |
O         |  64 Magenta Ink Jets
     O   -| 
  x
  x          small vertical space (!)
O        -| 
     O    |
O         |  64 Yellow Ink Jets
     O   -| 

As stated above, there are used only 3 * 64 = 192 ink jets instead of 208.




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Lexmark 3200
------------
Very strange. All Escapes are 8 bytes long:

1b 2a 80 00 00 00 00 00 
1b 33 00 00 00 00 00 33
1b 30 80 0c 02 00 00 be 
1b 21 00 00 00 00 00 21
1b 23 80 01 fc 00 00 a0 
1b 40 11 00 e0 01 e8 1a
1b 42 00 00 00 01 a0 e3 
1b 43 00 05 d6 1b a0 d9

Data packets follow:
83 ?? ?? FF pixels
   ^^ ^^ this defines number of pixel bytes: 1 = no pixel data
                                             0 = 1 byte of pixel data follow
c3 ?? ?? FF pixels
   ^^ ^^ as above
  pixel format unknown

Example:
83 ff ff ff 
   ^^ ^^ no pixel data (white on paper)
83 f7 ff ff 10 
   ^^ ^^ 1111 0111 1111 1111 - 1 zero bit = 1 data byte follows (0x10)
83 f7 7f ff 38 14 41
   ^^ ^^ 1111 0111 0111 1111 - 2 zero bits = 2 data byte follow (0x14 0x41)

These were seen on epilog:
1b 22 80 3a f4 00 00 d0
1b 31 10 01 e8 00 00 2a 
1b 33 00 00 00 00 00 33

===============================================================================
What I need to know:
-  escape for paper shift (look for escapes between two printing passes)
-  escape for paper eject (probably one of the 3 above - verify)
-  how are coded data for 83 ?? ?? ff & C3 ?? ?? ff packets
-  how is coded horizontal offset start and end, where is coded number
   of 83 ?? ?? ff & C3 ?? ?? FF packets (probably in some packet before these
   bytes)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Lexmark 2050
------------
Except pixel data the packets look similar to Lexmark 5xxx, 7xxx:

Init:
1b 2a 80        - ?? init
1b 2a 07 73 30  - ?? init like Lexmark 7xxx, 5xxx
1b 2a 07 63     - ?? init like Lexmark 7xxx, 5xxx
1b 2a 03 09 20
         ^^ ^^  - paper shift (BE order) - like Lexmark 7xxx, 5xxx
1b 2a 04 0f da 01 01 00 01 07 31 02 40 03 db
      06 1a 00 00 00 00 00 32 33 34 35 00 
... pixel data ...
1b 2a 07 65 - paper eject - like Lexmark 7xxx, 5xxx

=======================================================================
What I need to know:
 - format of the most important 1b 2a 04 .. packet, namely:
   * where is coded horizontal offset - start and end
   * where is coded number of packets
   * where is coded size of escape (if any)
   * format of uncompressed pixel data
========================================================================

