home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / teseract / source / tsinit.asm < prev    next >
Encoding:
Assembly Source File  |  1988-10-02  |  10.9 KB  |  402 lines

  1. IFNDEF TP4
  2.         PAGE 60,132
  3. ;----------------------------------------------------------------------------
  4. SUBTTL  TesSeRact Revision Level 1
  5. ;-----------------------------------------------------------------------------
  6. ;   TesSeRact(tm) -- A Library of Routines for Creating Ram-Resident (TSR)
  7. ;                    programs for the IBM PC and compatible Personal
  8. ;                    Computers.
  9. ;
  10. ;The software, documentation and source code are: 
  11. ;       Copyright (C) 1986, 1987, 1988 Tesseract Development Team
  12. ;       All Rights Reserved 
  13. ;       c/o Chip Rabinowitz
  14. ;       Innovative Data Concepts
  15. ;       2084 Woodlawn Avenue
  16. ;       Glenside, PA 19038
  17. ;       1-215-884-3373
  18. ;
  19. ;-----------------------------------------------------------------------------
  20. ;   This product supports the TesSeRact Standard for Ram-Resident Program 
  21. ;   Communication.  For information about TesSeRact, contact the TesSeRact 
  22. ;   Development Team at:
  23. ;       Compuserve:    70731,20
  24. ;       MCIMAIL:       315-5415
  25. ;   This MCIMAIL Account has been provided to the TesSeRact Development
  26. ;   Team by Borland International, Inc.  The TesSeRact Development Team
  27. ;   is in no way associated with Borland International, Inc.
  28. ;-----------------------------------------------------------------------------
  29.  
  30. INCLUDE TESS.INC
  31. INCLUDE mixed.inc
  32.  
  33. IFDEF   ALLPUBLIC
  34. INCLUDE tsinit.pub      ;public definitions (uses Periscope PUBLIC.COM /E)
  35. ENDIF
  36.  
  37. .MODEL small
  38.  
  39. EXTRN TSRCLEANUP:FAR
  40.  
  41. .CODE
  42.  
  43. EXTRN _TESSSETUPINTS:near
  44. EXTRN _TESSGETPSP:near
  45. EXTRN _TESS_TEMPPARMS:byte
  46. EXTRN _TESS_CPYRT:byte
  47. EXTRN TESSBEEP:FAR
  48.  
  49. EXTRN TESS_GLOBALS:byte
  50. EXTRN TESS_USERPARMS:byte
  51.  
  52. ENDIF
  53.  
  54. IFNDEF ASMCOM
  55.  
  56. hProc <TSDOINIT FAR>, <USES SI,DI>, HotKeyScan:byte, ShiftStateFlag:byte, TSRFlags:word, MemoryTop:word
  57.  
  58. ELSE
  59.  
  60. ;
  61. ;       In the assembler version, parameters are passed in registers; note 
  62. ;           that this function should not return unless there was a major
  63. ;           problem!
  64. ;
  65. ;       On entry:
  66. ;               AH = Scan Code of hotkey
  67. ;               AL = Shift State of hotkey
  68. ;               BX = TSR Activation Flags
  69. ;               DX = offset of Top of Memory
  70. ;
  71.  
  72. PUBLIC TSDOINIT
  73. TSDOINIT proc near
  74.  
  75. ENDIF
  76.  
  77. IFNDEF ASMCOM
  78.  
  79.         ASSUMENODS
  80.         mov     ax,ds
  81.         push    ds                      ;save data segment
  82.  
  83.         mov     WPTR [OURDSEG],ax       ;save default data segment
  84.  
  85.         push    cs
  86.         pop     ds                      ;address our segments
  87.  
  88.         ASSUMEDS
  89.  
  90. ELSE
  91.  
  92.         ASSUMEDS
  93.  
  94.         mov     WPTR [OURDSEG],cs       ;save default data segment
  95.  
  96.         push    dx
  97.         push    bx
  98.         push    ax                      ;save parameters for later!
  99. ENDIF
  100.  
  101.         mov     ax,3000h                ;get DOS version number
  102.         int     21h
  103.         mov     BPTR [DOSVERSION],al    ;0=1+,2=2.0+,3=3.0+
  104.  
  105.         push    cs
  106.         pop     es                      ;address our segments
  107.  
  108.         lea     si,_TESS_TEMPPARMS
  109.         lea     di,[USERPARMS]
  110.         mov     cx,0ah
  111.  
  112.         rep     movsb
  113.  
  114.         mov     ax,3400h                ;find the DOS Indos Byte
  115.         int     21h
  116.  
  117.         mov     WPTR [INDOSFLAG],bx     ;offset returned in BX
  118.         mov     WPTR [INDOSFLAG+2],es ;segment returned in ES
  119.  
  120.  
  121.         cmp     BPTR [DOSVERSION],4     ;if we're running OS/2
  122.         ja      criterr_not_needed      ;fake the criterr byte
  123.  
  124.         mov     WPTR [DOSCRITERR+2],es  ;as well as the segment for the critical flag
  125.  
  126.         mov     cx,8000h                ;search for instruction: CMP [crit flag],00
  127.  
  128.         mov     bx,0                    ;start search at beginning of segment
  129. Find_Critical_flag:
  130.         mov     ax,3e80h                ;3e80 is opcode to search for
  131.         mov     di,bx                   ;start search here
  132.         repnz   scasw                   ;search until a match is found
  133.  
  134.         jz      save_critical
  135.         jmp     short next_try          ;couldn't find critical byte
  136.  
  137. save_critical:
  138.  
  139.                                         ;now we're going to search for the
  140.                                         ;address of the critical flag
  141.  
  142.                                         ;es:[di-2] now points to:
  143.                                         ;       CMP [crit flag],00
  144.                                         ;       JNZ ...
  145.                                         ;       MOV SP,indos stack address
  146.  
  147.         mov     al,BPTR es:[di+5]       ;MOV SP,xxxx
  148.         cmp     al,0bch                 ;opcode for MOV SP
  149.         je      Found_Critical
  150. ;..lf                                   ;not right opcode, seach again
  151.         mov     bx,di                   ;restart search from last byte
  152. next_try:
  153.         push    bx
  154.         rcr     bx,1                    ;see if first or second time
  155.         pop     bx
  156.         jc      try_again
  157.         jcxz    bump_bx                 ;make sure we have more to search for
  158.         jmp short Find_Critical_flag    
  159. bump_bx:
  160.         mov     bx,1                    ;start on odd boundary
  161.         mov     cx,8000h                ;odd bytes of segment
  162. try_again:
  163.         jcxz    skip2                   ;make sure we have more to search for
  164.         jmp short Find_Critical_flag    
  165. skip2:
  166.         jmp     no_crit_found
  167.  
  168. criterr_not_needed:
  169.         mov     WPTR [DOSCRITERR+2],cs  ;fake everyone out by setting
  170.                                         ;criterr to a known zero value
  171.         mov     WPTR [DOSCRITERR],offset TESS_GLOBALS - 1
  172.         jmp     short init_continue
  173.  
  174. Found_Critical:
  175.         mov     ax,WPTR es:[di] ;here's the critical byte address
  176.         mov     WPTR [DOSCRITERR],ax
  177. init_continue:
  178.  
  179. IFNDEF ASMCOM
  180.         mov     al,HotKeyScan
  181.         mov     BPTR [HOTKEY],al
  182.         mov     al,ShiftStateFlag
  183.         mov     BPTR [SHIFTST],al
  184.  
  185. ELSE
  186.         pop     ax                      ;recover hotkey stuff
  187.         mov     BPTR [HOTKEY],al
  188.         mov     BPTR [SHIFTST],ah
  189. ENDIF
  190.         xor     ax,ax
  191.         mov     WPTR [STATUS],ax        ;clear status flags
  192.  
  193. get_psp_dta:
  194.  
  195.         getdta  <[OURDTA]>
  196.  
  197.         call    _TESSGETPSP
  198.         mov     WPTR [OURPSP],bx
  199.  
  200. set_popup:
  201.  
  202. IFNDEF ASMCOM
  203.         mov     ax,TSRFlags
  204. ELSE
  205.         pop     ax                      ;recover Tsr Activation info
  206. ENDIF
  207.         mov     WPTR [STATUS],ax        ;turn on appropriate flags
  208.  
  209. IFNDEF NOCKSUM
  210.         push    cs
  211.         pop     ds                      ;our segment
  212.         mov     si,offset _TESS_CPYRT   ;address to check
  213.  
  214.         xor     ax,ax
  215.  
  216. CK      equ     0e0h
  217.  
  218. ck_1:
  219.         lodsb                           ;get the byte
  220.         or      al,al                   ;are we at end?
  221.         jz      c_ck                    ;yep
  222.  
  223.         add     ah,al                   ;add it in
  224.         jmp     ck_1
  225.  
  226. c_ck:
  227.  
  228.         cmp     ah,CK
  229.         je      ck_ok
  230.  
  231.         call    TESSBEEP
  232.         jmp     c_ck
  233. ck_ok:
  234. ENDIF
  235.  
  236. save_hdl:
  237.         push    ds
  238.         mov     ax,WPTR [OURPSP]        ;get our PSP segment
  239.         mov     ds,ax
  240.         mov     bx,18h                  ;offset of handle table
  241.         mov     cx,3
  242. save_hdl_loop:
  243.         push    [bx]                    ;save each handle on stack
  244.         inc     bx
  245.         inc     bx
  246.         loop    save_hdl_loop
  247.  
  248.         mov     cx,5
  249. close_loop:
  250.         push    cx                      ;close the DOS pre-opened
  251.         mov     bx,cx                   ;handles
  252.         dec     bx
  253.         mov     ah,03eh
  254.  
  255.         int     21h
  256.  
  257.         pop     cx
  258.         loop    close_loop
  259.  
  260. restore_hdl_tbl:
  261.  
  262.         mov     bx,1Ch                  ;restore the handles
  263.         mov     cx,3
  264. rest_hdl_loop:
  265.         pop     [bx]
  266.         dec     bx
  267.         dec     bx
  268.         loop    rest_hdl_loop
  269.  
  270.         pop     ds
  271.  
  272. ;
  273. ;This patch courtesy of Brian Foley of TurboPower Software
  274. ;
  275. patch_sidekick:
  276.  
  277.         mov     ax,3508h
  278.         int     21h
  279.  
  280.         cmp     WPTR es:[bx-4],4b53h
  281.         jne     go_resident
  282.  
  283.         cmp     WPTR es:[bx-2],4942h
  284.         jne     go_resident
  285.  
  286.         mov     cx,100d                 ;it's early in the handler
  287.  
  288.         mov     al,1fh                  ;1f8c is opcode to search for
  289.         mov     di,bx                   ;start search here
  290.  
  291. not_this_opcode:
  292.         repnz   scasb                   ;search until a match is found
  293.         jz      found_sk        
  294.  
  295.         jcxz    go_resident             ;must be SK+
  296.  
  297. found_sk:
  298.         cmp     BPTR es:[di+4],74h      ;is it the JZ code?
  299.         jne     not_this_opcode         ;already changed!
  300.  
  301.         mov     BPTR es:[di+4],0ebh
  302.  
  303. go_resident:
  304.  
  305.         push    ds
  306.         mov     ax,40h
  307.         mov     ds,ax
  308.  
  309.         ASSUMENODS
  310.  
  311.         mov     si,80h                  ;check the BIOS data area
  312.         lodsw                           ;to make sure it supports
  313.         or      ax,ax                   ;the points to the keyboard
  314.         jnz     ok_kbd                  ;buffer
  315.  
  316.         mov     di,80h                  ;not OK, so
  317.         push    ds                      ;load the pointers in 
  318.         pop     es                      ;the correct place
  319.  
  320.         cli
  321.         mov     ax,1eh
  322.         stosw
  323.         add     ax,20h
  324.         stosw
  325.         mov     di,1ah
  326.         sub     ax,20h
  327.         stosw
  328.         stosw
  329.         sti
  330. ok_kbd:
  331.         pop     ds
  332.         ASSUMEDS
  333.  
  334.         xor     ax,ax                   ;start with our interrupts
  335.         inc     ax
  336.         call    _TESSSETUPINTS          ;setup interrupts
  337.  
  338.         mov     ax,5453h                ;call multiplex
  339.         mov     bx,10h                  ;  to enable TSR
  340.         mov     cx,WPTR [IDNUM]         ; our ID Number
  341.         int     2fh
  342.  
  343.         push    ds
  344.         mov     ax,WPTR [OURDSEG]
  345.         mov     ds,ax
  346.  
  347.         ASSUMENODS
  348.  
  349.         xor     ax,ax
  350.  
  351. IFNDEF ASMCOM
  352.         push    ax                      ;AX=0, initialize routine
  353. ENDIF
  354.  
  355. IFDEF   TP4
  356. IFNDEF ASMCOM
  357.         call    DPTR PCLEANUP           ;call user routine (TP4 version)
  358. ELSE
  359.         call    TSRCLEANUP              ;call user routine
  360. ENDIF
  361. ELSE
  362.         call    TSRCLEANUP              ;call user routine
  363. ENDIF
  364.  
  365.         pop     ds
  366.  
  367.         ASSUMEDS
  368.  
  369. IFNDEF ASMCOM
  370.         mov     dx,MemoryTop
  371. ELSE
  372.         pop     dx                      ;recover top of memory
  373.         shr     dx,1
  374.         shr     dx,1
  375.         shr     dx,1
  376.         shr     dx,1                    ;convert to paragraphs (DX / 16)
  377.         inc     dx                      ;round up!!
  378. ENDIF
  379.  
  380.         xor     al,al                   ; no errors
  381.         mov     ah,31h                  ; load terminate & stay resident code
  382.         int     21h
  383.  
  384. no_crit_found:                          ;exiting 'cause we couldn't find the critical
  385.                                         ;error flag byte
  386. abort_out:
  387. IFNDEF ASMCOM
  388.         mov     ax,-1
  389.         pop     ds
  390.         hRet
  391. hEndp
  392.  
  393. ELSE
  394.         ret
  395. TSDOINIT endp
  396.  
  397. ENDIF
  398.  
  399. ENDIT
  400.