; menu-driven program to initialize integral data systems (dataproducts)
; 460/560 and prism dot matrix printers.

; written and copyright (c) by frank gaude' -- 10/6/1982
; released to public domain for non-commerical use

; change history

; 09/27/83  more menu options provided.  menu redesigned.  tnx to robert
; lafara for multiple-commands-per-initialization idea.  'k' command
; is nice for writing short letters -- margins set using enhanced, justified,
; proportional spacing.  remember no cr's or lf's can be used, except
; to indicate a new paragraph.  (program runs under wordstar if the 'r'
; command is used and the program name is then entered.)  fg

; 06/18/83  added re-do message if incorrect entry made.  now allow input
; to simply leave the program without changing printer condition.  added
; normal mode justified proportional spacing command.  fg

SOURCE	ORG	100H		;tbase entry address
	JMP	BEGIN		;skip to start of main routine

; e q u a t e s

RDCON	EQU	1		;get character input and echo to console
WRCON	EQU	2		;write byte to console
BDOS	EQU	5		;entry to the cp/m bdos
LIST	EQU	5		;cp/m function for byte output to list..
PRINT	EQU	9		;..and for string output to console.
HT	EQU	9		;horizontal tab character
LF	EQU	10		;ascii line feed and..
CR	EQU	13		;..carriage return character.
ESC	EQU	27		;escape code (01bh) into ids program
                                  
; m a i n - l i n e   r o u t i n e
                                  
BEGIN	CALL	SAVSTAK		;save old stack pointer under ccp address
	CALL	CLS		;start fresh screen
BEG$AGN	LXI	D,MENU		;address of string into de-pair
	MVI	C,PRINT		;display above message
	CALL	BDOS		;cp/m does work, fall thru to 'input'.

; s u b r o u t i n e s

; test keyboard input command request

INPUT	MVI	C,RDCON		;wait for keyboard input and echo
	CALL	BDOS
	CALL	UCASE		;convert input to upper case
	LXI	D,IN4		;point to 1st function string..
	CPI	'I'		;test keyboard input
	JZ	TEXTOUT		;string out to printer
	LXI	D,IN12		;..2nd..
	CPI	'H'
	JZ	TEXTOUT
	LXI	D,NPS		;..etc.
	CPI	'M'
	JZ	TEXTOUT
	LXI	D,LPI3
	CPI	'3'		; 3..
	JZ	TEXTOUT
	LXI	D,LPI4
	CPI	'4'		;..4..
	JZ	TEXTOUT
	LXI	D,LPI6
	CPI	'6'		;..6 and..
	JZ	TEXTOUT
	LXI	D,LPI8
	CPI	'8'		;..8 lines per inch.
	JZ	TEXTOUT
	LXI	D,CPI10
	CPI	'A'		; 10..
	JZ	TEXTOUT
	LXI	D,CPI12
	CPI	'B'		;..12 and..
	JZ	TEXTOUT
	LXI	D,CPI168
	CPI	'C'		;..16.8 characters per inch.
	JZ	TEXTOUT
	LXI	D,JPSB		;justified, proportional spacing, bold and..
	CPI	'K'
	JZ	TEXTOUT
	LXI	D,JPSN		;..normal.
	CPI	'D'
	JZ	TEXTOUT
	LXI	D,FS		;go to fixed spacing (standard)
	CPI	'S'
	JZ	TEXTOUT
	LXI	D,NORMAL
	CPI	'N'		;go to normal mode and..
	JZ	TEXTOUT
	LXI	D,ENHANCE
	CPI	'E'		;..to enchanced mode.
	JZ	TEXTOUT
	LXI	D,JUST
	CPI	'J'		;turn justification on and..
	JZ	TEXTOUT
	LXI	D,NOJUST
	CPI	'U'		;..off (unjustified).
	JZ	TEXTOUT
	LXI	D,FF
	CPI	'F'		;output form feed and..
	JZ	TEXTOUT
	LXI	D,PS
	CPI	'P'		; (proportional spacing)
	JZ	TEXTOUT
	LXI	D,LINEF
	CPI	'L'		;..line feed.
	JZ	TEXTOUT
	LXI	D,TEST
	CPI	'T'		;run character-set test pattern
	JZ	TEXTOUT
	CPI	'X'		;exit to host system
	JZ	EXIT
	LXI	D,DFS
	CPI	'Z'		;printer default settings
	JZ	TEXTOUT
	CALL	CLS
	LXI	D,RE$DO		;ask to enter again
	MVI	C,PRINT
	CALL	BDOS
	JMP	BEG$AGN		;loop 'till valid input entered

; string out to printer
 
TEXTOUT	LDAX	D		;load character into a-reg
	CPI	'$'		;end of string?
	JZ	INPUT		;if so, return to main line..
	PUSH	D		;..else save pointer.
	MOV	E,A		;character into e-reg for 'bdos'
	MVI	C,LIST		;tell bdos to output to list device
	CALL	BDOS		;it's done!
	POP	D		;restore pointer then..
	INX	D		;..increment it and..
	JMP	TEXTOUT		;..continue until $ is reached.

; change lower case to upper case

UCASE	CPI	61H
	RC			;return if value in a-reg less 61h..
	CPI	7BH
	RNC			;..and more than 7bh (ascii a to z).
	ANI	5FH		;subtract 20h to make upper case
	RET

; clear screen subroutine

