Пример #1
0
int
dv_init(void)
{
	char *env;

	/* default value */
	develo_lpt = 0x378;
	develo_com = 0;
	develo_wait1 = 200000;
	develo = 0;

#ifdef __linux__
	if (iopl(3)) {
		perror("cannot access I/O ports");
		exit(1);
	}
#endif

	/* get environment variable */
	env = getenv("DEVELOPORT");

	/* ok found */
	develo = 1;

	/* parse string */
	while (env && *env != '\0') {
		/* LPT port address */
		if (strncasecmp(env, "LPT:", 4) == 0) {
			env += 4;
			develo_lpt = get_hex(&env);
		}

		/* COM port address */
		else if (strncasecmp(env, "COM:", 4) == 0) {
			env += 4;
			develo_com = get_hex(&env);
		}

		/* timeout delay 1 */
		else if (strncasecmp(env, "WAIT1:", 6) == 0) {
			env += 6;
			develo_wait1 = get_dec(&env);
		}

		/* timeout delay 2 */
		else if (strncasecmp(env, "WAIT2:", 6) == 0) {
			env += 6;
			develo_wait2 = get_dec(&env);
		}
		else {
			env++;
		}
	}

	/* ok */
	return (DV_OK);
}
Пример #2
0
int interrupt_init(void)
{
	int ret;

	/* call cpu specific function from $(CPU)/interrupts.c */
	ret = interrupt_init_cpu(&decrementer_count);

	if (ret)
		return ret;

	decrementer_count = get_tbclk() / CFG_HZ;
	debug("interrupt init: tbclk() = %d MHz, decrementer_count = %d\n",
	      (get_tbclk() / 1000000),
	      decrementer_count);

	set_dec(decrementer_count);

	set_msr(get_msr() | MSR_EE);

	debug("MSR = 0x%08lx, Decrementer reg = 0x%08lx\n",
	      get_msr(),
	      get_dec());

	return 0;
}
Пример #3
0
static long get_num(const char **s)
{
  if ( (**s) != '$' )
    return get_dec(s);
  (*s)++;
  skip_space(s);
  return get_hex(s);
}
Пример #4
0
void
init_adb_log(void)
{
    adb_log[0].b = ADB_B;
    adb_log[0].ifr = ADB_IFR;
    adb_log[0].acr = ADB_ACR;
    adb_log[0].time = get_dec();
    n_adb_log = 0;
}
Пример #5
0
/*
 * Calibrate the decrementer register using VIA timer 1.
 * This is used both on powermacs and CHRP machines.
 */
__initfunc(int via_calibrate_decr(void))
{
	struct device_node *vias;
	volatile unsigned char *via;
	int count = VIA_TIMER_FREQ_6 / HZ;
	unsigned int dstart, dend;

	vias = find_devices("via-cuda");
	if (vias == 0)
		vias = find_devices("via-pmu");
	if (vias == 0)
		vias = find_devices("via");
	if (vias == 0 || vias->n_addrs == 0)
		return 0;
	via = (volatile unsigned char *)
		ioremap(vias->addrs[0].address, vias->addrs[0].size);

	/* set timer 1 for continuous interrupts */
	out_8(&via[ACR], (via[ACR] & ~T1MODE) | T1MODE_CONT);
	/* set the counter to a small value */
	out_8(&via[T1CH], 2);
	/* set the latch to `count' */
	out_8(&via[T1LL], count);
	out_8(&via[T1LH], count >> 8);
	/* wait until it hits 0 */
	while ((in_8(&via[IFR]) & T1_INT) == 0)
		;
	dstart = get_dec();
	/* clear the interrupt & wait until it hits 0 again */
	in_8(&via[T1CL]);
	while ((in_8(&via[IFR]) & T1_INT) == 0)
		;
	dend = get_dec();

	decrementer_count = (dstart - dend) / 6;
	count_period_num = 60;
	count_period_den = decrementer_count * 6 * HZ / 100000;

	printk(KERN_INFO "via_calibrate_decr: decrementer_count = %u (%u ticks)\n",
	       decrementer_count, dstart - dend);

	return 1;
}
Пример #6
0
void
adb_chklog(void)
{
    struct adb_log *ap = &adb_log[n_adb_log + 1];

    ap->b = ADB_B;
    ap->ifr = ADB_IFR;
    ap->acr = ADB_ACR;
    if (ap->b != ap[-1].b || (ap->ifr & 4) != (ap[-1].ifr & 4)
	|| ap->acr != ap[-1].acr) {
	ap->time = get_dec();
	++n_adb_log;
    }
}
Пример #7
0
static long get_num(const char **s)
{
  if ( (**s) == '$' )
  {
    (*s)++;
    return get_hex(s);
  }
  if ( (**s) == '\'' )
  {
    (*s)++;
    return get_ascii(s);
  }
  
  return get_dec(s);
}
Пример #8
0
void
adbcmds(void)
{
    char cmd;
    unsigned rtcu, rtcl, dec, pdec, x;
    int i, j;
    unsigned char d[64];

    cmd = skipbl();
    switch (cmd) {
    case 't':
	for (;;) {
	    rtcl = get_rtcl();
	    rtcu = get_rtcu();
	    dec = get_dec();
	    printf("rtc u=%u l=%u dec=%x (%d = %d.%.7d)\n",
		   rtcu, rtcl, dec, pdec - dec, (pdec - dec) / 1000000000,
		   ((pdec - dec) % 1000000000) / 100);
	    pdec = dec;
	    if (cmd == 'x')
		break;
	    while (xmon_read(stdin, &cmd, 1) != 1)
		;
	}
	break;
    case 'r':
	init_adb_log();
	while (adb_bitwait(8, 0, 0, 0) == 0)
	    adb_readin();
	break;
    case 'w':
	i = 0;
	while (scanhex(&x))
	    d[i++] = x;
	init_adb_log();
	j = adb_write(d, i);
	printf("sent %d bytes\n", j);
	while (adb_bitwait(8, 0, 0, 0) == 0)
	    adb_readin();
	break;
    case 'l':
	dump_adb_log();
	break;
    }
}
Пример #9
0
s32 SEQ_MIDI_PORT_ClkPortFromNameGet(const char* name)
{
  int port_ix;
  for(port_ix=0; port_ix<NUM_CLK_PORTS; ++port_ix) {
    // terminate port name at first space
    const char *port_name = clk_ports[port_ix].name;
    const char *search_name = name;
    while( *port_name != 0 && *port_name == *search_name ) {
      ++port_name, ++search_name;
      if( *search_name == 0 && (*port_name == ' ' || *port_name == 0) )
	return clk_ports[port_ix].port;
    }
  }
  s32 value = get_dec(name);
  if( value >= 0 && value <= 0xff )
    return value;
  return -1; // port not found
}
Пример #10
0
int sync(int nbr, FILE *inf, char str[], int outp)
{   enum line_type  ty;
    int             nn;

    for(;;)
    {
        ty = find_line(inf, str);

        if(ty == bad_line) return -1;

        if(ty == test_no)
        {
            nn = get_dec(str + 2);

            if(nn >= nbr) return nn;
        }

        if(outp)
            printf("\n  %s", str);
    }
}
Пример #11
0
void ref_test(const char *in_file, const unsigned int it_cnt, enum test_type t_type, AESREF alg)
{   u4byte          i, kl, test_no, cnt, e_cnt;
    u1byte          key[32], pt[16], iv[16], ect[16], act[32];
    char            str[128], tstr[16];
    int             ty;
    IFILE           inf;

    con_string("\nTest file: "); con_string(in_file); con_string("\nStatus: \n");

    if(!(inf = open_ifile(inf, in_file)))   // reference file for test vectors
    {                                       // if file is not present
        con_string("error in running test\n"); return;
    }

    cnt = 0; e_cnt = test_no = 0;

    for(;;)                         // while there are tests
    {
        ty = find_line(inf, str);   // input a line

        if(ty < 0)                  // until end of file

            break;

        switch(ty)      // process line type
        {
          case 0:   kl = get_dec(str + 8); continue;        // key length
          case 1:   test_no = get_dec(str + 2); continue;   // test number
          case 2:   block_in(iv, str + 3); continue;        // init vector
          case 3:   block_in(key, str + 4); continue;       // key
          case 4:   block_in(pt, str + 3);                  // plaintext
                    if(t_type != ecb_md && t_type != cbc_md)
                        continue;
                    break;
          case 5:   block_in(ect, str + 3);                 // ciphertext
                    if(t_type == ecb_md || t_type == cbc_md)
                        continue;
                    break;
        }

        if(serpent_hack)
        
            block_reverse(key, kl / 8);

        alg.set_key(key, kl, both); // set the key

        if(it_cnt > 100)

            OUT_DOTS(test_no);

        if(t_type == ecb_md || t_type == cbc_md)
        {
            block_copy(act, ect, 16);           // encrypted text to low block

            if(t_type == cbc_md)                // CBC Monte Carlo decryption
            {
                block_copy(act + 16, iv, 16);   // IV to high block

                for(i = 0; i < it_cnt; i += 2)  // do decryptions two at a time
                {
                    if(serpent_hack)
                
                        block_reverse(act, 16);

                    alg.decrypt(act, ect);      // decrypt low block

                    if(serpent_hack)
                    {
                        block_reverse(act, 16); block_reverse(ect, 16);

                    }

                    block_xor(act + 16, ect, 16);// xor into high block

                    if(serpent_hack)
                
                        block_reverse(act + 16, 16);

                    alg.decrypt(act + 16, ect); // decrypt high block

                    if(serpent_hack)
                    {               
                        block_reverse(ect, 16); block_reverse(act + 16, 16);
                    }

                    block_xor(act, ect, 16);    // xor into low block
                }
            }
            else    // ECB Monte Carlo decryption 
            {
                if(serpent_hack)

                    block_reverse(act, 16);

                for(i = 0; i < it_cnt; ++i)
        
                    alg.decrypt(act, act);
        
                if(serpent_hack)

                    block_reverse(act, 16);
            }

            if(!block_cmp(pt, act, 16))
            {
                con_string("\n\ndecryption error on test "); 
                put_dec(tstr, test_no); con_string(tstr); e_cnt++;
            }

            if(t_type == ecb_md)    // test encryption if ECB mode
            {
                if(serpent_hack)

                    block_reverse(act, 16);

                for(i = 0; i < it_cnt; ++i)

                    alg.encrypt(act, act); 

                if(serpent_hack)

                    block_reverse(act, 16);

                if(!block_cmp(ect, act, 16))
                {   
                    con_string("\n\nencryption error on test ");
                    put_dec(tstr, test_no); con_string(tstr); e_cnt++;
                }
            }
        }
        else    // if(t_type == ecb_me || t_type == cbc_me || ecb_vk || ecb_vt)
        {
            if(t_type == cbc_me)                        // CBC Monte Carlo encryption
            {
                block_copy(act, iv, 16); 
                block_copy(act + 16, pt, 16);           // copy IV and plaintext

                for(i = 0; i < it_cnt; i += 2)
                {
                    block_xor(act + 16, act, 16);       // xor low block into high block

                    if(serpent_hack)

                        block_reverse(act + 16, 16);

                    alg.encrypt(act + 16, act + 16);    // encrypt high block

                    if(serpent_hack)

                        block_reverse(act + 16, 16);

                    block_xor(act, act + 16, 16);       // xor high block into low block

                    if(serpent_hack)

                        block_reverse(act, 16);

                    alg.encrypt(act, act);              // encrypt low block
        
                    if(serpent_hack)

                        block_reverse(act, 16);
                }
            }
            else    // ECB Monte Carlo encryption
            {
                block_copy(act, pt, 16);

                if(serpent_hack)

                    block_reverse(act, 16);

                for(i = 0; i < it_cnt; ++i)
        
                    alg.encrypt(act, act);

                if(serpent_hack)
                
                    block_reverse(act, 16);
            }

            if(!block_cmp(ect, act, 16))
            {
                    con_string("\n\nencryption error on test ");
                    put_dec(tstr, test_no); con_string(tstr); e_cnt++;
            }
        
            if(t_type != cbc_me)    // if ECB mode test decrytpion
            {
                if(serpent_hack)
                
                    block_reverse(act, 16);

                for(i = 0; i < it_cnt; ++i)

                    alg.decrypt(act, act); 

                if(serpent_hack)
                
                    block_reverse(act, 16);

                if(!block_cmp(pt, act, 16))
                {   
                    con_string("\n\ndecryption error on test ");
                    put_dec(tstr, test_no); con_string(tstr); e_cnt++;
                }
            }
        }
    }

    close_ifile(inf);

    if(e_cnt > 0)   // report any errors
    {
        put_dec(tstr, e_cnt); con_string("\n"); con_string(tstr);
        con_string(" errors during test\n");
    }
    else            // else report all is well

        con_string("\nall tests correct\n");
}
Пример #12
0
/////////////////////////////////////////////////////////////////////////////
//! Parser for a complete line - also used by shell.c for telnet
/////////////////////////////////////////////////////////////////////////////
s32 TERMINAL_ParseLine(char *input, void *_output_function)
{
  void (*out)(char *format, ...) = _output_function;
  char *separators = " \t";
  char *brkt;
  char *parameter;

  if( UIP_TERMINAL_ParseLine(input, _output_function) > 0 )
    return 0; // command parsed by UIP Terminal

  if( KEYBOARD_TerminalParseLine(input, _output_function) > 0 )
    return 0; // command parsed by Keyboard Terminal

  if( MIDIMON_TerminalParseLine(input, _output_function) > 0 )
    return 0; // command parsed

  if( MIDI_ROUTER_TerminalParseLine(input, _output_function) > 0 )
    return 0; // command parsed

#if !defined(MIOS32_FAMILY_EMULATION)
  if( AOUT_TerminalParseLine(input, _output_function) >= 1 )
    return 0; // command parsed
#endif

#ifdef MIOS32_LCD_universal
  if( APP_LCD_TerminalParseLine(input, _output_function) >= 1 )
    return 0; // command parsed
#endif

  if( (parameter = strtok_r(input, separators, &brkt)) ) {
    if( strcmp(parameter, "help") == 0 ) {
      out("Welcome to " MIOS32_LCD_BOOT_MSG_LINE1 "!");
      out("Following commands are available:");
      out("  system:                           print system info");
      out("  memory:                           print memory allocation info\n");
      out("  sdcard:                           print SD Card info\n");
      out("  sdcard_format:                    formats the SD Card (you will be asked for confirmation)\n");
      UIP_TERMINAL_Help(_output_function);
      KEYBOARD_TerminalHelp(_output_function);
      MIDIMON_TerminalHelp(_output_function);
      MIDI_ROUTER_TerminalHelp(_output_function);
      AOUT_TerminalHelp(_output_function);
#ifdef MIOS32_LCD_universal
      APP_LCD_TerminalHelp(_output_function);
#endif
      out("  set dout <pin> <0|1>:             directly sets DOUT (all or 0..%d) to given level (1 or 0)", MIOS32_SRIO_NUM_SR*8 - 1);
      out("  show douts:                       prints the current DOUT patterns");
      out("  set debug <on|off>:               enables debug messages (current: %s)", debug_verbose_level ? "on" : "off");
      out("  set autoload <on|off>:            enables autoload after filebrowser upload (current: %s)", autoload_enabled ? "on" : "off");
      out("  save <name>:                      stores current config on SD Card");
      out("  load <name>:                      restores config from SD Card");
      out("  show file:                        shows the current configuration file");
      out("  show pool:                        shows the items of the event pool");
      out("  show poolbin:                     shows the event pool in binary format");
      out("  show id <element>:<id>            shows informations about the given element id (e.g. BUTTON:1)");
      out("  show hw_id <element>:<hw_id>      shows informations about the given element hw_id (e.g. BUTTON:1)");
      out("  show ngr_tokens:                  shows .NGR token information");
      out("  lcd <string>:                     directly prints a string on LCD (can be formatted!)");
      out("  run [<section>] [<value>]:        executes the .NGR script with the optional section and value");
      out("  ngr_value:                        value used for 'run' (without parameter) and 'ngr' (is: %d)", ngr_value);
      out("  ngr_section:                      section used for 'run' (without parameter) and 'ngr' (is: %d)", ngr_section);
      out("  ngr <command>:                    directly executes a NGR command");
      out("  ngc <command>:                    directly executes a NGC command");
      out("  msd <on|off>:                     enables Mass Storage Device driver");
      out("  reset:                            resets the MIDIbox (!)\n");
      out("  help:                             this page");
      out("  exit:                             (telnet only) exits the terminal");
    } else if( strcmp(parameter, "system") == 0 ) {
      TERMINAL_PrintSystem(_output_function);
    } else if( strcmp(parameter, "memory") == 0 ) {
      TERMINAL_PrintMemoryInfo(out);
    } else if( strcmp(parameter, "sdcard") == 0 ) {
      TERMINAL_PrintSdCardInfo(out);
    } else if( strcmp(parameter, "sdcard_format") == 0 ) {
      if( !brkt || strcasecmp(brkt, "yes, I'm sure") != 0 ) {
	out("ATTENTION: this command will format your SD Card!!!");
	out("           ALL DATA WILL BE DELETED FOREVER!!!");
	out("           Check the current content with the 'sdcard' command");
	out("           Create a backup on your computer if necessary!");
	out("To start formatting, please enter: sdcard_format yes, I'm sure");
	if( brkt ) {
	  out("('%s' wasn't the right \"password\")", brkt);
	}
      } else {
	MUTEX_SDCARD_TAKE;
	out("Formatting SD Card...");
	FRESULT res;
	if( (res=f_mkfs(0,0,0)) != FR_OK ) {
	  out("Formatting failed with error code: %d!", res);
	} else {
	  out("...with success!");
	  MBNG_FILE_UnloadAllFiles();
	  MBNG_FILE_CreateDefaultFiles();
	}
	MUTEX_SDCARD_GIVE;
      }
    } else if( strcmp(parameter, "msd") == 0 ) {
      char *arg = NULL;
      if( (arg = strtok_r(NULL, separators, &brkt)) ) {
	if( strcmp(arg, "on") == 0 ) {
	  if( TASK_MSD_EnableGet() ) {
	    out("Mass Storage Device Mode already activated!\n");
	  } else {
	    out("Mass Storage Device Mode activated - USB MIDI will be disabled!!!\n");
	    // wait a second to ensure that this message is print in MIOS Terminal
	    int d;
	    for(d=0; d<1000; ++d)
	      MIOS32_DELAY_Wait_uS(1000);
	    // activate MSD mode
	    TASK_MSD_EnableSet(1);
	  }
	} else if( strcmp(arg, "off") == 0 ) {
	  if( !TASK_MSD_EnableGet() ) {
	    out("Mass Storage Device Mode already deactivated!\n");
	  } else {
	    out("Mass Storage Device Mode deactivated - USB MIDI will be available again\n");
	    TASK_MSD_EnableSet(0);
	  }
	} else
	  arg = NULL;
      }
      if( arg == NULL ) {
	out("Please enter 'msd on' or 'msd off'\n");
      }      
    } else if( strcmp(parameter, "lcd") == 0 ) {
      if( !brkt || !strlen(brkt) ) {
	out("Please specify string (can be optionally formatted)");
      } else {
	out("Print '%s'", brkt);

	MUTEX_LCD_TAKE;

	// print from a dummy item
	mbng_event_item_t item;
	MBNG_EVENT_ItemInit(&item, MBNG_EVENT_CONTROLLER_DISABLED);
	item.label = brkt;
	MBNG_LCD_PrintItemLabel(&item, NULL, 0);

	MUTEX_LCD_GIVE;
      }
    } else if( strcmp(parameter, "run") == 0 ) {
      s32 section, value;
      if( (parameter = strtok_r(NULL, separators, &brkt)) ) {
	if( (section=get_dec(parameter)) < 0 || section >= 256 ) {
	  out("Section number should be between 0..255!");
	} else {
	  ngr_section = section;
	}

	if( (parameter = strtok_r(NULL, separators, &brkt)) ) {
	  if( (value=get_dec(parameter)) < -16384 || value >= 16383 ) {
	    out("Value should be between -16384..16383!");
	  } else {
	    ngr_value = value;
	  }
	}
      }

      if( !MBNG_FILE_R_Valid() ) {
	out("ERROR: can't execute - missing %s.NGR file!", mbng_file_r_script_name);
      } else {
	out("Executing %s.NGR with ^section==%d ^value==%d", mbng_file_r_script_name, ngr_section, ngr_value);
	MBNG_FILE_R_ReadRequest(NULL, ngr_section, ngr_value, 1);
      }
    } else if( strcmp(parameter, "runstop") == 0 ) {
      if( MBNG_FILE_R_RunStop() > 0 ) {
	out("Stopped the execution of %s.NGR", mbng_file_r_script_name);
      } else {
	out("%s.NGR script not running.", mbng_file_r_script_name);
      }
    } else if( strcasecmp(parameter, "ngr_section") == 0 ) {
      s32 section;
      if( !(parameter = strtok_r(NULL, separators, &brkt)) ) {
	out("Please specify <ngr-section>! Current value: %d", ngr_section);
      } else if( (section=get_dec(parameter)) < 0 || section >= 256 ) {
	out("Section number should be between 0..255!");
      } else {
	ngr_section = section;
	out(".NGR section set to %d", ngr_section);
      }
    } else if( strcasecmp(parameter, "ngr_value") == 0 ) {
      s32 value;

      if( !(parameter = strtok_r(NULL, separators, &brkt)) ) {
	out("Please specify <ngr-value>! Current value: %d", ngr_value);
      } else if( (value=get_dec(parameter)) < -16384 || value >= 16383 ) {
	out("Value should be between -16384..16383!");
      } else {
	ngr_value = value;
	out(".NGR value set to %d", ngr_value);
      }
    } else if( strcasecmp(parameter, "ngr") == 0 ) {
      if( brkt == NULL ) {
	out("Please specify command!");
      } else {
	char load_filename[9];
	load_filename[0] = 0;

	MBNG_FILE_R_VarSectionSet(ngr_section);
	MBNG_FILE_R_VarValueSet(ngr_value);
	MBNG_FILE_R_Parser(0, brkt, NULL, NULL, load_filename, 0);
	out("Executed command with ^section==%d ^value==%d", ngr_section, ngr_value);

	if( load_filename[0] ) {
	  s32 status = MBNG_PATCH_Load(parameter);
	  if( status < 0 ) {
	    out("ERROR: failed to load patch '%s' on SD Card (status %d)!", parameter, status);
	  }
	}
      }
    } else if( strcasecmp(parameter, "ngc") == 0 ) {
      if( brkt == NULL ) {
	out("Please specify command!");
      } else {
	u8 got_first_event_item = 0;
	MBNG_FILE_C_Parser(0, brkt, &got_first_event_item);
	out("Executed command.");
      }
    } else if( strcmp(parameter, "save") == 0 ) {
      if( !(parameter = strtok_r(NULL, separators, &brkt)) ) {
	out("ERROR: please specify filename for patch (up to 8 characters)!");
      } else {
	if( strlen(parameter) > 8 ) {
	  out("ERROR: 8 characters maximum!");
	} else {
	  s32 status = MBNG_PATCH_Store(parameter);
	  if( status >= 0 ) {
	    out("Patch '%s' stored on SD Card!", parameter);
	  } else {
	    out("ERROR: failed to store patch '%s' on SD Card (status %d)!", parameter, status);
	  }
	}
      }
    } else if( strcmp(parameter, "load") == 0 ) {
      if( !(parameter = strtok_r(NULL, separators, &brkt)) ) {
	out("ERROR: please specify filename for patch (up to 8 characters)!");
      } else {
	if( strlen(parameter) > 8 ) {
	  out("ERROR: 8 characters maximum!");
	} else {
	  s32 status = MBNG_PATCH_Load(parameter);
	  if( status >= 0 ) {
	    out("Patch '%s' loaded from SD Card!", parameter);
	  } else {
	    out("ERROR: failed to load patch '%s' on SD Card (status %d)!", parameter, status);
	  }
	}
      }
    } else if( strcmp(parameter, "show") == 0 ) {
      if( !(parameter = strtok_r(NULL, separators, &brkt)) ) {
	out("ERROR: please specify the item which should be displayed!");
      } else {
	if( strcmp(parameter, "file") == 0 ) {
	  MBNG_FILE_C_Debug();
	} else if( strcmp(parameter, "douts") == 0 ) {
	  int page;
	  for(page=0; page<MIOS32_SRIO_NUM_DOUT_PAGES; ++page) {
	    char buffer[3*MIOS32_SRIO_NUM_SR + 20];
	    sprintf(buffer, "Page %2d:", page+0);
	    int i;
	    for(i=0; i<MIOS32_SRIO_NUM_SR; ++i) {
	      sprintf((char *)&buffer[8+i*3], " %02x", mios32_srio_dout[page][MIOS32_SRIO_NUM_SR-i-1]);
	    }
	    MIOS32_MIDI_SendDebugString(buffer);
	  }
	} else if( strcmp(parameter, "ngr_tokens") == 0 || strcmp(parameter, "ngrtokens") == 0 ) {
	  MBNG_FILE_R_TokenMemPrint();
	} else if( strcmp(parameter, "poolbin") == 0 ) {
	  MBNG_EVENT_PoolPrint();
	} else if( strcmp(parameter, "pool") == 0 ) {
	  MBNG_EVENT_PoolItemsPrint();
	  MBNG_EVENT_PoolMapsPrint();
	} else if( strcmp(parameter, "id") == 0 || strcmp(parameter, "hw_id") == 0 ) {
	  u8 search_hw_id = strcmp(parameter, "hw_id") == 0;
	  const char *separator_colon = ":";

	  char *id_str = brkt;
	  if( id_str == NULL || !strlen(id_str) ) {
	    out("Please specify <element>:<id> (e.g. LED:1)!");
	  } else {
	    char *values_str;
	    mbng_event_item_id_t id;
	    if( !(values_str = strtok_r(NULL, separator_colon, &brkt)) ||
		(id=MBNG_EVENT_ItemIdFromControllerStrGet(values_str)) == MBNG_EVENT_CONTROLLER_DISABLED ) {
	      out("Invalid element name '%s'!", id_str);
	    } else {
	      char *id_lower_str = brkt;
	      int id_lower = 0;
	      if( !(values_str = strtok_r(NULL, separator_colon, &brkt)) ||
		  (id_lower=get_dec(values_str)) < 1 || id_lower > 0xfff ) {
		out("Invalid element %s '%s:%s' (expecting %s:1 .. %s:4095)!", search_hw_id ? "hw_id" : "id", id_str, id_lower_str, id_str, id_str);
	      } else {
		id = id | id_lower;

		if( search_hw_id ) {
		  u8 num = MBNG_EVENT_ItemSearchByHwIdAndPrint(id);
		  if( num < 1 ) {
		    out("No items found which are assigned to this hw_id!");
		  }
		} else {
		  u8 num = MBNG_EVENT_ItemSearchByIdAndPrint(id);
		  if( num < 1 ) {
		    out("No items found which are assigned to this id!");
		  }
		}
	      }
	    }
	  }
	} else {
	  out("ERROR: invalid item which should be showed - see 'show pool' for available items!");
	}
      }
    } else if( strcmp(parameter, "reset") == 0 ) {
      MIOS32_SYS_Reset();
    } else if( strcmp(parameter, "set") == 0 ) {
      if( (parameter = strtok_r(NULL, separators, &brkt)) ) {
	if( strcmp(parameter, "dout") == 0 ) {
	  s32 pin = -1;
	  if( (parameter = strtok_r(NULL, separators, &brkt)) ) {
	    if( strcmp(parameter, "all") == 0 ) {
	      pin = -42;
	    } else {
	      pin = get_dec(parameter);
	    }
	  }

	  if( (pin < 0 && pin != -42) || pin >= (MIOS32_SRIO_NUM_SR*8) ) {
	    out("Pin number should be between 0..%d", MIOS32_SRIO_NUM_SR*8 - 1);
	  } else {
	    s32 value = -1;
	    if( (parameter = strtok_r(NULL, separators, &brkt)) )
	      value = get_dec(parameter);

	    if( value < 0 || value > 1 ) {
	      out("Expecting value 1 or 0 for DOUT pin %d", pin);
	    } else {
	      if( pin == -42 ) {
		for(pin=0; pin<(MIOS32_SRIO_NUM_SR*8); ++pin)
		  MIOS32_DOUT_PinSet(pin, value);
		out("All DOUT pins set to %d", value);
	      } else {
		MIOS32_DOUT_PinSet(pin, value);
		out("DOUT Pin %d (SR#%d.D%d) set to %d", pin, (pin/8)+1, 7-(pin%8), value);
	      }
	    }
	  }

	} else if( strcmp(parameter, "debug") == 0 ) {
	  int on_off = -1;
	  if( (parameter = strtok_r(NULL, separators, &brkt)) )
	    on_off = get_on_off(parameter);

	  if( on_off < 0 ) {
	    out("Expecting 'on' or 'off'");
	  } else {
	    debug_verbose_level = on_off ? DEBUG_VERBOSE_LEVEL_INFO : DEBUG_VERBOSE_LEVEL_ERROR;
	    out("Debug mode turned %s", on_off ? "on" : "off");
	  }

	} else if( strcmp(parameter, "autoload") == 0 ) {
	  int on_off = -1;
	  if( (parameter = strtok_r(NULL, separators, &brkt)) )
	    on_off = get_on_off(parameter);

	  if( on_off < 0 ) {
	    out("Expecting 'on' or 'off'");
	  } else {
	    autoload_enabled = on_off;
	    out("Autoload of .NGC file after filebrowser upload %s", on_off ? "on" : "off");
	  }
	} else {
	  out("Unknown set parameter: '%s'!", parameter);
	}
      } else {
	out("Missing parameter after 'set'!");
      }
    } else {
      out("Unknown command - type 'help' to list available commands!");
    }
  }

  return 0; // no error
}
Пример #13
0
/////////////////////////////////////////////////////////////////////////////
// Parser for a complete line
// Returns > 0 if command line matches with UIP terminal commands
/////////////////////////////////////////////////////////////////////////////
s32 LC_HWCFG_TerminalParseLine(char *input, void *_output_function)
{
  void (*out)(char *format, ...) = _output_function;
  char *separators = " \t";
  char *brkt;
  char *parameter;

  // since strtok_r works destructive (separators in *input replaced by NUL), we have to restore them
  // on an unsuccessful call (whenever this function returns < 1)
  int input_len = strlen(input);

  if( (parameter = strtok_r(input, separators, &brkt)) ) {
    if( strcmp(parameter, "set") == 0 ) {
      if( !(parameter = strtok_r(NULL, separators, &brkt)) ) {
	out("Missing parameter after 'set'!");
	return 1; // command taken
      }

      if( strcmp(parameter, "xxx") == 0 ) {
	s32 sr = -1;
	if( (parameter = strtok_r(NULL, separators, &brkt)) )
	  sr = get_dec(parameter);

	if( sr < 1 || sr > MIOS32_SRIO_ScanNumGet() ) {
	  out("Expecting SR number from 1..%d", MIOS32_SRIO_ScanNumGet());
	  return 1; // command taken
	}

	return 1; // command taken

      } else if( strcmp(parameter, "debug") == 0 ) {
	if( !(parameter = strtok_r(NULL, separators, &brkt)) ) {
	  out("Please specify on or off (alternatively 1 or 0)");
	  return 1; // command taken
	}

	int on_off = get_on_off(parameter);

	if( on_off < 0 ) {
	  out("Expecting 'on' or 'off' (alternatively 1 or 0)!");
	} else {
	  lc_hwcfg_verbose_level = on_off ? 2 : 1;

	  out("Debug mode %s", on_off ? "enabled" : "disabled");
	}
	return 1; // command taken
      } else {
	// out("Unknown command - type 'help' to list available commands!");
      }
    }
  }

  // restore input line (replace NUL characters by spaces)
  int i;
  char *input_ptr = input;
  for(i=0; i<input_len; ++i, ++input_ptr)
    if( !*input_ptr )
      *input_ptr = ' ';

  return 0; // command not taken
}
Пример #14
0
/*
 * This functions isn't finished yet, it currently only works when
 * a single process has saved to file.
 * 
 * Pagesize: Assume something really big here as you don't know where
 * the file was generated.  Make a note to add the pagesize
 * to the header page somewhere.
 */
