; TITLE  PTR   A PROGRAM TO CONFIGURE THE NEC-8023 A-C
;              OUTSIDE OF A TEXT EDITOR
; AUTHOR  David Allan Giunti
;         in 8080 ASSEMBLER
;         USE ASM.COM TO COMPILE
; DATE    OCT 1983
; PURPOSE TO SET PRINT STYLE FOR LISTINGS 
; AN ENHANSEMENT OF ROBERT LA FARA'S PRINTER SETTING 
; UTILITY IN THE OCTOBER 83 EDITION OF MICROSYSTEMS
;
; NOTES FOR ADAPTATION TO OTHER PRINTERS
; NOTE THAT THIS PROGRAM OUTPUTS TO THE LiST DEVICE 
; 2 SORTS OF CODE SEQUENCES <ESC> + CHR , AND 
; JUST 1 CHR AT A TIME
; YOUR PRINTER DOCUMENTATION SHOULD TELL YOU WHICH
; YOU NEED FOR WHAT. MODIFICATION FOR DIFFERENT
; ESC & CHR SEQUENCES IS CHANGING THE EQUates AT
; THE HEADING, MODIFICATION OF THE PARSE-ING ROUTINE
; SO THAT THE ROUTIEN IT CALLS CALLS THE APPROPRIATE
; SEQUENCE TO DO THE WORK. 

BDOS	EQU	5  ; CALL HERE FOR CPM SERVICE
	;
	; in response to HOWTOHACK.DOC ... CALL here 
	; do not use addresses peaked here to jump into
	; BIOS...  
	; and please forgive the EQUates , they make the 
	; code 1 BYTE smaller per use and are twice as
	; fast as address references 
	; ... when you update object code (AND(NOT(source)))
	;     you create undocumented features
	; 
CONOUT	EQU 	2  ; OUTPUT TO CONSOLE, 1 CHR AT A TIME  
LSTOUT	EQU	5  ; OUT TO PRINTER, 1 CHR AT A TIME
CONDIR	EQU	6  ; GET-CHR FROM CONSOLE, 1 CHR AT A TIME
PRTSTR	EQU	9  ; OUTPUT TO CONSOLE, END STRING WITH $

LF	EQU	0AH
CR	EQU	0DH
BELL	EQU	7	; CHIME CHR
FSTR	EQU	0CH	; FORM_FEED CHR
ESCAPE	EQU	1BH	; ESCAPE CHR

;  NEC-8023 DIRECTIONS, WITH OUT ESCAPE 
  
ENL	EQU	0EH	; ENLARGED CHRS IN ALL STYLES
ENLCXL	EQU	0FH	; CANCEL ENLARGEMENT
DARK	EQU	21H	; DOUBLE STRIKE ENHANSED
LIGHT	EQU	22H	; RETURN FROM ENHANSED
;   NEXT TWO WERE NOT IMPLEMENTED
LVFU	EQU	1DH	; START LOAD OF VFU BUFFER
FINVFU	EQU	1EH	; END OF FILL
 
;  EQUS FOR ESCAPES IN NEC 8023 A-C

PICA	EQU	4EH	; 10 CPI
PROP	EQU	50H	; PROPORTIONAL CHRS
;   ESC 1 TO 6 SET MIN DOTSPACES BETWEEN WORDS (NOT IMPLEMENTED)
COND	EQU	51H	; 12 CPI
ELIT	EQU	45H	; 17 CPI
ALPHA	EQU	24H	; SET ALPHANEUMERIC 
EIGHT	EQU	42H	; 1/8 LINE SPACING
SIXT	EQU	41H	; 1/6 LINE SPACING
; FOLLOWING NOT USED HERE
IG	EQU	23H	; GREEK & INTERNAL GRAPHICS
INCRE	EQU	5BH	; PRINT AS RECIEVED FROM
LOGICS	EQU	5DH	; LOGIC SEEKING MODE

