h36458
s 00216/00000/00000
d D 1.1 83/03/30 16:32:02 bog 1 0
c date and time created 83/03/30 16:32:02 by bog
e
u
4
U
t
T
I 1
; Send a file to RdFile on UNIX
; Small memory model
 
Axi	Equ	3
Axo	Equ	4
Cono	Equ	2
 
	CSeg
Start:
;	Mov	Si,Offset EchoPro	;Point to echo turner offer
;	Call	Pooper			;Turn off echo
 
;	Mov	Cx,1000			;Wait 1000 ms
;	Call	WaitMs
 
	Mov	Dx,Offset FCB		;Point to default FCB
	Mov	Cl,0fh			;Open file code
	Int	224			;Open File BDOS
	Cmp	Al,-1			;Look for error
	Jne	FFound
	Mov	Cl,009h			;Print string
	Mov	Dx,Offset Fnf		;Point to string
	Int	224			;BDOS
	Retf				; & quit
 
FFound:
	Mov	RecNo,0			;Start with record 0
	Mov	Buffp,081h		;Initialize buffer pointer
 
	Mov	Si,Offset FilePro	;Unix starter
	Call	Pooper			;Start Unix
 
	Mov	Si,Offset FileWai	;Wait for filename prompt
	Call	Waiter
 
	Mov	Si,Offset FCB+1		;Point to filename
	Mov	Cx,8			;8 char name
	Call	PoopFile		;Send the filename
	Mov	Dl,02eh			;Need a dot
	Mov	Cl,Axo			;Send to Unix
	Int	224			;BDOS write Axo:
	Mov	Cx,3			;3 chars in ext
	Call	PoopFile		;Send extension
	Mov	Si,Offset SendPro	;Send Cr
	Call	Pooper
 
 
	Mov	Si,Offset SendWai	;Point to wait for sending file
	Call	Waiter			; & wait for it
	
	Jmp	SendLoop		; & enter after wait
 
WaitLine:
	Mov	Si,Offset LineWai	;Wait for '?:'
	Call	Waiter			; prompt
 
SendLoop:
	Call	Getch			;Get a byte
	Cmp	Dl,00ah			;Linefeed?
	Je	SendLoop		;Yep...  skip it
	Cmp	Dl,01ah			;^Z?
	Je	Quit			;Quit if so
	Push	Dx			;Save char sent		
	Mov	Cl,Axo			;BDOS 4 is poop out to punch
	Int	224			;Send the character up the hill
	Pop	Dx			;Get char back
	Mov	Byte Ptr LastCr,1	;Assume true
	Cmp	Dl,00dh			;Cr?
	Je	WaitLine		;Yes; wait for prompt
	Mov	Byte Ptr LastCr,0	;Last was notCr
	Jmp	SendLoop		; & loop til eol or eof
 
Quit:
	Test	Byte Ptr LastCr,0ffh	;Was last char a Cr?
	Jnz	YQuit			;Yes--no need to send and prompt
	Mov	Cl,Axo			;BDOS 4 is poop out to punch
	Mov	Dl,00dh			;Send a Cr
	Int	224			;Send the character up the hill
	Mov	Si,Offset LineWai	;Wait for '?:'
	Call	Waiter			; prompt
 
YQuit:	Mov	Si,Offset Quitter	;Point to ender
	Call	Pooper			; & poop it out
	Mov	Si,Offset QuitWai	;Point to all done wait
	Call	Waiter			; & wait for it
	Retf				;& quit
 
Getch:
	Mov	Bx,Buffp		;Get buffer pointer
	Inc	Bx			;Bump to next char
 
	Cmp	Bx,080h			;Pointing at valid char?
	Jl	GotBuff			;Jump if still some in buffer
 
	Mov	Cl,014h			;Code for BDOS Read Seq
	Mov	Dx,Offset FCB		;Point to file control block
	Int	224			;Read next record
	Or	Al,Al			;Error?
	Je	GotIt			;Jump if no
	Mov	Cl,009h			;Print string
	Mov	Dx,Offset Rderr		;Point to message
	Int	224			;BDOS
 