CLS	MVI	E,CR		;put cursor on left side of screen
	MVI	C,WRCON
	CALL	BDOS		;send ascii 'cr' to console
	MVI	B,24		;set up for 24 linefeeds
CLSLP	MVI	E,LF		;put ascii 'lf' in a-reg
	MVI	C,WRCON
 	PUSH	B		;save count from alteration by bdos
	CALL	BDOS		;send ascii 'lf' to console
	POP	B		;restore
	DCR	B		;bump count down one
	JNZ	CLSLP		;loop 'till all done
	RET

; cp/m stack pointer saved -- new stack area set below cp/m ccp

SAVSTAK	POP	B		;get return address
	LXI	H,0		;clear hl-pair and..
	DAD	SP		;..put stack pointer there.
	SHLD	OLDSTAK		;save it
	LHLD	BDOS+1		;get fbase
	MOV	A,H		;put high order byte (pages) into a-reg
	SUI	8		;subtract cbase offset (8 pages = 800h)
	MOV	H,A		;put address in hl-pair
	SPHL			;use hl-pair as stack pointer
	PUSH	B		;set return address
	RET

; return to calling routine (cp/m)

EXIT	LHLD	OLDSTAK		;smooth exit..
	SPHL			;..back..
	RET			;..to cp/m ccp (cbase).

; i n i t i a l i z i e d   s t o r a g e

; main menu

MENU	DB	'Integral Data Systems 460/560/PRISM Initialization Menu'
	DB	CR,LF,LF
	DB	'N - Normal Mode              | E - Enchanced Mode',CR,LF
	DB	'S - Standard (fixed) Spacing | P - Proportional Spacing',CR,LF
	DB	'J - Justified Text Mode      | U - Unjustified',CR,LF,LF
	DB	'A - 10 characters per inch   | B - 12 characters per inch'
	DB	CR,LF
	DB	'C - 16.8 characters per inch',CR,LF,LF
	DB	'3 - Three lines per inch     | 4 - Four lines per inch',CR,LF
	DB	'6 - Six lines per inch       | 8 - Eight lines per inch'
	DB	CR,LF,LF
	DB	'I - Indent left 0.4 inch     | H - Indent left 1.0 inch',CR,LF
	DB	'K - Justified enhanced       | D - Justified normal'
	DB	CR,LF
	DB	'M - Proportional unjustified | Z - Default printer settings'
	DB	CR,LF,LF                                                    
	DB	'F - Form Feed                | L - Line Feed',CR,LF
	DB	'T - Test Mode                | X - Exit to CP/M',CR,LF,LF
	DB	'Enter choice(s): ','$'

; re-do message

RE$DO	DB	'---> Enter a character from the MENU below',CR,LF,LF,'$'

; escape and control code table.  see ids owner's manual for full explanation
; of sequence codes.

IN4	DB	ESC,'J,48,1584',CR   	;indent left .4 inch (in)
	DB	5,6,'$'			;no justify, fixed spacing
IN12	DB	ESC,'J,144,1584',CR  	;indent left 1.0 inch (in)
	DB	5,6,'$'
NPS	DB	ESC,'J,120,960',CR   	;margins set to 1" and 8"
	DB	5,16      		;no justify, proportional spacing (np)
	DB	2,29,'$'  		;set to normal mode, 10cpi pitch
JPSB	DB	ESC,'J,120,852',CR   	;margins set to 1" and 7.1"
	DB	4,16	  		;justified, proportional spacing (jp)
	DB	1,31,'$'  		;set to 8.4 cpi enhanced mode (11cpi)
JPSN	DB	ESC,'J,120,852',CR	;margins set to 1" and 7.1"
	DB	4,16			;justified, proportional spacing
	DB	2,29,'$'                ;set to 10 cpi normal mode
FS	DB	ESC,'J,120,840',CR   	;margins set to 1" and 7"
	DB	5,6       		;un-justified, fixed spacing (fs)
	DB	2,29,'$'  		;set to normal mode, 10cpi pitch
DFS	DB	ESC,'J,0,1584',CR  	;default settings of printer
	DB	5,6			;no justify, fixed spacing (dfs)
	DB	2,29,'$'		;normal mode, 10cpi pitch
LPI3	DB	ESC,'B,16',CR,'$'	; 3..
LPI4	DB	ESC,'B,12',CR,'$'	;..4..
LPI6	DB	ESC,'B,8',CR,'$'	;..6..
LPI8	DB	ESC,'B,6',CR,'$'	;..and 8 lines per inch.
CPI10	DB	29,'$'			; 10..
CPI12	DB	30,'$'			;..12 and..
CPI168	DB	31,'$'			;..16.8 characters per inch.
PS	DB	16,'$'	 		;proportional spacing
JUST	DB	4,'$'		 	;justify text
NOJUST	DB	5,'$'			;no justify
NORMAL	DB	2,'$' 	 		;normal mode
ENHANCE	DB	1,'$'		 	;enchanced mode (double cpi)
FF	DB	12,'$'			;output printer form-feed and..
LINEF	DB	10,'$'			;..line-feed.

; character-set test strings

TEST	DB	CR,LF,'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	DB	CR,LF,'abcdefghijklmnopqrstuvwxyz'
	DB	CR,LF,'1234567890-=`\;,./[]'''
	DB	CR,LF,'!@#%^&*()_+~":<>?{}|',CR,LF,'$'

; u n i n i t i a l i z e d   s t o r a g e   a r e a

OLDSTAK	DS	2			;old stack address

	END	SOURCE
