Difference between revisions of "Z80 Routines:Input:GetCSC"

From WikiTI
Jump to: navigation, search
m (Routines:Input:GetCSC moved to Z80 Routines:Input:GetCSC: Does it belong here?)
(Attempt to add this page to the category)
Line 1: Line 1:
 +
[[Category:Z80 Routines:Input|GetCSC]]
 +
[[Category:Z80 Routines|GetCSC]]
 
This is a replacement for the GetCSC routine. Its returns are exactly the same. You need to have a variable called lastKey so keys won't repeat. Unless you want that. Feel free to add versions with fun stuff like controlled repeating.
 
This is a replacement for the GetCSC routine. Its returns are exactly the same. You need to have a variable called lastKey so keys won't repeat. Unless you want that. Feel free to add versions with fun stuff like controlled repeating.
  

Revision as of 18:57, 27 September 2009

This is a replacement for the GetCSC routine. Its returns are exactly the same. You need to have a variable called lastKey so keys won't repeat. Unless you want that. Feel free to add versions with fun stuff like controlled repeating.

;====== GetCSC clone ===========================================================
; This routine is a replacement for the GetCSC bcall.  Its returns are the same.
; Inputs:
;  - None
; Outputs:
;  - A: Keycode
; Destroys:
;  - AF, BC

; To do: Add debouncing

GetCloneSC:
	ld	c, 0bfh
	ld	b, 7
getCSCloop:
	ld	a, c
	out	(1), a
	nop
	nop
	nop
	rrca
	ld	c, a
	in	a, (1)
	cp	0ffh
	jr	nz, getCSCgotCSC
	djnz	getCSCloop
	xor	a
	ld	(lastKey), a
	ret
getCSCgotCSC:
	dec	b
	ld	c, b
	call	getResetBit
	ld	a, b
	sla	c
	sla	c
	sla	c
	add	a, c
	ld	b, a		; This dance ensures that
	ld	a, (lastKey)	; the keycode is returned in A
	ld	c, a
	ld	a, b
	cp	c
	ld	(lastKey), a
	jr	nz, getCSCgoodCSC
	xor	a
getCSCgoodCSC:
	ret
			
getResetBit:
	cp	0ffh
	ret	z
	ld	b, 0
getResetBitLoop:
	rrca
	inc	b
	jr	c, getResetBitLoop
	ret