home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / wasm202.zip / BTYPE.ASM < prev    next >
Assembly Source File  |  1986-12-25  |  8KB  |  273 lines

  1.  
  2.  Title 'Wolfware Assembler Sample', 'Binary Type'
  3.  
  4. ;===============================================;
  5. ;           Binary Type Version 2.00            ;
  6. ;                                               ;
  7. ; Displays files to screen as ASCII             ;
  8. ; characters.  Once assembled, to display a     ;
  9. ; file, type:                                   ;
  10. ;                                               ;
  11. ; BTYPE <filespec>                              ;
  12. ;                                               ;
  13. ; There is no translation of any codes, all     ;
  14. ; are displayed as characters.  The BIOS screen ;
  15. ; functions are used.  The number of bytes to   ;
  16. ; display are determined by the size of the     ;
  17. ; file in the directory.                        ;
  18. ;===============================================;
  19.  
  20.  Proc Far
  21.  Call Open              ;open file
  22.  Mov File_Handle, Ax    ;save handle
  23.  
  24.  Call Allocate_Mem      ;get segment of buffer
  25.  Mov Read_Seg, Ax       ;save segment
  26.  Mov Cl, 4
  27.  Shl Bx, Cl             ;make byte form, times 16
  28.  Mov Read_Size, Bx      ;save bytes
  29.  
  30.  Call Display_Stat      ;get display status
  31.  Mov Col_Size, Ah       ;save columns
  32.  Mov Act_Page, Bh       ;save page
  33.  
  34. ;----- read a buffer full
  35.  
  36. More
  37.  Mov Ax, Read_Seg       ;segment
  38.  Mov Bx, File_Handle    ;handle
  39.  Mov Cx, Read_Size      ;bytes to read
  40.  Call Read              ;read into buffer
  41.  Mov Cx, Ax
  42.  
  43. ;----- display a buffer full
  44.  
  45.  Push Cx
  46.  Mov Ax, Read_Seg       ;segment
  47.  Call Display           ;display bytes to screen
  48.  Pop Cx
  49.  
  50.  Cmp Cx, Read_Size      ;check if full buffer read
  51.  Je More                ;jump if so, more to read
  52.  
  53. ;----- finished, close file and exit
  54.  
  55.  Call Close             ;close file
  56.  Mov Ax, 4c00h          ;function
  57.  Int 21h                ;execute
  58.  
  59. ;----- data
  60.  
  61. File_Handle Dw ?        ;file handle
  62. Read_Size Dw ?          ;bytes to read
  63. Read_Seg Dw ?           ;segment of read buffer
  64. Col_Size Db ?           ;number of columns in a line
  65. Act_Page Db ?           ;active screen page
  66.  
  67. ;===============================================;
  68. ;                      Open                     ;
  69. ; Open file named on the parameter line.  Exit  ;
  70. ; with error code 1 if could not open,          ;
  71. ; otherwise AX returns file handle.             ;
  72. ;===============================================;
  73.  
  74. Open Proc Near
  75.  
  76. ;----- set up file name and open file
  77.  
  78.  Mov Bl, [Com_Line]     ;input length
  79.  Sub Bh, Bh
  80.  Mov Byte [Bx+Com_Line+1], 0 ;string terminator
  81.  
  82.  Mov Ax, 3d00h          ;open file for read
  83.  Mov Dx, Com_Line + 2   ;start of name, skip length and leading space
  84.  Int 21h                ;execute
  85.  Jc Bterror             ;jump if error (file not found)
  86.  Ret
  87.  
  88. ;----- couldn't open file, error
  89.  
  90. Bterror
  91.  Mov Dx, Offset Emess   ;error message location
  92.  Mov Ah, 9              ;string display function
  93.  Int 21h                ;execute
  94.  
  95. ;----- exit with error code one
  96.  
  97.  Mov Ax, 4c01h          ;function
  98.  Int 21h                ;execute
  99.  
  100. ;----- data
  101.  
  102. Com_Line Equ 80h        ;offset of command line
  103. Emess Db 'File not found or error in parameter', 13, 10,'$'
  104.  Endp                   ;Open
  105.  
  106. ;===============================================;
  107. ;                  Allocate_Mem                 ;
  108. ; Allocate memory for a buffer to read the      ;
  109. ; file. FFF0H bytes will be allocated, or       ;
  110. ; what's available. AX returns the buffer       ;
  111. ; segment and BX returns the size in            ;
  112. ; paragraphs.                                   ;
  113. ;===============================================;
  114.  
  115. Allocate_Mem Proc Near
  116.  
  117. ;----- reduce present segment (assume ES = CS)
  118.  
  119.  Mov Bx, $Size          ;size of program
  120.  Add Bx, 100h           ;include PSP
  121.  Mov Cl, 4
  122.  Shr Bx, Cl             ;make paragragh form, divide by 16
  123.  Inc Bx                 ;allow for fraction
  124.  
  125.  Mov Ah, 4ah            ;function
  126.  Int 21h                ;execute
  127.  
  128. ;----- allocate new block
  129.  
  130.  Mov Ah, 48h            ;function
  131.  Mov Bx, 0800h          ;paragraphs to allocate
  132.  Int 21h                ;execute
  133.  Jc Smallmem            ;jump if insufficient memory
  134.  Ret
  135.  
  136. ;----- not enough memory, do it with available memory
  137.  
  138. Smallmem
  139.  Mov Ah, 48h            ;function
  140.  Int 21h                ;execute
  141.  Ret
  142.  Endp                   ;Allocate_Mem
  143.  
  144. ;===============================================;
  145. ;                 Display_Stat                  ;
  146. ; Get display status.  AH returns the number of ;
  147. ; columns and BH returns the active page.       ;
  148. ;===============================================;
  149.  
  150. Display_Stat Proc Near
  151.  Mov Ah, 15             ;get video state function
  152.  Int 10h                ;execute
  153.  Ret
  154.  Endp                   ;Display_Stat
  155.  
  156. ;===============================================;
  157. ;                     Read                      ;
  158. ; Read CX bytes to AX:0000 using the file       ;
  159. ; handle in BX.  AX returns the number of bytes ;
  160. ; read.                                         ;
  161. ;===============================================;
  162.  
  163. Read Proc Near
  164.  Push Ds
  165.  Mov Ds, Ax
  166.  
  167.  Mov Ah, 3fh            ;function
  168.  Sub Dx, Dx             ;read location is DS:DX (DS:0000)
  169.  Int 21h                ;execute
  170.  
  171.  Pop Ds
  172.  Ret
  173.  Endp                   ;Read
  174.  
  175. ;===============================================;
  176. ;                    Display                    ;
  177. ; Display CX bytes at AX:0000.                  ;
  178. ;===============================================;
  179.  
  180. Display Proc Near
  181.  Push Ds
  182.  Mov Ds, Ax             ;set to buffer segment
  183.  Sub Si, Si             ;start at offset 0
  184.  
  185. ;----- check if no bytes
  186.  
  187.  Or Cx, Cx              ;check if zero bytes
  188.  Jz Nobtd               ;jump if so
  189.  
  190. ;---- loop for each byte
  191.  
  192. Btdloop
  193.  Lodsb                  ;load next byte
  194.  Push Cx
  195.  Push Si
  196.  Call Display_Char      ;display
  197.  Call Inc_Cursor        ;move cursor
  198.  Pop Si
  199.  Pop Cx
  200.  Loop Btdloop
  201.  
  202. Nobtd
  203.  Pop Ds
  204.  Ret
  205.  Endp                   ;Display
  206.  
  207. ;===============================================;
  208. ;                 Display_Char                  ;
  209. ; Display character in AL. Uses ACT_PAGE        ;
  210. ; defined outside of this routine.              ;
  211. ;===============================================;
  212.  
  213. Display_Char Proc Near
  214.  Mov Ah, 10             ;function
  215.  Seg Cs
  216.  Mov Bh, Act_Page       ;active screen page
  217.  Mov Cx, 1              ;one character
  218.  Int 10h                ;execute
  219.  Ret
  220.  Endp                   ;Display_Char
  221.  
  222. ;===============================================;
  223. ;                   Inc_Cursor                  ;
  224. ; Increment cursor. Switch to new line if at    ;
  225. ; end of line. Uses ACT_PAGE and COL_SIZE       ;
  226. ; defined outside of this routine.              ;
  227. ;===============================================;
  228.  
  229. Inc_Cursor Proc Near
  230.  
  231. ;----- get present cursor position
  232.  
  233.  Mov Ah, 3              ;function
  234.  Seg Cs
  235.  Mov Bh, Act_Page       ;page
  236.  Int 10h                ;execute
  237.  
  238.  Inc Dl                 ;advance column
  239.  Seg Cs
  240.  Cmp Dl, Col_Size       ;check if on last column
  241.  Je Newline             ;if too far then jump
  242.  
  243. ;----- move cursor right one
  244.  
  245.  Mov Ah, 2              ;function
  246.  Int 10h                ;execute
  247.  Ret
  248.  
  249. ;----- new line
  250.  
  251. Newline
  252.  Mov Bl, 0              ;forground color if graphics (don't matter)
  253.  Mov Ax, 0e0dh          ;CR with teletype function
  254.  Int 10h                ;execute
  255.  Mov Ax, 0e0ah          ;LF with teletype function
  256.  Int 10h                ;execute
  257.  Ret
  258.  Endp                   ;Inc_Cursor
  259.  
  260. ;===============================================;
  261. ;                     Close                     ;
  262. ; Close file using the handle in BX.            ;
  263. ;===============================================;
  264.  
  265. Close Proc Near
  266.  Mov Ah, 3eh            ;function
  267.  Int 21h                ;execute
  268.  Ret
  269.  Endp                   ;Close
  270.  
  271.  Endp                   ;main program
  272.  
  273.