home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / pi12.lbr / PI.MZC / PI.MAC
Encoding:
Text File  |  1993-10-25  |  8.9 KB  |  678 lines

  1.  
  2.     TITLE Printer Initialise
  3.     SUBTTL Version 1.2
  4.  
  5.     .COMMENT *
  6.     Printer initialisation program by Chris Bellingham.
  7.     Started 8th July, 1982.
  8.     One of a suite of utility programs written for Z80 based machines.
  9.     Completed 11th July 1982
  10.     Small bug cleared 7/8/82. (PI14 included)
  11.  
  12.     Adapted to allow on-line HELP and lower case commands by
  13.     Mick Waters. 14/2/86.
  14.     *
  15.     .Z80
  16.     ASEG
  17.     ORG 100H
  18.  
  19.     ;program equates
  20. NULL    EQU    00H
  21. BEL    EQU    07H
  22. HT    EQU    09H
  23. LF    EQU    0AH
  24. VT    EQU    0BH
  25. FF    EQU    0CH
  26. CR    EQU    0DH
  27. SO    EQU    0EH
  28. SI    EQU    0FH
  29. DC1    EQU    11H
  30. DC2    EQU    12H
  31. DC3    EQU    13H
  32. DC4    EQU    14H
  33. CAN    EQU    18H
  34. ESC    EQU    1BH
  35. DEL    EQU    7FH
  36.  
  37. WCON    EQU    02H
  38. CTRLZ    EQU    1AH
  39. PBUFF    EQU    09H
  40. RBUFF    EQU    0AH
  41. WLIST    EQU    05H
  42. OPEN$    EQU    0FH
  43. CLOSE$    EQU    10H
  44. READ$    EQU    14H
  45. BOOT    EQU    0000H
  46. DOSENT    EQU    0005H
  47. DBUFF    EQU    0080H
  48. DFCB    EQU    005CH
  49. DFCB2    EQU    006CH
  50. NREC    EQU    007CH
  51.     ;end of equates
  52.     PAGE 60
  53.  
  54.     ;start of code
  55.  
  56.     JP START
  57.  
  58.     ;stack space
  59.     DEFS 30
  60. STACK:    DEFS 2
  61.  
  62.     ;Epson MX80 initialisation codes
  63. TABLE1:    DEFM "NUL"
  64.     DEFB NULL
  65.     DEFM "BEL"
  66.     DEFB BEL
  67.     DEFM "HT "
  68.     DEFB HT
  69.     DEFM "LF "
  70.     DEFB LF
  71.     DEFM "VT "
  72.     DEFB VT
  73.     DEFM "FF "
  74.     DEFB FF
  75.     DEFM "CR "
  76.     DEFB CR
  77.     DEFM "SO "
  78.     DEFB SO
  79.     DEFM "SI "
  80.     DEFB SI
  81.     DEFM "DC1"
  82.     DEFB DC1
  83.     DEFM "DC2"
  84.     DEFB DC2
  85.     DEFM "DC3"
  86.     DEFB DC3
  87.     DEFM "DC4"
  88.     DEFB DC4
  89.     DEFM "CAN"
  90.     DEFB CAN
  91.     DEFM "ESC"
  92.     DEFB ESC
  93.     DEFM "DEL"
  94.     DEFB DEL
  95.  
  96.     ;messages
  97. RDERR$:    DEFM "** READ ERROR **"
  98. CRLF$:    DEFB CR, LF, "$"
  99.  
  100. UNOP$:    DEFM "** UNABLE TO OPEN FILE **"
  101.     DEFB CR, LF, "$"
  102.  
  103.     ;Signon message
  104. SIGNON:    DEFB "Printer Initialise Version 1.2",CR,LF
  105.     DEFB "Copyright (C) 1982 C.C. Bellingham",CR,LF
  106.     DEFB "  Donated to the Public Domain for",CR,LF
  107.     DEFB "  non-commercial use only.",CR,LF,LF,"$"
  108.  
  109.     ;On-Line HELP message
  110. HELPM:    DEFB "Usage:",CR,LF
  111.     DEFB "  PI <D:FILENAME.TYP where:",CR,LF,LF
  112.     DEFB "      D:           is an optional drive letter",CR,LF
  113.     DEFB "      FILENAME.TYP is a text file containing the command line"
  114.     DEFB CR,LF,LF
  115.     DEFB "  PI command line  where:",CR,LF,LF
  116.     DEFB "      command line is a series of printer control codes",CR,LF
  117.     DEFB "      in the following format:",CR,LF
  118.     DEFB "      Any of NUL, BEL, HT, VT, FF, CR, LF, SO, SI,",CR,LF
  119.     DEFB "             DC1, DC2, DC3, DC4, CAN, ESC, DEL",CR,LF
  120.     DEFB "      A number in either HEX or Decimal. Hex prefixed by '#'"
  121.     DEFB CR,LF
  122.     DEFB "      A control character in CP/M style. ie. '^G' = Ctrl G"
  123.     DEFB CR,LF,LF
  124.     DEFB "See PI.DOC for details.",CR,LF,LF,"$"
  125.  
  126.     ;** main code begins
  127. START:    LD HL,0
  128.     ADD HL,SP
  129.     LD (STACK),HL
  130.     LD SP,STACK
  131.  
  132.     ; Print signon message
  133.     LD DE,SIGNON
  134.     LD C,PBUFF
  135.     CALL DOSENT
  136.  
  137.     ;get linelength
  138.     LD HL,DBUFF
  139. ST1:    LD A,(HL)
  140.     LD B,A
  141.  
  142.     ;put a space at the end
  143.     PUSH HL
  144.     ADD A,L
  145.     LD L,A
  146.     INC HL
  147.     LD (HL)," "
  148.     POP HL
  149.     LD A,B
  150.  
  151.     ;if zero then print help message
  152.     OR A
  153.     JR NZ,PI10
  154.  
  155.     ; Drop into internal command mode
  156.     LD E,"*"
  157.     LD C,WCON
  158.     CALL DOSENT
  159.     LD HL,DBUFF
  160.     PUSH HL
  161.     LD (HL),80
  162.     INC HL
  163.     LD (HL),0
  164.     POP DE
  165.     LD C,RBUFF
  166.     CALL DOSENT
  167.     LD DE,CRLF$
  168.     LD C,PBUFF
  169.     CALL DOSENT
  170.     LD HL,DBUFF+1
  171.     LD A,(HL)
  172.     OR A
  173.     JR NZ,ST1
  174. EXIT:    LD HL,(STACK)
  175.     LD SP,HL
  176.     RET
  177.  
  178.     ;ignore leading spaces
  179. PI10:    INC HL
  180.     LD A,(HL)
  181.     CP " "
  182.     JR NZ,PI11
  183.     DJNZ PI10
  184.  
  185.     ;check for help request
  186. PI11:    CP "/"
  187.     JR NZ,PI12
  188.  
  189.     ;print help message
  190.     LD DE,HELPM
  191.     LD C,PBUFF
  192.     CALL DOSENT
  193.     JR EXIT
  194.  
  195.     ;check for file indicator
  196. PI12:    CP "<"
  197.     JR NZ,PI13
  198.     CALL RDFILE
  199.  
  200. PI13:    DEC HL
  201.  
  202.     ;LST: init loop
  203. PI14:    CALL GETCH
  204.  
  205.     ;ignore spaces
  206.     CP " "
  207.     JR Z,PI20
  208.  
  209.     LD C,WLIST
  210.     PUSH BC
  211.     PUSH HL
  212.     LD E,A
  213.     CALL DOSENT
  214.     POP HL
  215.     POP BC
  216. PI20:    DJNZ PI14
  217.  
  218.     ;all done return to CP/M
  219.     JR EXIT
  220.  
  221.  
  222.  
  223.     ;*****************
  224.     ;** SUBROUTINES **
  225.     ;*****************
  226.  
  227.     ;get character for output
  228. GETCH:    INC HL
  229.     LD A,(HL)
  230.     CALL LO2UP
  231.  
  232.     ;do explicit control characters
  233.     CP "^"
  234.     JR NZ,ESCAPE
  235.  
  236.     ;check for next char
  237.     DEC B
  238.     LD A,B
  239.     OR A
  240.     JR Z,EXIT
  241.  
  242.     ;get char and convert to control char
  243.     INC HL
  244.     LD A,(HL)
  245.     CALL LO2UP
  246.     XOR 40H
  247.     RET
  248.  
  249.     ;check for explicit escape char
  250. ESCAPE:    CP "!"
  251.     JR NZ,NULCH
  252.     LD A,ESC
  253.     RET
  254.  
  255.     ;check for explicit null
  256. NULCH:    CP "."
  257.     JR NZ,CTRLCH
  258.     XOR A
  259.     RET
  260.  
  261.     ;anything less than 20H is a control char
  262. CTRLCH:    CP " "
  263.     RET C
  264.  
  265.     ;check for string
  266.     CP 22H    ;inverted commas
  267.     JR NZ,HNUM
  268.  
  269.     ;loop until end of string
  270.     LD C,WLIST
  271. STR10:    INC HL
  272.     DJNZ STR20
  273.     JR EXIT
  274.  
  275. STR20:    LD A,(HL)
  276.     CP 22H    ;end of string?
  277.     JR Z,STREND
  278.  
  279.     ;write to LST:
  280.     PUSH BC
  281.     PUSH HL
  282.     LD E,A
  283.     CALL DOSENT
  284.     POP HL
  285.     POP BC
  286.     JR STR10
  287.  
  288. STREND:    LD A," "
  289.     RET
  290.  
  291.  
  292.     ;check for HEX number
  293. HNUM:    CP "#"
  294.     JR Z,HEX
  295.  
  296.     ;check for decimal number
  297.     CALL NUMCHK
  298.     LD C,0
  299.     JP C,DEC
  300.  
  301.     ;deal with MX80 codes
  302.     CALL MXCDS
  303.     RET
  304.  
  305.  
  306.     ;save pointer and counter
  307. MXCDS:    PUSH BC
  308.  
  309.     ;get first char
  310. MX30:    PUSH HL
  311.     LD A,(HL)
  312.     CALL LO2UP
  313.  
  314.     ;16 entries in table
  315.     LD B,16
  316.     LD HL,TABLE1
  317.  
  318.     ;first character
  319. MX40:    CP (HL)
  320.     JR Z,MX60
  321.  
  322.     ;frig in case second char doesn't match
  323.     PUSH HL
  324. MX50:    POP HL
  325.  
  326.     ;get first char again
  327.     POP DE
  328.     PUSH DE
  329.     LD A,(DE)
  330.     CALL LO2UP
  331.  
  332.     ;get next entry
  333.     LD DE,04
  334.     ADD HL,DE
  335.     DJNZ MX40
  336.  
  337.     ;not in table
  338.     POP HL
  339.     POP BC
  340.     LD A,(HL)
  341.     CALL LO2UP
  342.     RET
  343.  
  344.     ;second char
  345. MX60:    POP DE
  346.     PUSH DE
  347.     PUSH HL
  348.     INC HL
  349.     INC DE
  350.     LD A,(DE)
  351.     CALL LO2UP
  352.     CP (HL)
  353.     JR NZ,MX50
  354.  
  355.     ;third char
  356.     INC HL
  357.     INC DE
  358.     LD A,(DE)
  359.     CALL LO2UP
  360.     CP (HL)
  361.     JR NZ,MX50
  362.  
  363.     ;valid name, get code
  364.     INC HL
  365.     LD A,(HL)
  366.     CALL LO2UP
  367.  
  368.     ;get pointer for next char
  369.     EX DE,HL
  370.  
  371.     ;clear stack
  372.     POP DE
  373.     POP DE
  374.  
  375.     ;get counter
  376.     POP BC
  377.     DEC B
  378.     DEC B
  379.  
  380.     ;is it zero?
  381.     PUSH AF
  382.     LD A,B
  383.     OR A
  384.     JR NZ,MX70
  385.     INC B
  386. MX70:    POP AF
  387.     RET
  388.  
  389.     ;get a hex number from input line
  390. HEX:    LD A,B
  391.  
  392.     ;check if # was the last char on line
  393.     CP 01
  394.     JR NZ,HEX10
  395. HEX5:    LD A,(HL)
  396.     CALL LO2UP
  397.     RET
  398.  
  399.     ;convert first digit
  400. HEX10:    CALL HEX45
  401.     JR C,HEX20
  402.  
  403.     ;first digit not hex
  404.     DEC HL
  405.     INC B
  406.     JR HEX5
  407.  
  408.     ;convert second digit
  409. HEX20:    PUSH AF
  410.     CALL HEX45
  411.     JR NC,HEX30
  412.  
  413.     ;add two digits together
  414.     LD E,A
  415.     POP AF
  416.     SLA A
  417.     SLA A
  418.     SLA A
  419.     SLA A
  420.     ADD A,E
  421.     RET
  422.  
  423.     ;second digit not hex
  424. HEX30:    DEC HL
  425.     INC B
  426.     POP AF
  427.     RET
  428.  
  429.     ;get next digit and convert to hex
  430. HEX45:    DEC B
  431.     INC HL
  432.  
  433.     ;get first ASCII byte
  434.     LD A,(HL)
  435.     CALL LO2UP
  436.     CALL NUMCHK
  437.     JR NC,HEX50
  438.  
  439.     ;convert to hex
  440.     AND 0FH
  441.     JR HEX53
  442.  
  443.     ;check for A - F
  444. HEX50:    CALL HEXCHK
  445.     JR NC,HEX55
  446.  
  447.     ;convert to hex
  448.     AND 0FH
  449.     ADD A,09
  450.  
  451.     ;return with carry set
  452. HEX53:    SCF
  453.  
  454.     ;or with carry reset
  455. HEX55:    RET
  456.  
  457.  
  458.     ;convert to binary value and add last
  459. DEC:    AND 0FH
  460.     ADD A,C
  461.  
  462.     ;check next char
  463.     LD C,A
  464.     INC HL
  465.     LD A,(HL)
  466.     CALL LO2UP
  467.     CALL NUMCHK
  468.     JR NC,DECDN
  469.     LD A,C
  470.  
  471.     ;multiply by 10
  472.     ADD A,A
  473.     LD C,A
  474.     ADD A,A
  475.     ADD A,A
  476.     ADD A,C
  477.  
  478.     ;save and move to next char
  479.     LD C,A
  480.     LD A,(HL)
  481.     CALL LO2UP
  482.     DJNZ DEC
  483.  
  484.     ;last char reached
  485.     INC B
  486. DECDN:    LD A,C
  487.     RET
  488.  
  489.     ;read 1 record from disk
  490.     ;copy filename
  491. RDFILE:    DJNZ FN10
  492.     JP UNOP
  493.  
  494.     ;ignore leading spaces
  495. FN10:    INC HL
  496.     LD A,(HL)
  497.     CP " "
  498.     JR Z,RDFILE
  499.  
  500.     ;drive initially default
  501.     LD DE,DFCB
  502.     XOR A
  503.     LD (DE),A
  504.  
  505.     ;check for drive name
  506.     INC HL
  507.     LD A,(HL)
  508.     DEC HL
  509.     CP ":"
  510.     JR NZ,FN30
  511.  
  512.     ;get drive name
  513.     LD A,(HL)
  514.     AND 0FH
  515.     LD (DE),A
  516.     INC HL
  517.     INC HL
  518.  
  519.     ;get filename
  520. FN30:    LD B,9
  521. FN31:    INC DE
  522.     LD A,(HL)
  523.     CALL LO2UP    ; Convert to upper case
  524.     INC HL
  525.  
  526.     ;if period then pad rest and do ext
  527.     CP "."
  528.     JR Z,FNSPC
  529.  
  530.     ;if space pad rest and ext
  531.     CP " "
  532.     JR Z,FILL5
  533.     LD (DE),A
  534.     DJNZ FN31
  535.  
  536.     ;bad filename
  537.     JP UNOP
  538.  
  539.     ;pad filename with spaces
  540. FNSPC:    DJNZ SPCS
  541.     JR FEXT
  542. SPCS:    LD A," "
  543.     LD (DE),A
  544.     INC DE
  545.     JR FNSPC
  546.  
  547.     ;get extension
  548. FEXT:    LD B,4
  549. FX10:    LD A,(HL)
  550.     INC HL
  551.  
  552.     ;if space then pad rest
  553.     CP " "
  554.     JR Z,FILL10
  555.     LD (DE),A
  556.     INC DE
  557.     DJNZ FX10
  558.     JR GETFIL
  559.  
  560.     ;add length of ext
  561. FILL5:    LD A,B
  562.     ADD A,3
  563.     LD B,A
  564.  
  565.     ;pad to end with spaces
  566. FILL10:    LD A," "
  567. FILL15:    DJNZ FILL20
  568.     JR GETFIL
  569. FILL20:    LD (DE),A
  570.     INC DE
  571.     JR FILL15
  572.  
  573.  
  574.     ;open file
  575. GETFIL:    LD DE,DFCB
  576.     LD C,OPEN$
  577.     PUSH DE
  578.     CALL DOSENT
  579.     POP DE
  580.  
  581.     ;open
  582.     CP 0FFH
  583.     JR Z,UNOP
  584.  
  585.     ;read record
  586.     XOR A
  587.     LD (NREC),A
  588.     LD C,READ$
  589.     PUSH DE
  590.     CALL DOSENT
  591.     POP DE
  592.  
  593.     ;read ok?
  594.     CP 00
  595.     JR NZ,RDERR
  596.  
  597.     ;move i/p record
  598.     PUSH DE
  599.     LD DE,BUFF
  600.     LD HL,80H
  601.     LD BC,80H
  602.     LDIR
  603.  
  604.     ;close file
  605.     POP DE
  606.     LD C,CLOSE$
  607.     CALL DOSENT
  608.  
  609.     ;find end of text
  610.     LD B,80H
  611.     LD C,0
  612.     LD E,C
  613.     LD HL,BUFF
  614. RD10:    LD A,(HL)
  615.     CP CTRLZ
  616.     JR Z,RD20
  617.  
  618.     ;convert incoming file to upper case ignoring items in quotes
  619.     CP 22H
  620.     JR NZ,RD11
  621.     PUSH AF
  622.     LD A,E
  623.     XOR 1        ; Flip bit 0 of E as a flag
  624.     LD E,A
  625.     POP AF
  626. RD11:    BIT 0,E        ; Test whether between quotes
  627.     CALL Z,LO2UP
  628.     LD (HL),A
  629.     INC C
  630.     INC HL
  631.     DJNZ RD10
  632.  
  633. RD20:    LD (HL)," "
  634.     LD B,C
  635.     LD HL,BUFF
  636.     RET
  637.  
  638. RDERR:    LD DE,RDERR$
  639.     JR PMESS
  640.  
  641. UNOP:    LD DE,UNOP$
  642. PMESS:    LD C,PBUFF
  643.     CALL DOSENT
  644.     JP BOOT
  645.  
  646.     ;convert lower to upper case
  647. LO2UP:    CP "a"
  648.     RET C
  649.     CP "z"+1
  650.     RET NC
  651.     AND 5FH
  652.     RET
  653.  
  654.     ;check for number
  655. NUMCHK:    CP "9"+1
  656.     RET NC
  657.     CP "0"
  658.     CCF
  659.     RET
  660.  
  661. HEXCHK:    CP "F"+1
  662.     RET NC
  663.     CP "A"
  664.     CCF
  665.     RET
  666.  
  667. BUFF:
  668.  
  669.     END
  670.  
  671. r number
  672. NUMCHK:    CP "9"+1
  673.     RET NC
  674.     CP "0"
  675.     CCF
  676.     RET
  677.  
  678. H