HIRES   ASM 
;***************************************
;
;	    >>> HIRES.KCC <<<
;
;    (CAOS-ERWEITERUNG FUER KC 85/4)
;
;       (TEXTMODE IM HIRES-MODUS)
;
;	   ` 1994 by R.K{stner
;
;***************************************
	ORG	06000H
;---------------------------------------
START	JP	BEGIN	;SELBSTSTART
;***************************************
;  CAOS-SYSTEMZELLEN
;***************************************
WINON	EQU	0B79CH
WINLG	EQU	0B79EH
CURSO	EQU	0B7A0H
STBT	EQU	0B7A2H
COLOR	EQU	0B7A3H
WEND	EQU	0B7A4H
CCTL0	EQU	0B7A6H
SUTAB	EQU	0B7B0H
CTAB	EQU	0B7B2H
OUTAB	EQU	0B7B9H
INTAB	EQU	0B7BBH
UOUT2	EQU	0B7C3H
L3TAB	EQU	0B7DDH
L3SIZ	EQU	0B7DFH
;***************************************
;  ARBEITSZELLEN
;***************************************
OTBNEU	DEFB	0
	DEFB	38H
	DEFB	2
	DEFB	3
WDPLR	DEFW	0	;(WEND)-PG/LORES
WDSLR	DEFW	0	;(WEND)-SC/LORES
WDSHR	DEFW	SCRLPG	;(WEND)-SC/HIRES
;***************************************
 
;CRT-Treiber
 
PADR1	LD	HL,(WINON)
	ADD	HL,DE
	SLA	H
	SLA	H
	SLA	H
	;
PADR	PUSH	AF
	LD	A,L	;Spalte
	LD	L,H	;Pixelzeile
	CP	28H
	JR	NC,IAD2	;zu gro~
	OR	80H
	LD	H,A	;HL=Pixeladr.
	POP	AF
	AND	A	;CY=0
	RET
	;
IAD2	POP	AF
	SCF		;CY=1
	RET
 
;HIRES-VERKNUEPFUNG
 
HIRVK	PUSH	BC
	PUSH	AF	;A-FARBCODE 0..3
	LD	A,C	;SINV & I/P lad.
	RLA
	AND	18H	;BIT 3/4 bleibt
	LD	C,A	;laden
	POP	AF
	OR	C	;01=FARBE/2=DL
	LD	C,A	;3=SINV/4=I/P
	JR	INPIX
HIRVC	DI		;wichtig !!!
	LD	A,(IX+1)
	LD	B,A	;merken
	XOR	2
	OUT	84H,A	;CIRM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28H
	JR	NC,POPS4;au~erhalb
	OR	80H
	LD	B,D
	LD	D,A
	LD	A,B	;A:=:D
	ADD	A
	ADD	A
	ADD	A	;*8
	LD	E,A
	EX	DE,HL	;HL-ADR.IRM
	LD	A,(STBT);DE-PIXELMUSTER
	LD	C,A
	LD	A,(COLOR)
	AND	1BH	;BIT 0/1 & 3/4
	LD	B,A
	RRCA
	RRCA
	RRCA		;A=INK
	SET	3,C	;INK laden
	BIT	0,C	;INK on?
	CALL	Z,HIRVK
	RES	3,C	;PAPER laden
	LD	A,B
	AND	3	;A=PAPER
	BIT	1,C	;PAPER on?
	CALL	Z,HIRVK
;
POPS4	POP	AF
	POP	BC
	POP	DE
	POP	HL
	RET
 
MOVELN	;Rolle Fenster f}r Scrolling
	PUSH	HL
	PUSH	DE
	PUSH	BC
	PUSH	AF
	EX	AF,AF'
	PUSH	AF
	LD	A,C	;BC:Pixelzeilen
	EX	AF,AF'
	LD	A,(WINLG) ;Spalten
MOLN1	PUSH	HL
	PUSH	DE
MOLN2	LDI		;zeichenweise
	LDI
	LDI
	LDI
	LDI
	LDI
	LDI
	LDI
	JP	PE,MOLN2
	POP	DE
	POP	HL
	INC	H	;neue Spalte
	INC	D
	EX	AF,AF'
	LD	C,A
	EX	AF,AF'
	DEC	A	;Spaltenz{hler
	JR	NZ,MOLN1
	EX	AF,AF'
	POP	AF
	EX	AF,AF'
	JR	POPS4
 
PCHR	;CRT-Grundprogramm
	LD	DE,(CURSO)
	LD	HL,STBT
	BIT	4,M	;ESC aktiv?
	JR	Z,PCHR3
CRT1	RES	4,M
	CP	'0'
	RET	C
	CP	'9'+1
	JR	NC,PCHR1
	SUB	'0'
	JR	PCHR2
	;
PCHR1	CP	'A'
	RET	C
	RES	5,A
	CP	'Z'+1
	RET	NC
	SUB	'A'-0AH
PCHR2	LD	HL,L3SIZ;Tabelle
	CP	M	;lang genug?
	RET	NC
	ADD	A	;*2
	LD	HL,(L3TAB) ;klar zum
	JR	PCHR4	;Ansprung
	;
PCHR3	CP	20H	;Steuerfunktion?
	JR	NC,PCHR5
	BIT	3,M	;darstellen?
	JR	NZ,PCHR5
	CP	001H
	JP	Z,CLR
	CP	002H
	JP	Z,CLLN
	CP	00CH
	JP	Z,CLS
	CP	012H
	JP	Z,SCROL
	CP	01AH
	JP	Z,INS
	CP	01FH
	JP	Z,DEL
	ADD	A	;*2
	LD	HL,(CTAB)
PCHR4	LD	C,A
	LD	B,0
	ADD	HL,BC
	LD	A,M
	INC	HL
	LD	H,M
	LD	L,A
JPHL	JP	(HL)	;anspringen
 
PCHR5	CALL	0F003H
	DEFB	32H
	RET	C	;au~erhalb
	LD	M,A	;ASCII eintragen
	CALL	WPIX	;darstellen
CUR	INC	E
CUR1	LD	A,(WINLG)
	DEC	A
	CP	E
	RET	NC
NL	LD	E,0	;NL f}r 1E
CUD	INC	D
	LD	A,(WINLG+1)
	CP	D
	RET	NZ
	LD	HL,(WEND)
	JP	(HL)	;PAGE o. SCROLL
 
SCROL	LD	HL,SCRLPG ;ShCUD
	LD	(WEND),HL
	RET
 
CLR	LD	A,E	;wie CUL
	AND	A
	JR	Z,CLR1
	DEC	E
	JR	DEL
CLR1	LD	A,D
	AND	A
	JR	Z,DEL
	DEC	D
	LD	A,(WINLG)
	DEC	A
	LD	E,A
DEL	PUSH	DE	;Cursor retten
	CALL	0F003H
	DEFB	32H
	LD	A,M
	AND	A	;Ende?
	JR	Z,POPDE
	PUSH	HL	;VRAM
DEL1	PUSH	DE	;Cursor
	INC	E	;n{chste Spalte
	CALL	0F003H	;raus?
	DEFB	32H
	JR	NC,DEL2
	LD	E,0	;ja, wie NL
	INC	D
	CALL	0F003H	;raus?
	DEFB	32H
	JR	C,DEL3	;ja-wie Ende
DEL2	LD	A,M
	AND	A	;Ende?
	JR	Z,DEL3
	LD	B,D
	LD	C,E	;BC:=DE
	POP	DE	;DE=links davon
	EX	(SP),HL	;HL=VRAM links
	LD	M,A	;eintragen
	CALL	WPIX	;zeichnen
	LD	D,B
	LD	E,C	;DE:=BC
	JR	DEL1	;von vorn
 
DEL3	POP	DE
	POP	HL
	LD	M,0
	LD	A,' '
	CALL	WPIX
POPDE	POP	DE
	RET
 
INS	PUSH	DE	;Cursor
	LD	A,' '
	CALL	0F003H
	DEFB	32H
INS1	LD	B,M	;VRAM
	LD	M,A	;neues Zeichen
	CALL	WPIX	;zeichnen
	LD	A,B
	AND	A	;Dummy?
	JR	Z,INS2
	INC	E	;CUR
	CALL	0F003H	;raus?
	DEFB	32H
	JR	NC,INS1
	LD	E,0	;wie NL
	INC	D
	CALL	0F003H	;raus?
	DEFB	32H
	JR	NC,INS1
INS2	POP	DE	;wenn ja Schlu~
	RET
 
CLS	LD	A,(WINLG+1) ;ShHOME
	LD	D,0
CLS1	PUSH	AF
	CALL	CLLN
	POP	AF
	INC	D
	DEC	A
	JR	NZ,CLS1	;A Zeilen
	LD	DE,0	;CURSOR HOME
	RET
 
 
SCRLPG	LD	A,(WINLG) ;Spalten
	LD	C,A
	LD	B,0
	LD	A,(WINLG+1) ;Zeilen
	DEC	A	;nur 1 Zeile?
	JR	Z,SCRL3	;nur CLLN
	PUSH	DE
	PUSH	AF
	LD	DE,0	;Cursor li/oben
	CALL	0F003H
	DEFB	32H
	EX	DE,HL
SCRL1	LD	HL,40	;1 Zeile tiefer
	ADD	HL,DE
	PUSH	HL
	PUSH	BC
	LDIR		;im VRAM eine
	POP	BC	;Zeile rollen
	POP	DE
	DEC	A
	JR	NZ,SCRL1;A*
	POP	AF
	ADD	A
	ADD	A
	ADD	A	;*8:=Pixelzeilen
	LD	C,A
	LD	DE,0
	LD	B,D	;B=0
	CALL	PADR1
	EX	DE,HL	;DE=PixAdr.
	LD	L,8	;H war 0
	ADD	HL,DE
	CALL	FARBEA
	CALL	MOVELN	;CIRM rollen
	CALL	FARBEA
	CALL	MOVELN	;PIRM rollen
	POP	DE	;CUPO
SCRL3	DEC	D
	;
CLLN	LD	E,0	;ShDEL
	CALL	0F003H	;Au~erhalb?
	DEFB	32H
	RET	C	;(Selbstschutz)
	LD	A,(WINLG)
	LD	B,A	;Spalten
	LD	C,A
	XOR	A
CLLN1	LD	M,A	;VRAM l|schen
	INC	HL
	DJNZ	CLLN1
	CALL	PADR1
	RET	C
	PUSH	DE
	LD	A,(COLOR)
	AND	3	;PAPER
	LD	DE,0	 ;sw
	OR	A
	JR	Z,CLLN2
	LD	DE,0FF00H;rt
	DEC	A
	JR	Z,CLLN2
	LD	DE,000FFH;tue
	DEC	A
	JR	Z,CLLN2
	LD	DE,0FFFFH;wss
CLLN2	LD	A,D
	LD	B,2
	JR	CLLN4
CLLN3	CALL	FARBEA
	LD	A,E
CLLN4	PUSH	HL
	PUSH	BC
	LD	B,C	;ZEICHENANZAHL
CLL1	LD	D,L	;L retten
	LD	M,A	;zeichenweise
	INC	L	;ohne Schleife
	LD	M,A
	INC	L
	LD	M,A
	INC	L
	LD	M,A
	INC	L
	LD	M,A
	INC	L
	LD	M,A
	INC	L
	LD	M,A
	INC	L
	LD	M,A	;8 BYTE
	LD	L,D	;L holen
	INC	H	;n{chste SPALTE
	DJNZ	CLL1
	POP	BC
	POP	HL
	DJNZ	CLLN3
	CALL	FARBEA
	POP	DE
	RET
 
FARBEA	PUSH	AF
	LD	A,(IX+1)
	XOR	2
	DI
	LD	(IX+1),A
	OUT	84H
	EI
	POP	AF
	RET
 
CRT	PUSH	HL	;CRT neu HIRES
	PUSH	DE
	PUSH	BC
	PUSH	AF
	CALL	PCHR
	LD	(CURSO),DE
	POP	AF
	POP	BC
	POP	DE
	POP	HL
	RET
 
;***************************************
;
;     ###  EINSPRUNG SELBSTSTART ###
;
;***************************************
	DEFW	07F7FH
	DEFM	'HIRES'
	DEFB	1
BEGIN	LD	A,(0E011H)
	CP	07FH
	JR	Z,BEGI1
	CALL	0F003H
	DEFB	023H
	DEFB	0CH
	DEFW	0A0DH
	DEFW	0A0AH
	DEFM	'  "HIRES.KCC" l'
	DEFB	07BH
	DEFM	'uft nur auf '
	DEFM	'KC 85/4 !!! '
	DEFW	0D0AH
	DB	7,7,7
	DEFB	0
	RET
BEGI1	XOR	A
	BIT	3,(IX+1)
	JR	NZ,BEGI2
	LD	A,1BH
	CALL	0F003H
	DEFB	24H
	LD	A,'A'
	CALL	0F003H
	DEFB	24H	;HIRES auf off
BEGI2	PUSH	AF	;merken
	LD	DE,(WEND);alt
	PUSH	DE
	LD	A,12H
	CALL	0F003H
	DEFB	24H	;SCROLL on
	LD	HL,(WEND)
	LD	(WDSLR),HL;merken
	LD	A,11H
	CALL	0F003H
	DEFB	24H	;PAGE on
	LD	HL,(WEND)
	LD	(WDPLR),HL;merken
	POP	HL
	LD	(WEND),HL;wie vor
	LD	HL,VMAIN
	LD	(UOUT2+1),HL;KAN.3 laden
	LD	HL,OTBNEU+3
	LD	(OUTAB),HL;KANAL 3 on
	POP	AF
	OR	A
	RET	Z
	LD	A,1BH
	CALL	0F003H
	DEFB	24H
	LD	A,'A'
	CALL	0F003H
	DEFB	24H	;HIRES war on
	RET
;***************************************
; HAUPTSCHLEIFE HIRES-TEST UND VERTEILER
;***************************************
VMAIN	PUSH	HL
	PUSH	AF
	LD	HL,(WEND)
	LD	A,(WDPLR)
	BIT	3,(IX+1)
	JR	NZ,VMAIL
	CP	L	;HIRES on
	JR	NZ,VMH1
	LD	A,(WDPLR+1)
	CP	H
	JR	Z,VMHW
VMH1	LD	A,(WDSHR)
	CP	L
	JR	NZ,VMH2
	LD	A,(WDSHR+1)
	CP	H
	JR	Z,VMHW
VMH2	LD	HL,(WDSHR)
	LD	(WEND),HL
VMHW	POP	AF
	POP	HL
	CALL	CRT	;CRT neu
	RET
VMAIL	CP	L	;LORES on
	JR	NZ,VML1
	LD	A,(WDPLR+1)
	CP	H
	JR	Z,VMLW
VML1	LD	A,(WDSLR)
	CP	L
	JR	NZ,VML2
	LD	A,(WDSLR+1)
	CP	H
	JR	Z,VMLW
VML2	LD	HL,(WDSLR)
	LD	(WEND),HL
VMLW	POP	AF
	POP	HL
	CALL	0F003H	;CRT alt
	DEFB	000H
	RET
À@Àt(Àp6ÀnTop of Text: End of Text: Start of MC: ASM-Offs
VMLW	POP	AF
	POP	HL
	CALL	0F003H	;CRT alt
	DEFB	000H
	RET
À@Àt(Àp6ÀnTop of Text: End of Text: Start of MC: ASM-Offs