           TITLE   FAKELPT for non-existing LPT ports .... FAKELPT.ASM

Cseg       SEGMENT para public 'code'

           org 100h

           assume cs:cseg,ds:cseg,es:nothing



entry proc far

su1:
  jmp su2

db "(c) Copyright 1989, Information Modes",0
db "Author: Don Jindra, 817-387-3339",0
db "Not public domain or shareware!",0

su2:
  call parms     ;read command line
  mov ax,4C00h   ;return to dos
  int 21h

entry endp


;page
subs proc near
;........................... Get setup parameters .............................

parms:
  push cs
  pop ds
  mov si,80h                  ;point to the command
  lodsb                       ;get count
  xor cx,cx
  mov cl,al


parms1:
  call nxtchar               ;get next char
  jnc parms1a
  jmp parms9                  ;if no more-->

parms1a:
  cmp al,"L"                 ;is LPTx ?
  jne parms2
  call nxtchar
  cmp al,"P"
  call nxtchar
  cmp al,"T"
  jne parms2                 ;yes:              no-->
  call getnum                ;pickup number
  dec dx
  mov cs:lptnum,dx           ;save lpt number

  call skipwhitespace        ;skip to next token
  jc parms1z
  call nxtchar               ;is it a "=" ?
  jc parms1z
  cmp al,"="
  jne parms1                 ;no-->

  call skipwhitespace        ;skip to next token
  jc parms1z
  push si                    ;save starting point
  push cx
  call nxtchar               ;see if this is a <LPTx=LPTy> format
  cmp al,"L"
  jne parms1b
  call nxtchar
  cmp al,"P"
  jne parms1b
  call nxtchar
  cmp al,"T"
  jne parms1b
  call getnum
  dec dx
  js parms1b                 ;it is:            it isnt-->
  pop ax                     ;loose old cx,si
  pop ax

  push es                    ;get bios seg
  mov bx,40h
  mov es,bx
  mov bx,dx                  ;bx--> proper LPTx
  shl bx,1
  mov dx,es:[bx+8]           ;get its port addr
  pop es
  jmp parms1c


parms1b:
  pop cx                     ;restore command line ptr/count
  pop si                     ;must be  <LPTx=hexvalue>  format 

  call gethexnum             ;assume a number is there
  or dx,dx
  jz parms2

parms1c:
  inc cs:numadds             ;got a good command
  push es
  mov bx,40h                 ;es=bios seg
  mov es,bx
  mov bx,cs:lptnum           ;bx--> LPTx
  shl bx,1
  mov es:[bx+8],dx           ;set new value
  pop es
  jmp parms1

parms1z:
  ret

parms2:
  jmp parms1

parms9:
  ret          


;page
;........................... Next char ........................................

nxtchar:
  jcxz nc10                  ;if no more chars in buffer -->
  lodsb                      ;get next char
  dec cx                     ;decrement count remaining
  cmp al,13                  ;is CR ?
  jz nc9                     ;no:               yes-->
  cmp al,"a"                 ;force to CAPs
  jc nc8
  cmp al,"z"+1
  jnc nc8
  xor al,20h

nc8:
  clc                        ;return good
  ret

nc9:
  dec si                     ;don't go passed CR
  xor cx,cx                  ;no more chars

nc10:
  stc                        ;return, none found
  ret


;........................... skip over whitespace .............................

skipwhitespace:

sw1:
  jcxz sw9
  lodsb
  dec cx
  cmp al," "
  je sw1
  cmp al,9
  je sw1

  inc cx
  dec si
  clc
  ret

sw9:
  stc
  ret




;........................... Get number .......................................

getnum:
  xor dx,dx                  ;init number = 0

gn1:
  jcxz gn9                   ;are any chars left?  no-->
  lodsb                      ;yes, get next one
  dec cx                     ;dec # left
  mov ah,al                  ;save char
  sub ah,"0"                 ;adjust ascii to number
  jc gn8                     ;was char < "0" ?   yes-->
  cmp ah,10                  ;is char  > "9" ?   
  jnc gn8                    ;                   yes-->

  push ax
  mov ax,10                  ;decimal shift left
  mul dx
  mov dx,ax
  pop ax
  add dl,ah                  ;add in ones
  adc dh,0
  jmp gn1                    ;see if more

gn8:
  dec si                     ;restore buffer ptr
  inc cx                     ;restore # remaining

gn9:
  ret

;page

;........................... gethexnum .......................................

gethexnum:
  xor dx,dx

gh1: call nxtchar
  jc gh9

  mov ah,al

  sub al,"0"
  jc gh8
  cmp al,10
  jc gh4
  add al,"0"
  sub al,"A"
  jc gh8
  cmp al,6
  jnc gh8
  add al,10

gh4:
  shl dx,1
  shl dx,1
  shl dx,1
  shl dx,1
  add dl,al
  adc dh,0
  jmp gh1
  

gh8:
  dec si
  inc cx

gh9:
  ret


outstr:

  lodsb
  or al,al
  jz o2
  mov ah,14
  push si
  int 10h
  pop si
  jmp outstr

o2: ret

lptnum  dw 0
numadds dw 0

subs endp

cseg ends
     end su1
