home *** CD-ROM | disk | FTP | other *** search
- title CUT-HPL_ASM ; 9-24-88
- ;AUTHOR: JACK W. GARLAND
-
- ;this program will un-arc and
- ;print a Dr. Halo II "cut" file
- ;on the HP Laser Jet printer.
-
- cgroup group code_seg, data_seg
- assume cs:cgroup, ds:cgroup
-
- code_seg segment public
- code_seg ends
-
- data_seg segment public
-
- PUBLIC DIGIT1
- DIGIT1 DB 30H
-
- PUBLIC DIGIT2
- DIGIT2 DB 31H
-
- ;DIGIT1 & DIGIT2 define # of copies
- ;to print.
- ;default = 01 (30h 31h)
- ;you can change this.
- ;example 12 copies / change DIGIT1
- ;to 31h, change DIGIT2 to 32h
-
- public FREE
- FREE db 8
- ;FREE = number of free bits in
- ;CURRENT byte of LINEBUFF.
-
- public CURRENT
- CURRENT dw ?
- ;Pointer to Current work byte in
- ;LINEBUFF (bit pack buffer)
-
- public LINEBUFF
- LINEBUFF db 100 dup(00)
- ;100 bytes of data to send to printer
- ;printed and set to all 0's after each
- ;print pass.
-
- public fcb ;file control block
- ;1st byte is drive spec, 0 = default drive
- fcb db 00h
- db 20h,20h,20h,20h ;filename
- db 20h,20h,20h,20h ;padded spaces
- db 43h,55h,54h ;extension .CUT
- ;filename.ext = ????????.CUT
- public zeros
- zeros db 00h,00h,00h,00h,00h
- db 00h,00h,00h,00h,00h
- db 00h,00h,00h,00h,00h
- db 00h,00h,00h,00h,00h
- db 00h,00h,00h,00h
- public dta
- dta db 80h dup(0) ;data transfer area
-
- public dta2
- dta2 db 90h dup(0) ;trash area used by DOS
-
- public MESSA
- MESSA DB 0ah,0dh,'You MUST include filename on command line. Ext. .CUT will be added by program',0ah,0dh,07h,24h
-
- public MESSB
- MESSB DB 0ah,0dh,'File does not exist in working directory. File must be in working directory.',0ah,0dh,07h,24h
-
- public MESSC
- MESSC DB 0ah,0dh,' Decompressing and Printing. Press key to abort!',0ah,0dh,24h
-
- data_seg ends
-
- code_seg segment public
- org 100h
-
- START proc near
- Call CLEAR_WHOLE_SCREEN
- Call GET_COMMAND_LINE_PARAMETERS
- ;on return, carry flag is clear
- ;if NO filename was on command line
- ;in which case we print MESSA and
- ;exit program.
- jc PROCEED ;jump if carry set
- push dx
- lea dx,MESSA
- Call PRINT_MESSAGE
- pop dx
- jmp QUITX
- PROCEED:
- ;check to see if file exists.
- ;try to open file.
- push dx
- push ax
- lea dx,fcb
- mov ah,0fh
- int 21h
- cmp al,0FFh ;error flag
- pop ax
- pop dx
- jb CONTINUE
- ;file not found.
- push dx
- lea dx,MESSB
- Call PRINT_MESSAGE
- pop dx
- jmp QUITX
- CONTINUE:
- Call INITIALIZE_LINEBUFF_POINTERS
- Call INITIALIZE_LASER_JET
- push dx
- lea dx,MESSC
- Call PRINT_MESSAGE
- pop dx
- ;open file
- Call ZERO_OUT_FCB
- lea dx,fcb
- mov ah,0fh
- int 21h
- ;set DTA
- lea dx,dta
- mov ah,1ah
- int 21h
- ;read 1 block (128 bytes)
- Call READ_FILE_BLOCK ;into DTA
- lea si,dta
- add si,6 ;si = si + 6
- mov cx,1050 ;# of lines to print
- RLOOP:
- push cx
- Call PROCESS_A_LINE
- Call PRINT_A_LINE
- Call INITIALIZE_LINEBUFF_POINTERS
- pop cx
- ;check for keypress:
- ;if key pressed the exit program
- ;after resetting printer
- push ax
- push dx
- mov ah,6
- mov dl,0FFh ;input request
- int 21h
- ;if no char read, zero flag is set
- pop dx
- pop ax
- jnz BREAKLOOP ;reset prtr & quit
- loop RLOOP
- BREAKLOOP:
- Call RESET_LASER_JET
- QUITX:
- mov ax,4c00h
- int 21h ;exit to DOS
- START endp
-
- PRINT_A_LINE PROC NEAR
- ;the next code string sent
- ;tells the printer how many data
- ;bytes will be following the command.
- ;This must precede each 100 bytes
- ;of data. 100 * 8 = 800 bits width.
- ;codes to send: (HEX)
- ;1b,2a,62,31,30,30,57
- ;ec * b 1 0 0 W
- push ax
- push cx
- push dx
- push si
- mov cx,100 ;100 byte counter
-
- mov dl,1bh
- mov ah,5
- int 21h
-
- mov dl,2ah
- int 21h
-
- mov dl,62h
- int 21h
-
- mov dl,31h
- int 21h
-
- mov dl,30h
- int 21h
-
- mov dl,30h
- int 21h
-
- mov dl,57h
- int 21h
-
- lea si,LINEBUFF
- TTTTT:
- mov dl,ds:[si]
- inc si
- int 21h
- loop TTTTT
- pop si
- pop dx
- pop cx
- pop ax
- ret
- PRINT_A_LINE ENDP
-
- INITIALIZE_LASER_JET PROC NEAR
- PUSH DX
- PUSH AX
- ;set top margin to 0
- mov dl,1bh
- mov ah,5
- int 21h
- mov dl,26h
- int 21h
- mov dl,6ch
- int 21h
- mov dl,30h
- int 21h
- mov dl,45h
- int 21h
-
- ;set text length to 66
- mov dl,1bh
- int 21h
- mov dl,26h
- int 21h
- mov dl,6ch
- int 21h
- mov dl,36h
- int 21h
- mov dl,36h
- int 21h
- mov dl,46h
- int 21h
-
- ;set number of copies
- ;up to 99 can be made.
- mov dl,1bh
- int 21h
- mov dl,26h
- int 21h
- mov dl,6ch
- int 21h
- mov dl,DIGIT1
- int 21h
- mov dl,DIGIT2
- int 21h
- mov dl,58h
- int 21h
-
- ;set resolution at 100 DPI
- ;hex codes to send:
- ;1b,2a,74,31,30,30,52
- mov dl,1bh
- int 21h
- mov dl,2ah
- int 21h
- mov dl,74h
- int 21h
- mov dl,31h
- int 21h
- mov dl,30h
- int 21h
- mov dl,30h
- int 21h
- mov dl,52h
- int 21h
-
- ;set X cursor at X = 000
- ;(1.8" @ 300 DPI)
- ;codes to send: (HEX)
- ;1B,2A,70,30,30,30,58
- ;ec * p 0 0 0 X
- mov dl,1bh
- int 21h
- mov dl,2ah
- int 21h
- mov dl,70h
- int 21h
- mov dl,30h
- int 21h
- mov dl,30h
- int 21h
- mov dl,30h
- int 21h
- mov dl,58h
- int 21h
-
- ;position the cursor Y = 037
- ;codes to send: (HEX)
- ;1B,2A,70,30,33,37,59
- ;ec * p 0 3 7 Y
- mov dl,1bh
- int 21h
- mov dl,2ah
- int 21h
- mov dl,70h
- int 21h
- mov dl,30h
- int 21h
- mov dl,33h
- int 21h
- mov dl,37h
- int 21h
- mov dl,59h
- int 21h
-
- ;start graphics at left graphics
- ;margin.
-
- ;codes to send
- ;1b,2a,72,30,41 hex
- mov dl,1bh
- int 21h
- mov dl,2ah
- int 21h
- mov dl,72h
- int 21h
- mov dl,30h
- int 21h
- mov dl,41h
- int 21h
- POP AX
- POP DX
- RET
- INITIALIZE_LASER_JET ENDP
-
- RESET_LASER_JET PROC NEAR
- push ax
- push dx
- ;send END of graphics codes.
- ;codes - HEX...
- ;1b,2a,72,42
- mov dl,1bh
- mov ah,5
- int 21h
-
- mov dl,2ah
- int 21h
-
- mov dl,72h
- int 21h
-
- mov dl,42h
- int 21h
-
- ;send EJECT page command.
- ;to HP Laser Jet printer.
- ;codes hex 1b,26,6c,30,48
- mov dl,1bh
- int 21h
-
- mov dl,26h
- int 21h
-
- mov dl,6ch
- int 21h
-
- mov dl,30h
- int 21h
-
- mov dl,48h
- int 21h
-
- ;send RESET codes to HP Laser
- mov dl,1bh
- int 21h
- mov dl,45h
- int 21h
-
- pop dx
- pop ax
- ret
- RESET_LASER_JET ENDP
-
- PROCESS_A_LINE PROC NEAR
- inc si
- Call READ_AGAIN
- inc si ;skip first 2 bytes
- ;of line data (length
- ;of record)
- DOAGAIN:
- Call READ_AGAIN
- mov bh,ds:[si]
- inc si
- Call READ_AGAIN
- cmp bh,00h ;end of line ?
- je QUIT
- cmp bh,80h
- jb FFF
- and bh,7fh ;clear most sig bit.
- mov ah,ds:[si]
- inc si
- cmp ah,00h ;should we PUTZEROS?
- ja GGGG
- Call PUTZEROS
- jmp DOAGAIN
- GGGG:
- Call PUTONES
- jmp DOAGAIN
- FFF:
- mov ch,0
- mov cl,bh ;CX = BH
- mov bh,1
- LOOPJ:
- mov ah,ds:[si]
- inc si
- Call READ_AGAIN
- cmp ah,00h
- ja IIII
- Call PUTZEROS
- jmp KKKKK
- IIII:
- Call PUTONES
- KKKKK:
- LOOP LOOPJ
- jmp DOAGAIN
- QUIT:
- ret
- PROCESS_A_LINE ENDP
-
- READ_AGAIN proc near
- ;determine if we have read up to
- ;end of 128 byte block. If so
- ;then read the next block
- push di
- lea di,dta2
- cmp si,di
- jb SKIPIT
- Call READ_FILE_BLOCK
- SKIPIT:
- pop di
- ret
- READ_AGAIN endp
-
- READ_FILE_BLOCK PROC NEAR
- PUSH DX
- PUSH AX
- lea dx,fcb
- mov ah,14h
- int 21h
- POP AX
- POP DX
- lea si,dta ;reset si pointer
- RET
- READ_FILE_BLOCK ENDP
-
- PUTONES proc near
- ;enter with number of 1 bits to set
- ;in the BH register, max will be 127
- push ax
- push bx
- push cx
- push dx
- push si
- LOOPBB:
- mov si,CURRENT
- mov dh,0FFh ;mask byte
- mov ah,FREE
- cmp bh,ah
- je CCC
- ja DDD
- ;BH is < FREE
- mov cl,8
- sub cl,ah ;cl = 8 - FREE
- shl dh,cl
- shr dh,cl
- sub ah,bh ;FREE = FREE - bh
- mov FREE,ah
- mov cl,ah
- shr dh,cl
- shl dh,cl
- or byte ptr ds:[si],dh ;set bits
- jmp EXIT
- CCC:
- mov cl,8
- sub cl,ah ;cl = 8 - FREE
- shl dh,cl
- shr dh,cl
- or byte ptr ds:[si],dh ;set bits
- mov FREE,8
- mov ax,CURRENT
- inc ax
- mov CURRENT,ax
- jmp EXIT
- DDD:
- mov cl,8
- sub cl,ah ;cl = 8 - FREE
- shl dh,cl
- shr dh,cl
- or byte ptr ds:[si],dh ;set bits
- sub bh,ah ;BH = BH - FREE
- mov FREE,8
- mov ax,CURRENT
- inc ax
- mov CURRENT,ax
- jmp LOOPBB ;at the top
- EXIT:
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- PUTONES endp
-
- PUTZEROS proc near
- ;enter with number of 0 bits to set
- ;in the BH register, max will be 127
- push ax
- LOOPB:
- mov ah,FREE
- cmp bh,ah
- je AAA
- ja BBB
- sub ah,bh ;FREE = FREE - bh
- mov FREE,ah
- jmp ZZZ ;exit
- AAA:
- mov FREE,8
- mov ax,CURRENT
- inc ax
- mov CURRENT,ax
- jmp ZZZ ;exit
- BBB:
- sub bh,ah
- mov FREE,8
- mov ax,CURRENT
- inc ax
- mov CURRENT,ax
- jmp LOOPB
- ZZZ:
- pop ax
- ret
- PUTZEROS endp
-
- INITIALIZE_LINEBUFF_POINTERS PROC NEAR
- push si
- push ax
- push cx
- mov FREE,8
- lea si,LINEBUFF
- mov CURRENT,si
- ;set all 100 bytes of LINEBUFF to 00
- mov cx,50
- xor ax,ax
- LOOPA:
- mov ds:[si],ax
- inc si
- inc si
- loop LOOPA
- pop cx
- pop ax
- pop si
- ret
- INITIALIZE_LINEBUFF_POINTERS ENDP
-
- ZERO_OUT_FCB PROC NEAR
- push si
- push cx
- push ax
- lea si,zeros
- mov cx,25
- mov al,0
- GLOOP:
- mov [si],al
- inc si
- loop GLOOP
- pop ax
- pop cx
- pop si
- ret
- ZERO_OUT_FCB ENDP
-
- PRINT_MESSAGE PROC NEAR
- push ax
- mov ah,09h
- int 21h
- pop ax
- ret
- PRINT_MESSAGE ENDP
-
- GET_COMMAND_LINE_PARAMETERS proc near
- ;If byte at CS:0080h in PSP = 0
- ;then no filename was specified
- ;on the command line. If name was
- ;specified then DOS has stored it
- ;at CS:005D-0064. We will add EXT
- ;of .CUT ourselves.
- push ax
- push si
- push di
- push cx
- mov al,ds:[0080h]
- cmp al,00h
- je NONAME ;jmp if no filename
- lea si,fcb
- inc si ;si now points to filename
- ;field in file control block
- mov di,005dh ;location of filename
- ;in PSP
- mov cx,8 ;counter
- LOOPUU:
- mov al,ds:[di]
- mov ds:[si],al
- inc si
- inc di
- loop LOOPUU
- stc ;set carry flag
- jmp HASNAME ;filename exists
- NONAME:
- clc ;clear carry flag
- ;no filename given
- HASNAME:
- pop cx
- pop di
- pop si
- pop ax
- ret
- GET_COMMAND_LINE_PARAMETERS endp
-
- CLEAR_WHOLE_SCREEN PROC NEAR
- push ax
- push bx
- push cx
- push dx
- xor al,al
- xor cx,cx
- mov dh,24
- mov dl,79
- mov bh,7
- mov ah,6
- int 10h
- mov dx,0000h
- mov bh,0
- mov ah,2
- int 10h
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- CLEAR_WHOLE_SCREEN ENDP
-
- code_seg ends
- end START
-