home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / asm / wasm / btype.asm < prev    next >
Assembly Source File  |  1988-03-07  |  7KB  |  268 lines

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