home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2047 < prev    next >
Internet Message Format  |  1990-12-28  |  7KB

  1. From: roelofs@nas.nasa.gov (Cave Newt)
  2. Newsgroups: comp.binaries.ibm.pc.d,alt.sources
  3. Subject: Re: screen clearing TSR
  4. Message-ID: <1990Nov12.055127.16872@nas.nasa.gov>
  5. Date: 12 Nov 90 05:51:27 GMT
  6.  
  7. Michael Page, apm388p@vaxc.cc.monash.edu.au, writes:
  8.  
  9. >I am looking for a simple utility which will enable me to *clear the screen*
  10. >(by sending ANSI <esc>[2J ?) by issuing a keystroke, for example while I am
  11. >in graphics mode of NCSA Telnet or Kermit.  (Perhaps this last requirement 
  12. >is irrelevant because presumably the keystroke would be intercepted by the 
  13. >PC before it is sent off.)
  14.  
  15. It's not clear to me whether you want something to send a clear-screen 
  16. signal to the host computer or simply a local, PC-based screen-clearer.  
  17. If the latter, here's a small (and pretty stupid) TSR to do it for you.  
  18. All this does is check the current video mode and then do a reset to that 
  19. mode (so if you're in graphics mode, you'll stay that way).  It doesn't 
  20. do anything beyond that, however, so if you're in a 35-line editor mode, 
  21. you'll lose the bottom 10 lines (and maybe the cursor, too) when the mode 
  22. gets reset.  But hey--that's what caveat emptor is all about. :)
  23.  
  24. Appended is a uuencoded .com file, then source (so you can compare with a 
  25. debug dump and convince yourself there're no trojans lurking about), and 
  26. follow-ups to alt.sources.d.
  27.  
  28. Greg
  29. roelofs@amelia.nas.nasa.gov
  30.  
  31.  
  32. begin 600 hotclear.com
  33. MZS.0`````/M0Y&`\+G40N$``'H[8H!<`'R0//`IT!E@N_RX#`;`@YB!3M`_-
  34. J$#+DS1!;6,^X"37-(8D>`P&,!@4!M"6Z!P'-(:$L`([`M$G-(;HU`<TG
  35. `
  36. end
  37.  
  38.  
  39. ;------------------------------------------------------------------------------
  40. ; hotclear.asm                                          G. Roelofs, 11 Nov 90
  41. ;
  42. ; TSR to clear screen when hotkey is pressed.  Not very bright:  clears screen
  43. ; by resetting video mode, which will nuke colors, fonts, etc. (in particular,
  44. ; 35-, 43-, 50- and 60-line modes get changed back to 25-line mode).  In addi-
  45. ; tion, hotclear doesn't bother to check and see if it's already resident, nor
  46. ; does it have any mechanism for turning itself off (both are pretty trivial
  47. ; to add, however).  Default hotkey is ALT-LEFTSHIFT-C, but it may be changed.
  48. ;------------------------------------------------------------------------------
  49.  
  50. BIOS_DATA       segment at 40h                  ; BIOS data area
  51.  
  52.                 org 17h
  53. kb_flag         db      ?                       ; keyboard status (shift)
  54.  
  55. BIOS_DATA       ends
  56.  
  57.  
  58.  
  59. CSEG            segment
  60.                 assume cs:CSEG, ds:nothing, es:nothing
  61.  
  62.                 org     2Ch
  63. envir_seg       dw      ?                       ; segment addr of environment
  64.  
  65.                 org     100h                    ; .com program
  66. begin:          jmp     initialize              ; code to make TSR
  67.  
  68. ;       Equates, data
  69. ;       -------------
  70.  
  71. EOI             equ     20h                     ; end-of-interrupt signal
  72. INT_CTRL        equ     20h                     ; 8259 port address
  73. KB_DATA         equ     60h                     ; keyboard data port
  74. KB_CTRL         equ     61h                     ; keyboard control port
  75. KB_STAT         equ     64h                     ; keyboard status port
  76. SHIFT_MASK      equ     00001111b               ; overall shift mask
  77. ALT_MASK        equ     00001000b               ; alt shift key is down
  78. CTRL_MASK       equ     00000100b               ; ctrl shift key is down
  79. LEFT_MASK       equ     00000010b               ; left shift key is down
  80. RIGHT_MASK      equ     00000001b               ; right shift key is down
  81. HOTSHIFT        equ     ALT_MASK+LEFT_MASK      ; (or just ALT_MASK, etc.)
  82. HOTKEY          equ     2Eh                     ; "c" scan code
  83.  
  84. oldint9h        label   dword
  85. oldint9h_addr   dw      2 dup (?)               ; old keyboard handler vector
  86.  
  87. ;       New interrupt 9h handler:  if not hotkey, let old one do the work
  88. ;       -----------------------------------------------------------------
  89.  
  90. newint9h        proc    near
  91.  
  92.                 sti                             ; set interrupt enable flag
  93.                 push    ax                      ; save AX
  94.                 in      al, KB_DATA             ; get scan code from keyboard
  95.                 cmp     al, HOTKEY              ; our hotkey?
  96.                 jne     outta_here              ; nope:  we're outta_here
  97.  
  98.                 mov     ax, BIOS_DATA           ; yep:  now check for our shift
  99.                 push    ds                      ; save DS
  100.                 mov     ds, ax                  ; now pointing at BIOS data area
  101.                 assume  ds:BIOS_DATA            ; so assembler knows what's up
  102.                 mov     al, kb_flag             ; get keyboard status
  103.                 pop     ds                      ; restore DS
  104.                 assume  ds:nothing              ; oh, nothing...
  105.                 and     al, SHIFT_MASK          ; only alt, ctrl, normal shifts
  106.                 cmp     al, HOTSHIFT            ; see if ours is (are) down
  107.                 je      our_thing               ; yep:  do our_thing
  108.  
  109. outta_here:     pop     ax                      ; nope:  we're outta_here
  110.                 jmp     oldint9h                ; let old handler handle it
  111.  
  112. ;       The people have spoken:  do a hard reset of the video mode to
  113. ;       whatever it is now.  Then leave.
  114.  
  115. our_thing:      mov     al, EOI                 ; end-of-interrupt signal (else
  116.                 out     INT_CTRL, al            ;  system locks up)
  117.                 push    bx                      ; gets modified by video call
  118.                 mov     ah, 0Fh                 ; current-video-state function
  119.                 int     10h                     ; video interrupt
  120.                 xor    ah, ah                  ; set-video-mode function
  121.                 int     10h                     ; banzai
  122.                 pop     bx                      ; restore regs
  123.                 pop     ax                      ;
  124.                 iret                            ; hot damn:  all done
  125.  
  126. newint9h        endp
  127.  
  128. ;       Reset interrupt vector, free environment, and become resident
  129. ;       -------------------------------------------------------------
  130.  
  131. initialize      proc    near
  132.                 assume  ds:CSEG
  133.  
  134.                 mov     ax, 3509h               ; get current keyboard handler
  135.                 int     21h                     ;  vector
  136.                 mov     oldint9h_addr, bx       ; save it for later use
  137.                 mov     oldint9h_addr[2], es    ;
  138.                 mov     ah, 25h                 ; set vector to our routine
  139.                 mov     dx, OFFSET newint9h     ; 
  140.                 int     21h                     ;
  141.                 mov     ax, envir_seg           ; get environment segment
  142.                 mov     es, ax                  ; 
  143.                 mov     ah, 49h                 ; free allocated memory:
  144.                 int     21h                     ;  if fails...too bad
  145.                 mov     dx, OFFSET initialize   ; end of resident code
  146.                 int     27h                     ; become TSR and return to DOS
  147.  
  148. initialize      endp
  149.  
  150. CSEG            ends
  151.                 end     begin                   ; non-TSR entry point
  152.