home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / BBS_UTIL / BM0406_A.ZIP / BMASM.ZIP / RBBSDV.ASM < prev    next >
Assembly Source File  |  1993-02-07  |  19KB  |  537 lines

  1. PAGE 60,132
  2. TITLE DESQview BASIC File Locking Interface Copyright 1988 by Jon Martin     
  3. ; Changes made for compatiblity with PDS v7.1 far string option (/Fs).
  4. ; Modification based on work by Scott McNay on 07/26/92.  Changed routines
  5. ; used by Scott for compatiblity and efficiency.  Thanks Scott for the
  6. ; breakthrough in giving RBBS 64K of string space!
  7. ; Richie Molinelli - 02/07/93
  8. ;--------------------------------------------------------------------;
  9. ;ROUTINE: LOCKDV              AUTHOR:  Jon Martin                    ;
  10. ;                                      4396 N. Prairie Willow Ct.    ;
  11. ;                                      Concord, California 94521     ;
  12. ;                                                                    ;
  13. ;DATE:  October 23, 1988      VERSION: 1.0                           ;       
  14. ;                                                                    ;
  15. ;DESCRIPTION: This subroutine enables programs written in Compiled   ;
  16. ;             BASIC to do Semaphore type resource locking when       ;
  17. ;             running in a DESQview environment.  Care was taken     ;
  18. ;             to allow the program to be fully DESQview aware.       ;
  19. ;             Programs calling this interface in a non DESQview      ;
  20. ;             environment will totally ignore the lock and unlock    ;
  21. ;             requests.  BEGINC (Begin critical) and ENDC (End       ;
  22. ;             critical) are used in a pre DESQview 2.00 environment. ;
  23. ;             API calls to Create and Test for the presence of       ;
  24. ;             mailboxes are used to implement the resource locking   ;
  25. ;             strategy when running in a DESQview 2.00 or higher     ;
  26. ;             environment.                                           ;
  27. ;                                                                    ;
  28. ;             LOCKING - Get resource name                            ;
  29. ;                       Find mailbox using resource name             ;
  30. ;                       If found then pause and loop until not found ;
  31. ;                       Create mailbox using resource name           ;
  32. ;                       return to calling program                    ;
  33. ;           UNLOCKING - Get resource name                            ;
  34. ;                       Find mailbox using resource name             ;
  35. ;                       If not found then return to calling program  ;
  36. ;                       If found then Close and Free mailbox         ;
  37. ;                       Return to calling program                    ;
  38. ;                                                                    ;
  39. ;                       BEGINC and ENDC have been wrapped around     ;
  40. ;                       those processes that were determined to be   ;
  41. ;                       necessary.                                   ;
  42. ;                                                                    ;
  43. ;FUNCTION: This routine supports calls from the IBM (MICROSOFT)      ;
  44. ;          BASIC Version 2.0 or Microsoft QuickBASIC Versions 1.0,   ;
  45. ;          2.01, 3.0, 4.00b & 4.50 compilers to the DESQview User    ;
  46. ;          Interface.  The calls are:                                ;
  47. ;                                                                    ;
  48. ;            CALL DVLOCK(resource name)                              ;
  49. ;                 a) returns if DESQview is not present              ;
  50. ;                 b) issues Begin Critical if DESQview level < 2.00  ;
  51. ;                 c) issues Lock Mailbox if DESQview level           ;
  52. ;                    >= 2.00                                         ;
  53. ;                                                                    ;
  54. ;            CALL DVUNLOCK(resource name)                            ;
  55. ;                 a) returns if DESQview is not present              ;
  56. ;                 b) issues End Critical if DESQview level <2.00     ;
  57. ;                 c) issues Unlock Mailbox if DESQview level         ;
  58. ;                    >= 2.00                                         ;
  59. ;                                                                    ;
  60. ; NOTE: "resource" must be a string and not exceed 32 characters     ;
  61. ;       Link this with your BASIC program in the following manner    ;
  62. ;                                                                    ;
  63. ;       LINK PGMNAME+LOCKDV,,,;                                      ;
  64. ;                                                                    ;
  65. ;--------------------------------------------------------------------;
  66.  
  67.                   EXTRN  StringAddress:FAR  ;FS020701
  68.  
  69. LOCKDV   SEGMENT BYTE PUBLIC 'CODE'
  70.  
  71.          ASSUME  CS:LOCKDV,DS:LOCKDV,ES:LOCKDV
  72.          ORG     0
  73. .xlist
  74. .SALL
  75. ;  DESQview API interfaces
  76.  
  77. ;***************************************************************
  78. ;
  79. ;  Function numbers (AX values) for the @CALL interface
  80. ;
  81. ;***************************************************************
  82.  
  83. DVC_PAUSE    EQU    1000H
  84. DVC_PRINTC    EQU    1003H
  85. DVC_GETBIT    EQU    1013H
  86. DVC_FREEBIT    EQU    1014H
  87. DVC_SETBIT    EQU    1015H
  88. DVC_ISOBJ    EQU    1016H
  89. DVC_LOCATE    EQU    1018H
  90. DVC_SOUND    EQU    1019H
  91. DVC_OSTACK    EQU    101AH
  92. DVC_BEGINC    EQU    101BH
  93. DVC_ENDC    EQU    101CH
  94. DVC_STOP    EQU    101DH
  95. DVC_START    EQU    101EH
  96. DVC_DISPEROR    EQU    101FH
  97. DVC_PGMINT    EQU    1021H
  98. DVC_POSWIN    EQU    1023H
  99. DVC_GETBUF    EQU    1024H
  100. DVC_USTACK    EQU    1025H
  101. DVC_POSTTASK    EQU    102BH
  102. DVC_NEWPROC    EQU    102CH
  103. DVC_KMOUSE    EQU    102DH
  104.  
  105. DVC_APPNUM    EQU    1107H
  106. DVC_DBGPOKE    EQU    110AH
  107. DVC_APILEVEL    EQU    110BH
  108. DVC_GETMEM    EQU    110CH
  109. DVC_PUTMEM    EQU    110DH
  110. DVC_FINDMAIL    EQU    110EH
  111. DVC_PUSHKEY    EQU    1110H
  112. DVC_JUSTIFY    EQU    1111H
  113. DVC_CSTYLE    EQU    1112H
  114.  
  115. DVC_DVPRESENT    EQU    0FFFFH
  116. DVC_SHADOW    EQU    0FFFEH
  117. DVC_UPDATE    EQU    0FFFDH
  118.  
  119. ;***************************************************************
  120. ;
  121. ;  Message numbers (BH values) for the @SEND interface
  122. ;
  123. ;***************************************************************
  124.  
  125. DVM_HANDLE    EQU    00H
  126. DVM_NEW        EQU    01H
  127. DVM_FREE    EQU    02H
  128. DVM_ADDR    EQU    03H
  129. DVM_DIR        EQU    03H
  130. DVM_READ    EQU    04H
  131. DVM_APPLY    EQU    04H
  132. DVM_WRITE    EQU    05H
  133. DVM_SIZEOF    EQU    08H
  134. DVM_LEN        EQU    09H
  135. DVM_ADDTO    EQU    0AH
  136. DVM_SUBFROM    EQU    0BH
  137. DVM_OPEN    EQU    0CH
  138. DVM_CLOSE    EQU    0DH
  139. DVM_ERASE    EQU    0EH
  140. DVM_STATUS    EQU    0FH
  141. DVM_EOF        EQU    10H
  142. DVM_AT        EQU    11H
  143. DVM_SETSCALE    EQU    11H
  144. DVM_SETNAME    EQU    11H
  145. DVM_READN    EQU    12H
  146. DVM_GETSCALE    EQU    12H
  147. DVM_REDRAW    EQU    13H
  148. DVM_SETESC    EQU    14H
  149. DVM_LOCK    EQU    14H
  150.  
  151. ;***************************************************************
  152. ;
  153. ;  Alias numbers (BL values) for the @SEND interface
  154. ;
  155. ;***************************************************************
  156.  
  157. DVA_TOS        EQU    00H
  158. DVA_ME        EQU    01H
  159. DVA_MAILTOS    EQU    02H
  160. DVA_MAILME    EQU    03H
  161. DVA_KEYTOS    EQU    04H
  162. DVA_KEYME    EQU    05H
  163. DVA_OBJQTOS    EQU    06H
  164. DVA_OBJQME    EQU    07H
  165. DVA_WINDOW    EQU    08H
  166. DVA_MAILBOX    EQU    09H
  167. DVA_KEYBOARD    EQU    0AH
  168. DVA_TIMER    EQU    0BH
  169. DVA_POINTER    EQU    0FH
  170. DVA_PANEL    EQU    10H
  171.  
  172.  
  173. ;***************************************************************
  174. ;
  175. ;  @SEND interface macro - bombs AH and BX
  176. ;
  177. ;***************************************************************
  178.  
  179. @SEND        macro    message,object
  180.         ifdef DVA_&object
  181.           MOV    BX,DVM_&message*256+DVA_&object
  182.             MOV    AH,12H
  183.           INT    15H
  184.         else        
  185.           @PUSH    &object
  186.           @SEND    &message,TOS
  187.         endif
  188.         endm
  189.  
  190. ;***************************************************************
  191. ;
  192. ;  @CALL interface macro - bombs AX
  193. ;
  194. ;***************************************************************
  195.  
  196. @CALL        macro    func
  197.             local    L1
  198.         ifndef DVC_&func
  199.           MOV    AX,&func
  200.           INT    15H
  201.         else
  202.         if (DVC_&func eq DVC_APILEVEL)
  203.           CMP    BX,200H        ; is 2.00 sufficient ?
  204.           JB    L1        ; jump if so
  205.           MOV    AX,DVC_APILEVEL    ; issue the call
  206.           INT    15H
  207.           CMP    AX,2        ; early version 2.00 ?
  208.           JNE    L1        ; jump if not
  209.           XCHG    BH,BL        ; reverse bytes
  210.           MOV    AX,DVC_APILEVEL    ; reissue call
  211.           INT    15H
  212.           XCHG    BH,BL        ; correct byte order
  213. L1:
  214.         else
  215.         if (DVC_&func eq DVC_DVPRESENT)
  216.           PUSH    BX        ; save registers
  217.           PUSH    CX
  218.           PUSH    DX
  219.           MOV    AX,2B01H    ; DOS Set Date function
  220.           XOR    BX,BX        ; in case outside DESQview
  221.           MOV    CX,'DE'        ; invalid date value
  222.           MOV    DX,'SQ'
  223.           INT    21H
  224.           MOV    AX,BX        ; version # to AX
  225.           CMP    AX,2        ; early DV 2.00 ?
  226.           JNE    L1        ; jump if not
  227.           XCHG    AH,AL        ; swap bytes if so
  228. L1:          POP    DX        ; restore registers
  229.           POP    CX
  230.           POP    BX
  231.         else
  232.         if (DVC_&func eq DVC_SHADOW)
  233.           MOV    AH,0FEH
  234.           INT    10H
  235.         else 
  236.         if (DVC_&func eq DVC_UPDATE)
  237.           MOV    AH,0FFH
  238.           INT    10H
  239.         else 
  240.           MOV    AX,DVC_&func
  241.           INT    15H
  242.         endif
  243.         endif
  244.         endif
  245.         endif
  246.         endif
  247.         endm
  248.  
  249.  
  250. ;***************************************************************
  251. ;
  252. ;  @PUSH and supporting macros - pushes 32-bit values on the stack
  253. ;
  254. ;***************************************************************
  255.  
  256. @PUSH_ESDI    macro
  257.         PUSH    ES
  258.         PUSH    DI
  259.         endm
  260.  
  261. @PUSH_DSSI    macro
  262.         PUSH    DS
  263.         PUSH    SI
  264.         endm
  265.  
  266. @PUSH_BXAX    macro
  267.         PUSH    BX
  268.         PUSH    AX
  269.         endm
  270.  
  271. @PUSH_DXCX    macro
  272.         PUSH    DX
  273.         PUSH    CX
  274.         endm
  275.  
  276. @PUSH_ESSI    macro
  277.         PUSH    ES
  278.         PUSH    SI
  279.         endm
  280.  
  281. @PUSH_DSDI    macro
  282.         PUSH    DS
  283.         PUSH    DI
  284.         endm
  285.  
  286. @PUSH        macro    parm
  287.         ifdef @PUSH_&parm
  288.           @PUSH_&parm
  289.         else          
  290.           PUSH    WORD PTR &parm+2
  291.           PUSH    WORD PTR &parm
  292.         endif
  293.         endm
  294.  
  295.  
  296. ;***************************************************************
  297. ;
  298. ;  @POP and supporting macros - pops 32-bit values from the stack
  299. ;
  300. ;***************************************************************
  301.  
  302. @POP_ESDI    macro
  303.         POP    DI
  304.         POP    ES
  305.         endm
  306.  
  307. @POP_DSSI    macro
  308.         POP    SI
  309.         POP    DS
  310.         endm
  311.  
  312. @POP_BXAX    macro
  313.         POP    AX
  314.         POP    BX
  315.         endm
  316.  
  317. @POP_DXCX    macro
  318.         POP    CX
  319.         POP    DX
  320.         endm
  321.  
  322. @POP_ESSI    macro
  323.         POP    SI
  324.         POP    ES
  325.         endm
  326.  
  327. @POP_DSDI    macro
  328.         POP    DI
  329.         POP    DS
  330.         endm
  331.  
  332. @POP        macro    parm
  333.         ifdef @POP_&parm
  334.           @POP_&parm
  335.         else          
  336.           POP    WORD PTR &parm
  337.           POP    WORD PTR &parm+2
  338.         endif
  339.         endm
  340.  
  341.  
  342. ;***************************************************************
  343. ;
  344. ;  @MOV and supporting macros - moves 32-bit values to/from memory
  345. ;
  346. ;***************************************************************
  347.  
  348. @DV_LOAD    macro    seg,off,arg
  349.         MOV    &seg,WORD PTR &arg+2
  350.         MOV    &off,WORD PTR &arg
  351.         endm
  352.  
  353. @DV_STORE    macro    seg,off,arg
  354.         MOV    WORD PTR &arg+2,&seg
  355.         MOV    WORD PTR &arg,&off
  356.         endm
  357.  
  358. @MOV_ESDI    macro    mac,arg
  359.         &mac    ES,DI,&arg
  360.         endm
  361.  
  362. @MOV_DSSI    macro    mac,arg
  363.         &mac    DS,SI,&arg
  364.         endm
  365.  
  366. @MOV_BXAX    macro    mac,arg
  367.         &mac    BX,AX,&arg
  368.         endm
  369.  
  370. @MOV_DXCX    macro    mac,arg
  371.         &mac    DX,CX,&arg
  372.         endm
  373.  
  374. @MOV_ESSI    macro    mac,arg
  375.         &mac    ES,SI,&arg
  376.         endm
  377.  
  378. @MOV_DSDI    macro    mac,arg
  379.         &mac    DS,DI,&arg
  380.         endm
  381.  
  382. @MOV        macro    dest,src
  383.         ifdef @MOV_&dest
  384.           @MOV_&dest    @DV_LOAD,&src
  385.         else
  386.           @MOV_&src    @DV_STORE,&dest
  387.         endif
  388.         endm
  389.  
  390.  
  391. ;***************************************************************
  392. ;
  393. ;  @CMP macro - compares BX:AX to DWORD in memory
  394. ;
  395. ;***************************************************************
  396.  
  397. @CMP        macro    parm
  398.         local    L1
  399.         CMP    AX,WORD PTR &parm
  400.         JNE    L1
  401.         CMP    BX,WORD PTR &parm+2
  402. L1:
  403.         endm
  404. .list
  405. CX_HOLD          DW      0
  406. SEMAPHORE        DD      0
  407. RESOURCE         DB      '                                '
  408. STRG_LOC         DW      0                       ;FS020701
  409.  
  410. DVLOCK   PROC    FAR
  411.          PUBLIC  DVLOCK 
  412.          PUSH    BP                              ;save base pointer
  413.          MOV     BP,SP                           ;establish new base
  414.          PUSH    DS                              ;save BASIC data segment
  415.          PUSH    ES                              ;save BASIC extra segment
  416. ;FS020701 MOV     BX,[BP+6]                       ;get string descriptor
  417. ;FS020701 MOV     DX,[BX+2]                       ;get address of string
  418. ;FS020701 MOV     CX,[BX]                         ;get length of string
  419.          PUSH    [BP+ 6]                         ;FS020701
  420.          CALL    StringAddress                   ;FS020701
  421.          MOV     CS:CX_HOLD,CX                   ;save length of string
  422.          MOV     CS:STRG_LOC,AX                  ;FS020701
  423.          PUSH    DS                              ;FS020701
  424.          PUSH    DX                              ;FS020701
  425.          POP     DS                              ;FS020701
  426.          MOV     SI,CS:STRG_LOC                  ;FS020701
  427.          MOV     CX,CS:CX_HOLD                   ;FS020701
  428.          PUSH    CS                              ;setup for ES
  429.          POP     ES                              ;ES now points to us
  430. ;FS020701MOV     SI,DX                           ;offset of BASIC'S string
  431.          LEA     DI,CS:RESOURCE                  ;point to resource name
  432.          CLD                                     ;start from bottom
  433.          REP     MOVSB                           ;copy string to resource name
  434.          POP     DS                              ;FS020701
  435.          @CALL   DVPRESENT                       ;test for DESQview
  436.          TEST    AX,AX                           ;well is it there?
  437.          JZ      LK_EXIT                         ;zero means no
  438.          MOV     BX,200H                         ;set API level required
  439.          CMP     AX,BX                           ;is required level supported?
  440.          JNB     APILKSEM                        ;not below means ok!
  441.          @CALL   BEGINC                          ;start critical
  442. LK_EXIT:
  443.          JMP     DVLOCK_EXIT                     ;exit lock resource
  444. APILKSEM:
  445.          @CALL   APILEVEL                        ;set API level
  446. LOOP_SEMA:
  447.          @CALL   BEGINC                          ;start critical
  448.          LEA     DI,CS:RESOURCE                  ;point to resource mailbox nm
  449.          PUSH    CS                              ;setup for ES
  450.          POP     ES                              ;ES now points to us
  451.          MOV     CX,CS:CX_HOLD                   ;setup resource name len
  452.          XOR     DX,DX                           ;clear high register
  453.          @CALL   FINDMAIL                        ;find the resource mailbox
  454.          TEST    BX,BX                           ;did we find it?
  455.          JZ      MAKE_SEMA                       ;zero means nope!
  456.          @CALL   ENDC                            ;end critical
  457.          @CALL   PAUSE                           ;let's wait for awhile
  458.          JMP     LOOP_SEMA                       ;let's go try again
  459. MAKE_SEMA:
  460.          @SEND   NEW,MAILBOX                     ;create resource mailbox
  461.          @POP    CS:SEMAPHORE                    ;save semaphore
  462.          LEA     DI,CS:RESOURCE                  ;point to resource mailbox nm
  463.          PUSH    CS                              ;setup for ES
  464.          POP     ES                              ;ES now points to us
  465.          @PUSH_ESDI                              ;put address on stack
  466.          MOV     CX,CS:CX_HOLD                   ;setup resource name len
  467.          XOR     DX,DX                           ;clear high register
  468.          @PUSH_DXCX                              ;put length on stack
  469.          @SEND   SETNAME,CS:SEMAPHORE            ;let's give it a name
  470.          @CALL   ENDC                            ;end critical
  471. DVLOCK_EXIT:
  472.          POP     ES                              ;restore BASIC extra segment
  473.          POP     DS                              ;restore BASIC data segment
  474.          POP     BP                              ;restore BASIC base pointer
  475.          RET     2                               ;return to BASIC
  476. DVLOCK   ENDP
  477.  
  478. DVUNLOCK PROC    FAR
  479.          PUBLIC  DVUNLOCK
  480.          PUSH    BP                              ;save base pointer
  481.          MOV     BP,SP                           ;establish new base
  482.          PUSH    DS                              ;save BASIC data segment
  483.          PUSH    ES                              ;save BASIC extra segment
  484. ;FS020701 MOV     BX,[BP+6]                       ;get string descriptor
  485. ;FS020701 MOV     DX,[BX+2]                       ;get address of string
  486. ;FS010701 MOV     CX,[BX]                         ;get length of string
  487.          PUSH    [BP+ 6]                         ;FS020701
  488.          CALL    StringAddress                   ;FS020701
  489.          MOV     CS:CX_HOLD,CX                   ;save length of string
  490.          MOV     CS:STRG_LOC,AX                  ;FS020701
  491.          PUSH    DS                              ;FS020701
  492.          PUSH    DX                              ;FS020701
  493.          POP     DS                              ;FS020701
  494.          MOV     SI,CS:STRG_LOC                  ;FS020701
  495.          MOV     CX,CS:CX_HOLD                   ;FS020701
  496.          PUSH    CS                              ;setup for ES
  497.          POP     ES                              ;ES now points to us
  498. ;FS020701 MOV     SI,DX                           ;offset of BASIC'S string
  499.          LEA     DI,CS:RESOURCE                  ;point to resource name
  500.          CLD                                     ;start from bottom
  501.          REP     MOVSB                           ;copy string to resource name
  502.          POP     DS                              ;FS020701
  503.          @CALL   DVPRESENT                       ;test for DESQview
  504.          TEST    AX,AX                           ;well is it there?
  505.          JZ      UNLKSEMA_EXIT                   ;zero means no
  506.          MOV     BX,200H                         ;set API level required
  507.          CMP     AX,BX                           ;is required level supported?
  508.          JNB     APIULSEM                        ;not below means ok!
  509.          @CALL   ENDC                            ;end critical
  510. UNLKSEMA_EXIT:
  511.          JMP     DVUNLOCK_EXIT                   ;exit unlock resource
  512. APIULSEM:
  513.          @CALL   APILEVEL
  514.          LEA     DI,CS:RESOURCE                  ;point to resource mailbox nm
  515.          PUSH    CS                              ;setup for ES
  516.          POP     ES                              ;ES now points to us
  517.          MOV     CX,CS:CX_HOLD                   ;setup resource name len
  518.          XOR     DX,DX                           ;clear high register
  519.          @CALL   FINDMAIL                        ;find resource mailbox
  520.          TEST    BX,BX                           ;did we find it?
  521.          JZ      DVUNLOCK_EXIT                   ;zero means nope!
  522.          @MOV    CS:SEMAPHORE,DSSI               ;found so save semaphore
  523.          @CALL   BEGINC                          ;begin critical
  524.          @SEND   CLOSE,CS:SEMAPHORE              ;unlock resource mailbox
  525.          @SEND   FREE,CS:SEMAPHORE               ;release resource mailbox
  526.          @CALL   ENDC                            ;end critical
  527. DVUNLOCK_EXIT:
  528.          POP     ES                              ;restore BASIC extra segment
  529.          POP     DS                              ;restore BASIC data segment
  530.          POP     BP                              ;restore BASIC base pointer
  531.          RET     2                               ;return to BASIC
  532. DVUNLOCK ENDP
  533.  
  534. LOCKDV   ENDS
  535.          END
  536. 
  537.