home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / wasm.arc / BTYPE.ASM next >
Encoding:
Assembly Source File  |  1986-02-16  |  6.9 KB  |  203 lines

  1.            TITLE     'Wolfware Sample Program','Binary Type'
  2.  
  3. ;----------------------------------------------;
  4. ;                  Binary Type                 ;
  5. ;                                              ;
  6. ; Displays files to screen as ASCII            ;
  7. ; characters.  Once assembled, to display a    ;
  8. ; file, type:                                  ;
  9. ;                                              ;
  10. ; BTYPE [filespec]                             ;
  11. ;                                              ;
  12. ; There is no translation of any codes, all    ;
  13. ; are displayed as characters.  The number of  ;
  14. ; bytes to display are determined by the size  ;
  15. ; of the file in the directory. Does not       ;
  16. ; support path names.                          ;
  17. ;----------------------------------------------;
  18.  
  19.            PROC      FAR
  20. FCB        EQU       5CH            ;formated FCB location
  21. SEG_SIZE   EQU       WORD [6]       ;bytes in segement
  22.  
  23.            MOV       DX,FCB         ;FCB
  24.            CALL      OPEN           ;open file
  25.            PUSH      DX
  26.  
  27. ;----- calculate available space
  28.  
  29.            MOV       AX,SEG_SIZE    ;bytes in segement
  30.            SUB       AX,OFFSET BUFFER + 100H ;space for program and stack
  31.            MOV       READ_SIZE,AX   ;save bytes to read
  32.  
  33. ;----- get active page and columns per line
  34.  
  35.            MOV       AH,15          ;get video state function
  36.            INT       10H            ;execute
  37.  
  38.            MOV       COL_SIZE,AH    ;save columns
  39.            MOV       ACT_PAGE,BH    ;save page
  40.  
  41. ;----- display file
  42.  
  43. MORE       MOV       BX,OFFSET BUFFER ;put after program
  44.            MOV       CX,READ_SIZE   ;bytes to read
  45.            MOV       BP,SP
  46.            MOV       DX,[BP]        ;FCB location from stack
  47.            CALL      READ           ;read into buffer
  48.  
  49.            PUSHF
  50.            MOV       SI,BX          ;source
  51.            CALL      DISPLAY        ;display bytes to screen
  52.            POPF
  53.            JZ        MORE           ;jump if more to read
  54.  
  55. ;----- finished, close file
  56.  
  57. DONE       POP       DX
  58.            CALL      CLOSE          ;close file
  59.            INT       20H            ;exit
  60.  
  61. ;----- data
  62.  
  63. READ_SIZE  DW        ?              ;bytes to read
  64. COL_SIZE   DB        ?              ;number of columns in a line
  65. ACT_PAGE   DB        ?              ;active screen page
  66.  
  67. ;----------------------------------------------;
  68. ;                    DISPLAY                   ;
  69. ; Display CX bytes at SI.                      ;
  70. ;----------------------------------------------;
  71.  
  72. DISPLAY    PROC      NEAR
  73.            OR        CX,CX          ;check if zero bytes
  74.            JZ        NOBTD          ;jump if so
  75.  
  76. BTDLOOP    LODSB                    ;load next byte
  77.  
  78.            PUSH      CX
  79.            PUSH      SI
  80.            CALL      DISPLAY_CHAR   ;display
  81.            CALL      INC_CURSOR     ;move cursor
  82.            POP       SI
  83.            POP       CX
  84.  
  85.            LOOP      BTDLOOP
  86. NOBTD      RET
  87.            ENDP                     ;DISPLAY
  88.  
  89. ;----------------------------------------------;
  90. ;                 DISPLAY_CHAR                 ;
  91. ; Display character in AL.                     ;
  92. ;----------------------------------------------;
  93.  
  94. DISPLAY_CHAR PROC     NEAR
  95.            MOV       BH,ACT_PAGE    ;active screen page
  96.            MOV       CX,1           ;one character
  97.            MOV       AH,10          ;character display function
  98.            INT       10H            ;execute
  99.            RET
  100.            ENDP                     ;DISPLAY_CHAR
  101.  
  102. ;----------------------------------------------;
  103. ;                   INC_CURSOR                 ;
  104. ; Increment cursor. Switch to new line if at   ;
  105. ; end of line.                                 ;
  106. ;----------------------------------------------;
  107.  
  108. INC_CURSOR PROC      NEAR
  109.            MOV       BH,ACT_PAGE    ;page
  110.            MOV       AH,3           ;read cursor position function
  111.            INT       10H            ;execute
  112.  
  113.            INC       DL
  114.            CMP       DL,COL_SIZE    ;check if on last column
  115.            JE        NEWLINE        ;if to far then jump
  116.  
  117. ;----- move cursor right one
  118.  
  119.            MOV       AH,2           ;move cursor function
  120.            INT       10H            ;execute
  121.            RET
  122.  
  123. ;----- new line
  124.  
  125. NEWLINE    MOV       BL,15          ;forground color if graphics (?)
  126.            MOV       AX,0E0DH       ;CR with teletype function
  127.            INT       10H            ;execute
  128.            MOV       AX,0E0AH       ;LF with teletype function
  129.            INT       10H            ;execute
  130.            RET
  131.            ENDP                     ;INC_CURSOR
  132.  
  133. ;----------------------------------------------;
  134. ;                     OPEN                     ;
  135. ; Open file using the FCB at DX.  Print error  ;
  136. ; message and exit program if can't open file. ;
  137. ;----------------------------------------------;
  138.  
  139. OPEN       PROC      NEAR
  140.            MOV       AH,0FH         ;open file function
  141.            INT       21H            ;execute
  142.  
  143.            OR        AL,AL          ;check if error
  144.            JNZ       BTERROR        ;jump if so
  145.  
  146.            MOV       BX,DX
  147.            MOV       WORD [BX+0EH],1 ;record size one
  148.            MOV       WORD [BX+21H],0 ;record number (low) zero
  149.            MOV       WORD [BX+23H],0 ;record number (high) zero
  150.            RET
  151.  
  152. ;----- couldn't open file, error
  153.  
  154. BTERROR    MOV       DX,OFFSET EMESS ;error message location
  155.            MOV       AH,9           ;string display function
  156.            INT       21H            ;execute
  157.            INT       20H            ;exit
  158.  
  159. ;----- error message
  160.  
  161. EMESS      DB        'File not found or error in parameter',13,10,'$'
  162.            ENDP                     ;OPEN
  163.  
  164. ;----------------------------------------------;
  165. ;                     READ                     ;
  166. ; Read CX bytes to BX using FCB in DX. ZF=1 if ;
  167. ; there is more in file and CX returns the     ;
  168. ; number of bytes read.                        ;
  169. ;----------------------------------------------;
  170.  
  171. READ       PROC      NEAR
  172.  
  173. ;----- set DTA
  174.  
  175.            PUSH      DX
  176.            MOV       DX,BX          ;DTA location
  177.            MOV       AH,1AH         ;set DTA function
  178.            INT       21H            ;execute
  179.            POP       DX
  180.  
  181. ;----- read bytes
  182.  
  183.            MOV       AH,27H         ;read random block function
  184.            INT       21H            ;execute
  185.            OR        AL,AL          ;set ZF
  186.            RET
  187.            ENDP                     ;READ
  188.  
  189. ;----------------------------------------------;
  190. ;                      CLOSE                   ;
  191. ; Close file using FCB at DX.                  ;
  192. ;----------------------------------------------;
  193.  
  194. CLOSE      PROC      NEAR
  195.            MOV       AH,10H         ;close fiel function
  196.            INT       21H            ;execute
  197.            RET
  198.            ENDP
  199.  
  200. BUFFER     LABEL     BYTE
  201.            ENDP
  202. 
  203.