VOGONS


First post, by ih8registrations

User metadata
Rank Oldbie
Rank
Oldbie
	for (r = 0; r <= 3; r++) {
Bitu f_vco = target * (1 << r);
if (MIN_VCO <= f_vco && f_vco < MAX_VCO) break;
}

If the min_vco <= && < max_vco is an out of bounds check then < max_vco should be >=. If not then < max_vco is unecessary.

Last edited by ih8registrations on 2007-09-10, 16:52. Edited 1 time in total.

Reply 2 of 5, by ih8registrations

User metadata
Rank Oldbie
Rank
Oldbie

I hadn't bothered to understand what it was doing, I just recognized the if logic; breaks only if both conditionals are true, if f_vco is less than or equal to min_vco then it's less than max_vco, as min_vco is less than max_vco, so either checking f_vco < max_vco is unecessary or it's supposed to be checking >=.

Reply 3 of 5, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Care that it's

MIN_VCO <= f_vco && f_vco < MAX_VCO

and not

f_vco <= MIN_VCO && f_vco < MAX_VCO

The <MAX_VCO check might be not necessary in the loop, but could be
put after it, yet it looks cleaner that way and isn't speed relevant code.

Reply 4 of 5, by ih8registrations

User metadata
Rank Oldbie
Rank
Oldbie

"Care that it's" What? A more complete sentence perhaps?

As well, in your example I can see you swapped variable positions but I don't know what you're trying to show in doing so.

I don't find doing such cleaner, but confusing, and yes, of course it isn't speed relevent.

Speaking of optimizations, vga_determinmode can be size optimized by replacing all the vga_setmode calls with variable=immediate.

void VGA_DetermineMode(void) {
int mode;
/* Test for VGA output active or direct color modes */
if (vga.s3.misc_control_2 & 0xf0) {
switch (vga.s3.misc_control_2 >> 4) {
case 1:mode=M_LIN8;break;
case 3:mode=M_LIN15;break;
case 5:mode=M_LIN16;break;
case 13:mode=M_LIN32;break;
}
/* Test for graphics or alphanumeric mode */
} else if (vga.attr.mode_control & 1) {
if (vga.gfx.mode & 0x40) mode=M_VGA;
else if (vga.gfx.mode & 0x20) mode=M_CGA4;
else if ((vga.gfx.miscellaneous & 0x0c)==0x0c) mode=M_CGA2;
else {
if (vga.s3.reg_31 & 0x8)
mode=M_LIN4;
else
mode=M_EGA;
}
} else {
mode=M_TEXT;
}
VGA_SetMode(mode);
}