
; menu driven program to initialize the ids 460/560
; and prism dot matrix printers.

; written by frank gaude' -- 10/6/1982

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

; equates

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	;the horizontal tab character
LF	EQU	0AH	;ascii line feed and..
CR	EQU	0DH	;..carriage return character.
ESC	EQU	27	;the escape code (01bh) into ids program

; main-line routine

BEGIN	CALL	SAVSTAK	;save old stack pointer
	CALL	CLS	;start fresh
	LXI	D,MENU	;address of string into the de register
	MVI	C,PRINT	;display above message
	CALL	BDOS	;it's done
	CALL	INPUT	;see what's the choice
	CALL	GETSTAK	;smooth exit back to cp/m ccp (cbase)

; subroutines

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	'A'	;test keyboard input
	JZ	TEXTOUT	;string out to printer
	LXI	D,IN12	;..2nd..
	CPI	'B'
	JZ	TEXTOUT
	LXI	D,NPS	;..etc.
	CPI	'C'
	JZ	TEXTOUT
	LXI	D,JPS
	CPI	'D'
	JZ	TEXTOUT
	LXI	D,JFS
	CPI	'E'
	JZ	TEXTOUT
	LXI	D,
	CPI	'F'
	JZ	TEXTOUT
	LXI	D,DFS
	CPI	'Z'
	JZ	TEXTOUT
	JMP	INPUT	;loop till a valid input is entered

; string out to printer
 
TEXTOUT	LDAX	D	;load character into a-register
	CPI	'$'	;is it the end of string?
	RZ		;if so, return to main line..
	PUSH	D	;..else save the pointer.
	MOV	E,A	;character into the e register for bdos
	MVI	C,LIST	;tell bdos to output to list device
	CALL	BDOS	;it's done!
	POP	D	;restore the pointer
	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 the ascii lf in a
	MVI	C,WRCON
 	PUSH	B	;save the 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 the ccp

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

; place cp/m stack at original location

GETSTAK	LHLD	OLDSTAK	;get old stack pointer
	SPHL		;put it into sp register
	RET		;quietly/quickly return to cp/m ccp

; initialized storage area begins
; main menu

MENU	DB	HT,'IDS 460/560/PRISM Printer Initialization'
	DB	CR,LF,LF
	DB	HT,HT,'A - Indent left four spaces',CR,LF
	DB	HT,HT,'B - Indent left twelve spaces',CR,LF
	DB	HT,HT,'C - Justified Proportional Spacing',CR,LF
	DB	HT,HT,'D - Unjustified Proportional Spacing',CR,LF
	DB	HT,HT,'E - Justified Fixed Spacing',CR,LF
	DB	HT,HT,'F -',CR,LF
	DB	HT,HT,'Z - Default Printer Settings',CR,LF
	DB	LF,HT,HT,'Enter choice: $'

; 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-spaces (in)
	DB	5,6		;no justify, fixed spacing
	DB	2,29,'$'	;set to normal mode, 10cpi pitch
IN12	DB	ESC,'J,144,1584',CR  ;indent left 12-spaces (in)
	DB	5,6
	DB	2,29,'$'
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
JPS	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)
JFS	DB	ESC,'J,120,840',CR   ;margins set to 1" and 7"
	DB	4,6       ;justified, fixed spacing (jf)
	DB	2,29,'$'  ;set to normal mode, 10cpi pitch
DFS	DB	ESC,'J,0,1584',CR  ;default condition of printer
	DB	5,6		;no justify, fixed spacing (df)
	DB	2,29,'$'	;normal mode, 10cpi pitch

; uninitialized area

OLDSTAK	DS	2	;old stack address

	END	SOURCE
