; ************************** AMUS Program Label ******************************
; Filename: BYTE.M68                                        Date: 01/23/90
; Category: UTIL         Hash Code: 525-467-332-132      Version: 1.0(101)
; Initials: ULTR/AM      Name: DAVID PALLMANN
; Company: ULTRASOFT CORPORATION                   Telephone #: 5163484848
; Related Files:                                                       
; Min. Op. Sys.: AMOSL 1.3B                    Expertise Level: BEG
; Special: Requires 2.0 assembler -- After assembly: .LNKLIT BYTE 
; Description: Byte conversion utility & dynamic ASCII/ISO Latin I character
; set chart.  Useful to programmers who need to do conversions (just about
; all of us at one time or another).  A must for AM65 users in particular.
; ****************************************************************************

;****************************************************************************
;*									    *
;*				    BYTE				    *
;*			   Byte Conversion Utility			    *
;*									    *
;****************************************************************************
;Copyright (C) 1990 UltraSoft Corporation.  All Rights Reserved.
;
;Written by: David Pallmann
;
;Edit History:
;1.0(100)  23-Jan-90  created. /DFP
;1.0(101)  23-Jan-90  fix descriptions (thanks Bob Currier). /DFP

	VMAJOR	=1
	VMINOR	=0
	VSUB	=0
	VEDIT	=101.
	VWHO	=0

	AUTOEXTERN

	SEARCH	SYS
	SEARCH	SYSSYM
	SEARCH	TRM

;ASCII character defintions

	$ESC	=33			; escape

;variables

	.OFINI
	.OFDEF	ROW,	1		; row number (1-8)
	.OFDEF	BYTE,	1		; current value
	.OFDEF	POS,	1		; relative position (0,2,4,...)
	.OFDEF	COL,	1		; cursor column position
	.OFDEF	BYTTBL,	16.		; byte value table
	.OFDEF	BUFFER,	4		; conversion buffer
	.OFSIZ	MEMSIZ

;macros

DEFINE	CURSOR	ROW,COL
	MOVB	ROW,D1
	ROLW	D1,#8.
	MOVB	COL,D1
	TCRT
	ENDM

DEFINE	CRT	N
	MOVW	#-1_8.+^D<N>,D1
	TCRT
	ENDM

DEFINE	REPEAT	COUNT,INSTR
	MOV	#COUNT,D0
1$$:	INSTR
	DEC	D0
	BNE	1$$
	ENDM

;***********
;*  START  *
;***********
;Start of program

START:	PHDR	-1,0,PH$REE!PH$REU	; program header
	GETIMP	MEMSIZ,A5		; 
	TRMRST	D0			; 
	ORW	#T$DAT!T$ECS!T$XLT,D0	; 
	TRMWST	D0			; 
	CALL	SCREEN			; display the screen
	CLRB	ROW(A5)			; clear row
	CALL	GETVAL			; 
	MOVB	#32.,POS(A5)		; start out in character column

;come here to get a new data line

NEWLIN:	CALL	PUTVAL			; 
	CMPB	ROW(A5),#16.		; 
	BGE	10$
	INCB	ROW(A5)			; update row
	CALL	GETVAL			; 
	BR	20$			; 
10$:	MOVB	#1,ROW(A5)		; 
	CALL	GETVAL			; 
20$:	CALL	UPDATE			; clear out current data line
	BR	GETCOL			; 

PRVLIN:	CALL	PUTVAL			; 
	CMPB	ROW(A5),#1		; 
	BLE	10$			; 
	DECB	ROW(A5)			; 
	CALL	GETVAL			; 
	BR	20$			; 
10$:	MOVB	#16.,ROW(A5)		; 
	CALL	GETVAL			; 
20$:	CALL	UPDATE			; 

;get column based on relative position

GETCOL:	LEA	A6,COLTBL		; 
	CLR	D6			; 
	MOVB	POS(A5),D6		; 
	ASR	D6			; 
	ADD	D6,A6			; 
	MOVB	@A6,COL(A5)		; 

;position cursor and get a character

POSITION:
	MOV	#5,D0			; 
	ADDB	ROW(A5),D0		; 
	CURSOR	D0,COL(A5)		; 
	CRT	28			; 
	TIN				; 
	MOV	D1,D0			; 
	CRT	29			; 
	MOV	D0,D1			; 

EDIT:	CMPB	D1,#$ESC		; 
	JEQ	QUIT			; 
	CMPB	D1,#'M-'@		; 
	JEQ	NEWLIN			; 
	CMPB	D1,#'J-'@		; 
	JEQ	NEWLIN			; 
	CMPB	D1,#'K-'@		; 
	JEQ	PRVLIN			; 
	CMPB	D1,#'H-'@		; 
	JEQ	BACKUP			; 
	CMPB	D1,#'L-'@		; 
	JEQ	ADVANCE			; 
	CMPB	D1,#'U-'@		; 
	JEQ	FAR.LEFT		; 
	CMPB	D1,#'N-'@		; 
	JEQ	FAR.RIGHT		; 
	CMPB	D1,#'A-'@		; 
	JEQ	PREV.WORD		; 
	CMPB	D1,#'W-'@		; 
	JEQ	NEXT.WORD		; 
	CMPB	D1,#'S-'@		; 
	JEQ	CHART			; 
	CMPB	D1,#'R-'@		; 
	JEQ	PREV.SCREEN		; 
	CMPB	D1,#'T-'@		; 
	JEQ	NEXT.SCREEN		; 
	CMPB	D1,#'^-'@		; 
	JEQ	HOME			; 
	CMPB	D1,#'E-'@		; 
	JEQ	ENDCHT			; 
	CMPB	D1,#'?			; 
	JEQ	HELP			; 
	CMPB	D1,#'G-'@		; 
	BNE	JUMP			; 
	TIN				; 

