コード例 #1
0
ファイル: modex.c プロジェクト: Yurand/tw-light
/* xtended_init:
 *  Selects the unchained 640x400 mode.
 */
static BITMAP *xtended_init(int w, int h, int v_w, int v_h, int color_depth)
{
   unsigned long addr;
   BITMAP *b;

   /* Do not continue if this version of Allegro was built in C-only mode.
    * The bank switchers assume asm-mode calling conventions, but the
    * library would try to call them with C calling conventions.
    */
#ifdef ALLEGRO_NO_ASM
   return NULL;
#endif

   /* see modexsms.c */
   _split_modex_screen_ptr = really_split_modex_screen;

   /* check it is a valid resolution */
   if (color_depth != 8) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Xtended mode only supports 8 bit color"));
      return NULL;
   }

   if ((w != 640) || (h != 400) || (v_w > 640) || (v_h > 400)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Xtended mode only supports 640x400"));
      return NULL;
   }

   /* lock everything that is used to draw mouse pointers */
   LOCK_VARIABLE(__modex_vtable); 
   LOCK_FUNCTION(_x_draw_sprite);
   LOCK_FUNCTION(_x_blit_from_memory);
   LOCK_FUNCTION(_x_blit_to_memory);

   /* set VESA mode 0x100 */
   addr = _set_vga_mode(0x100);

   if (!addr) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("VESA mode 0x100 not available"));
      return NULL;
   }

   outportw(0x3C4, 0x0604);         /* disable chain-4 */

   /* we only use 1/4th of the width for the bitmap line pointers */
   b = _make_bitmap(640/4, 400, addr, &gfx_xtended, 8, 640/4);
   if (!b)
      return NULL;

   b->w = b->cr = 640;
   b->vtable = &__modex_vtable;
   b->id |= BMP_ID_PLANAR;

   setup_x_magic(b);

   return b;
}
コード例 #2
0
ファイル: lmseev.c プロジェクト: AntonLanghoff/whitecatlib
/* mouse_init:
 *  Here we open the mouse device, initialise anything that needs it, 
 *  and chain to the framework init routine.
 */
static int mouse_init (void)
{
   char tmp1[128], tmp2[128];
   AL_CONST char *udevice;

   /* Set the current tool */
   current_tool = default_tool;

   /* Find the device filename */
   udevice = get_config_string (uconvert_ascii ("mouse", tmp1),
                                uconvert_ascii ("mouse_device", tmp2),
                                NULL);

   /* Open mouse device.  Devices are cool. */
   if (udevice) {
      TRACE(PREFIX_I "Trying %s device\n", udevice);
      intdrv.device = open_mouse_device (uconvert_toascii (udevice, tmp1));
      if (intdrv.device < 0) {
         uszprintf (allegro_error, ALLEGRO_ERROR_SIZE, get_config_text ("Unable to open %s: %s"),
                    udevice, ustrerror (errno));
         return -1;
      }
   }
   else {
      /* If not specified in the config file, try several /dev/input/event<n>
       * devices. */
      const char *device_name[] = { "/dev/input/event0",
                                    "/dev/input/event1",
                                    "/dev/input/event2",
                                    "/dev/input/event3",
                                    NULL };
      int i;

      TRACE(PREFIX_I "Trying /dev/input/event[0-3] devices\n");

      for (i=0; device_name[i]; i++) {
         intdrv.device = open_mouse_device (device_name[i]);
         if (intdrv.device >= 0) {
	    break;
         }
      }

      if (!device_name[i]) {
	 uszprintf (allegro_error, ALLEGRO_ERROR_SIZE, get_config_text ("Unable to open a mouse device: %s"),
		    ustrerror (errno));
	 return -1;
      }
   }

   intdrv.num_buttons = get_num_buttons(intdrv.device);
   /* Init the tablet data */
   init_tablet(intdrv.device);

   return __al_linux_mouse_init (&intdrv);
}
コード例 #3
0
ファイル: sndio.c プロジェクト: DragonFlyBSD/DPorts
/* used to probe and to configure the device.  don't use sio_start() here. */
static int
open_sndio_device(int input)
{
	hdl = sio_open(NULL, (input ? SIO_REC : SIO_PLAY), 0);
	if (hdl == NULL) {
		uszprintf(allegro_error, ALLEGRO_ERROR_SIZE,
		    get_config_text("sio_opn failed"));
		return -1;
	}

	sio_initpar(&par);
	par.bits = (_sound_bits == 8) ? 8 : 16;
	par.sig = (_sound_bits == 8) ? 0 : 1;
	if (input)
		par.rchan = (_sound_stereo) ? 2 : 1;
	else
		par.pchan = (_sound_stereo) ? 2 : 1;
	par.rate = (_sound_freq > 0) ? _sound_freq : 48000;
	par.le = SIO_LE_NATIVE;
	/* allegro wants small blocks */
	par.round = 512;
	par.appbufsz = par.rate / 10;

	if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) ||
	    (par.bits != 8 && par.bits != 16) ||
	    (par.bits == 8 && par.sig) ||
	    (par.bits == 16 && !par.sig) ||
	    (par.bits == 16 && par.le != SIO_LE_NATIVE) ||
	    (input && (par.rchan != 1 && par.rchan != 2)) ||
	    (!input && (par.pchan != 1 && par.pchan != 2))) {
		ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE,
		    get_config_text("could not set sndio parameters"));
		sio_close(hdl);
		return -1;
	}

	_sound_bits = par.bits;
	_sound_stereo = input ? par.rchan == 2 : par.pchan == 2;
	_sound_freq = par.rate;

	if (input) {
		sndio_rec_round = par.round; 
		sndio_rec_appbufsz = par.appbufsz;
		sndio_rec_bufsize = par.round * par.bps * par.rchan;
	} else {
		sndio_play_round = par.round;
		sndio_play_appbufsz = par.appbufsz;
		sndio_play_bufsize = sndio_play_round * par.bps * par.pchan;
	}
	sndio_signed = par.sig ? 1 : 0;

	return 0;
}
コード例 #4
0
ファイル: alsamidi.c プロジェクト: dodamn/pkg-allegro4.2
/* alsa_rawmidi_init:
 *  Inits the ALSA RawMIDI interface.
 */
