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-C802.Z80
< prev
next >
Wrap
Text File
|
1991-02-02
|
14KB
|
669 lines
;-----------------------------------------------------------------------------
;
; Overlay for ZMP (Z-Modem Program)
;
; Name ZMO-C802.Z80
;
; Dated October 4, 1988
;
; Written by -
; Ron Murray, c/o Z-Node 62, 061-9-450-0200, Perth, Western Australia.
; Modified for the Commodore 128 by Ron Murray
; Modified to v1.4 standard rjm 11/12/88
;
;
; Rename subsequent versions as ZMO-C8xx.Z80 etc
;
;
; This overlay is set up for a Commodore 128 running CP/M+. Modem
; routines are based on Irv Hoff's IMP overlay for the 128.
;
;
;-----------------------------------------------------------------------------
;
;
; System-dependent code overlay for ZMODEM
;
;
;
; Insert your own code as necessary in this file. Code contained herein
; has been written in Z80 code for use with M80 or SLR. Assemble as follows:
;
; SLR ZMO-C801/h
; MLOAD ZMP.COM=ZMODEM.COM,ZMO-C801.HEX
; or
; M80 =ZMO-C801.Z80
; RELHEX ZMO-C801
; MLOAD ZMP.COM=ZMODEM.COM,ZMO-C801.HEX
;
;
; (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), nor the BC register pair. If your overlay requires any of
; these to be changed, ensure they are restored to the original values
; on return.
; Since collecting parameters from C functions can be tricky, only change
; the parts marked 'Insert your own code here'. Do NOT modify the jump
; table at the start. Do NOT modify the entry/exit sections of each
; function. Do NOT pass 'GO'. Do NOT collect $200.
; Apart from defining modem functions, this file also defines terminal
; characteristics. Most have been set up for ADM-3A (with a few of my own
; additions). Modify to suit your own terminal. 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.
;
;
; If you find your overlay exceeds the maximum size (currently 0400h),
; you will have to contact me for another version. If too many people need
; to do it, we haven't allowed enough room.
;
; Ron Murray 15/8/88
;
;
;
;
false equ 0
true equ not false
; User-set variables: ***********
;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 'A' ; Drive to find overlay files on ('A'-'P')
overuser equ 0 ; User area to find files
clkspd equ 2 ; Processor clock speed in MHz
debug equ false
;Don't change the following three equates!!
userdef equ 00145h ; origin of this overlay
; This address may change with subsequent
; revisions.
mspeed equ 003ch ; place to store baud rate id to allow
; re-entry as per IMP. This MUST be the same
; as that set in ZMP
ovsize equ 0400h ; max size of this overlay
.z80 ; use z80 code
aseg ; absolute
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
; C128 specific equates ***************************************************
port equ 6
XxDconfig equ 0fd4eh
rs232_stat equ XxDconfig+1
xmit_data equ XxDconfig+2
recv_data equ XxDconfig+3
mdrcv equ 01h ; Modem receive ready
mdsndb equ 80h ; bit to test for send
mdsndr equ 00h ; value when send ready
d2pra equ 0dd00h ; cia #2: rs-232 tx data etc
d2prb equ d2pra+1 ; cia #2: rs-232 status/data bits
; ******************************************
;
; Main code starts here
;
codebgn equ $
;Jump table for the overlay: do NOT change this
jump_tab:
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
; 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
;
;Screen print function
scrnpr:
; <== Insert your own code here
call print
db 'This function not supported.',cr,lf,0
; <== End of your own code
spare:
ret
; User-defined entry routine: leave empty if not needed
userin:
ret
; User-defined exit routine: leave empty if not needed
userout:
ret
;Get a character from the modem: return in HL
mchin:
push bc
; <== Insert your own code here
ld a,(recv_data) ; get the data byte
ld hl,rs232_stat
res 0,(hl) ; reset bit 0 of status byte
; <== End of your own 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)
; <== Insert your own code here
ld (xmit_data),a ; store it
ld hl,rs232_stat ; and set the bit
set 7,(hl)
; <== End of your own code
ret ; done
;Test for output ready: return TRUE (1) in HL if ok
mordy:
; <== Insert your own code here
ld hl,0 ; assume not ready
ld a,(rs232_stat) ; get status byte
and mdsndb
cp mdsndr ; if bit ready,
jr nz,mordy1
inc hl ; bump hl
mordy1:
; <== End of your own code
ld a,l ; set/clear Z
or a
ret
;Test for character at modem: return TRUE (1) in HL if so
mirdy:
; <== Insert your own code here
ld hl,0
ld a,(rs232_stat) ; get status byte
and mdrcv ; mask off rx bit
cp mdrcv ; if ok,
jr nz,mirdy1
inc hl ; hl = 1
mirdy1:
; <== End of your own code
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:
; <== Insert your own code here
push bc
ld bc,d2pra
in a,(c) ; get current value of port
push af ; save it
xor 04h ; toggle TxD
out (c),a
ld hl,300
call waithlms ; wait 300 mS
pop af ; restore original value
ld bc,d2pra
out (c),a
pop bc
; <== End of your own code
ret
;
;Test UART flags for error: return TRUE (1) in HL if error.
mdmerr:
; <== Insert your own code here
ld hl,1 ; assume none
ld a,(rs232_stat) ; get status byte
and 018h ; mask off unwanted bits
jr z,mdmerr1
dec hl ; ok, we got some
mdmerr1:
; <== End of your own code
ld a,l ; set/clear Z
or a
ret
;Turn DTR ON
dtron:
; <== Insert your own code here
push bc
ld bc,d2prb ; get rs-232 bits
in a,(c)
or 6 ; set DTR and RTS
out (c),a
pop bc
; <== End of your own code
ret
;Turn DTR OFF
dtroff:
; <== Insert your own code here
push bc
ld bc,d2prb ; get rs-232 bits
in a,(c)
and 0f9h ; drop DTR and RTS
out (c),a
pop bc
; <== End of your own code
ret
;Initialise the (fake) 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
call getparm
ld (stop),hl ; stop bits
; <== Insert your own code here
; using values below
push bc
ld a,(parity) ; get parity ID
ld c,0 ; assume none
cp 'N' ; which is what we have if N
jr z,setpar
ld c,0c0h ; ok, assume even
cp 'E'
jr z,setpar ; yep, that's it
ld c,0e0h ; no, odd
setpar:
ld a,(data) ; test data bits
and 0fh ; (never sure if ASCII or binary!)
cp 7 ; if not 7,
jr z,setstop
inc c ; bump C
setstop:
ld a,(stop) ; now do stop bits
and 0fh
cp 2 ; if 2,
jr nz,setpars
inc c ; add 2
inc c
setpars:
ld a,c ; store it
ld (XxDconfig),a
ld a,(brate) ; get baud rate
ld c,a
ld b,0 ; in bc
ld hl,brval ; add to base
add hl,bc
ld a,(hl) ; and get divisor
or a ; don't do if zero
jr z,setpar1
push af ; ok, save for now
ld a,c
ld (mspeed),a ; save the baud rate in 3C for later as per IMP
ld hl,(0001) ; get BIOS address
ld de,57
add hl,de
call dopchl ; get address of char dev tbl
ld de,port*8+7 ; offset to rs-232 baud rate
add hl,de ; address in hl
pop af ; restore divisor
ld (hl),a ; store it
ld hl,(0001) ; get BIOS address
ld de,60 ; get port init address
add hl,de
ld c,port
call dopchl ; initialise
setpar1:
pop bc
; <== End of your own code
ret
dopchl:
jp (hl)
;--------------------------------------------------------------------------
stop: dw 1 ; stop bits
parity: dw 'N' ; parity
data: dw 8 ; data bits
brate: dw 7 ; baud rate:
;--------------------------------------------------------------------------
;Values for fake 6551 control reg for each baud rate
; Note that only rates up to 1200 will work in a C128
brval:
db 3 ; 110 0
db 6 ; 300 1
db 0 ; 450 2
db 7 ; 600 3
db 0 ; 710 4
db 8 ; 1200 5
db 9 ; 2400 6 .. you never know ..
db 0 ; 4800 7
db 0 ; 9600 8
db 0 ; 19200 9
db 0 ; 38400 10
db 0 ; 57600 11
db 0 ; 76800 12
;****************************************************************************
;Video terminal sequences: these are for ADM-3A: Modify as you wish
;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
; <== Insert your own code here
; using values in row and col
call print
db esc,'=',0 ; ADM-3A leadin
ld a,(row) ; row first
add a,' ' ; add offset
call cout
ld a,(col) ; sane for column
add a,' '
call cout
; <== end of your own code
ret
row: ds 2 ; row
col: ds 2 ; column
;Clear screen:
cls:
call print
db 01ah,0
ret
;Inverse video on:
invon:
call print
db esc,'G4',0
ret
;Inverse video off:
invoff:
call print
db esc,'G0',0
ret
;Turn off cursor:
hide:
ret
;Turn on cursor:
show:
ret
;Save cursor position:
savecu:
ret
;Restore cursor position:
rescu:
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 waithlms
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 regs
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
waithls:
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
waithlms:
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 lo
inc hl
ld d,(hl) ; then hi
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
if ($ - codebgn) gt ovsize
toobig: jp errval ; Overlay too large!
endif
end