Hi Sylvain,
Here's another little test program I put together that switches stacks. It
hooks the timer again so it gets a constant signal to test with. Before
hand the program sets MyStack to the PSP. Then during the handler, it
switches the current stack with that one. Upon which some registers are
pushed, a video interrupt is called and the registers are popped again.
Hopefully if all goes well, the program won't crash the system while all
this goes on. The video interrupt changes the border color to whatever is
in BX upon entry.
;--------------------------------------------------------------------------
;[TSRSTACK.ASM] - Public Domain (pd) by Denis Boyles
; ? A simple example of switching stacks within a TSR program.
This
; example uses the PSP for the stack giving it 256 bytes.
; ! Arrowsoft Assembler v1.00D / VAL Linker
.186 ;enable 80186+ instructions
PRG SEGMENT
ASSUME CS:PRG,DS:PRG
ORG 0100h
;[START]-------------------------------------------------------------------
; DOS Program Entry Point
START:
jmp main
;[DATA]--------------------------------------------------------------------
; Local global TSR data goes here
YourStack dd ?
MyStack dd ?
OldTck dd ?
;[NEWTCK]------------------------------------------------------------------
; Our new timer handler, IRQ-0 (8)
NewTck PROC
cli ;disable interrupts
mov word ptr CS:[YourStack][2],SS ;save interrupted stack address
mov word ptr CS:[YourStack][0],SP
mov SS,word ptr CS:[MyStack][2] ;set our own stack
mov SP,word ptr CS:[MyStack][0]
pusha ;push all registers
mov AX,1001h ;VIDEO - set border color
int 10h ;call VIDEO to change border
popa ;pop all registers
mov SS,word ptr CS:[YourStack][2] ;restore interrupted stack
mov SP,word ptr CS:[YourStack][0]
sti ;enable interrupts
jmp CS:[OldTck] ;chain to previous handler
NewTck ENDP
;[SNIP]--------------------------------------------------------------------
; All code/data upto this point is kept resident in memory
SNIP:
;[MAIN]--------------------------------------------------------------------
; Actual start of program, jumped to from DOS entry point above.
main PROC
mov word ptr [MyStack][2],CS ;save our stack address
mov word ptr [MyStack][0],offset START ;we'll use the PSP space
mov AX,3508h ;DOS - get vector for INT-08h (IRQ-0)
int 21h ;call DOS to get the address
mov word ptr [OldTck][2],ES ;save segment
mov word ptr [OldTck][0],BX ;save offset
sub AH,10h ;DOS - set vector for INT-08h (IRQ-0)
mov DX,offset NewTck ;DS:DX -> new handler routine
int 21h ;call DOS to set the new address
mov DX,offset SNIP ;all code upto SNIP is kept resident
shr DX,04h ;convert to paragraphs
inc DX ;plus one more to round up
mov AX,3100h ;DOS - TSR program with code (0)
int 21h ;call DOS to TSR program
main ENDP
PRG ENDS
END START
;--------------------------------------------------------------------------
Cheers,
Denis Boyles
* OLX 2.1 TD * Hello, I am part number ||X||||X||X||X||
--- Maximus/2 3.01
---------------
* Origin: Frog Hollow Port Moody BC 604-469-0264/0284 (1:153/290)
|