;
;
;  LOAD  GRAFIC DRIVER STARTING AT B900 IN 200H
	ORG	100H
	MVI	C,09H
	LXI	D,NCR
	PUSH	PSW
	CALL	0005H
	POP	PSW
	LXI   	H,0B901H
     	LXI   	D,0200H
LOADD:  NOP
     	LXI   	B,0C90H      ;  NUMBER OF BYTES FOR GRAFIC DRIVER
LOOP:	MOV	A,M	
     	XCHG
	MOV 	M,A
     	XCHG
	INX 	H
     	INX 	D
	DCX 	B
	MOV 	A,B
     	CPI 	0H
	JNZ 	LOOP
	MOV 	A,C
     	CPI 	0H
     	JNZ 	LOOP
     	LXI     H,LOADD		;CHANGE NOP TO XCHG FOR REVERSE TRANSFER
	MVI     A,0EBH
	MOV     M,A
	RET
NCR:	DB	'GRAFIC EXTENSION for NCR DECISION MATE V'
	DW      0A0DH
	DB	'Version 1.0'
	DW	0A0DH
	DB	'Copyright (c) 1983, NCR'
	DW	0A0DH
	DB	'$'
; GDC TESTPROGRAMM FUER          MIXED MODE     1.0   (BK)
;=======================         LAST CHANGE    18.3.83
; 
       ;PUBLIC     GINIT 	;PUBLIC DECLARATIONS FOR
       ;PUBLIC     GPOINT	;RELOCATIBLE ASSEMBLY
       ;PUBLIC     GZOOM
       ;PUBLIC     GCIRCL
       ;PUBLIC     GLINE
       ;PUBLIC     GBOX
       ;PUBLIC     GRECT
       ;PUBLIC     GPATT
       ;PUBLIC     GMODE
       ;PUBLIC     GTEXT
       ;PUBLIC     GEXIT
       ;PUBLIC     GPRINT
;  GDC INIT. CONSTANTS .
; 
VC 	EQU  	0016H      ;GRAPHIC NON-INTERLACED 
AW      EQU  	0028H      ;ACT.DISPLAY WORD/LINE
HS      EQU  	000BH      ;HORZ. SYNC WIDTH
VSL     EQU  	0040H      ;VERTIC.SYNC WIDTH LOW
VSH     EQU  	0001H      ;VERTIC.SYNC WIDTH HIGH
HFP     EQU  	0004H      ;HORZ.FRONT PORCH WIDTH
HBP     EQU  	0001H      ;HORZ.BACK PORCH WIDTH
VFP     EQU  	000EH      ;VERT.FRONT PORCH WIDTH
ALL     EQU  	0090H      ;ACTIV DISPLAY LINES LOW
ALH     EQU  	0001H      ;ACTIV DISPLAY LINES HIGH
VBP     EQU  	0034H      ;VERT.BACK PORCH WIDTH
; 
; GRAPHIC ADAPTER ADDRESSES 
; 
BSA     EQU  	0FD00H     ;BOARD SELECT ADDRESS 
WPA     EQU  	00A0H      ;WRITE PARAMETER
RSTA    EQU  	00A0H      ;READ STATUS
WCO     EQU  	00A1H      ;WRITE COMMANDS
RFIF    EQU  	00A1H      ;READ FIFO
;  GDC COMMAND TABLE 
; 
LPRD    EQU  	00C0H      ;LIGHT PEN 
GDRE    EQU  	0000H 
VSYNC   EQU  	006FH
CCHR    EQU  	004BH 
STAG    EQU  	006BH 
ZOOM    EQU     0046H 	
CURS    EQU     0049H 
PRAM    EQU     0070H 
PITCH   EQU     0047H 
WDAT    EQU     0020H 
MASK    EQU     004AH 
FIGS    EQU     004CH 
FIGD    EQU     006CH 
GCHD    EQU     0068H 
RDAT    EQU     00A0H 
CURD    EQU     00E0H 
WSET    EQU     0003H 
WCLR    EQU     0002H 
WCOM    EQU     0001H 
WREP    EQU     0000H 
PADA    EQU     0008H 
; 
; BEGIN OF PROGRAM 
; 
	ORG  	0B901H		;JUMP TABLE FOR INTERPRETED
GSTAT:  DB	0		;STATUS BYTE OKAY=0
        JMP     GINIT		;BASIC WITH FIXED START ADDRESSES
        JMP     GPOINT
        JMP     GZOOM
        JMP     GCIRCL
        JMP     GLINE
        JMP     GBOX
        JMP     GRECT
        JMP     GPATT
        JMP     GMODE
        JMP     GTEXT
        JMP     GEXIT
        JMP     GPRINT
ERRCH:  LDA 	GSTAT      ;CHECK IF GSTAT=0 
     	CPI  	0H
     	RET
XCOORD: MOV 	A,H  
     	CPI  	00H 		;TEST IF H,L<0 ==> ERROR NR. IN B  
	JM   	ERR1
     	CMP  	D		;TEST IF H>D ==> ERROR NR. IN C
     	JNC  	ERR2
     	DCR  	D
     	CMP	D		;TEST IF D=H ==> TEST L			
     	JZ   	LTESTX
     	RET
LTESTX: MOV 	A,L
     	CMP 	E		;TEST IF L>E ==> ERROR NR. IN C
     	JNC 	ERR2
     	RET
ERR1: 	MOV 	A,B             ; VALUE IN H,L < 0  ERROR CODE IN B
     	STA 	GSTAT
     	RET
ERR2: 	MOV 	A,C             ; VALUE IN H,L TOO BIG  ERROR CODE IN C
     	STA 	GSTAT
     	RET
PARCHK: MOV 	A,H           ;TEST IF H=0 AND L<E  
     	CPI  	0H
     	JNZ  	ERRXX
     	MOV  	A,L
	CMP  	E
     	JNC  	ERRXX
     	RET
ERRXX: 	MOV 	A,D            ; D= ERRORCODE
     	STA  	GSTAT
     	RET
