home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / CDOR0811.ZIP / SOURCE.ZIP / RBBSDV.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-01-23  |  13.2 KB  |  533 lines

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