JUMP:	CLRB	D0			; 
	MOVB	POS(A5),D0		; 
	MOVW	JMPTBL[~D0],D0		; 
	JMP	JMPTBL[~D0]		; 

DEFINE CASE LABEL=WORD LABEL-JMPTBL

JMPTBL:	CASE	BINARY8			; 000
	CASE	BINARY7			; 002
	CASE	BINARY6			; 004
	CASE	BINARY5			; 006
	CASE	BINARY4			; 008
	CASE	BINARY3			; 010
	CASE	BINARY2			; 012
	CASE	BINARY1			; 014
	CASE	OCTAL3			; 016
	CASE	OCTAL2			; 018
	CASE	OCTAL1			; 020
	CASE	DECIMAL3		; 022
	CASE	DECIMAL2		; 024
	CASE	DECIMAL1		; 026
	CASE	HEX2			; 028
	CASE	HEX1			; 030
	CASE	CHAR			; 032

BINARY8:
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B01111111,D1		; 
	CMPB	D0,#'0			; 
	JEQ	DIGIT			; 
	CMPB	D0,#'1			; 
	JNE	POSITION		; 
	ORB	#^B10000000,D1		; 
	JMP	DIGIT			; 

BINARY7:
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B10111111,D1		; 
	CMPB	D0,#'0			; 
	JEQ	DIGIT			; 
	CMPB	D0,#'1			; 
	JNE	POSITION		; 
	ORB	#^B01000000,D1		; 
	JMP	DIGIT			; 

BINARY6:
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B11011111,D1		; 
	CMPB	D0,#'0			; 
	JEQ	DIGIT			; 
	CMPB	D0,#'1			; 
	JNE	POSITION		; 
	ORB	#^B00100000,D1		; 
	JMP	DIGIT			; 

BINARY5:
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B11101111,D1		; 
	CMPB	D0,#'0			; 
	JEQ	DIGIT			; 
	CMPB	D0,#'1			; 
	JNE	POSITION		; 
	ORB	#^B00010000,D1		; 
	JMP	DIGIT			; 

BINARY4:
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B11110111,D1		; 
	CMPB	D0,#'0			; 
	JEQ	DIGIT			; 
	CMPB	D0,#'1			; 
	JNE	POSITION		; 
	ORB	#^B00001000,D1		; 
	JMP	DIGIT			; 

BINARY3:
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B11111011,D1		; 
	CMPB	D0,#'0			; 
	JEQ	DIGIT			; 
	CMPB	D0,#'1			; 
	JNE	POSITION		; 
	ORB	#^B00000100,D1		; 
	JMP	DIGIT			; 

BINARY2:
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B11111101,D1		; 
	CMPB	D0,#'0			; 
	JEQ	DIGIT			; 
	CMPB	D0,#'1			; 
	JNE	POSITION		; 
	ORB	#^B00000010,D1		; 
	JMP	DIGIT			; 

BINARY1:
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B11111110,D1		; 
	CMPB	D0,#'0			; 
	BEQ	10$			; 
	CMPB	D0,#'1			; 
	JNE	POSITION		; 
	ORB	#^B00000001,D1		; 
10$:	MOVB	D1,BYTE(A5)		; 
	CALL	UPDATE			; 
	CLRW	POS(A5)			; 
	JMP	NEWLIN			; 

OCTAL3:	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B00111111,D1		; 
	CMPB	D0,#'0			; 
	JLO	POSITION		; 
	CMPB	D0,#'7			; 
	JHI	POSITION		; 
	SUBB	#'0,D0			; 
	ROL	D0,#6			; 
	ADDB	D0,D1			; 
	JMP	DIGIT			; 

OCTAL2:	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B11000111,D1		; 
	CMPB	D0,#'0			; 
	JLO	POSITION		; 
	CMPB	D0,#'7			; 
	JHI	POSITION		; 
	SUBB	#'0,D0			; 
	ROL	D0,#3			; 
	ADDB	D0,D1			; 
	JMP	DIGIT			; 

OCTAL1:	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B11111000,D1		; 
	CMPB	D0,#'0			; 
	JLO	POSITION		; 
	CMPB	D0,#'7			; 
	JHI	POSITION		; 
	SUBB	#'0,D0			; 
	ADDB	D0,D1			; 
	MOVB	D1,BYTE(A5)		; 
	CALL	UPDATE			; 
	MOVB	#16.,POS(A5)		; 
	JMP	NEWLIN			; 

DECIMAL3:
	CMPB	D1,#'0			; 
	JLO	POSITION		; 
	CMPB	D1,#'9			; 
	JHI	POSITION		; 
	MOVB	D1,D0			; 
	CLR	D1			; 
	MOVB	BYTE(A5),D1		; 
	LEA	A2,BUFFER(A5)		; 
	DCVT	3,OT$MEM		; 
	CLRB	@A2			; 
	CLRB	BUFFER(A5)		; 
	ADDB	D0,BUFFER(A5)		; 
	LEA	A2,BUFFER(A5)		; 
	GTDEC				; 
	JMP	DIGIT			; 

DECIMAL2:
	CMPB	D1,#'0			; 
	JLO	POSITION		; 
	CMPB	D1,#'9			; 
	JHI	POSITION		; 
	MOVB	D1,D0			; 
	CLR	D1			; 
	MOVB	BYTE(A5),D1		; 
	LEA	A2,BUFFER(A5)		; 
	DCVT	3,OT$MEM		; 
	CLRB	@A2			; 
	CLRB	BUFFER+1(A5)		; 
	ADDB	D0,BUFFER+1(A5)		; 
	LEA	A2,BUFFER(A5)		; 
	GTDEC				; 
	JMP	DIGIT			; 

