	TITLE	SUBMIT

HEXIT	EQU 0;		exit to hot start of system
BDOS	EQU 5;		standart BDOS calls addres
TPASIZE	EQU 6;		addres of maxsize of TPA
STROUT	EQU 9;		BDOS call of writing string on a screen
FOPEN	EQU 0FH;	BDOS call of opening file bf it's FCB
SETDMA	EQU 1AH;	BDOS call of set DMA
READREC	EQU 14H;	BDOS call of sequential reading of one record (cluster)
RESDSK	EQU 0DH;	BDOS call resets all registered in system disk drives
RECSIZ	EQU 128;	size of one record (cluster)

EXIT_TO_DOS   MACRO
	LHLD STACK
	SPHL
	RET
	ENDM

TERMINATE  MACRO  TRMLINE
	LXI D,TRMLINE
	JMP TRMNT
	ENDM

	LXI H,0
	DAD SP
	SHLD STACK
	LHLD TPASIZE
	DCX H
	SPHL
	CALL INIFCB
	LXI H,5DH
	MOV A,M
	CPI 20H
	JNZ VFYINP
	LXI D,USAGE
	CALL PUTS
	EXIT_TO_DOS
VFYINP:	LXI H,82H;	Verifying input line
	CALL FLTRBL; filter of left blanks in file
	LXI D,F1
	MOV A,M
	ANI 7FH
	CPI 'A'
	JP VF1SFN
	TERMINATE ERRFN
VF1SFN:	CPI 'Z'+1
	JM OK1SFN
	TERMINATE ERRFN
OK1SFN:	MVI C,9;	First symbol of filename OK
VFNAM:	MOV A,M
	CPI '.';	First symbol already not equal to '.'
	JZ VFYEXT
	CPI ' ';	If blank stands instead of a point, it
	JZ NOEXT;	means that no extenston in input line
	ORA A
	JNZ VFNAM1
	TERMINATE NOPARM
VFNAM1:	STAX D
	INX H
	INX D
	DCR C	
	JNZ VFNAM
	TERMINATE ERRFN;Because filename too long
VFYEXT:	INX H;		Verifying file extension
	LXI D,T1
	XCHG
	MVI C,3
VFYSUB:	LDAX D
	ANI 7FH
	CMP M
	JZ VFYSU1
	TERMINATE ERREXT
VFYSU1:	INX H
	INX D
	DCR C
	JNZ VFYSUB
	XCHG
	MOV A,M
	CPI ' '
	JZ NOEXT
	CPI 0
	JNZ BADEXT
	TERMINATE NOPARM
BADEXT:	TERMINATE ERREXT
NOEXT:	INX H;		Beginning of verifying of parameters
	LXI D,PARM1
	XRA A
	STA NUMPAR;	Zero parameters "checked and processed"
VFYPAR: CALL STOREP
	ORA A
	JZ FINPAR
	CPI 0FFH;	Sign of a bad (very long) input parameter
	JNZ VFYP1
	TERMINATE PRMBAD
VFYP1:	PUSH H
	LXI H,15
	DAD D
	XCHG
	POP H
	LDA NUMPAR
	CPI 9
	JNZ VFYPAR
	TERMINATE MANYPR

;	Now NUMPAR is a number of parameters with 14 byte (maximum)
;	length (zero byte is a sign of parameter end).
;	Parameters (not more than 9) lays from PARM1 (next parameter
;	have addres PARM1+15)
;	Filename is in it's FCB structure and we can begin disk operations.
FINPAR:
	EXIT_TO_DOS

;	This procedure stores parameters to it's nests, but doesn't
;	tests the maximum count of parameters.
STOREP:	PUSH D
	PUSH B
	MVI B,15;	Really good parameter length is 14
	CALL FLTRBL;	filtration of left blanks of a parameter
	MOV A,M;	checking of FIRST symbor of parameter
	ORA A
	JNZ NEXTPR
	LDA NUMPAR;	Sign of end of input line reached
	ORA A;		so we check were any parameters processed,
	MVI A,0;	(if they were, processing of parameters completed)
	JNZ STRPE;	or input line hasn't parameters:
	TERMINATE NOPARM