static int alsa_rawmidi_init(int input, int voices)
{
   int ret = -1, err;
   char tmp1[128], tmp2[128], temp[256];
#if ALLEGRO_ALSA_VERSION == 9
   snd_rawmidi_info_t *info;
   const char *device = NULL;
#else  /* ALLEGRO_ALSA_VERSION == 5 */
   snd_rawmidi_info_t info;
   int card = -1;
   int device = -1;
#endif

   if (input) {
      ret = -1;
   }
   else {
#if ALLEGRO_ALSA_VERSION == 9
      device = get_config_string(uconvert_ascii("sound", tmp1),
				 uconvert_ascii("alsa_rawmidi_device", tmp2),
				 "default");

      err = snd_rawmidi_open(NULL, &rawmidi_handle, device, 0);
#else  /* ALLEGRO_ALSA_VERSION == 5 */
      card = get_config_int(uconvert_ascii("sound", tmp1),
			    uconvert_ascii("alsa_rawmidi_card", tmp2),
			    snd_defaults_rawmidi_card());

      device = get_config_int(uconvert_ascii("sound", tmp1),
			     uconvert_ascii("alsa_rawmidi_device", tmp2),
			     snd_defaults_rawmidi_device());

      err = snd_rawmidi_open(&rawmidi_handle, card, device, SND_RAWMIDI_OPEN_OUTPUT_APPEND);
#endif
      if (err) {
	 snprintf(temp, sizeof(temp), "Could not open card/rawmidi device: %s", snd_strerror(err));
	 ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(temp));
	 ret = -1;
      }

      ret = 0;
   }

   if (rawmidi_handle) {
#if ALLEGRO_ALSA_VERSION == 9
      snd_rawmidi_nonblock(rawmidi_handle, 0);
      snd_rawmidi_info_malloc(&info);
      snd_rawmidi_info(rawmidi_handle, info);
      _al_sane_strncpy(alsa_rawmidi_desc, snd_rawmidi_info_get_name(info), sizeof(alsa_rawmidi_desc));
#else  /* ALLEGRO_ALSA_VERSION == 5 */
      snd_rawmidi_block_mode(rawmidi_handle, 1);
      snd_rawmidi_info(rawmidi_handle, &info);
      _al_sane_strncpy(alsa_rawmidi_desc, info.name, sizeof(alsa_rawmidi_desc));
#endif
      midi_alsa.desc = alsa_rawmidi_desc;
      alsa_rawmidi_errors = 0;
   }

   return ret;
}
コード例 #5
0
ファイル: sndio.c プロジェクト: DragonFlyBSD/DPorts
/* Stops recording and switches the device back to the original mode. */
static void
sndio_rec_stop(void)
{
	if (hdl != NULL)
		sio_close(hdl);
	hdl = NULL;

	_sound_bits = sndio_save_bits;
	_sound_stereo = sndio_save_stereo;
	_sound_freq = sndio_save_freq;

	if (open_sndio_device(0) != 0)
		return;

	sndio_realpos = sndio_playpos = 0;
	sio_onmove(hdl, movecb, NULL);

	sndio_volume = 127;
	sio_onvol(hdl, volcb, NULL);

	if (!sio_start(hdl)) {
		ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE,
		    get_config_text("Can not start sndio"));
		sio_close(hdl);
		return;
	}

	_unix_bg_man->register_func(sndio_update);
}
コード例 #6
0
ファイル: vtswitch.c プロジェクト: GREYFOXRGR/allegro5
/* __al_linux_init_vtswitch:
 *  Takes control over our console.  It means we'll be notified when user
 *  switches to and from the graphics console.
 */
int __al_linux_init_vtswitch(void)
{
	struct sigaction sa;
	struct vt_mode vtm;

	if (vtswitch_initialised) return 0;  /* shouldn't happen */

	__al_linux_switching_blocked = (switch_mode == SWITCH_NONE) ? 1 : 0;
	console_active = console_should_be_active = 1;

	/* Hook the signals */
	sigemptyset(&sa.sa_mask);
	sigaddset(&sa.sa_mask, SIGIO); /* block async IO during the VT switch */
	sa.sa_flags = 0;
	sa.sa_handler = vt_switch_requested;
	if ((sigaction(SIGRELVT, &sa, NULL) < 0) || (sigaction(SIGACQVT, &sa, NULL) < 0)) {
		ustrzcpy (allegro_error, ALLEGRO_ERROR_SIZE, get_config_text ("Unable to control VT switching"));
		return 1;
	}

	/* Save old mode, take control, and arrange for the signals
	 * to be raised. */
	ioctl(__al_linux_console_fd, VT_GETMODE, &startup_vtmode);
	vtm = startup_vtmode;

	vtm.mode = VT_PROCESS;
	vtm.relsig = SIGRELVT;
	vtm.acqsig = SIGACQVT;

	ioctl(__al_linux_console_fd, VT_SETMODE, &vtm);

	vtswitch_initialised = 1;

	return 0;
}
コード例 #7
0
ファイル: joystick.c プロジェクト: ifilex/SRC
/* clear_joystick_vars:
 *  Resets the joystick state variables to their default values.
 */
static void clear_joystick_vars()
{
   char *unused = get_config_text("unused");
   int i, j, k;

   #define ARRAY_SIZE(a)   ((int)sizeof((a)) / (int)sizeof((a)[0]))

   for (i=0; i<ARRAY_SIZE(joy); i++) {
      joy[i].flags = 0;
      joy[i].num_sticks = 0;
      joy[i].num_buttons = 0;

      for (j=0; j<ARRAY_SIZE(joy[i].stick); j++) {
	 joy[i].stick[j].flags = 0;
	 joy[i].stick[j].num_axis = 0;
	 joy[i].stick[j].name = unused;

	 for (k=0; k<ARRAY_SIZE(joy[i].stick[j].axis); k++) {
	    joy[i].stick[j].axis[k].pos = 0;
	    joy[i].stick[j].axis[k].d1 = FALSE;
	    joy[i].stick[j].axis[k].d2 = FALSE;
	    joy[i].stick[j].axis[k].name = unused;
	 }
      }

      for (j=0; j<ARRAY_SIZE(joy[i].button); j++) {
	 joy[i].button[j].b = FALSE;
	 joy[i].button[j].name = unused;
      }
   }

   num_joysticks = 0;
}
コード例 #8
0
ファイル: allegro.c プロジェクト: Yurand/tw-light
/* _install_allegro_version_check:
 *  Initialises the Allegro library, but return with an error if an
 *  incompatible version is found.
 */
int _install_allegro_version_check(int system_id, int *errno_ptr,
   int (*atexit_ptr)(void (*func)(void)), int version)
{
   int r = _install_allegro(system_id, errno_ptr, atexit_ptr);

   int build_wip = version & 255;
   int build_ver = version & ~255;

   int version_ok;

   if (r != 0) {
      /* failed */
      return r;
   }

#if ALLEGRO_SUB_VERSION & 1
   /* This is a WIP runtime, so enforce strict compatibility. */
   version_ok = version == MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION);
#else
   /* This is a stable runtime, so the runtime should be at least as new
    * as the build headers (otherwise we may get a crash, since some
    * functions may have been used which aren't available in this runtime).
    */
   version_ok = (MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, 0) == build_ver) &&
      (ALLEGRO_WIP_VERSION >= build_wip);
#endif

   if (!version_ok) {
      uszprintf(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(
         "The detected dynamic Allegro library (%d.%d.%d) is "
         "not compatible with this program (%d.%d.%d)."),
         ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION,
         build_ver >> 16, (build_ver >> 8) & 255, build_wip);
      return -1;
   }
コード例 #9
0
ファイル: sndio.c プロジェクト: DragonFlyBSD/DPorts
/*
 *  Re-opens device with read-mode and starts recording (half-duplex).
 *  Returns the DMA buffer size if successful.
 */
static int
sndio_rec_start(int rate, int bits, int stereo)
{
	sndio_save_bits = _sound_bits;
	sndio_save_stereo = _sound_stereo;
	sndio_save_freq = _sound_freq;

	_unix_bg_man->unregister_func(sndio_update);

	if (hdl != NULL)
		sio_close(hdl);
	hdl = NULL;

	_sound_bits = bits;
	_sound_stereo = stereo;
	_sound_freq = rate;

	if (open_sndio_device(1) != 0)
		return 0;

	sndio_volume = 127;
	sio_onvol(hdl, volcb, NULL);

	if (!sio_start(hdl)) {
		ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE,
		    get_config_text("Can not start sndio for recording"));
		sio_close(hdl);
		return 0;
	}

	return sndio_rec_bufsize;
}
コード例 #10
0
ファイル: main.cpp プロジェクト: Aquilon96/ags
const char *set_allegro_error(const char *format, ...)
{
    va_list argptr;
    va_start(argptr, format);
    uvszprintf(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(format), argptr);
    va_end(argptr);
    return allegro_error;
}
コード例 #11
0
ファイル: graphics.c プロジェクト: Skiles/aseprite
/* init_gfx_driver:
 *  Helper function for initializing a graphics driver.
 */
static BITMAP *init_gfx_driver(GFX_DRIVER *drv, int w, int h, int v_w, int v_h)
{
   drv->name = drv->desc = get_config_text(drv->ascii_name);

   /* set gfx_driver so that it is visible when initializing the driver */
   gfx_driver = drv;

   return drv->init(w, h, v_w, v_h, _color_depth);
}
コード例 #12
0
ファイル: bmidiapi.cpp プロジェクト: Yurand/tw-light
/* be_midi_detect:
 *  BeOS MIDI detection.
 */
extern "C" int be_midi_detect(int input)
{
   if (input) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Input is not supported"));
      return FALSE;
   }
   
   return TRUE;
}
コード例 #13
0
ファイル: psound.c プロジェクト: Yurand/tw-light
/* digi_psp_detect:
 *  Returns TRUE if the audio hardware is present.
 */
static int digi_psp_detect(int input)
{
   if (input) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE,
         get_config_text("Input is not supported"));
      return FALSE;
   }

   return TRUE;
}
コード例 #14
0
ファイル: wgdi.c プロジェクト: dodamn/pkg-allegro4.2
/* gfx_gdi_init:
 */
static struct BITMAP *gfx_gdi_init(int w, int h, int v_w, int v_h, int color_depth)
{
   /* virtual screen are not supported */
   if ((v_w!=0 && v_w!=w) || (v_h!=0 && v_h!=h))
      return NULL;
   
   _enter_critical();

   gfx_gdi.w = w;
   gfx_gdi.h = h;

   if (adjust_window(w, h) != 0) {
      _TRACE(PREFIX_E "window size not supported.\n");
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Resolution not supported"));
      goto Error;
   }

   /* the last flag serves as an end of loop delimiter */
   gdi_dirty_lines = _AL_MALLOC_ATOMIC((h+1) * sizeof(char));
   ASSERT(gdi_dirty_lines);
   memset(gdi_dirty_lines, 0, (h+1) * sizeof(char));
   gdi_dirty_lines[h] = 1;

   /* create the screen surface */
   screen_surf = _AL_MALLOC_ATOMIC(w * h * BYTES_PER_PIXEL(color_depth));
   gdi_screen = _make_bitmap(w, h, (unsigned long)screen_surf, &gfx_gdi, color_depth, w * BYTES_PER_PIXEL(color_depth));
   gdi_screen->write_bank = gfx_gdi_write_bank; 
   _screen_vtable.acquire = gfx_gdi_lock;
   _screen_vtable.release = gfx_gdi_unlock;
   _screen_vtable.unwrite_bank = gfx_gdi_unwrite_bank; 

   /* create render timer */
   vsync_event = CreateEvent(NULL, FALSE, FALSE, NULL);
   install_int(render_proc, RENDER_DELAY);

   /* connect to the system driver */
   win_gfx_driver = &win_gfx_driver_gdi;

   /* set the default switching policy */
   set_display_switch_mode(SWITCH_PAUSE);

   /* grab input devices */
   win_grab_input();

   _exit_critical();

   return gdi_screen;

 Error:
   _exit_critical();

   gfx_gdi_exit(NULL);

   return NULL;
}
コード例 #15
0
ファイル: joystick.c プロジェクト: ifilex/SRC
/* install_joystick:
 *  Initialises the joystick module.
 */
int install_joystick(int type)
{
   int c;

   if (_joystick_installed)
      return 0;

   clear_joystick_vars();

   allegro_error[0] = 0;

   /* search table for a specific driver */
   for (c=0; _joystick_driver_list[c].driver; c++) { 
      if (_joystick_driver_list[c].driver_id == type) {
	 joystick_driver = _joystick_driver_list[c].driver;
	 joy_type = type;
	 if (joystick_driver->init() != 0) {
	    if (!allegro_error[0])
	       sprintf(allegro_error, get_config_text("%s not found"), joystick_driver->name);
	    joystick_driver = NULL; 
	    joy_type = JOY_TYPE_NONE;
	    return -1;
	 }
	 break;
      }
   }

   /* autodetect driver */
   if (!joystick_driver) {
      if (!joy_loading) {
	 if (load_joystick_data(NULL) == 0)
	    return 0;
      }

      for (c=0; _joystick_driver_list[c].driver; c++) {
	 if (_joystick_driver_list[c].autodetect) {
	    joystick_driver = _joystick_driver_list[c].driver;
	    joy_type = _joystick_driver_list[c].driver_id;
	    if (_joystick_driver_list[c].driver->init() == 0)
	       break;
	 }
      }
   }

   for (c=0; c<num_joysticks; c++)
      update_calib(c);

   poll_joystick();

   _add_exit_func(remove_joystick);
   _joystick_installed = TRUE;

   return 0;
}
コード例 #16
0
ファイル: graphics.c プロジェクト: Skiles/aseprite
/* _set_gfx_mode_safe:
 *  Special wrapper used when the card parameter of set_gfx_mode()
 *  is GFX_SAFE. In this case the function tries to query the
 *  system driver for a "safe" resolution+driver it knows it will
 *  work, and set it. If the system driver cannot get a "safe"
 *  resolution+driver, it will try the given parameters.
 */
static int _set_gfx_mode_safe(int card, int w, int h, int v_w, int v_h)
{
   char buf[ALLEGRO_ERROR_SIZE], tmp1[64];
   struct GFX_MODE mode;
   int ret, driver;

   ASSERT(card == GFX_SAFE);
   ASSERT(system_driver);
   TRACE(PREFIX_I "Trying to set a safe graphics mode.\n");
   
   if (system_driver->get_gfx_safe_mode) {
      ustrzcpy(buf, sizeof(buf), allegro_error);

      /* retrieve the safe graphics mode */
      system_driver->get_gfx_safe_mode(&driver, &mode);
      TRACE(PREFIX_I "The system driver suggests %dx%dx%d\n",
	    mode.width, mode.height, mode.bpp);

      /* try using the specified resolution but current depth */
      if (_set_gfx_mode(driver, w, h, 0, 0, TRUE) == 0)
         return 0;

      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, buf);

      /* finally use the safe settings */
      set_color_depth(mode.bpp);
      if (_set_gfx_mode(driver, mode.width, mode.height, 0, 0, TRUE) == 0)
         return 0;

      ASSERT(FALSE);  /* the safe graphics mode must always work */
   }
   else {
      TRACE(PREFIX_W "The system driver was unable to get a safe mode, "
	    "I'll try with the specified parameters...\n");
      /* no safe graphics mode, try hard-coded autodetected modes with
       * custom settings */
      _safe_gfx_mode_change = 1;

      ret = _set_gfx_mode(GFX_AUTODETECT, w, h, 0, 0, TRUE);

      _safe_gfx_mode_change = 0;

      if (ret == 0)
         return 0;
   }

   /* failing to set GFX_SAFE is a fatal error */
   TRACE(PREFIX_E "Bad bad, not even GFX_SAFE works?\n");
   _set_gfx_mode(GFX_TEXT, 0, 0, 0, 0, TRUE);
   allegro_message(uconvert_ascii("%s\n", tmp1),
		   get_config_text("Fatal error: unable to set GFX_SAFE"));
   return -1;
}
コード例 #17
0
ファイル: ptimer.c プロジェクト: AntonLanghoff/whitecatlib
/* psp_timer_init:
 *  Installs the PSP timer thread.
 */
static int psp_timer_init(void)
{
   /* Get the PSP ticks per second */
   psp_tick_resolution = sceRtcGetTickResolution();
   
   psp_timer_on = TRUE;

   timer_thread_UID = sceKernelCreateThread("psp_timer_thread",(void *)&psp_timer_thread,
                                             0x18, 0x10000, 0, NULL);
   
   if (timer_thread_UID < 0) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Cannot create timer thread"));
      psp_timer_exit();
      return -1;
   }
   
   if (sceKernelStartThread(timer_thread_UID, 0, NULL) != 0) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Cannot start timer thread"));
      psp_timer_exit();
      return -1;
   }

   return 0;
}
コード例 #18
0
ファイル: alsamidi.c プロジェクト: dodamn/pkg-allegro4.2
/* alsa_rawmidi_detect:
 *  ALSA RawMIDI detection.
 */
