ASM assistance, if you please.

Game development specific discussions.
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

Code: Select all

Const scrnW = 320
Const scrnH = 200

'''Dim As Ubyte RRam(320*200)

'''#include "fast_asm.bas"
#include once "fbgfx.bi"

Dim As Ubyte RRam(320*200)

sub ScrollUp (RRam2() as ubyte)

dim z as integer

dim Memry(320) as ubyte

For z = 0 To 319
  Memry(z) = RRam2(z)   'Point(z, 0)
Next z

asm

        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 320
        mov ESI, EAX
rep        MOVSD

end asm

'for z = 0 to 63679
'  RRam(z) = RRam2(z+320)
'next z

For z = 0 To 319
  RRam2(z+320*199) = Memry(z)
Next z


end sub
sub ScrollDown (RRam2() as ubyte)

dim z as integer

dim Memry(320) as ubyte

For z = 0 To 319
  Memry(z) = RRam2(z + 320*199)   'Point(z, 0)
Next z

asm
        
        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        add EAX, 63676
        mov ESI, EAX
        add EAX, 320
        mov EDI, EAX
        std
rep        MOVSD
        cld
        
end asm

'for z = 63679 to 0 step -1
'  RRam2(z+320) = RRam2(z)
'next z

For z = 0 To 319
  RRam2(z) = Memry(z)
Next z

end sub
sub ScrollLeft (RRam2() as ubyte)

dim clr as ubyte, z as integer

clr = RRam2(0)

asm

        mov ECX, 16000
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 1
        mov ESI, EAX
rep        MOVSD
        mov ECX, 3
rep        MOVSB

end asm
'for z = 1 to 63999
'  RRam2(z-1) = RRam2(z)
'next z

For z = 199 To 1 Step -1
  RRam2(320 * z+319) = RRam2(320 * (z-1) + 319)
Next z

RRam2(319) = clr

end sub
sub ScrollRight (RRam2() as ubyte)

dim clr as ubyte, z as integer

'''clr = RRam2(63999)
clr=RRam2(319)

asm

        mov ECX, 16000
        mov EAX, [RRam2]
        mov EAX, [EAX]
        add EAX, 63993
        mov ESI, EAX
        add EAX, 1
        mov EDI, EAX
        std
rep        MOVSD
        mov ECX, 3
rep        MOVSB
        cld
end asm

'for z = 63998 to 0 step -1
'  RRam2(z+1) = RRam2(z)
'next z

For z = 0 To 198
  RRam2(z*320) = RRam2((z+1) * 320)
Next z

'''RRam2(199 * 320) = clr
RRam2(0) = Clr

end sub

 

Sub saveScreen(RRam2() As Ubyte)
    Dim As Integer v,r,g,b
    Dim As Integer i
    i = 0
    For y As Integer = 0 To scrnH-1
        For x As Integer = 0 To scrnW-1
            v = Point(x,y)
            r = v Shr 16 And 255
            g = v Shr  8 And 255
            b = v And 255
            RRam2(i)= Int(r+g+b)/3
            i = i + 1
        Next x
    Next y
End Sub

Sub displayScreen(RRam2() As Ubyte)
    Dim As Integer i
    i = 0
    For y As Integer = 0 To scrnH-1
        For x As Integer = 0 To scrnW-1
            Pset(x,y),rgb(RRam2(i),RRam2(i),RRam2(i))
            i = i + 1
        Next x
    Next y
End Sub

           

screenres scrnW,scrnH,32

Dim As Integer x,y,c,rad,r,g,b

'fill screen with data
For i As Integer = 0 To 100
    x = Int(Rnd(1)*scrnW)
    y = Int(Rnd(1)*scrnH)
    r = Int(Rnd(1)*256)
    g = Int(Rnd(1)*256)
    b = Int(Rnd(1)*256)
    c = rgb(r,g,b)
    rad = Int(Rnd(1)*20)+5 'radius of circle
    Circle (x,y),rad,c,,,,f
Next i

saveScreen(RRam())
displayScreen(RRam())


Do
    If MULTIKEY(&h4B) Then scrollLeft(RRam())
    If MULTIKEY(&h4D) Then scrollRight(RRam())
    If MULTIKEY(&h48) Then scrollUp(RRam())
    If MULTIKEY(&h50) Then scrollDown(RRam())
    displayScreen(RRam())
    ScreenSync
    sleep 1,1
Loop Until multikey(&H01)

