home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / grafik / mandel / prologue.mac < prev    next >
Text File  |  1992-03-07  |  6KB  |  288 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. P286
  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.  
  30. macro   ShiftR  REG,TIMES
  31. ;; 2 - shift a register right a number of times.
  32. IF      IS286
  33.         shr     REG,TIMES
  34. ELSE
  35.         REPT    TIMES
  36.     shr    REG,1
  37.         ENDM
  38. ENDIF
  39.         endm
  40.  
  41. macro   ShiftL  REG,TIMES
  42. ;; 3 - shift a register left a number of times
  43. IF      IS286
  44.         shl     REG,TIMES
  45. ELSE
  46.         REPT    TIMES
  47.     shl    REG,1
  48.         ENDM
  49. ENDIF
  50.         endm
  51.  
  52. macro    LSMUL
  53. ;; 4 - performs a long signed multiply AX,DX * BX,CX
  54.     LOCAL    @@HOP1,@@HOP2
  55. ;; Long signed multiply
  56. ;; Long #1: AX,DX
  57. ;; Long #2: BX,CX
  58.     push    si
  59.     xchg    si,ax
  60.     xchg    dx,ax
  61.     or    ax,ax
  62.     jz    @@HOP1
  63.     mul    bx
  64. @@HOP1: xchg    cx,ax
  65.     or    ax,ax
  66.     jz    @@HOP2
  67.     mul    si
  68.     add    cx,ax
  69. @@HOP2: xchg    si,ax
  70.     mul    bx
  71.     add    dx,cx
  72.     pop    si
  73.     endm
  74.  
  75. macro    LongShiftL TIMES
  76. ;; 5 - Shift left AX,DX times.
  77.     REPT TIMES
  78.     shl    ax,1
  79.     rcl    dx,1
  80.     ENDM
  81.     endm
  82.  
  83. macro    LongShiftR TIMES
  84. ;; 6 - Shifr right AX,DX times
  85.     REPT TIMES
  86.     sar    dx,1
  87.     rcr    ax,1
  88.     ENDM
  89.     endm
  90.  
  91. macro    ShiftAL REG,TIMES
  92. ;; 7 - shift arithmetic left register, times
  93. IF      IS286
  94.     sal    REG,TIMES
  95. ELSE
  96.         REPT    TIMES
  97.     sal    REG,1
  98.         ENDM
  99. ENDIF
  100.     endm
  101.  
  102. macro    ShiftAR REG,TIMES
  103. ;; 8 - Shifr arithmatic right register, times
  104. IF      IS286
  105.     sar    REG,TIMES
  106. ELSE
  107.         REPT    TIMES
  108.     sar    REG,1
  109.         ENDM
  110. ENDIF
  111.     endm
  112.  
  113. macro   PushI   VALUE
  114. ;; 9 - Push an immediat onto the stack.
  115. ;; Push Immediate
  116. IF      IS286
  117.         push    VALUE
  118. ELSE
  119.         mov     ax,VALUE
  120.         push    ax
  121. ENDIF
  122.         endm
  123.  
  124. macro   PushEA  DATA
  125. ;; 10 - Push an effective address onto the stack.
  126. ;; Push Effective address
  127. IF      IS286
  128.         push    offset DATA
  129. ELSE
  130.         mov     ax,offset DATA
  131.         push    ax
  132. ENDIF
  133.         endm
  134.         
  135. macro   PushFar DATA
  136. ;; 11 - Push far address (relative to DS) onto the stack.
  137.         push    ds              ; push the segment
  138.         PushEA  DATA            ; push the offset
  139.         endm
  140.  
  141. macro   PushAll
  142. ;; 12 - Push ALL registers onto the stack.
  143. ;; Save all registers
  144. IF      IS286
  145.         pusha                   ;; if a 286 machine use the pusha opcode
  146.         push    ds              ;; save segment DS
  147.         push    es              ;; save segment ES
  148. ELSE
  149.         push    ax              ;; if not 286 machine use normal method
  150.         push    bx
  151.         push    cx
  152.         push    dx
  153.         push    si
  154.         push    di
  155.         push    bp
  156.         push    ds
  157.         push    es
  158. ENDIF
  159.         endm
  160.  
  161. macro   PopAll
  162. ;; 13 - Pop all registers off of the stack.
  163. ;;; Restore all registers from a push all
  164. IF      IS286
  165.         pop     es
  166.         pop     ds
  167.         popa
  168. ELSE
  169.         pop     es
  170.         pop     ds
  171.         pop     bp
  172.         pop     di
  173.         pop     si
  174.         pop     dx
  175.         pop     cx
  176.         pop     bx
  177.         pop     ax
  178. ENDIF
  179.         endm
  180.  
  181. macro   DOSTerminate
  182. ;; 14 - Terminate back to DOS
  183.     mov    ah,4Ch
  184.         int     21h
  185.         endm
  186.  
  187. macro   DosTSR  LOC
  188. ;; 15 - Terminate and stay resident back to DOS
  189.         lea     dx,[LOC+100h]   ; (End of program plus PSP)
  190.         int     27h             ; Terminate and stay resident.
  191.         endm
  192.  
  193. macro   Message data
  194. ;; 16 - Print a '$' terminated string to the console
  195.     push    ax
  196.         mov     ah,9            ; Function 9 write string
  197.         lea     dx,[data]       ; Get the address of the message
  198.         int     21h             ; Send the message to the screen.
  199.     pop    ax
  200.         endm
  201.  
  202. Macro    Get1Key
  203.     LOCAL    @@HOP1
  204.         mov     ah,08h          ; DOS getkey function.
  205.         int     21h
  206.     xor    ah,ah
  207.     or    al,al
  208.     jnz    @@HOP1
  209.         mov     ah,08h          ; DOS getkey function.
  210.         int     21h
  211.     xor    ah,ah
  212.     add    ax,256
  213. @@HOP1:
  214.         endm
  215.  
  216. Macro    GetKeystat
  217.     mov    ah,0Bh        ; get keyboard status.
  218.     int    21h        ; do DOS interupt.
  219.     or    al,al        ; test status
  220.     endm
  221.  
  222.  
  223.  
  224. macro   PENTER  STORAGE
  225. ;; 17 - Enter a procedue with storage space
  226. ;; Procedure enter, uses the 286/386 ENTER opcode
  227. IF      IS286
  228.         enter   STORAGE,0       ; nexting level, always zero.
  229. ELSE
  230.         push    bp
  231.         mov     bp,sp
  232.         IF      STORAGE
  233.         sub     sp,STORAGE
  234.         ENDIF
  235. ENDIF
  236.         endm
  237.  
  238. macro   PLEAVE
  239. ;; 18 - Exit a procedure with stack correction.
  240. IF      IS286
  241.         leave
  242. ELSE
  243.         mov     sp,bp
  244.         pop     bp
  245. ENDIF
  246.         endm
  247.  
  248. macro   PushCREGS
  249. ;; 19 - Save registers for C
  250.         push    es
  251.     push    ds   ;The Kernel is responsible for maintaining DS
  252.         push    si
  253.         push    di
  254.         cld
  255.         endm
  256.  
  257. macro   PopCREGS
  258. ;; 20 - Restore registers for C
  259.         pop     di
  260.         pop     si
  261.     pop    ds ;The Kernel is responsible for maintaining DS
  262.         pop     es
  263.         endm
  264.  
  265. ;; Macro used to insert breakpoints in code to invoke the debugger.  Using
  266. ;; the macro allows for easier searches to be done on debug invokations.
  267. Macro    DoDebug
  268.     int    3
  269.     endm
  270.  
  271. Macro    SwapSegs
  272.     push    es
  273.     push    ds
  274.     pop    es
  275.     pop    ds
  276.     endm
  277.  
  278.  
  279. Macro    CALLF procedure
  280. ;; This macro fakes a far call to a procedure which is near and dear to
  281. ;; us but defined as far.  This is done to avoid fixups and so that
  282. ;; kernel objects are COMable.    It is used when a kernel service, which
  283. ;; is defined as a far procedure, needs to be called locally.
  284.     push    cs
  285.     call    near ptr procedure
  286.     endm
  287.  
  288.