;((((((((((((((((((  GEMSET.ASM  ))))))))))))))))))
;                     01/16/86
;          (c)Copyright January 17, 1986
;               All rights reserved
;                   Curt Edwards
;
;
;NOTICE:
;I release this program to the public domain, to be used
;freely and distributed among users.  But under no
;circumstance shall it be used for profit or personal
;monetary gain.
;
;CREDITS:
;This program is almost a complete rewrite of the
;original GEMINI.ASM by Jim Schenkel on 2/10/83. He
;adapted his version from EPSET2.ASM written by,
;Kent Walker in 10/82 and corrected by Jim Wooley
;in 11/82.
;
;MODIFICATIONS:
;
; 1) Added capitialization routine to knock down the
;    redundency on evaluating user input.
;
; 2) Added the ability to patch screen codes to pretty
;    up the screen display.
;
; 3) Added some screen clean up routines for after a
;    selection is made.  Also added status prompts
;    to acknowledege what function was selected.
;
;PURPOSE:
;This program allows setting all the availible parameters
;of a Gemini 10 or 15X printer from the keyboard.  
;The user is presented a menu of options to choose 
;from.  The program is terminated with a carrige 
;return.
;
;UPDATES:
;I would appreciate it if any updates or modifications
;could be sent to me at the following address or by modem
;to my system.
;
;               Curt Edwards, Sysop
;          SoftStone RCP/M FOG System #24
;                   P.O. Box 694
;               Louisville, Ky 40014
;                  (502) 241-4109
;           24hrs 7 days - 300/1200 baud
;
;
;Now on with the code....     
;
;--------------------------------------------------
;<<<<<<<<<<<<<<<<<<<< Bdos Call Equates >>>>>>>>>>>     
;--------------------------------------------------
;
	bdos	equ	05h	;bdos
	boot	equ	00h	;reset (warm boot)
	conin	equ	01h	;console input
	conout	equ	02h	;console output
	prints	equ	09h	;print string
	lstchr	equ	5	;lst device function

;
;---------------------------------------------------
;<<<<<<<<<<<<<<<<<<<< Misc Equates >>>>>>>>>>>>>>>>>
;---------------------------------------------------
;

	bs	equ	08h	;back space
	bell	equ	07h	;bell
	cr	equ	0dh	;carrige return
	lf	equ	0ah	;line feed
	tab	equ	09h	;tab
	esc	equ	1bh	;escape
;
;--------------------------------------------------
;<<<<<<<<<<<<<<<<<<<< End of Equates  >>>>>>>>>>>>>
;--------------------------------------------------
;Offical Start of program |
;--------------------------
;
	org 	100h
	jmp	begin
;
;-----------------------
;Code some info in file |
;-----------------------
;
coding:
	db	'GEMSET.ASM      '	
	db	'Version 2.0     '	
	db	'By Curt Edwards '
	db	'(c)May 17, 1985 '
;
;-------------------------------------------
;This is the area to patch for screen codes |
;-------------------------------------------
;
	db	' PATCH AREA '
	db      ' CLSCR->'	;Embeds ASCII pointer to bytes
clscr:  db	0,'$'		;for clear screen
	db  	' REVON->'	;ASCII pointer to bytes
revon:	db	0,0,0,0,0,0,'$'	;for reverse or half ON
        db      ' REVOFF->'	;ASCII pointer to bytes
revoff: db      0,0,0,0,0,0,'$'	;for reverse or half OFF

;
;-------------------
;Set up Local Stack |
;-------------------
;
begin:
   	lxi	h,0		;zero hl register pair
  	dad	sp		;add the stack pointer
  	shld	oldsp		;store oldsp to restore when done
  	lxi	sp,stktop	;point to new local stack
;
;-------------------------------
;Actual working code starts here |
;--------------------------------
;
start:	call	cls		;clear screen
	call	prntmenu	;print the menu
getit:	mvi	c,conin		;get input
	call	bdos
 	cpi	cr		;is it a carrige return 
	jz	fini		;yes then exit  
	call	case		;translate to upper case
	
;Let's see what they want

	lxi	h,belon
	lxi	d,belonm
	cpi	'A'
	jz	list

	lxi	h,beloff
	lxi	d,beloffm
	cpi	'B'
	jz	list

	lxi	h,comp
	lxi	d,compm
	cpi	'C'
	jz	list

	lxi	h,uncomp
	lxi	d,uncompm
	cpi	'D'
	jz	list

	lxi	h,emph
	lxi	d,emphm
	cpi	'E'
	jz	list

	lxi	h,noemph
	lxi	d,noemphm
	cpi	'F'
	jz	list

	lxi	h,dblstr
	lxi	d,dblstrm
	cpi	'G'
	jz	list

	lxi	h,snglstr
	lxi	d,snglstrm
	cpi	'H'
	jz	list

	lxi	h,italic
	lxi	d,italicm
	cpi	'I'
	jz	list

	lxi	h,noital
	lxi	d,noitalm
	cpi	'J'
	jz	list

	lxi	h,pica
	lxi	d,picam
	cpi	'K'
	jz	list

	lxi	h,elite
	lxi	d,elitem
	cpi	'L'
	jz	list

	lxi	h,biprn
	lxi	d,biprnm
	cpi	'M'
	jz	list

	lxi	h,uniprn
	lxi	d,uniprnm
	cpi	'N'
	jz	list

	lxi	h,sensor
	lxi	d,sensorm
	cpi	'S'
	jz	list

	lxi	h,ignsen
	lxi	d,ignsenm
	cpi	'T'
	jz	list

	lxi	h,uline
	lxi	d,ulinem
	cpi	'U'
	jz	list

	lxi	h,noul
	lxi	d,noulm
	cpi	'V'
	jz	list

	lxi	h,wide
	lxi	d,widem
	cpi	'W'
	jz	list

	lxi	h,narrow
	lxi	d,narrowm
	cpi	'X'
	jz	list

	lxi	h,slash
	lxi	d,slashm
	cpi	'Y'
	jz	list

	lxi	h,noslsh
	lxi	d,noslshm
	cpi	'Z'
	jz	list

	lxi	h,sixlpi
	lxi	d,sixlpim
	cpi	'6'
	jz	list

	lxi	h,atelpi
	lxi	d,atelpim
	cpi	'8'
	jz	list

	lxi	h,tenlpi
	lxi	d,tenlpim
	cpi	'9'
	jz	list

	lxi	h,reset
	lxi	d,resetm
	cpi	'R'
	jz	list

	jmp 	getit

fini:	
	call	cls
	lxi	h,oldsp	;load h with old stack pointer
	sphl		;put it in the stack pointer
	jmp	wmboot  ;reset the disk system
	ret		;back to cpm
;
;--------------------------------------------------
;<<<<<<<<<< E N D   O F   P R O G R A M  >>>>>>>>>>
;--------------------------------------------------

;--------------------------------------------------
;<<<<<<<<<<<<<<<<< SUBROUTINES >>>>>>>>>>>>>>>>>>>>
;--------------------------------------------------
;Clears Screen |
;--------------
;
cls:
	push d! push b! push h
	lxi	d,clscr
	mvi	c,prints
	call	bdos
	pop h! pop b! pop d
	ret
;	
;--------------------------------------------------
;Prints the Menu |
;----------------
;
prntmenu:
	push d! push b! push h
	lxi	d,signon
	mvi	c,prints
	call	bdos
	call	vidon
	lxi	d,head
	mvi	c,prints
	call	bdos
	call	vidoff
	lxi	d,menu
	mvi	c,prints
	call	bdos
	call	vidon	
	lxi	d,prompt
	mvi	c,prints
	call	bdos
	call	vidoff
	pop h! pop b! pop d
	ret
;
;----------------
;Menu Text Table |
;----------------
;
signon:	db	' GEMSET Vers 20 - By Curt Edwards' ,cr,lf
	db	'(c) May 17, 1985 All Rights Reserved',cr,lf,'$'

head:	db	'Star Micronics GEMINI 10 & 15X Set-Up Utility' ,cr,lf,lf,'$'

menu:	db	tab,'       PRESS RETURN TO EXIT'		  ,cr,lf,lf
	db	'A = Bell ON              B = Bell OFF'		  ,cr,lf
	db	'C = Compressed ON        D = Compressed OFF'	  ,cr,lf
	db	'E = Emphasized ON        F = Emphasized OFF'	  ,cr,lf
	db	'G = Double Strike ON     H = Double Strike OFF'  ,cr,lf
	db	'I = Italics Font         J = Regular Font'	  ,cr,lf
	db	'K = Pica Pitch           L = Elite Pitch'	  ,cr,lf
	db	'M = Bi-directional ON    N = Bi-directional OFF' ,cr,lf
	db	'S = Paper-end Sensor ON  T = Paper-end Sensor OFF',cr,lf
	db	'U = Underlining ON       V = Underlining OFF'    ,cr,lf
	db	'W = Double Wide Pitch ON X = Double Wide Pitch OFF',cr,lf
	db	'Y = Slashed Zeroes ON    Z = Slashed Zeroes OFF' ,cr,lf
	db	'              6 = 6 Lines Per Inch'		  ,cr,lf
	db	'              8 = 8 Lines Per Inch'		  ,cr,lf
	db	'              9 = 10.2 Lines Per Inch'		  ,cr,lf,lf
	db	'R = Reset Printer to Standard Settings'	  ,cr,lf,lf
	db	tab,'$'

prompt:	db	'Enter Selection ]--> ','$'
;
;-------------------------------------------------- 
;Turn on enhanced video |
;-----------------------
vidon:
	push d! push b! push h	;save enviroment
	lxi 	d,revon
	mvi	c,prints
	call	bdos
	pop h! pop b! pop d	;restore enviroment
	ret			;return to calling routine
;
;--------------------------------------------------
;Turn off enhanced video |
;------------------------
;
vidoff:
	push d! push b! push h	;save enviroment          
	lxi	d,revoff
	mvi	c,prints
	call	bdos
	pop h! pop b! pop d     ;restore enviroment       
	ret                     ;return to calling routine
;
;--------------------------------------------------
;Translate lower case to uppercase |
;----------------------------------
;
case:
	push b! push d! push h
	cpi	'a'	;is it in the lower case range?
	rc		
	cpi	'z'+1
	rnc
	ani	5fh	;yes mask it
	pop h! pop d! pop b
	ret		;and return
;
;---------------------------------------------------
;Sends printer string to printer & message to |
;console.                                     |
;---------------------------------------------
;

list:
	push	h! push d	;save string pointers
	call	cls		;clear screen
	lxi	d,lines		;Send 10 line feeds to center message
	mvi	c,prints	;print them
	call	bdos	
	call	vidon		;turn on video
	pop	d		;restore message pointer
	mvi	c,prints	;print it
	call	bdos
	call	vidoff		;turn of video
	mvi	b,3		;set up outside delay counter
delay1:	lxi	d,0ffffh	;set up inside delay counter
delay2:	dcx	d		;dcr second
	mov	a,e		;get it in a
	ora	d		;is it zero
	jnz	delay2		;do it again
	dcr	b		;dcr first
	jnz	delay1		;not zero so loop
	pop	h		;restore pointer
loop:	mov	e,m		;first byte in e reg
	push	h		;save pointer
	mvi	c,lstchr	;set up output to printer call
	call	bdos		;send it
	pop	h		;restore pointer
	inx	h		;bump it
	mov	a,m		;get next char in a
	cpi	'$'		;is the the end?
	jz	start		;yes, go get next user input
	jmp	loop		;no, get next char

lines:	db	lf,lf,lf,lf,lf,lf,lf,lf,lf,'$'

;
;---------------------------------------------------
;Reset System (warm boot) |
;-------------------------
wmboot:
	push b! push d! push h
	mvi	c,boot
	call	bdos
	pop h! pop d! pop b
	ret
;
;---------------------------------------------------
;Storage areas for printer codes and console status |
; messages                                          |
;---------------------------------------------------
;
;
beloff	db	esc,'Y',01,'$'
beloffm db      cr,lf,lf,lf,07h,'Bell is now OFF !','$'

belon	db	esc,'Y',00,'$'
belonm  db	cr,lf,lf,lf,07h,'Bell is now ON !','$'

comp	db	0fh,'$'
compm	db	cr,lf,lf,lf,07h,'Compressed mode is now ON !','$'

uncomp	db	12h,'$'
uncompm	db	cr,lf,lf,lf,07h,'Compressed mode is now OFF !','$'

pica	db	esc,'B',01,'$'
picam	db	cr,lf,lf,lf,07h,'Pica Font is now ON !','$'

elite	db	esc,'B',02,'$'
elitem	db	cr,lf,lf,lf,07h,'Elite Font is now ON !','$'

emph	db	esc,'E','$'
emphm	db	cr,lf,lf,lf,07h,'Emphasized mode is now ON !','$'

noemph	db	esc,'F','$'
noemphm	db	cr,lf,lf,lf,07h,'Emphasized mose is now OFF !','$' 

dblstr	db	esc,'G','$'
dblstrm	db	cr,lf,lf,lf,07h,'Double Strike mode is now ON !','$'
 
snglstr	db	esc,'H','$'
snglstrm db	cr,lf,lf,lf,07h,'Double Strike mode is now OFF !','$'

biprn	db	esc,'U',00,'$'
biprnm	db	cr,lf,lf,lf,07h,'Bi-Directional print is now ON !','$'

uniprn	db	esc,'U',01,'$'
uniprnm	db	cr,lf,lf,lf,07h,'Bi-Directional print is now OFF !','$'

slash	db	esc,'V',01,'$'
slashm	db	cr,lf,lf,lf,07h,'Zeroes will now be Slashed !','$'
 
noslsh	db	esc,'V',00,'$'
noslshm	db	cr,lf,lf,lf,07h,'Zeroes will not be Slashed !','$'

wide	db	esc,'W',01,'$'
widem	db	cr,lf,lf,lf,07h,'Double-wide mode is now ON !','$'
 
narrow	db	esc,'W',00,'$'
narrowm db	cr,lf,lf,lf,07h,'Double-wide mode is now OFF !','$'

atelpi	db	esc,'O','$'
atelpim db	cr,lf,lf,lf,07h,'Printer is now in 8 lines per inch mode !','$'

tenlpi	db	esc,'1','$'
tenlpim	db	cr,lf,lf,lf,07h,'Printer is now in 10.2 lines per inch mode !','$'

sixlpi	db	esc,'2','$'
sixlpim	db	cr,lf,lf,lf,07h,'Printer is now in 6 lines per inch mode !','$'

italic	db	esc,'4','$'
italicm	db	cr,lf,lf,lf,07h,'Italics mode is now ON !','$'

noital  db	esc,'5','$'
noitalm	db	cr,lf,lf,lf,07h,'Italics mode is now OFF !','$'

ignsen	db	esc,'8','$'
ignsenm	db	cr,lf,lf,lf,07h,'Paper sensor is now OFF !','$'

sensor	db	esc,'9','$'
sensorm	db	cr,lf,lf,lf,07h,'Paper sensor is now ON !','$'

reset	db	esc,'@','$'
resetm	db	cr,lf,lf,lf,07h,'Your gemini is now RESET to it''s defaults settings!','$'

uline	db	esc,2dh,01,'$'
ulinem	db	cr,lf,lf,lf,07h,'Underline mode is now ON !','$'

noul	db	esc,2dh,00,'$'
noulm	db	cr,lf,lf,lf,07h,'Underline mose is now OFF !','$'

;
;Reserve Memory For Local Stack 
;
oldsp:	ds	2	;old stack pointer
	ds	32	;new stack

stktop:
;
	end	100h
