HP Laser Printer Documentation

advertisement
HP Laser Printer Documentation
The ability to print the graphics display for reference, documentation and publishing is extremely
valuable. The laser.scr file includes routines for printing the image from the monitor onto a HewlettPackard laser printer (Laserjet Series II). This file uses both assembly and Forth language. The
assembly language reads the RAM associated with the monitor display and reconstructs the image for
printing. Forth is used for all other operations, from sending commands to the printer, to transfering an
entire image. The file gives an example of using individual commands to print images to a page. Most
useful is the command mirage, used in the review routine of the Summary program, to print the current
display.
This file uses a feature in Forth that we generally avoid. Forth is thought of as having a dictionary
structure, where newer words are created from new combinations of previously existing definitions. As a
threaded interpretive language, the dictionary is searched beginning with the last definition and
proceeding, in order, to the very first definition. This feature has a consequence for both compilation and
execution (interpretive) speed of execution  older words take longer to find. By manipulating the
dictionary, however, one can cause searches through a subset of the dictionary. These subsets are called
vocabularies. If one is compiling assemby code, for example, it makes sense that only the assembler's
vocabulary be searched rather than all of the dictionary. There are some interesting possibilities, for
example, in creating dictionaries for different languages (spoken or computer). In general, however, we
have not found this device all that useful, and the laser.scr file gives some idea of its cumbersome nature.
There is one advantage to having multiple dictionaries, however, that led us to use it here and in a
few other instances. Unlike much of our own Forth code, really good Forth programming appears as
English-like sentences, and as such they are often self-documenting, requiring little comment. One of the
challenges for even our level of programming is to come up with reasonable names for each Forth
subroutine, names that have not been used before but that make sense. A thesaurus is the Forth
programmer's best friend, until even that is exhausted for alternative words that mean basically the same
thing. If only the same word could be used over again. The vocabulary feature of Forth allows the same
word to have different meanings in different situations. A somewhat trivial but nevertheless valid example
is the word help which, under one context could give a screen showing how a particular command works,
in another context could give a list of available commands, and in a third context could send a message
requesting help. As used in the present file, the word start in the laser vocabulary means to prepare the
laser printer to accept graphics commands, but in the forth vocabulary for the Runtime program it means
to begin timing the intertrial interval. The word reset in the laser vocabulary means to return the printer to
its default state, but in the forth vocabulary for the Runtime program it means to reinitialize the hardware
chips on the computer interface. The word transfer in the laser vocabulary moves a line of pixels from
the monitor as dots to the printer, but in the forth vocabulary for the Summary program it means to move
the trial-by-trial statistics from auxilliary memory to a library disk for archiving. The advantage to us is that
we do not have to think so hard for a new name. The disadvantage is the coding needed for dictionary
management, in particular to make sure that the correct definition is compiled or executed. The reader,
however, can safely ignore the dictionary and vocabulary features that are found in the file.
As with the other programs in these appendices, this file has been modified by identifying screens
by their numbers and by adding additional comments. This file still contains the definitions that were used
in debugging the code because these may be useful in understanding the way the monitor image is stored
in memory and may be useful for future modifications of the commands.
\ screen 0
\ LASER.SCR file
\ this file allows one to print out the monitor screen display to the Hewlett-Packard laser printer.
\ screen 1
\ this screen controls all loading of the laser routines.
RELOADING ASSEMBLER
RESIDENT
VOCABULARY LASER
\ assembler temporarily needed for compilation.
\ create definitions in normal (not assembler) dictionary.
\ Forth allows creation of different dictionaries whose
\ vocabularies are context-sensitive. For example,
\ help<return> in different situations can give different
\ information.
DECIMAL
2 SIZE 1- THRU
DECIMAL
ONLY
FORTH ALSO
FORTH DEFINITIONS
\ root dictionary.
\ add forth dictionary to root.
\ the dictionary order determines speed of compilation and
\ speed of execution by limiting the search to specific
\ dictionaries.
\ context for new definitions.
DISPOSE
\ removes temporary assembler.
\ screen 2
\ variables common to forth
ONLY
FORTH ALSO
FORTH DEFINITIONS
VLU STRETCH 2 IS STRETCH
VLU FIRSTLINE 0 IS FIRSTLINE
VLU LASTLINE 199 IS LASTLINE
VLU HIRES
75 IS HIRES
\ screen 3
\ return graphics screen line by line
ONLY
FORTH ALSO
LASER ALSO
LASER DEFINITIONS
HEX
CODE RASTER ( line# --)
\ places graphics line# in array info.
AX POP ( y)
AX SHR ( odd/even)
PUSHF
\ calc line start.
CLC
50 # BL MOV ( byts/ln)
\ height on printed page.
\ starting graphics line.
\ ending graphics line.
\ laser printer resolution; hires is 75, 100, 150 or 300 dpi.
BL BYTE MUL
POPF
1 L# JNC
CLC
2000 # AX ADD ( odd rows)
1 L: AX BX MOV 50 # CX MOV 0 # DX MOV
2 L: B800 # AX MOV AX DS MOV
0 [BX] AX BYTE MOV AH AH XOR
AX PUSH \ get graphics & save.
CS AX MOV AX DS MOV
AX POP
BX DX XCHG
AL INFO [BX] BYTE MOV
BX DX XCHG \ answer.
BX INC
DX INC
2 L# LOOP
NEXT C;
\ $50 = 80 bytes/line.
\ set DS.
\ restore DS.
DECIMAL
\ screen 4
\ some of these are words useful for testing, printing as numbers but not graphics.
: RUN ( n--)
\ print n numbers from array 'info', formatted according to the base.
( to = n) 0 ( from)
DO
I INFO + C@ S>D BASE @ 2 =
IF ( base is binary)
9
ELSE
BASE @ 16 =
IF ( base is hexadecimal)
3
ELSE ( base is decimal)
5
THEN
THEN
D.R
LOOP
CR ;
: IMPRINT ( from to --)
\ scroll numbers associated with range of lines from graphics display.
1+ SWAP
?DO
I RASTER
16 RUN
LOOP ;
: STATIONARY ( fr to --)
\ overprint in same location numbers associated with range of lines from graphics display.
1+ SWAP
?DO
I RASTER
0 22 AT
5 RUN
KEY ESC# = IF LEAVE THEN
LOOP ;
: DISTANCE ( --n)
\ shorten graphics line by # blanks at end.
80 ( max length)
0 79
DO
INFO I + C@
IF
LEAVE
ELSE
1THEN
-1 +LOOP ;
: #TO" ( n -- string)
\ convert a number to a string.
S>D <# #S #> ;
\ screen 5
\ hewlett packard laser jet graphics
: Ec ( --)
\ HP printer command <esc> usually begins a longer command to the printer.
ESC# EMIT ;
: RESET ( --)
\ HP printer command to reset.
Ec " E" TYPE ;
: G.ROW ( n --)
\ HP printer command.
Ec " &a" TYPE #TO" TYPE " V" TYPE ;
: L.ROW ( n --)
\ HP printer command.
Ec " &a" TYPE #TO" TYPE " R" TYPE ;
: G.COLUMN ( n --)
\ HP printer command.
Ec " &a" TYPE #TO" TYPE " H" TYPE ;
: L.COLUMN ( n --)
\ HP printer command.
Ec " &a" TYPE #TO" TYPE " C" TYPE ;
: RESOLUTION ( n --)
\ HP printer command.
\ n = 75, 100, 150, or 300 dpi.
Ec " *t" TYPE #TO" TYPE " R" TYPE ;
: START ( --)
\ HP printer command.
Ec " *r1A" TYPE ;
: XFR ( --)
\ HP printer command to print graphics line from array 'info'.
Ec " *b" TYPE DISTANCE #TO" TYPE " W" TYPE
DISTANCE 0
?DO
INFO I + C@ EMIT
LOOP ;
: END ( --)
\ HP printer command.
Ec " *rB" TYPE ;
: TRANSFER ( fr to --)
\ do not transfer to screen!
199 MIN 1+ SWAP 0 MAX 2DUP U< ABORT" Parameters wrong order"
?DO
I RASTER
STRETCH 0
?DO
XFR
NUF? ?LEAVE
LOOP
LOOP ;
\ screen 6
\
continued
: TRANS ( listof8 --)
\ transfer list to printer.
Ec " *b8W" TYPE 8 0 DO EMIT LOOP ;
: LM ( n --)
\ HP printer command for left margin.
Ec " &a" TYPE #TO" TYPE " L" TYPE ;
: RM ( n --)
\ HP printer command for right margin.
Ec " &a" TYPE #TO" TYPE " M" TYPE ;
: TM ( n --)
\ HP printer command for top margin.
Ec " &1" TYPE #TO" TYPE " E" TYPE ;
: PORTRAIT ( --)
\ HP printer command for portrait page orientation.
Ec " &I0O" TYPE ;
: LANDSCAPE ( --)
\ HP printer command for landscape page orientation.
Ec " &I1O" TYPE ;
: PICTURE ( n --)
\ print line from monitor.
\ n is resolution.
\ user must turn on printer.
RESOLUTION
START
0 135 TRANSFER
END ;
: FIRST ( n --)
\ first picture on the printed page.
\ used for loading & printing an experiment's pictures.
LOAD
PRINTER ON
RESET
10 LM 75 PICTURE
CR CR CR
PRINTER OFF ;
: SECOND ( n --)
\ this will work for all next pictures printed on page.
LOAD
PRINTER ON
75 PICTURE
PRINTER OFF ;
: FINAL ( n --)
\ this is the last picture printed on the page.
LOAD
PRINTER ON
75 PICTURE
PAGE
PRINTER OFF ;
\ screen 7
\
\ instructions using an example:
\
\ printer on
\ reset
\ 75 resolution
\ 0 l.row 0 l.column
\ ( display 1st graph)
\ start
\ 0 100 transfer
\ end
\ ( display 2nd graph)
\ 30 l.row 0 l.column
\ start
\ 0 100 transfer
\ end
\ page
\ printer off
\ screen 8
\ command word
ONLY
FORTH ALSO
LASER ALSO
FORTH DEFINITIONS
: MIRAGE ( --)
\ this is the main execution word for printing images from the monitor to the HP Laserjet printer.
\ do not use this for dot matrix.
[ FORTH ] PRINTING @
IF
PRINTER ON
[ LASER ] RESET
\ compiles laser 'reset', not runtime 'reset'.
HIRES
[ LASER ] RESOLUTION
0 [ LASER ] L.ROW
0 [ LASER ] L.COLUMN
[ LASER ] START
\ compiles laser 'start', not summary 'start'.
FIRSTLINE
LASTLINE
[ LASER ] TRANSFER \ compiles laser 'transfer', not summary 'transfer'.
[ LASER ] END
\ compiles laser 'end', not summary 'end'.
PAGE
PRINTER OFF
THEN
beep 1 delay beep ;
Download