ASxxxx Assembler V02.21  (Motorola 6809), page 1.
PHS Constant definitions
terminal screen control

                              1 	.sbttl	terminal screen control
                              2 
                              3 	.globl	tt_inp,	tt_out
                              4 
                              5 	.module	termio
                              6 
ASxxxx Assembler V02.21  (Motorola 6809), page 2.
PHS Constant definitions
terminal screen control

                              7 	.include	/define.def/
                              1 	.title	PHS Constant definitions
                              2 
                              3 
                              4 	.sbttl	VT1xx screen definitions
                              5 
                              6 	.radix	d
                              7 
                              8 ;
                              9 ;	VT1xx screen definitions
                             10 ;
                             11 
                    0050     12 	SCRNW	==	80		; screen width
                             13 
                    0000     14 	SCRNTP	==	 0		; ypos for top    line of edit area
                    0017     15 	SCRNBT	==	23		; ypos for bottom line of edit area
                    0000     16 	STATUS	==	 0		; ypos for status/command-input line
                             17 
                    0018     18 	SCRNL	==	24		; screen length
                             19 
                             20 
                             21 ; ----------------------------------------------------------
                             22 ; Definitions for various parameters
                             23 
                    FFFF     24 	ERR	==	(-1)
                    FFFE     25 	END	==	(-2)
                             26 
                    0000     27 	EOS	==	0
                    0001     28 	OK	==	1
                             29 
                    0000     30 	NO	==	0
                    0001     31 	YES	==	1
                             32 
                             33 ; ----------------------------------------------------------
                             34 ; Definitions for the Keypad
                             35 
                             36 			; zero not allowed
                    FFFF     37 	SELECT	==	 (-1)
                    FFFE     38 	CUT	==	 (-2)
                    FFFD     39 	APPEND	==	 (-3)
                    FFFC     40 	FNDNXT	==	 (-4)
                    FFFB     41 	GOLD	==	 (-5)
                    FFFA     42 	HELP	==	 (-6)
                    FFF9     43 	ENTER	==	 (-7)
                    0008     44 	SCRLL	==	   8	; backspace = 8
                    0009     45 	TAB	==	   9	; horizontal tab = 9
                    000A     46 	LF	==	  10	; linefeed = 10
                    000B     47 	SCRLU	==	  11	; vertical tab = 11
                    000C     48 	FF	==	  12	; formfeed = 12
                    000D     49 	CR	==	  13	; carriage return = 13
                    FFF2     50 	CHAR	==	(-14)
                    FFF1     51 	WORD	==	(-15)
                    FFF0     52 	LINE	==	(-16)
                    FFEF     53 	DELC	==	(-17)
                    FFEE     54 	DELW	==	(-18)
                    FFED     55 	DELL	==	(-19)
ASxxxx Assembler V02.21  (Motorola 6809), page 3.
PHS Constant definitions
VT1xx screen definitions

                    FFEC     56 	EOL	==	(-20)
                    0015     57 	CTRLU	==	  21	; ^U
                    FFEA     58 	ADVANCE	==	(-22)
                    0017     59 	CTRLW	==	  23	; ^W
                    FFE8     60 	SECTION	==	(-24)
                    FFE7     61 	PAGE	==	(-25)
                    001A     62 	CTRLZ	==	  26	; ^Z
                    001B     63 	ESCAPE	==	  27	; esc character
                    FFE4     64 	SCRLD	==	(-28)
                    FFE3     65 	SCRLR	==	(-29)
                    FFE2     66 	BACKUP	==	(-30)
                    FFE1     67 	ERROR	==	(-31)
                             68 				; characters 32-126 are valid
                    007F     69 	DELETE	==	 127	; delete to left of cursor
                    007F     70 	CRLF	==	0x7F	; internal line termination
                    0080     71 	REVERSE	==	0x80	; internal reverse video bit
                    0000     72 	NORMAL	==	0x00	; internal normal  video
                             73 
                             74 ; ----------------------------------------------------------
                             75 
                             76 	; VT1xx keypad definitions
                             77 	;
                             78 	;	(ESC O l)	--> (DELC)
                             79 	;	(ESC O m)	--> (DELW)
                             80 	;	(ESC O n)	--> (SELECT)
                             81 	;	(ESC O p)	--> (LINE)
                             82 	;	(ESC O q)	--> (WORD)
                             83 	;	(ESC O r)	--> (EOL)
                             84 	;	(ESC O s)	--> (CHAR)
                             85 	;	(ESC O t)	--> (ADVANCE)
                             86 	;	(ESC O u)	--> (BACKUP)
                             87 	;	(ESC O v)	--> (CUT)
                             88 	;	(ESC O w)	--> (PAGE)
                             89 	;	(ESC O x)	--> (SECTION)
                             90 	;	(ESC O y)	--> (APPEND)
                             91 	;	(ESC O M)	--> (ENTER)
                             92 	;	(ESC O P)	--> (GOLD)
                             93 	;	(ESC O Q)	--> (HELP)
                             94 	;	(ESC O R)	--> (FNDNXT)
                             95 	;	(ESC O S)	--> (DELL)
                             96 	;	(ESC O other)	--> (ERROR)
                             97 	;
                             98 	;	(GOLD)(DELC)	--> (UNDEL C)
                             99 	;	(GOLD)(DELW)	--> (UNDEL W)
                            100 	;	(GOLD)(SELECT)	--> (RESET)
                            101 	;	(GOLD)(LINE)	--> (OPENLINE)
                            102 	;	(GOLD)(WORD)	--> (CHNGCASE)
                            103 	;	(GOLD)(EOL)	--> (DEL EOL)
                            104 	;	(GOLD)(CHAR)	--> (BOTTOM)
                            105 	;	(GOLD)(BACKUP)	--> (TOP)
                            106 	;	(GOLD)(CUT)	--> (PASTE)
                            107 	;	(GOLD)(PAGE)	--> (COMMAND)
                            108 	;	(GOLD)(SECTION)	--> (MOVE CURSOR)
                            109 	;	(GOLD)(APPEND)	--> (REPLACE)
                            110 	;	(GOLD)(ENTER)	--> (SUBS)
                            111 	;	(GOLD)(GOLD)	--> (GOLD)
