A86: Re: Re: Re: Z80 & new game preview


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

A86: Re: Re: Re: Z80 & new game preview




*sigh* this guy's routine is faster and it even works! (i introduced a small
problem when finding the absolute value too often, hehe). you will no longer
need 2 tables, just one. (the one with all the squares in it). it'd be nice
if this worked on gameboy also. does the gameboy have "NEG"? if it doesn't,
you can change "NEG" to "DEC A\CPL" i believe.

; This routine performs BC = E * L
; D & H must point to a table of the lsb and msb of squares as follows:
;  .db 0*0/4,1*1/4,2*2/4,...,255*255/4
;  and then the msb's of those...
;  .db 256*256/4,...,511*511/4
;  and then the msb's of those.
; D & H are preserved if you call MULT many times in succession (saving 3
cycles each).
; Otherwise you'll want to init D & H at the beginning of MULT, and ditch
the last two
; lines. Also, if you want input to be in A * E, you can save 4 t-states =)

MULT    LD   A,L        4
        SUB  E          4       ; A=(a-b)
        JR   NC,noneg   7/12    ; if carry then A=(b-a)
        NEG             8
noneg   LD   L,A        4
        ADD  A,E        4
        ADD  A,E        4       ; A=(a+b) MOD 256
        LD   E,A        4
        JR   NC,small   7/12
        INC  D          4       ; if a+b is in the range 256-511, point
        INC  D          4       ; to the next block of the table
small   LD   A,(DE)     7       ; A=[(a+b)^2]/4, LSB
        SUB  (HL)       7       ; subtract [(a-b)^2]/4, LSB
        LD   C,A        4       ; C=a*b, LSB
        INC  D          4       ; point to table of squares, MSB
        INC  H          4
        LD   A,(DE)     7       ; as above, subtracting in the borrow flag
        SBC  A,(HL)     7
        LD   B,A        4       ; B=a*b, MSB  (*)
        DEC  H          4
        LD   D,H        4       ; restore to table of squares, LSB
        RET             10

   100
+    3  if swap of a&b required
+    3  if (a+b) > 255
+   10  if counting RET.

----- Original Message -----
From: Kirk Meyer <kirkmeyer@bigfoot.com>
To: <assembly-86@lists.ticalc.org>
Sent: Saturday, November 27, 1999 7:58 PM
Subject: A86: Re: Re: Z80 & new game preview


> Heh I forgot to mention that the routine does BC = A * B



References: