-
Notifications
You must be signed in to change notification settings - Fork 2
/
PRINTER.ASM
183 lines (131 loc) · 6.26 KB
/
PRINTER.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
$Title ('DTC/PC BIOS Parallel Printer Driver V1.0')
$Pagelength (80) Pagewidth (132) Debug Nogen
Name Printer
; Author: Don K. Harrison
; Start date: November 25, 1983 Last edit: December 20, 1983
; ************************
; * Module Description *
; ************************
; This module handles the parallel printer driver, accessed via
; interrupt 17H.
; (c) Display Telecommunications Corporation, 1983
; All Rights Reserved
$Eject
; **********************
; * Revision History *
; **********************
$Eject
; ********************
; * Public Symbols *
; ********************
Public PrinterDriver
; *************
; * Equates *
; *************
; All Equates in include file: IbmInc
$Include (IbmInc)
$Eject
; *******************
; * Data Segments *
; *******************
BiosDataArea Segment Public
Extrn PrintTimeOut:Byte, PrinterBase:Word
BiosDataArea Ends
$Eject
; ******************
; * Code Segment *
; ******************
Bios Segment Common
Assume Cs:Bios, Ds:BiosDataArea
Org 0EFD2H
PrinterDriver Proc Far
Sti ;Restore interrupts
Push Ds ;Save registers
Push Bx ;...that
Push Cx ;...we
Push Dx ;...will use
Mov Bx,BiosDataArea ;Point at our
Mov Ds,Bx ;...data segment
Mov Bx,Dx ;Use Bx as index of ports
Shl Bx,1 ;...(ports are words)
Mov Dx,PrinterBase[Bx] ;...and get our port
Or Dx,Dx ;If none, return
Jz PrinterReturn ;...no particular status
; Do case on command
Or Ah,Ah ;Case = 0?
Jz PrintChar ;...if so, jump and print char
Dec Ah ;Case = 1?
Jz PrintInitialize ;...if so, init printer
Dec Ah ;Case = 2?
Jz PrintStatus ;...if so, jump and return status
; If illegal command, just return
PrinterReturn:
Pop Dx ;Restore registers we
Pop Cx ;...used
Pop Bx ;...and
Pop Ds ;...return
Iret ;...to caller
; ***************************
; * Print Character in Al *
; ***************************
PrintChar Proc Near
Out Dx,Al ;Send char to printer
Inc Dx ;...then point at status
Mov Bh,PrintTimeOut[Bx] ;Get # of loops in Bh
Mov Ah,Al ;...save print character
PrintOuterLoop:
Xor Cx,Cx ;Maximum loop count
PrintInnerLoop:
In Al,Dx ;Get the status
Or Al,Al ;...and affect flags
Js StrobeChar ;...jump if not busy
Loop PrintInnerLoop ;...else loop till not busy
Dec Bh ;Decrement outer loop
Jnz PrintOuterLoop ;...and loop
; Timeout
Or Al,1 ;...set timeout error
And Al,11111001B ;...mask unused bits
Jmp StatusReturn2 ;...and return status
StrobeChar:
Inc Dx ;Point at command port
Mov Al,00001101B ;Strobe = high
Out Dx,Al ;...to printer
; This is an entry point from PrinterInitialize
StatusReturn3:
Mov Al,00001100B ;Strobe = low
Out Dx,Al ;...to printer
Dec Dx ;Point back at status
Jmp Short StatusReturn1 ;...and return with it
PrintChar Endp
; ***************************
; * Return Printer Status *
; ***************************
PrintStatus Proc Near
Mov Ah,Al ;Preserve Al
Inc Dx ;Increment to status port
StatusReturn1:
In Al,Dx ;...and get status
And Al,011111000B ;...turn off unused bits
StatusReturn2:
Xor Al,01001000B ;...and flip sense of some
Xchg Al,Ah ;...Al=char, Ah=status
Jmp PrinterReturn ;...jump and return status
PrintStatus Endp
; ************************
; * Initialize Printer *
; ************************
PrintInitialize Proc Near
Mov Ah,Al ;Preserve Al
Inc Dx ;Point at command
Inc Dx ;...port
Mov Al,00001000B ;Init bit
Out Dx,Al ;...to printer
Mov Cx,1500 ;Delay
InitDelay:
Loop InitDelay ;...for reset pulse
Jmp StatusReturn3 ;...then jump and turn off
;...init bit and return status
PrintInitialize Endp
PrinterDriver Endp
Bios Ends
End