Jump to content
IGNORED

need multiply by 1.6 and by 2.6666... algorithms/routines


Recommended Posts

Phaeron's code is elegant, but doesn't it scale down from 512x512 to 320x192, which is the exact opposite of what Thom was looking for, scale up from 320x192 to 512x512? I'm sure it can be reversed in a simple way, though I'm a little too thick to figure out how.

 

Derp. Here's two replacements. This time I'll leave them in BASIC USR() form, conversion to ASM entry point left as exercise for reader.

 

Fixed point division by 320 to produce a 9 bit fractional result with error [0..1):

        pla                 ;load argument count = 1
        sta     fr0         ;temp=1
        pla
        ror                 ;dividend bit 8 -> C
        pla
        ror                 ;A = dividend bits 8-1
        ror     fr0         ;temp = dividend bit 0 in high bit
        clc                 ;enter C=0
        ldx     #9          ;producing 9 bit result
xloop:
        tay                 ;save dividend
        sbc     #80-1       ;trial subtraction
        bcs     ok          ;C=1 if subtraction OK
        tya                 ;C=0, subtraction failed; restore
ok:
        rol     fr0         ;shift in quotient bit, shift out dividend LSB
        rol                 ;dividend x2 + capture quotient bit 8 + C=0
        dex                 ;next bit
        bne     xloop       ;continue until 9 quotient bits produced
        and     #1          ;isolate quotient bit 8
        sta     fr0+1       ;save quotient bits 0-7
        rts

Fixed point multiplication by 205/128 with error [-0.4, 1):

        pla                 ;discard argument count
        pla                 ;pull input value bit 8
        lsr                 ;multiplier bit 8 -> C
        pla                 ;pull input value bits 0-7
        sta     fr0
        lda     #0
        rol                 ;multiplier bit 8, set C=0
        ldx     #9          ;9 multiplier bits to process
bitloop:
        ror                 ;shift in result bit, shift out multiplier bit 8
        ror     fr0         ;shift in result bits, shift out next multiplier bit
        bcc     no_bit      ;skip if multiplier bit cleared
        adc     #205-1      ;add 205 if multiplier bit set
no_bit:
        dex                 ;next bit
        bne     bitloop     ;repeat until 9 bits processed
        rol     fr0         ;result bit 0 -> C
        rol                 ;A = result bits 0-7
        sta     fr0
        lda     #0
        rol                 ;A = result bit 8
        sta     fr0+1
        rts
  • Like 9
Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...