End
 
@Vendan

Ok, turns out that the scroll left & scroll right FB Basic routines were glitchy, fixed that, the ASM routines seem to be working great!

There is some small problem still, I'm trying to figure out where & why, but it put little 3 pixel glyph glitches on the scrolled data here & there at times, not sure why, if you sit there & scroll it in all directions for awhile, they start to appear.



:M

Thanks Vendan for helping with this, I meant to get back to this thread awhile ago to ask BasicCoder2 the same questions.

Please play with the demo program and see if you can figure out why the glitchy glyphs keep appearing.

I'll keep looking at it for another hour tonight.

[edit] seems if i hold right & tap down, the glitches appear alot.
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

Code: Select all

Const scrnW = 320
Const scrnH = 200

'''Dim As Ubyte RRam(320*200)

'''#include "fast_asm.bas"
#include once "fbgfx.bi"

Dim As Ubyte RRam(320*200)

randomize timer

sub ScrollUp (RRam2() as ubyte)

dim z as integer

dim Memry(320) as ubyte

For z = 0 To 319
  Memry(z) = RRam2(z)   'Point(z, 0)
Next z

asm

        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 320
        mov ESI, EAX
rep        MOVSD

end asm

'for z = 0 to 63679
'  RRam(z) = RRam2(z+320)
'next z

For z = 0 To 319
  RRam2(z+320*199) = Memry(z)
Next z


end sub
sub ScrollDown (RRam2() as ubyte)

dim z as integer

dim Memry(320) as ubyte

For z = 0 To 319
  Memry(z) = RRam2(z + 320*199)   'Point(z, 0)
Next z

asm
       
        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        add EAX, 63676
        mov ESI, EAX
        add EAX, 320
        mov EDI, EAX
        std
rep        MOVSD
        cld
       
end asm

'for z = 63679 to 0 step -1
'  RRam2(z+320) = RRam2(z)
'next z

For z = 0 To 319
  RRam2(z) = Memry(z)
Next z

end sub
sub ScrollLeft (RRam2() as ubyte)

dim clr as ubyte, z as integer

clr = RRam2(0)

asm

        mov ECX, 16000
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 1
        mov ESI, EAX
rep        MOVSD
        mov ECX, 3
rep        MOVSB

end asm
'for z = 1 to 63999
'  RRam2(z-1) = RRam2(z)
'next z

For z = 199 To 1 Step -1
  RRam2(320 * z+319) = RRam2(320 * (z-1) + 319)
Next z

RRam2(319) = clr

end sub
sub ScrollRight (RRam2() as ubyte)

dim clr as ubyte, clr2 as ubyte, z as integer

clr = RRam2(63999)
clr2 = RRam2(319)

asm

        mov ECX, 16000
        mov EAX, [RRam2]
        mov EAX, [EAX]
        add EAX, 63996
        mov ESI, EAX
        add EAX, 1
        mov EDI, EAX
        std
rep        MOVSD
        mov ECX, 3
rep        MOVSB
        cld
end asm

'for z = 63998 to 0 step -1
'  RRam2(z+1) = RRam2(z)
'next z

For z = 0 To 198
  RRam2(z*320) = RRam2((z+1) * 320)
Next z

RRam2(199 * 320) = clr

