[A83] Re: cant get code to work


[Prev][Next][Index][Thread]

[A83] Re: cant get code to work




>
> OK, I've tried several different things to get this code to work, but I
guess
> something is required that I'm unaware of.  The code works fine if I don't
> mess with the variable (friction), and I've tried putting that section in
> several parts of the code, still no luck. It just freezes when I hit 2nd.
> I'm sure it's something easy...
>
> getkey_2nd:
>       ld   a,kReset
>     out  (1),A
>     ld   a,Group7
>     out  (1),A
>     in   a,(1)
>     cp k2nd
>     ret nz
>     pop hl
>     pop bc
>     inc b
>     push bc
>     push hl
>     ld hl,(friction)
>     inc hl
>     inc hl
>     inc hl
>     ld (friction),hl
>     ret
>
> Also, could I use "add hl,3" or something similar instead of incrementing
> multiple times?
> Any help is appreciated.
>


There is no opcode 'add hl,nnnn'.  However, you can do 'add hl,de', 'add
hl,bc', 'add hl,hl', and 'add hl,sp'.  In this case 3 'inc hl's is smaller
and faster than the code it would take to load 3 into de or something and do
'add hl,de'.
Just in my opinion - It's bad coding to pop more words of the stack than
you've pushed, especially within subroutines.  Try to think of a way you
don't have to do that.  What is the 'inc b' for, BTW?
- - Joe




Follow-Ups: References: