;================================================================
;CP/M 2.2 f}r vortex-Speichererweiterung: Zeichenausgaberoutine
;Datei OSC4CHAR.MAC Version 02-Jan-89
;Include f}r OSC4BANK.MAC

;Ausgabe erfolgt beschleunigt in durch VIDATT angegebener Darstellung.
;Wahlweise sind deutsche Sonderzeichen m|glich
; Bit 0 -> Durchgestrichen
; Bit 1 -> Invertiert
; Bit 2 -> gerastert (halbhell)
; Bit 3 -> Unterstrichen
; Bit 4 -> Tiefgestellt
; Bit 5 -> Hochgestellt
; Bit 6 -> Fettschrift
; Bit 7 -> Kursiv

	.COMMENT @	;in OSC4BANK-MAC
	public chargr,charus,cwrite
tbuffer:ds 8		;8 Bytes Raum f}r aktuelle Zeichenmatrix
matrix:	ds 72		;Zeichenmatrix der deutschen Sonderzeichen
	@


;######	Zeichen in A an Spalte H Zeile L anzeigen
chargr:
;******	nur im Bildschirmmodus 2 erfolgt schnelle Ausgabe
	di
	exx
	bit 1,c			;Bildschirmmodus 2? = ld a,(0B1C8h)!cp 2
	exx
	ei
	jr z,cwrite		;Sprung zur alten Ausgaberoutine
;******	Charakterset fuer deutsche Umlaute suchen
	cp '@'
        jr z,code40		;Codewandlung
        cp '['
	jr c,outus
        cp '_'			;TXT WRITE CHAR eingetragen
        jr c,code5f		;Codewandlung
        cp '{'
	jr c,outus		;keine [nderung
        cp 7Fh
	jr nc,outus		;keine [nderung
code7f: add a,0CAh		;{|}~->Codes FCh-FFh
code40: add a,01Ah		;@->Code F7h
code5f: add a,09Dh-0F7h		;[\]^->Codes F8h-FBh
	ld bc,matrix		;Benutzerdefinierte Matrix
	jr disp
charus:
;******	nur im Bildschirmmodus 2 erfolgt schnelle Ausgabe
	di
	exx
	bit 1,c			;Bildschirmmodus 2? = ld a,(0B1C8h)!cp 2
	exx
	ei
cwrite:	jp z,$-$		;Sprung zur alten Ausgaberoutine
;******	Charaketerset fuer amerikanische Zeichen suchen
outus:	ld bc,3800h		;ROM-Zeichenmatrix
disp:
;******	relevante Matrix aus Zeichensatztabelle holen anhand Code in A
	ex de,hl		;DE := Koordinaten
	ld l,a
	ld h,0			;HL := Zeichencode
	add hl,hl
	add hl,hl
	add hl,hl
	add hl,bc		;BC := Zeichensatzadresse
	push hl			;(SP) := Charaktermatrix

;******	Spalte D Zeile E in Bildschirmposition umrechnen
	ld a,e
	add a,a
	add a,a
	add a,e		;Zeile * 5 (<120)
	rlca
	rlca
	rlca
	rlca		;Zeile * 8
	ld e,a
	and 0F8h	;Lower Byte
	add a,d		;Spalte addieren
	ld d,a
	ld a,e		;Higher Byte
	ld e,d
	adc a,0		;]bertrag
	ld d,a		;DE := Zeichenposition
	di		;Kollission mit Uhranzeige vermeiden !
	ld bc,0BC0Ch
	out (c),c
	ld b,0BFh
	in h,(c)
	ld bc,0BC0Dh
	out (c),c
	ld b,0BFh
	in l,(c)	;HL := CRTC - Bildshirmanfang
	ei
	add hl,hl	;CPU-Bildschirmoffset
	add hl,de	;HL := CPU-Zeichenadresse
	ld a,h
	and 07h		;2KB Bereich
	or 0c0h		;in oberen 16 KB
	ld h,a
	pop de		;DE := Charaktermatrix

;######	Zeichen ausgeben DE:= Charaktermatrix, HL:=Screenadresse
;(vidatt): Bit0=Durchgestrichen, Bit1=Invers, Bit2=gerastert
;Bit3=Unterstrichen, Bit4=Tief, Bit5=Hoch, Bit6=Fett, Bit7=Kursiv

	ld a,(vidatt)
	ld c,a		;Video-Attribut
	and 0FDh	;nichts au~er Invers?
	ld a,c
	jp z,tinvers
	push hl

	ex de,hl	;HL := Zeichenmatrix
	ld de,tbuffer	;DE := 8 Byte Puffer
	and 30h
	jr nz,tshift
	ld bc,8		;Matrix f}r weitere Mainpulationen in Puffer
	ldir
	jr tnoshif
