--- Frodo4/Src/C64_x.h 2003/07/01 17:51:17 1.2 +++ Frodo4/Src/C64_x.h 2010/04/21 21:59:24 1.9 @@ -1,7 +1,7 @@ /* * C64_x.h - Put the pieces together, X specific stuff * - * Frodo (C) 1994-1997,2002-2003 Christian Bauer + * Frodo Copyright (C) Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -95,6 +95,27 @@ int usleep(unsigned long int microSecond } #endif +#ifdef __linux__ +// select() timing is much more accurate under Linux +static void Delay_usec(unsigned long usec) +{ + int was_error; + struct timeval tv; + + tv.tv_sec = 0; + tv.tv_usec = usec; + do { + errno = 0; + was_error = select(0, NULL, NULL, NULL, &tv); + } while (was_error && (errno == EINTR)); +} +#else +static void Delay_usec(unsigned long usec) +{ + usleep(usec); +} +#endif + /* * Constructor, system-dependent things @@ -103,64 +124,18 @@ int usleep(unsigned long int microSecond void C64::c64_ctor1(void) { // Initialize joystick variables - joyfd[0] = joyfd[1] = -1; - joy_minx = joy_miny = 32767; - joy_maxx = joy_maxy = -32768; - - // we need to create a potential GUI subprocess here, because we don't want - // it to inherit file-descriptors (such as for the audio-device and alike..) -#if defined(__svgalib__) - gui = 0; -#else - // try to start up Tk gui. - gui = new CmdPipe("wish", "TkGui.tcl"); - if (gui) { - if (gui->fail) { - delete gui; gui = 0; - } - } - // wait until the GUI process responds (if it does...) - if (gui) { - if (5 != gui->ewrite("ping\n",5)) { - delete gui; gui = 0; - } else { - char c; - fd_set set; - FD_ZERO(&set); - FD_SET(gui->get_read_fd(), &set); - struct timeval tv; - tv.tv_usec = 0; - tv.tv_sec = 5; -// Use the following commented line for HP-UX < 10.20 -// if (select(FD_SETSIZE, (int *)&set, (int *)NULL, (int *)NULL, &tv) <= 0) { - if (select(FD_SETSIZE, &set, NULL, NULL, &tv) <= 0) { - delete gui; gui = 0; - } else { - if (1 != gui->eread(&c, 1)) { - delete gui; gui = 0; - } else { - if (c != 'o') { - delete gui; gui = 0; - } - } - } - } - } -#endif // __svgalib__ + joy_minx[0] = joy_miny[0] = 32767; + joy_maxx[0] = joy_maxy[0] = -32768; + joy_minx[1] = joy_miny[1] = 32767; + joy_maxx[1] = joy_maxy[1] = -32768; } void C64::c64_ctor2(void) { -#ifndef __svgalib__ - if (!gui) { - fprintf(stderr,"Alas, master, no preferences window will be available.\n" - "If you wish to see one, make sure the 'wish' interpreter\n" - "(Tk version >= 4.1) is installed in your path.\n" - "You can still use Frodo, though. Use F10 to quit, \n" - "F11 to cause an NMI and F12 to reset the C64.\n" - "You can change the preferences by editing ~/.frodorc\n"); - } -#endif // SVGAlib + printf("Use F9 to enter the SAM machine language monitor,\n" + "F10 to edit preferences or quit,\n" + "F11 to cause an NMI (RESTORE key) and\n" + "F12 to reset the C64.\n\n"); gettimeofday(&tv_start, NULL); } @@ -246,7 +221,7 @@ void C64::VBlank(bool draw_frame) // Limit speed to 100% if desired if ((speed_index > 100) && ThePrefs.LimitSpeed) { - usleep((unsigned long)(ThePrefs.SkipFrames * 20000 - elapsed_time)); + Delay_usec((unsigned long)(ThePrefs.SkipFrames * 20000 - elapsed_time)); speed_index = 100; } @@ -258,95 +233,11 @@ void C64::VBlank(bool draw_frame) /* - * Open/close joystick drivers given old and new state of - * joystick preferences - */ - -void C64::open_close_joysticks(bool oldjoy1, bool oldjoy2, bool newjoy1, bool newjoy2) -{ -#ifdef HAVE_LINUX_JOYSTICK_H - if (oldjoy1 != newjoy1) { - joy_minx = joy_miny = 32767; // Reset calibration - joy_maxx = joy_maxy = -32768; - if (newjoy1) { - joyfd[0] = open("/dev/js0", O_RDONLY); - if (joyfd[0] < 0) - fprintf(stderr, "Couldn't open joystick 1\n"); - } else { - close(joyfd[0]); - joyfd[0] = -1; - } - } - - if (oldjoy2 != newjoy2) { - joy_minx = joy_miny = 32767; // Reset calibration - joy_maxx = joy_maxy = -32768; - if (newjoy2) { - joyfd[1] = open("/dev/js1", O_RDONLY); - if (joyfd[1] < 0) - fprintf(stderr, "Couldn't open joystick 2\n"); - } else { - close(joyfd[1]); - joyfd[1] = -1; - } - } -#endif -} - - -/* - * Poll joystick port, return CIA mask - */ - -uint8 C64::poll_joystick(int port) -{ -#ifdef HAVE_LINUX_JOYSTICK_H - JS_DATA_TYPE js; - uint8 j = 0xff; - - if (joyfd[port] >= 0) { - if (read(joyfd[port], &js, JS_RETURN) == JS_RETURN) { - if (js.x > joy_maxx) - joy_maxx = js.x; - if (js.x < joy_minx) - joy_minx = js.x; - if (js.y > joy_maxy) - joy_maxy = js.y; - if (js.y < joy_miny) - joy_miny = js.y; - - if (joy_maxx-joy_minx < 100 || joy_maxy-joy_miny < 100) - return 0xff; - - if (js.x < (joy_minx + (joy_maxx-joy_minx)/3)) - j &= 0xfb; // Left - else if (js.x > (joy_minx + 2*(joy_maxx-joy_minx)/3)) - j &= 0xf7; // Right - - if (js.y < (joy_miny + (joy_maxy-joy_miny)/3)) - j &= 0xfe; // Up - else if (js.y > (joy_miny + 2*(joy_maxy-joy_miny)/3)) - j &= 0xfd; // Down - - if (js.buttons & 1) - j &= 0xef; // Button - } - } - return j; -#else - return 0xff; -#endif -} - - -/* * The emulation's main loop */ void C64::thread_func(void) { - int linecnt = 0; - #ifdef FRODO_SC while (!quit_thyself) { @@ -395,44 +286,25 @@ void C64::thread_func(void) // 1541 processor disabled, only emulate 6510 TheCPU->EmulateLine(cycles); #endif - linecnt++; -#if !defined(__svgalib__) - if ((linecnt & 0xfff) == 0 && gui) { - - // check for command from GUI process - // fprintf(stderr,":"); - while (gui->probe()) { - char c; - if (gui->eread(&c, 1) != 1) { - delete gui; - gui = 0; - fprintf(stderr,"Oops, GUI process died...\n"); - } else { - // fprintf(stderr,"%c",c); - switch (c) { - case 'q': - quit_thyself = true; - break; - case 'r': - Reset(); - break; - case 'p':{ - Prefs *np = Frodo::reload_prefs(); - NewPrefs(np); - ThePrefs = *np; - break; - } - default: - break; - } - } - } - } -#endif - } -#if !defined(__svgalib__) - if (gui) { - gui->ewrite("quit\n",5); } -#endif +} + + +/* + * Pause main emulation thread + */ + +void C64::Pause(void) +{ + TheSID->PauseSound(); +} + + +/* + * Resume main emulation thread + */ + +void C64::Resume(void) +{ + TheSID->ResumeSound(); }