Category : Printer Utilities
Archive   : MODESW.ZIP
Filename : MODESW.ASM

 
Output of file : MODESW.ASM contained in archive : MODESW.ZIP

;------------------------------------------------------------------------------
; MODESW.ASM -- Program to switch COM1 with COM2 and LPT1 with LPT2
;
; Written by Mark Ehr 11/13/85
; Copyright (C) 1985 Technical Support Services.
; All rights reserved.
;
;
; Please direct all correspondence to:
;
; Technical Support Services
; 1200 South Wadsworth Blvd.
; Lakewood, CO 80226
; (303) 935-4646.
;
; This program is placed in the public domain. It may be copied and
; reproduced freely, so long as no fee is charged.
;
;------------------------------------------------------------------------------

;
; PRINTS -- Macro to print strings via DOS function 09h. Pass the address
; of the string in the DX register.
;

PRINTS MACRO
MOV AH,9 ;DOS print string function
INT 21H ;Call DOS
ENDM

CGROUP GROUP CODE_SEG,DATA_SEG
ASSUME CS:CGROUP,DS:CGROUP

;
; Data Segment Starts Here
;

DATA_SEG SEGMENT PUBLIC
MESSG DB 13,10,' MODESW Version 1.0 by Mark Ehr.',
DB 13,10,'Copyright (C) 1985 Technical Support Services.',
DB 13,10,' 1200 South Wadsworth Blvd.',
DB 13,10,' Lakewood, CO 80226',
DB 13,10,' (303) 935-4646',
DB 13,10,13,10,' The IBM PC Software Experts.'
DB 13,10,13,10,'$'
COM12SW DB 'COM1 --> COM2.',13,10,'$'
COM21SW DB 'COM1 --> COM1.',13,10,'$'
LPT12SW DB 'LPT1 --> LPT2.',13,10,'$'
LPT21SW DB 'LPT1 --> LPT1.',13,10,'$'
HLPMSG DB 13,10,'Valid options are:',13,10,13,10,
DB 'modesw [-b][-c][-p][-s], where',13,10,13,10,
DB ' -b = Switch both printer and comm ports.',13,10,
DB ' -c = Switch comm ports only (COM1/COM2)',13,10,
DB ' -p = Switch printer ports only (LPT1/LPT2)',13,10,
DB ' -s = Show current port assignments',13,10,'$'
STATMSG DB 13,10,'[Current Status]',13,10,13,10,'$'
DATA_SEG ENDS

;
; Code Segment (aka main routine) starts here.
;

CODE_SEG SEGMENT
ORG 100H ;Make this a COM file.

START PROC FAR

MOV DX,OFFSET CGROUP:MESSG ;Point to intro message
PRINTS ;And print it.
;
; Get the switch options from the DOS command line via the PSP.
;

MOV SI,82H ;Point to DOS command line (PSP)
MOV AX,[SI] ;Get the data there
CMP AH,97 ;Value less than 97 dec ('a')?
JGE ROPE ;Nope, so go ahead with comparisons.
ADD AH,32 ;Convert it to a small letter.
MOV [SI],AX ;And save back to the PSP.
;
; Now that the trivialities are over, compare the command line for an
; appropriate switch. Please note that the PSP stores the command line
; bytes in reverse order; i.e., 'p-' instead of '-p'.
;

ROPE: MOV AX,702dh ;702d = p- (-p in reverse order)
CMP [SI],AX ;Check for valid option
JNE NEXT ;Nope, so go on to the next one.
CALL SW_LPT ;Yep -- go switch LPTs now.
JMP EXIT ;And exit to DOS.
NEXT: MOV AX,632dh ;632d = c- (-c in reverse order)
CMP [SI],AX ;Check for valid option.
JNE NEXT1 ;Nope, so keep going.
CALL SW_COM ;Yep -- go switch COMs.
JMP EXIT ;And exit to DOS.
NEXT1: MOV AX,622Dh ;622d = b- (-b in reverse order)
CMP [SI],AX ;Check for valid option.
JNE NEXT2 ;Nope, keep going (sigh).
CALL SW_LPT ;First switch LPTs,
CALL SW_COM ;Then COMs.
JMP EXIT ;And exit.

NEXT2: MOV AX,732Dh ;732d = s- (-s in reverse order)
CMP [SI],AX ;Check for valid option.
JNE HELP ;Nope, so give them some help.
CALL SW_STAT ;Go check status.
JMP EXIT ;And drop to DOS.
;
; Give the poor widdle confused user some help.
;

