> One trick I almost always use, is instead of:
[...]

Oh, yes, smart move! I'm pretty sure I had at least one copy of
Electron User that thought this technique so magnificent that it got a
front page mention as "discover extra registers" or something like
that.

> By the way:
>
>>        ld d, (NUMVERTS)
>
> I don't think you can do this?

No, you're right, you can't. It silently substituted ld a, (NUMVERTS),
so that loop was running quite a bit longer than it needed to and the
result not being visibly different unless the polygon hits the first
scanline. So easy to miss.

To be honest, more than 50% of my bugs today have been the result of
pyz80 silently substituting legal code for illegal code. All related
to my sudden haziness on the z80, of course.

On Sat, Oct 24, 2009 at 11:20 PM, Andrew Collier
<[email protected]> wrote:
> On 24 Oct 2009, at 20:08, Thomas Harte wrote:
>
>> Anyway, if some of you z80 experts could have a quick look and tell me
>> if I'm making any obvious style errors or otherwise missing obvious
>> optimisations — even if only on a peephole level — I'd be infinitely
>> grateful.
>
>
>> NUMVERTS:
>>        db 0
>
> ...
>>
>>        ld a, (NUMVERTS)
>
> I would write:
>
> NUMVERTS: equ $+1
>            ld a,00
>
> i.e. the data byte of the instruction is overwritten when the symbol is used
> (other code can write the symbol as normal). You can safely do this even if
> you're writing to the next consecutive instruction (i.e. there are no
> pipelining issues to be concerned with. Naturally, I would be shot for
> proposing this on any processor newer than the Z80)
>
> This is a byte smaller, and 8 t-states faster (not much, but it can be
> useful if the value is used frequently. Of course, if you read the variable
> in several places only one of them can be modified in this way. Choose the
> one which is executed most often).
>
> You can do this for any instruction which takes a literal data byte or word
> (use EQU $+2 for an instruction which uses the index registers). The only
> gotcha is that you must be careful to write the correct data size back, i.e.
> never write a double-register to storage allocated by 'ld a,00' otherwise
> you will corrupt the following instruction.
>
> By the way:
>
>>        ld d, (NUMVERTS)
>
> I don't think you can do this?
> If you've managed to persuade pyz80 to accept that, I'd be interested to see
> what opcode it generated...
>
> NB. the transformed alternative *is* available. i.e.:
> NUMVERTS: equ $+1
>            ld d,00
>
> HTH,
> Andrew
>
> --
> http://www.intensity.org.uk/
>
>
>
>

Reply via email to