tshift:	sub 10h		;Matrix in Puffer und dabei komprimieren
	jr nz,tnotief
	ld (de),a	;Voraussetzung: A = 0
	inc de
	ld (de),a
	inc de
	call tkompr	;Tiefstellen
	jr tnoshif
tnotief:sub 10h
	jr nz,tnohoch
	call tkompr	;Hochstellen
	ld (de),a	;Voraussetzung: A = 0
	inc de
	ld (de),a
	jr tnoshif
tnohoch:xor a
	ld (de),a
	inc de
	call tkompr	;Hoch + Tiefstellen = zentrieren
	ld (de),a
tnoshif:ld a,(vidatt)
	ld c,a

	and 0C0h	;Fett oder Kursiv verwendet?
	ld a,c
	jr z,tnofeku
	add a,a
	jr nc,tnokur
	ld hl,tbuffer	;Kursive Darstellung
	srl (hl)	;3 Rasterzeilen nach rechts rutschen
	inc hl
	srl (hl)
	inc hl
	srl (hl)
	ld hl,tbuffer+6	;3 Rasterzeilen bleiben
	sla (hl)	;2 Rasterzeilen nach links rutschen
	inc hl
	sla (hl)
tnokur:	add a,a
	jr nc,tnofett
	ld hl,tbuffer	;Fettschrift einschalten
	ld b,4
tf2:	ld a,(hl)
	add a,a
	or (hl)
	ld (hl),a
	inc hl
	ld a,(hl)
	add a,a
	or (hl)
	ld (hl),a
	inc hl
	djnz tf2
tnofett:ld a,c

tnofeku:and 09		;Unterstreichen oder Durchstreichen
	jr z,tnoduun
	ld a,0FFh
	bit 0,c
	jr z,tnodu
	ld (tbuffer+3),a	;Durchstreichen
tnodu:	bit 3,c
	jr z,tnoduun
	ld (tbuffer+7),a	;Unterstreichen

tnoduun:bit 2,c
	jr z,tlatt
	ld hl,tbuffer		;Rastern
	ld bc,0455h		;Schleifenz{hler + Raster
tras:	ld a,c
	and (hl)
	ld (hl),a
	inc hl
	ld a,c
	rrca			;Raster invertieren -> Schachbrett
	and (hl)
	ld (hl),a
	inc hl
	djnz tras

tlatt:	pop hl			;HL := Bildschirmadresse
	ld de,tbuffer		;DE := Zeichenmatrix
	ld a,(vidatt)		;A := Invers-Attribut
tinvers:and 02			;Zeichen auf Bildschirm darstellen
	jr z,tpos
	ld a,0FFh
tpos:	ld c,a			;C := Invers-Maske
	ld b,4
tpos2:	ld a,(de)		;Zeichenmatrix-Zeile
	inc de
	xor c
	ld (hl),a		;in Bildschirm
	set 3,h			;n{chste (ungerade!) Rasterzeile
	ld a,(de)		;Zeichenmatrix-Zeile
	inc de
	xor c
	ld (hl),a		;in Bildschirm
	ld a,h			;n{chste Rasterzeile
	add a,8
	ld h,a
	djnz tpos2
	ret

;******	Matrix in Puffer kopieren und dabei komprimieren
tkompr:	ldi
	inc hl
	ldi
	ldi
	inc hl
	ldi
	ldi
	ldi
	ret

;================================================================
