HP500C  ASM;
;Centronics-Treiber nach Handbuch M001
;
;+Druckertreiber f}r HP 500C
;
;   von Hendrik Wagenknecht
;	Ro~bachstra~e 55
;	06112 Halle/Saale
;	` Oktober 1994
;
;***************************************
;Parameter bei HP500C
;HP500C bn ze sp af qu fa
;	bn=Bildnummer bei bn=FF Eurolp
;	ze=Bild ab Zeile ze
;	sp=Bild ab Spalte sp
;	af= 1..4 Aufl|sung
;		1 =  75 dpi
;		2 = 100 dpi
;		3 = 150 dpi
;		4 = 300 dpi
;	qu=Qualit{t, 1=Draft, 0=Letter
;	fa= 1, dann Farbdruck
;	  = 0, nur Pixeldruck s/w
;***************************************
;	ORG	01000H
;Systemadressen
ARGN	EQU	0B781H
ARG1	EQU	0B782H
ARG2	EQU	0B784H
ARG3	EQU	0B786H
ARG4	EQU	0B788H
ARG5	EQU	0B78AH
ARG6	EQU	0B78CH
STBT	EQU	0B7A2H
OUTAB	EQU	0B7B9H
UOUT1	EQU	0B7BEH
UOUT2	EQU	0B7C4H
HCADR	EQU	0B799H
CRR	EQU	0DH
;
MKENN	EQU	0EFH
PIOA	EQU	4	;PIO A Daten
PIOAC	EQU	6	;PIO A Steuerw.
PIOB	EQU	5
PIOBC	EQU	7
REG	EQU	0C000H
REG7	EQU	0C749H
;Konstanten
FARIY	DW	02000H	;Farblagensp.
HCPZ	DEFB	0	;USER Kanal 1
MOD	DEFB	0CH	;Schacht 0C
RAM	DB	14H	;RAM-Schacht
;Variablen
BIYT	DB	0
;	BIT	0 = 1 Druckerres. vorh.
;	BIT	1 =
;	BIT	2 =
;	BIT	3 =
;
;
	DEFW	07F7FH
	DEFM	'CENTRON'
	DEFB	1
	CP	0
	JR	Z,START
;
	LD	A,L
	LD	(MOD),A
	LD	A,E
	SUB	2
	JR	C,ERROR
	AND	1
	LD	(HCPZ),A
;Selbststartadresse
;***************************************
START	LD	A,(MOD)
	LD	B,A
	LD	C,80H
	IN	A,(C)
	CP	MKENN
	JR	Z,ST1
;
ERROR	CALL	0F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afikmodus
;    - ohne Initialisierung des M001
;
DRAM	DEFW	08000H
PRAM	DEFW	08000H
BITS	DEFW	07F37H	;Speicheradresse
CLSB	DEFB	0
;{userste linke Drukposition
LPGON
	DEFM	'*r1A'
	DEFB	0
;Ende des Grafikmodus
GOFF
	DEFM	'*rbC'
	DEFB	0
;Aufl|sung 75dpi
A75
	DEFM	'*t75R'
	DEFB	0
;100dpi
A2
	DEFM	'*t100R'
	DEFB	0
;150dpi
A3
	DEFM	'*t150R'
	DEFB	0
;300dpi
A4
	DEFM	'*t300R'
	DEFB	0
;3 Farbebenen RGB-Palette
RGB
	DEFM	'*r3U'
	DB	0
;schwarz/wei~ Grafiken
SW
	DEFM	'*r1U'
	DB	0
;}bertragen von Grafiken
;Achtung! Die Daten m}ssen im Anschlu~
;folgen
GUB
	DEFM	'*b40W'
	DEFB	0
;Grafikdaten in Lagen (f}r Farbe!)
;Achtung! Die Daten m}ssen im Anschlu~
;folgen!
LAG
	DEFM	'*b40V'
	DB	0
;Anzahl der Pixel in einer Zeile
BREIT
	DEFM	'*r320S'
	DB	0
;Qualit{t
DRAF
	DEFM	'*r1Q'
	DB	0
;
LETT
	DEFM	'*r2Q'
	DB	0
;Grafik versetzt
GVER
	DEFM	'*o2Q'
	DB	0
;
GVER0
	DEFM	'*o0Q'
	DB	0
;Grafik heller
GHEL
	DEFM	'*o4Q'
	DB	0
;
GHEL0
	DEFM	'*o0Q'
	DB	0
;
STOUT	LD	A,1BH
	PUSH	HL
	CALL	0F003H
	DB	2
	POP	HL
STOA	LD	A,M
	CP	0
	RET	Z
	PUSH	AF
	PUSH	HL
	CALL	0F003H
	DEFB	2
	POP	HL
	POP	AF
	INC	HL
	JR	STOA
;
;UOUT
UOUT	PUSH	BC
	PUSH	HL
	CALL	0F003H
	DEFB	2
	POP	HL
	POP	BC
	RET
;
DOUT	LD	HL,(PRAM)
	LD	B,40
DOUA	LD	A,M
	CALL	UOUT
	PUSH	BC
	POP	BC
	INC	H
	DJNZ	DOUA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DB	1
IRML	DI
	IN	A,(88H)
	RES	2,A
	SET	5,A
	OUT	(88H),A
	LD	HL,8000H
	LD	DE,4000H
	LD	BC,27FFH
	LDIR
	IN	A,(88H)
	SET	2,A
	RES	5,A
	OUT	(88H),A
	EI
	RET
;
ULD	LD	HL,8000H
	LD	DE,4000H
	LD	BC,27FFH
	LDIR
	RET
;
BILDT2	CALL	0F003H
	DEFB	23H
	DEFB	0DH
	DEFM	'Neue Folie einlegen. '
	DEFM	'>RETURN<'
	DEFB	0
BTXT	CALL	0F003H
	DEFB	0EH
	JR	NC,BTXT
	RET
;
;
HPEURO	CALL	START
	CALL	0F003H
	DEFB	23H
	DEFM	'Bild 1'
	DEFB	0DH
	DEFB	27
	DEFB	'3'
	DEFB	0
;Bild 1
	CALL	ULD
	LD	HL,4000H
	LD	E,5
	LD	C,10H
	LD	A,3
	LD	(ARGN),A
	CALL	DR1
	LD	HL,A75
	CALL	DR2
	CALL	0F003H
	DEFB	23H
	DEFB	27
	DEFM	'1'
	DEFB	0
;Bild 2
BILD2	CALL	0F003H
	DEFB	23H
	DEFM	'Bild 2'
	DEFB	0DH
	DEFB	0
	LD	L,3
	LD	D,L
	LD	A,2
	CALL	0F003H
	DB	26H
;
	CALL	IRML
	LD	HL,A75
	CALL	DR2
	LD	A,12
	CALL	0F003H
	DEFB	2
	CALL	BILDT2
;Bild 3
	LD	L,4
	LD	D,0
	LD	A,2
	CALL	0F003H
	DEFB	26H
	LD	L,14H
	LD	D,41H
	LD	A,2
	CALL	0F003H
	DEFB	26H
	CALL	0F003H
	DEFB	23H
	DEFW	0A0DH
	DEFM	'Bild 3'
	DEFB	0DH
	DEFB	0
;
	LD	HL,4000H
	LD	E,5
	LD	C,10H
	LD	A,3
	LD	(ARGN),A
	CALL	DR1
	LD	HL,A75
	CALL	DR2
;Bild 4
	LD	L,14H
	LD	D,0C1H
	LD	A,2
	CALL	0F003H
	DEFB	26H
	CALL	0F003H
	DEFB	23H
	DEFM	'Bild 4'
	DEFW	0A0DH
	DEFB	0
;
	LD	HL,A75
	CALL	DR2
	CALL	CLS
;
	LD	L,14H
	LD	D,0
	LD	A,2
	CALL	0F003H
	DEFB	26H
	LD	L,0CH
	LD	D,0
	LD	A,2
	CALL	0F003H
	DEFB	26H
	LD	L,4
	LD	D,3
	LD	A,2
	CALL	0F003H
	DEFB	26H
	LD	L,3
	LD	D,0
	LD	A,2
	CALL	0F003H
	DB	26H
	RET
;NORM
;normale Daten FFH senden.
NORM	PUSH	AF
	PUSH	BC
	LD	HL,GUB
	CALL	STOUT
	LD	B,40
	LD	A,0FFH
NORMA	CALL	UOUT
	DJNZ	NORMA
	POP	BC
	POP	AF
	RET
;LAGE0
LAGE0	PUSH	BC
	PUSH	AF
	LD	HL,LAG
	CALL	STOUT
	LD	B,40
	POP	AF
	PUSH	AF
LAGA	CALL	UOUT
	DJNZ	LAGA
	POP	AF
	POP	BC
	RET
;
ESC9	CALL	0F003H
	DB	23H,1BH,39H,0
	RET
;COL
;lesen Byte von Color-RAM
;PE:	HL=Adresse
;PA:	A=Byte
;VR:	AF
COL	CALL	ESC9
	LD	A,M
	PUSH	AF
	CALL	ESC9
	POP	AF
	RET
;Farbe
FARDR	CALL	STOUT
	LD	HL,BREIT
	CALL	STOUT
	LD	HL,RGB
	CALL	STOUT
	LD	HL,LPGON
	CALL	STOUT
	LD	B,0
FRDR	PUSH	BC
	CALL	RGBT
	CALL	LAGE
	POP	BC
	DJNZ	FRDR
	LD	HL,GOFF
	CALL	STOUT
	RET
;
;RGBT
;Erstellung einer RGB-Tabelle
;PE:	(FARIY)=Tabellenanfang
;	HL=Speicheradresse
;PA:	(FARIY) bis (FARIY+120)=RGB-Tab.
;	HL+1
;VR:	AF,BC,D,HL
RGBT	PUSH	IY
	LD	IY,(FARIY)
	LD	HL,(PRAM)
	LD	B,40	;Anzahl der Sp.
;
RGBA	CALL	COL
	LD	C,A
	LD	A,M
	INC	H
	PUSH	BC
	PUSH	HL
	LD	B,8	;Pixelbyte
	LD	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