MateoConLechuga wrote:
What does your source file look like? Explanations for things are not helpful haha
Oh, sorry. Here it is:
Code: /* Keep these headers */
#include <stdbool.h>
#include <stddef.h> //need this
#include <stdint.h>
#include <tice.h>
/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <debug.h>
//libraries
#include <fileioc.h>
//includes
#include "access.h"
//defines
//functions
//variables
const open_type createMain = 0;
const open_type saveMain = 1;
const open_type openMain = 2;
const open_type createFile = 3;
const open_type saveFile = 4;
const open_type openFile = 5;
char apvName[] = "TextFile";
char readPlus[] = "r";
char write[] = "w";
int numofFiles_Open = 0;
int numofFiles = 0;
slotVars_t slotVars;
allfiles_t *allfiles_ptr = (allfiles_t*)0xD031F6; //address of allfiles
allfiles_t *allfiles_inc = (allfiles_t*)0xD031F6;
const allfiles_t allfiles = {0};
static const settings_t settings_d = { 1.0000, 0x5E, 0x36, 0};
settings_t settings_m;
fileStructure_t *file_1 = (fileStructure_t*)0xD09466;
fileStructure_t *file_2 = (fileStructure_t*)0xD0BF42;
fileStructure_t *file_3 = (fileStructure_t*)0xD0EA1E;
fileStructure_t *file_4 = (fileStructure_t*)0xD114FA;
int16_t maxFileSize = 0x2ADC;
fileStructure_t *hText_1 = (fileStructure_t*)0xD052C6;
fileStructure_t *hText_2 = (fileStructure_t*)0xD0632E;
fileStructure_t *hText_3 = (fileStructure_t*)0xD07396;
fileStructure_t *hText_4 = (fileStructure_t*)0xD083FE;
int16_t maxHTextSize = 0x1068;
openFiles openFile_1, openFile_2, openFile_3, openFile_4;
name_t blank = {0,0};
int openProg(open_type type, name_t fileName) { //fileName is only used when opening or saving a file
int result;
switch(type) {
case createMain:
slotVars.main = ti_Open(apvName, readPlus); //the problem occurs at this ti_Open
if (!slotVars.main) {
slotVars.main = ti_Open(apvName, write);
if (!slotVars.main) {
return -1; //change to error code: Malloc error
}else {
if (result = writeVar(type, slotVars.main))
return result;
break;
}
}else {
if (result = readVar(openMain, slotVars.main))
return result;
break;
}
case openMain:
slotVars.main = ti_Open(apvName, readPlus);
break; //may want to add ReadVar
case createFile:
if (numofFiles_Open < 4) {
if (!(slotVars.files[numofFiles_Open] = ti_Open(fileName.name, write)))
return -1; //change to error code: Malloc error
if (result = writeVar(type, slotVars.files[numofFiles_Open]))
return result;
++numofFiles_Open;
break;
}else
return -2; //change to error code: Cannot open file
case openFile:
if (numofFiles_Open < 4) {
slotVars.files[numofFiles_Open] = ti_Open(fileName.name, readPlus); //maxnumFiles
if (result = readVar(type, slotVars.files[numofFiles_Open]))
return result;
++numofFiles_Open;
break;
}else
return -2; //change to error code: Cannot open file
default:
return -4; //change to error code: Given parameter is invalid
}
return 0;
}
double doubleCompare(double flt1, double flt2) {
if (flt1 > flt2)
return 1.0;
if (flt1 < flt2)
return -1.0;
return 0;
}
void closeAll(void) {
int i;
ti_CloseAll();
slotVars.main = 0;
openFile_1.ptr = (fileStructure_t*)0;
openFile_2.ptr = (fileStructure_t*)0;
openFile_3.ptr = (fileStructure_t*)0;
openFile_4.ptr = (fileStructure_t*)0;
if (!numofFiles_Open)
return;
for(i = 0; i == numofFiles_Open; ++i) {
slotVars.files[i] = 0;
}
numofFiles_Open = 0;
}
void close(ti_var_t file) {
switch(file) {
case 2:
openFile_1.ptr = (fileStructure_t*)0;
break;
case 3:
openFile_2.ptr = (fileStructure_t*)0;
break;
case 4:
openFile_3.ptr = (fileStructure_t*)0;
break;
case 5:
openFile_4.ptr = (fileStructure_t*)0;
break;
}
ti_Close(file);
}
size_t writeVar(open_type type, ti_var_t file) {
switch(type) {
case createMain:
settings_m = settings_d;
if (!ti_Write(&settings_m, sizeof(settings_t), 1, file))
return -1; //change to error code: Malloc error
break;
case saveMain:
if (!ti_Write(&settings_m, sizeof(settings_t), 1, file))
return -1; //change to error code: Malloc error
if (!ti_Write(&numofFiles, sizeof(numofFiles), 1, file))
return -1; //change to error code: Malloc error
if (numofFiles)
if (!ti_Write(allfiles_ptr, sizeof(allfiles), numofFiles, file))
return -1; //change to error code: Malloc error
break;
case saveFile:
switch(file) {
case 2:
if (!ti_Write(openFile_1.ptr, openFile_1.ptr->size, 1, file))
return -1; //change to error code: Malloc error
if (!ti_Write(openFile_1.ptr->hidden_text, openFile_1.ptr->size_htext, 1, file))
return -1; //change to error code: Malloc error
break;
case 3:
if (!ti_Write(openFile_2.ptr, openFile_2.ptr->size, 1, file))
return -1; //change to error code: Malloc error
if (!ti_Write(openFile_2.ptr->hidden_text, openFile_2.ptr->size_htext, 1, file))
return -1; //change to error code: Malloc error
break;
case 4:
if (!ti_Write(openFile_3.ptr, openFile_3.ptr->size, 1, file))
return -1; //change to error code: Malloc error
if (!ti_Write(openFile_3.ptr->hidden_text, openFile_3.ptr->size_htext, 1, file))
return -1; //change to error code: Malloc error
break;
case 5:
if (!ti_Write(openFile_4.ptr, openFile_4.ptr->size, 1, file))
return -1; //change to error code: Malloc error
if (!ti_Write(openFile_4.ptr->hidden_text, openFile_4.ptr->size_htext, 1, file))
return -1; //change to error code: Malloc error
break;
default:
return -4; //change to error code: Given parameter is invalid
}
break;
default:
return -4; //change to error code: Given parameter is invalid
}
ti_Rewind(file);
return 0;
}
size_t readVar(open_type type, ti_var_t file) {
double result;
switch(type) {
case openMain:
ti_Read(&settings_m, sizeof(settings_t), 1, file);
result = doubleCompare(settings_d.version, settings_m.version);
if (result == -1.0)
return -3; //change to error code: Incompatable Version
else {
ti_Read(&numofFiles, sizeof(numofFiles), 1, file);
if (numofFiles)
ti_Read(allfiles_ptr, sizeof(allfiles), numofFiles, file);
}
break;
case openFile:
switch(file) {
case 2:
ti_Read(openFile_1.ptr, openFile_1.ptr->size, 1, file);
ti_Read(openFile_1.ptr->hidden_text, openFile_1.ptr->size_htext, 1, file);
break;
case 3:
ti_Read(openFile_2.ptr, openFile_2.ptr->size, 1, file);
ti_Read(openFile_2.ptr->hidden_text, openFile_2.ptr->size_htext, 1, file);
break;
case 4:
ti_Read(openFile_3.ptr, openFile_3.ptr->size, 1, file);
ti_Read(openFile_3.ptr->hidden_text, openFile_3.ptr->size_htext, 1, file);
break;
case 5:
ti_Read(openFile_4.ptr, openFile_4.ptr->size, 1, file);
ti_Read(openFile_4.ptr->hidden_text, openFile_4.ptr->size_htext, 1, file);
break;
default:
return -4; //change to error code: Given parameter is invalid
}
break;
default:
return -4; //change to error code: Given parameter is invalid
}
return 0;
}
I marked the spot where the ti_Open is.
The problems never happened before I updated the toolchain.