'''RRam2(319) = clr

RRam2(0) = Clr2


end sub

 

Sub saveScreen(RRam2() As Ubyte)
    Dim As Integer v,r,g,b
    Dim As Integer i
    i = 0
    For y As Integer = 0 To scrnH-1
        For x As Integer = 0 To scrnW-1
            v = Point(x,y)
            r = v Shr 16 And 255
            g = v Shr  8 And 255
            b = v And 255
            RRam2(i)= Int(r+g+b)/3
            i = i + 1
        Next x
    Next y
End Sub

Sub displayScreen(RRam2() As Ubyte)
    Dim As Integer i
    i = 0
    For y As Integer = 0 To scrnH-1
        For x As Integer = 0 To scrnW-1
            Pset(x,y),rgb(RRam2(i),RRam2(i),RRam2(i))
            i = i + 1
        Next x
    Next y
End Sub

           

screenres scrnW,scrnH,32

Dim As Integer x,y,c,rad,r,g,b

'fill screen with data
For i As Integer = 0 To 100
    x = Int(Rnd(1)*scrnW)
    y = Int(Rnd(1)*scrnH)
    r = Int(Rnd(1)*256)
    g = Int(Rnd(1)*256)
    b = Int(Rnd(1)*256)
    c = rgb(r,g,b)
    rad = Int(Rnd(1)*20)+5 'radius of circle
    Circle (x,y),rad,c,,,,f
Next i

saveScreen(RRam())
displayScreen(RRam())


Do
    If MULTIKEY(&h4B) Then scrollLeft(RRam())
    If MULTIKEY(&h4D) Then scrollRight(RRam())
    If MULTIKEY(&h48) Then scrollUp(RRam())
    If MULTIKEY(&h50) Then scrollDown(RRam())
    displayScreen(RRam())
    ScreenSync
    sleep 1,1
Loop Until multikey(&H01)

End
 
I tweaked both the ASM and the FB Basic, I think it's fixed!

The SCROLL RIGHT asm, I changed the

add EAX, 63993

to a

add EAX, 63996

I think that fixed it, also my FB Basic code was a bit off, a tiny bit, I think it's finally working perfect.

I'm going to work with the routines some more, and test it in a real environment.



:M
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

Code: Select all

Const scrnW = 320
Const scrnH = 200

'''Dim As Ubyte RRam(320*200)

'''#include "fast_asm.bas"
#include once "fbgfx.bi"

Dim As Ubyte RRam(320*200)

randomize timer

sub ScrollUp (RRam2() as ubyte)

dim z as integer

dim Memry(320) as ubyte

For z = 0 To 319
  Memry(z) = RRam2(z)   'Point(z, 0)
Next z

asm

        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 320
        mov ESI, EAX
rep        MOVSD

end asm

'for z = 0 to 63679
'  RRam(z) = RRam2(z+320)
'next z

For z = 0 To 319
  RRam2(z+320*199) = Memry(z)
Next z


end sub
sub ScrollDown (RRam2() as ubyte)

dim z as integer

dim Memry(320) as ubyte

For z = 0 To 319
  Memry(z) = RRam2(z + 320*199)   'Point(z, 0)
Next z

asm
       
        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        add EAX, 63676
        mov ESI, EAX
        add EAX, 320
        mov EDI, EAX
        std
rep        MOVSD
        cld
       
end asm

'for z = 63679 to 0 step -1
'  RRam2(z+320) = RRam2(z)
'next z

For z = 0 To 319
  RRam2(z) = Memry(z)
Next z

end sub
sub ScrollLeft (RRam2() as ubyte)

dim clr as ubyte, z as integer

clr = RRam2(0)

asm

        mov ECX, 16000
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 1
        mov ESI, EAX
rep        MOVSD
        mov ECX, 3
rep        MOVSB

end asm
'for z = 1 to 63999
'  RRam2(z-1) = RRam2(z)
'next z

For z = 199 To 1 Step -1
  RRam2(320 * z+319) = RRam2(320 * (z-1) + 319)
Next z

RRam2(319) = clr

end sub
sub ScrollRight (RRam2() as ubyte)

dim clr as ubyte, clr2 as ubyte, z as integer

clr = RRam2(63999)
clr2 = RRam2(319)

asm

        mov ECX, 16000
        mov EAX, [RRam2]
        mov EAX, [EAX]
        add EAX, 63996
        mov ESI, EAX
        add EAX, 1
        mov EDI, EAX
        std
rep        MOVSD
        mov ECX, 3
rep        MOVSB
        cld
end asm

'for z = 63998 to 0 step -1
'  RRam2(z+1) = RRam2(z)
'next z

For z = 0 To 198
  RRam2(z*320) = RRam2((z+1) * 320)
Next z

RRam2(199 * 320) = clr

'''RRam2(319) = clr

RRam2(0) = Clr2


end sub

 

Sub saveScreen(RRam2() As Ubyte)
    Dim As Integer v,r,g,b
    Dim As Integer i
    i = 0
    For y As Integer = 0 To scrnH-1
        For x As Integer = 0 To scrnW-1
            v = Point(x,y)
            r = v Shr 16 And 255
            g = v Shr  8 And 255
            b = v And 255
            RRam2(i)= Int(r+g+b)/3
            i = i + 1
        Next x
    Next y
End Sub

Sub displayScreen(RRam2() As Ubyte)
    Dim As Integer i
    i = 0
    For y As Integer = 0 To scrnH-1
        For x As Integer = 0 To scrnW-1
            Pset(x,y),rgb(RRam2(i),RRam2(i),RRam2(i))
            i = i + 1
        Next x
    Next y
