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

Forums > C64 Coding > Simple bilinear interpolation in assembler
2018-05-08 16:24

Registered: Apr 2012
Posts: 34
Simple bilinear interpolation in assembler


for some reason, with increasing age, i am no longer interested in spending much time on re-inventing the wheel.

Therefore, i'd like to ask if any of you wizards perhaps know of a close solution to this problem:

Lets say you have a "heatmap" in a matrix of 20x10 cells.

Does anyone perhaps already have a fast and simple routine for interpolating all the values within these cells, so that when you have some cells with very high values and some cells with very low values, that more or less smooth transitions (image blur) can be achieved in very few rasterlines?

Google just spat out hardcore math for me, which i feel unable to wrap my head around, when attempted to translate to a c64 assembler solution. (I code in assembly, directly, no c++ or the like, pretty please).

best regards
... 24 posts hidden. Click here to view all posts....
2018-06-09 00:39

Registered: Apr 2012
Posts: 34


linenums    = #$05
linecount   byte $05 ;(+1)

blur        lda  linenums  ;---
            sta  linecount ;---

            ldx #$00

do_blurX    ldy #$26

x_blurX     lda $0400+1,x
            sta pot

            lda $0400-1,x
            adc pot
            sta pot

            lda $0400,x
            adc pot
            bcc noclip
            lda #$ff
noclip      sta $0400,x


            bne x_blurX

            inx ;---
            inx ;--- these and this mechanism is 
                ;--- just there to provide a visual gap
                ;--- ofcourse the scanning could be seamless 

            dec linecount ;---
            bne do_blurX  ;---



pot         byte $0

needs deeper thought, but it works, horizontally, though.
2018-06-09 11:04

Registered: Mar 2005
Posts: 295
.prg would be good :)
2018-06-09 11:12
Rastah Bar

Registered: Oct 2012
Posts: 162
I can see some optimizations. For example, you can get rid of 2 LSRs by first adding ($0401,x)/2 and ($3ff,x)/2 and dividing the result by 4.

lda $401,x
sta pot
lda $03ff,x
adc pot
sta pot

Also, does it ever clip? ($400,x)/2 <= 128 and ($3ff,x)/8+($401,x)/8 <= 64, so their sum will not exceed 192.

And I would use a ZP address for pot.
2018-06-09 15:38

Registered: Feb 2017
Posts: 12
lda 03ff,x
adc 0401,x
adc 0400,x
sta 0400,x
adc 0402,x
adc 0401,x
sta 0401,x

Ps. Check out my fire effect in Tunnel Vision.
Edit. If unrolled, you can omit ,x indexing.
2018-06-09 16:39

Registered: Apr 2012
Posts: 34
sparta, that looks very sleek. i was afraid that something like that, which i do not fully understand, might work. how did you come up with this solution?
2018-06-09 16:54

Registered: Feb 2017
Posts: 12
Many many years of code optimization. :))

(JK, I am just a hobby coder)

Actually, I used something similar in my fire effect in Tunnel Vision. Except, I did not have enough memory to fully unroll the loop and I also modified the result using a cosine tab. In the fire effect, the 3rd addition comes from the char line below. Something like this:


When you add to 8-bit numbers, the result will be a 9-bit number with 1-8th bits in AR and the 9th bit in C. ROR will divide this 9-bit number by 2, rolling the C in AR. This will also modify C again, however, CLC can be safely omitted in most of the cases, because the difference in your result is <=1, and the next ROR will half that, too.
2018-06-09 16:54

Registered: Apr 2012
Posts: 34

although the rol solution (above) also has this effect of smearing things into one direction, which i am currently trying to suppress so i can do everything in one go, using lookup tables: (having some brightness trouble currently, though)

way less easy than i thought.

(both images show a 4x3 cross and a 3x3 square blurred)

Oh! Thank you for your explanation Sparta! Much appreciated!
2018-06-09 16:59

Registered: Feb 2017
Posts: 12
Double buffering will avoid the skew as you will not overwrite your original values.

Also, keep in mind the above solution is not a true average of the 3 values:

2018-06-09 17:00

Registered: Apr 2012
Posts: 34
And, because i didnt yet say what this is for: it is for a battle tactics ki precalculation. Now i said it.
2018-06-09 17:02

Registered: Apr 2012
Posts: 34
Ah! I had a double buffering version before but for some reason fell back to single frame! Thanks alot for the hint! That should do the trick!
Previous - 1 | 2 | 3 | 4 | 5 - 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
Users Online
Fred/Channel 4
Guests online: 35
Top Demos
1 Uncensored  (9.7)
2 Comaland 100%  (9.7)
3 Unboxed  (9.7)
4 Edge of Disgrace  (9.7)
5 Coma Light 13  (9.6)
6 The Shores of Reflec..  (9.6)
7 Lunatico  (9.6)
8 Wonderland XII  (9.6)
9 Old Men in Used Cars  (9.5)
10 C=Bit 18  (9.5)
Top onefile Demos
1 Arok 20 Invitation  (9.6)
2 Daah, Those Acid Pil..  (9.5)
3 FMX Music Demo  (9.5)
4 Crystal Gazer  (9.5)
5 Pandemoniac Part 2 o..  (9.5)
6 Rewind  (9.5)
7 Dawnfall V1.1  (9.5)
8 Party Horse  (9.4)
9 Dawnfall  (9.4)
10 In Memoriam BHF  (9.4)
Top Groups
1 Oxyron  (9.4)
2 Booze Design  (9.4)
3 Censor Design  (9.4)
4 Finnish Gold  (9.3)
5 The Transfer Team  (9.3)
Top Coders
1 Axis  (9.8)
2 CRT  (9.8)
3 Graham  (9.8)
4 Crossbow  (9.8)
5 Lft  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2018
Page generated in: 0.075 sec.