DECIMAL1:
	CMPB	D1,#'0			; 
	JLO	POSITION		; 
	CMPB	D1,#'9			; 
	JHI	POSITION		; 
	MOVB	D1,D0			; 
	CLR	D1			; 
	MOVB	BYTE(A5),D1		; 
	LEA	A2,BUFFER(A5)		; 
	DCVT	3,OT$MEM		; 
	CLRB	@A2			; 
	CLRB	BUFFER+2(A5)		; 
	ADDB	D0,BUFFER+2(A5)		; 
	LEA	A2,BUFFER(A5)		; 
	GTDEC				; 
	MOVB	D1,BYTE(A5)		; 
	CALL	UPDATE			; 
	MOVB	#22.,POS(A5)		; 
	JMP	NEWLIN			; 

HEX2:	UCS				; 
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B00001111,D1		; 
	CMPB	D0,#'A			; 
	BLO	10$			; 
	CMPB	D0,#'F			; 
	BHI	10$			; 
	SUBB	#'A,D0			; 
	ADDB	#10.,D0			; 
	BR	20$			; 
10$:	CMPB	D0,#'0			; 
	JLO	POSITION		; 
	CMPB	D0,#'7			; 
	JHI	POSITION		; 
	SUBB	#'0,D0			; 
20$:	ROL	D0,#4			; 
	ADDB	D0,D1			; 
	JMP	DIGIT			; 

HEX1:	UCS				; 
	MOVB	D1,D0			; 
	MOVB	BYTE(A5),D1		; 
	AND	#^B11110000,D1		; 
	CMPB	D0,#'A			; 
	BLO	10$
	CMPB	D0,#'F			; 
	BHI	10$			; 
	SUBB	#'A,D0			; 
	ADDB	#10.,D0			; 
	BR	20$			; 
10$:	CMPB	D0,#'0			; 
	JLO	POSITION		; 
	CMPB	D0,#'7			; 
	JHI	POSITION		; 
	SUBB	#'0,D0			; 
20$:	ADDB	D0,D1			; 
	MOVB	D1,BYTE(A5)		; 
	CALL	UPDATE			; 
	MOVB	#28.,POS(A5)		; 
	JMP	NEWLIN			; 

DIGIT:	MOVB	D1,BYTE(A5)		; 
	ADDB	#2,POS(A5)		; 
	CALL	PUTVAL			; 
	CALL	UPDATE			; 
	JMP	GETCOL			; 

CHAR:	MOVB	D1,BYTE(A5)		; 
	CALL	PUTVAL			; 
	CALL	UPDATE			; 
	JMP	NEWLIN			; 

;move left one cursor position

BACKUP:	TSTB	POS(A5)			; 
	BNE	10$			; 
	MOVB	#32.,POS(A5)		; 
	BR	20$			; 
10$:	SUBB	#2,POS(A5)		; 
20$:	JMP	GETCOL			; 

;move right one cursor position

ADVANCE:
	ADDB	#2,POS(A5)		; 
	CMPB	POS(A5),#32.		; 
	BLOS	10$			; 
	CLRB	POS(A5)			; 
10$:	JMP	GETCOL			; 

;move to far left cursor position

FAR.LEFT:
	CLRB	POS(A5)			; 
	JMP	GETCOL			; 

;move to far right cursor position

FAR.RIGHT:
	MOVB	#32.,POS(A5)		; 
	JMP	GETCOL			; 

;move "word" back

PREV.WORD:
	TSTB	POS(A5)			; 
	BNE	10$			; 
	MOVB	#32.,POS(A5)		; 
	JMP	GETCOL			; 
10$:	LEA	A6,COLTBL		; 
	CLR	D6			; 
	MOVB	POS(A5),D6		; 
	ASR	D6			; 
	ADD	D6,A6			; 
	MOVB	@A6,D6			; 
20$:	DECB	D6			; 
	SUBB	#2,POS(A5)		; 
	JEQ	FAR.LEFT		; 
	MOVB	-(A6),D7		; 
	CMPB	D6,D7			; 
	BEQ	20$			; 
	MOVB	D7,D6			; 
30$:	DECB	D6			; 
	MOVB	-(A6),D7		; 
	CMPB	D6,D7			; 
	JNE	GETCOL			; 
	SUBB	#2,POS(A5)		; 
	BR	30$			; 

;move "word" forward

NEXT.WORD:
	LEA	A6,COLTBL		; 
	CLR	D6			; 
	MOVB	POS(A5),D6		; 
	ASR	D6			; 
	ADD	D6,A6			; 
	MOVB	(A6)+,D6		; 
10$:	INCB	D6			; 
	ADDB	#2,POS(A5)		; 
	MOVB	(A6)+,D7		; 
	BEQ	FAR.LEFT		; 
	CMPB	D6,D7			; 
	BEQ	10$			; 
	JMP	GETCOL			; 

;**********
;*  HOME  *
;**********
;Home - display first page of ISO Latin I character set chart

HOME:	CALL	PUTVAL			; 
	MOVB	#1,ROW(A5)		; 
	CALL	GETVAL			; 
	CLRB	BYTE(A5)		; 
	CALL	PUTVAL			; 
	BR	CHART			; 

;************
;*  ENDCHT  *
;************
;End of chart - display last page of ISO Latin I character set chart

ENDCHT:	CALL	PUTVAL			; 
	MOVB	#1,ROW(A5)		; 
	CALL	GETVAL			; 
	MOVB	#255.-15.,BYTE(A5)	; 
	CALL	PUTVAL			; 
	BR	CHART			; 

;*****************
;*  PREV.SCREEN  *
;*****************
;Show previous screen of ISO Latin I character set chart

PREV.SCREEN:
	CALL	PUTVAL			; 
	MOVB	#1,ROW(A5)		; 
	CALL	GETVAL			; 
	SUBB	#16.,BYTE(A5)		; 
	CALL	PUTVAL			; 
	BR	CHART			; 

;*****************
;*  NEXT.SCREEN  *
;*****************
;Show next screen of ISO Latin I character set chart