;
;
PART1: 	DW 	0
       	DW 	0
        DB	0
        DW 	0059H
        DW 	0000H
        DB 	59H
        DW 	0FFFFH,0FFFFH,0FFFFH,0FFFFH
        DB 	0   ;CURS
        DW 	0
        DW 	0FFFFH  ;MASK
        DB 	02H   ;FIGS
        DW 	7FFFH,0008H,0008H,3FFFH,3FFFH
        DW 	0FFFFH
PART3: 	DB 	8FH
	DB  	0
      	DW 	0
      	DW 	0190H
      	DW 	0
      	DW 	0
      	DW 	0FFFFH,0FFFFH,0FFFFH,0FFFFH
ADSP:   SHLD 	XADR		;STORE PARAMETER ADDRESSES
     	XCHG
     	SHLD 	YADR
     	RET
PATR:   MOV  	E,M		;GET CONTENT OF <H,L> IN H,L
     	INX  	H
     	MOV  	D,M
     	XCHG
     	RET
XADR:   DW   	0
YADR:   DW   	0
ZADR:   DW   	0
; MAIN ROUTINES 
; 
GINIT: 	NOP			;INITIALIZE CRT,GRAFIC MEMORY
     	MVI 	A,0CH		;SET DEFAULT VALUES FOR GDC
     	CALL 	COOP
     	LXI 	H,PART1
     	CALL 	COZOOM
     	CALL 	COCCHR
     	CALL 	COPRAM
     	CALL 	COCURS
     	CALL 	COMASK
     	CALL 	COFIGS
     	MVI  	A,WDAT+WCLR
     	CALL 	COOP
     	MVI  	C,02H
     	CALL 	PAOP
     	MVI 	A,WDAT+WCOM
     	CALL 	COOP
     	MVI 	A,0DH
     	CALL 	COOP
     	MVI 	A,0H
     	STA  	GSTAT
     	RET
GEXIT: 	NOP			;CLEAR CRT, EXIT GRAFIC, ENTER ALPHA
     	LXI 	H,PART3
     	CALL 	COCCHR
     	CALL 	COZOOM
     	CALL 	COPRAM
     	MVI 	E,1AH
     	MVI 	C,02H
     	CALL 	0005H
     	RET
GPOINT: CALL 	ERRCH		;SET CURSOR IN GRAFIC MEMORY
     	RNZ			; 0<= X <=639   0<= Y <=399
     	CALL 	ADSP
     	LHLD 	XADR
     	CALL 	PATR
     	LXI  	D,0380H
     	LXI  	B,0102H
     	CALL 	XCOORD
     	CALL 	ERRCH
     	RNZ 
     	INX  	H
     	SHLD 	XCUB
     	LHLD 	YADR
     	CALL 	PATR
     	LXI  	D,0290H
     	LXI  	B,0304H
     	CALL 	XCOORD
     	CALL 	ERRCH
     	RNZ	
     	INX  	H
     	SHLD 	YCUB
SETCU:	CALL	CUR0 
     	LXI	H,MCUR
     	CALL 	COCURS           ;OUT CURSOR TO GDC 
     	RET
GZOOM: 	CALL 	ERRCH		;SET ZOOM FACTOR FOR TEXT AND BOXES
     	RNZ			; 0 <= ZFA <=15
     	CALL 	PATR
     	LXI  	D,0A10H
     	CALL 	PARCHK
     	CALL 	ERRCH
     	RNZ
     	XCHG
     	LXI  	H,ZFA
     	MOV  	M,E
     	CALL 	COZOOM
     	RET
GCIRCL: CALL 	ERRCH		;DRAW CIRCLE
     	RNZ
     	CALL 	PATR
     	DCX  	H
     	LXI  	D,14FFH
     	CALL 	PARCHK
     	CALL 	ERRCH
     	RNZ	
     	INX  	H
     	SHLD 	BIRA
     	CALL 	RACU       ;CALCU.CIRC. CURS.POINTS 
     	CALL 	DCRO 
     	MVI  	B,08H 
     	LXI  	H,NPO1 
KREI0:	CALL 	COCURS     ;CUR FOR CIRCL 
     	PUSH 	H 
     	LXI  	H,PAR1     ;CIRCLE PARAM 
     	INR  	M 
     	MVI  	A,0F7H 
     	ANA  	M 
     	MOV  	M,A        ;DIR LIMIT 
     	CALL 	COFIGSM 
     	MVI  	A,FIGD 
     	CALL 	COOP 
     	MVI   	A,05H
     	CMP 	B
     	JNZ 	KREI1
     	LXI  	H,DMPAR
     	MVI  	M,01H
KREI1:	DCR  	B 
     	POP  	H
     	JNZ  	KREI0 
     	RET
GLINE:  CALL 	ERRCH		;DRAW A LINE TO X,Y
     	RNZ
     	CALL 	ADSP	 
     	LHLD 	XADR				
     	CALL 	PATR
     	LXI  	D,0380H
     	LXI  	B,0506H
     	CALL 	XCOORD
     	CALL 	ERRCH
     	RNZ	
     	INX  	H		
     	SHLD 	EXCB
     	LHLD 	YADR
     	CALL 	PATR
     	LXI  	D,0290H
     	LXI  	B,0708H
     	CALL 	XCOORD
     	CALL 	ERRCH
     	RNZ
     	INX  	H
     	SHLD 	EYCB
     	CALL 	LIPA 
     	LXI 	H,PAR1 
     	CALL 	COFIGSM 
     	MVI  	A,FIGD 	
     	CALL 	COOP 	
     	RET
ZF:	DB	0
GBOX:	MVI  	A,01H		;DRAW A BOX = FILLED RECTANGLE
     	STA  	DIR+1
     	PUSH	H
	LHLD	ZFA
	MOV	A,L
	ADI	01H
	STA	ZF		;ZF=ZOOMFACTOR
	POP	H
	JMP  	RANG
