108 |
|
Display *x_display = NULL; // X11 display handle |
109 |
|
|
110 |
|
static int zero_fd = -1; // FD of /dev/zero |
111 |
– |
static bool lm_area_mapped = false; // Flag: Low Memory area mmap()ped |
111 |
|
static uint8 last_xpram[256]; // Buffer for monitoring XPRAM changes |
112 |
|
|
113 |
|
#ifdef HAVE_PTHREADS |
148 |
|
static void sigint_handler(...); |
149 |
|
#endif |
150 |
|
|
151 |
+ |
#if REAL_ADDRESSING |
152 |
+ |
static bool lm_area_mapped = false; // Flag: Low Memory area mmap()ped |
153 |
+ |
#endif |
154 |
+ |
|
155 |
|
#ifdef USE_MAPPED_MEMORY |
156 |
|
extern char *address_space, *good_address_map; |
157 |
|
#endif |
687 |
|
static void *xpram_func(void *arg) |
688 |
|
{ |
689 |
|
while (!xpram_thread_cancel) { |
690 |
< |
for (int i=0; i<60 && !xpram_thread_cancel; i++) { |
691 |
< |
#ifdef HAVE_NANOSLEEP |
689 |
< |
struct timespec req = {1, 0}; |
690 |
< |
nanosleep(&req, NULL); |
691 |
< |
#else |
692 |
< |
usleep(1000000); |
693 |
< |
#endif |
694 |
< |
} |
690 |
> |
for (int i=0; i<60 && !xpram_thread_cancel; i++) |
691 |
> |
Delay_usec(1000000); |
692 |
|
xpram_watchdog(); |
693 |
|
} |
694 |
|
return NULL; |
705 |
|
// Pseudo Mac 1Hz interrupt, update local time |
706 |
|
WriteMacInt32(0x20c, TimerDateTime()); |
707 |
|
|
708 |
+ |
SetInterruptFlag(INTFLAG_60HZ); |
709 |
+ |
TriggerInterrupt(); |
710 |
+ |
|
711 |
|
#ifndef HAVE_PTHREADS |
712 |
|
static int second_counter = 0; |
713 |
|
if (++second_counter > 60) { |
740 |
|
#ifdef HAVE_PTHREADS |
741 |
|
static void *tick_func(void *arg) |
742 |
|
{ |
743 |
+ |
uint64 next = GetTicks_usec(); |
744 |
|
while (!tick_thread_cancel) { |
744 |
– |
|
745 |
– |
// Wait |
746 |
– |
#ifdef HAVE_NANOSLEEP |
747 |
– |
struct timespec req = {0, 16625000}; |
748 |
– |
nanosleep(&req, NULL); |
749 |
– |
#else |
750 |
– |
usleep(16625); |
751 |
– |
#endif |
752 |
– |
|
753 |
– |
// Action |
745 |
|
one_tick(); |
746 |
+ |
next += 16625; |
747 |
+ |
int64 delay = next - GetTicks_usec(); |
748 |
+ |
if (delay > 0) |
749 |
+ |
Delay_usec(delay); |
750 |
+ |
else if (delay < -16625) |
751 |
+ |
next = GetTicks_usec(); |
752 |
|
} |
753 |
|
return NULL; |
754 |
|
} |
755 |
|
#endif |
756 |
|
|
757 |
|
|
758 |
+ |
/* |
759 |
+ |
* Get current value of microsecond timer |
760 |
+ |
*/ |
761 |
+ |
|
762 |
+ |
uint64 GetTicks_usec(void) |
763 |
+ |
{ |
764 |
+ |
#ifdef HAVE_CLOCK_GETTIME |
765 |
+ |
struct timespec t; |
766 |
+ |
clock_gettime(CLOCK_REALTIME, &t); |
767 |
+ |
return (uint64)t.tv_sec * 1000000 + t.tv_nsec / 1000; |
768 |
+ |
#else |
769 |
+ |
struct timeval t; |
770 |
+ |
gettimeofday(&t, NULL); |
771 |
+ |
return (uint64)t.tv_sec * 1000000 + t.tv_usec; |
772 |
+ |
#endif |
773 |
+ |
} |
774 |
+ |
|
775 |
+ |
|
776 |
+ |
/* |
777 |
+ |
* Delay by specified number of microseconds (<1 second) |
778 |
+ |
* (adapted from SDL_Delay() source) |
779 |
+ |
*/ |
780 |
+ |
|
781 |
+ |
void Delay_usec(uint32 usec) |
782 |
+ |
{ |
783 |
+ |
int was_error; |
784 |
+ |
#ifndef __linux__ // Non-Linux implementations need to calculate time left |
785 |
+ |
uint64 then, now, elapsed; |
786 |
+ |
#endif |
787 |
+ |
struct timeval tv; |
788 |
+ |
|
789 |
+ |
// Set the timeout interval - Linux only needs to do this once |
790 |
+ |
#ifdef __linux__ |
791 |
+ |
tv.tv_sec = 0; |
792 |
+ |
tv.tv_usec = usec; |
793 |
+ |
#else |
794 |
+ |
then = GetTicks_usec(); |
795 |
+ |
#endif |
796 |
+ |
do { |
797 |
+ |
errno = 0; |
798 |
+ |
#ifndef __linux__ |
799 |
+ |
/* Calculate the time interval left (in case of interrupt) */ |
800 |
+ |
now = GetTicks_usec(); |
801 |
+ |
elapsed = now - then; |
802 |
+ |
then = now; |
803 |
+ |
if (elapsed >= usec) |
804 |
+ |
break; |
805 |
+ |
usec -= elapsed; |
806 |
+ |
tv.tv_sec = 0; |
807 |
+ |
tv.tv_usec = usec; |
808 |
+ |
#endif |
809 |
+ |
was_error = select(0, NULL, NULL, NULL, &tv); |
810 |
+ |
} while (was_error && (errno == EINTR)); |
811 |
+ |
} |
812 |
+ |
|
813 |
+ |
|
814 |
|
#if !EMULATED_68K |
815 |
|
/* |
816 |
|
* Virtual 68k interrupt handler |