From c22fbd0374f877056aacdba3ab4ee8cfff672dff Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sun, 11 May 2014 19:18:53 -0700 Subject: [PATCH] Reduce dependence on global TEMP buffer * display.S still uses this ... will be refactored completely with new video update --- src/disk.c | 3 ++- src/display.c | 2 ++ src/interface.c | 17 ++++++++++------- src/joystick.c | 4 ++++ src/meta/debug.l | 2 +- src/meta/debugger.c | 2 ++ src/misc.c | 9 +++++---- src/misc.h | 6 +----- src/zlib-helpers.c | 8 ++++---- 9 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/disk.c b/src/disk.c index 2b5ea4fb..36a4f6b8 100644 --- a/src/disk.c +++ b/src/disk.c @@ -761,13 +761,14 @@ void disk_io_initialize(unsigned int slot) { FILE *f; int i; + char temp[PATH_MAX]; assert(slot == 6); /* load Disk II rom */ if (!slot6_rom_loaded) { - snprintf(temp, TEMPSIZE, "%s/slot6.rom", system_path); + snprintf(temp, PATH_MAX, "%s/slot6.rom", system_path); if ((f = fopen( temp, "r" )) == NULL) { printf("Cannot find file '%s'.\n",temp); diff --git a/src/display.c b/src/display.c index 20c45a6c..0a6e3d76 100644 --- a/src/display.c +++ b/src/display.c @@ -20,6 +20,8 @@ #define BEGIN_MIX 20 #define TEXT_COLS 40 +uint8_t temp[1024];// HACK to be removed + static uint8_t vga_mem_page_0[SCANWIDTH*SCANHEIGHT]; /* page0 framebuffer */ static uint8_t vga_mem_page_1[SCANWIDTH*SCANHEIGHT]; /* page1 framebuffer */ diff --git a/src/interface.c b/src/interface.c index b6fa7898..78401ab8 100644 --- a/src/interface.c +++ b/src/interface.c @@ -414,6 +414,7 @@ void c_interface_select_diskette( int drive ) curpos = entries - 1; } + char temp[PATH_MAX]; for (;;) { for (i = 0; i < 18; i++) @@ -424,7 +425,7 @@ void c_interface_select_diskette( int drive ) strcpy( temp, " " ); if (ent_no >= 0 && ent_no < entries) { - snprintf(temp, TEMPSIZE, "%s/%s", + snprintf(temp, PATH_MAX, "%s/%s", disk_path, namelist[ent_no]->d_name); if (!strcmp(temp, disk6.disk[drive].file_name)) { @@ -434,27 +435,27 @@ void c_interface_select_diskette( int drive ) stat(temp, &statbuf); if (S_ISDIR(statbuf.st_mode)) { - snprintf(temp, TEMPSIZE, " %s/", + snprintf(temp, PATH_MAX, " %s/", namelist[ ent_no ]->d_name ); } else { - snprintf(temp, TEMPSIZE, " %s", + snprintf(temp, PATH_MAX, " %s", namelist[ ent_no ]->d_name ); } if (c_interface_cut_name(temp)) { - strncat(temp, " ", TEMPSIZE-1); + strncat(temp, " ", PATH_MAX-1); } /* write protected disk in drive? */ else if ((in_drive) && (disk6.disk[drive].is_protected)) { - strncat(temp, (drive == 0) ? " " : " ", TEMPSIZE-1); + strncat(temp, (drive == 0) ? " " : " ", PATH_MAX-1); } else if (in_drive) { - strncat(temp, (drive == 0) ? " " : " ", TEMPSIZE-1); + strncat(temp, (drive == 0) ? " " : " ", PATH_MAX-1); } } @@ -553,7 +554,7 @@ void c_interface_select_diskette( int drive ) { int len; - snprintf(temp, TEMPSIZE, "%s/%s", + snprintf(temp, PATH_MAX, "%s/%s", disk_path, namelist[ curpos ]->d_name ); len = strlen(disk_path); @@ -723,6 +724,8 @@ void c_interface_parameters() c_interface_translate_screen( screen ); c_interface_print_screen( screen ); +#define TEMPSIZE 1024 + char temp[TEMPSIZE]; for (;;) { for (i = 0; (i < PARAMS_H) && (i < NUM_OPTIONS); i++) diff --git a/src/joystick.c b/src/joystick.c index 347bba61..dd7a65ac 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -169,6 +169,9 @@ static void c_calibrate_pc_joystick() } } +#define TEMPSIZE 256 + char temp[TEMPSIZE]; + #define CALIBRATE_SUBMENU_H 9 #define CALIBRATE_SUBMENU_W 40 char submenu[CALIBRATE_SUBMENU_H][CALIBRATE_SUBMENU_W+1] = @@ -369,6 +372,7 @@ static void c_calibrate_keypad_joystick() uint8_t x_last=CALIBRATE_JOYMENU_W>>1, y_last=CALIBRATE_JOYMENU_H>>1; const char* const spinney = "|/-\\"; uint8_t spinney_idx=0; + char temp[TEMPSIZE]; for (;;) { submenu[KEYPAD_SUBMENU_H-2][12] = joy_button0 ? 'X' : ' '; diff --git a/src/meta/debug.l b/src/meta/debug.l index 8d80373a..92202ff2 100644 --- a/src/meta/debug.l +++ b/src/meta/debug.l @@ -891,7 +891,7 @@ ADDRS [0-9a-fA-F]+ /* copy file name */ ptr = debugtext; while (!isspace(*debugtext)) ++debugtext; - int len = MIN(debugtext - ptr, TEMPSIZE-1); + int len = MIN(debugtext - ptr, DEBUG_BUFSZ-1); strncpy(buf, ptr, len); buf[len] = '\0'; diff --git a/src/meta/debugger.c b/src/meta/debugger.c index c40d209e..ea0dfbf8 100644 --- a/src/meta/debugger.c +++ b/src/meta/debugger.c @@ -464,6 +464,8 @@ void bload(FILE *f, char *name, int addrs) { return; } +#define TEMPSIZE 1024 + char temp[TEMPSIZE]; while ((len = fread(temp, 1, TEMPSIZE, f))) { hexstr = (uint8_t*)temp; diff --git a/src/misc.c b/src/misc.c index 2b0b0aaa..c8c8ffef 100644 --- a/src/misc.c +++ b/src/misc.c @@ -468,7 +468,8 @@ void c_initialize_apple_ii_memory() if (!iie_rom_loaded) { - snprintf(temp, TEMPSIZE, "%s/apple_IIe.rom", system_path); + char temp[PATH_MAX]; + snprintf(temp, PATH_MAX, "%s/apple_IIe.rom", system_path); if ((f = fopen(temp, "r")) == NULL) { printf("Cannot find file '%s'.\n",temp); @@ -633,10 +634,10 @@ static void main_thread(void *dummyptr) { extern void cpu_thread(void *dummyptr); -int main(int sargc, char *sargv[]) +int main(int _argc, char **_argv) { - argc = sargc; - argv = sargv; + argc = _argc; + argv = _argv; load_settings(); /* user prefs */ c_initialize_firsttime(); /* init svga graphics and vm */ diff --git a/src/misc.h b/src/misc.h index 5febc7c5..48ab59c5 100644 --- a/src/misc.h +++ b/src/misc.h @@ -46,13 +46,9 @@ uint8_t apple_ii_64k[2][65536]; /* 128k memory */ uint8_t language_card[2][8192], language_banks[2][8192]; /* global ref to commandline args */ -char **argv; +char **argv; int argc; -/* misc arrays */ -#define TEMPSIZE 4096 -char temp[ TEMPSIZE ]; /* should be >=4096 (stuff depends on this) */ - extern uint8_t *base_ramrd; extern uint8_t *base_ramwrt; extern uint8_t *base_textrd; diff --git a/src/zlib-helpers.c b/src/zlib-helpers.c index c5625772..fd836896 100644 --- a/src/zlib-helpers.c +++ b/src/zlib-helpers.c @@ -67,8 +67,8 @@ const char *def(const char* const src, const int expected_bytecount) break; } - char dst[TEMPSIZE]; - snprintf(dst, TEMPSIZE-1, "%s%s", src, ".gz"); + char dst[PATH_MAX]; + snprintf(dst, PATH_MAX-1, "%s%s", src, ".gz"); gzdest = gzopen(dst, "wb"); if (gzdest == NULL) { @@ -159,8 +159,8 @@ const char *inf(const char* const src, int *rawcount) } int len = strlen(src); - char dst[TEMPSIZE]; - snprintf(dst, TEMPSIZE-1, "%s", src); + char dst[PATH_MAX]; + snprintf(dst, PATH_MAX-1, "%s", src); if (! ( (dst[len-3] == '.') && (dst[len-2] == 'g') && (dst[len-1] == 'z') ) ) { ERRLOG("Expected filename ending in .gz"); break;