Author Topic: Using ASM to Plot Pixels.  (Read 12135 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Using ASM to Plot Pixels.
« Reply #20 on: March 24, 2007 »
It's an improvement :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Using ASM to Plot Pixels.
« Reply #21 on: March 24, 2007 »
yup :)

meybe if you access the precalced aray with asm.
This is only a wild guess and I have no idea if thats gonna be faster 
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Using ASM to Plot Pixels.
« Reply #22 on: March 25, 2007 »
If I'm thinking correctly then this might be the fastest way

according to my prog this is 3x faster than multiplying every pixel but it's only fast for drawing rectangles only works for rectangles.

Code: [Select]
for i=0 to 6000
    for y=0 to 599
        for x=0 to 799
            scr_buffer(d) = 255'rgb(255, 255, 255)
            d=d+1
        next
        d=y*800
    next
    d=0
next
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Using ASM to Plot Pixels.
« Reply #23 on: March 25, 2007 »
Why do you have two loops?  Why not just loop 800*600 times, then make a pointer to the buffer and get rid of d.  That should be a bit quicker.

Jim
Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Using ASM to Plot Pixels.
« Reply #24 on: March 25, 2007 »
In case i don't want to draw the whole screen, just a bit of it

would it work to do this?

Code: [Select]
for i=0 to 6000
    for y=0 to 800*600-1
            scr_buffer(y) = 255
    next
next
« Last Edit: March 25, 2007 by Paul »
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline MrP

  • Atari ST
  • ***
  • Posts: 176
  • Karma: 18
    • View Profile
Re: Using ASM to Plot Pixels.
« Reply #25 on: March 25, 2007 »
if you want to plot out the whole screen the fastest way I know of is to use asm and blit from the start of the screen to the end, much like you do with the for loop... also if your just plotting something that isn't full screen, asm again is way faster than nesting two for loops, don't know why but this was the case in the tests i did.....

Heres a routine i used to clear the screen to any colour when i first started messing around with asm.... Theres still some things you could do to make this a tad faster but its fast enough.....

Code: [Select]
sub pgl_cls(byval col as integer = rgb(0, 0, 0))
    asm
        mov ebx, [pgl_screen_ptr]
        mov edx, [pgl_screen_length]
        mov ecx, [col]
        lea eax, [ebx + edx]
        rep:
            mov [ebx], ecx
            add ebx, 4
            cmp ebx, eax
        jbe rep
    end asm
end sub

and to blit a full screen image with an alpha value using mmx..... again this was written a while ago so theres probably some optimisations that could be done, also it relies on some variables that are pre-determined at the start of the graphics lib I put together, so its pretty useless as usable code to copy and paste but you get the idea..... Jim helped out a lot with this when I was putting it together.... Cheers again Jim... Also dont be surprised if the comments dont make any sense, its been chopped and changed a bit while i was doing it.....

Code: [Select]
sub pgl_blit_screen(byval src_buffer as integer ptr, byval alpha as ubyte)
    dim p_alpha as integer = alpha shl 16 or alpha shl 8 or alpha
    asm
        mov eax, [src_buffer]     
        mov ebx, [pgl_screen_ptr]   
        mov ecx, [pgl_screen_length] 
        lea ecx, [ebx + ecx]
        add eax, 12
       
        pxor mm6, mm6
        movd mm2, [p_alpha]         'mm2 has alpha value
        punpcklbw mm2, mm6          'unpack it for processing
 
        dloop:
            movd mm0, [eax]         'image pixel col in mm0
            movd mm1, [ebx]         'screen pixel col in mm2
           
            punpcklbw mm0, mm6      'unpack mm0 using blank mm6 register as interleave
            punpcklbw mm1, mm6      'same for screen color
   
            psubw mm0, mm1          'subtract image color from screen color
            pmullw mm0, mm2         'multiply resulting color by alpha
            psrlw mm0, 8            'divide that by 255
            add eax, 4              'increment image position
            paddb mm0, mm1          'and then add screen color back in

            packuswb mm0, mm0       'repack image pixel back to lower 32 bits of mm0
            movd [ebx], mm0         'move result back to screen
       
            add ebx, 4              'increment screen position
       
            cmp ebx, ecx            'check for end of screen
        jbe dloop                   'if were not there wrap!!!!
       
        emms                        'restore floating point stuff, fuck this is expensive..
    end asm
end sub

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Using ASM to Plot Pixels.
« Reply #26 on: March 25, 2007 »
This is probably really good but i don't have the asm skills to try it :(
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won: