[net.micro.pc] Goodies for your library

HFISCHER%USC-ECLB@sri-unix.UUCP (01/01/84)

I am submitting two programs for the INFO-IBMPC library:

    (1) ScrnColr - Intercepts characters on the way to the IBM PC
                   screen handler and, if they are for white on black
                   or black on white, changes to whatever color attrib-
                   utes user assigns.

    (2) Bat-Ques - Allows interactive responses to questions within
                   .bat files, and allows testing of these responses.
                   For example, allows you to ask user if he wants
                   some option run, and then the .bat file can test
                   the results and do conditional execution.

[These programs are available as SCRNCOLR.ASM (.DOC) and BATQUES.ASM (.DOC)
in <INFO-IBMPC>, but as they are reasonably short I have kept them in
this message for the benefit of those who don't have FTP access to ISIB -ed]

ScrnColr
--------

This program is an adaptation of the program SCREEN, which is in 
the INFO-IBMPC library.  SCREEN traps keyboard entries, using 
alt-function key combinations. I found these incompatible many 
popular text editors. It was also incompatible with LOGO.  

ScrnColr only reads command line parameters, and does not inter-
cept keyboard entries.  I have been using it with ScrnSave, DVED,
Mince, Blue, Prof. Editor, ASM, LOGO, APL, Kermit, and many
others.  It seems compatible with all.

To  change color assignments for the 80 wide text mode only, run:

   ScrnColr nn rr

where nn are attributes to replace normal white on black and rr 
replace reverse video black on white. (nn and rr are standard HEX 
video codes) Examples:

   ScrnColr 06 60    for brown (amber) colors
   ScrnColr 17 71    for white on blue & opposite
   ScrnColr 1e 5c    for yellow on blue and lt. cyan on red

Acknowledgements are, of course, due to the authors and maintainers 
of SCREEN.ASM, from whence this program is derived.


Bat-Ques
--------

To ask a question:

   Bat-Ques tttttt$     where ttttttt is the text of the question

User then keys a single character response.

To check answer, use IF [not] errorlevel cc, where cc is the 
character code value of the response. Only single character responses 
are supported.

This program allows one to build decently friendly batch files. One 
no longer has only the ctrl-break response to a pause (which isn't 
very friendly).

Examples:

This program allows a batch file to ask the user a question and 
return a one-character response which is testable by the IF 
subcommand of bat files, via the errorlevel.

You use the question asker per following example:

   .
   .  (your batch file to ask if user wants to edit with
   .       mince/emacs or ibm's editor)
   .
   echo off
   bat-ques WHICH EDITOR, m OR e FOR MINCE (EMACS), i FOR IBM's? $
   if errorlevel 110 goto badresp
   if errorlevel 109 goto minceed
   if errorlevel 106 goto badresp
   if errorlevel 105 goto ibmed
   if errorlevel 102 goto badresp
   if errorlevel 101 goto minceed
   :badresp
   echo Your response was invalid. Sorry.
   goto endit
   :minceed
   if not exist mincomm.sum copy \bin\mince.swp mince.swp
   mince %1
   if not exist mincomm.sum del mince.swp
   goto endit
   :ibmed
   profed %1
   :endit
   echo on

Note that the question prompt follows the bat-ques command and must 
end with a dollar sign. The ascii value of the response is returned 
as the error level. Since error level tests are always greater than 
or equal tests, you must check for highest value first and lowest 
value last. Example above shows what you do to check for missing 
values. Note that the example assumes lower case answers only for 
simplicity sake.

Ascii values (e.g., A is 65, B is 66, a is 97) are found in back of 
your BASIC manual. Only one character responses are accepted, and 
they are not followed by a carriage return.

Extended ascii codes (function and alt keys) should work as per page
G-6 of your BASIC manual; the first call to bat-ques will return a 
zero and the next call (presumably "bat-ques $" without another 
prompt) will return the number shown on page G-7.


Friendly and colorful Hints
---------------------------

To make your screen even more friendly, especially since some programs
may leave you hanging in different directories from whence you
started, change your prompt to give you the directory instead of just
the default drive (but do remember that if you have no disk in the
defaulted drive you will get the drive not ready message when Prompt
tries to show the directory).

   prompt $p$g    --- best inserted into your autoexec.bat

To make your screen more colorful, (borrowing from IBM's use with TSO,
where prompts are different colors from responses), install the ANSI
screen handler, and change your prompt string to:

   prompt $e[0;31m$p$g$e[0m  -- red prompt string

Don't forget to end your .bat files which call programs which use 
the screen directly with the cls command.  Cls forces screen 
attributes to become the defaulted color.  Otherwise you have 
strange cluttered colors left on the screen.

To make KERMIT easier to handle, change the "curatt" definition from 
black and white (I use 02, green) and reassemble.  I don't suggest a 
background color with kermit because EMACS will leave black holes in 
your screen.  With curatt redefined, when "connected" you get that 
color, and when talking to kermit-86 you get the ScrnColr settings.

   For a enjoyable and prosperous '84, 

   Herm Fischer (HFischer@usc-eclb)

attached: 2 programs for library

page	64,132
title	scrncolr - Change display screen from white to color attrib
.radix 10
;***************************************************************
; Adapted from "SCREEN.ASM" by H. Fischer - HFischer@eclb 12/83
; SCREEN was Typed in by Glass - gjg@cmu-cs-cad from Byte Nov. 1983
;
; NOTE: only meaningful with color card, and does not look at
;	keyboard (which makes it easywriter, etc. compatible)
;
;   To build this program:
;	1>  masm scrncolr;	/* assemble the code */
;	2>  link scrncolr;	/* link it - will get no stack seg. message */
;	3>  exe2bin scrncolr.exe scrncolr.com  /* make executable */
;	4>  del scrncolr.exe	/* don't need this anymore */
;
;  To use program:  run it or place in autoexec.bat as follows:
;
;		scrncolr nn rr
;
;			where nn are screen attributes to replace
;			normal white (attr=07h) video, and rr are
;			attributes for reversed white (attr=70h)
;			(intensity and blink are preserved).
;
;	for example, to change calls for white to white on blue
;	and to change calls for reverse white to magenta on white,
; 	issue the call:  "scrncolr 17 75"
;
;  Only 80x25 screen calls are affected and only in text mode,
;	(this makes it LOGO and APL compatible)
;
;  COMMANDS:
;	none -- you reassemble to change the color assignment

;***************************************************************
;
;  Define interrupt vectors for
;	screen interrupt 10H, in segment 0.
;
;***************************************************************

scrvect	segment	at 0		; define screen interrupt vector
	org	10h*4
SCRINT	label	dword
scrvect	ends

;***************************************************************
;
;	define constants
;
;***************************************************************

bw_val	   equ	07h		; standard b&w attibute sent to monitor

;***************************************************************
;
;	start code area
;
;***************************************************************

code	segment para
	assume	cs:code
	org	82h		; parameters
PARM	label	word		;    normal & rev attribs "nn rr"
	org	100h		; start code offset 100h from starting segment
				; (this leaves room for DOS's work areas)

KEY	proc	far
START:
	; Initialization code...used only once, on system startup

	jmp	init_code	; call initialization routine
even
	validchk db 'FCP!'	; used by INSTALL to check for valid SCREEN
				; program


;***************************************************************
;
;	SCR_RTNE - Replaces SCREEN interrupt so that it can intercept
;		B&W character writes and change attributes
;
;***************************************************************

SCR_RTNE:
	assume	ds:code
	sti
	push	ds		; get cs into ds  the funny way
	push	cs
	pop 	ds
	cmp	ah,0		; Spot mode change call
	jne	NOT_MODE
	mov	savemod,al	; Save mode input
NOT_MODE:
	cmp	ah,6		; Spot SCROLL UP and SCROLL DOWN calls
	jl	NORMAL_SCR	;
 	push	ax		; check if in 80x25 modes
 	mov	al,savemod
 	cmp	al,2
 	pop	ax
 	jl	NORMAL_SCR	; no-ignore attribs (keep LOGO straight)
 	push	ax		; check if in 80x25 modes
 	mov	al,savemod
 	cmp	al,3
 	pop	ax
 	jg	NORMAL_SCR	; no-ignore attribs (keep LOGO straight)

	cmp	ah,6
	jg	NOT_SCROLL	;

SCROLL:
	call	GET_CH		; for scrolling, update attribute
	jmp	NORMAL_SCR	; now, execute scroll

NOT_SCROLL:
	cmp	ah,9		; check for "WRITE ATTRIBUTE/CHAR" cmd
	jne	NORMAL_SCR	; send out any other command as normal
	xchg	bh,bl		; get attribute for command
	call	GET_CH		; update attribute for command
	xchg	bh,bl		; move attribute back to bh for cmd

NORMAL_SCR:
	pop	ds		; restore ds reg

	;
	; NOTE:	We are now ready to invoke the BIOS screen interrupt.
	;	Since the ROM code includes an IRET interrupt return call,
	;	all we need to do is to jump to the start of the ROM code
	;	and all will be well.  Since the initialization code set
	;	up the address to the screen interrupt code below, we can
	;	set up a forced jump to that address.

JMP_SCR:			; Address to SCREEN interrupt
	db	0EAh		; force a FAR JMP but do not set up dest-
	dw	0,0		;   ination address at assembly time.
				;   (INIT routine will set this address)

savemod db	3		;   default to 80x24 color mode

KEY endp                        ;done with main routine

;***************************************************************
;
;	GET_CH - subroutine replaces B&W character with current replacement
;			attributes and allows for intensity bit setting
;
;		Inputs : bh contains attribute to be modified
;
;***************************************************************

GET_CH	proc	near
	mov	savech,bh	; save character
	and	bh,77h		; Remove intensity and blink bits
	cmp	bh,07h    	; see if currently defined B&W value
	jne	ISITREV		; exit if not
	mov	bh,savech	; otherwise, modify to current attribute
	and	bh,88h		; get rid of B&W part
	or	bh,normvid	; move in current attribute part
	jmp	OUT

ISITREV:
	cmp	bh,70h		; see if currently defined W&B value
	mov	bh,savech	; otherwise, modify to current attribute
	jne	OUT
	and	bh,88h
	or	bh,revrvid

OUT:
	ret			; done

savech	db      0		; temporary character store
normvid	db	05h		; replacement for white norml video
revrvid	db	50h             ; replacement for reverse white video
GET_CH	endp

LASTONE:	; all code after this label is freed to DOS use after
		; initialization of the program.


;***************************************************************
;
;	INIT_CODE - Code to load and initialize the SCREEN program..
;		sets up DOS to keep all code before "LASTONE" label
;		safe from overlaying during system operation.
;
;***************************************************************

INIT_CODE proc  near

	; initialize SCREEN intercept code
	assume	es:scrvect		;'vectors' is interrupt segment 0

	mov	ax,scrvect		; get address to interrupt vector
	mov	es,ax			; save in es
	mov	ax,es:scrint		; get address to interrupt
	mov	bx,offset jmp_scr+1	; address to place to save vector
	mov	[bx],ax			; save interrupt address
	mov	ax,es:scrint[2]		; get interrupt segment for rtne
	mov	[bx+2],ax		; save it too
	mov	es:scrint,offset scr_rtne ; now replace with own address
	mov	ax,cs			; save segment in interrupt vector
	mov	es:scrint[2],ax		;

	mov	ax,cs			; make parameters for color
	mov	ds,ax			;   addressable
	mov	dx,PARM
	test	dx,0040h		; fix hex a-f
	jz	IT2
	sub	dx,0007h
IT2:	test	dx,4000h
	jz	IT3
	sub	dx,0700h
IT3:
	and	dx,0f0fh		; strip and jamb nibbles
	mov	cl,4
	shl	dl,cl
	or	dh,dl
	mov	normvid,dh		; save parameter
	mov	dx,PARM+3
	test	dx,0040h		; fix hex a-f
	jz	IT4
	sub	dx,0007h
IT4:	test	dx,4000h
	jz	IT5
	sub	dx,0700h
IT5:
	and	dx,0f0fh
	mov	cl,4
	shl	dl,cl
	or	dh,dl
	mov	revrvid,dh


	mov	dx,offset lastone	; save all code up to "LASTONE" label
	int	27h			; no return needed

INIT_CODE endp
code ends
end start
********************************************************************
********************************************************************
********************************************************************
********************************************************************
********************************************************************
********************************************************************
********************************************************************
********************************************************************
	page 64,132
	title bat-ques -- Batch file Question Asker, sets errorlevel
.RADIX 10
;
;
;
;*****************************************************************
; INFO-IBMPC libarary contribution by H. Fischer - HFischer@eclb 12/83
; If you like it, do not send me $10 (but I will accept amounts
; with many more zeros if your generosity is excessive).
; Questions/problems to HFischer@eclb (213/902-5139).
;
; This program allows a batch file to ask the user a question
; and return a one-character response which is testable
; by the IF subcommand of bat files, via the errorlevel.
;
; You use the question asker per following example:
;
;   .
;   .  (your batch file to ask if guy wants to edit with
;   .       mince/emacs or ibm's editor)
;   .
;   echo off
;   bat-ques WHICH EDITOR, m OR e FOR MINCE (EMACS), i FOR IBM's? $
;   if errorlevel 110 goto badresp
;   if errorlevel 109 goto minceed
;   if errorlevel 106 goto badresp
;   if errorlevel 105 goto ibmed
;   if errorlevel 102 goto badresp
;   if errorlevel 101 goto minceed
;   :badresp
;   echo Your response was invalid. Sorry
;   goto endit
;   :minceed
;   if not exist mincomm.sum copy \bin\mince.swp mince.swp
;   mince %1
;   if not exist mincomm.sum del mince.swp
;   goto endit
;   :ibmed
;   profed %1
;   :endit
;   echo on
;
; Note that the question prompt follows the bat-ques command and
; must end with a dollar sign.  The ascii value of the response is
; returned as the error level.  Since error level tests are always
; greater than or equal tests, you must check for highest value first
; and lowest value last.  Example above shows what you doto check for
; missing values.  Note example assumes lower case answer only for
; simplicity sake.
;
; Ascii values (e.g., A is 65, B is 66, a is 97) are found in back
; of your BASIC manual.  Only one character responses are accepted,
; and they are not followed by a carriage return.
;
; Extended ascii codes (function and alt keys) should work as per
; page G-6 of your BASIC manual;  the first call to bat-ques will
; return a zero and the next call (presumably "bat-ques $" without
; another prompt) will return the number shown on page G-7.
;
; To build this program:
;	1) asm bat-ques
;	2) link bat-ques
;	3) exe2bin bat-ques.exe \bin\bat-ques.com (name your path dir!)
;	4) del bat-ques.exe
;
; have fun
;********************************************************************
code	segment	para
	assume	cs:code
	org 	82h
PROMPT	label	byte		; here DOS places the prompt string
	org 	100h
KEY	proc	far
START:
	mov	ax,cs		; make this mess addressable via ds
	mov	ds,ax
	assume	ds:code
	mov	dx,offset PROMPT
	mov	ah,9
	int	21h		; display the prompt
	mov	ah,1
	int	21h             ; get the input into AL
	mov	saveit,al
	mov	dx,offset newlin  ; move display to new line
	mov	ah,9
	int	21h
	mov	al,saveit
	mov	ah,4ch		; return the errorlevel already in AL
	int	21h
newlin: db	10,13,'$'	; give user a new line before quitting
saveit	db	0
KEY endp
code ends
end start
-------