NEXT.SCREEN:
	CALL	PUTVAL			; 
	MOVB	#1,ROW(A5)		; 
	CALL	GETVAL			; 
	ADDB	#16.,BYTE(A5)		; 
	CALL	PUTVAL			; 
					; fall through
;***********
;*  CHART  *
;***********
;Display section of ISO Latin I character set chart centered around
;current position and value

CHART:	LEA	A0,BYTTBL(A5)		; 
	CLR	D6			; 
	MOVB	ROW(A5),D6		; 
	DEC	D6			; 
	ADD	D6,A0			; 
	MOVB	ROW(A5),D0		; 

10$:	DECB	D0			; 
	BEQ	12$			; 
	MOVB	@A0,D7			; 
	DECB	D7			; 
	MOVB	D7,-(A0)		; 
	BR	10$			; 

12$:	LEA	A0,BYTTBL(A5)		; 
	CLR	D6			; 
	MOVB	ROW(A5),D6		; 
	DEC	D6			; 
	ADD	D6,A0			; 
	MOVB	ROW(A5),D0		; 

20$:	INCB	D0			; 
	CMPB	D0,#16.			; 
	BHI	22$			; 
	MOVB	@A0,D7			; 
	INCB	D7			; 
	MOVB	D7,1(A0)		; 
	INC	A0			; 
	BR	20$			; 

22$:	CALL	SHOW.LINES		; 
	JMP	POSITION		; 

;**********
;*  HELP  *
;**********
;Display help screen

HELP:	CRT	23			; 

	CURSOR	#3,#21.			; 
	CRT	46			; 
	CURSOR	#3,#27.			; 
	CRT	46			; 
	CURSOR	#3,#33.			; 
	CRT	46			; 
	CURSOR	#3,#39.			; 
	CRT	46			; 
	CURSOR	#3,#44.			; 
	CRT	46			; 

	CURSOR	#5,#10.			; 
	CRT	47			; 
	CURSOR	#5,#70.			; 
	CRT	47			; 

	CURSOR	#22.,#21.		; 
	CRT	46			; 
	CURSOR	#22.,#27.		; 
	CRT	46			; 
	CURSOR	#22.,#33.		; 
	CRT	46			; 
	CURSOR	#22.,#39.		; 
	CRT	46			; 
	CURSOR	#22.,#44.		; 
	CRT	46			; 

	CRT	24			; 

	CURSOR	#4,#11.			; 
	TYPE	< The BYTE utility is a living conversion table.  To obtain >
	CURSOR	#5,#11.			; 
	TYPE	< a conversion, simply move the cursor to the appropriate   >
	CURSOR	#6,#11.			; 
	TYPE	< column using the left or right arrow keys, and then enter >
	CURSOR	#7,#11.			; 
	TYPE	< a value.  As you type, all of the other columns update    >
	CURSOR	#8.,#11.		; 
	TYPE	< dynamically.  Press RETURN, down arrow, or up arrow to    >
	CURSOR	#9.,#11.		; 
	TYPE	< move up or down a line at a time.                         >
	CURSOR	#10.,#11.		; 
	TYPE	<                                                           >
	CURSOR	#11.,#11.		; 
	TYPE	< BYTE supports the ISO Latin I character set, a superset   >
	CURSOR	#12.,#11.		; 
	TYPE	< of ASCII.  Source: UltraSoft Corporation (516) 348-4848.  >
	CURSOR	#13.,#11.		; 
	TYPE	<                                                           >
	CURSOR	#14.,#11.		; 
	TYPE	< To enter a character that BYTE normally responds to (ESC, >
	CURSOR	#15.,#11.		; 
	TYPE	< for example), press Control-G and then the character.     >
	CURSOR	#16.,#11.		; 
	TYPE	<                                                           >
	CURSOR	#17.,#11.		; 
	TYPE	<                     ADDITIONAL COMMANDS                   >
	CURSOR	#18.,#11.		; 
	TYPE	< ESC - exit to AMOS                       ? - help         >
	CURSOR	#19.,#11.		; 
	TYPE	< ^S - fill out table   ^A - field left   ^W - field right  >
	CURSOR	#20.,#11.		; 
	TYPE	< ^^ - top of chart     ^U - far left     ^N - far right    >
	CURSOR	#21.,#11.		; 
	TYPE	< ^E - end of chart     ^R - page back    ^T - page forward >
	TIN				; 
	CALL	SCREEN			; 
	CALL	SHOW.LINES		; 
	JMP	POSITION		; 

;************
;*  UPDATE  *
;************
;Function:	Update values on current line
;
;Inputs:	BYTE(A5) - current value

UPDATE:	SAVE	A0,D0,D5		; 
	MOV	#5,D5			; 
	ADDB	ROW(A5),D5		; 

;binary

UP.BIN:	CURSOR	D5,#12.			; 
	CLR	D0			; 
	MOVB	BYTE(A5),D0		; 
	MOV	#8.,D2			; 
10$:	ASLB	D0			; 
	BCC	20$			; 
	TYPE	1			; 
	BR	30$			; 
20$:	TYPE	0			; 
30$:	SOB	D2,10$			; 

;octal

UP.OCT:	CURSOR	D5,#23.			; 
	JOBIDX				; 
	ANDW	#^C<J.HEX>,JOBTYP(A6)	; 
	CLR	D1			; 
	MOVB	BYTE(A5),D1		; 
	OCVT	3,OT$TRM		; 

;decimal

UP.DEC:	CURSOR	D5,#29.			; 
	CLR	D1			; 
	MOVB	BYTE(A5),D1		; 
	DCVT	3,OT$TRM		; 

;hexadecimal

UP.HEX:	CURSOR	D5,#36.			; 
	JOBIDX				; 
	ORW	#J.HEX,JOBTYP(A6)	; 
	CLR	D1			; 
	MOVB	BYTE(A5),D1		; 
	OCVT	2,OT$TRM		; 

;output character image