HELP:
MOV DX,OFFSET CGROUP:HLPMSG ;point to help message.
PRINTS ;And print it.

EXIT: INT 20H ;return to DOS

START ENDP

;
; SW_LPT -- Switches LPT1 and LPT2, or vice versa.
;

SW_LPT PROC NEAR
PUSH DS ;Save DS for later.
MOV AX,0040h ;Point to BIOS data area.
MOV DS,AX ;And do it.
MOV SI,08h ;First PRINTER_BASE
MOV AX,[SI] ;Get address
MOV SI,0Ah ;Second PRINTER_BASE
MOV BX,[SI] ;Get address
MOV SI,08h ;First PRINTER_BASE
MOV [SI],BX ;Now switch them around
MOV SI,0Ah ;Second PRINTER_BASE

MOV [SI],AX ;Finish the switch
POP DS ;Get DS back for some messages.
CMP AX,03BCH ;Was monochrome LPT1 in place?
JE LP12MG ;Yep, so tell them that.
CMP AX,0378H ;Or was it the IBM Parallel?
JE LP12MG ;Tell 'em.
MOV DX,OFFSET CGROUP:LPT21SW ;Otherwise, it was LPT1-->LPT1
JMP LEND ;And tell 'em that, too.
LP12MG: MOV DX,OFFSET CGROUP:LPT12SW ;Print LPT1-->LPT2 msg
LEND: PRINTS ;Do the dirty work.
RET ;And return to the calling proc.
SW_LPT ENDP

;
; SW_COM - Switches COM1 and COM2, and vice versa.
;

SW_COM PROC NEAR
PUSH DS ;Save Ds for later.
MOV AX,0040h ;setup for ds change
MOV DS,AX ;set DS to 0040h
MOV SI,00h ;First RS232_BASE
MOV AX,[SI] ;Get address
MOV SI,02h ;Second RS232_BASE
MOV BX,[SI] ;Get address
MOV SI,00h ;First RS232_BASE
MOV [SI],BX ;Now switch them around
MOV SI,02h ;Second RS232_BASE
MOV [SI],AX ;Finish the switch
POP DS ;Now get it back for prints.
CMP AX,03F8H ;Was COM1 in the first slot?
JE CM12MG ;Yep, so tell them what we did.
MOV DX,OFFSET CGROUP:COM21SW ;Otherwise, it was COM1-->COM1
JMP CEND ;Jump down and tell them the other option.
CM12MG: MOV DX,OFFSET CGROUP:COM12SW ;Print LPT1-->LPT2 msg
CEND: PRINTS ;Print whatever message we ended up with.
RET ;And return to calling program.
SW_COM ENDP

;
; SW_STAT -- Checks the current redirection status and reports to the user.
;

SW_STAT PROC NEAR
MOV DX,OFFSET CGROUP:STATMSG
PRINTS

; Get contents of current printer port assignment

PUSH DS ;Save DS for a sec
MOV AX,0040H ;Reset DS for a peek at the BIOS data area
MOV DS,AX ;And point it there.
MOV SI,08h ;PRINTER_BASE
MOV AX,[SI] ;Get address
POP DS ;And get DS back again.
CMP AX,03BCH ;IBM Monochrome?
JE PARSTAT ;Yep.
CMP AX,0378H ;IBM Parallel Adapter?
JE PARSTAT ;Yep.
JMP STAT2 ;Nope, so it must be LPT2.
PARSTAT:MOV DX,OFFSET CGROUP:LPT21SW
PRINTS ;Print the message.
JMP COMCHECK ;Now jump down and check the COM ports.
STAT2: MOV DX,OFFSET CGROUP:LPT12SW ;Tell them the ports are redirected.
PRINTS ;And print it.

COMCHECK:
PUSH DS ;Save DS for later.
MOV AX,0040h ;setup for ds change
MOV DS,AX ;set DS to 0040h
MOV SI,00h ;First RS232_BASE
MOV AX,[SI] ;Get address
CMP AX,03F8H ;Is COM1 in there?
JE COM1 ;Yep, so display message as such
JMP COM2 ;Nope, so it must be COM2 or NUL
COM1: POP DS ;Get DS back so we can display a msg
MOV DX,OFFSET CGROUP:COM21SW ;Point to the message.
PRINTS ;And print it.
RET ;Return to the main program.
COM2: POP DS ;Get DS back again to display a msg
MOV DX,OFFSET CGROUP:COM12SW ;Point to the message.
PRINTS ;And print it.
RET ;Return to the main program.
SW_STAT ENDP

CODE_SEG ENDS
END START
;
; That's all, folks!
;