Re: A83: ti compiler....hl to a question


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

Re: A83: ti compiler....hl to a question




Actually, the following is much more accurate, but not as simple to
understand :)

 ldi
 jr pe,-4

This actually takes place in one step.  It executes an 'ldi' (I don't know
whether or not it uses the same circuitry) and if BC is 0 (determined either
by the parity flag or an internal register...not sure if the register block
is updated on the fly or at the end) then PC is decremented by 2 (i.e. the
beginning of the ldir).  So, why is this important?  Because each step (the
combination of the two instructions above) is atomic (cannot be
interrupted).  But, the sequence can be interrupted anytime between steps.
In other words, an interrupt can occur in the middle of a copy operation.
Take the following code for example:

 ld hl,$8000
 ld de,$8000
 ld bc,$8000
 ldir

(yes, I know that it could be optimized to load all the registers from hl,
but for example's sake...)

You are going to have ~20 interrupts occur during that ldir.  This is a very
good thing for several reasons.  First off, as mentioned, you'd miss a lot
of interrupts during copies.  And this is bad.  On the calc, it's not so
important, since interrupts aren't that important, you'll just miss reading
keys or updating grayscale (which would still be bad).  But if you are doing
something like reading data from some kind of communications device, you
would lose this data.  There is another important reason: remember the R
register?  The R register controls the dynamic memory refresh.  If this
wasn't updated (make a loop that continuously sets it to 0), then the memory
wouldn't refresh and would lose all data.  I am not positive that tying up
the cpu for that long would cause the memory refresh to fail, but it makes
sense that there would be register contention otherwise.

> but, to explain...
> LDIR is equivalent to:
>
> label:
>   ld a,(hl)
>   ld (de),a
>   inc hl
>   inc de
>   dec bc
>   ld a,b
>   or c
>   jr nz,label





References: