Difference between revisions of "Z80 Routines:Input:GetCSC"
From WikiTI
(Attempt to add this page to the category) |
(added another routine) |
||
Line 1: | Line 1: | ||
[[Category:Z80 Routines:Input|GetCSC]] | [[Category:Z80 Routines:Input|GetCSC]] | ||
[[Category:Z80 Routines|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. | ||
Line 15: | Line 16: | ||
GetCloneSC: | GetCloneSC: | ||
− | ld c, | + | ; push bc ; uncomment for preserving bc |
+ | ld c, 0BFh | ||
ld b, 7 | ld b, 7 | ||
getCSCloop: | getCSCloop: | ||
Line 50: | Line 52: | ||
xor a | xor a | ||
getCSCgoodCSC: | getCSCgoodCSC: | ||
+ | ; pop bc | ||
ret | ret | ||
getResetBit: | getResetBit: | ||
− | cp | + | cp $FF |
ret z | ret z | ||
ld b, 0 | ld b, 0 | ||
Line 60: | Line 63: | ||
inc b | inc b | ||
jr c, getResetBitLoop | jr c, getResetBitLoop | ||
+ | ret</nowiki> | ||
+ | |||
+ | ==== Alternative Version ==== | ||
+ | |||
+ | This has debouncing? | ||
+ | |||
+ | <nowiki>;Getcsc replacement by James Montelongo | ||
+ | ; Outputs: | ||
+ | ; - A: Keycode | ||
+ | ; Destroys: | ||
+ | ; - AF | ||
+ | gsGetK: | ||
+ | gsGetCSC: | ||
+ | push hl | ||
+ | push de | ||
+ | push bc | ||
+ | ld e,$fe ;frist group | ||
+ | ld c,$01 ;key port | ||
+ | ld l,0 ;l holds key pressed | ||
+ | cscloop: | ||
+ | ld a,$ff ;For some reason emulator really wants it in the loop | ||
+ | out (1),a ;reset keyport | ||
+ | ld h,$fe | ||
+ | out (c),e ;set keygroup | ||
+ | ld b,8 ;loop, Delay needed when work with key driver | ||
+ | in a,(c) ;read key | ||
+ | cscbit: | ||
+ | inc l ;inc to get key pressed | ||
+ | rra ; if key pressed done | ||
+ | jp nc,donecsc | ||
+ | rlc h | ||
+ | djnz cscbit ;loop 8 | ||
+ | rlc e ;next key group | ||
+ | jp m,cscloop ;if bit 7 set loop | ||
+ | ld l,0 ;if no key pressed 0 | ||
+ | donecsc: | ||
+ | ld a,$ff | ||
+ | out (1),a | ||
+ | ld a,e | ||
+ | cpl | ||
+ | out (1),a | ||
+ | nop | ||
+ | nop | ||
+ | in a,(1) | ||
+ | inc a | ||
+ | jp z,nootherkeypressed | ||
+ | ld l,0 | ||
+ | nootherkeypressed: | ||
+ | ld a,$ff | ||
+ | out (1),a | ||
+ | nop | ||
+ | ld a,e | ||
+ | out (1),a | ||
+ | nop | ||
+ | nop | ||
+ | in a,(1) | ||
+ | cp h | ||
+ | jr z,only1key | ||
+ | ld l,0 | ||
+ | only1key: | ||
+ | ld a,l ; | ||
+ | or a | ||
+ | ld (gs_keymem),a | ||
+ | pop bc | ||
+ | pop de | ||
+ | pop hl | ||
ret</nowiki> | ret</nowiki> |
Revision as of 01:21, 15 June 2010
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: ; push bc ; uncomment for preserving bc 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: ; pop bc ret getResetBit: cp $FF ret z ld b, 0 getResetBitLoop: rrca inc b jr c, getResetBitLoop ret
Alternative Version
This has debouncing?
;Getcsc replacement by James Montelongo ; Outputs: ; - A: Keycode ; Destroys: ; - AF gsGetK: gsGetCSC: push hl push de push bc ld e,$fe ;frist group ld c,$01 ;key port ld l,0 ;l holds key pressed cscloop: ld a,$ff ;For some reason emulator really wants it in the loop out (1),a ;reset keyport ld h,$fe out (c),e ;set keygroup ld b,8 ;loop, Delay needed when work with key driver in a,(c) ;read key cscbit: inc l ;inc to get key pressed rra ; if key pressed done jp nc,donecsc rlc h djnz cscbit ;loop 8 rlc e ;next key group jp m,cscloop ;if bit 7 set loop ld l,0 ;if no key pressed 0 donecsc: ld a,$ff out (1),a ld a,e cpl out (1),a nop nop in a,(1) inc a jp z,nootherkeypressed ld l,0 nootherkeypressed: ld a,$ff out (1),a nop ld a,e out (1),a nop nop in a,(1) cp h jr z,only1key ld l,0 only1key: ld a,l ; or a ld (gs_keymem),a pop bc pop de pop hl ret