For reference, this assembly code comes from a larger function that finds the intersection between two boxes. In C, it'd be:
struct box {
uint16_t x0;
uint16_t y0;
uint16_t x1;
uint16_t y1;
};
void intersect(box* src1, box* src2, box* dest) {
dest->x0 = max(src1->x0, src2->x0);
dest->y0 = max(src1->y0, src2->y0);
dest->x1 = min(src1->x1, src2->x1);
dest->y1 = min(src1->y1, src2->y1);
if (dest->x0 > dest->x1 || dest->y0 > dest->y1) {
dest->x0 = dest->y0 = dest->x1 = dest->y1 = 0;
}
}
But everything is inlined, so the overall function size is 495 bytes, ouch! That's gotta hurt!
Well, beats me why the compiler loves to generate this instead of,
LD HL, 0x10
ADD HL, SP
INC (HL)
Insted, it's doing a 16-bit INC and immediately throwing out the high byte, because the underlying variable is a byte.
Sadly, this is part of the generated code for every "for" loop, so I recognize it on sight now.
Old function signature: byte get_tab16.1_ram_etc???nogo???_verify_assoc_wozthis(byte tab16row)
New function signature: byte get_ram_page_and_flags(byte widget_num)
Maybe you can see why I'm going through and renaming all these.
Of course, I am super glad that others have reverse engineered this enough to give me any function names and entry points to start with. Let alone ones that make a certain kind of sense if you understand the naming scheme.
"tab16" was the name of a particular table with 16-byte entries. The original reversers later discovered this to be a table of widget structs, but didn't rename it. "tab16row", therefore, is widget number.
"1_ram_etc???nogo???" is the name of the first field of the widget struct and some notes about its potential purpose. I gave it the more streamlined name of "ram_page_and_flags".
"wozthis" is the name of a global variable that was later discovered to be the index of the currently running app, but again, not renamed. "verify_assoc_wozthis" is referring to logic in the function that falls back to returning the current app's rampage_and_flags field, instead of looking it up in the widget, if a placeholder widget number (-1) is specified.
So the name makes perfect sense but only if you already kinda understand what the function did
I'm not really smart enough to intuit all this, so I have to re-rename everything with names that make sense TO ME!
box2->x0 = (box1->x1 - 30)*foo / (fbuf[0] + fbuf[1])
Sometime soon, hopefully, I will understand the significance of this value that #MailStation widget #4 has calculated.