Allo Denis!
Here is the program you sent me. I modified it to practice with the example
of dos stack swaping. I really want to make it. If you can find the "bug"
send it back.
;[BOSSKEY.ASM] - v1.00 Public Domain (pd) 1997 by Denis Boyles
; ! Arrowsoft Assembler v1.00D (MASM v3.0)
; ? A demonstration "hot-key" TSR program that utilizes the
NDOS
; flag. The program is a "Boss Screen" that's activated by
; pressing ALT-SYSRQ. Upon entry, INDOS is checked to see if
; it's safe to call DOS functions.
;
; If it's safe, the progam saves the current text screen,
; clears it and displays the "Boss Screen". Which is nothing
; more than a "Command Prompt" lookalike. Pressing a key will
; restore the screen and return to the interrupted program.
;
; * ALT-SYSRQ checking requires AT+ computer.
; CGA+ is required for the save/restore of the screen.
; Video mode changes are NOT intercepted, so be careful.
KEYBOARD EQU 16h ;define KEYBOARD services interrupt
DOS EQU 21h ;define DOS services interrupt
LF EQU 0Ah ;define linefeed character
CR EQU 0Dh ;define carriage return character
DUL EQU '$' ;define dollar sign string terminator
PRG SEGMENT
ASSUME CS:PRG,DS:PRG
ORG 0100h
;[START]-------------------------------------------------------------------
; DOS Program Entry Point.
START:
jmp main
;[DATA]--------------------------------------------------------------------
; TSR Local variables are kept here.
YourStack DD 00000000
MyStack DD 00000000
InCAS db 0 ;our own "flag" for program activation
InDOS dd ? ;pointer address to INDOS flag
OldCas dd ? ;pointer address of previous casette
INT
buffer db 4096 dup(?) ;buffer to store one 80x25 text screen
banner db CR,"Microsoft(R) MS-DOS(R) Version 6.20",CR,LF
db " (C)Copyright Microsoft Corp 1981-1993.",CR,LF,LF
db "C:\>"
db DUL
;[NEWCAS]------------------------------------------------------------------
; Our new casette interrupt handler (15h) which intercepts ALT-SYSRQ.
NewCas PROC
cmp AX,8500h ;keyboard calls this if ALT-SYSRQ
ress
jne NC1 ;if not, then chain to previous
ndler
mov word ptr [YourStack][0],sp ;
mov word ptr [YourStack][2],ss ;
mov ss,cs: word ptr [MyStack][2] ;
mov sp,cs: word ptr [MyStack][0] ;
push AX ;save ALL used registers
push CX
push DX
push DS
push ES
push DI
push SI
lds SI,CS:[InDOS] ;DS:SI = INDOS pointer address
lodsb ;load INDOS flag into AL
or AL,AL ;test for zero condition
jnz NC0 ;if 1 then INDOS so exit handler
mov AL,CS:[InCAS] ;load handler flag into AL
or AL,AL ;test for zero condition
jnz NC0 ;if 1 then already in handler, exit
not AL ;otherwise, flip flag, 0=FF=0
mov CS:[InCAS],AL ;store back into memory
call SaveScreen ;save current text screen to buffer
call ClearScreen ;clear current text screen
push CS ;save CS to stack so we can
pop DS ;load it back as DS to access data
mov AH,09h ;DOS - Print an ASCID String
mov DX,offset banner ;DS:DX -> string to print
int DOS ;DOS - call interrupt to print string
xor AH,AH ;KEYBOARD - Read Keyboard
int KEYBOARD ;KEYBOARD - call interrupt for
ypress
call LoadScreen ;restore text screen from buffer
mov AL,[InCAS] ;load handler flag into AL
not AL ;flip it back off FF=0=FF
mov [InCAS],AL ;store back into memory
NC0: ;come here when ALT-SYSRQ was pressed
cli
pop SI ;restore ALL saved registers
pop DI
pop ES
pop DS
pop DX
pop CX
pop AX
mov ss,cs: word ptr [YourStack][2]
mov sp,cs: word ptr [YourStack][0]
NC1: ;come here if ALT-SYSRQ was NOT
ressed
jmp CS:[OldCas] ;chain to previous interrupt handler
NewCas ENDP
;[SAVESCREEN]--------------------------------------------------------------
; Saves the current 80x25 color screen into the memory buffer.
SaveScreen PROC
mov AX,0B800h ;AX = B800h (color RAM segment)
mov DS,AX ;DS = AX = set source segment
xor SI,SI ;zero out source index
push CS ;save CS onto the stack to
pop ES ;load it back as ES, destination
mov DI,offset buffer ;DI = destination offset to buffer
mov CX,2048 ;CX = 4096 / 2 WORDS data to copy
rep movsw ;copy RAM to BUFFER
ret
SaveScreen ENDP
;[CLEARSCREEN]-------------------------------------------------------------
; Clears the current screen to the default DOS colors.
ClearScreen PROC
mov AX,0B800h ;AX = B800h (color RAM segment)
mov ES,AX ;ES = AX = destination segment
xor DI,DI ;zero out destination index
mov AX,0720h ;AH = gray on black, AL = space
mov CX,2048 ;CX = 4096 / 2 WORDS data to set
rep stosw ;fill screen with AX attribute
ret
ClearScreen ENDP
;[LOADSCREEN]--------------------------------------------------------------
; Restores the current text screen from the previously saved buffer.
LoadScreen PROC
mov SI,offset buffer ;SI = offset of source buffer
xor DI,DI ;zero out destination index
mov CX,2048 ;CX = 4096 / 2 WORDS data to copy
rep movsw ;copy BUFFER back to RAM
ret
LoadScreen ENDP
POINTER1 DB 100h dup(?) ; reserve 256 undefined bytes
EndStack:
;[SNIP]--------------------------------------------------------------------
; ALL code and data upto this point is kept resident in memory.
SNIP:
;[MAIN]--------------------------------------------------------------------
; Starting point of program after jump from initial entry above.
main PROC
mov ax,cs
mov cs:word ptr [MyStack][2],ax
mov cs:word ptr [MyStack][0],offset EndStack
mov AH,34h ;DOS - Get INDOS Address
int DOS ;DOS - call interrupt to get pointer
mov word ptr [InDOS][2],ES ;save segment (ES) in memory
mov word ptr [InDOS][0],BX ;save segment (BX) in memory
inc AH ;DOS - Get Interrupt Vector
mov AL,15h ;AL = interrupt vector to get
int DOS ;DOS - call interrupt to get vector
mov word ptr [OldCas][2],ES ;save segment (ES) in memory
mov word ptr [OldCas][0],BX ;save segment (BX) in memory
sub AH,10h ;DOS - Set Interrupt Vector
mov DX,offset NewCas ;DS:DX -> new interrupt handler
int DOS ;DOS - call interrupt to set vector
mov DX,offset SNIP ;ALL code/data upto SNIP is kept
mov CL,04h ;shift count of 4 to convert
shr DX,CL ;into paragraphs (DX/16)
inc DX ;plus one more to round up
mov AX,3100h ;DOS - TSR Program With Code (0)
int DOS ;DOS - call interrupt to leave
esident
main ENDP
PRG ENDS
END START
note: the Alt-Sysrequest doesn't work under dv. Also typing print screen key
deactivate complety the TSR.
Bye!
Sylvain
---
---------------
* Origin: Silicon Palace {514}432-2953 Lafontaine, Qu‚bec (1:242/100)
|