home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Emulatoren / UAE061.LZH / uae-0.6.1 / include / events.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  1.5 KB  |  72 lines

  1.  /*
  2.   * UAE - The Un*x Amiga Emulator
  3.   *
  4.   * Events
  5.   * 
  6.   * (c) 1995 Bernd Schmidt
  7.   */
  8.  
  9. /* This is tunable. 4 gives good results. */
  10. #ifdef LINUX_SOUND_SLOW_MACHINE
  11. #define cycles_per_instruction 8
  12. #else
  13. #define cycles_per_instruction 4
  14. #endif
  15.  
  16. extern unsigned long int cycles, nextevent, nextev_count;
  17. typedef void (*evfunc)(void);
  18.  
  19. struct ev
  20. {
  21.     int active;
  22.     unsigned long int evtime, oldcycles;
  23.     evfunc handler;
  24. };
  25.  
  26. enum { 
  27.     ev_hsync, ev_copper, ev_cia,
  28.     ev_blitter, ev_diskblk, ev_diskindex,
  29.     ev_max
  30. };
  31.  
  32. extern struct ev eventtab[ev_max];
  33.  
  34. static __inline__ void events_schedule(void)
  35. {
  36.     int i;
  37.     
  38.     unsigned long int mintime = ~0L;
  39.     nextevent = cycles + mintime;
  40.     for(i = 0; i < ev_max; i++) {
  41.     unsigned long int eventtime = eventtab[i].evtime + eventtab[i].oldcycles - cycles;
  42.     if (eventtab[i].active && eventtime < mintime) {        
  43.         mintime = eventtime;
  44.         nextevent = cycles + mintime;
  45.     }
  46.     }
  47.     nextev_count = nextevent - cycles;
  48. }
  49.  
  50. static __inline__ void do_cycles(void)
  51. {
  52.     if (nextev_count <= cycles_per_instruction) {
  53.     int j;
  54.     for(j = 0; j < cycles_per_instruction; j++) {
  55.         if (++cycles == nextevent) {
  56.         unsigned long int old_nextevent = nextevent;
  57.         int i;
  58.         
  59.         for(i = 0; i < ev_max; i++) {
  60.             if (eventtab[i].active && (eventtab[i].evtime + eventtab[i].oldcycles) == old_nextevent) {
  61.             (*eventtab[i].handler)();
  62.             }
  63.         }
  64.         events_schedule();
  65.         } else nextev_count--;
  66.     }
  67.     } else {
  68.         nextev_count -= cycles_per_instruction;
  69.     cycles += cycles_per_instruction;
  70.     }
  71. }
  72.