static int alsa_rawmidi_detect(int input)
{
#if ALLEGRO_ALSA_VERSION == 9
   const char *device = NULL;
#else  /* ALLEGRO_ALSA_VERSION == 5 */
   int card = -1;
   int device = -1;
#endif
   int ret = FALSE, err;
   char tmp1[128], tmp2[128], temp[256];
   snd_rawmidi_t *handle = NULL;

   if (input) {
      ret = FALSE;
   }
   else {
#if ALLEGRO_ALSA_VERSION == 9
      device = get_config_string(uconvert_ascii("sound", tmp1),
				 uconvert_ascii("alsa_rawmidi_device", tmp2),
				 "default");

      err = snd_rawmidi_open(NULL, &handle, device, 0);
#else  /* ALLEGRO_ALSA_VERSION == 5 */
      card = get_config_int(uconvert_ascii("sound", tmp1),
			    uconvert_ascii("alsa_rawmidi_card", tmp2),
			    snd_defaults_rawmidi_card());

      device = get_config_int(uconvert_ascii("sound", tmp1),
			      uconvert_ascii("alsa_rawmidi_device", tmp2),
			      snd_defaults_rawmidi_device());

      err = snd_rawmidi_open(&handle, card, device, SND_RAWMIDI_OPEN_OUTPUT_APPEND);
#endif
      if (err) {
	 snprintf(temp, sizeof(temp), "Could not open card/rawmidi device: %s", snd_strerror(err));
	 ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(temp));
	 ret = FALSE;
      }
      else {
	 snd_rawmidi_close(handle);
	 ret = TRUE;
      }
   }

   return ret;
}
コード例 #19
0
ファイル: sndio.c プロジェクト: DragonFlyBSD/DPorts
static int
sndio_detect(int input)
{
	if (input) {
		if (digi_driver != digi_input_driver) {
			ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE,
			    get_config_text("sndio output driver must be installed before input can be read"));
			return FALSE;
		}
		return TRUE;
	}

	if (open_sndio_device(0) != 0)
		return FALSE;

	sio_close(hdl);
	return TRUE;
}
コード例 #20
0
ファイル: jack.c プロジェクト: dodamn/pkg-allegro4.2
/* jack_detect:
 *  Detects driver presence.
 */
static int jack_detect(int input)
{ 
   if (input) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(
         "Input is not supported"));
      return FALSE;
   }

   if (!jack_client)
   {
      jack_client_name = get_config_string("sound", "jack_client_name",
	 jack_client_name); 
      jack_client = jack_client_new(jack_client_name);
      if (!jack_client)
	 return FALSE;
   }
   return TRUE;
}
コード例 #21
0
extern "C" void be_sys_message(AL_CONST char *msg)
{
    char  filename[MAXPATHLEN];
    char *title;
    char  tmp[ALLEGRO_MESSAGE_SIZE];
    char  tmp2[ALLEGRO_MESSAGE_SIZE];

    get_executable_name(filename, sizeof(filename));
    title = get_filename(filename);

    BAlert *alert = new BAlert(title,
                               uconvert(msg, U_CURRENT, tmp, U_UTF8, ALLEGRO_MESSAGE_SIZE),
                               uconvert(get_config_text("Ok"), U_CURRENT, tmp2, U_UTF8, ALLEGRO_MESSAGE_SIZE));
    alert->SetShortcut(0, B_ESCAPE);
    be_app->ShowCursor();
    alert->Go();
    be_app->HideCursor();
}
コード例 #22
0
ファイル: alsa9.c プロジェクト: dodamn/pkg-allegro4.2
/* alsa_detect:
 *  Detects driver presence.
 */
static int alsa_detect(int input)
{
   int ret = FALSE;
   char tmp1[128], tmp2[128];

   alsa_device = get_config_string(uconvert_ascii("sound", tmp1),
				   uconvert_ascii("alsa_device", tmp2),
				   alsa_device);

   ret = snd_pcm_open(&pcm_handle, alsa_device, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
   if (ret < 0) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not open card/pcm device"));
      return FALSE;
   }

   snd_pcm_close(pcm_handle);
   pcm_handle = NULL;
   return TRUE;
}
コード例 #23
0
ファイル: lmsegpmd.c プロジェクト: AntonLanghoff/whitecatlib
/* mouse_init:
 *  Here we open the mouse device, initialise anything that needs it, 
 *  and chain to the framework init routine.
 */
static int mouse_init (void)
{
	char tmp1[128], tmp2[128], tmp3[128];
	AL_CONST char *udevice;

	/* Find the device filename */
	udevice = get_config_string (uconvert_ascii ("mouse", tmp1),
				     uconvert_ascii ("mouse_device", tmp2),
				     uconvert_ascii (DEVICE_FILENAME, tmp3));

	/* Open mouse device.  Devices are cool. */
	intdrv.device = open (uconvert_toascii (udevice, tmp1), O_RDONLY | O_NONBLOCK);
	if (intdrv.device < 0) {
		uszprintf (allegro_error, ALLEGRO_ERROR_SIZE, get_config_text ("Unable to open %s: %s"),
			   udevice, ustrerror (errno));
		return -1;
	}

	/* Discard any garbage, so the next thing we read is a packet header */
	sync_mouse (intdrv.device);

	return __al_linux_mouse_init (&intdrv);
}
コード例 #24
0
ファイル: bmidiapi.cpp プロジェクト: Yurand/tw-light
/* be_midi_init:
 *  Initializes the BeOS MIDI driver.
 */
extern "C" int be_midi_init(int input, int voices)
{
   char tmp[256], tmp2[128], tmp3[128] = EMPTY_STRING;
   char *sound = uconvert_ascii("sound", tmp);
   int mode, freq, quality, reverb;
   synth_mode sm = B_BIG_SYNTH;
   interpolation_mode im = B_2_POINT_INTERPOLATION;
   char *reverb_name[] =
      { "no", "closet", "garage", "ballroom", "cavern", "dungeon" };
   
   if (input) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Input is not supported"));
      return -1;
   }
         
   _be_midisynth = new BMidiSynth();
   if (!_be_midisynth) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Not enough memory"));
      return -1;
   }
   
   /* Checks if instruments are available */
   mode = CLAMP(0, get_config_int(sound, uconvert_ascii("be_midi_quality", tmp), 1), 1);
   if (mode)
      sm = B_BIG_SYNTH;
   else
      sm = B_LITTLE_SYNTH;
   if ((be_synth->LoadSynthData(sm) != B_OK) ||
       (!be_synth->IsLoaded())) {
      delete _be_midisynth;
      _be_midisynth = NULL;
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not load MIDI instruments data file"));
      return -1;
   }
   
   /* Sets up synthetizer and loads instruments */
   _be_midisynth->EnableInput(true, true);
   
   /* Prevents other apps from changing instruments on the fly */
   _be_midisynth->FlushInstrumentCache(true);
   
   /* Reverberation is cool */
   reverb = CLAMP(0, get_config_int(sound, uconvert_ascii("be_midi_reverb", tmp), 0), 5);
   if (reverb) {
      be_synth->SetReverb((reverb_mode)reverb);
      be_synth->EnableReverb(true);
   }
   else
      be_synth->EnableReverb(false);
         
   /* Sets sampling rate and sample interpolation method */
   freq = get_config_int(sound, uconvert_ascii("be_midi_freq", tmp), 22050);
   quality = CLAMP(0, get_config_int(sound, uconvert_ascii("be_midi_interpolation", tmp), 1), 2);
   be_synth->SetSamplingRate(freq);
   switch (quality) {
      case 0:
         im = B_DROP_SAMPLE;
         break;
      case 1:
         im = B_2_POINT_INTERPOLATION;
         do_uconvert("fast", U_ASCII, tmp3, U_CURRENT, sizeof(tmp3));
         break;
      case 2:
         im = B_LINEAR_INTERPOLATION;
         do_uconvert("linear", U_ASCII, tmp3, U_CURRENT, sizeof(tmp3));
         break;
   }
   be_synth->SetInterpolation(im);
   
   /* Sets up driver description */
   uszprintf(be_midi_driver_desc, sizeof(be_midi_driver_desc),
             uconvert_ascii("BeOS %s quality synth, %s %d kHz, %s reverberation", tmp),
             uconvert_ascii(mode ? "high" : "low", tmp2), tmp3,
             (be_synth->SamplingRate() / 1000), reverb_name[reverb]);
   midi_beos.desc = be_midi_driver_desc;

   return 0;
}
コード例 #25
0
/* jwin_file_select_ex:
  *  Displays the JWin file selector, with the message as caption.
  *  Allows the user to select a file, and stores the selection in the
  *  path buffer, whose length in bytes is given by size and should have
  *  room for at least 80 characters. The files are filtered according to
  *  the file extensions in ext. Passing NULL includes all files, "PCX;BMP"
  *  includes only files with .PCX or .BMP extensions. Returns zero if it
  *  was closed with the Cancel button or non-zero if it was OK'd.
  */
