Esempio n. 1
0
/*
 * DANG_BEGIN_FUNCTION raw_keyboard_init
 * 
 * Initialize the keyboard for RAW mode.
 * 
 * DANG_END_FUNCTION
 */
static int raw_keyboard_init(void)
{
  k_printf("KBD(raw): raw_keyboard_init()\n");
   
  kbd_fd = STDIN_FILENO;

  ioctl(kbd_fd, KDGKBMODE, (int)&save_mode);

  if (tcgetattr(kbd_fd, &save_termios) < 0) {
    error("KBD(raw): Couldn't tcgetattr(kbd_fd,...) !\n");
    memset(&save_termios, 0, sizeof(save_termios));
    return FALSE;
  }

  save_kbd_flags = fcntl(kbd_fd, F_GETFL);
  fcntl(kbd_fd, F_SETFL, O_RDONLY | O_NONBLOCK);

  set_raw_mode();

  if (!isatty(kbd_fd)) {
    k_printf("KBD(raw): Using SIGIO\n");
    add_to_io_select(kbd_fd, 1, keyb_client_run);
  }
  else {
    k_printf("KBD(raw): Not using SIGIO\n");
    add_to_io_select(kbd_fd, 0, keyb_client_run);
  }
   
  return TRUE;
}
Esempio n. 2
0
static int midotmdty_init(void)
{
    const char *cmd1 = "OPEN %s\n";
    char buf[255];
    char *pbuf;
    int n, i, data_port;

    if (!midotmdty_detect())
	return FALSE;

    i = 1;
    if (*(char *) &i == 1)
	sprintf(buf, cmd1, "lsb");
    else
	sprintf(buf, cmd1, "msb");
    S_printf("\t%s", buf);
    write(ctrl_sock_out, buf, strlen(buf));
    n = read(ctrl_sock_in, buf, sizeof(buf) - 1);
    buf[n] = 0;
    S_printf("\tOpen: %s\n", buf);
    pbuf = strstr(buf, " is ready");
    if (!pbuf)
	return FALSE;
    *pbuf = 0;
    pbuf = strrchr(buf, ' ');
    if (!pbuf)
	return FALSE;
    data_port = atoi(pbuf + 1);
    if (!data_port) {
	error("Can't determine the data port number!\n");
	close(data_sock);
	close(ctrl_sock_out);
	return FALSE;
    }
    S_printf("\tUsing port %d for data\n", data_port);
    i = 1;
    setsockopt(data_sock, SOL_TCP, TCP_NODELAY, &i, sizeof(i));
    data_adr.sin_port = htons(data_port);
    if (connect(data_sock, (struct sockaddr *) &data_adr, sizeof(data_adr))
	!= 0) {
	error("Can't open data connection!\n");
	close(data_sock);
	close(ctrl_sock_out);
	return FALSE;
    }
    n = read(ctrl_sock_in, buf, sizeof(buf) - 1);
    buf[n] = 0;
    S_printf("\tConnect: %s\n", buf);

    if (TMDTY_CAPT) {
	add_to_io_select(data_sock, 1, midotmdty_io);
	pcm_stream = pcm_allocate_stream(2, "MIDI");
    }

    return TRUE;
}
Esempio n. 3
0
static void mhp_init(void)
{
  int retval;

  mhpdbg.fdin = mhpdbg.fdout = -1;
  mhpdbg.active = 0;
  mhpdbg.sendptr = 0;

  memset(&mhpdbg.intxxtab, 0, sizeof(mhpdbg.intxxtab));
  memset(&mhpdbgc.intxxalt, 0, sizeof(mhpdbgc.intxxalt));

  retval = asprintf(&pipename_in, "%s/dosemu.dbgin.%d", RUNDIR, getpid());
  assert(retval != -1);

  retval = asprintf(&pipename_out, "%s/dosemu.dbgout.%d", RUNDIR, getpid());
  assert(retval != -1);

  retval = mkfifo(pipename_in, S_IFIFO | 0600);
  if (!retval) {
    retval = mkfifo(pipename_out, S_IFIFO | 0600);
    if (!retval) {
      mhpdbg.fdin = open(pipename_in, O_RDONLY | O_NONBLOCK);
      if (mhpdbg.fdin != -1) {
        /* NOTE: need to open read/write else O_NONBLOCK would fail to open */
        mhpdbg.fdout = open(pipename_out, O_RDWR | O_NONBLOCK);
        if (mhpdbg.fdout != -1) {
          add_to_io_select(mhpdbg.fdin, mhp_input_async, NULL);
        }
        else {
          close(mhpdbg.fdin);
          mhpdbg.fdin = -1;
        }
      }
    }
  }
  else {
    fprintf(stderr, "Can't create debugger pipes, dosdebug not available\n");
  }
  if (mhpdbg.fdin == -1) {
    unlink(pipename_in);
    free(pipename_in);
    unlink(pipename_out);
    free(pipename_out);
  }
  else {
    if (dosdebug_flags) {
      /* don't fiddle with select, just poll until the terminal
       * comes up to send the first input
       */
       mhpdbg.nbytes = -1;
       wait_for_debug_terminal = 1;
       mhp_input();
    }
  }
}
Esempio n. 4
0
static int midipipe_init(void *arg)
{
    char *name = DOSEMU_MIDI_IN_PATH;
    pipe_fd = RPT_SYSCALL(open(name, O_RDONLY | O_NONBLOCK));
    if (pipe_fd == -1) {
	S_printf("%s: unable to open %s for reading: %s\n",
		 midipipe_name, name, strerror(errno));
	return 0;
    }
    add_to_io_select(pipe_fd, midipipe_io, NULL);
    return 1;
}
Esempio n. 5
0
/*
 * DANG_BEGIN_FUNCTION raw_keyboard_init
 *
 * Initialize the keyboard for RAW mode.
 *
 * DANG_END_FUNCTION
 */
