home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
BEEHIVE
/
COMMS
/
ZMP-OV16.ARC
/
ZMO-PW05.Z80
< prev
next >
Wrap
Text File
|
1991-02-02
|
17KB
|
761 lines
;-----------------------------------------------------------------------
; Amstrad PCW8000 Overlay for ZMP (Z-Modem Program) Jul 6, 89
;
; Name ZMO-PW05.Z80
;
; Dated Jul 6, 1989
;
; Modified from ZMP-BLNK.Z80 by Nigel Dallard
;
; NOTE: As supplied in the ZMP15.LBR library, ZMP-BLNK.Z80
; would not assemble with M80. M80 objected to the hyphen in the
; filename, and to the labels WAITHLS and WAITHLMS which it
; thought were the same label. To enable M80 to assemble the file
; the name should be changed. The offending labels have been changed
; to WAITSHL and WAITMSHL.
; The conditional assembly portion at the end of the file was also
; removed since it included a call to a non-existant label. This
; does not affect the program assuming the code is within the
; specified size limitation.
; The code as supplied did not initialise the serial port on entry.
; The routine USERIN is used to call the INIT routine part way
; through to cure this.
;
; * EXPLANATORY NOTE: this file uses BDOS calls to access the PCW
; hardware. Amstrad CP/M-80 version 1.4 (current) is said to have
; interrupt buffering which helps to overcome the "lost character"
; problem at 2400 baud. Apparently Amstrad did this without much
; if any publicity..... Up-grade to 1.4 if you can find a copy.
; The direct command "ESC-0" can be used to disable the status
; line; this also speeds up screen handling.... Try it.
; The overlay also handles split baud rates as used in UK;
; 1200 RX 75 TX or vice-versa. Ignore if you don't need this.
; Sorry; this file does NOT work on the CPC 6128 machine, (why ?)
; John Crux 17 March 1990 *
;
;-----------------------------------------------------------------------
;
; System-dependent code overlay for ZMODEM
;
; Assemble as follows:
;
; M80 =ZMOPW05
; RELHEX ZMOPW05
; MLOAD ZMP.COM=ZMPX.COM,ZMOPW05.HEX
; * or ZASM ZMO-PW05 HEX; MLOAD as before (Cromemco ZASM works OK) *
; * or ZSM ZMO-PW05; MLOAD as before *
; (Don't use L80 without changing the source for assembly as a CSEG
; file.)
;
;-----------------------------------------------------------------------
;
; Notes on modifying this file:
;
; C requires that functions do not change either index register (IX
; or IY). If your overlay requires either of these to be changed, ensure
; they are restored to the original values on return.
;
; An inline print routine is provided for printing strings in the usual
; way, usage is:
;
; CALL PRINT
; DB 'required string',0
;
;-----------------------------------------------------------------------
;
; Don't forget to set your clock speed at the clkspd variable.
;
;-----------------------------------------------------------------------
;
NO EQU 0
YES EQU NOT NO
;
;
; User-set variables:
;
CLKSPD EQU 4 ; Processor clock speed in MHz
DEBUG EQU NO ; To allow debugging of overlay with
; ; Z8E etc.
;
;
; Set the following two equates to the drive and user area which will
; contain ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set
; both to zero (null) to locate them on the drive from which ZMP was
; invoked.
;
OVERDRIVE EQU 0 ; Drive to find overlay files on ('A'-'P')
OVERUSER EQU 0 ; User area to find files
;
;-----------------------------------------------------------------------
;
; NOT user-set variables
;
USERDEF EQU 0145H ; Origin of this overlay. This address
; ; should not change with subsequent
; ; revisions.
MSPEED EQU 03CH ; Location of current baud rate
OVSIZE EQU 0400H ; Maximum size of this overlay
;
; .Z80 ; Use Z80 code (for M80)
;
; ASEG ; Absolute (for M80)
;
;
IF DEBUG
ORG 100H ; So you can debug it with CEBUG, ZSID, etc.
ELSE
ORG USERDEF
ENDIF
;
ESC EQU 1BH
CTRLQ EQU 11H
CR EQU 0DH
LF EQU 0AH
BDOS EQU 5
;
;-----------------------------------------------------------------------
;
;Jump table for the overlay: do NOT change this
;
JUMPTAB:JP SCRNPR ; Screen print
JP MRD ; Modem read with timeout
JP MCHIN ; Get a character from modem
JP MCHOUT ; Send a character to the modem
JP MORDY ; Test for tx buffer empty
JP MIRDY ; Test for character received
JP SNDBRK ; Send break
JP CURSADD ; Cursor addressing
JP CLS ; Clear screen
JP INVON ; Inverse video on
JP INVOFF ; Inverse video off
JP HIDE ; Hide cursor
JP SHOW ; Show cursor
JP SAVECU ; Save cursor position
JP RESCU ; Restore cursor position
JP MINT ; Service modem interrupt
JP INVEC ; Initialise interrupt vectors
JP DINVEC ; De-initialise interrupt vectors
JP MDMERR ; Test uart flags for error
JP DTRON ; Turn DTR on
JP DTROFF ; Turn DTR OFF
JP INIT ; Initialise uart
JP WAIT ; Wait seconds
JP MSWAIT ; Wait milliseconds
JP USERIN ; User-defined entry routine
JP USEROUT ; User-defined exit routine
JP GETVARS ; Get system variables
JP SETPORT ; Set the modem port being used
;
; Spare jumps for compatibility with future versions
;
JP SPARE ; Spare for later use
JP SPARE ; Spare for later use
JP SPARE ; Spare for later use
JP SPARE ; Spare for later use
JP SPARE ; Spare for later use
JP SPARE ; Spare for later use
;
;-----------------------------------------------------------------------
;
; Main code starts here
;
; Screen print function
;
SCRNPR: PUSH AF ; save registers
PUSH BC
PUSH DE
PUSH HL
CALL PRINT ; print message
DB CR,LF,'Press <EXTRA>+<PTR> for a screen dump.',CR,LF,0
POP HL ; restore registers
POP DE
POP BC
POP AF
;
SPARE: RET
;
; User-defined entry routine: used by ND to initialise UART on entry
;
USERIN: CALL INIT2
RET
;
; User-defined exit routine: leave empty if not needed
;
USEROUT:RET
;
; Get a character from the modem: return in HL
;
MCHIN: PUSH BC
;
; <== Start of user-defined code
;
PUSH DE ; save all unused registers
PUSH IX
PUSH IY
LD C,3 ; use BDOS to get a character from AUXIN:
CALL BDOS ; and put it in A
POP IY ; restore registers
POP IX
POP DE
;
; <== End of user-defined code
;
LD L,A ; Put in HL
LD H,0
OR A ; Set/clear Z
POP BC
RET
;
; Send a character to the modem
;
MCHOUT: LD HL,2 ; Get the character
ADD HL,SP
LD A,(HL)
;
; <== Start of user-defined code
;
PUSH BC ; save unused registers
PUSH DE
PUSH IX
PUSH IY
LD E,A ; move character to E
LD C,4 ; let BDOS pass the character to AUXOUT:
CALL BDOS
POP IY ; restore registers
POP IX
POP DE
POP BC
;
; <== End of user-defined code
;
RET ; Done
;
; Test for output ready: return TRUE (1) in HL if ok
;
MORDY: DS 0
;
; <== Start of user-defined code
;
PUSH BC ; save registers
PUSH DE
PUSH IX
PUSH IY
LD C,8 ; ask BDOS if AUXOUT: is ready
CALL BDOS ; BDOS returns with A=FFh if so
LD H,0 ; set HL accordingly
AND 1
LD L,A
POP IY ;restore registers
POP IX
POP DE
POP BC
;
; <== End of user-defined code
; ; NB next 2 lines commented out by ND 6/7/89
LD A,L ; Set/clear Z
OR A
RET
;
; Test for character at modem: return TRUE (1) in HL if so
;
MIRDY: DS 0
;
; <== Start of user-defined code
;
PUSH BC ; save registers
PUSH DE
PUSH IX
PUSH IY
LD C,7 ; ask BDOS if AUXIN: is ready
CALL BDOS ; BDOS returns A=FFh if so
LD H,0 ; set HL accordingly
AND 1
LD L,A
POP IY ; restore registers
POP IX
POP DE
POP BC
;
; <== End of user-defined code
; ; NB next 2 lines commented out by ND 6/7/89
LD A,L ; Set/clear Z
OR A
RET
;
; Send a break to the modem: leave empty if your system can't do it
;
SNDBRK: DS 0
;
; <== Start of user-defined code
;
; The PCW BDOS/BIOS doesn't allow you to send a BREAK.
; (except by directly driving the hardware....)
; <== End of user-defined code
;
RET
;
; Test UART flags for error: return TRUE (1) in HL if error.
;
MDMERR: DS 0
;
; <== Start of user-defined code
;
LD HL,0 ; Serial errors are dealt with by BDOS
;
; <== End of user-defined code
;
LD A,L ; Set/clear Z
OR A
RET
;
;
; Turn DTR ON
;
DTRON: DS 0
;
; <== Start of user-defined code
;
PUSH AF ; save registers
PUSH BC
PUSH DE
PUSH HL
PUSH IX
PUSH IY
LD A,80H ; ask the BIOS to drop DTR
CALL SIOSET
POP IY ; restore registers
POP IX
POP HL
POP DE
POP BC
POP AF
;
; <== End of user-defined code
;
RET
;
;
; Turn DTR OFF
;
DTROFF: DS 0
;
; <== Start of user-defined code
;
PUSH AF ; save registers
PUSH BC
PUSH DE
PUSH HL
PUSH IX
PUSH IY
LD A,7FH ; ask BIOS to raise DTR
CALL SIOSET
POP IY ; restore registers
POP IX
POP HL
POP DE
POP BC
POP AF
;
; <== End of user-defined code
;
RET
;
; Initialise the uart
;
INIT: LD HL,2 ; Get parameters
ADD HL,SP
EX DE,HL
CALL GETPARM ; In HL
LD (BRATE),HL ; Baud rate
CALL GETPARM
LD (PARITY),HL ; Parity
CALL GETPARM
LD (DATA),HL ; Data bits (BINARY 7 or 8)
CALL GETPARM
LD (STOP),HL ; Stop bits (BINARY 1 or 2)
;
; <== Start of user-defined code
;
; LD (MSPEED),A ; Don't forget to load mspeed with the
; ; Current BRATE value if the new rate
; ; is valid. See table of values below.
;
INIT2: PUSH AF ; save registers
PUSH BC
PUSH DE
PUSH HL
PUSH IX
PUSH IY
LD HL,(1) ; get address of WBOOT entry in BIOS jump table
LD DE,87 ; calculate the address of the USERF entry
ADD HL,DE
LD (PARMS+1),HL ; modify the jump instruction at PARMS
LD HL,(BRATE) ; HL = baud-rate code
ADD HL,HL ; double it
LD BC,BRTBL ; BC = base of baud-rate look-up table
ADD HL,BC ; HL points to entry in look-up table
LD E,(HL) ; E = encoded tx baud rate
INC HL
LD D,(HL) ; D = encoded rx baud rate
LD A,E ; encoded tx baud rate of 0 => not supported
OR A
JR NZ,SETBD ; if not supported, print message & leave
CALL PRINT ; baud rate set as present.
DB 'Baud Rate not supported.',CR,LF,0
JR CHKPAR
SETBD: EX DE,HL ; HL = encoded baud-rates
CALL BAUD ; let BIOS set the baud-rate
LD A,(BRATE) ; adjust the ZMP modem speed variable
LD (MSPEED),A
JR CHKPAR ; go on to set the rest of the uart parameters
BRTBL: DB 03H,03H ; 110 baud
DB 06H,06H ; 300 baud
DB 08H,02H ; 450 baud [ actually used for 7512 ]
DB 07H,07H ; 600 baud
DB 02H,08H ; 710 baud [ actually used for 1275 ]
DB 08H,08H ; 1200 baud
DB 0AH,0AH ; 2400 baud
DB 0CH,0CH ; 4800 baud
DB 0EH,0EH ; 9600 baud
DB 0FH,0FH ; 19200 baud
DB 00H,00H ; 38400 baud
DB 00H,00H ; 57600 baud
DB 00H,00H ; 76800 baud
CHKPAR: LD A,(PARITY) ; A = parity value
CP 'N'
JR NZ,NOTNONE
LD E,0 ; no parity => E = 0
JR CHKDATA
NOTNONE:CP 'O'
JR NZ,NOTODD
LD E,1 ; odd parity => E = 1
JR CHKDATA
NOTODD: LD E,2 ; even parity => E = 2
CHKDATA:LD A,(DATA) ; A = number of data bits
LD H,A ; H = rx data bits
LD L,A ; L = tx data bits
LD A,(STOP) ; A = number of stop bits
CP 1
JR NZ,STOP2
LD D,0 ; 1 stop bit => D = 0
JR SETSIO
STOP2: LD D,2 ; 2 stop bits => D = 2
SETSIO: LD A,0FEH ; sio mode = interrupt, no handshake
CALL SIOSET ; let BIOS set up the sio port
POP IY ; restore registers
POP IX
POP HL
POP DE
POP BC
POP AF
RET
BAUD: CALL PARMS ; set the baud rate
DW 00B9H ; via extended BIOS function B9h
RET
SIOSET: CALL PARMS ; set the sio parameters
DW 00B6H ; via extended BIOS function B6h
RET
PARMS: JP 0 ; BIOS entry point to set sio parameters
; and baud rate. The code self-modifies
; itself to provide the correct address.
;
; <== End of user-defined code
; ; NB the next line was commented out by ND 6/7/89
; RET
;
;-----------------------------------------------------------------------
;
STOP: DW 1 ; Stop bits
PARITY: DW 'N' ; Parity
DATA: DW 8 ; Data bits
BRATE: DW 6 ; Baud rate:
;
;-----------------------------------------------------------------------
;
; Values of BRATE for each baud rate
;
; baud rate BRATE
;
; 110 0
; 300 1
; 450 2
; 600 3
; 710 4
; 1200 5
; 2400 6
; 4800 7
; 9600 8
; 19200 9
; 38400 10
; 57600 11
; 76800 12
;
;-----------------------------------------------------------------------
;
; Set the port. ZMP supplies either 0 or 1 as a parameter. If you only
; have one UART port, or if you don't want to go through all the hassles
; just have this routine returning with no changes made. Note that ZMP
; calls this routine twice -- once for each port value -- on
; initialisation.
;
SETPORT:LD HL,2 ; Get port number
ADD HL,SP
EX DE,HL
CALL GETPARM ; In HL (values are 0 and 1)
;
; <== Start of user defined code
;
; Only one serial port on the PCW.
;
; <== End of user defined code
;
RET
;
PORT: DS 1
;-----------------------------------------------------------------------
;
; Video terminal sequences: these are for Amstrad PCW8000 series
;
; Cursor addressing:
;
CURSADD:LD HL,2 ; Get parameters
ADD HL,SP
EX DE,HL
CALL GETPARM ; In HL
LD (ROW),HL ; Row
CALL GETPARM
LD (COL),HL ; Column
;
; <== Start of user-defined code
;
CALL PRINT
DB ESC,'Y',0 ; leadin
LD A,(ROW) ; Row first
ADD A,' ' ; Add offset
CALL COUT
LD A,(COL) ; Same for column
ADD A,' '
CALL COUT
;
; <== End of user-defined code
;
RET
;
ROW: DS 2 ; Row
COL: DS 2 ; Column
;
; Clear screen
;
CLS: CALL PRINT
DB ESC,'E',ESC,'H',0
RET
;
; Inverse video on
;
INVON: CALL PRINT
DB ESC,'p',0
RET
;
; Inverse video off
;
INVOFF: CALL PRINT
DB ESC,'q',0
RET
;
;Turn off cursor
;
HIDE: CALL PRINT
DB ESC,'f',0
RET
;
; Turn on cursor
;
SHOW: CALL PRINT
DB ESC,'e',0
RET
;
; Save cursor position
;
SAVECU: CALL PRINT
DB ESC,'j',0
RET
;
; Restore cursor position
;
RESCU: CALL PRINT
DB ESC,'k',0
RET
;
;-----------------------------------------------------------------------
;
; Service modem interrupt
;
MINT: RET ; My system doesn't need this
;
; Initialise interrupt vectors
;
INVEC: RET ; Ditto
;
; De-initialise interrupt vectors
;
DINVEC: RET ; Ditto
;
;------------------ end of user-defined code ---------------------------
; do not change anything below here
;
; Modem character test for 100 ms
;
MRD: PUSH BC ; Save BC
LD BC,100 ; Set limit
;
MRD1: CALL MIRDY ; Char at modem?
JR NZ,MRD2 ; Yes, exit
LD HL,1 ; Else wait 1ms
CALL WAITMSHL
DEC BC ; Loop till done
LD A,B
OR C
JR NZ,MRD1
LD HL,0 ; None there, result=0
XOR A
;
MRD2: POP BC
RET
;
; Inline print routine: destroys A and HL
;
PRINT: EX (SP),HL ; Get address of string
;
PLOOP: LD A,(HL) ; Get next
INC HL ; Bump pointer
OR A ; Done if zero
JR Z,PDONE
CALL COUT ; Else print
JR PLOOP ; And loop
;
PDONE: EX (SP),HL ; Restore return address
RET ; And quit
;
; Output a character in A to the console
;
COUT: PUSH BC ; Save registers
PUSH DE
PUSH HL
LD E,A ; Character to E
LD C,2
CALL BDOS ; Print it
POP HL
POP DE
POP BC
RET
;
; Wait(seconds)
;
WAIT: LD HL,2
ADD HL,SP
EX DE,HL ; Get delay size
CALL GETPARM
; ; Fall thru to..
;Wait seconds in HL
;
WAITSHL:PUSH BC ; Save BC
PUSH DE ; DE
PUSH IX ; And IX
LD IX,0 ; Then point IX to 0
; So we don't upset memory-mapped I/O
;
; Calculate values for loop constants. Need to have two loops to avoid
; 16-bit overflow with clock speeds above 9 MHz.
;
OUTERVAL EQU (CLKSPD/10)+1
INNERVAL EQU (6667/OUTERVAL)*CLKSPD
;
WAIT10: LD B,OUTERVAL
;
WAIT11: LD DE,INNERVAL
;
WAIT12: BIT 0,(IX) ; Time-wasters
BIT 0,(IX)
BIT 0,(IX) ; 20 T-states each
BIT 0,(IX)
BIT 0,(IX)
BIT 0,(IX)
DEC DE
LD A,E
LD A,D
OR E
JR NZ,WAIT12 ; 150 T-states per inner loop
DJNZ WAIT11 ; Decrement outer loop
DEC HL ; Ok, decrement count in hl
LD A,H
OR L
JR NZ,WAIT10
POP IX ; Done -- restore ix
POP DE ; De
POP BC ; And bc
RET
;
; Wait milliseconds
;
MSWAIT: LD HL,2
ADD HL,SP
EX DE,HL ; Get delay size
CALL GETPARM
; ; Fall thru to..
; Wait milliseconds in HL
;
WAITMSHL:PUSH DE
;
W1MS0: LD DE,39*CLKSPD
;
W1MS1: DEC DE
LD A,D
OR E
JR NZ,W1MS1
DEC HL
LD A,H
OR L
JR NZ,W1MS0
POP DE
RET
;
; Get next parameter from (DE) into HL
;
GETPARM:EX DE,HL ; Get address into HL
LD E,(HL) ; Get LOW
INC HL
LD D,(HL) ; Then HIGH
INC HL ; Bump for next
EX DE,HL ; Result in hl, address still in de
RET
;
; Get address of user-defined variables
;
GETVARS:LD HL,USERVARS
RET
;
USERVARS:
DW OVERDRIVE ; OVR etc. drive/user
DW OVERUSER
;
;
END
L
JR NZ,WAIT10
POP IX ; Done -- restore ix
POP DE ; De
POP BC ; And bc
RET
;
; Wait milli