GRECT:  MVI  	A,00H		;RECTANGLE
     	STA  	DIR+1
	ADI	01H
	STA	ZF		;ZF=1
RANG: 	CALL 	ERRCH
     	RNZ
     	CALL 	ADSP
     	MOV  	L,C        ;store 3.param.
     	MOV  	H,B
     	SHLD 	ZADR
     	CALL 	PATR
     	LXI  	D,1E08H
     	CALL 	PARCHK
     	CALL 	ERRCH
     	RNZ
     	MOV  	A,L
     	STA  	DIR
     	LHLD 	XADR
     	CALL 	PATR
     	SHLD 	XDB
     	DCX  	H
	CALL	SIDECH
     	LXI  	D,0380H
     	LXI  	B,5051H
     	CALL 	XCOORD
     	CALL 	ERRCH
     	RNZ
     	LHLD 	YADR
     	CALL 	PATR
     	SHLD 	YDB
     	DCX  	H
	CALL	SIDECH
      	LXI  	D,0380H
     	LXI  	B,5253H	
     	CALL 	XCOORD
     	CALL 	ERRCH
     	RNZ	
     	LHLD 	DIR        ;TEST IF BOX 
     	MOV  	A,H
     	ANI  	0FH        ;TEST RECT OR BOX
     	JNZ  	RAN1       ;IF BOX 
     	CALL 	RECT 
     	LXI  	H,PAR1 
     	CALL 	COFIGSM 
     	MVI  	A,FIGD     ;START REC. DRAWING 
     	CALL 	COOP 
     	RET
RAN1:   CALL 	RARF       ;CALCULAT BOX PARAM. 
     	LXI  	H,PAR1 
     	CALL 	COFIGSM 
     	MVI  	A,GCHD     ;START AREA FILL 
     	CALL 	COOP 
     	RET
SIDECH:	XCHG			;MULTIPLY SIDELENGTH BY ZF
	MVI	H,0H
	MVI	L,0H
	LDA	ZF
ZFLOOP:	DAD	D
	DCR	A
	JNZ	ZFLOOP
	XCHG
	LHLD	DIR
	MOV	A,H
	ANI	0FH
	XCHG
	RNZ
	DCX	H
	RET
GPATT: 	CALL 	ERRCH		;SET FILL PATTERN FOR BOXES
     	RNZ			;AND LINE STYLE FOR DRAWING
     	CALL 	PATR		
     	LXI  	D,2810H
     	CALL 	PARCHK
     	CALL 	ERRCH
     	RNZ
     	MOV  	A,L
     	STA  	PATT
CH1: 	MVI  	H,00H
     	MOV  	L,A	
     	DAD  	H
     	DAD  	H
     	DAD  	H
     	LXI  	D,TAB6
     	DAD  	D
     	CALL 	COPRADA
     	RET	
GMODE: 	CALL 	ERRCH		;SET DRAWING MODE
     	RNZ			;1=COMPLEMENT
     	CALL 	PATR		;2=SET BLACK
     	LXI  	D,3204H		;3=SET WHITE
     	CALL 	PARCHK          ;0=RESET
     	CALL 	ERRCH
     	RNZ
     	MOV  	A,L
     	ORI  	20H
     	CALL 	COOP
     	RET
TAB6:   DW      0FFFFH,0FFFFH,0FFFFH,0FFFFH	;FILL PATTERNS
        DW      055AAH,055AAH,055AAH,055AAH
        DW      4488H,1122H,4488H,1122H
        DW      2211H,8844H,2211H,8844H
        DW      0AA00H,0AA00H,0AA00H,0AA00H
        DW      0FF00H,0FF00H,0FF00H,0FF00H
        DW      0AAAAH,0AAAAH,0AAAAH,0AAAAH
        DW      4281H,1824H,2418H,8142H
        DW      0FF0H,0FF0H,0FF0H,0FF0H
        DW      5555H,5555H,0AAAAH,0AAAAH
        DW      0CC33H,0CC33H,0CC33H,0CC33H
        DW      5555H,0AAAAH,5555H,0AAAAH
        DW      0A552H,944AH,5229H,4AA5H
        DW      0A54AH,2952H,4A94H,52A5H
        DW      0E773H,9CCEH,7339H,0CEE7H
        DW      0F0FH,0F0FH,0F0F0H,0F0F0H
PATT: 	DB   	0
RAFE:   DW      0 
BIWE:   DW      0 
XCUR:   DW      0 
XCUB:   DW      0 
YCUR:   DW      0 
YCUB:   DW      0 
YRAD:   DW      0 
XRAD:   DW      0 
; GRAPHIC CHARACTER IN/OUT 
; 
; 
GTEXT: 	CALL 	ERRCH
     	RNZ
     	CALL 	ADSP
     	LHLD 	YADR
	SHLD	ZADR
     	CALL 	PATR
     	LXI  	D,3C08H
     	CALL 	PARCHK
     	CALL 	ERRCH
     	RNZ	
     	MOV  	A,L         ;DIRECTION IN ACCU
	STA	DIR1
	ADI	2
	ANI	07
     	ORI  	10H
     	STA  	FIPAR
     	LHLD 	XADR
     	MOV  	C,M  
     	MVI	A,0H
	CMP	C		;RETURN IF LENGTH OF STRING=0
	RZ
	INX  	H
	CALL	PATR
GRC1:   MOV  	B,M          ;CHARECTER IN REG B
	INX  	H
     	PUSH 	H
     	PUSH 	B
	MOV	A,B
	CALL	GETCHR
	LXI	H,CHRRAM+8	;DRAW GRAPHIC CHR LOWER HALF
	CALL	DRAWCH
	LXI	H,CHRRAM	;DRAW GRAPHIC CHR UPPER HALF
	CALL	DRAWCH
	CALL	CALPOS		;CALCULAT NEXT CHR POSITION
	CALL	SETCU		;SET CURSOR
     	POP  	B
     	POP  	H
     	DCR  	C
     	JNZ  	GRC1
     	LDA  	PATT
     	JMP  	CH1
     	RET
