	TITLE	'TASTATURTREIBER K7604 M. JOYSTICK'

; VERSION 1.0
; 15.09.88

	MACLIB	Z80

	PUBLIC	TASINI,TAB,TASABF,TABMER
	EXTRN	INTEND,UHRPUF

ATS	EQU	40H		; BASISADRESSE DER ANSCHLUSS-
				; STEUERUNG
TASTE	EQU	ATS		; TASTATURZEICHEN
TASTST	EQU	TASTE+1		; ABFRAGE DER STATUSLEITUNGEN
TASANZ	EQU	ATS+2		; TASTATURKDO.
JOYST	EQU	TASTE+3

TASTP	EQU	0FF80H
TASTPE	EQU	TASTP+30H


; INITIALISIERUNG DER TASTATUR

TASINI:				; TASTATUR INIT.
	IN	TASTST
	BIT	3,A
	RNZ
	IN	TASTE
	JR	TASINI

;______________________________________________________________
; ABFRAGEN TASTATUR / JOYSTICK AUF ERSTBETAETIGUNG
;______________________________________________________________

TASABF:	IN	TASTST
	BIT	3,A
	JRZ	TASTDA		; --> NEUES ZEICHEN VON TAST.

;______________________________________________________________
; JOYSTICK ABFRAGEN
;______________________________________________________________

	LXI	H,TABJM
	IN	JOYST
	ANI	1FH
	CMA
	CMP	M
	MOV	M,A
	JRNZ	WDHABF		; --> NEUER JOYSTICKCODE
				;     WARTEN BIS STABIL
	INX	H
	CMP	M
	JRNZ	JOYABF		; --> NEUEN KODE AUSWERTEN

;______________________________________________________________
; ABFRAGEN WIEDERHOLFKT.
;______________________________________________________________

WDHABF:	LDA	UHRPUF+4
	ORA	A
	JNZ	INTEND		; --> NOCH NICHT WIEDERHOLEN

;______________________________________________________________

JOYABF:	MVI	A,5		; 100 ms wIEDERHOLFUNKTION
	STA	UHRPUF+4

;______________________________________________________________

	IN	TASTST
	BIT	3,A
	JRZ	TASTDA		; --> TASTE ERSTMALIG GEDRUECKT

;______________________________________________________________

	BIT	0,A
	JRZ	TASREP		; --> TASTE WIEDERHOLEN

;______________________________________________________________

	LXI	H,TABJN
	IN	JOYST
	ANI	1FH
	CMA
	CMP	M
	MOV	M,A		; NEUEN JOYSTICKKODE MERKEN
	JRZ	TASREP		; --> JOYSTICKKODE WDH.
	ORA	A
	JRNZ	TASTDA		; --> JOYSTICKCODE NEU
	JMP	INTEND

;______________________________________________________________
; EINSTELLEN ZEITKONSTANTE FUER ERSTE TASTENWIEDERHOLUNG
;______________________________________________________________

TASTDA:	MVI	A,25		; 500 ms FUER ERSTE WDH.
	STA	UHRPUF+4

TASREP:	MVI	B,TASTPE-TASTP	; BERECHNEN PUFFERPOSITION
	LXI	H,TASTP
TAPUBE:	MOV	A,M
	ORA	A
	JRZ	TAPUPO		; --> FREIE POSITION GEFUNDEN
	INX	H		; NAECHSTE POSITION PRUEFEN
	DJNZ	TAPUBE
	JMP	INTEND		; PUFFER VOLL

;______________________________________________________________
; TASTENCODE / JOYSTICKCODE AUSWERTEN
;______________________________________________________________

TAPUPO:	IN	TASTST
	CMA
	ANI	9
	JRNZ	TASCOD		; --> ZEICHEN VON TASTATUR

;______________________________________________________________
; KODE VON JOYSTICK
;______________________________________________________________

	IN	JOYST
	CMA
	ANI	1FH
	LXI	B,TABJ		; TABELLE DER KODEAEQUIVALENTE

;______________________________________________________________

SCHLEI:	SRLR	A
	JRC	ESCHLE		; KODE AKTIV
	ORA	A
	JZ	INTEND		; --> ENDE DER UMSETZUNG
SCHLE1:	INX	B		; NAECHSTES BIT PRUEFEN
	JR	SCHLEI

;______________________________________________________________

ESCHLE:	PUSH	PSW		; KODE UEBERNEHMEN
	LDAX	B
	MOV	M,A
	POP	PSW
	INX	H
	JR	SCHLE1

;______________________________________________________________
; KODE VON TASTATUR
;______________________________________________________________

TASCOD:	IN	TASTE
	MOV	M,A
	JMP	INTEND

;______________________________________________________________
; PUFFER
;______________________________________________________________

TABMER:	DW	0

TAB:
	DB	0C3H,19H,0	; FEHLER IM TASTEPROM
	DB	0D3H,19H,0

	DB	0B4H,11H,7FH,0
	DB	0B6H,11H,16H,0
	DB	0B7H,11H,01H,0
	DB	0B8H,11H,05H,0
	DB	0B9H,11H,06H,0
	DB	0BAH,11H,13H,0
	DB	0BBH,11H,12H,0
	DB	0BCH,11H,04H,0
	DB	0BDH,11H,13H,18H,0
	DB	0BEH,11H,18H,0
	DB	0BFH,11H,03H,0

	DB	0D1H,11H,19H,0
	DB	0D2H,01H,14H,0
	DB	0C5H,10H,16H,0
	DB	0D5H,10H,14H,0
	DB	0C6H,10H,13H,0
	DB	0D6H,10H,18H,0
	DB	0C8H,0BH,03H,0
	DB	0D8H,0BH,16H,0
	DB	0C9H,0BH,0EH,0
	DB	0D9H,0BH,19H,0
	DB	0CBH,0BH,02H,0
	DB	0DBH,11H,02H,0
	DB	0CCH,0BH,0BH,0
	DB	0DCH,11H,0BH,0
	DB	0DEH,11H,10H,0
	DB	0CFH,0FH,07H,0
	DB	0DFH,0FH,18H,0
	DB	0,0

TABE:

;______________________________________________________________

TABJM:	DB	0
TABJN:	DB	0

TABJ:
	DB	05H	; CURSOR UP
	DB	18H	; CURSOR DOWN
	DB	08H	; CURSOR LEFT
	DB	04H	; CURSOR RIGHT
	DB	0DH	; ENTER

	END