static int raw_keyboard_init(void)
{
  if (config.console_keyb > KEYB_TTY)
    return FALSE;

  k_printf("KBD(raw): raw_keyboard_init()\n");

  kbd_fd = STDIN_FILENO;

  if (config.console_keyb == KEYB_RAW)
    ioctl(kbd_fd, KDGKBMODE, &save_mode);

  if (tcgetattr(kbd_fd, &save_termios) < 0) {
    error("KBD(raw): Couldn't tcgetattr(kbd_fd,...) !\n");
    memset(&save_termios, 0, sizeof(save_termios));
    return FALSE;
  }

  set_raw_mode();

  add_to_io_select(kbd_fd, do_raw_getkeys, NULL);

  return TRUE;
}
Esempio n. 6
0
static u_char IPXOpenSocket(u_short port, u_short * newPort)
{
  int sock;			/* sock here means Linux socket handle */
  int opt;
  struct sockaddr_ipx ipxs;
  socklen_t len;
  struct sockaddr_ipx ipxs2;

  /* DANG_FIXTHIS - do something with longevity flag */
  n_printf("IPX: open socket %#x\n", ntohs(port));
  if (port != 0 && ipx_find_socket(port) != NULL) {
    n_printf("IPX: socket %x already open.\n", ntohs(port));
    /* someone already has this socket open */
    return (RCODE_SOCKET_ALREADY_OPEN);
  }
  /* DANG_FIXTHIS - kludge to support broken linux IPX stack */
  /* need to convert dynamic socket open into a real socket number */
/*  if (port == 0) {
    n_printf("IPX: using socket %x\n", nextDynamicSocket);
    port = nextDynamicSocket++;
  }
*/
  /* do a socket call, then bind to this port */
  sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
  if (sock == -1) {
    n_printf("IPX: could not open IPX socket: %s.\n", strerror(errno));
    /* I can't think of anything else to return */
    return (RCODE_SOCKET_TABLE_FULL);
  }

  opt = 1;
  /* Permit broadcast output */
  if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST,
		 &opt, sizeof(opt)) == -1) {
    /* I can't think of anything else to return */
    n_printf("IPX: could not set socket option for broadcast: %s.\n", strerror(errno));
    return (RCODE_SOCKET_TABLE_FULL);
  }
  /* allow setting the type field in the IPX header */
  opt = 1;
  if (setsockopt(sock, SOL_IPX, IPX_TYPE, &opt, sizeof(opt)) == -1) {
    /* I can't think of anything else to return */
    n_printf("IPX: could not set socket option for type: %s.\n", strerror(errno));
    return (RCODE_SOCKET_TABLE_FULL);
  }
  ipxs.sipx_family = AF_IPX;
  memcpy(&ipxs.sipx_network, MyAddress, 4);
/*  ipxs.sipx_network = htonl(MyNetwork); */
  memset(ipxs.sipx_node, 0, 6);	/* Please fill in my node name */
  ipxs.sipx_port = port;

  /* now bind to this port */
  if (bind(sock, &ipxs, sizeof(ipxs)) == -1) {
    /* I can't think of anything else to return */
    n_printf("IPX: could not bind socket to address: %s\n", strerror(errno));
    close( sock );
    return (RCODE_SOCKET_TABLE_FULL);
  }

  if( port==0 ) {
    len = sizeof(ipxs2);
    if (getsockname(sock,&ipxs2,&len) < 0) {
      /* I can't think of anything else to return */
      n_printf("IPX: could not get socket name in IPXOpenSocket: %s\n", strerror(errno));
      close( sock );
      return(RCODE_SOCKET_TABLE_FULL);
    } else {
      port = ipxs2.sipx_port;
      n_printf("IPX: opened dynamic socket %04x\n", port);
    }
  }

  /* if we successfully bound to this port, then record it */
  ipx_insert_socket(port, /* PSP */ 0, sock);
  add_to_io_select(sock, ipx_async_callback, NULL);
  n_printf("IPX: successfully opened socket %i, %04x\n", sock, port);
  *newPort = port;
  return (RCODE_SUCCESS);
}