Пример #1
0
void InitIOWindow( void )
{
    int                 i;

    MemInitTypes( MAS_IO | MTK_INTEGER, &IOData );
    if( IOData.num_types == 0 ) {
        return;
    }
    IOTypeMenu = WndMustAlloc( IOData.num_types * sizeof( *IOTypeMenu ) );
    for( i = 0; i < IOData.num_types; ++i ) {
        IOTypeMenu[i].id = MENU_IO_FIRST_TYPE + i;
        IOTypeMenu[i].style = GUI_STYLE_MENU_ENABLED | WND_MENU_ALLOCATED;
        IOTypeMenu[i].label = DupStr( IOData.labels[i] );
        IOTypeMenu[i].hinttext = DupStr( LIT_ENG( Empty ) );
        IOTypeMenu[i].child_num_items = 0;
        IOTypeMenu[i].child = NULL;
    }
    for( i = 0; i < ArraySize( IOMenu ); ++i ) {
        if( IOMenu[i].id == MENU_IO_TYPE ) {
            IOMenu[i].child = IOTypeMenu;
            IOMenu[i].child_num_items = IOData.num_types;
            break;
        }
    }
}
Пример #2
0
static void RepInitEv( event_record *ev )
{
    DIPHDL( cue, ch );
    if( ev->cue == NULL ) {
        if( DeAliasAddrCue( NO_MOD, ev->ip, ch ) != SR_NONE ) {
            ev->cue = CopySourceLine( ch );
        }
        if( ev->cue == NULL ) {
            UnAsm( ev->ip, TxtBuff, TXT_LEN );
            ev->cue = DupStr( TxtBuff );
        }
    }
    if( ev->addr_string == NULL ) {
        ev->addr_string = DupStr( GetEventAddress( ev ) );
    }
}
Пример #3
0
bool BreakWrite( address addr, mad_type_handle th, const char *comment )
{
    brkp                *bp;
    mad_type_info       mti;
    bool                ok_to_try = true;

    if( IS_BP_EXECUTE( th ) )
        return( false );
    MADTypeInfo( th, &mti );
    switch( mti.b.bits / BITS_PER_BYTE ) {
    case 8:
        if( !Is8ByteBreakpointsSupported() ) {
            ok_to_try = false;
        }
        // fall down
    case 1:
    case 2:
    case 4:
        if( ok_to_try ) {
            if(  FindBreak( addr ) != NULL ) {
                Error( ERR_NONE, LIT_ENG( ERR_POINT_EXISTS ) );
            }
            bp = AddPoint( addr, th, false );
            if( bp == NULL )
                return( true );
            bp->source_line = DupStr( comment );
            RecordBreakEvent( bp, B_SET );
            return( true );
        }
        // fall down
    default:
        return( false );
    }
}
Пример #4
0
bool BreakWrite( address addr, mad_type_handle th, char *comment )
{
    brkp                *bp;
    mad_type_info       mti;
    bool                ok_to_try = TRUE;
    if( th == MAD_NIL_TYPE_HANDLE ) return( FALSE );
    MADTypeInfo( th, &mti );
    switch( mti.b.bits / BITS_PER_BYTE ) {
    case 8:
        if( !Supports8ByteBreakpoints )
            ok_to_try = FALSE;
    case 1:
    case 2:
    case 4:
        if( ok_to_try ) {
            if(  FindBreak( addr ) != NULL ) {
                Error( ERR_NONE, LIT( ERR_POINT_EXISTS ) );
            }
            bp = AddPoint( addr, th, FALSE );
            if( bp == NULL ) return( TRUE );
            bp->source_line = DupStr( comment );
            RecordBreakEvent( bp, B_SET );
            return( TRUE );
        }
    default:
        return( FALSE );
    }
}
Пример #5
0
void ProcCmd( void )
{
    char        buff[TXT_LEN];
    unsigned    screen_mem;
    size_t      have_env;
    int         pass;

    MemSize = MIN_MEM_SIZE;
    TrapParms = NULL;
    _SwitchOn( SW_LOAD_SYMS );
    _SwitchOn( SW_USE_MOUSE );
    ProcSysOptInit();
    DUIScreenOptInit();

    have_env = DUIEnvLkup( EXENAME, buff, sizeof( buff ) );
    for( pass = 1; pass <= 2; ++pass ) {
        if( have_env ) {
            GetArg = &GetEnvArg;
            CurrArgc = 0;
            CurrArgp = buff;
            ProcOptList( pass );
            if( CurrChar != ARG_TERMINATE ) {
                OptError( LIT_ENG( STARTUP_Expect_End_Env_Str ) );
            }
        }
        GetArg = &GetCmdArg;
        CurrArgc = 0;
        CurrArgp = GetCmdArg( 0 );
        if( CurrArgp != NULL ) {
            ProcOptList( pass );
            if( pass == 2 ) {
                SetCmdArgStart( CurrArgc, CurrArgp );
            }
        }
        if( pass == 1 ) {
            screen_mem = DUIConfigScreen();
            if( MemSize + screen_mem >= MemSize ) {
                MemSize += screen_mem;
            } else {
                MemSize = ~0;
            }
            SysSetMemLimit();
            TrapParms = DupStr( "std" );
            InvokeFile = DupStr( "" );
        }
    }
}
Пример #6
0
/*
 * GetFileName -- get filename from command line
 */
