home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DIVERSEN / DOS32V3B / LIB / MACROS.386 < prev    next >
Text File  |  1995-02-10  |  6KB  |  243 lines

  1. ;╔═════════════════════════════════════════════════════════════════╗
  2. ;║         USFUL MACROS FOR YOUR PROTECTED MODE PROGRAMS           ║
  3. ;║Written by Adam Seychell                                         ║
  4. ;║                                                                 ║
  5. ;╚═════════════════════════════════════════════════════════════════╝
  6.  
  7. TRUE    EQU     1
  8. FALSE   EQU     0
  9. CRLF    EQU     10,13
  10.  
  11. Halt MACRO
  12.         mov     ax,4c00h
  13.         int     21h
  14. ENDM
  15.  
  16. ;-----------------------------------------------------------------------
  17. ;                    OPEN A FILE
  18. ;
  19. ; OpenFile     <Handle>,<'path\filename'>
  20. ;
  21. ; Example:      OpenFile      myfile,'c:\gif\bird.gif'
  22. ;
  23. ;-----------------------------------------------------------------------
  24. OpenFile macro X, FileName, nameOFS
  25. local skip_opfi
  26.         IFB <nameOFS>
  27.               mov edx,offset file_to_open&X    ; DS:EDX   points to file name
  28.         ELSE
  29.                 mov edx,nameOFS
  30.         ENDIF
  31.         mov ax,3D02h        ; open a file function
  32.         Int 21h
  33.         mov FileHandle&X , AX
  34.         jmp  skip_opfi
  35. file_to_open&X  db FileName,0
  36. FileHandle&X    dw 0
  37. skip_opfi:
  38. endm
  39.  
  40.  
  41.  
  42. ;-----------------------------------------------------------------------
  43. ;                    CREATE A FILE
  44. ;
  45. ; Usage:       CreateFile     <Handle>,<'path\filename'>
  46. ;
  47. ; Example:      CreateFile      myfile,'drum.voc'
  48. ;
  49. ;-----------------------------------------------------------------------
  50. CreateFile macro X, FileName , nameSEG , nameOFS
  51. local skip_crfi
  52.     jmp skip_crfi
  53. file_to_open&X  db FileName,0
  54. FileHandle&X    dw 0
  55. skip_crfi:
  56.         IFB <nameOFS>
  57.               mov edx,offset file_to_open&X    ; DS:EDX   points to file name
  58.         ELSE
  59.                 mov edx,nameOFS
  60.         ENDIF
  61.         mov     ax,3C02h            ; creat a file function
  62.         xor     ecx,ecx
  63.         Int 21h
  64.         mov FileHandle&X , AX
  65. endm
  66.  
  67.  
  68.  
  69.  
  70. ;-----------------------------------------------------------------------
  71. ;                     CLOSE A FILE
  72. ; Usage:         Close    <Handel>
  73. ;
  74. ; Example:       Close     myfile
  75. ;
  76. ;-----------------------------------------------------------------------
  77. Close  macro  X
  78.         mov ah,03Eh         ; close a file function
  79.         mov BX,FileHandle&X
  80.         int 21h
  81. endm
  82.  
  83.  
  84. ;-----------------------------------------------------------------------
  85. ;                   READ BLOCK FROM A FILE
  86. ;
  87. ; Usage:       BlockRead    <handel>,<32bit offset>,<bytes to read>
  88. ;
  89. ; Example:      BlockRead   myfile, EDX ,700000
  90. ;
  91. ;-----------------------------------------------------------------------
  92. BlockRead  macro   X , POINTER, BYTE_COUNT
  93.         push    dword ptr BYTE_COUNT
  94.         push    dword ptr POINTER
  95.         pop     edx
  96.         pop     ecx
  97.         mov     BX,FileHandle&X
  98.         mov     ah,3Fh
  99.         int     21h
  100.  
  101. endm
  102.  
  103.  
  104. ;-----------------------------------------------------------------------
  105. ;                   WRITE A BLOCK TO A FILE
  106. ;
  107. ; Usage:     BlockWrite  <handel>,<32bit offset>,<bytes to read>
  108. ;
  109. ; Example:     BlockWrite   myfile, EDX ,700000
  110. ;
  111. ;-----------------------------------------------------------------------
  112. BlockWrite  macro  X , POINTER, BYTE_COUNT
  113.         push    dword ptr BYTE_COUNT
  114.         push    dword ptr POINTER
  115.         pop     edx
  116.         pop     ecx
  117.         mov     BX,FileHandle&X
  118.         mov     ah,40h
  119.         int     21h
  120. endm
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. ;-------------------------------------------------------------------------
  128. ;              DISPLAY A STRING ON SCREEN
  129. ;
  130. ; Usage:        Write   <' string to display '>
  131. ;
  132. ;
  133. ;-------------------------------------------------------------------------
  134. Write MACRO STRING_, COLOR5_T
  135. LOCAL TEXT5_T , skip_wrln
  136.         push  eax
  137.         push  edx
  138.         jmp skip_wrln
  139.  
  140.         IFB <STRING_>
  141. TEXT5_T DB 36
  142.         ELSE
  143. TEXT5_T DB STRING_,36
  144.         ENDIF
  145. skip_wrln:
  146.  
  147.         MOV     EDX,OFFSET TEXT5_T
  148.         mov     ah,9
  149.         int     21h
  150.         pop edx
  151.         pop eax
  152. ENDM
  153.  
  154.  
  155.  
  156. ;-------------------------------------------------------------------------
  157. ;              DISPLAY A STRING ON SCREEN WITH CARAGE RETURN
  158. ;
  159. ; Usage:       Writeln   <' string to display '>
  160. ;
  161. ;
  162. ;-------------------------------------------------------------------------
  163. Writeln MACRO STRING_
  164. LOCAL TEXT3_S
  165. local skip_wrln
  166.         push eax
  167.         push edx
  168.  
  169.         jmp skip_wrln
  170.  
  171.         IFB <STRING_>
  172. TEXT3_S DB 13,10,36
  173.         ELSE
  174. TEXT3_S DB STRING_,13,10,36
  175.         ENDIF
  176. skip_wrln:
  177.         mov     EDX,offset TEXT3_S
  178.         mov     ah,9
  179.         Int  21h
  180.         pop edx
  181.         pop eax
  182. ENDM
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190. CRTC        equ    3D4h
  191. SEQ        EQU    3C4h
  192. GC        EQU    3CEh
  193. ATTR        EQU    3C0h
  194.  
  195.     
  196. ;═══════════════════════════════════════════════════════════════════════════
  197. ;        MACROS FOR     VGA    REGISTERS
  198. ;═══════════════════════════════════════════════════════════════════════════
  199.  
  200.  
  201. inp    MACRO    port
  202.     mov    dx,port        ;; Read a byte from port 'port' into al
  203.     in    al,dx
  204. ENDM
  205.  
  206. outp    MACRO    port, value
  207.     mov    dx,port        ;; Write a byte to port 'port'
  208.     mov    al,value
  209.     out    dx,al
  210. ENDM
  211.  
  212. outpW    MACRO    port, value
  213.     mov    dx,port        ;; Write a byte to port 'port'
  214.     mov    ax,value
  215.     out    dx,ax
  216. ENDM
  217.  
  218. rdindex    MACRO    port, index
  219.     mov    dx,port        ;; Read register 'port' index 'index'
  220.     mov    al,index
  221.     out    dx,al
  222.     inc    dx
  223.     in    al,dx        ;; Result in AL
  224. ENDM
  225.  
  226. wrindex    MACRO    port, index, val
  227.     mov    al,index    ;; Write 'port' index 'index' with 'val'
  228.     mov    ah,val
  229.     mov    dx,port
  230.     out    dx,ax
  231. ENDM
  232.  
  233. modindex    MACRO    port, index, mask, nvw
  234.     mov    dx,port
  235.     mov    al,index
  236.     out    dx,al
  237.     inc    dx
  238.     in    al,dx            ;; Read the old value
  239.     and    al,not mask        ;; Mask out bits to be changed
  240.     or    al,nvw            ;; Or in the changed bits
  241.     out    dx,al            ;; Write the value back again
  242. ENDM
  243.