int jwin_file_select_ex(AL_CONST char *message, char *path, AL_CONST char *ext, int size, int width, int height, FONT *title_font)
{
    static attrb_state_t default_attrb_state[ATTRB_MAX] = DEFAULT_ATTRB_STATE;
    int ret;
    char *p;
    char tmp[32];
    ASSERT(message);
    ASSERT(path);
    
    if(title_font)
    {
        file_selector[0].dp2=title_font;
    }
    
    if(width == OLD_FILESEL_WIDTH)
        width = 304;
        
#ifdef HAVE_DIR_LIST
        
    if(height == OLD_FILESEL_HEIGHT)
        height = 160;
        
#else
        
    if(height == OLD_FILESEL_HEIGHT)
        height = 188;
        
#endif
        
    /* for fs_dlist_proc() */
    ASSERT(size >= 4 * uwidth_max(U_CURRENT));
    
    usetc(updir, 0);
    file_selector[FS_WIN].dp = (char *)message;
    file_selector[FS_EDIT].d1 = size/uwidth_max(U_CURRENT) - 1;
    file_selector[FS_EDIT].dp = path;
    file_selector[FS_OK].dp = (void*)get_config_text("OK");
    file_selector[FS_CANCEL].dp = (void*)get_config_text("Cancel");
    
    /* Set default attributes. */
    memcpy(attrb_state, default_attrb_state, sizeof(default_attrb_state));
    
    /* Parse extension string. */
//  if (ext)// && ugetc(ext))
    {
        parse_extension_string(ext);
    }
    
    if(!ugetc(path))
    {
    
#ifdef HAVE_DIR_LIST
    
        int drive = _al_getdrive();
        
#else
        
        int drive = 0;
#endif
        
        _al_getdcwd(drive, path, size - ucwidth(OTHER_PATH_SEPARATOR));
        fix_filename_case(path);
        fix_filename_slashes(path);
        put_backslash(path);
    }
    
    clear_keybuf();
    
    do
    {
    }
    while(gui_mouse_b());
    
    file_selector[FS_TYPES].proc = fs_dummy_proc;
    enlarge_file_selector(width, height);
    ret = popup_zqdialog(file_selector, FS_EDIT);
    
    if(fext)
    {
        zc_free(fext);
        fext = NULL;
    }
    
    if(fext_p)
    {
        _al_free(fext_p);
        fext_p = NULL;
    }
    
    if((ret == FS_CANCEL) || (ret == FS_WIN) || (!ugetc(get_filename(path))))
        return FALSE;
        
    p = get_extension(path);
    
    if((!ugetc(p)) && (ext) && (!ustrpbrk(ext, uconvert_ascii(" ,;", tmp))))
    {
        size -= ((long)(size_t)p - (long)(size_t)path + ucwidth('.'));
        
        if(size >= uwidth_max(U_CURRENT) + ucwidth(0))          /* do not end with '.' */
        {
            p += usetc(p, '.');
            ustrzcpy(p, size, ext);
        }
    }
    
    return TRUE;
}
コード例 #26
0
ファイル: lconsole.c プロジェクト: AntonLanghoff/whitecatlib
/* init_console:
 *  Initialises this subsystem.
 */
