home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / sound / digpak / prologue.mac < prev    next >
Encoding:
Text File  |  1992-09-28  |  6.0 KB  |  323 lines

  1. ;; A header macro file that defines a lot of common useful macros when
  2. ;; programming in assembly.  Supports conditional assembly for taking
  3. ;; advantage of 80286 opcodes.
  4. IS286    equ    1
  5.  
  6. P386
  7.  
  8. Macro     SETUPSEGMENT
  9.  
  10. SEGMENT _TEXT    PARA PUBLIC 'CODE'
  11.     ASSUME    CS:_TEXT
  12.  
  13.     Endm
  14.  
  15. Struc    SEG_OFF
  16.  
  17. POFF    dw    ?
  18. PSEG    dw    ?
  19.  
  20.     Ends
  21.  
  22. UNION    FARPTR
  23.  
  24. DPTR    dd    ?
  25. XPTR    SEG_OFF <>
  26.  
  27.     ENDS
  28.  
  29. ;; This macro replaces the LOOP instruction, because the loop instruction
  30. ;; is too damned slow on a 386/486
  31. macro    CLOOP LABEL
  32.     dec    cx
  33.     jnz    LABEL
  34.     endm
  35.  
  36. macro    CLODSB
  37.     mov    al,[ds:si]
  38.     inc    si
  39.     endm
  40.  
  41. macro    CSTOSB
  42.     mov    [es:di],al
  43.     inc    di
  44.     endm
  45.  
  46. macro    CLODSW
  47.     mov    ax,[ds:si]
  48.     add    si,2
  49.     endm
  50.  
  51. macro    CSTOSW
  52.     mov    [es:di],ax
  53.     add    di,2
  54.     endm
  55.  
  56.  
  57. macro   ShiftR  REG,TIMES
  58. ;; 2 - shift a register right a number of times.
  59. IF      IS286
  60.         shr     REG,TIMES
  61. ELSE
  62.         REPT    TIMES
  63.     shr    REG,1
  64.         ENDM
  65. ENDIF
  66.         endm
  67.  
  68. macro   ShiftL  REG,TIMES
  69. ;; 3 - shift a register left a number of times
  70. IF      IS286
  71.         shl     REG,TIMES
  72. ELSE
  73.         REPT    TIMES
  74.     shl    REG,1
  75.         ENDM
  76. ENDIF
  77.         endm
  78.  
  79. macro    LSMUL
  80. ;; 4 - performs a long signed multiply AX,DX * BX,CX
  81.     LOCAL    @@HOP1,@@HOP2
  82. ;; Long signed multiply
  83. ;; Long #1: AX,DX
  84. ;; Long #2: BX,CX
  85.     push    si
  86.     xchg    si,ax
  87.     xchg    dx,ax
  88.     or    ax,ax
  89.     jz    @@HOP1
  90.     mul    bx
  91. @@HOP1: xchg    cx,ax
  92.     or    ax,ax
  93.     jz    @@HOP2
  94.     mul    si
  95.     add    cx,ax
  96. @@HOP2: xchg    si,ax
  97.     mul    bx
  98.     add    dx,cx
  99.     pop    si
  100.     endm
  101.  
  102. macro    LongShiftL TIMES
  103. ;; 5 - Shift left AX,DX times.
  104.     REPT TIMES
  105.     shl    ax,1
  106.     rcl    dx,1
  107.     ENDM
  108.     endm
  109.  
  110. macro    LongShiftR TIMES
  111. ;; 6 - Shifr right AX,DX times
  112.     REPT TIMES
  113.     sar    dx,1
  114.     rcr    ax,1
  115.     ENDM
  116.     endm
  117.  
  118. macro    ShiftAL REG,TIMES
  119. ;; 7 - shift arithmetic left register, times
  120. IF      IS286
  121.     sal    REG,TIMES
  122. ELSE
  123.         REPT    TIMES
  124.     sal    REG,1
  125.         ENDM
  126. ENDIF
  127.     endm
  128.  
  129. macro    ShiftAR REG,TIMES
  130. ;; 8 - Shifr arithmatic right register, times
  131. IF      IS286
  132.     sar    REG,TIMES
  133. ELSE
  134.         REPT    TIMES
  135.     sar    REG,1
  136.         ENDM
  137. ENDIF
  138.     endm
  139.  
  140. macro   PushI   VALUE
  141. ;; 9 - Push an immediat onto the stack.
  142. ;; Push Immediate
  143. IF      IS286
  144.         push    VALUE
  145. ELSE
  146.         mov     ax,VALUE
  147.         push    ax
  148. ENDIF
  149.         endm
  150.  
  151. macro   PushEA  DATA
  152. ;; 10 - Push an effective address onto the stack.
  153. ;; Push Effective address
  154. IF      IS286
  155.         push    offset DATA
  156. ELSE
  157.         mov     ax,offset DATA
  158.         push    ax
  159. ENDIF
  160.         endm
  161.         
  162. macro   PushFar DATA
  163. ;; 11 - Push far address (relative to DS) onto the stack.
  164.         push    ds              ; push the segment
  165.         PushEA  DATA            ; push the offset
  166.         endm
  167.  
  168. macro   PushAll
  169. ;; 12 - Push ALL registers onto the stack.
  170. ;; Save all registers
  171. IF      IS286
  172.         pusha                   ;; if a 286 machine use the pusha opcode
  173.         push    ds              ;; save segment DS
  174.         push    es              ;; save segment ES
  175. ELSE
  176.         push    ax              ;; if not 286 machine use normal method
  177.         push    bx
  178.         push    cx
  179.         push    dx
  180.         push    si
  181.         push    di
  182.         push    bp
  183.         push    ds
  184.         push    es
  185. ENDIF
  186.         endm
  187.  
  188. macro   PopAll
  189. ;; 13 - Pop all registers off of the stack.
  190. ;;; Restore all registers from a push all
  191. IF      IS286
  192.         pop     es
  193.         pop     ds
  194.         popa
  195. ELSE
  196.         pop     es
  197.         pop     ds
  198.         pop     bp
  199.         pop     di
  200.         pop     si
  201.         pop     dx
  202.         pop     cx
  203.         pop     bx
  204.         pop     ax
  205. ENDIF
  206.         endm
  207.  
  208. macro   DOSTerminate
  209. ;; 14 - Terminate back to DOS
  210.     mov    ah,4Ch
  211.         int     21h
  212.         endm
  213.  
  214. macro   DosTSR  LOC
  215. ;; 15 - Terminate and stay resident back to DOS
  216.         lea     dx,[LOC+100h]   ; (End of program plus PSP)
  217.         int     27h             ; Terminate and stay resident.
  218.         endm
  219.  
  220. macro   Message data
  221. ;; 16 - Print a '$' terminated string to the console
  222.     push    ax
  223.         mov     ah,9            ; Function 9 write string
  224.         lea     dx,[data]       ; Get the address of the message
  225.         int     21h             ; Send the message to the screen.
  226.     pop    ax
  227.         endm
  228.  
  229. Macro    Get1Key
  230.     LOCAL    @@HOP1
  231.         mov     ah,08h          ; DOS getkey function.
  232.         int     21h
  233.     xor    ah,ah
  234.     or    al,al
  235.     jnz    @@HOP1
  236.         mov     ah,08h          ; DOS getkey function.
  237.         int     21h
  238.     xor    ah,ah
  239.     add    ax,256
  240. @@HOP1:
  241.         endm
  242.  
  243. Macro    GetKeystat
  244.     mov    ah,0Bh        ; get keyboard status.
  245.     int    21h        ; do DOS interupt.
  246.     or    al,al        ; test status
  247.     endm
  248.  
  249.  
  250.  
  251. macro   PENTER  STORAGE
  252. ;; 17 - Enter a procedue with storage space
  253. ;; Procedure enter, uses the 286/386 ENTER opcode
  254. IF      IS286
  255.         enter   STORAGE,0       ; nexting level, always zero.
  256. ELSE
  257.         push    bp
  258.         mov     bp,sp
  259.         IF      STORAGE
  260.         sub     sp,STORAGE
  261.         ENDIF
  262. ENDIF
  263.         endm
  264.  
  265. macro   PLEAVE
  266. ;; 18 - Exit a procedure with stack correction.
  267. IF      IS286
  268.         leave
  269. ELSE
  270.         mov     sp,bp
  271.         pop     bp
  272. ENDIF
  273.         endm
  274.  
  275. macro   PushCREGS
  276. ;; 19 - Save registers for C
  277.         push    es
  278.     push    ds   ;The Kernel is responsible for maintaining DS
  279.         push    si
  280.         push    di
  281.         cld
  282.         endm
  283.  
  284. macro   PopCREGS
  285. ;; 20 - Restore registers for C
  286.         pop     di
  287.         pop     si
  288.     pop    ds ;The Kernel is responsible for maintaining DS
  289.         pop     es
  290.         endm
  291.  
  292. ;; Macro used to insert breakpoints in code to invoke the debugger.  Using
  293. ;; the macro allows for easier searches to be done on debug invokations.
  294. Macro    DoDebug
  295.     int    3
  296.     endm
  297.  
  298. Macro    SwapSegs
  299.     push    es
  300.     push    ds
  301.     pop    es
  302.     pop    ds
  303.     endm
  304.  
  305.  
  306. Macro    CALLF procedure
  307. ;; This macro fakes a far call to a procedure which is near and dear to
  308. ;; us but defined as far.  This is done to avoid fixups and so that
  309. ;; kernel objects are COMable.    It is used when a kernel service, which
  310. ;; is defined as a far procedure, needs to be called locally.
  311.     push    cs
  312.     call    near ptr procedure
  313.     endm
  314.  
  315. Macro    RepMovsb
  316.     push    cx
  317.     shr    cx,2        ; words.
  318.     rep    movsd
  319.     pop    cx
  320.     and    cx,3
  321.     rep    movsb
  322.     endm
  323.