UP.CHR:	CURSOR	D5,#41.			; 
	MOVB	BYTE(A5),D1		; 
	CMPB	D1,#40			; 
	BLO	UP.CHC			; 
	CMPB	D1,#'~			; 
	BLOS	UP.CHP			; 
	CMPB	D1,#240			; 
	BLO	UP.CHN			; 

UP.CHP:	TYPESP				; 
	TTY				; 
	BR	UP.DSC			; 

UP.CHC:	TYPE	^			; 
	ADDB	#'@,D1			; 
	TTY				; 
	BR	UP.DSC			; 

UP.CHN:	TYPE	<  >			; 

;output character description

UP.DSC:	CURSOR	D5,#46.			; 
	LEA	A0,DSCTBL		; 
	CLR	D0			; 
	MOVB	BYTE(A5),D0		; 
	BEQ	20$			; 
10$:	TSTB	(A0)+			; 
	BNE	10$			; 
	SOB	D0,10$			; 
20$:	MOV	#23.,D2			; 
30$:	MOVB	(A0)+,D1		; 
	BEQ	40$			; 
	TTY				; 
	DEC	D2			; 
	BR	30$			; 
40$:	TST	D2			; 
	BLE	60$			; 
50$:	TYPE	< >			; 
	SOB	D2,50$			; 
60$:

;return

UP.RTN:	REST	A0,D0,D5		; 
	RTN				; 

;**********
;*  QUIT  *
;**********
;Exit program

QUIT:	CURSOR	#23.,#1			; 
	CRT	9			; 
	CURSOR	#24.,#1			; 
	CRT	9			; 
	CRT	12			; 
	CRT	28			; 
	EXIT				; 

;***********
;*  CLEAR  *
;***********
;Function:	Clear current data line

CLEAR:	SAVE	D0			; 
	MOV	#5,D0			; 
	ADDB	ROW(A5),D0		; 
	CURSOR	D0,#12.			; 
	TYPE	00000000		; 
	CLRB	BYTE(A5)		; 
	CURSOR	D0,#23.			; 
	TYPE	000			; 
	CURSOR	D0,#29.			; 
	TYPE	000			; 
	CURSOR	D0,#35.			; 
	TYPE	$00			; 
	CURSOR	D0,#41.			; 
	TYPE	<^@>			; 
	CURSOR	D0,#46.			; 
	TYPE	<Null                   >
	REST	D0			; 
	RTN				; 

;************
;*  SCREEN  *
;************
;Function:	Put up display screen

SCREEN:	CRT	29			; turn off cursor
	CRT	0			; clear screen
	CRT	12			; high intensity

	CURSOR	#1,#55.			; reverse video banner
	CRT	33			; 
	CURSOR	#1,#27.			; 
	CRT	32			; 
	TYPE	< Byte Conversion Utility >
	CRT	33			; 

	CRT	11			; low intensity
	CURSOR	#1,#1			; output user name
	JOBIDX				; 
	TTYL	JOBUSN(A6)		; 

	CURSOR	#1,#63.			; output date and time
	CLR	D3			; 
	CLR	D4			; 
	CLR	D5			; 
	MOV	#0,A2			; 
	CALL	$ODTIM			; 
	CRT	12			; high intensity

	CRT	23			; enable alternate character set

;top of grid

	CURSOR	#3,#10.			; 
	CRT	38			; top left corner
	REPEAT	10.,<CRT 46>		; line over "Binary"
	CRT	42			; top intersect
	REPEAT	5,<CRT 46>		; line over "Oct"
	CRT	42			; top intersect
	REPEAT	5,<CRT 46>		; line over "Dec"
	CRT	42			; top intersect
	REPEAT	5,<CRT 46>		; line over "Hex"
	CRT	42			; top intersect
	REPEAT	4,<CRT 46>		; line over "Ch"
	CRT	42			; top intersect
	REPEAT	25.,<CRT 46>		; line over "Description"
	CRT	39			; top right corner

;label line of grid

	CURSOR	#4,#10.			; 
	CRT	47			; vertical line
	CRT	24			; 
	TYPE	<  Binary  >		; 
	CRT	23			; 
	CRT	47			; 
	CRT	24			; 
	TYPE	< Oct >			; 
	CRT	23			; 
	CRT	47			; 
	CRT	24			; 
	TYPE	< Dec >			; 
	CRT	23			; 
	CRT	47			; 
	CRT	24			; 
	TYPE	< Hex >			; 
	CRT	23			; 
	CRT	47			; 
	CRT	24			; 
	TYPE	< Ch >			; 
	CRT	23			; 
	CRT	47			; 
	CRT	24			; 
	TYPE	< Description             >
	CRT	23			; 
	CRT	47			; 

;lines under labels

	CURSOR	#5,#10.			; 
	CRT	44			; left intersect
	REPEAT	10.,<CRT 46>		; line over "Binary"
	CRT	48			; center intersect
	REPEAT	5,<CRT 46>		; line over "Oct"
	CRT	48			; center intersect
	REPEAT	5,<CRT 46>		; line over "Dec"
	CRT	48			; center intersect
	REPEAT	5,<CRT 46>		; line over "Hex"
	CRT	48			; center intersect
	REPEAT	4,<CRT 46>		; line over "Ch"
	CRT	48			; center intersect
	REPEAT	25.,<CRT 46>		; line over "Description"
	CRT	43			; right intersect

;data lines

	MOV	#6,D0			; 
	MOV	#16.,D2			; 
10$:	CURSOR	D0,#10.			; 
	CRT	47			; vertical line
	CURSOR	D0,#21.			; 
	CRT	47			; 
	CURSOR	D0,#27.			; 
	CRT	47			; 
	CURSOR	D0,#33.			; 
	CRT	47			; 
	CURSOR	D0,#39.			; 
	CRT	47			; 
	CURSOR	D0,#44.			; 
	CRT	47			; 
	CURSOR	D0,#70.			; 
	CRT	47			; 
	INCW	D0			; 
	SOB	D2,10$			; 