CLRTAB	EQU	32H	; CLEAR PRESET TABS
UNL	EQU	58H	; START UNDERLINE
UUL	EQU	59H	; STOP UNDERLINE
FORWRD	EQU	66H	; FEED PAPER FORWARD
REVRSE	EQU	72H	; REVERSE PAPER FEED



	ORG	100H   ;FIRST ADDRESS IN CPM
			; that is all yours
	LXI	SP,STKTOP   ;SET STACK AFTER PROG
MENU:	MVI	C,PRTSTR    ;DISPLAY MENU		
			   ;PRAM REG, FCN TO CALL
	LXI	D,MENDAT    ; LOAD ADDRESS IN DE
	CALL	BDOS	; WITH REGS LOADED CALL CPM

CHARIN:	MVI	C,CONDIR   ;DIRECT CONSOLE INPUT
	MVI	E,0FFH	   ;ASK FOR INPUT
	CALL	BDOS
	CPI	0	;IS ANYTHING TYPED ?
	JZ	CHARIN   ; IF NOT LOOP
	STA	CHAR	;IF SOMTHING SAVE IT
	MVI	C,CONOUT   ;ECOE TO SCREEN
	MOV	E,A
	CALL	BDOS
;
;  PARSER  CHECKS VALID INPUT, CALLS WORKING ROUTIENS
;          AND IF NOT A VALID COMAND INFORMS USER
;
;	TEST INPUT FOR VALID CHARACTERS
;	JuMP ACCORDINGLY
;
	LDA	CHAR	;START TEST AGAINST ACCUM
	CPI	' '	; ComPair to ' '
	JZ	CHARIN	; SKIP SPACES

	CPI	'5'	; LARGE PICA
	JZ	LP	;

	CPI	'6'	; LARGE ELITE
	JZ	LEL	;

	CPI	'8'	; 
	JZ	LCON	; LARGE CONDENSED

	CPI	'1'	; PICA
	JZ	PIC	;

	CPI	'2'	; ELITE
	JZ	EL	;

	CPI	'7'	; CONDENSED
	JZ	CON	;

;  IF IT ISN'T A NUMBER IT'S A LETTER
	ANI	5FH	; AND TO CONVERT TO UPPERCASE
	STA	CHAR	; STASH UCASED CHR IN CHAR

	CPI	'R'	; RETURN TO SMALL CHRS
	JZ	SMAL
 
	CPI	'B'	; LARGE PROPORTIONAL
	JZ	LPR

	CPI	'P'	; PROPORTIONAL
	JZ	PRO	;

	CPI	'D'	; ENHANSED DOUBLE STRIKE 
	JZ	ENH	;

	CPI	'L'	; RETURN FROM ENHANSED
	JZ	UNEN	;

	CPI	'Q'	; COLD BOOT
	JZ	QUIT	;

	CPI	 'S'	; 1/6 " SPACING
	JZ	SIX	;

	CPI	 'E'	; 1/8 " SPACING
	JZ	EIG	;

;
;       IF YOU GOT THIS FAR AND NOTHING MATCHED
;       INPUT WAS NOT VALID   ISSUE ERROR MESSAGE
;
ERMSG:	MVI	C,PRTSTR  ; PRINTSTRING FCN
	LXI	D,ERRMSG  ; ADDRESS OF MSG IN DE
	CALL	BDOS
	JMP	MENU
;
;   SUBROUTIENS HERE ARE RECURSIVE
;       SOME REQUIRE CHR OUTPUT THEN <ESC> CHR
;	OUTPUT
;

LP:	CALL	BIGPR
	JMP	PIC

LEL:	CALL	BIGPR
	JMP	EL

LPR:	CALL	BIGPR
	JMP	PRO

LCON:	CALL	BIGPR
	JMP	CON

PIC:	MVI	A,PICA
	JMP	EPTR

EL:	MVI	A,ELIT
	JMP	EPTR

PRO:	MVI	A,PROP
	JMP	EPTR

CON:	MVI	A,COND
	JMP	EPTR

ENH:	MVI	A,DARK
	JMP	EPTR

UNEN:	MVI	A,LIGHT
	JMP	EPTR

