// TSR_4 Example //Scout (expr JumpFAR ?) -> bytes =0EAh, ^1(4) equals _KeyboardFlags = 0417h equals Request = 0EAABh, Reply = 0ABEAh, HotKey = 0E08h, ShiftStatus = 00000001b MODEL Tiny, Pascal .ORG 100h PROGRAM TSR_4 .LOCALS _@ goto Initialize bytes Flags = 00000000b, SaveAH (proc FAR Int_16h()[] (if cs:Flags.test.00000001b= (if ah.test.11101110b<> if ax<>Request goto Pass_16h ax=Reply; push cs; pop es; .iret if) (if ah.test.00000001b= (while cs:SaveAH=ah .sti; .pushf; .cli; call DWORD PTR cs:Old_Int_16h() if ax<>HotKey then .iret call ChkShiftStatus() if <> then .iret call Main() ah=cs:SaveAH while) if) cs:SaveAH=ah; cs:SaveAH=-1 .sti; .pushf; .cli; call DWORD PTR cs:Old_Int_16h() (if <> and ax=HotKey call ChkShiftStatus() if <> then 2=.retf ah=cs:SaveAH .pushf; .cli; call DWORD PTR cs:Old_Int_16h() call Main() if) 2=.retf if) Pass_16h: JumpFAR Old_Int_16h proc) (proc ChkShiftStatus()[ax,es] es=ax=0 al=BYTE PTR es:[_KeyboardFlags]; al=.and.00001111b al=.cmp.ShiftStatus return proc) (proc Main()[ax] cs:Flags=.or.00000001b // [ Куча всего ] // Например: ax=0E07h; 10h=.int // cs:Flags=.and.11111110b return proc) equals DataSize = $ - OFFSET TSR_4 Initialize: // Перенаправляем стек sp=StackPtr push ax=0 // Перераспределить память bx=ProgSize; ah=4Ah; 21h=.int // Проверить наличие себя в памяти ax=Request; 16h=.int (if ax<>Reply bx=((DataSize+15)/16) ah=48h; 21h=.int es=ax si=OFFSET TSR_4; di=0; cx=DataSize; movsb=.rep // Чтобы со 100h начиналось (save ax) es=ax=-16 // Владелец WORD PTR es:[0F1h]=ax // Имя di=0F8h; si=OFFSET MyName; cx=3; movsw=.rep push es; pop ds ax=3516h; 21h=.int WORD PTR ds:[Old_Int_16h]=bx WORD PTR ds:[Old_Int_16h+2]=es dx=OFFSET Int_16h ah=25h; 21h=.int goto Finish if) // UnInstall dx=es ax=3516h; 21h=.int bx=-OFFSET Int_16h ax=es-dx.or.bx if <> goto Finish dx=.lds.DWORD PTR es:[Old_Int_16h] ax=2516h; 21h=.int push cs; pop ds es=ax=es+16 ah=49h; 21h=.int Finish: ax=4C00h; 21h=.int bytes MyName = "TSR_4".0 .evendata data StackBuff(100h), 'StackPtr' = OFFSET $, 'ProgSize' = (OFFSET $ - OFFSET TSR_4 + 100h + 15) SHR 4