diff options
| author | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-01-31 14:10:20 +0100 |
|---|---|---|
| committer | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-01-31 14:10:20 +0100 |
| commit | 26b206560dc4bce4537ec9fcceb2306534fd1c6a (patch) | |
| tree | 409ade6fe8eabe90c298fb1236028065e92af1e0 /libpsx/src | |
| parent | 78128c8058e6f522c55e7945274926d33183634f (diff) | |
Added -ffunction/data-sections and -Os to libpsx
Diffstat (limited to 'libpsx/src')
| -rw-r--r-- | libpsx/src/libc.c | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/libpsx/src/libc.c b/libpsx/src/libc.c index 8ad519b..59866f4 100644 --- a/libpsx/src/libc.c +++ b/libpsx/src/libc.c @@ -59,7 +59,7 @@ FILE file_structs[NUM_OF_FILE_STRUCTS] = .used = 1, .eof = 0, .error = 0 - }, + }, }; FILE *stdin = &file_structs[0]; @@ -70,14 +70,14 @@ FILE *stderr = &file_structs[2]; #define IS_CONS_OUT(f) (f->fildes == 1 || f->fildes == 2) //unsigned char file_state[NUM_OF_FILE_STRUCTS]; - + int libc_get_transtbl_fname(const char *tofind, char *outstr, int outl); unsigned int fmode_to_desmode(const char *fmode) { char rmode[16]; int x, y; - + y = 0; for(x=0;x<15;x++) @@ -90,9 +90,9 @@ unsigned int fmode_to_desmode(const char *fmode) rmode[y++] = fmode[x]; } } - + rmode[y] = 0; - + if(strcmp(rmode, "r") == 0) { dprintf("Open for reading.\n"); @@ -134,7 +134,7 @@ FILE *fdopen(int fildes, const char *mode) // Adjust for malloc int x; -// Find a free file structure +// Find a free file structure for(x = 0; x < NUM_OF_FILE_STRUCTS; x++) { if(file_structs[x].used == 0) @@ -146,14 +146,14 @@ FILE *fdopen(int fildes, const char *mode) } // If we found no free file structure, return NULL pointer - + if(x == NUM_OF_FILE_STRUCTS) return NULL; file_structs[x].fildes = fildes; file_structs[x].pos = lseek(fildes, 0, SEEK_CUR); file_structs[x].mode = fmode_to_desmode(mode); - + return &file_structs[x]; } @@ -161,7 +161,7 @@ static FILE *fopen_internal(const char *path, const char *mode, FILE *f) { int fd; char *s = NULL; - + if(strncmp(path, "cdromL:", 7) == 0) { s = malloc(1024); @@ -172,14 +172,14 @@ static FILE *fopen_internal(const char *path, const char *mode, FILE *f) fd = open(s, fmode_to_desmode(mode)); } else - fd = open(path, fmode_to_desmode(mode)); - + fd = open(path, fmode_to_desmode(mode)); + if(fd == -1) { if(s!=NULL)free(s); return NULL; } - + if(f == NULL) f = fdopen(fd, mode); else @@ -188,15 +188,15 @@ static FILE *fopen_internal(const char *path, const char *mode, FILE *f) f->pos = lseek(fd, 0, SEEK_CUR); f->mode = fmode_to_desmode(mode); } - + if(f == NULL) { if(s!=NULL)free(s); return NULL; } - + f->dev = FDEV_UNKNOWN; - + if(strncmp(path, "cdrom", 5) == 0 || strncmp(path, "cdromL", 6) == 0) f->dev = FDEV_CDROM; else if(strncmp(path, "bu", 2) == 0) @@ -204,7 +204,7 @@ static FILE *fopen_internal(const char *path, const char *mode, FILE *f) // nocash bios freezes at get_real_file_size(), due // to problems with firstfile() - + if(s!=NULL) { f->size = get_real_file_size(s); @@ -212,7 +212,7 @@ static FILE *fopen_internal(const char *path, const char *mode, FILE *f) } else f->size = get_real_file_size(path); - + return f; } @@ -232,7 +232,7 @@ int fclose(FILE *stream) * fread doesn't require reads to be carried in block unit * Notice that however seeks on the CD drive will be very slow - so avoid using non block units * - * This is done to make programming and porting easier + * This is done to make programming and porting easier */ int fread(void *ptr, int size, int nmemb, FILE *f) @@ -240,10 +240,10 @@ int fread(void *ptr, int size, int nmemb, FILE *f) int rsize = size * nmemb; int csize = rsize; int max; - int nsect = (f->pos + rsize) >> 11; + int nsect = (f->pos + rsize) >> 11; nsect -= f->pos >> 11; nsect++; - + //printf("f->dev = %d, f->pos = %d, rsize = %d\n", f->dev, f->pos, rsize); if(f->dev == FDEV_CDROM) @@ -251,62 +251,62 @@ int fread(void *ptr, int size, int nmemb, FILE *f) // First sector lseek(f->fildes, f->pos & (~0x7ff), SEEK_SET); read(f->fildes, onesec_buf, 2048); - + max = 2048 - (f->pos & 2047); - + //printf("ptr(FIRST) = %d, %x\n", ptr, ptr); printf("rsize = %d\n", rsize); - + memcpy(ptr, onesec_buf + (f->pos & 2047), (rsize > max) ? max : rsize); - + // Middle sector ptr += max; - + //printf("ptr(MIDDLEsex) = %d, %x\n", ptr, ptr); nsect--; csize -= max; - + if(nsect > 1) { //lseek(f->fildes, (f->pos & (~0x7ff)) + 2048, SEEK_SET); //#warning "Check correctness of this calculation." - + /*if(rsize & 2047) sect_num = (rsize|2047)+1; else sect_num = rsize; - + sect_num -= 4096;*/ - + //printf("read_middle=%d, sect_num = %d\n", read(f->fildes, ptr, sect_num), sect_num); - + read(f->fildes, ptr, (nsect - 1) * 2048); - + ptr += (nsect - 1) * 2048; csize -= (nsect - 1) * 2048; nsect = 1; } - + //printf("ptr(LAST) = %d, %x\n", ptr, ptr); - + if(nsect == 1) { // Last sector read(f->fildes, onesec_buf, 2048); - + memcpy(ptr, onesec_buf, csize); } } else if(f->dev == FDEV_CONSOLE) return 0; - + if(f->dev != FDEV_CONSOLE) { f->pos+= rsize; f->eof = (f->pos > f->size); - + if(f->eof) f->pos = f->size; } @@ -317,15 +317,15 @@ int fread(void *ptr, int size, int nmemb, FILE *f) int fgetc(FILE *f) { unsigned char c; - + if(f->pos >= f->size) return EOF; - + fread(&c, sizeof(char), 1, f); - + return (int)c; } - + int ftell(FILE *f) { return f->pos; @@ -348,7 +348,7 @@ int fseek(FILE *f, int offset, int whence) f->pos = whence + offset; break; } - + return 0; } @@ -373,7 +373,7 @@ int libc_get_transtbl_fname(const char *tofind, char *outstr, int outl) FILE *f; int s; int x; - int type; + int type = 0; int y; int l = strlen(tofind); int filename_found = 0; @@ -486,7 +486,7 @@ int libc_get_transtbl_fname(const char *tofind, char *outstr, int outl) for(; tofind[tfp] == '\\' || tofind[tfp] == '/'; tfp++); otfp = tfp; - + for(y = otfp; y < l; y++) { if(tofind[y] == '\0' || tofind[y] == '\\' || tofind[y] == '/') @@ -494,7 +494,7 @@ int libc_get_transtbl_fname(const char *tofind, char *outstr, int outl) } tfp = y; - + strcat(rootpath, orgname); strcat(rootpath, "\\"); @@ -519,7 +519,7 @@ int libc_get_transtbl_fname(const char *tofind, char *outstr, int outl) fseek(f, 0, SEEK_SET); fread(transtbl, 1, s, f); fclose(f); - + x = 0; } } @@ -597,11 +597,11 @@ int sio_putchar(int c) { if(c == '\n' && __sio_cr_mapped) sio_putchar('\r'); - + while(!SIOCheckOutBuffer()); - + SIOSendByte(c); - + return c; } @@ -609,9 +609,9 @@ int sio_puts(const char *str) { while(*str) sio_putchar(*(str++)); - + sio_putchar('\n'); - + return 1; } @@ -629,7 +629,7 @@ int putchar(int c) return sio_putchar(c); break; } - + return EOF; } @@ -644,23 +644,23 @@ int puts(const char *str) return sio_puts(str); break; } - + return EOF; } int fwrite(void *ptr, int size, int nmemb, FILE *f) -{ +{ if(IS_CONS_OUT(f)) // stdout or stderr { char *c = ptr; int i; - - for(i = 0; i < size; i++) + + for(i = 0; i < size; i++) putchar(c[i]); - + return size; } - + return 0; } @@ -668,7 +668,7 @@ int fputs(const char *str, FILE *stream) { if(IS_CONS_OUT(stream)) return puts(str); - + return EOF; } @@ -676,7 +676,7 @@ FILE *freopen(const char *path, const char *mode, FILE *stream) { if(stream == NULL) return NULL; - + if(stream->used) fclose(stream); |
