Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Fractional Scaling - Math problem
2012-02-05 08:06
TWW

Registered: Jul 2009
Posts: 545
Fractional Scaling - Math problem

Alright.

Say you got the fraction 44/93.

Then you want to scale it to a predetermined denominator of 128 which would give: 61/128 (rounded).

61 is found by calculating 44*128/93.

One multiplication and a division is a bit heavy if you plan to do real-time stuff.

The fastest way I have come up with so far is this:

Set up a 16 bit index table for 1-128 which gives the scaling factor of the denominator (i.e. 1,376 for 128/93). 7 bits for the whole number (1-128) and 9 bits for the decimals giving some accuracy.

Then multiply this with the original numerator to get the scaled numerator.

Still stuck with a small lookup-table (256b) and a 16 by 8 bit multiplication.

Any suggestions on how to do this faster (without spending 16k on a lookuptable)?
 
... 20 posts hidden. Click here to view all posts....
 
2016-03-27 18:05
TWW

Registered: Jul 2009
Posts: 545
So I finally found some tmie to finalize this stuff now when we're all global crisis'ing and all;

I've utilized jackassers extreemely fast multiplier along With the principles discussed above and it came out like this:

    // Calculate Pixel Error - Steep slopes
    // Y = DeltaY
    // X = DeltaX

    lda FractionTableLo,y
    sta !SMC1++1
    sta !SMC3++1
    eor #$ff
    sta !SMC2++1
    sta !SMC4++1
    lda FractionTableHi,y
    sta !SMC5++1
    eor #$ff
    sta !SMC6++1
!SMC1:
    lda Square1Lo,x
    sec
!SMC2:
    sbc Square2Lo,x
!SMC3:
    lda Square1Hi,x
!SMC4:
    sbc Square2Hi,x
    clc
!SMC5:
    adc Square1Lo,x
    sec
!SMC6:
    sbc Square2Lo,x
    // A = Pixel Error


Tables:

    .align $100
    .pc = * "Math Tables"
FractionTableHi:
    .fill 256, >round(65536 / i) + 0.5
FractionTableLo:
    .fill 256, <round(65536 / i) + 0.5
Square1Lo:
    .fill 512, [i*i/4] & $ff
Square1Hi:
    .fill 512, [i*i/4] >> 8
Square2Lo:
    .fill 512, [[[i-255]*[i-255]]/4] & $ff
Square2Hi:
    .fill 512, [[[i-255]*[i-255]]/4] >> 8


I like it even thoug it introduces some degree overhead and eats some memory.

EDIT: i use it for hires, 256 pixels wide.
2016-03-28 08:32
JackAsser

Registered: Jun 2002
Posts: 2014
Four years later?! :D Haha, nice TWW! :D
2016-03-29 18:44
Digger

Registered: Mar 2005
Posts: 437
No laugh JackAsser, I've been working on shit for 6 years and still have those "aha!" moments ;-)
2016-03-29 19:13
TWW

Registered: Jul 2009
Posts: 545
hehe I see clarifications are in order.

If You see Post #7 I solved this ages ago using 8k tables but was Limited to DX/DY max 128.

If You see in my last post it's now for bitmap hires (256 pixels in X) which would add more tables so I figgured I'd try this way now as my line-algo is more mem-intensive.

I am still not sure if this is the best way to solve it though...
Previous - 1 | 2 | 3 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
LordCrass
pcollins/Quantum
Guests online: 82
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Mutetus  (9.7)
3 Jeroen Tel  (9.7)
4 Linus  (9.6)
5 Stinsen  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.065 sec.