char *GetFileName( int pass )
{
    char        buff[CMD_LEN];

    WantEquals();
    GetItem( buff );
    return( pass == 1 ? NULL : DupStr( buff ) );
}
Пример #7
0
CHAR *S69_LoadTitle(void)
{
	CHAR s[36];

	_mm_fseek(modreader,2,SEEK_SET);
	if(!_mm_read_UBYTES(s,36,modreader)) return NULL;

	return(DupStr(s,36,1));
}
Пример #8
0
static CHAR *STX_LoadTitle(void)
{
	CHAR s[28];

	_mm_fseek(modreader,0,SEEK_SET);
	if(!_mm_read_UBYTES(s,20,modreader)) return NULL;

	return(DupStr(s,28,1));
}
Пример #9
0
CHAR *DSM_LoadTitle(void)
{
   CHAR s[28];

   _mm_fseek(modfp,12,SEEK_SET);
   if(!_mm_fread(s,28,1,modfp)) return NULL;
   
   return(DupStr(s,28));
}
Пример #10
0
CHAR *DSM_LoadTitle(void)
{
	CHAR s[28];

	_mm_fseek(modreader,12,SEEK_SET);
	if(!_mm_read_UBYTES(s,28,modreader)) return NULL;
   
	return(DupStr(s,28,1));
}
Пример #11
0
static void     ImgMenuItem( a_window *wnd, gui_ctl_id id, int row, int piece )
{
    image_entry *img;
    char        *new_name;
    char        *old_name;

    piece=piece;
    img = ImgGetImage( row );
    switch( id ) {
    case MENU_INITIALIZE:
        WndMenuGrayAll( wnd );
        if( img != NULL ) {
            if( img->dip_handle == NO_MOD ) {
                WndMenuEnable( wnd, MENU_IMAGE_ADD_SYMBOLS, TRUE );
            } else {
                WndMenuEnableAll( wnd );
            }
        }
        break;
    case MENU_IMAGE_ADD_SYMBOLS:
        // nyi - change sym_file
        if( img->deferred_symbols ) {
            ReLoadSymInfo( img );
        } else {
            new_name = DupStr( ImgSymName( img, TRUE ) );
            if( !SymBrowse( &new_name ) ) {
                _Free( new_name );
            } else {
                UnLoadSymInfo( img, TRUE );
                old_name = img->sym_name;
                img->sym_name = new_name;
                if( ReLoadSymInfo( img ) ) {
                    _Free( old_name );
                } else {
                    img->sym_name = old_name;
                    _Free( new_name );
                }
            }
        }
        ImgInit( wnd );
        break;
    case MENU_IMAGE_DEL_SYMBOLS:
        UnLoadSymInfo( img, TRUE );
        ImgInit( wnd );
        break;
    case MENU_IMAGE_SHOW_FUNCTIONS:
        WndGblFuncInspect( img->dip_handle );
        break;
    case MENU_IMAGE_SHOW_MODULES:
        WndModListInspect( img->dip_handle );
        break;
    case MENU_IMAGE_SHOW_GLOBALS:
        WndGblVarInspect( img->dip_handle );
        break;
    }
}
Пример #12
0
char *CopySourceLine( cue_handle *ch )
{
    char        *p;
    char        *source_line;

    if( !DUIGetSourceLine( ch, TxtBuff, TXT_LEN ) ) return( NULL );
    for( p = TxtBuff; *p == ' '; ++p ) ;
    source_line = DupStr( p );
    return( source_line );
}
Пример #13
0
static CHAR *GT2_LoadTitle(void)
{
	CHAR title[33];

	_mm_fseek(modreader, 8, SEEK_SET);
	if (!_mm_read_UBYTES(title, 32, modreader))
		return NULL;
	title[32] = 0;

	return (DupStr(title, 32, 1));
}
Пример #14
0
void DlgList( const char *title, void (*clear)(void), void (*add)(const char *,unsigned),
                           char_ring *(*next)(char_ring *), char *(*name)(char_ring *) )
{
    dlg_list dlg;
    dlg.clear = clear;
    dlg.add = add;
    dlg.next = next;
    dlg.name = name;
    dlg.title = DupStr( title );
    ResDlgOpen( &SourceEvent, &dlg, GUI_MAKEINTRESOURCE( DIALOG_LIST ) );
}
Пример #15
0
void SetBPCondition( brkp *bp, const char *condition )
{
    if( bp->condition != NULL ) {
        _Free( bp->condition );
    }
    if( condition == NULL || condition[0] == '\0' ) {
        bp->condition = NULL;
    } else {
        bp->condition = DupStr( condition );
    }
    bp->status.b.use_condition = ( bp->condition != NULL );
}
Пример #16
0
BaseRec::BaseRec(const DZStrW &base)
{
    DZStrW tmp(base);
    TCHAR lc = tmp.LastChar();

    if (lc != _T(':') && lc != BSLASH)
        tmp += BSLASH;

	Base = DupStr(tmp);

	Next = NULL;
}
Пример #17
0
/* Read sample information */
static BOOL OKT_doSAMP(int len)
{
	int t;
	SAMPLE *q;
	OKTSAMPLE s;

	of.numins = of.numsmp = (len / 0x20);
	if (!AllocSamples())
		return 0;

	for (t = 0, q = of.samples; t < of.numins; t++, q++) {
		_mm_read_UBYTES(s.sampname, 20, modreader);
		s.len = _mm_read_M_ULONG(modreader);
		s.loopbeg = _mm_read_M_UWORD(modreader);
		s.looplen = _mm_read_M_UWORD(modreader);
		_mm_read_UBYTE(modreader);
		s.volume = _mm_read_UBYTE(modreader);
		_mm_read_M_UWORD(modreader);

		if (_mm_eof(modreader)) {
			_mm_errno = MMERR_LOADING_SAMPLEINFO;
			return 0;
		}

		if (!s.len)
			q->seekpos = q->length = q->loopstart = q->loopend = q->flags = 0;
		else {
			s.len--;
			/* sanity checks */
			if (s.loopbeg > s.len)
				s.loopbeg = s.len;
			if (s.loopbeg + s.looplen > s.len)
				s.looplen = s.len - s.loopbeg;
			if (s.looplen < 2)
				s.looplen = 0;

			q->length = s.len;
			q->loopstart = s.loopbeg;
			q->loopend = s.looplen + q->loopstart;
			q->volume = s.volume;
			q->flags = SF_SIGNED;

			if (s.looplen)
				q->flags |= SF_LOOP;
		}
		q->samplename = DupStr(s.sampname, 20, 1);
		q->speed = 8363;
	}
	return 1;
}
Пример #18
0
void DlgCmd( void )
{
    char        buff[256];

    printf( "DBG>" );
    fflush( stdout );   // not really necessary
    gets( buff );
    if( buff[0] != NULLCHAR && buff[1] == NULLCHAR ) {
        switch( tolower( buff[0] ) ) {
        case 'u':
            WndAsmInspect( GetCodeDot() );
            break;
        case 's':
            DumpSource();
            break;
        case 'l':
            DumpLocals();
            break;
        case 'i':
            RunRequest( REQ_TRACE_INTO );
            break;
        case 'o':
            RunRequest( REQ_TRACE_OVER );
            break;
        case 'g':
            RunRequest( REQ_GO );
            break;
        case 'x':
            if( _IsOn( SW_REMOTE_LINK ) ) {
                printf( "Can't break remote task!\n" );
            } else {
                HMODULE hmod;
                PFN     proc = NULL;

                DosQueryModuleHandle( TrapParms, &hmod );
                DosQueryProcAddr( hmod, 5, 0, &proc );
//                if( proc != NULL )
//                    proc();
            }
            // break the task
            break;
        default:
            printf( "Error - unrecognized command\n" );
        }
    } else {
        DoCmd( DupStr( buff ) );
        DoInput();
    }
}
Пример #19
0
void DlgCmd( void )
{
    char        buff[256];

    printf( "DBG>" );
    fflush( stdout );
    gets( buff );
    if( buff[0] != NULLCHAR && buff[1] == NULLCHAR ) {
        switch( tolower( buff[0] ) ) {
        case 'u':
            WndAsmInspect( GetCodeDot() );
            break;
        case 's':
            DumpSource();
            break;
        case 'l':
            DumpLocals();
            break;
        case 'i':
            RunRequest( REQ_TRACE_INTO );
            break;
        case 'o':
            RunRequest( REQ_TRACE_OVER );
            break;
        case 'g':
            RunRequest( REQ_GO );
            break;
        case 'x':
            if( _IsOn( SW_REMOTE_LINK ) ) {
                printf( "Can't break remote task!\n" );
            } else {
                HANDLE hmod;
                FARPROC proc;
                hmod = GetModuleHandle( TrapParms );
                proc = GetProcAddress( hmod, (LPSTR)5 );
                if( proc != NULL ) proc();
                CloseHandle( hmod );
            }
            // break the task
            break;
        default:
            printf( "Error - unrecognized command\n" );
        }
    } else {
        DoCmd( DupStr( buff ) );
        DoInput();
    }
}
Пример #20
0
bool UnMapAddress( mappable_addr *loc, image_entry *image )
{
    map_entry           *map;
    mod_handle          himage;

    if( image == NULL ) {
        if( DeAliasAddrMod( loc->addr, &himage ) == SR_NONE )
            return( false );
        image = ImageEntry( himage );
    }
    if( image == NULL )
        return( false );
    DbgFree( loc->image_name );
    loc->image_name = DupStr( image->image_name );
    for( map = image->map_list; map != NULL; map = map->link ) {
        if( map->real_addr.segment == loc->addr.mach.segment ) {
            loc->addr.mach.segment = map->map_addr.segment;
            loc->addr.mach.offset = loc->addr.mach.offset - map->real_addr.offset;
            return( true );
        }
    }
    return( false );
}
Пример #21
0
/**
 * Read the UnicodeData.txt file.
 * @returns 0 on success.
 * @returns !0 on failure.
 * @param   pszBasePath         The base path, can be NULL.
 * @param   pszFilename         The name of the file.
 */
