DOS 3.30 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2688 lines
45 KiB

5 years ago
  1. _ _ | | _ _
  2. _ ______________
  3. Terminate Program (Function 00H)
  4. Call:
  5. AH = 00H
  6. CS
  7. Segment address of
  8. Program Segment Prefix
  9. Return:
  10. None
  11. Comments:
  12. Function 00H performs the same function as Interrupt 20H. It terminates
  13. the current process and returns control to its parent process. It also closes
  14. all open file handles and clears the disk cache. When this interrupt is
  15. issued, CS must contain the segment address of the Program Segment
  16. Prefix.
  17. The CS register must contain the segment address of the Program Seg-
  18. ment Prefix before you call this interrupt.
  19. The following exit addresses are restored from the specified offsets in the
  20. Program Segment Prefix:
  21. Offset
  22. Exit Address
  23. _ ________________________________________________________________
  24. 0AH Program terminate
  25. 0EH CONTROL-C
  26. 12H Critical error
  27. All file buffers are flushed to disk.
  28. 1
  29. _ _ | | _ _
  30. _ _ | | _ _
  31. _ ______________
  32. _ ________________________________________________________________
  33. Warning
  34. Close all files that have changed in length before calling this function.
  35. If you do not close a changed file, its length is not correctly recorded in
  36. the directory. See Function 10H for a description of the Close File sys-
  37. tem call.
  38. _ ________________________________________________________________
  39. Macro Definition:
  40. terminate_program macro
  41. xor ah,ah
  42. int 21H
  43. endm
  44. Example:
  45. The following program displays a message and returns to MS-DOS. It uses
  46. only the opening portion of the sample program skeleton shown in Figure
  47. 1.2.
  48. message db "Displayed by FUNC00H example", 0DH,0AH,"$"
  49. ;
  50. begin: display message ;see Function 09H
  51. terminate_program ;THIS FUNCTION
  52. code ends
  53. end start
  54. 2
  55. _ _ | | _ _
  56. _ _ | | _ _
  57. _ ______________
  58. Read Keyboard and Echo (Function 01H)
  59. Call:
  60. AH = 01H
  61. Return:
  62. AL
  63. Character typed
  64. Comments:
  65. Function 01H waits for a character to be read from standard input, then
  66. echoes the character to standard output and returns it in AL. If the char-
  67. acter is CONTROL-C, it executes Interrupt 23H.
  68. Macro Definition:
  69. read_kbd_and_echo macro
  70. mov ah, 01H
  71. int 21H
  72. endm
  73. Example:
  74. The following program displays and prints characters as you type them. If
  75. you press the RETURN key, the program sends a linefeed/carriage-return
  76. sequence to both the display and the printer.
  77. begin: read_kbd_and_echo ;THIS FUNCTION
  78. print_char al ;see Function 05H
  79. cmp al,0DH ;is it a CR?
  80. jne begin ;no, print it
  81. print_char 0AH ;see Function 05H
  82. display_char 0AH ;see Function 02H
  83. 3
  84. _ _ | | _ _
  85. _ _ | | _ _
  86. _ ______________
  87. jmp begin ;get another character
  88. 4
  89. _ _ | | _ _
  90. _ _ | | _ _
  91. _ ______________
  92. Display Character (Function 02H)
  93. Call:
  94. AH = 02H
  95. DL
  96. Character to be displayed
  97. Return:
  98. None
  99. Comments:
  100. Function 02H sends the character in DL to standard output. If you press
  101. CONTROL-C, it issues Interrupt 23H.
  102. Macro Definition:
  103. display_char macro character
  104. mov dl,character
  105. mov ah,02H
  106. int 21H
  107. endm
  108. Example:
  109. The following program converts lowercase characters to uppercase before
  110. displaying them.
  111. begin: read_kbd ;see Function 08H
  112. cmp al,"a"
  113. jl uppercase ;don't convert
  114. cmp al,"z"
  115. jg uppercase ;don't convert
  116. sub al,20H ;convert to ASCII code
  117. ;for uppercase
  118. 5
  119. _ _ | | _ _
  120. _ _ | | _ _
  121. _ ______________
  122. uppercase: display_char al ;THIS FUNCTION
  123. jmp begin: ;get another character
  124. 6
  125. _ _ | | _ _
  126. _ _ | | _ _
  127. _ ______________
  128. Auxiliary Input (Function 03H)
  129. Call:
  130. AH = 03H
  131. Return:
  132. AL
  133. Character from auxiliary device
  134. Comments:
  135. Function 03H waits for a character from standard auxiliary devices (AUX,
  136. COM1, COM2, COM3, COM4), then returns the character in AL. This
  137. system call does not return a status or error code.
  138. If you press CONTROL-C, it issues Interrupt 23H.
  139. Macro Definition:
  140. aux_input macro
  141. mov ah,03H
  142. int 21H
  143. endm
  144. Example:
  145. The following program prints characters as soon as it receives them from
  146. the auxiliary device. It stops printing when it receives an end-of-file char-
  147. acter (ASCII 26, or CONTROL-Z).
  148. begin: aux_input ;THIS FUNCTION
  149. cmp al,1AH ;end of file?
  150. je return ;yes, all done
  151. print_char al ;see Function 05H
  152. 7
  153. _ _ | | _ _
  154. _ _ | | _ _
  155. _ ______________
  156. jmp begin ;get another character
  157. 8
  158. _ _ | | _ _
  159. _ _ | | _ _
  160. _ ______________
  161. Auxiliary Output (Function 04H)
  162. Call:
  163. AH = 04H
  164. DL
  165. Character for auxiliary device
  166. Return:
  167. None
  168. Comments:
  169. Function 04H sends the character in DL to standard auxiliary. This sys-
  170. tem call does not return a status or error code.
  171. If you press CONTROL-C, it issues Interrupt 23H.
  172. Macro Definition:
  173. aux_output macro character
  174. mov dl,character
  175. mov ah,04H
  176. int 21H
  177. endm
  178. Example:
  179. The following program gets a series of strings of up to 80 bytes from the
  180. keyboard and sends each string to the auxiliary device. It stops when you
  181. type a null string (carriage-return only).
  182. string db 81 dup(?) ;see Function 0AH
  183. ;
  184. begin: get_string 80,string ;see Function 0AH
  185. cmp string[1],0 ;null string?
  186. 9
  187. _ _ | | _ _
  188. _ _ | | _ _
  189. _ ______________
  190. je return ;yes, all done
  191. mov cx, word ptr string[1] ;get string length
  192. mov bx,0 ;set index to 0
  193. send_it: aux_output string[bx+2] ;THIS FUNCTION
  194. inc bx ;bump index
  195. loop send_it ;send another character
  196. jmp begin ;get another string
  197. 10
  198. _ _ | | _ _
  199. _ _ | | _ _
  200. _ ______________
  201. Print Character (Function 05H)
  202. Call:
  203. AH = 05H
  204. DL
  205. Character for printer
  206. Return:
  207. None
  208. Comments:
  209. Function 05H sends the character in DL to the standard printer. If you
  210. press CONTROL-C, it issues Interrupt 23H. This function does not return a
  211. status or error code.
  212. Macro Definition:
  213. print_char macro character
  214. mov dl,character
  215. mov ah,05H
  216. int 21H
  217. endm
  218. Example:
  219. The following program prints a walking test pattern on the printer. It
  220. stops if you press CONTROL-C.
  221. line_num db 0
  222. ;
  223. begin: mov cx,60 ;print 60 lines
  224. start_line: mov bl,33 ;first printable ASCII
  225. ;character (!)
  226. add bl,line_num ;to offset one character
  227. 11
  228. _ _ | | _ _
  229. _ _ | | _ _
  230. _ ______________
  231. push cx ;save number-of-lines counter
  232. mov cx,80 ;loop counter for line
  233. print_it: print_char bl ;THIS FUNCTION
  234. inc bl ;move to next ASCII character
  235. cmp bl,126 ;last printable ASCII
  236. ;character (~)
  237. jl no_reset ;not there yet
  238. mov bl,33 ;start over with (!)
  239. no_reset: loop print_it ;print another character
  240. print_char 0DH ;carriage return
  241. print_char 0AH ;linefeed
  242. inc line_num ;to offset 1st char. of line
  243. pop cx ;restore #-of-lines counter
  244. loop start_line ;print another line
  245. 12
  246. _ _ | | _ _
  247. _ _ | | _ _
  248. _ ______________
  249. Direct Console I/O (Function 06H)
  250. Call:
  251. AH = 06H
  252. DL
  253. See text
  254. Return:
  255. AL
  256. If DL = FFH before call,
  257. then zero flag not set means AL
  258. has character from standard input.
  259. Zero flag set means there was not
  260. a character to get, and AL = 0.
  261. Comments:
  262. The action of Function 06H depends on the value in DL when the function
  263. is called:
  264. Value in DL
  265. Action
  266. _ ________________________________________________________________
  267. FFH If a character has been read from standard input, it is
  268. returned in AL and the zero flag is cleared (0); if a
  269. character has not been read, the zero flag is set (1).
  270. Not FFH The character in DL is sent to standard output.
  271. This function does not check for CONTROL-C.
  272. Macro Definition:
  273. dir_console_io macro switch
  274. mov dl,switch
  275. mov ah,06H
  276. int 21H
  277. endm
  278. 13
  279. _ _ | | _ _
  280. _ _ | | _ _
  281. _ ______________
  282. Example:
  283. The following program sets the system clock to 0 and displays the time
  284. continuously. When you type any character, the display freezes; when you
  285. type any character again, the clock is reset to 0 and the display starts
  286. again.
  287. time db "00:00:00.00",0DH,0AH,"$" ;see Function 09H
  288. ; ;for explanation of $
  289. ;
  290. begin: set_time 0,0,0,0 ;see Function 2DH
  291. read_clock: get_time ;see Function 2CH
  292. CONVERT ch,time ;see end of chapter
  293. CONVERT cl,time[3] ;see end of chapter
  294. CONVERT dh,time[6] ;see end of chapter
  295. CONVERT dl,time[9] ;see end of chapter
  296. display time ;see Function 09H
  297. dir_console_io FFH ;THIS FUNCTION
  298. cmp al,0 ;character typed?
  299. jne stop ;yes, stop timer
  300. jmp read_clock ;no, keep timer
  301. ;running
  302. stop: read_kbd ;see Function 08H
  303. jmp begin ;start over
  304. 14
  305. _ _ | | _ _
  306. _ _ | | _ _
  307. _ ______________
  308. Direct Console Input (Function 07H)
  309. Call:
  310. AH = 07H
  311. Return:
  312. AL
  313. Character from keyboard
  314. Comments:
  315. Function 07H waits for a character to be read from standard input, then
  316. returns it in AL. This function does not echo the character or check for
  317. CONTROL-C. (For a keyboard input function that echoes or checks for
  318. CONTROL-C, see Function 01H or 08H.)
  319. Macro Definition:
  320. dir_console_input macro
  321. mov ah,07H
  322. int 21H
  323. endm
  324. Example:
  325. The following program prompts for a password (eight characters max-
  326. imum) and places the characters into a string without echoing them.
  327. password db 8 dup(?)
  328. prompt db "Password: $" ;see Function 09H for
  329. ;explanation of $
  330. begin: display prompt ;see Function 09H
  331. mov cx,8 ;maximum length of password
  332. xor bx,bx ;so BL can be used as index
  333. 15
  334. _ _ | | _ _
  335. _ _ | | _ _
  336. _ ______________
  337. get_pass: dir_console_input ;THIS FUNCTION
  338. cmp al,0DH ;was it a carriage return?
  339. je return ;yes, all done
  340. mov password[bx],al ;no, put character in string
  341. inc bx ;bump index
  342. loop get_pass ;get another character
  343. 16
  344. _ _ | | _ _
  345. _ _ | | _ _
  346. _ ______________
  347. Read Keyboard (Function 08H)
  348. Call:
  349. AH = 08H
  350. Return:
  351. AL
  352. Character from keyboard
  353. Comments:
  354. Function 08H waits for a character to be read from standard input, then
  355. returns it in AL. If you press CONTROL-C, it issues Interrupt 23H. This
  356. function does not echo the character. (For a keyboard input function that
  357. echoes the character or checks for CONTROL-C, see Function 01H.)
  358. Macro Definition:
  359. read_kbd macro
  360. mov ah,08H
  361. int 21H
  362. endm
  363. Example:
  364. The following program prompts for a password (eight characters max-
  365. imum) and places the characters into a string without echoing them.
  366. password db 8 dup(?)
  367. prompt db "Password: $" ;see Function 09H
  368. ;for explanation of $
  369. begin: display prompt ;see Function 09H
  370. mov cx,8 ;maximum length of password
  371. xor bx,bx ;BL can be an index
  372. 17
  373. _ _ | | _ _
  374. _ _ | | _ _
  375. _ ______________
  376. get_pass: read_kbd ;THIS FUNCTION
  377. cmp al,0DH ;was it a carriage return?
  378. je return ;yes, all done
  379. mov password[bx],al ;no, put char. in string
  380. inc bx ;bump index
  381. loop get_pass ;get another character
  382. 18
  383. _ _ | | _ _
  384. _ _ | | _ _
  385. _ ______________
  386. Display String (Function 09H)
  387. Call:
  388. AH = 09H
  389. DS:DX
  390. Pointer to string to be displayed
  391. Return:
  392. None
  393. Comments:
  394. Function 09H sends to standard output a string that ends with "$" (the $
  395. is not displayed).
  396. The DX register must contain the offset (from the segment address in DS)
  397. of the string.
  398. Macro Definition:
  399. display macro string
  400. mov dx,offset string
  401. mov ah,09H
  402. int 21H
  403. endm
  404. Example:
  405. The following program displays the hexadecimal code of the key that is
  406. typed.
  407. table db "0123456789ABCDEF"
  408. result db " - 00H",0DH,0AH,"$" ;see text for
  409. ;explanation of $
  410. begin: read_kbd_and_echo ;see Function 01H
  411. 19
  412. _ _ | | _ _
  413. _ _ | | _ _
  414. _ ______________
  415. xor ah,ah ;clear upper byte
  416. convert ax,16,result[3] ;see end of chapter
  417. display result ;THIS FUNCTION
  418. jmp begin ;do it again
  419. 20
  420. _ _ | | _ _
  421. _ _ | | _ _
  422. _ ______________
  423. Buffered Keyboard Input (Function 0AH)
  424. Call:
  425. AH = 0AH
  426. DS:DX
  427. Pointer to input buffer
  428. Return:
  429. None
  430. Comments:
  431. Function 0AH gets a string from standard input. DX must contain the
  432. offset (from the segment address in DS) of an input buffer of the following
  433. form:
  434. Byte
  435. Contents
  436. _ ________________________________________________________________
  437. 1 Maximum number of characters in buffer, including the carriage
  438. return (you must set this value).
  439. 2 Actual number of characters typed, not counting the carriage
  440. return (the function sets this value).
  441. 3-n Buffer; must be at least as long as the number in byte 1.
  442. Characters are read from standard input and placed in the buffer begin-
  443. ning at the third byte until a RETURN character (ASCII 0DH) is read. If the
  444. buffer fills to one less than the maximum, additional characters read are
  445. ignored and ASCII 07H (Bel) is sent to standard output until a RETURN
  446. character is read. If you type the string at the console, it can be edited as
  447. it is being entered. If you press CONTROL-C, it issues Interrupt 23H.
  448. MS-DOS sets the second byte of the buffer to the number of characters
  449. read (not counting the carriage return).
  450. 21
  451. _ _ | | _ _
  452. _ _ | | _ _
  453. _ ______________
  454. Macro Definition:
  455. get_string macro limit,string
  456. mov dx,offset string
  457. mov string,limit
  458. mov ah,0AH
  459. int 21H
  460. endm
  461. Example:
  462. The following program gets a 16-byte (maximum) string from the key-
  463. board and fills a 24-line by 80-character screen with it.
  464. buffer label byte
  465. max_length db ? ;maximum length
  466. chars_entered db ? ;number of chars.
  467. string db 17 dup (?) ;16 chars + CR
  468. strings_per_line dw 0 ;how many strings
  469. ;fit on line
  470. crlf db 0DH,0AH
  471. ;
  472. begin: get_string 17,buffer ;THIS FUNCTION
  473. xor bx,bx ;so byte can be
  474. ;used as index
  475. mov bl,chars_entered ;get string length
  476. mov buffer[bx+2],"$" ;see Function 09H
  477. mov al,50H ;columns per line
  478. cbw
  479. div chars_entered ;times string fits
  480. ;on line
  481. xor ah,ah ;clear remainder
  482. mov strings_per_line,ax ;save col. counter
  483. mov cx,24 ;row counter
  484. display_screen: push cx ;save it
  485. mov cx,strings_per_line ;get col. counter
  486. display_line: display string ;see Function 09H
  487. loop display_line
  488. display crlf ;see Function 09H
  489. pop cx ;get line counter
  490. loop display_screen ;display 1 more line
  491. 22
  492. _ _ | | _ _
  493. _ _ | | _ _
  494. _ ______________
  495. Check Keyboard Status (Function 0BH)
  496. Call:
  497. AH = 0BH
  498. Return:
  499. AL
  500. 00H = no characters in type-ahead buffer
  501. FFH = characters in type-ahead buffer
  502. Comments:
  503. Function 0BH checks whether characters are available from standard
  504. input (if standard input has not been redirected, it checks the type-ahead
  505. buffer). If characters are available, AL returns FFH; if not, AL returns 0.
  506. If CONTROL-C is in the buffer, it issues Interrupt 23H.
  507. Macro Definition:
  508. check_kbd_status macro
  509. mov ah,0BH
  510. int 21H
  511. endm
  512. Example:
  513. The following program displays the time continuously until you press any
  514. key:
  515. time db "00:00:00.00",0DH,0AH,"$"
  516. .
  517. .
  518. begin: get_time ;see Function 2CH
  519. byte_to_dec ch,time ;see end of chapter
  520. byte_to_dec cl,time[3] ;see end of chapter
  521. 23
  522. _ _ | | _ _
  523. _ _ | | _ _
  524. _ ______________
  525. byte_to_dec dh,time[6] ;see end of chapter
  526. byte_to_dec dl,time[9] ;see end of chapter
  527. display time ;see Function 09H
  528. check_kbd_status ;THIS FUNCTION
  529. cmp al,0FFH ;has a key been typed?
  530. je return ;yes, go home
  531. jmp begin ;no, keep displaying
  532. ;time
  533. 24
  534. _ _ | | _ _
  535. _ _ | | _ _
  536. _ ______________
  537. Flush Buffer, Read Keyboard (Function 0CH)
  538. Call:
  539. AH = 0CH
  540. AL
  541. 1, 6, 7, 8, or 0AH = the
  542. corresponding function
  543. is called.
  544. Any other value = no
  545. further processing.
  546. Return:
  547. AL
  548. 00H = Type-ahead buffer was
  549. flushed; no other
  550. processing performed.
  551. Comments:
  552. Function 0CH empties the standard input buffer (if standard input has not
  553. been redirected, Function 0CH empties the type-ahead buffer). Further
  554. processing depends on the value in AL when the function is called.
  555. AL
  556. Action
  557. _ ________________________________________________________________
  558. 1,6,7,8, or 0AH The corresponding MS-DOS function is executed.
  559. Any other value No further processing; AL returns 0.
  560. Macro Definition:
  561. flush_and_read_kbd macro switch
  562. mov al,switch
  563. mov ah,0CH
  564. int 21H
  565. endm
  566. 25
  567. _ _ | | _ _
  568. _ _ | | _ _
  569. _ ______________
  570. Example:
  571. The following program both displays and prints characters as you type
  572. them. If you press the RETURN key, the program sends a carriage-
  573. return/linefeed sequence to both the display and the printer.
  574. begin: flush_and_read_kbd 1 ;THIS FUNCTION
  575. print_char al ;see Function 05H
  576. cmp al,0DH ;is it a carriage return?
  577. jne begin ;no, print it
  578. print_char 0AH ;see Function 05H
  579. display_char 0AH ;see Function 02H
  580. jmp begin ;get another character
  581. 26
  582. _ _ | | _ _
  583. _ _ | | _ _
  584. _ ______________
  585. Reset Disk (Function 0DH)
  586. Call:
  587. AH = 0DH
  588. Return:
  589. None
  590. Comments:
  591. Function 0DH flushes all file buffers to ensure that the internal buffer
  592. cache matches the disks in the drives. It writes out buffers that have been
  593. modified, and marks all buffers in the internal cache as free. This function
  594. request is normally used to force a known state of the system; CONTROL-C
  595. interrupt handlers should call this function.
  596. This function does not update directory entries; you must close changed
  597. files to update their directory entries (see Function 10H, Close File).
  598. Macro Definition:
  599. reset_disk macro
  600. mov ah,0DH
  601. int 21H
  602. endm
  603. 27
  604. _ _ | | _ _
  605. _ _ | | _ _
  606. _ ______________
  607. Example:
  608. The following program flushes all file buffers and selects disk A.
  609. begin: reset_disk
  610. select_disk "A"
  611. 28
  612. _ _ | | _ _
  613. _ _ | | _ _
  614. _ ______________
  615. Select Disk (Function 0EH)
  616. Call:
  617. AH = 0EH
  618. DL
  619. Logical drive number
  620. (0 = A, 1 = B, etc.)
  621. Return:
  622. AL
  623. Number of logical drives
  624. Comments:
  625. Function 0EH selects the drive specified in DL (0=A, 1=B, etc.) as the
  626. current logical drive. AL returns the number of logical drives.
  627. _ ________________________________________________________________
  628. Note
  629. For future compatibility, treat the value returned in AL with care.
  630. For example, if AL returns 5, it is not safe to assume that drives A, B,
  631. C, D, and E are all valid drive designators.
  632. _ ________________________________________________________________
  633. Macro Definition:
  634. select_disk macro disk
  635. mov dl,disk[-64]
  636. mov ah,0EH
  637. int 21H
  638. endm
  639. 29
  640. _ _ | | _ _
  641. _ _ | | _ _
  642. _ ______________
  643. Example:
  644. The following program toggles between drive A and drive B to select the
  645. current drive (in a two-drive system).
  646. begin: current_disk ;see Function 19H
  647. cmp al,00H ;drive A: selected?
  648. je select_b ;yes, select B
  649. select_disk "A" ;THIS FUNCTION
  650. jmp return
  651. select_b: select_disk "B" ;THIS FUNCTION
  652. 30
  653. _ _ | | _ _
  654. _ _ | | _ _
  655. _ ______________
  656. Open File (Function 0FH)
  657. Call:
  658. AH = 0FH
  659. DS:DX
  660. Pointer to unopened FCB
  661. Return:
  662. AL
  663. 00H = Directory entry found
  664. FFH = No directory entry found
  665. Comments:
  666. Function 0FH opens a file. DX must contain the offset (from the segment
  667. address in DS) of an unopened File Control Block (FCB). This call
  668. searches the disk directory for the named file.
  669. If the call finds a directory entry for the file, AL returns 0 and the FCB is
  670. filled as follows:
  671. o If the drive code was 0 (current drive), it is changed to the actual
  672. drive used (1=A, 2=B, etc.). This lets you change the current
  673. drive without interfering with subsequent operations on this file.
  674. o Current Block (offset 0CH) is set to 0.
  675. o Record Size (offset 0EH) is set to the system default of 128.
  676. o File Size (offset 0FH), Date of Last Write (offset 13H), and Time of
  677. Last Write (offset 15H) are set from the directory entry.
  678. Before performing a sequential disk operation on the file, you must set the
  679. Current Record field (offset 1FH). Before performing a random disk opera-
  680. tion on the file, you must set the Relative Record field (offset 20H). If the
  681. default record size (128 bytes) is not correct, set it to the correct length.
  682. If the call doesn't find a directory entry for the file, or if the file has the
  683. hidden or system attribute, AL returns 0FFH.
  684. 31
  685. _ _ | | _ _
  686. _ _ | | _ _
  687. _ ______________
  688. Macro Definition:
  689. open macro fcb
  690. mov dx,offset fcb
  691. mov ah,0FH
  692. int 21H
  693. endm
  694. Example:
  695. The following program prints a file named textfile.asc that is on the disk in
  696. drive B. If a partial record is in the buffer at end-of-file, the routine that
  697. prints the partial record prints characters until it encounters an end-of-file
  698. mark (ASCII 26, or CONTROL-Z).
  699. fcb db 2,"TEXTFILEASC"
  700. db 26 dup (?)
  701. buffer db 128 dup (?)
  702. ;
  703. begin: set_dta buffer ;see Function 1AH
  704. open fcb ;THIS FUNCTION
  705. read_line: read_seq fcb ;see Function 14H
  706. cmp al,02H ;end of file?
  707. je all_done ;yes, go home
  708. cmp al,00H ;more to come?
  709. jg check_more ;no, check for partial
  710. ;record
  711. mov cx,80H ;yes, print the buffer
  712. xor si,si ;set index to 0
  713. print_it: print_char buffer[si] ;see Function 05H
  714. inc si ;bump index
  715. loop print_it ;print next character
  716. jmp read_line ;read another record
  717. check_more: cmp al,03H ;part. record to print?
  718. jne all_done ;no
  719. mov cx,80H ;yes, print it
  720. xor si,si ;set index to 0
  721. find_eof: cmp buffer[si],26 ;end-of-file mark?
  722. je all_done ;yes
  723. print_char buffer[si] ;see Function 05H
  724. inc si ;bump index to next
  725. ;character
  726. loop find_eof
  727. all_done: close fcb ;see Function 10H
  728. 32
  729. _ _ | | _ _
  730. _ _ | | _ _
  731. _ ______________
  732. Close File (Function 10H)
  733. Call:
  734. AH = 10H
  735. DS:DX
  736. Pointer to opened FCB
  737. Return:
  738. AL
  739. 00H = Directory entry found
  740. FFH = No directory entry found
  741. Comments:
  742. Function 10H closes a file. DX must contain the offset (to the segment
  743. address in DS) of an opened FCB. This call searches the disk directory for
  744. the file named in the FCB. If it finds a directory entry for the file, it com-
  745. pares the location of the file with the corresponding entries in the FCB.
  746. The call then updates the directory entry, if necessary, to match the FCB,
  747. and AL returns 0.
  748. After you change a file, you must call this function to update the directory
  749. entry. You should close any FCB (even one for a file that has not been
  750. changed) when you no longer need access to a file.
  751. If this call doesn't find a directory entry for the file, AL returns FFH.
  752. Macro Definition:
  753. close macro fcb
  754. mov dx,offset fcb
  755. mov ah,10H
  756. int 21H
  757. endm
  758. 33
  759. _ _ | | _ _
  760. _ _ | | _ _
  761. _ ______________
  762. Example:
  763. The following program checks the first byte of the file named mod1.bas in
  764. drive B to see if it is FFH and, if it is, prints a message.
  765. message db "Not saved in ASCII format",0DH,0AH,"$"
  766. fcb db 2,"MOD1 BAS"
  767. db 26 dup (?)
  768. buffer db 128 dup (?)
  769. ;
  770. begin: set_dta buffer ;see Function 1AH
  771. open fcb ;see Function 0FH
  772. read_seq fcb ;see Function 14H
  773. cmp buffer,0FFH ;is first byte FFH?
  774. jne all_done ;no
  775. display message ;see Function 09H
  776. all_done: close fcb ;THIS FUNCTION
  777. 34
  778. _ _ | | _ _
  779. _ _ | | _ _
  780. _ ______________
  781. Search for First Entry (Function 11H)
  782. Call:
  783. AH = 11H
  784. DS:DX
  785. Pointer to unopened FCB
  786. Return:
  787. AL
  788. 00H = Directory entry found
  789. FFH = No directory entry found
  790. Comments:
  791. Function 11H searches the disk directory for the first matching filename.
  792. DX must contain the offset (from the segment address in DS) of an
  793. unopened FCB. The filename in the FCB can include wildcard characters.
  794. To search for hidden or system files, DX must point to the first byte of an
  795. extended FCB prefix.
  796. If this call does not find a directory entry for the filename in the FCB, AL
  797. returns FFH.
  798. But if the call does find a directory entry for the filename in the FCB, AL
  799. returns 0 and the call creates an unopened FCB of the same type (normal
  800. or extended) at the Disk Transfer Address as follows:
  801. 1. If the search FCB was normal, the first byte at the Disk Transfer
  802. Address is set to the drive number used in the search (1=A, 2=B,
  803. etc.) and the next 32 bytes contain the directory entry.
  804. 2. If the search FCB was extended, the first byte at the Disk Transfer
  805. Address is set to FFH, the next 5 bytes are set to 00H, and the fol-
  806. lowing byte is set to the value of the attribute byte in the search
  807. FCB. The remaining 33 bytes are the same as the result of the nor-
  808. mal FCB (drive number and 32 bytes of directory entry).
  809. If you use Function 12H (Search for Next Entry) to continue searching for
  810. matching filenames, you must not alter or open the original FCB at
  811. DS:DX.
  812. 35
  813. _ _ | | _ _
  814. _ _ | | _ _
  815. _ ______________
  816. The attribute field is the last byte of the extended FCB fields that precede
  817. the FCB (see earlier in this chapter). If the attribute field is zero, Function
  818. 11H searches only normal file entries. It does not search directory entries
  819. for hidden files, system files, volume label, and subdirectories.
  820. If the attribute field is hidden file, system file, or subdirectory entry (02H,
  821. 04H, or 10H), or any combination of those values, this call also searches all
  822. normal file entries. To search all directory entries except the volume label,
  823. set the attribute byte to 16H (hidden file and system file and directory
  824. entry).
  825. If the attribute field is Volume ID (08H), the call searches only the volume
  826. label entry.
  827. Macro Definition:
  828. search_first macro fcb
  829. mov dx,offset fcb
  830. mov ah,11H
  831. int 21H
  832. endm
  833. Example:
  834. The following program verifies the existence of a file named report.asm on
  835. the disk in drive B.
  836. yes db "FILE EXISTS.$"
  837. no db "FILE DOES NOT EXIST.$"
  838. crlf db 0DH,0AH,"$"
  839. fcb db 2,"REPORT *ASM"
  840. db 26 dup (?)
  841. buffer db 128 dup (?)
  842. ;
  843. begin: set_dta buffer ;see Function 1AH
  844. search_first fcb ;THIS FUNCTION
  845. cmp al,0FFH ;directory entry found?
  846. je not_there ;no
  847. display yes ;see Function 09H
  848. jmp continue
  849. not_there: display no ;see Function 09H
  850. continue: display crlf ;see Function 09H
  851. 36
  852. _ _ | | _ _
  853. _ _ | | _ _
  854. _ ______________
  855. Search for Next Entry (Function 12H)
  856. Call:
  857. AH = 12H
  858. DS:DX
  859. Pointer to unopened FCB
  860. Return:
  861. AL
  862. 00H = Directory entry found
  863. FFH = No directory entry found
  864. Comments:
  865. After you use Function 11H (Search for First Entry), you can use Function
  866. 12H to find any additional directory entries that match a filename (con-
  867. taining wildcard characters). Function 12H searches the disk directory for
  868. the next matching name. DX must contain the offset (from the segment
  869. address in DS) of an FCB specified in a previous call to Function 11H. To
  870. search for hidden or system files, DX must point to the first byte of an
  871. extended FCB prefix\(emone that includes the appropriate attribute value.
  872. If the call does not find a directory entry for the filename in the FCB, AL
  873. returns FFH.
  874. But if the call does find a directory entry for the filename in the FCB, AL
  875. returns 0 and the call creates an unopened FCB of the same type (normal
  876. or extended) at the Disk Transfer Address (see Function 11H for a descrip-
  877. tion of how the unopened FCB is formed).
  878. Macro Definition:
  879. search_next macro fcb
  880. mov dx,offset fcb
  881. mov ah,12H
  882. int 21H
  883. endm
  884. 37
  885. _ _ | | _ _
  886. _ _ | | _ _
  887. _ ______________
  888. Example:
  889. The following program displays the number of files on the disk in drive B.
  890. message db "No files",0DH,0AH,"$"
  891. files db 0
  892. fcb db 2,"???????????"
  893. db 26 dup (?)
  894. buffer db 128 dup (?)
  895. ;
  896. begin: set_dta buffer ;see Function 1AH
  897. search_first fcb ;see Function 11H
  898. cmp al,0FFH ;directory entry found?
  899. je all_done ;no, no files on disk
  900. inc files ;yes, increment file
  901. ;counter
  902. search_dir: search_next fcb ;THIS FUNCTION
  903. cmp al,0FFH ;directory entry found?
  904. je done ;no
  905. inc files ;yes, increment file
  906. ;counter
  907. jmp search_dir ;check again
  908. done: convert files,10,message ;see end of chapter
  909. all_done: display message ;see Function 09H
  910. 38
  911. _ _ | | _ _
  912. _ _ | | _ _
  913. _ ______________
  914. Delete File (Function 13H)
  915. Call:
  916. AH = 13H
  917. DS:DX
  918. Pointer to unopened FCB
  919. Return:
  920. AL
  921. 00H = Directory entry found
  922. FFH = No directory entry found
  923. Comments:
  924. Function 13H deletes a file. DX must contain the offset (from the segment
  925. address in DS) of an unopened FCB. This call searches the directory for a
  926. matching filename. The filename in the FCB can contain wildcard charac-
  927. ters.
  928. If the call does not find a matching directory entry, AL returns FFH.
  929. But if the call does find a matching directory entry, AL returns 0 and the
  930. call deletes the entry from the directory. If the filename contains a wild-
  931. card character, the call will delete all files which match.
  932. Do not delete open files.
  933. Macro Definition:
  934. delete macro fcb
  935. mov dx,offset fcb
  936. mov ah,13H
  937. int 21H
  938. endm
  939. 39
  940. _ _ | | _ _
  941. _ _ | | _ _
  942. _ ______________
  943. Example:
  944. The following program deletes each file on the disk in drive B that was last
  945. written before December 31, 1982.
  946. year dw 1982
  947. month db 12
  948. day db 31
  949. files db 0
  950. message db "No files deleted.",0DH,0AH,"$"
  951. fcb db 2,"???????????"
  952. db 26 dup (?)
  953. buffer db 128 dup (?)
  954. ;
  955. begin: set_dta buffer ;see Function 1AH
  956. search_first fcb ;see Function 11H
  957. cmp al,0FFH ;directory entry found?
  958. jne compare ;yes
  959. jmp all_done ;no, no files on disk
  960. compare: convert_date buffer ;see end of chapter
  961. cmp cx,year ;next several lines
  962. jg next ;check date in directory
  963. cmp dl,month ;entry against date
  964. jg next ;above & check next file
  965. cmp dh,day ;if date in directory
  966. jge next ;entry isn't earlier.
  967. delete buffer ;THIS FUNCTION
  968. inc files ;bump deleted-files
  969. ;counter
  970. next: search_next fcb ;see Function 12H
  971. cmp al,00H ;directory entry found?
  972. je compare ;yes, check date
  973. cmp files,0 ;any files deleted?
  974. je all_done ;no, display No files
  975. ;message.
  976. convert files,10,message ;see end of chapter
  977. all_done: display message ;see Function 09H
  978. 40
  979. _ _ | | _ _
  980. _ _ | | _ _
  981. _ ______________
  982. Sequential Read (Function 14H)
  983. Call:
  984. AH = 14H
  985. DS:DX
  986. Pointer to opened FCB
  987. Return:
  988. AL
  989. 00H = Read completed successfully
  990. 01H = EOF
  991. 02H = DTA too small
  992. 03H = EOF, partial record
  993. Comments:
  994. Function 14H reads a record from a specified file. DX must contain the
  995. offset (from the segment address in DS) of an opened FCB. This call loads
  996. the record pointed to by the Current Block field (offset 0CH) and Current
  997. Record (offset 1FH) field at the Disk Transfer Address, then increments the
  998. Current Block and Current Record fields.
  999. The length of the record is taken from the Record Size field (offset 0EH) of
  1000. the FCB.
  1001. AL returns a code that describes the processing:
  1002. Code
  1003. Meaning
  1004. _ ________________________________________________________________
  1005. 0 Read completed successfully
  1006. 1 End-of-file; no data in the record
  1007. 2 Not enough room at the Disk Transfer Address to read one record;
  1008. read canceled
  1009. 3 End-of-file; a partial record was read and padded to the record
  1010. length with zeros
  1011. 41
  1012. _ _ | | _ _
  1013. _ _ | | _ _
  1014. _ ______________
  1015. Macro Definition:
  1016. read_seq macro fcb
  1017. mov dx,offset fcb
  1018. mov ah,14H
  1019. int 21H
  1020. endm
  1021. Example:
  1022. The following program displays a file named textfile.asc that is on the disk
  1023. in drive B; its function is similar to the MS-DOS type command. If a par-
  1024. tial record is in the buffer at end-of-file, the routine that displays the par-
  1025. tial record displays characters until it encounters an end-of-file mark (ASCII
  1026. 26, or CONTROL-Z).
  1027. fcb db 2,"TEXTFILEASC"
  1028. db 26 dup (?)
  1029. buffer db 128 dup (?),"$"
  1030. ;
  1031. begin: set_dta buffer ;see Function 1AH
  1032. open fcb ;see Function 0FH
  1033. read_line: read_seq fcb ;THIS FUNCTION
  1034. cmp al,02H ;DTA too small?
  1035. je all_done ;yes
  1036. cmp al,00H ;end-of-file?
  1037. jg check_more ;yes
  1038. display buffer ;see Function 09H
  1039. jmp read_line ;get another record
  1040. check_more: cmp al,03H ;partial record in buffer?
  1041. jne all_done ;no, go home
  1042. xor si,si ;set index to 0
  1043. find_eof: cmp buffer[si],26 ;is character EOF?
  1044. je all_done ;yes, no more to display
  1045. display_char buffer[si] ;see Function 02H
  1046. inc si ;bump index
  1047. jmp find_eof ;check next character
  1048. all_done: close fcb ;see Function 10H
  1049. 42
  1050. _ _ | | _ _
  1051. _ _ | | _ _
  1052. _ ______________
  1053. Sequential Write (Function 15H)
  1054. Call:
  1055. AH = 15H
  1056. DS:DX
  1057. Pointer to opened FCB
  1058. Return:
  1059. AL
  1060. 00H = Write completed successfully
  1061. 01H = Disk full
  1062. 02H = DTA too small
  1063. Function 15H writes a record to a specified file. DX must contain the
  1064. offset (from the segment address in DS) of an opened FCB. This call
  1065. writes the record pointed to by the Current Block field (offset 0CH) and
  1066. Current Record field (offset 1FH) at the Disk Transfer Address, then incre-
  1067. ments the Current Block and Current Record fields.
  1068. The record size is taken from the value of the Record Size field (offset 0EH)
  1069. of the FCB. If the record size is less than a sector, the call writes the data
  1070. at the Disk Transfer Address to an MS-DOS buffer; MS-DOS writes the
  1071. buffer to disk when it contains a full sector of data, when the file is closed,
  1072. or when Function 0DH (Reset Disk) is issued.
  1073. AL returns a code that describes the processing:
  1074. Code
  1075. Meaning
  1076. _ ________________________________________________________________
  1077. 0 Write completed successfully
  1078. 1 Disk full; write canceled
  1079. 2 Not enough room at the Disk Transfer Address to write one record;
  1080. write canceled
  1081. 43
  1082. _ _ | | _ _
  1083. _ _ | | _ _
  1084. _ ______________
  1085. Macro Definition:
  1086. write_seq macro fcb
  1087. mov dx,offset fcb
  1088. mov ah,15H
  1089. int 21H
  1090. endm
  1091. Example:
  1092. The following program creates a file named dir.tmp on the disk in drive B,
  1093. containing the disk number (0=A, 1=B, etc.) and filename from each
  1094. directory entry on the disk.
  1095. record_size equ 0EH ;offset of Record Size
  1096. ; field in FCB
  1097. fcb1 db 2,"DIR TMP"
  1098. db 26 dup (?)
  1099. fcb2 db 2,"???????????"
  1100. db 26 dup (?)
  1101. buffer db 128 dup (?)
  1102. ;
  1103. begin: set_dta buffer ;see Function 1AH
  1104. search_first fcb2 ;see Function 11H
  1105. cmp al,0FFH ;directory entry found?
  1106. je all_done ;no, no files on disk
  1107. create fcb1 ;see Function 16H
  1108. mov fcb1[record_size],12
  1109. ;set record size to 12
  1110. write_it: write_seq fcb1 ;THIS FUNCTION
  1111. cmp al,0 ;write successful?
  1112. jne all_done ;no, go home
  1113. search_next fcb2 ;see Function 12H
  1114. cmp al,FFH ;directory entry found?
  1115. je all_done ;no, go home
  1116. jmp write_it ;yes, write the record
  1117. all_done: close fcb1 ;see Function 10H
  1118. 44
  1119. _ _ | | _ _
  1120. _ _ | | _ _
  1121. _ ______________
  1122. Create File (Function 16H)
  1123. Call:
  1124. AH = 16H
  1125. DS:DX
  1126. Pointer to unopened FCB
  1127. Return:
  1128. AL
  1129. 00H = Empty directory found
  1130. FFH = No empty directory available
  1131. Function 16H creates a file. DX must contain the offset (from the segment
  1132. address in DS) of an unopened FCB. MS-DOS searches the directory for
  1133. an entry that matches the specified filename or, if there is no matching
  1134. entry, an empty entry.
  1135. If MS-DOS finds a matching entry, it opens the file and sets the length to
  1136. zero (in other words, if you try to create a file that already exists, MS-DOS
  1137. erases it and creates a new, empty file). If MS-DOS doesn't find a matching
  1138. entry but does find an empty directory entry, it opens the file and sets its
  1139. length to zero. In either case, the call creates the file, and AL returns 0. If
  1140. MS-DOS doesn't find a matching entry and there is no empty entry, the
  1141. call doesn't create the file, and AL returns FFH.
  1142. You can assign an attribute to the file by using an extended FCB with the
  1143. attribute byte set to the appropriate value (see Extended FCB in Section
  1144. 1.9.1).
  1145. Macro Definition:
  1146. create macro fcb
  1147. mov dx,offset fcb
  1148. mov ah,16H
  1149. int 21H
  1150. endm
  1151. 45
  1152. _ _ | | _ _
  1153. _ _ | | _ _
  1154. _ ______________
  1155. Example:
  1156. The following program creates a file named dir.tmp on the disk in drive B,
  1157. containing the disk number (0 = A, 1 = B, etc.) and filename from each
  1158. directory entry on the disk.
  1159. record_size equ 0EH ;offset of Record Size
  1160. ; field of FCB
  1161. fcb1 db 2,"DIR TMP"
  1162. db 26 dup (?)
  1163. fcb2 db 2,"???????????"
  1164. db 26 dup (?)
  1165. buffer db 128 dup (?)
  1166. ;
  1167. begin: set_dta buffer ;see Function 1AH
  1168. search_first fcb2 ;see Function 11H
  1169. cmp al,0FFH ;directory entry found?
  1170. je all_done ;no, no files on disk
  1171. create fcb1 ;THIS FUNCTION
  1172. mov fcb1[record_size],12
  1173. ;set record size to 12
  1174. write_it: write_seq fcb1 ;see Function 15H
  1175. cmp al,0 ;write successful
  1176. jne all_done ;no, go home
  1177. search_next fcb2 ;see Function 12H
  1178. cmp al,FFH ;directory entry found?
  1179. je all_done ;no, go home
  1180. jmp write_it ;yes, write the record
  1181. all_done: close fcb1 ;see Function 10H
  1182. 46
  1183. _ _ | | _ _
  1184. _ _ | | _ _
  1185. _ ______________
  1186. Rename File (Function 17H)
  1187. Call:
  1188. AH = 17H
  1189. DS:DX
  1190. Pointer to modified FCB
  1191. Return:
  1192. AL
  1193. 00H = Directory entry found
  1194. FFH = No directory entry found
  1195. or destination already exists
  1196. Function 17H changes the name of an existing file. DX must contain the
  1197. offset (from the segment address in DS) of an FCB with the drive number
  1198. and filename filled in, followed by a second filename at offset 11H. DOS
  1199. searches the disk directory for an entry that matches the first filename.
  1200. This filename can contain wildcard characters.
  1201. If MS-DOS finds a matching directory entry and there is no directory entry
  1202. that matches the second filename, it changes the filename in the directory
  1203. entry to match the second filename in the modified FCB. AL then returns
  1204. zero. If the second filename does contain a wildcard character, this call
  1205. does not change the corresponding characters in the filename of the direc-
  1206. tory entry.
  1207. You cannot use this function request to rename a hidden file, a system file,
  1208. or a subdirectory. If MS-DOS does not find a matching directory entry or
  1209. if it finds an entry for the second filename, AL returns FFH.
  1210. Macro Definition:
  1211. rename macro fcb,newname
  1212. mov dx,offset fcb
  1213. mov ah,17H
  1214. int 21H
  1215. endm
  1216. 47
  1217. _ _ | | _ _
  1218. _ _ | | _ _
  1219. _ ______________
  1220. Example:
  1221. The following program prompts for the name of a file and a new name; it
  1222. then renames the file.
  1223. fcb db 37 dup (?)
  1224. prompt1 db "Filename: $"
  1225. prompt2 db "New name: $"
  1226. reply db 15 dup(?)
  1227. crlf db 0DH,0AH,"$"
  1228. ;
  1229. begin: display prompt1 ;see Function 09H
  1230. get_string 15,reply ;see Function 0AH
  1231. display crlf ;see Function 09H
  1232. parse reply[2],fcb ;see Function 29H
  1233. display prompt2 ;see Function 09H
  1234. get_string 15,reply ;see Function 0AH
  1235. display crlf ;see Function 09H
  1236. parse reply[2],fcb[16]
  1237. ;see Function 29H
  1238. rename fcb ;THIS FUNCTION
  1239. 48
  1240. _ _ | | _ _
  1241. _ _ | | _ _
  1242. _ ______________
  1243. Get Current Disk (Function 19H)
  1244. Call:
  1245. AH = 19H
  1246. Return:
  1247. AL
  1248. Currently selected drive
  1249. (0 = A, 1 = B, etc.)
  1250. Comments:
  1251. Function 19H returns the current drive in AL (0=A, 1=B, etc.).
  1252. Macro Definition:
  1253. current_disk macro
  1254. mov ah,19H
  1255. int 21H
  1256. endm
  1257. Example:
  1258. The following program displays the default drive in a two-drive system.
  1259. message db "Current disk is $"
  1260. crlf db 0DH,OAH,"$"
  1261. ;
  1262. begin: display message ;see Function 09H
  1263. current_disk ;THIS FUNCTION
  1264. cmp al,00H ;is it disk A?
  1265. jne disk_b ;no, it's disk B:
  1266. display_char "A" ;see Function 02H
  1267. jmp all_done
  1268. disk_b: display_char "B" ;see Function 02H
  1269. all_done: display crlf ;see Function 09H
  1270. 49
  1271. _ _ | | _ _
  1272. _ _ | | _ _
  1273. _ ______________
  1274. Set Disk Transfer Address (Function 1AH)
  1275. Call:
  1276. AH = 1AH
  1277. DS:DX
  1278. Disk Transfer Address
  1279. Return:
  1280. None
  1281. Comments:
  1282. Function 1AH sets the Disk Transfer Address. DX must contain the offset
  1283. (from the segment address in DS) of the Disk Transfer Address. Disk
  1284. transfers cannot wrap around from the end of the segment to the begin-
  1285. ning, nor can they overflow into another segment.
  1286. If you do not set the Disk Transfer Address, MS-DOS defaults to offset
  1287. 80H in the Program Segment Prefix. You can check the current Disk
  1288. Transfer Address with Function 2FH (Get Disk Transfer Address).
  1289. Macro Definition:
  1290. set_dta macro buffer
  1291. mov dx,offset buffer
  1292. mov ah,1AH
  1293. int 21H
  1294. endm
  1295. 50
  1296. _ _ | | _ _
  1297. _ _ | | _ _
  1298. _ ______________
  1299. Example:
  1300. The following program prompts for a letter, converts it to its alphabetic
  1301. sequence (A=1, B=2, etc.), then reads and displays the corresponding
  1302. record from a file named alphabet.dat that is on the disk in drive B. The
  1303. file contains 26 records, each 28 bytes long.
  1304. record_size equ 0EH ;offset of Record Size
  1305. ;field of FCB
  1306. relative_record equ 21H ;offset of Relative Record
  1307. ; field of FCB
  1308. fcb db 2,"ALPHABETDAT"
  1309. db 26 dup (?)
  1310. buffer db 28 dup(?),"$"
  1311. prompt db "Enter letter: $"
  1312. crlf db 0DH,0AH,"$"
  1313. ;
  1314. begin: set_dta buffer ;THIS FUNCTION
  1315. open fcb ;see Function 0FH
  1316. mov fcb[record_size],28 ;set record size
  1317. get_char: display prompt ;see Function 09H
  1318. read_kbd_and_echo ;see Function 01H
  1319. cmp al,0DH ;just a CR?
  1320. je all_done ;yes, go home
  1321. sub al,41H ;convert ASCII
  1322. ;code to record #
  1323. mov fcb[relative_record],al
  1324. ;set relative record
  1325. display crlf ;see Function 09H
  1326. read_ran fcb ;see Function 21H
  1327. display buffer ;see Function 09H
  1328. display crlf ;see Function 09H
  1329. jmp get_char ;get another character
  1330. all_done: close fcb ;see Function 10H
  1331. 51
  1332. _ _ | | _ _
  1333. _ _ | | _ _
  1334. _ ______________
  1335. Get Default Drive Data (Function 1BH)
  1336. Call:
  1337. AH = 1BH
  1338. Return:
  1339. AL
  1340. Sectors per cluster
  1341. CX
  1342. Bytes per sector
  1343. DX
  1344. Clusters per drive
  1345. DS:BX
  1346. Pointer to FAT ID byte
  1347. Function 1BH retrieves data about the disk in the default drive. The data
  1348. returns in the following registers:
  1349. Register
  1350. Contents
  1351. _ ________________________________________________________________
  1352. AL Number of sectors in a cluster (allocation unit)
  1353. CX Number of bytes in a sector
  1354. DX Number of clusters on the disk
  1355. BX returns the offset (to the segment address in DS) of the first byte of the
  1356. File Allocation Table (FAT), which identifies the type of disk in the drive:
  1357. Value
  1358. Type of Drive
  1359. _ ________________________________________________________________
  1360. FF Double-sided disk, 8 sectors per track, 40 tracks per side
  1361. FE Single-sided disk, 8 sectors per track, 40 tracks per side
  1362. FD Double-sided disk, 9 sectors per track, 40 tracks per side
  1363. FC Single-sided disk, 9 sectors per track, 40 tracks per side
  1364. F9 Double-sided disk, 15 sectors per track, 40 tracks per side
  1365. F9 Double-sided disk, 9 sectors per track, 80 tracks per side
  1366. F8 Fixed disk
  1367. This call is similar to Function 36H (Get Disk Free Space), except that it
  1368. 52
  1369. _ _ | | _ _
  1370. _ _ | | _ _
  1371. _ ______________
  1372. returns the address of the FAT ID byte in BX instead of the number of
  1373. available clusters. It is also similar to Function 1CH (Get Drive Data),
  1374. except that it returns data on the disk in the default drive instead of on
  1375. the disk in a specified drive. For a description of how MS-DOS stores data
  1376. on a disk, including a description of the File Allocation Table, see Chapter
  1377. 3, "MS-DOS Technical Information."
  1378. _ ________________________________________________________________
  1379. Warning
  1380. The FAT ID byte is no longer adequate to identify the type of drive
  1381. being used. See Chapter 2, "MS-DOS Device Drivers," for more
  1382. details.
  1383. _ ________________________________________________________________
  1384. Macro Definition:
  1385. def_drive_data macro
  1386. push ds
  1387. mov ah,1BH
  1388. int 21H
  1389. mov al,byte ptr[bx]
  1390. pop ds
  1391. endm
  1392. Example:
  1393. The following program displays a message that tells whether the default
  1394. drive is a disk or a fixed disk drive.
  1395. stdout equ 1
  1396. ;
  1397. msg db "Default drive is "
  1398. dskt db "disk."
  1399. fixed db "fixed."
  1400. crlf db ODH,OAH
  1401. ;
  1402. begin: write_handle stdout,msg,17 ;display message
  1403. jc write_error ;routine not shown
  1404. def_drive_data ;THIS FUNCTION
  1405. cmp byte ptr [bx],0F8H ;check FAT ID byte
  1406. jne disk ;it's a disk
  1407. write_handle stdout,fixed,6 ;see Function 40H
  1408. jc write_error ;see Function 40H
  1409. jmp short all_done ;clean up & go home
  1410. disk: write_handle stdout,dskt,9 ;see Function 40H
  1411. all_done: write_handle stdout,crlf,2 ;see Function 40H
  1412. jc write_error ;routine not shown
  1413. 53
  1414. _ _ | | _ _
  1415. _ _ | | _ _
  1416. _ ______________
  1417. Get Drive Data (Function 1CH)
  1418. Call:
  1419. AH = 1CH
  1420. DL
  1421. Drive (0=default, 1=A, etc.)
  1422. Return:
  1423. AL
  1424. 0FFH if drive number is invalid;
  1425. otherwise, sectors per cluster
  1426. CX
  1427. Bytes per sector
  1428. DX
  1429. Clusters per drive
  1430. DS:BX
  1431. Pointer to FAT ID byte
  1432. Comments:
  1433. Function 1CH retrieves data about the disk in the specified drive. DL must
  1434. contain the drive number (0=default, 1=A, etc.). The data returns in the
  1435. following registers:
  1436. Register
  1437. Contents
  1438. _ ________________________________________________________________
  1439. AL Number of sectors in a cluster (allocation unit)
  1440. CX Number of bytes in a sector
  1441. DX Number of clusters on the disk
  1442. BX returns the offset (to the segment address in DS) of the first byte of the
  1443. File Allocation Table (FAT), which identifies the type of disk in the drive:
  1444. Value
  1445. Type of Drive
  1446. _ ________________________________________________________________
  1447. FF Double-sided disk, 8 sectors per track, 40 tracks per side
  1448. FE Single-sided disk, 8 sectors per track, 40 tracks per side
  1449. FD Double-sided disk, 9 sectors per track, 40 tracks per side
  1450. FC Single-sided disk, 9 sectors per track, 40 tracks per side
  1451. 54
  1452. _ _ | | _ _
  1453. _ _ | | _ _
  1454. _ ______________
  1455. F9 Double-sided disk, 15 sectors per track, 40 tracks per side
  1456. F9 Double-sided disk, 9 sectors per track, 80 tracks per side
  1457. F8 Fixed disk
  1458. If the drive number in DL is invalid, AL returns 0FFH.
  1459. _ ________________________________________________________________
  1460. Warning
  1461. The FAT ID byte is no longer adequate to identify the type of drive
  1462. being used. See Chapter 2, "MS-DOS Device Drivers" for more details.
  1463. _ ________________________________________________________________
  1464. This call is similar to Function 36H (Get Disk Free Space), except that it
  1465. returns the address of the FAT ID byte in BX instead of the number of
  1466. available clusters. It is also similar to Function 1BH (Get Default Drive
  1467. Data), except that it returns data on the disk in the drive specified in DL
  1468. instead of the disk in the default drive. For a description of how MS-DOS
  1469. stores data on a disk, including a description of the File Allocation Table,
  1470. see Chapter 3, "MS-DOS Technical Information."
  1471. Macro Definition:
  1472. drive_data macro drive
  1473. push ds
  1474. mov dl,drive
  1475. mov ah,1BH
  1476. int 21H
  1477. mov al, byte ptr[bx]
  1478. pop ds
  1479. endm
  1480. Example:
  1481. The following program displays a message that tells whether drive B is a
  1482. disk or a fixed disk drive.
  1483. stdout equ 1
  1484. :
  1485. msg db "Drive B is "
  1486. dskt db "disk."
  1487. fixed db "fixed."
  1488. crlf db ODH,OAH
  1489. ;
  1490. begin: write_handle stdout,msg,11 ;display message
  1491. jc write_error ;routine not shown
  1492. drive_data 2 ;THIS FUNCTION
  1493. 55
  1494. _ _ | | _ _
  1495. _ _ | | _ _
  1496. _ ______________
  1497. cmp byte ptr [bx],0F8H ;check FAT ID byte
  1498. jne disk ;it's a disk
  1499. write_handle stdout,fixed,6 ;see Function 40H
  1500. jc write_error ;routine not shown
  1501. jmp all_done ;clean up & go home
  1502. disk: write_handle stdout,dskt,9 ;see Function 40H
  1503. all_done: write_handle stdout,crlf,2 ;see Function 40H
  1504. jc write_error ;routine not shown
  1505. 56
  1506. _ _ | | _ _