;**************************************************************
;
;	PROGRAM NAME:OKIDATA MICROLINE 82A SETUP
;	WRITTEN BY  :W.M.STEELE    SEPT. 25,1984
;
;**************************************************************
;
;CP/M ADDRESSES:
;
BASE	EQU	00H		;standard CP/M Base
WBOOT	EQU	BASE+03H	;addr.of vector to warm boot
BDOS	EQU	BASE+05H	;addr.of vector to BDOS entry
TPA	EQU	BASE+100H	;begin.of std.trans.program area
;
;BDOS FUNCTIONS:
;
KEYIN	EQU	01H		;get char.fr.keyboard to CRT
DSPLCHR EQU	02H		;display char.on CRT
LSTOUT	EQU	05H		;send char. to LST: device
DSPLSTG EQU	09H		;display string on CRT
;
;SCREEN CONTROLS:
;
CTRLC	EQU	03H		;restart
TAB	EQU	09H		;tab 8 spaces
LF	EQU	0AH		;linefeed
CR	EQU	0DH		;carriage return
CLR	EQU	1AH		;clear screen & home cursor
ESC	EQU	1BH		;escape
;
;PRINTER CONTROLS:
;
FORMFD	EQU	0CH		;formfeed
PRTRCLR EQU	18H		;clear printer buffer
CPI17	EQU	1DH		;set 16.5 char./in.
CPI10	EQU	1EH		;set 10 char./in.
WIDEON	EQU	1FH		;set wide characters on
BRITE	EQU	28H		;full intensity
DIM50	EQU	29H		;1/2 intensity
SETTOP	EQU	'5'		;set top of form
LPI06	EQU	'6'		;set 6 lines/in.
LPI08	EQU	'8'		;set 8 lines/in.
CPL80	EQU	'A'		;set 80 char./line (no side margins)
CPL64	EQU	'B'		;set 64 char./line (1" side margins)
FMLGTH	EQU	'F'		;set form length
;
;***************************************************************
;
	ORG	TPA
	JMP	PROLOG
;
;***************************************************************
;
MENU:	DB	CLR,LF,ESC,BRITE,CR
	DB	TAB,'   Printer Setup for OKIDATA 82A',CR,LF
	DB	TAB,'By: W.M.Steele  Dated: Sept. 25,1984',CR,LF,LF
	DB  ESC,DIM50,TAB,'Dimmed lines are modes set.',CR,LF,LF
	DB  ESC,BRITE,TAB,'Set Wide Char. AFTER (1) or (5)',CR,LF,LF
LINEA:	DB  ESC,BRITE,TAB,'CORRESPONDENCE MODE',CR,LF
LINE1:	DB  ESC,DIM50,TAB,TAB,'(1) 10 Characters per inch',CR,LF
LINE2:	DB  ESC,DIM50,TAB,TAB,'(2) 6 Lines per inch',CR,LF
LINE3:	DB  ESC,DIM50,TAB,TAB,'(3) 1" Side margins',CR,LF
LINE4:	DB  ESC,DIM50,TAB,TAB,'(4) 66 Lines per page',CR,LF,LF
LINEB:	DB  ESC,BRITE,TAB,'COMPRESSED MODE',CR,LF
LINE5:	DB  ESC,BRITE,TAB,TAB,'(5) 16.5 Characters per inch',CR,LF
LINE6:	DB  ESC,BRITE,TAB,TAB,'(6) 8 Lines per inch',CR,LF
LINE7:	DB  ESC,BRITE,TAB,TAB,'(7) No Side margins',CR,LF
LINE8:	DB  ESC,BRITE,TAB,TAB,'(8) 88 Lines per page',CR,LF,LF
LINE9:	DB  ESC,BRITE,TAB,TAB,'(9) Wide Characters',CR,LF
LINE0:	DB  ESC,BRITE,TAB,TAB,'(0) or (CTRL-C)	Done',CR,LF,LF
	DB  ESC,BRITE,TAB,TAB,TAB,'SELECT: ','$'
SETA:	DB	CPI10,ESC,LPI06,ESC,CPL64
SET4:	DB	ESC,FMLGTH,'66',00
SET1:	DB	CPI10,00
SET2:	DB	ESC,LPI06,00
SET3:	DB	ESC,CPL64,00
SET5:	DB	CPI17,00
SET6:	DB	ESC,LPI08,00
SET7:	DB	ESC,CPL80,00
SET8:	DB	ESC,FMLGTH,'88',00
SET9:	DB	WIDEON,00
SET0:	DB	ESC,SETTOP,CR,PRTRCLR,CR,00
;
PROLOG: LXI H,	0000H	;clear HL
	DAD 	SP	;add stack pointer
	SHLD	OLDSP	;store it
	LXI SP,	OLDSP	;get top of new stack
	LXI H,	SETA	;HL-->initial setup
	CALL	SETTER
PROGM:	LXI D,	MENU	;DE-->Menu
	MVI C,	DSPLSTG ;display it
	CALL	BDOS
	MVI C,	KEYIN	;get selection
	CALL	BDOS
	CPI	CTRLC	;exit?
	JZ	EPILOG	;if so--go
	CPI	'0'	;done?
	JZ	EPILOG	;if so--go
	JC	PROGM	;else is smaller than 1,try again
	CPI	'9'+1	;else if larger than 9--
	JNC	PROGM	;--again--try again
	SUI	30H	;make ASCII to hexidecimal
	LXI H,	TABLE-8	;get ready to select addr.fr.TABLE
PROGM1: STC		;set carry flag
	CMC		;now it's reset for sure
	RAL		;multiply
	RAL		;   hexidecimal
	RAL		;     selection by 8
	ADD	L	;add it L
	JNC	PROGM2	;if carry
	INR	H	;   increment H  
PROGM2: MOV L,	A	;put it back in L 
	MOV E,	M	;  HL points to addr.in
	INX	H	;  table to be dimmed
	MOV D,	M	;  get actual addr. in DE
	PUSH	H	;save table addr.	 
	XCHG		;and then get actual addr.to HL
DIMMER: MVI M,	DIM50	;dim the selection
	POP	H  	;get table addr.back	
	INX	H	;get next table addr.bytes
	MOV E,	M	;put them again in DE
	INX	H	
	MOV D,	M	
	PUSH	H	;save table pointer again
	XCHG		;and put actual addr. into HL
BRITER: MVI M,	BRITE	;brighten opposite selection
	POP	H	;get table addr.back again
	INX	H
	MOV E,	M
	INX	H
	MOV D,	M	;again, actual addr. to DE
	PUSH	H	;save it
	XCHG		;and put into HL
	MVI M,	BRITE	;selections (1) & (5) have two
	POP	H	;
	INX	H	;  'opposites' to brighten
	MOV E,	M	;
	INX	H	;    others just 'brighten' DUMMY
	MOV D,	M	;to DE
	XCHG		;to HL	
	CALL	SETTER	;HL--> the selection sequence
	JMP	PROGM	;start over for next selection
SETTER:	MOV A,	M	;get byte of selection sequence
	ORA	A	;is it the last one?
	RZ		;if so--return
	MOV E,	A	;else move char.to E
	PUSH	H	;save HL
	MVI C,	LSTOUT	;   and send it to printer
	CALL	BDOS	
	POP	H	;get HL back
	INX	H	;next byte?
	JMP	SETTER
EPILOG:	LXI H,	SET0	;final selection
	CALL	SETTER
	LHLD	OLDSP
	SPHL
	JMP	WBOOT
;
;**************************************************************
;
	DS	32	;program stack
OLDSP:	DS	2	;reserved for old stack addr.
TABLE:	DW	LINE1+1
	DW	LINE5+1
	DW	LINE9+1
	DW	SET1
	DW	LINE2+1
	DW	LINE6+1
	DW	DUMMY
	DW	SET2
	DW	LINE3+1
	DW	LINE7+1
	DW	DUMMY
	DW	SET3
	DW	LINE4+1
	DW	LINE8+1
	DW	DUMMY
	DW	SET4
	DW	LINE5+1
	DW	LINE1+1
	DW	LINE9+1
	DW	SET5
	DW	LINE6+1
	DW	LINE2+1
	DW	DUMMY
	DW	SET6
	DW	LINE7+1
	DW	LINE3+1
	DW	DUMMY
	DW	SET7
	DW	LINE8+1
	DW	LINE4+1
	DW	DUMMY
	DW	SET8
	DW	LINE9+1
	DW	DUMMY
	DW	DUMMY
	DW	SET9
DUMMY:	DB	00
	END	TPA
 	
 	      