home *** CD-ROM | disk | FTP | other *** search
-
- TITLE Printer Initialise
- SUBTTL Version 1.2
-
- .COMMENT *
- Printer initialisation program by Chris Bellingham.
- Started 8th July, 1982.
- One of a suite of utility programs written for Z80 based machines.
- Completed 11th July 1982
- Small bug cleared 7/8/82. (PI14 included)
-
- Adapted to allow on-line HELP and lower case commands by
- Mick Waters. 14/2/86.
- *
- .Z80
- ASEG
- ORG 100H
-
- ;program equates
- NULL EQU 00H
- BEL EQU 07H
- HT EQU 09H
- LF EQU 0AH
- VT EQU 0BH
- FF EQU 0CH
- CR EQU 0DH
- SO EQU 0EH
- SI EQU 0FH
- DC1 EQU 11H
- DC2 EQU 12H
- DC3 EQU 13H
- DC4 EQU 14H
- CAN EQU 18H
- ESC EQU 1BH
- DEL EQU 7FH
-
- WCON EQU 02H
- CTRLZ EQU 1AH
- PBUFF EQU 09H
- RBUFF EQU 0AH
- WLIST EQU 05H
- OPEN$ EQU 0FH
- CLOSE$ EQU 10H
- READ$ EQU 14H
- BOOT EQU 0000H
- DOSENT EQU 0005H
- DBUFF EQU 0080H
- DFCB EQU 005CH
- DFCB2 EQU 006CH
- NREC EQU 007CH
- ;end of equates
- PAGE 60
-
- ;start of code
-
- JP START
-
- ;stack space
- DEFS 30
- STACK: DEFS 2
-
- ;Epson MX80 initialisation codes
- TABLE1: DEFM "NUL"
- DEFB NULL
- DEFM "BEL"
- DEFB BEL
- DEFM "HT "
- DEFB HT
- DEFM "LF "
- DEFB LF
- DEFM "VT "
- DEFB VT
- DEFM "FF "
- DEFB FF
- DEFM "CR "
- DEFB CR
- DEFM "SO "
- DEFB SO
- DEFM "SI "
- DEFB SI
- DEFM "DC1"
- DEFB DC1
- DEFM "DC2"
- DEFB DC2
- DEFM "DC3"
- DEFB DC3
- DEFM "DC4"
- DEFB DC4
- DEFM "CAN"
- DEFB CAN
- DEFM "ESC"
- DEFB ESC
- DEFM "DEL"
- DEFB DEL
-
- ;messages
- RDERR$: DEFM "** READ ERROR **"
- CRLF$: DEFB CR, LF, "$"
-
- UNOP$: DEFM "** UNABLE TO OPEN FILE **"
- DEFB CR, LF, "$"
-
- ;Signon message
- SIGNON: DEFB "Printer Initialise Version 1.2",CR,LF
- DEFB "Copyright (C) 1982 C.C. Bellingham",CR,LF
- DEFB " Donated to the Public Domain for",CR,LF
- DEFB " non-commercial use only.",CR,LF,LF,"$"
-
- ;On-Line HELP message
- HELPM: DEFB "Usage:",CR,LF
- DEFB " PI <D:FILENAME.TYP where:",CR,LF,LF
- DEFB " D: is an optional drive letter",CR,LF
- DEFB " FILENAME.TYP is a text file containing the command line"
- DEFB CR,LF,LF
- DEFB " PI command line where:",CR,LF,LF
- DEFB " command line is a series of printer control codes",CR,LF
- DEFB " in the following format:",CR,LF
- DEFB " Any of NUL, BEL, HT, VT, FF, CR, LF, SO, SI,",CR,LF
- DEFB " DC1, DC2, DC3, DC4, CAN, ESC, DEL",CR,LF
- DEFB " A number in either HEX or Decimal. Hex prefixed by '#'"
- DEFB CR,LF
- DEFB " A control character in CP/M style. ie. '^G' = Ctrl G"
- DEFB CR,LF,LF
- DEFB "See PI.DOC for details.",CR,LF,LF,"$"
-
- ;** main code begins
- START: LD HL,0
- ADD HL,SP
- LD (STACK),HL
- LD SP,STACK
-
- ; Print signon message
- LD DE,SIGNON
- LD C,PBUFF
- CALL DOSENT
-
- ;get linelength
- LD HL,DBUFF
- ST1: LD A,(HL)
- LD B,A
-
- ;put a space at the end
- PUSH HL
- ADD A,L
- LD L,A
- INC HL
- LD (HL)," "
- POP HL
- LD A,B
-
- ;if zero then print help message
- OR A
- JR NZ,PI10
-
- ; Drop into internal command mode
- LD E,"*"
- LD C,WCON
- CALL DOSENT
- LD HL,DBUFF
- PUSH HL
- LD (HL),80
- INC HL
- LD (HL),0
- POP DE
- LD C,RBUFF
- CALL DOSENT
- LD DE,CRLF$
- LD C,PBUFF
- CALL DOSENT
- LD HL,DBUFF+1
- LD A,(HL)
- OR A
- JR NZ,ST1
- EXIT: LD HL,(STACK)
- LD SP,HL
- RET
-
- ;ignore leading spaces
- PI10: INC HL
- LD A,(HL)
- CP " "
- JR NZ,PI11
- DJNZ PI10
-
- ;check for help request
- PI11: CP "/"
- JR NZ,PI12
-
- ;print help message
- LD DE,HELPM
- LD C,PBUFF
- CALL DOSENT
- JR EXIT
-
- ;check for file indicator
- PI12: CP "<"
- JR NZ,PI13
- CALL RDFILE
-
- PI13: DEC HL
-
- ;LST: init loop
- PI14: CALL GETCH
-
- ;ignore spaces
- CP " "
- JR Z,PI20
-
- LD C,WLIST
- PUSH BC
- PUSH HL
- LD E,A
- CALL DOSENT
- POP HL
- POP BC
- PI20: DJNZ PI14
-
- ;all done return to CP/M
- JR EXIT
-
-
-
- ;*****************
- ;** SUBROUTINES **
- ;*****************
-
- ;get character for output
- GETCH: INC HL
- LD A,(HL)
- CALL LO2UP
-
- ;do explicit control characters
- CP "^"
- JR NZ,ESCAPE
-
- ;check for next char
- DEC B
- LD A,B
- OR A
- JR Z,EXIT
-
- ;get char and convert to control char
- INC HL
- LD A,(HL)
- CALL LO2UP
- XOR 40H
- RET
-
- ;check for explicit escape char
- ESCAPE: CP "!"
- JR NZ,NULCH
- LD A,ESC
- RET
-
- ;check for explicit null
- NULCH: CP "."
- JR NZ,CTRLCH
- XOR A
- RET
-
- ;anything less than 20H is a control char
- CTRLCH: CP " "
- RET C
-
- ;check for string
- CP 22H ;inverted commas
- JR NZ,HNUM
-
- ;loop until end of string
- LD C,WLIST
- STR10: INC HL
- DJNZ STR20
- JR EXIT
-
- STR20: LD A,(HL)
- CP 22H ;end of string?
- JR Z,STREND
-
- ;write to LST:
- PUSH BC
- PUSH HL
- LD E,A
- CALL DOSENT
- POP HL
- POP BC
- JR STR10
-
- STREND: LD A," "
- RET
-
-
- ;check for HEX number
- HNUM: CP "#"
- JR Z,HEX
-
- ;check for decimal number
- CALL NUMCHK
- LD C,0
- JP C,DEC
-
- ;deal with MX80 codes
- CALL MXCDS
- RET
-
-
- ;save pointer and counter
- MXCDS: PUSH BC
-
- ;get first char
- MX30: PUSH HL
- LD A,(HL)
- CALL LO2UP
-
- ;16 entries in table
- LD B,16
- LD HL,TABLE1
-
- ;first character
- MX40: CP (HL)
- JR Z,MX60
-
- ;frig in case second char doesn't match
- PUSH HL
- MX50: POP HL
-
- ;get first char again
- POP DE
- PUSH DE
- LD A,(DE)
- CALL LO2UP
-
- ;get next entry
- LD DE,04
- ADD HL,DE
- DJNZ MX40
-
- ;not in table
- POP HL
- POP BC
- LD A,(HL)
- CALL LO2UP
- RET
-
- ;second char
- MX60: POP DE
- PUSH DE
- PUSH HL
- INC HL
- INC DE
- LD A,(DE)
- CALL LO2UP
- CP (HL)
- JR NZ,MX50
-
- ;third char
- INC HL
- INC DE
- LD A,(DE)
- CALL LO2UP
- CP (HL)
- JR NZ,MX50
-
- ;valid name, get code
- INC HL
- LD A,(HL)
- CALL LO2UP
-
- ;get pointer for next char
- EX DE,HL
-
- ;clear stack
- POP DE
- POP DE
-
- ;get counter
- POP BC
- DEC B
- DEC B
-
- ;is it zero?
- PUSH AF
- LD A,B
- OR A
- JR NZ,MX70
- INC B
- MX70: POP AF
- RET
-
- ;get a hex number from input line
- HEX: LD A,B
-
- ;check if # was the last char on line
- CP 01
- JR NZ,HEX10
- HEX5: LD A,(HL)
- CALL LO2UP
- RET
-
- ;convert first digit
- HEX10: CALL HEX45
- JR C,HEX20
-
- ;first digit not hex
- DEC HL
- INC B
- JR HEX5
-
- ;convert second digit
- HEX20: PUSH AF
- CALL HEX45
- JR NC,HEX30
-
- ;add two digits together
- LD E,A
- POP AF
- SLA A
- SLA A
- SLA A
- SLA A
- ADD A,E
- RET
-
- ;second digit not hex
- HEX30: DEC HL
- INC B
- POP AF
- RET
-
- ;get next digit and convert to hex
- HEX45: DEC B
- INC HL
-
- ;get first ASCII byte
- LD A,(HL)
- CALL LO2UP
- CALL NUMCHK
- JR NC,HEX50
-
- ;convert to hex
- AND 0FH
- JR HEX53
-
- ;check for A - F
- HEX50: CALL HEXCHK
- JR NC,HEX55
-
- ;convert to hex
- AND 0FH
- ADD A,09
-
- ;return with carry set
- HEX53: SCF
-
- ;or with carry reset
- HEX55: RET
-
-
- ;convert to binary value and add last
- DEC: AND 0FH
- ADD A,C
-
- ;check next char
- LD C,A
- INC HL
- LD A,(HL)
- CALL LO2UP
- CALL NUMCHK
- JR NC,DECDN
- LD A,C
-
- ;multiply by 10
- ADD A,A
- LD C,A
- ADD A,A
- ADD A,A
- ADD A,C
-
- ;save and move to next char
- LD C,A
- LD A,(HL)
- CALL LO2UP
- DJNZ DEC
-
- ;last char reached
- INC B
- DECDN: LD A,C
- RET
-
- ;read 1 record from disk
- ;copy filename
- RDFILE: DJNZ FN10
- JP UNOP
-
- ;ignore leading spaces
- FN10: INC HL
- LD A,(HL)
- CP " "
- JR Z,RDFILE
-
- ;drive initially default
- LD DE,DFCB
- XOR A
- LD (DE),A
-
- ;check for drive name
- INC HL
- LD A,(HL)
- DEC HL
- CP ":"
- JR NZ,FN30
-
- ;get drive name
- LD A,(HL)
- AND 0FH
- LD (DE),A
- INC HL
- INC HL
-
- ;get filename
- FN30: LD B,9
- FN31: INC DE
- LD A,(HL)
- CALL LO2UP ; Convert to upper case
- INC HL
-
- ;if period then pad rest and do ext
- CP "."
- JR Z,FNSPC
-
- ;if space pad rest and ext
- CP " "
- JR Z,FILL5
- LD (DE),A
- DJNZ FN31
-
- ;bad filename
- JP UNOP
-
- ;pad filename with spaces
- FNSPC: DJNZ SPCS
- JR FEXT
- SPCS: LD A," "
- LD (DE),A
- INC DE
- JR FNSPC
-
- ;get extension
- FEXT: LD B,4
- FX10: LD A,(HL)
- INC HL
-
- ;if space then pad rest
- CP " "
- JR Z,FILL10
- LD (DE),A
- INC DE
- DJNZ FX10
- JR GETFIL
-
- ;add length of ext
- FILL5: LD A,B
- ADD A,3
- LD B,A
-
- ;pad to end with spaces
- FILL10: LD A," "
- FILL15: DJNZ FILL20
- JR GETFIL
- FILL20: LD (DE),A
- INC DE
- JR FILL15
-
-
- ;open file
- GETFIL: LD DE,DFCB
- LD C,OPEN$
- PUSH DE
- CALL DOSENT
- POP DE
-
- ;open
- CP 0FFH
- JR Z,UNOP
-
- ;read record
- XOR A
- LD (NREC),A
- LD C,READ$
- PUSH DE
- CALL DOSENT
- POP DE
-
- ;read ok?
- CP 00
- JR NZ,RDERR
-
- ;move i/p record
- PUSH DE
- LD DE,BUFF
- LD HL,80H
- LD BC,80H
- LDIR
-
- ;close file
- POP DE
- LD C,CLOSE$
- CALL DOSENT
-
- ;find end of text
- LD B,80H
- LD C,0
- LD E,C
- LD HL,BUFF
- RD10: LD A,(HL)
- CP CTRLZ
- JR Z,RD20
-
- ;convert incoming file to upper case ignoring items in quotes
- CP 22H
- JR NZ,RD11
- PUSH AF
- LD A,E
- XOR 1 ; Flip bit 0 of E as a flag
- LD E,A
- POP AF
- RD11: BIT 0,E ; Test whether between quotes
- CALL Z,LO2UP
- LD (HL),A
- INC C
- INC HL
- DJNZ RD10
-
- RD20: LD (HL)," "
- LD B,C
- LD HL,BUFF
- RET
-
- RDERR: LD DE,RDERR$
- JR PMESS
-
- UNOP: LD DE,UNOP$
- PMESS: LD C,PBUFF
- CALL DOSENT
- JP BOOT
-
- ;convert lower to upper case
- LO2UP: CP "a"
- RET C
- CP "z"+1
- RET NC
- AND 5FH
- RET
-
- ;check for number
- NUMCHK: CP "9"+1
- RET NC
- CP "0"
- CCF
- RET
-
- HEXCHK: CP "F"+1
- RET NC
- CP "A"
- CCF
- RET
-
- BUFF:
-
- END
-
- r number
- NUMCHK: CP "9"+1
- RET NC
- CP "0"
- CCF
- RET
-
- H