;
;PROGRAM TO CONVERT IMSAI VIO-C FONTS TO SSM VB-3 FONTS
;
;TO USE, LOAD AT 100 HEX UNDER DDT WITH IMSAI VIO ROM DATA
;FOR U49, U48, U47 LOADED AT 1000H, 1400H, 1800H, RESPECTIVELY.
;THIS PROGRAM LEAVES THE CORRESPONDING TWO CHARACTER SETS
;IN MEMORY AT 2000H-2800H AND 2800H-3000H, CORRESPONDING
;TO THE SETS STORED IN U49/U47 AND U48/U47, RESPECTIVELY.
;
;WRITTEN BY BARRY A. WATZMAN, MAR. 24, 1980
;
BASE	EQU	0
TPA	EQU	BASE+100H
VIODATA	EQU	BASE+1000H
VB3DATA	EQU	BASE+2000H
;
	ORG	TPA
;
;CLEAR THE DATA AREA TO HEX FF'S
;
	LXI	H,VB3DATA	;AREA TO CLEAR
	LXI	D,1000H		;COUNT
	MVI	B,0FFH
LOOP:	MOV	M,B
	INX	H
	DCX	D
	MOV	A,D		;TEST
	ORA	E
	JNZ	LOOP		;TILL DONE
;
;FILL IN DATA FROM LOW ORDER CHARACTER SET (8 ROWS FROM U49, 2 FROM U47)
;
	LXI	D,VB3DATA	;DESTINATION
	MVI	C,0		;CHAR CODE (HEX/ASCII)
CHARLP:	MVI	B,8		;NO OF BYTES PER CHAR IN U49
	LXI	H,VIODATA	;SOURCE
	PUSH	B		;SAVE COUNTS
	MVI	B,0		;B,C = HEX/ASCII CODE FOR CHARS
	DAD	B		;H,L POINTING TO 1ST BYTE FOR CHAR
	POP	B		;RESTORE H,L
BYTLP:	MOV	A,M		;GET BYTE
	ORI	80H		;IGNORE MSB
	STAX	D		;STORE IT
	INX	D		;POINT TO NEXT LOC. IN VB3 ROM
	PUSH	B		;SAVE COUNTERS
	LXI	B,80H		;OFFSET TO NEXT BYTE OF SAME CHAR
	DAD	B		;ADD TO VIO POINTER
	POP	B		;RESTORE COUNTER
	DCR	B		;DECR. COUNT OF BYTES IN ROM FOR THIS CHAR
	JNZ	BYTLP		;NOT DONE, DO NEXT BYTE
;
;HAVE U49 BYTES, NOW GET TWO BYTES FROM U47
;
	LXI	H,VIODATA+800H	;POINT TO DATA FROM U47
	PUSH	B		;SAVE B,C
	MVI	B,0		;B,C=HEX ASCII CODE FOR CHAR
	DAD	B		;ADD TO ROM START
	MOV	A,M		;GET BYTE
	ORI	80H		;IGNORE MSB
	STAX	D		;PUT BYTE
	INX	D		;INR DEST POINTER
	LXI	B,80H		;OFFSET TO NEXT BYTE IN U47
	DAD	B		;POINT TO IT
	MOV	A,M		;GET IT
	ORI	80H		;IGNORE MSB
	STAX	D		;STORE IT
	INX	D		;
	POP	B		;RESTORE COUNT
	INX	D		;VB3 HAS 16 BYTES PER CHAR, VIO ONLY 10
	INX	D
	INX	D
	INX	D
	INX	D
	INX	D
	INR	C		;ADVANCE CHAR POINTER
	JP	CHARLP		;DO NEXT CHAR UNLESS IT WENT TO 80H
;
;NOW REPEAT ENTIRE PROCEDURE FOR CHAR SET IN U48/U47
;
	MVI	C,0		;CHAR CODE (HEX/ASCII)
CHARLP1:MVI	B,8		;NO OF BYTES PER CHAR IN U49
	LXI	H,VIODATA+400H	;SOURCE
	PUSH	B		;SAVE COUNTS
	MVI	B,0		;B,C = HEX/ASCII CODE FOR CHARS
	DAD	B		;H,L POINTING TO 1ST BYTE FOR CHAR
	POP	B		;RESTORE H,L