SMAL:	MVI	E,ENLCXL
	CALL	SPR
	JMP	MENU

SIX:	MVI	A,SIXT
	JMP	EPTR

EIG:	MVI	A,EIGHT
	JMP	EPTR

;	
;   THIS ROUTINE GIVES THE ARGUMENT LOADED IN A TO
;   A LOCATION SET ASIDE IN RAM  (ARG1)
;   THE ROUTINE EPTR1 DOES NOT CARE HOW MANY 
;   CHARACTERS YOU WISH TO PRINT AFTER THE ESCAPE
;   IF YOUR PRINTER WANTS MORE CHARACTERS AFTER
;   THE <ESC>  SEE THE NOTES DOWN AT THE END
;
EPTR:	STA	ARG1
	LXI	H,ESTR	; POINT TO ESCAPE STRING
EPTR1:	SHLD	INDEX	; STORE ADDRESS
	MOV	E,M	; GET CHR
	MOV	A,E	; PUT IN A ALSO
	CPI	'$'	;CHECK TRAILOR CARD
	JZ	MENU	;     IF SO END
	MVI	C,LSTOUT  ; PRINT 1 CHR
	CALL	BDOS	; DO IT
	LHLD	INDEX	; RELOAD POINTER
	INX	H	; POINT TO NEXT CHR
	JMP	EPTR1

BIGPR:	MVI	E,ENL	; SUBROUTIEN TO LOAD ENLARGE 
SPR:	MVI	C,LSTOUT	; WHEN YOU LAND HERE YOU HAVE
				; ALLREADY LOADED E WITH THE
				; CHR YOU WISH TO OUTPUT
				; TO PRINT BUFFER
	CALL	BDOS		; NO CR REQUIRED
	RET

QUIT:	MVI	C,0
	CALL	BDOS	; WARM BOOT

MENDAT:	DB	CR,LF,'           PRINTER OPTIONS MENU',CR,LF,LF
	DB	' 5  : 5   CPI ENLARGED PICA',CR,LF
	DB	' 6  : 6   CPI ENLARGED ELITE',CR,LF 
	DB	' B  : 7.5 CPI ENLARGED CONDENSED',CR,LF	
	DB	' 8  : 8.5 CPI ENLARGED PROPORTIONAL',CR,LF
	DB	' 1  : 10  CPI PICA (default)',CR,LF
 	DB	' 2  : 12  CPI ELITE',CR,LF
	DB	' P  : 15  CPI PROPORTIONAL',CR,LF
	DB	' 7  : 17  CPI CONDENSED  (CAN''T DARKEN)',CR,LF,LF
	DB	' R  : RETURN FROM ENLARGED CHARACTERS',CR,LF
	DB	' D  : DARKEN',CR,LF
	DB	' L  : LIGHTEN default (Return from darken)',CR,LF
	DB	' S  : 1/6 " SPACING (default)',CR,LF
	DB	' E  : 1/8 " SPACING',CR,LF
	DB	' Q  : QUIT * Warm Boot*',CR,LF,LF
	DB	' ENTER OPTION... '
	DB	'$'   ; the dollar sign IS required for the screen 
ERRMSG:	DB	CR,LF,BELL,'NO SUCH OPTION... TRY AGAIN',CR,LF,'$' 
;
;	THIS IS THE FABELED ESCAPE SEQUENCE
ESTR:	DB	ESCAPE
ARG1	DS	1	; ESCAPES ARGUMENT
			; YOU CAN DS (Define Space) IN
			; BYTES TO YOUR HEARTS CONTENT
	DB	CR	; ... REMEMBER MOST PRINTERS 
			; WANT A CR TO GET THE BALL ROALING
			; AND THE OUTPUT ROUTIEN WANTS THE
			; $ CHR TO KNOW WNEN TO STOP
	DB	'$'	; the dollar sign is optional here
			; ...any other unused value 
			; would work as well  
;
CHAR:	DS	1
INDEX:	DS	2
	DS	32	; 16 LEVEL STACK
STKTOP:
	END   
