;CBBS V3.5.0 	CBBSENT1.ASM - MSG ENTRY, PART 1
;11/18/81 21:55:07
;
;	LINKS TO CBBSENT2
;
;	O O O	O   O	O O O	  O
;	O	OO  O	  O	O O
;CBBS	O O	O O O	  O	  O	.ASM
;	O	O  OO	  O	  O
;	O O O	O   O	  O	O O O
;
;MODS (THRU 3.2 MOVED TO "HISTORY")
;
;====> HISTORICAL COMMENTS SINCE 3.3 TO "HISTORY.033"
;
;---->	ENTER A MESSAGE
;
ENTER	EQU	$
;
	LXI	H,0	;SHOW ABOUT TO CLOBBER
	SHLD	FLAGPTR	;	FLAGGED MSG #'S
	IF	TWITCK
	CALL	TWITST	;DON'T LET 'TWITS'
	JZ	WHATM	;..ENTER MSGS
	LDA	TWITSW
	ORA	A
	JNZ	WHATM
	ENDIF
;
;DETERMINE THE NEXT MESSAGE NUMBER
;
	CALL	RDNEXT	;READ FILE 'NEXT'
02;START OF 02 MODS
;
;LIMIT # OF MSGS ALLOWED
;
	LXI	D,8EH	;TO # ACTIVE
	LXI	H,95H	;TO MAX ALLOWED
	MVI	B,5	;COMPARE LENGTH
	CALL	COMPR
	JC	ENROOM1	;ROOM FOR MORE
JZ	ENROOM1
ENNRM	CALL	ILPRT
	DB	'++Sorry, no room for more msgs++',CR,LF,0
	LDA	PASSFLG
	ORA	A
	JZ	ENROOM	;ALLOW OPERATOR
	JMP	DEFUNCT	;KILL STACKED LINES
;SEE IF AT MAX/USER
ENROOM1	LDA	ELEFT
	ORA	A
	JZ	ENNRM	;NO MORE
	DCR	A
	STA	ELEFT
ENROOM	EQU	$
02; END OF MODS
	CALL	ILPRT
	DB	'Msg ',0
	LXI	H,80H	;=MSG # IN DISK BUFFER
	CALL	TYPEMCR
	CALL	CRLF
;
	LXI	H,80H	;POINT TO MSG #
	LXI	D,MSGNO
	MVI	B,6	;5 DIGITS + CR
	CALL	MOVE	;MOVE TO MSGNO
	CALL	SETMSGN	;SET UP FILE NAME
	LDA	EXPERT
	ORA	A
	JNZ	GDATE
;
;EXPERTS DON'T SEE THE FOLLOWING:
;
	CALL	ILPRT
	DB	'Typing a dash for subject, etc. ',cr,lf
	DB	'backs up 1 question.',CR,LF
	DB	0
	JMP	GDATE
REDATE	MVI	A,CR
	STA	INBUF	;CANCEL STACKED INPUT
GDATE	EQU	$
;
	IF	CLOCK
	LXI	H,DATE
	CALL	RDDATE
	MVI	M,CR
	JNC	ENTER0	;CLOCK BOARD GOT DATE
	ENDIF
;
	CALL	GETVAR
	DB	'Date: Today''s date,'
	DB	' please (dd-mmm-yy)',0
	DW	DATE
03	DW	8	;HELP MSG #
	DB	9
	LDA	DATE
	CPI	' '
	JZ	REDATE
	CPI	CR
	JZ	REDATE
;EDIT DATE (FOR SLASHES, ALLOWING M OR MM)
	LXI	H,DATE+1
	MVI	A,'/'
	CMP	M
	JZ	ENTSL
	INX	H
	CMP	M
	JNZ	REDATE
;GOT FIRST SLASH, CHECK FOR SECOND
ENTSL	INX	H
	INX	H
	CMP	M
	JZ	ENTER0	;SINGLE DIGIT DAY
	INX	H
	CMP	M
	JNZ	REDATE
	JMP	ENTER0