DIR1:	DB	0
FIPAR:  DB   	10H
     	DW   	4007H,0008H,0008H,3FFFH,3FFFH
GPRINT: CALL 	ERRCH
     	RNZ	
     	CALL 	ADSP
     	LHLD 	XADR      ; PRINTER SELECTION
     	CALL 	PATR
     	LXI 	D,4605H	
     	CALL 	PARCHK
     	CALL 	ERRCH
     	RNZ	
     	MOV 	A,L
     	CPI 	04H
     	JNZ 	MXPR
     	STA 	ITOH
     	SUB 	A
     	MOV 	B,A	
     	STA 	DOUBLE
     	LHLD 	YADR
     	MOV 	A,M
HEXDEC: CPI 	0AH
     	JC 	STORLF
     	SUI 	0AH
     	INR 	B
     	JMP 	HEXDEC
STORLF: ADI 	30H
     	STA 	PTAB1+5
     	MOV 	A,B
     	ADI 	30H
     	STA 	PTAB1+4
     	MVI 	A,28H	
     	STA 	NUMB
     	LXI 	H,PTAB1	
     	LXI 	B,0605H
     	CALL 	PRINT
     	JMP 	HAC 
MXPR: 	STA 	EPSON
     	ANI 	01H
     	STA 	DOUBLE
     	LDA 	EPSON
     	ANI 	02H
     	MVI 	A,24H	
     	JZ  	MX82
MX100: 	MVI 	A,28H
MX82: 	STA 	NUMB 
     	LHLD 	YADR
     	MOV 	A,M
     	STA 	PTAB+5
     	LXI 	H,PTAB
     	LXI 	B,0605H
     	CALL 	PRINT
     	SUB 	A
     	STA 	ITOH
HAC: 	LDA 	ITOH	
     	CPI 	0H
     	LXI 	B,0605H
     	JNZ 	HACE
     	LXI 	B,0405H
     	LDA 	EPSON
HACE: 	RAL
     	RAL                 ;MULTIPLY EPSON BY 4 
     	MVI 	D,0H
     	MOV 	E,A
     	LXI 	H,GRMODE
     	DAD 	D               ;TO GET OFFSET DEPENDING ON EPSON
     	CALL 	PRINT
HAC0: 	LXI 	H,OUTBU
     	SHLD 	OUBU
     	LDA 	HDMER
     	ORA 	A
     	JNZ 	HAC2
     	LXI 	H,0
     	SHLD 	HCUR
     	SHLD 	GCUR
     	MVI 	A,32H
     	STA 	HDMER
     	LDA 	NUMB 
     	STA 	HCMER
HAC2: 	LXI 	H,HAPA
     	MVI 	A,PRAM+PADA
     	CALL 	COOP
     	MVI 	C,02H
     	CALL 	PAOP
     	LXI 	H,HCUR
     	CALL 	COCURS
     	LXI 	H,HAPB
     	CALL 	COMASK
     	LXI 	H,HAP6
     	CALL 	COFIGS
     	MVI 	A,RDAT
     	CALL 	COOP
     	LXI 	H,HAAD	
     	LXI 	D,HAAE
     	MVI 	C,08H
     	CALL 	LESE
     	LHLD 	OUBU
     	XCHG
     	CALL 	BYWA
     	XCHG
     	SHLD 	OUBU
     	LHLD 	HCUR
     	INX 	H
     	SHLD 	HCUR
     	LDA 	DOUBLE
     	STA 	NUMP
     	LXI 	H,OUTBU
     	LXI 	B,1005H
     	CALL 	PRINT
     	MVI 	A,0H
     	STA 	NUMP
     	LDA 	HCMER
     	DCR 	A
     	STA 	HCMER
     	JNZ 	HAC0
     	LXI 	B,0205H
     	LXI 	H,CRLF
     	CALL 	PRINT
     	LXI 	H,AW
     	DAD 	H
     	DAD 	H
     	DAD 	H
     	XCHG	
     	LHLD 	GCUR
     	DAD 	D
     	SHLD 	HCUR
     	SHLD 	GCUR
     	LDA 	NUMB
     	STA 	HCMER
     	LDA 	HDMER
     	DCR 	A
     	STA 	HDMER
     	JNZ 	HAC
     	LXI 	H,CRLF
     	LXI 	B,0605H
     	CALL 	PRINT
     	RET
BYWA: 	MVI 	A,01H
     	STA 	HAMER
BYWD: 	LXI 	B,0808H
BYWB: 	LXI 	H,HAAD
BYWC: 	LDA 	ITOH
     	CPI 	0H
     	JZ 	EP1
     	MOV 	A,M
     	RAR
     	MOV 	M,A
     	LDAX 	D
     	RAR
     	JMP 	ITOH1
EP1: 	MOV 	A,M
     	RAR
     	MOV 	M,A
     	LDAX 	D
     	RAL
ITOH1: 	INX 	H
     	STAX 	D
     	DCR 	B
     	JNZ 	BYWC
     	INX 	D
     	MVI 	B,08H
     	DCR 	C
     	JNZ 	BYWB
     	LDA 	HAMER
     	ANI 	01H
     	JZ 	BYWE
     	LXI 	H,HAAE
     	SHLD 	BYWB+1
     	DCR 	A
     	STA 	HAMER
     	JMP 	BYWD
BYWE: 	LXI 	H,HAAD
     	SHLD 	BYWB+1
     	RET
LESE: 	IN 	RSTA
     	ANI 	01H
     	JZ 	LESE
     	IN 	RFIF
     	MOV 	M,A
     	INX 	H
     	IN 	RFIF
     	STAX 	D
     	INX 	D
     	DCR 	C
     	JNZ 	LESE
     	RET	
HAPA: 	DW 	0FFFFH
HAPB: 	DW 	0FFFFH
HAP6: 	DB 	00H
      	DW 	4008H,0008H,0008H,3FFFH,3FFFH