extern int sf_from_file (struct sf *sf, char *fname)
{
    size_t pagesize = (size_t)(64*1024);
    struct stat s;
    char *raw, *raw0;
    char *bufEnd;
    char *buildPage = malloc(pagesize*2);
    uint64_t *dataPage;
    int fd;
    int res;
    
    if ( ! buildPage )
	return -1;
    
    memset(buildPage,0,pagesize);
    
    dataPage = (uint64_t *)&buildPage[pagesize];
    
    memset(dataPage,0,pagesize);
    
    if ( stat(fname,&s) < 0 ) {
	free(buildPage);
	return -1;
    }
    
    /* Malloc more size than required to check the file isn't
     * growing as we read it */    
    if ( (raw = raw0 = malloc((size_t)s.st_size+1)) == NULL ) {
	free(buildPage);
	return -1;
    }
    
    bufEnd = raw + s.st_size -1;
    
    if ( (fd = open(fname,O_RDONLY)) == -1 ) {
	free(buildPage);
	free(raw);
	return -1;
    }
    
    if ( (res = read(fd,raw,(size_t)s.st_size+1)) != s.st_size ) {
	free(buildPage);
	free(raw);
	(void)close(fd);
	return -1;
    }
    
    {
	char tmp[16];
	int i;
	
	for ( i = 0 ; i < 4 ; i++ ) {
	    raw = get_str(&buildPage[i*16],raw);
	}
	
	do {
	    memset(&tmp[0],0,16);
	    raw = get_str(&tmp[0], raw);
	    i = atoi(&tmp[0]);
	    raw = get_str(&tmp[0], raw);
	    
	    strncpy(&buildPage[i*16],&tmp[0],15);
	    
	    if ( *raw == '\n' )
		raw++;
	    
	} while ( *raw != '\n' );
    }
    
    do {
	
	{
	    uint64_t index = 0;
	    int i;
	    
	    for ( i = 0 ; i < 4 ; i++ ) {
		raw = get_hex(&dataPage[i],raw);
	    }
	    
	    do {
		raw = get_dec(&index, raw);
		raw = get_hex(&dataPage[index], raw);
		
		if ( *raw == '\n' )
		    raw++;
		
	    } while ( *raw != '\n' );
	}
	
    } while ( raw != bufEnd );
    
    free(raw0);
    
    sf->base = buildPage;
    sf->database = dataPage;
    sf->valid = TRUE;
    sf->jobsize = 1;
    sf->nlocal = 1;
    sf->pagesize_d = sf->pagesize_h = pagesize;
    
    return 0;
}
Пример #15
0
void GetRegister(const char const* *m_str, PASM_REG m_reg)
{
	const char *m_ptr = *m_str;
	ASM_REG reg = *m_reg;
	int thirdc;
	const char *m_ch;
	
	// 중요 : 이 함수는 다음과 같은 구문은 처리하지 못합니다.
	//	[<num2> + <reg> * <num1>]
	//	[<num1> * <reg> + <num2>]
	//	[<num2>	+ <num1> * <reg>]
	//	[<num1> * <reg>]
	//	[<num1> + <reg>]

	if (reg.isprocess)
		return;
	reg.isprocess = true;
	reg.error = SYNTAX_ERROR::_Not_Found_Error;
	
	//	[<reg> * <num1> + <num2>] 형식일 경우 이 플래그는 활성화됨
	thirdc = FALSE;

	//	상수식 분석
	if ( isdigit(*m_ptr)  ||
	  // isxdigit(*m_ptr) ||
		 *m_ptr == '-'    ||
		 *m_ptr == '+'       )
	{
		const char *foresee = m_ptr + 1;
		int get;
		int radix = 0;

		reg.type = REG_TYPE::_Reg_Numberic;
		
		//	맨 끝의 문자를 확인하기 위해 포인터를 옮김
	 // SkipFunc(&foresee, isspace);
		SkipFunc(&foresee, isxdigit);
	 // SkipFunc(&foresee, isspace);

		if (*foresee == 'o')
			get = get_oct(m_ptr);
		else if (*foresee == 'x')
			get = get_hex(m_ptr);
		else
			get = get_dec(m_ptr);

		reg.first = get;

		m_ptr = foresee + 1;
		goto PROC_END;
	}
	
	//
	//	rxx, exx와 참조형 오퍼랜드를 분석함
	//	디폴트 값은 16bit형 오퍼랜드임
	//
RE:	switch(tolower(*m_ptr))
	{
	case '[':
		reg.type = REG_TYPE::_Reg_Reference;
		SkipWS(&m_ptr);
		m_ptr++;
		goto RE;
	{ case 'e': reg.bit = 32; goto SET; }
 // { case 'r': bit = 64; goto SET; }
	{ default:  reg.bit = 16; break; }
SET:
		if (reg.type != REG_TYPE::_Reg_Reference)
			reg.type = REG_TYPE::_Reg_Normal;
		m_ptr++;
	}
	
	//
	//	exx에서 e을 넘긴 레지스터를 분석함
	//	형식은 모두 16bit로 통일
	//
	switch(tolower(*((m_ch = m_ptr + 1) - 1)))
	{
	case 'a': 
		if      (*m_ch == 'x') reg.first = AX;
		else if (*m_ch == 'l') reg.first = AL;
		else if (*m_ch == 'h') reg.first = AH;
		break;
	case 'b':
		if      (*m_ch == 'p') reg.first = BP;
		else if (*m_ch == 'x') reg.first = BX;
		else if (*m_ch == 'l') reg.first = BL;
		else if (*m_ch == 'h') reg.first = BH;
		break;
	case 'c':
		if      (*m_ch == 'x') reg.first = CX;
		else if (*m_ch == 'l') reg.first = CL;
		else if (*m_ch == 'h') reg.first = CH;
		break;
	case 'd':
		if      (*m_ch == 'i') reg.first = DI;
		else if (*m_ch == 'x') reg.first = DX;
		else if (*m_ch == 'l') reg.first = DL;
		else if (*m_ch == 'h') reg.first = DH;
		break;
	case 's':
		if      (*m_ch == 'p') reg.first = SP;
		else if (*m_ch == 'i') reg.first = SI;
		break;
	}
	
	//
	//	분석했던 레지스터의 총 길이가 2이므로
	//
	m_ptr += 2;
	SkipWS(&m_ptr);

	//
	//	일반 레지스터 형식이면 더 이상 분석할 필요없으니
	//	그냥 끝냄
	//
	if (reg.type == REG_TYPE::_Reg_Normal)
		goto PROC_END;

	//
	//	일반 참조형 레지스터 형식
	//
	if (*m_ptr == ']') {
		reg.type = REG_TYPE::_Reg_SingleReference;
		goto PROC_END;
	}
	
	//
	//	']'를 만나지 않으면 뭔가 더 있는 것임으로
	//
	if (*m_ptr == '+')
		reg.sign = REG_SIGN::_Sign_Plus;
	else if (*m_ptr == '-')
		reg.sign = REG_SIGN::_Sign_Minus;
	else if (*m_ptr == '*')
		reg.sign = REG_SIGN::_Sign_Multiple;
	SkipWS(&m_ptr);

	m_ptr++;

	//
	//	16진수의 문자열일 경우 ffh나, a2h같은 문자가 먼저 나와있을 수 있는데
	//	이 경우엔 분석을 막아 변수로 취급한다. 그로 인해 16진수의 경우엔 
	//	0ffh, 0a2h와 같이 나타내어야 한다.
	//
	if(isdigit(*m_ptr))
	{
		const char * t = m_ptr;
		int get;
		for (; *t != ']' && *t; t++)
			if (*t == '-' || *t == '+') {

				//
				//	[<reg> * <num1> + <num2>] 형식임이 확증됨
				//
				thirdc = TRUE;
				break;
			}

		//
		//	*t == NULL이면 열린 괄호가 닫히지 않았으므로 당연한 오류
		//
		if (!*t--) {
			reg.error = SYNTAX_ERROR::_Not_Find_Comma;
			goto PROC_END;
		}

		//
		//	']'가 나오기 전에 공백이 포함되어있을 수 있으므로
		//
		for (; isspace(*t); t--)
			;

		if (*t == 'o')
			get = get_oct(m_ptr);
		else if (*t == 'h')
			get = get_hex(m_ptr);
		else
			get = get_dec(m_ptr);

		reg.second = get;
		reg.type = REG_TYPE::_Reg_Reference;
		m_ptr = t + 1;

		if (thirdc == TRUE) {
			//
			//	이 코드구역은 상기구역과 동일함
			//
			const char * ptr = t+1;
			int get;
			SkipWS(&m_ptr);

			if (*ptr == '+')
				reg.sign = REG_SIGN::_Sign_Multiple_Plus;
			else if (*ptr == '-')
				reg.sign = REG_SIGN::_Sign_Multiple_Minus;
			SkipWS(&m_ptr);

			for (; *t != ']' && *t; t++)
				;
			
			if (!*t--) {
				reg.error = SYNTAX_ERROR::_Not_Find_Comma;
				goto PROC_END;
			}

			for (; isspace(*t); t--)
				;
			
			if (*t == 'o')
				get = get_oct(m_ptr);
			else if (*t == 'h')
				get = get_hex(m_ptr);
			else
				get = get_dec(m_ptr);

			reg.third = get;
			m_ptr = ptr + 1;
		}
	}

PROC_END:
	*m_reg = reg;
	*m_str = m_ptr;
}
Пример #16
0
/////////////////////////////////////////////////////////////////////////////
// Parser for a complete line - also used by shell.c for telnet
/////////////////////////////////////////////////////////////////////////////
s32 TERMINAL_ParseLine(char *input, void *_output_function)
{
  void (*out)(char *format, ...) = _output_function;
  char *separators = " \t";
  char *brkt;
  char *parameter;

  if( UIP_TERMINAL_ParseLine(input, _output_function) > 0 )
    return 0; // command parsed by UIP Terminal

  if( MIDIMON_TerminalParseLine(input, _output_function) > 0 )
    return 0; // command parsed

  if( MIDI_ROUTER_TerminalParseLine(input, _output_function) > 0 )
    return 0; // command parsed

  if( AOUT_TerminalParseLine(input, _output_function) > 0 )
    return 0; // command parsed

#ifdef MIOS32_LCD_universal
  if( APP_LCD_TerminalParseLine(input, _output_function) >= 1 )
    return 0; // command parsed
#endif

  if( (parameter = strtok_r(input, separators, &brkt)) ) {
    if( strcmp(parameter, "help") == 0 ) {
      out("Welcome to " MIOS32_LCD_BOOT_MSG_LINE1 "!");
      out("Following commands are available:");
      out("  system:                           print system info");
      out("  memory:                           print memory allocation info\n");
      out("  sdcard:                           print SD Card info\n");
      out("  sdcard_format:                    formats the SD Card (you will be asked for confirmation)\n");
      UIP_TERMINAL_Help(_output_function);
      MIDIMON_TerminalHelp(_output_function);
      MIDI_ROUTER_TerminalHelp(_output_function);
      out("  set dout <pin> <0|1>:             directly sets DOUT (all or 0..%d) to given level (1 or 0)", MIOS32_SRIO_NUM_SR*8 - 1);
      out("  set update_rate <1..%d>:          sets update rate of sound engine (factor*500 Hz), current: %d\n", APP_CV_UPDATE_RATE_FACTOR_MAX, APP_CvUpdateRateFactorGet());
      AOUT_TerminalHelp(_output_function);
#ifdef MIOS32_LCD_universal
      APP_LCD_TerminalHelp(_output_function);
#endif
      out("  save <name>:                      stores current config on SD Card");
      out("  load <name>:                      restores config from SD Card");
      out("  show:                             shows the current configuration file");
      out("  nrpn:                             shows the current NRPN parameters");
      out("  msd <on|off>:                     enables Mass Storage Device driver");
      out("  reset:                            resets the MIDIbox (!)\n");
      out("  help:                             this page");
      out("  exit:                             (telnet only) exits the terminal");
    } else if( strcmp(parameter, "system") == 0 ) {
      TERMINAL_PrintSystem(_output_function);
    } else if( strcmp(parameter, "memory") == 0 ) {
      TERMINAL_PrintMemoryInfo(out);
    } else if( strcmp(parameter, "sdcard") == 0 ) {
      TERMINAL_PrintSdCardInfo(out);
    } else if( strcmp(parameter, "sdcard_format") == 0 ) {
      if( !brkt || strcasecmp(brkt, "yes, I'm sure") != 0 ) {
	out("ATTENTION: this command will format your SD Card!!!");
	out("           ALL DATA WILL BE DELETED FOREVER!!!");
	out("           Check the current content with the 'sdcard' command");
	out("           Create a backup on your computer if necessary!");
	out("To start formatting, please enter: sdcard_format yes, I'm sure");
	if( brkt ) {
	  out("('%s' wasn't the right \"password\")", brkt);
	}
      } else {
	MUTEX_SDCARD_TAKE;
	out("Formatting SD Card...");
	FRESULT res;
	if( (res=f_mkfs(0,0,0)) != FR_OK ) {
	  out("Formatting failed with error code: %d!", res);
	} else {
	  out("...with success!");
	  MBCV_FILE_UnloadAllFiles();
	  MBCV_FILE_CreateDefaultFiles();
	}
	MUTEX_SDCARD_GIVE;
      }
    } else if( strcmp(parameter, "msd") == 0 ) {
      char *arg = NULL;
      if( (arg = strtok_r(NULL, separators, &brkt)) ) {
	if( strcmp(arg, "on") == 0 ) {
	  if( TASK_MSD_EnableGet() ) {
	    out("Mass Storage Device Mode already activated!\n");
	  } else {
	    out("Mass Storage Device Mode activated - USB MIDI will be disabled!!!\n");
	    // wait a second to ensure that this message is print in MIOS Terminal
	    int d;
	    for(d=0; d<1000; ++d)
	      MIOS32_DELAY_Wait_uS(1000);
	    // activate MSD mode
	    TASK_MSD_EnableSet(1);
	  }
	} else if( strcmp(arg, "off") == 0 ) {
	  if( !TASK_MSD_EnableGet() ) {
	    out("Mass Storage Device Mode already deactivated!\n");
	  } else {
	    out("Mass Storage Device Mode deactivated - USB MIDI will be available again.n");
	    TASK_MSD_EnableSet(0);
	  }
	} else
	  arg = NULL;
      }
      if( arg == NULL ) {
	out("Please enter 'msd on' or 'msd off'\n");
      }      
    } else if( strcmp(parameter, "save") == 0 ) {
      if( !(parameter = strtok_r(NULL, separators, &brkt)) ) {
	out("ERROR: please specify filename for patch (up to 8 characters)!");
      } else {
	if( strlen(parameter) > 8 ) {
	  out("ERROR: 8 characters maximum!");
	} else {
	  s32 status = MBCV_PATCH_StoreGlobal(parameter);
	  if( status >= 0 ) {
	    out("Patch '%s' stored on SD Card!", parameter);
	  } else {
	    out("ERROR: failed to store patch '%s' on SD Card (status %d)!", parameter, status);
	  }
	}
      }
    } else if( strcmp(parameter, "load") == 0 ) {
      if( !(parameter = strtok_r(NULL, separators, &brkt)) ) {
	out("ERROR: please specify filename for patch (up to 8 characters)!");
      } else {
	if( strlen(parameter) > 8 ) {
	  out("ERROR: 8 characters maximum!");
	} else {
	  s32 status = MBCV_PATCH_LoadGlobal(parameter);
	  if( status >= 0 ) {
	    out("Patch '%s' loaded from SD Card!", parameter);
	  } else {
	    out("ERROR: failed to load patch '%s' on SD Card (status %d)!", parameter, status);
	  }
	}
      }
    } else if( strcmp(parameter, "show") == 0 ) {
      MBCV_FILE_P_Debug();
    } else if( strcmp(parameter, "nrpn") == 0 || strcmp(parameter, "nrpns") == 0 ) {
      TERMINAL_ShowNrpns(out);
    } else if( strcmp(parameter, "reset") == 0 ) {
      MIOS32_SYS_Reset();
    } else if( strcmp(parameter, "set") == 0 ) {
      if( (parameter = strtok_r(NULL, separators, &brkt)) ) {
	if( strcmp(parameter, "dout") == 0 ) {
	  s32 pin = -1;
	  if( (parameter = strtok_r(NULL, separators, &brkt)) ) {
	    if( strcmp(parameter, "all") == 0 ) {
	      pin = -42;
	    } else {
	      pin = get_dec(parameter);
	    }
	  }

	  if( (pin < 0 && pin != -42) || pin >= (MIOS32_SRIO_NUM_SR*8) ) {
	    out("Pin number should be between 0..%d", MIOS32_SRIO_NUM_SR*8 - 1);
	  } else {
	    s32 value = -1;
	    if( (parameter = strtok_r(NULL, separators, &brkt)) )
	      value = get_dec(parameter);

	    if( value < 0 || value > 1 ) {
	      out("Expecting value 1 or 0 for DOUT pin %d", pin);
	    } else {
	      if( pin == -42 ) {
		for(pin=0; pin<(MIOS32_SRIO_NUM_SR*8); ++pin)
		  MIOS32_DOUT_PinSet(pin, value);
		out("All DOUT pins set to %d", value);
	      } else {
		MIOS32_DOUT_PinSet(pin, value);
		out("DOUT Pin %d (SR#%d.D%d) set to %d", pin, (pin/8)+1, 7-(pin%8), value);
	      }
	    }
	  }
	} else if( strcmp(parameter, "update_rate") == 0 ) {
	  s32 factor = -1;
	  if( (parameter = strtok_r(NULL, separators, &brkt)) ) {
	    factor = get_dec(parameter);
	  }

	  if( (factor < 1 || factor > APP_CV_UPDATE_RATE_FACTOR_MAX) ) {
	    out("Update Rate should be between 1..%d!", APP_CV_UPDATE_RATE_FACTOR_MAX);
	  } else {
	    APP_CvUpdateRateFactorSet(factor);
	    out("Update Rate set to %d Hz (factor %d)", 500*APP_CvUpdateRateFactorGet(), APP_CvUpdateRateFactorGet());
	  }
	} else {
	  out("Unknown set parameter: '%s'!", parameter);
	}
      } else {
	out("Missing parameter after 'set'!");
      }
    } else {
      out("Unknown command - type 'help' to list available commands!");
    }
  }

  return 0; // no error
}
Пример #17
0
void comp_vecs(const char *fn1, const char *fn2)
{   char            str1[128], str2[128];
    enum line_type  ty1, ty2;
    int             no1, no2, err_cnt, np_cnt, req;
    FILE            *if1, *if2;

    err_cnt = np_cnt = 0; req = TRUE;

    if(fopen_s(&if1, fn1, "r"))
    {
        printf("\n*** 1st file (%s) not found ***", fn1); return;
    }

    if(fopen_s(&if2, fn2, "r"))
    {
        printf("\n*** 2nd file (%s) not found ***", fn2); return;
    }

    for(;;)         // while there is still input
    {
        if(req)     // if another line needs to be input
        {
            ty1 = find_line(if1, str1); ty2 = find_line(if2, str2);
        }

        if(ty1 == bad_line && ty2 == bad_line)      // if end of file on both files
            break;

        if(ty1 == bad_line || ty2 == bad_line)      // if end of file on one file
        {
            printf("\n%s%s%s%s" , fn1, (ty1 == bad_line ? " short" : " long"), "er than ", fn2);
            break;
        }

        if(ty1 == test_no)          // if 'test number' line in file 1

            no1 = get_dec(str1);

        if(ty2 == test_no)          // if 'test number' line in file 2

            no2 = get_dec(str2);

        if(cmp_nocase(str1, str2) == 0)
        {
            req = TRUE; continue;   // if lines are the same continue
        }

        if(ty1 == test_no && ty2 == test_no)    // if not the same but both are at a
        {                                       // 'test number' line
            np_cnt += abs(no2 - no1); req = FALSE;

            if(no2 < no1)   // extra tests in file 2
            {
                printf("\nextra test(s) in %s:\n  %s", fn2, str2);
                no2 = sync(no1, if2, str2, np_cnt < 10); // skip tests in file 2
            }

            if(no1 < no2)   // extra test in file 1
            {
                printf("\nextra test(s) in %s:\n  %s", fn1, str1);
                no1 = sync(no2, if1, str1, np_cnt < 10);// skip tests in file 1
            }
        }
        else if(ty1 != ty2) // cannot synchronise test vector files
        {
            printf("\n*** synchronisation error tests %i and %i ***", no1, no2);
            fflush(stdout); return;
        }
        else if(ty1 != bad_line)   // test vector mismatch
        {
            err_cnt++;

            printf("\r*** mismatch error test %i ***", no1);
        }

        fflush(stdout);
    }

    if(np_cnt && !err_cnt)  // all tests present match

        printf("\nother tests match\n");

    else
    {
        if(err_cnt)
            printf("\r%s doesn't match %s (%i errors)\n", fn2, fn1, err_cnt);
        else
            printf("\r%s matches %s\n", df_string(fn2), df_string(fn1));
    }

    fclose(if1); fclose(if2);
}
Пример #18
0
/////////////////////////////////////////////////////////////////////////////
// reads the config file content (again)
// returns < 0 on errors (error codes are documented in seq_file.h)
/////////////////////////////////////////////////////////////////////////////
s32 SEQ_FILE_G_Read(char *session)
{
  s32 status = 0;
  seq_file_g_info_t *info = &seq_file_g_info;
  seq_file_t file;

  info->valid = 0; // will be set to valid if file content has been read successfully

  char filepath[MAX_PATH];
  sprintf(filepath, "%s/%s/MBSEQ_G.V4", SEQ_FILE_SESSION_PATH, session);

#if DEBUG_VERBOSE_LEVEL >= 2
  DEBUG_MSG("[SEQ_FILE_G] Open config file '%s'\n", filepath);
#endif

  if( (status=SEQ_FILE_ReadOpen(&file, filepath)) < 0 ) {
#if DEBUG_VERBOSE_LEVEL >= 2
    DEBUG_MSG("[SEQ_FILE_G] failed to open file, status: %d\n", status);
#endif
    return status;
  }

  // read config values
  char line_buffer[128];
  do {
    status=SEQ_FILE_ReadLine((u8 *)line_buffer, 128);

    if( status > 1 ) {
#if DEBUG_VERBOSE_LEVEL >= 3
      DEBUG_MSG("[SEQ_FILE_G] read: %s", line_buffer);
#endif

      // sscanf consumes too much memory, therefore we parse directly
      char *separators = " \t";
      char *brkt;
      char *parameter;

      if( (parameter = strtok_r(line_buffer, separators, &brkt)) ) {

	if( *parameter == '#' ) {
	  // ignore comments
	} else {
	  char *word = strtok_r(NULL, separators, &brkt);
	  s32 value = get_dec(word);

	  if( value < 0 ) {
#if DEBUG_VERBOSE_LEVEL >= 1
	    DEBUG_MSG("[SEQ_FILE_G] ERROR invalid value for parameter '%s'\n", parameter);
#endif
	  } else if( strcmp(parameter, "NumSteps") == 0 ) {
	    u8 groove = value;
	    if( groove < SEQ_GROOVE_NUM_TEMPLATES ) {
	      word = strtok_r(NULL, separators, &brkt);
	      int num_steps = get_dec(word);
	      if( num_steps > 0 )
		seq_groove_templates[groove].num_steps = num_steps;
	    }
	  } else if( strcmp(parameter, "Delay") == 0 ) {
	    u8 groove = value;
	    if( groove < SEQ_GROOVE_NUM_TEMPLATES ) {
	      int i;
	      for(i=0; i<16; ++i) {
		word = strtok_r(NULL, separators, &brkt);
		seq_groove_templates[groove].add_step_delay[i] = get_dec(word);
	      }
	    }
	  } else if( strcmp(parameter, "Length") == 0 ) {
	    u8 groove = value;
	    if( groove < SEQ_GROOVE_NUM_TEMPLATES ) {
	      int i;
	      for(i=0; i<16; ++i) {
		word = strtok_r(NULL, separators, &brkt);
		seq_groove_templates[groove].add_step_length[i] = get_dec(word);
	      }
	    }
	  } else if( strcmp(parameter, "Velocity") == 0 ) {
	    u8 groove = value;
	    if( groove < SEQ_GROOVE_NUM_TEMPLATES ) {
	      int i;
	      for(i=0; i<16; ++i) {
		word = strtok_r(NULL, separators, &brkt);
		seq_groove_templates[groove].add_step_velocity[i] = get_dec(word);
	      }
	    }
	  } else {
#if DEBUG_VERBOSE_LEVEL >= 1
	    DEBUG_MSG("[SEQ_FILE_HW] ERROR: unknown parameter: %s", line_buffer);
#endif
	  }
	}
      } else {
#if DEBUG_VERBOSE_LEVEL >= 1
	DEBUG_MSG("[SEQ_FILE_G] ERROR no space separator in following line: %s", line_buffer);
#endif
      }
    }

  } while( status >= 1 );

  // close file
  status |= SEQ_FILE_ReadClose(&file);

  if( status < 0 ) {
#if DEBUG_VERBOSE_LEVEL >= 1
    DEBUG_MSG("[SEQ_FILE_G] ERROR while reading file, status: %d\n", status);
#endif
    return SEQ_FILE_G_ERR_READ;
  }

  // file is valid! :)
  info->valid = 1;

  return 0; // no error
}
Пример #19
0
/////////////////////////////////////////////////////////////////////////////
// Restore configuration from /SYSEX/<device>/DEVCFG.V4 file
/////////////////////////////////////////////////////////////////////////////
static s32 SEQ_UI_SYSEX_RestoreConfig(void)
{
  s32 status = 0;

  if( !dir_name[0] ) {
    // not in device dir
    return -1;
  }

  file_t file;
  char filepath[MAX_PATH];
  sprintf(filepath, "/SYSEX/%s/DEVCFG.V4", dir_name);

  MUTEX_SDCARD_TAKE;

  if( (status=FILE_ReadOpen(&file, filepath)) < 0 ) {
    // no error if file doesn't exist...
    if( FILE_FileExists(filepath) >= 1 ) {
      DEBUG_MSG("[SEQ_UI_SYSEX] Failed to open %s file, status: %d\n", filepath, status);
      SEQ_UI_SDCardErrMsg(2000, status);
    }
    // take default values
    sysex_port = DEFAULT;
    sysex_delay_between_dumps = 100;
  } else {
    char line_buffer[128];
    do {
      status=FILE_ReadLine((u8 *)line_buffer, 128);

      // sscanf consumes too much memory, therefore we parse directly
      char *separators = " \t";
      char *brkt;
      char *parameter;

      if( (parameter = strtok_r(line_buffer, separators, &brkt)) ) {

	if( *parameter == '#' ) {
	  // ignore comments
	} else {
	  char *word = strtok_r(NULL, separators, &brkt);

	  if( strcasecmp(parameter, "DevicePort") == 0 ) {
	    s32 value = SEQ_MIDI_PORT_OutPortFromNameGet(word);
	    if( value < 0 ) {
	      DEBUG_MSG("[SEQ_UI_SYSEX] ERROR: invalid parameter value: %s %s\n", parameter, word);
	    } else {
	      sysex_port = value;
	    }
	  } else if( strcasecmp(parameter, "DelayBetweenDumps") == 0 ) {
	    s32 value = get_dec(word);
	    if( value < 0 || value > 65535 ) {
	      DEBUG_MSG("[SEQ_UI_SYSEX] ERROR: invalid parameter value: %s %s\n", parameter, word);
	    } else {
	      sysex_delay_between_dumps = value;
	    }
	  } else {
	    DEBUG_MSG("[SEQ_UI_SYSEX] ERROR: unknown parameter: %s\n", parameter);
	  }
	}
      }

    } while( status >= 1 );

    // close file
    status |= FILE_ReadClose(&file);

    if( status < 0 ) {
      DEBUG_MSG("[SEQ_UI_SYSEX] Errors while reading from %s file\n", filepath);
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "Errors while reading from", filepath);
    }
  }

  MUTEX_SDCARD_GIVE;

  return status;
}
Пример #20
0
/* array_size is the number of pre-allocated entries there are */
int get_only_partition(void *driver_info, int (*bottom_read_fun)(),
                        struct diskpart *array, int array_size,
                        int disk_size, char *drive_name)
{
	char buff[SECTOR_SIZE];
	int i,n,cnt;
	int arrsize;
	struct diskpart *res;

	/* first fill in the entire disk stuff */
	/* or should the calling routine do that already? */

	fill_array(array, 0, disk_size, NULL, 0, -1, -1);

	/* while the structure does not preclude additional nestings,
	   additional ones make no sense currently, so they are not
	   checked (Mach can't handle them anyway).  It might be nice
	   if for all partitions found, all types of sub-partitions
	   were looked for (unnecessary).  This will be done when this
           is moved out of ther kernel, and there is some way to name them */

	arrsize = array_size -1;  /* 1 for whole disk */

	/* search for dos partition table */
	/* find all the partitions (including logical) */
	n=get_dos(&array[1], buff, 0,
                driver_info, (bottom_read_fun), drive_name,
		arrsize);

	if (n>0) {
		fill_array(array, 0, disk_size, &array[1], n, 
			DISKPART_DOS, 256+DISKPART_DOS);
		arrsize-=n;


		/* search each one for a BSD disklabel (iff BSDOS) */
		/* note: searchine extended and logical partitions */
		for (i=0;i<n;i++)
			if (array[i+1].fsys==BSDOS) {
#if (PARTITION_DEBUG) 
				printf("BSD OS slice: %d\n",i+1);
#endif
				cnt=get_disklabel(&array[n+1], buff, 
					array[i+1].start,
                			driver_info, (bottom_read_fun),
                			drive_name,arrsize);

				if (cnt>0) {
					arrsize-=cnt;
					fill_array(&array[i+1],array[i+1].start,
						array[i+1].size, &array[n+1], 
						cnt, DISKPART_BSD,
						array[i+1].fsys);
				}
				n+=cnt;
			}

		/* search for VTOC -- in a DOS partition as well */
		for (i=0;i<n;i++)
			if (array[i+1].fsys==UNIXOS) {
#if (PARTITION_DEBUG) 
				printf("UNIXOS (vtoc) partition\n");
#endif
                                cnt=get_vtoc(&array[n+1], buff,   
                                        array[i+1].start,
                                        driver_info, (bottom_read_fun),
                                        drive_name,arrsize);

                                if (cnt>0) {
					arrsize-=cnt;
                                        fill_array(&array[i+1],array[i+1].start,
                                                array[i+1].size, &array[n+1],
                                                cnt, DISKPART_VTOC,
						array[i+1].fsys);
				}
				n+=cnt;
			}
	}

	/* search for only disklabel */
	if (n==0) {
		fill_array(array, 0, disk_size, &array[1], n, DISKPART_BSD,
			256+DISKPART_BSD);
		n=get_disklabel(&array[1], buff, 0, driver_info, 
			(bottom_read_fun), drive_name,arrsize);
	}

	/* search for only VTOC -- NOT TESTED! */
	if (n==0) {
		fill_array(array, 0, disk_size, &array[1], n, DISKPART_VTOC,
			256+DISKPART_VTOC);
		n=get_vtoc(&array[1], buff, 0, driver_info, (bottom_read_fun), 
                	drive_name,arrsize);
	}
#if 0
	/* search for only omron -- NOT TESTED! */
	if (n==0) {
		fill_array(array, 0, disk_size, &array[1], n, DISKPART_OMRON,
			256+DISKPART_OMRON);
		n=get_omron(&array[1], buff, 0,driver_info, (bottom_read_fun), 
                	drive_name,arrsize);
	}

	/* search for only dec -- NOT TESTED! */
	if (n==0) {
		fill_array(array, 0, disk_size, &array[1], n, DISKPART_DEC,
			256+DISKPART_DEC);
		n=get_dec(&array[1], buff, 0, driver_info, (bottom_read_fun), 
                	drive_name,arrsize);
	}
#endif 0

#if (PARTITION_DEBUG)	/* print out what we found */
	print_array(array,0);
#endif

}
Пример #21
0
/////////////////////////////////////////////////////////////////////////////
// Parser
/////////////////////////////////////////////////////////////////////////////
s32 SEQ_TERMINAL_Parse(mios32_midi_port_t port, u8 byte)
{
  // temporary change debug port (will be restored at the end of this function)
  mios32_midi_port_t prev_debug_port = MIOS32_MIDI_DebugPortGet();
  MIOS32_MIDI_DebugPortSet(port);

  if( byte == '\r' ) {
    // ignore
  } else if( byte == '\n' ) {
    // example for parsing the command:
    char *separators = " \t";
    char *brkt;
    char *parameter;

    if( (parameter = strtok_r(line_buffer, separators, &brkt)) ) {
      if( strcmp(parameter, "help") == 0 ) {
	SEQ_TERMINAL_PrintHelp(DEBUG_MSG);
      } else if( strcmp(parameter, "system") == 0 ) {
	SEQ_TERMINAL_PrintSystem(DEBUG_MSG);
      } else if( strcmp(parameter, "global") == 0 ) {
	SEQ_TERMINAL_PrintGlobalConfig(DEBUG_MSG);
      } else if( strcmp(parameter, "bookmarks") == 0 ) {
	SEQ_TERMINAL_PrintBookmarks(DEBUG_MSG);
      } else if( strcmp(parameter, "config") == 0 ) {
	SEQ_TERMINAL_PrintSessionConfig(DEBUG_MSG);
      } else if( strcmp(parameter, "tracks") == 0 ) {
	SEQ_TERMINAL_PrintTracks(DEBUG_MSG);
      } else if( strcmp(parameter, "track") == 0 ) {
	  char *arg;
	  if( (arg = strtok_r(NULL, separators, &brkt)) ) {
	    int track = get_dec(arg);
	    if( track < 1 || track > SEQ_CORE_NUM_TRACKS ) {
	      MUTEX_MIDIOUT_TAKE;
	      DEBUG_MSG("Wrong track number %d - expected track 1..%d\n", track, SEQ_CORE_NUM_TRACKS);
	      MUTEX_MIDIOUT_GIVE;
	    } else {
	      SEQ_TERMINAL_PrintTrack(DEBUG_MSG, track-1);
	    }
	  } else {
	    MUTEX_MIDIOUT_TAKE;
	    DEBUG_MSG("Please specify track, e.g. \"track 1\"\n");
	    MUTEX_MIDIOUT_GIVE;
	  }
      } else if( strcmp(parameter, "mixer") == 0 ) {
	SEQ_TERMINAL_PrintCurrentMixerMap(DEBUG_MSG);
      } else if( strcmp(parameter, "song") == 0 ) {
	SEQ_TERMINAL_PrintCurrentSong(DEBUG_MSG);
      } else if( strcmp(parameter, "grooves") == 0 ) {
	SEQ_TERMINAL_PrintGrooveTemplates(DEBUG_MSG);
      } else if( strcmp(parameter, "memory") == 0 ) {
	SEQ_TERMINAL_PrintMemoryInfo(DEBUG_MSG);
#if !defined(MIOS32_FAMILY_EMULATION)
      } else if( strcmp(parameter, "network") == 0 ) {
	SEQ_TERMINAL_PrintNetworkInfo(DEBUG_MSG);
      } else if( strcmp(parameter, "udpmon") == 0 ) {
	MUTEX_MIDIOUT_TAKE;
	char *arg;
	if( (arg = strtok_r(NULL, separators, &brkt)) ) {
	  int level = get_dec(arg);
	  switch( level ) {
	  case UDP_MONITOR_LEVEL_0_OFF:
	    DEBUG_MSG("Set UDP monitor level to %d (off)\n", level);
	    break;
	  case UDP_MONITOR_LEVEL_1_OSC_REC:
	    DEBUG_MSG("Set UDP monitor level to %d (received packets assigned to a OSC1..4 port)\n", level);
	    break;
	  case UDP_MONITOR_LEVEL_2_OSC_REC_AND_SEND:
	    DEBUG_MSG("Set UDP monitor level to %d (received and sent packets assigned to a OSC1..4 port)\n", level);
	    break;
	  case UDP_MONITOR_LEVEL_3_ALL_GEQ_1024:
	    DEBUG_MSG("Set UDP monitor level to %d (all received and sent packets with port number >= 1024)\n", level);
	    break;
	  case UDP_MONITOR_LEVEL_4_ALL:
	    DEBUG_MSG("Set UDP monitor level to %d (all received and sent packets)\n", level);
	    break;
	  default:
	    DEBUG_MSG("Invalid level %d - please specify monitor level 0..4\n", level);
	    level = -1; // invalidate level for next if() check
	  }

	  if( level >= 0 )
	    UIP_TASK_UDP_MonitorLevelSet(level);
	} else {
	  DEBUG_MSG("Please specify monitor level (0..4)\n");
	}
	MUTEX_MIDIOUT_GIVE;
#endif
      } else if( strcmp(parameter, "sdcard") == 0 ) {
	SEQ_TERMINAL_PrintSdCardInfo(DEBUG_MSG);
      } else if( strcmp(parameter, "testaoutpin") == 0 ) {
	char *arg;
	int pin_number = -1;
	int level = -1;

	if( (arg = strtok_r(NULL, separators, &brkt)) ) {
	  if( strcmp(arg, "cs") == 0 )
	    pin_number = 1;
	  else if( strcmp(arg, "si") == 0 )
	    pin_number = 2;
	  else if( strcmp(arg, "sc") == 0 )
	    pin_number = 3;
	  else if( strcmp(arg, "reset") == 0 ) {
	    pin_number = 0;
	    level = 0; // dummy
	  }
	}

	if( pin_number < 0 ) {
	  MUTEX_MIDIOUT_TAKE;
	  DEBUG_MSG("Please specifiy valid AOUT pin name: cs, si or sc\n");
	  MUTEX_MIDIOUT_GIVE;
	} else {
	  if( (arg = strtok_r(NULL, separators, &brkt)) )
	    level = get_dec(arg);

	  if( level != 0 && level != 1 ) {
	    MUTEX_MIDIOUT_TAKE;
	    DEBUG_MSG("Please specifiy valid logic level for AOUT pin: 0 or 1\n");
	    MUTEX_MIDIOUT_GIVE;
	  }
	}

	if( pin_number >= 0 && level >= 0 ) {
	  SEQ_TERMINAL_TestAoutPin(DEBUG_MSG, pin_number, level);
	} else {
	  MUTEX_MIDIOUT_TAKE;
	  DEBUG_MSG("Following commands are supported:\n");
	  DEBUG_MSG("testaoutpin cs 0  -> sets AOUT:CS to 0.4V");
	  DEBUG_MSG("testaoutpin cs 1  -> sets AOUT:CS to ca. 4V");
	  DEBUG_MSG("testaoutpin si 0  -> sets AOUT:SI to ca. 0.4V");
	  DEBUG_MSG("testaoutpin si 1  -> sets AOUT:SI to ca. 4V");
	  DEBUG_MSG("testaoutpin sc 0  -> sets AOUT:SC to ca. 0.4V");
	  DEBUG_MSG("testaoutpin sc 1  -> sets AOUT:SC to ca. 4V");
	  DEBUG_MSG("testaoutpin reset -> re-initializes AOUT module so that it can be used again.");
	  MUTEX_MIDIOUT_GIVE;
	}
      } else if( strcmp(parameter, "play") == 0 ) {
	SEQ_UI_Button_Play(0);
	MUTEX_MIDIOUT_TAKE;
	DEBUG_MSG("Sequencer started...\n");
	MUTEX_MIDIOUT_GIVE;
      } else if( strcmp(parameter, "stop") == 0 ) {
	SEQ_UI_Button_Stop(0);
	MUTEX_MIDIOUT_TAKE;
	DEBUG_MSG("Sequencer stopped...\n");
	MUTEX_MIDIOUT_GIVE;
      } else if( strcmp(parameter, "reset") == 0 ) {
	MIOS32_SYS_Reset();
      } else {
	MUTEX_MIDIOUT_TAKE;
	DEBUG_MSG("Unknown command - type 'help' to list available commands!\n");
	MUTEX_MIDIOUT_GIVE;
      }
    }

    line_ix = 0;

  } else if( line_ix < (STRING_MAX-1) ) {
    line_buffer[line_ix++] = byte;
    line_buffer[line_ix] = 0;
  }

  // restore debug port
  MIOS32_MIDI_DebugPortSet(prev_debug_port);

  return 0; // no error
}
Пример #22
0
/////////////////////////////////////////////////////////////////////////////
// reads the config file content (again)
// returns < 0 on errors (error codes are documented in seq_file.h)
/////////////////////////////////////////////////////////////////////////////
s32 SEQ_FILE_BM_Read(char *session, u8 global)
{
  s32 status = 0;
  seq_file_bm_info_t *info = &seq_file_bm_info[global];
  seq_file_t file;

  info->valid = 0; // will be set to valid if file content has been read successfully

  char filepath[MAX_PATH];
  if( global )
    sprintf(filepath, "%sMBSEQ_BM.V4", SEQ_FILES_PATH);
  else
    sprintf(filepath, "%s/%s/MBSEQ_BM.V4", SEQ_FILE_SESSION_PATH, session);

#if DEBUG_VERBOSE_LEVEL >= 2
  DEBUG_MSG("[SEQ_FILE_BM] Open config file '%s'\n", filepath);
#endif

  if( (status=SEQ_FILE_ReadOpen(&file, filepath)) < 0 ) {
#if DEBUG_VERBOSE_LEVEL >= 2
    DEBUG_MSG("[SEQ_FILE_BM] failed to open file, status: %d\n", status);
#endif
    return status;
  }

  // read config values
  u8 current_bookmark = 0;
  char line_buffer[128];
  do {
    status=SEQ_FILE_ReadLine((u8 *)line_buffer, 128);

    if( status > 1 ) {
#if DEBUG_VERBOSE_LEVEL >= 3
      DEBUG_MSG("[SEQ_FILE_BM] read: %s", line_buffer);
#endif

      // sscanf consumes too much memory, therefore we parse directly
      char *separators = " \t";
      char *brkt;
      char *parameter;

      if( (parameter = strtok_r(line_buffer, separators, &brkt)) ) {

	u8 parameter_enabled = 1;
	if( *parameter == '-' ) {
	  parameter_enabled = 0;
	  ++parameter;
	} else if( *parameter == '+' ) {
	  ++parameter;
	}

	if( *parameter == '#' ) {
	  // ignore comments
	} else if( strcmp(parameter, "Slot") == 0 ) {
	  char *word = strtok_r(NULL, separators, &brkt);
	  s32 value = get_dec(word);
	  if( value < 1 || value > SEQ_UI_BOOKMARKS_NUM ) {
#if DEBUG_VERBOSE_LEVEL >= 1
	    DEBUG_MSG("[SEQ_FILE_BM] ERROR invalid Slot number %d\n", value);
#endif
	  } else {
	    current_bookmark = value - 1;
	  }
	} else if( strcmp(parameter, "Name") == 0 ) {
	  //char *word = strtok_r(NULL, separators, &brkt);
	  seq_ui_bookmark_t *bm = &seq_ui_bookmarks[current_bookmark];
	  //strncpy(bm->name, word, 6);
	  //strncpy(bm->name, (char *)&line_buffer+5, 6); // allow spaces...
	  strncpy(bm->name, brkt, 6); // allow spaces...
	} else if( strcmp(parameter, "ParLayer") == 0 ) {
	  char *word = strtok_r(NULL, separators, &brkt);
	  int layer = word[0] - 'A';
	  if( layer < 0 || layer > 16 ) {
#if DEBUG_VERBOSE_LEVEL >= 1
	    DEBUG_MSG("[SEQ_FILE_BM] ERROR invalid ParLayer '%s' in Slot %d\n", word, current_bookmark+1);
#endif
	  } else {
	    seq_ui_bookmark_t *bm = &seq_ui_bookmarks[current_bookmark];
	    bm->par_layer = layer;
	    bm->enable.PAR_LAYER = parameter_enabled;
	  }
	} else if( strcmp(parameter, "TrgLayer") == 0 ) {
	  char *word = strtok_r(NULL, separators, &brkt);
	  int layer = word[0] - 'A';
	  if( layer < 0 || layer > 16 ) {
#if DEBUG_VERBOSE_LEVEL >= 1
	    DEBUG_MSG("[SEQ_FILE_BM] ERROR invalid TrgLayer '%s' in Slot %d\n", word, current_bookmark+1);
#endif
	  } else {
	    seq_ui_bookmark_t *bm = &seq_ui_bookmarks[current_bookmark];
	    bm->trg_layer = layer;
	    bm->enable.TRG_LAYER = parameter_enabled;
	  }
	} else if( strcmp(parameter, "Tracks") == 0 ) {
	  char *word = strtok_r(NULL, separators, &brkt);
	  if( strlen(word) < 16 ) {
#if DEBUG_VERBOSE_LEVEL >= 1
	    DEBUG_MSG("[SEQ_FILE_BM] ERROR invalid Tracks Parameter '%s' in Slot %d\n", word, current_bookmark+1);
#endif
	  } else {
	    seq_ui_bookmark_t *bm = &seq_ui_bookmarks[current_bookmark];
	    bm->tracks = 0;
	    int i;
	    for(i=0; i<16; ++i)
	      if( word[i] == '1' )
		bm->tracks |= (1 << i);
	    bm->enable.TRACKS = parameter_enabled;
	  }
	} else if( strcmp(parameter, "Mutes") == 0 ) {
	  char *word = strtok_r(NULL, separators, &brkt);
	  if( strlen(word) < 16 ) {
#if DEBUG_VERBOSE_LEVEL >= 1
	    DEBUG_MSG("[SEQ_FILE_BM] ERROR invalid Mutes Parameter '%s' in Slot %d\n", word, current_bookmark+1);
#endif
	  } else {
	    seq_ui_bookmark_t *bm = &seq_ui_bookmarks[current_bookmark];
	    bm->mutes = 0;
	    int i;
	    for(i=0; i<16; ++i)
	      if( word[i] == '1' )
		bm->mutes |= (1 << i);
	    bm->enable.MUTES = parameter_enabled;
	  }
	} else {
	  char *word = strtok_r(NULL, separators, &brkt);
	  s32 value = get_dec(word);
	  seq_ui_bookmark_t *bm = &seq_ui_bookmarks[current_bookmark];

	  if( value < 0 ) {
#if DEBUG_VERBOSE_LEVEL >= 1
	    DEBUG_MSG("[SEQ_FILE_BM] ERROR invalid value for parameter '%s' in Slot %d\n", parameter, current_bookmark);
#endif
	  } else if( strcmp(parameter, "Page") == 0 ) {
	    bm->page = value;
	    bm->enable.PAGE = parameter_enabled;
	  } else if( strcmp(parameter, "Group") == 0 ) {
	    bm->group = value - 1;
	    bm->enable.GROUP = parameter_enabled;
	  } else if( strcmp(parameter, "Instrument") == 0 ) {
	    bm->instrument = value - 1;
	    bm->enable.INSTRUMENT = parameter_enabled;
	  } else if( strcmp(parameter, "StepView") == 0 ) {
	    bm->step_view = value - 1;
	    bm->enable.STEP_VIEW = parameter_enabled;
	  } else if( strcmp(parameter, "Step") == 0 ) {
	    bm->step = value - 1;
	    bm->enable.STEP = parameter_enabled;
	  } else if( strcmp(parameter, "EditView") == 0 ) {
	    bm->edit_view = value;
	    bm->enable.EDIT_VIEW = parameter_enabled;
	  } else if( strcmp(parameter, "Solo") == 0 ) {
	    bm->flags.SOLO = value ? 1 : 0;
	    bm->enable.SOLO = parameter_enabled;
	  } else if( strcmp(parameter, "All") == 0 ) {
	    bm->flags.CHANGE_ALL_STEPS = value ? 1 : 0;
	    bm->enable.CHANGE_ALL_STEPS = parameter_enabled;
	  } else if( strcmp(parameter, "Fast") == 0 ) {
	    bm->flags.FAST = value ? 1 : 0;
	    bm->enable.FAST = parameter_enabled;
	  } else if( strcmp(parameter, "Metronome") == 0 ) {
	    bm->flags.METRONOME = value ? 1 : 0;
	    bm->enable.METRONOME = parameter_enabled;
	  } else if( strcmp(parameter, "LoopMode") == 0 ) {
	    bm->flags.LOOP = value ? 1 : 0;
	    bm->enable.LOOP = parameter_enabled;
	  } else if( strcmp(parameter, "FollowMode") == 0 ) {
	    bm->flags.FOLLOW = value ? 1 : 0;
	    bm->enable.FOLLOW = parameter_enabled;
	  } else {
#if DEBUG_VERBOSE_LEVEL >= 1
	    DEBUG_MSG("[SEQ_FILE_HW] ERROR: unknown parameter: %s in Slot %d", line_buffer, current_bookmark);
#endif
	  }
	}
      } else {
#if DEBUG_VERBOSE_LEVEL >= 1
	DEBUG_MSG("[SEQ_FILE_BM] ERROR no space separator in following line: %s", line_buffer);
#endif
      }
    }

  } while( status >= 1 );

  // close file
  status |= SEQ_FILE_ReadClose(&file);

  if( status < 0 ) {
#if DEBUG_VERBOSE_LEVEL >= 1
    DEBUG_MSG("[SEQ_FILE_BM] ERROR while reading file, status: %d\n", status);
#endif
    return SEQ_FILE_BM_ERR_READ;
  }

  // file is valid! :)
  info->valid = 1;

  return 0; // no error
}