Skip to content

Commit

Permalink
add warning about the default optimize settings changing
Browse files Browse the repository at this point in the history
  • Loading branch information
randomdude999 committed Jan 28, 2024
1 parent 9f082a2 commit 0924e12
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/manual/errors-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@
<tr><td>Espcblock_macro_invalid_static_args</td><td>Custom spcblock macros must have three static arguments</td></tr>
<tr><td>Espcblock_custom_types_incomplete</td><td>Custom spcblock types are not yet supported. One day.</td></tr>
<tr><td>Estartpos_without_spcblock</td><td>The startpos command is only valid in spcblocks</td></tr>
<tr><td>Einvalid_endspcblock_arg</td><td>Invalid argument to endspcblock: &quot;%s&quot;</td></tr>
<tr><td>Eunknown_endspcblock_format</td><td>Unsupported endspcblock format. Currently supported formats are &quot;endspcblock&quot; and &quot;endspcblock execute [label]&quot;</td></tr>
<tr><td>Einternal_error</td><td>An internal asar error occured (%s). Send help.</td></tr>
<tr><td>Epushns_without_pullns</td><td>pushns without matching pullns.</td></tr>
<tr><td>Epullns_without_pushns</td><td>pullns without matching pushns.</td></tr>
Expand Down
1 change: 1 addition & 0 deletions docs/manual/warnings-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<tr><td>Wmapper_already_set</td><td>A mapper has already been selected.</td><td>True</td></tr>
<tr><td>Wfeature_deprecated</td><td>DEPRECATION NOTIFICATION: Feature &quot;%s&quot; is deprecated and will be REMOVED in the future. Please update your code to conform to newer styles. Suggested work around: %s.</td><td>True</td></tr>
<tr><td>Wbyte_order_mark_utf8</td><td>UTF-8 byte order mark detected and skipped.</td><td>True</td></tr>
<tr><td>Woptimization_settings</td><td>In Asar 2.0, the default optimization settings will change to `optimize dp always` and `optimize address mirrors`, which changes this instruction&#x27;s argument from %d to %d bytes. Either specify the desired settings manually or use explicit length suffixes to silence this warning.</td><td>True</td></tr>

</table>
</body>
Expand Down
2 changes: 2 additions & 0 deletions src/asar/asar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/asar/assembleblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down
29 changes: 22 additions & 7 deletions src/asar/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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=='$')
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 &&
Expand Down
1 change: 1 addition & 0 deletions src/asar/warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/asar/warnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit 0924e12

Please sign in to comment.