[comp.binaries.ibm.pc.d] screen clearing TSR

apm388p@vaxc.cc.monash.edu.au (11/07/90)

Hi There, 

[I'm not sure if this made it out of here on the first go, so this is a repost]

I am looking for a simple utility which will enable me to *clear the screen*
(by sending ANSI <esc>[2J ?) by issuing a keystroke, for example while I am
in graphics mode of NCSA Telnet or Kermit.  (Perhaps this last requirement 
is irrelevant because presumably the keystroke would be intercepted by the 
PC before it is sent off.)

Is such a thing possible or available anywhere?  I looked through SIMTELs
screen directory but nothing seemed appropriate.  I'm not after a command-line
clear as I want it to operate while I'm running a program.

Thanks in advance,

Michael Page, Mathematics Department, Monash Uni, Melbourne, Oz

apm388p%monu1.cc.monash.edu.AU@uunet.uu.NET

roelofs@nas.nasa.gov (Cave Newt) (11/12/90)

Michael Page, apm388p@vaxc.cc.monash.edu.au, writes:

>I am looking for a simple utility which will enable me to *clear the screen*
>(by sending ANSI <esc>[2J ?) by issuing a keystroke, for example while I am
>in graphics mode of NCSA Telnet or Kermit.  (Perhaps this last requirement 
>is irrelevant because presumably the keystroke would be intercepted by the 
>PC before it is sent off.)

It's not clear to me whether you want something to send a clear-screen 
signal to the host computer or simply a local, PC-based screen-clearer.  
If the latter, here's a small (and pretty stupid) TSR to do it for you.  
All this does is check the current video mode and then do a reset to that 
mode (so if you're in graphics mode, you'll stay that way).  It doesn't 
do anything beyond that, however, so if you're in a 35-line editor mode, 
you'll lose the bottom 10 lines (and maybe the cursor, too) when the mode 
gets reset.  But hey--that's what caveat emptor is all about. :)

Appended is a uuencoded .com file, then source (so you can compare with a 
debug dump and convince yourself there're no trojans lurking about), and 
follow-ups to alt.sources.d.

Greg
roelofs@amelia.nas.nasa.gov


begin 600 hotclear.com
MZS.0`````/M0Y&`\+G40N$``'H[8H!<`'R0//`IT!E@N_RX#`;`@YB!3M`_-
J$#+DS1!;6,^X"37-(8D>`P&,!@4!M"6Z!P'-(:$L`([`M$G-(;HU`<TG
`
end


;------------------------------------------------------------------------------
; hotclear.asm                                          G. Roelofs, 11 Nov 90
;
; TSR to clear screen when hotkey is pressed.  Not very bright:  clears screen
; by resetting video mode, which will nuke colors, fonts, etc. (in particular,
; 35-, 43-, 50- and 60-line modes get changed back to 25-line mode).  In addi-
; tion, hotclear doesn't bother to check and see if it's already resident, nor
; does it have any mechanism for turning itself off (both are pretty trivial
; to add, however).  Default hotkey is ALT-LEFTSHIFT-C, but it may be changed.
;------------------------------------------------------------------------------

BIOS_DATA       segment at 40h                  ; BIOS data area

                org 17h
kb_flag         db      ?                       ; keyboard status (shift)

BIOS_DATA       ends



CSEG            segment
                assume cs:CSEG, ds:nothing, es:nothing

                org     2Ch
envir_seg       dw      ?                       ; segment addr of environment

                org     100h                    ; .com program
begin:          jmp     initialize              ; code to make TSR

;       Equates, data
;       -------------

EOI             equ     20h                     ; end-of-interrupt signal
INT_CTRL        equ     20h                     ; 8259 port address
KB_DATA         equ     60h                     ; keyboard data port
KB_CTRL         equ     61h                     ; keyboard control port
KB_STAT         equ     64h                     ; keyboard status port
SHIFT_MASK      equ     00001111b               ; overall shift mask
ALT_MASK        equ     00001000b               ; alt shift key is down
CTRL_MASK       equ     00000100b               ; ctrl shift key is down
LEFT_MASK       equ     00000010b               ; left shift key is down
RIGHT_MASK      equ     00000001b               ; right shift key is down
HOTSHIFT        equ     ALT_MASK+LEFT_MASK      ; (or just ALT_MASK, etc.)
HOTKEY          equ     2Eh                     ; "c" scan code

oldint9h        label   dword
oldint9h_addr   dw      2 dup (?)               ; old keyboard handler vector

;       New interrupt 9h handler:  if not hotkey, let old one do the work
;       -----------------------------------------------------------------

newint9h        proc    near

                sti                             ; set interrupt enable flag
                push    ax                      ; save AX
                in      al, KB_DATA             ; get scan code from keyboard
                cmp     al, HOTKEY              ; our hotkey?
                jne     outta_here              ; nope:  we're outta_here

                mov     ax, BIOS_DATA           ; yep:  now check for our shift
                push    ds                      ; save DS
                mov     ds, ax                  ; now pointing at BIOS data area
                assume  ds:BIOS_DATA            ; so assembler knows what's up
                mov     al, kb_flag             ; get keyboard status
                pop     ds                      ; restore DS
                assume  ds:nothing              ; oh, nothing...
                and     al, SHIFT_MASK          ; only alt, ctrl, normal shifts
                cmp     al, HOTSHIFT            ; see if ours is (are) down
                je      our_thing               ; yep:  do our_thing

outta_here:     pop     ax                      ; nope:  we're outta_here
                jmp     oldint9h                ; let old handler handle it

;       The people have spoken:  do a hard reset of the video mode to
;       whatever it is now.  Then leave.

our_thing:      mov     al, EOI                 ; end-of-interrupt signal (else
                out     INT_CTRL, al            ;  system locks up)
                push    bx                      ; gets modified by video call
                mov     ah, 0Fh                 ; current-video-state function
                int     10h                     ; video interrupt
                xor	ah, ah                  ; set-video-mode function
                int     10h                     ; banzai
                pop     bx                      ; restore regs
                pop     ax                      ;
                iret                            ; hot damn:  all done

newint9h        endp

;       Reset interrupt vector, free environment, and become resident
;       -------------------------------------------------------------

initialize      proc    near
                assume  ds:CSEG

                mov     ax, 3509h               ; get current keyboard handler
                int     21h                     ;  vector
                mov     oldint9h_addr, bx       ; save it for later use
                mov     oldint9h_addr[2], es    ;
                mov     ah, 25h                 ; set vector to our routine
                mov     dx, OFFSET newint9h     ; 
                int     21h                     ;
                mov     ax, envir_seg           ; get environment segment
                mov     es, ax                  ; 
                mov     ah, 49h                 ; free allocated memory:
                int     21h                     ;  if fails...too bad
                mov     dx, OFFSET initialize   ; end of resident code
                int     27h                     ; become TSR and return to DOS

initialize      endp

CSEG            ends
                end     begin                   ; non-TSR entry point