End Sub

           

screenres scrnW,scrnH,32

Dim As Integer x,y,c,rad,r,g,b

'fill screen with data
For i As Integer = 0 To 100
    x = Int(Rnd(1)*scrnW)
    y = Int(Rnd(1)*scrnH)
    r = Int(Rnd(1)*256)
    g = Int(Rnd(1)*256)
    b = Int(Rnd(1)*256)
    c = rgb(r,g,b)
    rad = Int(Rnd(1)*20)+5 'radius of circle
    Circle (x,y),rad,c,,,,f
Next i

saveScreen(RRam())
displayScreen(RRam())


Do
    If MULTIKEY(&h4B) Then 
      scrollLeft(RRam())
      scrollLeft(RRam())
    end if
    If MULTIKEY(&h4D) Then 
      scrollRight(RRam())
      scrollRight(RRam())
    end if
    If MULTIKEY(&h48) Then 
      scrollUp(RRam())
      scrollUp(RRam())
    end if
    If MULTIKEY(&h50) Then 
      scrollDown(RRam())
      scrollDown(RRam())
    end if
    displayScreen(RRam())
    ScreenSync
    sleep 1,1
    if rnd(1) < .5 then
      asm
        nop
      end asm
    end if
Loop Until multikey(&H01)

End
 


Slightly different version, not by much, I think I added the NOP and that's it, so it doesn't cache in the CPU, so it remains mostly smooth instead of having hiccups on performance.



:M
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

The procedures have a fair amount of overhead. The execution time for your code that “doesn’t cache in the CPU” is less than negligible compared to all the procedure calls in your main loop, and I basically don’t understand what you are trying to accomplish there.

Code: Select all

''=============================================================================
#include "windows.bi"
#include "counter.bas"
''=============================================================================
'' Counter.bas is available here:
''
'' http://www.freebasic.net/forum/viewtopic.php?t=4221#4221
''=============================================================================

Dim As Ubyte RRam(320*200)

sub ScrollUp0 (RRam2() as ubyte)
    dim z as integer
    dim Memry(320) as ubyte
    For z = 0 To 319
        Memry(z) = RRam2(z)   'Point(z, 0)
    Next z
    asm
        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 320
        mov ESI, EAX
        rep MOVSD
    end asm
    For z = 0 To 319
      RRam2(z+320*199) = Memry(z)
    Next z
end sub

sub ScrollUp1 (RRam2() as ubyte)
    asm
        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 320
        mov ESI, EAX
        rep MOVSD
    end asm
end sub

''=============================================================================

sleep 3000

counter_begin( 1000, HIGH_PRIORITY_CLASS )
counter_end
print counter_cycles

counter_begin( 1000, HIGH_PRIORITY_CLASS )
    scrollUp0(RRam())
counter_end
print counter_cycles

counter_begin( 1000, HIGH_PRIORITY_CLASS )
    scrollUp1(RRam())
counter_end
print counter_cycles

counter_begin( 1000, HIGH_PRIORITY_CLASS )
    if rnd(1) < .5 then
        asm
            nop
        end asm
    end if
counter_end
print counter_cycles

dim as double r

counter_begin( 1000, HIGH_PRIORITY_CLASS )
    r = rnd(1)
counter_end
print counter_cycles

sleep

Code: Select all

0
82516
70917
63
61
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

Code: Select all

dim Memry(320) as ubyte
    For z = 0 To 319
        Memry(z) = RRam2(z)   'Point(z, 0)
    Next z
When you scroll up, the top has to be redrawn on the bottom, or else it disappears.



:M

That's the purpose of that part of the routine, so that all the data remains the same, just in a 64K buffer of memory, it scrolls, and wraps around.

I dunno how you could stuff that part, where it saves the one scan line it loses, into ASM, so it keeps all the data being scrolled.

Code: Select all

Const scrnW = 320
Const scrnH = 200

'''Dim As Ubyte RRam(320*200)

'''#include "fast_asm.bas"
#include once "fbgfx.bi"

Dim As Ubyte RRam(320*200)

randomize timer

sub ScrollUp (RRam2() as ubyte)

dim z as integer

dim Memry(320) as ubyte

For z = 0 To 319
  Memry(z) = RRam2(z)   'Point(z, 0)
Next z

asm

        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 320
        mov ESI, EAX
rep        MOVSD