;bottom of grid

	CURSOR	#22.,#10.		; 
	CRT	40			; bottom left corner
	REPEAT	10.,<CRT 46>		; line under "Binary"
	CRT	45			; bottom intersect
	REPEAT	5,<CRT 46>		; line under "Oct"
	CRT	45			; bottom intersect
	REPEAT	5,<CRT 46>		; line under "Dec"
	CRT	45			; bottom intersect
	REPEAT	5,<CRT 46>		; line under "Hex"
	CRT	45			; bottom intersect
	REPEAT	4,<CRT 46>		; line under "Ch"
	CRT	45			; bottom intersect
	REPEAT	25.,<CRT 46>		; line under "Description"
	CRT	41			; bottom right corner

	CRT	24			; turn off alternate character set

	CURSOR	#23.,#30.		; 
	TYPE	[ Press ? for help ]	; 
	CURSOR	#24.,#21.		; 
	TYPE	[ Press ESCAPE to leave this screen ]

	RTN				; 

;****************
;*  SHOW.LINES  *
;****************
;Function:	Show value of all data lines

SHOW.LINES:
	PUSHB	ROW(A5)			; 
	PUSHB	BYTE(A5)		; 

	LEA	A0,BYTTBL(A5)		; 
	MOVB	#1,ROW(A5)		; 
30$:	MOVB	(A0)+,BYTE(A5)		; 
	CALL	UPDATE			; 
	INCB	ROW(A5)			; 
	CMPB	ROW(A5),#16.		; 
	BLE	30$			; 

	POPB	BYTE(A5)		; 
	POPB	ROW(A5)			; 
	RTN				; 

;************
;*  GETVAL  *
;************
;Function:	Get current data line value from table
;
;Inputs:	BYTTBL(A5) - byte table
;		ROW(A5)    - row (1-16)
;
;Outputs:	BYTE(A5)   - value for current row

GETVAL:	CLR	D6			; 
	MOVB	ROW(A5),D6		; 
	DEC	D6			; 
	LEA	A6,BYTTBL(A5)		; 
	ADD	D6,A6			; 
	MOVB	@A6,BYTE(A5)		; 
	RTN				; 

;************
;*  PUTCAL  *
;************
;Function:	Put current byte into data line value table
;
;Inputs:	BYTE(A5)   - byte
;		ROW(A5)    - row (1-16)
;
;Outputs:	BYTTBL(A5) - updated

PUTVAL:	CLR	D6			; 
	MOVB	ROW(A5),D6		; 
	DEC	D6			; 
	LEA	A6,BYTTBL(A5)		; 
	ADD	D6,A6			; 
	MOVB	BYTE(A5),@A6		; 
	RTN				; 

;************
;*  COLTBL  *
;************
;table of column positions

	BYTE	0			; ** start of table marker **

COLTBL:	BYTE	12.			; 000 binary 8
	BYTE	13.			; 002 binary 7
	BYTE	14.			; 004 binary 6
	BYTE	15.			; 006 binary 5
	BYTE	16.			; 008 binary 4
	BYTE	17.			; 010 binary 3
	BYTE	18.			; 012 binary 2
	BYTE	19.			; 014 binary 1

	BYTE	23.			; 016 octal 3
	BYTE	24.			; 018 octal 2
	BYTE	25.			; 020 octal 1

	BYTE	29.			; 022 decimal 3
	BYTE	30.			; 024 decimal 2
	BYTE	31.			; 026 decimal 1

	BYTE	36.			; 028 hex 2
	BYTE	37.			; 030 hex 1

	BYTE	42.			; 032 char 1

	BYTE	0			; ** end of table **

;************
;*  DSCTBL  *
;************
;table of character descriptions

