Below is a snippet from my thread that scrolls the name of my game across the screen. I had been using TickCount to scroll but the scrolling was jerky and woul'd change speed when moving the mouse cursor. Using ecx as a timer makes the bitmap scroll perfectly. However this got me thinking. Threads get a time slice of the processor and each thread has its own set of registers. So the question is this...Does ecx time down at the processor rate or would it be the processor rate divided by the time slice. This would be good to know if i were to add more threads that also used ecx as a timer.

thanx for any input

Why Tickcount makes it so jerky i don't understand.


mov var1, 0
.while var1 < ebx;<< Bitmap width
invoke BitBlt,hdc,SXPOS,SYPOS,SBMW,SBMH,cdc,var1,0,SRCCOPY

mov ecx, 0200000h

.while ecx > 0 ; time delay
dec ecx

add var1,1

jmp bla
Posted on 2002-05-30 13:53:35 by titan
This won't be a reliable timer.. The time it takes to decrement ecx 200000h times depends on many things, such as processor speed, how much time is given to your thread, etc etc.
If you want an accurate timer use multimedia timers. They are part of the multimedia API (winmm32.lib/inc, search msdn for multimedia timers). I've used it in my latest project for smooth scrolling a text on a small display. It's really smooth but almost doesn't use processor time.

Posted on 2002-05-30 14:08:07 by Thomas
thanx thomas, that will be much better
Posted on 2002-05-30 15:44:50 by titan
the only way to get a perfect scrolling is a timing on the vertical blank of the monitor (VBI). This could be done only via directx and the WaitForVerticalBlank method, but the speed depends also on the vertical refresh rate of the monitor.
I've added a small example scrolltext.
Posted on 2002-05-31 05:19:08 by beaster
Beaster: you are right, directX is the way to go if you need really smooth scrolling but for my purposes it's a bit overkill. It only needs to scroll a small text on a LCD like display which is part of a bigger program.
But I don't know what titan needs it for, might be a better solution.

Posted on 2002-05-31 05:39:48 by Thomas
I'm going to try both methods. Since it is a game i'm working on and i want smooth animation and so forth directX may be the best bet. However i know little about directX.

thanx again
Posted on 2002-05-31 16:01:18 by titan
If you use only the wait function from directx, its quite simple:

I cutted this from my source

;; one init

xor eax, eax
lea ebx, hddMain
push eax
push ebx
push eax
call DirectDrawCreate
cmp eax, DD_OK
jne iscExit

;; loop this:

;; paint something by gdi in memory
;; or
;; paint to directx backbuffer

xor eax, eax
push eax
callother hddMain, IDD_WaitForVerticalBlank

;; blit to screen
;; or
;; flip surfaces
(callother is a macro, I think its called coinvoke in MASM. Look for some COM basics at iczelion, if you are not familar with)
Posted on 2002-06-03 04:08:41 by beaster