static int init_console(void)
{
   char tmp[256];

   /* Find our tty's VT number */
   __al_linux_vt = get_tty(STDIN_FILENO);

   if (__al_linux_vt < 0) {
      uszprintf (allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Error finding our VT: %s"), ustrerror(errno));
      return 1;
   }

   if (__al_linux_vt != 0) {
      /* Open our current console */
      if ((__al_linux_console_fd = open("/dev/tty", O_RDWR)) < 0) {
	 uszprintf (allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unable to open %s: %s"),
		    uconvert_ascii("/dev/tty", tmp), ustrerror(errno));
	 return 1;
      }
   } else {
      int tty, console_fd, fd, child;
      unsigned short mask;
      char tty_name[16];
      struct vt_stat vts; 

      /* Now we need to find a VT we can use.  It must be readable and
       * writable by us, if we're not setuid root.  VT_OPENQRY itself
       * isn't too useful because it'll only ever come up with one 
       * suggestion, with no guarrantee that we actually have access 
       * to it.
       *
       * At some stage I think this is a candidate for config
       * file overriding, but for now we'll stat the first N consoles
       * to see which ones we can write to (hopefully at least one!),
       * so that we can use that one to do ioctls.  We used to use 
       * /dev/console for that purpose but it looks like it's not 
       * always writable by enough people.
       *
       * Having found and opened a writable device, we query the state
       * of the first sixteen (fifteen really) consoles, and try 
       * opening each unused one in turn.
       */

      if ((console_fd = open ("/dev/console", O_WRONLY)) < 0) {
	 int n;
	 uszprintf (allegro_error, ALLEGRO_ERROR_SIZE, uconvert_ascii("%s /dev/console: %s", tmp),
		    get_config_text("Unable to open"), ustrerror (errno));
	 /* Try some ttys instead... */
	 for (n = 1; n <= 24; n++) {
	     snprintf (tty_name, sizeof(tty_name), "/dev/tty%d", n);
	     tty_name[sizeof(tty_name)-1] = 0;
	     if ((console_fd = open (tty_name, O_WRONLY)) >= 0) break;
	 }
	 if (n > 24) return 1; /* leave the error message about /dev/console */
      }

      /* Get the state of the console -- in particular, the free VT field */
      if (ioctl (console_fd, VT_GETSTATE, &vts)) {
	 uszprintf (allegro_error, ALLEGRO_ERROR_SIZE, uconvert_ascii("VT_GETSTATE: %s", tmp), ustrerror (errno));
	 close (console_fd);
	 return 1;
      }

      __al_linux_prev_vt = vts.v_active;

      /* We attempt to set our euid to 0; if we were run with euid 0 to
       * start with, we'll be able to do this now.  Otherwise, we'll just
       * ignore the error returned since it might not be a problem if the
       * ttys we look at are owned by the user running the program. */
      seteuid(0);

      /* tty0 is not really a console, so start counting at 2. */
      fd = -1;
      for (tty = 1, mask = 2; mask; tty++, mask <<= 1) {
	 if (!(vts.v_state & mask)) {
	    snprintf (tty_name, sizeof(tty_name), "/dev/tty%d", tty);
	    tty_name[sizeof(tty_name)-1] = 0;
	    if ((fd = open (tty_name, O_RDWR)) != -1) {
	       close (fd);
	       break;
	    }
	 }
      }

      seteuid (getuid());

      if (!mask) {
	 ustrzcpy (allegro_error, ALLEGRO_ERROR_SIZE, get_config_text ("Unable to find a usable VT"));
	 close (console_fd);
	 return 1;
      }

      /* OK, now fork into the background, detach from the current console,
       * and attach to the new one. */
      child = fork();

      if (child < 0) {
	 /* fork failed */
	 uszprintf (allegro_error, ALLEGRO_ERROR_SIZE, uconvert_ascii ("fork: %s", tmp), ustrerror (errno));
	 close (console_fd);
	 return 1;
      }

      if (child) {
	 /* We're the parent -- write a note to the user saying where the
	  * app went, then quit */
	 fprintf (stderr, "Allegro application is running on VT %d\n", tty);
	 exit (0);
      }

      /* We're the child.  Detach from our controlling terminal, and start
       * a new session. */
      close (console_fd);
      ioctl (0, TIOCNOTTY, 0);
      setsid();

      /* Open the new one again.  It becomes our ctty, because we started a
       * new session above. */
      seteuid(0);
      fd = open (tty_name, O_RDWR);
      seteuid(getuid());

      if (fd == -1) {
	 ustrzcpy (allegro_error, ALLEGRO_ERROR_SIZE, get_config_text ("Unable to reopen new console"));
	 return 1;
      }

      /* Try to switch to it -- should succeed, since it's our ctty */
      ioctl (fd, VT_ACTIVATE, tty);

      __al_linux_vt = tty;
      __al_linux_console_fd = fd;

      /* Check we can reliably wait until we have the display */
      if (__al_linux_wait_for_display()) {
	 close (fd);
	 ustrzcpy (allegro_error, ALLEGRO_ERROR_SIZE, get_config_text ("VT_WAITACTIVE failure"));
	 return 1;
      }

      /* dup2 it to stdin, stdout and stderr if necessary */
      if (isatty(0)) dup2 (fd, 0);
      if (isatty(1)) dup2 (fd, 1);
      if (isatty(2)) dup2 (fd, 2);
   }

   /* Get termio settings and make a working copy */
   tcgetattr(__al_linux_console_fd, &__al_linux_startup_termio);
   __al_linux_work_termio = __al_linux_startup_termio;

   return 0;
}
コード例 #27
0
ファイル: xdga2.c プロジェクト: AntonLanghoff/whitecatlib
/* _xdga2_gfxdrv_init_drv:
 *  Initializes driver and creates screen bitmap.
 */
static BITMAP *_xdga2_private_gfxdrv_init_drv(GFX_DRIVER *drv, int w, int h, int vw, int vh, int depth, int accel)
{
   int dga_error_base, dga_major_version, dga_minor_version;
   int mode, mask, red_shift = 0, green_shift = 0, blue_shift = 0;
   long input_mask;
   char tmp1[128], tmp2[128];
   BITMAP *bmp;

   /* This is just to test if the system driver has been installed properly */
   if (_xwin.window == None)
      return NULL;

   /* Test that display is local.  */
   if (!_xdga2_private_display_is_local()) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("This driver needs local display"));
      return NULL;
   }

   /* Choose convenient size.  */
   if ((w == 0) && (h == 0)) {
      w = 640;
      h = 480;
   }

   if ((w < 80) || (h < 80) || (w > 4096) || (h > 4096)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported screen size"));
      return NULL;
   }

   if (vw < w)
      vw = w;
   if (vh < h)
      vh = h;

   if (1
#ifdef ALLEGRO_COLOR8
       && (depth != 8)
#endif
#ifdef ALLEGRO_COLOR16
       && (depth != 15)
       && (depth != 16)
#endif
#ifdef ALLEGRO_COLOR24
       && (depth != 24)
#endif
#ifdef ALLEGRO_COLOR32
       && (depth != 32)
#endif
       ) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported color depth"));
      return NULL;
   }

   /* Checks presence of DGA extension */
   if (!XDGAQueryExtension(_xwin.display, &dga_event_base, &dga_error_base) ||
       !XDGAQueryVersion(_xwin.display, &dga_major_version, &dga_minor_version)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("DGA extension is not supported"));
      return NULL;
   }

   /* Works only with DGA 2.0 or newer */
   if (dga_major_version < 2) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("DGA 2.0 or newer is required"));
      return NULL;
   }

   /* Attempts to access the framebuffer */
   if (!XDGAOpenFramebuffer(_xwin.display, _xwin.screen)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not open framebuffer"));
      return NULL;
   }

   /* Finds suitable video mode number */
   mode = _xdga2_find_mode(w, h, vw, vh, depth);
   if (!mode) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Resolution not supported"));
      return NULL;
   }

   /* Sets DGA video mode */
   dga_device = XDGASetMode(_xwin.display, _xwin.screen, mode);
   if (dga_device == NULL) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not switch to DGA mode"));
      return NULL;
   }
   _xwin.in_dga_mode = 2;
   _set_current_refresh_rate(dga_device->mode.verticalRefresh);
   set_display_switch_mode(SWITCH_NONE);

   /* Installs DGA color map */
   if (_dga_cmap) {
      XFreeColormap(_xwin.display, _dga_cmap);
      _dga_cmap = 0;
   }
   if ((dga_device->mode.visualClass == PseudoColor)
       || (dga_device->mode.visualClass == GrayScale)
       || (dga_device->mode.visualClass == DirectColor))
      _dga_cmap = XDGACreateColormap(_xwin.display, _xwin.screen, dga_device, AllocAll);
   else
      _dga_cmap = XDGACreateColormap(_xwin.display, _xwin.screen, dga_device, AllocNone);
   XDGAInstallColormap(_xwin.display, _xwin.screen, _dga_cmap);

   /* Sets up direct color shifts */
   if (depth != 8) {
      for (mask = dga_device->mode.redMask, red_shift = 0; (mask & 1) == 0;
         mask >>= 1, red_shift++);
      for (mask = dga_device->mode.greenMask, green_shift = 0; (mask & 1) == 0;
         mask >>= 1, green_shift++);
      for (mask = dga_device->mode.blueMask, blue_shift = 0; (mask & 1) == 0;
         mask >>= 1, blue_shift++);
   }
   switch (depth) {

      case 15:
         _rgb_r_shift_15 = red_shift;
         _rgb_g_shift_15 = green_shift;
         _rgb_b_shift_15 = blue_shift;
         break;

      case 16:
         _rgb_r_shift_16 = red_shift;
         _rgb_g_shift_16 = green_shift;
         _rgb_b_shift_16 = blue_shift;
         break;

      case 24:
         _rgb_r_shift_24 = red_shift;
         _rgb_g_shift_24 = green_shift;
         _rgb_b_shift_24 = blue_shift;
         break;

      case 32:
         _rgb_r_shift_32 = red_shift;
         _rgb_g_shift_32 = green_shift;
         _rgb_b_shift_32 = blue_shift;
         break;
   }

   /* Enables input */
   XSync(_xwin.display, True);
   input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
              | ButtonReleaseMask | PointerMotionMask;
   XDGASelectInput(_xwin.display, _xwin.screen, input_mask);
   if (_xwin_keyboard_focused) {
      (*_xwin_keyboard_focused)(FALSE, 0);
      keyboard_got_focus = TRUE;
   }
   _mouse_on = TRUE;

   /* Creates screen bitmap */
   drv->linear = TRUE;
   bmp = _make_bitmap(dga_device->mode.imageWidth, dga_device->mode.imageHeight,
         (uintptr_t)dga_device->data, drv, depth,
         dga_device->mode.bytesPerScanline);
   if (!bmp) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Not enough memory"));
      return NULL;
   }
   drv->w = bmp->cr = w;
   drv->h = bmp->cb = h;
   drv->vid_mem = dga_device->mode.imageWidth * dga_device->mode.imageHeight
                * BYTES_PER_PIXEL(depth);

   if (accel) {
      /* Hardware acceleration has been requested */
      
      /* Updates line switcher to accommodate framebuffer synchronization */
#ifdef ALLEGRO_NO_ASM
      bmp->write_bank = _xdga2_write_line;
      bmp->read_bank = _xdga2_write_line;
#else
      bmp->write_bank = _xdga2_write_line_asm;
      bmp->read_bank = _xdga2_write_line_asm;
#endif

      _screen_vtable.acquire = _xdga2_acquire;

      /* Checks for hardware acceleration support */
      if (dga_device->mode.flags & XDGASolidFillRect) {
         /* XDGAFillRectangle is available */
         _orig_hline = _screen_vtable.hline;
         _orig_vline = _screen_vtable.vline;
         _orig_rectfill = _screen_vtable.rectfill;
         _screen_vtable.hline = _xaccel_hline;
         _screen_vtable.vline = _xaccel_vline;
         _screen_vtable.rectfill = _xaccel_rectfill;
         _screen_vtable.clear_to_color = _xaccel_clear_to_color;
         gfx_capabilities |= (GFX_HW_HLINE | GFX_HW_FILL);
      }
      if (dga_device->mode.flags & XDGABlitRect) {
         /* XDGACopyArea is available */
         _screen_vtable.blit_to_self = _xaccel_blit_to_self;
         _screen_vtable.blit_to_self_forward = _xaccel_blit_to_self;
         _screen_vtable.blit_to_self_backward = _xaccel_blit_to_self;
         gfx_capabilities |= GFX_HW_VRAM_BLIT;
      }
      if (dga_device->mode.flags & XDGABlitTransRect) {
         /* XDGACopyTransparentArea is available */
         _orig_draw_sprite = _screen_vtable.draw_sprite;
         _orig_masked_blit = _screen_vtable.masked_blit;
         _screen_vtable.masked_blit = _xaccel_masked_blit;
         _screen_vtable.draw_sprite = _xaccel_draw_sprite;
         if (_screen_vtable.color_depth == 8)
            _screen_vtable.draw_256_sprite = _xaccel_draw_sprite;
         gfx_capabilities |= GFX_HW_VRAM_BLIT_MASKED;
      }

      RESYNC();
   }

   /* Checks for triple buffering */
   if (dga_device->mode.viewportFlags & XDGAFlipRetrace)
      gfx_capabilities |= GFX_CAN_TRIPLE_BUFFER;

   /* Sets up driver description */
   uszprintf(_xdga2_driver_desc, sizeof(_xdga2_driver_desc),
             uconvert_ascii("X-Windows DGA 2.0 graphics%s", tmp1),
             uconvert_ascii(accel ? (gfx_capabilities ? " (accelerated)" : "") : " (software only)", tmp2));
   drv->desc = _xdga2_driver_desc;

   return bmp;
}
コード例 #28
0
ファイル: graphics.c プロジェクト: Skiles/aseprite
/* _set_gfx_mode:
 *  Called by set_gfx_mode(). Separated to make a clear difference between
 *  the virtual GFX_SAFE driver and the rest. The allow_config parameter,
 *  if true, allows the configuration to override the graphics card/driver
 *  when using GFX_AUTODETECT.
 */
