diff --git a/docs/manual/errors-list.html b/docs/manual/errors-list.html index 74aa551f..50f7fc66 100644 --- a/docs/manual/errors-list.html +++ b/docs/manual/errors-list.html @@ -217,6 +217,8 @@ Espcblock_macro_invalid_static_argsCustom spcblock macros must have three static arguments Espcblock_custom_types_incompleteCustom spcblock types are not yet supported. One day. Estartpos_without_spcblockThe startpos command is only valid in spcblocks +Einvalid_endspcblock_argInvalid argument to endspcblock: "%s" +Eunknown_endspcblock_formatUnsupported endspcblock format. Currently supported formats are "endspcblock" and "endspcblock execute [label]" Einternal_errorAn internal asar error occured (%s). Send help. Epushns_without_pullnspushns without matching pullns. Epullns_without_pushnspullns without matching pushns. diff --git a/docs/manual/warnings-list.html b/docs/manual/warnings-list.html index c5394de5..2c8ef6e2 100644 --- a/docs/manual/warnings-list.html +++ b/docs/manual/warnings-list.html @@ -49,6 +49,7 @@ Wmapper_already_setA mapper has already been selected.True Wfeature_deprecatedDEPRECATION NOTIFICATION: Feature "%s" is deprecated and will be REMOVED in the future. Please update your code to conform to newer styles. Suggested work around: %s.True Wbyte_order_mark_utf8UTF-8 byte order mark detected and skipped.True +Woptimization_settingsIn Asar 2.0, the default optimization settings will change to `optimize dp always` and `optimize address mirrors`, which changes this instruction's argument from %d to %d bytes. Either specify the desired settings manually or use explicit length suffixes to silence this warning.True diff --git a/src/asar/asar.h b/src/asar/asar.h index f5262240..ef75ac94 100644 --- a/src/asar/asar.h +++ b/src/asar/asar.h @@ -112,6 +112,8 @@ namespace optimize_dp_flag { extern int optimize_dp; extern int dp_base; +extern bool set_optimize_dp; +extern bool set_optimize_address; namespace optimize_address_flag { enum : int { diff --git a/src/asar/assembleblock.cpp b/src/asar/assembleblock.cpp index 982c700d..71805e99 100644 --- a/src/asar/assembleblock.cpp +++ b/src/asar/assembleblock.cpp @@ -731,8 +731,10 @@ void initstuff() optimizeforbank = -1; optimize_dp = optimize_dp_flag::NONE; + set_optimize_dp = false; dp_base = 0; optimize_address = optimize_address_flag::DEFAULT; + set_optimize_address = false; in_struct = false; in_sub_struct = false; @@ -1869,16 +1871,19 @@ void assembleblock(const char * block, bool isspecialline) if (!stricmp(word[2], "none")) { optimize_dp = optimize_dp_flag::NONE; + set_optimize_dp = true; return; } if (!stricmp(word[2], "ram")) { optimize_dp = optimize_dp_flag::RAM; + set_optimize_dp = true; return; } if (!stricmp(word[2], "always")) { optimize_dp = optimize_dp_flag::ALWAYS; + set_optimize_dp = true; return; } asar_throw_error(1, error_type_block, error_id_bad_dp_optimize, word[2]); @@ -1888,16 +1893,19 @@ void assembleblock(const char * block, bool isspecialline) if (!stricmp(word[2], "default")) { optimize_address = optimize_address_flag::DEFAULT; + set_optimize_address = true; return; } if (!stricmp(word[2], "ram")) { optimize_address = optimize_address_flag::RAM; + set_optimize_address = true; return; } if (!stricmp(word[2], "mirrors")) { optimize_address = optimize_address_flag::MIRRORS; + set_optimize_address = true; return; } asar_throw_error(1, error_type_block, error_id_bad_address_optimize, word[2]); diff --git a/src/asar/main.cpp b/src/asar/main.cpp index f6f690ba..105bbf0f 100644 --- a/src/asar/main.cpp +++ b/src/asar/main.cpp @@ -39,8 +39,10 @@ int pass; int optimizeforbank=-1; int optimize_dp = optimize_dp_flag::NONE; +bool set_optimize_dp = false; int dp_base = 0; int optimize_address = optimize_address_flag::DEFAULT; +bool set_optimize_address = false; string thisfilename; int thisline; @@ -152,13 +154,19 @@ virtual_file_error asar_get_last_io_error() } static bool freespaced; -static int getlenforlabel(int insnespos, int thislabel, bool exists) +static int getlenforlabel(int insnespos, int thislabel, bool exists, bool use_asar2_settings) { if (warnxkas && (((unsigned int)(thislabel^insnespos)&0xFFFF0000)==0)) asar_throw_warning(1, warning_id_xkas_label_access); unsigned int bank = thislabel>>16; unsigned int word = thislabel&0xFFFF; unsigned int relaxed_bank; + int opt_dp = optimize_dp; + int opt_addr = optimize_address; + if(use_asar2_settings) { + if(!set_optimize_dp) opt_dp = optimize_dp_flag::ALWAYS; + if(!set_optimize_address) opt_addr = optimize_address_flag::MIRRORS; + } if(optimizeforbank >= 0) { relaxed_bank = optimizeforbank; } else { @@ -175,17 +183,17 @@ static int getlenforlabel(int insnespos, int thislabel, bool exists) freespaced=true; return 2; } - else if((optimize_dp == optimize_dp_flag::RAM) && bank == 0x7E && (word-dp_base < 0x100)) + else if((opt_dp == optimize_dp_flag::RAM) && bank == 0x7E && (word-dp_base < 0x100)) { return 1; } - else if(optimize_dp == optimize_dp_flag::ALWAYS && (bank == 0x7E || !(bank & 0x40)) && (word-dp_base < 0x100)) + else if(opt_dp == optimize_dp_flag::ALWAYS && (bank == 0x7E || !(bank & 0x40)) && (word-dp_base < 0x100)) { return 1; } else if ( // if we should optimize ram accesses... - (optimize_address == optimize_address_flag::RAM || optimize_address == optimize_address_flag::MIRRORS) + (opt_addr == optimize_address_flag::RAM || opt_addr == optimize_address_flag::MIRRORS) // and we're in a bank with ram mirrors... (optimizeforbank=0x7E is checked later) && !(relaxed_bank & 0x40) // and the label is in low RAM @@ -195,7 +203,7 @@ static int getlenforlabel(int insnespos, int thislabel, bool exists) } else if ( // if we should optimize mirrors... - optimize_address == optimize_address_flag::MIRRORS + opt_addr == optimize_address_flag::MIRRORS // we're in a bank with ram mirrors... && !(relaxed_bank & 0x40) // and the label is in a mirrored section @@ -221,6 +229,13 @@ static int getlenforlabel(int insnespos, int thislabel, bool exists) else { return 2;} } +static int getlenforlabel_wrap(int insnespos, int thislabel, bool exists) +{ + int oldlen = getlenforlabel(insnespos, thislabel, exists, false); + int newlen = getlenforlabel(insnespos, thislabel, exists, true); + if(oldlen != newlen) asar_throw_warning(2, warning_id_optimization_settings, oldlen, newlen); + return oldlen; +} bool is_hex_constant(const char* str){ if (*str=='$') @@ -253,7 +268,7 @@ int getlen(const char * orgstr, bool optimizebankextraction) // RPG Hacker: Umm... what kind of magic constant is this? label_data.pos = 31415926; bool found = labelval(posnegname, &label_data); - return getlenforlabel(snespos, (int)label_data.pos, found); + return getlenforlabel_wrap(snespos, (int)label_data.pos, found); } notposneglabel: int len=0; @@ -296,7 +311,7 @@ int getlen(const char * orgstr, bool optimizebankextraction) { snes_label thislabel; bool exists=labelval(&str, &thislabel); - thislen=getlenforlabel(snespos, (int)thislabel.pos, exists); + thislen=getlenforlabel_wrap(snespos, (int)thislabel.pos, exists); } else str++; if (optimizebankextraction && maybebankextraction && diff --git a/src/asar/warnings.cpp b/src/asar/warnings.cpp index e4b0c8e4..37e72af8 100644 --- a/src/asar/warnings.cpp +++ b/src/asar/warnings.cpp @@ -90,6 +90,7 @@ static asar_warning_mapping asar_warnings[] = { WRN(feature_deprecated), "DEPRECATION NOTIFICATION: Feature \"%s\" is deprecated and will be REMOVED in the future. Please update your code to conform to newer styles. Suggested work around: %s." }, { WRN(byte_order_mark_utf8), "UTF-8 byte order mark detected and skipped." }, + { WRN(optimization_settings), "In Asar 2.0, the default optimization settings will change to `optimize dp always` and `optimize address mirrors`, which changes this instruction's argument from %d to %d bytes. Either specify the desired settings manually or use explicit length suffixes to silence this warning." }, }; // RPG Hacker: Sanity check. This makes sure that the element count of asar_warnings diff --git a/src/asar/warnings.h b/src/asar/warnings.h index 5835cbcd..a3c73545 100644 --- a/src/asar/warnings.h +++ b/src/asar/warnings.h @@ -59,6 +59,8 @@ enum asar_warning_id : int warning_id_byte_order_mark_utf8, + warning_id_optimization_settings, + warning_id_end, warning_id_count = warning_id_end - warning_id_start - 1 };