;
;10/17/81 COMMENTED OUT - SCITRONICS DOESN'T GLITCH
;
;01 ;
;01 ;VALIDATE DATE ENTERED FROM CLOCK BOARD
;01 ;(CBBS/CHI COMES IN WITH MONTH=99 SOME TIMES)
;01 ;
;01 ENCKDAT	LDA	DATE
;01	CPI	'9'
;01	JZ	REDATE
;01	JMP	ENTER0
;
;REENTER WHO TO, IT WAS BAD
;
REWHO	MVI	A,CR
	STA	INBUF	;CANCEL STACKED LINES
;
;10/17/81 MODS SEE IF THIS IS AN OPERATOR CONTINUED MSG
;
ENTER0	LXI	H,MCONT	;POINT TO CONTINUE FLAG
	MOV	A,M	;GET IT
	MVI	M,0	;	AND ZERO IT
	ORA	A
	JZ	ENTER1
	LXI	H,CONTMSG ;POINT TO "(CONT'D)"
	LXI	D,SUBJ
	MVI	B,9
	CALL	MOVE
	JMP	ENCLR
;
CONTMSG	DB	'(CONT''D)',CR
;
;10/17/81 END OF MODS
;
ENTER1	CALL	GETVAR
	DB	'Who to: (20 letters max.) '
	DB	'(or use: ALL)',0
	DW	MSGTO
03	DW	9	;HELP MSG #
	DB	20	;MAX LEN
	LDA	MSGTO
	CPI	'-'
	JZ	FUNCT
	CPI	' '
	JZ	REWHO
	CPI	CR
	JZ	FUNCT	;%07/11/81 WAS REWHO
	LDA	MSGTO+1
	CPI	CR
	JZ	FUNCT
;
;12/03/78 IF DATE ENTERED (NO LONGER ASKED FOR
;IF CLOCK BOARD) THEN IGNORE IT, SKIP TO NEXT FIELD
;
	IF	CLOCK
	LDA	MSGTO
	ANI	0F0H	;MAKE NUMERIC
	CPI	'0'	;..TEST
	JNZ	ENSUBJ
	LDA	MSGTO+1
	CPI	'/'
	JZ	ENTER0	;SKIP DATE
	LDA	MSGTO+2
	CPI	'/'
	JZ	ENTER0
	ENDIF
;
	LDA	MSGTO
	CPI	'-'
	JZ	REDATE
;
	JMP	ENSUBJ
RESUBJ	MVI	A,CR
	STA	INBUF	;CANCEL STACKED LINES
ENSUBJ	CALL	GETVAR
	DB	'Subj: Be Specific!  '
	DB	'Press C/R for examples',CR,LF
	DB	CR,LF,'Message subject (30 '
	DB	'chars max)',0
	DW	SUBJ
03	DW	10	;HELP MSG #
	DB	30
	LDA	SUBJ
	CPI	' '
	JZ	RESUBJ
	CPI	'-'
	JZ	REWHO	;BACK UP 1 QUESTION
	CPI	CR	;NOTHING ENTERED?
	JNZ	REPASS
	CALL	ILPRT
	DB	CR,LF,'Typical:',CR,LF
	DB	'xxxxxx for sale '
	DB	'	(Don''t just say "for sale")',CR,LF
	DB	'need help with xxxxxx',CR,LF,0
	JMP	RESUBJ
;
;09/13/81 PASSWORD LOGIC CHANGED: NOW ALWAYS ENTER ONE.
;
REPASS	CALL	GETVAR
	DB	'Password: Enter 4 letter delete password',cr,lf
	DB	'(If you just press return, '
	DB	'anyone can kill your msg): ',0
	DW	PASSWD
03	DW	12	;HELP MSG #
	DB	4
	LXI	H,PASSWD
	MOV	A,M
	CPI	'-'
	JZ	RESUBJ
	MVI	B,0	;INIT COUNT
	CALL	COUNTC
	ora	a
	jz	ennopw
	cpi	4
	jnz	repass
;
ennopw	lda	expert
	ora	a
	jnz	nohelp
	call	getvar
	DB	'Help Y/(N): Review steps to '
	DB	'enter a message:',0
	DW	ANSWER
03	DW	13	;HELP MSG #
	DB	3
	LDA	ANSWER
	CPI	'-'
	JZ	REPASS
	CPI	'Y'	;11/18/81 MOD: "N" DEFAULT
	JNZ	NOHELP
;TYPE THE 'ENTINTRO' FILE
	LXI	H,ENINFL ;POINT TO FILENAME
	CALL	TYPEF	;TYPE THE FILE
NOHELP	CALL	QCASE	;SEE IF LOWER CASE
	LDA	EXPERT	;EXPERT USER?
	ORA	A
	JNZ	ENCLR	;SKIP PROMPT IF SO
	CALL	ILPRT
	DB	CR,LF
	DB	'Enter the msg, 60 chars/line max.  ',0
	CALL	ILPRT
	DB	'(Bell rings at 55).',0
	CALL	ILPRT
	DB	CR,LF,'Use ctl-I (tab) to space over.'
	DB	CR,LF,'-----> WHEN DONE ENTERING, '
	DB	'press return twice.'
	DB	CR,LF,'-----> TO ABORT, ENTER: ABORT'
	DB	CR,LF,'THEN PRESS RETURN'
	DB	CR,LF,0
;
ENCLR	LXI	H,'01'
	SHLD	LINO
	DCR	H	;MAKE IT '00' %
	SHLD	HILINE	;SAVE HI LINE #
	LXI	H,MSGBF	;POINT TO 16X64 AREA
	SHLD	LINEAD	;SAVE LINE ADDR
;STORE 0 AT START OF EACH LINE
	LXI	D,64
	MVI	B,17
ENST0	MVI	M,0
	DAD	D
	DCR	B
	JNZ	ENST0
ENLOOP	MVI	A,2	;SET SO CTL-K GOES
	STA	CTLKSW	;	TO ENCOMD, NOT FUNCT
	CALL	GETVARN	;NO TRANSLATE
LINO	DB	'## ',0
LINEAD	DW	$-$	;MODIFIED TO POINT TO BUFFER
03	DW	14	;HELP MSG #
	DB	60	;MAX LEN
;SEE IF END, I.E. EMPTY LINE
	LHLD	LINEAD
	MOV	A,M	;CHECK FOR
	CPI	CR	;BLANK LINE
	JZ	ENCOMD	;END OF ENTER, GET COMMAND
;SEE IF 'ABORT' ENTERED
	LHLD	LINEAD	;MOVE TO DE FOR..
	XCHG		;..XLATE TO UPPER CASE
	LXI	H,ABORTM
	MVI	B,6	;'ABORT',CR
	CALL	COMPR	;ABORT?
	JNZ	NOABORT
;
;ABORT REQUESTED, VERIFY IT'S WANTED
;
VABORT	CALL	GETVAR
	DB	'++ABORT DISCARDS YOUR '
	DB	'MESSAGE++',CR,LF
	DB	'ENTER Y TO THROW IT AWAY',0
	DW	ANSWER
03	DW	15	;HELP MSG #
	DB	3
	LDA	ANSWER
	CPI	'Y'
	JZ	FUNCT
	JMP	ENCOMD	;GET SUBCOMMAND
;
;BUMP LINE POINTER
;
NOABORT	LHLD	LINEAD
	LXI	D,64
	DAD	D
	SHLD	LINEAD
;BUMP LINE #
	LHLD	LINO
	SHLD	HILINE
	LXI	H,LINO+1
	CALL	ADD1	;ASCII ADD
;16 LINES?
	LDA	LINO
	CPI	'1'
	JNZ	ENLOOP
	LDA	LINO+1
	CPI	'7'
	JZ	ENFULL	;FULL
;>13 LINES?
	CPI	'4'
	JC	ENLOOP
;PRINT NUMBER OF LINES REMAINING (1, 2, 3)
	CMA		;MAKE NEG
	ANI	3
	ADI	'0'	;MAKE IT 1, 2, OR 3
	PUSH	PSW	;(FOR LINE/LINES TEST)
	CALL	TYPE	;TYPE 1, 2, OR 3
	CALL	ILPRT
	DB	' line',0
	POP	PSW
	CPI	'1'
	MVI	A,'s'
	CNZ	TYPE	;MAKE IT 'LINES' IF >1
	LDA	EXPERT	;EXPERT?
	ORA	A
	JNZ	ENXCR	;SKIP FOLLOWING MSG
	CALL	ILPRT
	DB	' left.  Press return to end'
	DB	CR,LF,0
	JMP	ENLOOP
ENXCR	CALL	CRLF	;EXPERT
	JMP	ENLOOP