BYTLP1:	MOV	A,M		;GET BYTE
	ORI	80H
	STAX	D		;STORE IT
	INX	D		;POINT TO NEXT LOC. IN VB3 ROM
	PUSH	B		;SAVE COUNTERS
	LXI	B,80H		;OFFSET TO NEXT BYTE OF SAME CHAR
	DAD	B		;ADD TO VIO POINTER
	POP	B		;RESTORE COUNTER
	DCR	B		;DECR. COUNT OF BYTES IN ROM FOR THIS CHAR
	JNZ	BYTLP1		;NOT DONE, DO NEXT BYTE
;
;HAVE U49 BYTES, NOW GET TWO BYTES FROM U47
;
	LXI	H,VIODATA+0A00H	;POINT TO DATA FROM U47
	PUSH	B		;SAVE B,C
	MVI	B,0		;B,C=HEX ASCII CODE FOR CHAR
	DAD	B		;ADD TO ROM START
	MOV	A,M		;GET BYTE
	ORI	80H
	STAX	D		;PUT BYTE
	INX	D		;INR DEST POINTER
	LXI	B,80H		;OFFSET TO NEXT BYTE IN U47
	DAD	B		;POINT TO IT
	MOV	A,M		;GET IT
	ORI	80H
	STAX	D		;STORE IT
	INX	D		;
	POP	B		;RESTORE COUNT
	INX	D		;VB3 HAS 16 BYTES PER CHAR, VIO ONLY 10
	INX	D
	INX	D
	INX	D
	INX	D
	INX	D
	INR	C		;ADVANCE CHAR POINTER
	JP	CHARLP1		;DO NEXT CHAR UNLESS IT WENT TO 80H
;
;NOW COMPLEMENT BYTES SINCE VIO DATA IS NEGATIVE
;
	LXI	H,VB3DATA	;AREA TO COMPLEMENT
	LXI	D,1000H		;LENGTH OF AREA
COMPLP:	MOV	A,M		;GET BYTE
	CMA			;COMPLEMENT
	MOV	M,A		;PUT BACK
	INX	H		;INR POINTER
	DCX	D		;DECR COUNT
	MOV	A,E
	ORA	D
	JNZ	COMPLP		;TEST & REPEAT TILL DONE
;
;NOW FOR THE HARD PART
;
;NEED TO REVERSE THE ORDER OF THE BITS IN THE BYTES
;
	LXI	H,VB3DATA	;AREA TO BIT-FLIP
	LXI	D,1000H		;LENGTH OF AREA
FLIPLP:	MOV	A,M		;GET BYTE
	CALL	FLIP		;FLIP IT
	MOV	M,A		;RESTORE IT
	INX	H		;INR POINTER
	DCX	D		;DECR COUNT
	MOV	A,E		;
	ORA	D		;
	JNZ	FLIPLP		;CONTINUE
;
;DONE, RETURN TO DDT
;
	RST	7		;DDT RE-ENTRY
;
;ROUTINE TO FLIP BITS OF BYTE IN A
;MUST PRESERVE H,L AND D,E, RETURN FLIPPED BYTE IN A
;
FLIP:	PUSH	D
	MVI	E,8		;NO OF BITS PER BYTE
	MVI	C,1		;MASK OF BIT TO SET
	MVI	B,0		;BYTE UNDER CONSTRUCTION
MORE:	RAL			;CARRY = HIGH ORDER BIT
	PUSH	PSW		;SAVE BYTE
	MOV	A,C		;GET MASK
	JNC	SKIPBIT		;BIT WAS 0
	ORA	B		;PUT BIT INTO BYTE
	MOV	B,A		;RESULT IN B
	MOV	A,C		;RESTORE SINGLE BIT VALUE IN C
SKIPBIT:RLC			;MOVE MASK LEFT
	MOV	C,A		;PUT MASK BACK IN C
	POP	PSW		;RESTORE BYTE
	DCR	E		;SEE IF DONE
	JNZ	MORE		;CONTINUE
	POP	D
	MOV	A,B		;RESTORE FINAL VALUE TO A
	RET
;
	END	CONVERT		;