home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / TASMSWAN.ZIP / DOSMACS.ASM < prev    next >
Assembly Source File  |  1989-07-15  |  12KB  |  325 lines

  1. %NOLIST
  2.  
  3. ;  *** Subset of DOS macros for Turbo Assembler (Ideal mode) ***
  4.  
  5. ;----------------------------------------------------------------------
  6. ;  MS_DOS - call any DOS function
  7. ;----------------------------------------------------------------------
  8. ;    Input:  functionNumber = DOS function number
  9. ;    Output:    depends upon specific function
  10. ;    Registers: depends upon specific function
  11. ;----------------------------------------------------------------------
  12. MACRO    MS_DOS    functionNumber
  13.     mov    ah,functionNumber
  14.     int    21h
  15. ENDM    MS_DOS    functionNumber
  16.  
  17. ;----------------------------------------------------------------------
  18. ;  (01h)  DOS_GetChar - get character with echo
  19. ;----------------------------------------------------------------------
  20. ;    Input:  none
  21. ;    Output:    al = next character from standard input
  22. ;    Registers: ax
  23. ;----------------------------------------------------------------------
  24. MACRO    DOS_GetChar
  25.     mov    ah,1
  26.     int    21h
  27. ENDM    DOS_GetChar
  28.  
  29. ;----------------------------------------------------------------------
  30. ;  (02h)  DOS_PutChar - Write character to standard output
  31. ;----------------------------------------------------------------------
  32. ;    Input:  dl = ASCII character (0-255)
  33. ;    Output:    none
  34. ;    Registers: ah
  35. ;----------------------------------------------------------------------
  36. MACRO    DOS_PutChar
  37.     mov    ah,2
  38.     int    21h
  39. ENDM    DOS_PutChar
  40.  
  41. ;----------------------------------------------------------------------
  42. ;  (05h)  DOS_PrintChar - Send character to standard list device
  43. ;----------------------------------------------------------------------
  44. ;    Input:  dl = ASCII character (0-255)
  45. ;    Output:    none
  46. ;    Registers: ah
  47. ;----------------------------------------------------------------------
  48. MACRO    DOS_PrintChar
  49.     mov    ah,5
  50.     int    21h
  51. ENDM    DOS_PrintChar
  52.  
  53. ;----------------------------------------------------------------------
  54. ;  (07h)  DOS_GetRawChar - get unfiltered character with no echo
  55. ;----------------------------------------------------------------------
  56. ;    Input:  none
  57. ;    Output:    al = next character from standard input
  58. ;    Registers: ax
  59. ;----------------------------------------------------------------------
  60. MACRO    DOS_GetRawChar
  61.     mov    ah,7
  62.     int    21h
  63. ENDM    DOS_GetRawChar
  64.  
  65. ;----------------------------------------------------------------------
  66. ;  (08h)  DOS_GetCharNoEcho - get Filtered character with no echo
  67. ;----------------------------------------------------------------------
  68. ;    Input:  none
  69. ;    Output:    al = next character from standard input
  70. ;    Registers: ax
  71. ;----------------------------------------------------------------------
  72. MACRO    DOS_GetCharNoEcho
  73.     mov    ah,8
  74.     int    21h
  75. ENDM    DOS_GetCharNoEcho
  76.  
  77. ;----------------------------------------------------------------------
  78. ;  (09h)  DOS_PutString - write ASCII$ string to standard output
  79. ;----------------------------------------------------------------------
  80. ;    Input:  string = label of ASCII$ variable
  81. ;    Output:    none
  82. ;    Registers: ah,dx
  83. ;----------------------------------------------------------------------
  84. MACRO    DOS_PutString string
  85.     mov    ah,9
  86.     mov    dx, offset string
  87.     int    21h
  88. ENDM    DOS_PutString
  89.  
  90. ;----------------------------------------------------------------------
  91. ;  (0Bh)  DOS_Keypressed - checks if a keyboard character is waiting
  92. ;----------------------------------------------------------------------
  93. ;    Input:  none
  94. ;    Output:     zf = 0 : (jnz) A character is waiting to be read
  95. ;           zf = 1 : (jz) No character waiting
  96. ;    Registers: ax
  97. ;----------------------------------------------------------------------
  98. MACRO    DOS_Keypressed
  99.     mov    ah,0Bh
  100.     int    21h
  101.     or    al,al
  102. ENDM    DOS_Keypressed
  103.  
  104. ;----------------------------------------------------------------------
  105. ;  (0Eh)  DOS_SetDrive - change current drive
  106. ;----------------------------------------------------------------------
  107. ;    Input:  dl = drive number (0 = A:, 1 = B:, 2 = C:,..., 25 = Z:)
  108. ;        NOTE:   F: to Z: requires LASTDRIVE=Z in config.sys file
  109. ;    Output:     al = total number of drives available
  110. ;    Registers: ax
  111. ;----------------------------------------------------------------------
  112. MACRO    DOS_SetDrive
  113.     mov    ah,0Eh
  114.     int    21h
  115. ENDM    DOS_SetDrive
  116.  
  117. ;----------------------------------------------------------------------
  118. ;  (19h)  DOS_GetDrive - get current drive number
  119. ;----------------------------------------------------------------------
  120. ;    Input:  none
  121. ;    Output:     al = drive number (0 = A:, 1 = B:, 2 = C:,..., 25 = Z:)
  122. ;    Registers: ax
  123. ;----------------------------------------------------------------------
  124. MACRO    DOS_GetDrive
  125.     mov    ah,19h
  126.     int    21h
  127. ENDM    DOS_GetDrive
  128.  
  129. ;----------------------------------------------------------------------
  130. ;  (25h)  DOS_SetVector - set interrupt vector
  131. ;----------------------------------------------------------------------
  132. ;    Input:  interrupt = interrupt number (0-255)
  133. ;        address   = label at start of interrupt routine
  134. ;    Output:     none
  135. ;    Registers: ax,dx
  136. ;----------------------------------------------------------------------
  137. MACRO    DOS_SetVector  interrupt,address
  138.     push    ds
  139.     mov    ax, SEG address
  140.     mov    ds,ax
  141.     mov    dx, OFFSET address
  142.     mov    ah,025h
  143.     mov    al,interrupt
  144.     int    21h
  145.     pop    ds
  146. ENDM    DOS_SetVector
  147.  
  148. ;----------------------------------------------------------------------
  149. ;  (35h)  DOS_GetVector - get interrupt vector
  150. ;----------------------------------------------------------------------
  151. ;    Input:  interrupt = interrupt number (0-255)
  152. ;    Output:    es:bx = segment:offset address of interrupt
  153. ;    Registers: ax,bx,es
  154. ;----------------------------------------------------------------------
  155. MACRO    DOS_GetVector  interrupt
  156.     mov    al,interrupt
  157.     mov    ah,35h
  158.     int    21h
  159. ENDM    DOS_GetVector
  160.  
  161. ;----------------------------------------------------------------------
  162. ;  (3Bh)  DOS_ChDir - change current directory
  163. ;----------------------------------------------------------------------
  164. ;    Input:  dirName = label of ASCIIZ string in ds data segment
  165. ;    Output:    cf = 0 : (jnc) change was successful
  166. ;        cf = 1 : (jc) change was not successful
  167. ;             ax = error code (3 = directory not found)
  168. ;    Registers: ax,dx
  169. ;----------------------------------------------------------------------
  170. MACRO    DOS_ChDir    dirName
  171.     mov    ah,3Bh
  172.     mov    dx, OFFSET dirName
  173.     int    21h
  174. ENDM    DOS_ChDir
  175.  
  176. ;----------------------------------------------------------------------
  177. ;  (3Ch)  DOS_CreateFile - creates a new file
  178. ;----------------------------------------------------------------------
  179. ;    Input:  fileName = label of ASCIIZ string in ds data segment
  180. ;        cx = attribute to use in directory
  181. ;            00 = normal file
  182. ;            01 = read-only (access denied for read/write)
  183. ;            02 = hidden (DIR does not show name)
  184. ;            04 = system file
  185. ;    Output:    cf = 0 : (jnc) File created
  186. ;            ax = file handle for future operations
  187. ;        cf = 1 : (jc)  File NOT created
  188. ;            ax = error code
  189. ;                3 = path not found
  190. ;                4 = no more handles available
  191. ;                5 = access denied
  192. ;    Registers: ax,dx
  193. ;----------------------------------------------------------------------
  194. MACRO    DOS_CreateFile    fileName
  195.     mov    ah,3Ch
  196.     mov    dx, OFFSET fileName
  197.     int    21h
  198. ENDM    DOS_CreateFile
  199.  
  200. ;----------------------------------------------------------------------
  201. ;  (3Dh)  DOS_OpenFile - open file for I/O
  202. ;----------------------------------------------------------------------
  203. ;    Input:  fileName = label of ASCIIZ string in ds data segment
  204. ;    Output:    cf = 0 : (jnc) File opened
  205. ;            ax = file handle for future operations
  206. ;        cf = 1 : (jc)  File NOT opened
  207. ;            ax = error code
  208. ;                2 = file not found
  209. ;                3 = path not found
  210. ;                4 = no more handles available
  211. ;                5 = access denied
  212. ;    Registers: ax,dx
  213. ;----------------------------------------------------------------------
  214. MACRO    DOS_OpenFile    fileName
  215.     mov    ah,3Dh
  216.     mov    al,02
  217.     mov    dx, OFFSET fileName
  218.     int    21h
  219. ENDM    DOS_OpenFile
  220.  
  221. ;----------------------------------------------------------------------
  222. ;  (3Eh)  DOS_CloseFile - close a previously opened file
  223. ;----------------------------------------------------------------------
  224. ;    Input:  bx = file handle from DOS_CreateFile or DOS_OpenFile
  225. ;    Output:    cf = 0 : (jnc) File closed
  226. ;        cf = 1 : (jc)  File NOT closed
  227. ;            ax = error code
  228. ;                6 = bad handle or file was not open
  229. ;    Registers: ax
  230. ;----------------------------------------------------------------------
  231. MACRO    DOS_CloseFile    fileName
  232.     mov    ah,3Eh
  233.     int    21h
  234. ENDM    DOS_CloseFile
  235.  
  236. ;----------------------------------------------------------------------
  237. ;  (3Fh)  DOS_ReadFile - read from  file or device
  238. ;----------------------------------------------------------------------
  239. ;    Input:  bx = file handle from DOS_CreateFile or DOS_OpenFile
  240. ;        cx = number of bytes requested to read
  241. ;        buffer = label of destination buffer in ds data segment
  242. ;          NOTE: buffer must be at least cx bytes long !!
  243. ;    Output:    cf = 0 : (jnc) Read was successful
  244. ;            ax = actual number of bytes read (0 = at end of file)
  245. ;        cf = 1 : (jc)  read NOT successful
  246. ;            ax = error code
  247. ;                5 = access denied
  248. ;                6 = bad handle or file was not open
  249. ;    Registers: ax,dx
  250. ;----------------------------------------------------------------------
  251. MACRO    DOS_ReadFile    buffer
  252.     mov    ah,3Fh
  253.     mov    dx, OFFSET buffer
  254.     int    21h
  255. ENDM    DOS_ReadFile
  256.  
  257. ;----------------------------------------------------------------------
  258. ;  (40h)  DOS_WriteFile - write to  file or device
  259. ;----------------------------------------------------------------------
  260. ;    Input:  bx = file handle from DOS_CreateFile or DOS_OpenFile
  261. ;        cx = number of bytes requested to write
  262. ;        buffer = label of source buffer in ds data segment
  263. ;    Output:    cf = 0 : (jnc) Write was successful
  264. ;            ax = actual number of bytes written (0 = disk is FULL)
  265. ;        cf = 1 : (jc)  Write NOT successful
  266. ;            ax = error code
  267. ;                5 = access denied
  268. ;                6 = bad handle or file was not open
  269. ;    Registers: ax,dx
  270. ;----------------------------------------------------------------------
  271. MACRO    DOS_WriteFile    buffer
  272.     mov    ah,40h
  273.     mov    dx, OFFSET buffer
  274.     int    21h
  275. ENDM    DOS_WriteFile
  276.  
  277. ;----------------------------------------------------------------------
  278. ;  (42h)  DOS_Seek - change location for next read/write
  279. ;----------------------------------------------------------------------
  280. ;    Input:  bx = file handle from DOS_CreateFile or DOS_OpenFile
  281. ;        cx = high word of 32-byte offset
  282. ;        dx = low word of 32-byte offset
  283. ;    Output:    cf = 0 : (jnc) Seek was successful
  284. ;            dx = high word of 32-byte offset position after seek
  285. ;            ax = low word of 32-byte offset position after seek
  286. ;        cf = 1 : (jc)  Seek NOT successful
  287. ;            ax = error code
  288. ;                6 = bad handle or file was not open
  289. ;    Registers: ax
  290. ;----------------------------------------------------------------------
  291. MACRO    DOS_Seek
  292.     mov    ah,42h
  293.     xor    al,al
  294.     int    21h
  295. ENDM    DOS_Seek
  296.  
  297. ;----------------------------------------------------------------------
  298. ;  (47h)  DOS_GetDir - get name of current directory
  299. ;----------------------------------------------------------------------
  300. ;    Input:  string = address of 64-byte (minimum) variable
  301. ;    Output:    directory name inserted into string in ASCIIZ format
  302. ;    Registers: ax,dl,si
  303. ;----------------------------------------------------------------------
  304. MACRO    DOS_GetDir    string
  305.     mov    ah,47h
  306.     xor    dl,dl
  307.     mov    si, OFFSET string
  308.     int    21h
  309. ENDM    DOS_GetDir
  310.  
  311. ;----------------------------------------------------------------------
  312. ;  (4Ch)  DOS_Terminate - End program
  313. ;----------------------------------------------------------------------
  314. ;    Input:  code = [label] or value to pass to DOS or parent process
  315. ;    Output:    none
  316. ;    Registers: ax
  317. ;----------------------------------------------------------------------
  318. MACRO    DOS_Terminate    code
  319.     mov    ah,4Ch
  320.     mov    al,code
  321.     int    21h
  322. ENDM    DOS_Terminate
  323.  
  324. %LIST
  325.