home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n002 / 4.ddi / ECLSRCA.ZIP / ECLMACRO.INC next >
Encoding:
Text File  |  1990-12-04  |  15.3 KB  |  542 lines

  1. ;   ECLMACRO.INC    Macro definition file for Essential Communications Library
  2. ;
  3. ;       ============================
  4. ;       MICROSOFT C COMPILER VERSION
  5. ;       ============================
  6. ;
  7. ;       MASM    <file>,,/DSMALL;    ** or **
  8. ;       MASM    <file>,,/DMEDIUM;   ** or **
  9. ;       MASM    <file>,,/DCOMPACT;  ** or **
  10. ;       MASM    <file>,,/DLARGE;    ** or **
  11. ;       MASM    <file>,,/DHUGE; 
  12. ;
  13. ;   These macros are not dependent on the compiler or its memory model:
  14. ;
  15. ;       getvec      Return the vector 32-bit address
  16. ;       setvec      Set the vector with a new handler
  17. ;       swapvec     Swap the vector's contents
  18. ;
  19. ;   THESE ARE DEPENDENT ON THE C COMPILER AND ITS MEMORY MODEL:
  20. ;
  21. ;       modstart    Start the module (setup compiler's segments)
  22. ;       modend      End the module
  23. ;       entry       Start a procedure (function)
  24. ;       endit       Conclude a procedure (function)
  25. ;       pushreg     Save registers, establish entry stack frame
  26. ;       popreg      Restore registers prior to function exit
  27. ;       loadint1    Load first stack argument (type integer)
  28. ;       loadint2    Load second stack argument (type integer)
  29. ;       loadint3    Load third stack argument (type integer)
  30. ;       loadptr2    Load second stack argument (type pointer)
  31. ;
  32. ;       (C) Copyright 1986, 1987, 1988 Essential Software Incorporate
  33. ;       (C) Copyright 1986, 1987, 1988 Advanced Firmware Engineering
  34. ;       All Rights Reserved
  35. ;
  36.  
  37. ;    Define constants for communication board types
  38. AST        EQU     2
  39. DIGI8        EQU     4
  40. STAR8        EQU     6
  41. PS2        EQU     8
  42. DIGIMC        EQU    10
  43. DIGIPC16    EQU    12
  44. ASTCMP        EQU    14
  45. ;
  46. ;       ===============================================================
  47. ;       getvec          Return the vector contents  *** MACRO ***
  48. ;       ===============================================================
  49. ;
  50. ;
  51. ;       Input           Description
  52. ;       --------------  ---------------------------
  53. ;       AL              Vector number
  54. ;
  55. ;       Output          Description
  56. ;       --------------  ---------------------------
  57. ;       BX              Offset of the returned vector
  58. ;       DX              Segment of the returned vector
  59. ;
  60. ;       Registers used  Description
  61. ;       --------------  ---------------------------
  62. ;       AX              Vector number and scratch
  63. ;       BX              Offset of the returned vector
  64. ;       DX              Segment of the returned vector
  65. ;       ===============================================================
  66. ;
  67.  
  68. getvec          MACRO
  69.                 PUSH    ES
  70.                 MOV     AH, 35h
  71.                 INT     21h
  72.                 MOV     DX, ES
  73.                 POP     ES
  74.                 ENDM
  75.  
  76.  
  77. ;
  78. ;       ===============================================================
  79. ;       setvec          Set the vector contents  *** MACRO ***
  80. ;       ===============================================================
  81. ;
  82. ;
  83. ;       Input           Description
  84. ;       --------------  ---------------------------
  85. ;       AL              Vector number
  86. ;       BX              Offset of the new vector
  87. ;       DX              Segment of the new vector
  88. ;
  89. ;       Output          Description
  90. ;       --------------  ---------------------------
  91. ;       Not applicable
  92. ;
  93. ;       Registers used  Description
  94. ;       --------------  ---------------------------
  95. ;       AX              Vector number and scratch
  96. ;       BX              Offset of the returned vector
  97. ;       DX              Segment of the returned vector
  98. ;       ===============================================================
  99. ;
  100.  
  101. setvec          MACRO
  102.                 PUSH    DS
  103.                 MOV     DS, DX
  104.                 MOV     DX, BX
  105.                 MOV     AH, 25h
  106.                 INT     21h  
  107.                 POP     DS
  108.                 ENDM
  109.  
  110. ;
  111. ;       ===============================================================
  112. ;       swapvec         Exchange the vector contents  *** MACRO ***
  113. ;       ===============================================================
  114. ;
  115. ;
  116. ;       Input           Description
  117. ;       --------------  ---------------------------
  118. ;       AL              Vector number
  119. ;       BX              Offset of the new vector
  120. ;       DX              Segment of the new vector
  121. ;
  122. ;       Output          Description
  123. ;       --------------  ---------------------------
  124. ;       BX              Offset of the returned vector
  125. ;       DX              Segment of the returned vector
  126. ;
  127. ;       Registers used  Description
  128. ;       --------------  ---------------------------
  129. ;       AX              Vector number and scratch
  130. ;       BX              Offset of the returned vector
  131. ;       DX              Segment of the returned vector
  132. ;       ===============================================================
  133. ;
  134.  
  135. swapvec         MACRO 
  136.                 PUSH    BP
  137.                 MOV     BP, SP
  138.                 PUSH    BX
  139.                 PUSH    DX
  140.                 PUSH    AX
  141.                 CLI
  142.                 getvec
  143.                 POP     AX
  144.                 XCHG    BX, [BP-2]
  145.                 XCHG    DX, [BP-4]
  146.                 setvec
  147.                 STI
  148.                 POP     DX
  149.                 POP     BX
  150.                 POP     BP
  151.                 ENDM
  152.  
  153.  
  154. ;
  155. ;       ===============================================================
  156. ;       modstart        Start the module segment  *** MACRO ***
  157. ;       ===============================================================
  158. ;
  159. ;       ldata   lprog   model
  160. ;       -----   -----   -----
  161. ;        ndef    ndef   SMALL  
  162. ;        ndef     1     MEDIUM 
  163. ;         1      ndef   COMPACT
  164. ;         1       1     LARGE  
  165. ;         1       1     HUGE   
  166. ;
  167. ;       Input           Description
  168. ;       --------------  ---------------------------
  169. ;       /Dmodel         Make sure that when assembled, model symbol is defined
  170. ;       ldata           Data space (=0 within one segment)
  171. ;       lprog           Large program space (=0 within one segment)
  172. ;
  173. ;       Output          Description
  174. ;       --------------  ---------------------------
  175. ;       <module>_code   Symbolic replacement string with code segment name
  176. ;
  177. ;       ===============================================================
  178. ;
  179.  
  180. modstart    MACRO   module
  181.  
  182. ifdef LARGE
  183. ;
  184. ; standard large model segmenting
  185. ;
  186.  
  187. module&_code segment byte public 'CODE'
  188.     assume cs:module&_code
  189.     ldata = 1
  190.     lprog = 1
  191.     cdseg equ module&_code
  192.     IFDEF   BUNDLD
  193.     ASSUME  DS:module&_code
  194.     ENDIF
  195. endif
  196.  
  197.  
  198. ifdef HUGE
  199. ;
  200. ; standard large model segmenting
  201. ;
  202.  
  203. module&_code segment byte public 'CODE'
  204.     assume cs:module&_code
  205.     ldata = 1
  206.     lprog = 1
  207.     cdseg equ module&_code
  208.     IFDEF   BUNDLD
  209.     ASSUME  DS:module&_code
  210.     ENDIF
  211. endif
  212.  
  213.  
  214. ifdef SMALL
  215. ;
  216. ;  standard small segmenting
  217. ;
  218. _text segment byte public 'CODE'
  219.     assume cs:_text
  220.     cdseg = _text
  221.     IFDEF   BUNDLD
  222.     ASSUME  DS:_text
  223.     ENDIF
  224. endif
  225.  
  226. ifdef MEDIUM
  227. ;
  228. ; standard medium model segmenting
  229. ;
  230.  
  231. module&_code segment byte public 'CODE'
  232.     assume cs:module&_code
  233.     lprog = 1
  234.     cdseg equ module&_code
  235.     IFDEF   BUNDLD
  236.     ASSUME  DS:module&_code
  237.     ENDIF
  238. endif
  239.  
  240. ifdef COMPACT
  241. ;
  242. ;  standard compact segmenting
  243. ;
  244. _text segment byte public 'CODE'
  245.     assume cs:_text
  246.     ldata = 1
  247.     cdseg = _text
  248.     IFDEF   BUNDLD
  249.     ASSUME  DS:_text
  250.     ENDIF
  251. endif
  252.     ENDM
  253.  
  254. ;
  255. ;       ===============================================================
  256. ;       modend          End the module segment  *** MACRO ***
  257. ;       ===============================================================
  258. ;
  259. ;       Using the table below, close the segmentation
  260. ;
  261. ;       ldata   lprog   model
  262. ;       -----   -----   -----
  263. ;         0       0     SMALL  
  264. ;         0       1     MEDIUM 
  265. ;         1       0     COMPACT
  266. ;         1       1     LARGE  
  267. ;         1       1     HUGE   
  268. ;
  269. ;       Input           Description
  270. ;       --------------  ---------------------------
  271. ;       <module>_code   Symbolic replacement string with code segment name
  272. ;
  273. ;       Output          Description
  274. ;       --------------  ---------------------------
  275. ;       Not applicable
  276. ;       ===============================================================
  277. ;
  278.  
  279. modend  MACRO module            ; MODule END
  280.  
  281. ifdef LARGE
  282. ;
  283.  
  284. module&_code ends
  285. endif
  286.  
  287. ifdef HUGE
  288. ;
  289.  
  290. module&_code ends
  291. endif
  292.  
  293.  
  294.  
  295. ifdef SMALL
  296. ;
  297. ;  standard small segmenting
  298. ;
  299. _text ends
  300. endif
  301.  
  302. ifdef COMPACT
  303. ;
  304. ;  standard small segmenting
  305. ;
  306. _text ends
  307. endif
  308.  
  309.  
  310.  
  311. ifdef MEDIUM
  312. ;
  313. ; standard medium model segmenting
  314. ;
  315.  
  316. module&_code ends
  317. endif
  318.         ENDM
  319.  
  320.  
  321.  
  322. ;
  323. ;       ===============================================================
  324. ;       entry   Establish the procedure entry *** MACRO ***
  325. ;       endit   Establish the procedure exit  *** MACRO ***
  326. ;       ===============================================================
  327. ;
  328. ;       Input           Description
  329. ;       --------------  ---------------------------
  330. ;       Not applicable
  331. ;
  332. ;       Output          Description
  333. ;       --------------  ---------------------------
  334. ;       Not applicable
  335. ;       ===============================================================
  336. ;
  337.  
  338. entry    MACRO    NAME
  339.     PUBLIC  _&NAME
  340.     IFDEF LPROG
  341. _&NAME    PROC   FAR
  342.     ELSE
  343. _&NAME    PROC   NEAR
  344.     ENDIF
  345.     ENDM
  346.  
  347.  
  348. endit MACRO NAME
  349. _&NAME ENDP
  350.     ENDM
  351.  
  352.  
  353. ;
  354. ;       ===============================================================
  355. ;       pushreg     Establish the stack frame *** MACRO ***
  356. ;       ===============================================================
  357. ;
  358. ;       |----------|            
  359. ;       | ret ip   | [BP+2]
  360. ;       |----------|
  361. ; BP  =>| old bp   | [BP+0]
  362. ;       |----------|            
  363. ;
  364. ;
  365. ;       Input           Description
  366. ;       --------------  ---------------------------
  367. ;       Not applicable
  368. ;
  369. ;       Output          Description
  370. ;       --------------  ---------------------------
  371. ;       BP              pointer to stack frame
  372. ;       BP              saved on the stack
  373. ;       ===============================================================
  374. ;
  375. pushreg MACRO
  376.         PUSH    BP
  377.         MOV     BP, SP
  378.         ENDM
  379.  
  380. ;
  381. ;       ===============================================================
  382. ;       popreg  Restore the stack frame  *** MACRO ***
  383. ;       ===============================================================
  384. ;
  385. ;
  386. ;
  387. ;       Input           Description
  388. ;       --------------  ---------------------------
  389. ;       BP              preset by pushreg macro
  390. ;
  391. ;       Output          Description
  392. ;       --------------  ---------------------------
  393. ;       BP              Restored from the stack
  394. ;       ===============================================================
  395. ;
  396. popreg  MACRO
  397.         POP     BP
  398.         ENDM
  399.  
  400. ;
  401. ;       ===============================================================
  402. ;       loadint1    Load in reg first integer argument  *** MACRO ***
  403. ;       ===============================================================
  404. ;
  405. ;
  406. ;       lprog def (large code space)    other (code space is small)
  407. ;               [ldata definition has no bearing]
  408. ;
  409. ;       |----------|            
  410. ;======>| int arg  | [BP+6]
  411. ;       |----------|                    |----------|
  412. ;       | caller cs| [BP+4]      ======>| int arg  | [BP+4]
  413. ;       |----------|                    |----------|
  414. ;       | caller ip| [BP+2]             | caller ip| [BP+2]
  415. ;       |----------|                    |----------|
  416. ;       | old bp   | [BP]               | old bp   | [BP]
  417. ;       |----------|                    |----------|
  418. ;
  419. ;       MEDIUM                          SMALL
  420. ;       LARGE                           COMPACT
  421. ;       HUGE
  422. ;
  423. ;
  424. ;       Input           Description
  425. ;       --------------  ---------------------------
  426. ;       BP              preset by pushreg macro
  427. ;
  428. ;       Output          Description
  429. ;       --------------  ---------------------------
  430. ;       AX              Loaded with first parameter from stack frame
  431. ;       ===============================================================
  432. ;
  433.  
  434. loadint1    MACRO  reg          ; load in first integer argument 
  435.             IFDEF LPROG
  436.             MOV     reg, [BP+6]
  437.             ELSE
  438.             MOV     reg, [BP+4]
  439.             ENDIF
  440.             ENDM
  441.  
  442. loadint2    MACRO  reg          ; load in second integer argument 
  443.             IFDEF LPROG
  444.             MOV     reg, [BP+8]
  445.             ELSE
  446.             MOV     reg, [BP+6]
  447.             ENDIF
  448.             ENDM
  449.  
  450. loadint3    MACRO  reg          ; load in third integer argument 
  451.             IFDEF LPROG
  452.             MOV     reg, [BP+10]
  453.             ELSE
  454.             MOV     reg, [BP+8]
  455.             ENDIF
  456.             ENDM
  457.  
  458. ;
  459. ;       ===============================================================
  460. ;       loadptr1    Load in DX:BX second pointer argument  *** MACRO ***
  461. ;       ===============================================================
  462. ;
  463. ;
  464. ;       lprog def (large code space)    lprog ndef (small code space)
  465. ;       ldata ndef (small data space)   ldata ndef (small data space)
  466. ;
  467. ;       |----------|       
  468. ;======>| pointer  | [BP+8]
  469. ;       |----------|                    |----------|
  470. ;       | int arg  | [BP+6]      ======>| pointer  | [BP+6]
  471. ;       |----------|                    |----------|
  472. ;       | caller cs| [BP+4]             | int arg  | [BP+4]
  473. ;       |----------|                    |----------|
  474. ;       | caller ip| [BP+2]             | caller ip| [BP+2]
  475. ;       |----------|                    |----------|
  476. ;       | old bp   | [BP]               | old bp   | [BP]
  477. ;       |----------|                    |----------|
  478. ;
  479. ;       MEDIUM                          SMALL
  480. ;
  481. ;       lprog def (large code space)    lprog ndef (small code space)
  482. ;       ldata def (small data space)    ldata def (small data space)
  483. ;
  484. ;       |----------|
  485. ;       |          | [BP+10]
  486. ;======>|--      --|                    |----------|
  487. ;       | pointer  | [BP+8]             |          | [BP+8]
  488. ;       |----------|             ======>|--      --|
  489. ;       | int arg  | [BP+6]             | pointer  | [BP+6]
  490. ;       |----------|                    |----------|
  491. ;       | caller cs| [BP+4]             | int arg  | [BP+4]
  492. ;       |----------|                    |----------|
  493. ;       | caller ip| [BP+2]             | caller ip| [BP+2]
  494. ;       |----------|                    |----------|
  495. ;       | old bp   | [BP]               | old bp   | [BP]
  496. ;       |----------|                    |----------|
  497. ;
  498. ;       LARGE                           COMPACT
  499. ;       HUGE
  500. ;
  501. ;
  502. ;       Input           Description
  503. ;       --------------  ---------------------------
  504. ;       BP              preset by pushreg macro
  505. ;
  506. ;       Output          Description
  507. ;       --------------  ---------------------------
  508. ;       DX:BX           Segment and offset of pointer value from stack frame
  509. ;       ===============================================================
  510. ;
  511.  
  512.  
  513. loadptr2    MACRO
  514.             IFDEF SMALL
  515.             MOV BX, [BP+6]
  516.             MOV DX, DS
  517.             ENDIF
  518.  
  519.             IFDEF MEDIUM
  520.             MOV BX, [BP+8]
  521.             MOV DX, DS
  522.             ENDIF
  523.  
  524.             IFDEF COMPACT
  525.             MOV BX, [BP+6]
  526.             MOV DX, [BP+8]
  527.             ENDIF
  528.  
  529.             IFDEF LARGE
  530.             MOV BX, [BP+8]
  531.             MOV DX, [BP+10]
  532.             ENDIF
  533.  
  534.             IFDEF HUGE 
  535.             MOV BX, [BP+8]
  536.             MOV DX, [BP+10]
  537.             ENDIF
  538.  
  539.             ENDM
  540.  
  541.  
  542.