Subversion Repositories svn.mios32

Rev

Rev 2516 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2516 Rev 2518
Line 1094... Line 1094...
1094
    if(filepath == NULL || prog == NULL) return -1;
1094
    if(filepath == NULL || prog == NULL) return -1;
1095
    //Read header
1095
    //Read header
1096
    MUTEX_SDCARD_TAKE;
1096
    MUTEX_SDCARD_TAKE;
1097
    file_t file;
1097
    file_t file;
1098
    s32 ret = FILE_ReadOpen(&file, filepath);
1098
    s32 ret = FILE_ReadOpen(&file, filepath);
-
 
1099
    if(ret < 0){
-
 
1100
        MUTEX_SDCARD_GIVE;
1099
    if(ret < 0) return ret;
1101
        return ret;
-
 
1102
    }
1100
    FILE_ReadSeek(16);
1103
    FILE_ReadSeek(16);
1101
    u8 b;
1104
    u8 b;
1102
    FILE_ReadByte(&b);
1105
    FILE_ReadByte(&b);
1103
    if(b != 0){
1106
    if(b != 0){
1104
        DBG("Loading percussion program not implemented yet!");
1107
        DBG("Loading percussion program not implemented yet!");
-
 
1108
        MUTEX_SDCARD_GIVE;
1105
        return -50;
1109
        return -50;
1106
    }
1110
    }
1107
    FILE_ReadByte(&prog->rootnote);
1111
    FILE_ReadByte(&prog->rootnote);
1108
    FILE_ReadWord(&prog->tlbaseoffs);
1112
    FILE_ReadWord(&prog->tlbaseoffs);
1109
    FILE_ReadBuffer((u8*)&prog->name, 13);
1113
    FILE_ReadBuffer((u8*)&prog->name, 13);
Line 1115... Line 1119...
1115
    VgmSource** ss;
1119
    VgmSource** ss;
1116
    for(v=0; v<3; ++v){
1120
    for(v=0; v<3; ++v){
1117
        ss = SelSource(prog, v);
1121
        ss = SelSource(prog, v);
1118
        *ss = NULL;
1122
        *ss = NULL;
1119
        FILE_ReadByte(&l);
1123
        FILE_ReadByte(&l);
-
 
1124
        if(l == 0) continue; //Null
1120
        FILE_ReadBuffer((u8*)tempbuf, l);
1125
        FILE_ReadBuffer((u8*)tempbuf, l);
1121
        tempbuf[l] = 0;
1126
        tempbuf[l] = 0;
1122
        DBG("Program %s: loading VGM file %s", prog->name, tempbuf);
1127
        DBG("Program %s: loading VGM file %s", prog->name, tempbuf);
1123
        //Load file
1128
        //Load file
1124
        FILE_ReadClose(&file);
1129
        FILE_ReadClose(&file);
1125
        MUTEX_SDCARD_GIVE;
1130
        MUTEX_SDCARD_GIVE;
1126
        ret = VGM_File_Load(tempbuf, ss, NULL);
1131
        ret = VGM_File_Load(tempbuf, ss, NULL);
1127
        if(ret < 0){
1132
        if(ret < 0){
1128
            DBG("Error %d loading VGM file", ret);
1133
            DBG("Error %d loading VGM file", ret);
1129
        }
1134
        }
1130
        if(v != 2){
-
 
1131
            MUTEX_SDCARD_TAKE;
1135
        MUTEX_SDCARD_TAKE;
1132
            FILE_ReadReOpen(&file);
1136
        FILE_ReadReOpen(&file);
1133
        }
1137
    }
-
 
1138
    FILE_ReadClose(&file);
1134
    }
1139
    MUTEX_SDCARD_GIVE;
1135
    vgmh2_free(tempbuf);
1140
    vgmh2_free(tempbuf);
1136
    //Update program usage
1141
    //Update program usage
1137
    SyEng_RecalcSourceAndProgramUsage(prog, NULL);
1142
    SyEng_RecalcSourceAndProgramUsage(prog, NULL);
1138
    return 0;
1143
    return ret;
1139
}
1144
}
1140
1145
1141
inline u8 TurnProgPathIntoVGMPath(char* tempbuf, char* filenamestart, u8 v){
1146
inline u8 TurnProgPathIntoVGMPath(char* tempbuf, char* filenamestart, u8 v){
1142
    u8 sl = strlen(vgmtypelabels[v]);
1147
    u8 sl = strlen(vgmtypelabels[v]);
1143
    memcpy(filenamestart, vgmtypelabels[v], sl);
1148
    memcpy(filenamestart, vgmtypelabels[v], sl);
Line 1150... Line 1155...
1150
1155
1151
s32 SyEng_SaveProgram(synprogram_t* prog, char* filepath){
1156
s32 SyEng_SaveProgram(synprogram_t* prog, char* filepath){
1152
    if(prog == NULL || filepath == NULL || strlen(filepath) == 0) return -1;
1157
    if(prog == NULL || filepath == NULL || strlen(filepath) == 0) return -1;
1153
    s32 ret = 0;
1158
    s32 ret = 0;
1154
    //Get and extend path
1159
    //Get and extend path
1155
    //--Assume filepath contains /SOME/PATH/PROGNAME.XYZ
1160
    //--Assume filepath contains /SOME/PATH/PROGNAME.PGM
1156
    char* tempbuf = vgmh2_malloc(256);
1161
    char* tempbuf = vgmh2_malloc(256);
1157
    u8 sl = strlen(filepath);
1162
    u8 sl = strlen(filepath);
1158
    memcpy(tempbuf, filepath, sl);
1163
    memcpy(tempbuf, filepath, sl);
1159
    char* filenamestart = tempbuf + sl;
1164
    char* filenamestart = tempbuf + sl;
1160
    *filenamestart = 0;
1165
    *filenamestart = 0;
1161
    while(*filenamestart != '.') --filenamestart;
1166
    while(*filenamestart != '.') --filenamestart;
-
 
1167
    *filenamestart = 0;
-
 
1168
    //--tempbuf now contains /SOME/PATH/PROGNAME
-
 
1169
    MUTEX_SDCARD_TAKE;
-
 
1170
    if(!FILE_DirExists(tempbuf)){
-
 
1171
        FILE_MakeDir(tempbuf);
-
 
1172
    }
1162
    *filenamestart = '/';
1173
    *filenamestart = '/';
1163
    ++filenamestart;
1174
    ++filenamestart;
1164
    //--tempbuf now contains /SOME/PATH/PROGNAME/XYZ and filenamestart points to X
1175
    //--tempbuf now contains /SOME/PATH/PROGNAME/PGM and filenamestart points to PGM
1165
    //Start program file
1176
    //Start program file
1166
    if(FILE_FileExists(filepath)){
1177
    if(FILE_FileExists(filepath)){
1167
        FILE_Remove(filepath);
1178
        FILE_Remove(filepath);
1168
    }
1179
    }
1169
    MUTEX_SDCARD_TAKE;
-
 
1170
    FILE_WriteOpen(filepath, 1);
1180
    FILE_WriteOpen(filepath, 1);
1171
    //Program file main
1181
    //Program file main
1172
    FILE_WriteBuffer((u8*)"MBQG Program", 12);
1182
    FILE_WriteBuffer((u8*)"MBQG Program", 12);
1173
    FILE_WriteWord(0);
1183
    FILE_WriteWord(0);
1174
    FILE_WriteByte(0);
1184
    FILE_WriteByte(0);