home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / SRPI.ZIP / SRPI / SRPI_M / MSAMPL.ASM < prev    next >
Assembly Source File  |  1991-09-04  |  14KB  |  294 lines

  1. ;*************************PROLOGUE*******************************
  2. ;                                                               *
  3. ; MODULE NAME = MSAMPL.ASM                                      *
  4. ;                                                               *
  5. ; DESCRIPTIVE NAME = Macro Assembler Sample Program             *
  6. ;                                                               *
  7. ; STATUS=    Extended Services Version 1.0 Modification 0       *
  8. ;                                                               *
  9. ; COPYRIGHT=  (C) COPYRIGHT IBM CORP. 1988, 1991                *
  10. ;             LICENSED MATERIAL - PROGRAM PROPERTY OF IBM       *
  11. ;             ALL RIGHTS RESERVED                               *
  12. ;                                                               *
  13. ; FUNCTION = Invoke a hypothetical server via the Macro         *
  14. ;            Assembler interface macros.                        *
  15. ;                                                               *
  16. ;            This sample program reads a customer record        *
  17. ;            from a host computer, examines the customer's      *
  18. ;            balance, and writes the customer record if         *
  19. ;            the balance is greater than zero.                  *
  20. ;                                                               *
  21. ; NOTES =                                                       *
  22. ;                                                               *
  23. ;   RESTRICTIONS = This sample program is provided solely       *
  24. ;                  as an example of how the Macro Assembler     *
  25. ;                  macros can be used to invoke a server.       *
  26. ;                                                               *
  27. ; MODULE TYPE = IBM MACRO Assembler/2 Version 1.00              *
  28. ;*************************END PROLOGUE***************************
  29. ;*************************DEFINITIONS****************************
  30. extrn DosExit:far
  31.         INCLUDE uuminfac.mac
  32.         SUBTTL  'CPRB Mapping'
  33.         PAGE
  34.         INCLUDE uumcprb.inc
  35. ;----------------------------------------------------------------
  36.         SUBTTL  'Customer Record Mapping'
  37.         PAGE
  38. mcustrec        STRUC
  39. mcusname        db      25 dup (?)      ;name
  40. mcusaddr        db      25 dup (?)      ;street address
  41. mcuscity        db      15 dup (?)      ;city
  42. mcusstat        db      15 dup (?)      ;state
  43. mcuszip         db       9 dup (?)      ;zip
  44. mcusacct        db      16 dup (?)      ;account number
  45. mcusbal         dd      ?               ;balance
  46. mcustrec        ENDS
  47. ;----------------------------------------------------------------
  48.         SUBTTL  'Request Parameters Mapping'
  49.         PAGE
  50. mqparms         STRUC
  51. mqpaflags       db      ?               ;Processing flags
  52. mqpaoper        db      8 dup (?)       ;Requesting operator
  53.  
  54. mqparms         ENDS
  55. ;
  56. ;Equates for processing flags defined in STRUC mqparms
  57. mqpalog         equ     01H             ;Log the transaction
  58. mqpacom         equ     02H             ;Commit the transaction
  59. ;
  60. ;----------------------------------------------------------------
  61.         SUBTTL  'MWORK - Work Area Segment'
  62.         PAGE
  63. mwork           SEGMENT 'data'
  64. mdabuf          db      SIZE mcustrec dup (?)  ;Allocate
  65. ;                                       buffer for customer
  66. ;                                       records
  67. mdabuf@         dd      mdabuf          ;Vector to customer
  68. ;                                        record buffer
  69. mdabufl         equ     SIZE mcustrec   ;Length of a customer
  70. ;                                        record
  71.  
  72. mqprmbuf        db      SIZE mqparms dup (?) ;Allocate a buffer
  73. ;                                       for request parms
  74. mqprmbuf@       dd      mqprmbuf        ;Vector to request
  75. ;                                        parameters buffer
  76. mqprmbufl       equ     SIZE mqparms    ;Length of a request
  77. ;                                        parameters
  78.  
  79. mserver_1$      equ     $               ;First character of
  80. ;                                        server name
  81. mserver         db      'IBMabase'      ;Server name
  82. mserver_len$    equ     $-mserver_1$    ;Length of server name
  83.  
  84. mfunc1          equ     1               ;Func code: Get Record
  85. mfunc2          equ     2               ;Func code: Update AR file
  86.  
  87. mrcok           equ     0000H           ;Server Return Code: OK
  88. mlstrh          equ     00H             ;Last Record high byte
  89. mlstrl          equ     04H             ;Last Record low byte
  90.  
  91. moper_1$        equ     $               ;First byte - operator
  92. ;                                        name
  93. moper           db      'ADMIN   '      ;Default operator name
  94. moper_len$      equ     $-moper_1$      ;Length - operator name
  95.  
  96. mretcode        dd      ?               ;SRPI Return Code
  97.                 org     mretcode-mwork
  98. mrclow          dw      0               ;Low word of return code
  99. mrchigh         dw      0               ;High word of return code
  100.  
  101. mservrc         dd      ?               ;Server Return Code
  102.                 org     mservrc-mwork
  103. msrvrclow       dw      0               ;Low word of return code
  104. msrvrchigh      dw      0               ;High word of return code
  105.  
  106. mwork           ENDS
  107. ;----------------------------------------------------------------
  108. mcprbseg        SEGMENT 'data'
  109. mcprb           db      SIZE uercprb dup (0FFH) ;Allocate space
  110. ;                                       for CPRB
  111. mcprbseg        ENDS
  112. dgroup          group   mwork, mcprbseg
  113. ;----------------------------------------------------------------
  114. mstack          SEGMENT stack 'stack'
  115.                 dw      255 dup (0FFFFH) ;Allocate a stack
  116. mstaktop        dw      0FFFFH           ;First stack entry
  117. mstack          ENDS
  118. ;**************************END DEFINITIONS***********************
  119.         SUBTTL  'Main procedure'
  120.         PAGE
  121. ;***************************PSEUDOCODE***************************
  122. ;                           PROC (MAIN)
  123. ;                       1. ESTABLISH A STACK
  124. ;                       1. SET DS TO POINT TO WORK AREA
  125. ;                       1. GET ADDRESS OF REQUEST PARAMETERS
  126. ;                       1. SET PROCESSING OPTION = COMMIT
  127. ;                            TRANSACTION
  128. ;                       1. SET REQUESTING OPERATOR ID
  129. ;                       1. GET ADDRESS OF CPRB INTO ES:DI
  130. ;                       1. DO WHILE SERVER RETURN CODE IS NOT LAST
  131. ;                            RECORD AND SRPI RETURN CODE IS GOOD
  132. ;                       2. INITIALIZE THE CPRB <SEND_REQ_INIT>
  133. ;                       2. . MOVE SERVER NAME AND FUNCTION (GET
  134. ;                             RECORD) INTO CPRB <SET_REQ_PARMS>
  135. ;                       2. . SET CPRB REQUEST PARAMETERS BUFFER
  136. ;                             INFORMATION <SET_REQ_BUFFERS>
  137. ;                       2. . SET CPRB REPLY DATA BUFFER INFORMATION
  138. ;                             <SET_REPLY_PARMS>
  139. ;                       2. . SEND THE REQUEST TO THE SERVER
  140. ;                             <SEND_REQUEST>
  141. ;                       2. . GET THE SRPI RETURN CODE AND SERVER RETURN
  142. ;                             CODE <GET_REPLY>
  143. ;                       2. . IF THE SRPI RETURN CODE IS GOOD
  144. ;                       3. . . IF THE SERVER RETURN CODE IS GOOD
  145. ;                       4. . . . IF THE ACCOUNT BALANCE IS POSITIVE
  146. ;                       5. . . . . SET CPRB FUNCTION = UPDATE
  147. ;                                       ACCOUNTS RECEIVABLE
  148. ;                                       <SET_REQ_PARMS>
  149. ;                       5. . . . . SET CPRB REQUEST DATA = CUSTOMER
  150. ;                                       RECORD <SET_REQ_BUFFERS>
  151. ;                       5. . . . . UPDATE THE ACCOUNTS RECEIVABLE
  152. ;                                       FILE <SEND_REQUEST>
  153. ;                       4. . . . ENDIF
  154. ;                       3. . . ENDIF
  155. ;                       2. . ENDIF
  156. ;                       1. ENDWHILE
  157. ;                       1. RETURN TO DOS
  158. ;                        ENDPROC (MAIN)
  159. ;************************END PSEUDOCODE**************************
  160. msampl          segment 'code'
  161.  
  162.         assume  cs:msampl
  163. ;**************************PROCEDURE*****************************
  164. ;****************************************************************
  165. ;                       PROC (MAIN)
  166. mentry:
  167. ;                       1. ESTABLISH A STACK
  168.         assume  ss:mstack
  169.         mov     ax,seg mstack
  170.         mov     ss,ax
  171.         mov     sp,offset mstaktop
  172.  
  173. ;                       1. SET DS TO POINT TO WORK AREA
  174.         assume  ds:mwork
  175.         mov     ax,seg mwork
  176.         mov     ds,ax
  177. ;                       1. GET ADDRESS OF REQUEST PARAMETERS
  178.         assume  es:mwork
  179.         les     di,mqprmbuf@            ;ES:DI  ->  request
  180. ;                                        parameters buffer
  181.  
  182. ;                       1. SET PROCESSING OPTION = COMMIT
  183. ;                            TRANSACTION
  184.         mov     BYTE PTR es:[di+mqpaflags],mqpacom
  185.  
  186. ;                       1. SET REQUESTING OPERATOR ID
  187.         mov     cx,moper_len$           ;length of operator name
  188.         add     di,OFFSET mqpaoper      ;ES:DI  ->  operator name
  189. ;                                        field in req parms buf
  190.         mov     si,OFFSET moper_1$      ;DS:SI  -> operator name
  191. rep     movsb                           ;Move operator name to
  192. ;                                        request parms buffer
  193.  
  194. ;                       1. GET ADDRESS OF CPRB INTO ES:DI
  195.         assume  es:mcprbseg
  196.         mov     ax,SEG mcprbseg
  197.         mov     es,ax
  198.         mov     di,OFFSET mcprb         ;ES:DI  ->  CPRB
  199.  
  200. ;                       1. DO WHILE SERVER RETURN CODE IS NOT LAST
  201. ;                            RECORD AND SRPI RETURN CODE IS GOOD
  202. loop1:
  203.         cmp     msrvrchigh,mlstrh
  204.         jne     nowhile
  205.         cmp     msrvrclow,mlstrl
  206.         je      nowhile
  207.         cmp     mrclow,uererrokeq
  208.         jne     nowhile
  209.         jmp     while
  210. nowhile:
  211.         jmp     exit
  212. while:
  213. ;                       2. . INITIALIZE THE CPRB <SEND_REQ_INIT>
  214.         SEND_REQ_INIT
  215.  
  216. ;                       2. . MOVE SERVER NAME AND FUNCTION (GET
  217. ;    +                          RECORD) INTO CPRB <SET_REQ_PARMS>
  218.         SET_REQ_PARMS   mserver,mfunc1
  219.  
  220. ;                       2. . SET CPRB REQUEST PARAMETERS BUFFER
  221. ;                              INFORMATION <SET_REQ_BUFFERS>
  222.         SET_REQ_BUFFERS mqprmbuf@,mqprmbufl
  223.  
  224. ;                       2. . SET CPRB REPLY DATA BUFFER INFORMATION
  225. ;                              <SET_REPLY_PARMS>
  226.         SET_REPLY_BUFFERS ,,mdabuf@,mdabufl
  227.  
  228. ;                       2. . SEND THE REQUEST TO THE SERVER
  229. ;                              <SEND_REQUEST>
  230.         SEND_REQUEST
  231.  
  232. ;                       2. . GET THE SRPI RETURN CODE AND SERVER RETURN
  233. ;                              CODE <GET_REPLY>
  234.         GET_REPLY  mretcode,mservrc
  235.  
  236. ;                       2. . IF THE SRPI RETURN CODE IS GOOD
  237.         cmp     mrchigh,uererrokeq
  238.         je      goodrc1                 ;exit label is >127
  239.         jmp     endit                   ; bytes away
  240. goodrc1:
  241.  
  242. ;                       3. . . IF THE SERVER RETURN CODE IS GOOD
  243.         cmp     msrvrchigh,mrcok        ;Compare high word of
  244. ;                                        server return code
  245.         je      goodrc2                 ;exit label is >127
  246.         jmp     endit                   ;bytes away
  247. goodrc2:
  248.         cmp     msrvrclow,mrcok         ;Compare low word of
  249. ;                                        server return code
  250.         jne     endit
  251. ;                       4. . . . IF THE ACCOUNT BALANCE IS POSITIVE
  252.         mov     si,WORD PTR mdabuf@     ;get offset of data buf,
  253. ;                                        DS:SI -> data buffer
  254.         mov     ax,WORD PTR [si+mcusbal];Get low word of
  255. ;                                        balance
  256.         mov     dx,WORD PTR [si+mcusbal+2];Get high word
  257. ;                                       of balance
  258.         sub     dx,0                    ;Subtract zero from the
  259. ;                                        high word
  260.         jl      endit                   ;Negative balance,quit
  261.         jg      update                  ;Positive balance, update
  262. ;                                        the AR file
  263.         cmp     ax,0                    ;Is low word zero?
  264.         je      endit                   ;Yes-zero balance, quit
  265.  
  266. ;                       5. . . . . SET CPRB FUNCTION = UPDATE
  267. ;                                       ACCOUNTS RECEIVABLE
  268. ;                                       <SET_REQ_PARMS>
  269. update:
  270.         SET_REQ_PARMS ,mfunc2
  271.  
  272. ;                       5. . . . . SET CPRB REQUEST DATA = CUSTOMER
  273. ;                                       RECORD <SET_REQ_BUFFERS>
  274.         SET_REQ_BUFFERS ,,mdabuf@,mdabufl
  275.  
  276. ;                       5. . . . . UPDATE THE ACCOUNTS RECEIVABLE
  277. ;                                       FILE <SEND_REQUEST>
  278.         SEND_REQUEST
  279. ;                       4. . . . ENDIF
  280. ;                       3. . . ENDIF
  281. ;                       2. . ENDIF
  282. endit:  jmp loop1
  283. ;                       1. ENDWHILE
  284. exit:
  285. ;                       1. RETURN TO DOS
  286.         sub     ax,ax                   ;Return to DOS
  287.         push    ax
  288.         push    ax
  289.         Call    DosExit
  290. ;                       ENDPROC (MAIN)
  291. ;***********************END PROCEDURE****************************
  292. msampl          ENDS
  293.         END     mentry
  294.