TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: DENIS BOYLES
from: SYLVAIN LAUZON
date: 1997-04-16 14:48:00
subject: Switching Stacks

The program worked until i load something in memory. I modified it a bit
but still bug. The keyboard interrupt didn't respond correctly after its
execution. Take a look on what i added. nothing fancy and should work but??
:-))
;--------------------------------------------------------------------------
;[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 ?
OldIdle     dd ?
indos       dd ?
critterr    dd ?
re_enter    db 0
;[NEWTCK]------------------------------------------------------------------
;   Our new timer handler, IRQ-0 (8)
NewTck PROC
    cli                                     ;disable interrupts
    cmp cs:re_enter,00h
    jne It
    mov cs:re_enter,01h
    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
    pusha
    les bx,dword ptr cs:indos
    cmp byte ptr es:[bx],00h
    jne short Exit
    les bx,dword ptr cs:critterr       ; Check critical error flag
    cmp byte ptr es:[bx],00h
    jnz short Exit
    popa
    pusha
    mov     AX,1001h                        ;VIDEO - set border color
    int     10h                             ;call VIDEO to change border
Exit:
    popa                                    ;pop all registers
    popa
    mov     SS,word ptr CS:[YourStack][2]   ;restore interrupted stack
    mov     SP,word ptr CS:[YourStack][0]
    mov cs:re_enter,00h                     ; can be safely re-entered now
    sti                                     ;enable interrupts
It: 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 ah,34h
    int 21h
    mov word ptr indos,bx
    mov word ptr indos+2,es
    mov word ptr critterr+2,es
    push bx
    mov ah,30h
    int 21h
    je DOSver2
    ja DOSver3
DOSver2:    ;If here, DOS Version 2.x is being run:
    pop     bx                      ;Get indosptr from stack.
    inc     bx                      ;CritErr flag is @ indosptr+1.
    mov     Word Ptr critterr,bx  ;Save CritErr Pointer.
    jmp     Go
            ;
 DOSver3:    ;If here, DOS Version 3.+ is being run:
    pop     bx                      ;Get indosptr from stack.
    dec     bx                      ;CritErr flag is @ indosptr-1.
    mov     Word Ptr critterr,bx  ;Save CritErr Pointer.
Go:
    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
 ;--------------------------------------------------------------------------
Shreddedwheat!,
Sylvain
---
---------------
* Origin: Silicon Palace {514}432-2953 Lafontaine, Qu‚bec (1:242/100)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.