static int _set_gfx_mode(int card, int w, int h, int v_w, int v_h, int allow_config)
{
   _DRIVER_INFO *driver_list;
   GFX_DRIVER *drv;
   char tmp1[64], tmp2[64];
   AL_CONST char *dv;
   int flags = 0;
   int c;
   ASSERT(system_driver);
   ASSERT(card != GFX_SAFE);

   /* remember the current console state */
   if (gfx_virgin) {
      TRACE(PREFIX_I "First call, remembering console state.\n");
      LOCK_FUNCTION(_stub_bank_switch);
      LOCK_FUNCTION(blit);

      if (system_driver->save_console_state)
	 system_driver->save_console_state();

      _add_exit_func(shutdown_gfx, "shutdown_gfx");

      gfx_virgin = FALSE;
   }

   timer_simulate_retrace(FALSE);
   _screen_split_position = 0;

   /* close down any existing graphics driver */
   if (gfx_driver) {
      TRACE(PREFIX_I "Closing graphics driver (%p) ", gfx_driver);
      TRACE("%s.\n", gfx_driver->ascii_name);
      if (_al_linker_mouse)
         _al_linker_mouse->show_mouse(NULL);

      while (vram_bitmap_list)
	 destroy_bitmap(vram_bitmap_list->bmp);

      bmp_read_line(screen, 0);
      bmp_write_line(screen, 0);
      bmp_unwrite_line(screen);

      if (gfx_driver->scroll)
	 gfx_driver->scroll(0, 0);

      if (gfx_driver->exit)
	 gfx_driver->exit(screen);

      destroy_bitmap(screen);

      gfx_driver = NULL;
      screen = NULL;
      gfx_capabilities = 0;
   }

   /* We probably don't want to do this because it makes
    * Allegro "forget" the color layout of previously set
    * graphics modes. But it should be retained if bitmaps
    * created in those modes are to be used in the new mode.
    */
#if 0
   /* restore default truecolor pixel format */
   _rgb_r_shift_15 = 0; 
   _rgb_g_shift_15 = 5;
   _rgb_b_shift_15 = 10;
   _rgb_r_shift_16 = 0;
   _rgb_g_shift_16 = 5;
   _rgb_b_shift_16 = 11;
   _rgb_r_shift_24 = 0;
   _rgb_g_shift_24 = 8;
   _rgb_b_shift_24 = 16;
   _rgb_r_shift_32 = 0;
   _rgb_g_shift_32 = 8;
   _rgb_b_shift_32 = 16;
   _rgb_a_shift_32 = 24;
#endif

   gfx_capabilities = 0;

   _set_current_refresh_rate(0);

   /* return to text mode? */
   if (card == GFX_TEXT) {
      TRACE(PREFIX_I "Closing, restoring original console state.\n");
      if (system_driver->restore_console_state)
	 system_driver->restore_console_state();

      if (_gfx_bank) {
	 _AL_FREE(_gfx_bank);
	 _gfx_bank = NULL;
      }

      TRACE(PREFIX_I "Graphic mode closed.\n");
      return 0;
   }

   /* now to the interesting part: let's try to find a graphics driver */
   usetc(allegro_error, 0);

   /* ask the system driver for a list of graphics hardware drivers */
   if (system_driver->gfx_drivers)
      driver_list = system_driver->gfx_drivers();
   else
      driver_list = _gfx_driver_list;

   /* filter specific fullscreen/windowed driver requests */
   if (card == GFX_AUTODETECT_FULLSCREEN) {
      flags |= GFX_DRIVER_FULLSCREEN_FLAG;
      card = GFX_AUTODETECT;
   }
   else if (card == GFX_AUTODETECT_WINDOWED) {
      flags |= GFX_DRIVER_WINDOWED_FLAG;
      card = GFX_AUTODETECT;
   }

   if (card == GFX_AUTODETECT) {
      /* autodetect the driver */
      int found = FALSE;

      tmp1[0] = '\0';

      /* first try the config variables */
      if (allow_config) {
	 /* try the gfx_card variable if GFX_AUTODETECT or GFX_AUTODETECT_FULLSCREEN was selected */
	 if (!(flags & GFX_DRIVER_WINDOWED_FLAG))
	    found = get_config_gfx_driver(uconvert_ascii("gfx_card", tmp1), w, h, v_w, v_h, flags, driver_list);

	 /* try the gfx_cardw variable if GFX_AUTODETECT or GFX_AUTODETECT_WINDOWED was selected */
	 if (!(flags & GFX_DRIVER_FULLSCREEN_FLAG) && !found)
	    found = get_config_gfx_driver(uconvert_ascii("gfx_cardw", tmp1), w, h, v_w, v_h, flags, driver_list);
      }

      /* go through the list of autodetected drivers if none was previously found */
      if (!found) {
	 TRACE(PREFIX_I "Autodetecting graphic driver.\n");
	 for (c=0; driver_list[c].driver; c++) {
	    if (driver_list[c].autodetect) {
	       drv = driver_list[c].driver;

	       if (gfx_driver_is_valid(drv, flags)) {
		  screen = init_gfx_driver(drv, w, h, v_w, v_h);

		  if (screen)
		     break;
	       }
	    }
	 }
      }
      else {
	 TRACE(PREFIX_I "GFX_AUTODETECT overridden through configuration:"
	       " %s.\n", tmp1);
      }
   }
   else {
      /* search the list for the requested driver */
      drv = get_gfx_driver_from_id(card, driver_list);

      if (drv)
	 screen = init_gfx_driver(drv, w, h, v_w, v_h);
   }

   /* gracefully handle failure */
   if (!screen) {
      gfx_driver = NULL;  /* set by init_gfx_driver() */

      if (!ugetc(allegro_error))
	 ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unable to find a suitable graphics driver"));

      TRACE(PREFIX_E "Failed setting graphic driver %d.\n", card);
      return -1;
   }

   /* set the basic capabilities of the driver */
   if ((VIRTUAL_W > SCREEN_W) || (VIRTUAL_H > SCREEN_H)) {
      if (gfx_driver->scroll)
	 gfx_capabilities |= GFX_CAN_SCROLL;

      if ((gfx_driver->request_scroll) || (gfx_driver->request_video_bitmap))
	 gfx_capabilities |= GFX_CAN_TRIPLE_BUFFER;
   }

   /* check whether we are instructed to disable vsync */
   dv = get_config_string(uconvert_ascii("graphics", tmp1),
                          uconvert_ascii("disable_vsync", tmp2),
                          NULL);

   if ((dv) && ((c = ugetc(dv)) != 0) && ((c == 'y') || (c == 'Y') || (c == '1')))
      _wait_for_vsync = FALSE;
   else
      _wait_for_vsync = TRUE;

   TRACE(PREFIX_I "The driver %s wait for vsync.\n",
	 (_wait_for_vsync) ? "will" : "won't");

   /* Give the gfx driver an opportunity to set the drawing mode */
   if ((gfx_driver->drawing_mode) && (!_dispsw_status))
      gfx_driver->drawing_mode();

   clear_bitmap(screen);

   /* set up the default colors */
   for (c=0; c<256; c++)
      _palette_color8[c] = c;

   set_palette(default_palette);

   if (_al_linker_mouse)
      _al_linker_mouse->set_mouse_etc();

   LOCK_DATA(gfx_driver, sizeof(GFX_DRIVER));

   _register_switch_bitmap(screen, NULL);

   TRACE(PREFIX_I "set_gfx_card success for %dx%dx%d.\n",
	 screen->w, screen->h, bitmap_color_depth(screen));
   return 0;
} 
コード例 #29
0
ファイル: jack.c プロジェクト: dodamn/pkg-allegro4.2
/* jack_init:
 *  JACK init routine.
 */
