home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / MISC_ASM.ZIP / ZCUT.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-10-29  |  12.7 KB  |  328 lines

  1. ;---------------------------------------; 
  2. ; ZCUT.ASM Macro assembler source code.    ; 
  3. ;---------------------------------------; 
  4.     CODE    SEGMENT            ; 
  5.     ASSUME    CS:CODE,SS:CODE        ; 
  6.     ASSUME    DS:CODE,ES:CODE        ; 
  7.     ORG    100H            ; ".COM" files originate at 100 Hex.
  8. ;---------------------------------------; 
  9. ; DOS loads program then gives control to below line START at offset 100H.
  10. ;---------------------------------------;
  11. START:    JMP    BEGIN            ; Jump over DONE_flag to BEGIN action.
  12. ;---------------------------------------;
  13. DONE_flag    DB    0        ; Done with ZCUT?  0 = No.  1 = Yes.
  14. ;---------------------------------------;
  15. ; Begin ZCUT action on below line.    ;
  16. ;---------------------------------------;
  17. BEGIN:    CALL    DISPLAY_copyright    ; Show user copyright message.
  18.     CALL    OPEN_filename        ; Must open [filename].
  19.     CALL    DISPLAY_processing    ; Show user processing [filename].
  20. MORE:    CALL    READ_filename        ; Read some of [filename] into memory.
  21.     CALL    DO_zcut_file        ; Do one Z01 to Z99 file.
  22.     CMP    DONE_flag,0        ; Do all of [filename] yet?
  23.     JE    MORE            ; No.  Jump to do MORE.
  24.     CALL    CLOSE_filename        ; Yes. Close [filename].
  25.     CALL    DISPLAY_processing_done    ; Show user processing completed.
  26.     MOV    AL,00            ; Tell batch file no errors.
  27.     MOV    AH,4CH            ; Terminate program DOS function.
  28.     INT    21H            ; Call DOS functions.
  29. ;---------------------------------------;
  30. ; End ZCUT action on above line.    ;
  31. ;---------------------------------------;
  32. ; Copyright message memory storage.    ;
  33. ;---------------------------------------;
  34. COPYRIGHT_MSG:                ;
  35. DB'ZCUT  Version 1.10.29 1987 (C) E R Garapic Brook Park OH.',13,10
  36. DB'Comes AS-IS with no warranty.  May be freely distributed.',13,10,13,10,'$'
  37. ;---------------------------------------;
  38. ; Display copyright message        ;
  39. ;---------------------------------------;
  40. DISPLAY_copyright:            ;
  41.     LEA    DX,COPYRIGHT_MSG    ; Point to message.
  42.     MOV    AH,9            ; Display string function.
  43.     INT    21H            ; Call DOS functions.
  44.     RET                ; Return to caller.
  45. ;---------------------------------------;
  46. ; Open [filename]            ;
  47. ;---------------------------------------;
  48. OPEN_filename:                ;
  49.     MOV    DI,80H            ;
  50.     MOV    BL,[DI]            ; Get [filename] byte count.
  51.     MOV    BH,0            ;
  52.     MOV    byte ptr [BX+DI+1],0    ; Make [filename] ASCIIZero string.
  53. NEXT_BYTE:                ;
  54.     INC    DI            ;
  55.       CMP    byte ptr [DI],' '    ; Space before [filename]?
  56.     JZ    NEXT_BYTE        ; Yes.  Increment pointer past space.
  57.         MOV     filename_PTR,DI        ; Save pointer to [filename] ASCIIZ.
  58.     MOV    DX,DI            ; Point DX to [filename] ASCIIZ.
  59.     MOV    AX,3D00H        ; Open file DOS function.
  60.     INT    21H            ; Call DOS functions.
  61.     JNC    OVER1            ; Jump over if no error.
  62.     JMP    ERROR_EXIT        ; Jump file access error.
  63. OVER1:    MOV    filename_HANDLE,AX    ; Store [filename] handle for later.
  64.     RET                ;
  65. ;---------------------------------------;
  66. ; [filename] handle memory storage    ;
  67. ;---------------------------------------;
  68. filename_HANDLE    DW    0000H        ; [filename] handle storage.
  69. ;---------------------------------------;
  70. ; Processing  message memory storage.    ;
  71. ;---------------------------------------;
  72. PROCESSING_MSG:                ;
  73. DB 'ZCUT is processing  $'        ;
  74. ;---------------------------------------;
  75. ; Display processing [filename]        ;
  76. ;---------------------------------------;
  77. DISPLAY_processing:            ;
  78.     LEA    DX,PROCESSING_MSG    ; Point to message.
  79.     MOV    AH,9            ; Display string function.
  80.     INT    21H            ; Call DOS functions.
  81.     CALL    DISPLAY_filename    ; Displays [filename].
  82.     RET                ; Return to caller.
  83. ;---------------------------------------;
  84. filename_PTR    dw ?            ; Address of first byte of [filename].
  85. ;---------------------------------------;
  86. ; Display [filename]            ; 
  87. ;---------------------------------------;
  88. DISPLAY_filename:            ; Display [filename]
  89.     MOV    BX,filename_PTR        ; Point to first [filename] character.
  90.         CALL    DISPLAY_NAME        ;
  91.     MOV    CX,2            ; Carriage Return, Line Feed count.
  92.     CALL    CRLF            ;
  93.     RET                ; Return to caller.
  94. ;---------------------------------------;
  95. ; Count of bytes read memory storage.    ;
  96. ;---------------------------------------;
  97. BYTES_READ    DW    0        ; Actual bytes read from [filename].
  98. AMOUNT        EQU    40000        ; Try for 40,000 bytes per read.
  99. ;---------------------------------------;
  100. ; Read file [filename].            ;
  101. ;---------------------------------------;
  102. READ_filename:                ; 
  103.     MOV    AH,3FH            ; AH = Read file function.
  104.     MOV    BX,filename_HANDLE    ; BX = File handle.
  105.     MOV    CX,AMOUNT        ; CX = 40,000 bytes.
  106.     LEA    DX,BUFFER        ; DX = Buffer address.
  107.     INT    21H            ; Call DOS functions.
  108.     JNC    OVER2            ; Jump over if no error.
  109.     JMP    ERROR_EXIT        ; Jump file access error.
  110. OVER2:                    ;
  111.     MOV    BYTES_READ,AX        ; Store amount of bytes read.
  112.     CMP    AX,AMOUNT        ;
  113.     JE    MORE1            ; Jump if equals AMOUNT.
  114.     MOV    DONE_flag,1        ; Flag = 1 is last block read.
  115. MORE1:                    ;        
  116.     CMP    DONE_flag,1        ; Last block read?
  117.     JE    NO_TOUCH_UP        ; Yes. Do NO_TOUCH_UP on last block.
  118.     CALL    TOUCH_UP        ; Read more bytes til end of line.
  119. NO_TOUCH_UP:                ;
  120.     RET                ; Return to caller.
  121. ;---------------------------------------;
  122. BUFFER_END_POINTER DW BUFFER         ; Point to file memory buffer.
  123. ;---------------------------------------;
  124. ; Computes end of line before cutting.    ;
  125. ;---------------------------------------;
  126. TOUCH_UP:                ;
  127.     ADD     BUFFER_END_POINTER,AX    ; Set pointer.
  128. TOUCH1:                    ;
  129.     MOV    AH,3FH            ; AH = Read file function.
  130.     MOV    BX,filename_HANDLE    ; BX = [filename] handle
  131.     MOV    CX,1            ; Read one byte of [filename].
  132.     MOV    DX,BUFFER_END_POINTER    ; DX = current [filename] buffer ptr.
  133.     INT    21H            ; Call DOS functions.
  134.     JNC    OVER3            ; Jump if no error.
  135.     JMP    ERROR_EXIT        ; Jump file access error.
  136. OVER3:                    ;
  137.     MOV    SI,BUFFER_END_POINTER    ; SI points to last byte read.
  138.     INC    BUFFER_END_POINTER    ; Point to next buffer location.
  139.     INC    BYTES_READ        ; Increment bytes read count.
  140.     MOV    AL,[SI]            ; Get last byte read.
  141.     CMP    AL,10            ; LineFeed?
  142.     JE    WE_DONE            ; Jump if yes.
  143.     JMP    TOUCH1            ; Jump to read another byte.
  144. WE_DONE:                ;
  145.     MOV    BUFFER_END_POINTER,offset BUFFER   ; Reset pointer.
  146.     RET                ; Return to caller.
  147. ;---------------------------------------;
  148. ; Do one Z01 thru Z99 file.        ;
  149. ;---------------------------------------;
  150. DO_zcut_file:                ;
  151.     CALL    ZCUT_AUTO_NAME        ; Auto name ZCUT filename.
  152.     MOV    AH,3CH            ; AH = Create file function.
  153.     MOV    CX,0000H        ; CX = Normal file.
  154.     LEA    DX,ZCUT_NAME_BUFFER    ; DX = ZCUT filename buffer.
  155.     INT    21H            ; Call DOS functions.
  156.     JNC    OVER4            ; Jump over if no error.
  157.     JMP    ERROR_EXIT        ; Jump file access error.
  158. OVER4:                    ;
  159.     MOV    ZCUT_HANDLE,AX        ; Save ZCUT_HANDLE
  160.     MOV    AH,40H            ; AH = Write to file function.
  161.     MOV     BX,ZCUT_HANDLE        ; BX = ZCUT_HANDLE
  162.         MOV     CX,BYTES_READ        ; CX = About 40,000 bytes.
  163.     LEA    DX, BUFFER        ; DX = Pointer to buffer.
  164.     INT    21H            ; Call DOS functions.
  165.     JNC    OVER5            ; Jump over if no erroe.
  166.     JMP    ERROR_EXIT        ; Jump file access error.
  167. OVER5:                    ;
  168.     MOV    AH,3EH            ; AX = Close file function.
  169.     MOV    BX,ZCUT_HANDLE        ; BX = ZCUT_HANDLE
  170.     INT    21H            ; Call DOS functions.
  171.     JNC    OVER6            ; Jump if no error.
  172.     JMP    ERROR_EXIT        ; Jump file access error.
  173. OVER6:                    ;
  174.     RET                ; Return to caller.
  175. ;---------------------------------------;
  176. ; Storage used by DO_zcut_file routine.    ;
  177. ;---------------------------------------;
  178. ZCUT_NAME_BUFFER    DB 80H DUP(?)    ; Auto name buffer. Z01 to Z99.
  179. BIN_NUM        DB    1        ; Auto name binary buffer.
  180. ZCUT_HANDLE    DW    0000H        ; ZCUT file handle.
  181. ;---------------------------------------;
  182. ; Prepare filename Z01 to Z99 for file creation and also display it to screen.
  183. ;---------------------------------------;
  184. ZCUT_AUTO_NAME:                ; 
  185.     MOV    SI,filename_PTR        ; Point to [filename].
  186.     LEA    DI,ZCUT_NAME_BUFFER    ; Point to auto filename buffer.
  187. ZMORE:                    ; 
  188.     MOV    AL,[SI]            ; Get one character from [filename]
  189.     CMP    AL,'.'            ; Period?
  190.     JE    BUILD_EXTENSION        ; Jump if yes.
  191.     CMP    AL,00H            ; Zero?
  192.     JE    BUILD_EXTENSION        ; Jump if yes.
  193.     MOV    [DI],AL            ; Put byte in auto name buffer.
  194.     INC    DI            ; Bump auto name buffer ptr.
  195.     INC    SI            ; Bump [filename] buffer ptr.
  196.     JMP    ZMORE            ; Jump ------------------> ZMORE:
  197. BUILD_EXTENSION:            ;
  198.     MOV    AL,'.'            ; Period part of extension.
  199.     MOV    [DI],AL            ; Place it.
  200.     INC    DI            ;
  201.     MOV    AL,'Z'            ; Z part of extension.
  202.     MOV    [DI],AL            ; Place it.
  203.     INC    DI            ;
  204.     CMP    BYTE PTR BIN_NUM,99    ; Is it .Z99 yet?
  205.     JNE    AUTO_NUMBER_EXT        ; No.  Jump over reset.
  206.     MOV    BYTE PTR BIN_NUM,1    ; Yes. Reset to .Z01 extension.
  207. AUTO_NUMBER_EXT:            ; Now auto number the extension.
  208.     MOV    AL,BIN_NUM        ; Get BIN_NUM in AL
  209.     CALL    BIN2ASC            ; Convert binary to ASCII & place it.
  210.     MOV    AL,0            ; Get zero for ASCIIZ string.
  211.     MOV    [DI],AL            ; Place it. For filename ASCIIZ string.
  212.     INC    BIN_NUM            ; Increment for next name. Z01-Z99.
  213.     CALL    DISPLAY_ZCUT_FILENAME    ; Show user the ZCUT filename.
  214.     RET                ; Return to caller.
  215. ;---------------------------------------;
  216. ; Convert binary number to ASCII and place the result.
  217. ;---------------------------------------;
  218. BIN2ASC:                ; DI points to destination on entry.
  219.     AAM                ; Convert AL binary to BCD value in AX.
  220.     ADD    AX,3030H        ; BCD to ASCII.
  221.     XCHG    AH,AL            ; Get SECOND digit in AL.
  222.     MOV    [DI],AL            ; Place it.
  223.     INC    DI            ;
  224.     XCHG    AH,AL            ; Get FIRST digit in AL.
  225.     MOV    [DI],AL            ; Place it.
  226.     INC    DI            ; 
  227.     RET                ; Return to caller.
  228. ;---------------------------------------;
  229. ; Display one ZCUT filename.        ;
  230. ;---------------------------------------;
  231. DISPLAY_ZCUT_FILENAME:            ;
  232.     LEA    BX,ZCUT_NAME_BUFFER    ; Point to ZCUT filename.
  233.         CALL    DISPLAY_NAME        ;
  234.     MOV    CX,1            ; Carriage Return, Line Feed count.
  235.     CALL    CRLF            ;
  236.     RET                ;
  237. ;---------------------------------------;
  238. ; Display [filename] or ZCUT file name    ;
  239. ;---------------------------------------;
  240. DISPLAY_NAME:                ;
  241.     MOV    DL,[BX]            ; Get one [filename] character.
  242.     CMP    DL,' '            ; Space?
  243.     JE    ZOUT            ; Jump if yes.
  244.     CMP    DL,0            ; Zero?
  245.     JE    ZOUT            ; Jump if yes.
  246.     CMP    DL,'a'            ; Lower case keyed in by user?
  247.     JB    IS_UPPER_CASE       ; Jump if no.
  248.     CMP    DL,'z'            ; Lower case keyed in by user?
  249.     JA    IS_UPPER_CASE        ; Jump if no.
  250.     AND    DL,5FH            ; Yes.  Then convert to upper case.
  251. IS_UPPER_CASE:                ; 
  252.     MOV    AH,02H            ; Display one character function.
  253.     INT    21H            ; Call DOS functions.
  254.     INC    BX            ; Point to next [filename] character.
  255.     JMP    DISPLAY_NAME        ; Jump to get another character.
  256. ZOUT:    RET                ; Return to caller.
  257. ;---------------------------------------;
  258. ; Carriage Return(s), Line feed(s).    ; On entry CX equals count.
  259. ;---------------------------------------;
  260. CRLF:                    ;
  261.     MOV    DL,13            ; Carriage Return.
  262.     MOV    AH,02H            ; Display character function.
  263.     INT    21H            ; Call DOS functions.
  264.     MOV    DL,10            ; Line Feed.
  265.     MOV    AH,02H            ; Display character function.
  266.     INT    21H            ; Call DOS functions.
  267.     LOOP    CRLF            ; Loop until CX is zero.
  268.         RET                ;
  269. ;---------------------------------------;
  270. ; Close [filename]            ;
  271. ;---------------------------------------;
  272. CLOSE_filename:                ;
  273.     MOV    AH,3EH            ; Close file function.
  274.     MOV    BX,filename_HANDLE    ;
  275.     INT    21H            ; Call DOS functions.
  276.     JNC    OVER7            ; Jump over if no error.
  277.     JMP    ERROR_EXIT        ; Jump file access error.
  278. OVER7:    RET                ; Return to caller.
  279. ;---------------------------------------;
  280. ; Processing complete message storage.    ;
  281. ;---------------------------------------;
  282. PROC_DONE_MSG:                ;
  283. DB    13,10                ; Carriage Return, Line Feed.
  284. DB    'Processing complete.'        ;
  285. DB    13,10                ; Carriage Return, Line Feed.
  286. DB    '$'                ; DOS end of string marker.
  287. ;---------------------------------------;
  288. ; Display processing complete message.    ;
  289. ;---------------------------------------;
  290. DISPLAY_processing_done:        ;
  291.     LEA    DX,PROC_DONE_MSG    ; Point to message.
  292.     MOV    AH,9            ; Display string function.
  293.     INT    21H            ; Call DOS functions.
  294.     RET                ; Return to caller.
  295. ;---------------------------------------;
  296. ; Error message memory storage.        ;
  297. ;---------------------------------------;
  298. ERROR_MSG:                ;
  299. DB'File access error.',13,10,13,10    ;
  300. DB'Possible causes:',13,10,13,10    ;
  301. DB'1) [filename] not given.',13,10    ;
  302. DB'2) [filename] does not exist.',13,10    ;
  303. DB'3) Z01-Z99 file(s) write protected.'    ;
  304. DB    13,10                ;
  305. DB    '$'                ;
  306. ;---------------------------------------;
  307. ; Display error message, return to DOS  ;
  308. ;---------------------------------------;
  309. ERROR_EXIT:                ; 
  310.     LEA    DX,ERROR_MSG        ; Point to file access error message.
  311.     MOV    AH,9            ; Display string function.
  312.     INT    21H            ; Call DOS functions.
  313.     MOV    AL,01            ; Tell batch file error code 1.
  314.     MOV    AH,4CH            ; Terminate program DOS function.
  315.     INT    21H            ; Call DOS functions.
  316. ;---------------------------------------;
  317. ; [filename] and ZCUT files memory storage.
  318. ;---------------------------------------;
  319. BUFFER:                    ; About 40,000 bytes starting here.
  320. ;---------------------------------------;
  321. ; Tell MACRO Assembler this is the end also that START is program entry point.
  322. ;---------------------------------------;
  323. CODE    ENDS                ; End of CODE SEGMENT
  324.     END    START            ; End for Macro. START = Entry point.
  325. ;---------------------------------------;
  326. ; End of ZCUT.ASM Macro assembler source code text.  10-29-87 Gene Garapic.
  327. ;---------------------------------------;
  328.