#! /usr/bin/perl # $Id: lexp5,v 1.1 1999-11-08 01:09:55+10 pbw Exp pbw $ sub A5pre { my $A5type = shift(@_); return pack("C4", 0xA5, 0, $A5type, 0x40); } sub A5cmd { my $A5type = shift(@_); my $cmd = A5pre($A5type); my $param; foreach $param (@_) { $cmd = pack(sprintf("a%dC", length($cmd)), $cmd, $param); } return $cmd; } sub Esc7 { my $cmd = pack("CaC", 0x1b,'*', 7); my $param; foreach $param (@_) { $cmd = pack(sprintf("a%dC", length($cmd)), $cmd, $param); } return $cmd; } sub Escm { my $cmd = pack("Ca2", 0x1b,'*m'); my $param; foreach $param (@_) { $cmd = pack(sprintf("a%dC", length($cmd)), $cmd, $param); } return $cmd; } sub pageinit1 { return A5cmd(6, 3, 3, 0xc0, 0x0f, 0x0f); } sub finpage { return Esc7(0x65); } sub startpage { return Escm(00, 0x40, 0x17, 5, 0xf, 0xf); } sub Vertmv { # Units are 1200ths of an inch my $short = shift(@_); return pack("C3n", 0x1b, 0x2a, 3, $short); } sub page_init { # This initialiser provides some cartridge alignment information # Two args: # Black-colour horiz separation (Cart. align. A) # Black-colour vert separation (Cart. align. B) my $alignA = shift(@_); my $alignB = shift(@_); $alignA = 15 unless ( $alignA >= 0 and $alignA <= 30 ); $alignB = 7 unless ( $alignB >= 0 and $alignB <= 15 ); return Escm( 0, 0x40, $alignA, $alignB, 0xf, 0xf ); } sub pens_speed_cmd { # Four args: # colour(black/colour) density(600/1200) dir(uni/bi) # These args are strings # plus one one-byte arguement whose values are only x18 or x1a # plus one argument whose function I do not know. It is the # last byte in the pen/speed/direction argument set. # N.B. Bi-directional printing is not available with 1200 mode - # at least. I don't see any such output from the windows driver. my $colour = shift(@_); my $density = shift(@_); my $dir = shift(@_); my $pen2 = shift (@_); my $byte6 = shift(@_); $colour = "black" unless ( $colour =~ /colou?r/ or $colour eq "black" ); $density = "600" unless ( $density eq "600" or $density eq "1200" ); $dir = "uni" unless ( $dir eq "uni" or $dir eq "bi" ); $dir = "uni" if $density eq "1200"; my $dirn = 0; $dirn = 1 if $dir eq "bi"; my $headspeed = 2 if $density eq "600"; $headspeed = 5 if $density eq "1200"; $headspeed = 1 if $dirn == 1; $pen = 0x200; $pen = 0x101 if $colour eq "black"; # $pen2 = 0x18; # $pen2 = 0x1a if ( $colour eq "black" and $density eq "600" ); return pack("C2nCC", $dirn, $headspeed, $pen, $pen2, $byte6); } $swipehdrstart = pack("CaC3", 0x1b, '*', 4, 0, 0); $pens_speed_5700 = pack("C6", 0, 3, 1, 1, 0x1a, 0); $swipehdrend = pack("C7", 0, 0, 0x22, 0x33, 0x44, 0x55, 1); $swipehdrfmt = "a5na6nnna7"; sub swipehdr { my $cmdlen = shift(@_); my $pens_speed = shift(@_); my $colcount = shift(@_); my $firstcol = shift(@_); my $lastcol = $firstcol + $colcount - 1; return pack($swipehdrfmt, $swipehdrstart, $cmdlen, $pens_speed, $colcount, $firstcol, $lastcol, $swipehdrend); } sub swipedata { # An array of words (16 bit network order shorts) containing the # directory and nozzle data # Just pack the words into a string, and return it. my $cmd, $param; foreach $param (@_) { $cmd = pack(sprintf("a%dn", length($cmd)), $cmd, $param); } return $cmd; } sub swipe { # Set up a swipe command. # Args: # colour, speed, direction, (strings) # pen2, byte6, (byte) # colcount, firstcol, (words) # directory and nozzle data (words) my $colour = shift; my $speed = shift; my $direction = shift; my $pen2 = shift; my $byte6 = shift; my $colcount = shift; my $firstcol = shift; my $header = swipehdr(0, pens_speed_cmd($colour, $speed, $direction, $pen2, $byte6), $colcount, $firstcol); my $data = swipedata(@_); my $cmdlen = length($header) + length($data); substr($header, 5, 2) = pack("n", $cmdlen); substr($data, 0, 0) = $header; return $data; } sub multicol { # Set up a swipe with horizontally separated columns # The initial arguments are as for the swipe sub, except that the # total column count value is not required, being calculated from # the data. Data values are # constructed as multiple instances of an argument defined as # number of blank columns # number of column copies # number of data words # directory word # data words # This set of data for a column is repeated indefinitely my $colour = shift; my $speed = shift; my $direction = shift; my $pen2 = shift; my $byte6 = shift; my $colcount; # Note that colcount is NOT required my $firstcol = shift; my @dataset; while ( $#_ > -1 ) { # Build data for one set of columns my $blanks = shift; # print STDERR $blanks, "\n"; $colcount += $blanks; my @coldata = (0x1fff) x $blanks; push @dataset, @coldata; my $copies = shift; # print STDERR $copies, "\n"; $colcount += $copies; my $datacount = shift; my $dir = shift; # print STDERR $datacount, " ", $dir, "\n"; my @column; push @column, $dir; for ( ; $datacount > 0; $datacount-- ) { push( @column, shift ); } # print STDERR "@column\n"; push @dataset, (@column) x $copies; } # print STDERR $#dataset, "\n"; return swipe($colour, $speed, $direction, $pen2, $byte6, $colcount, $firstcol, @dataset); } $A5_11_5000 = 1; $A5_11_5700 = 2; # Set up for 600 dpi uni black dot # Alignment A is 23, alignment B is 5 on my printer print page_init( 23, 5); print A5cmd(6, 3, 3, 0xc0, 0x0f, 0x0f); print A5cmd(3, 4, 5); print A5cmd(3, 4, 6); print A5cmd(3, 4, 7); print A5cmd(3, 4, 8); print A5cmd(4, 0xe0, 0x0b, 3); print A5cmd(11, 0xe0, 0x41, 0, 0, 0, 0, 0, 0, 0, $A5_11_5000); print A5cmd(6, 5, 0, 0, 0x80, 0); print Esc7(0x73, 0x30); print Escm(0, 0x14, 3, 0x84, 2, 0, 1, 0xf4); print Esc7(0x63); print Escm(0, 0x42, 0, 0); print A5cmd(5, 0xe0, 0x80, 8, 7); print Vertmv(0x412); print multicol("black", "600", "uni", 0x1a, 0x00, 0x158, 4, 5, 1, 0x1ffe, 0xaaaa, ); print finpage(); print finpage();