	title	PDMGTK
	subttl	Module from library PULL_DOWN_2 : PDMGTK

; Get key from translation table

; Copyright (C)	Werner Cirsovius
;		Hohe Weide 44
;		D-2000 Hamburg 20
;		Tel.: 040/4223247

;		Version 1.1 October 1988

; ENTRY	: Reg C holds key number
;	  Reg D holds translation table bit defined as:

; Bit       4         3        2      1       0
;	+-------+-----------+-----+-------+--------+
;	| Extra | Shift+Alt | Alt | Shift | Normal |
;	+-------+-----------+-----+-------+--------+

; Note that bit 0 is the highest and bit 4 the lowest
; priority

; EXIT	: Carry set on invalid key,
;	  Accu holds corresponding hex value from table

	public	pdmgtk

	ext	pdmxbs,pdmtop

	.xlist
	include	PDM.LIB
	.list

pdmgtk:
	ld	a,c		; Test max key number
	cp	tblen
	ccf
	ret	c		; Overflow, exit
	ld	a,d		; Get bit map
	and	11111b
	or	a		; Test any bit 
	scf
	ret	z
	ld	de,tblen	; Expand key # to 16 bit
	ld	hl,tblstr-tblen
bitshf:
	add	hl,de		; Point to map
	rra			; Find bit
	jr	nc,bitshf
	ld	b,0
	add	hl,bc		; Point to key
	push	hl
	ld	de,(pdmtop)	; Get bottom
	push	de
	ld	hl,rout
	ld	bc,routln
	ldir			; Routine into Common
	pop	bc
	pop	hl
	call	pdmxbs		; Execute routine
	dw	scrrun
	ld	a,l		; Get hex
	or	a
	ret

; ===== Routine in Common =====

rout:	; Simply fetch from table into Reg L

	ld	l,(hl)		; Fetch
	ret
routln	equ	$-rout

	end