;			in that case we terminate program
NEXTPR:	MOV A,M
	CPI 20H;	First byte of parameter can't be ' ' because we
	JZ PAREND;	made filtration of left parameter blanks already !
	ORA A;		First symbol also can't be 0 because we already
	JNZ PARSYM;	checked it.
	LDA NUMPAR;	So if any symbol of parameter is not equal to
	INR A;		' ' and equal to 0,  this is a sign of END OF
	STA NUMPAR;	THIS PARAMETER and END OF INPUT LINE.
	XRA A
	JMP STRPE
PARSYM:	STAX D
	INX D
	INX H
	DCR B
	JNZ NEXTPR
	MVI A,0FFH; Set sign of a too long parameter 0FFH (because if
	JMP STRPE;  we are here, parameter length is greater than 14).
PAREND:	LDA NUMPAR
	INR A
	STA NUMPAR; Parameter is good (with normal length)
STRPE:	POP B
	POP D
	RET

FLTRBL:	PUSH PSW; This procedure filters blanks
FLTRB1:	MOV A,M
	CPI ' '
	JNZ BLNOT
	INX H
	JMP FLTRB1
BLNOT:	POP PSW
	RET

PUTS:	PUSH H
	PUSH B
	PUSH PSW
	MVI C,STROUT
	CALL BDOS
	POP PSW
	POP B
	POP H
	RET

TRMNT:	PUSH D; Program   T E R M I N A T O R
	LXI D,TMESB
	CALL PUTS
	POP D
	CALL PUTS
	LXI D,TMESE
	CALL PUTS
	EXIT_TO_DOS

INIFCB:	PUSH H
	PUSH B
	LXI H,F1
	MVI C,8
	MVI B,20H
INIF1:	MOV M,B
	INX H
	DCR C
	JNZ INIF1
	MVI M,'S'
	INX H
	MVI M,'U'
	INX H
	MVI M,'B'
	INX H
	MVI C,24
	MVI B,0
INIF2:	MOV M,B
	INX H
	DCR C
	JNZ INIF2
	LXI H,PARM1
	LXI B,15*9
INIF3:	MOV M,B
	INX H
	DCR C
	JNZ INIF3
	POP B
	POP H
	RET


USAGE:	DB 1BH,61H,1BH,5BH
	DB 'Perlin Production Co.Ltd. SUBMIT v.0.1 1992 (c).'
	DB 0DH,0AH
	DB 'Usage:  SUBMIT fname[.SUB] parm1 [parm2 parm3 ... parmN]$'
TMESB:	DB 7,1BH,5BH,0DH,0AH,1BH,62H,'$'
ERRFN:	DB ' Error in input filename.$'
ERREXT:	DB ' Error in extension.$'
NOPARM:	DB ' Can''t find input parameters.$'
MANYPR:	DB ' Too many input parameters. Use only 9.$'
PRMBAD:	DB ' Input parameter too long.$'
NOFILE:	DB ' Can''t find file on a current disk.$'
TMESE:	DB ' PROGRAM TERMINATED.',1BH,61H,7,'$'

;	File control block:
FCB:
DR:	DB 0; 		current drive initiates
F1:	DB 20H
F2:	DB 20H
F3:	DB 20H
F4:	DB 20H
F5:	DB 20H
F6:	DB 20H
F7:	DB 20H
F8:	DB 20H
T1:	DB 20H
T2:	DB 20H
T3:	DB 20H
EX:	DB 0;		number of extent (byte fills by system)
S1:	DB 0;		level of using of current
S2:	DB 0;		extent by a file
RC:	DB 0;
D0:	REPT 16
	 DB 0;		reserved for DOS
	ENDM
CR:	DB 0
R0:	DB 0
R1:	DB 0
R2:	DB 0

;	End of file control block
NUMPAR:	DS 1 ;		Number of input line parameters
PARM1:	DS 15
PARM2:	DS 15
PARM3:	DS 15
PARM4:	DS 15
PARM5:	DS 15
PARM6:	DS 15
PARM7:	DS 15
PARM8:	DS 15
PARM9:	DS 15

STACK:	DW 1

	END