static int ReadUnicodeData(const char *pszBasePath, const char *pszFilename)
{
    /*
     * Open input.
     */
    FILE *pFile = OpenFile(pszBasePath, pszFilename);
    if (!pFile)
        return 1;

    /*
     * Parse the input and spit out the output.
     */
    char szLine[4096];
    RTUNICP i = 0;
    while (GetLineFromFile(szLine, sizeof(szLine), pFile) != NULL)
    {
        if (IsCommentOrBlankLine(szLine))
            continue;

        char *pszCurField;
        char *pszCodePoint = FirstField(&pszCurField, StripLine(szLine)); /* 0 */
        char *pszName = NextField(&pszCurField);                          /* 1 */
        char *pszGeneralCategory = NextField(&pszCurField);               /* 2 */
        char *pszCanonicalCombiningClass = NextField(&pszCurField);       /* 3 */
        char *pszBidiClass = NextField(&pszCurField);                     /* 4 */
        char *pszDecompositionType = NextField(&pszCurField);             /* 5 */
        char *pszDecompositionMapping = SplitDecompField(&pszDecompositionType);
        char *pszNumericType = NextField(&pszCurField);                   /* 6 */
        char *pszNumericValueD = NextField(&pszCurField);                 /* 7 */
        char *pszNumericValueN = NextField(&pszCurField);                 /* 8 */
        char *pszBidiMirrored = NextField(&pszCurField);                  /* 9 */
        char *pszUnicode1Name = NextField(&pszCurField);                  /* 10 */
        char *pszISOComment = NextField(&pszCurField);                    /* 11 */
        char *pszSimpleUpperCaseMapping = NextField(&pszCurField);        /* 12 */
        char *pszSimpleLowerCaseMapping = NextField(&pszCurField);        /* 13 */
        char *pszSimpleTitleCaseMapping = NextField(&pszCurField);        /* 14 */

        RTUNICP CodePoint = ToNum(pszCodePoint);
        if (CodePoint >= RT_ELEMENTS(g_aCPInfo))
        {
            ParseError("U+05X is out of range\n", CodePoint);
            continue;
        }

        /* catchup? */
        while (i < CodePoint)
            NullEntry(i++);
        if (i != CodePoint)
        {
            ParseError("i=%d CodePoint=%u\n", i, CodePoint);
            CloseFile(pFile);
            return 1;
        }

        /* this one */
        g_aCPInfo[i].CodePoint = i;
        g_aCPInfo[i].fNullEntry = 0;
        g_aCPInfo[i].pszName                    = DupStr(pszName);
        g_aCPInfo[i].SimpleUpperCaseMapping     = ToNumDefault(pszSimpleUpperCaseMapping, CodePoint);
        g_aCPInfo[i].SimpleLowerCaseMapping     = ToNumDefault(pszSimpleLowerCaseMapping, CodePoint);
        g_aCPInfo[i].SimpleTitleCaseMapping     = ToNumDefault(pszSimpleTitleCaseMapping, CodePoint);
        g_aCPInfo[i].CanonicalCombiningClass    = ToNum(pszCanonicalCombiningClass);
        g_aCPInfo[i].pszDecompositionType       = DupStr(pszDecompositionType);
        g_aCPInfo[i].paDecompositionMapping     = ToMapping(pszDecompositionMapping, &g_aCPInfo[i].cDecompositionMapping, 20);
        g_aCPInfo[i].pszGeneralCategory         = DupStr(pszGeneralCategory);
        g_aCPInfo[i].pszBidiClass               = DupStr(pszBidiClass);
        g_aCPInfo[i].pszNumericType             = DupStr(pszNumericType);
        g_aCPInfo[i].pszNumericValueD           = DupStr(pszNumericValueD);
        g_aCPInfo[i].pszNumericValueN           = DupStr(pszNumericValueN);
        g_aCPInfo[i].pszBidiMirrored            = DupStr(pszBidiMirrored);
        g_aCPInfo[i].pszUnicode1Name            = DupStr(pszUnicode1Name);
        g_aCPInfo[i].pszISOComment              = DupStr(pszISOComment);
        i++;
    }

    /* catchup? */
    while (i < RT_ELEMENTS(g_aCPInfo))
        NullEntry(i++);
    CloseFile(pFile);

    return 0;
}
Пример #22
0
static BOOL ULT_Load(BOOL curious)
{
    int t,u,tracks=0;
    SAMPLE *q;
    ULTSAMPLE s;
    ULTHEADER mh;
    UBYTE nos,noc,nop;

    /* try to read module header */
    _mm_read_string(mh.id,15,modreader);
    _mm_read_string(mh.songtitle,32,modreader);
    mh.reserved=_mm_read_UBYTE(modreader);

    if(_mm_eof(modreader)) {
        _mm_errno = MMERR_LOADING_HEADER;
        return 0;
    }

    ULT_Version[ULT_VERSION_LEN-1]='3'+(mh.id[14]-'1');
    of.modtype   = DupStr(ULT_Version,ULT_VERSION_LEN,1);
    of.initspeed = 6;
    of.inittempo = 125;
    of.reppos    = 0;

    /* read songtext */
    if ((mh.id[14]>'1')&&(mh.reserved))
        if(!ReadLinedComment(mh.reserved * 32, 32)) return 0;

    nos=_mm_read_UBYTE(modreader);
    if(_mm_eof(modreader)) {
        _mm_errno = MMERR_LOADING_HEADER;
        return 0;
    }

    of.songname=DupStr(mh.songtitle,32,1);
    of.numins=of.numsmp=nos;

    if(!AllocSamples()) return 0;
    q = of.samples;
    for(t=0; t<nos; t++) {
        /* try to read sample info */
        _mm_read_string(s.samplename,32,modreader);
        _mm_read_string(s.dosname,12,modreader);
        s.loopstart     =_mm_read_I_ULONG(modreader);
        s.loopend       =_mm_read_I_ULONG(modreader);
        s.sizestart     =_mm_read_I_ULONG(modreader);
        s.sizeend       =_mm_read_I_ULONG(modreader);
        s.volume        =_mm_read_UBYTE(modreader);
        s.flags         =_mm_read_UBYTE(modreader);
        s.speed         =(mh.id[14]>='4')?_mm_read_I_UWORD(modreader):8363;
        s.finetune      =_mm_read_I_SWORD(modreader);

        if(_mm_eof(modreader)) {
            _mm_errno = MMERR_LOADING_SAMPLEINFO;
            return 0;
        }

        q->samplename=DupStr(s.samplename,32,1);
        /* The correct formula for the coefficient would be
           pow(2,(double)s.finetume/OCTAVE/32768), but to avoid floating point
           here, we'll use a first order approximation here.
           1/567290 == Ln(2)/OCTAVE/32768 */
        q->speed=s.speed+s.speed*(((SLONG)s.speed*(SLONG)s.finetune)/567290);
        q->length    = s.sizeend-s.sizestart;
        q->volume    = s.volume>>2;
        q->loopstart = s.loopstart;
        q->loopend   = s.loopend;
        q->flags = SF_SIGNED;
        if(s.flags&ULTS_LOOP) q->flags|=SF_LOOP;
        if(s.flags&ULTS_16BITS) {
            s.sizeend+=(s.sizeend-s.sizestart);
            s.sizestart<<=1;
            q->flags|=SF_16BITS;
            q->loopstart>>=1;
            q->loopend>>=1;
        }
        q++;
    }
Пример #23
0
static BOOL MTM_Load(void)
{
    MTMSAMPLE s;
    INSTRUMENT *d;
    SAMPLE *q;

    int t,u;

    /* try to read module header */

    _mm_read_UBYTES(mh_mtm->id,3);
    mh_mtm->version		=_mm_read_UBYTE();
    _mm_read_str(mh_mtm->songname,20);
    mh_mtm->numtracks	=_mm_read_I_UWORD();
    mh_mtm->lastpattern	=_mm_read_UBYTE();
    mh_mtm->lastorder	=_mm_read_UBYTE();
    mh_mtm->commentsize	=_mm_read_I_UWORD();
    mh_mtm->numsamples	=_mm_read_UBYTE();
    mh_mtm->attribute	=_mm_read_UBYTE();
    mh_mtm->beatspertrack=_mm_read_UBYTE();
    mh_mtm->numchannels	=_mm_read_UBYTE();
    _mm_read_UBYTES(mh_mtm->panpos,32);

    if(modpos > modsize) {
        gModPlayerErrorMessage=ERROR_LOADING_HEADER;
        return 0;
    }

    /* set module variables */

    of.initspeed=6;
    of.inittempo=125;
    of.modtype=strdup(MTM_Version);
    of.numchn=mh_mtm->numchannels;
    of.numtrk=mh_mtm->numtracks+1;                              /* get number of channels */
    of.songname=DupStr(mh_mtm->songname,20);    /* make a cstr of songname */
    of.numpos=mh_mtm->lastorder+1;              /* copy the songlength */
    of.numpat=mh_mtm->lastpattern+1;
    for(t=0; t<32; t++) of.panning[t]=mh_mtm->panpos[t]<<4;

    of.numins=mh_mtm->numsamples;
    if(!AllocInstruments()) return 0;

    d=of.instruments;

    for(t=0; t<of.numins; t++) {

        d->numsmp=1;
        if(!AllocSamples(d)) return 0;
        q=d->samples;

        /* try to read sample info */

        _mm_read_str(s.samplename,22);
        s.length	=_mm_read_I_ULONG();
        s.reppos	=_mm_read_I_ULONG();
        s.repend	=_mm_read_I_ULONG();
        s.finetune	=_mm_read_UBYTE();
        s.volume	=_mm_read_UBYTE();
        s.attribute	=_mm_read_UBYTE();

        if(modpos > modsize) {
            gModPlayerErrorMessage=ERROR_LOADING_SAMPLEINFO;
            return 0;
        }

        d->insname=DupStr(s.samplename,22);
        q->seekpos=0;
        q->c2spd=finetune[s.finetune];
        q->length=s.length;
        q->loopstart=s.reppos;
        q->loopend=s.repend;
        q->volume=s.volume;

        q->flags=0;

        if(s.repend-s.reppos>2) q->flags|=SF_LOOP;      /* <- 1.00 bugfix */

        if(s.attribute&1) {

            /* If the sample is 16-bits, convert the length
               and replen byte-values into sample-values */

            q->flags|=SF_16BITS;
            q->length>>=1;
            q->loopstart>>=1;
            q->loopend>>=1;
        }

        d++;
    }
Пример #24
0
BOOL 
FAR_Load (BOOL curious)
{
  int t, u, tracks = 0;
  SAMPLE *q;
  FARSAMPLE s;
  FARNOTE *crow;
  UBYTE smap[8];

  /* try to read module header (first part) */
  _mm_read_UBYTES (mh1->id, 4, modreader);
  _mm_read_SBYTES (mh1->songname, 40, modreader);
  _mm_read_SBYTES (mh1->blah, 3, modreader);
  mh1->headerlen = _mm_read_I_UWORD (modreader);
  mh1->version = _mm_read_UBYTE (modreader);
  _mm_read_UBYTES (mh1->onoff, 16, modreader);
  _mm_read_UBYTES (mh1->edit1, 9, modreader);
  mh1->speed = _mm_read_UBYTE (modreader);
  _mm_read_UBYTES (mh1->panning, 16, modreader);
  _mm_read_UBYTES (mh1->edit2, 4, modreader);
  mh1->stlen = _mm_read_I_UWORD (modreader);

  /* init modfile data */
  of.modtype = strdup (FAR_Version);
  of.songname = DupStr (mh1->songname, 40, 1);
  of.numchn = 16;
  of.initspeed = mh1->speed;
  of.inittempo = 80;
  of.reppos = 0;
  for (t = 0; t < 16; t++)
    of.panning[t] = mh1->panning[t] << 4;

  /* read songtext into comment field */
  if (mh1->stlen)
    if (!ReadComment (mh1->stlen))
      return 0;

  /* try to read module header (second part) */
  _mm_read_UBYTES (mh2->orders, 256, modreader);
  mh2->numpat = _mm_read_UBYTE (modreader);
  mh2->snglen = _mm_read_UBYTE (modreader);
  mh2->loopto = _mm_read_UBYTE (modreader);
  _mm_read_I_UWORDS (mh2->patsiz, 256, modreader);

  of.numpos = mh2->snglen;
  if (!AllocPositions (of.numpos))
    return 0;
  for (t = 0; t < of.numpos; t++)
    {
      if (mh2->orders[t] == 0xff)
	break;
      of.positions[t] = mh2->orders[t];
    }

  /* count number of patterns stored in file */
  of.numpat = 0;
  for (t = 0; t < 256; t++)
    if (mh2->patsiz[t])
      if ((t + 1) > of.numpat)
	of.numpat = t + 1;
  of.numtrk = of.numpat * of.numchn;

  /* seek across eventual new data */
  _mm_fseek (modreader, mh1->headerlen - (869 + mh1->stlen), SEEK_CUR);

  /* alloc track and pattern structures */
  if (!AllocTracks ())
    return 0;
  if (!AllocPatterns ())
    return 0;

  for (t = 0; t < of.numpat; t++)
    {
      UBYTE rows = 0;

      memset (pat, 0, 256 * 16 * 4 * sizeof (FARNOTE));
      if (mh2->patsiz[t])
	{
	  rows = _mm_read_UBYTE (modreader);
	  /* tempo = */ _mm_read_UBYTE (modreader);

	  crow = pat;
	  /* file often allocates 64 rows even if there are less in pattern */
	  if (mh2->patsiz[t] < 2 + (rows * 16 * 4))
	    {
	      _mm_errno = MMERR_LOADING_PATTERN;
	      return 0;
	    }
	  for (u = (mh2->patsiz[t] - 2) / 4; u; u--, crow++)
	    {
	      crow->note = _mm_read_UBYTE (modreader);
	      crow->ins = _mm_read_UBYTE (modreader);
	      crow->vol = _mm_read_UBYTE (modreader);
	      crow->eff = _mm_read_UBYTE (modreader);
	    }

	  if (_mm_eof (modreader))
	    {
	      _mm_errno = MMERR_LOADING_PATTERN;
	      return 0;
	    }

	  crow = pat;
	  of.pattrows[t] = rows;
	  for (u = 16; u; u--, crow++)
	    if (!(of.tracks[tracks++] = FAR_ConvertTrack (crow, rows)))
	      {
		_mm_errno = MMERR_LOADING_PATTERN;
		return 0;
	      }
	}
      else
	tracks += 16;
    }

  /* read sample map */
  if (!_mm_read_UBYTES (smap, 8, modreader))
    {
      _mm_errno = MMERR_LOADING_HEADER;
      return 0;
    }

  /* count number of samples used */
  of.numins = 0;
  for (t = 0; t < 64; t++)
    if (smap[t >> 3] & (1 << (t & 7)))
      of.numins = t + 1;
  of.numsmp = of.numins;

  /* alloc sample structs */
  if (!AllocSamples ())
    return 0;

  q = of.samples;
  for (t = 0; t < of.numsmp; t++)
    {
      q->speed = 8363;
      q->flags = SF_SIGNED;
      if (smap[t >> 3] & (1 << (t & 7)))
	{
	  _mm_read_SBYTES (s.samplename, 32, modreader);
	  s.length = _mm_read_I_ULONG (modreader);
	  s.finetune = _mm_read_UBYTE (modreader);
	  s.volume = _mm_read_UBYTE (modreader);
	  s.reppos = _mm_read_I_ULONG (modreader);
	  s.repend = _mm_read_I_ULONG (modreader);
	  s.type = _mm_read_UBYTE (modreader);
	  s.loop = _mm_read_UBYTE (modreader);

	  q->samplename = DupStr (s.samplename, 32, 1);
	  q->length = s.length;
	  q->loopstart = s.reppos;
	  q->loopend = s.repend;
	  q->volume = s.volume << 2;

	  if (s.type & 1)
	    q->flags |= SF_16BITS;
	  if (s.loop & 8)
	    q->flags |= SF_LOOP;

	  q->seekpos = _mm_ftell (modreader);
	  _mm_fseek (modreader, q->length, SEEK_CUR);
	}
      else
	q->samplename = DupStr (NULL, 0, 0);
      q++;
    }
Пример #25
0
BOOL IT_Load(BOOL curious)
{
	int t,u,lp;
	INSTRUMENT *d;
	SAMPLE *q;
	BOOL compressed=0;

	numtrk=0;
	filters=0;

	/* try to read module header */
	_mm_read_I_ULONG(modreader);	/* kill the 4 byte header */
	_mm_read_string(mh->songname,26,modreader);
	_mm_read_UBYTES(mh->blank01,2,modreader);
	mh->ordnum      =_mm_read_I_UWORD(modreader);
	mh->insnum      =_mm_read_I_UWORD(modreader);
	mh->smpnum      =_mm_read_I_UWORD(modreader);
	mh->patnum      =_mm_read_I_UWORD(modreader);
	mh->cwt         =_mm_read_I_UWORD(modreader);
	mh->cmwt        =_mm_read_I_UWORD(modreader);
	mh->flags       =_mm_read_I_UWORD(modreader);
	mh->special     =_mm_read_I_UWORD(modreader);
	mh->globvol     =_mm_read_UBYTE(modreader);
	mh->mixvol      =_mm_read_UBYTE(modreader);
	mh->initspeed   =_mm_read_UBYTE(modreader);
	mh->inittempo   =_mm_read_UBYTE(modreader);
	mh->pansep      =_mm_read_UBYTE(modreader);
	mh->zerobyte    =_mm_read_UBYTE(modreader);
	mh->msglength   =_mm_read_I_UWORD(modreader);
	mh->msgoffset   =_mm_read_I_ULONG(modreader);
	_mm_read_UBYTES(mh->blank02,4,modreader);
	_mm_read_UBYTES(mh->pantable,64,modreader);
	_mm_read_UBYTES(mh->voltable,64,modreader);

	if(_mm_eof(modreader)) {
		_mm_errno=MMERR_LOADING_HEADER;
		return 0;
	}

	/* set module variables */
	of.songname    = DupStr(mh->songname,26,0); /* make a cstr of songname  */
	of.reppos      = 0;
	of.numpat      = mh->patnum;
	of.numins      = mh->insnum;
	of.numsmp      = mh->smpnum;
	of.initspeed   = mh->initspeed;
	of.inittempo   = mh->inittempo;
	of.initvolume  = mh->globvol;
	of.flags      |= UF_BGSLIDES|UF_ARPMEM;

	if(mh->songname[25]) {
		of.numvoices=1+mh->songname[25];
#ifdef MIKMOD_DEBUG
		fprintf(stderr,"Embedded IT limitation to %d voices\n",of.numvoices);
#endif
	}

	/* set the module type */
	/* 2.17 : IT 2.14p4 */
	/* 2.16 : IT 2.14p3 with resonant filters */
	/* 2.15 : IT 2.14p3 (improved compression) */
	if((mh->cwt<=0x219)&&(mh->cwt>=0x217))
		of.modtype=strdup(IT_Version[mh->cmwt<0x214?4:5]);
	else if (mh->cwt>=0x215)
		of.modtype=strdup(IT_Version[mh->cmwt<0x214?2:3]);
	else {
		of.modtype     = strdup(IT_Version[mh->cmwt<0x214?0:1]);
		of.modtype[mh->cmwt<0x214?15:26] = (mh->cwt>>8)+'0';
		of.modtype[mh->cmwt<0x214?17:28] = ((mh->cwt>>4)&0xf)+'0';
		of.modtype[mh->cmwt<0x214?18:29] = ((mh->cwt)&0xf)+'0';
	}

	if(mh->flags&8)
		of.flags|=(UF_XMPERIODS | UF_LINEAR);

	if((mh->cwt>=0x106)&&(mh->flags&16))
		old_effect=1;
	else
		old_effect=0;

	/* set panning positions */
	for(t=0;t<64;t++) {
		mh->pantable[t]&=0x7f;
		if(mh->pantable[t]<64)
			of.panning[t]=mh->pantable[t]<<2;
		else if(mh->pantable[t]==64)
			of.panning[t]=255;
		else if(mh->pantable[t]==100)
			of.panning[t]=PAN_SURROUND;
		else if(mh->pantable[t]==127)
			of.panning[t]=PAN_CENTER;
		else {
			_mm_errno=MMERR_LOADING_HEADER;
			return 0;
		}
	}

	/* set channel volumes */
	memcpy(of.chanvol,mh->voltable,64);

	/* read the order data */
	if(!AllocPositions(mh->ordnum)) return 0;
	if(!(origpositions=_mm_calloc(mh->ordnum,sizeof(UWORD)))) return 0;

	for(t=0;t<mh->ordnum;t++) {
		origpositions[t]=_mm_read_UBYTE(modreader);
		if((origpositions[t]>mh->patnum)&&(origpositions[t]<254))
			origpositions[t]=255;
	}

	if(_mm_eof(modreader)) {
		_mm_errno = MMERR_LOADING_HEADER;
		return 0;
	}

	poslookupcnt=(UBYTE)mh->ordnum;
	S3MIT_CreateOrders(curious);

	if(!(paraptr=(ULONG*)_mm_malloc((mh->insnum+mh->smpnum+of.numpat)*
	                               sizeof(ULONG)))) return 0;

	/* read the instrument, sample, and pattern parapointers */
	_mm_read_I_ULONGS(paraptr,mh->insnum+mh->smpnum+of.numpat,modreader);

	if(_mm_eof(modreader)) {
		_mm_errno = MMERR_LOADING_HEADER;
		return 0;
	}

	/* Check for and load midi information for resonant filters */
	if(mh->cmwt>=0x216) {
		if(mh->special&8) {
			IT_LoadMidiConfiguration(modreader);
			if(_mm_eof(modreader)) {
				_mm_errno = MMERR_LOADING_HEADER;
				return 0;
			}
		} else
			IT_LoadMidiConfiguration(NULL);
		filters=1;
	}

	/* Check for and load song comment */
	if((mh->special&1)&&(mh->cwt>=0x104)&&(mh->msglength)) {
		_mm_fseek(modreader,(long)(mh->msgoffset),SEEK_SET);
		if(!ReadComment(mh->msglength)) return 0;
	}

	if(!(mh->flags&4)) of.numins=of.numsmp;
	if(!AllocSamples()) return 0;

	if(!AllocLinear()) return 0;

	/* Load all samples */
	q = of.samples;
	for(t=0;t<mh->smpnum;t++) {
		ITSAMPLE s;

		/* seek to sample position */
		_mm_fseek(modreader,(long)(paraptr[mh->insnum+t]+4),SEEK_SET);

		/* load sample info */
		_mm_read_string(s.filename,12,modreader);
		s.zerobyte    = _mm_read_UBYTE(modreader);
		s.globvol     = _mm_read_UBYTE(modreader);
		s.flag        = _mm_read_UBYTE(modreader);
		s.volume      = _mm_read_UBYTE(modreader);
		_mm_read_string(s.sampname,26,modreader);
		s.convert     = _mm_read_UBYTE(modreader);
		s.panning     = _mm_read_UBYTE(modreader);
		s.length      = _mm_read_I_ULONG(modreader);
		s.loopbeg     = _mm_read_I_ULONG(modreader);
		s.loopend     = _mm_read_I_ULONG(modreader);
		s.c5spd       = _mm_read_I_ULONG(modreader);
		s.susbegin    = _mm_read_I_ULONG(modreader);
		s.susend      = _mm_read_I_ULONG(modreader);
		s.sampoffset  = _mm_read_I_ULONG(modreader);
		s.vibspeed    = _mm_read_UBYTE(modreader);
		s.vibdepth    = _mm_read_UBYTE(modreader);
		s.vibrate     = _mm_read_UBYTE(modreader);
		s.vibwave     = _mm_read_UBYTE(modreader);

		/* Generate an error if c5spd is > 512k, or samplelength > 256 megs
		   (nothing would EVER be that high) */

		if(_mm_eof(modreader)||(s.c5spd>0x7ffffL)||(s.length>0xfffffffUL)||
		   (s.loopbeg>0xfffffffUL)||(s.loopend>0xfffffffUL)) {
			_mm_errno = MMERR_LOADING_SAMPLEINFO;
			return 0;
		}

		q->samplename = DupStr(s.sampname,26,0);
		q->speed      = s.c5spd / 2;
		q->panning    = ((s.panning&127)==64)?255:(s.panning&127)<<2;
		q->length     = s.length;
		q->loopstart  = s.loopbeg;
		q->loopend    = s.loopend;
		q->volume     = s.volume;
		q->globvol    = s.globvol;
		q->seekpos    = s.sampoffset;

		/* Convert speed to XM linear finetune */
		if(of.flags&UF_LINEAR)
			q->speed=speed_to_finetune(s.c5spd,t);

		if(s.panning&128) q->flags|=SF_OWNPAN;

		if(s.vibrate) {
			q->vibflags |= AV_IT;
			q->vibtype   = s.vibwave;
			q->vibsweep  = s.vibrate * 2;
			q->vibdepth  = s.vibdepth;
			q->vibrate   = s.vibspeed;
		}

		if(s.flag&2) q->flags|=SF_16BITS;
		if((s.flag&8)&&(mh->cwt>=0x214)) {
			q->flags|=SF_ITPACKED;
			compressed=1;
		}
		if(s.flag&16) q->flags|=SF_LOOP;
		if(s.flag&64) q->flags|=SF_BIDI;

		if(mh->cwt>=0x200) {
			if(s.convert&1) q->flags|=SF_SIGNED;
			if(s.convert&4) q->flags|=SF_DELTA;
		}

		q++;
	}

	/* Load instruments if instrument mode flag enabled */
	if(mh->flags&4) {
		if(!AllocInstruments()) return 0;
		d=of.instruments;
		of.flags|=UF_NNA|UF_INST;

		for(t=0;t<mh->insnum;t++) {
			ITINSTHEADER ih;

			/* seek to instrument position */
			_mm_fseek(modreader,paraptr[t]+4,SEEK_SET);

			/* load instrument info */
			_mm_read_string(ih.filename,12,modreader);
			ih.zerobyte  = _mm_read_UBYTE(modreader);
			if(mh->cwt<0x200) {
				/* load IT 1.xx inst header */
				ih.volflg    = _mm_read_UBYTE(modreader);
				ih.volbeg    = _mm_read_UBYTE(modreader);
				ih.volend    = _mm_read_UBYTE(modreader);
				ih.volsusbeg = _mm_read_UBYTE(modreader);
				ih.volsusend = _mm_read_UBYTE(modreader);
				_mm_read_I_UWORD(modreader);
				ih.fadeout   = _mm_read_I_UWORD(modreader);
				ih.nna       = _mm_read_UBYTE(modreader);
				ih.dnc       = _mm_read_UBYTE(modreader);
			} else {
				/* Read IT200+ header */
				ih.nna       = _mm_read_UBYTE(modreader);
				ih.dct       = _mm_read_UBYTE(modreader);
				ih.dca       = _mm_read_UBYTE(modreader);
				ih.fadeout   = _mm_read_I_UWORD(modreader);
				ih.ppsep     = _mm_read_UBYTE(modreader);
				ih.ppcenter  = _mm_read_UBYTE(modreader);
				ih.globvol   = _mm_read_UBYTE(modreader);
				ih.chanpan   = _mm_read_UBYTE(modreader);
				ih.rvolvar   = _mm_read_UBYTE(modreader);
				ih.rpanvar   = _mm_read_UBYTE(modreader);
			}

			ih.trkvers   = _mm_read_I_UWORD(modreader);
			ih.numsmp    = _mm_read_UBYTE(modreader);
			_mm_read_UBYTE(modreader);
			_mm_read_string(ih.name,26,modreader);
			_mm_read_UBYTES(ih.blank01,6,modreader);
			_mm_read_I_UWORDS(ih.samptable,ITNOTECNT,modreader);
			if(mh->cwt<0x200) {
				/* load IT 1xx volume envelope */
				_mm_read_UBYTES(ih.volenv,200,modreader);
				for(lp=0;lp<ITENVCNT;lp++) {
					ih.oldvoltick[lp] = _mm_read_UBYTE(modreader);
					ih.volnode[lp]    = _mm_read_UBYTE(modreader);
				}
			} else {
				/* load IT 2xx volume, pan and pitch envelopes */

 ih.volflg   =_mm_read_UBYTE(modreader);             
 ih.volpts   =_mm_read_UBYTE(modreader);             
 ih.volbeg   =_mm_read_UBYTE(modreader);             
 ih.volend   =_mm_read_UBYTE(modreader);             
 ih.volsusbeg=_mm_read_UBYTE(modreader);             
 ih.volsusend=_mm_read_UBYTE(modreader);             
 for(lp=0;lp<ITENVCNT;lp++) {
 ih.volnode[lp]=_mm_read_UBYTE(modreader);
 ih.voltick[lp]=_mm_read_I_UWORD(modreader); 
 }                                                            
 _mm_read_UBYTE(modreader);
 ih.panflg   =_mm_read_UBYTE(modreader);             
 ih.panpts   =_mm_read_UBYTE(modreader);             
 ih.panbeg   =_mm_read_UBYTE(modreader);             
 ih.panend   =_mm_read_UBYTE(modreader);             
 ih.pansusbeg=_mm_read_UBYTE(modreader);             
 ih.pansusend=_mm_read_UBYTE(modreader);             
 for(lp=0;lp<ITENVCNT;lp++) {
 ih.pannode[lp]=_mm_read_SBYTE(modreader);
 ih.pantick[lp]=_mm_read_I_UWORD(modreader); 
 }                                                            
 _mm_read_UBYTE(modreader);
 ih.pitflg   =_mm_read_UBYTE(modreader);             
 ih.pitpts   =_mm_read_UBYTE(modreader);             
 ih.pitbeg   =_mm_read_UBYTE(modreader);             
 ih.pitend   =_mm_read_UBYTE(modreader);             
 ih.pitsusbeg=_mm_read_UBYTE(modreader);             
 ih.pitsusend=_mm_read_UBYTE(modreader);             
 for(lp=0;lp < ITENVCNT; lp++) {
 ih.pitnode[lp]=_mm_read_SBYTE(modreader);
 ih.pittick[lp]=_mm_read_I_UWORD(modreader); 
 }                                                            
 _mm_read_UBYTE(modreader);

			}

			if(_mm_eof(modreader)) {
				_mm_errno = MMERR_LOADING_SAMPLEINFO;
				return 0;
			}

			d->volflg|=EF_VOLENV;
			d->insname = DupStr(ih.name,26,0);
			d->nnatype = ih.nna & NNA_MASK;

			if(mh->cwt<0x200) {
				d->volfade=ih.fadeout<< 6;
				if(ih.dnc) {
					d->dct=DCT_NOTE;
					d->dca=DCA_CUT;
				}

				if(ih.volflg&1) d->volflg|=EF_ON;
				if(ih.volflg&2) d->volflg|=EF_LOOP;
				if(ih.volflg&4) d->volflg|=EF_SUSTAIN;

				/* XM conversion of IT envelope Array */
				d->volbeg    = ih.volbeg;
				d->volend    = ih.volend;
				d->volsusbeg = ih.volsusbeg;
				d->volsusend = ih.volsusend;

				if(ih.volflg&1) {
					for(u=0;u<ITENVCNT;u++)
						if(ih.oldvoltick[d->volpts]!=0xff) {
							d->volenv[d->volpts].val=(ih.volnode[d->volpts]<<2);
							d->volenv[d->volpts].pos=ih.oldvoltick[d->volpts];
							d->volpts++;
						} else
							break;
				}
			} else {
				d->panning=((ih.chanpan&127)==64)?255:(ih.chanpan&127)<<2;
				if(!(ih.chanpan&128)) d->flags|=IF_OWNPAN;

				if(!(ih.ppsep & 128)) {
					d->pitpansep=ih.ppsep<<2;
					d->pitpancenter=ih.ppcenter;
					d->flags|=IF_PITCHPAN;
				}
				d->globvol=ih.globvol>>1;
				d->volfade=ih.fadeout<<5;
				d->dct    =ih.dct;
				d->dca    =ih.dca;

				if(mh->cwt>=0x204) {
					d->rvolvar = ih.rvolvar;
					d->rpanvar = ih.rpanvar;
				}

if(ih.volflg&1) d->volflg|=EF_ON;
if(ih.volflg&2) d->volflg|=EF_LOOP;
if(ih.volflg&4) d->volflg|=EF_SUSTAIN;
d->volpts=ih.volpts;
d->volbeg=ih.volbeg;
d->volend=ih.volend;
d->volsusbeg=ih.volsusbeg;
d->volsusend=ih.volsusend;
for(u=0;u<ih.volpts;u++)
 d->volenv[u].pos=ih.voltick[u];                               if((d->volflg&EF_ON)&&(d->volpts<2))                          
 d->volflg&=~EF_ON;
for(u=0;u<ih.volpts;u++)
 d->volenv[u].val=(ih.volnode[u]<<2);
                               
if(ih.panflg&1) d->panflg|=EF_ON;
if(ih.panflg&2) d->panflg|=EF_LOOP;
if(ih.panflg&4) d->panflg|=EF_SUSTAIN;
d->panpts=ih.panpts;
d->panbeg=ih.panbeg;
d->panend=ih.panend;                                                   
d->pansusbeg=ih.pansusbeg;
d->pansusend=ih.pansusend;
for(u=0;u<ih.panpts;u++)
 d->panenv[u].pos=ih.pantick[u];                               
if((d->panflg&EF_ON)&&(d->panpts<2))         
d->panflg&=~EF_ON;                 
 for(u=0;u<ih.panpts;u++)
  d->panenv[u].val=ih.pannode[u]==32?255:(ih.pannode[u]+32)<<2;

if(ih.pitflg&1) d->pitflg|=EF_ON;
if(ih.pitflg&2) d->pitflg|=EF_LOOP;
if(ih.pitflg&4) d->pitflg|=EF_SUSTAIN;
d->pitpts=ih.pitpts;
d->pitbeg=ih.pitbeg;
d->pitend=ih.pitend;                                                   
d->pitsusbeg=ih.pitsusbeg;                                            
d->pitsusend=ih.pitsusend;                                            
for(u=0;u<ih.pitpts;u++)                                                    
d->pitenv[u].pos=ih.pittick[u];                               
if((d->pitflg&EF_ON)&&(d->pitpts<2))
d->pitflg&=~EF_ON;
 for(u=0;u<ih.pitpts;u++)
  d->pitenv[u].val=ih.pitnode[u]+32;

				if(ih.pitflg&0x80) {
					/* filter envelopes not supported yet */
					d->pitflg&=~EF_ON;
					ih.pitpts=ih.pitbeg=ih.pitend=0;
#ifdef MIKMOD_DEBUG
					{
						static int warn=0;

						if(!warn)
							fputs("\rFilter envelopes not supported yet\n",stderr);
						warn=1;
					}
#endif
				}
			}

			for(u=0;u<ITNOTECNT;u++) {
				d->samplenote[u]=(ih.samptable[u]&255);
				d->samplenumber[u]=
				  (ih.samptable[u]>>8)?((ih.samptable[u]>>8)-1):0xffff;
				if(d->samplenumber[u]>=of.numsmp)
					d->samplenote[u]=255;
				else if (of.flags&UF_LINEAR) {
					int note=(int)d->samplenote[u]+noteindex[d->samplenumber[u]];
					d->samplenote[u]=(note<0)?0:(note>255?255:note);
				}
			}

			d++;
		}
	} else if(of.flags & UF_LINEAR) {
Пример #26
0
BOOL 
DSM_Load (BOOL curious)
{
  int t;
  DSMINST s;
  SAMPLE *q;
  int cursmp = 0, curpat = 0, track = 0;

  blocklp = 0;
  blockln = 12;

  if (!GetBlockHeader ())
    return 0;
  if (memcmp (blockid, SONGID, 4))
    {
      _mm_errno = MMERR_LOADING_HEADER;
      return 0;
    }

  _mm_read_UBYTES (mh->songname, 28, modreader);
  mh->version = _mm_read_I_UWORD (modreader);
  mh->flags = _mm_read_I_UWORD (modreader);
  mh->reserved2 = _mm_read_I_ULONG (modreader);
  mh->numord = _mm_read_I_UWORD (modreader);
  mh->numsmp = _mm_read_I_UWORD (modreader);
  mh->numpat = _mm_read_I_UWORD (modreader);
  mh->numtrk = _mm_read_I_UWORD (modreader);
  mh->globalvol = _mm_read_UBYTE (modreader);
  mh->mastervol = _mm_read_UBYTE (modreader);
  mh->speed = _mm_read_UBYTE (modreader);
  mh->bpm = _mm_read_UBYTE (modreader);
  _mm_read_UBYTES (mh->panpos, DSM_MAXCHAN, modreader);
  _mm_read_UBYTES (mh->orders, DSM_MAXORDERS, modreader);

  /* set module variables */
  of.initspeed = mh->speed;
  of.inittempo = mh->bpm;
  of.modtype = strdup (DSM_Version);
  of.numchn = mh->numtrk;
  of.numpat = mh->numpat;
  of.numtrk = of.numchn * of.numpat;
  of.songname = DupStr (mh->songname, 28, 1);	/* make a cstr of songname */
  of.reppos = 0;

  for (t = 0; t < DSM_MAXCHAN; t++)
    of.panning[t] = mh->panpos[t] == DSM_SURROUND ? PAN_SURROUND :
      mh->panpos[t] < 0x80 ? (mh->panpos[t] << 1) : 255;

  if (!AllocPositions (mh->numord))
    return 0;
  of.numpos = 0;
  for (t = 0; t < mh->numord; t++)
    {
      of.positions[of.numpos] = mh->orders[t];
      if (mh->orders[t] < 254)
	of.numpos++;
    }

  of.numins = of.numsmp = mh->numsmp;

  if (!AllocSamples ())
    return 0;
  if (!AllocTracks ())
    return 0;
  if (!AllocPatterns ())
    return 0;

  while (cursmp < of.numins || curpat < of.numpat)
    {
      if (!GetBlockHeader ())
	return 0;
      if (!memcmp (blockid, INSTID, 4) && cursmp < of.numins)
	{
	  q = &of.samples[cursmp];

	  /* try to read sample info */
	  _mm_read_UBYTES (s.filename, 13, modreader);
	  s.flags = _mm_read_I_UWORD (modreader);
	  s.volume = _mm_read_UBYTE (modreader);
	  s.length = _mm_read_I_ULONG (modreader);
	  s.loopstart = _mm_read_I_ULONG (modreader);
	  s.loopend = _mm_read_I_ULONG (modreader);
	  s.reserved1 = _mm_read_I_ULONG (modreader);
	  s.c2spd = _mm_read_I_UWORD (modreader);
	  s.period = _mm_read_I_UWORD (modreader);
	  _mm_read_UBYTES (s.samplename, 28, modreader);

	  q->samplename = DupStr (s.samplename, 28, 1);
	  q->seekpos = _mm_ftell (modreader);
	  q->speed = s.c2spd;
	  q->length = s.length;
	  q->loopstart = s.loopstart;
	  q->loopend = s.loopend;
	  q->volume = s.volume;

	  if (s.flags & 1)
	    q->flags |= SF_LOOP;
	  if (s.flags & 2)
	    q->flags |= SF_SIGNED;
	  /* (s.flags&4) means packed sample,
	     but did they really exist in dsm ? */
	  cursmp++;
	}
      else if (!memcmp (blockid, PATTID, 4) && curpat < of.numpat)
	{
	  DSM_ReadPattern ();
	  for (t = 0; t < of.numchn; t++)
	    if (!(of.tracks[track++] = DSM_ConvertTrack (&dsmbuf[t * 64])))
	      return 0;
	  curpat++;
	}
    }

  return 1;
}
Пример #27
0
static BOOL ULT_Load(void)
{
    int t,u,tracks=0;
    INSTRUMENT *d;
    SAMPLE *q;
    ULTSAMPLE s;
    ULTHEADER mh;
    UBYTE nos,noc,nop;

    /* try to read module header */

    _mm_read_str(mh.id,15);
    _mm_read_str(mh.songtitle,32);
    mh.reserved=_mm_read_UBYTE();

    if(modpos > modsize){
	gModPlayerErrorMessage=ERROR_LOADING_HEADER;
	return 0;
    }

    if(mh.id[14]<'1' || mh.id[14]>'4'){
	//printf("This version is not yet supported\n");
	return 0;
    }

    of.modtype=strdup(ULT_Version[mh.id[14]-'1']);
    of.initspeed=6;
    of.inittempo=125;

    /* read songtext */

    if(!ReadComment((UWORD)(mh.reserved * 32))) return 0;

    nos=_mm_read_UBYTE();

    if(modpos > modsize){
	gModPlayerErrorMessage=ERROR_LOADING_HEADER;
	return 0;
    }

    of.songname=DupStr(mh.songtitle,32);
    of.numins=nos;

    if(!AllocInstruments()) return 0;

    d=of.instruments;

    for(t=0;t<nos;t++){

	d->numsmp=1;
	if(!AllocSamples(d)) return 0;
	q=d->samples;

	/* try to read sample info */

	_mm_read_str(s.samplename,32);
	_mm_read_str(s.dosname,12);
	s.loopstart	=_mm_read_I_ULONG();
	s.loopend	=_mm_read_I_ULONG();
	s.sizestart	=_mm_read_I_ULONG();
	s.sizeend	=_mm_read_I_ULONG();
	s.volume	=_mm_read_UBYTE();
	s.flags		=_mm_read_UBYTE();
	s.finetune	=_mm_read_I_SWORD();

	if(modpos > modsize){
	    gModPlayerErrorMessage=ERROR_LOADING_SAMPLEINFO;
	    return 0;
	}

	d->insname=DupStr(s.samplename,32);

	q->seekpos=0;

	q->c2spd=8363;

	if(mh.id[14]>='4'){
	    _mm_read_I_UWORD();	/* read 1.6 extra info(??) word */
	    q->c2spd=s.finetune;
	}

	q->length=s.sizeend-s.sizestart;
	q->volume=s.volume>>2;
	q->loopstart=s.loopstart;
	q->loopend=s.loopend;

	q->flags=SF_SIGNED;

	if(s.flags&ULTS_LOOP){
	    q->flags|=SF_LOOP;
	}

	if(s.flags&ULTS_16BITS){
	    q->flags|=SF_16BITS;
	    q->loopstart>>=1;
	    q->loopend>>=1;
	}

	/*      printf("Sample %d %s length %ld\n",t,d->samplename,d->length); */
	d++;
    }
Пример #28
0
static int MTM_Load(int curious)
{
	int t,u;
	MTMSAMPLE s;
	SAMPLE *q;
    (void)curious;

	/* try to read module header  */
	_mm_read_UBYTES(mh->id,3,modreader);
	mh->version     =_mm_read_UBYTE(modreader);
	_mm_read_string(mh->songname,20,modreader);
	mh->numtracks   =_mm_read_I_UWORD(modreader);
	mh->lastpattern =_mm_read_UBYTE(modreader);
	mh->lastorder   =_mm_read_UBYTE(modreader);
	mh->commentsize =_mm_read_I_UWORD(modreader);
	mh->numsamples  =_mm_read_UBYTE(modreader);
	mh->attribute   =_mm_read_UBYTE(modreader);
	mh->beatspertrack=_mm_read_UBYTE(modreader);
	mh->numchannels =_mm_read_UBYTE(modreader);
	_mm_read_UBYTES(mh->panpos,32,modreader);

	if(_mm_eof(modreader)) {
		_mm_errno = MMERR_LOADING_HEADER;
		return 0;
	}

	/* set module variables */
	of.initspeed = 6;
	of.inittempo = 125;
	of.modtype   = StrDup(MTM_Version);
	of.numchn    = mh->numchannels;
	of.numtrk    = mh->numtracks+1;           /* get number of channels */
	of.songname  = DupStr(mh->songname,20,1); /* make a cstr of songname */
	of.numpos    = mh->lastorder+1;           /* copy the songlength */
	of.numpat    = mh->lastpattern+1;
	of.reppos    = 0;
	of.flags    |= UF_PANNING;
	for(t=0;t<32;t++) of.panning[t]=mh->panpos[t]<< 4;
	of.numins=of.numsmp=mh->numsamples;

	if(!AllocSamples()) return 0;
	q=of.samples;
	for(t=0;t<of.numins;t++) {
		/* try to read sample info */
		_mm_read_string(s.samplename,22,modreader);
		s.length    =_mm_read_I_ULONG(modreader);
		s.reppos    =_mm_read_I_ULONG(modreader);
		s.repend    =_mm_read_I_ULONG(modreader);
		s.finetune  =_mm_read_UBYTE(modreader);
		s.volume    =_mm_read_UBYTE(modreader);
		s.attribute =_mm_read_UBYTE(modreader);

		if(_mm_eof(modreader)) {
			_mm_errno = MMERR_LOADING_SAMPLEINFO; 
			return 0;
		}

		q->samplename = DupStr(s.samplename,22,1);
		q->seekpos   = 0;
		q->speed     = finetune[s.finetune];
		q->length    = s.length;
		q->loopstart = s.reppos;
		q->loopend   = s.repend;
		q->volume    = s.volume;
		if((s.repend-s.reppos)>2) q->flags |= SF_LOOP;

		if(s.attribute&1) {
			/* If the sample is 16-bits, convert the length and replen
			   byte-values into sample-values */
			q->flags|=SF_16BITS;
			q->length>>=1;
			q->loopstart>>=1;
			q->loopend>>=1;
		}
		q++;
	}
Пример #29
0
		tracker=NUMTRACKERS-1; /* unknown tracker */
	else {
		if(mh->tracker>=0x3217)
			tracker=NUMTRACKERS+1; /* IT 2.14p4 */
		else if(mh->tracker>=0x3216)
			tracker=NUMTRACKERS; /* IT 2.14p3 */
		else tracker--;
	}
	of.modtype = strdup(S3M_Version[tracker]);
	if(tracker<NUMTRACKERS) {
		of.modtype[numeric[tracker]] = ((mh->tracker>>8) &0xf)+'0';
		of.modtype[numeric[tracker]+2] = ((mh->tracker>>4)&0xf)+'0';
		of.modtype[numeric[tracker]+3] = ((mh->tracker)&0xf)+'0';
	}
	/* set module variables */
	of.songname    = DupStr(mh->songname,28,0);
	of.numpat      = mh->patnum;
	of.reppos      = 0;
	of.numins      = of.numsmp = mh->insnum;
	of.initspeed   = mh->initspeed;
	of.inittempo   = mh->inittempo;
	of.initvolume  = mh->mastervol<<1;
	of.flags      |= UF_ARPMEM | UF_PANNING;
	if((mh->tracker==0x1300)||(mh->flags&64))
		of.flags|=UF_S3MSLIDES;
	of.bpmlimit    = 32;

	/* read the order data */
	if(!AllocPositions(mh->ordnum)) return 0;
	if(!(origpositions=_mm_calloc(mh->ordnum,sizeof(UWORD)))) return 0;
Пример #30
0
BOOL S69_Load(BOOL curious)
{
	int i;
	SAMPLE *current;
	S69SAMPLE sample;

	/* module header */
	_mm_read_UBYTES(mh->marker,2,modreader);
	_mm_read_UBYTES(mh->message,108,modreader);
	mh->nos=_mm_read_UBYTE(modreader);
	mh->nop=_mm_read_UBYTE(modreader);
	mh->looporder=_mm_read_UBYTE(modreader);
	_mm_read_UBYTES(mh->orders,0x80,modreader);
	for(i=0;i<0x80;i++)
		if ((mh->orders[i]>=0x80)&&(mh->orders[i]!=0xff)) {
			_mm_errno=MMERR_NOT_A_MODULE;
			return 1;
		}
	_mm_read_UBYTES(mh->tempos,0x80,modreader);
	for(i=0;i<0x80;i++)
		if ((!mh->tempos[i])||(mh->tempos[i]>32)) {
			_mm_errno=MMERR_NOT_A_MODULE;
			return 1;
		}
	_mm_read_UBYTES(mh->breaks,0x80,modreader);
	for(i=0;i<0x80;i++)
		if (mh->breaks[i]>0x3f) {
			_mm_errno=MMERR_NOT_A_MODULE;
			return 1;
		}

	/* set module variables */
	of.initspeed=4;
	of.inittempo=78;
	of.songname=DupStr(mh->message,36,1);
	of.modtype=StrDup(S69_Version[memcmp(mh->marker,"JN",2)==0]);
	of.numchn=8;
	of.numpat=mh->nop;
	of.numins=of.numsmp=mh->nos;
	of.numtrk=of.numchn*of.numpat;
	of.flags=UF_XMPERIODS|UF_LINEAR;

	for(i=   35;(i>=   0)&&(mh->message[i]==' ');i--) mh->message[i]=0;
	for(i=36+35;(i>=36+0)&&(mh->message[i]==' ');i--) mh->message[i]=0;
	for(i=72+35;(i>=72+0)&&(mh->message[i]==' ');i--) mh->message[i]=0;
	if((mh->message[0])||(mh->message[36])||(mh->message[72]))
		if((of.comment=(CHAR*)MikMod_malloc(3*(36+1)+1))) {
			strncpy(of.comment,mh->message,36);
			strcat(of.comment,"\r");
			if (mh->message[36]) strncat(of.comment,mh->message+36,36);
			strcat(of.comment,"\r");
			if (mh->message[72]) strncat(of.comment,mh->message+72,36);
			strcat(of.comment,"\r");
			of.comment[3*(36+1)]=0;
		}

	if(!AllocPositions(0x80)) return 0;
	for(i=0;i<0x80;i++) {
		if(mh->orders[i]>=mh->nop) break;
		of.positions[i]=mh->orders[i];
	}
	of.numpos=i;
	of.reppos=mh->looporder<of.numpos?mh->looporder:0;

	if(!AllocSamples()) return 0;
	current=of.samples;

	for(i=0;i<of.numins;i++) {
		/* sample information */
		_mm_read_UBYTES((UBYTE*)sample.filename,13,modreader);
		sample.length=_mm_read_I_SLONG(modreader);
		sample.loopbeg=_mm_read_I_SLONG(modreader);
		sample.loopend=_mm_read_I_SLONG(modreader);
		if (sample.loopend==0xfffff) sample.loopend=0;

		if((sample.length<0)||(sample.loopbeg<-1)||(sample.loopend<-1)) {
			_mm_errno = MMERR_LOADING_HEADER;
			return 0;
		}

		current->samplename=DupStr(sample.filename,13,1);
		current->seekpos=0;
		current->speed=0;
		current->length=sample.length;
		current->loopstart=sample.loopbeg;
		current->loopend=sample.loopend;
		current->flags=(sample.loopbeg<sample.loopend)?SF_LOOP:0;
		current->volume=64;

		current++;
	}

	if(!S69_LoadPatterns()) return 0;

	return 1;
}