Help converting code

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

User avatar
Seb McClouth
Veteran
Posts: 342
Joined: Wed Nov 09, 2005 7:47 am
Location: Inside the Matrix...
Contact:

Help converting code

Postby Seb McClouth » Mon Dec 11, 2006 9:45 am

Hey

I've tried to convert this Code:

Code: Select all

unsigned long loops_per_sec = 1;
228
229 static void calibrate_delay(void)
230 {
231         int ticks;
232
233         printk("Calibrating delay loop.. ");
234         while (loops_per_sec <<= 1) {
235                 ticks = jiffies;
236                 __delay(loops_per_sec);
237                 ticks = jiffies - ticks;
238                 if (ticks >= HZ) {
239                         __asm__("mull %1 ; divl %2"
240                                 :"=a" (loops_per_sec)
241                                 :"d" (HZ),
242                                  "r" (ticks),
243                                  "" (loops_per_sec)
244                                 :"dx");
245                         printk("ok - %lu.%02lu BogoMips\n",
246                                 loops_per_sec/500000,
247                                 (loops_per_sec/5000) % 100);
248                         return;
249                 }
250         }
251         printk("failed\n");
252 }


For as far possible ofcourse since I don't have the ___asm___ thingy. I wrote the following:

Code:

Code: Select all

SUB CalibrateDelay
Do While LoopsPerSec! <> 0 'needs to be! for use with Delay
 LoopsPerSec! = LoopsPerSec! * 2
 ticks = jiffies
 Delay LoopsPerSec!
 ticks = jiffies - ticks
 If LoopsPerSec! >= HZ THEN 'HZ = 100
  Print "Passed."
  EXIT LOOP
 ELSE
  Print "Failed."
  EXIT LOOP
 END IF
LOOP
END SUB

'The Delay Sub I'm using:
SUB Delay (loops!)
 T! = Timer + loops!
 PT! = Timer
 Do: Loop Until Timer >= T! Or Timer < PT!
END SUB



Fairly easy said... it does nothing. Can someone enlight me/help me out?
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.

Return to “QBASIC and QB64 Questions & Answers”

Who is online

Users browsing this forum: No registered users and 8 guests