HAAD: 	DS 	8
HAAE: 	DS 	8
HAMER: 	DB 	0
HCMER: 	DB 	0
HDMER: 	DB 	0
HCUR:  	DW 	0
       	DB 	0
GCUR:  	DW 	0
       	DB 	0
EPSON:  DB 	0 
ITOH:   DB 	0
DOUBLE: DB 	0 
NUMB:   DB 	0
NUMP:   DB 	0
OUBU:  	DW 	OUTBU
OUTBU: 	DS 	16
PTAB:  	DB 	1BH            ;AMERICAN CHARACTER SET + GRAFIC LINEFEED  
       	DB 	52H
       	DB 	00H
       	DB 	1BH
       	DB 	41H
       	DB 	0H
PTAB1: 	DB 	1BH
       	DB 	4EH
       	DB 	1BH 
       	DB 	54H
       	DB  	0H
       	DB  	0H
GRMODE: DW 	4B1BH,0240H     ;GRAFIC MODE + 576 CHAR, SD   
       	DW  	4C1BH,0480H     ;              576       DD
       	DW  	4B1BH,0280H     ;              640       SD
       	DW  	4C1BH,0500H	;              640       DD
       	DW  	531BH,3630H	;ITOH          640
       	DW  	3034H 
CRLF:  	DB 	0DH            ;CR+LF  +  NORMAL LINEFEED
       	DB 	0AH
       	DB 	1BH
       	DB 	41H
       	DB 	0AH
       	DB 	0AH
PRINT: 	LDA 	NUMP
     	MOV 	D,A
PRT1: 	MOV 	E,M	
     	PUSH 	H	
     	PUSH 	B
     	PUSH 	D
     	CALL 	0005H
     	POP 	D
     	POP 	B
     	POP 	H
     	DCR 	D
     	JZ 	PRT1
     	INX 	H
     	DCR 	B
     	JNZ 	PRINT
     	RET
COOP:   PUSH 	H 
     	PUSH 	PSW 
COST:   IN  	RSTA        ;LOAD GDC STATUS
     	ANI  	0AH        ;TEST STATUS 
     	JNZ  	COST 
     	POP  	PSW 
     	OUT  	WCO        ;COMMAND TO GDC
     	POP  	H 
     	RET 
PAOP:   IN  	RSTA        ;LOAD GDC STATUS
     	ANI  	0AH 
     	JNZ  	PAOP 
PACO:   MOV  	A,M        ;PARAMETER TO ACCU 
     	OUT  	WPA
     	INX  	H 	
     	DCR  	C 
     	JNZ  	PAOP 
     	RET 
COZOOM: MVI  	A,ZOOM
     	CALL 	COOP
     	MVI 	C,01H
     	CALL 	PAOP
     	RET
COCCHR: MVI 	A,CCHR
     	CALL 	COOP
     	MVI 	C,01H
     	CALL 	PAOP
     	RET	
COPRAM: MVI 	A,PRAM
     	CALL 	COOP
     	MVI 	C,10H
     	CALL 	PAOP
     	RET
COCURS: MVI 	A,CURS
     	CALL 	COOP
     	MVI 	C,03H	
     	CALL 	PAOP
     	RET
COMASK: MVI 	A,MASK
     	CALL 	COOP
     	MVI 	C,02H
     	CALL 	PAOP
     	RET
COFIGS: MVI 	A,FIGS
     	CALL 	COOP
     	MVI 	C,0BH
     	CALL 	PAOP
     	RET
COFIGSM: MVI 	A,FIGS
     	CALL 	COOP
     	CALL 	MIX
     	MVI 	C,0BH
     	CALL 	PAOP
     	RET
COPRADA: MVI 	A,PRAM+PADA
     	CALL 	COOP
     	MVI 	C,08H
     	CALL 	PAOP
     	RET 
MIX: 	LDA 	DCPAR+1
     	ORI 	40H
     	STA 	DCPAR+1
     	RET
; 
; X - Y CURSOR IN MEM ADDRESS 
CUR0:   PUSH 	H 
     	PUSH 	B 
     	PUSH 	D 
     	PUSH 	PSW 
     	LHLD 	YCUB
	SHLD	YCUB1
     	CALL 	YSPI 
     	SHLD 	YCUB       ;STORE BIN YCUR 
CUR3:   LXI  	B,0000H    ;CLEAR B+C 
     	LHLD 	XCUB       ;BIN CURS IN H+L 
     	DCX  	H
     	MOV  	A,L 	
     	ANI  	0FH        ;CUT LOWER BITS 
     	STA  	ZCUR 
     	RLC 	
     	RLC 
     	RLC 
     	RLC 
     	STA  	DCUR       ;STORE DOT CURSOR 
     	MOV  	A,L 
     	ANI  	0F0H       ;CUT DOT BITS 
     	MOV  	L,A 
     	LXI  	D,0FFF0H   ;-16 IN D+E 
CURS2:  CALL 	RWOR 
     	MOV  	A,C        ;X ADDRESS IN ACCU 
     	STA  	WCUR 
     	LHLD 	YCUB       ;Y BIN CURS IN H+L 
     	DCX  	H
     	XCHG 	
     	LXI  	H,0000H 
     	LXI  	B,AW       ;PITCH
     	CALL 	ADRE 
     	XCHG           		;LINE START ADDR. IN D+E 
     	LDA  	WCUR 
     	MOV  	L,A 
     	DAD  	D 
     	SHLD 	MCUR       ;STORE MEM ADDRESS 
     	POP  	PSW 
     	POP  	D 
     	POP  	B 
     	POP  	H 
     	RET 
YSPI:   CALL 	COMH       ;Y-POINT EXCHANGE 
     	XCHG 
     	MVI  	H,ALH 	
     	MVI  	L,ALL 
     	INX 	H
     	DAD  	D 
     	RET 
ADRE:   MVI  	A,00H 
     	CMP  	E 
     	JZ   	ADR1 
     	DAD  	B          ;ADD. AW 
     	DCR  	E
     	JMP  	ADRE 
