Re: LZ: A few optimizations and congrats for Daedalus Raytracer
[Prev][Next][Index][Thread]
Ryan Myers wrote:
>
> 4) My guess is you're still using "CALL GET_KEY", and that's a BIG bottleneck.
> My suggestion would be to visit Jingyang Xu's page and get the SCANKEY
> routines. They are MAJOR fast ( I'm using them in Spy Hunter and have
> to use
> delay routines to slow it down to playable speeds ) and also give you
> support for
> multiple keys and no delay on held keys.
>
> You basically can do multiple keys using SCANKEY like this:
OR you could use my ReadKey routine that's also fast. The IO is exactly the
same as for call GET_KEY but the difference is that it has key repeat. This
routine is VERY handy in interrupt handlers, where you CAN'T use GET_KEY
since it requires IM 1 (I believe), but you can also use it in games.
It's 62 bytes I think. (I used it in Game Wizard)
If two keys are pressed at the same time, the result will be 0 (don't know what
GET_KEY returns, but you can easily change that and the code will be smaller)
ReadKey:
push bc
push de
push hl
ld a,%11111110
ld hl,0
RepMask:
push af
out (1),a
in a,(1)
ld e,0
ld b,8
RepBitTest:
inc e
bit 0,a
jr nz,NoBit
push af
bit 7,h
jr nz,TwoKeys
ld a,l
add a,e
ld h,a
set 7,h
pop af
NoBit:
srl a
djnz RepBitTest
ld a,l
add a,8
ld l,a
pop af
rlca
bit 7,a
jr nz,RepMask
ld a,h
and %01111111
KeyDone:
pop hl
pop de
pop bc
ret
TwoKeys:
pop af
pop af
xor a
jr KeyDone
<pre>
--
Real name: Jimmy Mårdell
Email....: mailto:mja@algonet.se
IRC-name.: Yarin
WWW......: http://www.algonet.se/~mja
"Strap me down with disillusion
Tie me up in lifelines
Nothing stops my thoughts from breeding
Nothing's stopping my mind" - Leather Strip
</pre>
References: