home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
archives
/
trs80model2.zip
/
trssend.mac
< prev
next >
Wrap
Text File
|
1997-03-26
|
11KB
|
277 lines
title ksend/mac sending unit
cseg
;
;
extrn recptr,recbuf,rplus,mjump
extrn spaket,rpaket,screen
extrn rplus,sinit,state,byte,n,r
extrn rpack,spack,abort,acsum,flush
extrn fcb,writnx,open,rinit,close
extrn lrecl,readnx,buffil,filnam,tstack
public s_init,s_file,s_open,s_break
public s_data,s_eof
;
len equ 0
seq equ 1
type equ 2
data equ 3
quote equ '#'
_a equ 1
_c equ 2
_r equ 3
_rf equ 4
_rd equ 5
_s equ 6
_sf equ 7
_sd equ 8
_se equ 9
_sb equ 10
_o equ 11
;
;
subttl macros used in this module
;
;prmes to display messages
;
prmes macro lab
.xlist
extrn m_&lab,l_&lab
push hl
push bc
ld hl,m_&lab
ld bc,(l_&lab)
ld c,13
ld a,9
rst 8
pop bc
pop hl
.list
endm
;movb
;
movb macro value,loc
.xlist
push af
ld a,value
ld (loc),a
pop af
.list
endm
;
;blmov
;
blmov macro source,dest,len
.xlist
local $1,$2
push hl
push bc
push de
ld hl,source
ld de,dest
ld a,(len)
cp 0
jr nz,$1
ld b,1
ld c,0
jp $2
$1:
ld b,0
ld c,a
$2:
ldir
pop de
pop bc
pop hl
.list
endm
;
;fack to format an ack paket
;
f_ack macro
.xlist
ld (iy+len),3
ld a,(n)
add a,' '
ld (iy+seq),a
ld (iy+type),'Y'
ld hl,spaket
call acsum
.list
endm
;
;nplus
;
nplus macro
.xlist
ld hl,n
inc (hl)
res 6,(hl)
movb 0,r
.list
endm
;
subttl open file (pseudo-state, precedes send_init)
page
;
; open file
;
s_open:
call open ;open file (assume fcb set)
movb _s,state ;state = send_init
movb 0,n ;packet number to 0
movb 0,r ;reset retry count
call flush ;clear comm buffers
jp mjump ;and back
subttl send initialisation routine
page
;
; send init parameters
;
s_init:
ld ix,rpaket
ld iy,spaket
ld (iy+len),12 ;length of init packet
ld (iy+type),'S' ;type send init
ld a,(n) ;current packet number
add a,' ' ;make printable
ld (iy+seq),a ;into packet
movb 12,byte ;number of bytes to move
blmov rinit,spaket+data,byte
ld hl,spaket ;to point correctly
call acsum ;compute checksum
call spack ;and send packet
ld a,(hl) ;get paket length and fix it
sub ' ' ;because there might be a retry
ld (hl),a ;save back
call rpack ;get answer
jp c,rplus ;no good
call tstack ;was it a good ack ?
jp c,rplus ;no, send it again
blmov rpaket+data,sinit,byte
;move parameters to keep
ld hl,sinit+4 ;address of eol
res 5,(hl) ;sub 32 to get real eol
ld hl,sinit ;maxlen to send
res 5,(hl) ;sub 32
nplus ;increment packet count
movb _sf,state ;state = send file header
jp mjump ;and back
subttl send file header information
page
;
; send file header
;
s_file:
ld hl,filnam+1 ;where the filame start
ld a,(filnam) ;it's length
ld b,a ;store len in b
ld a,'/' ;byte to look for
s1:
cp (hl) ;is this a '/' ?
jp z,s2 ;yes change it t '.'
inc hl ;advance pointer
djnz s1 ;and check next byte
jp s3 ;there was no '/'
s2:
ld a,'.' ;a dot to normalize filename
ld (hl),a ;in place
s3:
ld (iy+type),'F' ;of type file header
ld a,(n) ;get packet count
add a,' ' ;make printable
ld (iy+seq),a ;insert in spacket
blmov filnam+1,spaket+data,filnam
;put in filename
ld a,(filnam) ;get filename length
add a,3 ;add len,seq,type
ld (iy+len),a ;set in spacket
ld hl,spaket ;hl to point correctly
call acsum ;compute checksum
call spack ;send it
ld a,(hl) ;get paket length and fix it
sub ' ' ;because there might be a retry
ld (hl),a ;save back in spaket
call rpack ;get answer
jp c,rplus ;no good
call tstack ;was it a good ack ?
jp c,rplus ;no
nplus ;update packet count
call buffil ;get a bufferfull
jp c,s_eof ;it was the end of file
movb _sd,state ;state = send_data
jp mjump ;return
subttl send data from file
page
;
; send data
;
s_data:
ld (iy+type),'D' ;data packet
ld a,(n) ;packet number
add a,' ' ;make printable
ld (iy+seq),a ;into packet
ld hl,spaket ;hl point correctly
call acsum ;compute checksum
call spack ;send it
ld a,(hl) ;get length to fix it in case
sub ' ' ; of a bad ack
ld (hl),a ;save back in spaket
call rpack ;get answer
jp c,rplus ;no good
call tstack ;a good ack ?
jp c,rplus ;nope...
nplus ;yes, update packet count
call buffil ;get next packet ready
jp c,s_eof ;we reach the eof
jp mjump ;and back
subttl send end of file
page
;
; send end of file
;
s_eof:
movb _se,state ;might not be done
ld (iy+type),'Z' ;eof in spacket
ld (iy+len),3 ;length
ld a,(n) ;packet number
add a,' ' ;make printable
ld (iy+seq),a ;into packet
ld hl,spaket ;to point correctly
call acsum ;compute checksum
call spack ;send packet
ld a,(hl) ;get paket length
sub ' ' ;and fix it
ld (hl),a ;back in spaket
call rpack ;get answer
jp c,rplus ;no good
call tstack ;test for good ack
jp c,rplus ;no good
nplus ;good, update packet count
movb _sb,state ;state = break transmission
jp mjump ;and back
subttl send break transmission
page
;
; send break transmission
;
s_break:
ld (iy+type),'B' ;in spaket, set type
ld (iy+len),3 ;and length
ld a,(n) ;current packet number
add a,' ' ;make printable
ld (iy+seq),a ;store in spaket
ld hl,spaket ;hl to point correctly
call acsum ;compute checksum
call spack ;send packet
ld a,(hl) ;get paket length and fix it
sub ' ' ;there might be a retry
ld (hl),a ;save back in spaket
call rpack ;get answer
jp c,rplus ;no good
call tstack ;check if correct ack
jp c,rplus ;no, send again
movb _c,state ;complete
jp mjump ;FIN...
end