ADR1:   CMP  	D 
     	RZ 
     	DAD  	B 
     	DCR  	E 
     	DCR  	D 
     	JMP  	ADRE 
MCUR:   DW   0 
DCUR:   DB   0 
WCUR:   DW   0 
ZCUR:   DW   0 
; 
; CALCUL RADIUS FOR CIRCL DRAWING 
RACU:    PUSH H 
     PUSH B 
     PUSH D 
     PUSH PSW 
     MVI  A,20H 
     STA  PAR1 
     LHLD BIRA       ;RADUIS IN H+L
     XCHG
RAC1:    LHLD MCUR       ;CIRC. CENTER 
     LXI  B,AW
     CALL COMP       ;GEN 2-COMP FROM AW 
     CALL ADRE 
     SHLD NPO1 
     SHLD NPO2 
     LHLD BIRA       ;BIN RAD IN H+L 
     XCHG 
     LHLD MCUR       ;CIRC. CENT IN H+L 
     LXI  B,AW       ;PITCH FOR CURS. CALC.
     CALL ADRE 
     SHLD SPO1       ;CIRC. SOUTH POINT 
     SHLD SPO2 
     LDA  DCUR       ;GET DOT CURSOR 
     STA  NPU1       ;NORTH DOT CURSOR 
     STA  NPU2 
     STA  SPU1 
     STA  SPU2 
     LHLD BIRA 
     MOV  A,L 
     STA  ZWDO 
     ANI  0F0H       ;CUT UPPER BITS 
     MOV  L,A 
     LXI  D,0FFF0H   ;-16 IN D+E 
     LXI  B,0000H 
     CALL RWOR       ;RAD IN MEM-WORD 
     PUSH B          ;SAVE RAD.WORD ADDR. 
     LDA  ZWDO       ;ZWI.BUFFER 
     ANI  0FH        ;CUT UPPER BITS 
     CALL RADO 
     STA  WPU1 
     STA  WPU2 
     LHLD MCUR       ;MEM ADDRESS 
     DAD  B 
     SHLD WPO1 
     SHLD WPO2 
     POP  B 
     LDA  ZWDO 
     ANI  0FH 
     CMA 
     INR  A 
     CALL RADO       ;CALCU. DOT FOR EASTPOINT 
RAC3:    STA  OPU1 
     STA  OPU2 
     CALL COMP       ;SUBT. RADIUS 
     LHLD MCUR       ;MEM ADDRESS 
     DAD  B 
RAC5:    SHLD OPO1 
     SHLD OPO2 
     POP  PSW 
     POP  D 
     POP  B 
     POP  H 
     RET 
RADO:    MOV  E,A 
     LDA  ZCUR 
     ADD  E 
     MOV  E,A 
     ANI  0F0H 
     JZ   RAC2 
     INX  B 
RAC2:    MOV  A,E 
     RLC 
     RLC 
     RLC 
     RLC 
     ANI  0F0H 
     RET 
COMP:    MOV  A,C 
     CMA 
     MOV  C,A 
     MOV  A,B 
     CMA 
     MOV  B,A 
     INX  B 
     RET 
RWOR:    DAD  D 
     INR  C 
     JC   RWOR 
     DCR  C 
     RET 
BIRA:	DW   	0 
NPO1:   DW   	0 
NPU1:   DB   	0 
SPO1:   DW   	0 
SPU1:   DB   	0 
OPO1:   DW   	0 
OPU1:   DB   	0 
WPO1:   DW   	0 
WPU1:   DB   	0 
SPO2:   DW   	0 
SPU2:   DB   	0 
NPO2:   DW   	0 
NPU2:   DB   	0 
WPO2:   DW   	0 
WPU2:   DB   	0 
OPO2:   DW   	0 
OPU2:   DB   	0 
ZWDO:   DB   	0 
; CALCUL. FIGS PARAM. 
DCRO:	PUSH 	H 
     	PUSH 	D 
     	PUSH 	B 
     	PUSH 	PSW 
     	LHLD 	BIRA 
     	SHLD 	RAD2 
     	MVI  	A,00H 
     	STA  	RAD1 
     	LXI  	B,0000H 
DCR1:   LXI  	H,SINKO 
     	LXI  	D,RAD1 
     	LDAX 	D 
     	ADD  	M 
     	STAX 	D 
     	INX  	H 
     	INX  	D 
     	LDAX 	D 
     	ADC  	M 
     	STAX 	D 
     	INX  	H 
     	INX  	D 
     	LDAX 	D 
     	ADC  	M 
     	STAX 	D 
     	INX  	B 
     	JC   	DCR1 
     	LDA  	RAD2
     	ANI  	01H
     	JNZ  	DCR2
     	LDA  	RAD1
     	ADI  	0B5H
     	JNC  	DCR2    
     	DCX  	B
DCR2:  	LXI  	H,DCPAR    ;START ADDR CIRC PARAM 
     	MOV  	M,C 
     	INX  	H 
     	MOV  	M,B        ;STORE DC PARAM 
     	LHLD 	BIRA 
     	DCX  	H 
     	SHLD 	DPAR 
     	DAD  	H          ;2TIMES RAD-1 
     	SHLD 	D2PAR 
     	LXI  	H,3FFFH    ;D1 =-1 
     	SHLD 	D1PAR      ;STORE D1 PARAM 
     	LXI  	H,0000H    ;DM PARAM
     	SHLD 	DMPAR 
     	POP  	PSW 
     	POP  	B 
     	POP  	D 
     	POP  	H 
     	RET 
SINKO:  DW   	0FE95H     ;2-COMP. SIN 45 
     	DB   	0FFH 
