; Printer.asm - primitives for access LPTx ports.     2006 Chris Evans
Lptpnext      dd 0ffff0000h
Lptdevattr    dw 1000000000000100b 
Lptstrategy   dw offset _lpt_strategy
Lptinterrupt  dw offset _lpt_interrupt
Lpt_device    db 'LPT     ' ; Blank-padded device (or 10-byte block device sub-unit number)
Lpt_device2   db 'PRN     '
; Jump table 
lpttable   db 9
           dw cs:lpt_init      ; 0 - initialize driver
           dw cs:lpt_init      ; 1 - media change check 
           dw cs:lpt_init      ; 2 - build BPB
           dw cs:lpt_init      ; 3 - IOCTL string output
           dw cs:lpt_input     ; 4 - input
           dw cs:lpt_input     ; 5 - nondestructive input
           dw cs:lpt_status    ; 6 - input status
           dw cs:lpt_init      ; 7 - input flush
           dw cs:lpt_output    ; 8 - output
           dw cs:lpt_output    ; 9 - output w/ verify

PRT_TIMEOUT    EQU 01h
PRT_IOERROR    EQU 08h
PRT_SELECTED   EQU 10h
PRT_OUTOFPAPER EQU 20h
PRT_ACK        EQU 40h
PRT_NOTBUSY    EQU 80h
PRT_WRITECHAR  EQU 00h
PRT_INITPORT   EQU 01h
PRT_GETSTATUS  EQU 02h


printerstatus   db 0
lptport         dw 0
printers    dw 0

; Basic BIOS int-17h support
; Remember to set port number in DX, Character in AL.

LPT:

lpt_init proc far

        mov  ah, PRT_INITPORT
        mov  cs:lptport, dx
        int  17h
        mov  cs:printerstatus, ah
        ;
        int  11h
        shr  ax, 14  ; bits 15-14
        and  ax, 3
        mov  cx, ax
        mov  cs:printers, ax
initprn:
        pusha
        _echo 'L'
        _echo 'P'
        _echo 'T'
        mov  ax, cx
        call putnum
        popa
        mov  ax, 0100h
        mov  dx, cx
        int  17h
        loop initprn

        clc
        ret
_lpt_strategy:
      retf
_lpt_interrupt:

      retf
lpt_init endp

lpt_input proc far

      ret
lpt_input endp

lpt_output proc far
    ; The DOS MODE command can redirect this output to a serial
    ; port.
    ; write_char(lr.DL, get_sft_idx(STDPRN));
    ; al = byte to print
    mov  ah, 00h
    mov  cs:lptport, dx     ; LPT1 = 0   etc...
    int  17h
    mov  cs:printerstatus, ah
    ret
lpt_output endp

lpt_status proc far
        mov  ah, PRT_GETSTATUS
        mov  cs:lptport, dx
        int  17h
        mov  cs:printerstatus, ah
        mov  al, cs:printerstatus
      ret
lpt_status endp

LPT_OUT proc far
    ; LPT OUT = DL = CHAR
    ; Sends the character in DL to the Standard Printer Device
    ; (Normally LPT1)
    mov al, dl
    call lpt_output
    ret
LPT_OUT endp

