home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / LASER / HALO_HPL.ZIP / CUT-HPL.ASM next >
Encoding:
Assembly Source File  |  1988-09-24  |  11.0 KB  |  648 lines

  1. title CUT-HPL_ASM ; 9-24-88
  2. ;AUTHOR: JACK W. GARLAND
  3.  
  4. ;this program will un-arc and
  5. ;print a Dr. Halo II "cut" file
  6. ;on the HP Laser Jet printer.
  7.  
  8. cgroup group code_seg, data_seg
  9. assume cs:cgroup, ds:cgroup
  10.  
  11. code_seg segment public
  12. code_seg ends
  13.  
  14. data_seg segment public
  15.  
  16. PUBLIC DIGIT1
  17. DIGIT1 DB 30H
  18.  
  19. PUBLIC DIGIT2
  20. DIGIT2 DB 31H
  21.  
  22. ;DIGIT1 & DIGIT2 define # of copies
  23. ;to print.
  24. ;default = 01 (30h 31h)
  25. ;you can change this.
  26. ;example 12 copies / change DIGIT1
  27. ;to 31h, change DIGIT2 to 32h
  28.  
  29. public FREE
  30. FREE db 8
  31. ;FREE = number of free bits in
  32. ;CURRENT byte of LINEBUFF.
  33.  
  34. public CURRENT
  35. CURRENT dw ?
  36. ;Pointer to Current work byte in
  37. ;LINEBUFF (bit pack buffer)
  38.  
  39. public LINEBUFF
  40. LINEBUFF db 100 dup(00)
  41. ;100 bytes of data to send to printer
  42. ;printed and set to all 0's after each
  43. ;print pass.
  44.  
  45. public fcb  ;file control block
  46. ;1st byte is drive spec, 0 = default drive
  47. fcb db 00h
  48.     db 20h,20h,20h,20h ;filename
  49.     db 20h,20h,20h,20h ;padded spaces
  50.     db 43h,55h,54h     ;extension .CUT
  51.     ;filename.ext = ????????.CUT
  52. public zeros
  53. zeros    db 00h,00h,00h,00h,00h
  54.          db 00h,00h,00h,00h,00h
  55.          db 00h,00h,00h,00h,00h
  56.          db 00h,00h,00h,00h,00h
  57.          db 00h,00h,00h,00h
  58. public dta
  59. dta db 80h dup(0) ;data transfer area
  60.  
  61. public dta2
  62. dta2 db 90h dup(0) ;trash area used by DOS
  63.  
  64. public MESSA
  65. MESSA DB 0ah,0dh,'You MUST include filename on command line.  Ext. .CUT will be added by program',0ah,0dh,07h,24h
  66.  
  67. public MESSB
  68. MESSB DB 0ah,0dh,'File does not exist in working directory.  File must be in working directory.',0ah,0dh,07h,24h
  69.  
  70. public MESSC
  71. MESSC DB 0ah,0dh,'             Decompressing and Printing.   Press key to abort!',0ah,0dh,24h
  72.  
  73. data_seg ends
  74.  
  75. code_seg segment public
  76. org 100h
  77.  
  78. START proc near
  79.    Call CLEAR_WHOLE_SCREEN
  80.    Call GET_COMMAND_LINE_PARAMETERS
  81. ;on return, carry flag is clear
  82. ;if NO filename was on command line
  83. ;in which case we print MESSA and
  84. ;exit program.
  85.    jc   PROCEED ;jump if carry set
  86.    push dx
  87.    lea  dx,MESSA
  88.    Call PRINT_MESSAGE
  89.    pop  dx
  90.    jmp  QUITX
  91. PROCEED:
  92. ;check to see if file exists.
  93. ;try to open file.
  94.    push dx
  95.    push ax
  96.    lea  dx,fcb
  97.    mov  ah,0fh
  98.    int  21h
  99.    cmp  al,0FFh  ;error flag
  100.    pop  ax
  101.    pop  dx
  102.    jb   CONTINUE
  103. ;file not found.
  104.    push dx
  105.    lea  dx,MESSB
  106.    Call PRINT_MESSAGE
  107.    pop  dx
  108.    jmp  QUITX
  109. CONTINUE:
  110.    Call INITIALIZE_LINEBUFF_POINTERS
  111.    Call INITIALIZE_LASER_JET
  112.    push dx
  113.    lea  dx,MESSC
  114.    Call PRINT_MESSAGE
  115.    pop  dx
  116. ;open file
  117.    Call ZERO_OUT_FCB
  118.    lea  dx,fcb
  119.    mov  ah,0fh
  120.    int  21h
  121. ;set DTA
  122.    lea  dx,dta
  123.    mov  ah,1ah
  124.    int  21h
  125. ;read 1 block (128 bytes)
  126.    Call READ_FILE_BLOCK  ;into DTA
  127.    lea  si,dta
  128.    add  si,6  ;si = si + 6
  129.    mov  cx,1050  ;# of lines to print
  130. RLOOP:
  131.    push cx
  132.    Call PROCESS_A_LINE
  133.    Call PRINT_A_LINE
  134.    Call INITIALIZE_LINEBUFF_POINTERS
  135.    pop  cx
  136. ;check for keypress:
  137. ;if key pressed the exit program
  138. ;after resetting printer
  139.    push ax
  140.    push dx
  141.    mov  ah,6
  142.    mov  dl,0FFh ;input request
  143.    int  21h
  144. ;if no char read, zero flag is set
  145.    pop  dx
  146.    pop  ax
  147.    jnz  BREAKLOOP ;reset prtr & quit
  148.    loop RLOOP
  149. BREAKLOOP:
  150.    Call RESET_LASER_JET
  151. QUITX:
  152.    mov  ax,4c00h
  153.    int  21h  ;exit to DOS
  154. START endp
  155.  
  156. PRINT_A_LINE PROC NEAR
  157. ;the next code string sent
  158. ;tells the printer how many data
  159. ;bytes will be following the command.
  160. ;This must precede each 100 bytes
  161. ;of data.  100 * 8 = 800 bits width.
  162. ;codes to send: (HEX)
  163. ;1b,2a,62,31,30,30,57
  164. ;ec *  b  1  0  0  W
  165.    push ax
  166.    push cx
  167.    push dx
  168.    push si
  169.    mov  cx,100   ;100 byte counter
  170.  
  171.    mov  dl,1bh
  172.    mov  ah,5
  173.    int  21h
  174.  
  175.    mov  dl,2ah
  176.    int  21h
  177.  
  178.    mov  dl,62h
  179.    int  21h
  180.  
  181.    mov  dl,31h
  182.    int  21h
  183.  
  184.    mov  dl,30h
  185.    int  21h
  186.  
  187.    mov  dl,30h
  188.    int  21h
  189.  
  190.    mov  dl,57h
  191.    int  21h
  192.  
  193.    lea  si,LINEBUFF
  194. TTTTT:
  195.    mov  dl,ds:[si]
  196.    inc  si
  197.    int  21h
  198.    loop TTTTT
  199.    pop  si
  200.    pop  dx
  201.    pop  cx
  202.    pop  ax
  203.    ret
  204. PRINT_A_LINE ENDP
  205.  
  206. INITIALIZE_LASER_JET PROC NEAR
  207.    PUSH DX
  208.    PUSH AX
  209. ;set top margin to 0
  210.    mov  dl,1bh
  211.    mov  ah,5
  212.    int  21h
  213.    mov  dl,26h
  214.    int  21h
  215.    mov  dl,6ch
  216.    int  21h
  217.    mov  dl,30h
  218.    int  21h
  219.    mov  dl,45h
  220.    int  21h
  221.  
  222. ;set text length to 66
  223.    mov  dl,1bh
  224.    int  21h
  225.    mov  dl,26h
  226.    int  21h
  227.    mov  dl,6ch
  228.    int  21h
  229.    mov  dl,36h
  230.    int  21h
  231.    mov  dl,36h
  232.    int  21h
  233.    mov  dl,46h
  234.    int  21h
  235.  
  236. ;set number of copies
  237. ;up to 99 can be made.
  238.    mov  dl,1bh
  239.    int  21h
  240.    mov  dl,26h
  241.    int  21h
  242.    mov  dl,6ch
  243.    int  21h
  244.    mov  dl,DIGIT1
  245.    int  21h
  246.    mov  dl,DIGIT2
  247.    int  21h
  248.    mov  dl,58h
  249.    int  21h
  250.  
  251. ;set resolution at 100 DPI
  252. ;hex codes to send:
  253. ;1b,2a,74,31,30,30,52
  254.    mov  dl,1bh
  255.    int  21h
  256.    mov  dl,2ah
  257.    int  21h
  258.    mov  dl,74h
  259.    int  21h
  260.    mov  dl,31h
  261.    int  21h
  262.    mov  dl,30h
  263.    int  21h
  264.    mov  dl,30h
  265.    int  21h
  266.    mov  dl,52h
  267.    int  21h
  268.  
  269. ;set X cursor at X = 000
  270. ;(1.8" @ 300 DPI)
  271. ;codes to send: (HEX)
  272. ;1B,2A,70,30,30,30,58
  273. ;ec *  p  0  0  0  X
  274.    mov  dl,1bh
  275.    int  21h
  276.    mov  dl,2ah
  277.    int  21h
  278.    mov  dl,70h
  279.    int  21h
  280.    mov  dl,30h
  281.    int  21h
  282.    mov  dl,30h
  283.    int  21h
  284.    mov  dl,30h
  285.    int  21h
  286.    mov  dl,58h
  287.    int  21h
  288.  
  289. ;position the cursor Y = 037
  290. ;codes to send: (HEX)
  291. ;1B,2A,70,30,33,37,59
  292. ;ec *  p  0  3  7  Y
  293.    mov  dl,1bh
  294.    int  21h
  295.    mov  dl,2ah
  296.    int  21h
  297.    mov  dl,70h
  298.    int  21h
  299.    mov  dl,30h
  300.    int  21h
  301.    mov  dl,33h
  302.    int  21h
  303.    mov  dl,37h
  304.    int  21h
  305.    mov  dl,59h
  306.    int  21h
  307.  
  308. ;start graphics at left graphics
  309. ;margin.
  310.  
  311. ;codes to send
  312. ;1b,2a,72,30,41  hex
  313.    mov  dl,1bh
  314.    int  21h
  315.    mov  dl,2ah
  316.    int  21h
  317.    mov  dl,72h
  318.    int  21h
  319.    mov  dl,30h
  320.    int  21h
  321.    mov  dl,41h
  322.    int  21h
  323.    POP  AX
  324.    POP  DX
  325.    RET
  326. INITIALIZE_LASER_JET ENDP
  327.  
  328. RESET_LASER_JET PROC NEAR
  329.    push ax
  330.    push dx
  331. ;send END of graphics codes.
  332. ;codes - HEX...
  333. ;1b,2a,72,42
  334.    mov  dl,1bh
  335.    mov  ah,5
  336.    int  21h
  337.  
  338.    mov  dl,2ah
  339.    int  21h
  340.  
  341.    mov  dl,72h
  342.    int  21h
  343.  
  344.    mov  dl,42h
  345.    int  21h
  346.  
  347. ;send EJECT page command.
  348. ;to HP Laser Jet printer.
  349. ;codes hex 1b,26,6c,30,48
  350.    mov  dl,1bh
  351.    int  21h
  352.  
  353.    mov  dl,26h
  354.    int  21h
  355.  
  356.    mov  dl,6ch
  357.    int  21h
  358.  
  359.    mov  dl,30h
  360.    int  21h
  361.  
  362.    mov  dl,48h
  363.    int  21h
  364.  
  365. ;send RESET codes to HP Laser
  366.    mov  dl,1bh
  367.    int  21h
  368.    mov  dl,45h
  369.    int  21h
  370.  
  371.    pop  dx
  372.    pop  ax
  373.    ret
  374. RESET_LASER_JET ENDP
  375.  
  376. PROCESS_A_LINE PROC NEAR
  377.    inc  si
  378.    Call READ_AGAIN
  379.    inc  si ;skip first 2 bytes
  380.            ;of line data (length
  381.            ;of record)
  382. DOAGAIN:
  383.    Call READ_AGAIN
  384.    mov  bh,ds:[si]
  385.    inc  si
  386.    Call READ_AGAIN
  387.    cmp  bh,00h  ;end of line ?
  388.    je   QUIT
  389.    cmp  bh,80h
  390.    jb   FFF
  391.    and  bh,7fh  ;clear most sig bit.
  392.    mov  ah,ds:[si]
  393.    inc  si
  394.    cmp  ah,00h  ;should we PUTZEROS?
  395.    ja   GGGG
  396.    Call PUTZEROS
  397.    jmp  DOAGAIN
  398. GGGG:
  399.    Call PUTONES
  400.    jmp  DOAGAIN
  401. FFF:
  402.    mov  ch,0
  403.    mov  cl,bh  ;CX = BH
  404.    mov  bh,1
  405. LOOPJ:
  406.    mov  ah,ds:[si]
  407.    inc  si
  408.    Call READ_AGAIN
  409.    cmp  ah,00h
  410.    ja   IIII
  411.    Call PUTZEROS
  412.    jmp  KKKKK
  413. IIII:
  414.    Call PUTONES
  415. KKKKK:
  416.    LOOP LOOPJ
  417.    jmp  DOAGAIN
  418. QUIT:
  419.    ret
  420. PROCESS_A_LINE ENDP
  421.  
  422. READ_AGAIN proc near
  423. ;determine if we have read up to
  424. ;end of 128 byte block.  If so
  425. ;then read the next block
  426.    push di
  427.    lea  di,dta2
  428.    cmp  si,di
  429.    jb   SKIPIT
  430.    Call READ_FILE_BLOCK
  431. SKIPIT:
  432.    pop  di
  433.    ret
  434. READ_AGAIN endp
  435.  
  436. READ_FILE_BLOCK PROC NEAR
  437.    PUSH DX
  438.    PUSH AX
  439.    lea  dx,fcb
  440.    mov  ah,14h
  441.    int  21h
  442.    POP  AX
  443.    POP  DX
  444.    lea  si,dta ;reset si pointer
  445.    RET
  446. READ_FILE_BLOCK ENDP
  447.  
  448. PUTONES proc near
  449. ;enter with number of 1 bits to set
  450. ;in the BH register, max will be 127
  451.    push ax
  452.    push bx
  453.    push cx
  454.    push dx
  455.    push si
  456. LOOPBB:
  457.    mov  si,CURRENT
  458.    mov  dh,0FFh  ;mask byte
  459.    mov  ah,FREE
  460.    cmp  bh,ah
  461.    je   CCC
  462.    ja   DDD
  463. ;BH is < FREE
  464.    mov  cl,8
  465.    sub  cl,ah ;cl = 8 - FREE
  466.    shl  dh,cl
  467.    shr  dh,cl
  468.    sub  ah,bh  ;FREE = FREE - bh
  469.    mov  FREE,ah
  470.    mov  cl,ah
  471.    shr  dh,cl
  472.    shl  dh,cl
  473.    or   byte ptr ds:[si],dh ;set bits
  474.    jmp  EXIT
  475. CCC:
  476.    mov  cl,8
  477.    sub  cl,ah ;cl = 8 - FREE
  478.    shl  dh,cl
  479.    shr  dh,cl
  480.    or   byte ptr ds:[si],dh ;set bits
  481.    mov  FREE,8
  482.    mov  ax,CURRENT
  483.    inc  ax
  484.    mov  CURRENT,ax
  485.    jmp  EXIT
  486. DDD:
  487.    mov  cl,8
  488.    sub  cl,ah ;cl = 8 - FREE
  489.    shl  dh,cl
  490.    shr  dh,cl
  491.    or   byte ptr ds:[si],dh ;set bits
  492.    sub  bh,ah  ;BH = BH - FREE
  493.    mov  FREE,8
  494.    mov  ax,CURRENT
  495.    inc  ax
  496.    mov  CURRENT,ax
  497.    jmp  LOOPBB  ;at the top
  498. EXIT:
  499.    pop  si
  500.    pop  dx
  501.    pop  cx
  502.    pop  bx
  503.    pop  ax
  504.    ret
  505. PUTONES endp
  506.  
  507. PUTZEROS proc near
  508. ;enter with number of 0 bits to set
  509. ;in the BH register, max will be 127
  510.    push ax
  511. LOOPB:
  512.    mov  ah,FREE
  513.    cmp  bh,ah
  514.    je   AAA
  515.    ja   BBB
  516.    sub  ah,bh ;FREE = FREE - bh
  517.    mov  FREE,ah
  518.    jmp  ZZZ   ;exit
  519. AAA:
  520.    mov  FREE,8
  521.    mov  ax,CURRENT
  522.    inc  ax
  523.    mov  CURRENT,ax
  524.    jmp  ZZZ   ;exit
  525. BBB:
  526.    sub  bh,ah
  527.    mov  FREE,8
  528.    mov  ax,CURRENT
  529.    inc  ax
  530.    mov  CURRENT,ax
  531.    jmp  LOOPB
  532. ZZZ:
  533.    pop  ax
  534.    ret
  535. PUTZEROS endp
  536.  
  537. INITIALIZE_LINEBUFF_POINTERS PROC NEAR
  538.    push si
  539.    push ax
  540.    push cx
  541.    mov  FREE,8
  542.    lea  si,LINEBUFF
  543.    mov  CURRENT,si
  544. ;set all 100 bytes of LINEBUFF to 00
  545.    mov  cx,50
  546.    xor  ax,ax
  547. LOOPA:
  548.    mov  ds:[si],ax
  549.    inc  si
  550.    inc  si
  551.    loop LOOPA
  552.    pop  cx
  553.    pop  ax
  554.    pop  si
  555.    ret
  556. INITIALIZE_LINEBUFF_POINTERS ENDP
  557.  
  558. ZERO_OUT_FCB PROC NEAR
  559.    push si
  560.    push cx
  561.    push ax
  562.    lea  si,zeros
  563.    mov  cx,25
  564.    mov  al,0
  565. GLOOP:
  566.    mov  [si],al
  567.    inc  si
  568.    loop GLOOP
  569.    pop  ax
  570.    pop  cx
  571.    pop  si
  572.    ret
  573. ZERO_OUT_FCB ENDP
  574.  
  575. PRINT_MESSAGE PROC NEAR
  576.    push ax
  577.    mov  ah,09h
  578.    int  21h
  579.    pop  ax
  580.    ret
  581. PRINT_MESSAGE ENDP
  582.  
  583. GET_COMMAND_LINE_PARAMETERS proc near
  584. ;If byte at CS:0080h in PSP = 0
  585. ;then no filename was specified
  586. ;on the command line.  If name was
  587. ;specified then DOS has stored it
  588. ;at CS:005D-0064.  We will add EXT
  589. ;of .CUT ourselves.
  590.    push ax
  591.    push si
  592.    push di
  593.    push cx
  594.    mov  al,ds:[0080h]
  595.    cmp  al,00h
  596.    je   NONAME    ;jmp if no filename
  597.    lea  si,fcb
  598.    inc  si   ;si now points to filename
  599.              ;field in file control block
  600.    mov  di,005dh  ;location of filename
  601.                   ;in PSP
  602.    mov  cx,8      ;counter
  603. LOOPUU:
  604.    mov  al,ds:[di]
  605.    mov  ds:[si],al
  606.    inc  si
  607.    inc  di
  608.    loop LOOPUU
  609.    stc              ;set carry flag
  610.    jmp  HASNAME     ;filename exists
  611. NONAME:
  612.    clc              ;clear carry flag
  613.                     ;no filename given
  614. HASNAME:
  615.    pop  cx
  616.    pop  di
  617.    pop  si
  618.    pop  ax
  619.    ret
  620. GET_COMMAND_LINE_PARAMETERS endp
  621.  
  622. CLEAR_WHOLE_SCREEN PROC NEAR
  623.    push ax
  624.    push bx
  625.    push cx
  626.    push dx
  627.    xor  al,al
  628.    xor  cx,cx
  629.    mov  dh,24
  630.    mov  dl,79
  631.    mov  bh,7
  632.    mov  ah,6
  633.    int  10h
  634.    mov  dx,0000h
  635.    mov  bh,0
  636.    mov  ah,2
  637.    int  10h
  638.    pop  dx
  639.    pop  cx
  640.    pop  bx
  641.    pop  ax
  642.    ret
  643. CLEAR_WHOLE_SCREEN ENDP
  644.  
  645. code_seg ends
  646. end START
  647.  
  648.