[NEW] File handling functions
This commit is contained in:
85
mini.cpp
85
mini.cpp
@@ -13,15 +13,19 @@ struct surface_t {
|
||||
|
||||
#define swap(a, b) {auto tmp=a;a=b;b=tmp;}
|
||||
|
||||
char window_title[256];
|
||||
uint16_t screen_width = 160;
|
||||
uint16_t screen_height = 120;
|
||||
uint8_t screen_zoom = 4;
|
||||
surface_t surfaces[10];
|
||||
surface_t *screen_surface = &surfaces[0];
|
||||
surface_t *dest_surface = screen_surface;
|
||||
surface_t *source_surface = NULL;
|
||||
surface_t *map_surface = NULL;
|
||||
char window_title[256];
|
||||
uint16_t screen_width = 160;
|
||||
uint16_t screen_height = 120;
|
||||
uint8_t screen_zoom = 4;
|
||||
|
||||
surface_t surfaces[10];
|
||||
surface_t *screen_surface = &surfaces[0];
|
||||
surface_t *dest_surface = screen_surface;
|
||||
surface_t *source_surface = NULL;
|
||||
surface_t *map_surface = NULL;
|
||||
|
||||
FILE *file = NULL;
|
||||
bool file_ignore_comma=true;
|
||||
|
||||
#define DEST(x, y) dest_surface->p[x+y*dest_surface->w]
|
||||
#define SOURCE(x, y) source_surface->p[x+y*source_surface->w]
|
||||
@@ -89,6 +93,7 @@ struct bmp_header_t {
|
||||
uint32_t num_important_colors; // ignore
|
||||
};
|
||||
|
||||
|
||||
char* get_value_from_line(char* line) {
|
||||
char* equal_character = strchr(line, '=');
|
||||
if (equal_character == NULL) return NULL;
|
||||
@@ -127,6 +132,8 @@ void reinit() {
|
||||
if (surfaces[i].p != NULL) free(surfaces[i].p);
|
||||
surfaces[i].p = NULL;
|
||||
}
|
||||
if (file!=NULL) fclose(file);
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
uint8_t newsurf(int w, int h) {
|
||||
@@ -902,3 +909,63 @@ void pdebug() {
|
||||
uint8_t ascii(const char *str, uint8_t index) {
|
||||
return str[index];
|
||||
}
|
||||
|
||||
|
||||
char fstr[255];
|
||||
|
||||
void fopen(const char *filename, uint8_t mode) {
|
||||
if (file != NULL) fclose(file);
|
||||
file = fopen(filename, mode==0?"r":"w");
|
||||
}
|
||||
|
||||
void fclose() {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void fwritei(int value) {
|
||||
sprintf(fstr, "%i ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwrited(float value) {
|
||||
char str[255];
|
||||
sprintf(fstr, "%f ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
void fwrites(const char *value) {
|
||||
char str[255];
|
||||
sprintf(fstr, "\"%s\" ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwriteb(bool value) {
|
||||
char str[255];
|
||||
sprintf(fstr, value?"true ":"false ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwriteln() {
|
||||
fwrite("\n", 1, 1, file);
|
||||
}
|
||||
|
||||
int freadi() {
|
||||
int value;
|
||||
fscanf(file, "%i", &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
float freadd() {
|
||||
float value;
|
||||
fscanf(file, "%f", &value);
|
||||
return value;
|
||||
}
|
||||
const char *freads() {
|
||||
fscanf(file, " \"%[^\"]\"", &fstr);
|
||||
//fscanf(file, "\"%[^\"]\"", &fstr);
|
||||
return fstr;
|
||||
}
|
||||
|
||||
bool freadb() {
|
||||
fscanf(file, "%s", &fstr);
|
||||
return strcmp(fstr, "true")==0?true:false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user