DSCTBL:	ASCIZ	"Null"			; 000
	ASCIZ	"Start of Heading"	; 001
	ASCIZ	"Start of Text"		; 002
	ASCIZ	"End of Text"		; 003
	ASCIZ	"End of Transmission"	; 004
	ASCIZ	"Enquiry"		; 005
	ASCIZ	"Acknowledge"		; 006
	ASCIZ	"Bell"			; 007
	ASCIZ	"Backspace"		; 008
	ASCIZ	"Horizontal Tab"	; 009
	ASCIZ	"Line Feed"		; 010
	ASCIZ	"Vertical Tab"		; 011
	ASCIZ	"Form Feed"		; 012
	ASCIZ	"Carriage Return"	; 013
	ASCIZ	"Shift Out"		; 014
	ASCIZ	"Shift In"		; 015
	ASCIZ	"Data Link Escape"	; 016
	ASCIZ	"Device Control 1"	; 017
	ASCIZ	"Device Control 2"	; 018
	ASCIZ	"Device Control 3"	; 019
	ASCIZ	"Device Control 4"	; 020
	ASCIZ	"Negative Acknowledge"	; 021
	ASCIZ	"Synchronous Idle"	; 022
	ASCIZ	"End Transmission Blocks" ; 023
	ASCIZ	"Cancel"		; 024
	ASCIZ	"End of Medium"		; 025
	ASCIZ	"Special Sequence"	; 026
	ASCIZ	"Escape"		; 027
	ASCIZ	"File Separator"	; 028
	ASCIZ	"Group Separator"	; 029
	ASCIZ	"Record Sepatator"	; 030
	ASCIZ	"Unit Separator"	; 031
	ASCIZ	"Space"			; 032
	ASCIZ	"Exclamation Mark"	; 033
	ASCIZ	"Quotation Mark"	; 034
	ASCIZ	"Number Sign"		; 035
	ASCIZ	"Dollar Sign"		; 036
	ASCIZ	"Percent Sign"		; 037
	ASCIZ	"Ampersand"		; 038
	ASCIZ	"Apostrophe"		; 039
	ASCIZ	"Opening Parenthesis"	; 040
	ASCIZ	"Closing Parenthesis"	; 041
	ASCIZ	"Asterisk"		; 042
	ASCIZ	"Plus"			; 043
	ASCIZ	"Comma"			; 044
	ASCIZ	"Dash or Minus"		; 045
	ASCIZ	"Period"		; 046
	ASCIZ	"Slash"			; 047
	ASCIZ	"Zero"			; 048
	ASCIZ	"One"			; 049
	ASCIZ	"Two"			; 050
	ASCIZ	"Three"			; 051
	ASCIZ	"Four"			; 052
	ASCIZ	"Five"			; 053
	ASCIZ	"Six"			; 054
	ASCIZ	"Seven"			; 055
	ASCIZ	"Eight"			; 056
	ASCIZ	"Nine"			; 057
	ASCIZ	"Colon"			; 058
	ASCIZ	"Semicolon"		; 059
	ASCIZ	"Left Angle Bracket"	; 060
	ASCIZ	"Equal Sign"		; 061
	ASCIZ	"Right Angle Bracket"	; 062
	ASCIZ	"Question Mark"		; 063
	ASCIZ	"Commerical At"		; 064
	ASCIZ	"Upper case A"		; 065
	ASCIZ	"Upper case B"		; 066
	ASCIZ	"Upper case C"		; 067
	ASCIZ	"Upper case D"		; 068
	ASCIZ	"Upper case E"		; 069
	ASCIZ	"Upper case F"		; 070
	ASCIZ	"Upper case G"		; 071
	ASCIZ	"Upper case H"		; 072
	ASCIZ	"Upper case I"		; 073
	ASCIZ	"Upper case J"		; 074
	ASCIZ	"Upper case K"		; 075
	ASCIZ	"Upper case L"		; 076
	ASCIZ	"Upper case M"		; 077
	ASCIZ	"Upper case N"		; 078
	ASCIZ	"Upper case O"		; 079
	ASCIZ	"Upper case P"		; 080
	ASCIZ	"Upper case Q"		; 081
	ASCIZ	"Upper case R"		; 082
	ASCIZ	"Upper case S"		; 083
	ASCIZ	"Upper case T"		; 084
	ASCIZ	"Upper case U"		; 085
	ASCIZ	"Upper case V"		; 086
	ASCIZ	"Upper case W"		; 087
	ASCIZ	"Upper case X"		; 088
	ASCIZ	"Upper case Y"		; 089
	ASCIZ	"Upper case Z"		; 090
	ASCIZ	"Left Square Bracket"	; 091
	ASCIZ	"Backslash"		; 092
	ASCIZ	"Right Square Bracket"	; 093
	ASCIZ	"Circumflex"		; 094
	ASCIZ	"Underscore"		; 095
	ASCIZ	"Grave Accent"		; 096
	ASCIZ	"Lower case a"		; 097
	ASCIZ	"Lower case b"		; 098
	ASCIZ	"Lower case c"		; 099
	ASCIZ	"Lower case d"		; 100
	ASCIZ	"Lower case e"		; 101
	ASCIZ	"Lower case f"		; 102
	ASCIZ	"Lower case g"		; 103
	ASCIZ	"Lower case h"		; 104
	ASCIZ	"Lower case i"		; 105
	ASCIZ	"Lower case j"		; 106
	ASCIZ	"Lower case k"		; 107
	ASCIZ	"Lower case l"		; 108
	ASCIZ	"Lower case m"		; 109
	ASCIZ	"Lower case n"		; 110
	ASCIZ	"Lower case o"		; 111
	ASCIZ	"Lower case p"		; 112
	ASCIZ	"Lower case q"		; 113
	ASCIZ	"Lower case r"		; 114
	ASCIZ	"Lower case s"		; 115
	ASCIZ	"Lower case t"		; 116
	ASCIZ	"Lower case u"		; 117
	ASCIZ	"Lower case v"		; 118
	ASCIZ	"Lower case w"		; 119
	ASCIZ	"Lower case x"		; 120
	ASCIZ	"Lower case y"		; 121
	ASCIZ	"Lower case z"		; 122
	ASCIZ	"Right Curly Brace"	; 123
	ASCIZ	"Vertical Bar"		; 124
	ASCIZ	"Left Curly Brace"	; 125
	ASCIZ	"Tilde"			; 126
	ASCIZ	"Del"			; 127
	ASCIZ	"ISO Upper Control-@"	; 128
	ASCIZ	"ISO Upper Control-A"	; 129
	ASCIZ	"ISO Upper Control-B"	; 130
	ASCIZ	"ISO Upper Control-C"	; 131
	ASCIZ	"ISO Upper Control-D"	; 132
	ASCIZ	"ISO Upper Control-E"	; 133
	ASCIZ	"ISO Upper Control-F"	; 134
	ASCIZ	"ISO Upper Control-G"	; 135
	ASCIZ	"ISO Upper Control-H"	; 136
	ASCIZ	"ISO Upper Control-I"	; 137
	ASCIZ	"ISO Upper Control-J"	; 138
	ASCIZ	"ISO Upper Control-K"	; 139
	ASCIZ	"ISO Upper Control-L"	; 140
	ASCIZ	"ISO Upper Control-M"	; 141
	ASCIZ	"ISO Upper Control-N"	; 142
	ASCIZ	"ISO Upper Control-O"	; 143
	ASCIZ	"ISO Upper Control-P"	; 144
	ASCIZ	"ISO Upper Control-Q"	; 145
	ASCIZ	"ISO Upper Control-R"	; 146
	ASCIZ	"ISO Upper Control-S"	; 147
	ASCIZ	"ISO Upper Control-T"	; 148
	ASCIZ	"ISO Upper Control-U"	; 149
	ASCIZ	"ISO Upper Control-V"	; 150
	ASCIZ	"ISO Upper Control-W"	; 151
	ASCIZ	"ISO Upper Control-X"	; 152
	ASCIZ	"ISO Upper Control-Y"	; 153
	ASCIZ	"ISO Upper Control-Z"	; 154
	ASCIZ	"ISO Upper Control-["	; 155
	ASCIZ	"ISO Upper Control-\"	; 156
	ASCIZ	"ISO Upper Control-]"	; 157
	ASCIZ	"ISO Upper Control-^"	; 158
	ASCIZ	"ISO Upper Control-_"	; 159
	ASCIZ	"Required Space"	; 160
	ASCIZ	"Inverse Exclamation Mrk" ; 161
	ASCIZ	"Cents"			; 162
	ASCIZ	"Sterling"		; 163
	ASCIZ	"Currency"		; 164
	ASCIZ	"Yen"			; 165
	ASCIZ	"Split Bar"		; 166
	ASCIZ	"Section"		; 167
	ASCIZ	"Dieresis"		; 168
	ASCIZ	"Copyright"		; 169
	ASCIZ	"Ord Feminine"		; 170
	ASCIZ	"Opening Guillemets"	; 171
	ASCIZ	"Not"			; 172
	ASCIZ	"Discretionary Hyphen"	; 173
	ASCIZ	"Registered"		; 174
	ASCIZ	"Hyphen"		; 175
	ASCIZ	"Ring"			; 176
	ASCIZ	"Plus or Minus"		; 177
	ASCIZ	"2 superscript"		; 178
	ASCIZ	"3 superscript"		; 179
	ASCIZ	"Acute Accent"		; 180
	ASCIZ	"Micro"			; 181
	ASCIZ	"Paragraph"		; 182
	ASCIZ	"Bullet"		; 183
	ASCIZ	"Cedilla"		; 184
	ASCIZ	"1 superscript"		; 185
	ASCIZ	"Ord Masculine"		; 186
	ASCIZ	"Closing Guillemets"	; 187
	ASCIZ	"One-quarter"		; 188
	ASCIZ	"One-half"		; 189
	ASCIZ	"Three-quarters"	; 190
	ASCIZ	"Inverse question mark"	; 191
	ASCIZ	"Upper case A grave"	; 192
	ASCIZ	"Upper case A acute"	; 193
	ASCIZ	"Upper case A circumflex" ; 194
	ASCIZ	"Upper case A tilde"	; 195
	ASCIZ	"Upper case A umlaut"	; 196
	ASCIZ	"Upper case A ring"	; 197
	ASCIZ	"Upper case AE ligature" ; 198
	ASCIZ	"Upper case C cedilla" ; 199
	ASCIZ	"Upper case E grave"	; 200
	ASCIZ	"Upper case E acute"	; 201
	ASCIZ	"Upper case E circumflex" ; 202
	ASCIZ	"Upper case E dieresis"	; 203
	ASCIZ	"Upper case I grave"	; 204
	ASCIZ	"Upper case I acute"	; 205
	ASCIZ	"Upper case I circumflex" ; 206
	ASCIZ	"Upper case I dieresis"	; 207
	ASCIZ	"Upper case Eth"	; 208
	ASCIZ	"Upper case N tilde"	; 209
	ASCIZ	"Upper case O grave"	; 210
	ASCIZ	"Upper case O acute"	; 211
	ASCIZ	"Upper case O circumflex" ; 212
	ASCIZ	"Upper case O tilde"	; 213
	ASCIZ	"Upper case O umlaut"	; 214
	ASCIZ	"Times"			; 215
	ASCIZ	"Upper case O slash"	; 216
	ASCIZ	"Upper case U grave"	; 217
	ASCIZ	"Upper case U acute"	; 218
	ASCIZ	"Upper case U circumflex" ; 219
	ASCIZ	"Upper case U umlaut"	; 220
	ASCIZ	"Upper case Y acute"	; 221
	ASCIZ	"Upper case Thorn"	; 222
	ASCIZ	"Ess tset"		; 223
	ASCIZ	"Lower case A grave"	; 224
	ASCIZ	"Lower case A acute"	; 225
	ASCIZ	"Lower case A circumflex" ; 226
	ASCIZ	"Lower case A tilde"	; 227
	ASCIZ	"Lower case A umlaut"	; 228
	ASCIZ	"Lower case A ring"	; 229
	ASCIZ	"Lower case AE ligature" ; 230
	ASCIZ	"Lower case C cedilla"	; 231
	ASCIZ	"Lower case E grave"	; 232
	ASCIZ	"Lower case E acute"	; 233
	ASCIZ	"Lower case E circumflex" ; 234
	ASCIZ	"Lower case E dieresis"	; 235
	ASCIZ	"Lower case I grave"	; 236
	ASCIZ	"Lower case I acute"	; 237
	ASCIZ	"Lower case I circumflex" ; 238
	ASCIZ	"Lower case I umlaut"	; 239
	ASCIZ	"Lower case Eth"	; 240
	ASCIZ	"Lower case N tilde"	; 241
	ASCIZ	"Lower case O grave"	; 242
	ASCIZ	"Lower case O acute"	; 243
	ASCIZ	"Lower case O circumflex" ; 244
	ASCIZ	"Lower case O tilde"	; 245
	ASCIZ	"Lower case O umlaut"	; 246
	ASCIZ	"Division"		; 247
	ASCIZ	"Lower case O slash"	; 248
	ASCIZ	"Lower case U grave"	; 249
	ASCIZ	"Lower case U acute"	; 250
	ASCIZ	"Lower case U circumflex" ; 251
	ASCIZ	"Lower case U umlaut"	; 252
	ASCIZ	"Lower case Y acute"	; 253
	ASCIZ	"Lower case Thorn"	; 254
	ASCIZ	"Lower case Y umlaut"	; 255
	BYTE	0			; ** end of table **

	EVEN				; 

	END