static int jack_init(int input, int voices)
{
   const char **ports;
   char tmp[128];

   if (!jack_detect(input))
      return -1;

   jack_bufsize = get_config_int("sound", "jack_buffer_size",
      jack_bufsize);

   if (jack_bufsize == -1)
      jack_bufsize = jack_get_buffer_size (jack_client);

   /* Those are already read in from the config file by Allegro. */
   jack_16bit = (_sound_bits == 16 ? 1 : 0);
   jack_stereo = (_sound_stereo ? 1 : 0);

   /* Let Allegro mix in its native unsigned format. */
   jack_signed = 0;

   jack_set_process_callback (jack_client, jack_process, NULL);

   output_left = jack_port_register (jack_client, jack_stereo ? "left" : "mono",
      JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);

   if (jack_stereo)
      output_right = jack_port_register (jack_client, "right",
         JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);

   jack_rate = jack_get_sample_rate (jack_client);

   jack_buffer = _AL_MALLOC_ATOMIC(jack_bufsize * (1 + jack_16bit) * (1 + jack_stereo));
   if (!jack_buffer) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(
         "Cannot allocate audio buffer"));
      jack_exit (input);
      return -1;
   }

   digi_jack.voices = voices;

   if (_mixer_init(jack_bufsize *  (1 + jack_stereo), jack_rate,
      jack_stereo, jack_16bit, &digi_jack.voices)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(
         "Cannot init software mixer"));
      jack_exit (input);
      return -1;
   }

   _mix_some_samples((uintptr_t) jack_buffer, 0, jack_signed);

   if (jack_activate (jack_client)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(
         "Cannot activate Jack client"));
      jack_exit (input);
      return 1;
   }

   /* Try to connect the ports. Failure to connect is not critical, since with
    * JACK, users may connect/disconnect ports anytime, without Allegro caring.
    */
   if ((ports = jack_get_ports (jack_client, NULL, NULL,
      JackPortIsPhysical|JackPortIsInput)) == NULL) {
      TRACE (PREFIX_I "Cannot find any physical playback ports");
   }

   if (ports) {
      if (ports[0]) {
	 if (jack_connect (jack_client, jack_port_name (output_left), ports[0]) == 0)
	    TRACE (PREFIX_I "Connected left playback port to %s", ports[0]);
      }
      if (jack_stereo && ports[1]) {
	 if (jack_connect (jack_client, jack_port_name (output_right), ports[1]) == 0)
	    TRACE (PREFIX_I "Connected right playback port to %s", ports[1]);
      }
      _AL_FREE (ports);
   }

   uszprintf(jack_desc, sizeof(jack_desc),
      get_config_text ("Jack, client '%s': %d bits, %s, %d bps, %s"),
      jack_client_name, jack_16bit ? 16 : 8,
      uconvert_ascii((jack_signed ? "signed" : "unsigned"), tmp),
      jack_rate, uconvert_ascii((jack_stereo ? "stereo" : "mono"), tmp));

   return 0;
}
コード例 #30
0
ファイル: sndio.c プロジェクト: DragonFlyBSD/DPorts
static int
sndio_init(int input, int voices)
{
	char tmp1[128], tmp2[128];

	if (input) {
		digi_driver->rec_cap_bits = 16;
		digi_driver->rec_cap_stereo = TRUE;
		return 0;
	}

	if (open_sndio_device(0) != 0)
		return -1;

	sndio_play_bufdata = _AL_MALLOC_ATOMIC(sndio_play_bufsize);
	if (sndio_play_bufdata == 0) {
		ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE,
		    get_config_text("Can not allocate audio buffer"));
		sio_close(hdl);
		return -1;
	}

	sndio_realpos = sndio_playpos = 0;
	sio_onmove(hdl, movecb, NULL);

	sndio_volume = 127;
	sio_onvol(hdl, volcb, NULL);

	if (!sio_start(hdl)) {
		ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE,
		    get_config_text("Can not start sndio"));
		sio_close(hdl);
		return -1;
	}

	digi_sndio.voices = voices;

	/* first arg is total number of samples */
	if (_mixer_init(sndio_play_round * (_sound_stereo ? 2 : 1),
	    _sound_freq, _sound_stereo, ((_sound_bits == 16) ? 1 : 0),
	    &digi_sndio.voices) != 0) {
		ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE,
		    get_config_text("Can not init software mixer"));
		sio_close(hdl);
		return -1;
	}

	_mix_some_samples((uintptr_t) sndio_play_bufdata, 0, sndio_signed);

	/* Add audio interrupt.  */
	_unix_bg_man->register_func(sndio_update);

	uszprintf(sndio_desc, sizeof(sndio_desc),
	    get_config_text("%s: %d bits, %s, %d Hz, %s"),
	    "sndio device",
	    _sound_bits,
	    uconvert_ascii((sndio_signed ? "signed" : "unsigned"), tmp1),
	    _sound_freq,
	    uconvert_ascii((par.pchan == 2 ? "stereo" : "mono"), tmp2));

	digi_driver->desc = sndio_desc;

	return 0;
}