home *** CD-ROM | disk | FTP | other *** search
- page 58,132
- title NEWPRN Copyright (c) 1986,87 COMPAQ Computer Corp.
- ;******************************************************************************
- ;
- ; Name: NEWPRN
- ;
- ; Group: DRIVER
- ;
- ; Revision: 1.10
- ;
- ; Date: June 15, 1987
- ;
- ; Author: M P Vaughan
- ;
- ;******************************************************************************
- ;
- ; Changes:
- ;
- ; DATE REVISION DESCRIPTION
- ; -------- -------- ------------------------------------------------------
- ; 12/15/86 1.00 Original. Adapted from PRINTER.ASM from REV F 386
- ; system ROM for installation as the INT 17h function for
- ; 386.
- ; 6/15/87 1.10 Shorten delay for recovery, and insert printer busy
- ; test in wait_milli. MPV
- ;******************************************************************************
- ;
- ; Functional Description:
- ;
- ; This module replaces INT 17h for the 386. This is all of the parallel
- ; printer functions. It is a patch for use with high capacity
- ; printers such as the HP Laserjet. The delays for the original INT 17h
- ; function sent the routine off into a 1ms delay to wait for the printer
- ; to become ready after it was busy. This routine inserts a check for
- ; printer busy (prn_busy) within the 1ms delay routine. If the printer
- ; becomes ready while still in the wait routine, PRN_BUSY will force an
- ; exit to print the routine. This lowers the delay when a full 1ms is
- ; not required for delay.
- ;
- ; jmp $+2 ; Changed to the following
- ; jmp $+2 ;
- ; ______________________
- ;
- ; call delay
- ; . .
- ; . .
- ; . .
- ; delay proc near
- ; push cx
- ; mov cx,0Fh
- ; this_one:
- ; loop this_one
- ; pop cx
- ; ret
- ; delay endp
- ;
- ;******************************************************************************
- ;
- ;******************************************************************************
- ;
- ; Equates
- ;
- ;******************************************************************************
- ;
- STANDARDOUT equ 01h
- LSR equ 5 ; line status register
- DOS equ 21h
- ;
- ;******************************************************************************
- ;
- ; Externals
- ;
- ;******************************************************************************
- ;
- extrn prntbase:word ; printer base addrs table
- extrn printtmo:byte ; table of timeout values
- extrn ram400:byte ; ram segment
-
-
- page
- ;
- dev segment byte public 'DEV'
- assume cs:dev,ds:seg ram400
- ;
- ;******************************************************************************
- ;
- ; dev_head
- ;
- ;******************************************************************************
- ;
- org 000h ; Devices have no psp, so start at 0h
- ;
- devhead label word
- dw -1, -1 ; Pointer to next device - must be set
- ; to -1
- dw 8000h ; Attributes - this is a char device
- dw strategy ; pointer to device strategy entry pt.
- dw entry ; pointer to device interrupt entry pt.
- db 'newprn ' ; Character device name field
- ;
- ;******************************************************************************
- ;
- ; Command Jump Tables
- ;
- devtbl label word
- dw dev$init
- dw exit ; Block device only
- dw exit ; Block device only
- dw exit ; IOCNTL input
- dw exit ; Input (read)
- dw exit ; Non-destructive input no wait (Char)
- dw exit ; Input status (char only)
- dw exit ; Input flush (char only)
- dw exit ; Output (write)
- dw exit ; Output (write) with verify
- dw exit ; Output status (char only)
- dw exit ; Output flush (char only)
- dw exit ; IOCNTL output
-
- page
- ;******************************************************************************
- ;
- ; Device entry point
- ;
- ; Strategy
- ;
- ptrsav dd 0
- ;
- stratp proc far
- ;
- strategy:
- mov word ptr [ptrsav],bx
- mov word ptr [ptrsav+2],es
- ret
- stratp endp
- ;
- ;******************************************************************************
- ;
- ; Main entry point
-
- cmdlen = 0 ; Command Length
- unit = 1 ; Unit number
- cmdcode = 2 ; Command Code
- status = 3 ; Status
- reservd = 5 ; 8 bytes reserved
- unitnum = 13 ; unit number of device
- brk_add = 14 ; Break address (transfer address)
-
-
- entry:
- push ax
- push bx
- pushf
- lds bx,cs:[ptrsav] ; Pointer to request header
- mov al,byte ptr [bx].cmdcode
- cmp al,0 ; Is the command initialize?
- jne exit ; N: Exit - there are no other fctns
- jmp dev$init ; Y: Do initialization - install the
- ; new keyboard buffer.
- page
- ;******************************************************************************
- ;
- ; Exit - this is the exit routine for this driver.
- ;
- exitp proc far
- exit:
- popf
- pop bx
- pop ax
- ret
- exitp endp
- ;
- ;******************************************************************************
- page
- ;******************************************************************************
- ;******************************************************************************
- ;
- ; Replacement INT 17h function.
- ;
- ;******************************************************************************
- ;
- ;
- ;
- ;
- ;******************************************************************************
- ;
- ; Name: printer - Printer Routine INT 17
- ;
- ; Group: ROM
- ;
- ; Revision: A
- ;
- ; Date: May 25, 1986
- ;
- ; Author: Lance Pontiff
- ;
- ;******************************************************************************
- ;
- ; CHANGES:
- ;
- ; DATE REVISION DESCRIPTION
- ; -------- -------- ------------------------------------------------------
- ; 05/25/86 original Adapted from DeskPro 286 Rev E ROM.
- ;
- ;******************************************************************************
-
- page
- ;******************************************************************************
- ;
- ; FUNCTIONAL DESCRIPTION:
- ;
- ; Interrupt 17 -- printer output
- ;
- ; (AH) = 0 Routine will print the character in (AL).
- ; Returns the printer status in (AH). Bit 0 set
- ; to a 1 if character could not be printed.
- ; (AH) = 1 Initializes the printer port.
- ; Returns with the printer status in (AH).
- ; (AH) = 2 Returns with the printer status in (AH).
- ;
- ; BITS FUNCTION
- ; ------ ---------------------------------
- ; 7 READY
- ; 6 ACKNOWLEDGE
- ; 5 OUT OF PAPER
- ; 4 SELECTED
- ;
- ; 3 I/O ERROR
- ; 2
- ; 1
- ; 0 TIME OUT
- ;
- ; (DX) Set to printer to be used (0, 1, 2).
- ;
- ;******************************************************************************
-
- page
- ;
- ; Publics
- ;
-
- printer proc near ; printer i/o routine
- sti ; enable interrupts
- push bx ; save registers
- push cx ;
- push dx ;
- push si ; save index register
- push ds ; save segment registers
- mov bx,seg ram400 ; setup ds register ...
- mov ds,bx ; to point to bios ram
- ;
- ; Setup dx to point to printer by
- ; indexing printer base table by printer number
- ;
- and dx,3 ; force 0,1,2,3 only
- mov si,dx
- mov bl,[printtmo+si] ; bl=timeout interval
- shl si,1 ; make word index
- mov dx,[prntbase+si] ; dx = printer base
- or dx,dx ; Q: printer base of zero?
- ; jz print_ret ; Y: ignore if zero
- jz _leave ; Y: Exit - print_ret is too far so do
- ; an intermediate jump (MPV 1.1)
- ; Check ah register and go to correct routine
- ;
- ; ah = 0 print character
- ; ah = 1 initialize printer
- ; ah = 2 status
- ;
- push ax ; save character
- test ah,ah ; Q: print char?
- jz print_it ; Y:
- dec ah ; Q: initialize printer?
- jz print_init ; Y:
- dec ah ; Q: get printer status?
- jz print_stat ; Y:
- pop ax ; N: ignore call
- _leave:
- jmp short print_ret
-
-
- page
- ;******************************************************************************
- ; Print a character routine
- ;
- ; Outputs character to 8 bit register
- ; Checks busy and waits if needed
- ; Strobes character into printer
- ; Then goes to status
- ;
- ; ENTRY - AL = character
- ; BL = timeout value (0.780 sec per count)
- ; DX = printer base i/o address
- ; EXIT - BH = status
- ;------------------------------------------------------------------------------
- print_it:
- out dx,al ; output ascii to printer
- inc dx ; point to status to check busy
- jmp $+2
- jmp $+2 ; Allow for recovery time
-
- ; call delay ; allow recovery time
- in al,dx ; get printer status
- and al,0f8h ; Q: printer ready?
- js prtchr ; Y: go strobe data
- push ax ; N: protect ax
- mov ax,90feh ; printer Device Wait
- clc ; default = ROM timeout
- int 15h ; Q: Device Wait performed?
- pop ax ; restore ax
- jc timeout ; Y:
- a_count:
- mov cx,780 ; wait 1 milliseconds 780 times
- normal_to:
- push bx ; N: protect bx
- mov bx,1 ; wait 10 milliseconds
- call wait_milli ;
- pop bx ; restore bx
- in al,dx ; al = printer status
- and al,0f8h ; Q: printer ready?
- js prtchr ; Y: go strobe character
- loop normal_to ; N: keep waiting
- dec bl ; Q: finished all counts?
- jnz a_count ; N:
- timeout: ; Y:
- jmp $+2 ; Allow for recovery time
- jmp $+2
-
- ; call delay ; allow recovery time
- in al,dx ; get printer status
- and al,0f8h ; Q: printer still busy?
- js prtchr ; N: go strobe character
- or al,1 ; Y: set time out bit
- jmp short print_exit ; exit & post status
- prtchr:
- inc dx ; strobe status
- in al,dx ; read current settings
- and al,1eh ;
- or al,01h ; set strobe bit
- jmp $+2 ; Allow for recovery time
- jmp $+2
-
- ; call delay ; allow recovery time
- out dx,al ; turn strobe on
- and al,1eh ; turn strobe off
- jmp short print_inits ;
-
- page
- ;******************************************************************************
- ; Initialize printer
- ;
- ; ENTRY - DX = printer i/o base address
- ; EXIT - BH = status
- ;------------------------------------------------------------------------------
- print_init:
- inc dx ; get address of init bit
- inc dx ;
- mov al,8 ; initialize latch to slctn
- jmp $+2 ; Allow for recovery time
- jmp $+2
-
- ; call delay ; allow recovery time
- out dx,al ; 'init' line low, select high
- mov bx,5 ; assert init 5 ms per centronics
- call wait_milli ; wait 5 milliseconds
- or al,4 ; set 'init' bit high
- print_inits:
- jmp $+2 ; Allow for recovery time
- jmp $+2
-
- ; call delay ; allow recovery time
- out dx,al ;
- dec dx ; get current status
- dec dx ; point to printer i/o base
- ; fall into 'print_stat'
-
- page
- ;******************************************************************************
- ; Status
- ;
- ; ENTRY - DX = printer i/o base address
- ; EXIT - AL = status
- ;------------------------------------------------------------------------------
- print_stat:
- inc dx ; point to status
- jmp $+2 ; Allow for recovery time
- jmp $+2
-
- ; call delay ; allow recovery time
- in al,dx ; input status
- and al,0f8h ; mask unwanted bits
- ; fall into 'print_exit'
-
- ;*****************************************************************************
- ; ENTRY - AL = masked status from port
- ; EXIT - AH = status
- ;------------------------------------------------------------------------------
- print_exit:
- xor al,48h ; invert sense of ack and err
- mov bh,al ; temp = al
- pop ax ; restore al, in particular
- mov ah,bh ; ah = temp
- print_ret:
- pop ds ; restore segment registers
- pop si ; restore index registers
- pop dx ; restore registers
- pop cx ;
- pop bx ;
- iret ; *** RETURN ***
- printer endp
-
- include pop_f.mac ; Macro to simulate POPF instruction.
-
- public wait_milli ; Wait # of milliseconds in BX.
- ;
- COUNTS_MILLI = 1192*2 ; System timer counts per millisecond.
- K16 DW 16 ; ROM constant for hex conversions.
-
-
- ; Equates
- ;
- include asciidef.equ ; ASCII defs.
- ;
- include ppi_def.equ ; 8255 PPI equates.
- ;
- include cnt_def.equ ; 8253 counter-timer equates.
- ;
- include vdu_def.equ ; VDU equates.
- ;
- ;******************************************************************************
- ;
- ; Delay Routines:
- ;
- ; NOTE: These routines has been modified for the 286-based products
- ; to be processor-speed independent. Note that this routine
- ; assumes that stack is available. Stack is needed to do POPF
- ; equivalent.
- ;
- ; REG.USED: BX
- ;******************************************************************************
- ;
- ; This routine delays the number of milliseconds specified in BX.
- ;
- wait_milli proc near
- push bp ; Save BP for caller.
- push ax ; Save AX for caller.
- push cx ; Save CX for caller.
- call delay_ms_sp ; Use routine with stack.
- pop cx ;
- pop ax ;
- pop bp ;
- ret ; *** RETURN ***
- wait_milli endp
- ;
- page
- ;******************************************************************************
- ;
- ; DELAY_MS_SP - Routine to delay 1 millisecond per count in BX.
- ;
- ; ENTRY - BX = # of Milliseconds
- ; BP = Return address
- ;
- ; EXIT - None
- ;
- ; NOTE: This routine has been modified for the 286-based products
- ; to be processor-speed independent. It assumes that the stack
- ; is available so that it can run the POP_F macro to preserve
- ; interrupt status the same as the caller.
- ;
- ; REG.USED: AX, BX, CX, BP
- ;******************************************************************************
- delay_ms_sp proc near ;
- mov cx,bx ; cx= number of milliseconds
- rd_ini_count: ;
- pushf ;
- cli ;;;
- mov al,LATCH_CNT0 ;;; Latch count for system timer.
- out cnt_mode,al ;;;
- in al,cnt_0 ;;; Read low byte first.
- mov ah,al ;;;
- jmp $+2 ;;;
- jmp $+2 ;;;
- in al,cnt_0 ;;; Read high byte.
- pop_f ;;;
- xchg al,ah ; Get bytes in the right order.
- mov bx,ax ; Save BX=initial count.
- rd_count: ;
- call prn_busy ; Q: Is the printer ready? (MPV 1.1)
- js _exit ; Y: Exit and print it.
- pushf ; N: Delay a little longer. (MPV 1.1)
- cli ;;;
- mov al,LATCH_CNT0 ;;; Latch count for system timer.
- out cnt_mode,al ;;;
- jmp $+2 ;;;
- jmp $+2 ;;;
- jmp $+2 ;;;
- in al,cnt_0 ;;; Read low byte of count.
- mov ah,al ;;;
- jmp $+2 ;;;
- jmp $+2 ;;;
- in al,cnt_0 ;;; Read high byte of count.
- pop_f ;
- xchg al,ah ; Get bytes in the right order.
- push bx ; Save initial timer count.
- sub bx,ax ; Initial count - Current count.
- cmp bx,COUNTS_MILLI ; Q: Reached desired count ?
- pop bx ; Restore initial timer count.
- jb rd_count ; No, keep reading count.
- loop rd_ini_count ; Yes, do more milliseconds.
- _exit:
- ret ;
- delay_ms_sp endp ;
- page
- ;
- delay proc near
- ; mov cx,0Fh ; (MPV 1.1)
- ;this_one: ; (MPV 1.1)
- ; loop this_one ; (MPV 1.1)
- ret
- dummy dt ? ; (MPV 1.1)
- delay endp
-
- prn_busy proc near ; (MPV 1.1)
- push ax
- in al,dx ; al = printer status
- and al,0f8h ; Q: printer ready?
- pop ax
- ret ; (MPV 1.1)
- prn_busy endp
- ;
- ;
- ;
- ;******************************************************************************
- ;******************************************************************************
- page
- ;******************************************************************************
- ;******************************************************************************
- ;
- ; dev$init - this installs the driver.
- ;
- ;******************************************************************************
- ; Start NEWPRN.SYS - save registers first, then install the new
- ; interrupt service routine.
- ;******************************************************************************
-
- dev$init:
- push ax
- push bx
- push cx
- push dx
- push si
- push di
- push bp
- push ds
- push es
- pushf
-
- ;
- page
- ;******************************************************************************
- ; Set up a new INT 17h handler
- ;******************************************************************************
- install:
-
- assume ds:dev
- mov ax,cs
- mov ds,ax
- ;
- mov dx,offset printer ; Set new INT 17h interrupt
- mov ax,2517h
- int DOS
- ;
-
- ;******************************************************************************
- ; All done, print install message and prepare to exit.
- ;******************************************************************************
-
- mov dx,offset i_msg
- mov ah,09h
- int DOS
- ;
- lds bx,cs:[ptrsav]
- mov word ptr [bx].brk_add, offset cs:dev$init
- mov word ptr [bx].status, 10h
- mov [bx].brk_add+2,cs
- ;
- _done:
- popf
- pop es
- pop ds
- pop bp
- pop di
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- jmp exit
-
- page
- ;******************************************************************************
- ; Installation messages
- ;******************************************************************************
-
- i_msg db CR,LF,' NEWPRN.SYS V1.10 Installed'
- db CR,LF,'(C) Copyright COMPAQ Computer Corp. 1987'
- db CR,LF
- db '$'
- ;
- dev ends
- end