RAD1:   DB   	0 
RAD2:   DB   	0 
RAD3:   DB   	0 
;
;			*GET CHARACTER FROM CHARACTER ROM*
;
;
GETCHR:
	PUSH	B
	PUSH	D
	PUSH	H		;SAVE REGISTERS
	ANI	07FH		;ONLY ASCII CHR ALOWED
	MOV	L,A
	MVI	H,0
	DAD	H
	DAD	H
	DAD	H
	DAD	H		;*16
	LXI	D,1000H		;START OF CHARACTER ROM
	DAD	D
	LXI	D,CHRRAM	;MOVE CHR FRO ROM TO RAM
	MVI	B,16
	OUT	11H		;ROMSELECT
GETCHR1:
	MOV	A,M
	STAX	D
	INX	H
	INX	D
	DCR	B
	JNZ	GETCHR1		;LOOP TIL DONE
	OUT	10H		;RAMSELECT
	POP	H
	POP	D
	POP	B
	RET
;
;
;			*DRAW CHARACTER*
;
;
DRAWCH:
	MVI	A,PRAM+PADA
	CALL	COOP		;OUTPUT PRAM COMMAND
	MVI	C,8
	CALL	PAOP		;OUTPUT 8 PARAMETER
	LXI	H,FIPAR
	MVI	A,FIGS
	CALL	COOP		;OUTPUT FIGS COMMAND
	MVI	C,0BH
	CALL	PAOP		;OUTPUT 11 PARAMETERS
	MVI	A,GCHD
	CALL	COOP		;OUTPUT START DRAWING
	RET
;
;
;			*CALCULATE NEXT CURSOR POSITION*
;
;		ENTRY CONDITIONS:(ZFA) = ZOOMFACTOR
;				 (XCUB)= X COORDINATE
;				 (YCUB1)= Y COORDINATE
;
;	
CALPOS:
	LDA	ZFA		;GET ZOOMFACTOR
	INR	A
	MOV	B,A
	ADD	A		;ZOOMFACTOR * 8
	ADD	A
	ADD	A
	MOV	L,A
	MVI	H,0
	SHLD	ZFA7		;SAVE ZOOMFACTOR * 8
	CALL	COMH		;NEGATE ZOOMFACTOR * 8
	SHLD	ZFA7M		;SAVE IT
	LHLD	YCUB1
	SHLD	YCUB
	LDA	DIR1		;GET DIRECTION
	CPI	0
	JZ	XPZ		;X=X+ZF*8
				;Y=Y
	CPI	1
	CZ	XPZ		;X=X+ZF*8
	JZ	YPZ		;Z=Z+ZF*8
	CPI	2
	JZ	YPZ		;X=X
				;Y=Y+ZF*8
	CPI	3
	CZ	XMZ		;X=X-ZF*8
	JZ	YPZ		;Y=Y+ZF*8
	CPI	4
	JZ	XMZ		;X=X-ZF*8
				;Y=Y
	CPI	5
	CZ	XMZ		;X=X-ZF*8
	JZ	YMZ		;Y=Y-ZF*8
	CPI	6
	JZ	YMZ		;X=X
				;Y=Y-ZF*8
	CALL	XPZ		;X=X+ZF*8
	JMP	YMZ		;Y=Y-ZF*8
XPZ:
	LHLD	XCUB		;X+ZF*8
	XCHG
	LHLD	ZFA7
	DAD	D
	SHLD	XCUB
	RET
XMZ:
	LHLD	XCUB		;X-ZF*8
	XCHG
	LHLD	ZFA7M
	DAD	D
	SHLD	XCUB
	RET
YPZ:
	LHLD	YCUB1		;Y+ZF*8
	XCHG
	LHLD	ZFA7
	DAD	D
	SHLD	YCUB
	RET
YMZ:
	LHLD	YCUB1		;Y-ZF*8
	XCHG
	LHLD	ZFA7M
	DAD	D
	SHLD	YCUB
	RET
CHRRAM: DS	16
YCUB1:	DW	0
ZFA7:	DW	0
ZFA7M:	DW	0
;
; CALCULATE LINE PARAMETER 
; 
TAB2:	DB   	0DH        ;DIR=5 QU=2 
        DB      0EH        ; 6 - 3 
        DB      0AH        ; 2 - 1 
        DB      09H        ; 1 - 4 
        DB      0CH        ; 4 - 2 
        DB      0FH        ; 7 - 3 
        DB      0BH        ; 3 - 1 
        DB      08H        ; 0 - 4 
        DB      0AH 
        DB      0EH 
        DB      0CH
        DB      08H
        DB      0DH        ; 5 - 2 
        DB      0FH        ; 7 - 3 
        DB      0BH        ; 3 - 1 
        DB      09H        ; 1 - 4 
