diff options
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/engine/game.cpp | 9 | ||||
-rw-r--r-- | engines/sci/engine/kstring.cpp | 17 | ||||
-rw-r--r-- | engines/sci/gfx/gfx_resource.h | 6 | ||||
-rw-r--r-- | engines/sci/gfx/resource/sci_pal_1.cpp | 7 | ||||
-rw-r--r-- | engines/sci/sfx/softseq/amiga.cpp | 21 | ||||
-rw-r--r-- | engines/sci/tools.cpp | 54 | ||||
-rw-r--r-- | engines/sci/tools.h | 5 |
7 files changed, 39 insertions, 80 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 5c7bd07f3e..83a62c57b0 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -24,6 +24,7 @@ */ #include "common/system.h" +#include "common/file.h" #include "sci/include/sciresource.h" #include "sci/include/engine.h" @@ -139,10 +140,10 @@ int _reset_graphics_input(EngineState *s) { } } else { // Check for Amiga palette file. - FILE *f = sci_fopen("spal", "rb"); - if (f) { - s->gfx_state->resstate->static_palette = gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, f); - fclose(f); + Common::File file; + if (file.open("spal")) { + s->gfx_state->resstate->static_palette = gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, file); + file.close(); _sci1_alloc_system_colors(s); } else { resource = scir_find_resource(s->resmgr, sci_palette, 999, 1); diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index f961515c94..0e48254026 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -408,6 +408,23 @@ reg_t kStrCpy(EngineState *s, int funct_nr, int argc, reg_t *argv) { return argv[0]; } +/* Simple heuristic to work around array handling peculiarity in SQ4: +It uses StrAt() to read the individual elements, so we must determine +whether a string is really a string or an array. */ +static int is_print_str(char *str) { + int printable = 0; + int len = strlen(str); + + if (len == 0) return 1; + + while (*str) { + if (isprint(*str)) printable++; + str++; + } + + return ((float)printable / (float)len >= 0.5); +} + reg_t kStrAt(EngineState *s, int funct_nr, int argc, reg_t *argv) { unsigned char *dest = (unsigned char *) kernel_dereference_bulk_pointer(s, argv[0], 0); diff --git a/engines/sci/gfx/gfx_resource.h b/engines/sci/gfx/gfx_resource.h index 8fc26d2d2c..b306d0d68b 100644 --- a/engines/sci/gfx/gfx_resource.h +++ b/engines/sci/gfx/gfx_resource.h @@ -31,6 +31,10 @@ #include "sci/gfx/gfx_system.h" #include "sci/gfx/gfx_driver.h" +namespace Common { + class File; +} + namespace Sci { /*** Styles for pic0 drawing ***/ @@ -355,7 +359,7 @@ gfx_pixmap_color_t *gfxr_read_pal1(int id, int *colors_nr, byte *resource, int s ** Returns : (gfx_pixmap_color_t *) *colors_nr color_t entries with the colors */ -gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, FILE *f); +gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, Common::File &file); /* Reads an SCI1 palette ** Parameters: (int *) colors_nr: Pointer to the variable the number of colors ** will be stored in diff --git a/engines/sci/gfx/resource/sci_pal_1.cpp b/engines/sci/gfx/resource/sci_pal_1.cpp index 97280cef25..544f6db4f3 100644 --- a/engines/sci/gfx/resource/sci_pal_1.cpp +++ b/engines/sci/gfx/resource/sci_pal_1.cpp @@ -25,6 +25,7 @@ /* SCI1 palette resource defrobnicator */ +#include "common/file.h" #include "sci/include/sci_memory.h" #include "sci/gfx/gfx_system.h" #include "sci/gfx/gfx_resource.h" @@ -132,7 +133,7 @@ gfx_pixmap_color_t *gfxr_read_pal1(int id, int *colors_nr, byte *resource, int s return retval; } -gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, FILE *f) { +gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, Common::File &file) { int i; gfx_pixmap_color_t *retval; @@ -141,8 +142,8 @@ gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, FILE *f) { for (i = 0; i < 32; i++) { int b1, b2; - b1 = fgetc(f); - b2 = fgetc(f); + b1 = file.readByte(); + b2 = file.readByte(); if (b1 == EOF || b2 == EOF) { GFXERROR("Palette file ends prematurely\n"); diff --git a/engines/sci/sfx/softseq/amiga.cpp b/engines/sci/sfx/softseq/amiga.cpp index a6926b2101..938a778e6d 100644 --- a/engines/sci/sfx/softseq/amiga.cpp +++ b/engines/sci/sfx/softseq/amiga.cpp @@ -27,6 +27,7 @@ #include "sci/include/sci_memory.h" #include "sci/sfx/softseq.h" +#include "common/file.h" #include "common/frac.h" namespace Sci { @@ -112,7 +113,7 @@ static hw_channel_t hw_channels[HW_CHANNELS_NR]; static int volume = 127; /* Frequencies for every note */ -static int freq_table[] = { +static const int freq_table[] = { 58, 62, 65, 69, 73, 78, 82, 87, 92, 98, 104, 110, 117, 124, 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, @@ -360,7 +361,7 @@ static int32 read_int32(byte *data) { return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; } -static instrument_t *read_instrument(FILE *file, int *id) { +static instrument_t *read_instrument(Common::File &file, int *id) { instrument_t *instrument; byte header[61]; int size; @@ -368,7 +369,7 @@ static instrument_t *read_instrument(FILE *file, int *id) { int loop_offset; int i; - if (fread(header, 1, 61, file) < 61) { + if (file.read(header, 61) < 61) { sciprintf("[sfx:seq:amiga] Error: failed to read instrument header\n"); return NULL; } @@ -411,7 +412,7 @@ static instrument_t *read_instrument(FILE *file, int *id) { sciprintf(" Segment offsets: 0 %i %i\n", loop_offset, read_int32(header + 43)); #endif instrument->samples = (int8 *) sci_malloc(size + 1); - if (fread(instrument->samples, 1, size, file) < (unsigned int)size) { + if (file.read(instrument->samples, size) < (unsigned int)size) { sciprintf("[sfx:seq:amiga] Error: failed to read instrument samples\n"); return NULL; } @@ -451,20 +452,17 @@ static int ami_set_option(sfx_softseq_t *self, const char *name, const char *val } static int ami_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch2, int patch2_len) { - FILE *file; + Common::File file; byte header[40]; int i; - file = sci_fopen("bank.001", "rb"); - - if (!file) { + if (!file.open("bank.001")) { sciprintf("[sfx:seq:amiga] Error: file bank.001 not found\n"); return SFX_ERROR; } - if (fread(header, 1, 40, file) < 40) { + if (file.read(header, 40) < 40) { sciprintf("[sfx:seq:amiga] Error: failed to read header of file bank.001\n"); - fclose(file); return SFX_ERROR; } @@ -494,7 +492,6 @@ static int ami_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch if (!instrument) { sciprintf("[sfx:seq:amiga] Error: failed to read bank.001\n"); - fclose(file); return SFX_ERROR; } @@ -506,8 +503,6 @@ static int ami_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch bank.instruments[id] = instrument; } - fclose(file); - return SFX_OK; } diff --git a/engines/sci/tools.cpp b/engines/sci/tools.cpp index 7183dab841..8acb14868e 100644 --- a/engines/sci/tools.cpp +++ b/engines/sci/tools.cpp @@ -53,16 +53,6 @@ namespace Sci { -// FIXME: Get rid of G_DIR_SEPARATOR / G_DIR_SEPARATOR_S -#if _MSC_VER -# define G_DIR_SEPARATOR_S "\\" -# define G_DIR_SEPARATOR '\\' -#else -# define G_DIR_SEPARATOR_S "/" -# define G_DIR_SEPARATOR '/' -#endif - - #ifndef _MSC_VER # include <sys/time.h> #endif @@ -331,11 +321,6 @@ Common::String _fcaseseek(const char *fname) { // Expects *dir to be uninitialized and the caller to // free it afterwards */ - if (strchr(fname, G_DIR_SEPARATOR)) { - fprintf(stderr, "_fcaseseek() does not support subdirs\n"); - BREAKPOINT(); - } - // Look up the file, ignoring case Common::ArchiveMemberList files; SearchMan.listMatchingMembers(files, fname); @@ -388,26 +373,6 @@ char *sci_getcwd() { return NULL; } -#ifdef __DC__ - -int sci_fd_size(int fd) { - return fs_total(fd); -} - -int sci_file_size(const char *fname) { - int fd = fs_open(fname, O_RDONLY); - int retval = -1; - - if (fd != 0) { - retval = sci_fd_size(fd); - fs_close(fd); - } - - return retval; -} - -#else - int sci_fd_size(int fd) { struct stat fd_stat; @@ -426,23 +391,4 @@ int sci_file_size(const char *fname) { return fn_stat.st_size; } -#endif - -/* Simple heuristic to work around array handling peculiarity in SQ4: -It uses StrAt() to read the individual elements, so we must determine -whether a string is really a string or an array. */ -int is_print_str(char *str) { - int printable = 0; - int len = strlen(str); - - if (len == 0) return 1; - - while (*str) { - if (isprint(*str)) printable++; - str++; - } - - return ((float)printable / (float)len >= 0.5); -} - } // End of namespace Sci diff --git a/engines/sci/tools.h b/engines/sci/tools.h index 7528035742..b1fa306355 100644 --- a/engines/sci/tools.h +++ b/engines/sci/tools.h @@ -182,11 +182,6 @@ int sci_file_size(const char *fname); ** Returns : (int) filesize of the file, -1 on error */ -/* Simple heuristic to work around array handling peculiarity in SQ4: -It uses StrAt() to read the individual elements, so we must determine -whether a string is really a string or an array. */ -int is_print_str(char *str); - /** Find first set bit in bits and return its index. Returns 0 if bits is 0. */ int sci_ffs(int bits); |