;
;BUFFER FULL
;
ENFULL	CALL	ILPRT
	DB	CR,LF
	DB	'Message full, (16 lines).'
	DB	CR,LF,0
	MVI	A,CR
	STA	INBUF	;KILL STACKED LINES
	JMP	ENCOMD	;GET SUBCOMMAND
;
;SAVE THE MSG
;
;OPEN AND EXTEND THE APPROPRIATE DISK FILE
;(MESSAGE.NNX WHERE NN IS THE FIRST 2 DIGITS
;OF THE MESSAGE #)
;
ENSAVE	CALL	ILPRT
	DB	'Writing to disk.',CR,LF,0
	MVI	A,1	;GET NON ZERO VALUE
	STA	CTLKSW	;DISABLE CTL-K ABORT
;
;KEEP RUNNING EVEN IF LOSS OF MODEM CARRIER
;BECAUSE WE ARE UPDATING THE DISK
;
	STA	DKUPSW
	CALL	SETMSGN	;SETUP MSG # IN NAME
	LXI	H,MSGFN ;POINT TO FILENAME
	CALL	EXTEND	;OPEN (OR MAKE IF NEW)
;
;WRITE THE FILE HEADER
;
	CALL	WRHDR	;WRITE HEADER
;
;WRITE THE MESSAGE ITSELF
;
	LXI	H,MSGBF	;POINT TO FIRST LINE
	MVI	B,16	;MAX LINES
ENWRL	PUSH	H
	MOV	A,M	;END?
	ORA	A
	JZ	ENWRCLS	;YES, CLOSE FILE
	CALL	WRLINE	;WRITE THRU CR/LF
	POP	H
	LXI	D,64
	DAD	D
	DCR	B
	JNZ	ENWRL
;
;END OF WRITE, CLOSE THE FILE
;
ENWRCLS	CALL	WREOF	;EOF, THEN CLOSE
;
;UPDATE THE 'NEXT' MESSAGE NUMBER FILE
;
	CALL	RDNEXT	;READ THE FILE
	LXI	H,84H	;POINT TO UNITS
	CALL	ADD1	;BUMP IT BY 1
;
;UPDATE THE # OF ACTIVE MESSAGES
;
	LXI	H,92H	;POINT TO UNITS
	CALL	ADD1	;BUMP IT BY 1
;
;WRITE "NEXT" FILE BACK
;
	XRA	A	;GET 0
	STA	FCBRNO	;WRITE RECORD 0
	LXI	D,FCB
	MVI	C,WRITE
	CALL	BDOS	;UPDATE IN PLACE
	ORA	A	;OK?
	JZ	CLSNXT	;OK, WRITE SUMMARY
	CALL	ILPRT
	DB	'++ERROR writing "NEXT" file',CR,LF,0
	JMP	TELLUS
03;CLOSE NEXT FILE
CLSNXT	CALL	CLOSENX
;
;UPDATE THE SUMMARY FILE
;
	CALL	ILPRT
	DB	CR,LF
	DB	'Updating summary.',CR,LF,0
	LXI	H,SUMFL
	CALL	EXTEND
	CALL	WRHDR	;WRITE HEADER
	CALL	WREOF	;WRITE EOF, CLOSE
	JMP	FUNCT
;
;SUBROUTINE TO WRITE HEADER TO FILE,
;USED FOR BOTH MESSAGE AND SUMMARY FILE
;
WRHDR	MVI	A,'G'-40H ;BELL CHAR AS HDR I.D.
	CALL	WRBYTE
	LXI	H,MSGNO
	CALL	WRVARC	;MESSAGE #
	LXI	H,HILINE ;# LINES
	CALL	WRVARC
	LXI	H,DATE
	CALL	WRVARC	;DATE
	CALL	WRNAME	;"FIRST LAST,"
	LXI	H,MSGTO
	CALL	WRVAR	;WHO MESSAGE IS TO
	CALL	WRCRLF	;CR/LF
	LXI	H,SUBJ
	CALL	WRVARC	;SUBJECT
	LXI	H,PASSWD ;PASSWORD
	CALL	WRVAR
	CALL	WRCRLF	;THEN FINAL CR/LF
	RET		;FROM WRHDR
;
	LINK	CBBSENT2 ;TO NEXT .ASM FILE