LIPA:   PUSH 	H 
     	PUSH 	D 
     	PUSH 	B 
     	PUSH 	PSW 
     	XRA  	A 
     	STA  	CBY 
     	LHLD 	EXCB     ;  +X END POINT IN MEM.
     	XCHG 
     	LHLD 	XCUB       ;X-START POINT 
     	MOV  	C,L        ;COMP START POINT 
     	MOV  	B,H 
     	CALL 	COMP 
     	XCHG           ;END POINT IN H+L 
     	DAD  	B 
     	CNC  	COMH 
     	SHLD 	DEX        ;STORE DELTA X 
     	MVI  	A,02H      ;IF X-POS STORE 1 
     	CC   	LIPB       ;IF POSITIV 
     	LHLD 	EYCB        ;Y END POINT IN H+L
     	CALL 	YSPI 
     	SHLD 	EYCB       ;STORE END POINT Y 
     	XCHG           ;Y-END IN D+E 
     	LHLD 	YCUB       ;Y-START POINT 
     	MOV  	C,L 
     	MOV  	B,H 
     	CALL 	COMP       ;CALCU. DELTA Y 
     	XCHG           ;END POINT IN H+L 
     	DAD  	B 
     	CNC  	COMH 
     	SHLD 	DEY        ;STORE DELTA Y 
     	MVI  	A,01H      ;IF X-POS STORE 1 
     	CC   	LIPB 
     	XCHG           ;DELTA Y IN D+E 
     	LHLD 	DEX        ;GET DELTA X 
     	MOV  	C,L 
     	MOV  	B,H 
     	CALL 	COMP 
     	XCHG           ;DEY IN H+L - DEX IN D+E 
     	DAD  	B          ;SUB X FROM Y 
     	MVI  	A,04H      ;IF Y > X STORE 1 
     	CC   	LIPB 
     	MOV  	A,L        ;TEST Y = X 
     	ORA  	H 
     	MVI  	A,08H      ;SET 1 IF X=Y 
     	CZ   	LIPB 
     	LHLD 	DEY        ;DEY IN H+L - DEX IN D+E 
     	MOV  	A,L 
     	ORA  	H 
     	CZ   	LIPC 
     	MOV  	A,E 	
     	ORA  	D 
     	CZ   	LIPF       ;TEST DEX=0 
     	LDA  	CBY 
     	ANI  	04H        ;IF 1 INDEPEN.=DEY 
     	CZ   	LIPD 
     	SHLD 	DCPAR 
     	MOV  	C,L        ;INDEP IN B+C 
     	MOV  	B,H 
     	CALL 	COMP 
     	MOV  	L,E        ;DEPENT. IN H+L 
     	MOV  	H,D 
     	DAD  	H 
     	SHLD 	D1PAR      ;2X DEPENT 
     	DAD  	B 
     	SHLD 	DPAR       ;2X DEP -INDEP 
     	XCHG           ;DEPEN IN H+L 
     	DAD  	B 
     	DAD  	H 
     	SHLD 	D2PAR 
     	LXI  	H,3FFFH 
     	SHLD 	DMPAR 
CALE:   LXI  	H,TAB2 
     	LXI  	D,0000H 
     	LDA  	CBY 
     	MOV  	C,A 
     	ANI  	10H        ;TEST X OR Y =0 
     	CNZ  	LIPE 
     	MOV  	E,C 
     	DAD  	D 
     	MOV  	A,M        ;GET DIR PARAMETER 
     	STA  	PAR1 
     	LHLD 	EXCB       ;STORE NEW START POINT 
     	SHLD 	XCUB 
     	LHLD 	EYCB 
     	SHLD 	YCUB 
     	POP  	PSW 
     	POP  	B 
     	POP  	D 
     	POP  	H 
     	RET 
LIPC:   MVI  	A,10H      ;X OR Y = 0    
     	CALL 	LIPB 
     	LDA  	CBY 
     	ANI  	02H 
     	RZ 
     	LDA  	CBY 
     	ANI  	0FCH       ;SET DIR 
     	STA  	CBY 
     	RET 
LIPF:   MVI  	A,14H      ;IF DEX = 0 	
     	CALL 	LIPB 
     	RET 
LIPD:   XCHG 
     	RET 
LIPE:   LDA  	CBY        ;IF X OR Y = 0 
     	ANI  	03H 
     	ORI  	08H 
     	MOV  	C,A 	
     	RET 
COMH:   PUSH 	PSW        ;SAVE CARRY 
     	MOV  	A,L 
     	CMA 
     	MOV  	L,A 
     	MOV  	A,H 
     	CMA 
     	MOV  	H,A 
     	INX  	H 
     	POP  	PSW 
     	RET 
LIPB:   PUSH 	H 
     	LXI  	H,CBY 
     	ORA  	M 
     	MOV  	M,A 
     	POP  	H 
     	RET 
EXCR:   DW      0 
EYCR:   DW      0 
EXCB:   DW      0 
EYCB:   DW      0 
DEX:    DW      0 
DEY:    DW      0 
CBY:    DB      0 
PAR1:   DB      0          ;P1 PARAM 
DCPAR:  DW      0 
DPAR:   DW      0 
D2PAR:  DW      0 
D1PAR:  DW      0 
DMPAR:  DW      0 
ZFA:    DW      0H 
; RECTANGLE ROUTINES 
; 
RECT:	PUSH 	H 
     	PUSH 	D 
     	PUSH 	B 
     	PUSH 	PSW 
     	CALL 	XYDB       ;XY IN BINARY 
     	DCX  	H
     	DCX  	D
	SHLD 	DPAR       ;A=X 
     	SHLD 	DMPAR 
     	XCHG 
     	SHLD 	D2PAR      ;B=Y 
	LXI  	H,0003H    ;SET RECTAN PARAM 
     	SHLD 	DCPAR 
     	LXI  	H,3FFFH 
     	SHLD 	D1PAR 
     	LDA  	DIR 
     	ADI  	02H
     	ANI  	07H 
     	ORI  	40H 
     	STA  	PAR1      
     	POP  	PSW 
     	POP  	B 
     	POP  	D 
     	POP  	H
     	RET 
XYDB: 	LHLD 	YDB
     	XCHG 	
     	LHLD 	XDB        ;X IN H+L   Y IN D+E 
     	LDA  	DIR 
	ANI  	07H 
     	ADI  	04H 
     	RET 
RARF:	PUSH 	H 
     	PUSH 	D 
     	PUSH 	B 
     	PUSH 	PSW 
     	CALL 	XYDB 
     	XCHG 
     	MOV  	A,H 
     	ANI  	3FH        ;CUT UPPER 2BITS 
     	MOV  	H,A 
     	DCX  	H
     	SHLD 	DCPAR      ;Y=B 
     	XCHG 		   ;X=A 
	SHLD 	DPAR       ;Y=A 
     	SHLD 	D2PAR 
     	LXI  	H,3FFFH 
     	SHLD 	D1PAR 
     	SHLD 	DMPAR 
     	LDA  	DIR        ;DIRECTION 
     	ADI  	02H
     	ANI  	07H 
     	ORI  	10H 
     	STA  	PAR1 
     	POP  	PSW 
     	POP  	B 
     	POP  	D 
     	POP  	H 
     	RET
DIR:    DW   	0 
XDI:    DW   	0 
XDB:    DW   	0 
YDI:    DW   	0 
YDB:    DW   	0 
;END 