end asm

'for z = 0 to 63679
'  RRam(z) = RRam2(z+320)
'next z

For z = 0 To 319
  RRam2(z+320*199) = Memry(z)
Next z


end sub
sub ScrollDown (RRam2() as ubyte)

dim z as integer

dim Memry(320) as ubyte

For z = 0 To 319
  Memry(z) = RRam2(z + 320*199)   'Point(z, 0)
Next z

asm
       
        mov ECX, 15920
        mov EAX, [RRam2]
        mov EAX, [EAX]
        add EAX, 63676
        mov ESI, EAX
        add EAX, 320
        mov EDI, EAX
        std
rep        MOVSD
        cld
       
end asm

'for z = 63679 to 0 step -1
'  RRam2(z+320) = RRam2(z)
'next z

For z = 0 To 319
  RRam2(z) = Memry(z)
Next z

end sub
sub ScrollLeft (RRam2() as ubyte)

dim clr as ubyte, z as integer

clr = RRam2(0)

asm

        mov ECX, 16000
        mov EAX, [RRam2]
        mov EAX, [EAX]
        mov EDI, EAX
        add EAX, 1
        mov ESI, EAX
rep        MOVSD
        mov ECX, 3
rep        MOVSB

end asm
'for z = 1 to 63999
'  RRam2(z-1) = RRam2(z)
'next z

For z = 199 To 1 Step -1
  RRam2(320 * z+319) = RRam2(320 * (z-1) + 319)
Next z

RRam2(319) = clr

end sub
sub ScrollRight (RRam2() as ubyte)

dim clr as ubyte, clr2 as ubyte, z as integer

clr = RRam2(63999)
clr2 = RRam2(319)

asm

        mov ECX, 16000
        mov EAX, [RRam2]
        mov EAX, [EAX]
        add EAX, 63996
        mov ESI, EAX
        add EAX, 1
        mov EDI, EAX
        std
rep        MOVSD
        mov ECX, 3
rep        MOVSB
        cld
end asm

'for z = 63998 to 0 step -1
'  RRam2(z+1) = RRam2(z)
'next z

For z = 0 To 198
  RRam2(z*320) = RRam2((z+1) * 320)
Next z

RRam2(199 * 320) = clr

'''RRam2(319) = clr

RRam2(0) = Clr2


end sub

 

Sub saveScreen(RRam2() As Ubyte)
    Dim As Integer v,r,g,b
    Dim As Integer i
    i = 0
    For y As Integer = 0 To scrnH-1
        For x As Integer = 0 To scrnW-1
            v = Point(x,y)
            r = v Shr 16 And 255
            g = v Shr  8 And 255
            b = v And 255
            RRam2(i)= Int(r+g+b)/3
            i = i + 1
        Next x
    Next y
End Sub

Sub displayScreen(RRam2() As Ubyte)
    Dim As Integer i
    i = 0
    For y As Integer = 0 To scrnH-1
        For x As Integer = 0 To scrnW-1
            Pset(x,y),rgb(RRam2(i),RRam2(i),RRam2(i))
            i = i + 1
        Next x
    Next y
End Sub

           

screenres scrnW,scrnH,32

Dim As Integer x,y,c,rad,r,g,b

'fill screen with data
For i As Integer = 0 To 100
    x = Int(Rnd(1)*scrnW)
    y = Int(Rnd(1)*scrnH)
    r = Int(Rnd(1)*256)
    g = Int(Rnd(1)*256)
    b = Int(Rnd(1)*256)
    c = rgb(r,g,b)
    rad = Int(Rnd(1)*20)+5 'radius of circle
    Circle (x,y),rad,c,,,,f
Next i

saveScreen(RRam())
displayScreen(RRam())


Do
    If MULTIKEY(&h4B) Then 
      'scrollLeft(RRam())
      scrollLeft(RRam())
    end if
    If MULTIKEY(&h4D) Then 
      'scrollRight(RRam())
      scrollRight(RRam())
    end if
    If MULTIKEY(&h48) Then 
      'scrollUp(RRam())
      scrollUp(RRam())
    end if
    If MULTIKEY(&h50) Then 
      'scrollDown(RRam())
      scrollDown(RRam())
    end if
    displayScreen(RRam())
    ScreenSync
    sleep 1,1
    if rnd(1) < .5 then
      asm
        nop
        nop
        nop
      end asm
    end if
Loop Until multikey(&H01)

End
 
This works, and I think I eliminated all the errors, and dumb mistakes which I made, if it can be turned into pure ASM, that is the end goal.

There might be a bit of redundant code, I'm not sure, but as far as I can tell, this is the final version, minus any changes which would turn it into pure ASM.
Vendan
Posts: 48
Joined: Sep 18, 2006 0:25

Post by Vendan »

I'm not sure how much more asm can help out.

What I added was a rare case where a person can easily out-optimize a good compiler, but I wouldn't count on that happening often. I'd be a little surprised if it can be optimized terribly much more, as all the other stuff will be asm based on a loop. My code was just so much faster due to usage of the rep movsd/movsb commands which have a 3 clock setup and then 1 clock per copy, which is crazy fast. Any asm not using it for this kind of thing is at an almost ridiculous disadvantage, but it is an edge case that not many compilers can pick up.

To sum it up, don't worry about trying to optimize it further with asm, it has already hit the point of diminishing returns.
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

@Vendan

Yeah, I was only making a case to @MichealW, I'm very glad that you DID optimize what you could, and I GREATLY appreciate it!

I agree, I think that the ASM in the main work loop, then the FB Basic code on the outside edges to put the pieces back in their proper places, I think we nailed it.

I've been hitting the books hard, and I actually needed this routine here VERY shortly, so your intersection in this thread couldn't have come at a more perfect time.

BASICCODER2 You did a marvelous job, I'm going to use everyone's work here, so I can work on incorporating more ASM into my stuff.

I'm already using this now vs SLEEP, ..

Code: Select all

asm
  nop
end asm
Just gotta make it more like MILLIDELAY from QBasic Games and More, where it times itself, and can give a very precise timing, with much more precision, without having to up the CPU timer precision.



:M

Thanks guys for all your help.

I think we can now put [solved] on this thread.

I've tested that last version, that had your code Vendan, with the couple tweaks of my FB Basic code, and one minor numeric change in one of your ASM loops, I think it's flawless now.

I am going to use this to scroll blocks of not just graphical data, but any data that's 64K that I want to move stuff to either the end of the array, or to the beginning.

There's not just a limit of graphics this is good for, but other types of data as well.

Ouch, need to go get my typing wrist braces on now, ouch.
Vendan
Posts: 48
Joined: Sep 18, 2006 0:25

Post by Vendan »

Glad to hear it. Just remember a nop loop is still sucking CPU time, which is generally a no-no. Sleep should yield control to the OS, thus reducing cpu usage. In games, it's generally not a big deal, as you get to be the primary foreground app with little else actively running, but try to play nice where possible.

For instance, if you implement a framerate limiter, make sure it does a sleep.
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

Just remember a nop loop is still sucking CPU time
If this is true, how does a legitimate SLEEP command actually relenquish control of the CPU and allow time slices to march forward??

I'd like to see a SLEEP command disassembled, to see what really happens, cause that statement, that a NOP loop STILL consumes CPU time, is very contradictory, in my mind at least. Confusing, at LEAST.



~Kiyote!
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

You do understand that NOP is an instruction? It has the same encoding as XCHG (E)AX, (E)AX. Per the Intel documentation:

“Performs no operation. This instruction is a one-byte instruction that takes up space in the instruction stream but does not affect the machine context, except the EIP register.”
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

You do understand that NOP is an instruction?
Then how can a SLEEP command, which will be parsed, translated and turned back into another set of ASM altogether, relinquish CPU processor time either?

I really don't get, if you can't NOP, and then give the CPU time to scratch it's bum, how can you SLEEP which is really

001A:MOV BLAH,3
001B:INT &HFF,C
001C:OO KI,&H30

really,

a BUNCH of instructions.

I don't get it.
Is there not a single OPCODE that DOES tell the processor, ok, my timeslice is over, or at least I'm giving up the rest of the time early?




~Kiyote!

CONFUSED
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

Multitasking, time-slicing, etc and are functions of the OS.

http://en.wikipedia.org/wiki/Computer_multitasking
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

MichaelW wrote:Multitasking, time-slicing, etc and are functions of the OS.

http://en.wikipedia.org/wiki/Computer_multitasking
Yeah, I was thinking of having my graphics in the MAIN, and two exactly the same threads, running, and they would sync and if there was any time difference in execution time, slow down or speed up the opposing thread.

A real LEFT BRAIN RIGHT BRAIN in execution.

:M
Post Reply