home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
archives
/
trs80model2.tar.gz
/
trs80model2.tar
/
trsutil2.mac
< prev
Wrap
Text File
|
1997-03-26
|
11KB
|
259 lines
subttl kutil2/mac utilities and other odd routines
extrn rlen,slen,csvc,rsvc,ssvc,r,n,mjump
extrn spaket,rpaket,byte,recptr,sinit
extrn fcb,lrecl,filbuf,recbuf,lrecl,paraml
extrn readnx,crp,cbp,word
public tstack,buffil,eof
;
; useful symbols
;
soh equ 1
tout equ 10
len equ 0
seq equ 1
type equ 2
data equ 3
dfport equ 'A'
;
;
;
;svc to make a trsdos supervisor call
; syntax svc code
; where code is the trsdos code
;
svc macro code
ld a,code
rst 8
endm
;
;
;prmes to print messages on the screen
; syntax prmes lab
; where lab if the label as defined with mssg
;
prmes macro lab
.xlist
extrn m_&lab,l_&lab
push hl
push bc
ld hl,m_&lab ;get address of message
ld bc,(l_&lab) ;and length
ld c,13 ;add a CR at end of ttyout
svc 9 ;call dos
pop bc
pop hl
.list
endm
;
;blmov to move a block of text
; syntax blmov source,destination,length
; if length is 0 then assume 256
;
blmov macro source,dest,len
.xlist
local $1,$2
push hl
push bc
push de
ld hl,source ;address of source
ld de,dest ;address of destination
ld a,(len) ;get length
cp 0 ;is it zero ?
jr nz,$1
ld b,1 ;then set bc = 256
ld c,0 ;(b=1 ; c=0)
jp $2 ;go to start move
$1:
ld b,0
ld c,a ;bc = length
$2:
ldir ;move and check if bc=0
pop de
pop bc
pop hl
.list
endm
movb macro value,loc
.xlist
push af
ld a,value
ld (loc),a
pop af
.list
endm
;
;
; tstack to test a received packet for a good ack
;
tstack:
ld a,(n) ;cirrent packet count
add a,' ' ;make printable
cp (ix+seq) ;equal to seq received ?
jp nz,plus1 ;no, test n+1
ld a,(ix+type) ;get packet type
cp 'Y' ;is an ack ?
jp nz,nogood ;no return error code
$1:
scf
ccf
ret ;return no error
plus1:
inc a ;increment packet count
cp (ix+seq) ;equal to received ?
jp z,$1 ;yes, all ok
nogood:
scf ;set carry
ret
;
; buffil to fill a send packet data field from
; record buffer
;
buffil:
movb 3,cbp ;initialize buffer pointer
b5:
ld a,(cbp) ;get buffer pointer
inc a ;it might be one less
ld hl,sinit ;maxlen to send
cp (hl) ;equal to max or max-1 ?
jp c,b0 ;no, there is room
b4:
ld a,(cbp) ;buffer pointer
ld (iy+len),a ;in packet
scf
ccf
ret ;return all ok
b0:
xor a ;clear a
ld hl,crp ;record pointer address
cp (hl) ;buffer empty ?
jp nz,b1 ;no
call readnx ;get something (EOF...)
jp nc,b1 ;not end of file yet
ld a,(cbp) ;spaket pointer
ld (iy+len),a ;put in place
cp 3 ;is this the start ?
jp nz,b13 ;not yet, return normally
scf ;flag to never return here
b13: ret
b1:
ld a,(cbp) ;buffer pointer
ld b,a ;save in b
ld a,(sinit) ;maxlen to send
sub b ;a=SA=mxl-cbp
ld (byte),a ;save in byte
ld a,(crp) ;record pointer
ld b,a ;save in b
ld a,(lrecl) ;record length
sub b ;a=BA=lrecl-crp
ld hl,byte ;get byte address
cp (hl) ;BA > SA ?
jp nc,b2 ;go move SA bytes
ld (byte),a ;save BA in byte
b2:
ld hl,spaket ;packet address
ld a,(cbp) ;current pointer
add a,l ;add to low byte
ld l,a ;save back
ld a,0 ;clear a keeping carry
adc a,h ;add carry to high byte
ld h,a ;save back
ex de,hl ;save in DE
ld hl,recbuf ;record address
ld a,(crp) ;record pointer
add a,l ;add to low byte
ld l,a ;save back
ld a,0 ;clear a keeping carry
adc a,h ;add to high byte
ld h,a ;save back
;
; here we move from recbuf to spaket
; making sure the control caracters are quoted,
; and uncontrollified (same thing for del),
; and that the quote caracter is itself quoted.
;
movb 0,word ;this will be the count from recbuf
movb 0,word+1 ;and the count of quote bytes
b9:
ld a,31 ;limit of control char.
ld b,(hl) ;get character in b to
res 7,b ; reset seventh bit
cp b ;compare 31 to byte to send
jp c,b6 ;this is not a control char.
b8:
ld a,(sinit+5) ;get the quote byte
ld (de),a ;move in spaket
inc de ;update spaket pointer
push hl ;save
ld hl,word+1 ;points to quote count
inc (hl) ;update count
pop hl ;restore
ld a,64 ;to uncontrollify
xor (hl) ;the byte to send
ld (hl),a ;and put it back in recbuf
jp b7 ;go send it
b6:
ld a,127 ;del byte
cp b ;is this it ?
jp z,b8 ;yes go uncontrollify it
;
ld a,(sinit+5) ;quote byte
cp (hl) ;is this what we are sending ?
jp nz,b7 ;no, go on
ld (de),a ;yes put it in spaket
inc de ;and update pointer
push hl ;save
ld hl,word+1 ;get quote count address
inc (hl) ;and update it
pop hl ;restore hl
b7:
ldi ;move the byte in spaket
push hl ;save
ld hl,word ;count address
inc (hl) ;update it
ld a,(hl) ;get count of bytes from recbuf
ld hl,word+1 ;and count of quote bytes
add a,(hl) ;add them to get real count
ld hl,byte ;address of max to moved
inc a ;increment real count
; to get to max-1 or max
cp (hl) ;compare count+1 to max
jp nc,b10 ;this is it, finish.
pop hl ;restore
jp b9 ;one more time...
b10:
ld a,(word) ;real count moved from recbuf
ld (byte),a ;put where we need it
pop hl ;restore to recbuf
b11:
;
; at this point we have moved up to (byte) bytes
; maby less if there was only one control character
; Most of those bytes come from recbuf plus some
; instances of the quote byte.
;
ld a,(word) ;number of bytes moved
ld hl,word+1 ;address of quote count
add a,(hl) ;a = total count
ld hl,cbp ;buffer pointer
add a,(hl) ;increment
ld (hl),a ;save back in cbp
ld hl,crp ;record pointer
ld a,(word) ;get back bytes moved from rec
add a,(hl) ;fix pointer
ld (hl),a ;save back in cbp
ld a,(lrecl) ;record length
cp (hl) ;equal to record pointer ?
jp nz,b3 ;no, go on
movb 0,crp ;yes, reset crp
b3:
jp b5 ;one more time
;
; eof this routine will be accessed automatically
; from a read of eof by trsdos.
; Might be accessed twice ...
;
eof:
scf ;set carry
ret
end