Re: [AD] Timer problems on 4.3.10

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Replying to myself here.

On 25/01/2009, you wrote:
>
> I just had a user report a problem that rest() wasn't working and when
> I looked into it, surely enough it was broken.  The odd thing is that
> when I looked at my timer implementation it doesn't make much sense.
>  Fair enough, I remember I wrote that when I was new to Allegro.

Further investigation proved the problem to be twofold.

1) I had somehow mangled my SYSTEM_DRIVER.timer_drivers variable to be NULL,
thus making Allegro think that there was no Amiga timer driver.  Doh.  So
it then tried to emulated timers using clock().

2) This emulated use of clock() was buggy because it assumed that the
clock_t type returned by clock() is 32 bits.  On Amiga OS 4 it is 64 bits.

I've fixed this and a patch is attached.  A simple test of:

textout();
rest(500);
textout();
rest(500);
textout();

Work now, whereas before this patch it instantly draws all of the text
because of 64 -> 32 bit overflows.  Also, you might noticed that I removed
in the patch a strange MIN(..., 2) statement.  What was this?

This fixes the Allegro side of things but it would still be nice if someone
could answer my other question so I can fix my Amiga timer driver.

-- 
/-------------------------------------------------------------------\
[Hitman/Code HQ - 6502/z80/68000/604e/80x86/ARM coder - Amiga rulez!]
[VZ-200/VIC-20/MZ-700/c16/c64*10/c128*8/Plus-4/CPC464/CD32/500*2    ]
[600/1000/1200*2/A4000/SNES/N64/Dreamcast/Athlon 1100/AmigaOne      ]
[Assembly Language: The most fun you can have with your clothes on! ]
\-------------------------------------------------------------------/
Index: src/timer.c
===================================================================
--- src/timer.c	(revision 11144)
+++ src/timer.c	(working copy)
@@ -162,6 +162,8 @@
  */
 void rest_callback(unsigned int time, void (*callback)(void))
 {
+   clock_t target_time;
+
    if (!time) {
       ASSERT(system_driver);
       if (system_driver->yield_timeslice)
@@ -190,10 +192,11 @@
       }
    }
    else {
-      time = clock() + MIN(time * CLOCKS_PER_SEC / 1000, 2);
+      target_time = clock() + ((clock_t) time * CLOCKS_PER_SEC / 1000);
+
       do {
          rest(0);
-      } while (clock() < (clock_t)time);
+      } while (clock() < target_time);
    }
 }
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/