carlsson Posted December 17, 2018 Share Posted December 17, 2018 I'll admit as much as I tried to replace ROR with ROL, BCC with BCS and ADC with SBC but it only became weird... 1 Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted December 17, 2018 Share Posted December 17, 2018 Why not using fastmul? Or did I miss something? 8.8 fixed point maths? Quote Link to comment Share on other sites More sharing options...
phaeron Posted December 18, 2018 Share Posted December 18, 2018 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 9 Quote Link to comment Share on other sites More sharing options...
k-Pack Posted January 7, 2019 Share Posted January 7, 2019 Sorry, I missed the post suggesting floating point routines. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.