GotIt:
	Mov	Bx,0			;Point at first byte
 
GotBuff:
	Mov	Buffp,Bx		; & save buffer pointer back
	Mov	Dl,Buff[Bx]		;Get a byte
	And	Dl,07fh			;Mask to Ascii
	Ret
 
PoopFile:
	Mov	Dl,Byte Ptr [Si]	;Get a byte
	Inc	Si			;Point to next
	And	Dl,07fh			;Mask to Ascii
	Cmp	Dl,020h			;Space?
	Je	PoopRet			;Don't send if so
	Cmp	Dl,041h			;Uppercase?
	Jb	PoopIt			;Nope
	Cmp	Dl,05ah			;Within uppercase range?
	Ja	PoopIt			;Nope
	Add	Dl,020h			;Make it lowercase
 
PoopIt:
	Push	Cx			;Save count
	Mov	Cx,Axo			;Point to Axo:
	Int	224			;BDOS send out Axo:
	Pop	Cx			;Restore count
 
PoopRet:
	Loop	PoopFile		;Loop until name/ext done
	Ret				; & return
 
Pooper:	Mov	Dl,Byte Ptr [Si]	;Get a byte
	Inc	Si			;Bump index
	Or	Dl,Dl			;Done?
	Jz	PoopFin			;Jump if yes
	Mov	Cl,Axo			;Code for Axo: write
	Int	224			;BDOS write to Axo:
	Jmp	Pooper			; & loop
 
PoopFin:
	Ret				;Quit when done
 
WaitNot:
	Pop	Si			;Get pointer to beginning back
 
Waiter:	Push	Si			;Save pointer to beginning
 
WaitLoop:
	Mov	Cl,Byte Ptr [Si]	;Get a byte
	Inc	Si			;Bump ptr
	Mov	Ch,0			;Clear high
	Jcxz	WaitFnd			;Found string!
 
	Push	Cx			;Save target char
 
WaitMore:
	Mov	Cl,Axi			;Point to Axi:
	Int	224			;Get a character from Axi:
	And	Al,07fh			;Mask to Ascii
	Jz	WaitMore		;Loop if seeing NUL
	Cbw				;Full 16 bits
	Pop	Cx			;Get target back
	Cmp	Ax,Cx			;Still the same?
	Je	WaitLoop		;Loop if yes
	Pop	Si			;Point back to beginning of string
	Jmp	Waiter			;Start again if no match
; Note that this will not rescan for repetitive match
 
WaitFnd:
	Push	Ax			;Save regs
	Push	Cx
	Mov	Cl,Cono			;Poop to screen
	Mov	Dl,02Ah			;Char to poop
	Int	224			;Echo to screen
	Pop	Cx			;Restore regs
	Pop	Dx
	Pop	Si			;Trash saved pointer
	Ret
 
;WaitMs:	Mov	Ax,140			;About 7 us/inner loop
 
;MsLoop:	Dec	Ax			;Down
;	Jns	MsLoop			;Decrement
;	Loop	WaitMs			;Loop until Cx==0
;	Ret				; & return
 
	DSeg
	Org	05ch
FCB	Rb	32
RecNo	Rb	1
	Rb	3
 
Buff	Rb	080h
Buffp	Rw	1
 
LineWai	Db	'?:',13,10,0
FileWai	Db	'filename:',13,10,0
SendWai	Db	'opened',13,10,0
QuitWai	Db	':On:',13,10,0
 
;EchoPro	Db	'stty -echo',13,0
;FilePro	Db	'upload',13,0
FilePro	Db	'up',13,0
SendPro	Db	13,0
 
Quitter	Db	'!END',13,'echoon',13,0
 
Fnf	Db	'File not found$'
RdErr	Db	'Read error$'
 
LastCr	Db	0			;True if last char sent was Cr
	End
 
E 1