ASxxxx Assembler V02.21  (Motorola 6809), page 4.
PHS Constant definitions
VT1xx screen definitions

                            112 	;	(GOLD)(HELP)	--> (HELP)
                            113 	;	(GOLD)(FNDNXT)	--> (FIND)
                            114 	;	(GOLD)(DELL)	--> (UNDEL L)
                            115 	;
                            116 	;	(ESC [ A)	--> (SCRLU)
                            117 	;	(ESC [ B)	--> (SCRLD)
                            118 	;	(ESC [ C)	--> (SCRLL)
                            119 	;	(ESC [ D)	--> (SCRLR)
                            120 	;	(ESC [ other)	--> (ERROR)
                            121 
                            122 
                            123 	.sbttl	Acquisition Definitions
                            124 
                    0000    125 	$STOP	==	0b00000000	; acq$sts bits
                    0001    126 	$SCAN	==	0b00000001
                    0002    127 	$FAILED	==	0b00000010
                    0004    128 	$HOLD	==	0b00000100
                    0008    129 	$ACTIVE	==	0b00001000
                            130 
                    0003    131 	$OFF	==	0b00000011	; LED control bits
                    0000    132 	$YELLOW	==	0b00000000
                    0003    133 	$YFLASH	==	0b00000011
                    0001    134 	$RED	==	0b00000001
                    0002    135 	$RFLASH	==	0b00000010
                    0002    136 	$GREEN	==	0b00000010
                    0001    137 	$GFLASH	==	0b00000001
                            138 
                            139 	.sbttl	HV-Status
                            140 
                    0000    141 	$HVQMRK	==	0		; unknown state
                    0001    142 	$HVOFF	==	1
                    0002    143 	$HVON	==	2
                    0003    144 	$HVZERO	==	3
                    0004    145 	$HVFAIL	==	4
                            146 
                            147 	.sbttl	HV-Queue Functions
                            148 
                    0001    149 	M16F	==	1		; HV-Off
                    0002    150 	M16N	==	2		; HV-On
                    0003    151 	M16S	==	3		; HV-Status
                    0004    152 	M16D	==	4		; Demand Voltages
                    0005    153 	M16V	==	5		; Voltage Readings
                    0006    154 	M16CxxG	==	6		; Get Channel Voltage
                    0007    155 	M16CxxS	==	7		; Set Channel Voltage
                    0008    156 	M16CxxZ	==	8		; Zero Channel
                    0009    157 	M16CxxR	==	9		; Restore Channel
                    000A    158 	M16UPDT	==	10		; Update Sequence
                    000B    159 	M16WAIT	==	11		; 5 Second Wait
                            160 
                            161 
ASxxxx Assembler V02.21  (Motorola 6809), page 5.
PHS Constant definitions
HV-Queue Functions

                              8 
                              9 	.area	TERMIO
                             10 
                             11 	; These routines require the following variables and buffers.
                             12 	;
                             13 	; syscin
                             14 	;	cstate		translator state
                             15 	;
                             16 	; format buffer routine variables
                             17 	;	fmtrow		format buffer row
                             18 	;	fmtcol		format buffer column
                             19 	;	findex		address of character in format buffer
                             20 	;	rflag		normal/reverse video flag
                             21 	;
                             22 	;	fmtbuf		format buffer allocation
                             23 	;
                             24 	; output buffer routine variables
                             25 	;	ostate		current state of output buffer scanner
                             26 	;	index		current output scanner index
                             27 	;	first		first changed character in line
                             28 	;	count		number of changed characters in line
                             29 	;	outz		current screen video mode
                             30 	;	savez		saved screen video mode
                             31 	;
                             32 	;	outbuf		output buffer allocation
                             33 	;
                             34 
                             35 	; Terminal escape sequence translator
                             36 	; vt1xx keypad mode
                             37 
   9CE0                      38 sysnxt:
   9CE0 0C 79                39 	inc	*cstate		; next state
   9CE2                      40 syscin::
   9CE2 BD 83 1A             41 	jsr	tt_inp		; get a character
   9CE5 27 15                42 	beq	2$
                             43 
   9CE7 34 14                44 	pshs	x,b
   9CE9 30 8C 11             45 	leax	3$,pcr
   9CEC D6 79                46 	ldb	*cstate
   9CEE 58                   47 	aslb
   9CEF C1 08                48 	cmpb	#4$-3$		; valid cstate ?
   9CF1 25 03                49 	blo	1$		; yes - skip
   9CF3 5F                   50 	clrb
   9CF4 D7 79                51 	stb	*cstate		; reset state
   9CF6 AD 95                52 1$:	jsr	[b,x]		; go to state
   9CF8 35 14                53 	puls	x,b
   9CFA 97 2F                54 	sta	*char		; save character
   9CFC 39                   55 2$:	rts
                             56 
   9CFD 9D 05 9D 0A 9D 19    57 3$:	.word	4$,	5$,	6$,	7$
        9D 1E
                             58 
                             59 
                             60 ;state0
   9D05 81 1B                61 4$:	cmpa	#ESCAPE		; start an escape sequence ?
   9D07 27 D7                62 	beq	sysnxt		; yes - loop
ASxxxx Assembler V02.21  (Motorola 6809), page 6.
PHS Constant definitions
HV-Queue Functions

   9D09 39                   63 	rts			; return character
                             64 
                             65 ;state1
   9D0A 81 4F                66 5$:	cmpa	#'O		; next state = 2 ?
   9D0C 27 D2                67 	beq	sysnxt		; yes - loop
   9D0E 0C 79                68 	inc	*cstate
   9D10 81 5B                69 	cmpa	#'[		; next state = 3 ?
   9D12 27 CC                70 	beq	sysnxt		; yes - loop
   9D14 86 E1                71 	lda	#ERROR		; not a valid sequence
   9D16 0F 79                72 	clr	*cstate
   9D18 39                   73 	rts
                             74 
                             75 ;state2
   9D19 30 8C 12             76 6$:	leax	10$,pcr
   9D1C 20 03                77 	bra	8$
                             78 
                             79 ;state3
   9D1E 30 8C 33             80 7$:	leax	11$,pcr
                             81 
                             82 ;statex
   9D21 A1 81                83 8$:	cmpa	,x++		; match table entry ?
   9D23 27 04                84 	beq	9$
   9D25 6D 1E                85 	tst	-2,x		; end of table ?
   9D27 26 F8                86 	bne	8$
   9D29 A6 1F                87 9$:	lda	-1,x		; get translation
   9D2B 0F 79                88 	clr	*cstate
   9D2D 39                   89 	rts
                             90 
                             91 
   9D2E 6C EF 6D EE 6E FF    92 10$:	.byte	'l,DELC,	'm,DELW,	'n,SELECT,	'p,LINE
        70 F0
   9D36 71 F1 72 EC 73 F2    93 	.byte	'q,WORD,	'r,EOL,		's,CHAR,	't,ADVANCE
        74 EA
   9D3E 75 E2 76 FE 77 E7    94 	.byte	'u,BACKUP,	'v,CUT,		'w,PAGE,	'x,SECTION
        78 E8
   9D46 79 FD 4D F9 50 FB    95 	.byte	'y,APPEND,	'M,ENTER,	'P,GOLD,	'Q,HELP
        51 FA
   9D4E 52 FC 53 ED 00 E1    96 	.byte	'R,FNDNXT,	'S,DELL,	 0,ERROR
                             97 
   9D54 41 0B 42 E4 43 E3    98 11$:	.byte	'A,SCRLU,	'B,SCRLD,	'C,SCRLR,	'D,SCRLL
        44 08
   9D5C 00 E1                99 	.byte	 0,ERROR
                            100 
                            101 
                            102 	;
                            103 	; fmtindex	-	calculate the pointer into
                            104 	;			the fmt buffer.
                            105 	;	a	-	row
                            106 	;	b	-	column
                            107 	;
                            108 	; returns:
                            109 	;	y	-	returns address for fmtbuf(row,column)
                            110 
   9D5E                     111 fmtindex::
   9D5E 34 06               112 	pshs	d
   9D60 DD 74               113 	std	*fmtrow		; row,column
ASxxxx Assembler V02.21  (Motorola 6809), page 7.
PHS Constant definitions
HV-Queue Functions

   9D62 31 C9 03 00         114 	leay	fmtbuf,u
   9D66 C6 50               115 	ldb	#SCRNW
   9D68 3D                  116 	mul
   9D69 DB 75               117 	addb	*fmtcol
   9D6B 89 00               118 	adca	#0
   9D6D 31 AB               119 	leay	d,y
   9D6F 10 9F 76            120 	sty	*findex		; save &fmtbuf(row,column)
   9D72 35 06               121 	puls	d
   9D74 39                  122 	rts
                            123 
                            124 
                            125 	;
                            126 	; fmtdeol	-	Clear to end of line.
                            127 	;
                            128 	;	a	-	row
                            129 	;	b	-	column
                            130 
   9D75                     131 fmtdeol::
   9D75 34 26               132 	pshs	y,d
   9D77 BD 9D 5E            133 	jsr	fmtindex
   9D7A 86 50               134 	lda	#SCRNW
   9D7C 90 75               135 	suba	*fmtcol
   9D7E 27 07               136 	beq	2$
   9D80 C6 20               137 	ldb	#(' )		; space character
   9D82 E7 A0               138 1$:	stb	,y+
   9D84 4A                  139 	deca
   9D85 2E FB               140 	bgt	1$
                            141 
   9D87 35 26               142 2$:	puls	y,d
   9D89 39                  143 	rts
                            144 
                            145 
                            146 	;
                            147 	;  fmtchar	-	Output a single character
                            148 	;			to the screen buffer.
                            149 	;
                            150 
   9D8A                     151 fmtchar::
   9D8A 34 20               152 	pshs	y
   9D8C 34 06               153 	pshs	d
   9D8E DC 74               154 	ldd	*fmtrow		; load row,column
   9D90 BD 9D 5E            155 	jsr	fmtindex
   9D93 35 06               156 	puls	d
   9D95 A7 A4               157 	sta	,y		; place character
   9D97 35 20               158 	puls	y
   9D99 39                  159 	rts
                            160 
                            161 
                            162 	; fmthtxt	-	Format the character string
                            163 	;			horizontally into the format buffer.
                            164 	;
                            165 	;	x	-	pointer to string
                            166 	;	a	-	row
                            167 	;	b	-	column
                            168 	;
                            169 	;	returns:
ASxxxx Assembler V02.21  (Motorola 6809), page 8.
PHS Constant definitions
HV-Queue Functions

                            170 	;	a	-	row
                            171 	;	b	-	new column position
                            172 
   9D9A                     173 fmthtxt::
   9D9A 34 30               174 	pshs	x,y		; save registers
                            175 
   9D9C BD 9D 5E            176 	jsr	fmtindex	; pointer to character position in fmtbuf
                            177 
   9D9F A6 84               178 1$:	lda	,x		; set reverse video flag
   9DA1 84 80               179 	anda	#REVERSE
   9DA3 97 78               180 	sta	*rflag
                            181 
   9DA5 A6 80               182 	lda	,x+
   9DA7 84 7F               183 	anda	#0x7F
   9DA9 27 3F               184 	beq	5$
   9DAB 81 7F               185 	cmpa	#CRLF
   9DAD 27 3B               186 	beq	5$
                            187 
                            188 	; TAB processing
                            189 
   9DAF 81 09               190 	cmpa	#TAB		; TAB's are expanded to spaces
   9DB1 26 19               191 	bne	3$		; with a fixed spacing of 8 characters
   9DB3 86 08               192 	lda	#0d8
   9DB5 D6 75               193 	ldb	*fmtcol
   9DB7 C4 07               194 	andb	#0x07
   9DB9 34 04 A0 E0         195 	sba			; character positions to fill
   9DBD DB 75               196 	addb	*fmtcol		; update column position
   9DBF D7 75               197 	stb	*fmtcol
                            198 
   9DC1 C6 20               199 	ldb	#(' )		; space character
   9DC3 DA 78               200 	orb	*rflag		; set video mode bit
   9DC5 E7 A0               201 2$:	stb	,y+		; place characters
   9DC7 4A                  202 	deca
   9DC8 2E FB               203 	bgt	2$
   9DCA 20 D3               204 	bra	1$
                            205 
                            206 	; Nonprinting character processing
                            207 
   9DCC 81 20               208 3$:	cmpa	#0d32		; nonprinting character ?
   9DCE 24 12               209 	bhis	4$		; no - skip
                            210 
   9DD0 C6 5E               211 	ldb	#'^		; show as ^_
   9DD2 DA 78               212 	orb	*rflag
   9DD4 E7 A0               213 	stb	,y+
   9DD6 8B 40               214 	adda	#0d64
   9DD8 9A 78               215 	ora	*rflag
   9DDA A7 A0               216 	sta	,y+
                            217 
   9DDC 0C 75               218 	inc	*fmtcol		; update column
   9DDE 0C 75               219 	inc	*fmtcol
   9DE0 20 BD               220 	bra	1$
                            221 
                            222 	; Process all normal characters
                            223 
   9DE2 9A 78               224 4$:	ora	*rflag
   9DE4 A7 A0               225 	sta	,y+
ASxxxx Assembler V02.21  (Motorola 6809), page 9.
PHS Constant definitions
HV-Queue Functions

   9DE6 0C 75               226 	inc	*fmtcol
   9DE8 20 B5               227 	bra	1$
                            228 
   9DEA 35 30               229 5$:	puls	x,y		; restore registers
   9DEC DC 74               230 	ldd	*fmtrow		; return current row,column
   9DEE 39                  231 	rts
                            232 
                            233 
                            234 	; fmtvtxt	-	Format the character string
                            235 	;			vertically into the format buffer.
                            236 	;
                            237 	;	x	-	pointer to string
                            238 	;	a	-	row
                            239 	;	b	-	column
                            240 	;
                            241 	;	returns:
                            242 	;	a	-	new row position
                            243 	;	b	-	column position
                            244 
   9DEF                     245 fmtvtxt::
   9DEF 34 30               246 	pshs	x,y		; save registers
                            247 
   9DF1 BD 9D 5E            248 	jsr	fmtindex	; pointer to character position in fmtbuf
                            249 
   9DF4 A6 84               250 1$:	lda	,x		; set reverse video flag
   9DF6 84 80               251 	anda	#REVERSE
   9DF8 97 78               252 	sta	*rflag
                            253 
   9DFA A6 80               254 	lda	,x+
   9DFC 84 7F               255 	anda	#0x7F
   9DFE 27 4B               256 	beq	5$
   9E00 81 7F               257 	cmpa	#CRLF
   9E02 27 47               258 	beq	5$
                            259 
                            260 	; TAB processing
                            261 
   9E04 81 09               262 	cmpa	#TAB		; TAB's are expanded to spaces
   9E06 26 1C               263 	bne	3$		; with a fixed spacing of 8 characters
   9E08 86 08               264 	lda	#0d8
   9E0A D6 74               265 	ldb	*fmtrow
   9E0C C4 07               266 	andb	#0x07
   9E0E 34 04 A0 E0         267 	sba			; character positions to fill
   9E12 DB 74               268 	addb	*fmtrow		; update row position
   9E14 D7 74               269 	stb	*fmtrow
                            270 
   9E16 C6 20               271 	ldb	#(' )		; space character
   9E18 DA 78               272 	orb	*rflag		; set video mode bit
   9E1A E7 A4               273 2$:	stb	,y		; place characters
   9E1C 31 A8 50            274 	leay	SCRNW,y		; update buffer location
   9E1F 4A                  275 	deca
   9E20 2E F8               276 	bgt	2$
   9E22 20 D0               277 	bra	1$
                            278 
                            279 	; Nonprinting character processing
                            280 
   9E24 81 20               281 3$:	cmpa	#0d32		; nonprinting character ?
ASxxxx Assembler V02.21  (Motorola 6809), page 10.
PHS Constant definitions
HV-Queue Functions

   9E26 24 18               282 	bhis	4$		; no - skip
                            283 
   9E28 C6 5E               284 	ldb	#'^		; show as ^_
   9E2A DA 78               285 	orb	*rflag
   9E2C E7 A4               286 	stb	,y
   9E2E 31 A8 50            287 	leay	SCRNW,y		; update buffer location
   9E31 8B 40               288 	adda	#0d64
   9E33 9A 78               289 	ora	*rflag
   9E35 A7 A4               290 	sta	,y
   9E37 31 A8 50            291 	leay	SCRNW,y		; update buffer location
                            292 
   9E3A 0C 74               293 	inc	*fmtrow		; update column
   9E3C 0C 74               294 	inc	*fmtrow
   9E3E 20 B4               295 	bra	1$
                            296 
                            297 	; Process all normal characters
                            298 
   9E40 9A 78               299 4$:	ora	*rflag
   9E42 A7 A4               300 	sta	,y
   9E44 31 A8 50            301 	leay	SCRNW,y		; update buffer location
   9E47 0C 74               302 	inc	*fmtrow
   9E49 20 A9               303 	bra	1$
                            304 
   9E4B 35 30               305 5$:	puls	x,y		; restore registers
   9E4D DC 74               306 	ldd	*fmtrow		; return current row,column
   9E4F 39                  307 	rts
                            308 
                            309 
                            310 	;	x	-	integer value to convert to ascii
                            311 	;	d	-	row / column of the first position
                            312 	;			of the 6 character string space to
                            313 	;			right justify the converted integer
                            314 
   9E50                     315 fmt4rjint::
   9E50 34 36               316 	pshs	d,x,y
   9E52 BD 9D 5E            317 	jsr	fmtindex	; get buffer position in y
   9E55 1F 10               318 	tfr	x,d		; convert integer in x
   9E57 32 7A               319 	leas	-6,s		; space for string
   9E59 1F 41               320 	tfr	s,x		; string address
   9E5B 6F E2               321 	clr	,-s		; front termination
   9E5D BD E4 0E            322 	jsr	i$w$dz		; convert to ascii
                            323 
   9E60 86 20               324 	lda	#(' )		; clear old string in buffer
   9E62 C6 04               325 	ldb	#4
   9E64 A7 A0               326 1$:	sta	,y+
   9E66 5A                  327 	decb
   9E67 2E FB               328 	bgt	1$
                            329 
   9E69 A6 82               330 2$:	lda	,-x		; copy string into buffer
   9E6B 2F 04               331 	ble	3$
   9E6D A7 A2               332 	sta	,-y
   9E6F 20 F8               333 	bra	2$
                            334 
   9E71 32 67               335 3$:	leas	7,s		; pop string
   9E73 35 36               336 	puls	d,x,y
   9E75 39                  337 	rts
ASxxxx Assembler V02.21  (Motorola 6809), page 11.
PHS Constant definitions
HV-Queue Functions

                            338 
                            339 
                            340 	;	x	-	integer value to convert to ascii
                            341 	;	d	-	row / column of the first position
                            342 	;			of the 6 character string space to
                            343 	;			left justify the converted integer
                            344 
   9E76                     345 fmt4ljint::
   9E76 34 36               346 	pshs	d,x,y
   9E78 BD 9D 5E            347 	jsr	fmtindex	; get buffer position in y
   9E7B 1F 10               348 	tfr	x,d		; convert integer in x
   9E7D 32 7A               349 	leas	-6,s		; space for string
   9E7F 1F 41               350 	tfr	s,x		; string address
   9E81 BD E4 0E            351 	jsr	i$w$dz		; convert to ascii
                            352 
   9E84 C6 04               353 	ldb	#4
   9E86 1F 41               354 	tfr	s,x
   9E88 A6 80               355 1$:	lda	,x+		; copy string into buffer
   9E8A 2F 05               356 	ble	2$
   9E8C A7 A0               357 	sta	,y+
   9E8E 5A                  358 	decb
   9E8F 20 F7               359 	bra	1$
                            360 
   9E91 86 20               361 2$:	lda	#(' )		; clear old string in buffer
   9E93 20 02               362 	bra	4$
                            363 
   9E95 A7 A0               364 3$:	sta	,y+
   9E97 5A                  365 4$:	decb
   9E98 2C FB               366 	bge	3$
                            367 
   9E9A 32 66               368 5$:	leas	6,s		; pop string
   9E9C 35 36               369 	puls	d,x,y
   9E9E 39                  370 	rts
                            371 
                            372 
                            373 	;	x	-	integer value to convert to ascii
                            374 	;	d	-	row / column of the first position
                            375 	;			of the 6 character string space to
                            376 	;			right justify the converted integer
                            377 
   9E9F                     378 fmt6rjint::
   9E9F 34 36               379 	pshs	d,x,y
   9EA1 BD 9D 5E            380 	jsr	fmtindex	; get buffer position in y
   9EA4 1F 10               381 	tfr	x,d		; convert integer in x
   9EA6 32 7A               382 	leas	-6,s		; space for string
   9EA8 1F 41               383 	tfr	s,x		; string address
   9EAA 6F E2               384 	clr	,-s		; front termination
   9EAC BD E4 0E            385 	jsr	i$w$dz		; convert to ascii
                            386 
   9EAF 86 20               387 	lda	#(' )		; clear old string in buffer
   9EB1 C6 06               388 	ldb	#6
   9EB3 A7 A0               389 1$:	sta	,y+
   9EB5 5A                  390 	decb
   9EB6 2E FB               391 	bgt	1$
                            392 
   9EB8 A6 82               393 2$:	lda	,-x		; copy string into buffer
ASxxxx Assembler V02.21  (Motorola 6809), page 12.
PHS Constant definitions
HV-Queue Functions

   9EBA 2F 04               394 	ble	3$
   9EBC A7 A2               395 	sta	,-y
   9EBE 20 F8               396 	bra	2$
                            397 
   9EC0 32 67               398 3$:	leas	7,s		; pop string
   9EC2 35 36               399 	puls	d,x,y
   9EC4 39                  400 	rts
                            401 
                            402 
                            403 	;	x	-	integer value to convert to ascii
                            404 	;	d	-	row / column of the first position
                            405 	;			of the 6 character string space to
                            406 	;			left justify the converted integer
                            407 
   9EC5                     408 fmt6ljint::
   9EC5 34 36               409 	pshs	d,x,y
   9EC7 BD 9D 5E            410 	jsr	fmtindex	; get buffer position in y
   9ECA 1F 10               411 	tfr	x,d		; convert integer in x
   9ECC 32 7A               412 	leas	-6,s		; space for string
   9ECE 1F 41               413 	tfr	s,x		; string address
   9ED0 BD E4 0E            414 	jsr	i$w$dz		; convert to ascii
                            415 
   9ED3 C6 06               416 	ldb	#6
   9ED5 1F 41               417 	tfr	s,x
   9ED7 A6 80               418 1$:	lda	,x+		; copy string into buffer
   9ED9 2F 05               419 	ble	2$
   9EDB A7 A0               420 	sta	,y+
   9EDD 5A                  421 	decb
   9EDE 20 F7               422 	bra	1$
                            423 
   9EE0 86 20               424 2$:	lda	#(' )		; clear old string in buffer
   9EE2 20 02               425 	bra	4$
                            426 
   9EE4 A7 A0               427 3$:	sta	,y+
   9EE6 5A                  428 4$:	decb
   9EE7 2C FB               429 	bge	3$
                            430 
   9EE9 32 66               431 5$:	leas	6,s		; pop string
   9EEB 35 36               432 	puls	d,x,y
   9EED 39                  433 	rts
                            434 
                            435 
                            436 	;
                            437 	; outpos	-	output the current position to the screen
                            438 	;
                            439 	;	u	-	current user structure
                            440 	;	a	-	row
                            441 	;	b	-	column
                            442 
   9EEE                     443 outpos::
   9EEE 34 06               444 	pshs	d
   9EF0 86 1B               445 	lda	#ESCAPE
   9EF2 BD 82 F3            446 	jsr	tt_out
   9EF5 86 5B               447 	lda	#'[
   9EF7 BD 82 F3            448 	jsr	tt_out
   9EFA A6 60               449 	lda	0,s		; row first
ASxxxx Assembler V02.21  (Motorola 6809), page 13.
PHS Constant definitions
HV-Queue Functions

   9EFC BD 9F 11            450 	jsr	outarg
   9EFF 86 3B               451 	lda	#';
   9F01 BD 82 F3            452 	jsr	tt_out
   9F04 A6 61               453 	lda	1,s		; column last
   9F06 BD 9F 11            454 	jsr	outarg
   9F09 86 48               455 	lda	#'H
   9F0B BD 82 F3            456 	jsr	tt_out
   9F0E 35 06               457 	puls	d
   9F10 39                  458 	rts
                            459 
                            460 	;
                            461 	; outarg	-	output the position as an ascii string
                            462 	;
                            463 	;	u	-	current user structure
                            464 	;	a	-	argument
                            465 
   9F11                     466 outarg::
   9F11 34 16               467 	pshs	x,d
                            468 
   9F13 5F                  469 	clrb			;	- tens
   9F14 4C                  470 	inca			; +1	- ones
                            471 
   9F15 81 0A               472 1$:	cmpa	#0d10		; tens digits
   9F17 25 05               473 	blo	2$
   9F19 5C                  474 	incb
   9F1A 80 0A               475 	suba	#0d10
   9F1C 20 F7               476 	bra	1$
                            477 
   9F1E 5D                  478 2$:	tstb
   9F1F 27 09               479 	beq	3$
   9F21 1E 89               480 	exg	a,b
   9F23 8B 30               481 	adda	#'0
   9F25 BD 82 F3            482 	jsr	tt_out		; tens digit
   9F28 1E 89               483 	exg	a,b
                            484 
   9F2A 8B 30               485 3$:	adda	#'0
   9F2C BD 82 F3            486 	jsr	tt_out		; ones digit
                            487 
   9F2F 35 16               488 	puls	x,d
   9F31 39                  489 	rts
                            490 
                            491 
                            492 	;
                            493 	; outzset	-	set the video mode
                            494 	;			return old video mode
                            495 	;
                            496 	;	u	-	current user structure
                            497 	;	a	-	returns old mode
                            498 	;		0	normal
                            499 	;		1	reverse
                            500 
   9F32                     501 outzset::
   9F32 4D                  502 	tsta
   9F33 26 15               503 	bne	outrev		; go to outrev
                            504 				; fall through to outnorm
                            505 	
ASxxxx Assembler V02.21  (Motorola 6809), page 14.
PHS Constant definitions
HV-Queue Functions

                            506 	;
                            507 	; outnorm	-	set normal video mode
                            508 	;			return old video mode
                            509 	;
                            510 	;	u	-	current user structure
                            511 	;	a	-	returns old mode
                            512 	;		0	normal
                            513 	;		1	reverse
                            514 
   9F35                     515 outnorm::
   9F35 96 7E               516 	lda	*outz		; check current mode
   9F37 27 0D               517 	beq	1$		; normal - exit
   9F39 34 10               518 	pshs	x
   9F3B 0F 7E               519 	clr	*outz		; change to normal
   9F3D 30 8C 07            520 	leax	2$,pcr
   9F40 8D 32               521 	bsr	escout
   9F42 86 01               522 	lda	#1		; was reverse
   9F44 35 10               523 	puls	x
   9F46 39                  524 1$:	rts
                            525 
   9F47 5B 6D 00            526 2$:	.asciz	"[m"
                            527 
                            528 
                            529 	;
                            530 	; outrev	-	set reverse video mode
                            531 	;			return old video mode
                            532 	;
                            533 	;	u	-	current user structure
                            534 	;	a	-	returns old mode
                            535 	;		0	normal
                            536 	;		1	reverse
                            537 
   9F4A                     538 outrev::
   9F4A 96 7E               539 	lda	*outz		; check current mode
   9F4C 26 0C               540 	bne	1$		; reverse - exit
   9F4E 34 10               541 	pshs	x
   9F50 0C 7E               542 	inc	*outz		; change to reverse
   9F52 30 8C 06            543 	leax	2$,pcr
   9F55 8D 1D               544 	bsr	escout
   9F57 4F                  545 	clra			; was normal
   9F58 35 10               546 	puls	x
   9F5A 39                  547 1$:	rts
                            548 
   9F5B 5B 37 6D 00         549 2$:	.asciz	"[7m"
                            550 
                            551 
                            552 	;
                            553 	; outclr	-	clear screen
                            554 	;
                            555 	;	u	-	current user structure
                            556 
   9F5F                     557 outclr::
   9F5F 34 12               558 	pshs	x,a
   9F61 30 8C 02            559 	leax	1$,pcr		; clear screen
   9F64 20 10               560 	bra	escgo
                            561 
ASxxxx Assembler V02.21  (Motorola 6809), page 15.
PHS Constant definitions
HV-Queue Functions

   9F66 5B 32 4A 00         562 1$:	.asciz	"[2J"
                            563 
                            564 
                            565 	;
                            566 	; outdeol	-	clear to end of line
                            567 	;
                            568 	;	u	-	current user structure
                            569 
   9F6A                     570 outdeol::
   9F6A 34 12               571 	pshs	x,a
   9F6C 30 8C 02            572 	leax	1$,pcr		; clear to end of line
   9F6F 20 05               573 	bra	escgo
                            574 
   9F71 5B 4B 00            575 1$:	.asciz	"[K"
                            576 
                            577 
                            578 	;
                            579 	; escout	-	output the escape sequence
                            580 	;
                            581 	;	u	-	current user structure
                            582 	;	x	-	character string
                            583 	;	a	-	temporary
                            584 
   9F74                     585 escout::
   9F74 34 12               586 	pshs	x,a
                            587 
   9F76 86 1B               588 escgo:	lda	#ESCAPE
                            589 
   9F78 BD 82 F3            590 1$:	jsr	tt_out
   9F7B A6 80               591 	lda	,x+
   9F7D 26 F9               592 	bne	1$
                            593 
   9F7F 35 12               594 	puls	x,a
   9F81 39                  595 	rts
                            596 
                            597 
                            598 	;
                            599 	; outekp	-	enable alternate keypad mode
                            600 	;			set scroll region
                            601 	;
                            602 	;	u	-	current user structure
                            603 
   9F82                     604 outekp::
   9F82 34 06               605 	pshs	d
   9F84 86 1B               606 	lda	#ESCAPE
   9F86 BD 82 F3            607 	jsr	tt_out
   9F89 86 3D               608 	lda	#'=		; enable alternate keypad mode
   9F8B BD 82 F3            609 	jsr	tt_out
   9F8E 86 00               610 	lda	#SCRNTP
   9F90 C6 17               611 	ldb	#SCRNBT
   9F92 8D 17               612 	bsr	outscroll
   9F94 35 06               613 	puls	d
   9F96 39                  614 	rts
                            615 
                            616 
                            617 	;
ASxxxx Assembler V02.21  (Motorola 6809), page 16.
PHS Constant definitions
HV-Queue Functions

                            618 	; outdkp	-	disable alternate keypad mode
                            619 	;			reset scroll rgion
                            620 	;
                            621 	;	u	-	current user structure
                            622 
   9F97                     623 outdkp::
   9F97 34 06               624 	pshs	d
   9F99 86 1B               625 	lda	#ESCAPE
   9F9B BD 82 F3            626 	jsr	tt_out
   9F9E 86 3C               627 	lda	#'<		; disable alternate keypad mode
   9FA0 BD 82 F3            628 	jsr	tt_out
   9FA3 4F                  629 	clra			; reset scroll region and scroll
   9FA4 C6 17               630 	ldb	#SCRNL-1
   9FA6 8D 03               631 	bsr	outscroll
   9FA8 35 06               632 	puls	d
   9FAA 39                  633 	rts
                            634 
                            635 	;
                            636 	; outscroll	-	scroll region
                            637 	;
                            638 	;	u	-	current user structure
                            639 	;	a	-	TOP of region
                            640 	;	b	-	BOTTOM of region
                            641 
   9FAB                     642 outscroll::
   9FAB 34 06               643 	pshs	d
   9FAD 86 1B               644 	lda	#ESCAPE
   9FAF BD 82 F3            645 	jsr	tt_out
   9FB2 86 5B               646 	lda	#'[
   9FB4 BD 82 F3            647 	jsr	tt_out
   9FB7 A6 60               648 	lda	0,s		; screen top
   9FB9 BD 9F 11            649 	jsr	outarg
   9FBC 86 3B               650 	lda	#';
   9FBE BD 82 F3            651 	jsr	tt_out
   9FC1 A6 61               652 	lda	1,s		; screen bottom
   9FC3 BD 9F 11            653 	jsr	outarg
   9FC6 86 72               654 	lda	#'r
   9FC8 BD 82 F3            655 	jsr	tt_out
   9FCB 35 06               656 	puls	d
   9FCD 39                  657 	rts
                            658 
                            659 
                            660 	;
                            661 	; clrsbufs	-	clear the screen buffers
                            662 	;
                            663 	;			fills fmtbuf with spaces
                            664 	;			fills outbuf with spaces
                            665 
   9FCE                     666 clrsbufs::
   9FCE 34 72               667 	pshs	x,y,u,a
   9FD0 30 C9 0A 80         668 	leax	outbuf,u	; output buffer
   9FD4 33 C9 03 00         669 	leau	fmtbuf,u	; format buffer
   9FD8 10 8E 07 80         670 	ldy	#(SCRNBT-SCRNTP+1)*SCRNW
   9FDC 86 20               671 	lda	#(' )		; space character
   9FDE A7 80               672 1$:	sta	,x+		; load outbuf with spaces
   9FE0 A7 C0               673 	sta	,u+		; load fmtbuf with spaces
ASxxxx Assembler V02.21  (Motorola 6809), page 17.
PHS Constant definitions
HV-Queue Functions

   9FE2 31 3F               674 	leay	-1,y
   9FE4 26 F8               675 	bne	1$
   9FE6 35 72               676 	puls	x,y,u,a
   9FE8 39                  677 	rts
                            678 
                            679 
                            680 	;
                            681 	; outblk	-	output block buffer
                            682 	;
                            683 	;	This routine outputs any updates to the
                            684 	;	video terminal screen.  This routine
                            685 	;	never blocks and updates one screen line
                            686 	;	per call if there is space available in the
                            687 	;	port output buffer.
                            688 	;
                            689 	;	registers are not preserved
                            690 	;
                            691 	;	enter with u pointing to the work page
                            692 	;
                            693 
   9FE9                     694 outblk::
   9FE9 1F 30               695 	tfr	u,d
   9FEB 1F 8B               696 	tfr	a,dp		; set direct page
   9FED D6 41               697 	ldb	*scrn$sts	; this screen active ?
   9FEF 2A 50               698 	bpl	8$		; no - exit
   9FF1 96 06               699 	lda	*bfstat		; check if space available
   9FF3 85 01               700 	bita	#dl		; empty ?
   9FF5 26 4A               701 	bne	8$		; no - exit
                            702 
   9FF7 C5 40               703 	bitb	#0q100		; clear screen ?
   9FF9 27 10               704 	beq	1$		; no - skip
   9FFB C4 BF               705 	andb	#~0q100		; clear flag bit
   9FFD D7 41               706 	stb	*scrn$sts
   9FFF BD 9F CE            707 	jsr	clrsbufs	; clear the screen buffers
   A002 BD 9F 5F            708 	jsr	outclr		; and the screen
   A005 BD 9F 35            709 	jsr	outnorm		; normal video
   A008 BD 9F 82            710 	jsr	outekp		; enable the keypad
                            711 
   A00B C5 20               712 1$:	bitb	#0q040		; move cursor ?
   A00D 27 09               713 	beq	2$		; no - skip
   A00F C4 DF               714 	andb	#~0q040		; clear flag bit
   A011 D7 41               715 	stb	*scrn$sts
   A013 DC 45               716 	ldd	*scrn$pos
   A015 BD 9E EE            717 	jsr	outpos		; and move screen cursor
                            718 
   A018 96 7E               719 2$:	lda	*outz		; save video status
   A01A 97 7F               720 	sta	*savez
                            721 
   A01C 30 8C 0C            722 	leax	4$,pcr
   A01F D6 7A               723 	ldb	*ostate
   A021 C1 02               724 	cmpb	#2		; valid state ?
   A023 25 03               725 	blo	3$		; yes - skip
   A025 5F                  726 	clrb			; reset state
   A026 0F 7A               727 	clr	*ostate
   A028 58                  728 3$:	aslb
   A029 6E 95               729 	jmp	[b,x]		; go to state
ASxxxx Assembler V02.21  (Motorola 6809), page 18.
PHS Constant definitions
HV-Queue Functions

                            730 
   A02B A0 2F A0 33         731 4$:	.word	5$,	6$
                            732 
                            733 ; state0
   A02F 0F 7B               734 5$:	clr	*index
   A031 0C 7A               735 	inc	*ostate
                            736 
                            737 ; state1
   A033 8D 0D               738 6$:	bsr	9$		; scan line for changes
   A035 96 7B               739 	lda	*index		; update line index
   A037 4C                  740 	inca
   A038 81 17               741 	cmpa	#SCRNBT-SCRNTP	; finished after #() lines
   A03A 23 03               742 	blos	7$
   A03C 4F                  743 	clra			; restart sequence scan
   A03D 97 7A               744 	sta	*ostate
   A03F 97 7B               745 7$:	sta	*index	
   A041 39                  746 8$:	rts
                            747 
                            748 	;
                            749 	;	scan a line of text for changes
                            750 	;
                            751 
   A042 96 7B               752 9$:	lda	*index		; line number
   A044 C6 50               753 	ldb	#SCRNW		; line width
   A046 3D                  754 	mul
   A047 30 C9 03 00         755 	leax	fmtbuf,u	; compute pointer into fmtbuf
   A04B 30 8B               756 	leax	d,x
   A04D 31 C9 0A 80         757 	leay	outbuf,u	; compute pointer into outbuf
   A051 31 AB               758 	leay	d,y
   A053 34 30               759 	pshs	x,y		; save buffer pointers
                            760 
   A055 0F 7C               761 	clr	*first		; first
   A057 0F 7D               762 	clr	*count		; count
                            763 
   A059 5F                  764 	clrb
   A05A A6 80               765 10$:	lda	,x+		; compare character by character
   A05C A1 A0               766 	cmpa	,y+
   A05E 26 08               767 	bne	11$
   A060 5C                  768 	incb
   A061 C1 50               769 	cmpb	#SCRNW
   A063 26 F5               770 	bne	10$
   A065 16 00 54            771 	lbra	18$		; no changes - just exit
                            772 
   A068 D7 7C               773 11$:	stb	*first		; save first changed location
   A06A 35 30               774 	puls	x,y		; get pointers back
   A06C 34 30               775 	pshs	x,y
   A06E 30 88 50            776 	leax	SCRNW,x		; end of string pointers
   A071 31 A8 50            777 	leay	SCRNW,y
   A074 C6 50               778 	ldb	#SCRNW
   A076 A6 82               779 12$:	lda	,-x		; scan back from end
   A078 A1 A2               780 	cmpa	,-y
   A07A 26 03               781 	bne	13$
   A07C 5A                  782 	decb
   A07D 26 F7               783 	bne	12$
   A07F D0 7C               784 13$:	subb	*first		; compute number of characters changed
   A081 D7 7D               785 	stb	*count
ASxxxx Assembler V02.21  (Motorola 6809), page 19.
PHS Constant definitions
HV-Queue Functions

                            786 
   A083 35 30               787 	puls	x,y		; restore buffer pointers
   A085 34 30               788 	pshs	x,y
   A087 D6 7C               789 	ldb	*first		; column
   A089 30 85               790 	leax	b,x		; fmtbuf + index*SCRNW + first
   A08B 31 A5               791 	leay	b,y		; outbuf + index*SCRNW + first
                            792 
   A08D 96 7B               793 	lda	*index		; row
   A08F 8B 00               794 	adda	#SCRNTP
   A091 BD 9E EE            795 	jsr	outpos		; position cursor at first position
                            796 
   A094 D6 7D               797 	ldb	*count		; number of changed characters
   A096 5A                  798 14$:	decb
   A097 2B 19               799 	bmi	17$
   A099 A6 80               800 	lda	,x+		; update character in buffer
   A09B A7 A0               801 	sta	,y+
   A09D 34 02               802 	pshs	a
   A09F 2B 05               803 	bmi	15$		; reverse video
                            804 
   A0A1 BD 9F 35            805 	jsr	outnorm		; normal video character
   A0A4 20 03               806 	bra	16$
                            807 
   A0A6 BD 9F 4A            808 15$:	jsr	outrev		; reverse video character
                            809 
   A0A9 35 02               810 16$:	puls	a
   A0AB 84 7F               811 	anda	#0x7F		; mask video mode and update
   A0AD BD 82 F3            812 	jsr	tt_out
   A0B0 20 E4               813 	bra	14$		; loop for count characters
                            814 
   A0B2 DC 45               815 17$:	ldd	*scrn$pos	; restore cursor position
   A0B4 BD 9E EE            816 	jsr	outpos
                            817 
   A0B7 96 7F               818 	lda	*savez
   A0B9 BD 9F 32            819 	jsr	outzset
   A0BC 32 64               820 18$:	leas	4,s		; pop buffer pointers
   A0BE 39                  821 	rts
                            822 
                            823 
