	title	Module from library PULL_DOWN_3 : PDMTTX
	name	('PDMTTX')

; Get key string from token table

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

;		Version 1.0 April 1995

; ENTRY	Accu holds token code #80 .. #9E
;	Reg HL points to buffer to be filled by string

; EXIT	Carry set on invalid token
;	Carry reset on valid token, buffer filled with tokens
;	Reg HL holds buffer address started with token count

; **** NOTE: Module must be initialized by calling PDMXOS

	entry	pdmttx

	ext	pdmxbs,pdmtop,p@@gtt

	.xlist
	include	PDM.LIB
	.list

pdmttx:
	and	7fh		; Mask for #00 .. #1E
	cp	1fh		; Test max
	ccf
	ret	c		; .. invalid
	push	hl
	push	hl
	ld	b,a		; Save fixed key
	push	bc
	ld	de,@code
	ld	hl,p@@gtt
	ld	bc,codlen
	ldir			; Unpack code
	ld	de,(pdmtop)	; Get bottom for Common
	push	de
	ld	hl,rout
	ld	bc,routln
	ldir			; Unpack code
	ex	de,hl		; Get Common buffer
	pop	bc		; Get real routine address
	pop	de		; Get key code
	push	hl		; Save Common buffer
	call	pdmxbs
	dw	scrrun
	pop	hl		; Get buffer in Common
	pop	de		; Get user buffer
	ld	c,(hl)		; Get length
	call	movit	; Load code
	pop	hl
	or	a
	ret

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

rout:	; Reg HL holds buffer in Common
	; Reg D holds normalized key #00..#1E

	ld	a,d		; Get key
	push	hl
@code:
	nop
	nop
	nop
codlen	equ	$-@code
	ld	de,0		; Init increment
	inc	a
srcexs:
	add	hl,de		; Point to token
	ld	e,(hl)		; Get length
	inc	hl
	dec	a
	jr	nz,srcexs	; Test found
	dec	hl
	ld	c,e
	pop	de
movit:
	ld	b,0
	inc	bc
	ldir			; Get tokens
	ret

routln	equ	$-rout

	end

